TYPO3 API  SVNRelease
class.tx_rtehtmlarea_tableoperations.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2008-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the Typo3 project. The Typo3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 /**
00025  * Table Operations extension for htmlArea RTE
00026  *
00027  * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
00028  *
00029  * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_tableoperations.php 10451 2011-02-12 00:34:01Z stan $
00030  *
00031  */
00032 class tx_rtehtmlarea_tableoperations extends tx_rtehtmlarea_api {
00033 
00034     protected $extensionKey = 'rtehtmlarea';        // The key of the extension that is extending htmlArea RTE
00035     protected $pluginName = 'TableOperations';      // The name of the plugin registered by the extension
00036     protected $relativePathToLocallangFile = '';    // Path to this main locallang file of the extension relative to the extension dir.
00037     protected $relativePathToSkin = 'extensions/TableOperations/skin/htmlarea.css';     // Path to the skin (css) file relative to the extension dir
00038     protected $htmlAreaRTE;                 // Reference to the invoking object
00039     protected $thisConfig;                  // Reference to RTE PageTSConfig
00040     protected $toolbar;                 // Reference to RTE toolbar array
00041     protected $LOCAL_LANG;                  // Frontend language array
00042     protected $requiresClassesConfiguration = true;     // True if the registered plugin requires the PageTSConfig Classes configuration
00043     protected $requiredPlugins = 'TYPO3Color,BlockStyle';   // The comma-separated list of names of prerequisite plugins
00044     protected $pluginButtons = 'table, toggleborders, tableproperties, tablerestyle, rowproperties, rowinsertabove, rowinsertunder, rowdelete, rowsplit,
00045                         columnproperties, columninsertbefore, columninsertafter, columndelete, columnsplit,
00046                         cellproperties, cellinsertbefore, cellinsertafter, celldelete, cellsplit, cellmerge';
00047     protected $convertToolbarForHtmlAreaArray = array (
00048         'table'         => 'InsertTable',
00049         'toggleborders'     => 'TO-toggle-borders',
00050         'tableproperties'   => 'TO-table-prop',
00051         'tablerestyle'      => 'TO-table-restyle',
00052         'rowproperties'     => 'TO-row-prop',
00053         'rowinsertabove'    => 'TO-row-insert-above',
00054         'rowinsertunder'    => 'TO-row-insert-under',
00055         'rowdelete'     => 'TO-row-delete',
00056         'rowsplit'      => 'TO-row-split',
00057         'columnproperties'  => 'TO-col-prop',
00058         'columninsertbefore'    => 'TO-col-insert-before',
00059         'columninsertafter' => 'TO-col-insert-after',
00060         'columndelete'      => 'TO-col-delete',
00061         'columnsplit'       => 'TO-col-split',
00062         'cellproperties'    => 'TO-cell-prop',
00063         'cellinsertbefore'  => 'TO-cell-insert-before',
00064         'cellinsertafter'   => 'TO-cell-insert-after',
00065         'celldelete'        => 'TO-cell-delete',
00066         'cellsplit'     => 'TO-cell-split',
00067         'cellmerge'     => 'TO-cell-merge',
00068         );
00069     public function main($parentObject) {
00070         $available = parent::main($parentObject);
00071         if ($this->htmlAreaRTE->client['browser'] == 'opera') {
00072             $this->thisConfig['hideTableOperationsInToolbar'] = 0;
00073         }
00074         return $available;
00075     }
00076     /**
00077      * Return JS configuration of the htmlArea plugins registered by the extension
00078      *
00079      * @param   integer     Relative id of the RTE editing area in the form
00080      *
00081      * @return  string      JS configuration for registered plugins, in this case, JS configuration of block elements
00082      *
00083      * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
00084      * Each of the instructions should be of the form:
00085      *  RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
00086      */
00087     public function buildJavascriptConfiguration($RTEcounter) {
00088         global $TSFE, $LANG;
00089 
00090         $registerRTEinJavascriptString = '';
00091         if (in_array('table', $this->toolbar)) {
00092 
00093                 // Combining fieldset disablers as a list
00094             $disabledFieldsets = array('Alignment', 'Borders', 'Color', 'Description', 'Layout', 'RowGroup', 'Spacing', 'Style');
00095             foreach ($disabledFieldsets as $index => $fieldset) {
00096                 if (!trim($this->thisConfig['disable'.$fieldset.'FieldsetInTableOperations'])) {
00097                     unset($disabledFieldsets[$index]);
00098                 }
00099             }
00100             $disabledFieldsets = strtolower(implode(',', $disabledFieldsets));
00101 
00102                 // Dialogue fieldsets removal configuration
00103             if ($disabledFieldsets) {
00104                 $dialogues = array('table', 'tableproperties', 'rowproperties', 'columnproperties', 'cellproperties');
00105                 foreach ($dialogues as $dialogue) {
00106                     if (in_array($dialogue, $this->toolbar)) {
00107                         if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.'][$dialogue.'.'])) {
00108                             $registerRTEinJavascriptString .= '
00109                     RTEarea['.$RTEcounter.'].buttons.'.$dialogue.' = new Object();
00110                     RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = "' . $disabledFieldsets . '";';
00111                         } else if ($this->thisConfig['buttons.'][$dialogue.'.']['removeFieldsets']) {
00112                             $registerRTEinJavascriptString .= '
00113                     RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets += ",' . $disabledFieldsets . '";';
00114                         } else {
00115                             $registerRTEinJavascriptString .= '
00116                     RTEarea['.$RTEcounter.'].buttons.'.$dialogue.'.removeFieldsets = ",' . $disabledFieldsets . '";';
00117                         }
00118                     }
00119                 }
00120             }
00121 
00122             $registerRTEinJavascriptString .= '
00123             RTEarea['.$RTEcounter.'].hideTableOperationsInToolbar = ' . (trim($this->thisConfig['hideTableOperationsInToolbar']) ? 'true' : 'false') . ';';
00124         }
00125         return $registerRTEinJavascriptString;
00126     }
00127     /**
00128      * Return an updated array of toolbar enabled buttons
00129      *
00130      * @param   array       $show: array of toolbar elements that will be enabled, unless modified here
00131      *
00132      * @return  array       toolbar button array, possibly updated
00133      */
00134     public function applyToolbarConstraints($show) {
00135             // We will not allow any table operations button if the table button is not enabled
00136         if (!in_array('table', $show)) {
00137             return array_diff($show, t3lib_div::trimExplode(',', $this->pluginButtons));
00138         } else {
00139             return $show;
00140         }
00141     }
00142 }
00143 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php'])) {
00144     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/TableOperations/class.tx_rtehtmlarea_tableoperations.php']);
00145 }
00146 ?>