Added feature #10513: htmlArea RTE: Improve spell checker configurability
authorStanislas Rolland <typo3@sjbr.ca>
Sat, 21 Feb 2009 05:27:57 +0000 (05:27 +0000)
committerStanislas Rolland <typo3@sjbr.ca>
Sat, 21 Feb 2009 05:27:57 +0000 (05:27 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@5046 709f56b5-9817-0410-a4d7-c38de5d9e867

12 files changed:
ChangeLog
typo3/sysext/rtehtmlarea/ChangeLog
typo3/sysext/rtehtmlarea/doc/manual.sxw
typo3/sysext/rtehtmlarea/ext_conf_template.txt
typo3/sysext/rtehtmlarea/ext_localconf.php
typo3/sysext/rtehtmlarea/extensions/SpellChecker/class.tx_rtehtmlarea_spellchecker.php
typo3/sysext/rtehtmlarea/htmlarea/plugins/SpellChecker/popups/spell-check-ui-iso-8859-1.html
typo3/sysext/rtehtmlarea/htmlarea/plugins/SpellChecker/popups/spell-check-ui.html
typo3/sysext/rtehtmlarea/htmlarea/plugins/SpellChecker/spell-check-ui.js
typo3/sysext/rtehtmlarea/htmlarea/plugins/SpellChecker/spell-checker.js
typo3/sysext/rtehtmlarea/pi1/class.tx_rtehtmlarea_pi1.php
typo3/sysext/rtehtmlarea/res/demo/pageTSConfig.txt

index 05982cb..69f631e 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
 
        * Fixed bug #8905: option+space for inserting non-braking space on Mac OSX does not work properly
        * Added feature #10510: htmlArea RTE: Allow to specify default content language in BE
+       * Added feature #10513: htmlArea RTE: Improve spell checker configurability
 
 2009-02-19  Jeff Segars  <jeff@webempoweredchurch.org>
 
index 35ae602..ff50e64 100644 (file)
@@ -2,6 +2,7 @@
 
        * Fixed bug #8905: option+space for inserting non-braking space on Mac OSX does not work properly
        * Added feature #10510: htmlArea RTE: Allow to specify default content language in BE
+       * Added feature #10513: htmlArea RTE: Improve spell checker configurability
 
 2009-02-18  Stanislas Rolland  <typo3@sjbr.ca>
 
index c2bb37d..33088fa 100644 (file)
Binary files a/typo3/sysext/rtehtmlarea/doc/manual.sxw and b/typo3/sysext/rtehtmlarea/doc/manual.sxw differ
index be7a533..c7a18e9 100644 (file)
@@ -10,10 +10,10 @@ noSpellCheckLanguages = ja,km,ko,lo,th,zh,b5,gb
   # cat=basic; type=string; label=Aspell path: The server path where Aspell is installed.
 AspellDirectory = /usr/bin/aspell
 
-  # cat=basic; type=string; label=Default Aspell dictionary: The default dictionary to be used by the htmlArea SpellChecker plugin. This should be set to the default language of the site.
+  # cat=basic; type=string; label=Default Aspell dictionary: The default dictionary to be used by the htmlArea SpellChecker plugin. DEPRECATED. Use Page TSConfig properties defaultContentLanguage and buttons.spellcheck.dictionaries.[language-iso-code].defaultValue.
 defaultDictionary = en
 
-  # cat=basic; type=string; label=List of Aspell dictionaries: The list of dictionaries available to the htmlArea SpellChecker plugin. This list is used only if safe_mode is enabled. If safe_mode is not enabled, the list is automatically obtained from Aspell.
+  # cat=basic; type=string; label=List of Aspell dictionaries: The list of dictionaries available to the htmlArea SpellChecker plugin. DEPRECATED. Use Page TSConfig properties buttons.spellcheck.dictionaries.items and restrictToItems.
 dictionaryList  = en
 
   # cat=basic/enable/100; type=options[Minimal (Most features disabled. Administrator needs to enable them using TypoScript. For advanced administrators only.),Typical (Most commonly used features are enabled. Select this option if you are unsure which one to use.),Demo (Show-off configuration. Includes pre-configured styles. Not for production environments.)]; label=Default configuration settings
index e2c745b..2552fdd 100644 (file)
@@ -204,15 +204,16 @@ $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['Language']['disableInFE'] = 0;
        // Spell checking configuration
 $TYPO3_CONF_VARS['FE']['eID_include']['rtehtmlarea_spellchecker'] = 'EXT:'.$_EXTKEY.'/pi1/class.tx_rtehtmlarea_pi1.php';
 $TYPO3_CONF_VARS['BE']['AJAX']['rtehtmlarea::spellchecker'] = 'EXT:'.$_EXTKEY.'/pi1/class.tx_rtehtmlarea_pi1.php:tx_rtehtmlarea_pi1->main';
-$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['dictionaryList'] = $_EXTCONF['dictionaryList'] ? $_EXTCONF['dictionaryList'] : 'en';
-$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['defaultDictionary'] = $_EXTCONF['defaultDictionary'] ? $_EXTCONF['defaultDictionary'] : 'en';
-$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['AspellDirectory'] = $_EXTCONF['AspellDirectory'] ? $_EXTCONF['AspellDirectory'] : '/usr/bin/aspell';
-$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['noSpellCheckLanguages'] = $_EXTCONF['noSpellCheckLanguages'] ? $_EXTCONF['noSpellCheckLanguages'] : 'ja,km,ko,lo,th,zh,b5,gb';
-$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['forceCommandMode'] = $_EXTCONF['forceCommandMode'] ? $_EXTCONF['forceCommandMode'] : 0;
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker'] = array();
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['objectReference'] = 'EXT:'.$_EXTKEY.'/extensions/SpellChecker/class.tx_rtehtmlarea_spellchecker.php:&tx_rtehtmlarea_spellchecker';
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['addIconsToSkin'] = 0;
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['disableInFE'] = 0;
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['AspellDirectory'] = $_EXTCONF['AspellDirectory'] ? $_EXTCONF['AspellDirectory'] : '/usr/bin/aspell';
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['noSpellCheckLanguages'] = $_EXTCONF['noSpellCheckLanguages'] ? $_EXTCONF['noSpellCheckLanguages'] : 'ja,km,ko,lo,th,zh,b5,gb';
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['forceCommandMode'] = $_EXTCONF['forceCommandMode'] ? $_EXTCONF['forceCommandMode'] : 0;
+       // The following two properties DEPRECATED as of TYPO3 4.3.0
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['dictionaryList'] = $_EXTCONF['dictionaryList'] ? $_EXTCONF['dictionaryList'] : 'en';
+$TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['SpellChecker']['defaultDictionary'] = $_EXTCONF['defaultDictionary'] ? $_EXTCONF['defaultDictionary'] : 'en';
 
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['FindReplace'] = array();
 $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['FindReplace']['objectReference'] = 'EXT:'.$_EXTKEY.'/extensions/FindReplace/class.tx_rtehtmlarea_findreplace.php:&tx_rtehtmlarea_findreplace';
index cf1e468..1fe3a2d 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2008-2209 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
@@ -47,14 +47,13 @@ class tx_rtehtmlarea_spellchecker extends tx_rtehtmlareaapi {
        protected $convertToolbarForHtmlAreaArray = array (
                'spellcheck'    => 'SpellCheck',
                );
-       protected $spellCheckerModes = array( 'ultra', 'fast', 'normal', 'bad-spellers');
+       protected $spellCheckerModes = array('ultra', 'fast', 'normal', 'bad-spellers');
 
        public function main($parentObject) {
-               global $TYPO3_CONF_VARS;
 
                return parent::main($parentObject)
                        && t3lib_extMgm::isLoaded('static_info_tables')
-                       && !in_array($this->htmlAreaRTE->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->htmlAreaRTE->ID]['noSpellCheckLanguages']))
+                       && !in_array($this->htmlAreaRTE->language, t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->htmlAreaRTE->ID]['plugins'][$pluginName]['noSpellCheckLanguages']))
                        && ($this->htmlAreaRTE->contentCharset == 'iso-8859-1' || $this->htmlAreaRTE->contentCharset == 'utf-8');
        }
 
