Documentation TYPO3 par Ameos

class.t3lib_page.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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 $sys_language_uid = 0;
00111 
00112                 // Versioning preview related:
00113         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!!!
00114         var $versionPreviewMap = array(
00115 # EXAMPLE:              'tt_content:421' => 427
00116         );
00117 
00118 
00119                 // Internal, dynamic:
00120         var $error_getRootLine = '';            // Error string set by getRootLine()
00121         var $error_getRootLine_failPid = 0;             // Error uid set by getRootLine()
00122 
00123 
00132         function init($show_hidden)     {
00133                 $this->where_hid_del = ' AND pages.deleted=0 ';
00134                 if (!$show_hidden)      {
00135                         $this->where_hid_del.= 'AND pages.hidden=0 ';
00136                 }
00137                 $this->where_hid_del.= 'AND (pages.starttime<='.$GLOBALS['SIM_EXEC_TIME'].') AND (pages.endtime=0 OR pages.endtime>'.$GLOBALS['SIM_EXEC_TIME'].') ';
00138         }
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156         /*******************************************
00157          *
00158          * Selecting page records
00159          *
00160          ******************************************/
00161 
00171         function getPage($uid)  {
00172                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->where_hid_del);
00173                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00174 #??                     $this->versionOL('pages',$row);
00175                         return $this->getPageOverlay($row);
00176                 }
00177                 return Array();
00178         }
00179 
00187         function getPage_noCheck($uid)  {
00188                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'uid='.intval($uid).$this->deleteClause('pages'));
00189                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00190 #??                     $this->versionOL('pages',$row);
00191                         return $this->getPageOverlay($row);
00192                 }
00193                 return Array();
00194         }
00195 
00203         function getFirstWebPage($uid)  {
00204                 $output = '';
00205                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($uid).$this->where_hid_del, '', 'sorting', '1');
00206                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00207 #??                     $this->versionOL('pages',$row);
00208                         $output = $this->getPageOverlay($row);
00209                 }
00210                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00211                 return $output;
00212         }
00213 
00221         function getPageIdFromAlias($alias)     {
00222                 $alias = strtolower($alias);
00223                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'alias="'.$GLOBALS['TYPO3_DB']->quoteStr($alias, 'pages').'" AND pid>=0 AND pages.deleted=0');    // "AND pid>=0" is because of versioning...
00224                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00225                         return $row['uid'];
00226                 }
00227                 return 0;
00228         }
00229 
00237         function getPageOverlay($pageInput,$lUid=-1)    {
00238 
00239                         // Initialize:
00240                 if ($lUid<0)    $lUid = $this->sys_language_uid;
00241                 unset($row);
00242 
00243                         // If language UID is different from zero, do overlay:
00244                 if ($lUid)      {
00245                         $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
00246                         if (is_array($pageInput))       {
00247                                 $page_id = $pageInput['uid'];   // Was the whole record
00248                                 $fieldArr = array_intersect($fieldArr,array_keys($pageInput));          // Make sure that only fields which exist in the incoming record are overlaid!
00249                         } else {
00250                                 $page_id = $pageInput;  // Was the id
00251                         }
00252 
00253                         if (count($fieldArr))   {
00254                                 /*
00255                                         NOTE to enabledFields('pages_language_overlay'):
00256                                         Currently the showHiddenRecords of TSFE set will allow pages_language_overlay records to be selected as they are child-records of a page.
00257                                         However you may argue that the showHiddenField flag should determine this. But that's not how it's done right now.
00258                                 */
00259 
00260                                         // Selecting overlay record:
00261                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00262                                                         implode(',',$fieldArr),
00263                                                         'pages_language_overlay',
00264                                                         'pid='.intval($page_id).'
00265                                                                 AND sys_language_uid='.intval($lUid).
00266                                                                 $this->enableFields('pages_language_overlay'),
00267                                                         '',
00268                                                         '',
00269                                                         '1'
00270                                                 );
00271                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00272                                 if (is_array($row))     {
00273                                         $row['_PAGES_OVERLAY'] = TRUE;
00274                                         $this->versionOL('pages_language_overlay',$row);
00275 
00276                                                 // Unset vital fields that are NOT allowed to be overlaid:
00277                                         unset($row['uid']);
00278                                         unset($row['pid']);
00279                                 }
00280                         }
00281                 }
00282 
00283                         // Create output:
00284                 if (is_array($pageInput))       {
00285                         return is_array($row) ? array_merge($pageInput,$row) : $pageInput;      // If the input was an array, simply overlay the newfound array and return...
00286                 } else {
00287                         return is_array($row) ? $row : array(); // always an array in return
00288                 }
00289         }
00290 
00300         function getRecordOverlay($table,$row,$sys_language_content,$OLmode='') {
00301                 global $TCA;
00302 
00303                 if ($row['uid']>0 && $row['pid']>0)     {
00304                         if ($TCA[$table] && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])     {
00305                                 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....)
00306 
00307                                                 // Will try to overlay a record only if the sys_language_content value is larger that zero.
00308                                         if ($sys_language_content>0)    {
00309 
00310                                                         // Must be default language or [All], otherwise no overlaying:
00311                                                 if ($row[$TCA[$table]['ctrl']['languageField']]<=0)     {
00312 
00313                                                                 // Select overlay record:
00314                                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00315                                                                                 '*',
00316                                                                                 $table,
00317                                                                                 'pid='.intval($row['pid']).
00318                                                                                         ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sys_language_content).
00319                                                                                         ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
00320                                                                                         $this->enableFields($table),
00321                                                                                 '',
00322                                                                                 '',
00323                                                                                 '1'
00324                                                                         );
00325                                                         $olrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00326                                                         $this->versionOL($table,$olrow);
00327         #debug($row);
00328         #debug($olrow);
00329                                                                 // Merge record content by traversing all fields:
00330                                                         if (is_array($olrow))   {
00331                                                                 foreach($row as $fN => $fV)     {
00332                                                                         if ($fN!='uid' && $fN!='pid' && isset($olrow[$fN]))     {
00333 
00334                                                                                 if ($GLOBALS['TSFE']->TCAcachedExtras[$table]['l10n_mode'][$fN]!='exclude'
00335                                                                                                 && ($GLOBALS['TSFE']->TCAcachedExtras[$table]['l10n_mode'][$fN]!='mergeIfNotBlank' || strcmp(trim($olrow[$fN]),'')))    {
00336                                                                                         $row[$fN] = $olrow[$fN];
00337                                                                                 }
00338                                                                         }
00339                                                                 }
00340                                                         } 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.
00341                                                                 unset($row);
00342                                                         }
00343 
00344                                                         // 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.
00345                                                 } elseif ($sys_language_content!=$row[$TCA[$table]['ctrl']['languageField']])   {
00346                                                         unset($row);
00347                                                 }
00348                                         } else {
00349                                                         // When default language is displayed, we never want to return a record carrying another language!:
00350                                                 if ($row[$TCA[$table]['ctrl']['languageField']]>0)      {
00351                                                         unset($row);
00352                                                 }
00353                                         }
00354                                 }
00355                         }
00356                 }
00357 
00358                 return $row;
00359         }
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378         /*******************************************
00379          *
00380          * Page related: Menu, Domain record, Root line
00381          *
00382          ******************************************/
00383 
00396         function getMenu($uid,$fields='*',$sortField='sorting',$addWhere='')    {
00397                 $output = Array();
00398                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'pages', 'pid='.intval($uid).$this->where_hid_del.' '.$addWhere, '', $sortField);
00399                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00400 #??                     $this->versionOL('pages',$row);
00401 
00402                                 // Keep mount point:
00403                         $origUid = $row['uid'];
00404                         $mount_info = $this->getMountPointInfo($origUid, $row); // $row MUST have "uid", "pid", "doktype", "mount_pid", "mount_pid_ol" fields in it
00405                         if (is_array($mount_info) && $mount_info['overlay'])    {       // There is a valid mount point.
00406                                 $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!
00407                                 if (count($mp_row))     {
00408                                         $row = $mp_row;
00409                                         $row['_MP_PARAM'] = $mount_info['MPvar'];
00410                                 } 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!
00411                         }
00412 
00413                                 // Add to output array after overlaying language:
00414                         if (is_array($row))     {
00415                                 $output[$origUid] = $this->getPageOverlay($row);
00416                         }
00417                 }
00418                 return $output;
00419         }
00420 
00431         function getDomainStartPage($domain, $path='',$request_uri='')  {
00432                 $domain = explode(':',$domain);
00433                 $domain = strtolower(ereg_replace('\.$','',$domain[0]));
00434                         // Removing extra trailing slashes
00435                 $path = trim(ereg_replace('\/[^\/]*$','',$path));
00436                         // Appending to domain string
00437                 $domain.= $path;
00438                 $domain = ereg_replace('\/*$','',$domain);
00439 
00440                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00441                                         'pages.uid,sys_domain.redirectTo,sys_domain.prepend_params',
00442                                         'pages,sys_domain',
00443                                         'pages.uid=sys_domain.pid
00444                                                 AND sys_domain.hidden=0
00445                                                 AND (sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain, 'sys_domain').'" OR sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain.'/', 'sys_domain').'") '.
00446                                                 $this->where_hid_del,
00447                                         '',
00448                                         '',
00449                                         1
00450                                 );
00451                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00452                         if ($row['redirectTo']) {
00453                                 $rURL = $row['redirectTo'];
00454                                 if ($row['prepend_params'])     {
00455                                         $rURL = ereg_replace('\/$','',$rURL);
00456                                         $prependStr = ereg_replace('^\/','',substr($request_uri,strlen($path)));
00457                                         $rURL.='/'.$prependStr;
00458                                 }
00459                                 Header('Location: '.t3lib_div::locationHeaderUrl($rURL));
00460                                 exit;
00461                         } else {
00462                                 return $row['uid'];
00463                         }
00464                 }
00465         }
00466 
00479         function getRootLine($uid, $MP='', $ignoreMPerrors=FALSE)       {
00480 
00481                         // Initialize:
00482                 $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,'.$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields']);
00483                 $this->error_getRootLine = '';
00484                 $this->error_getRootLine_failPid = 0;
00485 
00486                         // Splitting the $MP parameters if present
00487                 $MPA = array();
00488                 if ($MP)        {
00489                         $MPA = explode(',',$MP);
00490                         reset($MPA);
00491                         while(list($MPAk) = each($MPA)) {
00492                                 $MPA[$MPAk] = explode('-', $MPA[$MPAk]);
00493                         }
00494                 }
00495 
00496                 $loopCheck = 0;
00497                 $theRowArray = Array();
00498                 $uid = intval($uid);
00499 
00500                 while ($uid!=0 && $loopCheck<20)        {       // Max 20 levels in the page tree.
00501                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($uid).' AND pages.deleted=0 AND pages.doktype!=255');
00502                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00503                                 $this->fixVersioningPid('pages',$row);
00504 #??                             $this->versionOL('pages',$row);
00505 
00506                                         // 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:
00507                                 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'] && $row['doktype']==7 && !$ignoreMPerrors)   {
00508                                         $mount_info = $this->getMountPointInfo($row['uid'], $row);
00509                                         if ($loopCheck>0 || $mount_info['overlay'])     {
00510                                                 $this->error_getRootLine = 'Illegal Mount Point found in rootline';
00511                                                 return array();
00512                                         }
00513                                 }
00514 
00515                                 $uid = $row['pid'];     // Next uid
00516 
00517                                 if (count($MPA) && $GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'])      {
00518                                         $curMP = end($MPA);
00519                                         if (!strcmp($row['uid'],$curMP[0]))     {
00520 
00521                                                 array_pop($MPA);
00522                                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($selFields, 'pages', 'uid='.intval($curMP[1]).' AND pages.deleted=0 AND pages.doktype!=255');
00523                                                 $mp_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00524 
00525                                                 if (is_array($mp_row))  {
00526                                                         $this->fixVersioningPid('pages',$mp_row);
00527 #??                                                     $this->versionOL('pages',$mp_row);
00528                                                         $mount_info = $this->getMountPointInfo($mp_row['uid'], $mp_row);
00529                                                         if (is_array($mount_info) && $mount_info['mount_pid']==$curMP[0])       {
00530                                                                 $uid = $mp_row['pid'];  // Setting next uid
00531 
00532                                                                 if ($mount_info['overlay'])     {       // Symlink style: Keep mount point (current row).
00533                                                                         $row['_MOUNT_OL'] = TRUE;       // Set overlay mode:
00534                                                                         $row['_MOUNT_PAGE'] = array(
00535                                                                                 'uid' => $mp_row['uid'],
00536                                                                                 'pid' => $mp_row['pid'],
00537                                                                                 'title' =>  $mp_row['title'],
00538                                                                         );
00539                                                                 } else {        // Normal operation: Insert the mount page row in rootline instead mount point.
00540                                                                         if ($loopCheck>0)       {
00541                                                                                 $row = $mp_row;
00542                                                                         } else {
00543                                                                                 $this->error_getRootLine = 'Current Page Id is a mounted page of the overlay type and cannot be accessed directly!';
00544                                                                                 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!)
00545                                                                         }
00546                                                                 }
00547 
00548                                                                 $row['_MOUNTED_FROM'] = $curMP[0];
00549                                                                 $row['_MP_PARAM'] = $mount_info['MPvar'];
00550                                                         } else {
00551                                                                 $this->error_getRootLine = 'MP var was corrupted';
00552                                                                 return array(); // The MP variables did NOT connect proper mount points:
00553                                                         }
00554                                                 } else {
00555                                                         $this->error_getRootLine = 'No moint point record found according to PID in MP var';
00556                                                         return array(); // The second PID in MP var was NOT a valid page.
00557                                                 }
00558                                         }
00559                                 }
00560                                         // Add row to rootline with language overlaid:
00561                                 $theRowArray[] = $this->getPageOverlay($row);
00562                         } else {
00563                                 $this->error_getRootLine = 'Broken rootline';
00564                                 $this->error_getRootLine_failPid = $uid;
00565                                 return array(); // broken rootline.
00566                         }
00567 
00568                         $loopCheck++;
00569                 }
00570 
00571                         // If the MPA array is NOT empty, we have to return an error; All MP elements were not resolved!
00572                 if (count($MPA))        {
00573                         $this->error_getRootLine = 'MP value remain!';
00574                         return array();
00575                 }
00576 
00577                         // Create output array (with reversed order of numeric keys):
00578                 $output = Array();
00579                 $c = count($theRowArray);
00580                 foreach($theRowArray as $key => $val)   {
00581                         $c--;
00582                         $output[$c] = $val;
00583                 }
00584 
00585                 return $output;
00586         }
00587 
00597         function getPathFromRootline($rl,$len=20)       {
00598                 if (is_array($rl))      {
00599                         $c=count($rl);
00600                         $path = '';
00601                         for ($a=0;$a<$c;$a++)   {
00602                                 if ($rl[$a]['uid'])     {
00603                                         $path.='/'.t3lib_div::fixed_lgd_cs(strip_tags($rl[$a]['title']),$len);
00604                                 }
00605                         }
00606                         return $path;
00607                 }
00608         }
00609 
00618         function getExtURL($pagerow,$disable=0) {
00619                 if ($pagerow['doktype']==3 && !$disable)        {
00620                         $redirectTo = $this->urltypes[$pagerow['urltype']].$pagerow['url'];
00621 
00622                                 // If relative path, prefix Site URL:
00623                         $uI = parse_url($redirectTo);
00624                         if (!$uI['scheme'] && substr($redirectTo,0,1)!='/')     { // relative path assumed now...
00625                                 $redirectTo = t3lib_div::getIndpEnv('TYPO3_SITE_URL').$redirectTo;
00626                         }
00627                         return $redirectTo;
00628                 }
00629         }
00630 
00642         function getMountPointInfo($pageId, $pageRec=FALSE, $prevMountPids=array(), $firstPageUid=0)    {
00643                 if ($GLOBALS['TYPO3_CONF_VARS']['FE']['enable_mount_pids'])     {
00644 
00645                                 // Get pageRec if not supplied:
00646                         if (!is_array($pageRec))        {
00647                                 $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');
00648                                 $pageRec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00649 #??                             $this->versionOL('pages',$pageRec);
00650                         }
00651 
00652                                 // Set first Page uid:
00653                         if (!$firstPageUid)     $firstPageUid = $pageRec['uid'];
00654 
00655                                 // Look for mount pid value plus other required circumstances:
00656                         $mount_pid = intval($pageRec['mount_pid']);
00657                         if (is_array($pageRec) && $pageRec['doktype']==7 && $mount_pid>0 && !in_array($mount_pid, $prevMountPids))      {
00658 
00659                                         // Get the mount point record (to verify its general existence):
00660                                 $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');
00661                                 $mount_rec = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00662                                 if (is_array($mount_rec))       {
00663 #??                                     $this->versionOL('pages',$mount_rec);
00664 
00665                                                 // Look for recursive mount point:
00666                                         $prevMountPids[] = $mount_pid;
00667                                         $recursiveMountPid = $this->getMountPointInfo($mount_pid, $mount_rec, $prevMountPids, $firstPageUid);
00668 
00669                                                 // Return mount point information:
00670                                         return $recursiveMountPid ?
00671                                                                 $recursiveMountPid :
00672                                                                 array(
00673                                                                         'mount_pid' => $mount_pid,
00674                                                                         'overlay' => $pageRec['mount_pid_ol'],
00675                                                                         'MPvar' => $mount_pid.'-'.$firstPageUid,
00676                                                                         'mount_point_rec' => $pageRec,
00677                                                                         'mount_pid_rec' => $mount_rec,
00678                                                                 );
00679                                 } else {
00680                                         return -1;      // Means, there SHOULD have been a mount point, but there was none!
00681                                 }
00682                         }
00683                 }
00684 
00685                 return FALSE;
00686         }
00687 
00688 
00689 
00690 
00691 
00692 
00693 
00694 
00695 
00696 
00697 
00698 
00699 
00700 
00701 
00702 
00703 
00704         /*********************************
00705          *
00706          * Selecting records in general
00707          *
00708          **********************************/
00709 
00719         function checkRecord($table,$uid,$checkPage=0)  {
00720                 global $TCA;
00721                 $uid=intval($uid);
00722                 if (is_array($TCA[$table])) {
00723                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($uid).$this->enableFields($table));
00724                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00725 #??                             $this->versionOL($table,$row);
00726                                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00727                                 if ($checkPage) {
00728                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'pages', 'uid='.intval($row['pid']).$this->enableFields('pages'));
00729                                         if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00730                                                 return $row;
00731                                         } else {
00732                                                 return 0;
00733                                         }
00734                                 } else {
00735                                         return $row;
00736                                 }
00737                         }
00738                 }
00739         }
00740 
00750         function getRawRecord($table,$uid,$fields='*')  {
00751                 global $TCA;
00752                 $uid = intval($uid);
00753                 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()...
00754                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).$this->deleteClause($table));
00755                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00756 #??                             $this->versionOL($table,$row);
00757                                 return $row;
00758                         }
00759                 }
00760         }
00761 
00774         function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='')     {
00775                 global $TCA;
00776                 if (is_array($TCA[$theTable])) {
00777                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00778                                                 '*',
00779                                                 $theTable,
00780                                                 $theField.'="'.$GLOBALS['TYPO3_DB']->quoteStr($theValue, $theTable).'"'.
00781                                                         $this->deleteClause($theTable).' '.
00782                                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
00783                                                 $groupBy,
00784                                                 $orderBy,
00785                                                 $limit
00786                                         );
00787                         $rows = array();
00788                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00789 #??                             $this->versionOL($theTable,$row);
00790                                 $rows[] = $row;
00791                         }
00792                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00793                         if (count($rows))       return $rows;
00794                 }
00795         }
00796 
00797 
00798 
00799 
00800 
00801 
00802 
00803 
00804 
00805 
00806 
00807 
00808 
00809 
00810         /*********************************
00811          *
00812          * Caching and standard clauses
00813          *
00814          **********************************/
00815 
00826         function getHash($hash,$expTime=0)      {
00827                         //
00828                 $expTime = intval($expTime);
00829                 if ($expTime)   {
00830                         $whereAdd = ' AND tstamp > '.(time()-$expTime);
00831                 }
00832                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"'.$whereAdd);
00833                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00834                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00835                         return $row['content'];
00836                 }
00837         }
00838 
00849         function storeHash($hash,$data,$ident)  {
00850                 $insertFields = array(
00851                         'hash' => $hash,
00852                         'content' => $data,
00853                         'ident' => $ident,
00854                         'tstamp' => time()
00855                 );
00856                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"');
00857                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
00858         }
00859 
00867         function deleteClause($table)   {
00868                 global $TCA;
00869                 if (!strcmp($table,'pages'))    {       // Hardcode for pages...:
00870                         return ' AND deleted=0';
00871                 } else {
00872                         return $TCA[$table]['ctrl']['delete'] ? ' AND '.$TCA[$table]['ctrl']['delete'].'=0' : '';
00873                 }
00874         }
00875 
00886         function enableFields($table,$show_hidden=-1,$ignore_array=array())     {
00887                 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
00888                         $show_hidden = $table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords;
00889                 }
00890                 if ($show_hidden==-1)   $show_hidden=0; // If show_hidden was not changed during the previous evaluation, do it here.
00891 
00892                 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00893                 $query='';
00894                 if (is_array($ctrl))    {
00895                         if ($ctrl['delete'])    {
00896                                 $query.=' AND '.$table.'.'.$ctrl['delete'].'=0';
00897                         }
00898                         if (is_array($ctrl['enablecolumns']))   {
00899                                 if ($ctrl['enablecolumns']['disabled'] && !$show_hidden && !$ignore_array['disabled'])  {
00900                                         $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00901                                         $query.=' AND '.$field.'=0';
00902                                 }
00903                                 if ($ctrl['enablecolumns']['starttime'] && !$ignore_array['starttime']) {
00904                                         $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00905                                         $query.=' AND ('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00906                                 }
00907                                 if ($ctrl['enablecolumns']['endtime'] && !$ignore_array['endtime'])     {
00908                                         $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00909                                         $query.=' AND ('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00910                                 }
00911                                 if ($ctrl['enablecolumns']['fe_group'] && !$ignore_array['fe_group'])   {
00912                                         $field = $table.'.'.$ctrl['enablecolumns']['fe_group'];
00913                                         $gr_list = $GLOBALS['TSFE']->gr_list;
00914                                         if (!strcmp($gr_list,''))       $gr_list=0;
00915                                         $query.=' AND '.$field.' IN ('.$gr_list.')';
00916                                 }
00917                         }
00918                 } else {
00919                         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.');
00920                 }
00921 
00922                 return $query;
00923         }
00924 
00925 
00926 
00927 
00928 
00929 
00930 
00931 
00932 
00933 
00934 
00935 
00936 
00937 
00938 
00939         /*********************************
00940          *
00941          * Versioning Preview
00942          *
00943          **********************************/
00944 
00954         function fixVersioningPid($table,&$rr)  {
00955                 global $TCA;
00956 # SWAP uid as well???
00957                 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!
00958                         if ($rr['t3ver_oid']>0) {       // If "t3ver_oid" is already a field, just set this:
00959                                 $oid = $rr['t3ver_oid'];
00960                         } else {        // Otherwise we have to expect "uid" to be in the record and look up based on this:
00961                                 $newPidRec = $this->getRawRecord($table,$rr['uid'],'t3ver_oid');
00962                                 if (is_array($newPidRec))       {
00963                                         $oid = $newPidRec['t3ver_oid'];
00964                                 }
00965                         }
00966 
00967                                 // If ID of current online version is found, look up the PID value of that:
00968                         if ($oid)       {
00969                                 $oidRec = $this->getRawRecord($table,$oid,'pid');
00970                                 if (is_array($oidRec))  {
00971                                         $rr['_ORIG_pid'] = $rr['pid'];
00972                                         $rr['pid'] = $oidRec['pid'];
00973                                 }
00974                         }
00975                 }
00976         }
00977 
00986         function versionOL($table,&$row)        {
00987                 global $TCA;
00988 
00989                 if ($this->versioningPreview && $TCA[$table]['ctrl']['versioning'])     {
00990 #debug($row,$table);
00991 #debug($this->versionPreviewMap);
00992                         if (is_array($row) && isset($this->versionPreviewMap[$table.':'.$row['uid']]))  {
00993 
00994                                         // ID to look for:
00995                                 $lookFor = $this->versionPreviewMap[$table.':'.$row['uid']];
00996 
00997                                         // Select the alternative version:
00998                                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($lookFor).$this->deleteClause($table));
00999                                 if ($altrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
01000                                         if ($altrow['pid']==-1 && $altrow['t3ver_oid']==$row['uid'])    {
01001                                                 unset($altrow['pid']);  // Unsetting PID since this is basically the same as what fixVersioningPid would do to the record...
01002                                                 unset($altrow['uid']);  // Unsetting UID because the overlaid record should KEEP its own UID.
01003                                                 # unset(...);   // more fields being unset???
01004                                                 $row = t3lib_div::array_merge_recursive_overrule($row,$altrow,TRUE);
01005 #debug($row,'Found:');
01006                                         }
01007                                 }
01008                         }
01009                 }
01010         }
01011 }
01012 
01013 
01014 
01015 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php'])      {
01016         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_page.php']);
01017 }
01018 ?>


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