Fixed bug #11468: [Bug]: $altUrl parameter has no effect in t3lib_BEfunc::viewOnClick...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_page.php
index 1766e89..8635ed9 100644 (file)
@@ -125,6 +125,8 @@ class t3lib_pageSelect {
                // Internal caching
        protected $cache_getRootLine = array();
        protected $cache_getPage = array();
+       protected $cache_getPage_noCheck = array();
+       protected $cache_getPageIdFromAlias = array();
        protected $cache_getMountPointInfo = array();
 
        /**
@@ -186,6 +188,19 @@ class t3lib_pageSelect {
         * @see getPage_noCheck()
         */
        function getPage($uid, $disableGroupAccessCheck=FALSE)  {
+                       // 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);
 
@@ -210,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;
        }
 
        /**
@@ -256,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;
        }
 
@@ -469,7 +497,7 @@ class t3lib_pageSelect {
                                                'pages',
                                                $searchField . '=' . $searchUid .
                                                        $this->where_hid_del .
-                                                       $this->where_groupAccess . 
+                                                       $this->where_groupAccess .
                                                        ' ' . $addWhere
                                        );
                                        if (!$count) {
@@ -502,12 +530,12 @@ 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.redirectHttpStatusCode,sys_domain.prepend_params',
@@ -526,16 +554,16 @@ class t3lib_pageSelect {
                        if ($row['redirectTo']) {
                                $redirectUrl = $row['redirectTo'];
                                if ($row['prepend_params'])     {
-                                       $redirectUrl = ereg_replace('\/$', '', $redirectUrl);
-                                       $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
+                                       $redirectUrl = rtrim($redirectUrl, '/');
+                                       $prependStr = ltrim(substr($request_uri,strlen($path)), '/');
                                        $redirectUrl .= '/' . $prependStr;
                                }
 
                                $statusCode = intval($row['redirectHttpStatusCode']);
-                               if ($statusCode && defined('t3lib_div::HTTP_STATUS_' . $statusCode)) {
-                                       t3lib_div::redirect($redirectUrl, constant('t3lib_div::HTTP_STATUS_' . $statusCode));
+                               if ($statusCode && defined('t3lib_utility_Http::HTTP_STATUS_' . $statusCode)) {
+                                       t3lib_utility_Http::redirect($redirectUrl, constant('t3lib_utility_Http::HTTP_STATUS_' . $statusCode));
                                } else {
-                                       t3lib_div::redirect($redirectUrl, 't3lib_div::HTTP_STATUS_301');
+                                       t3lib_utility_Http::redirect($redirectUrl, 't3lib_utility_Http::HTTP_STATUS_301');
                                }
                                exit;
                        } else {
@@ -573,8 +601,7 @@ 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]);
                        }
                }
@@ -944,16 +971,28 @@ class t3lib_pageSelect {
         * @return      string          The "content" field of the "cache_hash" cache entry.
         * @see tslib_TStemplate::start(), storeHash()
         */
-       public static function getHash($hash)   {
+       public static function getHash($hash, $expTime = 0)     {
                $hashContent = null;
 
-               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-               $cacheEntry = $contentHashCache->get($hash);
+               if (TYPO3_UseCachingFramework) {
+                       $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+                       $cacheEntry = $contentHashCache->get($hash);
 
-               if ($cacheEntry) {
-                       $hashContent = $cacheEntry;
+                       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;
        }
 
@@ -970,12 +1009,23 @@ class t3lib_pageSelect {
         * @see tslib_TStemplate::start(), getHash()
         */
        public static function storeHash($hash, $data, $ident, $lifetime = 0) {
-               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
-                       $hash,
-                       $data,
-                       array('ident_' . $ident),
-                       $lifetime
-               );
+               if (TYPO3_UseCachingFramework) {
+                       $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);
+               }
        }
 
        /**