@@ -70,21 +69,21 @@ class tx_rtehtmlarea_spellchecker extends tx_rtehtmlareaapi {
         *      RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
         */
        public function buildJavascriptConfiguration($RTEcounter) {
-               global $TSFE, $LANG, $TYPO3_CONF_VARS, $BE_USER;
+               $button = 'spellcheck';
 
                        // Set the SpellChecker mode
-               $spellCheckerMode = isset($BE_USER->userTS['options.']['HTMLAreaPspellMode']) ? trim($BE_USER->userTS['options.']['HTMLAreaPspellMode']) : 'normal';
+               $spellCheckerMode = isset($GLOBALS['BE_USER']->userTS['options.']['HTMLAreaPspellMode']) ? trim($GLOBALS['BE_USER']->userTS['options.']['HTMLAreaPspellMode']) : 'normal';
                if (!in_array($spellCheckerMode, $this->spellCheckerModes)) {
                        $spellCheckerMode = 'normal';
                }
                        // Set the use of personal dictionary
-               $enablePersonalDicts = $this->thisConfig['enablePersonalDicts'] ? ((isset($BE_USER->userTS['options.']['enablePersonalDicts']) && $BE_USER->userTS['options.']['enablePersonalDicts']) ? true : false) : false;
+                       // $this->thisConfig['enablePersonalDicts'] is DEPRECATED as of 4.3.0
+               $enablePersonalDicts = ($this->thisConfig['buttons.'][$button.'.']['enablePersonalDictionaries'] || $this->thisConfig['enablePersonalDicts']) ? ((isset($GLOBALS['BE_USER']->userTS['options.']['enablePersonalDicts']) && $GLOBALS['BE_USER']->userTS['options.']['enablePersonalDicts']) ? true : false) : false;
                if (ini_get('safe_mode') || $this->htmlAreaRTE->is_FE()) {
                        $enablePersonalDicts = false;
                }
 
                $registerRTEinJavascriptString = '';
-               $button = 'spellcheck';
                if (in_array($button, $this->toolbar)) {
                        if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
                                        $registerRTEinJavascriptString .= '
index 4397004..843fa37 100644 (file)
@@ -53,6 +53,8 @@
                <input type="hidden" name="pspell_mode" id="f_pspell_mode" />
                <input type="hidden" name="userUid" id="f_user_uid" />
                <input type="hidden" name="enablePersonalDicts" id="f_personal_dicts" />
+               <input type="hidden" name="showDictionaries" id="f_show_dictionaries" />
+               <input type="hidden" name="restrictToDictionaries" id="f_restrict_to_dictionaries" />
                <input type="hidden" name="init" id="f_init" value="1" />
        </form>
        <div class="title">Spell Checker</div>
index f0afa54..165164f 100644 (file)
@@ -53,6 +53,8 @@
                <input type="hidden" name="pspell_mode" id="f_pspell_mode" />
                <input type="hidden" name="userUid" id="f_user_uid" />
                <input type="hidden" name="enablePersonalDicts" id="f_personal_dicts" />
+               <input type="hidden" name="showDictionaries" id="f_show_dictionaries" />
+               <input type="hidden" name="restrictToDictionaries" id="f_restrict_to_dictionaries" />
                <input type="hidden" name="init" id="f_init" value="1" />
        </form>
        <div class="title">Spell Checker</div>
index 3fc656d..8c7b8f8 100644 (file)
@@ -2,7 +2,7 @@
 *  Copyright notice
 *
 *  (c) 2003 dynarch.com. Authored by Mihai Bazon, sponsored by www.americanbible.org.
-*  (c) 2004-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2004-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -200,11 +200,13 @@ function initDocument() {
        var field = document.getElementById("f_content");
        field.value = HTMLArea.getHTML(editor._doc.body, false, editor);
        document.getElementById("f_init").value = "0";
-       document.getElementById("f_dictionary").value = plugin.contentISOLanguage;
+       document.getElementById("f_dictionary").value = plugin.defaultDictionary ? plugin.defaultDictionary : plugin.contentISOLanguage;
        document.getElementById("f_charset").value = plugin.contentCharset;
        document.getElementById("f_pspell_mode").value = plugin.spellCheckerMode;
        document.getElementById("f_user_uid").value = plugin.userUid;
        document.getElementById("f_personal_dicts").value = plugin.enablePersonalDicts;
+       document.getElementById("f_show_dictionaries").value = plugin.showDictionaries;
+       document.getElementById("f_restrict_to_dictionaries").value = plugin.restrictToDictionaries;
        field.form.submit();
                // assign some global event handlers
        var select = document.getElementById("v_suggestions");
index e973a2b..f9992ff 100644 (file)
@@ -2,7 +2,7 @@
 *  Copyright notice
 *
 *  (c) 2003 dynarch.com. Authored by Mihai Bazon, sponsored by www.americanbible.org.
-*  (c) 2004-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2004-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -49,6 +49,9 @@ SpellChecker = HTMLArea.Plugin.extend({
                this.spellCheckerMode = this.pageTSconfiguration.spellCheckerMode;
                this.enablePersonalDicts = this.pageTSconfiguration.enablePersonalDicts;
                this.userUid = this.editorConfiguration.userUid;
+               this.defaultDictionary = (this.pageTSconfiguration.dictionaries && this.pageTSconfiguration.dictionaries[this.contentISOLanguage] && this.pageTSconfiguration.dictionaries[this.contentISOLanguage].defaultValue) ? this.pageTSconfiguration.dictionaries[this.contentISOLanguage].defaultValue : "";
+               this.showDictionaries = (this.pageTSconfiguration.dictionaries && this.pageTSconfiguration.dictionaries.items) ? this.pageTSconfiguration.dictionaries.items : "";
+               this.restrictToDictionaries = (this.pageTSconfiguration.dictionaries && this.pageTSconfiguration.dictionaries.restrictToItems) ? this.pageTSconfiguration.dictionaries.restrictToItems : "";
 
                /*
                 * Registering plugin "About" information
index 2706c88..d627b0f 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2003-2008 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2003-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
@@ -71,8 +71,8 @@ class tx_rtehtmlarea_pi1 {
                        // Setting start time
                $time_start = microtime(true);
                $this->pspell_is_available = in_array('pspell', get_loaded_extensions());
-               $this->AspellDirectory = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['AspellDirectory'])? trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['AspellDirectory']) : '/usr/bin/aspell';
-               $this->forceCommandMode = (trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['forceCommandMode']))? trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['forceCommandMode']) : 0;
+               $this->AspellDirectory = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['AspellDirectory'])? trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['AspellDirectory']) : '/usr/bin/aspell';
+               $this->forceCommandMode = (trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['forceCommandMode']))? trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['forceCommandMode']) : 0;
                $safe_mode_is_enabled = ini_get('safe_mode');
                if($safe_mode_is_enabled && !$this->pspell_is_available ) echo('Configuration problem: Spell checking cannot be performed');
                if($safe_mode_is_enabled && $this->forceCommandMode) echo('Configuration problem: Spell checking cannot be performed in command mode');
@@ -84,53 +84,34 @@ class tx_rtehtmlarea_pi1 {
                }
 
                        // Setting the list of dictionaries
-               if(!$safe_mode_is_enabled && (!$this->pspell_is_available || $this->forceCommandMode)) {
+               if (!$safe_mode_is_enabled && (!$this->pspell_is_available || $this->forceCommandMode)) {
                        $dictionaryList = shell_exec( $this->AspellDirectory.' dump dicts');
                        $dictionaryList = implode(',', t3lib_div::trimExplode(chr(10), $dictionaryList, 1));
                }
-               if( empty($dictionaryList) ) {
-                       $dictionaryList = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['dictionaryList']);
-               }
-               if( empty($dictionaryList) ) {
-                       $dictionaryList = 'en';
+               if (empty($dictionaryList)) {
+                       $dictionaryList = t3lib_div::_POST('showDictionaries');
+                               // Applying EM variable DEPRECATED as of TYPO3 4.3.0
+                       $dictionaryList = $dictionaryList ? $dictionaryList : trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['dictionaryList']);
                }
                $dictionaryArray = t3lib_div::trimExplode(',', $dictionaryList, 1);
-
-               $defaultDictionary = trim($GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->extKey]['defaultDictionary']);
-               if(!$defaultDictionary || !in_array($defaultDictionary, $dictionaryArray)) {
-                       $defaultDictionary = 'en';
-               }
-
-                       // Get the defined sys_language codes
-               $languageArray = array();
-               $tableA = 'sys_language';
-               $tableB = 'static_languages';
-               $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2';
-               $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
-               $whereClause = '1=1 ';
-               $whereClause .= ' AND ' . $tableA . '.hidden != 1';
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selectFields, $table, $whereClause);
-               while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))    {
-                       $languageArray[] = strtolower($row['lg_iso_2']).($row['lg_country_iso_2']?'_'.$row['lg_country_iso_2']:'');
+               $restrictToDictionaries = t3lib_div::_POST('restrictToDictionaries');
+               if ($restrictToDictionaries) {
+                       $dictionaryArray = array_intersect($dictionaryArray, t3lib_div::trimExplode(',', $restrictToDictionaries, 1));
                }
-               if(!in_array($defaultDictionary, $languageArray)) {
-                       $languageArray[] = $defaultDictionary;
+               if (!count($dictionaryArray)) {
+                       $dictionaryArray[] = 'en';
                }
-               foreach ($dictionaryArray as $key => $dict) {
-                       $lang = explode('-', $dict);
-                       if( !in_array(substr($dict, 0, 2), $languageArray) || !empty($lang[1])) {
-                               unset($dictionaryArray[$key]);
-                       } else {
-                               $dictionaryArray[$key] = $lang[0];
-                       }
+               $this->dictionary = t3lib_div::_POST('dictionary');
+                       // Applying EM variable DEPRECATED as of TYPO3 4.3.0
+               $defaultDictionary = $this->dictionary ? $this->dictionary : trim($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plugins']['SpellChecker']['defaultDictionary']);
+               if (!$defaultDictionary || !in_array($defaultDictionary, $dictionaryArray)) {
+                       $defaultDictionary = 'en';
                }
                uasort($dictionaryArray, 'strcoll');
                $dictionaryList = implode(',', $dictionaryArray);
-
                        // Setting the dictionary
-               $this->dictionary = t3lib_div::_POST('dictionary');
-               if( empty($this->dictionary) || !in_array($this->dictionary, $dictionaryArray)) {
-                       $this->dictionary = $defaultDictionary;
+               if (empty($this->dictionary) || !in_array($this->dictionary, $dictionaryArray)) {
+                       $this->dictionary = 'en';
                }
                $dictionaries = substr_replace($dictionaryList, '@'.$this->dictionary, strpos($dictionaryList, $this->dictionary), strlen($this->dictionary));
 
index 51aea0b..5cfd21a 100644 (file)
@@ -239,7 +239,7 @@ RTE.default {
 
                ## Configuration specific to the spellcheck button or SpellCheck feature (htmlArea RTE only)
                ## Enable the use of personal dictionaries
-       enablePersonalDicts = 1
+       buttons.spellcheck.enablePersonalDictionaries = 1
 }
 
        ## Use same processing as on entry to database to clean content pasted into the editor