Mercurial > hg > rc2
comparison program/steps/utils/spell.inc @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4681f974d28b |
---|---|
1 <?php | |
2 | |
3 /** | |
4 +-----------------------------------------------------------------------+ | |
5 | program/steps/utils/spell.inc | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2005-2011, The Roundcube Dev Team | | |
9 | | | |
10 | Licensed under the GNU General Public License version 3 or | | |
11 | any later version with exceptions for skins & plugins. | | |
12 | See the README file for a full license statement. | | |
13 | | | |
14 | PURPOSE: | | |
15 | Invoke the configured or default spell checking engine. | | |
16 | | | |
17 +-----------------------------------------------------------------------+ | |
18 | Author: Kris Steinhoff <steinhof@umich.edu> | | |
19 +-----------------------------------------------------------------------+ | |
20 */ | |
21 | |
22 // read input | |
23 $lang = rcube_utils::get_input_value('lang', rcube_utils::INPUT_GET); | |
24 $data = file_get_contents('php://input'); | |
25 | |
26 $learn_word = strpos($data, '<learnword>'); | |
27 | |
28 // Get data string | |
29 $left = strpos($data, '<text>'); | |
30 $right = strrpos($data, '</text>'); | |
31 $data = substr($data, $left+6, $right-($left+6)); | |
32 $data = html_entity_decode($data, ENT_QUOTES, RCUBE_CHARSET); | |
33 | |
34 $spellchecker = new rcube_spellchecker($lang); | |
35 | |
36 if ($learn_word) { | |
37 $spellchecker->add_word($data); | |
38 $result = '<?xml version="1.0" encoding="'.RCUBE_CHARSET.'"?><learnwordresult></learnwordresult>'; | |
39 } | |
40 else if (empty($data)) { | |
41 $result = '<?xml version="1.0" encoding="'.RCUBE_CHARSET.'"?><spellresult charschecked="0"></spellresult>'; | |
42 } | |
43 else { | |
44 $spellchecker->check($data); | |
45 $result = $spellchecker->get_xml(); | |
46 } | |
47 | |
48 if ($err = $spellchecker->error()) { | |
49 rcube::raise_error(array('code' => 500, 'type' => 'php', | |
50 'file' => __FILE__, 'line' => __LINE__, | |
51 'message' => "Spell check engine error: " . trim($err)), | |
52 true, false); | |
53 | |
54 header("HTTP/1.0 500 Internal Server Error"); | |
55 exit; | |
56 } | |
57 | |
58 // set response length | |
59 header("Content-Length: " . strlen($result)); | |
60 | |
61 // Don't use server's default Content-Type charset (#1486406) | |
62 header("Content-Type: text/xml; charset=" . RCUBE_CHARSET); | |
63 print $result; | |
64 exit; |