2019-05-18 11:47:39 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2021-03-29 02:40:20 -04:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 09:45:36 -05: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;
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\Renderer;
|
2019-09-28 14:09:11 -04:00
|
|
|
use Friendica\Core\Session;
|
2019-05-18 11:47:39 -04:00
|
|
|
use Friendica\Database\DBA;
|
2019-12-15 16:34:11 -05:00
|
|
|
use Friendica\DI;
|
2020-08-04 23:02:43 -04:00
|
|
|
use Friendica\Model;
|
|
|
|
use Friendica\Module;
|
|
|
|
use Friendica\Network\HTTPException;
|
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
|
|
|
{
|
2021-11-14 17:13:47 -05:00
|
|
|
public function content(): string
|
2019-05-18 11:47:39 -04:00
|
|
|
{
|
2020-01-19 15:21:13 -05:00
|
|
|
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
|
2020-08-04 23:02:43 -04:00
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
2019-12-15 16:34:11 -05:00
|
|
|
$a = DI::app();
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2021-11-14 17:19:25 -05:00
|
|
|
$nickname = $this->parameters['nickname'];
|
|
|
|
$type = $this->parameters['type'] ?? 'all';
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$profile = Model\Profile::load($a, $nickname);
|
|
|
|
if (empty($profile)) {
|
2020-08-04 23:02:43 -04:00
|
|
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$is_owner = $profile['uid'] == local_user();
|
2020-08-09 09:09:38 -04:00
|
|
|
|
2021-08-23 14:07:32 -04:00
|
|
|
if ($profile['hide-friends'] && !$is_owner) {
|
2020-08-04 23:02:43 -04:00
|
|
|
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
|
|
|
}
|
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
|
|
|
|
2021-08-08 06:14:56 -04:00
|
|
|
$o = self::getTabsHTML($a, 'contacts', $is_owner, $profile['nickname'], $profile['hide-friends']);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2021-07-24 06:09:39 -04:00
|
|
|
$tabs = self::getContactFilterTabs('profile/' . $nickname, $type, Session::isAuthenticated() && $profile['uid'] != local_user());
|
2020-08-06 10:34:11 -04:00
|
|
|
|
2019-05-18 11:47:39 -04:00
|
|
|
$condition = [
|
2021-07-24 06:09:39 -04:00
|
|
|
'uid' => $profile['uid'],
|
2019-05-18 11:47:39 -04:00
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'archive' => false,
|
2020-10-07 16:06:15 -04: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) {
|
2020-08-04 23:02:43 -04: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
|
|
|
}
|
|
|
|
|
|
|
|
$total = DBA::count('contact', $condition);
|
|
|
|
|
2020-08-07 21:18:25 -04:00
|
|
|
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 30);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
|
|
|
|
2020-08-04 23:02:43 -04:00
|
|
|
$contacts = array_map(
|
|
|
|
[Module\Contact::class, 'getContactTemplateVars'],
|
|
|
|
Model\Contact::selectToArray([], $condition, $params)
|
|
|
|
);
|
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':
|
|
|
|
$title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
|
|
|
|
break;
|
|
|
|
case 'following':
|
|
|
|
$title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total);
|
|
|
|
break;
|
|
|
|
case 'mutuals':
|
|
|
|
$title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total);
|
|
|
|
$desc = DI::l10n()->t(
|
|
|
|
'These contacts both follow and are followed by <strong>%s</strong>.',
|
2021-07-24 06:09:39 -04:00
|
|
|
htmlentities($profile['name'], ENT_COMPAT, 'UTF-8')
|
2020-08-04 23:02:43 -04:00
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 'all':
|
|
|
|
default:
|
|
|
|
$title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
|
|
|
|
break;
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
|
|
|
'$title' => $title,
|
2020-08-04 23:02:43 -04:00
|
|
|
'$desc' => $desc,
|
2020-08-06 10:34:11 -04:00
|
|
|
'$tabs' => $tabs,
|
|
|
|
|
2020-08-04 23:02:43 -04:00
|
|
|
'$noresult_label' => DI::l10n()->t('No contacts.'),
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
'$contacts' => $contacts,
|
|
|
|
'$paginate' => $pager->renderFull($total),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|