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\Navigation\Notifications\Collection\FormattedNotifications;
29 use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
30 use Friendica\Network\HTTPException\InternalServerErrorException;
33 * Prints all notification types except introduction:
39 class Notifications extends BaseNotifications
44 public static function getNotifications()
46 $notificationHeader = '';
49 $factory = DI::formattedNotificationFactory();
51 if ((DI::args()->get(1) == 'network')) {
52 $notificationHeader = DI::l10n()->t('Network Notifications');
54 'ident' => FormattedNotification::NETWORK,
55 'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
57 } elseif ((DI::args()->get(1) == 'system')) {
58 $notificationHeader = DI::l10n()->t('System Notifications');
60 'ident' => FormattedNotification::SYSTEM,
61 'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
63 } elseif ((DI::args()->get(1) == 'personal')) {
64 $notificationHeader = DI::l10n()->t('Personal Notifications');
66 'ident' => FormattedNotification::PERSONAL,
67 'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
69 } elseif ((DI::args()->get(1) == 'home')) {
70 $notificationHeader = DI::l10n()->t('Home Notifications');
72 'ident' => FormattedNotification::HOME,
73 'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
76 DI::baseUrl()->redirect('notifications');
80 'header' => $notificationHeader,
81 'notifications' => $notifications,
85 public static function content(array $parameters = [])
87 Nav::setSelected('notifications');
89 $notificationContent = [];
90 $notificationNoContent = '';
92 $notificationResult = self::getNotifications();
93 $notifications = $notificationResult['notifications'] ?? [];
94 $notificationHeader = $notificationResult['header'] ?? '';
96 if (!empty($notifications['notifications'])) {
97 $notificationTemplates = [
98 'like' => 'notifications/likes_item.tpl',
99 'dislike' => 'notifications/dislikes_item.tpl',
100 'attend' => 'notifications/attend_item.tpl',
101 'attendno' => 'notifications/attend_item.tpl',
102 'attendmaybe' => 'notifications/attend_item.tpl',
103 'friend' => 'notifications/friends_item.tpl',
104 'comment' => 'notifications/comments_item.tpl',
105 'post' => 'notifications/posts_item.tpl',
106 'notification' => 'notifications/notification.tpl',
108 // Loop trough ever notification This creates an array with the output html for each
109 // notification and apply the correct template according to the notificationtype (label).
110 /** @var FormattedNotification $Notification */
111 foreach ($notifications['notifications'] as $Notification) {
112 $notificationArray = $Notification->toArray();
114 $notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
116 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
117 '$notification' => $notificationArray
121 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']);
124 $notificationShowLink = [
125 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
126 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
129 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);