2019-05-18 11:47:39 -04:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
2022-01-02 08:27:47 +01:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 15:45:36 +01: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/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
namespace Friendica\Module\Profile;
|
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
use Friendica\App;
|
2019-05-18 11:47:39 -04:00
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Pager;
|
2022-12-17 00:20:23 -05:00
|
|
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
|
|
|
use Friendica\Core\L10n;
|
2019-05-18 11:47:39 -04:00
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Renderer;
|
2022-12-17 00:20:23 -05:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
|
|
|
use Friendica\Database\Database;
|
2020-08-04 23:02:43 -04:00
|
|
|
use Friendica\Model;
|
|
|
|
use Friendica\Module;
|
2022-12-17 00:20:23 -05:00
|
|
|
use Friendica\Module\Response;
|
2020-08-04 23:02:43 -04:00
|
|
|
use Friendica\Network\HTTPException;
|
2022-12-17 00:20:23 -05:00
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-08-04 23:02:43 -04:00
|
|
|
class Contacts extends Module\BaseProfile
|
2019-05-18 11:47:39 -04:00
|
|
|
{
|
2022-12-17 00:20:23 -05:00
|
|
|
/** @var IManageConfigValues */
|
|
|
|
private $config;
|
|
|
|
/** @var IHandleUserSessions */
|
|
|
|
private $userSession;
|
|
|
|
/** @var App */
|
|
|
|
private $app;
|
|
|
|
/** @var Database */
|
|
|
|
private $database;
|
|
|
|
|
|
|
|
public function __construct(Database $database, App $app, IHandleUserSessions $userSession, IManageConfigValues $config, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
|
|
|
{
|
|
|
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
|
|
|
|
|
|
|
$this->config = $config;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
$this->app = $app;
|
|
|
|
$this->database = $database;
|
|
|
|
}
|
|
|
|
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function content(array $request = []): string
|
2019-05-18 11:47:39 -04:00
|
|
|
{
|
2022-12-17 00:20:23 -05:00
|
|
|
if ($this->config->get('system', 'block_public') && !$this->userSession->isAuthenticated()) {
|
|
|
|
throw new HTTPException\NotFoundException($this->t('User not found.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
2021-11-14 23:19:25 +01:00
|
|
|
$nickname = $this->parameters['nickname'];
|
2022-12-17 00:20:23 -05:00
|
|
|
$type = $this->parameters['type'] ?? 'all';
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
$profile = Model\Profile::load($this->app, $nickname);
|
2021-07-24 10:09:39 +00:00
|
|
|
if (empty($profile)) {
|
2022-12-17 00:20:23 -05:00
|
|
|
throw new HTTPException\NotFoundException($this->t('User not found.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
$is_owner = $profile['uid'] == $this->userSession->getLocalUserId();
|
2020-08-09 09:09:38 -04:00
|
|
|
|
2021-08-23 14:07:32 -04:00
|
|
|
if ($profile['hide-friends'] && !$is_owner) {
|
2022-12-17 00:20:23 -05:00
|
|
|
throw new HTTPException\ForbiddenException($this->t('Permission denied.'));
|
2020-08-04 23:02:43 -04:00
|
|
|
}
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-08-04 23:02:43 -04:00
|
|
|
Nav::setSelected('home');
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2022-11-30 14:38:23 -05:00
|
|
|
$o = self::getTabsHTML('contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, $this->userSession->isAuthenticated() && $profile['uid'] != $this->userSession->getLocalUserId());
|
2020-08-06 10:34:11 -04:00
|
|
|
|
2019-05-18 11:47:39 -04:00
|
|
|
$condition = [
|
2021-07-24 10:09:39 +00:00
|
|
|
'uid' => $profile['uid'],
|
2019-05-18 11:47:39 -04:00
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'archive' => false,
|
2020-10-07 20:06:15 +00:00
|
|
|
'failed' => false,
|
2020-08-04 23:02:43 -04:00
|
|
|
'self' => false,
|
2019-05-18 11:47:39 -04:00
|
|
|
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
|
|
|
|
];
|
|
|
|
|
|
|
|
switch ($type) {
|
2022-12-17 00:20:23 -05:00
|
|
|
case 'followers':
|
|
|
|
$condition['rel'] = [Model\Contact::FOLLOWER, Model\Contact::FRIEND];
|
|
|
|
break;
|
|
|
|
case 'following':
|
|
|
|
$condition['rel'] = [Model\Contact::SHARING, Model\Contact::FRIEND];
|
|
|
|
break;
|
|
|
|
case 'mutuals':
|
|
|
|
$condition['rel'] = Model\Contact::FRIEND;
|
|
|
|
break;
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
$total = $this->database->count('contact', $condition);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
$pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
|
|
|
|
2022-12-17 00:37:40 -05:00
|
|
|
// Contact list is obtained from the visited profile user, but the contact display is visitor dependent
|
2020-08-04 23:02:43 -04:00
|
|
|
$contacts = array_map(
|
2022-12-17 00:37:40 -05:00
|
|
|
function ($contact) {
|
|
|
|
$contact = Model\Contact::selectFirst(
|
|
|
|
[],
|
|
|
|
['uri-id' => $contact['uri-id'], 'uid' => [0, $this->userSession->getLocalUserId()]],
|
|
|
|
['order' => ['uid' => 'DESC']]
|
|
|
|
);
|
|
|
|
return Module\Contact::getContactTemplateVars($contact);
|
|
|
|
},
|
|
|
|
Model\Contact::selectToArray(['uri-id'], $condition, $params)
|
2020-08-04 23:02:43 -04:00
|
|
|
);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-08-04 23:02:43 -04:00
|
|
|
$desc = '';
|
2019-05-18 11:47:39 -04:00
|
|
|
switch ($type) {
|
2020-08-04 23:02:43 -04:00
|
|
|
case 'followers':
|
2022-12-17 00:20:23 -05:00
|
|
|
$title = $this->tt('Follower (%s)', 'Followers (%s)', $total);
|
2020-08-04 23:02:43 -04:00
|
|
|
break;
|
|
|
|
case 'following':
|
2022-12-17 00:20:23 -05:00
|
|
|
$title = $this->tt('Following (%s)', 'Following (%s)', $total);
|
2020-08-04 23:02:43 -04:00
|
|
|
break;
|
|
|
|
case 'mutuals':
|
2022-12-17 00:20:23 -05:00
|
|
|
$title = $this->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
|
|
|
$desc = $this->t(
|
2020-08-04 23:02:43 -04:00
|
|
|
'These contacts both follow and are followed by <strong>%s</strong>.',
|
2021-07-24 10:09:39 +00:00
|
|
|
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
|
2020-08-04 23:02:43 -04:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
default:
|
2022-12-17 00:20:23 -05:00
|
|
|
$title = $this->tt('Contact (%s)', 'Contacts (%s)', $total);
|
2020-08-04 23:02:43 -04:00
|
|
|
break;
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
2022-12-17 00:20:23 -05:00
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
|
|
|
'$title' => $title,
|
|
|
|
'$desc' => $desc,
|
|
|
|
'$tabs' => $tabs,
|
2020-08-06 10:34:11 -04:00
|
|
|
|
2022-12-17 00:20:23 -05:00
|
|
|
'$noresult_label' => $this->t('No contacts.'),
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
'$contacts' => $contacts,
|
|
|
|
'$paginate' => $pager->renderFull($total),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|