3 * @copyright Copyright (C) 2010-2022, 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\Module\BaseNotifications;
30 use Friendica\Module\Response;
31 use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
32 use Friendica\Util\Profiler;
33 use Psr\Log\LoggerInterface;
36 * Prints all notification types except introduction:
42 class Notifications extends BaseNotifications
44 /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotify */
45 protected $formattedNotifyFactory;
47 public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, array $server, array $parameters = [])
49 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
51 $this->formattedNotifyFactory = $formattedNotifyFactory;
57 public function getNotifications()
59 $notificationHeader = '';
62 $factory = $this->formattedNotifyFactory;
64 if (($this->args->get(1) == 'network')) {
65 $notificationHeader = $this->t('Network Notifications');
67 'ident' => FormattedNotify::NETWORK,
68 'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
70 } elseif (($this->args->get(1) == 'system')) {
71 $notificationHeader = $this->t('System Notifications');
73 'ident' => FormattedNotify::SYSTEM,
74 'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
76 } elseif (($this->args->get(1) == 'personal')) {
77 $notificationHeader = $this->t('Personal Notifications');
79 'ident' => FormattedNotify::PERSONAL,
80 'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
82 } elseif (($this->args->get(1) == 'home')) {
83 $notificationHeader = $this->t('Home Notifications');
85 'ident' => FormattedNotify::HOME,
86 'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
89 $this->baseUrl->redirect('notifications');
93 'header' => $notificationHeader,
94 'notifications' => $notifications,
98 protected function content(array $request = []): string
100 Nav::setSelected('notifications');
102 $notificationContent = [];
103 $notificationNoContent = '';
105 $notificationResult = $this->getNotifications();
106 $notifications = $notificationResult['notifications'] ?? [];
107 $notificationHeader = $notificationResult['header'] ?? '';
109 if (!empty($notifications['notifications'])) {
110 $notificationTemplates = [
111 'like' => 'notifications/likes_item.tpl',
112 'dislike' => 'notifications/dislikes_item.tpl',
113 'attend' => 'notifications/attend_item.tpl',
114 'attendno' => 'notifications/attend_item.tpl',
115 'attendmaybe' => 'notifications/attend_item.tpl',
116 'friend' => 'notifications/friends_item.tpl',
117 'comment' => 'notifications/comments_item.tpl',
118 'post' => 'notifications/posts_item.tpl',
119 'notification' => 'notifications/notification.tpl',
121 // Loop trough ever notification This creates an array with the output html for each
122 // notification and apply the correct template according to the notificationtype (label).
123 /** @var FormattedNotify $Notification */
124 foreach ($notifications['notifications'] as $Notification) {
125 $notificationArray = $Notification->toArray();
127 $notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
129 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
130 '$notification' => $notificationArray
134 $notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']);
137 $notificationShowLink = [
138 'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
139 'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')),
142 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);