2019-05-18 11:47:39 -04:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @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\ContactSelector;
|
|
|
|
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;
|
2019-05-18 11:47:39 -04:00
|
|
|
use Friendica\Model\Contact;
|
|
|
|
use Friendica\Model\Profile;
|
2020-01-26 09:49:11 -05:00
|
|
|
use Friendica\Module\BaseProfile;
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-01-26 09:49:11 -05:00
|
|
|
class Contacts extends BaseProfile
|
2019-05-18 11:47:39 -04:00
|
|
|
{
|
2019-11-05 16:48:54 -05:00
|
|
|
public static function content(array $parameters = [])
|
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-01-18 14:52:34 -05:00
|
|
|
throw new \Friendica\Network\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
|
|
|
|
|
|
|
//@TODO: Get value from router parameters
|
|
|
|
$nickname = $a->argv[1];
|
2019-10-15 09:20:32 -04:00
|
|
|
$type = ($a->argv[3] ?? '') ?: 'all';
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
Nav::setSelected('home');
|
|
|
|
|
|
|
|
$user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
|
|
|
|
if (!DBA::isResult($user)) {
|
2020-01-18 14:52:34 -05:00
|
|
|
throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
$a->profile_uid = $user['uid'];
|
|
|
|
|
|
|
|
Profile::load($a, $nickname);
|
|
|
|
|
2019-11-02 21:19:42 -04:00
|
|
|
$is_owner = $a->profile['uid'] == local_user();
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-01-26 09:49:11 -05:00
|
|
|
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
if (!count($a->profile) || $a->profile['hide-friends']) {
|
2020-07-23 02:25:01 -04:00
|
|
|
notice(DI::l10n()->t('Permission denied.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
$condition = [
|
|
|
|
'uid' => $a->profile['uid'],
|
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'hidden' => false,
|
|
|
|
'archive' => false,
|
|
|
|
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
|
|
|
|
];
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'followers': $condition['rel'] = [1, 3]; break;
|
|
|
|
case 'following': $condition['rel'] = [2, 3]; break;
|
|
|
|
case 'mutuals': $condition['rel'] = 3; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$total = DBA::count('contact', $condition);
|
|
|
|
|
2020-02-16 11:53:52 -05:00
|
|
|
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
|
|
|
|
|
|
|
$contacts_stmt = DBA::select('contact', [], $condition, $params);
|
|
|
|
|
|
|
|
if (!DBA::isResult($contacts_stmt)) {
|
2020-07-23 02:25:01 -04:00
|
|
|
notice(DI::l10n()->t('No contacts.'));
|
2019-05-18 11:47:39 -04:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
|
|
|
|
$contacts = [];
|
|
|
|
|
|
|
|
while ($contact = DBA::fetch($contacts_stmt)) {
|
|
|
|
if ($contact['self']) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-16 00:18:33 -04:00
|
|
|
$contact_details = Contact::getByURLForUser($contact['url'], $a->profile['uid']) ?: $contact;
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
$contacts[] = [
|
|
|
|
'id' => $contact['id'],
|
2020-01-18 14:52:34 -05:00
|
|
|
'img_hover' => DI::l10n()->t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
|
2019-05-18 11:47:39 -04:00
|
|
|
'photo_menu' => Contact::photoMenu($contact),
|
2020-07-28 08:58:19 -04:00
|
|
|
'thumb' => Contact::getThumb($contact_details),
|
2019-05-18 11:47:39 -04:00
|
|
|
'name' => substr($contact_details['name'], 0, 20),
|
|
|
|
'username' => $contact_details['name'],
|
|
|
|
'details' => $contact_details['location'],
|
|
|
|
'tags' => $contact_details['keywords'],
|
|
|
|
'about' => $contact_details['about'],
|
|
|
|
'account_type' => Contact::getAccountType($contact_details),
|
|
|
|
'url' => Contact::magicLink($contact['url']),
|
|
|
|
'sparkle' => '',
|
|
|
|
'itemurl' => $contact_details['addr'] ? : $contact['url'],
|
2019-12-27 12:24:29 -05:00
|
|
|
'network' => ContactSelector::networkToName($contact['network'], $contact['url'], $contact['protocol']),
|
2019-05-18 11:47:39 -04:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
DBA::close($contacts_stmt);
|
|
|
|
|
|
|
|
switch ($type) {
|
2020-01-18 14:53:01 -05: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); break;
|
2019-05-18 11:47:39 -04:00
|
|
|
|
2020-01-18 14:53:01 -05:00
|
|
|
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,
|
|
|
|
'$nickname' => $nickname,
|
|
|
|
'$type' => $type,
|
|
|
|
|
2020-01-18 14:52:34 -05:00
|
|
|
'$all_label' => DI::l10n()->t('All contacts'),
|
|
|
|
'$followers_label' => DI::l10n()->t('Followers'),
|
|
|
|
'$following_label' => DI::l10n()->t('Following'),
|
|
|
|
'$mutuals_label' => DI::l10n()->t('Mutual friends'),
|
2019-05-18 11:47:39 -04:00
|
|
|
|
|
|
|
'$contacts' => $contacts,
|
|
|
|
'$paginate' => $pager->renderFull($total),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|