summaryrefslogtreecommitdiff
path: root/roundcubemail/program/steps/mail/spell_pspell.inc
diff options
context:
space:
mode:
authorthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2008-08-15 10:35:09 +0000
committerthomasb <thomasb@208e9e7b-5314-0410-a742-e7e81cd9613c>2008-08-15 10:35:09 +0000
commitde5b04c5ba495d7bdc3f807cbedcdb7b377d5e00 (patch)
tree99bd5e9412d7314629c89aa3505d09eb114a9ec4 /roundcubemail/program/steps/mail/spell_pspell.inc
parentd3ca93a34895a2b99cb07661e3b19421268af1db (diff)
Added pspell support patch by Kris Steinhoff (#1483960)
git-svn-id: https://svn.roundcube.net/trunk@1649 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/steps/mail/spell_pspell.inc')
-rw-r--r--roundcubemail/program/steps/mail/spell_pspell.inc54
1 files changed, 54 insertions, 0 deletions
diff --git a/roundcubemail/program/steps/mail/spell_pspell.inc b/roundcubemail/program/steps/mail/spell_pspell.inc
new file mode 100644
index 000000000..ad637e85b
--- /dev/null
+++ b/roundcubemail/program/steps/mail/spell_pspell.inc
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | program/steps/mail/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$
+
+*/
+
+if (!extension_loaded('pspell')) {
+ raise_error(array(
+ 'code' => 500,
+ 'file' => __FILE__,
+ 'message' => "Pspell extension not available"), true, false);
+
+ header('HTTP/1.1 404 Not Found');
+ exit;
+}
+
+$data = file_get_contents('php://input');
+$xml = simplexml_load_string($data);
+$text = (string)$xml->text;
+$words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE );
+$plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, 'utf-8');
+$out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.strlen($text).'">';
+foreach ($words as $w) {
+ $word = $w[0];
+ $pos = $w[1];
+ $len = strlen($word);
+ if (!pspell_check($plink, $word)) {
+ $suggestions = pspell_suggest($plink, $word);
+ $out .= '<c o="'.$pos.'" l="'.$len.'">';
+ $out .= implode("\t", $suggestions);
+ $out .= '</c>';
+ }
+}
+$out .= '</spellresult>';
+
+echo $out;
+exit;
+
+?>