/** * Prepare classes for FE-rendering if it is needed in TYPO3 backend. * * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController or tslib_fe */ public static function prepareTSFE($options = array()) { $pid = array_key_exists('pid', $options) ? $options['pid'] : 1; $type = array_key_exists('type', $options) ? $options['type'] : 99; $force = array_key_exists('force', $options) ? TRUE : FALSE; if (!is_object($GLOBALS['TT'])) { $className = tx_rnbase_util_Typo3Classes::getTimeTrackClass(); $GLOBALS['TT'] = new $className(); $GLOBALS['TT']->start(); } $typoScriptFrontendControllerClass = tx_rnbase_util_Typo3Classes::getTypoScriptFrontendControllerClass(); if (!is_object($GLOBALS['TSFE']) || !$GLOBALS['TSFE'] instanceof $typoScriptFrontendControllerClass || $force) { if (!defined('PATH_tslib')) { // PATH_tslib setzen if (@is_dir(PATH_site . 'typo3/sysext/cms/tslib/')) { define('PATH_tslib', PATH_site . 'typo3/sysext/cms/tslib/'); } elseif (@is_dir(PATH_site . 'tslib/')) { define('PATH_tslib', PATH_site . 'tslib/'); } else { define('PATH_tslib', ''); } } $GLOBALS['TSFE'] = tx_rnbase::makeInstance($typoScriptFrontendControllerClass, $GLOBALS['TYPO3_CONF_VARS'], $pid, $type); } // base user groups if (empty($GLOBALS['TSFE']->gr_list) || $force) { $GLOBALS['TSFE']->gr_list = '0,-1'; } // init the syspage for pageSelect if (!is_object($GLOBALS['TSFE']->sys_page) || $force) { $temp_sys_page = tx_rnbase_util_TYPO3::getSysPage(); $temp_sys_page->init(0); $GLOBALS['TSFE']->sys_page = $temp_sys_page; } // init the template if (!is_object($GLOBALS['TSFE']->tmpl) || $force) { $GLOBALS['TSFE']->initTemplate(); if (empty($GLOBALS['TSFE']->tmpl->getFileName_backPath)) { $GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site; } } // initial empty config if (!is_array($GLOBALS['TSFE']->config)) { $GLOBALS['TSFE']->config = array(); } if (!is_array($GLOBALS['TSFE']->config['config'])) { $GLOBALS['TSFE']->config['config'] = array(); } // init the language if (empty($GLOBALS['TSFE']->lang) || $force) { $GLOBALS['TSFE']->initLLvars(); } return $GLOBALS['TSFE']; }
/** * @param array $options * @param string $tableName * @param string $tableAlias * @return string */ public function handleEnableFieldsOptions(array $options, $tableName, $tableAlias) { $enableFields = ''; if (!$options['enablefieldsoff']) { if (is_object($GLOBALS['BE_USER']) && $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['rn_base']['loadHiddenObjects']) { $options['enablefieldsbe'] = 1; } // Zur Where-Clause noch die gültigen Felder hinzufügen $sysPage = tx_rnbase_util_TYPO3::getSysPage(); $mode = TYPO3_MODE == 'BE' ? 1 : 0; $ignoreArr = array(); if (intval($options['enablefieldsbe'])) { $mode = 1; // Im BE alle sonstigen Enable-Fields ignorieren $ignoreArr = array('starttime' => 1, 'endtime' => 1, 'fe_group' => 1); } elseif (intval($options['enablefieldsfe'])) { $mode = 0; } // Workspaces: Bei Tabellen mit Workspace-Support werden die EnableFields automatisch reduziert. Die Extension // Muss aus dem ResultSet ggf. Datensätze entfernen. $enableFields = $sysPage->enableFields($tableName, $mode, $ignoreArr); // Wir setzen zusätzlich pid >=0, damit Version-Records nicht erscheinen // allerdings nur, wenn die Tabelle versionierbar ist! if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'])) { $enableFields .= ' AND ' . $tableName . '.pid >=0'; } // Replace tablename with alias if ($tableAlias) { $enableFields = str_replace($tableName, $tableAlias, $enableFields); } } return $enableFields; }
/** * @param int $pageId * * @return void */ public static function enableLinkCreation($pageId = 1) { tx_rnbase_util_Misc::prepareTSFE(); $GLOBALS['TSFE']->sys_page = tx_rnbase_util_TYPO3::getSysPage(); $GLOBALS['TSFE']->initTemplate(); $GLOBALS['TSFE']->id = $pageId; }
/** * Multi substitution function with caching. * * This function should be a one-stop substitution function for working with HTML-template. It does not substitute by str_replace but by splitting. This secures that the * value inserted does not themselves contain markers or subparts. * This function takes three kinds of substitutions in one: * $markContentArray is a regular marker-array where the 'keys' are substituted in $content with their values * $subpartContentArray works exactly like markContentArray only is whole subparts substituted and not only a single marker. * $wrappedSubpartContentArray is an array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating. * * @param string The content stream, typically HTML template content. * @param array Regular marker-array where the 'keys' are substituted in $content with their values * @param array Exactly like markContentArray only is whole subparts substituted and not only a single marker. * @param array An array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating. * @return string The output content stream * @see substituteSubpart(), substituteMarker(), substituteMarkerInObject(), TEMPLATE() */ public static function substituteMarkerArrayCached($content, array $markContentArray = NULL, array $subpartContentArray = NULL, array $wrappedSubpartContentArray = NULL) { tx_rnbase_util_Misc::pushTT('substituteMarkerArray'); // If not arrays then set them if (is_null($markContentArray)) { $markContentArray = array(); } // Plain markers if (is_null($subpartContentArray)) { $subpartContentArray = array(); } // Subparts being directly substituted if (is_null($wrappedSubpartContentArray)) { $wrappedSubpartContentArray = array(); } // Subparts being wrapped // Finding keys and check hash: $sPkeys = array_keys($subpartContentArray); $wPkeys = array_keys($wrappedSubpartContentArray); $mPKeys = array_keys($markContentArray); $aKeys = array_merge($mPKeys, $sPkeys, $wPkeys); if (!count($aKeys)) { tx_rnbase_util_Misc::pullTT(); return $content; } asort($aKeys); asort($mPKeys); asort($sPkeys); asort($wPkeys); $storeKey = ''; if (self::isSubstCacheEnabled()) { $storeKey = md5('substituteMarkerArrayCached_storeKey:' . serialize(array($content, $mPKeys, $sPkeys, $wPkeys))); } if (self::isSubstCacheEnabled() && self::$substMarkerCache[$storeKey]) { $storeArr = self::$substMarkerCache[$storeKey]; // $GLOBALS['TT']->setTSlogMessage('Cached', 0); } else { if (self::isSubstCacheEnabled()) { $storeArrDat = tx_rnbase_util_TYPO3::getSysPage()->getHash($storeKey); } if (!self::isSubstCacheEnabled() || !isset($storeArrDat)) { // Initialize storeArr $storeArr = array(); // Finding subparts and substituting them with the subpart as a marker foreach ($sPkeys as $sPK) { $content = self::substituteSubpart($content, $sPK, $sPK); } // Finding subparts and wrapping them with markers foreach ($wPkeys as $wPK) { $content = self::substituteSubpart($content, $wPK, array($wPK, $wPK)); } // traverse keys and quote them for reg ex. foreach ($aKeys as $tK => $tV) { $aKeys[$tK] = preg_quote($tV, '/'); } $regex = '/' . implode('|', $aKeys) . '/'; // Doing regex's $storeArr['c'] = preg_split($regex, $content); preg_match_all($regex, $content, $keyList); $storeArr['k'] = $keyList[0]; if (self::isSubstCacheEnabled()) { // Setting cache: self::$substMarkerCache[$storeKey] = $storeArr; // Storing the cached data: tx_rnbase_util_TYPO3::getSysPage()->storeHash($storeKey, serialize($storeArr), 'substMarkArrayCached'); } } else { // Unserializing $storeArr = unserialize($storeArrDat); // Setting cache: self::$substMarkerCache[$storeKey] = $storeArr; } } // Substitution/Merging: // Merging content types together, resetting $valueArr = array_merge($markContentArray, $subpartContentArray, $wrappedSubpartContentArray); $wSCA_reg = array(); $content = ''; // traversing the keyList array and merging the static and dynamic content foreach ($storeArr['k'] as $n => $keyN) { $content .= $storeArr['c'][$n]; if (!is_array($valueArr[$keyN])) { $content .= $valueArr[$keyN]; } else { $content .= $valueArr[$keyN][intval($wSCA_reg[$keyN]) % 2]; $wSCA_reg[$keyN]++; } } $content .= $storeArr['c'][count($storeArr['k'])]; tx_rnbase_util_Misc::pullTT(); return $content; }