Project

General

Profile

Feature #19283 » 9284.diff

Administrator Admin, 2008-09-09 13:36

View differences:

typo3/sysext/cms/tslib/interfaces/interface.tslib_fe_setpagecachecontenthook.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2008 Martin Holtz <typo3@martinholtz.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* interface for classes which hook into tslib_fe for changing the cache expires timestamp
*
* @author Martin Holtz <typo3@martinholtz.de>
* @package TYPO3
* @subpackage t3lib
*/
interface tslib_fe_setPageCacheContentHook {
/**
* expiresTimestamp which is be used to store the cache-page
* can be altered from extensions
*
* @param int Timestamp, which defines when the page-cache is outdated
* @param int Page ID
* @param mixed The additional cache_data array, fx. $this->config
* @return int new Timestamp
*/
public function getCacheExpiresTimestamp($contentObjectName, array $configuration, $TypoScriptKey, tslib_cObj &$parentObject);
}
?>\ No newline at end of file
typo3/sysext/cms/tslib/class.tslib_fe.php (working copy)
}
}
}
/**
* Sets cache content; Inserts the content string into the cache_pages table.
*
......
* @return void
* @see realPageCacheContent(), tempPageCacheContent()
*/
function setPageCacheContent($content,$data,$tstamp) {
function setPageCacheContent($content, $data, $tstamp) {
$this->clearPageCacheContent();
// only if content is not "message_page_is_being_generated"
// which expires after 30 seconds
if (!$this->tempContent) {
// can be changed from an extension via $GLOBALS['TSFE']->cacheExpires
if ($this->cacheExpires > 0 && $this->cacheExpires < $tstamp) {
$tstamp = $this->cacheExpires;
}
// Call hook for $tstamp calculation
if(is_array($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['setPageCacheContent'])) {
foreach($TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['setPageCacheContent'] as $classData) {
$hookObject = &t3lib_div::getUserObj($classData);
if(!($hookObject instanceof tslib_fe_setPageCacheContentHook)) {
throw new UnexpectedValueException(
'$hookObject must implement interface tslib_content_tslib_fe_setPageCacheContentHook',
1220839864
);
}
$modifiedTimestamp = $hookObject->getCacheExpiresTimestamp($tstamp, $this->id, $data);
if ($modifiedTimestamp > 0 && $modifiedTimestamp < $tstamp) {
$tstamp = $modifiedTimestamp;
}
}
}
$pageSelect = t3lib_div::makeInstance('t3lib_pageSelect');
// Workspace does not matter, because they are on an different page
// so whe can use $this-id to check for content elements on this page
// Versioning does not matter, because they got pid = -1
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'*',
'tt_content',
'tt_content.pid = '.intval($this->id)
. ' AND (
(tt_content.starttime > '.$GLOBALS['EXEC_TIME'].' AND tt_content.starttime < '.$tstamp.')
OR (tt_content.endtime > '.$GLOBALS['EXEC_TIME'].' AND tt_content.endtime < '.$tstamp.')
) '
. $pageSelect->enableFields(
'tt_content',
0,
array('starttime' => true, 'endtime' => true),
FALSE
)
);
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
// $tstamp is the orignial expire-date of that page
// usually it is calculated by cache-expiredate and
// $GLOBALS['EXEC_TIME']
// the page starttime/endtime is checked before
// it is requested from cache. So we do not have to care
// of starttime/endtime of the page itself
// we want to respect the starttime / endtime of the
// content elements
//
// we have to check for each content element only, if it has a starttime
// or an endtime which takes effect betwwen $GLOBALS['EXEC_TIME']
// and the default-expire date ($tstamp).
if ($row['starttime'] < $tstamp && $row['starttime'] > $GLOBALS['EXEC_TIME']) {
$tstamp = $row['starttime'];
}
if ($row['endtime'] < $tstamp && $row['endtime'] > $GLOBALS['EXEC_TIME']) {
$tstamp = $row['endtime'];
}
}
}
$insertFields = array(
'hash' => $this->newHash,
'page_id' => $this->id,
(2-2/8)