2020-08-06 22:49:21 -04:00
|
|
|
<?php
|
2022-01-02 04:49:50 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
|
|
|
*
|
|
|
|
* @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/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
namespace Friendica\Module\Contact;
|
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
use Friendica\App;
|
2020-08-06 22:49:21 -04:00
|
|
|
use Friendica\BaseModule;
|
|
|
|
use Friendica\Content\Pager;
|
2020-10-09 15:08:50 -04:00
|
|
|
use Friendica\Content\Widget;
|
2022-12-17 00:38:02 -05:00
|
|
|
use Friendica\Core\L10n;
|
2020-08-06 22:49:21 -04:00
|
|
|
use Friendica\Core\Renderer;
|
2022-12-17 00:38:02 -05:00
|
|
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
2020-08-06 22:49:21 -04:00
|
|
|
use Friendica\Model;
|
2020-10-09 15:08:50 -04:00
|
|
|
use Friendica\Model\User;
|
2020-08-06 22:49:21 -04:00
|
|
|
use Friendica\Module;
|
2022-12-17 00:38:02 -05:00
|
|
|
use Friendica\Module\Response;
|
2020-08-06 22:49:21 -04:00
|
|
|
use Friendica\Network\HTTPException;
|
2022-12-17 00:38:02 -05:00
|
|
|
use Friendica\Util\Profiler;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
class Contacts extends BaseModule
|
|
|
|
{
|
2022-12-17 00:38:02 -05:00
|
|
|
/** @var IHandleUserSessions */
|
|
|
|
private $userSession;
|
|
|
|
/** @var App\Page */
|
|
|
|
private $page;
|
|
|
|
|
|
|
|
public function __construct(App\Page $page, IHandleUserSessions $userSession, 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->userSession = $userSession;
|
|
|
|
$this->page = $page;
|
|
|
|
}
|
|
|
|
|
2021-11-20 09:38:03 -05:00
|
|
|
protected function content(array $request = []): string
|
2020-08-06 22:49:21 -04:00
|
|
|
{
|
2022-12-17 00:38:02 -05:00
|
|
|
if (!$this->userSession->getLocalUserId()) {
|
2020-08-06 22:49:21 -04:00
|
|
|
throw new HTTPException\ForbiddenException();
|
|
|
|
}
|
|
|
|
|
2021-11-14 17:19:25 -05:00
|
|
|
$cid = $this->parameters['id'];
|
|
|
|
$type = $this->parameters['type'] ?? 'all';
|
2022-12-17 00:38:02 -05:00
|
|
|
$accounttype = $request['accounttype'] ?? '';
|
2020-10-09 15:08:50 -04:00
|
|
|
$accounttypeid = User::getAccountTypeByString($accounttype);
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
if (!$cid) {
|
2022-12-17 00:38:02 -05:00
|
|
|
throw new HTTPException\BadRequestException($this->t('Invalid contact.'));
|
2020-08-06 22:49:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$contact = Model\Contact::getById($cid, []);
|
|
|
|
if (empty($contact)) {
|
2022-12-17 00:38:02 -05:00
|
|
|
throw new HTTPException\NotFoundException($this->t('Contact not found.'));
|
2020-08-06 22:49:21 -04:00
|
|
|
}
|
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
$localContactId = Model\Contact::getPublicIdByUserId($this->userSession->getLocalUserId());
|
2020-08-06 22:49:21 -04:00
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
$this->page['aside'] = Widget\VCard::getHTML($contact);
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
$condition = [
|
|
|
|
'blocked' => false,
|
2022-12-17 00:38:02 -05:00
|
|
|
'self' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'failed' => false,
|
2020-08-06 22:49:21 -04:00
|
|
|
];
|
|
|
|
|
2020-10-09 15:08:50 -04:00
|
|
|
if (isset($accounttypeid)) {
|
|
|
|
$condition['contact-type'] = $accounttypeid;
|
|
|
|
}
|
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
$noresult_label = $this->t('No known contacts.');
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'followers':
|
|
|
|
$total = Model\Contact\Relation::countFollowers($cid, $condition);
|
|
|
|
break;
|
|
|
|
case 'following':
|
|
|
|
$total = Model\Contact\Relation::countFollows($cid, $condition);
|
|
|
|
break;
|
|
|
|
case 'mutuals':
|
|
|
|
$total = Model\Contact\Relation::countMutuals($cid, $condition);
|
|
|
|
break;
|
|
|
|
case 'common':
|
|
|
|
$total = Model\Contact\Relation::countCommon($localContactId, $cid, $condition);
|
2022-12-17 00:38:02 -05:00
|
|
|
$noresult_label = $this->t('No common contacts.');
|
2020-08-06 22:49:21 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$total = Model\Contact\Relation::countAll($cid, $condition);
|
|
|
|
}
|
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
$pager = new Pager($this->l10n, $this->args->getQueryString(), 30);
|
2020-08-06 22:49:21 -04:00
|
|
|
$desc = '';
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'followers':
|
|
|
|
$friends = Model\Contact\Relation::listFollowers($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
2022-12-17 00:38:02 -05:00
|
|
|
$title = $this->tt('Follower (%s)', 'Followers (%s)', $total);
|
2020-08-06 22:49:21 -04:00
|
|
|
break;
|
|
|
|
case 'following':
|
|
|
|
$friends = Model\Contact\Relation::listFollows($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
2022-12-17 00:38:02 -05:00
|
|
|
$title = $this->tt('Following (%s)', 'Following (%s)', $total);
|
2020-08-06 22:49:21 -04:00
|
|
|
break;
|
|
|
|
case 'mutuals':
|
|
|
|
$friends = Model\Contact\Relation::listMutuals($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
2022-12-17 00:38:02 -05:00
|
|
|
$title = $this->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
|
|
|
$desc = $this->t(
|
2020-08-06 22:49:21 -04:00
|
|
|
'These contacts both follow and are followed by <strong>%s</strong>.',
|
|
|
|
htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'common':
|
|
|
|
$friends = Model\Contact\Relation::listCommon($localContactId, $cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
2022-12-17 00:38:02 -05:00
|
|
|
$title = $this->tt('Common contact (%s)', 'Common contacts (%s)', $total);
|
|
|
|
$desc = $this->t(
|
2020-08-06 22:49:21 -04:00
|
|
|
'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
|
|
|
|
htmlentities($contact['name'], ENT_COMPAT, 'UTF-8')
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$friends = Model\Contact\Relation::listAll($cid, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
2022-12-17 00:38:02 -05:00
|
|
|
$title = $this->tt('Contact (%s)', 'Contacts (%s)', $total);
|
2020-08-06 22:49:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$o = Module\Contact::getTabsHTML($contact, Module\Contact::TAB_CONTACTS);
|
|
|
|
|
|
|
|
$tabs = self::getContactFilterTabs('contact/' . $cid, $type, true);
|
|
|
|
|
2022-12-17 00:39:06 -05:00
|
|
|
// Contact list is obtained from the visited contact, but the contact display is visitor dependent
|
|
|
|
$contacts = array_map(
|
|
|
|
function ($contact) {
|
|
|
|
$contact = Model\Contact::selectFirst(
|
|
|
|
[],
|
|
|
|
['uri-id' => $contact['uri-id'], 'uid' => [0, $this->userSession->getLocalUserId()]],
|
|
|
|
['order' => ['uid' => 'DESC']]
|
|
|
|
);
|
|
|
|
return Module\Contact::getContactTemplateVars($contact);
|
|
|
|
},
|
|
|
|
$friends
|
|
|
|
);
|
2020-08-06 22:49:21 -04:00
|
|
|
|
|
|
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
|
|
|
'$title' => $title,
|
|
|
|
'$desc' => $desc,
|
|
|
|
'$tabs' => $tabs,
|
|
|
|
|
|
|
|
'$noresult_label' => $noresult_label,
|
|
|
|
|
|
|
|
'$contacts' => $contacts,
|
|
|
|
'$paginate' => $pager->renderFull($total),
|
|
|
|
]);
|
|
|
|
|
2022-12-17 00:38:02 -05:00
|
|
|
$this->page['aside'] .= Widget::accountTypes($_SERVER['REQUEST_URI'], $accounttype);
|
2020-10-09 15:08:50 -04:00
|
|
|
|
2020-08-06 22:49:21 -04:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|