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 26$call = 'ajax_'.$_POST['call']; 27if(function_exists($call)){ 28 $call(); 29}else{ 30 print "The called function '".htmlspecialchars($call)."' does not exist!"; 31} 32 33/** 34 * Searches for matching pagenames 35 * 36 * @author Andreas Gohr <andi@splitbrain.org> 37 */ 38function ajax_qsearch(){ 39 global $conf; 40 global $lang; 41 42 $query = cleanID($_POST['q']); 43 if(empty($query)) return; 44 45 require_once(DOKU_INC.'inc/html.php'); 46 require_once(DOKU_INC.'inc/fulltext.php'); 47 48 $data = array(); 49 $data = ft_pageLookup($query); 50 51 if(!count($data)) return; 52 53 print '<strong>'.$lang['quickhits'].'</strong>'; 54 print '<ul>'; 55 foreach($data as $id){ 56 print '<li>'; 57 print html_wikilink(':'.$id); 58 print '</li>'; 59 } 60 print '</ul>'; 61} 62 63/** 64 * Refresh a page lock and save draft 65 * 66 * Andreas Gohr <andi@splitbrain.org> 67 */ 68function ajax_lock(){ 69 global $conf; 70 global $lang; 71 $id = cleanID($_POST['id']); 72 if(empty($id)) return; 73 74 if(!checklock($id)){ 75 lock($id); 76 echo 1; 77 } 78 79 if($conf['usedraft'] && $_POST['wikitext']){ 80 $client = $_SERVER['REMOTE_USER']; 81 if(!$client) $client = clientIP(true); 82 83 $draft = array('id' => $ID, 84 'prefix' => $_POST['prefix'], 85 'text' => $_POST['wikitext'], 86 'suffix' => $_POST['suffix'], 87 'date' => $_POST['date'], 88 'client' => $client, 89 ); 90 $cname = getCacheName($draft['client'].$id,'.draft'); 91 if(io_saveFile($cname,serialize($draft))){ 92 echo $lang['draftdate'].' '.date($conf['dformat']); 93 } 94 } 95 96} 97 98/** 99 * Delete a draft 100 */ 101function ajax_draftdel(){ 102 $id = cleanID($_POST['id']); 103 if(empty($id)) return; 104 105 $client = $_SERVER['REMOTE_USER']; 106 if(!$client) $client = clientIP(true); 107 108 $cname = getCacheName($client.$id,'.draft'); 109 @unlink($cname); 110} 111 112//Setup VIM: ex: et ts=2 enc=utf-8 : 113?> 114