]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Introductions.php
Replace `$parameters` argument per method with `static::$parameters`
[friendica.git] / src / Module / Notifications / Introductions.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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\Notifications;
23
24 use Friendica\Content\ContactSelector;
25 use Friendica\Content\Nav;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\Renderer;
29 use Friendica\DI;
30 use Friendica\Model\User;
31 use Friendica\Module\BaseNotifications;
32 use Friendica\Navigation\Notifications\ValueObject\Introduction;
33
34 /**
35  * Prints notifications about introduction
36  */
37 class Introductions extends BaseNotifications
38 {
39         /**
40          * @inheritDoc
41          */
42         public static function getNotifications()
43         {
44                 $id  = (int)DI::args()->get(2, 0);
45                 $all = DI::args()->get(2) == 'all';
46
47                 $notifications = [
48                         'ident'         => 'introductions',
49                         'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
50                 ];
51
52                 return [
53                         'header'        => DI::l10n()->t('Notifications'),
54                         'notifications' => $notifications,
55                 ];
56         }
57
58         public static function content()
59         {
60                 Nav::setSelected('introductions');
61
62                 $all = DI::args()->get(2) == 'all';
63
64                 $notificationContent   = [];
65                 $notificationNoContent = '';
66
67                 $notificationResult = self::getNotifications();
68                 $notifications      = $notificationResult['notifications'] ?? [];
69                 $notificationHeader = $notificationResult['header'] ?? '';
70
71                 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
72                 $notificationTemplate    = Renderer::getMarkupTemplate('notifications/intros.tpl');
73
74                 // The link to switch between ignored and normal connection requests
75                 $notificationShowLink = [
76                         'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
77                         'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')),
78                 ];
79
80                 $owner = User::getOwnerDataById(local_user());
81         
82                 // Loop through all introduction notifications.This creates an array with the output html for each
83                 // introduction
84                 /** @var Introduction $Introduction */
85                 foreach ($notifications['notifications'] as $Introduction) {
86
87                         // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
88                         // We have to distinguish between these two because they use different data.
89                         switch ($Introduction->getLabel()) {
90                                 case 'friend_suggestion':
91                                         $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
92                                                 '$type'                  => $Introduction->getLabel(),
93                                                 '$str_notification_type' => DI::l10n()->t('Notification type:'),
94                                                 '$str_type'              => $Introduction->getType(),
95                                                 '$intro_id'              => $Introduction->getIntroId(),
96                                                 '$lbl_madeby'            => DI::l10n()->t('Suggested by:'),
97                                                 '$madeby'                => $Introduction->getMadeBy(),
98                                                 '$madeby_url'            => $Introduction->getMadeByUrl(),
99                                                 '$madeby_zrl'            => $Introduction->getMadeByZrl(),
100                                                 '$madeby_addr'           => $Introduction->getMadeByAddr(),
101                                                 '$contact_id'            => $Introduction->getContactId(),
102                                                 '$photo'                 => $Introduction->getPhoto(),
103                                                 '$fullname'              => $Introduction->getName(),
104                                                 '$dfrn_url'              => $owner['url'],
105                                                 '$url'                   => $Introduction->getUrl(),
106                                                 '$zrl'                   => $Introduction->getZrl(),
107                                                 '$lbl_url'               => DI::l10n()->t('Profile URL'),
108                                                 '$addr'                  => $Introduction->getAddr(),
109                                                 '$action'                => 'follow',
110                                                 '$approve'               => DI::l10n()->t('Approve'),
111                                                 '$note'                  => $Introduction->getNote(),
112                                                 '$ignore'                => DI::l10n()->t('Ignore'),
113                                                 '$discard'               => DI::l10n()->t('Discard'),
114                                                 '$is_mobile'             => DI::mode()->isMobile(),
115                                         ]);
116                                         break;
117
118                                 // Normal connection requests
119                                 default:
120                                         if ($Introduction->getNetwork() === Protocol::DFRN) {
121                                                 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
122                                                 $knowyou     = ($Introduction->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
123                                         } else {
124                                                 $lbl_knowyou = '';
125                                                 $knowyou = '';
126                                         }
127
128                                         $convertedName = BBCode::convert($Introduction->getName());
129
130                                         $helptext  = DI::l10n()->t('Shall your connection be bidirectional or not?');
131                                         $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName);
132                                         $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName);
133                 
134                                         $friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true];
135                                         $follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false];
136
137                                         $action = 'follow_confirm';
138
139                                         $header = $Introduction->getName();
140
141                                         if ($Introduction->getAddr() != '') {
142                                                 $header .= ' <' . $Introduction->getAddr() . '>';
143                                         }
144
145                                         $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
146
147                                         if ($Introduction->getNetwork() != Protocol::DIASPORA) {
148                                                 $discard = DI::l10n()->t('Discard');
149                                         } else {
150                                                 $discard = '';
151                                         }
152
153                                         $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
154                                                 '$type'                  => $Introduction->getLabel(),
155                                                 '$header'                => $header,
156                                                 '$str_notification_type' => DI::l10n()->t('Notification type:'),
157                                                 '$str_type'              => $Introduction->getType(),
158                                                 '$dfrn_id'               => $Introduction->getDfrnId(),
159                                                 '$uid'                   => $Introduction->getUid(),
160                                                 '$intro_id'              => $Introduction->getIntroId(),
161                                                 '$contact_id'            => $Introduction->getContactId(),
162                                                 '$photo'                 => $Introduction->getPhoto(),
163                                                 '$fullname'              => $Introduction->getName(),
164                                                 '$location'              => $Introduction->getLocation(),
165                                                 '$lbl_location'          => DI::l10n()->t('Location:'),
166                                                 '$about'                 => $Introduction->getAbout(),
167                                                 '$lbl_about'             => DI::l10n()->t('About:'),
168                                                 '$keywords'              => $Introduction->getKeywords(),
169                                                 '$lbl_keywords'          => DI::l10n()->t('Tags:'),
170                                                 '$hidden'                => ['hidden', DI::l10n()->t('Hide this contact from others'), $Introduction->isHidden(), ''],
171                                                 '$lbl_connection_type'   => $helptext,
172                                                 '$friend'                => $friend,
173                                                 '$follower'              => $follower,
174                                                 '$url'                   => $Introduction->getUrl(),
175                                                 '$zrl'                   => $Introduction->getZrl(),
176                                                 '$lbl_url'               => DI::l10n()->t('Profile URL'),
177                                                 '$addr'                  => $Introduction->getAddr(),
178                                                 '$lbl_knowyou'           => $lbl_knowyou,
179                                                 '$lbl_network'           => DI::l10n()->t('Network:'),
180                                                 '$network'               => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
181                                                 '$knowyou'               => $knowyou,
182                                                 '$approve'               => DI::l10n()->t('Approve'),
183                                                 '$note'                  => $Introduction->getNote(),
184                                                 '$ignore'                => DI::l10n()->t('Ignore'),
185                                                 '$discard'               => $discard,
186                                                 '$action'                => $action,
187                                                 '$is_mobile'              => DI::mode()->isMobile(),
188                                         ]);
189                                         break;
190                         }
191                 }
192
193                 if (count($notifications['notifications']) == 0) {
194                         notice(DI::l10n()->t('No introductions.'));
195                         $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
196                 }
197
198                 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
199         }
200 }