Merge pull request #8975 from MrPetovan/task/8918-move-mod-common
Move mod/common.php to src/ Part 2: Add Module\Profile\Common class
This commit is contained in:
commit
1fb47b96aa
2
boot.php
2
boot.php
|
@ -266,7 +266,7 @@ function public_contact()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns contact id of authenticated site visitor or false
|
* Returns public contact id of authenticated site visitor or false
|
||||||
*
|
*
|
||||||
* @return int|bool visitor_id or false
|
* @return int|bool visitor_id or false
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -374,81 +374,59 @@ class Widget
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return common friends visitor widget
|
* Show a random selection of five common contacts between the visitor and the viewed profile user.
|
||||||
*
|
*
|
||||||
* @param string $profile_uid uid
|
* @param int $uid Viewed profile user ID
|
||||||
|
* @param string $nickname Viewed profile user nickname
|
||||||
* @return string|void
|
* @return string|void
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function commonFriendsVisitor($profile_uid)
|
public static function commonFriendsVisitor(int $uid, string $nickname)
|
||||||
{
|
{
|
||||||
if (local_user() == $profile_uid) {
|
if (local_user() == $uid) {
|
||||||
return;
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$zcid = 0;
|
$visitorPCid = local_user() ? Contact::getPublicIdByUserId(local_user()) : remote_user();
|
||||||
|
if (!$visitorPCid) {
|
||||||
$cid = Session::getRemoteContactID($profile_uid);
|
return '';
|
||||||
|
|
||||||
if (!$cid) {
|
|
||||||
if (Profile::getMyURL()) {
|
|
||||||
$contact = DBA::selectFirst('contact', ['id'],
|
|
||||||
['nurl' => Strings::normaliseLink(Profile::getMyURL()), 'uid' => $profile_uid]);
|
|
||||||
if (DBA::isResult($contact)) {
|
|
||||||
$cid = $contact['id'];
|
|
||||||
} else {
|
|
||||||
$gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Profile::getMyURL())]);
|
|
||||||
if (DBA::isResult($gcontact)) {
|
|
||||||
$zcid = $gcontact['id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cid == 0 && $zcid == 0) {
|
$localPCid = Contact::getPublicIdByUserId($uid);
|
||||||
return;
|
|
||||||
|
$condition = [
|
||||||
|
'NOT `self` AND NOT `blocked` AND NOT `hidden` AND `id` != ?',
|
||||||
|
$localPCid,
|
||||||
|
];
|
||||||
|
|
||||||
|
$total = Contact\Relation::countCommon($localPCid, $visitorPCid, $condition);
|
||||||
|
if (!$total) {
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cid) {
|
$commonContacts = Contact\Relation::listCommon($localPCid, $visitorPCid, $condition, 0, 5, true);
|
||||||
$t = GContact::countCommonFriends($profile_uid, $cid);
|
if (!DBA::isResult($commonContacts)) {
|
||||||
} else {
|
return '';
|
||||||
$t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$t) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($cid) {
|
|
||||||
$r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
|
|
||||||
} else {
|
|
||||||
$r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DBA::isResult($r)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = [];
|
$entries = [];
|
||||||
foreach ($r as $rr) {
|
foreach ($commonContacts as $contact) {
|
||||||
$contact = Contact::getByURL($rr['url']);
|
$entries[] = [
|
||||||
$entry = [
|
'url' => Contact::magicLink($contact['url']),
|
||||||
'url' => Contact::magicLink($rr['url']),
|
'name' => $contact['name'],
|
||||||
'name' => $contact['name'] ?? $rr['name'],
|
'photo' => Contact::getThumb($contact),
|
||||||
'photo' => Contact::getThumb($contact, $rr['photo']),
|
|
||||||
];
|
];
|
||||||
$entries[] = $entry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('widget/remote_friends_common.tpl');
|
$tpl = Renderer::getMarkupTemplate('widget/remote_friends_common.tpl');
|
||||||
return Renderer::replaceMacros($tpl, [
|
return Renderer::replaceMacros($tpl, [
|
||||||
'$desc' => DI::l10n()->tt("%d contact in common", "%d contacts in common", $t),
|
'$desc' => DI::l10n()->tt("%d contact in common", "%d contacts in common", $total),
|
||||||
'$base' => DI::baseUrl(),
|
'$base' => DI::baseUrl(),
|
||||||
'$uid' => $profile_uid,
|
'$nickname' => $nickname,
|
||||||
'$cid' => (($cid) ? $cid : '0'),
|
'$linkmore' => $total > 5 ? 'true' : '',
|
||||||
'$linkmore' => (($t > 5) ? 'true' : ''),
|
|
||||||
'$more' => DI::l10n()->t('show more'),
|
'$more' => DI::l10n()->t('show more'),
|
||||||
'$items' => $entries
|
'$contacts' => $entries
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,10 +65,10 @@ class Session
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns contact ID for given user ID
|
* Return the user contact ID of a visitor for the given user ID they are visiting
|
||||||
*
|
*
|
||||||
* @param integer $uid User ID
|
* @param integer $uid User ID
|
||||||
* @return integer Contact ID of visitor for given user ID
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public static function getRemoteContactID($uid)
|
public static function getRemoteContactID($uid)
|
||||||
{
|
{
|
||||||
|
|
|
@ -431,7 +431,7 @@ class Relation
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function listCommon(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||||
{
|
{
|
||||||
$condition = DBA::mergeConditions($condition,
|
$condition = DBA::mergeConditions($condition,
|
||||||
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
||||||
|
@ -439,7 +439,7 @@ class Relation
|
||||||
$sourceId, $targetId]
|
$sourceId, $targetId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return DI::dba()->selectToArray('contact', $fields, $condition,
|
return DI::dba()->selectToArray('contact', [], $condition,
|
||||||
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,6 @@ class Relation
|
||||||
*
|
*
|
||||||
* @param int $sourceId Public contact id
|
* @param int $sourceId Public contact id
|
||||||
* @param int $targetId Public contact id
|
* @param int $targetId Public contact id
|
||||||
* @param array $field Field list
|
|
||||||
* @param array $condition Additional condition array on the contact table
|
* @param array $condition Additional condition array on the contact table
|
||||||
* @param int $count
|
* @param int $count
|
||||||
* @param int $offset
|
* @param int $offset
|
||||||
|
@ -478,7 +477,7 @@ class Relation
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function listCommonFollows(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||||
{
|
{
|
||||||
$condition = DBA::mergeConditions($condition,
|
$condition = DBA::mergeConditions($condition,
|
||||||
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
|
||||||
|
@ -486,7 +485,7 @@ class Relation
|
||||||
$sourceId, $targetId]
|
$sourceId, $targetId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return DI::dba()->selectToArray('contact', $fields, $condition,
|
return DI::dba()->selectToArray('contact', [], $condition,
|
||||||
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -516,7 +515,6 @@ class Relation
|
||||||
*
|
*
|
||||||
* @param int $sourceId Public contact id
|
* @param int $sourceId Public contact id
|
||||||
* @param int $targetId Public contact id
|
* @param int $targetId Public contact id
|
||||||
* @param array $field Field list
|
|
||||||
* @param array $condition Additional condition on the contact table
|
* @param array $condition Additional condition on the contact table
|
||||||
* @param int $count
|
* @param int $count
|
||||||
* @param int $offset
|
* @param int $offset
|
||||||
|
@ -524,7 +522,7 @@ class Relation
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function listCommonFollowers(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
|
||||||
{
|
{
|
||||||
$condition = DBA::mergeConditions($condition,
|
$condition = DBA::mergeConditions($condition,
|
||||||
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
|
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
|
||||||
|
@ -532,7 +530,7 @@ class Relation
|
||||||
$sourceId, $targetId]
|
$sourceId, $targetId]
|
||||||
);
|
);
|
||||||
|
|
||||||
return DI::dba()->selectToArray('contact', $fields, $condition,
|
return DI::dba()->selectToArray('contact', [], $condition,
|
||||||
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ class GContact
|
||||||
$sourceId,
|
$sourceId,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition);
|
return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +74,7 @@ LIMIT 1",
|
||||||
$sourceId,
|
$sourceId,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, [], $condition);
|
return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +100,7 @@ LIMIT 1",
|
||||||
$sourceId,
|
$sourceId,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition, $limit, $start, $shuffle);
|
return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,6 +134,6 @@ LIMIT 1",
|
||||||
$sourceId,
|
$sourceId,
|
||||||
];
|
];
|
||||||
|
|
||||||
return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, [], $condition, $limit, $start, $shuffle);
|
return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, $condition, $limit, $start, $shuffle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1030,7 +1030,7 @@ class Contact extends BaseModule
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($contact['uid']) && !empty($contact['rel'])) {
|
if (!empty($contact['uid']) && !empty($contact['rel']) && local_user() == $contact['uid']) {
|
||||||
switch ($contact['rel']) {
|
switch ($contact['rel']) {
|
||||||
case Model\Contact::FRIEND:
|
case Model\Contact::FRIEND:
|
||||||
$alt_text = DI::l10n()->t('Mutual Friendship');
|
$alt_text = DI::l10n()->t('Mutual Friendship');
|
||||||
|
|
112
src/Module/Profile/Common.php
Normal file
112
src/Module/Profile/Common.php
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Friendica\Module\Profile;
|
||||||
|
|
||||||
|
use Friendica\Content\Nav;
|
||||||
|
use Friendica\Content\Pager;
|
||||||
|
use Friendica\Core\Protocol;
|
||||||
|
use Friendica\Core\Renderer;
|
||||||
|
use Friendica\Core\Session;
|
||||||
|
use Friendica\Module;
|
||||||
|
use Friendica\DI;
|
||||||
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\Profile;
|
||||||
|
use Friendica\Module\BaseProfile;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
|
class Common extends BaseProfile
|
||||||
|
{
|
||||||
|
public static function content(array $parameters = [])
|
||||||
|
{
|
||||||
|
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
|
||||||
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$a = DI::app();
|
||||||
|
|
||||||
|
Nav::setSelected('home');
|
||||||
|
|
||||||
|
$nickname = $parameters['nickname'];
|
||||||
|
|
||||||
|
Profile::load($a, $nickname);
|
||||||
|
|
||||||
|
if (empty($a->profile)) {
|
||||||
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$o = self::getTabsHTML($a, 'contacts', false, $nickname);
|
||||||
|
|
||||||
|
if (!empty($a->profile['hide-friends'])) {
|
||||||
|
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$displayCommonTab = Session::isAuthenticated() && $a->profile['uid'] != local_user();
|
||||||
|
|
||||||
|
if (!$displayCommonTab) {
|
||||||
|
$a->redirect('profile/' . $nickname . '/contacts');
|
||||||
|
};
|
||||||
|
|
||||||
|
$sourceId = Contact::getIdForURL(Profile::getMyURL());
|
||||||
|
$targetId = Contact::getPublicIdByUserId($a->profile['uid']);
|
||||||
|
|
||||||
|
$condition = [
|
||||||
|
'blocked' => false,
|
||||||
|
'deleted' => false,
|
||||||
|
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED],
|
||||||
|
];
|
||||||
|
|
||||||
|
$total = Contact\Relation::countCommon($sourceId, $targetId, $condition);
|
||||||
|
|
||||||
|
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
|
||||||
|
|
||||||
|
$commonFollows = Contact\Relation::listCommon($sourceId, $targetId, $condition, $pager->getItemsPerPage(), $pager->getStart());
|
||||||
|
|
||||||
|
$contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $commonFollows);
|
||||||
|
|
||||||
|
$title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
|
||||||
|
$desc = DI::l10n()->t(
|
||||||
|
'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
|
||||||
|
htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
|
||||||
|
);
|
||||||
|
|
||||||
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
||||||
|
$o .= Renderer::replaceMacros($tpl, [
|
||||||
|
'$title' => $title,
|
||||||
|
'$desc' => $desc,
|
||||||
|
'$nickname' => $nickname,
|
||||||
|
'$type' => 'common',
|
||||||
|
'$displayCommonTab' => $displayCommonTab,
|
||||||
|
|
||||||
|
'$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'),
|
||||||
|
'$common_label' => DI::l10n()->t('Common'),
|
||||||
|
'$noresult_label' => DI::l10n()->t('No common contacts.'),
|
||||||
|
|
||||||
|
'$contacts' => $contacts,
|
||||||
|
'$paginate' => $pager->renderFull($total),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,57 +28,53 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Profile;
|
use Friendica\Model;
|
||||||
use Friendica\Module\BaseProfile;
|
use Friendica\Module;
|
||||||
use Friendica\Module\Contact as ModuleContact;
|
use Friendica\Network\HTTPException;
|
||||||
|
|
||||||
class Contacts extends BaseProfile
|
class Contacts extends Module\BaseProfile
|
||||||
{
|
{
|
||||||
public static function content(array $parameters = [])
|
public static function content(array $parameters = [])
|
||||||
{
|
{
|
||||||
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
|
if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
|
||||||
throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$a = DI::app();
|
$a = DI::app();
|
||||||
|
|
||||||
//@TODO: Get value from router parameters
|
$nickname = $parameters['nickname'];
|
||||||
$nickname = $a->argv[1];
|
$type = $parameters['type'] ?? 'all';
|
||||||
$type = ($a->argv[3] ?? '') ?: 'all';
|
|
||||||
|
|
||||||
Nav::setSelected('home');
|
Model\Profile::load($a, $nickname);
|
||||||
|
|
||||||
$user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
|
if (empty($a->profile)) {
|
||||||
if (!DBA::isResult($user)) {
|
throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||||
throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$a->profile_uid = $user['uid'];
|
if (!empty($a->profile['hide-friends'])) {
|
||||||
|
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||||
|
}
|
||||||
|
|
||||||
Profile::load($a, $nickname);
|
Nav::setSelected('home');
|
||||||
|
|
||||||
$is_owner = $a->profile['uid'] == local_user();
|
$is_owner = $a->profile['uid'] == local_user();
|
||||||
|
|
||||||
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
|
$o = self::getTabsHTML($a, 'contacts', $is_owner, $nickname);
|
||||||
|
|
||||||
if (!count($a->profile) || $a->profile['hide-friends']) {
|
|
||||||
notice(DI::l10n()->t('Permission denied.'));
|
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
$condition = [
|
$condition = [
|
||||||
'uid' => $a->profile['uid'],
|
'uid' => $a->profile['uid'],
|
||||||
'blocked' => false,
|
'blocked' => false,
|
||||||
'pending' => false,
|
'pending' => false,
|
||||||
'hidden' => false,
|
'hidden' => false,
|
||||||
'archive' => false,
|
'archive' => false,
|
||||||
|
'self' => false,
|
||||||
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
|
'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED]
|
||||||
];
|
];
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'followers': $condition['rel'] = [1, 3]; break;
|
case 'followers': $condition['rel'] = [Model\Contact::FOLLOWER, Model\Contact::FRIEND]; break;
|
||||||
case 'following': $condition['rel'] = [2, 3]; break;
|
case 'following': $condition['rel'] = [Model\Contact::SHARING, Model\Contact::FRIEND]; break;
|
||||||
case 'mutuals': $condition['rel'] = 3; break;
|
case 'mutuals': $condition['rel'] = Model\Contact::FRIEND; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = DBA::count('contact', $condition);
|
$total = DBA::count('contact', $condition);
|
||||||
|
@ -87,42 +83,46 @@ class Contacts extends BaseProfile
|
||||||
|
|
||||||
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||||
|
|
||||||
$contacts_stmt = DBA::select('contact', [], $condition, $params);
|
$contacts = array_map(
|
||||||
|
[Module\Contact::class, 'getContactTemplateVars'],
|
||||||
if (!DBA::isResult($contacts_stmt)) {
|
Model\Contact::selectToArray([], $condition, $params)
|
||||||
notice(DI::l10n()->t('No contacts.'));
|
);
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
$contacts = [];
|
|
||||||
|
|
||||||
while ($contact = DBA::fetch($contacts_stmt)) {
|
|
||||||
if ($contact['self']) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$contacts[] = ModuleContact::getContactTemplateVars($contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
DBA::close($contacts_stmt);
|
|
||||||
|
|
||||||
|
$desc = '';
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'followers': $title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total); break;
|
case 'followers':
|
||||||
case 'following': $title = DI::l10n()->tt('Following (%s)', 'Following (%s)', $total); break;
|
$title = DI::l10n()->tt('Follower (%s)', 'Followers (%s)', $total);
|
||||||
case 'mutuals': $title = DI::l10n()->tt('Mutual friend (%s)', 'Mutual friends (%s)', $total); break;
|
break;
|
||||||
|
case 'following':
|
||||||
case 'all': default: $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total); break;
|
$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>.',
|
||||||
|
htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'all':
|
||||||
|
default:
|
||||||
|
$title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
$tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
|
||||||
$o .= Renderer::replaceMacros($tpl, [
|
$o .= Renderer::replaceMacros($tpl, [
|
||||||
'$title' => $title,
|
'$title' => $title,
|
||||||
|
'$desc' => $desc,
|
||||||
'$nickname' => $nickname,
|
'$nickname' => $nickname,
|
||||||
'$type' => $type,
|
'$type' => $type,
|
||||||
|
'$displayCommonTab' => Session::isAuthenticated() && $a->profile['uid'] != local_user(),
|
||||||
|
|
||||||
'$all_label' => DI::l10n()->t('All contacts'),
|
'$all_label' => DI::l10n()->t('All contacts'),
|
||||||
'$followers_label' => DI::l10n()->t('Followers'),
|
'$followers_label' => DI::l10n()->t('Followers'),
|
||||||
'$following_label' => DI::l10n()->t('Following'),
|
'$following_label' => DI::l10n()->t('Following'),
|
||||||
'$mutuals_label' => DI::l10n()->t('Mutual friends'),
|
'$mutuals_label' => DI::l10n()->t('Mutual friends'),
|
||||||
|
'$common_label' => DI::l10n()->t('Common'),
|
||||||
|
'$noresult_label' => DI::l10n()->t('No contacts.'),
|
||||||
|
|
||||||
'$contacts' => $contacts,
|
'$contacts' => $contacts,
|
||||||
'$paginate' => $pager->renderFull($total),
|
'$paginate' => $pager->renderFull($total),
|
||||||
|
|
|
@ -108,7 +108,7 @@ class Status extends BaseProfile
|
||||||
|
|
||||||
$o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
|
$o .= self::getTabsHTML($a, 'status', $is_owner, $a->profile['nickname']);
|
||||||
|
|
||||||
$o .= Widget::commonFriendsVisitor($a->profile['uid']);
|
$o .= Widget::commonFriendsVisitor($a->profile['uid'], $a->profile['nickname']);
|
||||||
|
|
||||||
$commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
$commpage = $a->profile['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
|
||||||
$commvisitor = $commpage && $remote_contact;
|
$commvisitor = $commpage && $remote_contact;
|
||||||
|
|
|
@ -252,6 +252,7 @@ return [
|
||||||
'/profile' => [
|
'/profile' => [
|
||||||
'/{nickname}' => [Module\Profile\Index::class, [R::GET]],
|
'/{nickname}' => [Module\Profile\Index::class, [R::GET]],
|
||||||
'/{nickname}/profile' => [Module\Profile\Profile::class, [R::GET]],
|
'/{nickname}/profile' => [Module\Profile\Profile::class, [R::GET]],
|
||||||
|
'/{nickname}/contacts/common' => [Module\Profile\Common::class, [R::GET]],
|
||||||
'/{nickname}/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]],
|
'/{nickname}/contacts[/{type}]' => [Module\Profile\Contacts::class, [R::GET]],
|
||||||
'/{nickname}/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]],
|
'/{nickname}/status[/{category}[/{date1}[/{date2}]]]' => [Module\Profile\Status::class, [R::GET]],
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
<div class="generic-page-wrapper">
|
<div class="generic-page-wrapper">
|
||||||
{{include file="section_title.tpl"}}
|
{{include file="section_title.tpl"}}
|
||||||
|
|
||||||
|
{{if $desc}}
|
||||||
|
<p>{{$desc nofilter}}</p>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<ul role="menubar" class="tabs">
|
<ul role="menubar" class="tabs">
|
||||||
<li role="menuitem"><a href="profile/{{$nickname}}/contacts" class="tab button{{if !$type || $type == 'all'}} active{{/if}}">{{$all_label}}</a></li>
|
<li role="menuitem"><a href="profile/{{$nickname}}/contacts" class="tab button{{if !$type || $type == 'all'}} active{{/if}}">{{$all_label}}</a></li>
|
||||||
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/followers" class="tab button{{if $type == 'followers'}} active{{/if}}">{{$followers_label}}</a></li>
|
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/followers" class="tab button{{if $type == 'followers'}} active{{/if}}">{{$followers_label}}</a></li>
|
||||||
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/following" class="tab button{{if $type == 'following'}} active{{/if}}">{{$following_label}}</a></li>
|
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/following" class="tab button{{if $type == 'following'}} active{{/if}}">{{$following_label}}</a></li>
|
||||||
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/mutuals" class="tab button{{if $type == 'mutuals'}} active{{/if}}">{{$mutuals_label}}</a></li>
|
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/mutuals" class="tab button{{if $type == 'mutuals'}} active{{/if}}">{{$mutuals_label}}</a></li>
|
||||||
|
{{if $displayCommonTab}}
|
||||||
|
<li role="menuitem"><a href="profile/{{$nickname}}/contacts/common" class="tab button{{if $type == 'common'}} active{{/if}}{{if !$common_count}} disabled{{/if}}">{{$common_label}}</a></li>
|
||||||
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
|
{{if $contacts}}
|
||||||
<div id="viewcontact_wrapper-{{$id}}">
|
<div id="viewcontact_wrapper-{{$id}}">
|
||||||
{{foreach $contacts as $contact}}
|
{{foreach $contacts as $contact}}
|
||||||
{{include file="contact_template.tpl"}}
|
{{include file="contact_template.tpl"}}
|
||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
</div>
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="alert alert-info" role="alert">{{$noresult_label}}</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
<div id="view-contact-end"></div>
|
<div id="view-contact-end"></div>
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
|
|
||||||
<div id="remote-friends-in-common" class="bigwidget">
|
<div id="remote-friends-in-common" class="bigwidget">
|
||||||
<div id="rfic-desc">{{$desc nofilter}} {{if $linkmore}}<a href="{{$base}}/common/rem/{{$uid}}/{{$cid}}">{{$more}}</a>{{/if}}</div>
|
<div id="rfic-desc">{{$desc nofilter}} {{if $linkmore}}<a href="profile/{{$nickname}}/contacts/common">{{$more}}</a>{{/if}}</div>
|
||||||
{{if $items}}
|
{{foreach $contacts as $contact}}
|
||||||
{{foreach $items as $item}}
|
|
||||||
<div class="profile-match-wrapper">
|
<div class="profile-match-wrapper">
|
||||||
<div class="profile-match-photo">
|
<div class="profile-match-photo">
|
||||||
<a href="{{$item.url}}">
|
<a href="{{$contact.url}}">
|
||||||
<img src="{{$item.photo}}" width="80" height="80" alt="{{$item.name}}" title="{{$item.name}}" />
|
<img src="{{$contact.photo}}" width="80" height="80" alt="{{$contact.name}}" title="{{$contact.name}}" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-match-break"></div>
|
<div class="profile-match-break"></div>
|
||||||
<div class="profile-match-name">
|
<div class="profile-match-name">
|
||||||
<a href="{{$item.url}}" title="{{$item.name}}">{{$item.name}}</a>
|
<a href="{{$contact.url}}" title="{{$contact.name}}">{{$contact.name}}</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-match-end"></div>
|
<div class="profile-match-end"></div>
|
||||||
</div>
|
</div>
|
||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
{{/if}}
|
|
||||||
<div id="rfic-end" class="clear"></div>
|
<div id="rfic-end" class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
<div class="contact-entry-photo mframe" id="contact-entry-photo-{{$contact.id}}">
|
<div class="contact-entry-photo mframe" id="contact-entry-photo-{{$contact.id}}">
|
||||||
|
|
||||||
<div class="contact-photo-image-wrapper hidden-xs">
|
<div class="contact-photo-image-wrapper hidden-xs">
|
||||||
<img class="contact-photo media-object xl" src="{{$contact.thumb}}" {{$contact.sparkle}} alt="{{$contact.name}}" />
|
<a href="{{$contact.url}}">
|
||||||
|
<img class="contact-photo media-object xl" src="{{$contact.thumb}}" {{$contact.sparkle}} alt="{{$contact.name}}" />
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{* For very small displays we use a dropdown menu for contact relating actions *}}
|
{{* For very small displays we use a dropdown menu for contact relating actions *}}
|
||||||
|
|
|
@ -1,18 +1,38 @@
|
||||||
<div class="generic-page-wrapper">
|
<div class="generic-page-wrapper">
|
||||||
{{include file="section_title.tpl"}}
|
{{include file="section_title.tpl"}}
|
||||||
|
|
||||||
<ul class="nav nav-tabs">
|
{{if $desc}}
|
||||||
<li role="presentation"{{if !$type || $type == 'all'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts">{{$all_label}}</a></li>
|
<p>{{$desc nofilter}}</p>
|
||||||
<li role="presentation"{{if $type == 'followers'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/followers">{{$followers_label}}</a></li>
|
{{/if}}
|
||||||
<li role="presentation"{{if $type == 'following'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/following">{{$following_label}}</a></li>
|
|
||||||
<li role="presentation"{{if $type == 'mutuals'}} class="active"{{/if}}><a href="profile/{{$nickname}}/contacts/mutuals">{{$mutuals_label}}</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<ul id="viewcontact_wrapper{{if $id}}-{{$id}}{{/if}}" class="viewcontact_wrapper media-list">
|
<ul class="nav nav-tabs">
|
||||||
{{foreach $contacts as $contact}}
|
<li role="presentation"{{if !$type || $type == 'all'}} class="active"{{/if}}>
|
||||||
<li>{{include file="contact_template.tpl"}}</li>
|
<a href="profile/{{$nickname}}/contacts">{{$all_label}}</a>
|
||||||
{{/foreach}}
|
</li>
|
||||||
|
<li role="presentation"{{if $type == 'followers'}} class="active"{{/if}}>
|
||||||
|
<a href="profile/{{$nickname}}/contacts/followers">{{$followers_label}}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation"{{if $type == 'following'}} class="active"{{/if}}>
|
||||||
|
<a href="profile/{{$nickname}}/contacts/following">{{$following_label}}</a>
|
||||||
|
</li>
|
||||||
|
<li role="presentation"{{if $type == 'mutuals'}} class="active"{{/if}}>
|
||||||
|
<a href="profile/{{$nickname}}/contacts/mutuals">{{$mutuals_label}}</a>
|
||||||
|
</li>
|
||||||
|
{{if $displayCommonTab}}
|
||||||
|
<li role="presentation"{{if $type == 'common'}} class="active"{{/if}}>
|
||||||
|
<a href="profile/{{$nickname}}/contacts/common" class="tab button">{{$common_label}}</a>
|
||||||
|
</li>
|
||||||
|
{{/if}}
|
||||||
</ul>
|
</ul>
|
||||||
|
{{if $contacts}}
|
||||||
|
<ul id="viewcontact_wrapper{{if $id}}-{{$id}}{{/if}}" class="viewcontact_wrapper media-list">
|
||||||
|
{{foreach $contacts as $contact}}
|
||||||
|
<li>{{include file="contact_template.tpl"}}</li>
|
||||||
|
{{/foreach}}
|
||||||
|
</ul>
|
||||||
|
{{else}}
|
||||||
|
<div class="alert alert-info" role="alert">{{$noresult_label}}</div>
|
||||||
|
{{/if}}
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
<div id="view-contact-end"></div>
|
<div id="view-contact-end"></div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue