xref: /plugin/searchindex/ajax.php (revision 4773e14500fce3dfff8e66d291ab9dd93ca4eeb4)
1dc6fce52SAndreas Gohr<?php
2*4773e145SAndreas Gohr
3dc6fce52SAndreas Gohr/**
4dc6fce52SAndreas Gohr * AJAX call handler for searchindex plugin
5dc6fce52SAndreas Gohr *
6dc6fce52SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
7dc6fce52SAndreas Gohr * @author     Andreas Gohr <andi@splitbrain.org>
8dc6fce52SAndreas Gohr */
9dc6fce52SAndreas Gohr
10*4773e145SAndreas Gohrif (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../../../') . '/');
11dc6fce52SAndreas Gohrrequire_once(DOKU_INC . 'inc/init.php');
12dc6fce52SAndreas Gohrsession_write_close();
13*4773e145SAndreas Gohrheader('Content-Type: application/json; charset=utf-8');
14*4773e145SAndreas Gohr@ignore_user_abort(true);
15dc6fce52SAndreas Gohr
16dc6fce52SAndreas Gohr// we only work for admins!
17*4773e145SAndreas Gohrif(!auth_isadmin()) throw new Exception('access denied');
18*4773e145SAndreas Gohr
19*4773e145SAndreas Gohr/** @var helper_plugin_searchindex $helper */
20*4773e145SAndreas Gohr$helper = plugin_load('helper', 'searchindex');
21*4773e145SAndreas Gohrglobal $INPUT;
22*4773e145SAndreas Gohr
23*4773e145SAndreas Gohrswitch($INPUT->post->str('call')) {
24*4773e145SAndreas Gohr    case 'pagelist':
25*4773e145SAndreas Gohr        echo json_encode($helper->getPagelist());
26*4773e145SAndreas Gohr        break;
27*4773e145SAndreas Gohr    case 'clearindex':
28*4773e145SAndreas Gohr        echo json_encode($helper->clearIndex());
29*4773e145SAndreas Gohr        break;
30*4773e145SAndreas Gohr    case 'indexpage':
31*4773e145SAndreas Gohr        $page = $INPUT->post->str('page');
32*4773e145SAndreas Gohr        $force = $INPUT->post->bool('force');
33*4773e145SAndreas Gohr        echo json_encode($helper->indexPage($page, $force));
34*4773e145SAndreas Gohr        break;
35*4773e145SAndreas Gohr    default:
36*4773e145SAndreas Gohr        throw new \Exception('The called function does not exist!');
37dc6fce52SAndreas Gohr}
38