Added feature #13953: Hookrequest - t3lib_page::getRecordOverlay (thanks to Tolleiv...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_page.php
old mode 100755 (executable)
new mode 100644 (file)
index 098f12e..0383ef4
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2007 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -63,7 +63,7 @@
  *  823:     function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='')
  *
  *              SECTION: Caching and standard clauses
- *  875:     function getHash($hash,$expTime=0)
+ *  875:     function getHash($hash)
  *  898:     function storeHash($hash,$data,$ident)
  *  916:     function deleteClause($table)
  *  936:     function enableFields($table,$show_hidden=-1,$ignore_array=array(),$noVersionPreview=FALSE)
@@ -113,7 +113,7 @@ class t3lib_pageSelect {
        var $sys_language_uid = 0;
 
                // Versioning preview related:
-       var $versioningPreview = FALSE;         // If true, preview of other record versions is allowed. THIS MUST ONLY BE SET IF the page is not cached and truely previewed by a backend user!!!
+       var $versioningPreview = FALSE;         // If true, versioning preview of other record versions is allowed. THIS MUST ONLY BE SET IF the page is not cached and truely previewed by a backend user!!!
        var $versioningWorkspaceId = 0;         // Workspace ID for preview
        var $workspaceCache = array();
 
@@ -123,9 +123,11 @@ class t3lib_pageSelect {
        var $error_getRootLine_failPid = 0;             // Error uid set by getRootLine()
 
                // Internal caching
-       private $cache_getRootLine = array();
-       private $cache_getPage = array();
-       private $cache_getMountPointInfo = array();
+       protected $cache_getRootLine = array();
+       protected $cache_getPage = array();
+       protected $cache_getPage_noCheck = array();
+       protected $cache_getPageIdFromAlias = array();
+       protected $cache_getMountPointInfo = array();
 
        /**
         * init() MUST be run directly after creating a new template-object
@@ -141,11 +143,11 @@ class t3lib_pageSelect {
                if (!$show_hidden)      {
                        $this->where_hid_del.= 'AND pages.hidden=0 ';
                }
-               $this->where_hid_del.= 'AND (pages.starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (pages.endtime=0 OR pages.endtime>'.$GLOBALS['SIM_EXEC_TIME'].') ';
+               $this->where_hid_del .= 'AND pages.starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ' AND (pages.endtime=0 OR pages.endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ') ';
 
                        // Filter out new/deleted place-holder pages in case we are NOT in a versioning preview (that means we are online!)
                if (!$this->versioningPreview)  {
-                       $this->where_hid_del.= ' AND NOT(pages.t3ver_state>0)';
+                       $this->where_hid_del .= ' AND NOT pages.t3ver_state>0';
                } else {
                                // For version previewing, make sure that enable-fields are not de-selecting hidden pages - we need versionOL() to unset them only if the overlay record instructs us to.
                        $this->versioningPreview_where_hid_del = $this->where_hid_del;  // Copy where_hid_del to other variable (used in relation to versionOL())
@@ -186,20 +188,36 @@ class t3lib_pageSelect {
         * @see getPage_noCheck()
         */
        function getPage($uid, $disableGroupAccessCheck=FALSE)  {
-               if (is_array($this->cache_getPage[$uid][$disableGroupAccessCheck?1:0])) {
-                       return $this->cache_getPage[$uid][$disableGroupAccessCheck?1:0];
+                       // Hook to manipulate the page uid for special overlay handling
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+
+                               if (!($hookObject instanceof t3lib_pageSelect_getPageHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getPageHook', 1251476766);
+                               }
+
+                               $hookObject->getPage_preProcess($uid, $disableGroupAccessCheck, $this);
+                       }
+               }
+
+               $accessCheck = $disableGroupAccessCheck ? '' : $this->where_groupAccess;
+               $cacheKey = md5($accessCheck . '-' . $this->where_hid_del . '-' . $this->sys_language_uid);
+
+               if (is_array($this->cache_getPage[$uid][$cacheKey])) {
+                       return $this->cache_getPage[$uid][$cacheKey];
                }
                $result = array();
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->where_hid_del.($disableGroupAccessCheck ? '' : $this->where_groupAccess));
+               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->where_hid_del.$accessCheck);
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
-               if ($row)       {
+               if ($row) {
                        $this->versionOL('pages',$row);
-                       if (is_array($row))     {
+                       if (is_array($row)) {
                                $result = $this->getPageOverlay($row);
-                               $this->cache_getPage[$uid][$disableGroupAccessCheck?1:0] = $result;
                        }
                }
+               $this->cache_getPage[$uid][$cacheKey] = $result;
                return $result;
        }
 
@@ -207,20 +225,28 @@ class t3lib_pageSelect {
         * Return the $row for the page with uid = $uid WITHOUT checking for ->where_hid_del (start- and endtime or hidden). Only "deleted" is checked!
         *
         * @param       integer         The page id to look up
-        * @return      array           The page row with overlayed localized fields. Empty it no page.
+        * @return      array           The page row with overlayed localized fields. Empty array if no page.
         * @see getPage()
         */
        function getPage_noCheck($uid)  {
+               if ($this->cache_getPage_noCheck[$uid]) {
+                       return $this->cache_getPage_noCheck[$uid];
+               }
+
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->deleteClause('pages'));
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
-               if ($row)       {
+
+               $result = array();
+               if ($row) {
                        $this->versionOL('pages',$row);
-                       if (is_array($row))     {
-                               return $this->getPageOverlay($row);
+                       if (is_array($row)) {
+                               $result = $this->getPageOverlay($row);
                        }
                }
-               return Array();
+               $this->cache_getPage_noCheck[$uid] = $result;
+
+               return $result;
        }
 
        /**
@@ -253,12 +279,17 @@ class t3lib_pageSelect {
         */
        function getPageIdFromAlias($alias)     {
                $alias = strtolower($alias);
+               if ($this->cache_getPageIdFromAlias[$alias]) {
+                       return $this->cache_getPageIdFromAlias[$alias];
+               }
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'alias='.$GLOBALS['TYPO3_DB']->fullQuoteStr($alias, 'pages').' AND pid>=0 AND pages.deleted=0');  // "AND pid>=0" because of versioning (means that aliases sent MUST be online!)
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                if ($row)       {
+                       $this->cache_getPageIdFromAlias[$alias] = $row['uid'];
                        return $row['uid'];
                }
+               $this->cache_getPageIdFromAlias[$alias] = 0;
                return 0;
        }
 
@@ -275,6 +306,18 @@ class t3lib_pageSelect {
                if ($lUid<0)    $lUid = $this->sys_language_uid;
                $row = NULL;
 
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPageOverlay'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPageOverlay'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+
+                               if (!($hookObject instanceof t3lib_pageSelect_getPageOverlayHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getPageOverlayHook', 1269878881);
+                               }
+
+                               $hookObject->getPageOverlay_preProcess($pageInput, $lUid, $this);
+                       }
+               }
+
                        // If language UID is different from zero, do overlay:
                if ($lUid)      {
                        $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
@@ -337,6 +380,17 @@ class t3lib_pageSelect {
        function getRecordOverlay($table,$row,$sys_language_content,$OLmode='') {
                global $TCA;
 
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
+
+                               if (!($hookObject instanceof t3lib_pageSelect_getRecordOverlayHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getRecordOverlayHook', 1269881658);
+                               }
+                               $hookObject->getRecordOverlay_preProcess($table,$row,$sys_language_content,$OLmode, $this);
+                       }
+               }
+
                if ($row['uid']>0 && $row['pid']>0)     {
                        if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])     {
                                if (!$TCA[$table]['ctrl']['transOrigPointerTable'])     {       // Will not be able to work with other tables (Just didn't implement it yet; Requires a scan over all tables [ctrl] part for first FIND the table that carries localization information for this table (which could even be more than a single table) and then use that. Could be implemented, but obviously takes a little more....)
@@ -385,7 +439,7 @@ class t3lib_pageSelect {
                                                        unset($row);
                                                }
                                        } else {
-                                                       // When default language is displayed, we never want to return a record carrying another language!:
+                                                       // When default language is displayed, we never want to return a record carrying another language!
                                                if ($row[$TCA[$table]['ctrl']['languageField']]>0)      {
                                                        unset($row);
                                                }
@@ -393,7 +447,16 @@ class t3lib_pageSelect {
                                }
                        }
                }
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'] as $classRef) {
+                               $hookObject = t3lib_div::getUserObj($classRef);
 
+                               if (!($hookObject instanceof t3lib_pageSelect_getRecordOverlayHook)) {
+                                       throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getRecordOverlayHook', 1269881659);
+                               }
+                               $hookObject->getRecordOverlay_postProcess($table,$row,$sys_language_content,$OLmode, $this);
+                       }
+               }
                return $row;
        }
 
@@ -461,11 +524,17 @@ class t3lib_pageSelect {
                                                        // If a shortcut mode is set and no valid page is given to select subpags from use the actual page.
                                                $searchUid = intval($row['shortcut'])?intval($row['shortcut']):$row['uid'];
                                        }
-                                       $res2 = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', $searchField.'='.$searchUid.$this->where_hid_del.$this->where_groupAccess.' '.$addWhere, '', $sortField);
-                                       if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res2)) {
+                                       $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
+                                               'uid',
+                                               'pages',
+                                               $searchField . '=' . $searchUid .
+                                                       $this->where_hid_del .
+                                                       $this->where_groupAccess .
+                                                       ' ' . $addWhere
+                                       );
+                                       if (!$count) {
                                                unset($row);
                                        }
