Documentation TYPO3 par Ameos

class.tx_rtehtmlarea_pi2.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2005-2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.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 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00035 require_once(t3lib_extMgm::extPath('rtehtmlarea').'class.tx_rtehtmlarea_base.php');
00036 
00037 class tx_rtehtmlarea_pi2 extends tx_rtehtmlarea_base {
00038 
00039                 // External:
00040         var $RTEWrapStyle = '';                         // Alternative style for RTE wrapper <div> tag.
00041         var $RTEdivStyle = '';                          // Alternative style for RTE <div> tag.
00042         var $extHttpPath;                               // full Path to this extension for http (so no Server path). It ends with "/"
00043 
00044                 // For the editor
00045         var $elementId;
00046         var $elementParts;
00047         var $tscPID;
00048         var $typeVal;
00049         var $thePid;
00050         var $RTEsetup;
00051         var $thisConfig;
00052         var $confValues;
00053         var $language;
00054         var $spellCheckerLanguage;
00055         var $spellCheckerCharset;
00056         var $spellCheckerMode;
00057         var $specConf;
00058         var $LOCAL_LANG;
00059 
00075         function drawRTE(&$pObj,$table,$field,$row,$PA,$specConf,$thisConfig,$RTEtypeVal,$RTErelPath,$thePidValue) {
00076                 global $TSFE, $TYPO3_CONF_VARS, $TYPO3_DB;
00077                 
00078                         //call $this->transformContent
00079                         //call $this->triggerField
00080                 $this->TCEform = $pObj;
00081                 $this->client = $this->clientInfo();
00082                 $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version);
00083 
00084                 /* =======================================
00085                  * INIT THE EDITOR-SETTINGS
00086                  * =======================================
00087                  */
00088 
00089                         // first get the http-path to typo3:
00090                 $this->httpTypo3Path = substr( substr( t3lib_div::getIndpEnv('TYPO3_SITE_URL'), strlen( t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST') ) ), 0, -1 );
00091                 if (strlen($this->httpTypo3Path) == 1) {
00092                         $this->httpTypo3Path = '/';
00093                 } else {
00094                         $this->httpTypo3Path .= '/';
00095                 }
00096                         // Get the path to this extension:
00097                 $this->extHttpPath = $this->httpTypo3Path.t3lib_extMgm::siteRelPath($this->ID);
00098                         // Get the site URL
00099                 $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');
00100                         // Get the host URL
00101                 $this->hostURL = t3lib_div::getIndpEnv('TYPO3_REQUEST_HOST');
00102 
00103                         // Element ID + pid
00104                 $this->elementId = $PA['itemFormElName'];
00105                 $this->elementParts[0] = $table;
00106                 $this->elementParts[1] = $row['uid'];
00107                 $this->tscPID = $thePidValue;
00108                 $this->thePid = $thePidValue;
00109 
00110                         // Record "type" field value:
00111                 $this->typeVal = $RTEtypeVal; // TCA "type" value for record
00112 
00113                 unset($this->RTEsetup);
00114                 $pageTSConfig = $TSFE->getPagesTSconfig();
00115                 $this->RTEsetup = $pageTSConfig['RTE.'];
00116                 $this->thisConfig = $this->RTEsetup['default.'];
00117                 $this->thisConfig = $this->thisConfig['FE.'];
00118 
00119                         // Special configuration (line) and default extras:
00120                 $this->specConf = $specConf;
00121                 
00122                         // Language
00123                 $TSFE->initLLvars();
00124                 $this->language = $TSFE->lang;
00125                 $this->LOCAL_LANG = t3lib_div::readLLfile('EXT:' . $this->ID . '/locallang.xml', $this->language);
00126                 if ($this->language=='default' || !$this->language)     {
00127                         $this->language='en';
00128                 }
00129                         // Character set
00130                 $this->charset = $TSFE->labelsCharset;
00131                 $this->OutputCharset  = $TSFE->metaCharset ? $TSFE->metaCharset : $TSFE->renderCharset;
00132 
00133                 /* =======================================
00134                  * TOOLBAR CONFIGURATION
00135                  * =======================================
00136                  */
00137                         // htmlArea plugins list
00138                 $this->pluginEnableArray = array_intersect(t3lib_div::trimExplode(',', $this->pluginList , 1), t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['HTMLAreaPluginList'], 1));
00139                 $hidePlugins = array('TYPO3Browsers', 'UserElements', 'Acronym', 'TYPO3HtmlParser');
00140                 if ($this->client['BROWSER'] == 'opera') {
00141                         $hidePlugins[] = 'ContextMenu';
00142                         $this->thisConfig['hideTableOperationsInToolbar'] = 0;
00143                 }
00144                 if(!t3lib_extMgm::isLoaded('sr_static_info') || in_array($this->language, t3lib_div::trimExplode(',', $TYPO3_CONF_VARS['EXTCONF'][$this->ID]['noSpellCheckLanguages']))) $hidePlugins[] = 'SpellChecker';
00145                 $this->pluginEnableArray = array_diff($this->pluginEnableArray, $hidePlugins);
00146                 $this->pluginEnableArrayMultiple = $this->pluginEnableArray;
00147 
00148                         // Toolbar
00149                 $this->setToolBar();
00150 
00151                         // Check if some plugins need to be disabled
00152                 $this->setPlugins();
00153 
00154                 /* =======================================
00155                  * PLUGIN-SPECIFIC CONFIGURATION
00156                  * =======================================
00157                  */
00158 
00159                 if( $this->isPluginEnable('SpellChecker') ) {
00160                                 // Set the language of the content for the SpellChecker
00161                         $this->spellCheckerLanguage = $TYPO3_CONF_VARS['EXTCONF']['rtehtmlarea']['defaultDictionary'];
00162                         if($row['sys_language_uid']) {
00163                                 $tableA = 'sys_language';
00164                                 $tableB = 'static_languages';
00165                                 $languagesUidsList = $row['sys_language_uid'];
00166                                 $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3';
00167                                 $table = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid';
00168                                 $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') ';
00169                                 $whereClause .= $TSFE->cObj->enableFields($tableA);
00170                                 $res = $TYPO3_DB->exec_SELECTquery($selectFields, $table, $whereClause);
00171                                 while ( $languageRow = $TYPO3_DB->sql_fetch_assoc($res) ) {
00172                                         $this->spellCheckerLanguage = strtolower(trim($languageRow['lg_iso_2']).(trim($languageRow['lg_country_iso_2'])?'_'.trim($languageRow['lg_country_iso_2']):''));
00173                                         $this->spellCheckerTypo3Language = strtolower(trim($languageRow['lg_typo3']));
00174                                 }
00175                         }
00176                         $this->spellCheckerLanguage = $this->spellCheckerLanguage?$this->spellCheckerLanguage:$this->language;
00177                         $this->spellCheckerTypo3Language = $this->spellCheckerTypo3Language?$this->spellCheckerTypo3Language:$TSFE->lang;
00178                         if ($this->spellCheckerTypo3Language=='default') {
00179                                 $this->spellCheckerTypo3Language='en';
00180                         }
00181 
00182                                 // Set the charset of the content for the SpellChecker
00183                         $this->spellCheckerCharset = $TSFE->csConvObj->charSetArray[$this->spellCheckerTypo3Language];
00184                         $this->spellCheckerCharset = $this->spellCheckerCharset ? $this->spellCheckerCharset : 'iso-8859-1';
00185                         $this->spellCheckerCharset = trim($TSFE->config['config']['metaCharset']) ? trim($TSFE->config['config']['metaCharset']) : $this->spellCheckerCharset;
00186 
00187                                 // Set the SpellChecker mode
00188                         $this->spellCheckerMode = isset($this->thisConfig['HTMLAreaPspellMode']) ? trim($this->thisConfig['HTMLAreaPspellMode']) : 'normal';
00189                         if( !in_array($this->spellCheckerMode, $this->spellCheckerModes)) {
00190                                 $this->spellCheckerMode = 'normal';
00191                         }
00192                 }
00193 
00194                 if( $this->isPluginEnable('QuickTag') && trim($this->thisConfig['hideTags'])) {
00195                         $this->quickTagHideTags = implode(',', t3lib_div::trimExplode(',', $this->thisConfig['hideTags'], 1));
00196                 }
00197 
00198                 /* =======================================
00199                  * SET STYLES
00200                  * =======================================
00201                  */
00202 
00203                 $RTEWidth = 460+($pObj->docLarge ? 150 : 0);
00204                 $RTEHeight = 380;
00205                 $editorWrapWidth = $RTEWidth . 'px';
00206                 $editorWrapHeight = $RTEHeight . 'px';
00207                 $this->RTEWrapStyle = $this->RTEWrapStyle ? $this->RTEWrapStyle : ($this->RTEdivStyle ? $this->RTEdivStyle : ('height:' . ($RTEHeight+2) . 'px; width:'. ($RTEWidth+2) . 'px;'));               
00208                 $this->RTEdivStyle = $this->RTEdivStyle ? $this->RTEdivStyle : 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:'.$RTEWidth.'px; border: 1px solid black;';
00209                 $this->toolbar_level_size = $RTEWidth;
00210 
00211                 /* =======================================
00212                  * LOAD JS, CSS and more
00213                  * =======================================
00214                  */
00215                         // Preloading the pageStyle
00216                 $filename = trim($this->thisConfig['contentCSS']) ? trim($this->thisConfig['contentCSS']) : 'EXT:' . $this->ID . '/htmlarea/plugins/DynamicCSS/dynamiccss.css';
00217                 $additionalCode_loadCSS = '
00218                 <link rel="alternate stylesheet" type="text/css" href="' . $this->getFullFileName($filename) . '" />';
00219 
00220                         // Loading the editor skin
00221                 $skinFilename = trim($this->thisConfig['skin']) ? trim($this->thisConfig['skin']) : 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
00222                 if($this->client['BROWSER'] == 'gecko' && $this->client['VERSION'] == '1.3' && substr($skinFilename,0,4) == 'EXT:')  {
00223                         $skinFilename = 'EXT:' . $this->ID . '/htmlarea/skins/default/htmlarea.css';
00224                 }
00225                 if (substr($skinFilename,0,4) == 'EXT:')      {       // extension
00226                         list($extKey,$local) = explode('/',substr($skinFilename,4),2);
00227                         $skinFilename='';
00228                         if (strcmp($extKey,'') &&  t3lib_extMgm::isLoaded($extKey) && strcmp($local,'')) {
00229                                 $skinFilename = $this->httpTypo3Path . t3lib_extMgm::siteRelPath($extKey).$local;
00230                                 $skinDir = $this->siteURL . t3lib_extMgm::siteRelPath($extKey) . dirname($local);
00231                         }
00232                 } elseif (substr($skinFilename,0,1) != '/') {
00233                         $skinDir = $this->siteURL.dirname($skinFilename);
00234                         $skinFilename = $this->siteURL.$skinFilename;
00235                 } else {
00236                         $skinDir = substr($this->siteURL,0,-1) . dirname($skinFilename);
00237                 }
00238 
00239                 $this->editorCSS = $skinFilename;
00240                 $this->editedContentCSS = $skinDir . '/htmlarea-edited-content.css';
00241                 $additionalCode_loadCSS .= '
00242                 <link rel="alternate stylesheet" type="text/css" href="' . $this->editedContentCSS . '" />';
00243                 $additionalCode_loadCSS .= '
00244                 <link rel="stylesheet" type="text/css" href="' . $this->editorCSS . '" />';
00245 
00246                         // Loading CSS, JavaScript files and code
00247                 $TSFE->additionalHeaderData['htmlArea'] = $additionalCode_loadCSS;
00248                 $pObj->additionalJS_initial = $this->loadJSfiles($pObj->RTEcounter);
00249                 $pObj->additionalJS_pre[] = $this->loadJScode($pObj->RTEcounter);
00250 
00251                 /* =======================================
00252                  * DRAW THE EDITOR
00253                  * =======================================
00254                  */
00255                         // Transform value:
00256                 $value = $this->transformContent('rte',$PA['itemFormElValue'],$table,$field,$row,$specConf,$thisConfig,$RTErelPath,$thePidValue);
00257                 if ($this->client['BROWSER'] == 'gecko') {
00258                                 // change <strong> to <b>
00259                         $value = preg_replace('/<(\/?)strong/i', "<$1b", $value);
00260                                 // change <em> to <i>
00261                         $value = preg_replace('/<(\/?)em([^b>]*>)/i', "<$1i$2", $value);
00262                 }
00263                 
00264                         // Register RTE windows:
00265                 $pObj->RTEwindows[] = $PA['itemFormElName'];
00266                         
00267                         // Register RTE in JS:
00268                 $pObj->additionalJS_post[] = $this->registerRTEinJS($pObj->RTEcounter);
00269                 
00270                         // Set the save option for the RTE:
00271                 $pObj->additionalJS_submit[] = $this->setSaveRTE($pObj->RTEcounter, $pObj->formName, htmlspecialchars($PA['itemFormElName']));
00272                 
00273                         // draw the textarea
00274                 $visibility = 'hidden';
00275                 $item = $this->triggerField($PA['itemFormElName']).'
00276                         <div id="pleasewait' . $pObj->RTEcounter . '" class="pleasewait">' . $TSFE->csConvObj->conv($TSFE->getLLL('Please wait',$this->LOCAL_LANG), $this->charset, $TSFE->renderCharset) . '</div>
00277                         <div id="editorWrap' . $pObj->RTEcounter . '" class="editorWrap" style="visibility:' . $visibility . '; '. htmlspecialchars($this->RTEWrapStyle). '">
00278                         <textarea id="RTEarea'.$pObj->RTEcounter.'" name="'.htmlspecialchars($PA['itemFormElName']).'" style="'.htmlspecialchars($this->RTEdivStyle).'">'.t3lib_div::formatForTextarea($value).'</textarea>
00279                         </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . '
00280                         ';
00281                 return $item;
00282         }
00283         
00290         function setSaveRTE($number, $form, $textarea) {
00291                 return '
00292                 editornumber = '.$number.';
00293                 if (RTEarea[editornumber]) {
00294                         fields = document.getElementsByName(\'' . $textarea . '\');
00295                         field = fields.item(0);
00296                         if(field && field.tagName.toLowerCase() == \'textarea\') field.value = RTEarea[editornumber][\'editor\'].getHTML();
00297                 }
00298                 else {
00299                         OK=0;
00300                 }
00301                 ';
00302         }
00303         
00304 }
00305 
00306 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php'])        {
00307         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/pi2/class.tx_rtehtmlarea_pi2.php']);
00308 }
00309 
00310 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6