2020-01-22 22:18:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Module\Notifications;
|
|
|
|
|
|
|
|
use Friendica\Content\Nav;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Module\BaseNotifications;
|
2020-01-25 01:01:49 +00:00
|
|
|
use Friendica\Object\Notification\Notification;
|
2020-01-22 22:18:14 +00:00
|
|
|
|
2020-01-22 22:31:00 +00:00
|
|
|
/**
|
|
|
|
* Prints all notification types except introduction:
|
|
|
|
* - Network
|
|
|
|
* - System
|
|
|
|
* - Personal
|
|
|
|
* - Home
|
|
|
|
*/
|
2020-01-22 22:18:14 +00:00
|
|
|
class Notifications extends BaseNotifications
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2020-01-24 17:32:38 +00:00
|
|
|
public static function getNotifications()
|
2020-01-22 22:18:14 +00:00
|
|
|
{
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationHeader = '';
|
2020-01-25 01:01:49 +00:00
|
|
|
/** @var Notification[] $notifications */
|
|
|
|
$notifications = [];
|
2020-01-22 22:18:14 +00:00
|
|
|
|
|
|
|
// Get the network notifications
|
|
|
|
if ((DI::args()->get(1) == 'network')) {
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationHeader = DI::l10n()->t('Network Notifications');
|
2020-01-25 01:01:49 +00:00
|
|
|
$notifications = [
|
|
|
|
'ident' => Notification::NETWORK,
|
|
|
|
'notifications' => DI::factNotification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
|
|
|
];
|
2020-01-22 22:18:14 +00:00
|
|
|
|
|
|
|
// Get the system notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'system')) {
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationHeader = DI::l10n()->t('System Notifications');
|
2020-01-25 01:01:49 +00:00
|
|
|
$notifications = [
|
|
|
|
'ident' => Notification::SYSTEM,
|
|
|
|
'notifications' => DI::factNotification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
|
|
|
];
|
2020-01-22 22:18:14 +00:00
|
|
|
|
|
|
|
// Get the personal notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'personal')) {
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationHeader = DI::l10n()->t('Personal Notifications');
|
2020-01-25 01:01:49 +00:00
|
|
|
$notifications = [
|
|
|
|
'ident' => Notification::PERSONAL,
|
|
|
|
'notifications' => DI::factNotification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
|
|
|
];
|
2020-01-22 22:18:14 +00:00
|
|
|
|
|
|
|
// Get the home notifications
|
|
|
|
} elseif ((DI::args()->get(1) == 'home')) {
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationHeader = DI::l10n()->t('Home Notifications');
|
2020-01-25 01:01:49 +00:00
|
|
|
$notifications = [
|
|
|
|
'ident' => Notification::HOME,
|
|
|
|
'notifications' => DI::factNotification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
|
|
|
|
];
|
2020-01-22 22:18:14 +00:00
|
|
|
// fallback - redirect to main page
|
|
|
|
} else {
|
|
|
|
DI::baseUrl()->redirect('notifications');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2020-01-24 17:32:38 +00:00
|
|
|
'header' => $notificationHeader,
|
|
|
|
'notifications' => $notifications,
|
2020-01-22 22:18:14 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function content(array $parameters = [])
|
|
|
|
{
|
|
|
|
Nav::setSelected('notifications');
|
|
|
|
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationContent = [];
|
|
|
|
$notificationNoContent = '';
|
2020-01-22 22:18:14 +00:00
|
|
|
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationResult = self::getNotifications();
|
|
|
|
$notifications = $notificationResult['notifications'] ?? [];
|
|
|
|
$notificationHeader = $notificationResult['header'] ?? '';
|
2020-01-22 22:18:14 +00:00
|
|
|
|
|
|
|
|
2020-01-24 17:32:38 +00:00
|
|
|
if (!empty($notifications['notifications'])) {
|
2020-01-22 22:18:14 +00: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-25 01:01:49 +00:00
|
|
|
/** @var Notification $notification */
|
2020-01-24 17:32:38 +00:00
|
|
|
foreach ($notifications['notifications'] as $notification) {
|
2020-01-22 22:18:14 +00:00
|
|
|
$notification_templates = [
|
2020-01-24 17:56:34 +00: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 22:18:14 +00:00
|
|
|
];
|
|
|
|
|
2020-01-25 01:01:49 +00:00
|
|
|
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification->getLabel()]);
|
2020-01-24 17:32:38 +00:00
|
|
|
|
|
|
|
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
|
2020-01-25 01:01:49 +00:00
|
|
|
'$item_label' => $notification->getLabel(),
|
|
|
|
'$item_link' => $notification->getLink(),
|
|
|
|
'$item_image' => $notification->getImage(),
|
|
|
|
'$item_url' => $notification->getUrl(),
|
|
|
|
'$item_text' => $notification->getText(),
|
|
|
|
'$item_when' => $notification->getWhen(),
|
|
|
|
'$item_ago' => $notification->getAgo(),
|
|
|
|
'$item_seen' => $notification->isSeen(),
|
2020-01-22 22:18:14 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
} else {
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
|
2020-01-22 22:18:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 17:32:38 +00:00
|
|
|
$notificationShowLink = [
|
|
|
|
'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
|
2020-01-22 22:37:23 +00:00
|
|
|
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
|
2020-01-22 22:18:14 +00:00
|
|
|
];
|
|
|
|
|
2020-01-24 17:32:38 +00:00
|
|
|
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
2020-01-22 22:18:14 +00:00
|
|
|
}
|
|
|
|
}
|