1<?php
2define("DOKU_INC", realpath(dirname(__FILE__).'/../../../../') . '/');
3
4define ("DOKU_PLUGIN", DOKU_INC . 'lib/plugins/');
5define("PAGES", DOKU_INC . 'data/pages/');
6define("FCKEDITOR", DOKU_PLUGIN . 'ckgdoku/fckeditor/editor/');
7define('CONNECTOR', FCKEDITOR . 'filemanager/connectors/php/');
8require_once(CONNECTOR . 'check_acl.php');
9require_once(DOKU_INC.'inc/Input.class.php');
10
11require_once(CONNECTOR . 'SafeFN.class.php');
12global $dwfck_conf;
13global $Dwfck_conf_values;
14$INPUT = new Input();
15$page = $INPUT->str('dw_id');
16$page =  ltrim($page, ':');
17
18$dwfck_conf = doku_config_values();  // needed for cleanID
19$Dwfck_conf_values = $dwfck_conf;
20$page = str_replace(':', '/',$page);
21$page = dwiki_encodeFN($page);
22if(!empty($Dwfck_conf_values['ckg_savedir'])) {
23  $path = $Dwfck_conf_values['ckg_savedir'] . '/pages/' . $page . '.txt';
24}
25else $path = PAGES . $page . '.txt';
26
27$resp = "";
28$headers = array();
29$lines = file($path);
30
31foreach ($lines as $line) {
32   if (preg_match('/^=+([^=]+)=+\s*$/',$line,$matches)) {
33          $suffix_anchor = "";
34          $suffix_header = "";
35          if(isset($headers[$matches[1]])) {
36              $headers[$matches[1]]++;
37              $suffix_anchor = $headers[$matches[1]];
38              $suffix_header = " [$suffix_anchor]";
39          }
40          else {
41            $headers[$matches[1]]=0;
42          }
43
44          $resp .=  trim($matches[1]) . $suffix_header . ";;" ;
45          $resp .= cleanID($matches[1]). $suffix_anchor . "@@" ;
46   }
47
48}
49
50$resp = rtrim($resp,'@');
51echo  rawurlencode($resp);
52//file_put_contents('ajax-resp.txt', "dw_id=" . $_REQUEST['dw_id'] . "\npage=$page\npath=$path\n$resp\n" );
53
54echo "\n";
55function doku_config_values() {
56  $dwphp = DOKU_INC . 'conf/dokuwiki.php';
57  $localphp = DOKU_INC . 'conf/local.php';
58  if(file_exists($dwphp))
59  {
60    include($dwphp);
61    if(file_exists($localphp))
62    {
63      include($localphp);
64    }
65    if(trim($conf['savedir'],'/.\/') != 'data') {
66     $conf['ckg_savedir']= $conf['savedir'];
67   }
68    return $conf;
69  }
70
71  return false;
72}
73?>
74
75