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;
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Module\BaseNotifications;
|
2021-09-18 01:08:29 -04:00
|
|
|
use Friendica\Navigation\Notifications\Collection\FormattedNotifications;
|
|
|
|
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
|
|
|
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
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
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-24 12:32:38 -05:00
|
|
|
public static 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-09-18 01:08:29 -04:00
|
|
|
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification $factory */
|
|
|
|
$factory = DI::getDice()->create(\Friendica\Navigation\Notifications\Factory\FormattedNotification::class);
|
|
|
|
|
2020-01-22 17:18:14 -05:00
|
|
|
if ((DI::args()->get(1) == 'network')) {
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationHeader = DI::l10n()->t('Network Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::NETWORK,
|
|
|
|
'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
} elseif ((DI::args()->get(1) == 'system')) {
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationHeader = DI::l10n()->t('System Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::SYSTEM,
|
|
|
|
'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
} elseif ((DI::args()->get(1) == 'personal')) {
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationHeader = DI::l10n()->t('Personal Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::PERSONAL,
|
|
|
|
'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
} elseif ((DI::args()->get(1) == 'home')) {
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationHeader = DI::l10n()->t('Home Notifications');
|
2020-01-24 20:01:49 -05:00
|
|
|
$notifications = [
|
2021-09-18 01:08:29 -04:00
|
|
|
'ident' => FormattedNotification::HOME,
|
|
|
|
'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
2020-01-24 20:01:49 -05:00
|
|
|
];
|
2020-01-22 17:18:14 -05:00
|
|
|
} else {
|
|
|
|
DI::baseUrl()->redirect('notifications');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2020-01-24 12:32:38 -05:00
|
|
|
'header' => $notificationHeader,
|
|
|
|
'notifications' => $notifications,
|
2020-01-22 17:18:14 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function content(array $parameters = [])
|
|
|
|
{
|
|
|
|
Nav::setSelected('notifications');
|
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationContent = [];
|
|
|
|
$notificationNoContent = '';
|
2020-01-22 17:18:14 -05:00
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
$notificationResult = self::getNotifications();
|
|
|
|
$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'])) {
|
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 01:08:29 -04:00
|
|
|
/** @var FormattedNotification $notification */
|
2020-01-24 12:32:38 -05:00
|
|
|
foreach ($notifications['notifications'] as $notification) {
|
2020-01-22 17:18:14 -05:00
|
|
|
$notification_templates = [
|
2020-01-24 12:56:34 -05:00
|
|
|
'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
|
|
|
];
|
|
|
|
|
2021-09-18 01:08:29 -04:00
|
|
|
$notificationArray = $notification->toArray();
|
|
|
|
|
|
|
|
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$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-09-18 01:08:29 -04:00
|
|
|
$notificationNoContent = DI::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 = [
|
|
|
|
'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
|
2020-01-22 17:37:23 -05:00
|
|
|
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
|
2020-01-22 17:18:14 -05:00
|
|
|
];
|
|
|
|
|
2020-01-24 12:32:38 -05:00
|
|
|
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
2020-01-22 17:18:14 -05:00
|
|
|
}
|
|
|
|
}
|