register_hook('PLUGIN_NOTIFICATION_REGISTER_SOURCE', 'AFTER', $this, 'add_notifications_source'); $controller->register_hook('PLUGIN_NOTIFICATION_GATHER', 'AFTER', $this, 'add_notifications'); $controller->register_hook('PLUGIN_NOTIFICATION_CACHE_DEPENDENCIES', 'AFTER', $this, 'add_notification_cache_dependencies'); } public function add_notifications_source(Doku_Event $event) { $event->data[] = 'ireadit'; } public function add_notification_cache_dependencies(Doku_Event $event) { if (!in_array('ireadit', $event->data['plugins'])) return; try { /** @var \helper_plugin_ireadit_db $db_helper */ $db_helper = plugin_load('helper', 'ireadit_db'); $sqlite = $db_helper->getDB(); $event->data['dependencies'][] = $sqlite->getAdapter()->getDbFile(); } catch (Exception $e) { msg($e->getMessage(), -1); return; } } public function add_notifications(Doku_Event $event) { if (!in_array('ireadit', $event->data['plugins'])) return; try { /** @var \helper_plugin_ireadit_db $db_helper */ $db_helper = plugin_load('helper', 'ireadit_db'); $sqlite = $db_helper->getDB(); } catch (Exception $e) { msg($e->getMessage(), -1); return; } $user = $event->data['user']; $res = $sqlite->query('SELECT page, rev FROM ireadit WHERE timestamp IS NULL AND user = ? ORDER BY timestamp', $user); $notifications = $sqlite->res2arr($res); foreach ($notifications as $notification) { $page = $notification['page']; $rev = $notification['rev']; $link = ''; if (useHeading('content')) { $heading = p_get_first_heading($page); if (!blank($heading)) { $link .= $heading; } else { $link .= noNSorNS($page); } } else { $link .= noNSorNS($page); } $link .= ''; $full = sprintf($this->getLang('notification full'), $link); $event->data['notifications'][] = [ 'plugin' => 'ireadit', 'id' => $page . ':' . $rev, 'full' => $full, 'brief' => $link, 'timestamp' => (int)$rev ]; } } }