3 * $RCSfile: tinyspell.php,v $
5 * $Date: 2006/03/14 17:33:47 $
8 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
11 // Ignore the Notice errors for now.
12 error_reporting(E_ALL ^ E_NOTICE);
14 require_once("config.php");
16 $id = sanitize($_POST['id'], "loose");
18 if (!$spellCheckerConfig['enabled']) {
19 header('Content-type: text/xml; charset=utf-8');
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." />';
25 $defaultLanguage = $spellCheckerConfig['default.language'];
26 $defaultMode = $spellCheckerConfig['default.mode'];
28 // Normaly not required to configure
29 $defaultSpelling = $spellCheckerConfig['default.spelling'];
30 $defaultJargon = $spellCheckerConfig['default.jargon'];
31 $defaultEncoding = $spellCheckerConfig['default.encoding'];
32 $outputType = "xml"; // Do not change
34 // Get input parameters.
36 $check = urldecode(getRequestParam('check'));
37 $cmd = sanitize(getRequestParam('cmd'));
38 $lang = sanitize(getRequestParam('lang'), "strict");
39 $mode = sanitize(getRequestParam('mode'), "strict");
40 $spelling = sanitize(getRequestParam('spelling'), "strict");
41 $jargon = sanitize(getRequestParam('jargon'), "strict");
42 $encoding = sanitize(getRequestParam('encoding'), "strict");
43 $sg = sanitize(getRequestParam('sg'), "bool");
49 $validRequest = false;
52 $lang = $defaultLanguage;
58 $spelling = $defaultSpelling;
61 $jargon = $defaultJargon;
64 $encoding = $defaultEncoding;
66 function sanitize($str, $type="strict") {
69 $str = preg_replace("/[^a-zA-Z0-9_\-]/i", "", $str);
72 $str = preg_replace("/</i", ">", $str);
73 $str = preg_replace("/>/i", "<", $str);
76 if ($str == "true" || $str == true)
86 function getRequestParam($name, $default_value = false) {
87 if (!isset($_REQUEST[$name]))
88 return $default_value;
90 if (!isset($_GLOBALS['magic_quotes_gpc']))
91 $_GLOBALS['magic_quotes_gpc'] = ini_get("magic_quotes_gpc");
93 if (isset($_GLOBALS['magic_quotes_gpc'])) {
94 if (is_array($_REQUEST[$name])) {
97 foreach($_REQUEST[$name] as $name => $value)
98 $newarray[stripslashes($name)] = stripslashes($value);
102 return stripslashes($_REQUEST[$name]);
105 return $_REQUEST[$name];
109 $tinyspell = new $spellCheckerConfig['class']($spellCheckerConfig, $lang, $mode, $spelling, $jargon, $encoding);
111 if (count($tinyspell->errorMsg) == 0) {
114 // Space for non-exec version and \n for the exec version.
115 $words = preg_split("/ |\n/", $check, -1, PREG_SPLIT_NO_EMPTY);
116 $result = $tinyspell->checkWords($words);
120 $result = $tinyspell->getSuggestion($check);
124 // Just use this for now.
125 $tinyspell->errorMsg[] = "No command.";
126 $outputType = $outputType . "error";
130 $outputType = $outputType . "error";
136 switch($outputType) {
138 header('Content-type: text/xml; charset=utf-8');
139 $body = '<?xml version="1.0" encoding="utf-8" ?>';
142 if (count($result) == 0)
143 $body .= '<res id="' . $id . '" cmd="'. $cmd .'" />';
145 $body .= '<res id="' . $id . '" cmd="'. $cmd .'">'. urlencode(implode(" ", $result)) .'</res>';
150 header('Content-type: text/xml; charset=utf-8');
151 $body = '<?xml version="1.0" encoding="utf-8" ?>';
153 $body .= '<res id="' . $id . '" cmd="'. $cmd .'" error="true" msg="'. implode(" ", $tinyspell->errorMsg) .'" />';