3 namespace Friendica\Module\Notifications;
5 use Friendica\Content\Nav;
6 use Friendica\Content\Pager;
7 use Friendica\Core\Renderer;
9 use Friendica\Module\BaseNotifications;
12 * Prints all notification types except introduction:
18 class Notifications extends BaseNotifications
23 public static function getNotifications()
25 $nm = DI::notification();
27 $notificationHeader = '';
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);
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);
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);
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
50 DI::baseUrl()->redirect('notifications');
54 $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
56 // Add additional informations (needed for json output)
57 $notifications['items_page'] = $pager->getItemsPerPage();
58 $notifications['page'] = $pager->getPage();
61 'header' => $notificationHeader,
62 'notifications' => $notifications,
66 public static function content(array $parameters = [])
68 Nav::setSelected('notifications');
70 $notificationContent = [];
71 $notificationNoContent = '';
73 $notificationResult = self::getNotifications();
74 $notifications = $notificationResult['notifications'] ?? [];
75 $notificationHeader = $notificationResult['header'] ?? '';
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',
94 $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]);
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'],
108 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
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')),
116 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);