1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Core_Ajax_Imple_SpellChecker extends Horde_Core_Ajax_Imple
16: {
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
29: public function __construct($params = array())
30: {
31: if (empty($params['id'])) {
32: $params['id'] = $this->_randomid();
33: }
34:
35: if (empty($params['targetId'])) {
36: $params['targetId'] = $this->_randomid();
37: }
38:
39: if (empty($params['triggerId'])) {
40: $params['triggerId'] = $params['targetId'] . '_trigger';
41: }
42:
43: if (empty($params['locales'])) {
44: $key_list = array_keys($GLOBALS['registry']->nlsconfig->spelling);
45: asort($key_list, SORT_LOCALE_STRING);
46: $params['locales'] = array();
47:
48: foreach ($key_list as $lcode) {
49: $params['locales'][] = array('l' => $GLOBALS['registry']->nlsconfig->languages[$lcode], 'v' => $lcode);
50: }
51: }
52:
53: parent::__construct($params);
54: }
55:
56: 57:
58: public function attach()
59: {
60: Horde::addScriptFile('effects.js', 'horde');
61: Horde::addScriptFile('keynavlist.js', 'horde');
62: Horde::addScriptFile('spellchecker.js', 'horde');
63:
64: $opts = array(
65: 'locales' => $this->_params['locales'],
66: 'sc' => 'widget',
67: 'statusButton' => $this->_params['triggerId'],
68: 'target' => $this->_params['targetId'],
69: 'url' => strval($this->_getUrl('SpellChecker', 'horde', array('input' => $this->_params['targetId'])))
70: );
71: if (isset($this->_params['states'])) {
72: $opts['bs'] = $this->_params['states'];
73: }
74:
75: Horde::addInlineScript(array(
76: $this->_params['id'] . ' = new SpellChecker(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON) . ')'
77: ), 'dom');
78: }
79:
80: 81:
82: public function handle($args, $post)
83: {
84: $spellArgs = array();
85:
86: if (!empty($GLOBALS['conf']['spell']['params'])) {
87: $spellArgs = $GLOBALS['conf']['spell']['params'];
88: }
89:
90: if (isset($args['locale'])) {
91: $spellArgs['locale'] = $args['locale'];
92: } elseif (isset($GLOBALS['language'])) {
93: $spellArgs['locale'] = $GLOBALS['language'];
94: }
95:
96:
97: try {
98: $result = Horde::loadConfiguration('spelling.php', 'ignore_list', 'horde');
99: $spellArgs['localDict'] = $result;
100: } catch (Horde_Exception $e) {}
101:
102: if (!empty($args['html'])) {
103: $spellArgs['html'] = true;
104: }
105:
106: try {
107: $speller = Horde_SpellChecker::factory($GLOBALS['conf']['spell']['driver'], $spellArgs);
108: } catch (Horde_Exception $e) {
109: Horde::logMessage($e, 'ERR');
110: return array();
111: }
112:
113: try {
114: return $speller->spellCheck(Horde_Util::getPost($args['input']));
115: } catch (Horde_Exception $e) {
116: Horde::logMessage($e, 'ERR');
117: return array('bad' => array(), 'suggestions' => array());
118: }
119: }
120:
121: }
122: