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


Généré par TYPO3 Ameos avec  doxygen 1.4.6