mirror of
https://github.com/friendica/friendica
synced 2025-04-19 10:30:10 +00:00
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
14 changed files with 258 additions and 140 deletions
|
@ -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']) {
|
||||
case Model\Contact::FRIEND:
|
||||
$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\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Module\BaseProfile;
|
||||
use Friendica\Module\Contact as ModuleContact;
|
||||
use Friendica\Model;
|
||||
use Friendica\Module;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
class Contacts extends BaseProfile
|
||||
class Contacts extends Module\BaseProfile
|
||||
{
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
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();
|
||||
|
||||
//@TODO: Get value from router parameters
|
||||
$nickname = $a->argv[1];
|
||||
$type = ($a->argv[3] ?? '') ?: 'all';
|
||||
$nickname = $parameters['nickname'];
|
||||
$type = $parameters['type'] ?? 'all';
|
||||
|
||||
Nav::setSelected('home');
|
||||
Model\Profile::load($a, $nickname);
|
||||
|
||||
$user = DBA::selectFirst('user', [], ['nickname' => $nickname, 'blocked' => false]);
|
||||
if (!DBA::isResult($user)) {
|
||||
throw new \Friendica\Network\HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
|
||||
if (empty($a->profile)) {
|
||||
throw new 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();
|
||||
|
||||
$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 = [
|
||||
'uid' => $a->profile['uid'],
|
||||
'blocked' => false,
|
||||
'pending' => false,
|
||||
'hidden' => false,
|
||||
'archive' => false,
|
||||
'self' => 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;
|
||||
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;
|
||||
}
|
||||
|
||||
$total = DBA::count('contact', $condition);
|
||||
|
@ -87,42 +83,46 @@ class Contacts extends BaseProfile
|
|||
|
||||
$params = ['order' => ['name' => false], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||
|
||||
$contacts_stmt = DBA::select('contact', [], $condition, $params);
|
||||
|
||||
if (!DBA::isResult($contacts_stmt)) {
|
||||
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);
|
||||
$contacts = array_map(
|
||||
[Module\Contact::class, 'getContactTemplateVars'],
|
||||
Model\Contact::selectToArray([], $condition, $params)
|
||||
);
|
||||
|
||||
$desc = '';
|
||||
switch ($type) {
|
||||
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;
|
||||
|
||||
case 'all': default: $title = DI::l10n()->tt('Contact (%s)', 'Contacts (%s)', $total); break;
|
||||
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>.',
|
||||
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');
|
||||
$o .= Renderer::replaceMacros($tpl, [
|
||||
'$title' => $title,
|
||||
'$desc' => $desc,
|
||||
'$nickname' => $nickname,
|
||||
'$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'),
|
||||
'$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,
|
||||
'$paginate' => $pager->renderFull($total),
|
||||
|
|
|
@ -108,7 +108,7 @@ class Status extends BaseProfile
|
|||
|
||||
$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;
|
||||
$commvisitor = $commpage && $remote_contact;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue