function getContent($params = array()) { $this->gatekeeper(); $user = Idno::site()->session()->currentUser(); $limit = 10; $offset = $this->getInput('offset', 0); $notifs = Notification::getFromX('Idno\\Entities\\Notification', ['owner' => $user->getUUID()], [], $limit, $offset); $count = Notification::countFromX('Idno\\Entities\\Notification', ['owner' => $user->getUUID()]); $body = Idno::site()->template()->__(['user' => $user, 'notifications' => $notifs, 'count' => $count])->draw('account/notifications'); $page = Idno::site()->template()->__(['title' => 'Notifications', 'body' => $body])->drawPage(false); // mark all notifications as seen foreach ($notifs as $notif) { $notif->markRead(); $notif->save(); } echo $page; }
function getContent($params = array()) { $this->gatekeeper(); $user = Idno::site()->session()->currentUser(); $last_time = $user->last_notification_time; if (!$last_time) { $last_time = 0; } $notifs = Notification::getFromX('Idno\\Entities\\Notification', ['owner' => $user->getUUID()]); $notifs = array_filter($notifs, function ($notif) use($last_time) { return $notif->created > $last_time; }); if ($notifs) { $user->last_notification_time = $notifs[0]->created; $user->save(); } $arr = array_map(function ($notif) { Idno::site()->template()->setTemplateType('email-text'); $body = Idno::site()->template()->__(['notification' => $notif])->draw($notif->getMessageTemplate()); return ['title' => $notif->getMessage(), 'body' => $body, 'created' => date('c', $notif->created)]; }, $notifs); Idno::site()->template()->setTemplateType('json'); Idno::site()->template()->__(['notifications' => $arr])->drawPage(); }
/** * Look up the number of unread notifications for this user * * @return integer */ public function countUnreadNotifications() { $count = Notification::countFromX('Idno\\Entities\\Notification', ['owner' => $this->getUUID(), 'read' => false]); return $count; }
/** * A webmention to our profile page means someone mentioned us. */ function webmentionContent($source, $target, $source_response, $source_mf2) { Idno::site()->logging()->info("received user mention from {$source} to {$target}"); if (empty($this->arguments)) { Idno::site()->logging()->debug("could not process user mention, no pagehandler arguments"); return false; } $user = User::getByHandle($this->arguments[0]); if (empty($user)) { Idno::site()->logging()->debug('could not process user mention, no user for handle ' . $this->arguments[0]); return false; } Idno::site()->logging()->debug("found target user {$user->getHandle()}"); // if this is anything other than a normal mention (e.g. a delete), accept the wm, but do nothing if ($source_response['response'] !== 200) { return true; } $title = Webmention::getTitleFromContent($source_response['content'], $source); $mention = ['permalink' => $source, 'title' => $title]; // look for the first and only h-entry or h-event on the page $entry = Webmention::findRepresentativeHEntry($source_mf2, $source, ['h-entry', 'h-event']); $card = Webmention::findAuthorHCard($source_mf2, $source, $entry); // try to get some more specific details of the mention from mf2 content if ($entry) { if (!empty($entry['properties']['url'])) { $mention['permalink'] = $entry['properties']['url'][0]; } if (!empty($entry['properties']['content'])) { $content = $entry['properties']['content'][0]; $mention['content'] = Idno::site()->template()->sanitize_html(is_array($content) ? $content['html'] : $content); } } $sender_url = false; if ($card) { if (!empty($card['properties']['url'])) { $sender_url = $card['properties']['url'][0]; $mention['owner_url'] = $card['properties']['url'][0]; } if (!empty($card['properties']['name'])) { $mention['owner_name'] = $card['properties']['name'][0]; } } $message = 'You were mentioned'; if (isset($mention['owner_name'])) { $message .= ' by ' . $mention['owner_name']; } $message .= ' on ' . parse_url($mention['permalink'], PHP_URL_HOST); $notif = new Notification(); if ($notif->setNotificationKey(['mention', $user->getUUID(), $source, $target])) { $notif->setOwner($user); $notif->setMessage($message); $notif->setMessageTemplate('content/notification/mention'); $notif->setActor($sender_url); $notif->setVerb('mention'); $notif->setObject($mention); $notif->setTarget($user); $notif->save(); $user->notify($notif); } else { \Idno\Core\Idno::site()->logging()->debug("ignoring duplicate notification", ['source' => $source, 'target' => $target, 'user' => $user->getHandle()]); } return true; }