3 * @copyright Copyright (C) 2010-2023, 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;
25 use Friendica\App\Arguments;
26 use Friendica\Content\Nav;
27 use Friendica\Core\L10n;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\Session\Capability\IHandleUserSessions;
30 use Friendica\Module\BaseNotifications;
31 use Friendica\Module\Response;
32 use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
33 use Friendica\Util\Profiler;
34 use Psr\Log\LoggerInterface;
37 * Prints all notification types except introduction:
43 class Notifications extends BaseNotifications
45 /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotify */
46 protected $formattedNotifyFactory;
48 public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, IHandleUserSessions $userSession, array $server, array $parameters = [])
50 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $userSession, $server, $parameters);
52 $this->formattedNotifyFactory = $formattedNotifyFactory;
58 public function getNotifications()
60 $notificationHeader = '';
63 $factory = $this->formattedNotifyFactory;
65 if (($this->args->get(1) == 'network')) {
66 $notificationHeader = $this->t('Network Notifications');
68 'ident' => FormattedNotify::NETWORK,
69 'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
71 } elseif (($this->args->get(1) == 'system')) {
72 $notificationHeader = $this->t('System Notifications');
74 'ident' => FormattedNotify::SYSTEM,
75 'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
77 } elseif (($this->args->get(1) == 'personal')) {
78 $notificationHeader = $this->t('Personal Notifications');
80 'ident' => FormattedNotify::PERSONAL,
81 'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
83 } elseif (($this->args->get(1) == 'home')) {
84 $notificationHeader = $this->t('Home Notifications');
86 'ident' => FormattedNotify::HOME,
87 'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
90 $this->baseUrl->redirect('notifications');
94 'header' => $notificationHeader,
95 'notifications' => $notifications,
99 protected function content(array $request = []): string
101 Nav::setSelected('notifications');
103 $notificationContent = [];
104 $notificationNoContent = '';
106 $notificationResult = $this->getNotifications();
107 $notifications = $notificationResult['notifications'] ?? [];
108 $notificationHeader = $notificationResult['header'] ?? '';
110 if (!empty($notifications['notifications'])) {
111 $notificationTemplates = [
112 'like' => 'notifications/likes_item.tpl',
113 'dislike' => 'notifications/dislikes_item.tpl',
114 'attend' => 'notifications/attend_item.tpl',
115 'attendno' => 'notifications/attend_item.tpl',
116 'attendmaybe' => 'notifications/attend_item.tpl',
117 'friend' => 'notifications/friends_item.tpl',
118 'comment' => 'notifications/comments_item.tpl',
119 'post' => 'notifications/posts_item.tpl',
120 'notification' => 'notifications/notification.tpl',
122 // Loop trough ever notification This creates an array with the output html for each
123 // notification and apply the correct template according to the notificationtype (label).
124 /** @var FormattedNotify $Notification */
125 foreach ($notifications['notifications'] as $Notification) {
126 $notificationArray = $Notification->toArray();
128 $notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
130 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
131 '$notification' => $notificationArray
135 $notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']);
138 $notificationShowLink = [
139 'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
140 'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')),
143 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);