first commit. dokuwiki.
[h2N7SspZmY.git] / lib / plugins / tag / ajax.php
blob9e57afc8fd72d1719e2eb5ea61d68ca388c4b463
1 <?php
2 /**
3 * AJAX call handler for tagindex admin plugin
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 * @author Gina Häußge, Michael Klier <dokuwiki@chimeric.de>
7 * @author Andreas Gohr <andi@splitbrain.org>
8 */
10 //fix for Opera XMLHttpRequests
11 if(!count($_POST) && $HTTP_RAW_POST_DATA) {
12 parse_str($HTTP_RAW_POST_DATA, $_POST);
15 if (!defined('DOKU_INC'))
16 define('DOKU_INC', realpath(dirname(__FILE__) . '/../../../') . '/');
18 if (!defined('NL'))
19 define('NL', "\n");
21 require_once(DOKU_INC.'inc/init.php');
22 require_once(DOKU_INC.'inc/common.php');
23 require_once(DOKU_INC.'inc/pageutils.php');
24 require_once(DOKU_INC.'inc/auth.php');
25 require_once(DOKU_INC.'inc/search.php');
26 require_once(DOKU_INC.'inc/indexer.php');
28 //close session
29 session_write_close();
31 header('Content-Type: text/plain; charset=utf-8');
33 if (!auth_isadmin()) {
34 die('for admins only');
37 //clear all index files
38 if (@file_exists($conf['indexdir'].'/page.idx')) { // new word length based index
39 $tag_idx = $conf['indexdir'].'/topic.idx';
40 } else { // old index
41 $tag_idx = $conf['cachedir'].'/topic.idx';
44 $tag_helper =& plugin_load('helper', 'tag');
46 //call the requested function
47 $call = 'ajax_'.$_POST['call'];
48 if(function_exists($call)) {
49 $call();
50 }else{
51 print "The called function '".htmlspecialchars($call)."' does not exist!";
54 /**
55 * Searches for pages
57 * @author Andreas Gohr <andi@splitbrain.org>
59 function ajax_pagelist() {
60 global $conf;
62 $pages = array();
63 search($pages, $conf['datadir'], 'search_allpages', array());
65 foreach($pages as $page) {
66 print $page['id']."\n";
70 /**
71 * Clear all index files
73 function ajax_clearindex() {
74 global $conf;
75 global $tag_idx;
77 // keep running
78 @ignore_user_abort(true);
80 // try to aquire a lock
81 $lock = $conf['lockdir'].'/_tagindexer.lock';
82 while(!@mkdir($lock)) {
83 if(time()-@filemtime($lock) > 60*5) {
84 // looks like a stale lock - remove it
85 @rmdir($lock);
86 }else{
87 print 'tagindexer is locked.';
88 exit;
93 io_saveFile($tag_idx,'');
95 // we're finished
96 @rmdir($lock);
98 print 1;
102 * Index the given page's tags
104 function ajax_indexpage() {
105 global $conf;
106 global $tag_helper;
108 if(!$_POST['page']) {
109 print 1;
110 exit;
113 // keep running
114 @ignore_user_abort(true);
116 // try to aquire a lock
117 $lock = $conf['lockdir'].'/_tagindexer.lock';
118 while(!@mkdir($lock)) {
119 if(time()-@filemtime($lock) > 60*5) {
120 // looks like a stale lock - remove it
121 @rmdir($lock);
122 }else{
123 print 'tagindexer is locked.';
124 exit;
129 // do the work
130 $page = array(
131 'id' => $_POST['page'],
134 $tag_helper->_generateTagData($page);
136 // we're finished
137 @rmdir($lock);
139 print 1;
141 // vim:ts=4:sw=4:et:enc=utf-8: