PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-includes/js/tinymce/plugins/spellchecker/ -> tinyspell.php (source)

   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      // Ignore the Notice errors for now.
  12      error_reporting(E_ALL ^ E_NOTICE);
  13  
  14      require_once ("config.php");
  15  
  16      $id = sanitize($_POST['id'], "loose");
  17  
  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." />';
  21          die;
  22      }
  23  
  24      // Basic config
  25      $defaultLanguage = $spellCheckerConfig['default.language'];
  26      $defaultMode = $spellCheckerConfig['default.mode'];
  27  
  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
  33  
  34      // Get input parameters.
  35  
  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");
  44      $words = array();
  45  
  46      $validRequest = true;
  47  
  48      if (empty($check))
  49          $validRequest = false;
  50  
  51      if (empty($lang))
  52          $lang = $defaultLanguage;
  53  
  54      if (empty($mode))
  55          $mode = $defaultMode;
  56  
  57      if (empty($spelling))
  58          $spelling = $defaultSpelling;
  59  
  60      if (empty($jargon))
  61          $jargon = $defaultJargon;
  62  
  63      if (empty($encoding))
  64          $encoding = $defaultEncoding;
  65  
  66  	function sanitize($str, $type="strict") {
  67          switch ($type) {
  68              case "strict":
  69                  $str = preg_replace("/[^a-zA-Z0-9_\-]/i", "", $str);
  70              break;
  71              case "loose":
  72                  $str = preg_replace("/</i", "&gt;", $str);
  73                  $str = preg_replace("/>/i", "&lt;", $str);
  74              break;
  75              case "bool":
  76                  if ($str == "true" || $str == true)
  77                      $str = true;
  78                  else
  79                      $str = false;
  80              break;
  81          }
  82  
  83          return $str;
  84      }
  85  
  86  	function getRequestParam($name, $default_value = false) {
  87          if (!isset($_REQUEST[$name]))
  88              return $default_value;
  89  
  90          if (!isset($_GLOBALS['magic_quotes_gpc']))
  91              $_GLOBALS['magic_quotes_gpc'] = ini_get("magic_quotes_gpc");
  92  
  93          if (isset($_GLOBALS['magic_quotes_gpc'])) {
  94              if (is_array($_REQUEST[$name])) {
  95                  $newarray = array();
  96  
  97                  foreach($_REQUEST[$name] as $name => $value)
  98                      $newarray[stripslashes($name)] = stripslashes($value);
  99  
 100                  return $newarray;
 101              }
 102              return stripslashes($_REQUEST[$name]);
 103          }
 104  
 105          return $_REQUEST[$name];
 106      }
 107  
 108      $result = array();
 109      $tinyspell = new $spellCheckerConfig['class']($spellCheckerConfig, $lang, $mode, $spelling, $jargon, $encoding);
 110  
 111      if (count($tinyspell->errorMsg) == 0) {
 112          switch($cmd) {
 113              case "spell":
 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);
 117              break;
 118  
 119              case "suggest":
 120                  $result = $tinyspell->getSuggestion($check);
 121              break;
 122  
 123              default:
 124                  // Just use this for now.
 125                  $tinyspell->errorMsg[] = "No command.";
 126                  $outputType = $outputType . "error";
 127              break;
 128          }
 129      } else
 130          $outputType = $outputType . "error";
 131  
 132      if (!$result)
 133          $result = array();
 134  
 135      // Output data
 136      switch($outputType) {
 137          case "xml":
 138              header('Content-type: text/xml; charset=utf-8');
 139              $body  = '<?xml version="1.0" encoding="utf-8" ?>';
 140              $body .= "\n";
 141  
 142              if (count($result) == 0)
 143                  $body .= '<res id="' . $id . '" cmd="'. $cmd .'" />';
 144              else
 145                  $body .= '<res id="' . $id . '" cmd="'. $cmd .'">'. urlencode(implode(" ", $result)) .'</res>';
 146  
 147              echo $body;
 148          break;
 149          case "xmlerror";
 150              header('Content-type: text/xml; charset=utf-8');
 151              $body  = '<?xml version="1.0" encoding="utf-8" ?>';
 152              $body .= "\n";
 153              $body .= '<res id="' . $id . '" cmd="'. $cmd .'" error="true" msg="'. implode(" ", $tinyspell->errorMsg) .'" />';
 154              echo $body;
 155          break;
 156          case "html":
 157              var_dump($result);
 158          break;
 159          case "htmlerror":
 160              echo "Error";
 161          break;
 162      }
 163  
 164  ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt