Merge pull request #8155 from nupplaphil/task/move_notifications
Move mod/notifications to Module\Notification
This commit is contained in:
commit
188720c3cd
68 changed files with 794 additions and 686 deletions
|
|
@ -257,11 +257,11 @@ abstract class DI
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Model\Notify
|
||||
* @return Model\Notification
|
||||
*/
|
||||
public static function notify()
|
||||
public static function notification()
|
||||
{
|
||||
return self::$dice->create(Model\Notify::class);
|
||||
return self::$dice->create(Model\Notification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ use Friendica\Network\HTTPException;
|
|||
* Methods for read and write notifications from/to database
|
||||
* or for formatting notifications
|
||||
*/
|
||||
final class Notify
|
||||
final class Notification
|
||||
{
|
||||
/** @var int The default limit of notifies per page */
|
||||
/** @var int The default limit of notifications per page */
|
||||
const DEFAULT_PAGE_LIMIT = 80;
|
||||
|
||||
const NETWORK = 'network';
|
||||
|
|
@ -110,10 +110,10 @@ final class Notify
|
|||
|
||||
$dbFilter = array_merge($filter, ['uid' => local_user()]);
|
||||
|
||||
$stmtNotifies = $this->dba->select('notify', [], $dbFilter, $params);
|
||||
$stmtNotifications = $this->dba->select('notify', [], $dbFilter, $params);
|
||||
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
return $this->setExtra($this->dba->toArray($stmtNotifies));
|
||||
if ($this->dba->isResult($stmtNotifications)) {
|
||||
return $this->setExtra($this->dba->toArray($stmtNotifications));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -172,8 +172,8 @@ final class Notify
|
|||
/**
|
||||
* Format the notification query in an usable array
|
||||
*
|
||||
* @param array $notifies The array from the db query
|
||||
* @param string $ident The notifications identifier (e.g. network)
|
||||
* @param array $notifications The array from the db query
|
||||
* @param string $ident The notifications identifier (e.g. network)
|
||||
*
|
||||
* @return array
|
||||
* string 'label' => The type of the notification
|
||||
|
|
@ -186,127 +186,127 @@ final class Notify
|
|||
* bool 'seen' => Is the notification marked as "seen"
|
||||
* @throws Exception
|
||||
*/
|
||||
private function formatList(array $notifies, string $ident = "")
|
||||
private function formatList(array $notifications, string $ident = "")
|
||||
{
|
||||
$formattedNotifies = [];
|
||||
$formattedNotifications = [];
|
||||
|
||||
foreach ($notifies as $notify) {
|
||||
foreach ($notifications as $notification) {
|
||||
// Because we use different db tables for the notification query
|
||||
// we have sometimes $notify['unseen'] and sometimes $notify['seen].
|
||||
// So we will have to transform $notify['unseen']
|
||||
if (array_key_exists('unseen', $notify)) {
|
||||
$notify['seen'] = ($notify['unseen'] > 0 ? false : true);
|
||||
// we have sometimes $notification['unseen'] and sometimes $notification['seen].
|
||||
// So we will have to transform $notification['unseen']
|
||||
if (array_key_exists('unseen', $notification)) {
|
||||
$notification['seen'] = ($notification['unseen'] > 0 ? false : true);
|
||||
}
|
||||
|
||||
// For feed items we use the user's contact, since the avatar is mostly self choosen.
|
||||
if (!empty($notify['network']) && $notify['network'] == Protocol::FEED) {
|
||||
$notify['author-avatar'] = $notify['contact-avatar'];
|
||||
if (!empty($notification['network']) && $notification['network'] == Protocol::FEED) {
|
||||
$notification['author-avatar'] = $notification['contact-avatar'];
|
||||
}
|
||||
|
||||
// Depending on the identifier of the notification we need to use different defaults
|
||||
switch ($ident) {
|
||||
case self::SYSTEM:
|
||||
$default_item_label = 'notify';
|
||||
$default_item_link = $this->baseUrl->get(true) . '/notify/view/' . $notify['id'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['photo'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['url'];
|
||||
$default_item_text = strip_tags(BBCode::convert($notify['msg']));
|
||||
$default_item_when = DateTimeFormat::local($notify['date'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['date']);
|
||||
$default_item_label = 'notification';
|
||||
$default_item_link = $this->baseUrl->get(true) . '/notification/view/' . $notification['id'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notification['photo'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notification['url'];
|
||||
$default_item_text = strip_tags(BBCode::convert($notification['msg']));
|
||||
$default_item_when = DateTimeFormat::local($notification['date'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notification['date']);
|
||||
break;
|
||||
|
||||
case self::HOME:
|
||||
$default_item_label = 'comment';
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['author-link'];
|
||||
$default_item_text = $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']);
|
||||
$default_item_when = DateTimeFormat::local($notify['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['created']);
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notification['author-link'];
|
||||
$default_item_text = $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name']);
|
||||
$default_item_when = DateTimeFormat::local($notification['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notification['created']);
|
||||
break;
|
||||
|
||||
default:
|
||||
$default_item_label = (($notify['id'] == $notify['parent']) ? 'post' : 'comment');
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['author-link'];
|
||||
$default_item_text = (($notify['id'] == $notify['parent'])
|
||||
? $this->l10n->t("%s created a new post", $notify['author-name'])
|
||||
: $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']));
|
||||
$default_item_when = DateTimeFormat::local($notify['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['created']);
|
||||
$default_item_label = (($notification['id'] == $notification['parent']) ? 'post' : 'comment');
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notification['author-link'];
|
||||
$default_item_text = (($notification['id'] == $notification['parent'])
|
||||
? $this->l10n->t("%s created a new post", $notification['author-name'])
|
||||
: $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name']));
|
||||
$default_item_when = DateTimeFormat::local($notification['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notification['created']);
|
||||
}
|
||||
|
||||
// Transform the different types of notification in an usable array
|
||||
switch ($notify['verb']) {
|
||||
switch ($notification['verb']) {
|
||||
case Activity::LIKE:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'like',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s liked %s's post", $notify['author-name'], $notify['parent-author-name']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s liked %s's post", $notification['author-name'], $notification['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::DISLIKE:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'dislike',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s disliked %s's post", $notify['author-name'], $notify['parent-author-name']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s disliked %s's post", $notification['author-name'], $notification['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTEND:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'attend',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is attending %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s is attending %s's event", $notification['author-name'], $notification['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDNO:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'attendno',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is not attending %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s is not attending %s's event", $notification['author-name'], $notification['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDMAYBE:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'attendmaybe',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s may attend %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s may attend %s's event", $notification['author-name'], $notification['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::FRIEND:
|
||||
if (!isset($notify['object'])) {
|
||||
$formattedNotify = [
|
||||
if (!isset($notification['object'])) {
|
||||
$formattedNotification = [
|
||||
'label' => 'friend',
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
|
|
@ -314,31 +314,31 @@ final class Notify
|
|||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
}
|
||||
/// @todo Check if this part here is used at all
|
||||
$this->logger->info('Complete data.', ['notify' => $notify, 'callStack' => System::callstack(20)]);
|
||||
$this->logger->info('Complete data.', ['notification' => $notification, 'callStack' => System::callstack(20)]);
|
||||
|
||||
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
$obj = XML::parseString($xmlHead . $notify['object']);
|
||||
$notify['fname'] = $obj->title;
|
||||
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
$obj = XML::parseString($xmlHead . $notification['object']);
|
||||
$notification['fname'] = $obj->title;
|
||||
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => 'friend',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is now friends with %s", $notify['author-name'], $notify['fname']),
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notification['author-link'],
|
||||
'text' => $this->l10n->t("%s is now friends with %s", $notification['author-name'], $notification['fname']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$formattedNotify = [
|
||||
$formattedNotification = [
|
||||
'label' => $default_item_label,
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
|
|
@ -346,23 +346,23 @@ final class Notify
|
|||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
'seen' => $notification['seen']
|
||||
];
|
||||
}
|
||||
|
||||
$formattedNotifies[] = $formattedNotify;
|
||||
$formattedNotifications[] = $formattedNotification;
|
||||
}
|
||||
|
||||
return $formattedNotifies;
|
||||
return $formattedNotifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
|
|
@ -372,8 +372,8 @@ final class Notify
|
|||
*/
|
||||
public function getNetworkList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::NETWORK;
|
||||
$notifies = [];
|
||||
$ident = self::NETWORK;
|
||||
$notifications = [];
|
||||
|
||||
$condition = ['wall' => false, 'uid' => local_user()];
|
||||
|
||||
|
|
@ -388,11 +388,11 @@ final class Notify
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
$notifications = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'notifications' => $notifications,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
|
|
@ -402,10 +402,10 @@ final class Notify
|
|||
/**
|
||||
* Get system notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
|
|
@ -415,8 +415,8 @@ final class Notify
|
|||
*/
|
||||
public function getSystemList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::SYSTEM;
|
||||
$notifies = [];
|
||||
$ident = self::SYSTEM;
|
||||
$notifications = [];
|
||||
|
||||
$filter = ['uid' => local_user()];
|
||||
if (!$seen) {
|
||||
|
|
@ -427,17 +427,17 @@ final class Notify
|
|||
$params['order'] = ['date' => 'DESC'];
|
||||
$params['limit'] = [$start, $limit];
|
||||
|
||||
$stmtNotifies = $this->dba->select('notify',
|
||||
$stmtNotifications = $this->dba->select('notify',
|
||||
['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'],
|
||||
$filter,
|
||||
$params);
|
||||
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
$notifies = $this->formatList($this->dba->toArray($stmtNotifies), $ident);
|
||||
if ($this->dba->isResult($stmtNotifications)) {
|
||||
$notifications = $this->formatList($this->dba->toArray($stmtNotifications), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'notifications' => $notifications,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
|
|
@ -447,10 +447,10 @@ final class Notify
|
|||
/**
|
||||
* Get personal notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
|
|
@ -460,8 +460,8 @@ final class Notify
|
|||
*/
|
||||
public function getPersonalList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::PERSONAL;
|
||||
$notifies = [];
|
||||
$ident = self::PERSONAL;
|
||||
$notifications = [];
|
||||
|
||||
$myurl = str_replace('http://', '', DI::app()->contact['nurl']);
|
||||
$diasp_url = str_replace('/profile/', '/u/', $myurl);
|
||||
|
|
@ -480,11 +480,11 @@ final class Notify
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
$notifications = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'notifications' => $notifications,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
|
|
@ -494,10 +494,10 @@ final class Notify
|
|||
/**
|
||||
* Get home notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
|
|
@ -507,8 +507,8 @@ final class Notify
|
|||
*/
|
||||
public function getHomeList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::HOME;
|
||||
$notifies = [];
|
||||
$ident = self::HOME;
|
||||
$notifications = [];
|
||||
|
||||
$condition = ['wall' => true, 'uid' => local_user()];
|
||||
|
||||
|
|
@ -523,11 +523,11 @@ final class Notify
|
|||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
$notifications = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'notifications' => $notifications,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
|
|
@ -553,9 +553,9 @@ final class Notify
|
|||
public function getIntroList(bool $all = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT, int $id = 0)
|
||||
{
|
||||
/// @todo sanitize wording according to SELF::INTRO
|
||||
$ident = 'introductions';
|
||||
$notifies = [];
|
||||
$sql_extra = "";
|
||||
$ident = 'introductions';
|
||||
$notifications = [];
|
||||
$sql_extra = "";
|
||||
|
||||
if (empty($id)) {
|
||||
if (!$all) {
|
||||
|
|
@ -568,7 +568,7 @@ final class Notify
|
|||
}
|
||||
|
||||
/// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
|
||||
$stmtNotifies = $this->dba->p(
|
||||
$stmtNotifications = $this->dba->p(
|
||||
"SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
|
||||
`fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
|
||||
`fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
|
||||
|
|
@ -585,13 +585,13 @@ final class Notify
|
|||
$start,
|
||||
$limit
|
||||
);
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
$notifies = $this->formatIntroList($this->dba->toArray($stmtNotifies));
|
||||
if ($this->dba->isResult($stmtNotifications)) {
|
||||
$notifications = $this->formatIntroList($this->dba->toArray($stmtNotifications));
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'ident' => $ident,
|
||||
'notifications' => $notifies,
|
||||
'notifications' => $notifications,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
|
|
@ -623,7 +623,7 @@ final class Notify
|
|||
|
||||
$intro = [
|
||||
'label' => 'friend_suggestion',
|
||||
'notify_type' => $this->l10n->t('Friend Suggestion'),
|
||||
'str_type' => $this->l10n->t('Friend Suggestion'),
|
||||
'intro_id' => $intro['intro_id'],
|
||||
'madeby' => $intro['name'],
|
||||
'madeby_url' => $intro['url'],
|
||||
|
|
@ -657,7 +657,7 @@ final class Notify
|
|||
}
|
||||
$intro = [
|
||||
'label' => (($intro['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
|
||||
'notify_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
|
||||
'str_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
|
||||
'dfrn_id' => $intro['issued-id'],
|
||||
'uid' => $_SESSION['uid'],
|
||||
'intro_id' => $intro['intro_id'],
|
||||
165
src/Module/BaseNotifications.php
Normal file
165
src/Module/BaseNotifications.php
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module;
|
||||
|
||||
use Exception;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Notification;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
|
||||
/**
|
||||
* Base Module for each tab of the notification display
|
||||
*
|
||||
* General possibility to print it as JSON as well
|
||||
*/
|
||||
abstract class BaseNotifications extends BaseModule
|
||||
{
|
||||
/** @var array Array of URL parameters */
|
||||
const URL_TYPES = [
|
||||
Notification::NETWORK => 'network',
|
||||
Notification::SYSTEM => 'system',
|
||||
Notification::HOME => 'home',
|
||||
Notification::PERSONAL => 'personal',
|
||||
Notification::INTRO => 'intros',
|
||||
];
|
||||
|
||||
/** @var array Array of the allowed notifications and their printable name */
|
||||
const PRINT_TYPES = [
|
||||
Notification::NETWORK => 'Network',
|
||||
Notification::SYSTEM => 'System',
|
||||
Notification::HOME => 'Home',
|
||||
Notification::PERSONAL => 'Personal',
|
||||
Notification::INTRO => 'Introductions',
|
||||
];
|
||||
|
||||
/** @var array The array of access keys for notification pages */
|
||||
const ACCESS_KEYS = [
|
||||
Notification::NETWORK => 'w',
|
||||
Notification::SYSTEM => 'y',
|
||||
Notification::HOME => 'h',
|
||||
Notification::PERSONAL => 'r',
|
||||
Notification::INTRO => 'i',
|
||||
];
|
||||
|
||||
/** @var int The default count of items per page */
|
||||
const ITEMS_PER_PAGE = 20;
|
||||
|
||||
/** @var boolean True, if ALL entries should get shown */
|
||||
protected static $showAll;
|
||||
/** @var int The determined start item of the current page */
|
||||
protected static $firstItemNum;
|
||||
|
||||
/**
|
||||
* Collects all notifications from the backend
|
||||
*
|
||||
* @return array The determined notification array
|
||||
* ['header', 'notifications']
|
||||
*/
|
||||
abstract public static function getNotifications();
|
||||
|
||||
public static function init(array $parameters = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
|
||||
}
|
||||
|
||||
$page = ($_REQUEST['page'] ?? 0) ?: 1;
|
||||
|
||||
self::$firstItemNum = ($page * self::ITEMS_PER_PAGE) - self::ITEMS_PER_PAGE;
|
||||
self::$showAll = ($_REQUEST['show'] ?? '') === 'all';
|
||||
}
|
||||
|
||||
public static function post(array $parameters = [])
|
||||
{
|
||||
$request_id = DI::args()->get(1);
|
||||
|
||||
if ($request_id === 'all') {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($request_id) {
|
||||
$intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
|
||||
|
||||
switch ($_POST['submit']) {
|
||||
case DI::l10n()->t('Discard'):
|
||||
$intro->discard();
|
||||
break;
|
||||
case DI::l10n()->t('Ignore'):
|
||||
$intro->ignore();
|
||||
break;
|
||||
}
|
||||
|
||||
DI::baseUrl()->redirect('notifications/intros');
|
||||
}
|
||||
}
|
||||
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
// If the last argument of the query is NOT json, return
|
||||
if (DI::args()->get(DI::args()->getArgc() - 1) !== 'json') {
|
||||
return;
|
||||
}
|
||||
|
||||
System::jsonExit(static::getNotifications()['notifs'] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the printable result of notifications for a specific tab
|
||||
*
|
||||
* @param string $header The notification header
|
||||
* @param array $notifications The array with the notifications
|
||||
* @param string $noContent The string in case there are no notifications
|
||||
* @param array $showLink The possible links at the top
|
||||
*
|
||||
* @return string The rendered output
|
||||
*
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
protected static function printContent(string $header, array $notifications, string $noContent, array $showLink)
|
||||
{
|
||||
// Get the nav tabs for the notification pages
|
||||
$tabs = self::getTabs();
|
||||
|
||||
// Set the pager
|
||||
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
|
||||
|
||||
$notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl');
|
||||
return Renderer::replaceMacros($notif_tpl, [
|
||||
'$header' => $header ?? DI::l10n()->t('Notifications'),
|
||||
'$tabs' => $tabs,
|
||||
'$notifications' => $notifications,
|
||||
'$noContent' => $noContent,
|
||||
'$showLink' => $showLink,
|
||||
'$paginate' => $pager->renderMinimal(count($notifications))
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* List of pages for the Notifications TabBar
|
||||
*
|
||||
* @return array with with notifications TabBar data
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getTabs()
|
||||
{
|
||||
$selected = DI::args()->get(1, '');
|
||||
|
||||
$tabs = [];
|
||||
|
||||
foreach (self::URL_TYPES as $type => $url) {
|
||||
$tabs[] = [
|
||||
'label' => DI::l10n()->t(self::PRINT_TYPES[$type]),
|
||||
'url' => 'notifications/' . $url,
|
||||
'sel' => (($selected == $url) ? 'active' : ''),
|
||||
'id' => $type . '-tab',
|
||||
'accesskey' => self::ACCESS_KEYS[$type],
|
||||
];
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
}
|
||||
194
src/Module/Notifications/Introductions.php
Normal file
194
src/Module/Notifications/Introductions.php
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Notifications;
|
||||
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseNotifications;
|
||||
|
||||
/**
|
||||
* Prints notifications about introduction
|
||||
*/
|
||||
class Introductions extends BaseNotifications
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function getNotifications()
|
||||
{
|
||||
$id = (int)DI::args()->get(2, 0);
|
||||
$all = DI::args()->get(2) == 'all';
|
||||
|
||||
$notifications = DI::notification()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id);
|
||||
|
||||
return [
|
||||
'header' => DI::l10n()->t('Notifications'),
|
||||
'notifications' => $notifications,
|
||||
];
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
Nav::setSelected('introductions');
|
||||
|
||||
$all = DI::args()->get(2) == 'all';
|
||||
|
||||
$notificationContent = [];
|
||||
$notificationNoContent = '';
|
||||
|
||||
$notificationResult = self::getNotifications();
|
||||
$notifications = $notificationResult['notifications'] ?? [];
|
||||
$notificationHeader = $notificationResult['header'] ?? '';
|
||||
|
||||
$notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
|
||||
$notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
|
||||
|
||||
// The link to switch between ignored and normal connection requests
|
||||
$notificationShowLink = [
|
||||
'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
|
||||
'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests'))
|
||||
];
|
||||
|
||||
// Loop through all introduction notifications.This creates an array with the output html for each
|
||||
// introduction
|
||||
foreach ($notifications['notifications'] as $notification) {
|
||||
|
||||
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
||||
// We have to distinguish between these two because they use different data.
|
||||
switch ($notification['label']) {
|
||||
case 'friend_suggestion':
|
||||
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
|
||||
'$type' => $notification['label'],
|
||||
'str_notification_type' => DI::l10n()->t('Notification type:'),
|
||||
'str_type' => $notification['str_type'],
|
||||
'$intro_id' => $notification['intro_id'],
|
||||
'$lbl_madeby' => DI::l10n()->t('Suggested by:'),
|
||||
'$madeby' => $notification['madeby'],
|
||||
'$madeby_url' => $notification['madeby_url'],
|
||||
'$madeby_zrl' => $notification['madeby_zrl'],
|
||||
'$madeby_addr' => $notification['madeby_addr'],
|
||||
'$contact_id' => $notification['contact_id'],
|
||||
'$photo' => $notification['photo'],
|
||||
'$fullname' => $notification['name'],
|
||||
'$url' => $notification['url'],
|
||||
'$zrl' => $notification['zrl'],
|
||||
'$lbl_url' => DI::l10n()->t('Profile URL'),
|
||||
'$addr' => $notification['addr'],
|
||||
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
|
||||
'$knowyou' => $notification['knowyou'],
|
||||
'$approve' => DI::l10n()->t('Approve'),
|
||||
'$note' => $notification['note'],
|
||||
'$request' => $notification['request'],
|
||||
'$ignore' => DI::l10n()->t('Ignore'),
|
||||
'$discard' => DI::l10n()->t('Discard'),
|
||||
]);
|
||||
break;
|
||||
|
||||
// Normal connection requests
|
||||
default:
|
||||
$friend_selected = (($notification['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
|
||||
$fan_selected = (($notification['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
|
||||
|
||||
$lbl_knowyou = '';
|
||||
$knowyou = '';
|
||||
$helptext = '';
|
||||
$helptext2 = '';
|
||||
$helptext3 = '';
|
||||
|
||||
if ($notification['network'] === Protocol::DFRN) {
|
||||
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
|
||||
$knowyou = (($notification['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
|
||||
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
|
||||
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
|
||||
$helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
|
||||
} elseif ($notification['network'] === Protocol::DIASPORA) {
|
||||
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
|
||||
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
|
||||
$helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
|
||||
}
|
||||
|
||||
$dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl');
|
||||
$dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
|
||||
'$intro_id' => $notification['intro_id'],
|
||||
'$friend_selected' => $friend_selected,
|
||||
'$fan_selected' => $fan_selected,
|
||||
'$approve_as1' => $helptext,
|
||||
'$approve_as2' => $helptext2,
|
||||
'$approve_as3' => $helptext3,
|
||||
'$as_friend' => DI::l10n()->t('Friend'),
|
||||
'$as_fan' => (($notification['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
|
||||
]);
|
||||
|
||||
$contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification['contact_id']]);
|
||||
|
||||
if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
|
||||
$action = 'follow_confirm';
|
||||
} else {
|
||||
$action = 'dfrn_confirm';
|
||||
}
|
||||
|
||||
$header = $notification['name'];
|
||||
|
||||
if ($notification['addr'] != '') {
|
||||
$header .= ' <' . $notification['addr'] . '>';
|
||||
}
|
||||
|
||||
$header .= ' (' . ContactSelector::networkToName($notification['network'], $notification['url']) . ')';
|
||||
|
||||
if ($notification['network'] != Protocol::DIASPORA) {
|
||||
$discard = DI::l10n()->t('Discard');
|
||||
} else {
|
||||
$discard = '';
|
||||
}
|
||||
|
||||
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
|
||||
'$type' => $notification['label'],
|
||||
'$header' => $header,
|
||||
'str_notification_type' => DI::l10n()->t('Notification type:'),
|
||||
'str_type' => $notification['notifytype'],
|
||||
'$dfrn_text' => $dfrn_text,
|
||||
'$dfrn_id' => $notification['dfrn_id'],
|
||||
'$uid' => $notification['uid'],
|
||||
'$intro_id' => $notification['intro_id'],
|
||||
'$contact_id' => $notification['contact_id'],
|
||||
'$photo' => $notification['photo'],
|
||||
'$fullname' => $notification['name'],
|
||||
'$location' => $notification['location'],
|
||||
'$lbl_location' => DI::l10n()->t('Location:'),
|
||||
'$about' => $notification['about'],
|
||||
'$lbl_about' => DI::l10n()->t('About:'),
|
||||
'$keywords' => $notification['keywords'],
|
||||
'$lbl_keywords' => DI::l10n()->t('Tags:'),
|
||||
'$gender' => $notification['gender'],
|
||||
'$lbl_gender' => DI::l10n()->t('Gender:'),
|
||||
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
|
||||
'$url' => $notification['url'],
|
||||
'$zrl' => $notification['zrl'],
|
||||
'$lbl_url' => DI::l10n()->t('Profile URL'),
|
||||
'$addr' => $notification['addr'],
|
||||
'$lbl_knowyou' => $lbl_knowyou,
|
||||
'$lbl_network' => DI::l10n()->t('Network:'),
|
||||
'$network' => ContactSelector::networkToName($notification['network'], $notification['url']),
|
||||
'$knowyou' => $knowyou,
|
||||
'$approve' => DI::l10n()->t('Approve'),
|
||||
'$note' => $notification['note'],
|
||||
'$ignore' => DI::l10n()->t('Ignore'),
|
||||
'$discard' => $discard,
|
||||
'$action' => $action,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($notifications['notifications']) == 0) {
|
||||
info(DI::l10n()->t('No introductions.') . EOL);
|
||||
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
|
||||
}
|
||||
|
||||
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,9 @@ use Friendica\DI;
|
|||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* Interacting with the /notify command
|
||||
* Interacting with the /notification command
|
||||
*/
|
||||
class Notify extends BaseModule
|
||||
class Notification extends BaseModule
|
||||
{
|
||||
public static function init(array $parameters = [])
|
||||
{
|
||||
|
|
@ -21,11 +21,9 @@ class Notify extends BaseModule
|
|||
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
|
||||
$success = DI::notify()->setAllSeen();
|
||||
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
|
||||
$success = DI::notification()->setAllSeen();
|
||||
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
echo json_encode([
|
||||
|
|
@ -36,22 +34,20 @@ class Notify extends BaseModule
|
|||
}
|
||||
|
||||
/**
|
||||
* Redirect to the notifications main page or to the url for the chosen notify
|
||||
* Redirect to the notifications main page or to the url for the chosen notifications
|
||||
*
|
||||
* @return string|void
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
$a = DI::app();
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
|
||||
$notificationsManager = DI::notify();
|
||||
if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
|
||||
$notificationManager = DI::notification();
|
||||
// @TODO: Replace with parameter from router
|
||||
$note = $notificationsManager->getByID($a->argv[2]);
|
||||
$note = $notificationManager->getByID(DI::args()->get(2));
|
||||
if (!empty($note)) {
|
||||
$notificationsManager->setSeen($note);
|
||||
$notificationManager->setSeen($note);
|
||||
if (!empty($note['link'])) {
|
||||
System::externalRedirect($note['link']);
|
||||
}
|
||||
118
src/Module/Notifications/Notifications.php
Normal file
118
src/Module/Notifications/Notifications.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Module\Notifications;
|
||||
|
||||
use Friendica\Content\Nav;
|
||||
use Friendica\Content\Pager;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseNotifications;
|
||||
|
||||
/**
|
||||
* Prints all notification types except introduction:
|
||||
* - Network
|
||||
* - System
|
||||
* - Personal
|
||||
* - Home
|
||||
*/
|
||||
class Notifications extends BaseNotifications
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getNotifications()
|
||||
{
|
||||
$nm = DI::notification();
|
||||
|
||||
$notificationHeader = '';
|
||||
|
||||
// Get the network notifications
|
||||
if ((DI::args()->get(1) == 'network')) {
|
||||
$notificationHeader = DI::l10n()->t('Network Notifications');
|
||||
$notifications = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
||||
|
||||
// Get the system notifications
|
||||
} elseif ((DI::args()->get(1) == 'system')) {
|
||||
$notificationHeader = DI::l10n()->t('System Notifications');
|
||||
$notifications = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
||||
|
||||
// Get the personal notifications
|
||||
} elseif ((DI::args()->get(1) == 'personal')) {
|
||||
$notificationHeader = DI::l10n()->t('Personal Notifications');
|
||||
$notifications = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
||||
|
||||
// Get the home notifications
|
||||
} elseif ((DI::args()->get(1) == 'home')) {
|
||||
$notificationHeader = DI::l10n()->t('Home Notifications');
|
||||
$notifications = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
|
||||
// fallback - redirect to main page
|
||||
} else {
|
||||
DI::baseUrl()->redirect('notifications');
|
||||
}
|
||||
|
||||
// Set the pager
|
||||
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
|
||||
|
||||
// Add additional informations (needed for json output)
|
||||
$notifications['items_page'] = $pager->getItemsPerPage();
|
||||
$notifications['page'] = $pager->getPage();
|
||||
|
||||
return [
|
||||
'header' => $notificationHeader,
|
||||
'notifications' => $notifications,
|
||||
];
|
||||
}
|
||||
|
||||
public static function content(array $parameters = [])
|
||||
{
|
||||
Nav::setSelected('notifications');
|
||||
|
||||
$notificationContent = [];
|
||||
$notificationNoContent = '';
|
||||
|
||||
$notificationResult = self::getNotifications();
|
||||
$notifications = $notificationResult['notifications'] ?? [];
|
||||
$notificationHeader = $notificationResult['header'] ?? '';
|
||||
|
||||
|
||||
if (!empty($notifications['notifications'])) {
|
||||
// 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).
|
||||
foreach ($notifications['notifications'] as $notification) {
|
||||
$notification_templates = [
|
||||
'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',
|
||||
];
|
||||
|
||||
$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'],
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
|
||||
}
|
||||
|
||||
$notificationShowLink = [
|
||||
'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
|
||||
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
|
||||
];
|
||||
|
||||
return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue