From: Michael M Slusarz Date: Thu, 16 Jul 2009 19:56:22 +0000 (-0600) Subject: Import SpellChecker imple object from IMP. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=97650a299a5cbbae94deb6676dd8f234a7ffc22a;p=horde.git Import SpellChecker imple object from IMP. --- diff --git a/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php b/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php new file mode 100644 index 000000000..b062ba902 --- /dev/null +++ b/framework/Ajax/lib/Horde/Ajax/Imple/SpellChecker.php @@ -0,0 +1,110 @@ + + * @package Horde_Ajax + */ +class Horde_Ajax_Imple_SpellChecker extends Horde_Ajax_Imple_Base +{ + /** + * Constructor. + * + * @param array $params Configuration parameters. + *
+     * 'id' => TODO (optional)
+     * 'locales' => TODO (optional)
+     * 'states' => TODO (optional)
+     * 'targetId' => TODO (optional)
+     * 'triggerId' => TODO (optional)
+     * 
+ */ + public function __construct($params = array()) + { + if (empty($params['id'])) { + $params['id'] = $this->_randomid(); + } + if (empty($params['targetId'])) { + $params['targetId'] = $this->_randomid(); + } + if (empty($params['triggerId'])) { + $params['triggerId'] = $params['targetId'] . '_trigger'; + } + if (empty($params['states'])) { + $params['states'] = '""'; + } else { + $params['states'] = Horde_Serialize::serialize($params['states'], Horde_Serialize::JSON, Horde_Nls::getCharset()); + } + if (empty($params['locales'])) { + $params['locales'] = array(); + foreach (array_keys(Horde_Nls::$config['spelling']) as $lcode) { + $params['locales'][$lcode] = Horde_Nls::$config['languages'][$lcode]; + } + } + asort($params['locales'], SORT_LOCALE_STRING); + $params['locales'] = Horde_Serialize::serialize($params['locales'], Horde_Serialize::JSON, Horde_Nls::getCharset()); + + parent::__construct($params); + } + + /** + */ + public function attach() + { + Horde::addScriptFile('prototype.js', 'horde', true); + Horde::addScriptFile('effects.js', 'horde', true); + Horde::addScriptFile('KeyNavList.js', 'horde', true); + Horde::addScriptFile('SpellChecker.js', 'horde', true); + + $url = $this->_getUrl('SpellChecker', 'horde', array('input' => $this->_params['targetId'])); + + Horde::addInlineScript($this->_params['id'] . ' = new SpellChecker("' . $url . '", "' . $this->_params['targetId'] . '", "' . $this->_params['triggerId'] . '", ' . $this->_params['states'] . ', ' . $this->_params['locales'] . ', \'widget\');', 'dom'); + } + + /** + */ + public function handle($args) + { + $spellArgs = array(); + + if (!empty($GLOBALS['conf']['spell']['params'])) { + $spellArgs = $GLOBALS['conf']['spell']['params']; + } + + if (isset($args['locale'])) { + $spellArgs['locale'] = $args['locale']; + } elseif (isset($GLOBALS['language'])) { + $spellArgs['locale'] = $GLOBALS['language']; + } + + /* Add local dictionary words. */ + try { + $result = Horde::loadConfiguration('spelling.php', 'ignore_list', 'horde'); + $spellArgs['localDict'] = $result; + } catch (Horde_Exception $e) {} + + if (!empty($args['html'])) { + $spellArgs['html'] = true; + } + + try { + $speller = Horde_SpellChecker::getInstance($GLOBALS['conf']['spell']['driver'], $spellArgs); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + return array(); + } + + try { + return $speller->spellCheck(Horde_Util::getPost($args['input'])); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR); + return array('bad' => array(), 'suggestions' => array()); + } + } + +} diff --git a/framework/Ajax/package.xml b/framework/Ajax/package.xml index 4094921aa..94bcf8b76 100644 --- a/framework/Ajax/package.xml +++ b/framework/Ajax/package.xml @@ -33,6 +33,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -48,16 +49,26 @@ http://pear.php.net/dtd/package-2.0.xsd"> 1.7.0 + + Core + pear.horde.org + - - Core - pear.horde.org - - + + + SpellChecker + pear.horde.org + + + Serialize + pear.horde.org + + +