[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/typo3/sysext/rtehtmlarea/pi2/ -> class.tx_rtehtmlarea_pi2.php (source)

   1  <?php
   2  /***************************************************************
   3  *  Copyright notice
   4  *
   5  *  (c) 2005-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
   6  *  All rights reserved
   7  *
   8  *  This script is part of the TYPO3 project. The TYPO3 project is
   9  *  free software; you can redistribute it and/or modify
  10  *  it under the terms of the GNU General Public License as published by
  11  *  the Free Software Foundation; either version 2 of the License, or
  12  *  (at your option) any later version.
  13  *
  14  *  The GNU General Public License can be found at
  15  *  http://www.gnu.org/copyleft/gpl.html.
  16  *  A copy is found in the textfile GPL.txt and important notices to the license
  17  *  from the author is found in LICENSE.txt distributed with these scripts.
  18  *
  19  *
  20  *  This script is distributed in the hope that it will be useful,
  21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23  *  GNU General Public License for more details.
  24  *
  25  *  This copyright notice MUST APPEAR in all copies of the script!
  26  ***************************************************************/
  27  /**
  28   * Front end RTE based on htmlArea
  29   *
  30   * @author Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca>
  31   *
  32   * $Id: class.tx_rtehtmlarea_pi2.php 1676 2006-08-15 04:51:33Z stanrolland $  *
  33   */
  34  
  35  require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php');
  36  require_once(PATH_t3lib.'class.t3lib_parsehtml_proc.php');
  37  require_once(PATH_t3lib.'class.t3lib_befunc.php');
  38  
  39  class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
  40  
  41          // External:
  42      var $RTEWrapStyle = '';                // Alternative style for RTE wrapper <div> tag.
  43      var $RTEdivStyle = '';                // Alternative style for RTE <div> tag.
  44      var $extHttpPath;                // full Path to this extension for http (so no Server path). It ends with "/"
  45  
  46          // For the editor
  47      var $elementId;
  48      var $elementParts;
  49      var $tscPID;
  50      var $typeVal;
  51      var $thePid;
  52      var $RTEsetup;
  53      var $thisConfig;
  54      var $confValues;
  55      var $language;
  56      var $spellCheckerLanguage;
  57      var $spellCheckerCharset;
  58      var $spellCheckerMode;
  59      var $specConf;
  60      var $LOCAL_LANG;
  61  
  62      /**
  63       * Draws the RTE as an iframe
  64       *
  65       * @param    object        Reference to parent object, which is an instance of the TCEforms.
  66       * @param    string        The table name
  67       * @param    string        The field name
  68       * @param    array        The current row from which field is being rendered
  69       * @param    array        Array of standard content for rendering form fields from TCEforms. See TCEforms for details on this. Includes for instance the value and the form field name, java script actions and more.
  70       * @param    array        "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array.
  71       * @param    array        Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc.
  72       * @param    string        Record "type" field value.
  73       * @param    string        Relative path for images/links in RTE; this is used when the RTE edits content from static files where the path of such media has to be transformed forth and back!
  74       * @param    integer        PID value of record (true parent page id)
  75       * @return    string        HTML code for RTE!
  76       */
  77  	function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
  78          global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
  79          
  80              //call $this->transformContent
  81              //call $this->triggerField
  82                  $this->TCEform = $pObj;
  83          $this->client = $this->clientInfo();
  84          $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
  85  
  86          /* =======================================
  87           * INIT THE EDITOR-SETTINGS
  88           * =======================================
  89           */
  90  
  91              // first get the http-path to typo3:
  92          $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
  93          if (strlen($this->httpTypo3Path) == 1) {
  94              $this->httpTypo3Path = '/';
  95          } else {
  96              $this->httpTypo3Path .= '/';
  97          }
  98              // Get the path to this extension:
  99          $this->extHttpPath = $this->httpTypo3Path.t3lib_extMgm::siteRelPath($this->ID);
 100              // Get the site URL
 101          $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
 102              // Get the host URL
 103          $this->hostURL = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
 104  
 105              // Element ID + pid
 106          $this->elementId = $PA['itemFormElName'];
 107          $this->elementParts[0] = $table;
 108          $this->elementParts[1] = $row['uid'];
 109          $this->tscPID = $thePidValue;
 110          $this->thePid = $thePidValue;
 111  
 112              // Record "type" field value:
 113          $this->typeVal = $RTEtypeVal; // TCA "type" value for record
 114  
 115          unset($this->RTEsetup);
 116          $pageTSConfig = $TSFE->getPagesTSconfig();
 117          $this->RTEsetup = $pageTSConfig['RTE.'];
 118          $this->thisConfig = $this->RTEsetup['default.'];
 119          $this->thisConfig = $this->thisConfig['FE.'];
 120  
 121              // Special configuration (line) and default extras:
 122          $this->specConf = $specConf;
 123          
 124          if ($this->thisConfig['forceHTTPS']) {
 125              $this->httpTypo3Path = preg_replace('/^(http|https)/', 'https', $this->httpTypo3Path);
 126              $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath);
 127              $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL);
 128              $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL);
 129          }
 130          
 131              // Language
 132          $TSFE->initLLvars();
 133          $this->language = $TSFE->lang;
 134          $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
 135          if ($this->language=='default' || !$this->language)    {
 136              $this->language='en';
 137          }
 138              // Character set
 139          $this->charset = $TSFE->labelsCharset;
 140          $this->OutputCharset  = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
 141  
 142          /* =======================================
 143           * TOOLBAR CONFIGURATION
 144           * =======================================
 145           */
 146              // htmlArea plugins list
 147          $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
 148          $hidePlugins = array('TYPO3Browsers', 'UserElements', 'Acronym', 'TYPO3HtmlParser');
 149          if ($this->client['BROWSER'] == 'opera') {
 150              $hidePlugins[] = 'ContextMenu';
 151              $this->thisConfig['hideTableOperationsInToolbar'] = 0;
 152              $this->thisConfig['disableEnterParagraphs'] = 1;
 153          }
 154          if(!t3lib_extMgm::isLoaded('static_info_tables') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
 155          $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
 156          $this->pluginEnableArrayMultiple = $this->pluginEnableArray;
 157  
 158              // Toolbar
 159          $this->setToolBar();
 160  
 161              // Check if some plugins need to be disabled
 162          $this->setPlugins();
 163  
 164          /* =======================================
 165           * PLUGIN-SPECIFIC CONFIGURATION
 166           * =======================================
 167           */
 168  
 169          if( $this->isPluginEnable('SpellChecker') ) {
 170                  // Set the language of the content for the SpellChecker
 171              $this->spellCheckerLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
 172              if($row['sys_language_uid']) {
 173                  $tableA = 'sys_language';
 174                  $tableB = 'static_languages';
 175                  $languagesUidsList = $row['sys_language_uid'];
 176                  $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
 177                  $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
 178                  $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
 179                  $whereClause .= $TSFE->cObj->enableFields($tableA);
 180                  $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $whereClause);
 181                  while ( $languageRow = $TYPO3_DB->sql_fetch_assoc($res) ) {
 182                      $this->spellCheckerLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
 183                      $this->spellCheckerTypo3Language = strtolower(trim($languageRow['lg_typo3']));
 184                  }
 185              }
 186              $this->spellCheckerLanguage = $this->spellCheckerLanguage?$this->spellCheckerLanguage:$this->language;
 187              $this->spellCheckerTypo3Language = $this->spellCheckerTypo3Language?$this->spellCheckerTypo3Language:$TSFE->lang;
 188              if ($this->spellCheckerTypo3Language=='default') {
 189                  $this->spellCheckerTypo3Language='en';
 190              }
 191  
 192                  // Set the charset of the content for the SpellChecker
 193              $this->spellCheckerCharset = $TSFE->csConvObj->charSetArray[$this->spellCheckerTypo3Language];
 194              $this->spellCheckerCharset = $this->spellCheckerCharset ? $this->spellCheckerCharset : 'iso-8859-1';
 195              $this->spellCheckerCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->spellCheckerCharset;
 196  
 197                  // Set the SpellChecker mode
 198              $this->spellCheckerMode = isset($this->thisConfig['HTMLAreaPspellMode']) ? trim($this->thisConfig['HTMLAreaPspellMode']) : 'normal';
 199              if( !in_array($this->spellCheckerMode, $this->spellCheckerModes)) {
 200                  $this->spellCheckerMode = 'normal';
 201              }
 202          }
 203  
 204          if( $this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
 205              $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
 206          }
 207  
 208          /* =======================================
 209           * SET STYLES
 210           * =======================================
 211           */
 212  
 213          $RTEWidth = 460+($pObj->docLarge ? 150 : 0);
 214          $RTEHeight = 380;
 215          $editorWrapWidth = $RTEWidth . 'px';
 216          $editorWrapHeight = $RTEHeight . 'px';
 217          $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . ($RTEHeight+2) . 'px; width:'. ($RTEWidth+2) . 'px;'));        
 218          $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black;';
 219          $this->toolbar_level_size = $RTEWidth;
 220  
 221          /* =======================================
 222           * LOAD JS, CSS and more
 223           * =======================================
 224           */
 225              // Preloading the pageStyle
 226          $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
 227          $additionalCode_loadCSS = '
 228          <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
 229  
 230              // Loading the editor skin
 231          $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
 232          if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:')  {
 233              $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
 234          }
 235          if (substr($skinFilename,0,4) == 'EXT:')      {       // extension
 236              list($extKey,$local) = explode('/',substr($skinFilename,4),2);
 237              $skinFilename='';
 238              if (strcmp($extKey,'') &&  t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
 239                  $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey).$local;
 240                  $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
 241              }
 242          } elseif (substr($skinFilename,0,1) != '/') {
 243              $skinDir = $this->siteURL.dirname($skinFilename);
 244              $skinFilename = $this->siteURL.$skinFilename;
 245          } else {
 246              $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
 247          }
 248  
 249          $this->editorCSS = $skinFilename;
 250          $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
 251          $additionalCode_loadCSS .= '
 252          <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
 253          $additionalCode_loadCSS .= '
 254          <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
 255  
 256              // Loading CSS, JavaScript files and code
 257          $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
 258          $pObj->additionalJS_initial = $this->loadJSfiles($pObj->RTEcounter);
 259          $pObj->additionalJS_pre[] = $this->loadJScode($pObj->RTEcounter);
 260  
 261          /* =======================================
 262           * DRAW THE EDITOR
 263           * =======================================
 264           */
 265              // Transform value:
 266          $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
 267          if ($this->client['BROWSER'] == 'gecko') {
 268                  // change <strong> to <b>
 269              $value = preg_replace('/<(\/?)strong/i', "<$1b", $value);
 270                  // change <em> to <i>
 271              $value = preg_replace('/<(\/?)em([^b>]*>)/i', "<$1i$2", $value);
 272          }
 273          
 274              // Register RTE windows:
 275          $pObj->RTEwindows[] = $PA['itemFormElName'];
 276              
 277              // Register RTE in JS:
 278          $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter);
 279          
 280              // Set the save option for the RTE:
 281          $pObj->additionalJS_submit[] = $this->setSaveRTE($pObj->RTEcounter, $pObj->formName, htmlspecialchars($PA['itemFormElName']));
 282          
 283              // draw the textarea
 284          $visibility = 'hidden';
 285          $item = $this->triggerField($PA['itemFormElName']).'
 286              <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait" style="display: none;" >' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
 287              <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="'. htmlspecialchars($this->RTEWrapStyle). '">
 288              <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
 289              </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
 290              ';
 291          return $item;
 292      }
 293      
 294      /**
 295       * Return the JS-Code for copy the HTML-Code from the editor in the hidden input field.
 296       * This is for submit function from the form.
 297       *
 298       * @return string        the JS-Code
 299       */
 300  	function setSaveRTE($number, $form, $textarea) {
 301          return '
 302          editornumber = '.$number.';
 303          if (RTEarea[editornumber]) {
 304              fields = document.getElementsByName(\'' . $textarea . '\');
 305              field = fields.item(0);
 306              if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
 307          }
 308          else {
 309              OK=0;
 310          }
 311          ';
 312      }
 313      
 314  }
 315  
 316  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php'])    {
 317      include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);
 318  }
 319  
 320  ?>


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics