]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Introductions.php
99066bd3c90d515079d62d52ab6e304039c40eaf
[friendica.git] / src / Module / Notifications / Introductions.php
1 <?php
2
3 namespace Friendica\Module\Notifications;
4
5 use Friendica\Content\ContactSelector;
6 use Friendica\Content\Nav;
7 use Friendica\Core\Protocol;
8 use Friendica\Core\Renderer;
9 use Friendica\Database\DBA;
10 use Friendica\DI;
11 use Friendica\Module\BaseNotifications;
12
13 /**
14  * Prints notifications about introduction
15  */
16 class Introductions extends BaseNotifications
17 {
18         /**
19          * @inheritDoc
20          */
21         public static function getNotifications()
22         {
23                 $id  = (int)DI::args()->get(2, 0);
24                 $all = DI::args()->get(2) == 'all';
25
26                 $notifications = DI::notification()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id);
27
28                 return [
29                         'header'        => DI::l10n()->t('Notifications'),
30                         'notifications' => $notifications,
31                 ];
32         }
33
34         public static function content(array $parameters = [])
35         {
36                 Nav::setSelected('introductions');
37
38                 $all = DI::args()->get(2) == 'all';
39
40                 $notificationContent   = [];
41                 $notificationNoContent = '';
42
43                 $notificationResult = self::getNotifications();
44                 $notifications      = $notificationResult['notifications'] ?? [];
45                 $notificationHeader = $notificationResult['header'] ?? '';
46
47                 $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
48                 $notificationTemplate    = Renderer::getMarkupTemplate('notifications/intros.tpl');
49
50                 // The link to switch between ignored and normal connection requests
51                 $notificationShowLink = [
52                         'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
53                         'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests'))
54                 ];
55
56                 // Loop through all introduction notifications.This creates an array with the output html for each
57                 // introduction
58                 foreach ($notifications['notifications'] as $notification) {
59
60                         // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
61                         // We have to distinguish between these two because they use different data.
62                         switch ($notification['label']) {
63                                 case 'friend_suggestion':
64                                         $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
65                                                 '$type'                 => $notification['label'],
66                                                 'str_notification_type' => DI::l10n()->t('Notification type:'),
67                                                 'str_type'              => $notification['str_type'],
68                                                 '$intro_id'             => $notification['intro_id'],
69                                                 '$lbl_madeby'           => DI::l10n()->t('Suggested by:'),
70                                                 '$madeby'               => $notification['madeby'],
71                                                 '$madeby_url'           => $notification['madeby_url'],
72                                                 '$madeby_zrl'           => $notification['madeby_zrl'],
73                                                 '$madeby_addr'          => $notification['madeby_addr'],
74                                                 '$contact_id'           => $notification['contact_id'],
75                                                 '$photo'                => $notification['photo'],
76                                                 '$fullname'             => $notification['name'],
77                                                 '$url'                  => $notification['url'],
78                                                 '$zrl'                  => $notification['zrl'],
79                                                 '$lbl_url'              => DI::l10n()->t('Profile URL'),
80                                                 '$addr'                 => $notification['addr'],
81                                                 '$hidden'               => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
82                                                 '$knowyou'              => $notification['knowyou'],
83                                                 '$approve'              => DI::l10n()->t('Approve'),
84                                                 '$note'                 => $notification['note'],
85                                                 '$request'              => $notification['request'],
86                                                 '$ignore'               => DI::l10n()->t('Ignore'),
87                                                 '$discard'              => DI::l10n()->t('Discard'),
88                                         ]);
89                                         break;
90
91                                 // Normal connection requests
92                                 default:
93                                         $friend_selected = (($notification['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
94                                         $fan_selected    = (($notification['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
95
96                                         $lbl_knowyou = '';
97                                         $knowyou     = '';
98                                         $helptext    = '';
99                                         $helptext2   = '';
100                                         $helptext3   = '';
101
102                                         if ($notification['network'] === Protocol::DFRN) {
103                                                 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
104                                                 $knowyou     = (($notification['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
105                                                 $helptext    = DI::l10n()->t('Shall your connection be bidirectional or not?');
106                                                 $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.', $notification['name'], $notification['name']);
107                                                 $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.', $notification['name']);
108                                         } elseif ($notification['network'] === Protocol::DIASPORA) {
109                                                 $helptext  = DI::l10n()->t('Shall your connection be bidirectional or not?');
110                                                 $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.', $notification['name'], $notification['name']);
111                                                 $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
112                                         }
113
114                                         $dfrn_tpl  = Renderer::getMarkupTemplate('notifications/netfriend.tpl');
115                                         $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
116                                                 '$intro_id'        => $notification['intro_id'],
117                                                 '$friend_selected' => $friend_selected,
118                                                 '$fan_selected'    => $fan_selected,
119                                                 '$approve_as1'     => $helptext,
120                                                 '$approve_as2'     => $helptext2,
121                                                 '$approve_as3'     => $helptext3,
122                                                 '$as_friend'       => DI::l10n()->t('Friend'),
123                                                 '$as_fan'          => (($notification['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
124                                         ]);
125
126                                         $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification['contact_id']]);
127
128                                         if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
129                                                 $action = 'follow_confirm';
130                                         } else {
131                                                 $action = 'dfrn_confirm';
132                                         }
133
134                                         $header = $notification['name'];
135
136                                         if ($notification['addr'] != '') {
137                                                 $header .= ' <' . $notification['addr'] . '>';
138                                         }
139
140                                         $header .= ' (' . ContactSelector::networkToName($notification['network'], $notification['url']) . ')';
141
142                                         if ($notification['network'] != Protocol::DIASPORA) {
143                                                 $discard = DI::l10n()->t('Discard');
144                                         } else {
145                                                 $discard = '';
146                                         }
147
148                                         $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
149                                                 '$type'                 => $notification['label'],
150                                                 '$header'               => $header,
151                                                 'str_notification_type' => DI::l10n()->t('Notification type:'),
152                                                 'str_type'              => $notification['notifytype'],
153                                                 '$dfrn_text'            => $dfrn_text,
154                                                 '$dfrn_id'              => $notification['dfrn_id'],
155                                                 '$uid'                  => $notification['uid'],
156                                                 '$intro_id'             => $notification['intro_id'],
157                                                 '$contact_id'           => $notification['contact_id'],
158                                                 '$photo'                => $notification['photo'],
159                                                 '$fullname'             => $notification['name'],
160                                                 '$location'             => $notification['location'],
161                                                 '$lbl_location'         => DI::l10n()->t('Location:'),
162                                                 '$about'                => $notification['about'],
163                                                 '$lbl_about'            => DI::l10n()->t('About:'),
164                                                 '$keywords'             => $notification['keywords'],
165                                                 '$lbl_keywords'         => DI::l10n()->t('Tags:'),
166                                                 '$gender'               => $notification['gender'],
167                                                 '$lbl_gender'           => DI::l10n()->t('Gender:'),
168                                                 '$hidden'               => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
169                                                 '$url'                  => $notification['url'],
170                                                 '$zrl'                  => $notification['zrl'],
171                                                 '$lbl_url'              => DI::l10n()->t('Profile URL'),
172                                                 '$addr'                 => $notification['addr'],
173                                                 '$lbl_knowyou'          => $lbl_knowyou,
174                                                 '$lbl_network'          => DI::l10n()->t('Network:'),
175                                                 '$network'              => ContactSelector::networkToName($notification['network'], $notification['url']),
176                                                 '$knowyou'              => $knowyou,
177                                                 '$approve'              => DI::l10n()->t('Approve'),
178                                                 '$note'                 => $notification['note'],
179                                                 '$ignore'               => DI::l10n()->t('Ignore'),
180                                                 '$discard'              => $discard,
181                                                 '$action'               => $action,
182                                         ]);
183                                         break;
184                         }
185                 }
186
187                 if (count($notifications['notifications']) == 0) {
188                         info(DI::l10n()->t('No introductions.') . EOL);
189                         $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
190                 }
191
192                 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
193         }
194 }