friendica_2021.01_tupambae_.../mod/viewcontacts.php

121 lines
3.5 KiB
PHP
Raw Normal View History

2010-07-29 03:24:07 +02:00
<?php
/**
* @file mod/viewcontacts.php
*/
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Core\Config;
2018-01-21 19:33:59 +01:00
use Friendica\Core\L10n;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
2017-12-07 15:04:24 +01:00
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Util\Proxy as ProxyUtils;
2018-01-22 15:16:25 +01:00
function viewcontacts_init(App $a)
{
if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
}
2010-07-29 03:24:07 +02:00
if ($a->argc < 2) {
throw new \Friendica\Network\HTTPException\ForbiddenException(L10n::t('Access denied.'));
}
Nav::setSelected('home');
2018-12-25 17:36:41 +01:00
$user = DBA::selectFirst('user', [], ['nickname' => $a->argv[1], 'blocked' => false]);
if (!DBA::isResult($user)) {
throw new \Friendica\Network\HTTPException\NotFoundException();
}
2018-12-25 17:36:41 +01:00
$a->data['user'] = $user;
$a->profile_uid = $user['uid'];
Profile::load($a, $a->argv[1]);
2010-07-29 03:24:07 +02:00
}
2018-01-22 15:16:25 +01:00
function viewcontacts_content(App $a)
{
if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
2018-01-21 19:33:59 +01:00
notice(L10n::t('Public access denied.') . EOL);
return;
}
2018-02-12 04:10:11 +01:00
$is_owner = $a->profile['profile_uid'] == local_user();
// tabs
2018-12-25 17:36:41 +01:00
$o = Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
2010-07-29 03:24:07 +02:00
if (!count($a->profile) || $a->profile['hide-friends']) {
2018-01-21 19:33:59 +01:00
notice(L10n::t('Permission denied.') . EOL);
return $o;
}
2018-12-25 17:36:41 +01:00
$condition = [
'uid' => $a->profile['uid'],
'blocked' => false,
'pending' => false,
'hidden' => false,
'archive' => false,
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]
];
2019-01-27 20:54:08 +01:00
$total = DBA::count('contact', $condition);
2018-12-25 17:36:41 +01:00
$pager = new Pager($a->query_string);
2010-07-29 03:24:07 +02:00
2018-12-25 17:36:41 +01:00
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$contacts_stmt = DBA::select('contact', [], $condition, $params);
if (!DBA::isResult($contacts_stmt)) {
info(L10n::t('No contacts.') . EOL);
2010-07-29 03:24:07 +02:00
return $o;
}
$contacts = [];
2010-07-29 03:24:07 +02:00
2018-12-25 17:36:41 +01:00
while ($contact = DBA::fetch($contacts_stmt)) {
/// @TODO This triggers an E_NOTICE if 'self' is not there
2018-12-25 17:36:41 +01:00
if ($contact['self']) {
2010-07-29 03:24:07 +02:00
continue;
}
2010-07-29 03:24:07 +02:00
2018-12-25 17:36:41 +01:00
$contact_details = Contact::getDetailsByURL($contact['url'], $a->profile['uid'], $contact);
$contacts[] = [
2018-12-25 17:36:41 +01:00
'id' => $contact['id'],
'img_hover' => L10n::t('Visit %s\'s profile [%s]', $contact_details['name'], $contact['url']),
'photo_menu' => Contact::photoMenu($contact),
'thumb' => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
'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_details['addr'] : $contact['url']),
'network' => ContactSelector::networkToName($contact['network'], $contact['url']),
];
2010-07-29 03:24:07 +02:00
}
2018-12-25 17:36:41 +01:00
DBA::close($contacts_stmt);
2010-07-29 03:24:07 +02:00
$tpl = Renderer::getMarkupTemplate("viewcontact_template.tpl");
$o .= Renderer::replaceMacros($tpl, [
2018-12-25 17:36:41 +01:00
'$title' => L10n::t('Contacts'),
'$contacts' => $contacts,
'$paginate' => $pager->renderFull($total),
]);
2010-07-29 03:24:07 +02:00
return $o;
}