3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Notifications;
24 use Friendica\Content\Nav;
25 use Friendica\Core\Renderer;
27 use Friendica\Module\BaseNotifications;
28 use Friendica\Object\Notification\Notification;
31 * Prints all notification types except introduction:
37 class Notifications extends BaseNotifications
42 public static function getNotifications()
44 $notificationHeader = '';
45 /** @var Notification[] $notifications */
48 // Get the network notifications
49 if ((DI::args()->get(1) == 'network')) {
50 $notificationHeader = DI::l10n()->t('Network Notifications');
52 'ident' => Notification::NETWORK,
53 'notifications' => DI::notification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
56 // Get the system notifications
57 } elseif ((DI::args()->get(1) == 'system')) {
58 $notificationHeader = DI::l10n()->t('System Notifications');
60 'ident' => Notification::SYSTEM,
61 'notifications' => DI::notification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
64 // Get the personal notifications
65 } elseif ((DI::args()->get(1) == 'personal')) {
66 $notificationHeader = DI::l10n()->t('Personal Notifications');
68 'ident' => Notification::PERSONAL,
69 'notifications' => DI::notification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
72 // Get the home notifications
73 } elseif ((DI::args()->get(1) == 'home')) {
74 $notificationHeader = DI::l10n()->t('Home Notifications');
76 'ident' => Notification::HOME,
77 'notifications' => DI::notification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
79 // fallback - redirect to main page
81 DI::baseUrl()->redirect('notifications');
85 'header' => $notificationHeader,
86 'notifications' => $notifications,
90 public static function content(array $parameters = [])
92 Nav::setSelected('notifications');
94 $notificationContent = [];
95 $notificationNoContent = '';
97 $notificationResult = self::getNotifications();
98 $notifications = $notificationResult['notifications'] ?? [];
99 $notificationHeader = $notificationResult['header'] ?? '';
102 if (!empty($notifications['notifications'])) {
103 // Loop trough ever notification This creates an array with the output html for each
104 // notification and apply the correct template according to the notificationtype (label).
105 /** @var Notification $notification */
106 foreach ($notifications['notifications'] as $notification) {
107 $notification_templates = [
108 'like' => 'notifications/likes_item.tpl',
109 'dislike' => 'notifications/dislikes_item.tpl',
110 'attend' => 'notifications/attend_item.tpl',
111 'attendno' => 'notifications/attend_item.tpl',
112 'attendmaybe' => 'notifications/attend_item.tpl',
113 'friend' => 'notifications/friends_item.tpl',
114 'comment' => 'notifications/comments_item.tpl',
115 'post' => 'notifications/posts_item.tpl',
116 'notification' => 'notifications/notification.tpl',
119 $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification->getLabel()]);
121 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
122 '$item_label' => $notification->getLabel(),
123 '$item_link' => $notification->getLink(),
124 '$item_image' => $notification->getImage(),
125 '$item_url' => $notification->getUrl(),
126 '$item_text' => $notification->getText(),
127 '$item_when' => $notification->getWhen(),
128 '$item_ago' => $notification->getAgo(),
129 '$item_seen' => $notification->isSeen(),
133 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
136 $notificationShowLink = [
137 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
138 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
141 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);