]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notifications.php
50995645c38537f05dd99451122574ceee5e8e04
[friendica.git] / src / Module / Notifications / Notifications.php
1 <?php
2
3 namespace Friendica\Module\Notifications;
4
5 use Friendica\Content\Nav;
6 use Friendica\Content\Pager;
7 use Friendica\Core\Renderer;
8 use Friendica\DI;
9 use Friendica\Module\BaseNotifications;
10
11 /**
12  * Prints all notification types except introduction:
13  * - Network
14  * - System
15  * - Personal
16  * - Home
17  */
18 class Notifications extends BaseNotifications
19 {
20         /**
21          * {@inheritDoc}
22          */
23         public static function getNotifies()
24         {
25                 $nm = DI::notify();
26
27                 $notif_header = '';
28
29                 // Get the network notifications
30                 if ((DI::args()->get(1) == 'network')) {
31                         $notif_header = DI::l10n()->t('Network Notifications');
32                         $notifs       = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
33
34                         // Get the system notifications
35                 } elseif ((DI::args()->get(1) == 'system')) {
36                         $notif_header = DI::l10n()->t('System Notifications');
37                         $notifs       = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
38
39                         // Get the personal notifications
40                 } elseif ((DI::args()->get(1) == 'personal')) {
41                         $notif_header = DI::l10n()->t('Personal Notifications');
42                         $notifs       = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
43
44                         // Get the home notifications
45                 } elseif ((DI::args()->get(1) == 'home')) {
46                         $notif_header = DI::l10n()->t('Home Notifications');
47                         $notifs       = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
48                         // fallback - redirect to main page
49                 } else {
50                         DI::baseUrl()->redirect('notifications');
51                 }
52
53                 // Set the pager
54                 $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
55
56                 // Add additional informations (needed for json output)
57                 $notifs['items_page'] = $pager->getItemsPerPage();
58                 $notifs['page']       = $pager->getPage();
59
60                 return [
61                         'header' => $notif_header,
62                         'notifs' => $notifs,
63                 ];
64         }
65
66         public static function content(array $parameters = [])
67         {
68                 Nav::setSelected('notifications');
69
70                 $notif_content   = [];
71                 $notif_nocontent = '';
72
73                 $notif_result = self::getNotifies();
74                 $notifs       = $notif_result['notifs'] ?? [];
75                 $notif_header = $notif_result['header'] ?? '';
76
77
78                 if (!empty($notifs['notifications'])) {
79                         // Loop trough ever notification This creates an array with the output html for each
80                         // notification and apply the correct template according to the notificationtype (label).
81                         foreach ($notifs['notifications'] as $notif) {
82                                 $notification_templates = [
83                                         'like'        => 'notifications_likes_item.tpl',
84                                         'dislike'     => 'notifications_dislikes_item.tpl',
85                                         'attend'      => 'notifications_attend_item.tpl',
86                                         'attendno'    => 'notifications_attend_item.tpl',
87                                         'attendmaybe' => 'notifications_attend_item.tpl',
88                                         'friend'      => 'notifications_friends_item.tpl',
89                                         'comment'     => 'notifications_comments_item.tpl',
90                                         'post'        => 'notifications_posts_item.tpl',
91                                         'notify'      => 'notify.tpl',
92                                 ];
93
94                                 $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]);
95
96                                 $notif_content[] = Renderer::replaceMacros($tpl_notif, [
97                                         '$item_label' => $notif['label'],
98                                         '$item_link'  => $notif['link'],
99                                         '$item_image' => $notif['image'],
100                                         '$item_url'   => $notif['url'],
101                                         '$item_text'  => $notif['text'],
102                                         '$item_when'  => $notif['when'],
103                                         '$item_ago'   => $notif['ago'],
104                                         '$item_seen'  => $notif['seen'],
105                                 ]);
106                         }
107                 } else {
108                         $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']);
109                 }
110
111                 $notif_show_lnk = [
112                         'href' => (self::$showAll ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'),
113                         'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
114                 ];
115
116                 return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk);
117         }
118 }