3 * AJAX Backend for indexmenu
5 * @author Samuele Tognini <samuele@netsons.org>
6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
9 //fix for Opera XMLHttpRequests
10 if(!count($_POST) && @$HTTP_RAW_POST_DATA){
11 parse_str($HTTP_RAW_POST_DATA, $_POST);
14 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__
).'/../../../').'/');
15 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC
.'lib/plugins/');
16 require_once(DOKU_INC
.'inc/init.php');
17 require_once(DOKU_INC
.'inc/auth.php');
18 if(!defined('INDEXMENU_IMG_ABSDIR')) define('INDEXMENU_IMG_ABSDIR',DOKU_PLUGIN
."indexmenu/images");
20 session_write_close();
22 $ajax_indexmenu=new ajax_indexmenu_plugin
;
23 $ajax_indexmenu->render();
25 class ajax_indexmenu_plugin
{
29 * @author Samuele Tognini <samuele@netsons.org>
33 $req=$_REQUEST['req'];
36 if ($req == 'send' and isset($_REQUEST['t'])) {
37 include(DOKU_PLUGIN
.'indexmenu/inc/repo.class.php');
38 $repo=new repo_indexmenu_plugin
;
39 $succ=$repo->send_theme($_REQUEST['t']);
41 if ($succ) return true;
43 header('Content-Type: text/html; charset=utf-8');
44 header('Cache-Control: public, max-age=3600');
45 header('Pragma: public');
49 print $this->local_themes();
53 if (isset($_REQUEST['id'])) print $this->print_toc($_REQUEST['id']);
57 if (isset($_REQUEST['idx'])) print $this->print_index($_REQUEST['idx']);
63 * Print a list of local themes
65 * @author Samuele Tognini <samuele@netsons.org>
68 function local_themes() {
69 $list='indexmenu,'.DOKU_URL
.",lib/plugins/indexmenu/images,";
71 $handle=@opendir
(INDEXMENU_IMG_ABSDIR
);
72 while (false !== ($file = readdir($handle))) {
73 if ( is_dir (INDEXMENU_IMG_ABSDIR
.'/'.$file)
76 && $file != "repository"
84 $list .= implode(",",$data);
91 * @author Samuele Tognini <samuele@netsons.org>
92 * @author Andreas Gohr <andi@splitbrain.org>
94 function print_toc($id) {
95 require_once(DOKU_INC
.'inc/parser/xhtml.php');
97 if (auth_quickaclcheck($id) < AUTH_READ
) return;
98 $meta = p_get_metadata($id);
99 $toc = $meta['description']['tableofcontents'];
100 $out .= '<div class="tocheader toctoggle">'.DOKU_LF
;
102 $out .= $this->render_toc($toc);
104 $out .= '<a href="'.wl($id).'">';
105 $out .= ($meta['title']) ?
htmlspecialchars($meta['title']) : htmlspecialchars(noNS($id));
106 $out .= '</a>'.DOKU_LF
;
107 if ($meta['description']['abstract']) {
108 $out .= '</div>'.DOKU_LF
;
109 $out .= '<div class="indexmenu_toc_inside">'.DOKU_LF
;
110 $out .= p_render('xhtml',p_get_instructions($meta['description']['abstract']),$info);
111 $out .= '</div>'.DOKU_LF
;
114 $out .= '</div>'.DOKU_LF
;
119 * Return the TOC rendered to XHTML
121 * @author Andreas Gohr <andi@splitbrain.org>
123 function render_toc($toc){
125 $r = new Doku_Renderer_xhtml
;
127 $out .= $lang['toc'];
128 $out .= '</div>'.DOKU_LF
;
129 $out .= '<div class="indexmenu_toc_inside">'.DOKU_LF
;
130 $out .= html_buildlist($r->toc
,'toc',array($this,'_tocitem'));
131 $out .= '</div>'.DOKU_LF
;
136 * Callback for html_buildlist
138 function _tocitem($item){
139 $id=cleanID($_POST['id']);
140 return '<span class="li"><a href="'.wl($id,'#'.$item['hid'],false,'').'" class="toc">'.
141 htmlspecialchars($item['title']).'</a></span>';
147 * @author Samuele Tognini <samuele@netsons.org>
148 * @author Andreas Gohr <andi@splitbrain.org>
150 function print_index($ns) {
151 require_once(DOKU_PLUGIN
.'indexmenu/syntax/indexmenu.php');
153 $idxm=new syntax_plugin_indexmenu_indexmenu();
154 $ns=$idxm->_parse_ns($ns);
158 if ($_REQUEST['max'] > 0) {
159 $max=$_REQUEST['max'];
162 $nss= ($_REQUEST['nss']) ?
cleanID($_REQUEST['nss']) : '';
163 $idxm->sort
=$_REQUEST['sort'];
164 $idxm->msort
=$_REQUEST['msort'];
165 $idxm->rsort
=$_REQUEST['rsort'];
166 $idxm->nsort
=$_REQUEST['nsort'];
167 $fsdir="/".utf8_encodeFN(str_replace(':','/',$ns));
168 $opts= array('level' => $level,
169 'nons' => $_REQUEST['nons'],
170 'nss' => array(array($nss,1)),
173 'nopg' => $_REQUEST['nopg'],
174 'skip_index' => $idxm->getConf('skip_index'),
175 'skip_file' => $idxm->getConf('skip_file'),
176 'headpage' => $idxm->getConf('headpage'),
177 'hide_headpage' => $idxm->getConf('hide_headpage')
179 if ($idxm->sort||
$idxm->msort||
$idxm->rsort
) {
180 $idxm->_search($data,$conf['datadir'],array($idxm,'_search_index'),$opts,$fsdir);
182 search($data,$conf['datadir'],array($idxm,'_search_index'),$opts,$fsdir);
184 if ($_REQUEST['nojs']) {
185 require_once(DOKU_INC
.'inc/html.php');
186 $out_tmp=html_buildlist($data,'idx',array($idxm,"_html_list_index"),"html_li_index");
187 $out.=preg_replace('/<ul class="idx">(.*)<\/ul>/s',"$1",$out_tmp);
189 $nodes=$idxm->_jsnodes($data,'',0);
191 $out.=rtrim($nodes[0],",");