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 /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification $factory */
50 $factory = DI::getDice()->create(\Friendica\Navigation\Notifications\Factory\FormattedNotification::class);
52 if ((DI::args()->get(1) == 'network')) {
53 $notificationHeader = DI::l10n()->t('Network Notifications');
55 'ident' => FormattedNotification::NETWORK,
56 'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
58 } elseif ((DI::args()->get(1) == 'system')) {
59 $notificationHeader = DI::l10n()->t('System Notifications');
61 'ident' => FormattedNotification::SYSTEM,
62 'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
64 } elseif ((DI::args()->get(1) == 'personal')) {
65 $notificationHeader = DI::l10n()->t('Personal Notifications');
67 'ident' => FormattedNotification::PERSONAL,
68 'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
70 } elseif ((DI::args()->get(1) == 'home')) {
71 $notificationHeader = DI::l10n()->t('Home Notifications');
73 'ident' => FormattedNotification::HOME,
74 'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
77 DI::baseUrl()->redirect('notifications');
81 'header' => $notificationHeader,
82 'notifications' => $notifications,
86 public static function content(array $parameters = [])
88 Nav::setSelected('notifications');
90 $notificationContent = [];
91 $notificationNoContent = '';
93 $notificationResult = self::getNotifications();
94 $notifications = $notificationResult['notifications'] ?? [];
95 $notificationHeader = $notificationResult['header'] ?? '';
97 if (!empty($notifications['notifications'])) {
98 $notificationTemplates = [
99 'like' => 'notifications/likes_item.tpl',
100 'dislike' => 'notifications/dislikes_item.tpl',
101 'attend' => 'notifications/attend_item.tpl',
102 'attendno' => 'notifications/attend_item.tpl',
103 'attendmaybe' => 'notifications/attend_item.tpl',
104 'friend' => 'notifications/friends_item.tpl',
105 'comment' => 'notifications/comments_item.tpl',
106 'post' => 'notifications/posts_item.tpl',
107 'notification' => 'notifications/notification.tpl',
109 // Loop trough ever notification This creates an array with the output html for each
110 // notification and apply the correct template according to the notificationtype (label).
111 /** @var FormattedNotification $Notification */
112 foreach ($notifications['notifications'] as $Notification) {
113 $notificationArray = $Notification->toArray();
115 $notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
117 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
118 '$notification' => $notificationArray
122 $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']);
125 $notificationShowLink = [
126 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
127 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
130 return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);