2021-11-07 22:19:29 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2021-11-07 22:19:29 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Contact;
|
|
|
|
|
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\BaseModule;
|
|
|
|
use Friendica\Contact\LocalRelationship\Repository\LocalRelationship;
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Widget;
|
|
|
|
use Friendica\Core\L10n;
|
|
|
|
use Friendica\Core\Protocol;
|
2022-10-20 21:35:01 +00:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
2021-11-07 22:19:29 +00:00
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\Model;
|
|
|
|
use Friendica\Module\Contact;
|
2021-11-27 12:19:26 +00:00
|
|
|
use Friendica\Module\Response;
|
2021-11-07 22:19:29 +00:00
|
|
|
use Friendica\Module\Security\Login;
|
|
|
|
use Friendica\Network\HTTPException\NotFoundException;
|
2021-11-27 12:19:26 +00:00
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2021-11-07 22:19:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show a contact posts and comments
|
|
|
|
*/
|
|
|
|
class Posts extends BaseModule
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var LocalRelationship
|
|
|
|
*/
|
|
|
|
private $localRelationship;
|
|
|
|
/**
|
|
|
|
* @var App\Page
|
|
|
|
*/
|
|
|
|
private $page;
|
2022-10-20 21:35:01 +00:00
|
|
|
/**
|
|
|
|
* @var IHandleUserSessions
|
|
|
|
*/
|
|
|
|
private $userSession;
|
2021-11-07 22:19:29 +00:00
|
|
|
|
2022-10-20 21:35:01 +00:00
|
|
|
public function __construct(L10n $l10n, LocalRelationship $localRelationship, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, App\Page $page, IHandleUserSessions $userSession, $server, array $parameters = [])
|
2021-11-07 22:19:29 +00:00
|
|
|
{
|
2021-11-27 12:19:26 +00:00
|
|
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
2021-11-07 22:19:29 +00:00
|
|
|
|
|
|
|
$this->localRelationship = $localRelationship;
|
|
|
|
$this->page = $page;
|
2022-10-20 21:35:01 +00:00
|
|
|
$this->userSession = $userSession;
|
2021-11-07 22:19:29 +00:00
|
|
|
}
|
|
|
|
|
2021-11-27 12:19:26 +00:00
|
|
|
protected function content(array $request = []): string
|
2021-11-07 22:19:29 +00:00
|
|
|
{
|
2022-10-20 21:35:01 +00:00
|
|
|
if (!$this->userSession->getLocalUserId()) {
|
2021-11-07 22:19:29 +00:00
|
|
|
return Login::form($_SERVER['REQUEST_URI']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backward compatibility: Ensure to use the public contact when the user contact is provided
|
|
|
|
// Remove by version 2022.03
|
2022-10-20 21:35:01 +00:00
|
|
|
$data = Model\Contact::getPublicAndUserContactID(intval($this->parameters['id']), $this->userSession->getLocalUserId());
|
2021-11-07 22:19:29 +00:00
|
|
|
if (empty($data)) {
|
|
|
|
throw new NotFoundException($this->t('Contact not found.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$contact = Model\Contact::getById($data['public']);
|
|
|
|
if (!DBA::isResult($contact)) {
|
|
|
|
throw new NotFoundException($this->t('Contact not found.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't display contacts that are about to be deleted
|
|
|
|
if (DBA::isResult($contact) && (!empty($contact['deleted']) || !empty($contact['network']) && $contact['network'] == Protocol::PHANTOM)) {
|
|
|
|
throw new NotFoundException($this->t('Contact not found.'));
|
|
|
|
}
|
|
|
|
|
2022-10-20 21:35:01 +00:00
|
|
|
$localRelationship = $this->localRelationship->getForUserContact($this->userSession->getLocalUserId(), $contact['id']);
|
2021-11-07 22:19:29 +00:00
|
|
|
if ($localRelationship->rel === Model\Contact::SELF) {
|
|
|
|
$this->baseUrl->redirect('profile/' . $contact['nick']);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->page['aside'] .= Widget\VCard::getHTML($contact);
|
|
|
|
|
|
|
|
Nav::setSelected('contact');
|
|
|
|
|
|
|
|
$o = Contact::getTabsHTML($contact, Contact::TAB_POSTS);
|
|
|
|
|
|
|
|
$o .= Model\Contact::getPostsFromId($contact['id']);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|