1<?php
2/**
3 * AJAX call handler for inlineeditor plugin
4 *
5 * @license    GPL 3 (http://www.gnu.org/licenses/gpl.html)
6 * @author     Simon-Shlomo Poil <simon.shlomo@poil.dk>
7 *
8 * build on script from the quickedit plugin by     Arthur Lobert <arthur.lobert@gmail.com>
9 */
10
11if (!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../../../') . '/');
12
13
14//fix for Opera XMLHttpRequests
15if(!count($_POST) && $HTTP_RAW_POST_DATA)
16{
17	parse_str($HTTP_RAW_POST_DATA, $_POST);
18}
19
20require_once(DOKU_INC.'inc/init.php');
21
22require_once(DOKU_INC.'inc/auth.php');
23
24require_once(DOKU_INC.'inc/common.php');
25require_once(DOKU_INC.'inc/pageutils.php');
26
27
28
29//close session
30session_write_close();
31header('Content-Type: text/plain; charset=utf-8');
32
33//call the requested function
34$call = 'ajax_'.$_POST['call'];
35if(function_exists($call))
36{
37	$call();
38}
39else
40{
41	print "The called function '".htmlspecialchars($call)."' does not exist!";
42}
43
44function ajax_save_page()
45{
46global $ID;
47$ID = $_POST['page'];
48$INFO = pageinfo();
49if($INFO['writable']==1){
50		if ($_POST['range'][0] == '0' && $_POST['range'][1] == '-')
51			$_POST['range'][0] = '1';
52	$tab = rawWikiSlices($_POST['range'], $_POST['page']);
53//	if ($tab[2])
54//		$text = $tab[0].$_POST['text'].'='.$tab[2];
55//	else
56		$text = $tab[0].$_POST['text'].$tab[2];
57	saveWikiText($_POST['page'],$text,$_POST['sub'], $_POST['minor']);
58	unlock($_POST['page']);
59	print 1;
60}else{
61print 0;
62}
63}
64
65function ajax_get_text() {
66global $ID;
67$ID = $_POST['page'];
68$INFO = pageinfo();
69if ($INFO['writable'] == 1) {
70if(checklock($_POST['page'])) {
71return false;;
72}
73else{
74		lock($_POST['page']);
75		// we're finished
76		if ($_POST['range'][0] == '0' && $_POST['range'][1] == '-')
77			$_POST['range'][0] = '1';
78		$t = rawWikiSlices($_POST['range'], $_POST['page'], false);
79		print 	$t[1];
80		}
81} else
82{
83print 0;
84}
85	}
86
87function ajax_unlockpage() {
88unlock($_POST['page']);
89print  0;
90}
91
92?>
93