thomascube
2008-09-18 7dfb1fba5001299300736e6b5d95d9400575e3e7
commit | author | age
5d2b7f 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/spell_pspell.inc                                   |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Licensed under the GNU GPL                                            |
9  |                                                                       |
10  | PURPOSE:                                                              |
11  |   Use the Pspell extension to check spelling, returns results         |
12  |   compatible with spell_googie.inc.                                   |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Kris Steinhoff <steinhof@umich.edu>                           |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
22 if (!extension_loaded('pspell')) {
23     raise_error(array(
24       'code' => 500,
25       'file' => __FILE__,
26       'message' => "Pspell extension not available"), true, false);
27       
28     header('HTTP/1.1 404 Not Found');
29     exit;
30 }
31
32 $data = file_get_contents('php://input');
33 $xml = simplexml_load_string($data);
34 $text = (string)$xml->text;
35 $words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL,  PREG_SPLIT_NO_EMPTY |  PREG_SPLIT_OFFSET_CAPTURE );
36 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET), null, null, 'utf-8');
37 $out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.strlen($text).'">';
38 foreach ($words as $w) {
39     $word = $w[0];
40     $pos  = $w[1];
41     $len  = strlen($word);
d4c01c 42     if ($plink && !pspell_check($plink, $word)) {
5d2b7f 43         $suggestions = pspell_suggest($plink, $word);
T 44         $out .= '<c o="'.$pos.'" l="'.$len.'">';
45         $out .= implode("\t", $suggestions);
46         $out .= '</c>';
47     }
48 }
49 $out .= '</spellresult>';
50
d4c01c 51 header("Content-Type: text/xml");
5d2b7f 52 echo $out;
T 53 exit;
54
55 ?>