Added feature #13953: Hookrequest - t3lib_page::getRecordOverlay (thanks to Tolleiv...
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_page.php
index 51e78f7..0383ef4 100644 (file)
@@ -143,11 +143,11 @@ class t3lib_pageSelect {
                if (!$show_hidden)      {
                        $this->where_hid_del.= 'AND pages.hidden=0 ';
                }
                if (!$show_hidden)      {
                        $this->where_hid_del.= 'AND pages.hidden=0 ';
                }
-               $this->where_hid_del.= 'AND (pages.starttime<='.$GLOBALS['SIM_ACCESS_TIME'].') AND (pages.endtime=0 OR pages.endtime>'.$GLOBALS['SIM_ACCESS_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)  {
 
                        // 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())
                } 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())
@@ -188,6 +188,19 @@ class t3lib_pageSelect {
         * @see getPage_noCheck()
         */
        function getPage($uid, $disableGroupAccessCheck=FALSE)  {
         * @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);
 
                $accessCheck = $disableGroupAccessCheck ? '' : $this->where_groupAccess;
                $cacheKey = md5($accessCheck . '-' . $this->where_hid_del . '-' . $this->sys_language_uid);
 
@@ -293,6 +306,18 @@ class t3lib_pageSelect {
                if ($lUid<0)    $lUid = $this->sys_language_uid;
                $row = NULL;
 
                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']);
                        // If language UID is different from zero, do overlay:
                if ($lUid)      {
                        $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
@@ -355,6 +380,17 @@ class t3lib_pageSelect {
        function getRecordOverlay($table,$row,$sys_language_content,$OLmode='') {
                global $TCA;
 
        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....)
                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....)
@@ -411,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;
        }
 
                return $row;
        }
 
@@ -547,10 +592,10 @@ class t3lib_pageSelect {
                                }
 
                                $statusCode = intval($row['redirectHttpStatusCode']);
                                }
 
                                $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 {
                                } else {
-                                       t3lib_div::redirect($redirectUrl, 't3lib_div::HTTP_STATUS_301');
+                                       t3lib_utility_Http::redirect($redirectUrl, 't3lib_utility_Http::HTTP_STATUS_301');
                                }
                                exit;
                        } else {
                                }
                                exit;
                        } else {
@@ -588,8 +633,7 @@ class t3lib_pageSelect {
                $MPA = array();
                if ($MP)        {
                        $MPA = explode(',',$MP);
                $MPA = array();
                if ($MP)        {
                        $MPA = explode(',',$MP);
-                       reset($MPA);
-                       while(list($MPAk) = each($MPA)) {
+                       foreach ($MPA as $MPAk => $v) {
                                $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
                        }
                }
                                $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
                        }
                }
@@ -838,8 +882,8 @@ class t3lib_pageSelect {
        function checkRecord($table,$uid,$checkPage=0)  {
                global $TCA;
                $uid = intval($uid);
        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)       {
                        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        if ($row)       {
@@ -875,8 +919,9 @@ class t3lib_pageSelect {
        function getRawRecord($table,$uid,$fields='*',$noWSOL=FALSE)    {
                global $TCA;
                $uid = intval($uid);
        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) {
                        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        if ($row) {
@@ -959,16 +1004,30 @@ class t3lib_pageSelect {
         * @return      string          The "content" field of the "cache_hash" cache entry.
         * @see tslib_TStemplate::start(), storeHash()
         */
         * @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;
 
                $hashContent = null;
 
-               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
-               $cacheEntry = $contentHashCache->get($hash);
+               if (TYPO3_UseCachingFramework) {
+                       if (is_object($GLOBALS['typo3CacheManager'])) {
+                               $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;
        }
 
                return $hashContent;
        }
 
@@ -985,12 +1044,25 @@ class t3lib_pageSelect {
         * @see tslib_TStemplate::start(), getHash()
         */
        public static function storeHash($hash, $data, $ident, $lifetime = 0) {
         * @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) {
+                       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);
+               }
        }
 
        /**
        }
 
        /**
@@ -1051,7 +1123,7 @@ class t3lib_pageSelect {
                                        }
                                        if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
                                        }
                                        if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
-                                               $query.=' AND ('.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
+                                               $query .= ' AND ' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'];
                                        }
                                        if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
                                        }
                                        if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime']) {
                                                $field = $table.'.'.$ctrl['enablecolumns']['endtime'];