[FEATURE] Add hook to tslib_fe->getHash()
authorFabrizio Branca <mail@fabrizio-branca.de>
Mon, 18 Jul 2011 18:44:52 +0000 (20:44 +0200)
committerSteffen Ritter <info@rs-websystems.de>
Fri, 10 Feb 2012 15:10:53 +0000 (16:10 +0100)
This hook enables you to modify the hash_base that is used to store
different versions of a page in the cache. Normally it is fixed to
take the id, cHash, groups and some other stuff into account, but does
not allow to add own parameters.
Using this hook you can enable to store different versions of a page
depending on other parameters than GET-parameters.
It also solves an issue that different values of linkVars will produce
the same page if used independent from TypoScript conditions and without
cHash (which otherwise should be forced for all plugins and menu
generation).
The modified patch cleans up the hashbase creation and allows
to use the hook for the lockhash as well.

Change-Id: I68b0cfbcbec7eee496c4f903e3a129b7f33ab7c4
Resolves: #28299
Releases: 4.7
Reviewed-on: http://review.typo3.org/3403
Reviewed-by: Thomas Layh
Tested-by: Thomas Layh
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
typo3/sysext/cms/tslib/class.tslib_fe.php

index 855765a..70cd66f 100644 (file)
         * @see getFromCache(), getLockHash()
         */
        function getHash()      {
-               $this->hash_base = serialize(
-                       array(
-                               'all' => $this->all,
-                               'id' => intval($this->id),
-                               'type' => intval($this->type),
-                               'gr_list' => (string)$this->gr_list,
-                               'MP' => (string)$this->MP,
-                               'cHash' => $this->cHash_array,
-                               'domainStartPage' => $this->domainStartPage,
-                       )
-               );
-
+               $this->hash_base = $this->createHashBase(FALSE);
                return md5($this->hash_base);
        }
 
         * @see getFromCache(), getHash()
         */
        function getLockHash()  {
-               $lockHash = serialize(
-                       array(
-                               'id' => intval($this->id),
-                               'type' => intval($this->type),
-                               'gr_list' => (string)$this->gr_list,
-                               'MP' => (string)$this->MP,
-                               'cHash' => $this->cHash_array,
-                               'domainStartPage' => $this->domainStartPage,
-                       )
+               $lockHash = $this->createHashBase(TRUE);
+               return md5($lockHash);
+       }
+
+
+       /**
+        * Calculates the cache-hash (or the lock-hash)
+        * This hash is unique to the template,
+        * the variables ->id, ->type, ->gr_list (list of groups),
+        * ->MP (Mount Points) and cHash array
+        * Used to get and later store the cached data.
+        *
+        * @param boolean $createLockHashBase whether to create the lock hash, which doesn't contain the "this->all" (the template information)
+        * @return string the serialized hash base
+        */
+       protected function createHashBase($createLockHashBase = FALSE) {
+               $hashParameters = array(
+                       'id'      => intval($this->id),
+                       'type'    => intval($this->type),
+                       'gr_list' => (string) $this->gr_list,
+                       'MP'      => (string) $this->MP,
+                       'cHash'   => $this->cHash_array,
+                       'domainStartPage' => $this->domainStartPage
                );
 
-               return md5($lockHash);
+                       // include the template information if we shouldn't create a lock hash
+               if (!$createLockHashBase) {
+                       $hashParameters['all'] = $this->all;
+               }
+
+                       // Call hook to influence the hash calculation
+               if (is_array($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'])) {
+                       $_params = array(
+                               'hashParameters' => &$hashParameters,
+                               'createLockHashBase' => $createLockHashBase
+                       );
+                       foreach ($this->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'] as $_funcRef) {
+                               t3lib_div::callUserFunction($_funcRef, $_params, $this);
+                       }
+               }
+
+               return serialize($hashParameters);
        }
 
        /**