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');
33 // max. number of suggestions for one word
34 define('MAX_SUGGESTIONS', 10);
37 $data = file_get_contents('php://input');
39 // parse data (simplexml_load_string breaks CRLFs)
40 $left = strpos($data, '<text>');
41 $right = strrpos($data, '</text>');
42 $text = substr($data, $left+6, $right-($left+6));
43 $text = html_entity_decode($text, ENT_QUOTES, RCMAIL_CHARSET);
46 $words = preg_split('/[ !"#$%&()*+\\,\/\n:;<=>?@\[\]^_{|}-]+|\.[^\w]/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE );
49 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, RCMAIL_CHARSET, PSPELL_FAST);
52 $out = '<?xml version="1.0" encoding="'.RCMAIL_CHARSET.'"?><spellresult charschecked="'.mb_strlen($text).'">';
55 foreach ($words as $w) {
58 $len = mb_strlen($word);
59 if ($word && $plink && preg_match('/[^0-9\.]/', $word)
60 && !pspell_check($plink, $word)) {
61 $suggestions = pspell_suggest($plink, $word);
62 if (sizeof($suggestions)>10)
63 $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
65 $out .= '<c o="'.$pos.'" l="'.$len.'">';
66 $out .= implode("\t", $suggestions);
69 $diff += (strlen($word) - $len);
72 $out .= '</spellresult>';
74 header("Content-Type: text/xml");