4 +-----------------------------------------------------------------------+
5 | program/steps/mail/spell_pspell.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Licensed under the GNU GPL |
11 | Use the Pspell extension to check spelling, returns results |
12 | compatible with spell_googie.inc. |
14 +-----------------------------------------------------------------------+
15 | Author: Kris Steinhoff <steinhof@umich.edu> |
16 +-----------------------------------------------------------------------+
22 if (!extension_loaded('pspell')) {
27 'message' => "Pspell extension not available"), true, false);
29 header('HTTP/1.1 404 Not Found');
34 $data = file_get_contents('php://input');
36 // parse data (simplexml_load_string breaks CRLFs)
37 $left = strpos($data, '<text>');
38 $right = strrpos($data, '</text>');
39 $text = substr($data, $left+6, $right-($left+6));
40 $text = html_entity_decode($text, ENT_QUOTES, RCMAIL_CHARSET);
43 $words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE );
46 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, RCMAIL_CHARSET, PSPELL_FAST);
49 $out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.rc_strlen($text).'">';
52 foreach ($words as $w) {
55 $len = rc_strlen($word);
56 if ($word && $plink && !pspell_check($plink, $word)) {
57 $suggestions = pspell_suggest($plink, $word);
58 $out .= '<c o="'.$pos.'" l="'.$len.'">';
59 $out .= implode("\t", $suggestions);
62 $diff += (strlen($word) - $len);
65 $out .= '</spellresult>';
67 header("Content-Type: text/xml");