]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/utils/spell_html.inc
d0324c6176174f36aa6be59ef4341e44f09e3b47
[roundcube.git] / program / steps / utils / spell_html.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/utils/spell_html.inc                                    |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2005-2011, The Roundcube Dev Team                       |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Spellchecker for TinyMCE                                            |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Aleksander Machniak <alec@alec.pl>                            |
16  +-----------------------------------------------------------------------+
17
18  $Id: spell_html.inc 4815 2011-05-30 15:08:26Z alec $
19
20 */
21
22 // read input data
23 $data = file_get_contents('php://input');
24
25 // Decode JSON input
26 $request = json_decode($data, true);
27 $result = array();
28
29 $lang = $request['params'][0];
30 $data = $request['params'][1];
31 $data = implode("\n", (array) $data);
32
33 $result['id'] = $request['id'];
34
35 $spellchecker = new rcube_spellchecker($lang);
36
37 if ($request['method'] == 'checkWords') {
38     $result['result'] = $spellchecker->get_words($data);
39 }
40 else if ($request['method'] == 'getSuggestions') {
41     $result['result'] = $spellchecker->get_suggestions($data);
42 }
43
44 if ($error = $spellchecker->error()) {
45     echo '{"error":{"errstr":"' . addslashes($error) . '","errfile":"","errline":null,"errcontext":"","level":"FATAL"}}';
46     exit;
47 }
48
49 // send output
50 header("Content-Type: text/xml; charset=".RCMAIL_CHARSET);
51 echo json_encode($result);
52 exit;
53