Changeset 4985 for trunk/wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php
- Timestamp:
- 03/07/2007 04:26:26 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php
r4747 r4985 1 1 <?php 2 /* * 2 /* * 3 3 * Tiny Spelling Interface for TinyMCE Spell Checking. 4 4 * 5 5 * Copyright © 2006 Moxiecode Systems AB 6 6 */ 7 8 require_once("HttpClient.class.php");9 7 10 8 class TinyGoogleSpell { … … 23 21 24 22 for ($i=0; $i<count($matches); $i++) 25 $words[] = substr($wordstr, $matches[$i][1], $matches[$i][2]);23 $words[] = $this->unhtmlentities(mb_substr($wordstr, $matches[$i][1], $matches[$i][2], "UTF-8")); 26 24 27 25 return $words; 26 } 27 28 function unhtmlentities($string) { 29 $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); 30 $string = preg_replace('~&#([0-9]+);~e', 'chr(\\1)', $string); 31 32 $trans_tbl = get_html_translation_table(HTML_ENTITIES); 33 $trans_tbl = array_flip($trans_tbl); 34 35 return strtr($string, $trans_tbl); 28 36 } 29 37 … … 35 43 36 44 if (count($matches) > 0) 37 $sug = explode("\t", $matches[0][4]);45 $sug = explode("\t", utf8_encode($this->unhtmlentities($matches[0][4]))); 38 46 39 47 return $sug; 40 48 } 41 49 50 function _xmlChars($string) { 51 $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES); 52 53 foreach ($trans as $k => $v) 54 $trans[$k] = "&#".ord($k).";"; 55 56 return strtr($string, $trans); 57 } 58 42 59 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); 60 $server = "www.google.com"; 61 $port = 443; 62 $path = "/tbproxy/spell?lang=" . $this->lang . "&hl=en"; 63 $host = "www.google.com"; 64 $url = "https://" . $server; 50 65 51 66 // 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>'; 67 $xml = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>' . $word_list . '</text></spellrequest>'; 55 68 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(); 69 $header = "POST ".$path." HTTP/1.0 \r\n"; 70 $header .= "MIME-Version: 1.0 \r\n"; 71 $header .= "Content-type: application/PTI26 \r\n"; 72 $header .= "Content-length: ".strlen($xml)." \r\n"; 73 $header .= "Content-transfer-encoding: text \r\n"; 74 $header .= "Request-number: 1 \r\n"; 75 $header .= "Document-type: Request \r\n"; 76 $header .= "Interface-Version: Test 1.4 \r\n"; 77 $header .= "Connection: close \r\n\r\n"; 78 $header .= $xml; 79 //$this->_debugData($xml); 80 81 // Use raw sockets 82 $fp = fsockopen("ssl://" . $server, $port, $errno, $errstr, 30); 83 if ($fp) { 84 // Send request 85 fwrite($fp, $header); 86 87 // Read response 88 $xml = ""; 89 while (!feof($fp)) 90 $xml .= fgets($fp, 128); 91 92 fclose($fp); 93 } else { 94 // Use curl 95 $ch = curl_init(); 96 curl_setopt($ch, CURLOPT_URL,$url); 97 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 98 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); 99 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 100 $xml = curl_exec($ch); 101 curl_close($ch); 60 102 } 61 103 104 //$this->_debugData($xml); 105 62 106 // Grab and parse content 63 $xml = $client->getContent();64 107 preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER); 65 108 66 109 return $matches; 110 } 111 112 function _debugData($data) { 113 $fh = @fopen("debug.log", 'a+'); 114 @fwrite($fh, $data); 115 @fclose($fh); 67 116 } 68 117 }
Note: See TracChangeset
for help on using the changeset viewer.