Added feature #13580: htmlArea RTE: Extjize the RTE
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / class.tx_rtehtmlareaapi.php
index d8de86f..790bd03 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 2007 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+*  (c) 2007-2009 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the Typo3 project. The Typo3 project is
 /**
  * API for extending htmlArea RTE
  *
- * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
+ * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
  *
- * TYPO3 CVS ID: $Id$
+ * TYPO3 SVN ID: $Id$
  *
  */
 
-require_once(PATH_t3lib.'class.t3lib_div.php');
-
 abstract class tx_rtehtmlareaapi {
-       
+
        protected $extensionKey;                                // The key of the extension that is extending htmlArea RTE
-       protected $relativePathToLocallangFile;                 // Path to this main locallang file of the extension relative to the extension dir.
-       protected $relativePathToSkin;                          // Path to the skin (css) file relative to the extension dir.
+       protected $pluginName;                                  // The name of the plugin registered by the extension
+       protected $relativePathToLocallangFile;                 // Path to the localization file for this script, relative to the extension dir
+       protected $relativePathToSkin;                          // Path to the skin (css) file that should be added to the RTE skin when the registered plugin is enabled, relative to the extension dir
+       protected $relativePathToPluginDirectory;               // Path to the directory containing the plugin, relative to the extension dir (should end with slash /)
        protected $htmlAreaRTE;                                 // Reference to the invoking object
+       protected $rteExtensionKey;                             // The extension key of the RTE
        protected $thisConfig;                                  // Reference to RTE PageTSConfig
-       protected $toolBar;                                     // Refrence to RTE toolbar array
+       protected $toolbar;                                     // Refrence to RTE toolbar array
        protected $LOCAL_LANG;                                  // Frontend language array
-       protected $pluginButtons = '';                          // The comma-seperated list of button names that the extension id adding to the htmlArea RTE tollbar
+       protected $pluginButtons = '';                          // The comma-separated list of button names that the registered plugin is adding to the htmlArea RTE toolbar
+       protected $pluginLabels = '';                           // The comma-separated list of label names that the registered plugin is adding to the htmlArea RTE toolbar
+       protected $pluginAddsButtons = true;                    // Boolean indicating whether the plugin is adding buttons or not
        protected $convertToolbarForHtmlAreaArray = array();    // The name-converting array, converting the button names used in the RTE PageTSConfing to the button id's used by the JS scripts
-       
+       protected $requiresClassesConfiguration = false;        // True if the registered plugin requires the PageTSConfig Classes configuration
+       protected $requiresSynchronousLoad = false;             // True if the plugin must be loaded synchronously
+       protected $requiredPlugins = '';                        // The comma-separated list of names of prerequisite plugins
+
        /**
         * Returns true if the plugin is available and correctly initialized
         *
@@ -52,26 +58,33 @@ abstract class tx_rtehtmlareaapi {
         * @return      boolean         true if this plugin object should be made available in the current environment and is correctly initialized
         */
        public function main($parentObject) {
-               global $TYPO3_CONF_VARS, $LANG;
-               
-               $this->htmlAreaRTE =& $parentObject;
+               global $TYPO3_CONF_VARS, $LANG, $TSFE;
+
+               $this->htmlAreaRTE = $parentObject;
+               $this->rteExtensionKey =& $this->htmlAreaRTE->ID;
                $this->thisConfig =& $this->htmlAreaRTE->thisConfig;
                $this->toolbar =& $this->htmlAreaRTE->toolbar;
-               
+               $this->LOCAL_LANG =& $this->htmlAreaRTE->LOCAL_LANG;
+
+                       // Set the value of this boolean based on the initial value of $this->pluginButtons
+               $this->pluginAddsButtons = !empty($this->pluginButtons);
+
                        // Check if the plugin should be disabled in frontend
-               if ($this->htmlAreaRTE->is_FE() && is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]) && $TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]['disableInFE']) {
+               if ($this->htmlAreaRTE->is_FE() && $TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['disableInFE']) {
                        return false;
                }
-               
+
                        // Localization array must be initialized here
-               if ($this->htmlAreaRTE->is_FE()) {
-                       $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile, $this->htmlAreaRTE->language);
-               } else {
-                       $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
+               if ($this->relativePathToLocallangFile) {
+                       if ($this->htmlAreaRTE->is_FE()) {
+                               $this->LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($this->LOCAL_LANG, t3lib_div::readLLfile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile, $this->htmlAreaRTE->language));
+                       } else {
+                               $LANG->includeLLFile('EXT:' . $this->extensionKey . '/' . $this->relativePathToLocallangFile);
+                       }
                }
                return true;
        }
