From 677e1f26fe47cc0c3e0819cb99a9024af49a619c Mon Sep 17 00:00:00 2001 From: alecpl Date: Tue, 18 May 2010 10:25:29 +0000 Subject: - Some files from /bin + spellchecking actions moved to the new 'utils' task --- CHANGELOG | 1 + bin/html2text.php | 38 ------------ bin/killcache.php | 65 --------------------- bin/modcss.php | 108 ----------------------------------- program/include/rcmail.php | 23 ++++---- program/include/rcube_imap.php | 4 +- program/js/app.js | 6 +- program/js/googiespell.js | 4 +- program/js/list.js | 2 +- program/steps/mail/compose.inc | 3 +- program/steps/mail/func.inc | 5 +- program/steps/mail/spell.inc | 28 --------- program/steps/mail/spell_googie.inc | 73 ----------------------- program/steps/mail/spell_pspell.inc | 78 ------------------------- program/steps/utils/html2text.inc | 28 +++++++++ program/steps/utils/killcache.inc | 52 +++++++++++++++++ program/steps/utils/modcss.inc | 98 +++++++++++++++++++++++++++++++ program/steps/utils/spell.inc | 28 +++++++++ program/steps/utils/spell_googie.inc | 73 +++++++++++++++++++++++ program/steps/utils/spell_pspell.inc | 78 +++++++++++++++++++++++++ 20 files changed, 381 insertions(+), 414 deletions(-) delete mode 100644 bin/html2text.php delete mode 100644 bin/killcache.php delete mode 100644 bin/modcss.php delete mode 100644 program/steps/mail/spell.inc delete mode 100644 program/steps/mail/spell_googie.inc delete mode 100644 program/steps/mail/spell_pspell.inc create mode 100644 program/steps/utils/html2text.inc create mode 100644 program/steps/utils/killcache.inc create mode 100644 program/steps/utils/modcss.inc create mode 100644 program/steps/utils/spell.inc create mode 100644 program/steps/utils/spell_googie.inc create mode 100644 program/steps/utils/spell_pspell.inc diff --git a/CHANGELOG b/CHANGELOG index 7f3adcefe..b29c6f06b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ CHANGELOG RoundCube Webmail =========================== +- Some files from /bin + spellchecking actions moved to the new 'utils' task - Added thread tree icons - Extend contact groups support (#1486682) - Fix check-recent action issues and performance (#1486526) diff --git a/bin/html2text.php b/bin/html2text.php deleted file mode 100644 index 0074b605a..000000000 --- a/bin/html2text.php +++ /dev/null @@ -1,38 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/'); -require INSTALL_PATH . 'program/include/iniset.php'; - -$RCMAIL = rcmail::get_instance(); - -if (!empty($RCMAIL->user->ID)) { - $converter = new html2text($HTTP_RAW_POST_DATA); - - header('Content-Type: text/plain; charset=UTF-8'); - print trim($converter->get_text()); -} -else { - header("HTTP/1.0 403 Forbidden"); - echo "Requires a valid user session"; -} - -?> diff --git a/bin/killcache.php b/bin/killcache.php deleted file mode 100644 index 7bce676fb..000000000 --- a/bin/killcache.php +++ /dev/null @@ -1,65 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -define('INSTALL_PATH', realpath(dirname(__FILE__).'/..') . '/'); -require INSTALL_PATH . 'program/include/iniset.php'; - -$config = new rcube_config(); - -// don't allow public access if not in devel_mode -if (!$config->get('devel_mode') && $_SERVER['REMOTE_ADDR']) { - header("HTTP/1.0 401 Access denied"); - die("Access denied!"); -} - -$options = array( - 'use_transactions' => false, - 'log_line_break' => "\n", - 'idxname_format' => '%s', - 'debug' => false, - 'quote_identifier' => true, - 'force_defaults' => false, - 'portability' => true -); - -$dbh = MDB2::factory($config->get('db_dsnw'), $options); -if (PEAR::isError($dbh)) { - exit($mdb2->getMessage()); -} - -//TODO: transaction here (if supported by DB) would be a good thing -$res =& $dbh->exec("DELETE FROM cache"); -if (PEAR::isError($res)) { - $dbh->disconnect(); - exit($res->getMessage()); -} - -$res =& $dbh->exec("DELETE FROM messages"); -if (PEAR::isError($res)) { - $dbh->disconnect(); - exit($res->getMessage()); -} - -echo "Cache cleared\n"; - -$dbh->disconnect(); - -?> diff --git a/bin/modcss.php b/bin/modcss.php deleted file mode 100644 index 7e02e4651..000000000 --- a/bin/modcss.php +++ /dev/null @@ -1,108 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/'); -require INSTALL_PATH . 'program/include/iniset.php'; - -$RCMAIL = rcmail::get_instance(); - -$source = ''; -$error = 'Requires a valid user session and source url'; - -if (empty($RCMAIL->user->ID)) { - header('HTTP/1.1 403 Forbidden'); - echo $error; - exit; -} - -$url = preg_replace('![^a-z0-9:./\-_?$&=%]!i', '', $_GET['u']); -if ($url === null) { - header('HTTP/1.1 403 Forbidden'); - echo $error; - exit; -} - -$a_uri = parse_url($url); -$port = $a_uri['port'] ? $a_uri['port'] : 80; -$host = $a_uri['host']; -$path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : ''); - -// don't allow any other connections than http(s) -if (strtolower(substr($a_uri['scheme'], 0, 4)) != 'http') { - header('HTTP/1.1 403 Forbidden'); - echo "Invalid URL"; - exit; -} - -// try to open socket connection -if (!($fp = fsockopen($host, $port, $errno, $error, 15))) { - header('HTTP/1.1 500 Internal Server Error'); - echo $error; - exit; -} - -// set timeout for socket -stream_set_timeout($fp, 30); - -// send request -$out = "GET $path HTTP/1.0\r\n"; -$out .= "Host: $host\r\n"; -$out .= "Connection: Close\r\n\r\n"; -fwrite($fp, $out); - -// read response -$header = true; -$headers = array(); -while (!feof($fp)) { - $line = trim(fgets($fp, 4048)); - - if ($header) { - if (preg_match('/^HTTP\/1\..\s+(\d+)/', $line, $regs) - && intval($regs[1]) != 200) { - break; - } - else if (empty($line)) { - $header = false; - } - else { - list($key, $value) = explode(': ', $line); - $headers[strtolower($key)] = $value; - } - } - else { - $source .= "$line\n"; - } -} -fclose($fp); - -// check content-type header and mod styles -$mimetype = strtolower($headers['content-type']); -if (!empty($source) && in_array($mimetype, array('text/css','text/plain'))) { - header('Content-Type: text/css'); - echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['c'])); - exit; -} -else - $error = "Invalid response returned by server"; - -header('HTTP/1.0 404 Not Found'); -echo $error; -exit; diff --git a/program/include/rcmail.php b/program/include/rcmail.php index d9ee00a42..864ee8d41 100644 --- a/program/include/rcmail.php +++ b/program/include/rcmail.php @@ -28,10 +28,10 @@ */ class rcmail { - static public $main_tasks = array('mail','settings','addressbook','login','logout','dummy'); - + static public $main_tasks = array('mail','settings','addressbook','login','logout','utils','dummy'); + static private $instance; - + public $config; public $user; public $db; @@ -43,10 +43,10 @@ class rcmail public $task; public $action = ''; public $comm_path = './'; - + private $texts; - - + + /** * This implements the 'singleton' design pattern * @@ -107,11 +107,12 @@ class rcmail $this->action = asciiwords(get_input_value('_action', RCUBE_INPUT_GPC)); // reset some session parameters when changing task - if ($this->session && $_SESSION['task'] != $this->task) - $this->session->remove('page'); - - // set current task to session - $_SESSION['task'] = $this->task; + if ($this->task != 'utils') { + if ($this->session && $_SESSION['task'] != $this->task) + $this->session->remove('page'); + // set current task to session + $_SESSION['task'] = $this->task; + } // init output class if (!empty($_REQUEST['_remote'])) diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php index 1a665761a..7b7a3cf6a 100644 --- a/program/include/rcube_imap.php +++ b/program/include/rcube_imap.php @@ -2716,7 +2716,7 @@ class rcube_imap if ($result) { $delm = $this->get_hierarchy_delimiter(); - + // check if mailbox children are subscribed foreach ($a_subscribed as $c_subscribed) if (preg_match('/^'.preg_quote($mailbox.$delm, '/').'/', $c_subscribed)) { @@ -2727,7 +2727,7 @@ class rcube_imap // clear cache $this->clear_message_cache($mailbox.'.msg'); - $this->clear_cache('mailboxes'); + $this->clear_cache('mailboxes'); } // try to subscribe it diff --git a/program/js/app.js b/program/js/app.js index 253d8591d..dfd7c9f87 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -50,7 +50,6 @@ function rcube_webmail() this.env.request_timeout = 180; // seconds this.env.draft_autosave = 0; // seconds this.env.comm_path = './'; - this.env.bin_path = './bin/'; this.env.blankpage = 'program/blank.gif'; // set jQuery ajax options @@ -4825,8 +4824,7 @@ function rcube_webmail() } // replace quota image - obj.innerHTML = ''; - $(obj).append(bar1).append(bar2).append(main); + $(obj).html('').append(bar1).append(bar2).append(main); }; /********************************************************/ @@ -4836,7 +4834,7 @@ function rcube_webmail() this.html2plain = function(htmlText, id) { var rcmail = this, - url = this.env.bin_path + 'html2text.php'; + url = '?_task=utils&_action=html2text'; this.set_busy(true, 'converting'); console.log('HTTP POST: ' + url); diff --git a/program/js/googiespell.js b/program/js/googiespell.js index 5f201b7a1..c7be29e57 100644 --- a/program/js/googiespell.js +++ b/program/js/googiespell.js @@ -855,9 +855,9 @@ this.flashNoSpellingErrorState = function(on_finish) { no_spell_errors = function () { ref.checkSpellingState() }; var rsm = $('').text(this.lang_no_error_found); - + $(this.switch_lan_pic).hide(); - $(this.spell_span).empty().append(rsm) + $(this.spell_span).empty().append(rsm) .removeClass().addClass('googie_check_spelling_ok'); window.setTimeout(no_spell_errors, 1000); diff --git a/program/js/list.js b/program/js/list.js index 42149d6a1..8cfd05e49 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -1315,7 +1315,7 @@ add_dragfix: function() }) .css($(this).offset()) .appendTo(document.body); - }); + }); }, diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index bc7cd8960..97541da91 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -555,7 +555,7 @@ function rcmail_compose_body($attrib) $OUTPUT->include_script('googiespell.js'); $OUTPUT->add_script(sprintf( - "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','%s&_action=spell&lang=');\n". + "var googie = new GoogieSpell('\$__skin_path/images/googiespell/','?_task=utils&_action=spell&lang=');\n". "googie.lang_chck_spell = \"%s\";\n". "googie.lang_rsm_edt = \"%s\";\n". "googie.lang_close = \"%s\";\n". @@ -566,7 +566,6 @@ function rcmail_compose_body($attrib) "googie.setSpellContainer('spellcheck-control');\n". "googie.decorateTextarea('%s');\n". "%s.set_env('spellcheck', googie);", - $RCMAIL->comm_path, JQ(Q(rcube_label('checkspelling'))), JQ(Q(rcube_label('resumeediting'))), JQ(Q(rcube_label('close'))), diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 00a8edf95..951e777b1 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -27,7 +27,7 @@ $SEARCH_MODS_DEFAULT = array('*' => array('subject'=>1, 'from'=>1), $SENT_MBOX = $EMAIL_ADDRESS_PATTERN = '([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9][a-z0-9\-\.]*\\.[a-z]{2,5})'; // actions that do not require imap connection -$NOIMAP_ACTIONS = array('spell', 'addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment'); +$NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment'); // always instantiate imap object (but not yet connect to server) $RCMAIL->imap_init(); @@ -1068,7 +1068,8 @@ function rcmail_alter_html_link($matches) $end = '>'; if ($tag == 'link' && preg_match('/^https?:\/\//i', $attrib['href'])) { - $attrib['href'] = "./bin/modcss.php?u=" . urlencode($attrib['href']) . "&c=" . urlencode($GLOBALS['rcmail_html_container_id']); + $attrib['href'] = "?_task=utils&_action=modcss&u=" . urlencode($attrib['href']) + . "&c=" . urlencode($GLOBALS['rcmail_html_container_id']); $end = ' />'; } else if (preg_match('/^mailto:'.$EMAIL_ADDRESS_PATTERN.'(\?[^"\'>]+)?/i', $attrib['href'], $mailto)) { diff --git a/program/steps/mail/spell.inc b/program/steps/mail/spell.inc deleted file mode 100644 index a567c7bf6..000000000 --- a/program/steps/mail/spell.inc +++ /dev/null @@ -1,28 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -if ($spell_engine = $RCMAIL->config->get('spellcheck_engine', 'googie')) { - include('spell_'.$spell_engine.'.inc'); -} - -header('HTTP/1.1 404 Not Found'); -exit; - -?> diff --git a/program/steps/mail/spell_googie.inc b/program/steps/mail/spell_googie.inc deleted file mode 100644 index f3b1c684d..000000000 --- a/program/steps/mail/spell_googie.inc +++ /dev/null @@ -1,73 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -$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'); -$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); - } - -// remove headers -$pos = strpos($store, ' diff --git a/program/steps/mail/spell_pspell.inc b/program/steps/mail/spell_pspell.inc deleted file mode 100644 index b443ed525..000000000 --- a/program/steps/mail/spell_pspell.inc +++ /dev/null @@ -1,78 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -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; -} - -// max. number of suggestions for one word -define('MAX_SUGGESTIONS', 10); - -// read input -$data = file_get_contents('php://input'); - -// parse data (simplexml_load_string breaks CRLFs) -$left = strpos($data, ''); -$right = strrpos($data, ''); -$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 = ''; - -$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)>10) - $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS); - - $out .= ''; - $out .= implode("\t", $suggestions); - $out .= ''; - } - $diff += (strlen($word) - $len); -} - -$out .= ''; - -header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); -echo $out; -exit; - -?> diff --git a/program/steps/utils/html2text.inc b/program/steps/utils/html2text.inc new file mode 100644 index 000000000..ff2b40e6b --- /dev/null +++ b/program/steps/utils/html2text.inc @@ -0,0 +1,28 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$converter = new html2text($HTTP_RAW_POST_DATA); + +header('Content-Type: text/plain; charset=UTF-8'); +print trim($converter->get_text()); +exit; + +?> diff --git a/program/steps/utils/killcache.inc b/program/steps/utils/killcache.inc new file mode 100644 index 000000000..a2e7b3e25 --- /dev/null +++ b/program/steps/utils/killcache.inc @@ -0,0 +1,52 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +// 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!"); +} + +$options = array( + 'use_transactions' => false, + 'log_line_break' => "\n", + 'idxname_format' => '%s', + 'debug' => false, + 'quote_identifier' => true, + 'force_defaults' => false, + 'portability' => true +); + +// @TODO: transaction here (if supported by DB) would be a good thing +$res = $RCMAIL->db->query("DELETE FROM cache"); +if (PEAR::isError($res)) { + exit($res->getMessage()); +} + +$res = $RCMAIL->db->query("DELETE FROM messages"); +if (PEAR::isError($res)) { + exit($res->getMessage()); +} + +echo "Cache cleared\n"; +exit; + +?> diff --git a/program/steps/utils/modcss.inc b/program/steps/utils/modcss.inc new file mode 100644 index 000000000..2224901ac --- /dev/null +++ b/program/steps/utils/modcss.inc @@ -0,0 +1,98 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$source = ''; + +$url = preg_replace('![^a-z0-9:./\-_?$&=%]!i', '', $_GET['u']); +if ($url === null) { + header('HTTP/1.1 403 Forbidden'); + echo $error; + exit; +} + +$a_uri = parse_url($url); +$port = $a_uri['port'] ? $a_uri['port'] : 80; +$host = $a_uri['host']; +$path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : ''); + +// don't allow any other connections than http(s) +if (strtolower(substr($a_uri['scheme'], 0, 4)) != 'http') { + header('HTTP/1.1 403 Forbidden'); + echo "Invalid URL"; + exit; +} + +// try to open socket connection +if (!($fp = fsockopen($host, $port, $errno, $error, 15))) { + header('HTTP/1.1 500 Internal Server Error'); + echo $error; + exit; +} + +// set timeout for socket +stream_set_timeout($fp, 30); + +// send request +$out = "GET $path HTTP/1.0\r\n"; +$out .= "Host: $host\r\n"; +$out .= "Connection: Close\r\n\r\n"; +fwrite($fp, $out); + +// read response +$header = true; +$headers = array(); +while (!feof($fp)) { + $line = trim(fgets($fp, 4048)); + + if ($header) { + if (preg_match('/^HTTP\/1\..\s+(\d+)/', $line, $regs) + && intval($regs[1]) != 200) { + break; + } + else if (empty($line)) { + $header = false; + } + else { + list($key, $value) = explode(': ', $line); + $headers[strtolower($key)] = $value; + } + } + else { + $source .= "$line\n"; + } +} +fclose($fp); + +// check content-type header and mod styles +$mimetype = strtolower($headers['content-type']); +if (!empty($source) && in_array($mimetype, array('text/css','text/plain'))) { + header('Content-Type: text/css'); + echo rcmail_mod_css_styles($source, preg_replace('/[^a-z0-9]/i', '', $_GET['c'])); + exit; +} +else + $error = "Invalid response returned by server"; + +header('HTTP/1.0 404 Not Found'); +echo $error; +exit; + +?> diff --git a/program/steps/utils/spell.inc b/program/steps/utils/spell.inc new file mode 100644 index 000000000..dab56956b --- /dev/null +++ b/program/steps/utils/spell.inc @@ -0,0 +1,28 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +if ($spell_engine = $RCMAIL->config->get('spellcheck_engine', 'googie')) { + include('spell_'.$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 new file mode 100644 index 000000000..ec60f48f0 --- /dev/null +++ b/program/steps/utils/spell_googie.inc @@ -0,0 +1,73 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$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'); +$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); + } + +// remove headers +$pos = strpos($store, ' diff --git a/program/steps/utils/spell_pspell.inc b/program/steps/utils/spell_pspell.inc new file mode 100644 index 000000000..f892f8963 --- /dev/null +++ b/program/steps/utils/spell_pspell.inc @@ -0,0 +1,78 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +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; +} + +// max. number of suggestions for one word +define('MAX_SUGGESTIONS', 10); + +// read input +$data = file_get_contents('php://input'); + +// parse data (simplexml_load_string breaks CRLFs) +$left = strpos($data, ''); +$right = strrpos($data, ''); +$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 = ''; + +$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)>10) + $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS); + + $out .= ''; + $out .= implode("\t", $suggestions); + $out .= ''; + } + $diff += (strlen($word) - $len); +} + +$out .= ''; + +header("Content-Type: text/xml; charset=".RCMAIL_CHARSET); +echo $out; +exit; + +?> -- cgit v1.2.3