]> git.mxchange.org Git - friendica.git/blob - src/Module/Notifications/Notifications.php
rename CSS attributes notify => 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 /**
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 getNotifications()
24         {
25                 $nm = DI::notification();
26
27                 $notificationHeader = '';
28
29                 // Get the network notifications
30                 if ((DI::args()->get(1) == 'network')) {
31                         $notificationHeader = DI::l10n()->t('Network Notifications');
32                         $notifications      = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
33
34                         // Get the system notifications
35                 } elseif ((DI::args()->get(1) == 'system')) {
36                         $notificationHeader = DI::l10n()->t('System Notifications');
37                         $notifications      = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
38
39                         // Get the personal notifications
40                 } elseif ((DI::args()->get(1) == 'personal')) {
41                         $notificationHeader = DI::l10n()->t('Personal Notifications');
42                         $notifications      = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
43
44                         // Get the home notifications
45                 } elseif ((DI::args()->get(1) == 'home')) {
46                         $notificationHeader = DI::l10n()->t('Home Notifications');
47                         $notifications      = $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                 $notifications['items_page'] = $pager->getItemsPerPage();
58                 $notifications['page']       = $pager->getPage();
59
60                 return [
61                         'header'        => $notificationHeader,
62                         'notifications' => $notifications,
63                 ];
64         }
65
66         public static function content(array $parameters = [])
67         {
68                 Nav::setSelected('notifications');
69
70                 $notificationContent   = [];
71                 $notificationNoContent = '';
72
73                 $notificationResult = self::getNotifications();
74                 $notifications      = $notificationResult['notifications'] ?? [];
75                 $notificationHeader = $notificationResult['header'] ?? '';
76
77
78                 if (!empty($notifications['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 ($notifications['notifications'] as $notification) {
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                                         'notification' => 'notifications/notification.tpl',
92                                 ];
93
94                                 $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]);
95
96                                 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
97                                         '$item_label' => $notification['label'],
98                                         '$item_link'  => $notification['link'],
99                                         '$item_image' => $notification['image'],
100                                         '$item_url'   => $notification['url'],
101                                         '$item_text'  => $notification['text'],
102                                         '$item_when'  => $notification['when'],
103                                         '$item_ago'   => $notification['ago'],
104                                         '$item_seen'  => $notification['seen'],
105                                 ]);
106                         }
107                 } else {
108                         $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
109                 }
110
111                 $notificationShowLink = [
112                         'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
113                         'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
114                 ];
115
116                 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
117         }
118 }