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