[ Index ]
 

Code source de WordPress 2.1.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/wp-includes/js/tinymce/plugins/spellchecker/classes/ -> TinyPspellShell.class.php (source)

   1  <?php
   2  /* * 
   3   * Tiny Spelling Interface for TinyMCE Spell Checking.
   4   *
   5   * Copyright © 2006 Moxiecode Systems AB
   6   *
   7   */
   8  
   9  class TinyPspellShell {
  10      var $lang;
  11      var $mode;
  12      var $string;
  13      var $error;
  14      var $errorMsg;
  15  
  16      var $cmd;
  17      var $tmpfile;
  18  
  19      var $jargon;
  20      var $spelling;
  21      var $encoding;
  22  
  23  	function TinyPspellShell(&$config, $lang, $mode, $spelling, $jargon, $encoding) {
  24          $this->lang = $lang;
  25          $this->mode = $mode;
  26          $this->error = false;
  27          $this->errorMsg = array();
  28  
  29          $this->tmpfile = tempnam($config['tinypspellshell.tmp'], "tinyspell");
  30          $this->cmd = "cat ". $this->tmpfile ." | " . $config['tinypspellshell.aspell'] . " -a --lang=". $this->lang;
  31      }
  32  
  33      // Returns array with bad words or false if failed.
  34  	function checkWords($wordArray) {
  35          if ($fh = fopen($this->tmpfile, "w")) {
  36              fwrite($fh, "!\n");
  37              foreach($wordArray as $key => $value)
  38                  fwrite($fh, "^" . $value . "\n");
  39  
  40              fclose($fh);
  41          } else {
  42              $this->errorMsg[] = "PSpell not found.";
  43              return array();
  44          }
  45  
  46          $data = shell_exec($this->cmd);
  47          @unlink($this->tmpfile);
  48          $returnData = array();
  49          $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
  50  
  51          foreach($dataArr as $dstr) {
  52              $matches = array();
  53  
  54              // Skip this line.
  55              if (strpos($dstr, "@") === 0)
  56                  continue;
  57  
  58              preg_match("/\& (.*) .* .*: .*/i", $dstr, $matches);
  59  
  60              if (!empty($matches[1]))
  61                  $returnData[] = $matches[1];
  62          }
  63  
  64          return $returnData;
  65      }
  66  
  67      // Returns array with suggestions or false if failed.
  68  	function getSuggestion($word) {
  69          if ($fh = fopen($this->tmpfile, "w")) {
  70              fwrite($fh, "!\n");
  71              fwrite($fh, "^$word\n");
  72              fclose($fh);
  73          } else
  74              wp_die("Error opening tmp file.");
  75  
  76          $data = shell_exec($this->cmd);
  77          @unlink($this->tmpfile);
  78          $returnData = array();
  79          $dataArr = preg_split("/\n/", $data, -1, PREG_SPLIT_NO_EMPTY);
  80  
  81          foreach($dataArr as $dstr) {
  82              $matches = array();
  83  
  84              // Skip this line.
  85              if (strpos($dstr, "@") === 0)
  86                  continue;
  87  
  88              preg_match("/\& .* .* .*: (.*)/i", $dstr, $matches);
  89  
  90              if (!empty($matches[1])) {
  91                  // For some reason, the exec version seems to add commas?
  92                  $returnData[] = str_replace(",", "", $matches[1]);
  93              }
  94          }
  95          return $returnData;
  96      }
  97  }
  98  
  99  // Setup classname, should be the same as the name of the spellchecker class
 100  $spellCheckerConfig['class'] = "TinyPspellShell";
 101  
 102  ?>


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7