-                                       $GLOBALS['TYPO3_DB']->sql_free_result($res2);
                                } elseif ($row['doktype'] == 4 && $checkShortcuts)      {
                                                // Neither shortcut target nor mode is set. Remove the page from the menu.
                                        unset($row);
@@ -493,15 +562,15 @@ class t3lib_pageSelect {
         */
        function getDomainStartPage($domain, $path='',$request_uri='')  {
                $domain = explode(':',$domain);
-               $domain = strtolower(ereg_replace('\.$','',$domain[0]));
+               $domain = strtolower(preg_replace('/\.$/','',$domain[0]));
                        // Removing extra trailing slashes
-               $path = trim(ereg_replace('\/[^\/]*$','',$path));
+               $path = trim(preg_replace('/\/[^\/]*$/','',$path));
                        // Appending to domain string
                $domain.= $path;
-               $domain = ereg_replace('\/*$','',$domain);
+               $domain = preg_replace('/\/*$/','',$domain);
 
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                       'pages.uid,sys_domain.redirectTo,sys_domain.prepend_params',
+                                       'pages.uid,sys_domain.redirectTo,sys_domain.redirectHttpStatusCode,sys_domain.prepend_params',
                                        'pages,sys_domain',
                                        'pages.uid=sys_domain.pid
                                                AND sys_domain.hidden=0
@@ -515,14 +584,19 @@ class t3lib_pageSelect {
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
                if ($row)       {
                        if ($row['redirectTo']) {
-                               $rURL = $row['redirectTo'];
+                               $redirectUrl = $row['redirectTo'];
                                if ($row['prepend_params'])     {
-                                       $rURL = ereg_replace('\/$','',$rURL);
-                                       $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
-                                       $rURL.= '/'.$prependStr;
+                                       $redirectUrl = rtrim($redirectUrl, '/');
+                                       $prependStr = ltrim(substr($request_uri,strlen($path)), '/');
+                                       $redirectUrl .= '/' . $prependStr;
+                               }
+
+                               $statusCode = intval($row['redirectHttpStatusCode']);
+                               if ($statusCode && defined('t3lib_utility_Http::HTTP_STATUS_' . $statusCode)) {
+                                       t3lib_utility_Http::redirect($redirectUrl, constant('t3lib_utility_Http::HTTP_STATUS_' . $statusCode));
+                               } else {
+                                       t3lib_utility_Http::redirect($redirectUrl, 't3lib_utility_Http::HTTP_STATUS_301');
                                }
-                               Header('HTTP/1.1 301 Moved Permanently');
-                               Header('Location: '.t3lib_div::locationHeaderUrl($rURL));
                                exit;
                        } else {
                                return $row['uid'];
@@ -542,9 +616,12 @@ class t3lib_pageSelect {
         * @return      array           Array with page records from the root line as values. The array is ordered with the outer records first and root record in the bottom. The keys are numeric but in reverse order. So if you traverse/sort the array by the numeric keys order you will get the order from root and out. If an error is found (like eternal looping or invalid mountpoint) it will return an empty array.
         * @see tslib_fe::getPageAndRootline()
         */
-       function getRootLine($uid, $MP='', $ignoreMPerrors=FALSE)       {
-               if (is_array($this->cache_getRootLine[$uid][$MP][$ignoreMPerrors?1:0]))     {
-                       return $this->cache_getRootLine[$uid][$MP][$ignoreMPerrors?1:0];
+       function getRootLine($uid, $MP = '', $ignoreMPerrors = false) {
+               $cacheUid = $uid = intval($uid);
+               $cacheIgnoreMPerrors = ($ignoreMPerrors ? 1 : 0);
+
+               if (is_array($this->cache_getRootLine[$cacheUid][$this->sys_language_uid][$MP][$cacheIgnoreMPerrors])) {
+                       return $this->cache_getRootLine[$cacheUid][$this->sys_language_uid][$MP][$cacheIgnoreMPerrors];
                }
 
                        // Initialize:
@@ -556,15 +633,13 @@ class t3lib_pageSelect {
                $MPA = array();
                if ($MP)        {
                        $MPA = explode(',',$MP);
-                       reset($MPA);
-                       while(list($MPAk) = each($MPA)) {
+                       foreach ($MPA as $MPAk => $v) {
                                $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
                        }
                }
 
                $loopCheck = 0;
                $theRowArray = Array();
-               $uid = intval($uid);
 
                while ($uid!=0 && $loopCheck<20)        {       // Max 20 levels in the page tree.
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($uid).' AND pages.deleted=0 AND pages.doktype!=255');
@@ -658,7 +733,7 @@ class t3lib_pageSelect {
                }
 
                        // Note: rootline errors are not cached
-               $this->cache_getRootLine[$uid][$MP][$ignoreMPerrors?1:0] = $output;
+               $this->cache_getRootLine[$cacheUid][$this->sys_language_uid][$MP][$cacheIgnoreMPerrors] = $output;
                return $output;
        }
 
@@ -721,13 +796,8 @@ class t3lib_pageSelect {
 
                if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'])     {
 
-                               // Set first Page uid:
-                       if (!$firstPageUid)     {
-                               $firstPageUid = $pageRec['uid'];
-                       }
-
-                       if (isset($this->cache_getMountPointInfo[$pageId][$firstPageUid]))     {
-                               return $this->cache_getMountPointInfo[$pageId][$firstPageUid];
+                       if (isset($this->cache_getMountPointInfo[$pageId]))     {
+                               return $this->cache_getMountPointInfo[$pageId];
                        }
 
                                // Get pageRec if not supplied:
@@ -738,6 +808,10 @@ class t3lib_pageSelect {
                                $this->versionOL('pages',$pageRec);             // Only look for version overlay if page record is not supplied; This assumes that the input record is overlaid with preview version, if any!
                        }
 
+                               // Set first Page uid:
+                       if (!$firstPageUid)     {
+                               $firstPageUid = $pageRec['uid'];
+                       }
 
                                // Look for mount pid value plus other required circumstances:
                        $mount_pid = intval($pageRec['mount_pid']);
@@ -770,7 +844,7 @@ class t3lib_pageSelect {
                        }
                }
 
-               $this->cache_getMountPointInfo[$pageId][$firstPageUid] = $result;
+               $this->cache_getMountPointInfo[$pageId] = $result;
                return $result;
        }
 
@@ -808,8 +882,8 @@ class t3lib_pageSelect {
        function checkRecord($table,$uid,$checkPage=0)  {
                global $TCA;
                $uid = intval($uid);
-               if (is_array($TCA[$table]))     {
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($uid).$this->enableFields($table));
+               if (is_array($TCA[$table]) && $uid > 0) {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid = ' . $uid . $this->enableFields($table));
                        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        if ($row)       {
@@ -845,8 +919,9 @@ class t3lib_pageSelect {
        function getRawRecord($table,$uid,$fields='*',$noWSOL=FALSE)    {
                global $TCA;
                $uid = intval($uid);
-               if (is_array($TCA[$table]) || $table=='pages') {        // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
-                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).$this->deleteClause($table));
+                       // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
+               if ((is_array($TCA[$table]) || $table == 'pages') && $uid > 0) {
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid = ' . $uid . $this->deleteClause($table));
                        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        if ($row) {
@@ -917,48 +992,77 @@ class t3lib_pageSelect {
         **********************************/
 
        /**
-        * Returns string value stored for the hash string in the table "cache_hash"
+        * Returns string value stored for the hash string in the cache "cache_hash"
         * Can be used to retrieved a cached value
-        * Can be used from your frontend plugins if you like. It is also used to store the parsed TypoScript template structures. You can call it directly like t3lib_pageSelect::getHash()
+        * Can be used from your frontend plugins if you like. It is also used to
+        * store the parsed TypoScript template structures. You can call it directly
+        * like t3lib_pageSelect::getHash()
+        *
+        * IDENTICAL to the function by same name found in t3lib_page
         *
         * @param       string          The hash-string which was used to store the data value
-        * @param       integer         Allowed expiretime in seconds. Basically a record is selected only if it is not older than this value in seconds. If expTime is not set, the hashed value will never expire.
-        * @return      string          The "content" field of the "cache_hash" table row.
+        * @return      string          The "content" field of the "cache_hash" cache entry.
         * @see tslib_TStemplate::start(), storeHash()
         */
-       function getHash($hash,$expTime=0)      {
-                       // if expTime is not set, the hash will never expire
-               $expTime = intval($expTime);
-               if ($expTime) {
-                       $whereAdd = ' AND tstamp > '.(time()-$expTime);
-               }
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
-               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
-               $GLOBALS['TYPO3_DB']->sql_free_result($res);
-               if ($row)       {
-                       return $row['content'];
+       public static function getHash($hash, $expTime = 0)     {
+               $hashContent = null;
+
+               if (TYPO3_UseCachingFramework) {
+                       if (is_object($GLOBALS['typo3CacheManager'])) {
+                               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                               $cacheEntry = $contentHashCache->get($hash);
+
+                               if ($cacheEntry) {
+                                       $hashContent = $cacheEntry;
+                               }
+                       }
+               } else {
+                       $expTime = intval($expTime);
+                       if ($expTime) {
+                               $whereAdd = ' AND tstamp > '.($GLOBALS['ACCESS_TIME']-$expTime);
+                       }
+                       $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
+                       $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
+                       if ($row)       {
+                               $hashContent = $row['content'];
+                       }
                }
+               return $hashContent;
        }
 
        /**
-        * Stores a string value in the cache_hash table identified by $hash.
-        * Can be used from your frontend plugins if you like. You can call it directly like t3lib_pageSelect::storeHash()
+        * Stores a string value in the cache_hash cache identified by $hash.
+        * Can be used from your frontend plugins if you like. You can call it
+        * directly like t3lib_pageSelect::storeHash()
         *
         * @param       string          32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
         * @param       string          The data string. If you want to store an array, then just serialize it first.
-        * @param       string          $ident is just a textual identification in order to inform about the content! May be 20 characters long.
+        * @param       string          $ident is just a textual identification in order to inform about the content!
+        * @param       integer         The lifetime for the cache entry in seconds
         * @return      void
         * @see tslib_TStemplate::start(), getHash()
         */
-       function storeHash($hash,$data,$ident)  {
-               $insertFields = array(
-                       'hash' => $hash,
-                       'content' => $data,
-                       'ident' => $ident,
-                       'tstamp' => time()
-               );
-               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
-               $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
+       public static function storeHash($hash, $data, $ident, $lifetime = 0) {
+               if (TYPO3_UseCachingFramework) {
+                       if (is_object($GLOBALS['typo3CacheManager'])) {
+                               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
+                                       $hash,
+                                       $data,
+                                       array('ident_' . $ident),
+                                       $lifetime
+                               );
+                       }
+               } else {
+                       $insertFields = array(
+                               'hash' => $hash,
+                               'content' => $data,
+                               'ident' => $ident,
+                               'tstamp' => $GLOBALS['EXEC_TIME']
+                       );
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
+                       $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
+               }
        }
 
        /**
@@ -1019,11 +1123,11 @@ class t3lib_pageSelect {
                                        }
                                        if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
-                                               $query.=' AND ('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
+                                               $query .= ' AND ' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'];
                                        }
                                        if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
-                                               $query.=' AND ('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
+                                               $query.=' AND ('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
                                        }
                                        if ($ctrl['enablecolumns']['fe_group'] && !$ignore_array['fe_group']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['fe_group'];
@@ -1379,4 +1483,5 @@ class t3lib_pageSelect {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php'])     {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']);
 }
-?>
+
+?>
\ No newline at end of file