00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00107 class t3lib_pageSelect {
00108 var $urltypes = Array('','http:
00109 var $where_hid_del = ' AND pages.deleted=0';
00110 var $sys_language_uid = 0;
00111
00112
00113 var $versioningPreview = FALSE;
00114 var $versionPreviewMap = array(
00115 # EXAMPLE: 'tt_content:421' => 427
00116 );
00117
00118
00119
00120 var $error_getRootLine = '';
00121 var $error_getRootLine_failPid = 0;
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
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');
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
00240 if ($lUid<0) $lUid = $this->sys_language_uid;
00241 unset($row);
00242
00243
00244 if ($lUid) {
00245 $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
00246 if (is_array($pageInput)) {
00247 $page_id = $pageInput['uid'];
00248 $fieldArr = array_intersect($fieldArr,array_keys($pageInput));
00249 } else {
00250 $page_id = $pageInput;
00251 }
00252
00253 if (count($fieldArr)) {
00254
00255
00256
00257
00258
00259
00260
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
00277 unset($row['uid']);
00278 unset($row['pid']);
00279 }
00280 }
00281 }
00282
00283
00284 if (is_array($pageInput)) {
00285 return is_array($row) ? array_merge($pageInput,$row) : $pageInput;
00286 } else {
00287 return is_array($row) ? $row : array();
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']) {
00306
00307
00308 if ($sys_language_content>0) {
00309
00310
00311 if ($row[$TCA[$table]['ctrl']['languageField']]<=0) {
00312
00313
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
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) {
00341 unset($row);
00342 }
00343
00344
00345 } elseif ($sys_language_content!=$row[$TCA[$table]['ctrl']['languageField']]) {
00346 unset($row);
00347 }
00348 } else {
00349
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
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
00403 $origUid = $row['uid'];
00404 $mount_info = $this->getMountPointInfo($origUid, $row);
00405 if (is_array($mount_info) && $mount_info['overlay']) {
00406 $mp_row = $this->getPage($mount_info['mount_pid']);
00407 if (count($mp_row)) {
00408 $row = $mp_row;
00409 $row['_MP_PARAM'] = $mount_info['MPvar'];
00410 } else unset($row);
00411 }
00412
00413
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
00435 $path = trim(ereg_replace('\/[^\/]*$','',$path));
00436
00437 $domain.= $path;
00438 $domain = ereg_replace('\
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
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') {
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,
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
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')) {
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'])) {
00888 $show_hidden = $table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords;
00889 }
00890 if ($show_hidden==-1) $show_hidden=0;
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
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'])) {
00958 if ($rr['t3ver_oid']>0) {
00959 $oid = $rr['t3ver_oid'];
00960 } else {
00961 $newPidRec = $this->getRawRecord($table,$rr['uid'],'t3ver_oid');
00962 if (is_array($newPidRec)) {
00963 $oid = $newPidRec['t3ver_oid'];
00964 }
00965 }
00966
00967
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
00995 $lookFor = $this->versionPreviewMap[$table.':'.$row['uid']];
00996
00997
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']);
01002 unset($altrow['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 ?>