2020-01-22 23:18:14 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Notifications;
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Content\Pager;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Module\BaseNotifications;
|
|
|
|
|
2020-01-22 23:31:00 +01:00
|
|
|
/**
|
|
|
|
* Prints all notification types except introduction:
|
|
|
|
* - Network
|
|
|
|
* - System
|
|
|
|
* - Personal
|
|
|
|
* - Home
|
|
|
|
*/
|
2020-01-22 23:18:14 +01:00
|
|
|
class Notifications extends BaseNotifications
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-24 18:32:38 +01:00
|
|
|
public static function getNotifications()
|
2020-01-22 23:18:14 +01:00
|
|
|
{
|
2020-01-24 18:32:38 +01:00
|
|
|
$nm = DI::notification();
|
2020-01-22 23:18:14 +01:00
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationHeader = '';
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
// Get the network notifications
|
|
|
|
if ((DI::args()->get(1) == 'network')) {
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationHeader = DI::l10n()->t('Network Notifications');
|
|
|
|
$notifications = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
// Get the system notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'system')) {
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationHeader = DI::l10n()->t('System Notifications');
|
|
|
|
$notifications = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
// Get the personal notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'personal')) {
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationHeader = DI::l10n()->t('Personal Notifications');
|
|
|
|
$notifications = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
// Get the home notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'home')) {
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationHeader = DI::l10n()->t('Home Notifications');
|
|
|
|
$notifications = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
2020-01-22 23:18:14 +01:00
|
|
|
// fallback - redirect to main page
|
|
|
|
} else {
|
|
|
|
DI::baseUrl()->redirect('notifications');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the pager
|
2020-01-22 23:37:23 +01:00
|
|
|
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
// Add additional informations (needed for json output)
|
2020-01-24 18:32:38 +01:00
|
|
|
$notifications['items_page'] = $pager->getItemsPerPage();
|
|
|
|
$notifications['page'] = $pager->getPage();
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
return [
|
2020-01-24 18:32:38 +01:00
|
|
|
'header' => $notificationHeader,
|
|
|
|
'notifications' => $notifications,
|
2020-01-22 23:18:14 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function content(array $parameters = [])
|
|
|
|
{
|
|
|
|
Nav::setSelected('notifications');
|
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationContent = [];
|
|
|
|
$notificationNoContent = '';
|
2020-01-22 23:18:14 +01:00
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationResult = self::getNotifications();
|
|
|
|
$notifications = $notificationResult['notifications'] ?? [];
|
|
|
|
$notificationHeader = $notificationResult['header'] ?? '';
|
2020-01-22 23:18:14 +01:00
|
|
|
|
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
if (!empty($notifications['notifications'])) {
|
2020-01-22 23:18:14 +01: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).
|
2020-01-24 18:32:38 +01:00
|
|
|
foreach ($notifications['notifications'] as $notification) {
|
2020-01-22 23:18:14 +01:00
|
|
|
$notification_templates = [
|
2020-01-24 18:56:34 +01: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 23:18:14 +01:00
|
|
|
];
|
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]);
|
|
|
|
|
|
|
|
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
|
|
|
|
'$item_label' => $notification['label'],
|
|
|
|
'$item_link' => $notification['link'],
|
|
|
|
'$item_image' => $notification['image'],
|
|
|
|
'$item_url' => $notification['url'],
|
|
|
|
'$item_text' => $notification['text'],
|
|
|
|
'$item_when' => $notification['when'],
|
|
|
|
'$item_ago' => $notification['ago'],
|
|
|
|
'$item_seen' => $notification['seen'],
|
2020-01-22 23:18:14 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
|
2020-01-22 23:18:14 +01:00
|
|
|
}
|
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
$notificationShowLink = [
|
|
|
|
'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
|
2020-01-22 23:37:23 +01:00
|
|
|
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
|
2020-01-22 23:18:14 +01:00
|
|
|
];
|
|
|
|
|
2020-01-24 18:32:38 +01:00
|
|
|
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
2020-01-22 23:18:14 +01:00
|
|
|
}
|
|
|
|
}
|