Make WordPress Core


Ignore:
Timestamp:
03/07/2007 04:26:26 AM (19 years ago)
Author:
ryan
Message:

Update to tinyMCE spellchecker 1.0.3.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/tinymce/plugins/spellchecker/classes/TinyGoogleSpell.class.php

    r4747 r4985  
    11<?php
    2 /* * 
     2/* *
    33 * Tiny Spelling Interface for TinyMCE Spell Checking.
    44 *
    55 * Copyright © 2006 Moxiecode Systems AB
    66 */
    7 
    8 require_once("HttpClient.class.php");
    97
    108class TinyGoogleSpell {
     
    2321
    2422        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"));
    2624
    2725        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);
    2836    }
    2937
     
    3543
    3644        if (count($matches) > 0)
    37             $sug = explode("\t", $matches[0][4]);
     45            $sug = explode("\t", utf8_encode($this->unhtmlentities($matches[0][4])));
    3846
    3947        return $sug;
    4048    }
    4149
     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
    4259    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;
    5065
    5166        // 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>';
    5568
    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);
    60102        }
    61103
     104        //$this->_debugData($xml);
     105
    62106        // Grab and parse content
    63         $xml = $client->getContent();
    64107        preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $xml, $matches, PREG_SET_ORDER);
    65108
    66109        return $matches;
     110    }
     111
     112    function _debugData($data) {
     113        $fh = @fopen("debug.log", 'a+');
     114        @fwrite($fh, $data);
     115        @fclose($fh);
    67116    }
    68117}
Note: See TracChangeset for help on using the changeset viewer.