1*dc6fce52SAndreas Gohr<?php 2*dc6fce52SAndreas Gohr/** 3*dc6fce52SAndreas Gohr * AJAX call handler for searchindex plugin 4*dc6fce52SAndreas Gohr * 5*dc6fce52SAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6*dc6fce52SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 7*dc6fce52SAndreas Gohr */ 8*dc6fce52SAndreas Gohr 9*dc6fce52SAndreas Gohr//fix for Opera XMLHttpRequests 10*dc6fce52SAndreas Gohrif(!count($_POST) && $HTTP_RAW_POST_DATA){ 11*dc6fce52SAndreas Gohr parse_str($HTTP_RAW_POST_DATA, $_POST); 12*dc6fce52SAndreas Gohr} 13*dc6fce52SAndreas Gohr 14*dc6fce52SAndreas Gohrif(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); 15*dc6fce52SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 16*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/init.php'); 17*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/common.php'); 18*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/pageutils.php'); 19*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/auth.php'); 20*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/search.php'); 21*dc6fce52SAndreas Gohrrequire_once(DOKU_INC.'inc/indexer.php'); 22*dc6fce52SAndreas Gohr//close sesseion 23*dc6fce52SAndreas Gohrsession_write_close(); 24*dc6fce52SAndreas Gohr 25*dc6fce52SAndreas Gohrheader('Content-Type: text/plain; charset=utf-8'); 26*dc6fce52SAndreas Gohr 27*dc6fce52SAndreas Gohr//we only work for admins! 28*dc6fce52SAndreas Gohrif (auth_quickaclcheck($conf['start']) < AUTH_ADMIN){ 29*dc6fce52SAndreas Gohr die('access denied'); 30*dc6fce52SAndreas Gohr} 31*dc6fce52SAndreas Gohr 32*dc6fce52SAndreas Gohr//call the requested function 33*dc6fce52SAndreas Gohr$call = 'ajax_'.$_POST['call']; 34*dc6fce52SAndreas Gohrif(function_exists($call)){ 35*dc6fce52SAndreas Gohr $call(); 36*dc6fce52SAndreas Gohr}else{ 37*dc6fce52SAndreas Gohr print "The called function '".htmlspecialchars($call)."' does not exist!"; 38*dc6fce52SAndreas Gohr} 39*dc6fce52SAndreas Gohr 40*dc6fce52SAndreas Gohr/** 41*dc6fce52SAndreas Gohr * Searches for pages 42*dc6fce52SAndreas Gohr * 43*dc6fce52SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 44*dc6fce52SAndreas Gohr */ 45*dc6fce52SAndreas Gohrfunction ajax_pagelist(){ 46*dc6fce52SAndreas Gohr global $conf; 47*dc6fce52SAndreas Gohr $data = array(); 48*dc6fce52SAndreas Gohr search($data,$conf['datadir'],'search_allpages',array()); 49*dc6fce52SAndreas Gohr 50*dc6fce52SAndreas Gohr foreach($data as $val){ 51*dc6fce52SAndreas Gohr print $val['id']."\n"; 52*dc6fce52SAndreas Gohr } 53*dc6fce52SAndreas Gohr} 54*dc6fce52SAndreas Gohr 55*dc6fce52SAndreas Gohr/** 56*dc6fce52SAndreas Gohr * Clear all index files 57*dc6fce52SAndreas Gohr */ 58*dc6fce52SAndreas Gohrfunction ajax_clearindex(){ 59*dc6fce52SAndreas Gohr global $conf; 60*dc6fce52SAndreas Gohr // keep running 61*dc6fce52SAndreas Gohr @ignore_user_abort(true); 62*dc6fce52SAndreas Gohr 63*dc6fce52SAndreas Gohr // try to aquire a lock 64*dc6fce52SAndreas Gohr $lock = $conf['lockdir'].'/_indexer.lock'; 65*dc6fce52SAndreas Gohr while(!@mkdir($lock)){ 66*dc6fce52SAndreas Gohr if(time()-@filemtime($lock) > 60*5){ 67*dc6fce52SAndreas Gohr // looks like a stale lock - remove it 68*dc6fce52SAndreas Gohr @rmdir($lock); 69*dc6fce52SAndreas Gohr }else{ 70*dc6fce52SAndreas Gohr print 'indexer is locked.'; 71*dc6fce52SAndreas Gohr exit; 72*dc6fce52SAndreas Gohr } 73*dc6fce52SAndreas Gohr 74*dc6fce52SAndreas Gohr } 75*dc6fce52SAndreas Gohr 76*dc6fce52SAndreas Gohr //clear all index files 77*dc6fce52SAndreas Gohr io_saveFile($conf['cachedir'].'/word.idx',''); 78*dc6fce52SAndreas Gohr io_saveFile($conf['cachedir'].'/page.idx',''); 79*dc6fce52SAndreas Gohr io_saveFile($conf['cachedir'].'/index.idx',''); 80*dc6fce52SAndreas Gohr 81*dc6fce52SAndreas Gohr // we're finished 82*dc6fce52SAndreas Gohr @rmdir($lock); 83*dc6fce52SAndreas Gohr 84*dc6fce52SAndreas Gohr print 1; 85*dc6fce52SAndreas Gohr} 86*dc6fce52SAndreas Gohr 87*dc6fce52SAndreas Gohr/** 88*dc6fce52SAndreas Gohr * Index the given page 89*dc6fce52SAndreas Gohr * 90*dc6fce52SAndreas Gohr * We're doing basicly the same as the real indexer but ignore the 91*dc6fce52SAndreas Gohr * last index time here 92*dc6fce52SAndreas Gohr */ 93*dc6fce52SAndreas Gohrfunction ajax_indexpage(){ 94*dc6fce52SAndreas Gohr global $conf; 95*dc6fce52SAndreas Gohr 96*dc6fce52SAndreas Gohr if(!$_POST['page']){ 97*dc6fce52SAndreas Gohr print 1; 98*dc6fce52SAndreas Gohr exit; 99*dc6fce52SAndreas Gohr } 100*dc6fce52SAndreas Gohr 101*dc6fce52SAndreas Gohr // keep running 102*dc6fce52SAndreas Gohr @ignore_user_abort(true); 103*dc6fce52SAndreas Gohr 104*dc6fce52SAndreas Gohr // try to aquire a lock 105*dc6fce52SAndreas Gohr $lock = $conf['lockdir'].'/_indexer.lock'; 106*dc6fce52SAndreas Gohr while(!@mkdir($lock)){ 107*dc6fce52SAndreas Gohr if(time()-@filemtime($lock) > 60*5){ 108*dc6fce52SAndreas Gohr // looks like a stale lock - remove it 109*dc6fce52SAndreas Gohr @rmdir($lock); 110*dc6fce52SAndreas Gohr }else{ 111*dc6fce52SAndreas Gohr print 'indexer is locked.'; 112*dc6fce52SAndreas Gohr exit; 113*dc6fce52SAndreas Gohr } 114*dc6fce52SAndreas Gohr 115*dc6fce52SAndreas Gohr } 116*dc6fce52SAndreas Gohr 117*dc6fce52SAndreas Gohr // do the work 118*dc6fce52SAndreas Gohr idx_addPage($_POST['page']); 119*dc6fce52SAndreas Gohr 120*dc6fce52SAndreas Gohr // we're finished 121*dc6fce52SAndreas Gohr io_saveFile(metaFN($id,'.indexed'),''); 122*dc6fce52SAndreas Gohr @rmdir($lock); 123*dc6fce52SAndreas Gohr 124*dc6fce52SAndreas Gohr print 1; 125*dc6fce52SAndreas Gohr} 126*dc6fce52SAndreas Gohr 127*dc6fce52SAndreas Gohr//Setup VIM: ex: et ts=4 enc=utf-8 : 128*dc6fce52SAndreas Gohr?> 129