3 namespace Friendica\Module\Notifications;
5 use Friendica\Content\Nav;
6 use Friendica\Core\Renderer;
8 use Friendica\Module\BaseNotifications;
9 use Friendica\Object\Notification\Notification;
12 * Prints all notification types except introduction:
18 class Notifications extends BaseNotifications
23 public static function getNotifications()
25 $notificationHeader = '';
26 /** @var Notification[] $notifications */
29 // Get the network notifications
30 if ((DI::args()->get(1) == 'network')) {
31 $notificationHeader = DI::l10n()->t('Network Notifications');
33 'ident' => Notification::NETWORK,
34 'notifications' => DI::notification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
37 // Get the system notifications
38 } elseif ((DI::args()->get(1) == 'system')) {
39 $notificationHeader = DI::l10n()->t('System Notifications');
41 'ident' => Notification::SYSTEM,
42 'notifications' => DI::notification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
45 // Get the personal notifications
46 } elseif ((DI::args()->get(1) == 'personal')) {
47 $notificationHeader = DI::l10n()->t('Personal Notifications');
49 'ident' => Notification::PERSONAL,
50 'notifications' => DI::notification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
53 // Get the home notifications
54 } elseif ((DI::args()->get(1) == 'home')) {
55 $notificationHeader = DI::l10n()->t('Home Notifications');
57 'ident' => Notification::HOME,
58 'notifications' => DI::notification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
60 // fallback - redirect to main page
62 DI::baseUrl()->redirect('notifications');
66 'header' => $notificationHeader,
67 'notifications' => $notifications,
71 public static function content(array $parameters = [])
73 Nav::setSelected('notifications');
75 $notificationContent = [];
76 $notificationNoContent = '';
78 $notificationResult = self::getNotifications();
79 $notifications = $notificationResult['notifications'] ?? [];
80 $notificationHeader = $notificationResult['header'] ?? '';
83 if (!empty($notifications['notifications'])) {
84 // Loop trough ever notification This creates an array with the output html for each
85 // notification and apply the correct template according to the notificationtype (label).
86 /** @var Notification $notification */
87 foreach ($notifications['notifications'] as $notification) {
88 $notification_templates = [
89 'like' => 'notifications/likes_item.tpl',
90 'dislike' => 'notifications/dislikes_item.tpl',
91 'attend' => 'notifications/attend_item.tpl',
92 'attendno' => 'notifications/attend_item.tpl',
93 'attendmaybe' => 'notifications/attend_item.tpl',
94 'friend' => 'notifications/friends_item.tpl',
95 'comment' => 'notifications/comments_item.tpl',
96 'post' => 'notifications/posts_item.tpl',
97 'notification' => 'notifications/notification.tpl',
100 $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification->getLabel()]);
102 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
103 '$item_label' => $notification->getLabel(),
104 '$item_link' => $notification->getLink(),
105 '$item_image' => $notification->getImage(),
106 '$item_url' => $notification->getUrl(),
107 '$item_text' => $notification->getText(),
108 '$item_when' => $notification->getWhen(),
109 '$item_ago' => $notification->getAgo(),
110 '$item_seen' => $notification->isSeen(),
114 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
117 $notificationShowLink = [
118 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
119 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
122 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);