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