You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spell.inc 2.5KB

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