Project

General

Profile

Bug #17088 » bug_5152_v2.diff

Administrator Admin, 2007-10-19 12:14

View differences:

t3lib/class.t3lib_tstemplate.php (Arbeitskopie)
var $whereClause = ''; // This MUST be initialized by the init() function
var $debug = 0;
var $allowedPaths = array(); // This is the only paths (relative!!) that are allowed for resources in TypoScript. Should all be appended with '/'. You can extend these by the global array TYPO3_CONF_VARS. See init() function.
var $currentPageData = ''; // Contains "currentPageData" when rendered/fetched from cache. See getCurrentPageData()
var $simulationHiddenOrTime=0; // See init(); Set if preview of some kind is enabled.
var $loaded = 0; // Set, if the TypoScript template structure is loaded and OK, see ->start()
......
* Unfortunately this does not take into account if the templates in the rowSum of currentPageData has changed composition, eg. due to hidden fields or start/end time.
* So if a template is hidden or times out, it'll not be discovered unless the page is regenerated - at least the this->start function must be called, because this will make a new portion of data in currentPageData string
*
* @return mixed The array $this->currentPageData if found cached in "cache_pagesection". If the string "none" was returned it means the array must be generated and stored in the cache-table
* @return mixed $currentPageData if found cached in "cache_pagesection". Otherwise false is returned which means that the array must be generated and stored in the cache-table
* @see start(), tslib_fe::getFromCache()
*/
function getCurrentPageData() {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_pagesection', 'page_id='.intval($GLOBALS['TSFE']->id).' AND mpvar_hash='.t3lib_div::md5int($GLOBALS['TSFE']->MP));
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$this->currentPageData = unserialize($row['content']);
$currentPageData = unserialize($row['content']);
} else {
$this->currentPageData = 'none';
$currentPageData = false;
}
return $this->currentPageData;
return $currentPageData; // 2007-05-30 / Stucki: Notice that $this->currentPageData is not used anymore!
}
/**
* Fetches data about which TypoScript-matches there are at this page. Then it performs a matchingtest.
*
* @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the $this->currentPageData array
* @param array An array with three keys, "all", "rowSum" and "rootLine" - all coming from the "currentPageData" array
* @return array The input array but with a new key added, "match" which contains the items from the "all" key which when passed to tslib_matchCondition returned true.
* @see t3lib_matchCondition, tslib_fe::getFromCache()
*/
......
/**
* This is all about fetching the right TypoScript template structure. If it's not cached then it must be generated and cached!
* The method traverse the rootline structure from out to in, fetches the hierarchy of template records and based on this either finds the cached TypoScript template structure or parses the template and caches it for next time.
* Sets $this->setup to the parsed TypoScript Template array
* Sets $this->setup to the parsed TypoScript template array
*
* @param array The rootline of the current page (going ALL the way to tree root)
* @return void
* @see tslib_fe::getConfigArray()
*/
function start($theRootLine) {
if (is_array($theRootLine)) {
$setupData='';
$cc=Array();
$hash='';
if (is_array($theRootLine)) {
$setupData = '';
$hash = '';
$isCached = false; // Flag that indicates that the existing data in cache_pagesection could be used (this is the case if $TSFE->all is set, and the rowSum still matches). Based on this we decide if cache_pagesection needs to be updated...
$this->runThroughTemplates($theRootLine);
// Getting the currentPageData if not already found
if (!$this->currentPageData && !$GLOBALS['TSFE']->no_cache) {
$this->getCurrentPageData();
}
if (!$this->forceTemplateParsing) {
// Getting the currentPageData if not already found
if ($GLOBALS['TSFE']->all) {
$cc = $GLOBALS['TSFE']->all;
// This is about getting the hash string which is used to fetch the cached TypoScript template.
// If there was some cached currentPageData that's good (it gives us the hash),
// However if the actual rowSum and the rowSum of currentPageData is different from each other, thats a problem, and we should re-make the current page data.
if (is_array($this->currentPageData) &&
!strcmp(serialize($this->rowSum), serialize($this->currentPageData['rowSum'])) // The two ROWsums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
) {
// If currentPageData was actually there, we match the result...
$cc['all'] = $this->currentPageData['all'];
$cc['rowSum'] = $this->currentPageData['rowSum'];
$cc = $this->matching($cc);
$hash = md5(serialize($cc));
} else {
// If currentPageData was not there, we first find $rowSum (freshly generated). After that we try to see, if rowSum is stored with a list of all matching-parameters. If so we match the result
$rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
$result = t3lib_pageSelect::getHash($rowSumHash, 0);
if ($result) {
$cc['all'] = unserialize($result);
$cc['rowSum'] = $this->rowSum;
$cc = $this->matching($cc);
// The two ROWsums must NOT be different from each other - which they will be if start/endtime or hidden has changed!
if (strcmp(serialize($this->rowSum),serialize($cc['rowSum']))) {
unset($cc);
} else {
// If $TSFE->all really contains valid data, we don't need to update cache_pagesection (because this data was fetched from there already)
if (!strcmp(serialize($this->rootLine),serialize($cc['rootLine']))) {
$isCached = true;
}
// When the data is serialized below (ROWSUM hash), it must not contain the rootline by concept. So this must be removed (and added again later)...
unset($cc['rootLine']);
}
}
// This is about getting the hash string which is used to fetch the cached TypoScript template.
// If there was some cached currentPageData that's good (it gives us the hash),
// However if the actual rowSum and the rowSum of currentPageData is different from each other, thats a problem, and we should re-make the current page data.
if (is_array($cc)) {
// If currentPageData was actually there, we match the result (if this wasn't done already in $TSFE->getFromCache()...)
if (!$cc['match']) {
$cc = $this->matching($cc);
ksort($cc);
}
$hash = md5(serialize($cc));
} else {
// If currentPageData was not there, we first find $rowSum (freshly generated). After that we try to see, if rowSum is stored with a list of all conditions. If so we match the result.
$rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
$result = t3lib_pageSelect::getHash($rowSumHash, 0);
if ($result) {
$cc = array();
$cc['all'] = unserialize($result);
$cc['rowSum'] = $this->rowSum;
$cc = $this->matching($cc);
ksort($cc);
$hash = md5(serialize($cc));
}
}
}
if ($hash) {
// Get TypoScript setup array
$setupData = t3lib_pageSelect::getHash($hash, 0);
if ($hash) {
// Get TypoScript setup array
$setupData = t3lib_pageSelect::getHash($hash, 0);
}
}
if ($hash && $setupData && !$this->forceTemplateParsing) {
if ($setupData) {
// If TypoScript setup structure was cached we unserialize it here:
$this->setup = unserialize($setupData);
} else {
......
$this->generateConfig();
// This stores the template hash thing
$cc=Array();
$cc['all']=$this->sections; // All sections in the template at this point is found
$cc['rowSum']=$this->rowSum; // The line of templates is collected
$cc = array();
$cc['all'] = $this->sections; // All sections in the template at this point is found
$cc['rowSum'] = $this->rowSum; // The line of templates is collected
$cc = $this->matching($cc);
ksort($cc);
$hash = md5(serialize($cc));
......
if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('TS template size, serialized: '.strlen(serialize($this->setup)).' bytes');
$rowSumHash = md5('ROWSUM:'.serialize($this->rowSum));
t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - AL');
t3lib_pageSelect::storeHash($rowSumHash, serialize($cc['all']), 'TMPL CONDITIONS - ALL');
}
// Add rootLine
$cc['rootLine'] = $this->rootLine;
// Make global and save.
$GLOBALS['TSFE']->all=$cc;
ksort($cc);
if (!$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) { // Only save currentPageData, if we're not simulating by hidden/starttime/endtime
// Make global and save
$GLOBALS['TSFE']->all = $cc;
// Matching must be executed for every request, so this must never be part of the pagesection cache!
unset($cc['match']);
if (!$isCached && !$this->simulationHiddenOrTime && !$GLOBALS['TSFE']->no_cache) { // Only save the data if we're not simulating by hidden/starttime/endtime
$dbFields = array(
'content' => serialize($cc),
'tstamp' => $GLOBALS['EXEC_TIME']
typo3/sysext/cms/tslib/class.tslib_fe.php (Arbeitskopie)
*/
var $tmpl='';
var $cacheTimeOutDefault=''; // Is set to the time-to-live time of cached pages. If false, default is 60*60*24, which is 24 hours.
var $cacheContentFlag=''; // Set internally if cached content is fetched from the database
var $cacheContentFlag = 0; // Set internally if cached content is fetched from the database
var $cacheExpires=0; // Set to the expire time of cached content
var $isClientCachable=FALSE; // Set if cache headers allowing caching are sent.
var $all=''; // $all used by template fetching system. This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
......
* @return void
*/
function getFromCache() {
if (!$this->no_cache) {
$this->tmpl->getCurrentPageData();
if (!$this->no_cache) {
$cc = $this->tmpl->getCurrentPageData();
if (is_array($cc)) {
// BE CAREFUL to change the content of the cc-array. This array is serialized and an md5-hash based on this is used for caching the page.
// If this hash is not the same in here in this section and after page-generation, then the page will not be properly cached!
$cc = $this->tmpl->matching($cc); // This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
ksort($cc);
$cc = Array();
if (is_array($this->tmpl->currentPageData)) {
// BE CAREFULL to change the content of the cc-array. This array is serialized and an md5-hash based on this is used for caching the page.
// If this hash is not the same in here in this section and after page-generation the page will not be properly cached!
$cc['all'] = $this->tmpl->currentPageData['all'];
$cc['rowSum'] = $this->tmpl->currentPageData['rowSum'];
$cc['rootLine'] = $this->tmpl->currentPageData['rootLine']; // This rootline is used with templates only (matching()-function)
$this->all = $this->tmpl->matching($cc); // This array is an identification of the template. If $this->all is empty it's because the template-data is not cached, which it must be.
ksort($this->all);
$this->all = $cc;
}
unset($cc);
}
$this->content=''; // clearing the content-variable, which will hold the pagecontent
......
$this->newHash = $this->getHash();
$GLOBALS['TT']->push('Cache Row','');
if ($row = $this->getFromCache_queryRow()) {
$row = $this->getFromCache_queryRow();
if ($row) {
$this->config = (array)unserialize($row['cache_data']); // Fetches the lowlevel config stored with the cached data
$this->content = $row['HTML']; // Getting the content
$this->tempContent = $row['temp_content']; // Flag for temp content
$this->cacheContentFlag = 1; // Setting flag, so we know, that some cached content is gotten.
$this->cacheContentFlag = 1; // Setting flag, so we know, that some cached content has been loaded
$this->cacheExpires = $row['expires'];
if ($this->TYPO3_CONF_VARS['FE']['debug'] || $this->config['config']['debug']) {
$dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
$timeFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
$this->content.=chr(10).'<!-- Cached page generated '.date($dateFormat.' '.$timeFormat, $row['tstamp']).'. Expires '.Date($dateFormat.' '.$timeFormat, $row['expires']).' -->';
$this->content.= chr(10).'<!-- Cached page generated '.date($dateFormat.' '.$timeFormat, $row['tstamp']).'. Expires '.Date($dateFormat.' '.$timeFormat, $row['expires']).' -->';
}
}
$GLOBALS['TT']->pull();
}
......
/********************************************
*
* Page generation; cache handling
......
* @return void
*/
function generatePage_preProcessing() {
ksort($this->all);
// Same codeline as in getFromCache(). BUT $this->all has been set in the meantime, so we can't just skip this line and let it be set above! Keep this line!
$this->newHash = $this->getHash();
$this->newHash = $this->getHash(); // Same codeline as in getFromCache(). But $this->all has been changed by t3lib_TStemplate::start() in the meantime, so this must be called again!
$this->config['hash_base'] = $this->hash_base; // For cache management informational purposes.
// Here we put some temporary stuff in the cache in order to let the first hit generate the page. The temporary cache will expire after a few seconds (typ. 30) or will be cleared by the rendered page, which will also clear and rewrite the cache.
(1-1/2)