-
+ 24380C644E90518106B47367B3C3DDF490D6702CE47474FFA8E2FAA4E9FF63FFF6ED2F1FF52FFBF1137D000FC2DCC84BFE62D624AF6BDDF5F39DEB22C223BB60
mp-wp/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
(0 . 0)(1 . 158)
122518 <?php
122519 /**
122520 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
122521 *
122522 * @package MCManager.includes
122523 * @author Moxiecode
122524 */
122525
122526 class GoogleSpell extends SpellChecker {
122527 /**
122528 * Spellchecks an array of words.
122529 *
122530 * @param {String} $lang Language code like sv or en.
122531 * @param {Array} $words Array of words to spellcheck.
122532 * @return {Array} Array of misspelled words.
122533 */
122534 function &checkWords($lang, $words) {
122535 $wordstr = implode(' ', $words);
122536 $matches = $this->_getMatches($lang, $wordstr);
122537 $words = array();
122538
122539 for ($i=0; $i<count($matches); $i++)
122540 $words[] = $this->_unhtmlentities(mb_substr($wordstr, $matches[$i][1], $matches[$i][2], "UTF-8"));
122541
122542 return $words;
122543 }
122544
122545 /**
122546 * Returns suggestions of for a specific word.
122547 *
122548 * @param {String} $lang Language code like sv or en.
122549 * @param {String} $word Specific word to get suggestions for.
122550 * @return {Array} Array of suggestions for the specified word.
122551 */
122552 function &getSuggestions($lang, $word) {
122553 $sug = array();
122554 $osug = array();
122555 $matches = $this->_getMatches($lang, $word);
122556
122557 if (count($matches) > 0)
122558 $sug = explode("\t", utf8_encode($this->_unhtmlentities($matches[0][4])));
122559
122560 // Remove empty
122561 foreach ($sug as $item) {
122562 if ($item)
122563 $osug[] = $item;
122564 }
122565
122566 return $osug;
122567 }
122568
122569 function &_getMatches($lang, $str) {
122570 $server = "www.google.com";
122571 $port = 443;
122572 $path = "/tbproxy/spell?lang=" . $lang . "&hl=en";
122573 $host = "www.google.com";
122574 $url = "https://" . $server;
122575
122576 // Setup XML request
122577 $xml = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>' . $str . '</text></spellrequest>';
122578
122579 $header = "POST ".$path." HTTP/1.0 \r\n";
122580 $header .= "MIME-Version: 1.0 \r\n";
122581 $header .= "Content-type: application/PTI26 \r\n";
122582 $header .= "Content-length: ".strlen($xml)." \r\n";
122583 $header .= "Content-transfer-encoding: text \r\n";
122584 $header .= "Request-number: 1 \r\n";
122585 $header .= "Document-type: Request \r\n";
122586 $header .= "Interface-Version: Test 1.4 \r\n";
122587 $header .= "Connection: close \r\n\r\n";
122588 $header .= $xml;
122589
122590 // Use curl if it exists
122591 if (function_exists('curl_init')) {
122592 // Use curl
122593 $ch = curl_init();
122594 curl_setopt($ch, CURLOPT_URL,$url);
122595 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
122596 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
122597 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
122598 $xml = curl_exec($ch);
122599 curl_close($ch);
122600 } else {
122601 // Use raw sockets
122602 $fp = fsockopen("ssl://" . $server, $port, $errno, $errstr, 30);
122603 if ($fp) {
122604 // Send request
122605 fwrite($fp, $header);
122606
122607 // Read response
122608 $xml = "";
122609 while (!feof($fp))
122610 $xml .= fgets($fp, 128);
122611
122612 fclose($fp);
122613 } else
122614 echo "Could not open SSL connection to google.";
122615 }
122616
122617 // Grab and parse content
122618 $matches = array();
122619 preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER);
122620
122621 return $matches;
122622 }
122623
122624 function _unhtmlentities($string) {
122625 $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string);
122626 $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string);
122627
122628 $trans_tbl = get_html_translation_table(HTML_ENTITIES);
122629 $trans_tbl = array_flip($trans_tbl);
122630
122631 return strtr($string, $trans_tbl);
122632 }
122633 }
122634
122635 // Patch in multibyte support
122636 if (!function_exists('mb_substr')) {
122637 function mb_substr($str, $start, $len = '', $encoding="UTF-8"){
122638 $limit = strlen($str);
122639
122640 for ($s = 0; $start > 0;--$start) {// found the real start
122641 if ($s >= $limit)
122642 break;
122643
122644 if ($str[$s] <= "\x7F")
122645 ++$s;
122646 else {
122647 ++$s; // skip length
122648
122649 while ($str[$s] >= "\x80" && $str[$s] <= "\xBF")
122650 ++$s;
122651 }
122652 }
122653
122654 if ($len == '')
122655 return substr($str, $s);
122656 else
122657 for ($e = $s; $len > 0; --$len) {//found the real end
122658 if ($e >= $limit)
122659 break;
122660
122661 if ($str[$e] <= "\x7F")
122662 ++$e;
122663 else {
122664 ++$e;//skip length
122665
122666 while ($str[$e] >= "\x80" && $str[$e] <= "\xBF" && $e < $limit)
122667 ++$e;
122668 }
122669 }
122670
122671 return substr($str, $s, $e - $s);
122672 }
122673 }
122674
122675 ?>