/** * @param tx_rnbase_parameters $parameters * @param tx_rnbase_configurations $configurations * * @return string */ function execute(&$parameters, &$configurations) { $this->setConfigurations($configurations); $debugKey = $configurations->get($this->getConfId() . '_debugview'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $memStart = memory_get_usage(); } if ($configurations->getBool($this->getConfId() . 'toUserInt')) { if ($debug) { tx_rnbase_util_Debug::debug('Converting to USER_INT!', 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } $configurations->convertToUserInt(); } // Add JS or CSS files $this->addResources($configurations, $this->getConfId()); $cacheHandler = $this->getCacheHandler($configurations, $this->getConfId() . '_caching.'); $out = $cacheHandler ? $cacheHandler->getOutput() : ''; $cached = !empty($out); if (!$cached) { $viewData =& $configurations->getViewData(); tx_rnbase_util_Misc::pushTT(get_class($this), 'handleRequest'); $out = $this->handleRequest($parameters, $configurations, $viewData); tx_rnbase_util_Misc::pullTT(); if (!$out) { // View // It is possible to set another view via typoscript $viewClassName = $configurations->get($this->getConfId() . 'viewClassName'); $viewClassName = strlen($viewClassName) > 0 ? $viewClassName : $this->getViewClassName(); // TODO: error handling... $view = tx_rnbase::makeInstance($viewClassName); $view->setTemplatePath($configurations->getTemplatePath()); if (method_exists($view, 'setController')) { $view->setController($this); } // Das Template wird komplett angegeben $tmplName = $this->getTemplateName(); if (!$tmplName || !strlen($tmplName)) { tx_rnbase_util_Misc::mayday('No template name defined!'); } $view->setTemplateFile($configurations->get($tmplName . 'Template', TRUE)); tx_rnbase_util_Misc::pushTT(get_class($this), 'render'); $out = $view->render($tmplName, $configurations); tx_rnbase_util_Misc::pullTT(); } if ($cacheHandler) { $cacheHandler->setOutput($out); } } if ($debug) { $memEnd = memory_get_usage(); tx_rnbase_util_Debug::debug(array('Action' => get_class($this), 'Conf Id' => $this->getConfId(), 'Execution Time' => microtime(TRUE) - $time, 'Memory Start' => $memStart, 'Memory End' => $memEnd, 'Memory Consumed' => $memEnd - $memStart, 'Cached?' => $cached ? 'yes' : 'no', 'CacheHandler' => is_object($cacheHandler) ? get_class($cacheHandler) : '', 'SubstCacheEnabled?' => tx_rnbase_util_Templates::isSubstCacheEnabled() ? 'yes' : 'no'), 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } // reset the substCache after each view! tx_rnbase_util_Templates::resetSubstCache(); return $out; }
function main($out, $configurationArray) { tx_rnbase_util_Misc::pushTT('tx_rnbase_controller', 'start'); // Making the configurations object tx_rnbase_util_Misc::pushTT('init configuration', ''); $configurations = $this->_makeConfigurationsObject($configurationArray); tx_rnbase_util_Misc::pullTT(); tx_rnbase_util_Misc::enableTimeTrack($configurations->get('_enableTT') ? TRUE : FALSE); // Making the parameters object tx_rnbase_util_Misc::pushTT('init parameters', ''); $parameters = $this->_makeParameterObject($configurations); // Make sure to keep all parameters $configurations->setParameters($parameters); tx_rnbase_util_Misc::pullTT(); try { // check for doConvertToUserIntObject $configurations->getBool('toUserInt') && $configurations->convertToUserInt(); } catch (tx_rnbase_exception_Skip $e) { // dont do anything! the controller will be called twice, // if we convert the USER to USER_INTERNAL return ''; } // Finding the action: $actions = $this->_findAction($parameters, $configurations); if (!isset($actions)) { return $this->getUnknownAction(); } $out = ''; if (is_array($actions)) { foreach ($actions as $actionName) { tx_rnbase_util_Misc::pushTT('call action', $actionName); $out .= $this->doAction($actionName, $parameters, $configurations); tx_rnbase_util_Misc::pullTT(); } } else { // Call a single action tx_rnbase_util_Misc::pushTT('call action', $actionName); $out .= $this->doAction($actions, $parameters, $configurations); tx_rnbase_util_Misc::pullTT(); } tx_rnbase_util_Misc::pullTT(); return $out; }
/** * End TimeTrack section */ protected function pullTT() { tx_rnbase_util_Misc::pullTT(); }
/** * 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; }