4 +-----------------------------------------------------------------------+
5 | program/steps/utils/spell_pspell_tiny.inc |
7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2005-2010, Roundcube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Use the Pspell extension to check spelling in TinyMCE |
14 +-----------------------------------------------------------------------+
15 | Author: Aleksander Machniak <alec@alec.pl> |
16 +-----------------------------------------------------------------------+
18 $Id: spell_pspell.inc 3780 2010-06-23 09:55:08Z alec $
22 function json_error($str)
24 echo '{"error":{"errstr":"' . addslashes($str) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}';
28 if (!extension_loaded('pspell')) {
32 'file' => __FILE__, 'line' => __LINE__,
33 'message' => "Pspell extension not available"), true, false);
35 json_error("Pspell extension not available");
39 $data = file_get_contents('php://input');
42 $request = json_decode($data, true);
45 $lang = $request['params'][0];
46 $data = $request['params'][1];
47 $result['id'] = $request['id'];
50 $plink = pspell_new($lang, null, null, RCMAIL_CHARSET, PSPELL_FAST);
53 json_error("Unable to load Pspell engine for selected language");
56 if ($request['method'] == 'checkWords') {
57 $result['result'] = array();
58 foreach ((array)$data as $word) {
59 if ($word && preg_match('/[^0-9\.]/', $word)
60 && !pspell_check($plink, $word)) {
61 $result['result'][] = $word;
65 else if ($request['method'] == 'getSuggestions') {
66 $suggestions = pspell_suggest($plink, $data);
67 if (sizeof($suggestions)>MAX_SUGGESTIONS)
68 $suggestions = array_slice($suggestions, 0, MAX_SUGGESTIONS);
69 $result['result'] = $suggestions;
73 header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);
74 echo json_encode($result);