Project

General

Profile

Feature #17862 ยป cHashTunnel_v2.patch

Administrator Admin, 2007-11-30 12:00

View differences:

t3lib/class.t3lib_div.php (Arbeitskopie)
$pA = array();
foreach($params as $theP) {
$pKV = explode('=', $theP); // Splitting single param by '=' sign
if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0]) && !preg_match('/TSFE_ADMIN_PANEL\[.*?\]/',$pKV[0])) {
if (!t3lib_div::inList('id,type,no_cache,cHash,MP,ftu',$pKV[0]) && !preg_match('/(TSFE_ADMIN_PANEL|cHashTunnel)\[.*?\]/',$pKV[0])) {
$pA[rawurldecode($pKV[0])] = (string)rawurldecode($pKV[1]);
}
}
......
}
/**
* Create a hash for each prefixId in the cHashTunnel, works similar to cHash but is
* checked individually by the plugin script (pi<x>).
*
* @param string $addQueryParams: Query-parameters: "&xxx=yyy&zzz=uuu"
* @return string The adjusted $addQueryParams with [hash] parameter for each prefixId
*/
function cHashTunnelPrepare($addQueryParams) {
parse_str($addQueryParams, $params);
if (isset($params['cHashTunnel'])) {
foreach ($params['cHashTunnel'] as $prefixId => $value) {
$addQueryParams .= '&cHashTunnel['.$prefixId.'][hash]='.t3lib_div::cHashTunnelHash($value);
}
}
return $addQueryParams;
}
/**
* Creates a unique hash for disposal in cHashTunnel.
*
* @param mixed $value: Array or string of a prefixId section
* @return string The
*/
function cHashTunnelHash($value) {
if (!is_array($value)) {
$value = array($value);
}
if (isset($value['hash'])) {
unset($value['hash']);
}
$value['encryptionKey'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
ksort($value);
return t3lib_div::shortMD5(serialize($value));
}
/**
* Responds on input localization setting value whether the page it comes from should be hidden if no translation exists or not.
*
* @param integer Value from "l18n_cfg" field of a page record
typo3/sysext/cms/tslib/class.tslib_fe.php (Arbeitskopie)
var $RDCT='';
var $page_cache_reg1=0; // This can be set from applications as a way to tag cached versions of a page and later perform some external cache management, like clearing only a part of the cache of a page...
var $siteScript=''; // Contains the value of the current script path that activated the frontend. Typically "index.php" but by rewrite rules it could be something else! Used for Speaking Urls / Simulate Static Documents.
var $cHashTunnel=''; // Extension prefixIds to be tunnelled.
// USER
var $fe_user=''; // The user (object)
......
// No cache
if ($this->config['config']['no_cache']) { $this->set_no_cache(); } // Set $this->no_cache true if the config.no_cache value is set!
// set cHashTunnel if set
if (trim($this->config['config']['cHashTunnel'])) {
$this->cHashTunnel = trim($this->config['config']['cHashTunnel']);
}
// Check PATH_INFO url
if ($this->absRefPrefix_force && strcmp($this->config['config']['simulateStaticDocuments'],'PATH_INFO')) {
typo3/sysext/cms/tslib/class.tslib_pibase.php (Arbeitskopie)
if ($this->prefixId) {
$this->piVars = t3lib_div::GParrayMerged($this->prefixId);
// Leave cHash tunnel and put parameters for this plugin to $this->piVars:
if (t3lib_div::inList($GLOBALS['TSFE']->cHashTunnel, $this->prefixId)) {
$cHashTunnel = t3lib_div::GParrayMerged('cHashTunnel');
if (isset($cHashTunnel[$this->prefixId]) && is_array($cHashTunnel[$this->prefixId])) {
// check cHashTunnelHash:
if (t3lib_div::cHashTunnelHash($cHashTunnel[$this->prefixId]) == $cHashTunnel[$this->prefixId]['hash']) {
foreach ($cHashTunnel[$this->prefixId] as $key => $value) {
// Directly assign tunnelled values to $this->piVars
$this->piVars[$key] = $value;
}
} else {
// @TODO: Remove the output or generate a better/nice error message:
// $calcHash = t3lib_div::cHashTunnelHash($cHashTunnel[$this->prefixId]);
// die('Error in cHashTunnel: '.$cHashTunnel[$this->prefixId]['hash'].' vs. '.$calcHash);
}
}
}
// cHash mode check
// IMPORTANT FOR CACHED PLUGINS (USER cObject): As soon as you generate cached plugin output which depends on parameters (eg. seeing the details of a news item) you MUST check if a cHash value is set.
// Background: The function call will check if a cHash parameter was sent with the URL because only if it was the page may be cached. If no cHash was found the function will simply disable caching to avoid unpredictable caching behaviour. In any case your plugin can generate the expected output and the only risk is that the content may not be cached. A missing cHash value is considered a mistake in the URL resulting from either URL manipulation, "realurl" "grayzones" etc. The problem is rare (more frequent with "realurl") but when it occurs it is very puzzling!
typo3/sysext/cms/tslib/class.tslib_content.php (Arbeitskopie)
// Query Params:
$addQueryParams = $conf['addQueryString'] ? $this->getQueryArguments($conf['addQueryString.']) : '';
$addQueryParams .= trim($this->stdWrap($conf['additionalParams'],$conf['additionalParams.']));
// Apply cHashTunnel:
if (substr($addQueryParams,0,1)=='&' && $GLOBALS['TSFE']->cHashTunnel) {
$cHashTunnelParts = array_unique(t3lib_div::trimExplode(',', $GLOBALS['TSFE']->cHashTunnel));
$pattern = '/&('.implode('|', $cHashTunnelParts).')(\[|=)/';
$replacement = '&cHashTunnel[\1]\2';
$addQueryParams = preg_replace($pattern, $replacement, $addQueryParams);
$addQueryParams = t3lib_div::cHashTunnelPrepare($addQueryParams);
}
if (substr($addQueryParams,0,1)!='&') {
$addQueryParams = '';
} elseif ($conf['useCacheHash']) { // cache hashing:
    (1-1/1)