4 +-----------------------------------------------------------------------+
5 | program/steps/utils/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 +-----------------------------------------------------------------------+
18 $Id: spell_pspell.inc 3989 2010-09-25 13:03:53Z alec $
22 if (!extension_loaded('pspell')) {
26 'file' => __FILE__, 'line' => __LINE__,
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:;<=>?@\[\]^_{|}-]+|\.[^\w]/', $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="'.RCMAIL_CHARSET.'"?><spellresult charschecked="'.mb_strlen($text).'">';
52 foreach ($words as $w) {
55 $len = mb_strlen($word);
56 if ($word && $plink && preg_match('/[^0-9\.]/', $word)
57 && !pspell_check($plink, $word)) {
58 $suggestions = pspell_suggest($plink, $word);
59 if (sizeof($suggestions)>MAX_SUGGESTIONS)
60 $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
62 $out .= '<c o="'.$pos.'" l="'.$len.'">';
63 $out .= implode("\t", $suggestions);
66 $diff += (strlen($word) - $len);
69 $out .= '</spellresult>';
71 header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);