diff options
Diffstat (limited to 'webmail/program/steps/utils')
| -rw-r--r-- | webmail/program/steps/utils/error.inc | 139 | ||||
| -rw-r--r-- | webmail/program/steps/utils/html2text.inc | 31 | ||||
| -rw-r--r-- | webmail/program/steps/utils/killcache.inc | 50 | ||||
| -rw-r--r-- | webmail/program/steps/utils/modcss.inc | 63 | ||||
| -rw-r--r-- | webmail/program/steps/utils/save_pref.inc | 69 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell.inc | 51 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell_googie.inc | 75 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell_html.inc | 57 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell_html_googie.inc | 110 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell_html_pspell.inc | 76 | ||||
| -rw-r--r-- | webmail/program/steps/utils/spell_pspell.inc | 75 |
11 files changed, 796 insertions, 0 deletions
diff --git a/webmail/program/steps/utils/error.inc b/webmail/program/steps/utils/error.inc new file mode 100644 index 0000000..9fb71c5 --- /dev/null +++ b/webmail/program/steps/utils/error.inc @@ -0,0 +1,139 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/error.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2012, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Display error message page | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + +-----------------------------------------------------------------------+ +*/ + +$rcmail = rcmail::get_instance(); + +// browser is not compatible with this application +if ($ERROR_CODE==409) { + $user_agent = htmlentities($_SERVER['HTTP_USER_AGENT']); + $__error_title = 'Your browser does not suit the requirements for this application'; + $__error_text = <<<EOF +<i>Supported browsers:</i><br /> +» Microsoft Internet Explorer 7+<br /> +» Mozilla Firefox 3+<br /> +» Chrome 10+<br /> +» Safari 4+<br /> +» Opera 8+<br /> +<br /> +» JavaScript enabled<br /> +» Support for XMLHTTPRequest<br /> + +<p><i>Your configuration:</i><br /> +$user_agent</p> +EOF; +} + +// authorization error +else if ($ERROR_CODE==401) { + $__error_title = "AUTHORIZATION FAILED"; + $__error_text = "Could not verify that you are authorized to access this service!<br />\n". + "Please contact your server-administrator."; +} + +// forbidden due to request check +else if ($ERROR_CODE==403) { + $__error_title = "REQUEST CHECK FAILED"; + $__error_text = "Access to this service was denied due to failing security checks!<br />\n". + "Please contact your server-administrator."; +} + +// failed request (wrong step in URL) +else if ($ERROR_CODE==404) { + $__error_title = "REQUEST FAILED/FILE NOT FOUND"; + $request_url = htmlentities($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); + $__error_text = <<<EOF +The requested page was not found!<br /> +Please contact your server-administrator. + +<p><i>Failed request:</i><br /> +http://$request_url</p> +EOF; +} + +// database connection error +else if ($ERROR_CODE==601) +{ + $__error_title = "CONFIGURATION ERROR"; + $__error_text = nl2br($ERROR_MESSAGE) . "<br />Please read the INSTALL instructions!"; +} + +// database connection error +else if ($ERROR_CODE==603) { + $__error_title = "DATABASE ERROR: CONNECTION FAILED!"; + $__error_text = "Unable to connect to the database!<br />Please contact your server-administrator."; +} + +// system error +else { + $__error_title = "SERVICE CURRENTLY NOT AVAILABLE!"; + $__error_text = "Please contact your server-administrator."; + + if (($rcmail->config->get('debug_level') & 4) && $ERROR_MESSAGE) + $__error_text = $ERROR_MESSAGE; + else + $__error_text = sprintf('Error No. [%s]', $ERROR_CODE); +} + +$HTTP_ERR_CODE = $ERROR_CODE && $ERROR_CODE < 600 ? $ERROR_CODE : 500; + +// Ajax request +if ($rcmail->output && $rcmail->output->type == 'js') { + header("HTTP/1.0 $HTTP_ERR_CODE $__error_title"); + die; +} + +// compose page content +$__page_content = <<<EOF +<div> +<h3 class="error-title">$__error_title</h3> +<p class="error-text">$__error_text</p> +</div> +EOF; + +if ($rcmail->output && $rcmail->output->template_exists('error')) { + $rcmail->output->reset(); + $rcmail->output->send('error'); +} + +$__skin = $rcmail->config->get('skin', 'default'); +$__productname = $rcmail->config->get('product_name', 'Roundcube Webmail'); + +// print system error page +print <<<EOF +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"><head> +<title>$__productname :: ERROR</title> +<link rel="stylesheet" type="text/css" href="skins/$__skin/common.css" /> +</head> +<body> + +<table border="0" cellsapcing="0" cellpadding="0" width="100%" height="80%"><tr><td align="center"> + +$__page_content + +</td></tr></table> + +</body> +</html> +EOF; + +exit; + diff --git a/webmail/program/steps/utils/html2text.inc b/webmail/program/steps/utils/html2text.inc new file mode 100644 index 0000000..c6481b1 --- /dev/null +++ b/webmail/program/steps/utils/html2text.inc @@ -0,0 +1,31 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/html2text.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2012, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Convert HTML message to plain text | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + +-----------------------------------------------------------------------+ +*/ + +$html = $HTTP_RAW_POST_DATA; + +// Replace emoticon images with its text representation +$html = rcmail_replace_emoticons($html); + +$converter = new rcube_html2text($html, false, true, 0); + +header('Content-Type: text/plain; charset=UTF-8'); +print rtrim($converter->get_text()); +exit; diff --git a/webmail/program/steps/utils/killcache.inc b/webmail/program/steps/utils/killcache.inc new file mode 100644 index 0000000..1cb99b8 --- /dev/null +++ b/webmail/program/steps/utils/killcache.inc @@ -0,0 +1,50 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/killcache.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2010, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Delete rows from cache tables | + | | + +-----------------------------------------------------------------------+ + | Author: Dennis P. Nikolaenko <dennis@nikolaenko.ru> | + +-----------------------------------------------------------------------+ +*/ + +// don't allow public access if not in devel_mode +if (!$RCMAIL->config->get('devel_mode')) { + header("HTTP/1.0 401 Access denied"); + die("Access denied!"); +} + +// @TODO: transaction here (if supported by DB) would be a good thing +$res = $RCMAIL->db->query("DELETE FROM cache"); +if ($err = $RCMAIL->db->is_error($res)) { + exit($err); +} + +$res = $RCMAIL->db->query("DELETE FROM cache_messages"); +if ($err = $RCMAIL->db->is_error($res)) { + exit($err); +} + +$res = $RCMAIL->db->query("DELETE FROM cache_index"); +if ($err = $RCMAIL->db->is_error($res)) { + exit($err); +} + +$res = $RCMAIL->db->query("DELETE FROM cache_thread"); +if ($err = $RCMAIL->db->is_error($res)) { + exit($err); +} + +echo "Cache cleared\n"; +exit; diff --git a/webmail/program/steps/utils/modcss.inc b/webmail/program/steps/utils/modcss.inc new file mode 100644 index 0000000..1a28c65 --- /dev/null +++ b/webmail/program/steps/utils/modcss.inc @@ -0,0 +1,63 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/modcss.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2007-2012, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Modify CSS source from a URL | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + | Author: Aleksander Machniak <alec@alec.pl> | + +-----------------------------------------------------------------------+ +*/ + +$url = preg_replace('![^a-z0-9.-]!i', '', $_GET['_u']); + +if ($url === null || !($realurl = $_SESSION['modcssurls'][$url])) { + header('HTTP/1.1 403 Forbidden'); + exit("Unauthorized request"); +} + +// don't allow any other connections than http(s) +if (!preg_match('~^(https?)://~i', $realurl, $matches)) { + header('HTTP/1.1 403 Forbidden'); + exit("Invalid URL"); +} + +if (!ini_get('allow_url_fopen')) { + header('HTTP/1.1 403 Forbidden'); + exit("HTTP connections disabled"); +} + +$scheme = strtolower($matches[1]); +$options = array( + $scheme => array( + 'method' => 'GET', + 'timeout' => 15, + ) +); + +$context = stream_context_create($options); +$source = @file_get_contents($realurl, false, $context); + +// php.net/manual/en/reserved.variables.httpresponseheader.php +$headers = implode("\n", (array)$http_response_header); +$ctype = '~Content-Type:\s+text/(css|plain)~i'; + +if ($source !== false && preg_match($ctype, $headers)) { + header('Content-Type: text/css'); + echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['_c'])); + exit; +} + +header('HTTP/1.0 404 Not Found'); +exit("Invalid response returned by server"); diff --git a/webmail/program/steps/utils/save_pref.inc b/webmail/program/steps/utils/save_pref.inc new file mode 100644 index 0000000..7c30be7 --- /dev/null +++ b/webmail/program/steps/utils/save_pref.inc @@ -0,0 +1,69 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/save_pref.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2013, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Save preferences setting in database | + | | + +-----------------------------------------------------------------------+ + | Author: Aleksander Machniak <alec@alec.pl> | + +-----------------------------------------------------------------------+ +*/ + +$name = get_input_value('_name', RCUBE_INPUT_POST); +$value = get_input_value('_value', RCUBE_INPUT_POST); +$sessname = get_input_value('_session', RCUBE_INPUT_POST); + +// Whitelisted preferences and session variables, others +// can be added by plugins +$whitelist = array( + 'preview_pane', + 'list_cols', + 'collapsed_folders', + 'collapsed_abooks', +); +$whitelist_sess = array( + 'list_attrib/columns', +); + +$whitelist = array_merge($whitelist, $RCMAIL->plugins->allowed_prefs); +$whitelist_sess = array_merge($whitelist_sess, $RCMAIL->plugins->allowed_session_prefs); + +if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) { + raise_error(array('code' => 500, 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => sprintf("Hack attempt detected (user: %s)", $RCMAIL->get_user_name())), + true, false); + + $OUTPUT->reset(); + $OUTPUT->send(); +} + +// save preference value +$RCMAIL->user->save_prefs(array($name => $value)); + +// update also session if requested +if ($sessname) { + // Support multidimensional arrays... + $vars = explode('/', $sessname); + + // ... up to 3 levels + if (count($vars) == 1) + $_SESSION[$vars[0]] = $value; + else if (count($vars) == 2) + $_SESSION[$vars[0]][$vars[1]] = $value; + else if (count($vars) == 3) + $_SESSION[$vars[0]][$vars[1]][$vars[2]] = $value; +} + +$OUTPUT->reset(); +$OUTPUT->send(); diff --git a/webmail/program/steps/utils/spell.inc b/webmail/program/steps/utils/spell.inc new file mode 100644 index 0000000..a0dd35d --- /dev/null +++ b/webmail/program/steps/utils/spell.inc @@ -0,0 +1,51 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/spell.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2011, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Invoke the configured or default spell checking engine. | + | | + +-----------------------------------------------------------------------+ + | Author: Kris Steinhoff <steinhof@umich.edu> | + +-----------------------------------------------------------------------+ +*/ + +// read input +$lang = get_input_value('lang', RCUBE_INPUT_GET); +$data = file_get_contents('php://input'); + +$learn_word = strpos($data, '<learnword>'); + +// Get data string +$left = strpos($data, '<text>'); +$right = strrpos($data, '</text>'); +$data = substr($data, $left+6, $right-($left+6)); +$data = html_entity_decode($data, ENT_QUOTES, RCMAIL_CHARSET); + +$spellchecker = new rcube_spellchecker($lang); + +if ($learn_word) { + $spellchecker->add_word($data); + $result = '<?xml version="1.0" encoding="'.RCMAIL_CHARSET.'"?><learnwordresult></learnwordresult>'; +} +else { + $spellchecker->check($data); + $result = $spellchecker->get_xml(); +} + +// set response length +header("Content-Length: " . strlen($result)); + +// Don't use server's default Content-Type charset (#1486406) +header("Content-Type: text/xml; charset=" . RCMAIL_CHARSET); +print $result; +exit; diff --git a/webmail/program/steps/utils/spell_googie.inc b/webmail/program/steps/utils/spell_googie.inc new file mode 100644 index 0000000..41fc026 --- /dev/null +++ b/webmail/program/steps/utils/spell_googie.inc @@ -0,0 +1,75 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/spell_googie.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2007, Roundcube Dev. - Switzerland | + | Licensed under the GNU GPL | + | | + | PURPOSE: | + | Submit request to Google's spell checking engine | + | | + | CREDITS: | + | Script from GoogieSpell by amix.dk | + | | + +-----------------------------------------------------------------------+ + | Author: Thomas Bruederli <roundcube@gmail.com> | + +-----------------------------------------------------------------------+ + + $Id: spell_googie.inc 4626 2011-03-31 12:32:44Z alec $ + +*/ + +$REMOTE_REQUEST = TRUE; + +// default settings +$host = "ssl://www.google.com"; +$port = 443; +$lang = get_input_value('lang', RCUBE_INPUT_GET); +$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; + } + +$data = file_get_contents('php://input'); +// Google has some problem with spaces, use \n instead +$data = str_replace(' ', "\n", $data); +$store = ""; + +if ($fp = fsockopen($host, $port, $errno, $errstr, 30)) + { + $out = "POST $path HTTP/1.0\r\n"; + $out .= "Host: " . str_replace('ssl://', '', $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); + } + +// remove headers +$pos = strpos($store, '<?xml'); +$store = substr($store, $pos); + +// set response length +header("Content-Length: " . strlen($store)); + +// Don't use server's default Content-Type charset (#1486406) +header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); +print $store; +exit; + + diff --git a/webmail/program/steps/utils/spell_html.inc b/webmail/program/steps/utils/spell_html.inc new file mode 100644 index 0000000..861e4ba --- /dev/null +++ b/webmail/program/steps/utils/spell_html.inc @@ -0,0 +1,57 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/spell_html.inc | + | | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2011, The Roundcube Dev Team | + | | + | Licensed under the GNU General Public License version 3 or | + | any later version with exceptions for skins & plugins. | + | See the README file for a full license statement. | + | | + | PURPOSE: | + | Spellchecker for TinyMCE | + | | + +-----------------------------------------------------------------------+ + | Author: Aleksander Machniak <alec@alec.pl> | + +-----------------------------------------------------------------------+ +*/ + +// read input data +$data = file_get_contents('php://input'); + +// Decode JSON input +$request = json_decode($data, true); +$result = array(); + +$lang = $request['params'][0]; +$data = $request['params'][1]; +$data = implode("\n", (array) $data); + +$result['id'] = $request['id']; + +$spellchecker = new rcube_spellchecker($lang); + +if ($request['method'] == 'checkWords') { + $result['result'] = $spellchecker->get_words($data); +} +else if ($request['method'] == 'getSuggestions') { + $result['result'] = $spellchecker->get_suggestions($data); +} +else if ($request['method'] == 'learnWord') { + $spellchecker->add_word($data); + $result['result'] = true; +} + +if ($error = $spellchecker->error()) { + echo '{"error":{"errstr":"' . addslashes($error) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}'; + exit; +} + +// send output +header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); +echo json_encode($result); +exit; + diff --git a/webmail/program/steps/utils/spell_html_googie.inc b/webmail/program/steps/utils/spell_html_googie.inc new file mode 100644 index 0000000..df18c03 --- /dev/null +++ b/webmail/program/steps/utils/spell_html_googie.inc @@ -0,0 +1,110 @@ +<?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: " . str_replace('ssl://', '', $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("\n", (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') { + if ($matches[0][4]) { + $suggestions = explode("\t", $matches[0][4]); + if (sizeof($suggestions)>MAX_SUGGESTIONS) + $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS); + $result['result'] = $suggestions; + } + else + $result['result'] = array(); +} + +// send output +header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); +echo json_encode($result); +exit; + diff --git a/webmail/program/steps/utils/spell_html_pspell.inc b/webmail/program/steps/utils/spell_html_pspell.inc new file mode 100644 index 0000000..b38324c --- /dev/null +++ b/webmail/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/webmail/program/steps/utils/spell_pspell.inc b/webmail/program/steps/utils/spell_pspell.inc new file mode 100644 index 0000000..f3178ec --- /dev/null +++ b/webmail/program/steps/utils/spell_pspell.inc @@ -0,0 +1,75 @@ +<?php + +/* + +-----------------------------------------------------------------------+ + | program/steps/utils/spell_pspell.inc | + | | + | This file is part of the Roundcube Webmail client | + | Licensed under the GNU GPL | + | | + | PURPOSE: | + | Use the Pspell extension to check spelling, returns results | + | compatible with spell_googie.inc. | + | | + +-----------------------------------------------------------------------+ + | Author: Kris Steinhoff <steinhof@umich.edu> | + +-----------------------------------------------------------------------+ + + $Id: spell_pspell.inc 3989 2010-09-25 13:03:53Z alec $ + +*/ + +if (!extension_loaded('pspell')) { + raise_error(array( + 'code' => 500, + 'type' => 'php', + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Pspell extension not available"), true, false); + + header('HTTP/1.1 404 Not Found'); + exit; +} + +// read input +$data = file_get_contents('php://input'); + +// parse data (simplexml_load_string breaks CRLFs) +$left = strpos($data, '<text>'); +$right = strrpos($data, '</text>'); +$text = substr($data, $left+6, $right-($left+6)); +$text = html_entity_decode($text, ENT_QUOTES, RCMAIL_CHARSET); + +// tokenize +$words = preg_split('/[ !"#$%&()*+\\,\/\n:;<=>?@\[\]^_{|}-]+|\.[^\w]/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE ); + +// init spellchecker +$plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, RCMAIL_CHARSET, PSPELL_FAST); + +// send output +$out = '<?xml version="1.0" encoding="'.RCMAIL_CHARSET.'"?><spellresult charschecked="'.mb_strlen($text).'">'; + +$diff = 0; +foreach ($words as $w) { + $word = trim($w[0]); + $pos = $w[1] - $diff; + $len = mb_strlen($word); + if ($word && $plink && preg_match('/[^0-9\.]/', $word) + && !pspell_check($plink, $word)) { + $suggestions = pspell_suggest($plink, $word); + if (sizeof($suggestions)>MAX_SUGGESTIONS) + $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS); + + $out .= '<c o="'.$pos.'" l="'.$len.'">'; + $out .= implode("\t", $suggestions); + $out .= '</c>'; + } + $diff += (strlen($word) - $len); +} + +$out .= '</spellresult>'; + +header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); +echo $out; +exit; + + |
