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;
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\Navigation\Notifications\ValueObject\FormattedNotification;
31 use Friendica\Util\Profiler;
32 use Psr\Log\LoggerInterface;
35 * Prints all notification types except introduction:
41 class Notifications extends BaseNotifications
43 /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
44 protected $formattedNotificationFactory;
46 public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, array $server, array $parameters = [])
48 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
50 $this->formattedNotificationFactory = $formattedNotificationFactory;
56 public function getNotifications()
58 $notificationHeader = '';
61 $factory = $this->formattedNotificationFactory;
63 if (($this->args->get(1) == 'network')) {
64 $notificationHeader = $this->t('Network Notifications');
66 'ident' => FormattedNotification::NETWORK,
67 'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
69 } elseif (($this->args->get(1) == 'system')) {
70 $notificationHeader = $this->t('System Notifications');
72 'ident' => FormattedNotification::SYSTEM,
73 'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
75 } elseif (($this->args->get(1) == 'personal')) {
76 $notificationHeader = $this->t('Personal Notifications');
78 'ident' => FormattedNotification::PERSONAL,
79 'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
81 } elseif (($this->args->get(1) == 'home')) {
82 $notificationHeader = $this->t('Home Notifications');
84 'ident' => FormattedNotification::HOME,
85 'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
88 $this->baseUrl->redirect('notifications');
92 'header' => $notificationHeader,
93 'notifications' => $notifications,
97 protected function content(array $request = []): string
99 Nav::setSelected('notifications');
101 $notificationContent = [];
102 $notificationNoContent = '';
104 $notificationResult = $this->getNotifications();
105 $notifications = $notificationResult['notifications'] ?? [];
106 $notificationHeader = $notificationResult['header'] ?? '';
108 if (!empty($notifications['notifications'])) {
109 $notificationTemplates = [
110 'like' => 'notifications/likes_item.tpl',
111 'dislike' => 'notifications/dislikes_item.tpl',
112 'attend' => 'notifications/attend_item.tpl',
113 'attendno' => 'notifications/attend_item.tpl',
114 'attendmaybe' => 'notifications/attend_item.tpl',
115 'friend' => 'notifications/friends_item.tpl',
116 'comment' => 'notifications/comments_item.tpl',
117 'post' => 'notifications/posts_item.tpl',
118 'notification' => 'notifications/notification.tpl',
120 // Loop trough ever notification This creates an array with the output html for each
121 // notification and apply the correct template according to the notificationtype (label).
122 /** @var FormattedNotification $Notification */
123 foreach ($notifications['notifications'] as $Notification) {
124 $notificationArray = $Notification->toArray();
126 $notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
128 $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
129 '$notification' => $notificationArray
133 $notificationNoContent = $this->t('No more %s notifications.', $notificationResult['ident']);
136 $notificationShowLink = [
137 'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
138 'text' => ($this->showAll ? $this->t('Show unread') : $this->t('Show all')),
141 return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);