1<?php 2 3// must be run within Dokuwiki 4if (!defined('DOKU_INC')) { 5 die(); 6} 7 8class action_plugin_sitemapnavi_ajax extends DokuWiki_Action_Plugin 9{ 10 /** 11 * Registers a callback function for a given event 12 * 13 * @param Doku_Event_Handler $controller DokuWiki's event controller object 14 * @return void 15 */ 16 public function register(Doku_Event_Handler $controller) 17 { 18 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax'); 19 $controller->register_hook('DOKUWIKI_STARTED', 'BEFORE', $this, 'markAsAvailableInJSINFO'); 20 } 21 22 /** 23 * Let js know that this plugin exists 24 */ 25 public function markAsAvailableInJSINFO() { 26 global $JSINFO; 27 if (empty($JSINFO['plugins'])) { 28 $JSINFO['plugins'] = []; 29 } 30 $JSINFO['plugins']['sitemapnavi'] = true; 31 } 32 33 /** 34 * Pass Ajax call to a type 35 * 36 * @param Doku_Event $event event object by reference 37 * @param mixed $param [the parameters passed as fifth argument to register_hook() when this 38 * handler was registered] 39 */ 40 public function handle_ajax(Doku_Event $event, $param) 41 { 42 if ($event->data !== 'plugin__sitemapnavi') { 43 return; 44 } 45 $event->preventDefault(); 46 $event->stopPropagation(); 47 48 // get namespace 49 global $INPUT, $INFO; 50 51 if (empty($INFO)) { 52 $INFO = [ 53 'id' => getID(), 54 'namespace' => getNS(getID()) 55 ]; 56 } 57 $ns = $INPUT->str('namespace'); 58 59 /** @var helper_plugin_sitemapnavi $helper */ 60 $helper = $this->loadHelper('sitemapnavi'); 61 echo $helper->getSiteMap($ns); 62 } 63} 64