]> git.mxchange.org Git - friendica.git/blob - src/Module/Profile/Common.php
Merge pull request #8980 from annando/fcontact-model
[friendica.git] / src / Module / Profile / Common.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Profile;
23
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session;
29 use Friendica\Module;
30 use Friendica\DI;
31 use Friendica\Model\Contact;
32 use Friendica\Model\Profile;
33 use Friendica\Module\BaseProfile;
34 use Friendica\Network\HTTPException;
35
36 class Common extends BaseProfile
37 {
38         public static function content(array $parameters = [])
39         {
40                 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
41                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
42                 }
43
44                 $a = DI::app();
45
46                 Nav::setSelected('home');
47
48                 $nickname = $parameters['nickname'];
49
50                 Profile::load($a, $nickname);
51
52                 if (empty($a->profile)) {
53                         throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
54                 }
55
56                 $o = self::getTabsHTML($a, 'contacts', false, $nickname);
57
58                 if (!empty($a->profile['hide-friends'])) {
59                         throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
60                 }
61
62                 $displayCommonTab = Session::isAuthenticated() && $a->profile['uid'] != local_user();
63
64                 if (!$displayCommonTab) {
65                         $a->redirect('profile/' . $nickname . '/contacts');
66                 };
67
68                 $sourceId = Contact::getIdForURL(Profile::getMyURL());
69                 $targetId = Contact::getPublicIdByUserId($a->profile['uid']);
70
71                 $condition = [
72                         'blocked' => false,
73                         'deleted' => false,
74                         'network' => [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED],
75                 ];
76
77                 $total = Contact\Relation::countCommon($sourceId, $targetId, $condition);
78
79                 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
80
81                 $commonFollows = Contact\Relation::listCommon($sourceId, $targetId, $condition, $pager->getItemsPerPage(), $pager->getStart());
82
83                 $contacts = array_map([Module\Contact::class, 'getContactTemplateVars'], $commonFollows);
84
85                 $title = DI::l10n()->tt('Common contact (%s)', 'Common contacts (%s)', $total);
86                 $desc = DI::l10n()->t(
87                         'Both <strong>%s</strong> and yourself have publicly interacted with these contacts (follow, comment or likes on public posts).',
88                         htmlentities($a->profile['name'], ENT_COMPAT, 'UTF-8')
89                 );
90
91                 $tpl = Renderer::getMarkupTemplate('profile/contacts.tpl');
92                 $o .= Renderer::replaceMacros($tpl, [
93                         '$title'    => $title,
94                         '$desc'     => $desc,
95                         '$nickname' => $nickname,
96                         '$type'     => 'common',
97                         '$displayCommonTab' => $displayCommonTab,
98
99                         '$all_label'       => DI::l10n()->t('All contacts'),
100                         '$followers_label' => DI::l10n()->t('Followers'),
101                         '$following_label' => DI::l10n()->t('Following'),
102                         '$mutuals_label'   => DI::l10n()->t('Mutual friends'),
103                         '$common_label'    => DI::l10n()->t('Common'),
104                         '$noresult_label'  => DI::l10n()->t('No common contacts.'),
105
106                         '$contacts' => $contacts,
107                         '$paginate' => $pager->renderFull($total),
108                 ]);
109
110                 return $o;
111         }
112 }