1<?php
2/**
3 *  Indexmenu Action component
4 *
5 *  $Id: action.php 113 2009-01-13 16:24:03Z wingedfox $
6 *  $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/Indexmenu2/tags/Indexmenu2.v2.1.2/action.php $
7 *
8 *  @lastmodified $Date: 2009-01-13 19:24:03 +0300 (Втр, 13 Янв 2009) $
9 *  @license      LGPL 2 (http://www.gnu.org/licenses/lgpl.html)
10 *  @author       Ilya Lebedev <ilya@lebedev.net>
11 *  @version      $Rev: 113 $
12 *  @copyright    (c) 2005-2007, Ilya Lebedev
13 */
14
15if(!defined('DOKU_INC')) die();
16if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
17require_once(DOKU_PLUGIN.'action.php');
18
19class action_plugin_indexmenu extends DokuWiki_Action_Plugin {
20
21  /**
22   * return some info
23   */
24  function getInfo(){
25      preg_match("#^.*?Indexmenu2/([^\\/]+)#"," $HeadURL: https://svn.debugger.ru/repos/common/DokuWiki/Indexmenu2/tags/Indexmenu2.v2.1.2/action.php $ ", $v);
26      $v = preg_replace("#.*?((trunk|.v)[\d.]+)#","\\1",$v[1]);
27      $b = preg_replace("/\\D/","", " $Rev: 113 $ ");
28      return array( 'author' => "Ilya Lebedev"
29                   ,'email'  => 'ilya@lebedev.net'
30                   ,'date'   => preg_replace("#.*?(\d{4}-\d{2}-\d{2}).*#","\\1",'$Date: 2009-01-13 19:24:03 +0300 (Втр, 13 Янв 2009) $')
31                   ,'name'   => "Indexmenu 2 {$v}.$b Action component."
32                   ,'desc'   => "Performs special Indexmenu actions."
33                   ,'url'    => 'https://www.dokuwiki.org/plugin:indexmenu2'
34                  );
35  }
36
37  /*
38   * plugin should use this method to register its handlers with the dokuwiki's event controller
39   */
40  function register(&$controller) {
41      $controller->register_hook('TPL_METAHEADER_OUTPUT','BEFORE', $this, '_inject_loader');
42      $controller->register_hook('PARSER_CACHE_USE', 'BEFORE',  $this, '_purgecache');
43      $r = $this->getConf('replace_idx');
44      if (@$r) {
45          $controller->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'html_index_replacement');
46      }
47  }
48
49  /**
50   *  Inject the virtual keyboard loaders
51   *
52   *  @author Ilya Lebedev <ilya@lebedev.net>
53   *  @param $event object target event
54   *  @param $param mixed event parameters passed from register_hook
55   */
56  function _inject_loader (&$event, $param) {
57      global $INFO;
58      global $ACT;
59
60      if ($ACT != 'show' && $ACT != 'preview') return; // nothing to do for us
61
62      $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', 'src' => DOKU_BASE.'/lib/plugins/indexmenu/cms/cms.js'
63                                       ,'_data'=>'');
64  }
65
66  /**
67   * Check for pages changes and eventually purge cache.
68   *
69   * @author Samuele Tognini <samuele@cli.di.unipi.it>
70   * @author Ilya Lebedev <ilya@lebedev.net>
71   */
72  function _purgecache(&$event, $param) {
73    global $ID;
74    global $conf;
75    //purge only xhtml cache
76    if ($event->data->mode != "xhtml") return;
77    //Check if it is an indexmenu page
78    if (!p_get_metadata($ID,'indexmenu')) return;
79    //Check if a page is more recent than purgefile.
80    $event->preventDefault();
81    $event->stopPropagation();
82    $event->result = false;
83  }
84  /**
85   *  Replaces the built-in namespace index with indexmenu one
86   *
87   *  @param mixed $event event object
88   *  @param array $param event params
89   *  @author Ilya Lebedev <ilya@lebedev.net>
90   */
91  function html_index_replacement (&$event, $param) {
92    global $conf;
93    global $ID;
94    global $lang;
95
96    if ('index' != $event->data) return;
97
98    $info = "";
99    $depth = (int)@$this->getConf('replace_idx_depth');
100    if ($depth < 1 || $depth > 10) $depth = 1;
101    $theme = $this->getConf('replace_idx_theme');
102    if (@empty($theme)) $theme = 'IndexMenu';
103    $ajax = 'ajax'==$this->getConf('replace_idx')?"|js#$theme+ajax":'';
104
105    if ($this->getConf('replace_idx_msg')) {
106        echo p_locale_xhtml('index');
107        $instr = "";
108    } else {
109        $instr = "======{$lang['btn_index']}==\n\n";
110    }
111    $instr .= "{{indexmenu>.#$depth$ajax}}";
112    $instr = p_get_instructions($instr);
113    $instr = p_render('xhtml', $instr, $info);
114
115    echo $instr;
116
117    // prevent Dokuwiki normal processing of $ACT (it would clean the variable and destroy our 'index' value.
118    $event->preventDefault();
119    // index command belongs to us, there is no need to hold up Dokuwiki letting other plugins see if its for them
120    $event->stopPropagation();
121
122  }
123}
124