Ticket #1483960: pspell.patch
| File pspell.patch, 7.7 kB (added by ksteinhoff, 3 months ago) |
|---|
-
config/main.inc.php.dist
190 190 $rcmail_config['enable_spellcheck'] = TRUE; 191 191 192 // Set the spell checking engine. 'googie' is the default. 'pspell' is also available, 193 // but requires the Pspell extensions. 194 $rcmail_config['spellcheck_engine'] = 'googie'; 195 192 196 // For a locally installed Nox Spell Server, please specify the URI to call it. 193 197 // Get Nox Spell Server from http://orangoo.com/labs/?page_id=72 -
program/steps/mail/spell_googie.inc
1 <?php 2 3 /* 4 +-----------------------------------------------------------------------+ 5 | program/steps/mail/spell_googie.inc | 6 | | 7 | This file is part of the RoundCube Webmail client | 8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | 9 | Licensed under the GNU GPL | 10 | | 11 | PURPOSE: | 12 | Submit request to Google's spell checking engine | 13 | | 14 | CREDITS: | 15 | Script from GoogieSpell by amix.dk | 16 | | 17 +-----------------------------------------------------------------------+ 18 | Author: Thomas Bruederli <roundcube@gmail.com> | 19 +-----------------------------------------------------------------------+ 20 21 $Id$ 22 23 */ 24 25 $REMOTE_REQUEST = TRUE; 26 27 // default settings 28 $host = "ssl://www.google.com"; 29 $port = 443; 30 $lang = get_input_value('lang', RCUBE_INPUT_GET); 31 $path = "/tbproxy/spell?lang=$lang"; 32 33 // spell check uri is configured 34 if (!empty($CONFIG['spellcheck_uri'])) 35 { 36 $a_uri = parse_url($CONFIG['spellcheck_uri']); 37 $ssl = ($a_uri['scheme']=='https' || $a_uri['scheme']=='ssl'); 38 $port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80); 39 $host = ($ssl ? 'ssl://' : '') . $a_uri['host']; 40 $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $lang; 41 } 42 43 $data = file_get_contents('php://input'); 44 $store = ""; 45 46 if ($fp = fsockopen($host, $port, $errno, $errstr, 30)) 47 { 48 $out = "POST $path HTTP/1.0\r\n"; 49 $out .= "Host: $host\r\n"; 50 $out .= "Content-Length: " . strlen($data) . "\r\n"; 51 $out .= "Content-type: application/x-www-form-urlencoded\r\n"; 52 $out .= "Connection: Close\r\n\r\n"; 53 $out .= $data; 54 fwrite($fp, $out); 55 56 while (!feof($fp)) 57 $store .= fgets($fp, 128); 58 fclose($fp); 59 } 60 61 print $store; 62 exit; 63 64 ?> -
program/steps/mail/spell.inc
6 6 | | 7 7 | This file is part of the RoundCube Webmail client | 8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |9 8 | Licensed under the GNU GPL | 10 9 | | 11 10 | PURPOSE: | 12 | Submit request to Google's spell checking engine | 13 | | 14 | CREDITS: | 15 | Script from GoogieSpell by amix.dk | 11 | Invoke the configured or default spell checking engine. | 16 12 | | 17 13 +-----------------------------------------------------------------------+ 18 | Author: Thomas Bruederli <roundcube@gmail.com>|14 | Author: Kris Steinhoff <steinhof@umich.edu> | 19 15 +-----------------------------------------------------------------------+ 20 16 … … 23 19 */ 24 20 25 $REMOTE_REQUEST = TRUE; 26 27 // default settings 28 $host = "ssl://www.google.com"; 29 $port = 443; 30 $lang = get_input_value('lang', RCUBE_INPUT_GET); 31 $path = "/tbproxy/spell?lang=$lang"; 32 33 // spell check uri is configured 34 if (!empty($CONFIG['spellcheck_uri'])) 35 { 36 $a_uri = parse_url($CONFIG['spellcheck_uri']); 37 $ssl = ($a_uri['scheme']=='https' || $a_uri['scheme']=='ssl'); 38 $port = $a_uri['port'] ? $a_uri['port'] : ($ssl ? 443 : 80); 39 $host = ($ssl ? 'ssl://' : '') . $a_uri['host']; 40 $path = $a_uri['path'] . ($a_uri['query'] ? '?'.$a_uri['query'] : '') . $lang; 41 } 42 43 $data = file_get_contents('php://input'); 44 $store = ""; 45 46 if ($fp = fsockopen($host, $port, $errno, $errstr, 30)) 47 { 48 $out = "POST $path HTTP/1.0\r\n"; 49 $out .= "Host: $host\r\n"; 50 $out .= "Content-Length: " . strlen($data) . "\r\n"; 51 $out .= "Content-type: application/x-www-form-urlencoded\r\n"; 52 $out .= "Connection: Close\r\n\r\n"; 53 $out .= $data; 54 fwrite($fp, $out); 55 56 while (!feof($fp)) 57 $store .= fgets($fp, 128); 58 fclose($fp); 59 } 21 if ($spell_engine = $RCMAIL->config->get('spellcheck_engine', 'googie')) { 22 include('spell_'.$spell_engine.'.inc'); 23 } 60 24 61 print $store;62 25 exit; 63 26 -
program/steps/mail/spell_pspell.inc
1 <?php 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 exit; 24 } 25 26 $data = file_get_contents('php://input'); 27 $xml = simplexml_load_string($data); 28 $text = (string)$xml->text; 29 $words = preg_split('/[ !"#$%&()*+\\,-.\/\n:;<=>?@\[\]^_{|}]+/', $text, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE ); 30 $plink = pspell_new(get_input_value('lang', RCUBE_INPUT_GET)); 31 $out = '<?xml version="1.0" encoding="UTF-8"?><spellresult charschecked="'.strlen($text).'">'; 32 foreach ($words as $w) { 33 $word = $w[0]; 34 $pos = $w[1]; 35 $len = strlen($word); 36 if (!pspell_check($plink, $word)) { 37 $suggestions = pspell_suggest($plink, $word); 38 $out .= '<c o="'.$pos.'" l="'.$len.'">'; 39 $out .= implode("\t", $suggestions); 40 $out .= '</c>'; 41 } 42 } 43 $out .= '</spellresult>'; 44 45 echo $out; 46 exit; 47 48 ?>
