* */ //fix for Opera XMLHttpRequests if(!count($_POST) && $HTTP_RAW_POST_DATA){ parse_str($HTTP_RAW_POST_DATA, $_POST); } if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/pageutils.php'); require_once(DOKU_INC.'inc/auth.php'); require_once(DOKU_INC.'inc/JSON.php'); //close session session_write_close(); // check, if user is admin (or at least manager) if (! auth_ismanager()) { exit; } if ($_POST["q"] == "namespaces") { get_namespace_list(); } elseif ($_POST["q"] == "pages") { get_pages_list(); } function get_namespace_list() { $ID = $_POST["pageid"]; $selid = $_POST["selid"]; $opt = array(); // all namespace $namespaces = get_namespaces(); // add namespaces of current page to the list of namespaces (even if the namespaces doesn't exist yet for($ns_id = getNS($ID); $ns_id !== false; $ns_id = getNS($ns_id)){ if (!in_array($ns_id,$namespaces)) $namespaces[] = $ns_id; } sort($namespaces); $namespaces = array_reverse($namespaces); foreach ($namespaces as $ns_id) { $opt[] = array('value'=> $ns_id, 'text'=> $ns_id.':*'); if ($ns_id == $selid) { // set sel on current selected namespcase $opt[count($opt)-1]['sel'] = true; } } $opt[] = array('value'=> '*', 'text'=> '*'); // flip options $opt = array_reverse($opt); /* now construct a json */ $json = new JSON(); //header('Content-Type: application/json'); header('Content-Type: text/javascript'); print $json->encode($opt); } function get_pages_list() { $id = $_POST["aclid"]; $selected_id = $_POST["selid"]; $opt = array(); $pages = array_reverse(get_pages($id)); // add pages in list foreach ($pages as $page_id) { $page_id = ($id != '*' ? $id . ':' : '') . $page_id; $opt[] = array( 'value'=> $page_id, 'text'=> $page_id.' ('.$_POST['page_text'].')' ); if ($page_id == $selected_id) $opt[count($opt)-1]['sel'] = true; } // additional namespaces for(; $id !== false && $id != '*'; $id=getNS($id)){ $opt[] = array('value'=> $id.':*', 'text'=> $id.':* ('.$_POST['ns_text'].')'); if ($id.':*' == $selected_id) $opt[count($opt)-1]['sel'] = true; } // the top namespace $opt[] = array('value'=> '*', 'text'=> '* ('.$_POST['ns_text'].')'); // flip options $opt = array_reverse($opt); /* now construct a json */ $json = new JSON(); //header('Content-Type: application/json'); header('Content-Type: text/javascript'); print $json->encode($opt); } function get_pages($tns='') { return _getlist($tns,false,false,true); } function get_namespaces($tns='') { return _getlist($tns,true,true,false); } // inspired from addnewpageplugin: function _getlist ($tns='',$recursive = true, $namespaces=true,$pages=false) { require_once(DOKU_INC.'inc/search.php'); global $conf; if ($tns == '*') $tns = ''; if (!is_dir($tns)) $tns = str_replace(':','/',$tns); $data = array(); search($data,$conf['datadir'] ."/" . $tns,'search_index',array('ns' => '')); $data2 = array(); foreach($data as $k => $v) { if ($v['type']=='d') { //Namespace if ($namespaces) array_push($data2,$v['id']); if ($recursive) { $r=_getlist($tns.'/'.$v['id'],$recursive,$namespaces,$pages); foreach ($r as $vv) { array_push($data2,$v['id'].':'.$vv); } } } elseif ($v['type']=='f') { //Page if ($pages) array_push($data2,$v['id']); } } return $data2; } ?>