1<?php 2/** 3 * DokuWiki AJAX call handler 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <andi@splitbrain.org> 7 */ 8 9//fix for Opera XMLHttpRequests 10if(!count($_POST) && $HTTP_RAW_POST_DATA){ 11 parse_str($HTTP_RAW_POST_DATA, $_POST); 12} 13 14if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 15require_once(DOKU_INC.'inc/init.php'); 16require_once(DOKU_INC.'inc/common.php'); 17require_once(DOKU_INC.'inc/pageutils.php'); 18require_once(DOKU_INC.'inc/auth.php'); 19//close sesseion 20session_write_close(); 21 22header('Content-Type: text/html; charset=utf-8'); 23 24 25//call the requested function 26if (!isset($_POST['call'])) { return; } 27$call = 'ajax_'.$_POST['call']; 28if(function_exists($call)){ 29 $call(); 30}else{ 31 $call = $_POST['call']; 32 $evt = new Doku_Event('AJAX_CALL_UNKNOWN', $call); 33 if ($evt->advise_before()) { 34 print "AJAX call '".htmlspecialchars($_POST['call'])."' unknown!\n"; 35 } 36 $evt->advise_after(); 37 unset($evt); 38} 39 40/** 41 * Searches for matching pagenames 42 * 43 * @author Andreas Gohr <andi@splitbrain.org> 44 */ 45function ajax_qsearch(){ 46 global $conf; 47 global $lang; 48 49 $query = cleanID($_POST['q']); 50 if(empty($query)) return; 51 52 require_once(DOKU_INC.'inc/html.php'); 53 require_once(DOKU_INC.'inc/fulltext.php'); 54 55 $data = array(); 56 $data = ft_pageLookup($query); 57 58 if(!count($data)) return; 59 60 print '<strong>'.$lang['quickhits'].'</strong>'; 61 print '<ul>'; 62 foreach($data as $id){ 63 print '<li>'; 64 print html_wikilink(':'.$id); 65 print '</li>'; 66 } 67 print '</ul>'; 68} 69 70/** 71 * Refresh a page lock and save draft 72 * 73 * Andreas Gohr <andi@splitbrain.org> 74 */ 75function ajax_lock(){ 76 global $conf; 77 global $lang; 78 $id = cleanID($_POST['id']); 79 if(empty($id)) return; 80 81 if(!checklock($id)){ 82 lock($id); 83 echo 1; 84 } 85 86 if($conf['usedraft'] && $_POST['wikitext']){ 87 $client = $_SERVER['REMOTE_USER']; 88 if(!$client) $client = clientIP(true); 89 90 $draft = array('id' => $id, 91 'prefix' => $_POST['prefix'], 92 'text' => $_POST['wikitext'], 93 'suffix' => $_POST['suffix'], 94 'date' => $_POST['date'], 95 'client' => $client, 96 ); 97 $cname = getCacheName($draft['client'].$id,'.draft'); 98 if(io_saveFile($cname,serialize($draft))){ 99 echo $lang['draftdate'].' '.date($conf['dformat']); 100 } 101 } 102 103} 104 105/** 106 * Delete a draft 107 * 108 * @author Andreas Gohr <andi@splitbrain.org> 109 */ 110function ajax_draftdel(){ 111 $id = cleanID($_POST['id']); 112 if(empty($id)) return; 113 114 $client = $_SERVER['REMOTE_USER']; 115 if(!$client) $client = clientIP(true); 116 117 $cname = getCacheName($client.$id,'.draft'); 118 @unlink($cname); 119} 120 121/** 122 * Return subnamespaces for the Mediamanager 123 */ 124function ajax_medians(){ 125 global $conf; 126 require_once(DOKU_INC.'inc/search.php'); 127 require_once(DOKU_INC.'inc/media.php'); 128 129 // wanted namespace 130 $ns = cleanID($_POST['ns']); 131 $dir = utf8_encodeFN(str_replace(':','/',$ns)); 132 133 $lvl = count(explode(':',$ns)); 134 135 $data = array(); 136 search($data,$conf['mediadir'],'search_index',array('nofiles' => true),$dir); 137 foreach($data as $item){ 138 $item['level'] = $lvl+1; 139 echo media_nstree_li($item); 140 echo media_nstree_item($item); 141 echo '</li>'; 142 } 143} 144 145/** 146 * Return subnamespaces for the Mediamanager 147 */ 148function ajax_medialist(){ 149 global $conf; 150 require_once(DOKU_INC.'inc/media.php'); 151 152 media_filelist($_POST['ns']); 153} 154 155//Setup VIM: ex: et ts=2 enc=utf-8 : 156?> 157