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')) {
26 'message' => "Pspell extension not available"), true, false);
28 header('HTTP/1.1 404 Not Found');
33 $data = file_get_contents('php://input');
35 // parse data (simplexml_load_string breaks CRLFs)
36 $left = strpos($data, '<text>');
37 $right = strrpos($data, '</text>');
38 $text = substr($data, $left+6, $right-($left+6));
41 $words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE );
44 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, 'utf-8', PSPELL_FAST);
47 $out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.rc_strlen($text).'">';
50 foreach ($words as $w) {
53 $len = rc_strlen($word);
54 if ($word && $plink && !pspell_check($plink, $word)) {
55 $suggestions = pspell_suggest($plink, $word);
56 $out .= '<c o="'.$pos.'" l="'.$len.'">';
57 $out .= implode("\t", $suggestions);
60 $diff += (strlen($word) - $len);
63 $out .= '</spellresult>';
65 header("Content-Type: text/xml");