[ 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/ -> TinyGoogleSpell.class.php (source)

   1  <?php
   2  /* * 
   3   * Tiny Spelling Interface for TinyMCE Spell Checking.
   4   *
   5   * Copyright © 2006 Moxiecode Systems AB
   6   */
   7  
   8  require_once ("HttpClient.class.php");
   9  
  10  class TinyGoogleSpell {
  11      var $lang;
  12  
  13  	function TinyGoogleSpell(&$config, $lang, $mode, $spelling, $jargon, $encoding) {
  14          $this->lang = $lang;
  15      }
  16  
  17      // Returns array with bad words or false if failed.
  18  	function checkWords($word_array) {
  19          $words = array();
  20          $wordstr = implode(' ', $word_array);
  21  
  22          $matches = $this->_getMatches($wordstr);
  23  
  24          for ($i=0; $i<count($matches); $i++)
  25              $words[] = substr($wordstr, $matches[$i][1], $matches[$i][2]);
  26  
  27          return $words;
  28      }
  29  
  30      // Returns array with suggestions or false if failed.
  31  	function getSuggestion($word) {
  32          $sug = array();
  33  
  34          $matches = $this->_getMatches($word);
  35  
  36          if (count($matches) > 0)
  37              $sug = explode("\t", $matches[0][4]);
  38  
  39          return $sug;
  40      }
  41  
  42  	function _getMatches($word_list) {
  43          $xml = "";
  44  
  45          // Setup HTTP Client
  46          $client = new HttpClient('www.google.com');
  47          $client->setUserAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR');
  48          $client->setHandleRedirects(false);
  49          $client->setDebug(false);
  50  
  51          // Setup XML request
  52          $xml .= '<?xml version="1.0" encoding="utf-8" ?>';
  53          $xml .= '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">';
  54          $xml .= '<text>' . htmlentities($word_list) . '</text></spellrequest>';
  55  
  56          // Execute HTTP Post to Google
  57          if (!$client->post('/tbproxy/spell?lang=' . $this->lang, $xml)) {
  58              $this->errorMsg[] = 'An error occurred: ' . $client->getError();
  59              return array();
  60          }
  61  
  62          // Grab and parse content
  63          $xml = $client->getContent();
  64          preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER);
  65  
  66          return $matches;
  67      }
  68  }
  69  
  70  // Setup classname, should be the same as the name of the spellchecker class
  71  $spellCheckerConfig['class'] = "TinyGoogleSpell";
  72  
  73  ?>


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