/** * This function performs processing on the input $row array and stores internally a corresponding array which contains processed values, ready to pass on to the TCEforms rendering in the frontend! * The objective with this function is to prepare the content for handling in TCEforms. * Default values from outside/TSconfig is added by fetchRecord(). In this function default values from TCA is used if a field is NOT defined in $row. * The resulting, processed row is stored in $this->regTableItems_data[$uniqueItemRef], where $uniqueItemRef is "[tablename]_[id-value]" * * @param string The table name * @param string The uid value of the record (integer). Can also be a string (NEW-something) if the record is a NEW record. * @param integer The pid integer. For existing records this is of course the row's "pid" field. For new records it can be either a page id (positive) or a pointer to another record from the SAME table (negative) after which the record should be inserted (or on same page) * @param array The row of the current record. If NEW record, then it may be loaded with default values (by eg. fetchRecord()). * @return void * @see fetchRecord() */ function renderRecord($table, $id, $pid, $row) { global $TCA; // Init: $uniqueItemRef = $table . '_' . $id; t3lib_div::loadTCA($table); // Fetches the true PAGE TSconfig pid to use later, if needed. (Until now, only for the RTE, but later..., who knows?) list($tscPID) = t3lib_BEfunc::getTSCpid($table, $id, $pid); $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($table, array_merge($row, array('uid' => $id, 'pid' => $pid))); // If the record has not already been loaded (in which case we DON'T do it again)... if (!$this->regTableItems[$uniqueItemRef]) { $this->regTableItems[$uniqueItemRef] = 1; // set "loaded" flag. // If the table is pages, set the previous page id internally. if ($table == 'pages') { $this->prevPageID = $id; } $this->regTableItems_data[$uniqueItemRef] = $this->renderRecordRaw($table, $id, $pid, $row, $TSconfig, $tscPID); // Merges the processed array on-top of the raw one - this is done because some things in TCEforms may need access to other fields than those in the columns configuration! if ($this->addRawData && is_array($row) && is_array($this->regTableItems_data[$uniqueItemRef])) { $this->regTableItems_data[$uniqueItemRef] = array_merge($row, $this->regTableItems_data[$uniqueItemRef]); } } }
/** * Clearing the cache based on a page being updated * If the $table is 'pages' then cache is cleared for all pages on the same level (and subsequent?) * Else just clear the cache for the parent page of the record. * * @param string Table name of record that was just updated. * @param integer UID of updated / inserted record * @return void */ function clear_cache($table, $uid) { global $TCA, $TYPO3_CONF_VARS; $uid = intval($uid); $pageUid = 0; if (is_array($TCA[$table]) && $uid > 0) { // Get Page TSconfig relavant: list($tscPID) = t3lib_BEfunc::getTSCpid($table, $uid, ''); $TSConfig = $this->getTCEMAIN_TSconfig($tscPID); if (!$TSConfig['clearCache_disable']) { // If table is "pages": if (t3lib_extMgm::isLoaded('cms')) { $list_cache = array(); if ($table === 'pages' || $table === 'pages_language_overlay') { if ($table === 'pages_language_overlay') { $pageUid = $this->getPID($table, $uid); } else { $pageUid = $uid; } // Builds list of pages on the SAME level as this page (siblings) $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery('A.pid AS pid, B.uid AS uid', 'pages A, pages B', 'A.uid=' . intval($pageUid) . ' AND B.pid=A.pid AND B.deleted=0'); $pid_tmp = 0; while ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { $list_cache[] = $row_tmp['uid']; $pid_tmp = $row_tmp['pid']; // Add children as well: if ($TSConfig['clearCache_pageSiblingChildren']) { $res_tmp2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'pid=' . intval($row_tmp['uid']) . ' AND deleted=0'); while ($row_tmp2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp2)) { $list_cache[] = $row_tmp2['uid']; } $GLOBALS['TYPO3_DB']->sql_free_result($res_tmp2); } } $GLOBALS['TYPO3_DB']->sql_free_result($res_tmp); // Finally, add the parent page as well: $list_cache[] = $pid_tmp; // Add grand-parent as well: if ($TSConfig['clearCache_pageGrandParent']) { $res_tmp = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', 'pages', 'uid=' . intval($pid_tmp)); if ($row_tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_tmp)) { $list_cache[] = $row_tmp['pid']; } } } else { // For other tables than "pages", delete cache for the records "parent page". $list_cache[] = $pageUid = intval($this->getPID($table, $uid)); } // Call pre-processing function for clearing of cache for page ids: if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'])) { foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearPageCacheEval'] as $funcName) { $_params = array('pageIdArray' => &$list_cache, 'table' => $table, 'uid' => $uid, 'functionID' => 'clear_cache()'); // Returns the array of ids to clear, false if nothing should be cleared! Never an empty array! t3lib_div::callUserFunction($funcName, $_params, $this); } } // Delete cache for selected pages: if (is_array($list_cache)) { if (TYPO3_UseCachingFramework) { $pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages'); $pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection'); $pageIds = $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache); foreach ($pageIds as $pageId) { $pageCache->flushByTag('pageId_' . $pageId); $pageSectionCache->flushByTag('pageId_' . $pageId); } } else { $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pages', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_pagesection', 'page_id IN (' . implode(',', $GLOBALS['TYPO3_DB']->cleanIntArray($list_cache)) . ')'); } } } } // Clear cache for pages entered in TSconfig: if ($TSConfig['clearCacheCmd']) { $Commands = t3lib_div::trimExplode(',', strtolower($TSConfig['clearCacheCmd']), 1); $Commands = array_unique($Commands); foreach ($Commands as $cmdPart) { $this->clear_cacheCmd($cmdPart); } } // Call post processing function for clear-cache: if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'])) { $_params = array('table' => $table, 'uid' => $uid, 'uid_page' => $pageUid, 'TSConfig' => $TSConfig); foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'] as $_funcRef) { t3lib_div::callUserFunction($_funcRef, $_params, $this); } } } }
/** * Checking if the RTE is available/enabled for a certain table/field and if so, it returns true. * Used to determine if the RTE button should be displayed. * * @param string Table name * @param array Record row (needed, if there are RTE dependencies based on other fields in the record) * @param string Field name * @return boolean Returns true if the rich text editor would be enabled/available for the field name specified. */ function isRTEforField($table, $row, $field) { $specConf = $this->getSpecConfForField($table, $row, $field); $p = t3lib_BEfunc::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']); if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) { t3lib_BEfunc::fixVersioningPid($table, $row); list($tscPID, $thePidValue) = t3lib_BEfunc::getTSCpid($table, $row['uid'], $row['pid']); if ($thePidValue >= 0) { // If the pid-value is not negative (that is, a pid could NOT be fetched) $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($tscPID)); $RTEtypeVal = t3lib_BEfunc::getTCAtypeValue($table, $row); $thisConfig = t3lib_BEfunc::RTEsetup($RTEsetup['properties'], $table, $field, $RTEtypeVal); if (!$thisConfig['disabled']) { return TRUE; } } } return FALSE; }
/** * Return TSCpid (cached) * Using t3lib_BEfunc::getTSCpid() * * @param string Tablename * @param string UID value * @param string PID value * @return integer Returns the REAL pid of the record, if possible. If both $uid and $pid is strings, then pid=-1 is returned as an error indication. * @see t3lib_BEfunc::getTSCpid() */ function getTSCpid($table, $uid, $pid) { $key = $table . ':' . $uid . ':' . $pid; if (!isset($this->cache_getTSCpid[$key])) { $this->cache_getTSCpid[$key] = t3lib_BEfunc::getTSCpid($table, $uid, $pid); } return $this->cache_getTSCpid[$key]; }
/** * Draws the RTE as an iframe * * @param object Reference to parent object, which is an instance of the TCEforms. * @param string The table name * @param string The field name * @param array The current row from which field is being rendered * @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. * @param array "special" configuration - what is found at position 4 in the types configuration of a field from record, parsed into an array. * @param array Configuration for RTEs; A mix between TSconfig and otherwise. Contains configuration for display, which buttons are enabled, additional transformation information etc. * @param string Record "type" field value. * @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! * @param integer PID value of record (true parent page id) * @return string HTML code for RTE! */ function drawRTE($parentObject, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue) { global $BE_USER, $LANG, $TYPO3_DB, $TYPO3_CONF_VARS; $this->TCEform = $parentObject; $inline = $this->TCEform->inline; $LANG->includeLLFile('EXT:' . $this->ID . '/locallang.xml'); $this->client = $this->clientInfo(); $this->typoVersion = t3lib_div::int_from_ver(TYPO3_version); $this->userUid = 'BE_' . $BE_USER->user['uid']; // Draw form element: if ($this->debugMode) { // Draws regular text area (debug mode) $item = parent::drawRTE($this->TCEform, $table, $field, $row, $PA, $specConf, $thisConfig, $RTEtypeVal, $RTErelPath, $thePidValue); } else { // Draw real RTE /* ======================================= * INIT THE EDITOR-SETTINGS * ======================================= */ // Set backPath $this->backPath = $this->TCEform->backPath; // Get the path to this extension: $this->extHttpPath = $this->backPath . t3lib_extMgm::extRelPath($this->ID); // Get the site URL $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL'); // Get the host URL $this->hostURL = $this->siteURL . TYPO3_mainDir; // Element ID + pid $this->elementId = $PA['itemFormElName']; // Form element name $this->elementParts = explode('][', preg_replace('/\\]$/', '', preg_replace('/^(TSFE_EDIT\\[data\\]\\[|data\\[)/', '', $this->elementId))); // Find the page PIDs: list($this->tscPID, $this->thePid) = t3lib_BEfunc::getTSCpid(trim($this->elementParts[0]), trim($this->elementParts[1]), $thePidValue); // Record "types" field value: $this->typeVal = $RTEtypeVal; // TCA "types" value for record // Find "thisConfig" for record/editor: unset($this->RTEsetup); $this->RTEsetup = $BE_USER->getTSConfig('RTE', t3lib_BEfunc::getPagesTSconfig($this->tscPID)); $this->thisConfig = $thisConfig; // Special configuration and default extras: $this->specConf = $specConf; if ($this->thisConfig['forceHTTPS']) { $this->extHttpPath = preg_replace('/^(http|https)/', 'https', $this->extHttpPath); $this->siteURL = preg_replace('/^(http|https)/', 'https', $this->siteURL); $this->hostURL = preg_replace('/^(http|https)/', 'https', $this->hostURL); } /* ======================================= * LANGUAGES & CHARACTER SETS * ======================================= */ // Languages: interface and content $this->language = $LANG->lang; if ($this->language == 'default' || !$this->language) { $this->language = 'en'; } $this->contentTypo3Language = $this->language; $this->contentISOLanguage = 'en'; $this->contentLanguageUid = $row['sys_language_uid'] > 0 ? $row['sys_language_uid'] : 0; if (t3lib_extMgm::isLoaded('static_info_tables')) { if ($this->contentLanguageUid) { $tableA = 'sys_language'; $tableB = 'static_languages'; $languagesUidsList = $this->contentLanguageUid; $selectFields = $tableA . '.uid,' . $tableB . '.lg_iso_2,' . $tableB . '.lg_country_iso_2,' . $tableB . '.lg_typo3'; $tableAB = $tableA . ' LEFT JOIN ' . $tableB . ' ON ' . $tableA . '.static_lang_isocode=' . $tableB . '.uid'; $whereClause = $tableA . '.uid IN (' . $languagesUidsList . ') '; $whereClause .= t3lib_BEfunc::BEenableFields($tableA); $whereClause .= t3lib_BEfunc::deleteClause($tableA); $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause); while ($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) { $this->contentISOLanguage = strtolower(trim($languageRow['lg_iso_2']) . (trim($languageRow['lg_country_iso_2']) ? '_' . trim($languageRow['lg_country_iso_2']) : '')); $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3'])); } } else { $this->contentISOLanguage = trim($this->thisConfig['defaultContentLanguage']) ? trim($this->thisConfig['defaultContentLanguage']) : 'en'; $selectFields = 'lg_iso_2, lg_typo3'; $tableAB = 'static_languages'; $whereClause = 'lg_iso_2 = ' . $TYPO3_DB->fullQuoteStr(strtoupper($this->contentISOLanguage), $tableAB); $res = $TYPO3_DB->exec_SELECTquery($selectFields, $tableAB, $whereClause); while ($languageRow = $TYPO3_DB->sql_fetch_assoc($res)) { $this->contentTypo3Language = strtolower(trim($languageRow['lg_typo3'])); } } } // Character sets: interface and content $this->charset = $LANG->charSet; $this->OutputCharset = $this->charset; $this->contentCharset = $LANG->csConvObj->charSetArray[$this->contentTypo3Language]; $this->contentCharset = $this->contentCharset ? $this->contentCharset : 'iso-8859-1'; $this->origContentCharSet = $this->contentCharset; $this->contentCharset = trim($TYPO3_CONF_VARS['BE']['forceCharset']) ? trim($TYPO3_CONF_VARS['BE']['forceCharset']) : $this->contentCharset; /* ======================================= * TOOLBAR CONFIGURATION * ======================================= */ $this->initializeToolbarConfiguration(); /* ======================================= * SET STYLES * ======================================= */ $RTEWidth = isset($BE_USER->userTS['options.']['RTESmallWidth']) ? $BE_USER->userTS['options.']['RTESmallWidth'] : '530'; $RTEHeight = isset($BE_USER->userTS['options.']['RTESmallHeight']) ? $BE_USER->userTS['options.']['RTESmallHeight'] : '380'; $RTEWidth = $RTEWidth + ($this->TCEform->docLarge ? isset($BE_USER->userTS['options.']['RTELargeWidthIncrement']) ? $BE_USER->userTS['options.']['RTELargeWidthIncrement'] : '150' : 0); $RTEWidth -= $inline->getStructureDepth() > 0 ? ($inline->getStructureDepth() + 1) * $inline->getLevelMargin() : 0; if (isset($this->thisConfig['RTEWidthOverride'])) { if (strstr($this->thisConfig['RTEWidthOverride'], '%')) { if ($this->client['browser'] != 'msie') { $RTEWidth = intval($this->thisConfig['RTEWidthOverride']) > 0 ? $this->thisConfig['RTEWidthOverride'] : '100%'; } } else { $RTEWidth = intval($this->thisConfig['RTEWidthOverride']) > 0 ? intval($this->thisConfig['RTEWidthOverride']) : $RTEWidth; } } $RTEWidth = strstr($RTEWidth, '%') ? $RTEWidth : $RTEWidth . 'px'; $RTEHeight = $RTEHeight + ($this->TCEform->docLarge ? isset($BE_USER->userTS['options.']['RTELargeHeightIncrement']) ? $BE_USER->userTS['options.']['RTELargeHeightIncrement'] : 0 : 0); $RTEHeightOverride = intval($this->thisConfig['RTEHeightOverride']); $RTEHeight = $RTEHeightOverride > 0 ? $RTEHeightOverride : $RTEHeight; $editorWrapWidth = '99%'; $editorWrapHeight = '100%'; $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:' . $RTEHeight . 'px; width:' . $RTEWidth . '; border: 1px solid black; padding: 2px 2px 2px 2px;'; /* ======================================= * LOAD CSS AND JAVASCRIPT * ======================================= */ // Preloading the pageStyle and including RTE skin stylesheets $this->addPageStyle(); $this->addSkin(); // Loading JavaScript files and code if ($this->TCEform->RTEcounter == 1) { $this->TCEform->additionalJS_pre['rtehtmlarea-loadJScode'] = $this->loadJScode($this->TCEform->RTEcounter); } $this->TCEform->additionalCode_pre['rtehtmlarea-loadJSfiles'] = $this->loadJSfiles($this->TCEform->RTEcounter); $pageRenderer = $GLOBALS['SOBE']->doc->getPageRenderer(); $pageRenderer->enableExtJSQuickTips(); if (!$GLOBALS['TYPO3_CONF_VARS']['EXTCONF'][$this->ID]['enableCompressedScripts']) { $pageRenderer->enableExtJsDebug(); } /* ======================================= * DRAW THE EDITOR * ======================================= */ // Transform value: $value = $this->transformContent('rte', $PA['itemFormElValue'], $table, $field, $row, $specConf, $thisConfig, $RTErelPath, $thePidValue); // Further content transformation by registered plugins foreach ($this->registeredPlugins as $pluginId => $plugin) { if ($this->isPluginEnabled($pluginId) && method_exists($plugin, "transformContent")) { $value = $plugin->transformContent($value); } } // Register RTE windows $this->TCEform->RTEwindows[] = $PA['itemFormElName']; $textAreaId = htmlspecialchars($PA['itemFormElName']); // Check if wizard_rte called this for fullscreen edtition; if so, change the size of the RTE to fullscreen using JS if (basename(PATH_thisScript) == 'wizard_rte.php') { $this->fullScreen = true; $editorWrapWidth = '100%'; $editorWrapHeight = '100%'; $this->RTEdivStyle = 'position:relative; left:0px; top:0px; height:100%; width:100%; border: 1px solid black; padding: 2px 0px 2px 2px;'; } // Register RTE in JS: $this->TCEform->additionalJS_post[] = $this->registerRTEinJS($this->TCEform->RTEcounter, $table, $row['uid'], $field, $textAreaId); // Set the save option for the RTE: $this->TCEform->additionalJS_submit[] = $this->setSaveRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId); $this->TCEform->additionalJS_delete[] = $this->setDeleteRTE($this->TCEform->RTEcounter, $this->TCEform->formName, $textAreaId); // Draw the textarea $visibility = 'hidden'; $item = $this->triggerField($PA['itemFormElName']) . ' <div id="pleasewait' . $textAreaId . '" class="pleasewait" style="display: block;" >' . $LANG->getLL('Please wait') . '</div> <div id="editorWrap' . $textAreaId . '" class="editorWrap" style="visibility: hidden; width:' . $editorWrapWidth . '; height:' . $editorWrapHeight . ';"> <textarea id="RTEarea' . $textAreaId . '" name="' . htmlspecialchars($PA['itemFormElName']) . '" style="' . t3lib_div::deHSCentities(htmlspecialchars($this->RTEdivStyle)) . '">' . t3lib_div::formatForTextarea($value) . '</textarea> </div>' . ($TYPO3_CONF_VARS['EXTCONF'][$this->ID]['enableDebugMode'] ? '<div id="HTMLAreaLog"></div>' : '') . ' '; } // Return form item: return $item; }
/** * Processes bparams parameter * Example value: "data[pages][39][bodytext]|||tt_content|" or "data[tt_content][NEW3fba56fde763d][image]|||gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai|" * * Values: * 0: form field name reference * 1: old/unused? * 2: RTEConfigParams * 3: allowed types. Eg. "tt_content" or "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai" * 4: allowed file types when tx_dam table. Eg. "gif,jpg,jpeg,tif,bmp,pcx,tga,png,pdf,ai" * * @return void */ function processParams() { $this->act = $this->isParamPassed('act') ? $this->act : $this->getModSettings('act'); $this->mode = $this->isParamPassed('mode') ? $this->mode : $this->getModSettings('mode'); $this->bparams = $this->isParamPassed('bparams') ? $this->bparams : $this->getModSettings('bparams'); $this->reinitParams(); // Set Page TSConfig $pArr = explode('|', $this->bparams); if ($this->mode == 'rte') { $RTEtsConfigParts = explode(':', $pArr[2]); $tscPID = $RTEtsConfigParts[5]; } else { $this->formFieldName = $pArr[0]; $elementParts = explode('][', preg_replace('/\\]$/', '', preg_replace('/^(TSFE_EDIT\\[data\\]\\[|data\\[)/', '', $this->formFieldName))); list($tscPID, $thePid) = t3lib_BEfunc::getTSCpid(trim($elementParts[0]), trim($elementParts[1]), $thePidValue); } $this->modPageConfig = $GLOBALS['BE_USER']->getTSConfig('tx_dam.elementBrowser', t3lib_BEfunc::getPagesTSconfig($tscPID)); $this->allowedFileTypes = array(); $this->disallowedFileTypes = array(); switch ((string) $this->mode) { case 'rte': break; case 'db': $this->allowedTables = $pArr[3]; if ($this->allowedTables === 'tx_dam') { $this->allowedFileTypes = t3lib_div::trimExplode(',', $pArr[4], true); $this->disallowedFileTypes = t3lib_div::trimExplode(',', $pArr[5], true); } break; case 'file': case 'filedrag': $this->allowedTables = ''; $this->allowedFileTypes = t3lib_div::trimExplode(',', $pArr[3], true); break; case 'wizard': break; } if ($this->allowedFileTypes) { $allAllowed = false; foreach ($this->allowedFileTypes as $key => $type) { if ($type === '*') { $allAllowed = true; } elseif (substr($type, 0, 1) === '-') { unset($this->allowedFileTypes[$key]); $this->disallowedFileTypes[] = substr($type, 1); } } if ($allAllowed) { $this->allowedFileTypes = array(); } } }