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