-       
+
        /**
         * Returns a modified toolbar order string
         *
@@ -82,7 +95,7 @@ abstract class tx_rtehtmlareaapi {
                $addButtons = implode(',', array_diff(t3lib_div::trimExplode(',', $this->pluginButtons, 1), t3lib_div::trimExplode(',', $this->htmlAreaRTE->defaultToolbarOrder, 1)));
                return (($addButtons ? ('bar,'  . $addButtons . ',linebreak,') : '')  . $this->htmlAreaRTE->defaultToolbarOrder);
        }
-       
+
        /**
         * Returns the path to the skin component (button icons) that should be added to linked stylesheets
         *
@@ -90,39 +103,40 @@ abstract class tx_rtehtmlareaapi {
         */
        public function getPathToSkin() {
                global $TYPO3_CONF_VARS;
-               if (is_array($TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]) && $TYPO3_CONF_VARS['EXTCONF'][$this->extensionKey]['addIconsToSkin']) {
+               if ($TYPO3_CONF_VARS['EXTCONF'][$this->rteExtensionKey]['plugins'][$this->pluginName]['addIconsToSkin']) {
                        return $this->relativePathToSkin;
                } else {
                        return '';
                }
        }
-       
+
        /**
         * Return JS configuration of the htmlArea plugins registered by the extension
         *
         * @param       integer         Relative id of the RTE editing area in the form
         *
         * @return      string          JS configuration for registered plugins
-        * 
+        *
         * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
         * Each of the instructions should be of the form:
         *      RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
         */
        public function buildJavascriptConfiguration($RTEcounter) {
                global $TSFE, $LANG;
-               
+
                $registerRTEinJavascriptString = '';
-               foreach($this->pluginButtons as $button) {
-                       if (in_array($button, $this->toolBar)) {
+               $pluginButtons = t3lib_div::trimExplode(',', $this->pluginButtons, 1);
+               foreach ($pluginButtons as $button) {
+                       if (in_array($button, $this->toolbar)) {
                                if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$button.'.'])) {
                                        $registerRTEinJavascriptString .= '
-                                       RTEarea['.$RTEcounter.']["buttons"]["'. $button .'"] = new Object();';
+                       RTEarea['.$RTEcounter.'].buttons.'. $button .' = new Object();';
                                }
                        }
                }
                return $registerRTEinJavascriptString;
        }
-       
+
        /**
         * Returns the extension key
         *
@@ -131,7 +145,25 @@ abstract class tx_rtehtmlareaapi {
        public function getExtensionKey() {
                return $this->extensionKey;
        }
-       
+
+       /**
+        * Returns the path to the plugin directory, if any
+        *
+        * @return      string          the full path to the plugin directory
+        */
+       public function getPathToPluginDirectory() {
+               return ($this->relativePathToPluginDirectory ? $this->htmlAreaRTE->httpTypo3Path . t3lib_extMgm::siteRelPath($this->extensionKey) . $this->relativePathToPluginDirectory : '');
+       }
+
+       /**
+        * Returns a boolean indicating whether the plugin adds buttons or not to the toolbar
+        *
+        * @return      boolean
+        */
+       public function addsButtons() {
+               return $this->pluginAddsButtons;
+       }
+
        /**
         * Returns the list of buttons implemented by the plugin
         *
@@ -140,7 +172,16 @@ abstract class tx_rtehtmlareaapi {
        public function getPluginButtons() {
                return $this->pluginButtons;
        }
-       
+
+       /**
+        * Returns the list of toolbar labels implemented by the plugin
+        *
+        * @return      string          the list of labels implemented by the plugin
+        */
+       public function getPluginLabels() {
+               return $this->pluginLabels;
+       }
+
        /**
         * Returns the conversion array from TYPO3 button names to htmlArea button names
         *
@@ -150,6 +191,43 @@ abstract class tx_rtehtmlareaapi {
                return $this->convertToolbarForHtmlAreaArray;
        }
 
+       /**
+        * Returns true if the extension requires the PageTSConfig Classes configuration
+        *
+        * @return      boolean         true if the extension requires the PageTSConfig Classes configuration
+        */
+       public function requiresClassesConfiguration() {
+               return $this->requiresClassesConfiguration;
+       }
+
+       /**
+        * Returns true if the plugin requires synchronous load
+        *
+        * @return      boolean         true if the plugin requires synchronous load
+        */
+       public function requiresSynchronousLoad() {
+               return $this->requiresSynchronousLoad;
+       }
+
+       /**
+        * Sets the plugin to require synchronous load or not
+        *
+        * @param       boolean         $value: the boolean value to set
+        *
+        * @return      void
+        */
+       public function setSynchronousLoad($value = true) {
+               $this->requiresSynchronousLoad = $value;
+       }
+
+       /**
+        * Returns the list of plugins required by the plugin
+        *
+        * @return      string          the list of plugins required by the plugin
+        */
+       public function getRequiredPlugins() {
+               return $this->requiredPlugins;
+       }
 } // end of class
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/class.tx_rtehtmlareaapi.php']) {