thomascube
2011-04-12 3d8b54edf74792e3996d861a6a30c41d82976261
commit | author | age
5d2b7f 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
f4f629 5  | program/steps/utils/spell_googie.inc                                  |
5d2b7f 6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
f5e7b3 8  | Copyright (C) 2005-2007, The Roundcube Dev Team                       |
5d2b7f 9  | Licensed under the GNU GPL                                            |
T 10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Submit request to Google's spell checking engine                    |
13  |                                                                       |
14  | CREDITS:                                                              |
15  |   Script from GoogieSpell by amix.dk                                  |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20
21  $Id$
22
23 */
24
25 $REMOTE_REQUEST = TRUE;
26
27 // default settings
28 $host = "ssl://www.google.com";
29 $port = 443;
30 $lang = get_input_value('lang', RCUBE_INPUT_GET);
31 $path = "/tbproxy/spell?lang=$lang";
32
33 // spell check uri is configured
34 if (!empty($CONFIG['spellcheck_uri']))
35   {
36   $a_uri = parse_url($CONFIG['spellcheck_uri']);
37   $ssl = ($a_uri['scheme']=='https' || $a_uri['scheme']=='ssl');
38   $port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80);
39   $host = ($ssl ? 'ssl://' : '') . $a_uri['host'];
40   $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $lang;
41   }
42
43 $data = file_get_contents('php://input');
8b2c23 44 // Google has some problem with spaces, use \n instead
A 45 $data = str_replace(' ', "\n", $data);
5d2b7f 46 $store = "";
T 47
48 if ($fp = fsockopen($host, $port, $errno, $errstr, 30))
49   {
50   $out = "POST $path HTTP/1.0\r\n";
52c0f7 51   $out .= "Host: " . str_replace('ssl://', '', $host) . "\r\n";
5d2b7f 52   $out .= "Content-Length: " . strlen($data) . "\r\n";
57837f 53   $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
5d2b7f 54   $out .= "Connection: Close\r\n\r\n";
T 55   $out .= $data;
56   fwrite($fp, $out);
f4f629 57
5d2b7f 58   while (!feof($fp))
T 59     $store .= fgets($fp, 128);
60   fclose($fp);
61   }
62
baf645 63 // remove headers
A 64 $pos = strpos($store, '<?xml');
65 $store = substr($store, $pos);
66
67 // set response length
68 header("Content-Length: " . strlen($store));
69
57837f 70 // Don't use server's default Content-Type charset (#1486406)
A 71 header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);
677e1f 72 print $store;
5d2b7f 73 exit;
T 74
b25dfd 75