summaryrefslogtreecommitdiff
path: root/program/steps
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-06-24 13:27:43 +0000
committeralecpl <alec@alec.pl>2010-06-24 13:27:43 +0000
commitf4f6291ec16bd2fe368f868e667ea2071c514098 (patch)
treee5d74a7168dfb1a4a015f6db4d7f10076f95b515 /program/steps
parent2011bef155aacdfa8461a4d5c2cd3988d946d135 (diff)
- Use built-in spellchecker instead of a PHP files of spellchecker plugin in TinyMCE
Diffstat (limited to 'program/steps')
-rw-r--r--program/steps/utils/spell.inc8
-rw-r--r--program/steps/utils/spell_googie.inc4
-rw-r--r--program/steps/utils/spell_html_googie.inc106
-rw-r--r--program/steps/utils/spell_html_pspell.inc76
-rw-r--r--program/steps/utils/spell_pspell.inc5
5 files changed, 191 insertions, 8 deletions
diff --git a/program/steps/utils/spell.inc b/program/steps/utils/spell.inc
index d0fbcb9e4..3778865ac 100644
--- a/program/steps/utils/spell.inc
+++ b/program/steps/utils/spell.inc
@@ -18,11 +18,15 @@
*/
+// max. number of suggestions for one word
+define('MAX_SUGGESTIONS', 10);
+
+$tiny = !empty($_GET['tiny']) ? 'html_' : '';
+
if ($spell_engine = $RCMAIL->config->get('spellcheck_engine', 'googie')) {
- include('spell_'.$spell_engine.'.inc');
+ include('spell_'.$tiny.$spell_engine.'.inc');
}
header('HTTP/1.1 404 Not Found');
exit;
-
diff --git a/program/steps/utils/spell_googie.inc b/program/steps/utils/spell_googie.inc
index 038559c3f..d06a1a88a 100644
--- a/program/steps/utils/spell_googie.inc
+++ b/program/steps/utils/spell_googie.inc
@@ -2,7 +2,7 @@
/*
+-----------------------------------------------------------------------+
- | program/steps/utils/spell.inc |
+ | program/steps/utils/spell_googie.inc |
| |
| This file is part of the RoundCube Webmail client |
| Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
@@ -52,7 +52,7 @@ if ($fp = fsockopen($host, $port, $errno, $errstr, 30))
$out .= "Connection: Close\r\n\r\n";
$out .= $data;
fwrite($fp, $out);
-
+
while (!feof($fp))
$store .= fgets($fp, 128);
fclose($fp);
diff --git a/program/steps/utils/spell_html_googie.inc b/program/steps/utils/spell_html_googie.inc
new file mode 100644
index 000000000..292f303a3
--- /dev/null
+++ b/program/steps/utils/spell_html_googie.inc
@@ -0,0 +1,106 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/utils/spell_html_googie.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Submit request to Google's spell checking engine |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Aleksander Machniak <alec@alec.pl> |
+ +-----------------------------------------------------------------------+
+
+ $Id: spell_googie.inc 3780 2010-06-23 09:55:08Z alec $
+
+*/
+
+function json_error($str)
+{
+ echo '{"error":{"errstr":"' . addslashes($str) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}';
+ exit;
+}
+
+function googie_get($host, $port, $path, $data)
+{
+ $store = '';
+ if ($fp = fsockopen($host, $port, $errno, $errstr, 30)) {
+ $out = "POST $path HTTP/1.0\r\n";
+ $out .= "Host: $host\r\n";
+ $out .= "Content-Length: " . strlen($data) . "\r\n";
+ $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $out .= "Connection: Close\r\n\r\n";
+ $out .= $data;
+ fwrite($fp, $out);
+
+ while (!feof($fp))
+ $store .= fgets($fp, 128);
+ fclose($fp);
+ }
+
+ if (!$store) {
+ json_error("Empty result from spelling engine");
+ }
+
+ $matches = array();
+ preg_match_all('/<c o="([^"]*)" l="([^"]*)" s="([^"]*)">([^<]*)<\/c>/', $store, $matches, PREG_SET_ORDER);
+
+ return $matches;
+}
+
+$REMOTE_REQUEST = TRUE;
+
+// read input
+$data = file_get_contents('php://input');
+
+// Decode JSON input
+$request = json_decode($data, true);
+$result = array();
+
+$lang = $request['params'][0];
+$data = $request['params'][1];
+$result['id'] = $request['id'];
+
+// default settings
+$host = "ssl://www.google.com";
+$port = 443;
+$path = "/tbproxy/spell?lang=$lang";
+
+// spell check uri is configured
+if (!empty($CONFIG['spellcheck_uri']))
+ {
+ $a_uri = parse_url($CONFIG['spellcheck_uri']);
+ $ssl = ($a_uri['scheme']=='https' || $a_uri['scheme']=='ssl');
+ $port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80);
+ $host = ($ssl ? 'ssl://' : '') . $a_uri['host'];
+ $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $lang;
+ }
+
+$wordstr = implode(' ', (array) $data);
+$data = '<?xml version="1.0" encoding="utf-8" ?>'
+ .'<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">'
+ .'<text>' . $wordstr . '</text>'
+ .'</spellrequest>';
+$matches = googie_get($host, $port, $path, $data);
+
+if ($request['method'] == 'checkWords') {
+ $result['result'] = array();
+ for ($i=0, $len=count($matches); $i<$len; $i++)
+ $result['result'][] = mb_substr($wordstr, $matches[$i][1], $matches[$i][2], RCMAIL_CHARSET);
+}
+else if ($request['method'] == 'getSuggestions') {
+ $suggestions = explode("\t", $matches[0][4]);
+ if (sizeof($suggestions)>MAX_SUGGESTIONS)
+ $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
+ $result['result'] = $suggestions;
+}
+
+// send output
+header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);
+echo json_encode($result);
+exit;
+
diff --git a/program/steps/utils/spell_html_pspell.inc b/program/steps/utils/spell_html_pspell.inc
new file mode 100644
index 000000000..13344b02e
--- /dev/null
+++ b/program/steps/utils/spell_html_pspell.inc
@@ -0,0 +1,76 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/utils/spell_pspell_tiny.inc |
+ | |
+ | This file is part of the RoundCube Webmail client |
+ | Copyright (C) 2005-2010, RoundCube Dev. - Switzerland |
+ | Licensed under the GNU GPL |
+ | |
+ | PURPOSE: |
+ | Use the Pspell extension to check spelling in TinyMCE |
+ | |
+ +-----------------------------------------------------------------------+
+ | Author: Aleksander Machniak <alec@alec.pl> |
+ +-----------------------------------------------------------------------+
+
+ $Id: spell_pspell.inc 3780 2010-06-23 09:55:08Z alec $
+
+*/
+
+function json_error($str)
+{
+ echo '{"error":{"errstr":"' . addslashes($str) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}';
+ exit;
+}
+
+if (!extension_loaded('pspell')) {
+ raise_error(array(
+ 'code' => 500,
+ 'type' => 'php',
+ 'file' => __FILE__, 'line' => __LINE__,
+ 'message' => "Pspell extension not available"), true, false);
+
+ json_error("Pspell extension not available");
+}
+
+// read input
+$data = file_get_contents('php://input');
+
+// Decode JSON input
+$request = json_decode($data, true);
+$result = array();
+
+$lang = $request['params'][0];
+$data = $request['params'][1];
+$result['id'] = $request['id'];
+
+// init spellchecker
+$plink = pspell_new($lang, null, null, RCMAIL_CHARSET, PSPELL_FAST);
+
+if (!$plink) {
+ json_error("Unable to load Pspell engine for selected language");
+}
+
+if ($request['method'] == 'checkWords') {
+ $result['result'] = array();
+ foreach ((array)$data as $word) {
+ if ($word && preg_match('/[^0-9\.]/', $word)
+ && !pspell_check($plink, $word)) {
+ $result['result'][] = $word;
+ }
+ }
+}
+else if ($request['method'] == 'getSuggestions') {
+ $suggestions = pspell_suggest($plink, $data);
+ if (sizeof($suggestions)>MAX_SUGGESTIONS)
+ $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
+ $result['result'] = $suggestions;
+}
+
+// send output
+header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);
+echo json_encode($result);
+exit;
+
diff --git a/program/steps/utils/spell_pspell.inc b/program/steps/utils/spell_pspell.inc
index 2c9c2333c..58720ff42 100644
--- a/program/steps/utils/spell_pspell.inc
+++ b/program/steps/utils/spell_pspell.inc
@@ -30,9 +30,6 @@ if (!extension_loaded('pspell')) {
exit;
}
-// max. number of suggestions for one word
-define('MAX_SUGGESTIONS', 10);
-
// read input
$data = file_get_contents('php://input');
@@ -59,7 +56,7 @@ foreach ($words as $w) {
if ($word && $plink && preg_match('/[^0-9\.]/', $word)
&& !pspell_check($plink, $word)) {
$suggestions = pspell_suggest($plink, $word);
- if (sizeof($suggestions)>10)
+ if (sizeof($suggestions)>MAX_SUGGESTIONS)
$suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
$out .= '<c o="'.$pos.'" l="'.$len.'">';