Пример #1
0
 /**
  * Spellcheck
  *
  * Used by the Spellcheck crappola
  *
  * @access	public
  * @return	void
  */
 function spellcheck()
 {
     $this->output->enable_profiler(FALSE);
     if (!class_exists('EE_Spellcheck')) {
         require APPPATH . 'libraries/Spellcheck.php';
     }
     return EE_Spellcheck::check();
 }
Пример #2
0
 /** --------------------------------
 	/**  SpellCheck - JS
 	/** --------------------------------*/
 function spellcheck_js()
 {
     if (!class_exists('EE_Spellcheck')) {
         require APPPATH . 'libraries/Spellcheck.php';
     }
     $SPELL = new EE_Spellcheck();
     $this->spellcheck_enabled = $SPELL->enabled;
     return $SPELL->JavaScript($this->_create_path('spellcheck'), TRUE);
 }
Пример #3
0
 /** -----------------------------------------
 	/**  Spell Check for Textareas
 	/** -----------------------------------------*/
 function check($lang = 'en')
 {
     // Make a local reference to the ExpressionEngine super object
     $this->EE =& get_instance();
     /* -------------------------------------------
     		/*	Hidden Configuration Variable
     		/*
     		/*	- spellcheck_language_code => What is the two letter ISO 639 language
     		/*	  code for the spellcheck (ex: en, es, de)
     		/* -------------------------------------------*/
     if (ee()->config->item('spellcheck_language_code') !== FALSE && strlen(ee()->config->item('spellcheck_language_code')) == 2) {
         $lang = ee()->config->item('spellcheck_language_code');
     }
     // ----------------------------------
     //  These 100 words make up 1/2 of all written material
     //  and by not checking them we should be able to greatly
     //  speed up the spellchecker
     // ----------------------------------
     $common = array('the', 'of', 'and', 'a', 'to', 'in', 'is', 'you', 'that', 'it', 'he', 'was', 'for', 'on', 'are', 'as', 'with', 'his', 'they', 'I', 'at', 'be', 'this', 'have', 'from', 'or', 'one', 'had', 'by', 'word', 'but', 'not', 'what', 'all', 'were', 'we', 'when', 'your', 'can', 'said', 'there', 'use', 'an', 'each', 'which', 'she', 'do', 'how', 'their', 'if', 'will', 'up', 'other', 'about', 'out', 'many', 'then', 'them', 'these', 'so', 'some', 'her', 'would', 'make', 'like', 'him', 'into', 'time', 'has', 'look', 'two', 'more', 'write', 'go', 'see', 'number', 'no', 'way', 'could', 'people', 'my', 'than', 'first', 'water', 'been', 'call', 'who', 'oil', 'its', 'now', 'find', 'long', 'down', 'day', 'did', 'get', 'come', 'made', 'may', 'part');
     // The contents of the field are encoded by javascript before
     // they are sent to us so we have to decode them before processing.
     // We are also removing any HTML code and HTML code entities so that we
     // do not process them as misspelled words.
     $content = preg_replace("|<.*?" . ">|", '', rawurldecode(ee()->security->xss_clean(ee()->input->get_post('q'))));
     $content = str_replace(array('&amp;', '&lt;', '&gt;'), '', $content);
     $str = '<?xml version="1.0" encoding="UTF-8"?' . ">\n<items>\n";
     $items = array();
     $prechecked = array();
     if (!function_exists('pspell_new')) {
         $content = str_replace('&', ' ', stripslashes($content));
         // Google has silently changed the service internally, setting ignoredups="1" now causes results to
         // always return as spelled correctly.  -- changed 8/20/08 d.j.
         $payload = '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="0"><text>' . $content . '</text></spellrequest>';
         $url = 'https://www.google.com/tbproxy/spell?lang=' . $lang . '&hl=' . $lang;
         if (function_exists('curl_init')) {
             $data = EE_Spellcheck::curl_process($url, $payload);
         } else {
             $data = EE_Spellcheck::fsockopen_process($url, $payload);
         }
         if ($data == '') {
             ee()->output->set_status_header(404);
             @header("Date: " . gmdate("D, d M Y H:i:s") . " GMT");
             exit('Unable to connect to spellcheck');
         }
         // suckz => <c o="10" l="5" s="0">sucks	sicks	suck	sacks	socks</c>
         if ($data != '' && preg_match_all("|<c\\s+(.*?)>(.*?)</c>|is", $data, $matches)) {
             for ($i = 0, $s = count($matches['0']); $i < $s; ++$i) {
                 $x = explode('"', $matches['1'][$i]);
                 $word = substr($content, $x['1'], $x['3']);
                 if (!in_array($word, $prechecked)) {
                     $sug = preg_split("|\\s+|s", $matches['2'][$i]);
                     natcasesort($sug);
                     $items[] = $word . ':' . implode(',', $sug) . '';
                     $prechecked[] = $word;
                 }
             }
         }
     } else {
         // Split it up by non-words
         preg_match_all("|[\\w\\']{2,20}|", stripslashes($content), $parts);
         $pspell = pspell_new($lang);
         for ($i = 0, $s = count($parts['0']); $i < $s; $i++) {
             if (!is_numeric($parts['0'][$i]) && !in_array(strtolower($parts['0'][$i]), $common) && !in_array($parts['0'][$i], $prechecked) && !pspell_check($pspell, $parts['0'][$i])) {
                 $sug = array();
                 if ($suggestions = pspell_suggest($pspell, $parts['0'][$i])) {
                     foreach ($suggestions as $suggest) {
                         $sug[] = $suggest;
                         if (count($sug) > 8) {
                             break;
                         }
                     }
                 }
                 natcasesort($sug);
                 $items[] = $parts['0'][$i] . ':' . implode(',', $sug) . '';
                 $prechecked[] = $parts['0'][$i];
             }
         }
     }
     $str .= count($items) == 0 ? '' : "<item>" . implode("</item>\n<item>", $items) . "</item>";
     $str .= "\n</items>";
     @header("Content-Type: text/xml");
     exit($str);
 }