1<?php
2define('FCK_ACTION_SUBDIR', realpath(dirname(__FILE__)) . '/../action/');
3
4     global $wiki_text;
5    // file_put_contents('save_ref.txt', print_r($_REQUEST,true));
6
7       $wiki_text = urldecode($_REQUEST['wikitext']);
8
9        if(!preg_match('/^\s+(\-|\*)/',$wiki_text)){
10              $wiki_text = trim($wiki_text);
11        }
12
13          /* preserve newlines in code blocks */
14          $wiki_text = preg_replace_callback(
15            '/(<code>|<file>)(.*?)(<\/code>|<\/file>)/ms',
16            create_function(
17                '$matches',
18                'return  str_replace("\n", "__code_NL__",$matches[0]);'
19            ),
20            $wiki_text
21          );
22
23        $wiki_text = preg_replace('/^\s*[\r\n]$/ms',"__n__", $wiki_text);
24        $wiki_text = preg_replace('/\r/ms',"", $wiki_text);
25        $wiki_text = preg_replace('/^\s+(?=\^|\|)/ms',"", $wiki_text);
26        $wiki_text = preg_replace('/__n__/',"\n", $wiki_text);
27        $wiki_text = str_replace("__code_NL__","\n", $wiki_text);
28
29
30       $wiki_text .= "\n";
31
32
33        $pos = strpos($wiki_text, 'MULTI_PLUGIN_OPEN');
34        if($pos !== false) {
35           $wiki_text = preg_replace_callback(
36            '|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms',
37            create_function(
38                '$matches',
39                  'return  preg_replace("/\\\\\\\\/ms","\n",$matches[0]);'
40            ),
41            $wiki_text
42          );
43
44           $wiki_text = preg_replace_callback(
45            '|MULTI_PLUGIN_OPEN.*?MULTI_PLUGIN_CLOSE|ms',
46            create_function(
47                '$matches',
48                  'return  preg_replace("/^\s+/ms","",$matches[0]);'
49            ),
50            $wiki_text
51          );
52
53        }
54
55     replace_entities();
56
57     file_put_contents($_REQUEST['rsave_id'], $wiki_text);
58     echo 'done';
59
60
61exit;
62
63function replace_entities() {
64global $wiki_text;
65global $ents;
66    $serialized = FCK_ACTION_SUBDIR . 'ent.ser';
67    $ents = unserialize(file_get_contents($serialized));
68
69       $wiki_text = preg_replace_callback(
70            '|(&(\w+);)|',
71            create_function(
72                '$matches',
73                'global $ents; return $ents[$matches[2]];'
74            ),
75            $wiki_text
76        );
77
78}
79?>
80
81