]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Introductions.php
Add phpdoc
[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 getNotifies()
22         {
23                 $id  = (int)DI::args()->get(2, 0);
24                 $all = DI::args()->get(2) == 'all';
25
26                 $notifs = DI::notify()->getIntroList($all, self::$start, self::PER_PAGE, $id);
27
28                 return [
29                         'header' => DI::l10n()->t('Notifications'),
30                         'notifs' => $notifs,
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                 $notif_content   = [];
41                 $notif_nocontent = '';
42
43                 $notif_result = self::getNotifies();
44                 $notifs       = $notif_result['notifs'] ?? [];
45                 $notif_header = $notif_result['header'] ?? '';
46
47                 $sugg = Renderer::getMarkupTemplate('suggestions.tpl');
48                 $tpl  = Renderer::getMarkupTemplate('intros.tpl');
49
50                 // The link to switch between ignored and normal connection requests
51                 $notif_show_lnk = [
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 ($notifs['notifications'] as $notif) {
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 ($notif['label']) {
63                                 case 'friend_suggestion':
64                                         $notif_content[] = Renderer::replaceMacros($sugg, [
65                                                 '$type'           => $notif['label'],
66                                                 '$str_notifytype' => DI::l10n()->t('Notification type:'),
67                                                 '$notify_type'    => $notif['notify_type'],
68                                                 '$intro_id'       => $notif['intro_id'],
69                                                 '$lbl_madeby'     => DI::l10n()->t('Suggested by:'),
70                                                 '$madeby'         => $notif['madeby'],
71                                                 '$madeby_url'     => $notif['madeby_url'],
72                                                 '$madeby_zrl'     => $notif['madeby_zrl'],
73                                                 '$madeby_addr'    => $notif['madeby_addr'],
74                                                 '$contact_id'     => $notif['contact_id'],
75                                                 '$photo'          => $notif['photo'],
76                                                 '$fullname'       => $notif['name'],
77                                                 '$url'            => $notif['url'],
78                                                 '$zrl'            => $notif['zrl'],
79                                                 '$lbl_url'        => DI::l10n()->t('Profile URL'),
80                                                 '$addr'           => $notif['addr'],
81                                                 '$hidden'         => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
82                                                 '$knowyou'        => $notif['knowyou'],
83                                                 '$approve'        => DI::l10n()->t('Approve'),
84                                                 '$note'           => $notif['note'],
85                                                 '$request'        => $notif['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 = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
94                                         $fan_selected    = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
95
96                                         $lbl_knowyou = '';
97                                         $knowyou     = '';
98                                         $helptext    = '';
99                                         $helptext2   = '';
100                                         $helptext3   = '';
101
102                                         if ($notif['network'] === Protocol::DFRN) {
103                                                 $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
104                                                 $knowyou     = (($notif['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.', $notif['name'], $notif['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.', $notif['name']);
108                                         } elseif ($notif['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.', $notif['name'], $notif['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.', $notif['name']);
112                                         }
113
114                                         $dfrn_tpl  = Renderer::getMarkupTemplate('netfriend.tpl');
115                                         $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
116                                                 '$intro_id'        => $notif['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'          => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
124                                         ]);
125
126                                         $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['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 = $notif['name'];
135
136                                         if ($notif['addr'] != '') {
137                                                 $header .= ' <' . $notif['addr'] . '>';
138                                         }
139
140                                         $header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')';
141
142                                         if ($notif['network'] != Protocol::DIASPORA) {
143                                                 $discard = DI::l10n()->t('Discard');
144                                         } else {
145                                                 $discard = '';
146                                         }
147
148                                         $notif_content[] = Renderer::replaceMacros($tpl, [
149                                                 '$type'           => $notif['label'],
150                                                 '$header'         => $header,
151                                                 '$str_notifytype' => DI::l10n()->t('Notification type:'),
152                                                 '$notify_type'    => $notif['notify_type'],
153                                                 '$dfrn_text'      => $dfrn_text,
154                                                 '$dfrn_id'        => $notif['dfrn_id'],
155                                                 '$uid'            => $notif['uid'],
156                                                 '$intro_id'       => $notif['intro_id'],
157                                                 '$contact_id'     => $notif['contact_id'],
158                                                 '$photo'          => $notif['photo'],
159                                                 '$fullname'       => $notif['name'],
160                                                 '$location'       => $notif['location'],
161                                                 '$lbl_location'   => DI::l10n()->t('Location:'),
162                                                 '$about'          => $notif['about'],
163                                                 '$lbl_about'      => DI::l10n()->t('About:'),
164                                                 '$keywords'       => $notif['keywords'],
165                                                 '$lbl_keywords'   => DI::l10n()->t('Tags:'),
166                                                 '$gender'         => $notif['gender'],
167                                                 '$lbl_gender'     => DI::l10n()->t('Gender:'),
168                                                 '$hidden'         => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''],
169                                                 '$url'            => $notif['url'],
170                                                 '$zrl'            => $notif['zrl'],
171                                                 '$lbl_url'        => DI::l10n()->t('Profile URL'),
172                                                 '$addr'           => $notif['addr'],
173                                                 '$lbl_knowyou'    => $lbl_knowyou,
174                                                 '$lbl_network'    => DI::l10n()->t('Network:'),
175                                                 '$network'        => ContactSelector::networkToName($notif['network'], $notif['url']),
176                                                 '$knowyou'        => $knowyou,
177                                                 '$approve'        => DI::l10n()->t('Approve'),
178                                                 '$note'           => $notif['note'],
179                                                 '$ignore'         => DI::l10n()->t('Ignore'),
180                                                 '$discard'        => $discard,
181                                                 '$action'         => $action,
182                                         ]);
183                                         break;
184                         }
185                 }
186
187                 if (count($notifs['notifications']) == 0) {
188                         info(DI::l10n()->t('No introductions.') . EOL);
189                         $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']);
190                 }
191
192                 return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk);
193         }
194 }