[ Index ] |
|
Code source de WordPress 2.1.2 |
1 <?php 2 /** 3 * $RCSfile: tinyspell.php,v $ 4 * $Revision: 1.1 $ 5 * $Date: 2006/03/14 17:33:47 $ 6 * 7 * @author Moxiecode 8 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 9 */ 10 11 require_once ("config.php"); 12 13 $id = sanitize($_POST['id'], "loose"); 14 15 if (!$spellCheckerConfig['enabled']) { 16 header('Content-type: text/xml; charset=utf-8'); 17 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." />'; 18 die; 19 } 20 21 // Basic config 22 $defaultLanguage = $spellCheckerConfig['default.language']; 23 $defaultMode = $spellCheckerConfig['default.mode']; 24 25 // Normaly not required to configure 26 $defaultSpelling = $spellCheckerConfig['default.spelling']; 27 $defaultJargon = $spellCheckerConfig['default.jargon']; 28 $defaultEncoding = $spellCheckerConfig['default.encoding']; 29 $outputType = "xml"; // Do not change 30 31 // Get input parameters. 32 33 $check = $_POST['check']; 34 $cmd = sanitize($_POST['cmd']); 35 $lang = sanitize($_POST['lang'], "strict"); 36 $mode = sanitize($_POST['mode'], "strict"); 37 $spelling = sanitize($_POST['spelling'], "strict"); 38 $jargon = sanitize($_POST['jargon'], "strict"); 39 $encoding = sanitize($_POST['encoding'], "strict"); 40 $sg = sanitize($_POST['sg'], "bool"); 41 $words = array(); 42 43 $validRequest = true; 44 45 if (empty($check)) 46 $validRequest = false; 47 48 if (empty($lang)) 49 $lang = $defaultLanguage; 50 51 if (empty($mode)) 52 $mode = $defaultMode; 53 54 if (empty($spelling)) 55 $spelling = $defaultSpelling; 56 57 if (empty($jargon)) 58 $jargon = $defaultJargon; 59 60 if (empty($encoding)) 61 $encoding = $defaultEncoding; 62 63 function sanitize($str, $type="strict") { 64 switch ($type) { 65 case "strict": 66 $str = preg_replace("/[^a-zA-Z0-9_\-]/i", "", $str); 67 break; 68 case "loose": 69 $str = preg_replace("/</i", ">", $str); 70 $str = preg_replace("/>/i", "<", $str); 71 break; 72 case "bool": 73 if ($str == "true" || $str == true) 74 $str = true; 75 else 76 $str = false; 77 break; 78 } 79 80 return $str; 81 } 82 83 $result = array(); 84 $tinyspell = new $spellCheckerConfig['class']($spellCheckerConfig, $lang, $mode, $spelling, $jargon, $encoding); 85 86 if (count($tinyspell->errorMsg) == 0) { 87 switch($cmd) { 88 case "spell": 89 // Space for non-exec version and \n for the exec version. 90 $words = preg_split("/ |\n/", $check, -1, PREG_SPLIT_NO_EMPTY); 91 $result = $tinyspell->checkWords($words); 92 break; 93 case "suggest": 94 $result = $tinyspell->getSuggestion($check); 95 break; 96 default: 97 // Just use this for now. 98 $tinyspell->errorMsg[] = "No command."; 99 $outputType = $outputType . "error"; 100 break; 101 } 102 } else 103 $outputType = $outputType . "error"; 104 105 if (!$result) 106 $result = array(); 107 108 // Output data 109 switch($outputType) { 110 case "xml": 111 header('Content-type: text/xml; charset=utf-8'); 112 echo '<?xml version="1.0" encoding="utf-8" ?>'; 113 echo "\n"; 114 if (count($result) == 0) 115 echo '<res id="' . $id . '" cmd="'. $cmd .'" />'; 116 else 117 echo '<res id="' . $id . '" cmd="'. $cmd .'">'. utf8_encode(implode(" ", $result)) .'</res>'; 118 119 break; 120 case "xmlerror"; 121 header('Content-type: text/xml; charset=utf-8'); 122 echo '<?xml version="1.0" encoding="utf-8" ?>'; 123 echo "\n"; 124 echo '<res id="' . $id . '" cmd="'. $cmd .'" error="true" msg="'. implode(" ", $tinyspell->errorMsg) .'" />'; 125 break; 126 case "html": 127 var_dump($result); 128 break; 129 case "htmlerror": 130 echo "Error"; 131 break; 132 } 133 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 19:41:27 2007 | par Balluche grâce à PHPXref 0.7 |