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;
11 class Notifications extends BaseNotifications
16 public static function getNotifies()
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);
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);
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);
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
43 DI::baseUrl()->redirect('notifications');
47 $pager = new Pager(DI::args()->getQueryString(), self::PER_PAGE);
49 // Add additional informations (needed for json output)
50 $notifs['items_page'] = $pager->getItemsPerPage();
51 $notifs['page'] = $pager->getPage();
54 'header' => $notif_header,
59 public static function content(array $parameters = [])
61 Nav::setSelected('notifications');
64 $notif_nocontent = '';
66 $notif_result = self::getNotifies();
67 $notifs = $notif_result['notifs'] ?? [];
68 $notif_header = $notif_result['header'] ?? '';
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',
87 $tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]);
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'],
101 $notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']);
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')),
109 return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk);