1<?php 2// must be run within DokuWiki 3if (!defined('DOKU_INC')) die(); 4 5/** 6 * All DokuWiki plugins to extend the parser/rendering mechanism 7 * need to inherit from this class 8 */ 9class action_plugin_ireadit_notification extends DokuWiki_Action_Plugin 10{ 11 public function register(Doku_Event_Handler $controller) 12 { 13 $controller->register_hook('PLUGIN_NOTIFICATION_REGISTER_SOURCE', 'AFTER', $this, 'add_notifications_source'); 14 $controller->register_hook('PLUGIN_NOTIFICATION_GATHER', 'AFTER', $this, 'add_notifications'); 15 $controller->register_hook('PLUGIN_NOTIFICATION_CACHE_DEPENDENCIES', 'AFTER', $this, 'add_notification_cache_dependencies'); 16 } 17 18 public function add_notifications_source(Doku_Event $event) 19 { 20 $event->data[] = 'ireadit'; 21 } 22 23 public function add_notification_cache_dependencies(Doku_Event $event) 24 { 25 if (!in_array('ireadit', $event->data['plugins'])) return; 26 $event->data['_nocache'] = true; // TODO: notification cache mechanism should be updated to "Igor" dokuwiki 27 } 28 29 public function add_notifications(Doku_Event $event) 30 { 31 if (!in_array('ireadit', $event->data['plugins'])) return; 32 33 $user = $event->data['user']; 34 35 /** @var helper_plugin_ireadit $helper */ 36 $helper = $this->loadHelper('ireadit'); 37 $pages = $helper->get_list($user); 38 39 foreach ($pages as $page => $row) { 40 if ($row['state'] == 'read') continue; 41 42 $link = '<a class="wikilink1" href="' . wl($page, '', true) . '">'; 43 if (useHeading('content')) { 44 $heading = p_get_first_heading($page); 45 if (!blank($heading)) { 46 $link .= $heading; 47 } else { 48 $link .= noNSorNS($page); 49 } 50 } else { 51 $link .= noNSorNS($page); 52 } 53 $link .= '</a>'; 54 $full = sprintf($this->getLang('notification full'), $link); 55 $event->data['notifications'][] = [ 56 'plugin' => 'ireadit', 57 'id' => $page . ':' . $row['current_rev'], 58 'full' => $full, 59 'brief' => $link, 60 'timestamp' => (int) $row['current_rev'] 61 ]; 62 } 63 } 64} 65