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 $where_groupAccess = '';
00111 var $sys_language_uid = 0;
00112
00113
00114 var $versioningPreview = FALSE;
00115 var $versionPreviewMap = array(
00116 # EXAMPLE: 'tt_content:421' => 427
00117 );
00118
00119
00120
00121 var $error_getRootLine = '';
00122 var $error_getRootLine_failPid = 0;
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
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');
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
00243 if ($lUid<0) $lUid = $this->sys_language_uid;
00244 unset($row);
00245
00246
00247 if ($lUid) {
00248 $fieldArr = explode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
00249 if (is_array($pageInput)) {
00250 $page_id = $pageInput['uid'];
00251 $fieldArr = array_intersect($fieldArr,array_keys($pageInput));
00252 } else {
00253 $page_id = $pageInput;
00254 }
00255
00256 if (count($fieldArr)) {
00257
00258
00259
00260
00261
00262
00263
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
00280 unset($row['uid']);
00281 unset($row['pid']);
00282 }
00283 }
00284 }
00285
00286
00287 if (is_array($pageInput)) {
00288 return is_array($row) ? array_merge($pageInput,$row) : $pageInput;
00289 } else {
00290 return is_array($row) ? $row : array();
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']) {
00309
00310
00311 if ($sys_language_content>0) {
00312
00313
00314 if ($row[$TCA[$table]['ctrl']['languageField']]<=0) {
00315
00316
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
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) {
00344 unset($row);
00345 }
00346
00347
00348 } elseif ($sys_language_content!=$row[$TCA[$table]['ctrl']['languageField']]) {
00349 unset($row);
00350 }
00351 } else {
00352
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
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
00406 $origUid = $row['uid'];
00407 $mount_info = $this->getMountPointInfo($origUid, $row);
00408 if (is_array($mount_info) && $mount_info['overlay']) {
00409 $mp_row = $this->getPage($mount_info['mount_pid']);
00410 if (count($mp_row)) {
00411 $row = $mp_row;
00412 $row['_MP_PARAM'] = $mount_info['MPvar'];
00413 } else unset($row);
00414 }
00415
00416
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
00438 $path = trim(ereg_replace('\/[^\/]*$','',$path));
00439
00440 $domain.= $path;
00441 $domain = ereg_replace('\
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
00467
00468
00469
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
00588
00589
00590
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
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
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') {
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,
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
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')) {
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'])) {
00891 $show_hidden = $table=='pages' ? $GLOBALS['TSFE']->showHiddenPage : $GLOBALS['TSFE']->showHiddenRecords;
00892 }
00893 if ($show_hidden==-1) $show_hidden=0;
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
00922
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
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'])) {
00975 if ($rr['t3ver_oid']>0) {
00976 $oid = $rr['t3ver_oid'];
00977 } else {
00978 $newPidRec = $this->getRawRecord($table,$rr['uid'],'t3ver_oid');
00979 if (is_array($newPidRec)) {
00980 $oid = $newPidRec['t3ver_oid'];
00981 }
00982 }
00983
00984
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
01012 $lookFor = $this->versionPreviewMap[$table.':'.$row['uid']];
01013
01014
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']);
01019 unset($altrow['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 ?>