diff --git a/t3lib/class.t3lib_page.php b/t3lib/class.t3lib_page.php index 0f87b74a05392b78b9c514d033fdc73fa67f3384..de1f7275fce3f79c00723cf68835e5893d3128ab 100644 --- a/t3lib/class.t3lib_page.php +++ b/t3lib/class.t3lib_page.php @@ -30,35 +30,40 @@ * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj * XHTML-trans compliant * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> + * @author Kasper Skårhøj <kasperYYYY@typo3.com> */ - /** * Page functions, a lot of sql/pages-related functions * Mainly used in the frontend but also in some cases in the backend. * It's important to set the right $where_hid_del in the object so that the functions operate properly * - * @author Kasper Skårhøj <kasperYYYY@typo3.com> + * @author Kasper Skårhøj <kasperYYYY@typo3.com> * @package TYPO3 * @subpackage t3lib * @see tslib_fe::fetch_the_id() */ class t3lib_pageSelect { var $urltypes = Array('', 'http://', 'ftp://', 'mailto:', 'https://'); - var $where_hid_del = ' AND pages.deleted=0'; // 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 - var $where_groupAccess = ''; // Clause for fe_group access + // 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 + var $where_hid_del = ' AND pages.deleted=0'; + // Clause for fe_group access + var $where_groupAccess = ''; var $sys_language_uid = 0; // Versioning preview related: - 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 + // 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 $versioningPreview = FALSE; + // Workspace ID for preview + var $versioningWorkspaceId = 0; var $workspaceCache = array(); // Internal, dynamic: - var $error_getRootLine = ''; // Error string set by getRootLine() - var $error_getRootLine_failPid = 0; // Error uid set by getRootLine() + // Error string set by getRootLine() + var $error_getRootLine = ''; + // Error uid set by getRootLine() + var $error_getRootLine_failPid = 0; // Internal caching protected $cache_getRootLine = array(); @@ -92,8 +97,8 @@ class t3lib_pageSelect { * init() MUST be run directly after creating a new template-object * 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 * - * @param boolean If $show_hidden is TRUE, the hidden-field is ignored!! Normally this should be FALSE. Is used for previewing. - * @return void + * @param boolean $show_hidden If $show_hidden is TRUE, the hidden-field is ignored!! Normally this should be FALSE. Is used for previewing. + * @return void * @see tslib_fe::fetch_the_id(), tx_tstemplateanalyzer::initialize_editor() */ function init($show_hidden) { @@ -109,12 +114,13 @@ class t3lib_pageSelect { $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()) - $this->where_hid_del = ' AND pages.deleted=0 '; // Clear where_hid_del + // Copy where_hid_del to other variable (used in relation to versionOL()) + $this->versioningPreview_where_hid_del = $this->where_hid_del; + // Clear where_hid_del + $this->where_hid_del = ' AND pages.deleted=0 '; } } - /******************************************* * * Selecting page records @@ -126,9 +132,9 @@ class t3lib_pageSelect { * Any pages_language_overlay will be applied before the result is returned. * If no page is found an empty array is returned. * - * @param integer The page id to look up. - * @param boolean If set, the check for group access is disabled. VERY rarely used - * @return array The page row with overlayed localized fields. Empty it no page. + * @param integer $uid The page id to look up. + * @param boolean $disableGroupAccessCheck If set, the check for group access is disabled. VERY rarely used + * @return array The page row with overlayed localized fields. Empty it no page. * @see getPage_noCheck() */ function getPage($uid, $disableGroupAccessCheck = FALSE) { @@ -168,8 +174,8 @@ 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 array if no page. + * @param integer $uid The page id to look up + * @return array The page row with overlayed localized fields. Empty array if no page. * @see getPage() */ function getPage_noCheck($uid) { @@ -196,8 +202,8 @@ class t3lib_pageSelect { /** * Returns the $row of the first web-page in the tree (for the default menu...) * - * @param integer The page id for which to fetch first subpages (PID) - * @return mixed If found: The page record (with overlayed localized fields, if any). If NOT found: blank value (not array!) + * @param integer $uid The page id for which to fetch first subpages (PID) + * @return mixed If found: The page record (with overlayed localized fields, if any). If NOT found: blank value (not array!) * @see tslib_fe::fetch_the_id() */ function getFirstWebPage($uid) { @@ -217,8 +223,8 @@ class t3lib_pageSelect { /** * Returns a pagerow for the page with alias $alias * - * @param string The alias to look up the page uid for. - * @return integer Returns page uid (integer) if found, otherwise 0 (zero) + * @param string $alias The alias to look up the page uid for. + * @return integer Returns page uid (integer) if found, otherwise 0 (zero) * @see tslib_fe::checkAndSetAlias(), tslib_cObj::typoLink() */ function getPageIdFromAlias($alias) { @@ -240,9 +246,9 @@ class t3lib_pageSelect { /** * Returns the relevant page overlay record fields * - * @param mixed 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. - * @param integer Language UID if you want to set an alternative value to $this->sys_language_uid which is default. Should be >=0 - * @return array Page row which is overlayed with language_overlay record (or the overlay record alone) + * @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. + * @param integer $lUid Language UID if you want to set an alternative value to $this->sys_language_uid which is default. Should be >=0 + * @return array Page row which is overlayed with language_overlay record (or the overlay record alone) */ function getPageOverlay($pageInput, $lUid = -1) { @@ -268,18 +274,19 @@ class t3lib_pageSelect { if ($lUid) { $fieldArr = t3lib_div::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']); if (is_array($pageInput)) { - $page_id = $pageInput['uid']; // Was the whole record - $fieldArr = array_intersect($fieldArr, array_keys($pageInput)); // Make sure that only fields which exist in the incoming record are overlaid! + // Was the whole record + $page_id = $pageInput['uid']; + // Make sure that only fields which exist in the incoming record are overlaid! + $fieldArr = array_intersect($fieldArr, array_keys($pageInput)); } else { - $page_id = $pageInput; // Was the id + // Was the id + $page_id = $pageInput; } if (count($fieldArr)) { - /* - NOTE to enabledFields('pages_language_overlay'): - Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page. - However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now. - */ + // NOTE to enabledFields('pages_language_overlay'): + // Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page. + // However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now. // Selecting overlay record: $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( @@ -309,20 +316,22 @@ class t3lib_pageSelect { // Create output: if (is_array($pageInput)) { - return is_array($row) ? array_merge($pageInput, $row) : $pageInput; // If the input was an array, simply overlay the newfound array and return... + // If the input was an array, simply overlay the newfound array and return... + return is_array($row) ? array_merge($pageInput, $row) : $pageInput; } else { - return is_array($row) ? $row : array(); // always an array in return + // Always an array in return + return is_array($row) ? $row : array(); } } /** * Creates language-overlay for records in general (where translation is found in records from the same table) * - * @param string Table name - * @param array Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField'] - * @param integer Pointer to the sys_language uid for content on the site. - * @param string Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE) - * @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. + * @param string $table Table name + * @param array $row Record to overlay. Must containt uid, pid and $table]['ctrl']['languageField'] + * @param integer $sys_language_content Pointer to the sys_language uid for content on the site. + * @param string $OLmode Overlay mode. If "hideNonTranslated" then records without translation will not be returned un-translated but unset (and return value is FALSE) + * @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. */ function getRecordOverlay($table, $row, $sys_language_content, $OLmode = '') { if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getRecordOverlay'])) { @@ -418,7 +427,6 @@ class t3lib_pageSelect { return $row; } - /******************************************* * * Page related: Menu, Domain record, Root line @@ -430,15 +438,15 @@ class t3lib_pageSelect { * If there are mount points in overlay mode the _MP_PARAM field is set to the corret MPvar. * If the $uid being input does in itself require MPvars to define a correct rootline these must be handled externally to this function. * - * @param integer The page id for which to fetch subpages (PID) - * @param string List of fields to select. Default is "*" = all - * @param string The field to sort by. Default is "sorting" - * @param string Optional additional where clauses. Like "AND title like '%blabla%'" for instance. - * @param boolean check if shortcuts exist, checks by default - * @return array Array with key/value pairs; keys are page-uid numbers. values are the corresponding page records (with overlayed localized fields, if any) + * @param integer $uid The page id for which to fetch subpages (PID) + * @param string $fields List of fields to select. Default is "*" = all + * @param string $sortField The field to sort by. Default is "sorting" + * @param string $addWhere Optional additional where clauses. Like "AND title like '%blabla%'" for instance. + * @param boolean $checkShortcuts Check if shortcuts exist, checks by default + * @return array Array with key/value pairs; keys are page-uid numbers. values are the corresponding page records (with overlayed localized fields, if any) * @see tslib_fe::getPageShortcut(), tslib_menu::makeMenu(), tx_wizardcrpages_webfunc_2, tx_wizardsortpages_webfunc_2 */ - function getMenu($uid, $fields = '*', $sortField = 'sorting', $addWhere = '', $checkShortcuts = 1) { + function getMenu($uid, $fields = '*', $sortField = 'sorting', $addWhere = '', $checkShortcuts = TRUE) { $output = Array(); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', 'pid=' . intval($uid) . $this->where_hid_del . $this->where_groupAccess . ' ' . $addWhere, '', $sortField); @@ -447,9 +455,12 @@ class t3lib_pageSelect { if (is_array($row)) { // Keep mount point: $origUid = $row['uid']; - $mount_info = $this->getMountPointInfo($origUid, $row); // $row MUST have "uid", "pid", "doktype", "mount_pid", "mount_pid_ol" fields in it - if (is_array($mount_info) && $mount_info['overlay']) { // There is a valid mount point. - $mp_row = $this->getPage($mount_info['mount_pid']); // Using "getPage" is OK since we need the check for enableFields AND for type 2 of mount pids we DO require a doktype < 200! + // $row MUST have "uid", "pid", "doktype", "mount_pid", "mount_pid_ol" fields in it + $mount_info = $this->getMountPointInfo($origUid, $row); + // There is a valid mount point. + if (is_array($mount_info) && $mount_info['overlay']) { + // Using "getPage" is OK since we need the check for enableFields AND for type 2 of mount pids we DO require a doktype < 200! + $mp_row = $this->getPage($mount_info['mount_pid']); if (count($mp_row)) { $row = $mp_row; $row['_MP_PARAM'] = $mount_info['MPvar']; @@ -458,19 +469,19 @@ class t3lib_pageSelect { } // 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! } - // if shortcut, look up if the target exists and is currently visible + // If shortcut, look up if the target exists and is currently visible if ($row['doktype'] == t3lib_pageSelect::DOKTYPE_SHORTCUT && ($row['shortcut'] || $row['shortcut_mode']) && $checkShortcuts) { if ($row['shortcut_mode'] == self::SHORTCUT_MODE_NONE) { - // no shortcut_mode set, so target is directly set in $row['shortcut'] + // No shortcut_mode set, so target is directly set in $row['shortcut'] $searchField = 'uid'; $searchUid = intval($row['shortcut']); } elseif ($row['shortcut_mode'] == self::SHORTCUT_MODE_FIRST_SUBPAGE || $row['shortcut_mode'] == self::SHORTCUT_MODE_RANDOM_SUBPAGE) { - // check subpages - first subpage or random subpage + // Check subpages - first subpage or random subpage $searchField = 'pid'; // 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']; } elseif ($row['shortcut_mode'] == self::SHORTCUT_MODE_PARENT_PAGE) { - // shortcut to parent page + // Shortcut to parent page $searchField = 'uid'; $searchUid = $row['pid']; } @@ -504,10 +515,10 @@ class t3lib_pageSelect { * Will find the page carrying the domain record matching the input domain. * Might exit after sending a redirect-header IF a found domain record instructs to do so. * - * @param string Domain name to search for. Eg. "www.typo3.com". Typical the HTTP_HOST value. - * @param string Path for the current script in domain. Eg. "/somedir/subdir". Typ. supplied by t3lib_div::getIndpEnv('SCRIPT_NAME') - * @param string Request URI: Used to get parameters from if they should be appended. Typ. supplied by t3lib_div::getIndpEnv('REQUEST_URI') - * @return mixed If found, returns integer with page UID where found. Otherwise blank. Might exit if location-header is sent, see description. + * @param string $domain Domain name to search for. Eg. "www.typo3.com". Typical the HTTP_HOST value. + * @param string $path Path for the current script in domain. Eg. "/somedir/subdir". Typ. supplied by t3lib_div::getIndpEnv('SCRIPT_NAME') + * @param string $request_uri Request URI: Used to get parameters from if they should be appended. Typ. supplied by t3lib_div::getIndpEnv('REQUEST_URI') + * @return mixed If found, returns integer with page UID where found. Otherwise blank. Might exit if location-header is sent, see description. * @see tslib_fe::findDomainRecord() */ function getDomainStartPage($domain, $path = '', $request_uri = '') { @@ -560,10 +571,10 @@ class t3lib_pageSelect { * Further: If any "recycler" page is found (doktype=255) then it will also block for the rootline) * 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'] * - * @param integer The page uid for which to seek back to the page tree root. - * @param string Commalist of MountPoint parameters, eg. "1-2,3-4" etc. Normally this value comes from the GET var, MP - * @param boolean If set, some errors related to Mount Points in root line are ignored. - * @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. + * @param integer $uid The page uid for which to seek back to the page tree root. + * @param string $MP Commalist of MountPoint parameters, eg. "1-2,3-4" etc. Normally this value comes from the GET var, MP + * @param boolean $ignoreMPerrors If set, some errors related to Mount Points in root line are ignored. + * @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) { @@ -589,9 +600,10 @@ class t3lib_pageSelect { } $loopCheck = 0; - $theRowArray = Array(); + $theRowArray = array(); - while ($uid != 0 && $loopCheck < 99) { // Max 99 levels in the page tree. + // Max 99 levels in the page tree. + while ($uid != 0 && $loopCheck < 99) { $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid=' . intval($uid) . ' AND pages.deleted=0 AND pages.doktype<>255'); $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $GLOBALS['TYPO3_DB']->sql_free_result($res); @@ -609,7 +621,8 @@ class t3lib_pageSelect { } } - $uid = $row['pid']; // Next uid + // Next uid + $uid = $row['pid']; if (count($MPA) && $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids']) { $curMP = end($MPA); @@ -626,10 +639,13 @@ class t3lib_pageSelect { if (is_array($mp_row)) { $mount_info = $this->getMountPointInfo($mp_row['uid'], $mp_row); if (is_array($mount_info) && $mount_info['mount_pid'] == $curMP[0]) { - $uid = $mp_row['pid']; // Setting next uid + // Setting next uid + $uid = $mp_row['pid']; - if ($mount_info['overlay']) { // Symlink style: Keep mount point (current row). - $row['_MOUNT_OL'] = TRUE; // Set overlay mode: + // Symlink style: Keep mount point (current row). + if ($mount_info['overlay']) { + // Set overlay mode: + $row['_MOUNT_OL'] = TRUE; $row['_MOUNT_PAGE'] = array( 'uid' => $mp_row['uid'], 'pid' => $mp_row['pid'], @@ -640,7 +656,8 @@ class t3lib_pageSelect { $row = $mp_row; } else { $this->error_getRootLine = 'Current Page Id is a mounted page of the overlay type and cannot be accessed directly!'; - return array(); // Matching the page id (first run, $loopCheck = 0) with the MPvar is ONLY allowed if the mount point is the "overlay" type (otherwise it could be forged!) + // Matching the page id (first run, $loopCheck = 0) with the MPvar is ONLY allowed if the mount point is the "overlay" type (otherwise it could be forged!) + return array(); } } @@ -648,11 +665,13 @@ class t3lib_pageSelect { $row['_MP_PARAM'] = $mount_info['MPvar']; } else { $this->error_getRootLine = 'MP var was corrupted'; - return array(); // The MP variables did NOT connect proper mount points: + // The MP variables did NOT connect proper mount points: + return array(); } } else { $this->error_getRootLine = 'No moint point record found according to PID in MP var'; - return array(); // The second PID in MP var was NOT a valid page. + // The second PID in MP var was NOT a valid page. + return array(); } } } @@ -662,7 +681,8 @@ class t3lib_pageSelect { } else { $this->error_getRootLine = 'Broken rootline (failed on page with uid ' . $uid . ')'; $this->error_getRootLine_failPid = $uid; - return array(); // broken rootline. + // Broken rootline. + return array(); } $loopCheck++; @@ -691,9 +711,9 @@ class t3lib_pageSelect { * Creates a "path" string for the input root line array titles. * Used for writing statistics. * - * @param array A rootline array! - * @param integer The max length of each title from the rootline. - * @return string The path in the form "/page title/This is another pageti.../Another page" + * @param array $rl A rootline array! + * @param integer $len The max length of each title from the rootline. + * @return string The path in the form "/page title/This is another pageti.../Another page" * @see tslib_fe::getConfigArray() */ function getPathFromRootline($rl, $len = 20) { @@ -712,9 +732,9 @@ class t3lib_pageSelect { /** * Returns the URL type for the input page row IF the doktype is 3 and not disabled. * - * @param array The page row to return URL type for - * @param boolean A flag to simply disable any output from here. - * @return string The URL type from $this->urltypes array. False if not found or disabled. + * @param array $pagerow The page row to return URL type for + * @param boolean $disable A flag to simply disable any output from here. + * @return string The URL type from $this->urltypes array. False if not found or disabled. * @see tslib_fe::setExternalJumpUrl() */ function getExtURL($pagerow, $disable = 0) { @@ -723,7 +743,8 @@ class t3lib_pageSelect { // If relative path, prefix Site URL: $uI = parse_url($redirectTo); - if (!$uI['scheme'] && substr($redirectTo, 0, 1) != '/') { // relative path assumed now... + // Relative path assumed now. + if (!$uI['scheme'] && substr($redirectTo, 0, 1) != '/') { $redirectTo = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $redirectTo; } return $redirectTo; @@ -734,11 +755,11 @@ class t3lib_pageSelect { * Returns MountPoint id for page * 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. * - * @param integer 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...) - * @param array 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 - * @param array Array accumulating formerly tested page ids for mount points. Used for recursivity brake. - * @param integer The first page id. - * @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. + * @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...) + * @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 + * @param array $prevMountPids Array accumulating formerly tested page ids for mount points. Used for recursivity brake. + * @param integer $firstPageUid The first page id. + * @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. * @see tslib_menu */ function getMountPointInfo($pageId, $pageRec = FALSE, $prevMountPids = array(), $firstPageUid = 0) { @@ -755,7 +776,8 @@ class t3lib_pageSelect { $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'); $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); $GLOBALS['TYPO3_DB']->sql_free_result($res); - $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! + // Only look for version overlay if page record is not supplied; This assumes that the input record is overlaid with preview version, if any! + $this->versionOL('pages', $pageRec); } // Set first Page uid: @@ -789,7 +811,8 @@ class t3lib_pageSelect { 'mount_pid_rec' => $mountRec, ); } else { - $result = -1; // Means, there SHOULD have been a mount point, but there was none! + // Means, there SHOULD have been a mount point, but there was none! + $result = -1; } } } @@ -798,7 +821,6 @@ class t3lib_pageSelect { return $result; } - /********************************* * * Selecting records in general @@ -809,10 +831,10 @@ class t3lib_pageSelect { * Checks if a record exists and is accessible. * The row is returned if everything's OK. * - * @param string The table name to search - * @param integer The uid to look up in $table - * @param boolean If checkPage is set, it's also required that the page on which the record resides is accessible - * @return mixed Returns array (the record) if OK, otherwise blank/0 (zero) + * @param string $table The table name to search + * @param integer $uid The uid to look up in $table + * @param boolean $checkPage If checkPage is set, it's also required that the page on which the record resides is accessible + * @return mixed Returns array (the record) if OK, otherwise blank/0 (zero) */ function checkRecord($table, $uid, $checkPage = 0) { $uid = intval($uid); @@ -843,11 +865,11 @@ class t3lib_pageSelect { /** * Returns record no matter what - except if record is deleted * - * @param string The table name to search - * @param integer The uid to look up in $table - * @param string The fields to select, default is "*" - * @param boolean If set, no version overlay is applied - * @return mixed Returns array (the record) if found, otherwise blank/0 (zero) + * @param string $table The table name to search + * @param integer $uid The uid to look up in $table + * @param string $fields The fields to select, default is "*" + * @param boolean $noWSOL If set, no version overlay is applied + * @return mixed Returns array (the record) if found, otherwise blank/0 (zero) * @see getPage_noCheck() */ function getRawRecord($table, $uid, $fields = '*', $noWSOL = FALSE) { @@ -871,14 +893,14 @@ class t3lib_pageSelect { /** * Selects records based on matching a field (ei. other than UID) with a value * - * @param string The table name to search, eg. "pages" or "tt_content" - * @param string The fieldname to match, eg. "uid" or "alias" - * @param string The value that fieldname must match, eg. "123" or "frontpage" - * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! - * @param string Optional GROUP BY field(s), if none, supply blank string. - * @param string Optional ORDER BY field(s), if none, supply blank string. - * @param string Optional LIMIT value ([begin,]max), if none, supply blank string. - * @return mixed Returns array (the record) if found, otherwise nothing (void) + * @param string $theTable The table name to search, eg. "pages" or "tt_content" + * @param string $theField The fieldname to match, eg. "uid" or "alias" + * @param string $theValue The value that fieldname must match, eg. "123" or "frontpage" + * @param string $whereClause Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! + * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string. + * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string. + * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string. + * @return mixed Returns array (the record) if found, otherwise nothing (void) */ function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') { if (is_array($GLOBALS['TCA'][$theTable])) { @@ -894,7 +916,6 @@ class t3lib_pageSelect { ); $rows = array(); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { - #$this->versionOL($theTable,$row); // not used since records here are fetched based on other fields than uid! if (is_array($row)) { $rows[] = $row; } @@ -906,7 +927,6 @@ class t3lib_pageSelect { } } - /********************************* * * Caching and standard clauses @@ -920,8 +940,8 @@ class t3lib_pageSelect { * store the parsed TypoScript template structures. You can call it directly * like t3lib_pageSelect::getHash() * - * @param string The hash-string which was used to store the data value - * @return string The "content" field of the "cache_hash" cache entry. + * @param string $hash The hash-string which was used to store the data value + * @return string The "content" field of the "cache_hash" cache entry. * @see tslib_TStemplate::start(), storeHash() */ public static function getHash($hash, $expTime = 0) { @@ -944,11 +964,11 @@ class t3lib_pageSelect { * 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! - * @param integer The lifetime for the cache entry in seconds - * @return void + * @param string $hash 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored) + * @param string $data 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! + * @param integer $lifetime The lifetime for the cache entry in seconds + * @return void * @see tslib_TStemplate::start(), getHash() */ public static function storeHash($hash, $data, $ident, $lifetime = 0) { @@ -965,12 +985,13 @@ class t3lib_pageSelect { /** * Returns the "AND NOT deleted" clause for the tablename given IF $GLOBALS['TCA'] configuration points to such a field. * - * @param string Tablename - * @return string + * @param string $table Tablename + * @return string * @see enableFields() */ function deleteClause($table) { - if (!strcmp($table, 'pages')) { // Hardcode for pages because TCA might not be loaded yet (early frontend initialization) + // Hardcode for pages because TCA might not be loaded yet (early frontend initialization) + if (!strcmp($table, 'pages')) { return ' AND pages.deleted=0'; } else { return $GLOBALS['TCA'][$table]['ctrl']['delete'] ? ' AND ' . $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0' : ''; @@ -981,11 +1002,11 @@ class t3lib_pageSelect { * 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. * Is using the $GLOBALS['TCA'] arrays "ctrl" part where the key "enablefields" determines for each table which of these features applies to that table. * - * @param string Table name found in the $GLOBALS['TCA'] array - * @param integer 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. - * @param 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. - * @param boolean If set, enableFields will be applied regardless of any versioning preview settings which might otherwise disable enableFields - * @return string The clause starting like " AND ...=... AND ...=..." + * @param string $table Table name found in the $GLOBALS['TCA'] array + * @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. + * @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. + * @param boolean $noVersionPreview If set, enableFields will be applied regardless of any versioning preview settings which might otherwise disable enableFields + * @return string The clause starting like " AND ...=... AND ...=..." * @see tslib_cObj::enableFields(), deleteClause() */ function enableFields($table, $show_hidden = -1, $ignore_array = array(), $noVersionPreview = FALSE) { @@ -1007,12 +1028,14 @@ class t3lib_pageSelect { // Filter out new place-holder records in case we are NOT in a versioning preview (that means we are online!) if ($ctrl['versioningWS'] && !$this->versioningPreview) { - $query .= ' AND ' . $table . '.t3ver_state<=0 AND ' . $table . '.pid<>-1'; // Shadow state for new items MUST be ignored! + // Shadow state for new items MUST be ignored! + $query .= ' AND ' . $table . '.t3ver_state<=0 AND ' . $table . '.pid<>-1'; } // Enable fields: if (is_array($ctrl['enablecolumns'])) { - if (!$this->versioningPreview || !$ctrl['versioningWS'] || $noVersionPreview) { // In case of versioning-preview, enableFields are ignored (checked in versionOL()) + // In case of versioning-preview, enableFields are ignored (checked in versionOL()) + if (!$this->versioningPreview || !$ctrl['versioningWS'] || $noVersionPreview) { if ($ctrl['enablecolumns']['disabled'] && !$show_hidden && !$ignore_array['disabled']) { $field = $table . '.' . $ctrl['enablecolumns']['disabled']; $query .= ' AND ' . $field . '=0'; @@ -1060,17 +1083,20 @@ class t3lib_pageSelect { /** * Creating where-clause for checking group access to elements in enableFields function * - * @param string Field with group list - * @param string Table name - * @return string AND sql-clause + * @param string $field Field with group list + * @param string $table Table name + * @return string AND sql-clause * @see enableFields() */ function getMultipleGroupsWhereClause($field, $table) { $memberGroups = t3lib_div::intExplode(',', $GLOBALS['TSFE']->gr_list); $orChecks = array(); - $orChecks[] = $field . '=\'\''; // If the field is empty, then OK - $orChecks[] = $field . ' IS NULL'; // If the field is NULL, then OK - $orChecks[] = $field . '=\'0\''; // If the field contsains zero, then OK + // If the field is empty, then OK + $orChecks[] = $field . '=\'\''; + // If the field is NULL, then OK + $orChecks[] = $field . ' IS NULL'; + // If the field contsains zero, then OK + $orChecks[] = $field . '=\'0\''; foreach ($memberGroups as $value) { $orChecks[] = $GLOBALS['TYPO3_DB']->listQuery($field, $value, $table); @@ -1079,7 +1105,6 @@ class t3lib_pageSelect { return ' AND (' . implode(' OR ', $orChecks) . ')'; } - /********************************* * * Versioning Preview @@ -1093,9 +1118,9 @@ class t3lib_pageSelect { * Used whenever you are tracking something back, like making the root line. * Principle; Record offline! => Find online? * - * @param string Table name - * @param array 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. - * @return void (Passed by ref). + * @param string $table Table name + * @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. + * @return void (Passed by ref). * @see t3lib_BEfunc::fixVersioningPid(), versionOL(), getRootLine() */ function fixVersioningPid($table, &$rr) { @@ -1120,14 +1145,15 @@ class t3lib_pageSelect { $oidRec = $this->getRawRecord($table, $oid, 'pid', TRUE); if (is_array($oidRec)) { - # 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()). However if the page is NOT a branch version it should not happen - but then again, direct access to that uid should not happen! + // 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()). + // However if the page is NOT a branch version it should not happen - but then again, direct access to that uid should not happen! $rr['_ORIG_pid'] = $rr['pid']; $rr['pid'] = $oidRec['pid']; } } } - // changing PID in case of moving pointer: + // Changing PID in case of moving pointer: if ($movePlhRec = $this->getMovePlaceholder($table, $rr['uid'], 'pid')) { $rr['pid'] = $movePlhRec['pid']; } @@ -1139,21 +1165,25 @@ class t3lib_pageSelect { * 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. * Principle; Record online! => Find offline? * - * @param string Table name - * @param array 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! - * @param boolean 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) - * @param boolean 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! - * @return void (Passed by ref). + * @param string $table Table name + * @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! + * @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) + * @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! + * @return void (Passed by ref). * @see fixVersioningPid(), t3lib_BEfunc::workspaceOL() */ function versionOL($table, &$row, $unsetMovePointers = FALSE, $bypassEnableFieldsCheck = FALSE) { if ($this->versioningPreview && is_array($row)) { - $movePldSwap = $this->movePlhOL($table, $row); // will overlay any movePlhOL found with the real record, which in turn will be overlaid with its workspace version if any. - if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, $table, $row['uid'], implode(',', array_keys($row)), $bypassEnableFieldsCheck)) { // implode(',',array_keys($row)) = Using fields from original record to make sure no additional fields are selected. This is best for eg. getPageOverlay() + // will overlay any movePlhOL found with the real record, which in turn will be overlaid with its workspace version if any. + $movePldSwap = $this->movePlhOL($table, $row); + // implode(',',array_keys($row)) = Using fields from original record to make sure no additional fields are selected. This is best for eg. getPageOverlay() + if ($wsAlt = $this->getWorkspaceVersionOfRecord($this->versioningWorkspaceId, $table, $row['uid'], implode(',', array_keys($row)), $bypassEnableFieldsCheck)) { if (is_array($wsAlt)) { // Always fix PID (like in fixVersioningPid() above). [This is usually not the important factor for versioning OL] - $wsAlt['_ORIG_pid'] = $wsAlt['pid']; // Keep the old (-1) - indicates it was a version... - $wsAlt['pid'] = $row['pid']; // Set in the online versions PID. + // Keep the old (-1) - indicates it was a version... + $wsAlt['_ORIG_pid'] = $wsAlt['pid']; + // Set in the online versions PID. + $wsAlt['pid'] = $row['pid']; // For versions of single elements or page+content, preserve online UID and PID (this will produce true "overlay" of element _content_, not any references) // For page+content the "_ORIG_uid" should actually be used as PID for selection of tables with "versioning_followPages" enabled. @@ -1170,19 +1200,22 @@ class t3lib_pageSelect { // Check if it is deleted/new if ((int) $row['t3ver_state'] === 1 || (int) $row['t3ver_state'] === 2) { - $row = FALSE; // Unset record if it turned out to be deleted in workspace + // Unset record if it turned out to be deleted in workspace + $row = FALSE; } // Check if move-pointer in workspace (unless if a move-placeholder is the reason why it appears!): // 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. if ((int) $row['t3ver_state'] === 4 && !$movePldSwap && $unsetMovePointers) { - $row = FALSE; // Unset record if it turned out to be deleted in workspace + // Unset record if it turned out to be deleted in workspace + $row = FALSE; } } else { // No version found, then check if t3ver_state =1 (online version is dummy-representation) // 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 if ($wsAlt <= -1 || (int) $row['t3ver_state'] > 0) { - $row = FALSE; // Unset record if it turned out to be "hidden" + // Unset record if it turned out to be "hidden" + $row = FALSE; } } } @@ -1193,9 +1226,9 @@ class t3lib_pageSelect { * 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) * Used from versionOL * - * @param string Table name - * @param array Row (passed by reference) - only online records... - * @return boolean TRUE if overlay is made. + * @param string $table Table name + * @param array $row Row (passed by reference) - only online records... + * @return boolean TRUE if overlay is made. * @see t3lib_BEfunc::movePlhOl() */ function movePlhOL($table, &$row) { @@ -1227,10 +1260,10 @@ class t3lib_pageSelect { /** * Returns move placeholder of online (live) version * - * @param string Table name - * @param integer Record UID of online version - * @param string Field list, default is * - * @return array If found, the record, otherwise nothing. + * @param string $table Table name + * @param integer $uid Record UID of online version + * @param string $fields Field list, default is * + * @return array If found, the record, otherwise nothing. * @see t3lib_BEfunc::getMovePlaceholder() */ function getMovePlaceholder($table, $uid, $fields = '*') { @@ -1260,12 +1293,12 @@ class t3lib_pageSelect { /** * Select the version of a record for a workspace * - * @param integer Workspace ID - * @param string Table name to select from - * @param integer Record uid for which to find workspace version. - * @param string Field list to select - * @param boolean If TRUE, enablefields are not checked for. - * @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. + * @param integer $workspace Workspace ID + * @param string $table Table name to select from + * @param integer $uid Record uid for which to find workspace version. + * @param string $fields Field list to select + * @param boolean $bypassEnableFieldsCheck If TRUE, enablefields are not checked for. + * @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. * @see t3lib_befunc::getWorkspaceVersionOfRecord() */ function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields = '*', $bypassEnableFieldsCheck = FALSE) { @@ -1299,9 +1332,11 @@ class t3lib_pageSelect { t3ver_wsid=' . intval($workspace) . $enFields )) { - return $newrow; // Return offline version, tested for its enableFields. + // Return offline version, tested for its enableFields. + return $newrow; } else { - return -1; // Return -1 because offline version was de-selected due to its enableFields. + // Return -1 because offline version was de-selected due to its enableFields. + return -1; } } else { // OK, so no workspace version was found. Then check if online version can be selected with full enable fields and if so, return 1: @@ -1310,21 +1345,24 @@ class t3lib_pageSelect { $table, 'uid=' . intval($uid) . $enFields )) { - return 1; // Means search was done, but no version found. + // Means search was done, but no version found. + return 1; } else { - return -2; // Return -2 because the online record was de-selected due to its enableFields. + // Return -2 because the online record was de-selected due to its enableFields. + return -2; } } } - return FALSE; // No look up in database because versioning not enabled / or workspace not offline + // No look up in database because versioning not enabled / or workspace not offline + return FALSE; } /** * Checks if user has access to workspace. * - * @param int $wsid Workspace ID - * @return boolean <code>TRUE</code> if has access + * @param integer $wsid Workspace ID + * @return boolean <code>TRUE</code> if has access */ function checkWorkspaceAccess($wsid) { if (!$GLOBALS['BE_USER'] || !t3lib_extMgm::isLoaded('workspaces')) { @@ -1351,4 +1389,4 @@ class t3lib_pageSelect { } } -?> +?> \ No newline at end of file