- $formattedNotifies = [];
-
- foreach ($notifications as $notification) {
- // Because we use different db tables for the notification query
- // 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($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 = '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/' . $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 = (($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 ($notification['verb']) {
- case Activity::LIKE:
- $formattedNotify = [
- 'label' => 'like',
- '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' => $notification['seen']
- ];
- break;
-
- case Activity::DISLIKE:
- $formattedNotify = [
- 'label' => 'dislike',
- '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' => $notification['seen']
- ];
- break;
-
- case Activity::ATTEND:
- $formattedNotify = [
- 'label' => 'attend',
- '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' => $notification['seen']
- ];
- break;
-
- case Activity::ATTENDNO:
- $formattedNotify = [
- 'label' => 'attendno',
- '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' => $notification['seen']
- ];
- break;
-
- case Activity::ATTENDMAYBE:
- $formattedNotify = [
- 'label' => 'attendmaybe',
- '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' => $notification['seen']
- ];
- break;
-
- case Activity::FRIEND:
- if (!isset($notification['object'])) {
- $formattedNotify = [
- 'label' => 'friend',
- 'link' => $default_item_link,
- 'image' => $default_item_image,
- 'url' => $default_item_url,
- 'text' => $default_item_text,
- 'when' => $default_item_when,
- 'ago' => $default_item_ago,
- 'seen' => $notification['seen']
- ];
- break;
- }
- /// @todo Check if this part here is used at all
- $this->logger->info('Complete data.', ['notification' => $notification, 'callStack' => System::callstack(20)]);
-
- $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
- $obj = XML::parseString($xmlHead . $notification['object']);
- $notification['fname'] = $obj->title;
-
- $formattedNotify = [
- 'label' => 'friend',
- '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' => $notification['seen']
- ];
- break;
-
- default:
- $formattedNotify = [
- 'label' => $default_item_label,
- 'link' => $default_item_link,
- 'image' => $default_item_image,
- 'url' => $default_item_url,
- 'text' => $default_item_text,
- 'when' => $default_item_when,
- 'ago' => $default_item_ago,
- 'seen' => $notification['seen']
- ];
- }
-
- $formattedNotifies[] = $formattedNotify;