Documentation TYPO3 par Ameos

class.t3lib_page.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00107 class t3lib_pageSelect {
00108         var $urltypes = Array('','http://','ftp://','mailto:');
00109         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
00110         var $where_groupAccess = '';    // Clause for fe_group access
00111         var $sys_language_uid = 0;
00112 
00113                 // Versioning preview related:
00114         var $versioningPreview = FALSE;         // If true, preview of other record versions is allowed. THIS MUST ONLY BE SET IF the page is not cached and truely previewed by a backend user!!!
00115         var $versionPreviewMap = array(
00116 # EXAMPLE:              'tt_content:421' => 427
00117         );
00118 
00119 
00120                 // Internal, dynamic:
00121         var $error_getRootLine = '';            // Error string set by getRootLine()
00122         var $error_getRootLine_failPid = 0;             // Error uid set by getRootLine()
00123 
00124 
00133         function init($show_hidden)     {
00134                 $this->where_groupAccess = '';
00135                 $this->where_hid_del = ' AND pages.deleted=0 ';
00136                 if (!$show_hidden)      {
00137                         $this->where_hid_del.= 'AND pages.hidden=0 ';
00138                 }
00139                 $this->where_hid_del.= 'AND (pages.starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (pages.endtime=0 OR pages.endtime>'.$GLOBALS['SIM_EXEC_TIME'].') ';
00140         }
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158         /*******************************************
00159          *
00160          * Selecting page records
00161          *
00162          ******************************************/
00163 
00174         function getPage($uid, $disableGroupAccessCheck=FALSE)  {
00175                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->where_hid_del.($disableGroupAccessCheck ? '' : $this->where_groupAccess));
00176                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00177 #??                     $this->versionOL('pages',$row);
00178                         return $this->getPageOverlay($row);
00179                 }
00180                 return Array();
00181         }
00182 
00190         function getPage_noCheck($uid)  {
00191                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->deleteClause('pages'));
00192                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00193 #??                     $this->versionOL('pages',$row);
00194                         return $this->getPageOverlay($row);
00195                 }
00196                 return Array();
00197         }
00198 
00206         function getFirstWebPage($uid)  {
00207                 $output = '';
00208                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($uid).$this->where_hid_del.$this->where_groupAccess, '', 'sorting', '1');
00209                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00210 #??                     $this->versionOL('pages',$row);
00211                         $output = $this->getPageOverlay($row);
00212                 }
00213                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00214                 return $output;
00215         }
00216 
00224         function getPageIdFromAlias($alias)     {
00225                 $alias = strtolower($alias);
00226                 $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" is because of versioning...
00227                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00228                         return $row['uid'];
00229                 }
00230                 return 0;
00231         }
00232 
00240         function getPageOverlay($pageInput,$lUid=-1)    {
00241 
00242                         // Initialize:
00243                 if ($lUid<0)    $lUid = $this->sys_language_uid;
00244                 unset($row);
00245 
00246                         // If language UID is different from zero, do overlay:
00247                 if ($lUid)      {
00248                         $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
00249                         if (is_array($pageInput))       {
00250                                 $page_id = $pageInput['uid'];   // Was the whole record
00251                                 $fieldArr = array_intersect($fieldArr,array_keys($pageInput));          // Make sure that only fields which exist in the incoming record are overlaid!
00252                         } else {
00253                                 $page_id = $pageInput;  // Was the id
00254                         }
00255 
00256                         if (count($fieldArr))   {
00257                                 /*
00258                                         NOTE to enabledFields('pages_language_overlay'):
00259                                         Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page.
00260                                         However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now.
00261                                 */
00262 
00263                                         // Selecting overlay record:
00264                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00265                                                         implode(',',$fieldArr),
00266                                                         'pages_language_overlay',
00267                                                         'pid='.intval($page_id).'
00268                                                                 AND sys_language_uid='.intval($lUid).
00269                                                                 $this->enableFields('pages_language_overlay'),
00270                                                         '',
00271                                                         '',
00272                                                         '1'
00273                                                 );
00274                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00275                                 if (is_array($row))     {
00276                                         $row['_PAGES_OVERLAY'] = TRUE;
00277                                         $this->versionOL('pages_language_overlay',$row);
00278 
00279                                                 // Unset vital fields that are NOT allowed to be overlaid:
00280                                         unset($row['uid']);
00281                                         unset($row['pid']);
00282                                 }
00283                         }
00284                 }
00285 
00286                         // Create output:
00287                 if (is_array($pageInput))       {
00288                         return is_array($row) ? array_merge($pageInput,$row) : $pageInput;      // If the input was an array, simply overlay the newfound array and return...
00289                 } else {
00290                         return is_array($row) ? $row : array(); // always an array in return
00291                 }
00292         }
00293 
00303         function getRecordOverlay($table,$row,$sys_language_content,$OLmode='') {
00304                 global $TCA;
00305 
00306                 if ($row['uid']>0 && $row['pid']>0)     {
00307                         if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])     {
00308                                 if (!$TCA[$table]['ctrl']['transOrigPointerTable'])     {       // Will not be able to work with other tables (Just didn't implement it yet; Requires a scan over all tables [ctrl] part for first FIND the table that carries localization information for this table (which could even be more than a single table) and then use that. Could be implemented, but obviously takes a little more....)
00309 
00310                                                 // Will try to overlay a record only if the sys_language_content value is larger that zero.
00311                                         if ($sys_language_content>0)    {
00312 
00313                                                         // Must be default language or [All], otherwise no overlaying:
00314                                                 if ($row[$TCA[$table]['ctrl']['languageField']]<=0)     {
00315 
00316                                                                 // Select overlay record:
00317                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00318                                                                                 '*',
00319                                                                                 $table,
00320                                                                                 'pid='.intval($row['pid']).
00321                                                                                         ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sys_language_content).
00322                                                                                         ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
00323                                                                                         $this->enableFields($table),
00324                                                                                 '',
00325                                                                                 '',
00326                                                                                 '1'
00327                                                                         );
00328                                                         $olrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00329                                                         $this->versionOL($table,$olrow);
00330         #debug($row);
00331         #debug($olrow);
00332                                                                 // Merge record content by traversing all fields:
00333                                                         if (is_array($olrow))   {
00334                                                                 foreach($row as $fN => $fV)     {
00335                                                                         if ($fN!='uid' && $fN!='pid' && isset($olrow[$fN]))     {
00336 
00337                                                                                 if ($GLOBALS['TSFE']->TCAcachedExtras[$table]['l10n_mode'][$fN]!='exclude'
00338                                                                                                 && ($GLOBALS['TSFE']->TCAcachedExtras[$table]['l10n_mode'][$fN]!='mergeIfNotBlank' || strcmp(trim($olrow[$fN]),'')))    {
00339                                                                                         $row[$fN] = $olrow[$fN];
00340                                                                                 }
00341                                                                         }
00342                                                                 }
00343                                                         } elseif ($OLmode==='hideNonTranslated' && $row[$TCA[$table]['ctrl']['languageField']]==0)      {       // Unset, if non-translated records should be hidden. ONLY done if the source record really is default language and not [All] in which case it is allowed.
00344                                                                 unset($row);
00345                                                         }
00346 
00347                                                         // 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.
00348                                                 } elseif ($sys_language_content!=$row[$TCA[$table]['ctrl']['languageField']])   {
00349                                                         unset($row);
00350                                                 }
00351                                         } else {
00352                                                         // When default language is displayed, we never want to return a record carrying another language!:
00353                                                 if ($row[$TCA[$table]['ctrl']['languageField']]>0)      {
00354                                                         unset($row);
00355                                                 }
00356                                         }
00357                                 }
00358                         }
00359                 }
00360 
00361                 return $row;
00362         }
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381         /*******************************************
00382          *
00383          * Page related: Menu, Domain record, Root line
00384          *
00385          ******************************************/
00386 
00399         function getMenu($uid,$fields='*',$sortField='sorting',$addWhere='')    {
00400                 $output = Array();
00401                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', 'pid='.intval($uid).$this->where_hid_del.$this->where_groupAccess.' '.$addWhere, '', $sortField);
00402                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00403 #??                     $this->versionOL('pages',$row);
00404 
00405                                 // Keep mount point:
00406                         $origUid = $row['uid'];
00407                         $mount_info = $this->getMountPointInfo($origUid, $row); // $row MUST have "uid", "pid", "doktype", "mount_pid", "mount_pid_ol" fields in it
00408                         if (is_array($mount_info) && $mount_info['overlay'])    {       // There is a valid mount point.
00409                                 $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!
00410                                 if (count($mp_row))     {
00411                                         $row = $mp_row;
00412                                         $row['_MP_PARAM'] = $mount_info['MPvar'];
00413                                 } else unset($row);     // 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!
00414                         }
00415 
00416                                 // Add to output array after overlaying language:
00417                         if (is_array($row))     {
00418                                 $output[$origUid] = $this->getPageOverlay($row);
00419                         }
00420                 }
00421                 return $output;
00422         }
00423 
00434         function getDomainStartPage($domain, $path='',$request_uri='')  {
00435                 $domain = explode(':',$domain);
00436                 $domain = strtolower(ereg_replace('\.$','',$domain[0]));
00437                         // Removing extra trailing slashes
00438                 $path = trim(ereg_replace('\/[^\/]*$','',$path));
00439                         // Appending to domain string
00440                 $domain.= $path;
00441                 $domain = ereg_replace('\/*$','',$domain);
00442 
00443                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00444                                         'pages.uid,sys_domain.redirectTo,sys_domain.prepend_params',
00445                                         'pages,sys_domain',
00446                                         'pages.uid=sys_domain.pid
00447                                                 AND sys_domain.hidden=0
00448                                                 AND (sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain, 'sys_domain').' OR sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain.'/', 'sys_domain').') '.
00449                                                 $this->where_hid_del.$this->where_groupAccess,
00450                                         '',
00451                                         '',
00452                                         1
00453                                 );
00454                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00455                         if ($row['redirectTo']) {
00456                                 $rURL = $row['redirectTo'];
00457                                 if ($row['prepend_params'])     {
00458                                         $rURL = ereg_replace('\/$','',$rURL);
00459                                         $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
00460                                         $rURL.= '/'.$prependStr;
00461                                 }
00462                                 Header('Location: '.t3lib_div::locationHeaderUrl($rURL));
00463                                 exit;
00464                         } else {
00465                                 return $row['uid'];
00466                         }
00467                 }
00468         }
00469 
00482         function getRootLine($uid, $MP='', $ignoreMPerrors=FALSE)       {
00483 
00484                         // Initialize:
00485                 $selFields = t3lib_div::uniqueList('pid,uid,t3ver_oid,title,alias,nav_title,media,layout,hidden,starttime,endtime,fe_group,extendToSubpages,doktype,TSconfig,storage_pid,is_siteroot,mount_pid,mount_pid_ol,fe_login_mode,'.$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']);
00486                 $this->error_getRootLine = '';
00487                 $this->error_getRootLine_failPid = 0;
00488 
00489                         // Splitting the $MP parameters if present
00490                 $MPA = array();
00491                 if ($MP)        {
00492                         $MPA = explode(',',$MP);
00493                         reset($MPA);
00494                         while(list($MPAk) = each($MPA)) {
00495                                 $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
00496                         }
00497                 }
00498 
00499                 $loopCheck = 0;
00500                 $theRowArray = Array();
00501                 $uid = intval($uid);
00502 
00503                 while ($uid!=0 && $loopCheck<20)        {       // Max 20 levels in the page tree.
00504                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($uid).' AND pages.deleted=0 AND pages.doktype!=255');
00505                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00506                                 $this->fixVersioningPid('pages',$row);
00507 #??                             $this->versionOL('pages',$row);
00508 
00509                                         // Mount Point page types are allowed ONLY a) if they are the outermost record in rootline and b) if the overlay flag is not set:
00510                                 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] && $row['doktype']==7 && !$ignoreMPerrors)   {
00511                                         $mount_info = $this->getMountPointInfo($row['uid'], $row);
00512                                         if ($loopCheck>0 || $mount_info['overlay'])     {
00513                                                 $this->error_getRootLine = 'Illegal Mount Point found in rootline';
00514                                                 return array();
00515                                         }
00516                                 }
00517 
00518                                 $uid = $row['pid'];     // Next uid
00519 
00520                                 if (count($MPA) && $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'])      {
00521                                         $curMP = end($MPA);
00522                                         if (!strcmp($row['uid'],$curMP[0]))     {
00523 
00524                                                 array_pop($MPA);
00525                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($curMP[1]).' AND pages.deleted=0 AND pages.doktype!=255');
00526                                                 $mp_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00527 
00528                                                 if (is_array($mp_row))  {
00529                                                         $this->fixVersioningPid('pages',$mp_row);
00530 #??                                                     $this->versionOL('pages',$mp_row);
00531                                                         $mount_info = $this->getMountPointInfo($mp_row['uid'], $mp_row);
00532                                                         if (is_array($mount_info) && $mount_info['mount_pid']==$curMP[0])       {
00533                                                                 $uid = $mp_row['pid'];  // Setting next uid
00534 
00535                                                                 if ($mount_info['overlay'])     {       // Symlink style: Keep mount point (current row).
00536                                                                         $row['_MOUNT_OL'] = TRUE;       // Set overlay mode:
00537                                                                         $row['_MOUNT_PAGE'] = array(
00538                                                                                 'uid' => $mp_row['uid'],
00539                                                                                 'pid' => $mp_row['pid'],
00540                                                                                 'title' =>  $mp_row['title'],
00541                                                                         );
00542                                                                 } else {        // Normal operation: Insert the mount page row in rootline instead mount point.
00543                                                                         if ($loopCheck>0)       {
00544                                                                                 $row = $mp_row;
00545                                                                         } else {
00546                                                                                 $this->error_getRootLine = 'Current Page Id is a mounted page of the overlay type and cannot be accessed directly!';
00547                                                                                 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!)
00548                                                                         }
00549                                                                 }
00550 
00551                                                                 $row['_MOUNTED_FROM'] = $curMP[0];
00552                                                                 $row['_MP_PARAM'] = $mount_info['MPvar'];
00553                                                         } else {
00554                                                                 $this->error_getRootLine = 'MP var was corrupted';
00555                                                                 return array(); // The MP variables did NOT connect proper mount points:
00556                                                         }
00557                                                 } else {
00558                                                         $this->error_getRootLine = 'No moint point record found according to PID in MP var';
00559                                                         return array(); // The second PID in MP var was NOT a valid page.
00560                                                 }
00561                                         }
00562                                 }
00563                                         // Add row to rootline with language overlaid:
00564                                 $theRowArray[] = $this->getPageOverlay($row);
00565                         } else {
00566                                 $this->error_getRootLine = 'Broken rootline';
00567                                 $this->error_getRootLine_failPid = $uid;
00568                                 return array(); // broken rootline.
00569                         }
00570 
00571                         $loopCheck++;
00572                 }
00573 
00574                         // If the MPA array is NOT empty, we have to return an error; All MP elements were not resolved!
00575                 if (count($MPA))        {
00576                         $this->error_getRootLine = 'MP value remain!';
00577                         return array();
00578                 }
00579 
00580                         // Create output array (with reversed order of numeric keys):
00581                 $output = Array();
00582                 $c = count($theRowArray);
00583                 foreach($theRowArray as $key => $val)   {
00584                         $c--;
00585                         $output[$c] = $val;
00586                 }
00587 
00588                 return $output;
00589         }
00590 
00600         function getPathFromRootline($rl,$len=20)       {
00601                 if (is_array($rl))      {
00602                         $c=count($rl);
00603                         $path = '';
00604                         for ($a=0;$a<$c;$a++)   {
00605                                 if ($rl[$a]['uid'])     {
00606                                         $path.='/'.t3lib_div::fixed_lgd_cs(strip_tags($rl[$a]['title']),$len);
00607                                 }
00608                         }
00609                         return $path;
00610                 }
00611         }
00612 
00621         function getExtURL($pagerow,$disable=0) {
00622                 if ($pagerow['doktype']==3 && !$disable)        {
00623                         $redirectTo = $this->urltypes[$pagerow['urltype']].$pagerow['url'];
00624 
00625                                 // If relative path, prefix Site URL:
00626                         $uI = parse_url($redirectTo);
00627                         if (!$uI['scheme'] && substr($redirectTo,0,1)!='/')     { // relative path assumed now...
00628                                 $redirectTo = t3lib_div::getIndpEnv('TYPO3_SITE_URL').$redirectTo;
00629                         }
00630                         return $redirectTo;
00631                 }
00632         }
00633 
00645         function getMountPointInfo($pageId, $pageRec=FALSE, $prevMountPids=array(), $firstPageUid=0)    {
00646                 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'])     {
00647 
00648                                 // Get pageRec if not supplied:
00649                         if (!is_array($pageRec))        {
00650                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,doktype,mount_pid,mount_pid_ol', 'pages', 'uid='.intval($pageId).' AND pages.deleted=0 AND pages.doktype!=255');
00651                                 $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00652 #??                             $this->versionOL('pages',$pageRec);
00653                         }
00654 
00655                                 // Set first Page uid:
00656                         if (!$firstPageUid)     $firstPageUid = $pageRec['uid'];
00657 
00658                                 // Look for mount pid value plus other required circumstances:
00659                         $mount_pid = intval($pageRec['mount_pid']);
00660                         if (is_array($pageRec) && $pageRec['doktype']==7 && $mount_pid>0 && !in_array($mount_pid, $prevMountPids))      {
00661 
00662                                         // Get the mount point record (to verify its general existence):
00663                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid,doktype,mount_pid,mount_pid_ol', 'pages', 'uid='.$mount_pid.' AND pages.deleted=0 AND pages.doktype!=255');
00664                                 $mount_rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00665                                 if (is_array($mount_rec))       {
00666 #??                                     $this->versionOL('pages',$mount_rec);
00667 
00668                                                 // Look for recursive mount point:
00669                                         $prevMountPids[] = $mount_pid;
00670                                         $recursiveMountPid = $this->getMountPointInfo($mount_pid, $mount_rec, $prevMountPids, $firstPageUid);
00671 
00672                                                 // Return mount point information:
00673                                         return $recursiveMountPid ?
00674                                                                 $recursiveMountPid :
00675                                                                 array(
00676                                                                         'mount_pid' => $mount_pid,
00677                                                                         'overlay' => $pageRec['mount_pid_ol'],
00678                                                                         'MPvar' => $mount_pid.'-'.$firstPageUid,
00679                                                                         'mount_point_rec' => $pageRec,
00680                                                                         'mount_pid_rec' => $mount_rec,
00681                                                                 );
00682                                 } else {
00683                                         return -1;      // Means, there SHOULD have been a mount point, but there was none!
00684                                 }
00685                         }
00686                 }
00687 
00688                 return FALSE;
00689         }
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00700 
00701 
00702 
00703 
00704 
00705 
00706 
00707         /*********************************
00708          *
00709          * Selecting records in general
00710          *
00711          **********************************/
00712 
00722         function checkRecord($table,$uid,$checkPage=0)  {
00723                 global $TCA;
00724                 $uid=intval($uid);
00725                 if (is_array($TCA[$table])) {
00726                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($uid).$this->enableFields($table));
00727                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00728 #??                             $this->versionOL($table,$row);
00729                                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00730                                 if ($checkPage) {
00731                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid='.intval($row['pid']).$this->enableFields('pages'));
00732                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00733                                                 return $row;
00734                                         } else {
00735                                                 return 0;
00736                                         }
00737                                 } else {
00738                                         return $row;
00739                                 }
00740                         }
00741                 }
00742         }
00743 
00753         function getRawRecord($table,$uid,$fields='*')  {
00754                 global $TCA;
00755                 $uid = intval($uid);
00756                 if (is_array($TCA[$table]) || $table=='pages') {        // Excluding pages here so we can ask the function BEFORE TCA gets initialized. Support for this is followed up in deleteClause()...
00757                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).$this->deleteClause($table));
00758                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00759 #??                             $this->versionOL($table,$row);
00760                                 return $row;
00761                         }
00762                 }
00763         }
00764 
00777         function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
00778                 global $TCA;
00779                 if (is_array($TCA[$theTable])) {
00780                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00781                                                 '*',
00782                                                 $theTable,
00783                                                 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
00784                                                         $this->deleteClause($theTable).' '.
00785                                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
00786                                                 $groupBy,
00787                                                 $orderBy,
00788                                                 $limit
00789                                         );
00790                         $rows = array();
00791                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00792 #??                             $this->versionOL($theTable,$row);
00793                                 $rows[] = $row;
00794                         }
00795                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00796                         if (count($rows))       return $rows;
00797                 }
00798         }
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 
00808 
00809 
00810 
00811 
00812 
00813         /*********************************
00814          *
00815          * Caching and standard clauses
00816          *
00817          **********************************/
00818 
00829         function getHash($hash,$expTime=0)      {
00830                         //
00831                 $expTime = intval($expTime);
00832                 if ($expTime)   {
00833                         $whereAdd = ' AND tstamp > '.(time()-$expTime);
00834                 }
00835                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
00836                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00837                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00838                         return $row['content'];
00839                 }
00840         }
00841 
00852         function storeHash($hash,$data,$ident)  {
00853                 $insertFields = array(
00854                         'hash' => $hash,
00855                         'content' => $data,
00856                         'ident' => $ident,
00857                         'tstamp' => time()
00858                 );
00859                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
00860                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
00861         }
00862 
00870         function deleteClause($table)   {
00871                 global $TCA;
00872                 if (!strcmp($table,'pages'))    {       // Hardcode for pages...:
00873                         return ' AND pages.deleted=0';
00874                 } else {
00875                         return $TCA[$table]['ctrl']['delete'] ? ' AND '.$table.'.'.$TCA[$table]['ctrl']['delete'].'=0' : '';
00876                 }
00877         }
00878 
00889         function enableFields($table,$show_hidden=-1,$ignore_array=array())     {
00890                 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
00891                         $show_hidden = $table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords;
00892                 }
00893                 if ($show_hidden==-1)   $show_hidden=0; // If show_hidden was not changed during the previous evaluation, do it here.
00894 
00895                 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00896                 $query='';
00897                 if (is_array($ctrl))    {
00898                         if ($ctrl['delete'])    {
00899                                 $query.=' AND '.$table.'.'.$ctrl['delete'].'=0';
00900                         }
00901                         if (is_array($ctrl['enablecolumns']))   {
00902                                 if ($ctrl['enablecolumns']['disabled'] && !$show_hidden && !$ignore_array['disabled'])  {
00903                                         $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00904                                         $query.=' AND '.$field.'=0';
00905                                 }
00906                                 if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
00907                                         $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00908                                         $query.=' AND ('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00909                                 }
00910                                 if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime'])     {
00911                                         $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00912                                         $query.=' AND ('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00913                                 }
00914                                 if ($ctrl['enablecolumns']['fe_group'] && !$ignore_array['fe_group'])   {
00915                                         $field = $table.'.'.$ctrl['enablecolumns']['fe_group'];
00916                                         $gr_list = $GLOBALS['TSFE']->gr_list;
00917                                         if (!strcmp($gr_list,''))       $gr_list=0;
00918                                         $query.=' AND '.$field.' IN ('.$gr_list.')';
00919                                 }
00920 
00921                                         // Call hook functions for additional enableColumns
00922                                         // It is used by the extension ingmar_accessctrl which enables assigning more than one usergroup to content and page records
00923                                 if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_page.php']['addEnableColumns']))    {
00924                                         $_params = array(
00925                                                 'table' => $table,
00926                                                 'show_hidden' => $show_hidden,
00927                                                 'ignore_array' => $ignore_array,
00928                                                 'ctrl' => $ctrl
00929                                         );
00930                                         foreach($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_page.php']['addEnableColumns'] as $_funcRef)    {
00931                                                 $query .= t3lib_div::callUserFunction($_funcRef,$_params,$this);
00932                                         }
00933                                 }
00934                         }
00935                 } else {
00936                         die ('NO entry in the $TCA-array for the table "'.$table.'". This means that the function enableFields() is called with an invalid table name as argument.');
00937                 }
00938 
00939                 return $query;
00940         }
00941 
00942 
00943 
00944 
00945 
00946 
00947 
00948 
00949 
00950 
00951 
00952 
00953 
00954 
00955 
00956         /*********************************
00957          *
00958          * Versioning Preview
00959          *
00960          **********************************/
00961 
00971         function fixVersioningPid($table,&$rr)  {
00972                 global $TCA;
00973 # SWAP uid as well???
00974                 if ($this->versioningPreview && $rr['pid']==-1 && ($table=='pages' || $TCA[$table]['ctrl']['versioning']))      {       // Have to hardcode it for "pages" table since TCA is not loaded at this moment!
00975                         if ($rr['t3ver_oid']>0) {       // If "t3ver_oid" is already a field, just set this:
00976                                 $oid = $rr['t3ver_oid'];
00977                         } else {        // Otherwise we have to expect "uid" to be in the record and look up based on this:
00978                                 $newPidRec = $this->getRawRecord($table,$rr['uid'],'t3ver_oid');
00979                                 if (is_array($newPidRec))       {
00980                                         $oid = $newPidRec['t3ver_oid'];
00981                                 }
00982                         }
00983 
00984                                 // If ID of current online version is found, look up the PID value of that:
00985                         if ($oid)       {
00986                                 $oidRec = $this->getRawRecord($table,$oid,'pid');
00987                                 if (is_array($oidRec))  {
00988                                         $rr['_ORIG_pid'] = $rr['pid'];
00989                                         $rr['pid'] = $oidRec['pid'];
00990                                 }
00991                         }
00992                 }
00993         }
00994 
01003         function versionOL($table,&$row)        {
01004                 global $TCA;
01005 
01006                 if ($this->versioningPreview && $TCA[$table]['ctrl']['versioning'])     {
01007 #debug($row,$table);
01008 #debug($this->versionPreviewMap);
01009                         if (is_array($row) && isset($this->versionPreviewMap[$table.':'.$row['uid']]))  {
01010 
01011                                         // ID to look for:
01012                                 $lookFor = $this->versionPreviewMap[$table.':'.$row['uid']];
01013 
01014                                         // Select the alternative version:
01015                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($lookFor).$this->deleteClause($table));
01016                                 if ($altrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
01017                                         if ($altrow['pid']==-1 && $altrow['t3ver_oid']==$row['uid'])    {
01018                                                 unset($altrow['pid']);  // Unsetting PID since this is basically the same as what fixVersioningPid would do to the record...
01019                                                 unset($altrow['uid']);  // Unsetting UID because the overlaid record should KEEP its own UID.
01020                                                 # unset(...);   // more fields being unset???
01021                                                 $row = t3lib_div::array_merge_recursive_overrule($row,$altrow,TRUE);
01022 #debug($row,'Found:');
01023                                         }
01024                                 }
01025                         }
01026                 }
01027         }
01028 }
01029 
01030 
01031 
01032 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php'])      {
01033         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']);
01034 }
01035 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6