3 * $RCSfile: tinyspell.php,v $
\r
5 * $Date: 2006/03/14 17:33:47 $
\r
8 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
\r
11 // Ignore the Notice errors for now.
\r
12 error_reporting(E_ALL ^ E_NOTICE);
\r
14 require_once("config.php");
\r
16 $id = sanitize($_POST['id'], "loose");
\r
18 if (!$spellCheckerConfig['enabled']) {
\r
19 header('Content-type: text/xml; charset=utf-8');
\r
20 echo '<?xml version="1.0" encoding="utf-8" ?><res id="' . $id . '" error="true" msg="You must enable the spellchecker by modifying the config.php file." />';
\r
25 $defaultLanguage = $spellCheckerConfig['default.language'];
\r
26 $defaultMode = $spellCheckerConfig['default.mode'];
\r
28 // Normaly not required to configure
\r
29 $defaultSpelling = $spellCheckerConfig['default.spelling'];
\r
30 $defaultJargon = $spellCheckerConfig['default.jargon'];
\r
31 $defaultEncoding = $spellCheckerConfig['default.encoding'];
\r
32 $outputType = "xml"; // Do not change
\r
34 // Get input parameters.
\r
36 $check = urldecode($_REQUEST['check']);
\r
37 $cmd = sanitize($_REQUEST['cmd']);
\r
38 $lang = sanitize($_REQUEST['lang'], "strict");
\r
39 $mode = sanitize($_REQUEST['mode'], "strict");
\r
40 $spelling = sanitize($_REQUEST['spelling'], "strict");
\r
41 $jargon = sanitize($_REQUEST['jargon'], "strict");
\r
42 $encoding = sanitize($_REQUEST['encoding'], "strict");
\r
43 $sg = sanitize($_REQUEST['sg'], "bool");
\r
46 $validRequest = true;
\r
49 $validRequest = false;
\r
52 $lang = $defaultLanguage;
\r
55 $mode = $defaultMode;
\r
57 if (empty($spelling))
\r
58 $spelling = $defaultSpelling;
\r
61 $jargon = $defaultJargon;
\r
63 if (empty($encoding))
\r
64 $encoding = $defaultEncoding;
\r
66 function sanitize($str, $type="strict") {
\r
69 $str = preg_replace("/[^a-zA-Z0-9_\-]/i", "", $str);
\r
72 $str = preg_replace("/</i", ">", $str);
\r
73 $str = preg_replace("/>/i", "<", $str);
\r
76 if ($str == "true" || $str == true)
\r
87 $tinyspell = new $spellCheckerConfig['class']($spellCheckerConfig, $lang, $mode, $spelling, $jargon, $encoding);
\r
89 if (count($tinyspell->errorMsg) == 0) {
\r
92 // Space for non-exec version and \n for the exec version.
\r
93 $words = preg_split("/ |\n/", $check, -1, PREG_SPLIT_NO_EMPTY);
\r
94 $result = $tinyspell->checkWords($words);
\r
98 $result = $tinyspell->getSuggestion($check);
\r
102 // Just use this for now.
\r
103 $tinyspell->errorMsg[] = "No command.";
\r
104 $outputType = $outputType . "error";
\r
108 $outputType = $outputType . "error";
\r
114 switch($outputType) {
\r
116 header('Content-type: text/xml; charset=utf-8');
\r
117 $body = '<?xml version="1.0" encoding="utf-8" ?>';
\r
120 if (count($result) == 0)
\r
121 $body .= '<res id="' . $id . '" cmd="'. $cmd .'" />';
\r
123 $body .= '<res id="' . $id . '" cmd="'. $cmd .'">'. urlencode(implode(" ", $result)) .'</res>';
\r
128 header('Content-type: text/xml; charset=utf-8');
\r
129 $body = '<?xml version="1.0" encoding="utf-8" ?>';
\r
131 $body .= '<res id="' . $id . '" cmd="'. $cmd .'" error="true" msg="'. implode(" ", $tinyspell->errorMsg) .'" />';
\r