2020-01-22 17:18:14 -05:00
|
|
|
<?php
|
2020-02-09 09:45:36 -05:00
|
|
|
/**
|
2021-03-29 02:40:20 -04:00
|
|
|
* @copyright Copyright (C) 2010-2021, the Friendica project
|
2020-02-09 09:45:36 -05:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2020-01-22 17:18:14 -05:00
|
|
|
|
|
|
|
namespace Friendica\Module\Notifications;
|
|
|
|
|
2021-11-17 15:32:57 -05:00
|
|
|
use Friendica\App\Arguments;
|
|
|
|
use Friendica\App\BaseURL;
|
2020-01-22 17:18:14 -05:00
|
|
|
use Friendica\Content\Nav;
|
2021-11-17 15:32:57 -05:00
|
|
|
use Friendica\Core\L10n;
|
2020-01-22 17:18:14 -05:00
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Module\BaseNotifications;
|
2021-09-18 01:08:29 -04:00
|
|
|
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
|
2020-01-22 17:18:14 -05:00
|
|
|
|
2020-01-22 17:31:00 -05:00
|
|
|
/**
|
|
|
|
* Prints all notification types except introduction:
|
|
|
|
* - Network
|
|
|
|
* - System
|
|
|
|
* - Personal
|
|
|
|
* - Home
|
|
|
|
*/
|
2020-01-22 17:18:14 -05:00
|
|
|
class Notifications extends BaseNotifications
|
|
|
|
{
|
2021-11-17 15:32:57 -05:00
|
|
|
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
|
|
|
|
protected $formattedNotificationFactory;
|
|
|
|
|
|
|
|
/** @var BaseURL */
|
|
|
|
protected $baseUrl;
|
|
|
|
|
|
|
|
public function __construct(BaseURL $baseUrl, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, Arguments $args, L10n $l10n, array $parameters = [])
|
|
|
|
{
|
|
|
|
parent::__construct($args, $l10n, $parameters);
|
|
|
|
|
|
|
|
$this->formattedNotificationFactory = $formattedNotificationFactory;
|
|
|
|
$this->baseUrl = $baseUrl;
|
|
|
|
}
|
|
|
|
|
2020-01-22 17:18:14 -05:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2021-11-17 15:32:57 -05:00
|
|
|
public function getNotifications()
|
2020-01-22 17:18:14 -05:00
|
|
|
{
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationHeader = '';
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [];
|
2020-01-22 17:18:14 -05:00
|
|
|
|
2021-11-17 15:32:57 -05:00
|
|
|
$factory = $this->formattedNotificationFactory;
|
2021-09-18 01:08:29 -04:00
|
|
|
|
2021-11-17 15:32:57 -05:00
|
|
|
if (($this->args->get(1) == 'network')) {
|
|
|
|
$notificationHeader = $this->l10n->t('Network Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::NETWORK,
|
2021-11-17 15:32:57 -05:00
|
|
|
'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2021-11-17 15:32:57 -05:00
|
|
|
} elseif (($this->args->get(1) == 'system')) {
|
|
|
|
$notificationHeader = $this->l10n->t('System Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::SYSTEM,
|
2021-11-17 15:32:57 -05:00
|
|
|
'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2021-11-17 15:32:57 -05:00
|
|
|
} elseif (($this->args->get(1) == 'personal')) {
|
|
|
|
$notificationHeader = $this->l10n->t('Personal Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::PERSONAL,
|
2021-11-17 15:32:57 -05:00
|
|
|
'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2021-11-17 15:32:57 -05:00
|
|
|
} elseif (($this->args->get(1) == 'home')) {
|
|
|
|
$notificationHeader = $this->l10n->t('Home Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::HOME,
|
2021-11-17 15:32:57 -05:00
|
|
|
'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
} else {
|
2021-11-17 15:32:57 -05:00
|
|
|
$this->baseUrl->redirect('notifications');
|
2020-01-22 17:18:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2020-01-24 12:32:38 -05:00
|
|
|
'header' => $notificationHeader,
|
|
|
|
'notifications' => $notifications,
|
2020-01-22 17:18:14 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-11-14 17:13:47 -05:00
|
|
|
public function content(): string
|
2020-01-22 17:18:14 -05:00
|
|
|
{
|
|
|
|
Nav::setSelected('notifications');
|
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationContent = [];
|
|
|
|
$notificationNoContent = '';
|
2020-01-22 17:18:14 -05:00
|
|
|
|
2021-11-17 15:32:57 -05:00
|
|
|
$notificationResult = $this->getNotifications();
|
2020-01-24 12:32:38 -05:00
|
|
|
$notifications = $notificationResult['notifications'] ?? [];
|
|
|
|
$notificationHeader = $notificationResult['header'] ?? '';
|
2020-01-22 17:18:14 -05:00
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
if (!empty($notifications['notifications'])) {
|
2021-09-18 00:03:32 -04:00
|
|
|
$notificationTemplates = [
|
|
|
|
'like' => 'notifications/likes_item.tpl',
|
|
|
|
'dislike' => 'notifications/dislikes_item.tpl',
|
|
|
|
'attend' => 'notifications/attend_item.tpl',
|
|
|
|
'attendno' => 'notifications/attend_item.tpl',
|
|
|
|
'attendmaybe' => 'notifications/attend_item.tpl',
|
|
|
|
'friend' => 'notifications/friends_item.tpl',
|
|
|
|
'comment' => 'notifications/comments_item.tpl',
|
|
|
|
'post' => 'notifications/posts_item.tpl',
|
|
|
|
'notification' => 'notifications/notification.tpl',
|
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
// Loop trough ever notification This creates an array with the output html for each
|
|
|
|
// notification and apply the correct template according to the notificationtype (label).
|
2021-09-18 00:03:32 -04:00
|
|
|
/** @var FormattedNotification $Notification */
|
|
|
|
foreach ($notifications['notifications'] as $Notification) {
|
|
|
|
$notificationArray = $Notification->toArray();
|
2021-09-18 01:08:29 -04:00
|
|
|
|
2021-09-18 00:03:32 -04:00
|
|
|
$notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
|
2020-01-24 12:32:38 -05:00
|
|
|
|
|
|
|
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
|
2021-09-18 01:08:29 -04:00
|
|
|
'$notification' => $notificationArray
|
2020-01-22 17:18:14 -05:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
2021-11-17 15:32:57 -05:00
|
|
|
$notificationNoContent = $this->l10n->t('No more %s notifications.', $notificationResult['ident']);
|
2020-01-22 17:18:14 -05:00
|
|
|
}
|
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationShowLink = [
|
2021-11-17 15:32:57 -05:00
|
|
|
'href' => ($this->showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
|
|
|
|
'text' => ($this->showAll ? $this->l10n->t('Show unread') : $this->l10n->t('Show all')),
|
2020-01-22 17:18:14 -05:00
|
|
|
];
|
|
|
|
|
2021-11-17 15:32:57 -05:00
|
|
|
return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
2020-01-22 17:18:14 -05:00
|
|
|
}
|
|
|
|
}
|