2 /***************************************************************
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Contains a class with "Page functions" mainly for the frontend
30 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
31 * XHTML-trans compliant
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 * Page functions, a lot of sql/pages-related functions
38 * Mainly used in the frontend but also in some cases in the backend.
39 * It's important to set the right $where_hid_del in the object so that the functions operate properly
41 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
44 * @see tslib_fe::fetch_the_id()
46 class t3lib_pageSelect
{
47 var $urltypes = Array('', 'http://', 'ftp://', 'mailto:', 'https://');
48 // This is not the final clauses. There will normally be conditions for the hidden,starttime and endtime fields as well. You MUST initialize the object by the init() function
49 var $where_hid_del = ' AND pages.deleted=0';
50 // Clause for fe_group access
51 var $where_groupAccess = '';
52 var $sys_language_uid = 0;
54 // Versioning preview related:
55 // 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!!!
56 var $versioningPreview = FALSE;
57 // Workspace ID for preview
58 var $versioningWorkspaceId = 0;
59 var $workspaceCache = array();
63 // Error string set by getRootLine()
64 var $error_getRootLine = '';
65 // Error uid set by getRootLine()
66 var $error_getRootLine_failPid = 0;
69 protected $cache_getRootLine = array();
70 protected $cache_getPage = array();
71 protected $cache_getPage_noCheck = array();
72 protected $cache_getPageIdFromAlias = array();
73 protected $cache_getMountPointInfo = array();
76 * Named constants for "magic numbers" of the field doktype
78 const DOKTYPE_DEFAULT
= 1;
79 const DOKTYPE_LINK
= 3;
80 const DOKTYPE_SHORTCUT
= 4;
81 const DOKTYPE_BE_USER_SECTION
= 6;
82 const DOKTYPE_MOUNTPOINT
= 7;
83 const DOKTYPE_SPACER
= 199;
84 const DOKTYPE_SYSFOLDER
= 254;
85 const DOKTYPE_RECYCLER
= 255;
89 * Named constants for "magic numbers" of the field shortcut_mode
91 const SHORTCUT_MODE_NONE
= 0;
92 const SHORTCUT_MODE_FIRST_SUBPAGE
= 1;
93 const SHORTCUT_MODE_RANDOM_SUBPAGE
= 2;
94 const SHORTCUT_MODE_PARENT_PAGE
= 3;
97 * init() MUST be run directly after creating a new template-object
98 * This sets the internal variable $this->where_hid_del to the correct where clause for page records taking deleted/hidden/starttime/endtime/t3ver_state into account
100 * @param boolean $show_hidden If $show_hidden is TRUE, the hidden-field is ignored!! Normally this should be FALSE. Is used for previewing.
102 * @see tslib_fe::fetch_the_id(), tx_tstemplateanalyzer::initialize_editor()
104 function init($show_hidden) {
105 $this->where_groupAccess
= '';
106 $this->where_hid_del
= ' AND pages.deleted=0 ';
108 $this->where_hid_del
.= 'AND pages.hidden=0 ';
110 $this->where_hid_del
.= 'AND pages.starttime<=' . $GLOBALS['SIM_ACCESS_TIME'] . ' AND (pages.endtime=0 OR pages.endtime>' . $GLOBALS['SIM_ACCESS_TIME'] . ') ';
112 // Filter out new/deleted place-holder pages in case we are NOT in a versioning preview (that means we are online!)
113 if (!$this->versioningPreview
) {
114 $this->where_hid_del
.= ' AND NOT pages.t3ver_state>0';
116 // 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.
117 // Copy where_hid_del to other variable (used in relation to versionOL())
118 $this->versioningPreview_where_hid_del
= $this->where_hid_del
;
119 // Clear where_hid_del
120 $this->where_hid_del
= ' AND pages.deleted=0 ';
124 /*******************************************
126 * Selecting page records
128 ******************************************/
131 * Returns the $row for the page with uid = $uid (observing ->where_hid_del)
132 * Any pages_language_overlay will be applied before the result is returned.
133 * If no page is found an empty array is returned.
135 * @param integer $uid The page id to look up.
136 * @param boolean $disableGroupAccessCheck If set, the check for group access is disabled. VERY rarely used
137 * @return array The page row with overlayed localized fields. Empty it no page.
138 * @see getPage_noCheck()
140 function getPage($uid, $disableGroupAccessCheck = FALSE) {
141 // Hook to manipulate the page uid for special overlay handling
142 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'])) {
143 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'] as $classRef) {
144 $hookObject = t3lib_div
::getUserObj($classRef);
146 if (!($hookObject instanceof t3lib_pageSelect_getPageHook
)) {
147 throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getPageHook', 1251476766);
150 $hookObject->getPage_preProcess($uid, $disableGroupAccessCheck, $this);
154 $accessCheck = $disableGroupAccessCheck ?
'' : $this->where_groupAccess
;
155 $cacheKey = md5($accessCheck . '-' . $this->where_hid_del
. '-' . $this->sys_language_uid
);
157 if (is_array($this->cache_getPage
[$uid][$cacheKey])) {
158 return $this->cache_getPage
[$uid][$cacheKey];
161 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid=' . intval($uid) . $this->where_hid_del
. $accessCheck);
162 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
163 $GLOBALS['TYPO3_DB']->sql_free_result($res);
165 $this->versionOL('pages', $row);
166 if (is_array($row)) {
167 $result = $this->getPageOverlay($row);
170 $this->cache_getPage
[$uid][$cacheKey] = $result;
175 * Return the $row for the page with uid = $uid WITHOUT checking for ->where_hid_del (start- and endtime or hidden). Only "deleted" is checked!
177 * @param integer $uid The page id to look up
178 * @return array The page row with overlayed localized fields. Empty array if no page.
181 function getPage_noCheck($uid) {
182 if ($this->cache_getPage_noCheck
[$uid]) {
183 return $this->cache_getPage_noCheck
[$uid];
186 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid=' . intval($uid) . $this->deleteClause('pages'));
187 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
188 $GLOBALS['TYPO3_DB']->sql_free_result($res);
192 $this->versionOL('pages', $row);
193 if (is_array($row)) {
194 $result = $this->getPageOverlay($row);
197 $this->cache_getPage_noCheck
[$uid] = $result;
203 * Returns the $row of the first web-page in the tree (for the default menu...)
205 * @param integer $uid The page id for which to fetch first subpages (PID)
206 * @return mixed If found: The page record (with overlayed localized fields, if any). If NOT found: blank value (not array!)
207 * @see tslib_fe::fetch_the_id()
209 function getFirstWebPage($uid) {
211 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid=' . intval($uid) . $this->where_hid_del
. $this->where_groupAccess
, '', 'sorting', '1');
212 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
213 $GLOBALS['TYPO3_DB']->sql_free_result($res);
215 $this->versionOL('pages', $row);
216 if (is_array($row)) {
217 $output = $this->getPageOverlay($row);
224 * Returns a pagerow for the page with alias $alias
226 * @param string $alias The alias to look up the page uid for.
227 * @return integer Returns page uid (integer) if found, otherwise 0 (zero)
228 * @see tslib_fe::checkAndSetAlias(), tslib_cObj::typoLink()
230 function getPageIdFromAlias($alias) {
231 $alias = strtolower($alias);
232 if ($this->cache_getPageIdFromAlias
[$alias]) {
233 return $this->cache_getPageIdFromAlias
[$alias];
235 $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!)
236 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
237 $GLOBALS['TYPO3_DB']->sql_free_result($res);
239 $this->cache_getPageIdFromAlias
[$alias] = $row['uid'];
242 $this->cache_getPageIdFromAlias
[$alias] = 0;
247 * Returns the relevant page overlay record fields
249 * @param mixed $pageInput If $pageInput is an integer, it's the pid of the pageOverlay record and thus the page overlay record is returned. If $pageInput is an array, it's a page-record and based on this page record the language record is found and OVERLAYED before the page record is returned.
250 * @param integer $lUid Language UID if you want to set an alternative value to $this->sys_language_uid which is default. Should be >=0
251 * @return array Page row which is overlayed with language_overlay record (or the overlay record alone)
253 function getPageOverlay($pageInput, $lUid = -1) {
257 $lUid = $this->sys_language_uid
;
261 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPageOverlay'])) {
262 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPageOverlay'] as $classRef) {
263 $hookObject = t3lib_div
::getUserObj($classRef);
265 if (!($hookObject instanceof t3lib_pageSelect_getPageOverlayHook
)) {
266 throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getPageOverlayHook', 1269878881);
269 $hookObject->getPageOverlay_preProcess($pageInput, $lUid, $this);
273 // If language UID is different from zero, do overlay:
275 $fieldArr = t3lib_div
::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
276 if (is_array($pageInput)) {
277 // Was the whole record
278 $page_id = $pageInput['uid'];
279 // Make sure that only fields which exist in the incoming record are overlaid!
280 $fieldArr = array_intersect($fieldArr, array_keys($pageInput));
283 $page_id = $pageInput;
286 if (count($fieldArr)) {
287 // NOTE to enabledFields('pages_language_overlay'):
288 // Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page.
289 // However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now.
291 // Selecting overlay record:
292 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
293 implode(',', $fieldArr),
294 'pages_language_overlay',
295 'pid=' . intval($page_id) . '
296 AND sys_language_uid=' . intval($lUid) .
297 $this->enableFields('pages_language_overlay'),
302 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
303 $GLOBALS['TYPO3_DB']->sql_free_result($res);
304 $this->versionOL('pages_language_overlay', $row);
306 if (is_array($row)) {
307 $row['_PAGES_OVERLAY'] = TRUE;
308 $row['_PAGES_OVERLAY_UID'] = $row['uid'];
309 $row['_PAGES_OVERLAY_LANGUAGE'] = $lUid;
311 // Unset vital fields that are NOT allowed to be overlaid:
319 if (is_array($pageInput)) {
320 // If the input was an array, simply overlay the newfound array and return...
321 return is_array($row) ?
array_merge($pageInput, $row) : $pageInput;
323 // Always an array in return
324 return is_array($row) ?
$row : array();
329 * Creates language-overlay for records in general (where translation is found in records from the same table)
331 * @param string $table Table name
332 * @param array $row Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField']
333 * @param integer $sys_language_content Pointer to the sys_language uid for content on the site.
334 * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE)
335 * @return mixed Returns the input record, possibly overlaid with a translation. But if $OLmode is "hideNonTranslated" then it will return FALSE if no translation is found.
337 function getRecordOverlay($table, $row, $sys_language_content, $OLmode = '') {
338 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) {
339 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'] as $classRef) {
340 $hookObject = t3lib_div
::getUserObj($classRef);
342 if (!($hookObject instanceof t3lib_pageSelect_getRecordOverlayHook
)) {
343 throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getRecordOverlayHook', 1269881658);
345 $hookObject->getRecordOverlay_preProcess($table, $row, $sys_language_content, $OLmode, $this);
349 if ($row['uid'] > 0 && $row['pid'] > 0) {
350 if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['languageField']
351 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']) {
352 if (!$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
353 // Will not be able to work with other tables (Just didn't implement it yet; Requires a scan
354 // over all tables [ctrl] part for first FIND the table that carries localization information for
355 // this table (which could even be more than a single table) and then use that. Could be
356 // implemented, but obviously takes a little more....)
358 // Will try to overlay a record only if the sys_language_content value is larger than zero.
359 if ($sys_language_content > 0) {
361 // Must be default language or [All], otherwise no overlaying:
362 if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] <= 0) {
364 // Select overlay record:
365 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
368 'pid=' . intval($row['pid']) .
369 ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '=' . intval($sys_language_content) .
370 ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($row['uid']) .
371 $this->enableFields($table),
376 $olrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
377 $GLOBALS['TYPO3_DB']->sql_free_result($res);
378 $this->versionOL($table, $olrow);
380 // Merge record content by traversing all fields:
381 if (is_array($olrow)) {
382 if (isset($olrow['_ORIG_uid'])) {
383 $row['_ORIG_uid'] = $olrow['_ORIG_uid'];
385 if (isset($olrow['_ORIG_pid'])) {
386 $row['_ORIG_pid'] = $olrow['_ORIG_pid'];
388 foreach ($row as $fN => $fV) {
389 if ($fN != 'uid' && $fN != 'pid' && isset($olrow[$fN])) {
391 if ($GLOBALS['TSFE']->TCAcachedExtras
[$table]['l10n_mode'][$fN] != 'exclude'
392 && ($GLOBALS['TSFE']->TCAcachedExtras
[$table]['l10n_mode'][$fN] != 'mergeIfNotBlank' ||
strcmp(trim($olrow[$fN]), ''))) {
393 $row[$fN] = $olrow[$fN];
395 } elseif ($fN == 'uid') {
396 $row['_LOCALIZED_UID'] = $olrow['uid'];
399 } elseif ($OLmode === 'hideNonTranslated' && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] == 0) {
400 // Unset, if non-translated records should be hidden. ONLY done if the source record
401 // really is default language and not [All] in which case it is allowed.
405 // Otherwise, check if sys_language_content is different from the value of the record - that means a japanese site might try to display french content.
406 } elseif ($sys_language_content != $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]) {
410 // When default language is displayed, we never want to return a record carrying another language!
411 if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0) {
418 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) {
419 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'] as $classRef) {
420 $hookObject = t3lib_div
::getUserObj($classRef);
422 if (!($hookObject instanceof t3lib_pageSelect_getRecordOverlayHook
)) {
423 throw new UnexpectedValueException('$hookObject must implement interface t3lib_pageSelect_getRecordOverlayHook', 1269881659);
425 $hookObject->getRecordOverlay_postProcess($table, $row, $sys_language_content, $OLmode, $this);
431 /*******************************************
433 * Page related: Menu, Domain record, Root line
435 ******************************************/
438 * Returns an array with pagerows for subpages with pid=$uid (which is pid here!). This is used for menus.
439 * If there are mount points in overlay mode the _MP_PARAM field is set to the corret MPvar.
440 * If the $uid being input does in itself require MPvars to define a correct rootline these must be handled externally to this function.
442 * @param integer $uid The page id for which to fetch subpages (PID)
443 * @param string $fields List of fields to select. Default is "*" = all
444 * @param string $sortField The field to sort by. Default is "sorting"
445 * @param string $addWhere Optional additional where clauses. Like "AND title like '%blabla%'" for instance.
446 * @param boolean $checkShortcuts Check if shortcuts exist, checks by default
447 * @return array Array with key/value pairs; keys are page-uid numbers. values are the corresponding page records (with overlayed localized fields, if any)
448 * @see tslib_fe::getPageShortcut(), tslib_menu::makeMenu(), tx_wizardcrpages_webfunc_2, tx_wizardsortpages_webfunc_2
450 function getMenu($uid, $fields = '*', $sortField = 'sorting', $addWhere = '', $checkShortcuts = TRUE) {
453 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', 'pid=' . intval($uid) . $this->where_hid_del
. $this->where_groupAccess
. ' ' . $addWhere, '', $sortField);
454 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
455 $this->versionOL('pages', $row, TRUE);
456 if (is_array($row)) {
458 $origUid = $row['uid'];
459 // $row MUST have "uid", "pid", "doktype", "mount_pid", "mount_pid_ol" fields in it
460 $mount_info = $this->getMountPointInfo($origUid, $row);
461 // There is a valid mount point.
462 if (is_array($mount_info) && $mount_info['overlay']) {
463 // Using "getPage" is OK since we need the check for enableFields AND for type 2 of mount pids we DO require a doktype < 200!
464 $mp_row = $this->getPage($mount_info['mount_pid']);
465 if (count($mp_row)) {
467 $row['_MP_PARAM'] = $mount_info['MPvar'];
470 } // If the mount point could not be fetched with respect to enableFields, unset the row so it does not become a part of the menu!
473 // If shortcut, look up if the target exists and is currently visible
474 if ($row['doktype'] == self
::DOKTYPE_SHORTCUT
&& ($row['shortcut'] ||
$row['shortcut_mode']) && $checkShortcuts) {
475 if ($row['shortcut_mode'] == self
::SHORTCUT_MODE_NONE
) {
476 // No shortcut_mode set, so target is directly set in $row['shortcut']
477 $searchField = 'uid';
478 $searchUid = intval($row['shortcut']);
479 } elseif ($row['shortcut_mode'] == self
::SHORTCUT_MODE_FIRST_SUBPAGE ||
$row['shortcut_mode'] == self
::SHORTCUT_MODE_RANDOM_SUBPAGE
) {
480 // Check subpages - first subpage or random subpage
481 $searchField = 'pid';
482 // If a shortcut mode is set and no valid page is given to select subpags from use the actual page.
483 $searchUid = intval($row['shortcut']) ?
intval($row['shortcut']) : $row['uid'];
484 } elseif ($row['shortcut_mode'] == self
::SHORTCUT_MODE_PARENT_PAGE
) {
485 // Shortcut to parent page
486 $searchField = 'uid';
487 $searchUid = $row['pid'];
489 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
492 $searchField . '=' . $searchUid .
493 $this->where_hid_del
.
494 $this->where_groupAccess
.
500 } elseif ($row['doktype'] == self
::DOKTYPE_SHORTCUT
&& $checkShortcuts) {
501 // Neither shortcut target nor mode is set. Remove the page from the menu.
505 // Add to output array after overlaying language:
506 if (is_array($row)) {
507 $output[$origUid] = $this->getPageOverlay($row);
511 $GLOBALS['TYPO3_DB']->sql_free_result($res);
516 * Will find the page carrying the domain record matching the input domain.
517 * Might exit after sending a redirect-header IF a found domain record instructs to do so.
519 * @param string $domain Domain name to search for. Eg. "www.typo3.com". Typical the HTTP_HOST value.
520 * @param string $path Path for the current script in domain. Eg. "/somedir/subdir". Typ. supplied by t3lib_div::getIndpEnv('SCRIPT_NAME')
521 * @param string $request_uri Request URI: Used to get parameters from if they should be appended. Typ. supplied by t3lib_div::getIndpEnv('REQUEST_URI')
522 * @return mixed If found, returns integer with page UID where found. Otherwise blank. Might exit if location-header is sent, see description.
523 * @see tslib_fe::findDomainRecord()
525 function getDomainStartPage($domain, $path = '', $request_uri = '') {
526 $domain = explode(':', $domain);
527 $domain = strtolower(preg_replace('/\.$/', '', $domain[0]));
528 // Removing extra trailing slashes
529 $path = trim(preg_replace('/\/[^\/]*$/', '', $path));
530 // Appending to domain string
532 $domain = preg_replace('/\/*$/', '', $domain);
534 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
535 'pages.uid,sys_domain.redirectTo,sys_domain.redirectHttpStatusCode,sys_domain.prepend_params',
537 'pages.uid=sys_domain.pid
538 AND sys_domain.hidden=0
539 AND (sys_domain.domainName=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($domain, 'sys_domain') . ' OR sys_domain.domainName=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($domain . '/', 'sys_domain') . ') ' .
540 $this->where_hid_del
. $this->where_groupAccess
,
545 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
546 $GLOBALS['TYPO3_DB']->sql_free_result($res);
548 if ($row['redirectTo']) {
549 $redirectUrl = $row['redirectTo'];
550 if ($row['prepend_params']) {
551 $redirectUrl = rtrim($redirectUrl, '/');
552 $prependStr = ltrim(substr($request_uri, strlen($path)), '/');
553 $redirectUrl .= '/' . $prependStr;
556 $statusCode = intval($row['redirectHttpStatusCode']);
557 if ($statusCode && defined('t3lib_utility_Http::HTTP_STATUS_' . $statusCode)) {
558 t3lib_utility_Http
::redirect($redirectUrl, constant('t3lib_utility_Http::HTTP_STATUS_' . $statusCode));
560 t3lib_utility_Http
::redirect($redirectUrl, 't3lib_utility_Http::HTTP_STATUS_301');
570 * Returns array with fields of the pages from here ($uid) and back to the root
571 * NOTICE: This function only takes deleted pages into account! So hidden, starttime and endtime restricted pages are included no matter what.
572 * Further: If any "recycler" page is found (doktype=255) then it will also block for the rootline)
573 * If you want more fields in the rootline records than default such can be added by listing them in $GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']
575 * @param integer $uid The page uid for which to seek back to the page tree root.
576 * @param string $MP Commalist of MountPoint parameters, eg. "1-2,3-4" etc. Normally this value comes from the GET var, MP
577 * @param boolean $ignoreMPerrors If set, some errors related to Mount Points in root line are ignored.
578 * @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.
579 * @see tslib_fe::getPageAndRootline()
581 function getRootLine($uid, $MP = '', $ignoreMPerrors = FALSE) {
582 $rootline = t3lib_div
::makeInstance('t3lib_rootline', $uid, $MP, $this);
583 if ($ignoreMPerrors) {
585 return $rootline->get();
586 } catch (Exception
$e) {
587 $this->error_getRootLine
= $e->getMessage();
588 if (substr($e->getMessage(), -7) == 'uid -1.') {
589 $this->error_getRootLine_failPid
= -1;
594 return $rootline->get();
599 * Creates a "path" string for the input root line array titles.
600 * Used for writing statistics.
602 * @param array $rl A rootline array!
603 * @param integer $len The max length of each title from the rootline.
604 * @return string The path in the form "/page title/This is another pageti.../Another page"
605 * @see tslib_fe::getConfigArray()
607 function getPathFromRootline($rl, $len = 20) {
611 for ($a = 0; $a < $c; $a++
) {
612 if ($rl[$a]['uid']) {
613 $path .= '/' . t3lib_div
::fixed_lgd_cs(strip_tags($rl[$a]['title']), $len);
621 * Returns the URL type for the input page row IF the doktype is 3 and not disabled.
623 * @param array $pagerow The page row to return URL type for
624 * @param boolean $disable A flag to simply disable any output from here.
625 * @return string The URL type from $this->urltypes array. False if not found or disabled.
626 * @see tslib_fe::setExternalJumpUrl()
628 function getExtURL($pagerow, $disable = 0) {
629 if ($pagerow['doktype'] == self
::DOKTYPE_LINK
&& !$disable) {
630 $redirectTo = $this->urltypes
[$pagerow['urltype']] . $pagerow['url'];
632 // If relative path, prefix Site URL:
633 $uI = parse_url($redirectTo);
634 // Relative path assumed now.
635 if (!$uI['scheme'] && substr($redirectTo, 0, 1) != '/') {
636 $redirectTo = t3lib_div
::getIndpEnv('TYPO3_SITE_URL') . $redirectTo;
643 * Returns MountPoint id for page
644 * Does a recursive search if the mounted page should be a mount page itself. It has a run-away break so it can't go into infinite loops.
646 * @param integer $pageId Page id for which to look for a mount pid. Will be returned only if mount pages are enabled, the correct doktype (7) is set for page and there IS a mount_pid (which has a valid record that is not deleted...)
647 * @param array $pageRec Optional page record for the page id. If not supplied it will be looked up by the system. Must contain at least uid,pid,doktype,mount_pid,mount_pid_ol
648 * @param array $prevMountPids Array accumulating formerly tested page ids for mount points. Used for recursivity brake.
649 * @param integer $firstPageUid The first page id.
650 * @return mixed Returns FALSE if no mount point was found, "-1" if there should have been one, but no connection to it, otherwise an array with information about mount pid and modes.
653 function getMountPointInfo($pageId, $pageRec = FALSE, $prevMountPids = array(), $firstPageUid = 0) {
656 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids']) {
658 if (isset($this->cache_getMountPointInfo
[$pageId])) {
659 return $this->cache_getMountPointInfo
[$pageId];
662 // Get pageRec if not supplied:
663 if (!is_array($pageRec)) {
664 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,doktype,mount_pid,mount_pid_ol,t3ver_state', 'pages', 'uid=' . intval($pageId) . ' AND pages.deleted=0 AND pages.doktype<>255');
665 $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
666 $GLOBALS['TYPO3_DB']->sql_free_result($res);
667 // Only look for version overlay if page record is not supplied; This assumes that the input record is overlaid with preview version, if any!
668 $this->versionOL('pages', $pageRec);
671 // Set first Page uid:
672 if (!$firstPageUid) {
673 $firstPageUid = $pageRec['uid'];
676 // Look for mount pid value plus other required circumstances:
677 $mount_pid = intval($pageRec['mount_pid']);
678 if (is_array($pageRec) && $pageRec['doktype'] == self
::DOKTYPE_MOUNTPOINT
&& $mount_pid > 0 && !in_array($mount_pid, $prevMountPids)) {
680 // Get the mount point record (to verify its general existence):
681 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,doktype,mount_pid,mount_pid_ol,t3ver_state', 'pages', 'uid=' . $mount_pid . ' AND pages.deleted=0 AND pages.doktype<>255');
682 $mountRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
683 $GLOBALS['TYPO3_DB']->sql_free_result($res);
684 $this->versionOL('pages', $mountRec);
686 if (is_array($mountRec)) {
687 // Look for recursive mount point:
688 $prevMountPids[] = $mount_pid;
689 $recursiveMountPid = $this->getMountPointInfo($mount_pid, $mountRec, $prevMountPids, $firstPageUid);
691 // Return mount point information:
692 $result = $recursiveMountPid ?
695 'mount_pid' => $mount_pid,
696 'overlay' => $pageRec['mount_pid_ol'],
697 'MPvar' => $mount_pid . '-' . $firstPageUid,
698 'mount_point_rec' => $pageRec,
699 'mount_pid_rec' => $mountRec,
702 // Means, there SHOULD have been a mount point, but there was none!
708 $this->cache_getMountPointInfo
[$pageId] = $result;
712 /*********************************
714 * Selecting records in general
716 **********************************/
719 * Checks if a record exists and is accessible.
720 * The row is returned if everything's OK.
722 * @param string $table The table name to search
723 * @param integer $uid The uid to look up in $table
724 * @param boolean $checkPage If checkPage is set, it's also required that the page on which the record resides is accessible
725 * @return mixed Returns array (the record) if OK, otherwise blank/0 (zero)
727 function checkRecord($table, $uid, $checkPage = 0) {
729 if (is_array($GLOBALS['TCA'][$table]) && $uid > 0) {
730 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid = ' . $uid . $this->enableFields($table));
731 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
732 $GLOBALS['TYPO3_DB']->sql_free_result($res);
734 $this->versionOL($table, $row);
735 if (is_array($row)) {
737 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid=' . intval($row['pid']) . $this->enableFields('pages'));
738 $numRows = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
739 $GLOBALS['TYPO3_DB']->sql_free_result($res);
754 * Returns record no matter what - except if record is deleted
756 * @param string $table The table name to search
757 * @param integer $uid The uid to look up in $table
758 * @param string $fields The fields to select, default is "*"
759 * @param boolean $noWSOL If set, no version overlay is applied
760 * @return mixed Returns array (the record) if found, otherwise blank/0 (zero)
761 * @see getPage_noCheck()
763 function getRawRecord($table, $uid, $fields = '*', $noWSOL = FALSE) {
765 // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
766 if ((is_array($GLOBALS['TCA'][$table]) ||
$table == 'pages') && $uid > 0) {
767 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid = ' . $uid . $this->deleteClause($table));
768 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
769 $GLOBALS['TYPO3_DB']->sql_free_result($res);
772 $this->versionOL($table, $row);
774 if (is_array($row)) {
782 * Selects records based on matching a field (ei. other than UID) with a value
784 * @param string $theTable The table name to search, eg. "pages" or "tt_content"
785 * @param string $theField The fieldname to match, eg. "uid" or "alias"
786 * @param string $theValue The value that fieldname must match, eg. "123" or "frontpage"
787 * @param string $whereClause Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
788 * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string.
789 * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string.
790 * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
791 * @return mixed Returns array (the record) if found, otherwise nothing (void)
793 function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
794 if (is_array($GLOBALS['TCA'][$theTable])) {
795 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
798 $theField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable) .
799 $this->deleteClause($theTable) . ' ' .
800 $whereClause, // whereClauseMightContainGroupOrderBy
806 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
807 if (is_array($row)) {
811 $GLOBALS['TYPO3_DB']->sql_free_result($res);
818 /*********************************
820 * Caching and standard clauses
822 **********************************/
825 * Returns string value stored for the hash string in the cache "cache_hash"
826 * Can be used to retrieved a cached value
827 * Can be used from your frontend plugins if you like. It is also used to
828 * store the parsed TypoScript template structures. You can call it directly
829 * like t3lib_pageSelect::getHash()
831 * @param string $hash The hash-string which was used to store the data value
832 * @return string The "content" field of the "cache_hash" cache entry.
833 * @see tslib_TStemplate::start(), storeHash()
835 public static function getHash($hash, $expTime = 0) {
838 if (is_object($GLOBALS['typo3CacheManager'])) {
839 $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
840 $cacheEntry = $contentHashCache->get($hash);
843 $hashContent = $cacheEntry;
851 * Stores a string value in the cache_hash cache identified by $hash.
852 * Can be used from your frontend plugins if you like. You can call it
853 * directly like t3lib_pageSelect::storeHash()
855 * @param string $hash 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
856 * @param string $data The data string. If you want to store an array, then just serialize it first.
857 * @param string $ident Is just a textual identification in order to inform about the content!
858 * @param integer $lifetime The lifetime for the cache entry in seconds
860 * @see tslib_TStemplate::start(), getHash()
862 public static function storeHash($hash, $data, $ident, $lifetime = 0) {
863 if (is_object($GLOBALS['typo3CacheManager'])) {
864 $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
867 array('ident_' . $ident),
874 * Returns the "AND NOT deleted" clause for the tablename given IF $GLOBALS['TCA'] configuration points to such a field.
876 * @param string $table Tablename
878 * @see enableFields()
880 function deleteClause($table) {
881 // Hardcode for pages because TCA might not be loaded yet (early frontend initialization)
882 if (!strcmp($table, 'pages')) {
883 return ' AND pages.deleted=0';
885 return $GLOBALS['TCA'][$table]['ctrl']['delete'] ?
' AND ' . $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0' : '';
890 * Returns a part of a WHERE clause which will filter out records with start/end times or hidden/fe_groups fields set to values that should de-select them according to the current time, preview settings or user login. Definitely a frontend function.
891 * Is using the $GLOBALS['TCA'] arrays "ctrl" part where the key "enablefields" determines for each table which of these features applies to that table.
893 * @param string $table Table name found in the $GLOBALS['TCA'] array
894 * @param integer $show_hidden If $show_hidden is set (0/1), any hidden-fields in records are ignored. NOTICE: If you call this function, consider what to do with the show_hidden parameter. Maybe it should be set? See tslib_cObj->enableFields where it's implemented correctly.
895 * @param array $ignore_array Array you can pass where keys can be "disabled", "starttime", "endtime", "fe_group" (keys from "enablefields" in TCA) and if set they will make sure that part of the clause is not added. Thus disables the specific part of the clause. For previewing etc.
896 * @param boolean $noVersionPreview If set, enableFields will be applied regardless of any versioning preview settings which might otherwise disable enableFields
897 * @return string The clause starting like " AND ...=... AND ...=..."
898 * @see tslib_cObj::enableFields(), deleteClause()
900 function enableFields($table, $show_hidden = -1, $ignore_array = array(), $noVersionPreview = FALSE) {
901 if ($show_hidden == -1 && is_object($GLOBALS['TSFE'])) { // If show_hidden was not set from outside and if TSFE is an object, set it based on showHiddenPage and showHiddenRecords from TSFE
902 $show_hidden = $table == 'pages' ?
$GLOBALS['TSFE']->showHiddenPage
: $GLOBALS['TSFE']->showHiddenRecords
;
904 if ($show_hidden == -1) {
906 } // If show_hidden was not changed during the previous evaluation, do it here.
908 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
910 if (is_array($ctrl)) {
912 // Delete field check:
913 if ($ctrl['delete']) {
914 $query .= ' AND ' . $table . '.' . $ctrl['delete'] . '=0';
917 // Filter out new place-holder records in case we are NOT in a versioning preview (that means we are online!)
918 if ($ctrl['versioningWS'] && !$this->versioningPreview
) {
919 // Shadow state for new items MUST be ignored!
920 $query .= ' AND ' . $table . '.t3ver_state<=0 AND ' . $table . '.pid<>-1';
924 if (is_array($ctrl['enablecolumns'])) {
925 // In case of versioning-preview, enableFields are ignored (checked in versionOL())
926 if (!$this->versioningPreview ||
!$ctrl['versioningWS'] ||
$noVersionPreview) {
927 if ($ctrl['enablecolumns']['disabled'] && !$show_hidden && !$ignore_array['disabled']) {
928 $field = $table . '.' . $ctrl['enablecolumns']['disabled'];
929 $query .= ' AND ' . $field . '=0';
931 if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
932 $field = $table . '.' . $ctrl['enablecolumns']['starttime'];
933 $query .= ' AND ' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'];
935 if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime']) {
936 $field = $table . '.' . $ctrl['enablecolumns']['endtime'];
937 $query .= ' AND (' . $field . '=0 OR ' . $field . '>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
939 if ($ctrl['enablecolumns']['fe_group'] && !$ignore_array['fe_group']) {
940 $field = $table . '.' . $ctrl['enablecolumns']['fe_group'];
941 $query .= $this->getMultipleGroupsWhereClause($field, $table);
944 // Call hook functions for additional enableColumns
945 // It is used by the extension ingmar_accessctrl which enables assigning more than one usergroup to content and page records
946 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['addEnableColumns'])) {
949 'show_hidden' => $show_hidden,
950 'ignore_array' => $ignore_array,
953 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['addEnableColumns'] as $_funcRef) {
954 $query .= t3lib_div
::callUserFunction($_funcRef, $_params, $this);
960 throw new InvalidArgumentException(
961 'There is no entry in the $TCA array for the table "' . $table .
962 '". This means that the function enableFields() is ' .
963 'called with an invalid table name as argument.',
972 * Creating where-clause for checking group access to elements in enableFields function
974 * @param string $field Field with group list
975 * @param string $table Table name
976 * @return string AND sql-clause
977 * @see enableFields()
979 function getMultipleGroupsWhereClause($field, $table) {
980 $memberGroups = t3lib_div
::intExplode(',', $GLOBALS['TSFE']->gr_list
);
982 // If the field is empty, then OK
983 $orChecks[] = $field . '=\'\'';
984 // If the field is NULL, then OK
985 $orChecks[] = $field . ' IS NULL';
986 // If the field contsains zero, then OK
987 $orChecks[] = $field . '=\'0\'';
989 foreach ($memberGroups as $value) {
990 $orChecks[] = $GLOBALS['TYPO3_DB']->listQuery($field, $value, $table);
993 return ' AND (' . implode(' OR ', $orChecks) . ')';
996 /*********************************
1000 **********************************/
1003 * Finding online PID for offline version record
1004 * ONLY active when backend user is previewing records. MUST NEVER affect a site served which is not previewed by backend users!!!
1005 * Will look if the "pid" value of the input record is -1 (it is an offline version) and if the table supports versioning; if so, it will translate the -1 PID into the PID of the original record
1006 * Used whenever you are tracking something back, like making the root line.
1007 * Principle; Record offline! => Find online?
1009 * @param string $table Table name
1010 * @param array $rr Record array passed by reference. As minimum, "pid" and "uid" fields must exist! "t3ver_oid" and "t3ver_wsid" is nice and will save you a DB query.
1011 * @return void (Passed by ref).
1012 * @see t3lib_BEfunc::fixVersioningPid(), versionOL(), getRootLine()
1014 function fixVersioningPid($table, &$rr) {
1015 if ($this->versioningPreview
&& is_array($rr) && $rr['pid'] == -1
1016 && ($table == 'pages' ||
$GLOBALS['TCA'][$table]['ctrl']['versioningWS'])) {
1017 // Have to hardcode it for "pages" table since TCA is not loaded at this moment!
1019 // Check values for t3ver_oid and t3ver_wsid:
1020 if (isset($rr['t3ver_oid']) && isset($rr['t3ver_wsid'])) { // If "t3ver_oid" is already a field, just set this:
1021 $oid = $rr['t3ver_oid'];
1022 $wsid = $rr['t3ver_wsid'];
1023 } else { // Otherwise we have to expect "uid" to be in the record and look up based on this:
1024 $newPidRec = $this->getRawRecord($table, $rr['uid'], 't3ver_oid,t3ver_wsid', TRUE);
1025 if (is_array($newPidRec)) {
1026 $oid = $newPidRec['t3ver_oid'];
1027 $wsid = $newPidRec['t3ver_wsid'];
1031 // If workspace ids matches and ID of current online version is found, look up the PID value of that:
1032 if ($oid && (($this->versioningWorkspaceId
== 0 && $this->checkWorkspaceAccess($wsid)) ||
!strcmp((int) $wsid, $this->versioningWorkspaceId
))) {
1033 $oidRec = $this->getRawRecord($table, $oid, 'pid', TRUE);
1035 if (is_array($oidRec)) {
1036 // SWAP uid as well? Well no, because when fixing a versioning PID happens it is assumed that this is a "branch" type page and therefore the uid should be kept (like in versionOL()).
1037 // However if the page is NOT a branch version it should not happen - but then again, direct access to that uid should not happen!
1038 $rr['_ORIG_pid'] = $rr['pid'];
1039 $rr['pid'] = $oidRec['pid'];
1044 // Changing PID in case of moving pointer:
1045 if ($movePlhRec = $this->getMovePlaceholder($table, $rr['uid'], 'pid')) {
1046 $rr['pid'] = $movePlhRec['pid'];
1051 * Versioning Preview Overlay
1052 * ONLY active when backend user is previewing records. MUST NEVER affect a site served which is not previewed by backend users!!!
1053 * Generally ALWAYS used when records are selected based on uid or pid. If records are selected on other fields than uid or pid (eg. "email = ....") then usage might produce undesired results and that should be evaluated on individual basis.
1054 * Principle; Record online! => Find offline?
1056 * @param string $table Table name
1057 * @param array $row Record array passed by reference. As minimum, the "uid", "pid" and "t3ver_state" fields must exist! The record MAY be set to FALSE in which case the calling function should act as if the record is forbidden to access!
1058 * @param boolean $unsetMovePointers If set, the $row is cleared in case it is a move-pointer. This is only for preview of moved records (to remove the record from the original location so it appears only in the new location)
1059 * @param boolean $bypassEnableFieldsCheck Unless this option is TRUE, the $row is unset if enablefields for BOTH the version AND the online record deselects it. This is because when versionOL() is called it is assumed that the online record is already selected with no regards to it's enablefields. However, after looking for a new version the online record enablefields must ALSO be evaluated of course. This is done all by this function!
1060 * @return void (Passed by ref).
1061 * @see fixVersioningPid(), t3lib_BEfunc::workspaceOL()
1063 function versionOL($table, &$row, $unsetMovePointers = FALSE, $bypassEnableFieldsCheck = FALSE) {
1064 if ($this->versioningPreview
&& is_array($row)) {
1065 // will overlay any movePlhOL found with the real record, which in turn will be overlaid with its workspace version if any.
1066 $movePldSwap = $this->movePlhOL($table, $row);
1067 // implode(',',array_keys($row)) = Using fields from original record to make sure no additional fields are selected. This is best for eg. getPageOverlay()
1068 if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId
, $table, $row['uid'], implode(',', array_keys($row)), $bypassEnableFieldsCheck)) {
1069 if (is_array($wsAlt)) {
1070 // Always fix PID (like in fixVersioningPid() above). [This is usually not the important factor for versioning OL]
1071 // Keep the old (-1) - indicates it was a version...
1072 $wsAlt['_ORIG_pid'] = $wsAlt['pid'];
1073 // Set in the online versions PID.
1074 $wsAlt['pid'] = $row['pid'];
1076 // For versions of single elements or page+content, preserve online UID and PID (this will produce true "overlay" of element _content_, not any references)
1077 // For page+content the "_ORIG_uid" should actually be used as PID for selection of tables with "versioning_followPages" enabled.
1078 $wsAlt['_ORIG_uid'] = $wsAlt['uid'];
1079 $wsAlt['uid'] = $row['uid'];
1081 // Translate page alias as well so links are pointing to the _online_ page:
1082 if ($table === 'pages') {
1083 $wsAlt['alias'] = $row['alias'];
1086 // Changing input record to the workspace version alternative:
1089 // Check if it is deleted/new
1090 if ((int) $row['t3ver_state'] === 1 ||
(int) $row['t3ver_state'] === 2) {
1091 // Unset record if it turned out to be deleted in workspace
1095 // Check if move-pointer in workspace (unless if a move-placeholder is the reason why it appears!):
1096 // You have to specifically set $unsetMovePointers in order to clear these because it is normally a display issue if it should be shown or not.
1097 if ((int) $row['t3ver_state'] === 4 && !$movePldSwap && $unsetMovePointers) {
1098 // Unset record if it turned out to be deleted in workspace
1102 // No version found, then check if t3ver_state =1 (online version is dummy-representation)
1103 // Notice, that unless $bypassEnableFieldsCheck is TRUE, the $row is unset if enablefields for BOTH the version AND the online record deselects it. See note for $bypassEnableFieldsCheck
1104 if ($wsAlt <= -1 ||
(int) $row['t3ver_state'] > 0) {
1105 // Unset record if it turned out to be "hidden"
1114 * Checks if record is a move-placeholder (t3ver_state==3) and if so it will set $row to be the pointed-to live record (and return TRUE)
1115 * Used from versionOL
1117 * @param string $table Table name
1118 * @param array $row Row (passed by reference) - only online records...
1119 * @return boolean TRUE if overlay is made.
1120 * @see t3lib_BEfunc::movePlhOl()
1122 function movePlhOL($table, &$row) {
1123 if (($table == 'pages' ||
(int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) && (int) $row['t3ver_state'] === 3) {
1124 // Only for WS ver 2... (moving)
1126 // If t3ver_move_id is not found, then find it... (but we like best if it is here...)
1127 if (!isset($row['t3ver_move_id'])) {
1128 $moveIDRec = $this->getRawRecord($table, $row['uid'], 't3ver_move_id', TRUE);
1129 $moveID = $moveIDRec['t3ver_move_id'];
1131 $moveID = $row['t3ver_move_id'];
1134 // Find pointed-to record.
1136 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(implode(',', array_keys($row)), $table, 'uid=' . intval($moveID) . $this->enableFields($table));
1137 $origRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
1138 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1149 * Returns move placeholder of online (live) version
1151 * @param string $table Table name
1152 * @param integer $uid Record UID of online version
1153 * @param string $fields Field list, default is *
1154 * @return array If found, the record, otherwise nothing.
1155 * @see t3lib_BEfunc::getMovePlaceholder()
1157 function getMovePlaceholder($table, $uid, $fields = '*') {
1158 if ($this->versioningPreview
) {
1159 $workspace = (int) $this->versioningWorkspaceId
;
1160 if (($table == 'pages' ||
(int) $GLOBALS['TCA'][$table]['ctrl']['versioningWS'] >= 2) && $workspace !== 0) {
1162 // Select workspace version of record:
1163 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1168 t3ver_move_id=' . intval($uid) . ' AND
1169 t3ver_wsid=' . intval($workspace) .
1170 $this->deleteClause($table)
1173 if (is_array($row)) {
1182 * Select the version of a record for a workspace
1184 * @param integer $workspace Workspace ID
1185 * @param string $table Table name to select from
1186 * @param integer $uid Record uid for which to find workspace version.
1187 * @param string $fields Field list to select
1188 * @param boolean $bypassEnableFieldsCheck If TRUE, enablefields are not checked for.
1189 * @return mixed If found, return record, otherwise other value: Returns 1 if version was sought for but not found, returns -1/-2 if record (offline/online) existed but had enableFields that would disable it. Returns FALSE if not in workspace or no versioning for record. Notice, that the enablefields of the online record is also tested.
1190 * @see t3lib_befunc::getWorkspaceVersionOfRecord()
1192 function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields = '*', $bypassEnableFieldsCheck = FALSE) {
1193 if ($workspace !== 0) {
1194 // Have to hardcode it for "pages" table since TCA is not loaded at this moment!
1196 // Setting up enableFields for version record:
1197 if ($table == 'pages') {
1198 $enFields = $this->versioningPreview_where_hid_del
;
1200 $enFields = $this->enableFields($table, -1, array(), TRUE);
1203 // Select workspace version of record, only testing for deleted.
1204 $newrow = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1208 t3ver_oid=' . intval($uid) . ' AND
1209 t3ver_wsid=' . intval($workspace) .
1210 $this->deleteClause($table)
1213 // If version found, check if it could have been selected with enableFields on as well:
1214 if (is_array($newrow)) {
1215 if ($bypassEnableFieldsCheck ||
$GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1219 t3ver_oid=' . intval($uid) . ' AND
1220 t3ver_wsid=' . intval($workspace) .
1223 // Return offline version, tested for its enableFields.
1226 // Return -1 because offline version was de-selected due to its enableFields.
1230 // OK, so no workspace version was found. Then check if online version can be selected with full enable fields and if so, return 1:
1231 if ($bypassEnableFieldsCheck ||
$GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
1234 'uid=' . intval($uid) . $enFields
1236 // Means search was done, but no version found.
1239 // Return -2 because the online record was de-selected due to its enableFields.
1245 // No look up in database because versioning not enabled / or workspace not offline
1250 * Checks if user has access to workspace.
1252 * @param integer $wsid Workspace ID
1253 * @return boolean <code>TRUE</code> if has access
1255 function checkWorkspaceAccess($wsid) {
1256 if (!$GLOBALS['BE_USER'] ||
!t3lib_extMgm
::isLoaded('workspaces')) {
1259 if (isset($this->workspaceCache
[$wsid])) {
1260 $ws = $this->workspaceCache
[$wsid];
1264 // No $GLOBALS['TCA'] yet!
1265 $ws = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', 'sys_workspace', 'uid=' . intval($wsid) . ' AND deleted=0');
1266 if (!is_array($ws)) {
1273 $ws = $GLOBALS['BE_USER']->checkWorkspace($ws);
1274 $this->workspaceCache
[$wsid] = $ws;
1276 return ($ws['_ACCESS'] != '');