From ded713982e3f2e73b50ba2b5589cdd82cc68b749 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 15 Aug 2008 18:00:33 -0400
Subject: [PATCH] Respect spellcheck_uri in tinyMCE spellchecker (#1484196)

---
 CHANGELOG                                                        |    1 +
 program/js/tiny_mce/plugins/spellchecker/config.php              |    1 +
 program/js/tiny_mce/plugins/spellchecker/classes/GoogleSpell.php |   16 ++++++++++++----
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index d42fca9..9494f0b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -7,6 +7,7 @@
 - Better fix for skipping untagged responses (#1485261)
 - Added pspell support patch by Kris Steinhoff (#1483960)
 - Enable spellchecker for HTML editor (#1485114)
+- Respect spellcheck_uri in tinyMCE spellchecker (#1484196)
 
 2008/08/09 (alec)
 ----------
diff --git a/program/js/tiny_mce/plugins/spellchecker/classes/GoogleSpell.php b/program/js/tiny_mce/plugins/spellchecker/classes/GoogleSpell.php
index 53d4300..7347984 100755
--- a/program/js/tiny_mce/plugins/spellchecker/classes/GoogleSpell.php
+++ b/program/js/tiny_mce/plugins/spellchecker/classes/GoogleSpell.php
@@ -53,8 +53,16 @@
 		$server = "www.google.com";
 		$port = 443;
 		$path = "/tbproxy/spell?lang=" . $lang . "&hl=en";
-		$host = "www.google.com";
-		$url = "https://" . $server;
+		$ssl = true;
+		
+		// spell check uri is configured (added by RoundCube)
+		if (!empty($this->_config['rpc_uri'])) {
+			$a_uri = parse_url($this->_config['rpc_uri']);
+			$ssl = ($a_uri['scheme']=='https' || $a_uri['scheme']=='ssl');
+			$port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80);
+			$server = $a_uri['host'];
+			$path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $lang;
+		}
 
 		// Setup XML request
 		$xml = '<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>' . $str . '</text></spellrequest>';
@@ -74,7 +82,7 @@
 		if (function_exists('curl_init')) {
 			// Use curl
 			$ch = curl_init();
-			curl_setopt($ch, CURLOPT_URL,$url);
+			curl_setopt($ch, CURLOPT_URL, ($ssl ? "https://" : "http://") . $server);
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
 			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
@@ -82,7 +90,7 @@
 			curl_close($ch);
 		} else {
 			// Use raw sockets
-			$fp = fsockopen("ssl://" . $server, $port, $errno, $errstr, 30);
+			$fp = fsockopen(($ssl ? "ssl://" : "") . $server, $port, $errno, $errstr, 30);
 			if ($fp) {
 				// Send request
 				fwrite($fp, $header);
diff --git a/program/js/tiny_mce/plugins/spellchecker/config.php b/program/js/tiny_mce/plugins/spellchecker/config.php
index 827749e..53e6e46 100755
--- a/program/js/tiny_mce/plugins/spellchecker/config.php
+++ b/program/js/tiny_mce/plugins/spellchecker/config.php
@@ -7,6 +7,7 @@
 	
 	$rcmail_config = new rcube_config();
 	$config['general.engine'] = $rcmail_config->get('spellcheck_engine') == 'pspell' ? 'PSpell' : 'GoogleSpell';
+	$config['GoogleSpell.rpc_uri'] = $rcmail_config->get('spellcheck_uri');
 	
 	/** end RoundCube specific code */
 

--
Gitblit v1.9.1