TYPO3 API  SVNRelease
class.tx_rtehtmlarea_selectfont.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  * SelectFont extension for htmlArea RTE
00026  *
00027  * @author Stanislas Rolland <typo3(arobas)sjbr.ca>
00028  *
00029  * TYPO3 SVN ID: $Id: class.tx_rtehtmlarea_selectfont.php 10120 2011-01-18 20:03:36Z ohader $
00030  *
00031  */
00032 class tx_rtehtmlarea_selectfont extends tx_rtehtmlarea_api {
00033 
00034     protected $extensionKey = 'rtehtmlarea';    // The key of the extension that is extending htmlArea RTE
00035     protected $pluginName = 'SelectFont';   // The name of the plugin registered by the extension
00036     protected $relativePathToLocallangFile = 'extensions/SelectFont/locallang.xml'; // Path to this main locallang file of the extension relative to the extension dir.
00037     protected $relativePathToSkin = '';     // 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 = 'fontstyle,fontsize';
00044     protected $convertToolbarForHtmlAreaArray = array (
00045         'fontstyle'     => 'FontName',
00046         'fontsize'      => 'FontSize',
00047         );
00048 
00049     protected $defaultFont = array(
00050         'fontstyle' => array(
00051             'Arial'         => 'Arial,sans-serif',
00052             'Arial Black'       => '\'Arial Black\',sans-serif',
00053             'Verdana'       => 'Verdana,Arial,sans-serif',
00054             'Times New Roman'   => '\'Times New Roman\',Times,serif',
00055             'Garamond'      => 'Garamond',
00056             'Lucida Handwriting'    => '\'Lucida Handwriting\'',
00057             'Courier'       => 'Courier',
00058             'Webdings'      => 'Webdings',
00059             'Wingdings'     => 'Wingdings',
00060             ),
00061         'fontsize' => array(
00062             'Extra small'   =>  '8px',
00063             'Very small'    =>  '9px',
00064             'Small'     =>  '10px',
00065             'Medium'    =>  '12px',
00066             'Large'     =>  '16px',
00067             'Very large'    =>  '24px',
00068             'Extra large'   =>  '32px',
00069             ),
00070         );
00071 
00072     protected $RTEProperties;
00073 
00074     public function main($parentObject) {
00075         $enabled = parent::main($parentObject) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rtehtmlarea']['allowStyleAttribute'];
00076         if ($this->htmlAreaRTE->is_FE()) {
00077             $this->RTEProperties = $this->htmlAreaRTE->RTEsetup;
00078         } else {
00079             $this->RTEProperties = $this->htmlAreaRTE->RTEsetup['properties'];
00080         }
00081         return $enabled;
00082     }
00083 
00084     /**
00085      * Return JS configuration of the htmlArea plugins registered by the extension
00086      *
00087      * @param   integer     Relative id of the RTE editing area in the form
00088      *
00089      * @return string       JS configuration for registered plugins
00090      *
00091      * The returned string will be a set of JS instructions defining the configuration that will be provided to the plugin(s)
00092      * Each of the instructions should be of the form:
00093      *  RTEarea['.$RTEcounter.']["buttons"]["button-id"]["property"] = "value";
00094      */
00095     public function buildJavascriptConfiguration($RTEcounter) {
00096         $registerRTEinJavascriptString = '';
00097         $pluginButtonsArray = t3lib_div::trimExplode(",", $this->pluginButtons);
00098 
00099             // Process Page TSConfig configuration for each button
00100         foreach ($pluginButtonsArray as $buttonId) {
00101             if (in_array($buttonId, $this->toolbar)) {
00102                 $registerRTEinJavascriptString .= $this->buildJSFontItemsConfig($RTEcounter, $buttonId);
00103             }
00104         }
00105         return $registerRTEinJavascriptString;
00106     }
00107 
00108     /**
00109      * Return Javascript configuration of font faces
00110      *
00111      * @param   integer     $RTEcounter: The index number of the current RTE editing area within the form.
00112      * @param   string      $buttonId: button id
00113      *
00114      * @return  string      Javascript configuration of font faces
00115      */
00116     protected function buildJSFontItemsConfig($RTEcounter, $buttonId) {
00117         $configureRTEInJavascriptString = '';
00118 
00119             // Getting removal and addition configuration
00120         $hideItems = $this->htmlAreaRTE->cleanList($this->thisConfig['hideFont' .  (($buttonId == 'fontstyle') ? 'Faces' : 'Sizes')]);
00121         $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig[($buttonId == 'fontstyle') ? 'fontFace' : 'fontSize']), 1);
00122         if (is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
00123             if ($this->thisConfig['buttons.'][$buttonId . '.']['removeItems']) {
00124                 $hideItems = $this->thisConfig['buttons.'][$buttonId . '.']['removeItems'];
00125             }
00126             if ($this->thisConfig['buttons.'][$buttonId . '.']['addItems']) {
00127                 $addItems = t3lib_div::trimExplode(',', $this->htmlAreaRTE->cleanList($this->thisConfig['buttons.'][$buttonId . '.']['addItems']), 1);
00128             }
00129         }
00130             // Initializing the items array
00131         $items = array();
00132         if ($this->htmlAreaRTE->is_FE()) {
00133             $items['none'] = array($GLOBALS['TSFE']->getLLL((($buttonId == 'fontstyle') ? 'Default font' : 'Default size'), $this->LOCAL_LANG), 'none');
00134         } else {
00135             $items['none'] = array(($GLOBALS['LANG']->getLL(($buttonId == 'fontstyle') ? 'Default font' : 'Default size')), 'none');
00136         }
00137             // Inserting and localizing default items
00138         if ($hideItems != '*') {
00139             $index = 0;
00140             foreach ($this->defaultFont[$buttonId] as $name => $value) {
00141                 if (!t3lib_div::inList($hideItems, strval($index+1))) {
00142                     if ($this->htmlAreaRTE->is_FE()) {
00143                         $label = $GLOBALS['TSFE']->getLLL($name,$this->LOCAL_LANG);
00144                     } else {
00145                         $label = $GLOBALS['LANG']->getLL($name);
00146                         if (!$label) {
00147                             $label = $name;
00148                         }
00149                     }
00150                     $items[$name] = array($label, $this->htmlAreaRTE->cleanList($value));
00151                 }
00152                 $index++;
00153             }
00154         }
00155             // Adding configured items
00156         if (is_array($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'])) {
00157             foreach ($this->RTEProperties[($buttonId == 'fontstyle') ? 'fonts.' : 'fontSizes.'] as $name => $conf) {
00158                 $name = substr($name,0,-1);
00159                 if (in_array($name, $addItems)) {
00160                     $label = $this->htmlAreaRTE->getPageConfigLabel($conf['name'],0);
00161                     $items[$name] = array($label, $this->htmlAreaRTE->cleanList($conf['value']));
00162                 }
00163             }
00164         }
00165             // Seting default item
00166         if ($this->thisConfig['buttons.'][$buttonId . '.']['defaultItem'] && $items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]) {
00167             $items['none'] = array($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']][0], 'none');
00168             unset($items[$this->thisConfig['buttons.'][$buttonId . '.']['defaultItem']]);
00169         }
00170             // Setting the JS list of options
00171         $itemsJSArray = array();
00172         foreach ($items as $name => $option) {
00173             $itemsJSArray[] = array('text' => $option[0], 'value' => $option[1]);
00174         }
00175         if ($this->htmlAreaRTE->is_FE()) {
00176             $GLOBALS['TSFE']->csConvObj->convArray($itemsJSArray, $this->htmlAreaRTE->OutputCharset, 'utf-8');
00177         } else {
00178             $GLOBALS['LANG']->csConvObj->convArray($itemsJSArray, $GLOBALS['LANG']->charSet, 'utf-8');
00179         }
00180         $itemsJSArray = json_encode(array('options' => $itemsJSArray));
00181             // Adding to button JS configuration
00182         if (!is_array( $this->thisConfig['buttons.']) || !is_array($this->thisConfig['buttons.'][$buttonId . '.'])) {
00183             $configureRTEInJavascriptString .= '
00184             RTEarea['.$RTEcounter.'].buttons.'. $buttonId .' = new Object();';
00185         }
00186         $configureRTEInJavascriptString .= '
00187             RTEarea['.$RTEcounter.'].buttons.'. $buttonId . '.dataUrl = \'' . $this->htmlAreaRTE->writeTemporaryFile('', $buttonId . '_'. $this->htmlAreaRTE->contentLanguageUid, 'js', $itemsJSArray) . '\';';
00188         return $configureRTEInJavascriptString;
00189     }
00190 }
00191 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php'])) {
00192     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/extensions/SelectFont/class.tx_rtehtmlarea_selectfont.php']);
00193 }
00194 ?>