TYPO3 API  SVNRelease
class.tx_rtehtmlarea_blockelements.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2007-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  * BlockElements extension for htmlArea RTE
00026  *
00027  * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
00028  *
00029  * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_blockelements.php 10120 2011-01-18 20:03:36Z ohader $
00030  *
00031  */
00032 class tx_rtehtmlarea_blockelements extends tx_rtehtmlarea_api {
00033 
00034     protected $extensionKey = 'rtehtmlarea';        // The key of the extension that is extending htmlArea RTE
00035     protected $pluginName = 'BlockElements';        // The name of the plugin registered by the extension
00036     protected $relativePathToLocallangFile = 'extensions/BlockElements/locallang.xml';  // Path to this main locallang file of the extension relative to the extension dir.
00037     protected $relativePathToSkin = 'extensions/BlockElements/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 
00043     protected $pluginButtons = 'formatblock, indent, outdent, blockquote, insertparagraphbefore, insertparagraphafter, left, center, right, justifyfull, orderedlist, unorderedlist, line';
00044     protected $convertToolbarForHtmlAreaArray = array (
00045         'formatblock'       => 'FormatBlock',
00046         'indent'        => 'Indent',
00047         'outdent'       => 'Outdent',
00048         'blockquote'        => 'Blockquote',
00049         'insertparagraphbefore' => 'InsertParagraphBefore',
00050         'insertparagraphafter'  => 'InsertParagraphAfter',
00051         'left'          => 'JustifyLeft',
00052         'center'        => 'JustifyCenter',
00053         'right'         => 'JustifyRight',
00054         'justifyfull'       => 'JustifyFull',
00055         'orderedlist'       => 'InsertOrderedList',
00056         'unorderedlist'     => 'InsertUnorderedList',
00057         'line'          => 'InsertHorizontalRule',
00058         );
00059 
00060     protected $defaultBlockElements = array(
00061         'none'      => 'No block',
00062         'p'     => 'Paragraph',
00063         'h1'        => 'Heading 1',
00064         'h2'        => 'Heading 2',
00065         'h3'        => 'Heading 3',
00066         'h4'        => 'Heading 4',
00067         'h5'        => 'Heading 5',
00068         'h6'        => 'Heading 6',
00069         'pre'       => 'Preformatted',
00070         'address'   => 'Address',
00071         'blockquote'    => 'Long quotation',
00072         'div'       => 'Section',
00073     );
00074 
00075     protected $defaultBlockElementsOrder = 'none, p, h1, h2, h3, h4, h5, h6, pre, address, blockquote, div';
00076 
00077     /**
00078      * Return JS configuration of the htmlArea plugins registered by the extension
00079      *
00080      * @param   integer     Relative id of the RTE editing area in the form
00081      *
00082      * @return  string      JS configuration for registered plugins, in this case, JS configuration of block elements
00083      *
00084      * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
00085      * Each of the instructions should be of the form:
00086      *  RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
00087      */
00088     public function buildJavascriptConfiguration($RTEcounter) {
00089         global $TSFE, $LANG;
00090 
00091         $registerRTEinJavascriptString = '';
00092         if (in_array('formatblock', $this->toolbar)) {
00093             if (!is_array( $this->thisConfig['buttons.']) || !is_array( $this->thisConfig['buttons.']['formatblock.'])) {
00094                 $registerRTEinJavascriptString .= '
00095             RTEarea['.$RTEcounter.'].buttons.formatblock = new Object();';
00096             }
00097                 // Default block elements
00098             $hideItems = array();
00099             $addItems = array();
00100             $restrictTo = array('*');
00101             $blockElementsOrder = $this->defaultBlockElementsOrder;
00102             $prefixLabelWithTag = false;
00103             $postfixLabelWithTag = false;
00104 
00105                 // Processing PageTSConfig
00106             if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['formatblock.'])) {
00107                     // Removing elements
00108                 if ($this->thisConfig['buttons.']['formatblock.']['removeItems']) {
00109                     $hideItems =  t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['removeItems'])), 1);
00110                 }
00111                     // Adding elements
00112                 if ($this->thisConfig['buttons.']['formatblock.']['addItems']) {
00113                     $addItems =  t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['addItems'])), 1);
00114                 }
00115                     // Restriction clause
00116                 if ($this->thisConfig['buttons.']['formatblock.']['restrictToItems']) {
00117                     $restrictTo =  t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList('none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['restrictToItems'])), 1);
00118                 }
00119                     // Elements order
00120                 if ($this->thisConfig['buttons.']['formatblock.']['orderItems']) {
00121                     $blockElementsOrder = 'none,'.t3lib_div::strtolower($this->thisConfig['buttons.']['formatblock.']['orderItems']);
00122                 }
00123                 $prefixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['prefixLabelWithTag']) ? true : $prefixLabelWithTag;
00124                 $postfixLabelWithTag = ($this->thisConfig['buttons.']['formatblock.']['postfixLabelWithTag']) ? true : $postfixLabelWithTag;
00125             }
00126                 // Processing old style configuration for hiding paragraphs
00127             if ($this->thisConfig['hidePStyleItems']) {
00128                 $hideItems = array_merge($hideItems, t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList(t3lib_div::strtolower($this->thisConfig['hidePStyleItems'])), 1));
00129             }
00130                 // Adding custom items
00131             $blockElementsOrder = array_merge(t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($blockElementsOrder), 1), $addItems);
00132                 // Applying User TSConfig restriction
00133             $blockElementsOrder = array_diff($blockElementsOrder, $hideItems);
00134             if (!in_array('*', $restrictTo)) {
00135                 $blockElementsOrder = array_intersect($blockElementsOrder, $restrictTo);
00136             }
00137                 // Localizing the options
00138             $blockElementsOptions = array();
00139             if ($this->htmlAreaRTE->cleanList($this->thisConfig['hidePStyleItems']) != '*') {
00140                 $labels = array();
00141                 if (is_array($this->thisConfig['buttons.'])
00142                         && is_array($this->thisConfig['buttons.']['formatblock.'])
00143                         && is_array($this->thisConfig['buttons.']['formatblock.']['items.'])) {
00144                     $labels = $this->thisConfig['buttons.']['formatblock.']['items.'];
00145                 }
00146                 foreach ($blockElementsOrder as $item) {
00147                     if ($this->htmlAreaRTE->is_FE()) {
00148                         $blockElementsOptions[$item] = $TSFE->getLLL($this->defaultBlockElements[$item],$this->LOCAL_LANG);
00149                     } else {
00150                         $blockElementsOptions[$item] = $LANG->getLL($this->defaultBlockElements[$item]);
00151                     }
00152                     // Getting custom labels
00153                     if (is_array($labels[$item.'.']) && $labels[$item.'.']['label']) {
00154                         $blockElementsOptions[$item] = $this->htmlAreaRTE->getPageConfigLabel($labels[$item.'.']['label'], 0);
00155                     }
00156                     $blockElementsOptions[$item] = (($prefixLabelWithTag && $item != 'none')?($item . ' - '):'') . $blockElementsOptions[$item] . (($postfixLabelWithTag && $item != 'none')?(' - ' . $item):'');
00157                 }
00158             }
00159 
00160             $first = array_shift($blockElementsOptions);
00161                 // Sorting the options
00162             if (!is_array($this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.']['formatblock.']) || !$this->thisConfig['buttons.']['formatblock.']['orderItems']) {
00163                 asort($blockElementsOptions);
00164             }
00165                 // Generating the javascript options
00166             $JSBlockElements = array();
00167             $JSBlockElements[] = array($first, 'none');
00168             foreach ($blockElementsOptions as $item => $label) {
00169                 $JSBlockElements[] = array($label, $item);
00170             }
00171             if ($this->htmlAreaRTE->is_FE()) {
00172                 $GLOBALS['TSFE']->csConvObj->convArray($JSBlockElements, $this->htmlAreaRTE->OutputCharset, 'utf-8');
00173             } else {
00174                 $GLOBALS['LANG']->csConvObj->convArray($JSBlockElements, $GLOBALS['LANG']->charSet, 'utf-8');
00175             }
00176             $registerRTEinJavascriptString .= '
00177             RTEarea['.$RTEcounter.'].buttons.formatblock.options = ' . json_encode($JSBlockElements) . ';';
00178         }
00179         return $registerRTEinJavascriptString;
00180     }
00181 }
00182 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php'])) {
00183     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/BlockElements/class.tx_rtehtmlarea_blockelements.php']);
00184 }
00185 ?>