| | 1 | <?php |
| | 2 | /** |
| | 3 | * Extension of TinyMCE GoogleSpell class for Wordpress |
| | 4 | * |
| | 5 | * WP_GoogleSpell extends TinyMCE's GoogleSpell class. It overrides the way in which the |
| | 6 | * http request to google is executed and uses WP_Http instead of curl/fsockopen. |
| | 7 | * |
| | 8 | * In order to use this class the "general.engine" value in config.php |
| | 9 | * (wp-includes/js/tinymce/plugins/spellchecker) needs to be set to "WP_GoogleSpell" |
| | 10 | * instead of "GoogleSpell". |
| | 11 | * |
| | 12 | * @link http://trac.wordpress.org/ticket/9798 Request for proxy support for spellchecking |
| | 13 | * |
| | 14 | * @package WordPress |
| | 15 | * @subpackage TinyMCE |
| | 16 | * @since 2.8.0 |
| | 17 | * @author Benedikt Forchhammer <b.forchhammer@mind2.de> |
| | 18 | */ |
| | 19 | |
| | 20 | // Wordpress functions and classes |
| | 21 | require_once(dirname(__FILE__) . '/../../../../../../wp-load.php'); |
| | 22 | |
| | 23 | // The SpellChecking Engine which we want to extend |
| | 24 | require_once(dirname(__FILE__) . '/GoogleSpell.php'); |
| | 25 | |
| | 26 | class WP_GoogleSpell extends GoogleSpell { |
| | 27 | |
| | 28 | function &_getMatches($lang, $str) { |
| | 29 | if (class_exists('WP_Http')) { |
| | 30 | $http = new WP_Http(); |
| | 31 | |
| | 32 | // request url |
| | 33 | $host = "www.google.com:443"; |
| | 34 | $path = "/tbproxy/spell?lang=" . $lang . "&hl=en"; |
| | 35 | $url = "https://" . $host . $path; |
| | 36 | |
| | 37 | // Setup XML request |
| | 38 | $xml = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>' . $str . '</text></spellrequest>'; |
| | 39 | |
| | 40 | // set up request arguments. |
| | 41 | // [bforchhammer] sslverify disabled because it did not work on our server / should possibly be enabled by default? |
| | 42 | $args = array( 'body' => $xml, 'sslverify' => false ); |
| | 43 | |
| | 44 | $response = $http->post($url, $args); |
| | 45 | |
| | 46 | if (is_wp_error($response)) { |
| | 47 | echo implode("\n", $response->get_error_messages()); |
| | 48 | return array(); |
| | 49 | } |
| | 50 | else { |
| | 51 | // Grab and parse content |
| | 52 | $matches = array(); |
| | 53 | preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $response['body'], $matches, PREG_SET_ORDER); |
| | 54 | |
| | 55 | return $matches; |
| | 56 | } |
| | 57 | } |
| | 58 | else { |
| | 59 | echo 'WP_Http class has not been loaded'; |
| | 60 | } |
| | 61 | } |
| | 62 | } |
| | 63 | ?> |
| | 64 | No newline at end of file |