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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 final class t3lib_BEfunc {
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 public static function deleteClause($table,$tableAlias = '') {
00206 global $TCA;
00207 if ($TCA[$table]['ctrl']['delete']) {
00208 return ' AND '.($tableAlias ? $tableAlias : $table).'.'.$TCA[$table]['ctrl']['delete'].'=0';
00209 } else {
00210 return '';
00211 }
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 public static function getRecord($table, $uid, $fields = '*', $where = '', $useDeleteClause = true) {
00230 if ($GLOBALS['TCA'][$table]) {
00231 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00232 $fields,
00233 $table,
00234 'uid=' . intval($uid) . ($useDeleteClause ? self::deleteClause($table) : '') . $where
00235 );
00236 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00237 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00238 if ($row) {
00239 return $row;
00240 }
00241 }
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 public static function getRecordWSOL($table, $uid, $fields = '*', $where = '', $useDeleteClause = true) {
00255 if ($fields !== '*') {
00256 $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
00257 $row = self::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
00258 self::workspaceOL($table, $row);
00259
00260 if (is_array ($row)) {
00261 foreach (array_keys($row) as $key) {
00262 if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
00263 unset ($row[$key]);
00264 }
00265 }
00266 }
00267 } else {
00268 $row = self::getRecord($table, $uid, $fields, $where);
00269 self::workspaceOL($table, $row);
00270 }
00271 return $row;
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287 public static function getRecordRaw($table, $where = '', $fields = '*') {
00288 $row = FALSE;
00289 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
00290 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00291 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00292 }
00293 return $row;
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 public static function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = true) {
00313 global $TCA;
00314 if (is_array($TCA[$theTable])) {
00315 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00316 '*',
00317 $theTable,
00318 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
00319 ($useDeleteClause ? self::deleteClause($theTable).' ' : '').
00320 self::versioningPlaceholderClause($theTable) . ' ' .
00321 $whereClause,
00322 $groupBy,
00323 $orderBy,
00324 $limit
00325 );
00326 $rows = array();
00327 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00328 $rows[] = $row;
00329 }
00330 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00331 if (count($rows)) return $rows;
00332 }
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 public static function searchQuery($searchWords, $fields, $table = '') {
00346 t3lib_div::logDeprecatedFunction();
00347
00348 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords, $fields, $table);
00349 }
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362 public static function listQuery($field, $value) {
00363 t3lib_div::logDeprecatedFunction();
00364
00365 return $GLOBALS['TYPO3_DB']->listQuery($field, $value, '');
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 public static function splitTable_Uid($str) {
00377 list($uid, $table) = explode('_', strrev($str), 2);
00378 return array(strrev($table), strrev($uid));
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391 public static function getSQLselectableList($in_list, $tablename, $default_tablename) {
00392 $list = Array();
00393 if ((string)trim($in_list)!='') {
00394 $tempItemArray = explode(',', trim($in_list));
00395 foreach ($tempItemArray as $key => $val) {
00396 $val = strrev($val);
00397 $parts = explode('_', $val, 2);
00398 if ((string)trim($parts[0])!='') {
00399 $theID = intval(strrev($parts[0]));
00400 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
00401 if ($theTable==$tablename) {$list[] = $theID;}
00402 }
00403 }
00404 }
00405 return implode(',', $list);
00406 }
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 public static function BEenableFields($table, $inv = 0) {
00420 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00421 $query = array();
00422 $invQuery = array();
00423 if (is_array($ctrl)) {
00424 if (is_array($ctrl['enablecolumns'])) {
00425 if ($ctrl['enablecolumns']['disabled']) {
00426 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00427 $query[] = $field.'=0';
00428 $invQuery[] = $field.'!=0';
00429 }
00430 if ($ctrl['enablecolumns']['starttime']) {
00431 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00432 $query[] = '('.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
00433 $invQuery[] = '('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
00434 }
00435 if ($ctrl['enablecolumns']['endtime']) {
00436 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00437 $query[] = '('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
00438 $invQuery[] = '('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
00439 }
00440 }
00441 }
00442 $outQ = ($inv ? '(' . implode(' OR ', $invQuery) . ')' : implode(' AND ', $query));
00443
00444 return $outQ ? ' AND ' . $outQ : '';
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 public static function getRecordLocalization($table, $uid, $language, $andWhereClause = '') {
00457 $recordLocalization = false;
00458 if (self::isTableLocalizable($table)) {
00459 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
00460 $recordLocalization = self::getRecordsByField(
00461 $table,
00462 $tcaCtrl['transOrigPointerField'],
00463 $uid,
00464 'AND '.$tcaCtrl['languageField'].'='.intval($language).($andWhereClause ? ' '.$andWhereClause : ''),
00465 '',
00466 '',
00467 '1'
00468 );
00469 }
00470 return $recordLocalization;
00471 }
00472
00473
00474
00475
00476
00477
00478
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 public static function mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
00509 t3lib_div::logDeprecatedFunction();
00510
00511 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00512 $select,
00513 $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
00514 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
00515 $whereClause,
00516 $groupBy,
00517 $orderBy,
00518 $limit
00519 );
00520 return $query;
00521 }
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532 public static function DBcompileInsert($table, $fields_values) {
00533 t3lib_div::logDeprecatedFunction();
00534
00535 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548 public static function DBcompileUpdate($table, $where, $fields_values) {
00549 t3lib_div::logDeprecatedFunction();
00550
00551 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
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 public static function BEgetRootLine($uid, $clause = '', $workspaceOL = FALSE) {
00581 static $BEgetRootLine_cache = array();
00582
00583 $output = array();
00584 $pid = $uid;
00585 $ident = $pid . '-' . $clause . '-' . $workspaceOL;
00586
00587 if (is_array($BEgetRootLine_cache[$ident])) {
00588 $output = $BEgetRootLine_cache[$ident];
00589 } else {
00590 $loopCheck = 100;
00591 $theRowArray = array();
00592 while ($uid != 0 && $loopCheck) {
00593 $loopCheck--;
00594 $row = self::getPageForRootline($uid, $clause, $workspaceOL);
00595 if (is_array($row)) {
00596 $uid = $row['pid'];
00597 $theRowArray[] = $row;
00598 } else {
00599 break;
00600 }
00601 }
00602 if ($uid == 0) {
00603 $theRowArray[] = array('uid' => 0, 'title' => '');
00604 }
00605 $c = count($theRowArray);
00606
00607 foreach ($theRowArray as $val) {
00608 $c--;
00609 $output[$c] = array(
00610 'uid' => $val['uid'],
00611 'pid' => $val['pid'],
00612 'title' => $val['title'],
00613 'TSconfig' => $val['TSconfig'],
00614 'is_siteroot' => $val['is_siteroot'],
00615 'storage_pid' => $val['storage_pid'],
00616 't3ver_oid' => $val['t3ver_oid'],
00617 't3ver_wsid' => $val['t3ver_wsid'],
00618 't3ver_state' => $val['t3ver_state'],
00619 't3ver_swapmode' => $val['t3ver_swapmode'],
00620 't3ver_stage' => $val['t3ver_stage']
00621 );
00622 if (isset($val['_ORIG_pid'])) {
00623 $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
00624 }
00625 }
00626 $BEgetRootLine_cache[$ident] = $output;
00627 }
00628 return $output;
00629 }
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 protected static function getPageForRootline($uid, $clause, $workspaceOL) {
00641 static $getPageForRootline_cache = array();
00642 $ident = $uid . '-' . $clause . '-' . $workspaceOL;
00643
00644 if (is_array($getPageForRootline_cache[$ident])) {
00645 $row = $getPageForRootline_cache[$ident];
00646 } else {
00647 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00648 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
00649 'pages',
00650 'uid=' . intval($uid) . ' ' .
00651 self::deleteClause('pages') . ' ' .
00652 $clause
00653 );
00654
00655 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00656 if ($row) {
00657 if ($workspaceOL) {
00658 self::workspaceOL('pages', $row);
00659 }
00660 if (is_array($row)) {
00661 self::fixVersioningPid('pages', $row);
00662 $getPageForRootline_cache[$ident] = $row;
00663 }
00664 }
00665 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00666 }
00667 return $row;
00668 }
00669
00670
00671
00672
00673
00674
00675
00676
00677 public static function openPageTree($pid, $clearExpansion) {
00678 global $BE_USER;
00679
00680
00681 if ($clearExpansion) {
00682 $expandedPages = array();
00683 } else {
00684 $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
00685 }
00686
00687
00688 $rL = self::BEgetRootLine($pid);
00689
00690
00691 $mountIndex = 0;
00692 $mountKeys = array_flip($BE_USER->returnWebmounts());
00693 foreach($rL as $rLDat) {
00694 if (isset($mountKeys[$rLDat['uid']])) {
00695 $mountIndex = $mountKeys[$rLDat['uid']];
00696 break;
00697 }
00698 }
00699
00700
00701 foreach($rL as $rLDat) {
00702 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
00703 }
00704
00705
00706 $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
00707 $BE_USER->writeUC();
00708 }
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722 public static function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0) {
00723 if (!$titleLimit) { $titleLimit = 1000; }
00724
00725 $loopCheck = 100;
00726 $output = $fullOutput = '/';
00727
00728 $clause = trim($clause);
00729 if ($clause !== '' && substr($clause, 0, 3) !== 'AND') {
00730 $clause = 'AND ' . $clause;
00731 }
00732 $data = self::BEgetRootLine($uid, $clause);
00733
00734 foreach ($data as $record) {
00735 if ($record['uid'] === 0) {
00736 continue;
00737 }
00738 if ($record['_ORIG_pid'] && $record['t3ver_swapmode'] > 0) {
00739 $output = ' [#VEP#]' . $output;
00740 }
00741 $output = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $titleLimit) . $output;
00742 if ($fullTitleLimit) {
00743 $fullOutput = '/' . t3lib_div::fixed_lgd_cs(strip_tags($record['title']), $fullTitleLimit) . $fullOutput;
00744 }
00745 }
00746
00747 if ($fullTitleLimit) {
00748 return array($output, $fullOutput);
00749 } else {
00750 return $output;
00751 }
00752 }
00753
00754
00755
00756
00757
00758
00759
00760
00761 public static function getExcludeFields() {
00762 global $TCA;
00763
00764 $theExcludeArray = Array();
00765 $tc_keys = array_keys($TCA);
00766 foreach($tc_keys as $table) {
00767
00768 t3lib_div::loadTCA($table);
00769
00770 if (is_array($TCA[$table]['columns'])) {
00771 $f_keys = array_keys($TCA[$table]['columns']);
00772 foreach($f_keys as $field) {
00773 if ($TCA[$table]['columns'][$field]['exclude']) {
00774
00775 $Fname = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00776
00777 $theExcludeArray[] = Array($Fname, $table.':'.$field);
00778 }
00779 }
00780 }
00781 }
00782 return $theExcludeArray;
00783 }
00784
00785
00786
00787
00788
00789
00790
00791 public static function getExplicitAuthFieldValues() {
00792 global $TCA;
00793
00794
00795 $adLabel = array(
00796 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
00797 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
00798 );
00799
00800
00801 $allowDenyOptions = Array();
00802 $tc_keys = array_keys($TCA);
00803 foreach($tc_keys as $table) {
00804
00805
00806 t3lib_div::loadTCA($table);
00807
00808
00809 if (is_array($TCA[$table]['columns'])) {
00810 $f_keys = array_keys($TCA[$table]['columns']);
00811 foreach($f_keys as $field) {
00812 $fCfg = $TCA[$table]['columns'][$field]['config'];
00813 if ($fCfg['type']=='select' && $fCfg['authMode']) {
00814
00815
00816 if (is_array($fCfg['items'])) {
00817
00818 $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00819
00820
00821 foreach($fCfg['items'] as $iVal) {
00822 if (strcmp($iVal[1], '')) {
00823
00824
00825 $iMode = '';
00826 switch((string)$fCfg['authMode']) {
00827 case 'explicitAllow':
00828 $iMode = 'ALLOW';
00829 break;
00830 case 'explicitDeny':
00831 $iMode = 'DENY';
00832 break;
00833 case 'individual':
00834 if (!strcmp($iVal[4], 'EXPL_ALLOW')) {
00835 $iMode = 'ALLOW';
00836 } elseif (!strcmp($iVal[4], 'EXPL_DENY')) {
00837 $iMode = 'DENY';
00838 }
00839 break;
00840 }
00841
00842
00843 if ($iMode) {
00844 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
00845 }
00846 }
00847 }
00848 }
00849 }
00850 }
00851 }
00852 }
00853
00854 return $allowDenyOptions;
00855 }
00856
00857
00858
00859
00860
00861
00862 public static function getSystemLanguages() {
00863
00864
00865 $sysLanguages = array();
00866 $sysLanguages[] = array('Default language', 0);
00867
00868
00869 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag', 'sys_language', 'pid=0' . self::deleteClause('sys_language'));
00870 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00871 $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
00872 }
00873 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00874
00875 return $sysLanguages;
00876 }
00877
00878
00879
00880
00881
00882
00883
00884 public static function isTableLocalizable($table) {
00885 $isLocalizable = false;
00886 if (isset($GLOBALS['TCA'][$table]['ctrl']) && is_array($GLOBALS['TCA'][$table]['ctrl'])) {
00887 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
00888 $isLocalizable = (isset($tcaCtrl['languageField']) && $tcaCtrl['languageField'] && isset($tcaCtrl['transOrigPointerField']) && $tcaCtrl['transOrigPointerField']);
00889 }
00890 return $isLocalizable;
00891 }
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902 public static function getInlineLocalizationMode($table, $fieldOrConfig) {
00903 $localizationMode = false;
00904 if (is_array($fieldOrConfig) && count($fieldOrConfig)) {
00905 $config = $fieldOrConfig;
00906 } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
00907 $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
00908 }
00909 if (is_array($config) && isset($config['type']) && $config['type']=='inline' && self::isTableLocalizable($table)) {
00910 $localizationMode = (isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode'] ? $config['behaviour']['localizationMode'] : 'select');
00911
00912 if ($localizationMode=='select' && !self::isTableLocalizable($config['foreign_table'])) {
00913 $localizationMode = false;
00914 }
00915 }
00916 return $localizationMode;
00917 }
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929 public static function readPageAccess($id, $perms_clause) {
00930 if ((string)$id!='') {
00931 $id = intval($id);
00932 if (!$id) {
00933 if ($GLOBALS['BE_USER']->isAdmin()) {
00934 $path = '/';
00935 $pageinfo['_thePath'] = $path;
00936 return $pageinfo;
00937 }
00938 } else {
00939 $pageinfo = self::getRecord('pages', $id, '*', ($perms_clause ? ' AND ' . $perms_clause : ''));
00940 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id, $perms_clause)) {
00941 self::workspaceOL('pages', $pageinfo);
00942 if (is_array($pageinfo)) {
00943 self::fixVersioningPid('pages', $pageinfo);
00944 list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = self::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
00945 return $pageinfo;
00946 }
00947 }
00948 }
00949 }
00950 return false;
00951 }
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962 public static function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
00963 global $TCA;
00964
00965 t3lib_div::loadTCA($table);
00966 if ($TCA[$table]) {
00967
00968
00969 $fieldValue = self::getTCAtypeValue($table, $rec);
00970
00971
00972 $typesConf = $TCA[$table]['types'][$fieldValue];
00973
00974
00975 $fieldList = explode(',', $typesConf['showitem']);
00976 $altFieldList = array();
00977
00978
00979 foreach($fieldList as $k => $v) {
00980 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
00981 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
00982 $specConfParts = self::getSpecConfParts($pSpec, $defaultExtras);
00983
00984 $fieldList[$k] = array(
00985 'field' => $pFieldName,
00986 'title' => $pAltTitle,
00987 'palette' => $pPalette,
00988 'spec' => $specConfParts,
00989 'origString' => $v
00990 );
00991 if ($useFieldNameAsKey) {
00992 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
00993 }
00994 }
00995 if ($useFieldNameAsKey) {
00996 $fieldList = $altFieldList;
00997 }
00998
00999
01000 return $fieldList;
01001 }
01002 }
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015 public static function getTCAtypeValue($table, $rec) {
01016 global $TCA;
01017
01018
01019 t3lib_div::loadTCA($table);
01020 if ($TCA[$table]) {
01021 $field = $TCA[$table]['ctrl']['type'];
01022 $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
01023 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
01024 return $fieldValue;
01025 }
01026 }
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038 public static function getSpecConfParts($str, $defaultExtras) {
01039
01040
01041 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
01042
01043 $reg = array();
01044 if (count($specConfParts)) {
01045 foreach($specConfParts as $k2 => $v2) {
01046 unset($specConfParts[$k2]);
01047 if (preg_match('/(.*)\[(.*)\]/', $v2, $reg)) {
01048 $specConfParts[trim($reg[1])] = array(
01049 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
01050 );
01051 } else {
01052 $specConfParts[trim($v2)] = 1;
01053 }
01054 }
01055 } else {
01056 $specConfParts = array();
01057 }
01058 return $specConfParts;
01059 }
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069 public static function getSpecConfParametersFromArray($pArr) {
01070 $out = array();
01071 if (is_array($pArr)) {
01072 foreach ($pArr as $k => $v) {
01073 $parts = explode('=', $v, 2);
01074 if (count($parts)==2) {
01075 $out[trim($parts[0])] = trim($parts[1]);
01076 } else {
01077 $out[$k] = $v;
01078 }
01079 }
01080 }
01081 return $out;
01082 }
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098 public static function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = TRUE, $newRecordPidValue = 0) {
01099 global $TYPO3_CONF_VARS;
01100
01101
01102 $ds_pointerField = $conf['ds_pointerField'];
01103 $ds_array = $conf['ds'];
01104 $ds_tableField = $conf['ds_tableField'];
01105 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
01106
01107
01108 $dataStructArray = '';
01109 if (is_array($ds_array)) {
01110
01111 if ($ds_pointerField) {
01112
01113
01114 $pointerFields = t3lib_div::trimExplode(',', $ds_pointerField);
01115 if(count($pointerFields) == 2) {
01116 if($ds_array[$row[$pointerFields[0]].','.$row[$pointerFields[1]]]) {
01117 $srcPointer = $row[$pointerFields[0]].','.$row[$pointerFields[1]];
01118 } elseif($ds_array[$row[$pointerFields[1]].',*']) {
01119 $srcPointer = $row[$pointerFields[1]].',*';
01120 } elseif($ds_array['*,'.$row[$pointerFields[1]]]) {
01121 $srcPointer = '*,'.$row[$pointerFields[1]];
01122 } elseif($ds_array[$row[$pointerFields[0]]]) {
01123 $srcPointer = $row[$pointerFields[0]];
01124 }
01125 } else {
01126 $srcPointer = $row[$pointerFields[0]];
01127 }
01128
01129 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
01130 } else $srcPointer = 'default';
01131
01132
01133 if (substr($ds_array[$srcPointer], 0, 5)=='FILE:') {
01134 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
01135 if ($file && @is_file($file)) {
01136 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01137 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer], 5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")';
01138 } else {
01139 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
01140 }
01141
01142 } elseif ($ds_pointerField) {
01143
01144 $srcPointer = $row[$ds_pointerField];
01145
01146
01147 if ($ds_searchParentField && !$srcPointer) {
01148 $rr = self::getRecord($table, $row['uid'], 'uid,' . $ds_searchParentField);
01149 if ($WSOL) {
01150 self::workspaceOL($table, $rr);
01151 self::fixVersioningPid($table, $rr, TRUE);
01152 }
01153 $uidAcc = array();
01154 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
01155 while(!$srcPointer) {
01156
01157 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01158 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),
01159 $table,
01160 'uid=' . intval($newRecordPidValue ? $newRecordPidValue : $rr[$ds_searchParentField]) . self::deleteClause($table) ###NOTE_A###
01161 );
01162 $newRecordPidValue = 0;
01163 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01164 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01165
01166
01167 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break;
01168 $uidAcc[$rr['uid']] = 1;
01169
01170 if ($WSOL) {
01171 self::workspaceOL($table, $rr);
01172 self::fixVersioningPid($table, $rr, TRUE);
01173 }
01174 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
01175 }
01176 }
01177
01178
01179 if ($srcPointer) {
01180 if (t3lib_div::testInt($srcPointer)) {
01181 list($tName, $fName) = explode(':', $ds_tableField, 2);
01182 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
01183 $dataStructRec = self::getRecord($tName, $srcPointer);
01184 if ($WSOL) {
01185 self::workspaceOL($tName, $dataStructRec);
01186 }
01187 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
01188 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
01189 } else {
01190 $file = t3lib_div::getFileAbsFileName($srcPointer);
01191 if ($file && @is_file($file)) {
01192 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01193 } else $dataStructArray = 'The file "'.$srcPointer.'" was not found ("'.$file.'")';
01194 }
01195 } else $dataStructArray = 'No source value in fieldname "'.$ds_pointerField.'"';
01196 } else $dataStructArray = 'No proper configuration!';
01197
01198
01199 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
01200 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
01201 $hookObj = t3lib_div::getUserObj($classRef);
01202 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
01203 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
01204 }
01205 }
01206 }
01207
01208 return $dataStructArray;
01209 }
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245 public static function storeHash($hash, $data, $ident) {
01246 if (TYPO3_UseCachingFramework) {
01247 $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set(
01248 $hash,
01249 $data,
01250 array('ident_' . $ident),
01251 0
01252 );
01253 } else {
01254 $insertFields = array(
01255 'hash' => $hash,
01256 'content' => $data,
01257 'ident' => $ident,
01258 'tstamp' => $GLOBALS['EXEC_TIME']
01259 );
01260 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
01261 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
01262 }
01263 }
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274 public static function getHash($hash, $expTime = 0) {
01275 $hashContent = null;
01276 if (TYPO3_UseCachingFramework) {
01277 $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
01278 $cacheEntry = $contentHashCache->get($hash);
01279
01280 if ($cacheEntry) {
01281 $hashContent = $cacheEntry;
01282 }
01283 } else {
01284 $expTime = intval($expTime);
01285 if ($expTime) {
01286 $whereAdd = ' AND tstamp > '.(time()-$expTime);
01287 }
01288 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
01289 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01290 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01291
01292 $hashContent = (is_array($row) ? $row['content'] : null);
01293 }
01294 return $hashContent;
01295 }
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321 public static function getPagesTSconfig($id, $rootLine = '', $returnPartArray = 0) {
01322 $id = intval($id);
01323 if (!is_array($rootLine)) {
01324 $rootLine = self::BEgetRootLine($id, '', TRUE);
01325 }
01326 ksort($rootLine);
01327 $TSdataArray = array();
01328 $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
01329 foreach($rootLine as $k => $v) {
01330 $TSdataArray['uid_'.$v['uid']] = $v['TSconfig'];
01331 }
01332 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
01333 if ($returnPartArray) {
01334 return $TSdataArray;
01335 }
01336
01337
01338 $pageTS = implode(LF . '[GLOBAL]' . LF, $TSdataArray);
01339 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['TSconfigConditions']) {
01340
01341 $parseObj = t3lib_div::makeInstance('t3lib_TSparser_TSconfig');
01342 $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
01343 if ($res) {
01344 $TSconfig = $res['TSconfig'];
01345 }
01346 } else {
01347 $hash = md5('pageTS:' . $pageTS);
01348 $cachedContent = self::getHash($hash);
01349 $TSconfig = array();
01350 if (isset($cachedContent)) {
01351 $TSconfig = unserialize($cachedContent);
01352 } else {
01353 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
01354 $parseObj->parse($pageTS);
01355 $TSconfig = $parseObj->setup;
01356 self::storeHash($hash, serialize($TSconfig), 'PAGES_TSconfig');
01357 }
01358 }
01359
01360
01361 $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
01362 if (is_array($userTSconfig)) {
01363 $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
01364 }
01365 return $TSconfig;
01366 }
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386 public static function updatePagesTSconfig($id, $pageTS, $TSconfPrefix, $impParams = '') {
01387 $id = intval($id);
01388 if (is_array($pageTS) && $id>0) {
01389 if (!is_array($impParams)) {
01390 $impParams = self::implodeTSParams(self::getPagesTSconfig($id));
01391 }
01392 $set = array();
01393 foreach ($pageTS as $f => $v) {
01394 $f = $TSconfPrefix.$f;
01395 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]), trim($v))) {
01396 $set[$f] = trim($v);
01397 }
01398 }
01399 if (count($set)) {
01400
01401 $pRec = self::getRecord('pages', $id);
01402 $TSlines = explode(LF, $pRec['TSconfig']);
01403 $TSlines = array_reverse($TSlines);
01404
01405 foreach ($set as $f => $v) {
01406 $inserted = 0;
01407 foreach ($TSlines as $ki => $kv) {
01408 if (substr($kv, 0, strlen($f)+1)==$f.'=') {
01409 $TSlines[$ki] = $f.'='.$v;
01410 $inserted = 1;
01411 break;
01412 }
01413 }
01414 if (!$inserted) {
01415 $TSlines = array_reverse($TSlines);
01416 $TSlines[] = $f.'='.$v;
01417 $TSlines = array_reverse($TSlines);
01418 }
01419 }
01420 $TSlines = array_reverse($TSlines);
01421
01422
01423 $TSconf = implode(LF, $TSlines);
01424
01425 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
01426 }
01427 }
01428 }
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438 public static function implodeTSParams($p, $k = '') {
01439 $implodeParams = array();
01440 if (is_array($p)) {
01441 foreach ($p as $kb => $val) {
01442 if (is_array($val)) {
01443 $implodeParams = array_merge($implodeParams, self::implodeTSParams($val, $k . $kb));
01444 } else {
01445 $implodeParams[$k.$kb] = $val;
01446 }
01447 }
01448 }
01449 return $implodeParams;
01450 }
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464
01465
01466
01467
01468
01469
01470
01471
01472
01473
01474 public static function getUserNames($fields = 'username,usergroup,usergroup_cached_list,uid', $where = '') {
01475 $be_user_Array = Array();
01476
01477 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 ' . $where . self::deleteClause('be_users'), '', 'username');
01478 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01479 $be_user_Array[$row['uid']] = $row;
01480 }
01481 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01482
01483 return $be_user_Array;
01484 }
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494 public static function getGroupNames($fields = 'title,uid', $where = '') {
01495 $be_group_Array = Array();
01496
01497 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 ' . $where . self::deleteClause('be_groups'), '', 'title');
01498 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01499 $be_group_Array[$row['uid']] = $row;
01500 }
01501 $GLOBALS['TYPO3_DB']->sql_free_result($res);
01502
01503 return $be_group_Array;
01504 }
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514 public static function getListGroupNames($fields = 'title, uid') {
01515 $exQ = ' AND hide_in_lists=0';
01516 if (!$GLOBALS['BE_USER']->isAdmin()) {
01517 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
01518 }
01519 return self::getGroupNames($fields, $exQ);
01520 }
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533 public static function blindUserNames($usernames, $groupArray, $excludeBlindedFlag = 0) {
01534 if (is_array($usernames) && is_array($groupArray)) {
01535 foreach ($usernames as $uid => $row) {
01536 $userN = $uid;
01537 $set = 0;
01538 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
01539 foreach ($groupArray as $v) {
01540 if ($v && t3lib_div::inList($row['usergroup_cached_list'], $v)) {
01541 $userN = $row['username'];
01542 $set = 1;
01543 }
01544 }
01545 } else {
01546 $userN = $row['username'];
01547 $set = 1;
01548 }
01549 $usernames[$uid]['username'] = $userN;
01550 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
01551 }
01552 }
01553 return $usernames;
01554 }
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565 public static function blindGroupNames($groups, $groupArray, $excludeBlindedFlag = 0) {
01566 if (is_array($groups) && is_array($groupArray)) {
01567 foreach ($groups as $uid => $row) {
01568 $groupN = $uid;
01569 $set = 0;
01570 if (t3lib_div::inArray($groupArray, $uid)) {
01571 $groupN = $row['title'];
01572 $set = 1;
01573 }
01574 $groups[$uid]['title'] = $groupN;
01575 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
01576 }
01577 }
01578 return $groups;
01579 }
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606 public static function daysUntil($tstamp) {
01607 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
01608 return ceil($delta_t/(3600*24));
01609 }
01610
01611
01612
01613
01614
01615
01616
01617
01618 public static function date($tstamp) {
01619 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], (int)$tstamp);
01620 }
01621
01622
01623
01624
01625
01626
01627
01628
01629 public static function datetime($value) {
01630 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
01631 }
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641
01642 public static function time($value, $withSeconds = TRUE) {
01643 $hh = floor($value/3600);
01644 $min = floor(($value-$hh*3600)/60);
01645 $sec = $value-$hh*3600-$min*60;
01646 $l = sprintf('%02d', $hh).':'.sprintf('%02d', $min);
01647 if ($withSeconds) {
01648 $l .= ':'.sprintf('%02d', $sec);
01649 }
01650 return $l;
01651 }
01652
01653
01654
01655
01656
01657
01658
01659
01660
01661 public static function calcAge($seconds, $labels = 'min|hrs|days|yrs') {
01662 $labelArr = explode('|', $labels);
01663 $prefix = '';
01664 if ($seconds<0) {$prefix = '-'; $seconds = abs($seconds);}
01665 if ($seconds<3600) {
01666 $seconds = round ($seconds/60).' '.trim($labelArr[0]);
01667 } elseif ($seconds<24*3600) {
01668 $seconds = round ($seconds/3600).' '.trim($labelArr[1]);
01669 } elseif ($seconds<365*24*3600) {
01670 $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
01671 } else {
01672 $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
01673 }
01674 return $prefix.$seconds;
01675 }
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687 public static function dateTimeAge($tstamp, $prefix = 1, $date = '') {
01688 return $tstamp ?
01689 ($date=='date' ? self::date($tstamp) : self::datetime($tstamp)) .
01690 ' (' . self::calcAge($prefix * ($GLOBALS['EXEC_TIME'] - $tstamp), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) . ')'
01691 : '';
01692 }
01693
01694
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706 public static function titleAttrib($content = '', $hsc = 0) {
01707 t3lib_div::logDeprecatedFunction();
01708
01709 global $CLIENT;
01710 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
01711 return strcmp($content, '')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
01712 }
01713
01714
01715
01716
01717
01718
01719
01720
01721 public static function titleAltAttrib($content) {
01722 $out = '';
01723 $out.=' alt="'.htmlspecialchars($content).'"';
01724 $out.=' title="'.htmlspecialchars($content).'"';
01725 return $out;
01726 }
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745 public static function thumbCode($row, $table, $field, $backPath, $thumbScript = '', $uploaddir = NULL, $abs = 0, $tparams = '', $size = '') {
01746 global $TCA;
01747
01748 t3lib_div::loadTCA($table);
01749
01750
01751 $uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
01752 $uploaddir = preg_replace('#/$#','', $uploaddir);
01753
01754
01755 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
01756 $thumbScript = 'gfx/notfound_thumb.gif';
01757 } elseif(!$thumbScript) {
01758 $thumbScript = 'thumbs.php';
01759 }
01760
01761 $sizeParts = array();
01762 if ($size = trim($size)) {
01763 $sizeParts = explode('x', $size.'x'.$size);
01764 if(!intval($sizeParts[0])) $size = '';
01765 }
01766
01767
01768 $thumbs = explode(',', $row[$field]);
01769 $thumbData = '';
01770 foreach ($thumbs as $theFile) {
01771 if (trim($theFile)) {
01772 $fI = t3lib_div::split_fileref($theFile);
01773 $ext = $fI['fileext'];
01774
01775 $max = 0;
01776 if (t3lib_div::inList('gif,jpg,png', $ext)) {
01777 $imgInfo = @getimagesize(PATH_site.$uploaddir.'/'.$theFile);
01778 if (is_array($imgInfo)) {$max = max($imgInfo[0], $imgInfo[1]);}
01779 }
01780
01781 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
01782 $theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01783 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01784 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
01785
01786 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $ext)) {
01787 $theFile_abs = PATH_site.($uploaddir?$uploaddir.'/':'').trim($theFile);
01788 $theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01789
01790 if (!is_readable($theFile_abs)) {
01791 $flashMessage = t3lib_div::makeInstance(
01792 't3lib_FlashMessage',
01793 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_missing_text') . ' <abbr title="' . $theFile_abs . '">' . $theFile . '</abbr>',
01794 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_missing'),
01795 t3lib_FlashMessage::ERROR
01796 );
01797 $thumbData .= $flashMessage->render();
01798 continue;
01799 }
01800
01801 $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01802 $params = '&file='.rawurlencode($theFile);
01803 $params.= $size?'&size='.$size:'';
01804 $params.= '&md5sum='.t3lib_div::shortMD5($check);
01805
01806 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01807 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01808 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
01809 } else {
01810 $icon = self::getFileIcon($ext);
01811 $url = 'gfx/fileicons/'.$icon;
01812 $thumbData.= '<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
01813 }
01814 }
01815 }
01816 return $thumbData;
01817 }
01818
01819
01820
01821
01822
01823
01824
01825
01826
01827
01828
01829 public static function getThumbNail($thumbScript, $theFile, $tparams = '', $size = '') {
01830 $check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01831 $params = '&file='.rawurlencode($theFile);
01832 $params.= trim($size)?'&size='.trim($size):'';
01833 $params.= '&md5sum='.t3lib_div::shortMD5($check);
01834
01835 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01836 $th = '<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
01837 return $th;
01838 }
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849 public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = 1) {
01850 global $TCA, $LANG;
01851 $parts = array();
01852 $parts[] = 'id='.$row['uid'];
01853 if ($row['alias']) $parts[] = $LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
01854 if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id'];
01855
01856 switch($row['t3ver_state']) {
01857 case 1:
01858 $parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
01859 break;
01860 case 2:
01861 $parts[] = 'Deleted element!';
01862 break;
01863 case 3:
01864 $parts[] = 'NEW LOCATION (PLH) WSID#'.$row['t3ver_wsid'];
01865 break;
01866 case 4:
01867 $parts[] = 'OLD LOCATION (PNT) WSID#'.$row['t3ver_wsid'];
01868 break;
01869 case -1:
01870 $parts[] = 'New element!';
01871 break;
01872 }
01873
01874 if ($row['doktype']=='3') {
01875 $parts[] = $LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
01876 } elseif ($row['doktype']=='4') {
01877 if ($perms_clause) {
01878 $label = self::getRecordPath(intval($row['shortcut']), $perms_clause, 20);
01879 } else {
01880 $lRec = self::getRecordWSOL('pages', intval($row['shortcut']), 'title');
01881 $label = $lRec['title'];
01882 }
01883 if ($row['shortcut_mode']>0) {
01884 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
01885 $LANG->sL(self::getLabelFromItemlist('pages', 'shortcut_mode', $row['shortcut_mode']));
01886 }
01887 $parts[] = $LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
01888 } elseif ($row['doktype']=='7') {
01889 if ($perms_clause) {
01890 $label = self::getRecordPath(intval($row['mount_pid']), $perms_clause, 20);
01891 } else {
01892 $lRec = self::getRecordWSOL('pages', intval($row['mount_pid']), 'title');
01893 $label = $lRec['title'];
01894 }
01895 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
01896 if ($row['mount_pid_ol']) {
01897 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
01898 }
01899 }
01900 if ($row['nav_hide']) $parts[] = rtrim($LANG->sL($TCA['pages']['columns']['nav_hide']['label']), ':');
01901 if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
01902 if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']) . ' ' . self::dateTimeAge($row['starttime'], -1, 'date');
01903 if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']) . ' ' . self::dateTimeAge($row['endtime'], -1, 'date');
01904 if ($row['fe_group']) {
01905 $fe_groups = array();
01906 foreach (t3lib_div::intExplode(',', $row['fe_group']) as $fe_group) {
01907 if ($fe_group<0) {
01908 $fe_groups[] = $LANG->sL(self::getLabelFromItemlist('pages', 'fe_group', $fe_group));
01909 } else {
01910 $lRec = self::getRecordWSOL('fe_groups', $fe_group, 'title');
01911 $fe_groups[] = $lRec['title'];
01912 }
01913 }
01914 $label = implode(', ', $fe_groups);
01915 $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
01916 }
01917 $out = htmlspecialchars(implode(' - ', $parts));
01918 return $includeAttrib ? 'title="'.$out.'"' : $out;
01919 }
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929
01930
01931 public static function getRecordIconAltText($row, $table = 'pages') {
01932 if ($table=='pages') {
01933 $out = self::titleAttribForPages($row, '', 0);
01934 } else {
01935 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
01936
01937 $out = 'id='.$row['uid'];
01938 if ($table=='pages' && $row['alias']) {
01939 $out.=' / '.$row['alias'];
01940 }
01941 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
01942 $out.=' - v#1.'.$row['t3ver_id'];
01943 }
01944 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
01945 switch($row['t3ver_state']) {
01946 case 1:
01947 $out.= ' - PLH WSID#'.$row['t3ver_wsid'];
01948 break;
01949 case 2:
01950 $out.= ' - Deleted element!';
01951 break;
01952 case 3:
01953 $out.= ' - NEW LOCATION (PLH) WSID#'.$row['t3ver_wsid'];
01954 break;
01955 case 4:
01956 $out.= ' - OLD LOCATION (PNT) WSID#'.$row['t3ver_wsid'];
01957 break;
01958 case -1:
01959 $out.= ' - New element!';
01960 break;
01961 }
01962 }
01963
01964 if ($ctrl['disabled']) {
01965 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
01966 }
01967 if ($ctrl['starttime']) {
01968 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
01969 $out .= ' - ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.starttime') . ':' .
01970 self::date($row[$ctrl['starttime']]) . ' (' . self::daysUntil($row[$ctrl['starttime']]) . ' ' .
01971 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.days') . ')';
01972 }
01973 }
01974 if ($row[$ctrl['endtime']]) {
01975 $out .= ' - ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.endtime') . ': ' .
01976 self::date($row[$ctrl['endtime']]) . ' (' . self::daysUntil($row[$ctrl['endtime']]) . ' ' .
01977 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.days') . ')';
01978 }
01979 }
01980 return htmlspecialchars($out);
01981 }
01982
01983
01984
01985
01986
01987
01988
01989
01990
01991
01992 public static function getLabelFromItemlist($table, $col, $key) {
01993 global $TCA;
01994
01995 t3lib_div::loadTCA($table);
01996
01997
01998 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
01999
02000 foreach ($TCA[$table]['columns'][$col]['config']['items'] as $k => $v) {
02001
02002 if (!strcmp($v[1], $key)) return $v[0];
02003 }
02004 }
02005 }
02006
02007
02008
02009
02010
02011
02012
02013
02014
02015
02016
02017 public static function getItemLabel($table, $col, $printAllWrap = '') {
02018 global $TCA;
02019
02020 t3lib_div::loadTCA($table);
02021
02022 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
02023
02024 return $TCA[$table]['columns'][$col]['label'];
02025 }
02026 if ($printAllWrap) {
02027 $parts = explode('|', $printAllWrap);
02028 return $parts[0].$col.$parts[1];
02029 }
02030 }
02031
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043 public static function getRecordTitle($table, $row, $prep = FALSE, $forceResult = TRUE) {
02044 global $TCA;
02045 if (is_array($TCA[$table])) {
02046
02047
02048 if ($TCA[$table]['ctrl']['label_userFunc']) {
02049 $params['table'] = $table;
02050 $params['row'] = $row;
02051 $params['title'] = '';
02052
02053 t3lib_div::callUserFunction($TCA[$table]['ctrl']['label_userFunc'], $params, $this);
02054 $t = $params['title'];
02055 } else {
02056
02057
02058 $t = self::getProcessedValue($table, $TCA[$table]['ctrl']['label'], $row[$TCA[$table]['ctrl']['label']], 0, 0, false, $row['uid'], $forceResult);
02059 if ($TCA[$table]['ctrl']['label_alt'] && ($TCA[$table]['ctrl']['label_alt_force'] || !strcmp($t, ''))) {
02060 $altFields = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['label_alt'], 1);
02061 $tA = array();
02062 if (!empty($t)) $tA[] = $t;
02063 foreach ($altFields as $fN) {
02064 $t = trim(strip_tags($row[$fN]));
02065 if (strcmp($t, '')) {
02066 $t = self::getProcessedValue($table, $fN, $t, 0, 0, false, $row['uid']);
02067 if (!$TCA[$table]['ctrl']['label_alt_force']) {
02068 break;
02069 }
02070 $tA[] = $t;
02071 }
02072 }
02073 if ($TCA[$table]['ctrl']['label_alt_force']) {
02074 $t = implode(', ', $tA);
02075 }
02076 }
02077 }
02078
02079
02080 if ($prep || $forceResult) {
02081 if ($prep) {
02082 $t = self::getRecordTitlePrep($t);
02083 }
02084 if (!strcmp(trim($t), '')) {
02085 $t = self::getNoRecordTitle($prep);
02086 }
02087 }
02088
02089 return $t;
02090 }
02091 }
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101 public static function getRecordTitlePrep($title, $titleLength = 0) {
02102
02103 if (!$titleLength || !t3lib_div::testInt($titleLength) || $titleLength < 0) {
02104 $titleLength = $GLOBALS['BE_USER']->uc['titleLen'];
02105 }
02106 $titleOrig = htmlspecialchars($title);
02107 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($title, $titleLength));
02108
02109 if ($titleOrig != $title) {
02110 $title = '<span title="'.$titleOrig.'">'.$title.'</span>';
02111 }
02112 return $title;
02113 }
02114
02115
02116
02117
02118
02119
02120
02121 public static function getNoRecordTitle($prep = FALSE) {
02122 $noTitle = '['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title', 1).']';
02123 if ($prep) $noTitle = '<em>'.$noTitle.'</em>';
02124 return $noTitle;
02125 }
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144 public static function getProcessedValue($table, $col, $value, $fixed_lgd_chars = 0, $defaultPassthrough = 0, $noRecordLookup = FALSE, $uid = 0, $forceResult = TRUE) {
02145 global $TCA;
02146 global $TYPO3_CONF_VARS;
02147
02148 if ($col == 'uid') {
02149
02150 return $value;
02151 }
02152
02153 t3lib_div::loadTCA($table);
02154
02155 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
02156
02157 $theColConf = $TCA[$table]['columns'][$col]['config'];
02158
02159
02160
02161
02162 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) {
02163 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) {
02164 t3lib_div::callUserFunction($_funcRef,$theColConf,$this);
02165 }
02166 }
02167
02168 $l = '';
02169 switch((string)$theColConf['type']) {
02170 case 'radio':
02171 $l = self::getLabelFromItemlist($table, $col, $value);
02172 $l = $GLOBALS['LANG']->sL($l);
02173 break;
02174 case 'select':
02175 if ($theColConf['MM']) {
02176
02177 if ($noRecordLookup) {
02178 $MMfield = $theColConf['foreign_table'].'.uid';
02179 } else {
02180 $MMfields = array($theColConf['foreign_table'].'.'.$TCA[$theColConf['foreign_table']]['ctrl']['label']);
02181 foreach (t3lib_div::trimExplode(',', $TCA[$theColConf['foreign_table']]['ctrl']['label_alt'], 1) as $f) {
02182 $MMfields[] = $theColConf['foreign_table'].'.'.$f;
02183 }
02184 $MMfield = join(',',$MMfields);
02185 }
02186
02187 $dbGroup = t3lib_div::makeInstance('t3lib_loadDBGroup');
02188 $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
02189 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']];
02190
02191 if (is_array($selectUids) && count($selectUids)>0) {
02192 $MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
02193 'uid, '.$MMfield,
02194 $theColConf['foreign_table'],
02195 'uid IN ('.implode(',', $selectUids).')'
02196 );
02197 while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres)) {
02198 $mmlA[] = ($noRecordLookup ? $MMrow['uid'] : self::getRecordTitle($theColConf['foreign_table'], $MMrow, FALSE, $forceResult));
02199 }
02200 $GLOBALS['TYPO3_DB']->sql_free_result($MMres);
02201
02202 if (is_array($mmlA)) {
02203 $l = implode('; ', $mmlA);
02204 } else {
02205 $l = '';
02206 }
02207 } else {
02208 $l = 'N/A';
02209 }
02210 } else {
02211 $l = self::getLabelFromItemlist($table, $col, $value);
02212 $l = $GLOBALS['LANG']->sL($l);
02213 if ($theColConf['foreign_table'] && !$l && $TCA[$theColConf['foreign_table']]) {
02214 if ($noRecordLookup) {
02215 $l = $value;
02216 } else {
02217 $rParts = t3lib_div::trimExplode(',', $value, 1);
02218 $lA = array();
02219 foreach ($rParts as $rVal) {
02220 $rVal = intval($rVal);
02221 if ($rVal>0) {
02222 $r = self::getRecordWSOL($theColConf['foreign_table'], $rVal);
02223 } else {
02224 $r = self::getRecordWSOL($theColConf['neg_foreign_table'], -$rVal);
02225 }
02226 if (is_array($r)) {
02227 $lA[] = $GLOBALS['LANG']->sL($rVal>0?$theColConf['foreign_table_prefix']:$theColConf['neg_foreign_table_prefix']) . self::getRecordTitle($rVal>0?$theColConf['foreign_table']:$theColConf['neg_foreign_table'], $r, FALSE, $forceResult);
02228 } else {
02229 $lA[] = $rVal?'['.$rVal.'!]':'';
02230 }
02231 }
02232 $l = implode(', ', $lA);
02233 }
02234 }
02235 }
02236 break;
02237 case 'group':
02238 $l = implode(', ', t3lib_div::trimExplode(',', $value, 1));
02239 break;
02240 case 'check':
02241 if (!is_array($theColConf['items']) || count($theColConf['items'])==1) {
02242 $l = $value ? $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes') : $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:no');
02243 } else {
02244 $lA = Array();
02245 foreach ($theColConf['items'] as $key => $val) {
02246 if ($value & pow(2, $key)) {$lA[] = $GLOBALS['LANG']->sL($val[0]);}
02247 }
02248 $l = implode(', ', $lA);
02249 }
02250 break;
02251 case 'input':
02252 if (isset($value)) {
02253 if (t3lib_div::inList($theColConf['eval'], 'date')) {
02254 $l = self::date($value) .
02255 ' (' .
02256 ($GLOBALS['EXEC_TIME'] - $value > 0 ? '-' : '') .
02257 self::calcAge(abs($GLOBALS['EXEC_TIME'] - $value), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) .
02258 ')';
02259 } elseif (t3lib_div::inList($theColConf['eval'], 'time')) {
02260 $l = self::time($value, FALSE);
02261 } elseif (t3lib_div::inList($theColConf['eval'], 'timesec')) {
02262 $l = self::time($value);
02263 } elseif (t3lib_div::inList($theColConf['eval'], 'datetime')) {
02264 $l = self::datetime($value);
02265 } else {
02266 $l = $value;
02267 }
02268 }
02269 break;
02270 case 'flex':
02271 $l = strip_tags($value);
02272 break;
02273 default:
02274 if ($defaultPassthrough) {
02275 $l = $value;
02276 } elseif ($theColConf['MM']) {
02277 $l = 'N/A';
02278 } elseif ($value) {
02279 $l = t3lib_div::fixed_lgd_cs(strip_tags($value), 200);
02280 }
02281 break;
02282 }
02283
02284
02285 if (stristr($theColConf['eval'], 'password')) {
02286 unset($l);
02287 $randomNumber = rand(5, 12);
02288 for ($i=0; $i < $randomNumber; $i++) {
02289 $l .= '*';
02290 }
02291 }
02292
02293
02294
02295
02296 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) {
02297 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) {
02298 $params = array(
02299 'value' => $l,
02300 'colConf' => $theColConf
02301 );
02302 $l = t3lib_div::callUserFunction($_funcRef, $params, $this);
02303 }
02304 }
02305
02306 if ($fixed_lgd_chars) {
02307 return t3lib_div::fixed_lgd_cs($l, $fixed_lgd_chars);
02308 } else {
02309 return $l;
02310 }
02311 }
02312 }
02313
02314
02315
02316
02317
02318
02319
02320
02321
02322
02323
02324
02325
02326
02327 public static function getProcessedValueExtra($table, $fN, $fV, $fixed_lgd_chars = 0, $uid = 0, $forceResult = TRUE) {
02328 global $TCA;
02329 $fVnew = self::getProcessedValue($table, $fN, $fV, $fixed_lgd_chars, 0, 0, $uid, $forceResult);
02330 if (!isset($fVnew)) {
02331 if (is_array($TCA[$table])) {
02332 if ($fN==$TCA[$table]['ctrl']['tstamp'] || $fN==$TCA[$table]['ctrl']['crdate']) {
02333 $fVnew = self::datetime($fV);
02334 } elseif ($fN=='pid'){
02335 $fVnew = self::getRecordPath($fV, '1=1', 20);
02336 } else {
02337 $fVnew = $fV;
02338 }
02339 }
02340 }
02341 return $fVnew;
02342 }
02343
02344
02345
02346
02347
02348
02349
02350
02351 public static function getFileIcon($ext) {
02352 return $GLOBALS['FILEICONS'][$ext] ? $GLOBALS['FILEICONS'][$ext] : $GLOBALS['FILEICONS']['default'];
02353 }
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366 public static function getCommonSelectFields($table, $prefix = '', $fields = array()) {
02367 global $TCA;
02368 $fields[] = $prefix.'uid';
02369 $fields[] = $prefix.$TCA[$table]['ctrl']['label'];
02370
02371 if ($TCA[$table]['ctrl']['label_alt']) {
02372 $secondFields = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['label_alt'], 1);
02373 foreach($secondFields as $fieldN) {
02374 $fields[] = $prefix.$fieldN;
02375 }
02376 }
02377 if ($TCA[$table]['ctrl']['versioningWS']) {
02378 $fields[] = $prefix.'t3ver_id';
02379 $fields[] = $prefix.'t3ver_state';
02380 $fields[] = $prefix.'t3ver_wsid';
02381 $fields[] = $prefix.'t3ver_count';
02382 }
02383
02384 if ($TCA[$table]['ctrl']['selicon_field']) $fields[] = $prefix.$TCA[$table]['ctrl']['selicon_field'];
02385 if ($TCA[$table]['ctrl']['typeicon_column']) $fields[] = $prefix.$TCA[$table]['ctrl']['typeicon_column'];
02386
02387 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
02388 if ($TCA[$table]['ctrl']['enablecolumns']['disabled']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['disabled'];
02389 if ($TCA[$table]['ctrl']['enablecolumns']['starttime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['starttime'];
02390 if ($TCA[$table]['ctrl']['enablecolumns']['endtime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['endtime'];
02391 if ($TCA[$table]['ctrl']['enablecolumns']['fe_group']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['fe_group'];
02392 }
02393
02394 return implode(',', array_unique($fields));
02395 }
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408 public static function makeConfigForm($configArray, $defaults, $dataPrefix) {
02409 $params = $defaults;
02410 if (is_array($configArray)) {
02411 $lines = array();
02412 foreach ($configArray as $fname => $config) {
02413 if (is_array($config)) {
02414 $lines[$fname] = '<strong>'.htmlspecialchars($config[1]).'</strong><br />';
02415 $lines[$fname].=$config[2].'<br />';
02416 switch($config[0]) {
02417 case 'string':
02418 case 'short':
02419 $formEl = '<input type="text" name="'.$dataPrefix.'['.$fname.']" value="'.$params[$fname].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($config[0]=='short'?24:48).' />';
02420 break;
02421 case 'check':
02422 $formEl = '<input type="hidden" name="'.$dataPrefix.'['.$fname.']" value="0" /><input type="checkbox" name="'.$dataPrefix.'['.$fname.']" value="1"'.($params[$fname]?' checked="checked"':'').' />';
02423 break;
02424 case 'comment':
02425 $formEl = '';
02426 break;
02427 case 'select':
02428 $opt = array();
02429 foreach ($config[3] as $k => $v) {
02430 $opt[] = '<option value="'.htmlspecialchars($k).'"'.($params[$fname]==$k?' selected="selected"':'').'>'.htmlspecialchars($v).'</option>';
02431 }
02432 $formEl = '<select name="'.$dataPrefix.'['.$fname.']">'.implode('', $opt).'</select>';
02433 break;
02434 default:
02435 debug($config);
02436 break;
02437 }
02438 $lines[$fname].=$formEl;
02439 $lines[$fname].='<br /><br />';
02440 } else {
02441 $lines[$fname] = '<hr />';
02442 if ($config) $lines[$fname].='<strong>'.strtoupper(htmlspecialchars($config)).'</strong><br />';
02443 if ($config) $lines[$fname].='<br />';
02444 }
02445 }
02446 }
02447 $out = implode('', $lines);
02448 $out.='<input type="submit" name="submit" value="Update configuration" />';
02449 return $out;
02450 }
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481 public static function helpTextIcon($table, $field, $BACK_PATH, $force = 0) {
02482 global $TCA_DESCR, $BE_USER;
02483
02484 $onClick = 'vHWin=window.open(\''.$BACK_PATH.'view_help.php?tfID='.($table.'.'.$field).'\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
02485 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && (isset($BE_USER->uc['edit_showFieldHelp']) || $force)) {
02486 if ($BE_USER->uc['edit_showFieldHelp'] == 'icon') {
02487 $text = self::helpText($table, $field, $BACK_PATH, '');
02488 $text = '<div class="typo3-csh-inline">' . $GLOBALS['LANG']->hscAndCharConv($text, false) . '</div>';
02489 }
02490 return '<a class="typo3-csh-link" href="#" onclick="'.htmlspecialchars($onClick).'">' . t3lib_iconWorks::getSpriteIcon('actions-system-help-open', array('class' => 'typo3-csh-icon')) . $text.'</a>';
02491 }
02492 }
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508 public static function helpText($table, $field, $BACK_PATH, $styleAttrib = '') {
02509 global $TCA_DESCR, $BE_USER;
02510 $output = '';
02511
02512 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field])) {
02513 $data = $TCA_DESCR[$table]['columns'][$field];
02514
02515 if ($data['image_descr'] || $data['seeAlso'] || $data['details'] || $data['syntax']) {
02516 $arrow = t3lib_iconWorks::getSpriteIcon('actions-view-go-forward');
02517 }
02518
02519 if ($data['description'] || $arrow) {
02520 $output = '<p class="t3-csh-short">' . nl2br(htmlspecialchars($data['description'])) . $arrow . '</p>';
02521 }
02522
02523
02524 if ($data['alttitle']) {
02525 $output = '<h2 class="t3-row-header">' . $data['alttitle'] . '</h2>' . $output;
02526 }
02527 }
02528 return $output;
02529 }
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547 public static function cshItem($table, $field, $BACK_PATH, $wrap = '', $onlyIconMode = FALSE, $styleAttrib = '') {
02548 global $TCA_DESCR, $LANG, $BE_USER;
02549
02550 if ($BE_USER->uc['edit_showFieldHelp']) {
02551 $LANG->loadSingleTableDescription($table);
02552
02553 if (is_array($TCA_DESCR[$table])) {
02554
02555 $fullText = self::helpText($table, $field, $BACK_PATH, '');
02556 $icon = self::helpTextIcon($table, $field, $BACK_PATH);
02557
02558 if ($fullText && !$onlyIconMode && $BE_USER->uc['edit_showFieldHelp'] == 'text') {
02559
02560
02561 $params = $styleAttrib ? ' style="'.$styleAttrib.'"' : '';
02562
02563
02564 $fullText = '<table border="0" cellpadding="0" cellspacing="0" class="typo3-csh-inline"'.$params.'>
02565 <tr>
02566 <td valign="top" width="14"><div class="t3-row-header">' . $icon . '</div></td>
02567 <td valign="top">'.$fullText.'</td>
02568 </tr>
02569 </table>';
02570
02571 $output = $LANG->hscAndCharConv($fullText, false);
02572 } else {
02573 $output = $icon;
02574
02575 if ($output && $wrap) {
02576 $wrParts = explode('|', $wrap);
02577 $output = $wrParts[0].$output.$wrParts[1];
02578 }
02579 }
02580
02581 return $output;
02582 }
02583 }
02584 }
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597 public static function editOnClick($params, $backPath = '', $requestUri = '') {
02598 $retUrl = 'returnUrl='.($requestUri==-1?"'+T3_THIS_LOCATION+'":rawurlencode($requestUri?$requestUri:t3lib_div::getIndpEnv('REQUEST_URI')));
02599 return "window.location.href='".$backPath."alt_doc.php?".$retUrl.$params."'; return false;";
02600 }
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616 public static function viewOnClick($id, $backPath = '', $rootLine = '', $anchor = '', $altUrl = '', $addGetVars = '', $switchFocus = TRUE) {
02617
02618 $viewScriptPreviewEnabled = t3lib_extMgm::isLoaded('version') ?
02619 '/' . TYPO3_mainDir . t3lib_extMgm::extRelPath('version') . 'ws/wsol_preview.php?id='
02620 :
02621 '/index.php?id='
02622 ;
02623 $viewScriptPreviewDisabled = '/index.php?id=';
02624 if ($altUrl) {
02625 $viewScriptPreviewEnabled = $viewScriptPreviewDisabled = $altUrl;
02626 }
02627
02628
02629 $viewLanguageOrder = $GLOBALS['BE_USER']->getTSConfigVal('options.view.languageOrder');
02630 if (strlen($viewLanguageOrder)) {
02631 $suffix = '';
02632
02633
02634 if (!$GLOBALS['BE_USER']->user['admin'] &&
02635 strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
02636 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
02637 }
02638
02639
02640 $lOrder = t3lib_div::intExplode(',', $viewLanguageOrder);
02641 foreach($lOrder as $langUid) {
02642 if (is_array($allowed_languages) && count($allowed_languages)) {
02643 if (isset($allowed_languages[$langUid])) {
02644 $suffix = '&L=' . $langUid;
02645 break;
02646 }
02647 } else {
02648 $suffix = '&L=' . $langUid;
02649 break;
02650 }
02651 }
02652
02653 $addGetVars .= $suffix;
02654 }
02655
02656
02657 $sys_page = t3lib_div::makeInstance('t3lib_pageSelect');
02658 $sys_page->init(FALSE);
02659 $mountPointInfo = $sys_page->getMountPointInfo($id);
02660 if ($mountPointInfo && $mountPointInfo['overlay']) {
02661 $id = $mountPointInfo['mount_pid'];
02662 $addGetVars .= '&MP=' . $mountPointInfo['MPvar'];
02663 }
02664
02665 $viewDomain = self::getViewDomain($id, $rootLine);
02666 $urlPreviewEnabled = $viewDomain . $viewScriptPreviewEnabled . $id . $addGetVars . $anchor;
02667 $urlPreviewDisabled = $viewDomain . $viewScriptPreviewDisabled . $id . $addGetVars . $anchor;
02668
02669 return "var previewWin=window.open(top.TYPO3.configuration.inWorkspace !== 0 && top.TYPO3.configuration.workspaceFrontendPreviewEnabled ?'" .
02670 $urlPreviewEnabled . "':'" . $urlPreviewDisabled .
02671 "','newTYPO3frontendWindow');" . ( $switchFocus ? 'previewWin.focus();' : '');
02672 }
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685 public static function getViewDomain($pageId, $rootLine = null) {
02686 $domain = rtrim(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '/');
02687
02688 if (!is_array($rootLine)) {
02689 $rootLine = self::BEgetRootLine($pageId);
02690 }
02691
02692
02693 if (count($rootLine) > 0) {
02694 $urlParts = parse_url($domain);
02695 if (self::getDomainStartPage($urlParts['host'], $urlParts['path'])) {
02696 $protocol = t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https:
02697 $domain = $protocol . self::firstDomainRecord($rootLine);
02698 }
02699 }
02700
02701 return $domain;
02702 }
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713 public static function getModTSconfig($id, $TSref) {
02714 $pageTS_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref, self::getPagesTSconfig($id));
02715 $BE_USER_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref);
02716 $modTSconfig = t3lib_div::array_merge_recursive_overrule($pageTS_modOptions, $BE_USER_modOptions);
02717 return $modTSconfig;
02718 }
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734 public static function getFuncMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '') {
02735 if (is_array($menuItems)) {
02736 if (!is_array($mainParams)) {
02737 $mainParams = array('id' => $mainParams);
02738 }
02739 $mainParams = t3lib_div::implodeArrayForUrl('', $mainParams);
02740
02741 if (!$script) {
02742 $script = basename(PATH_thisScript);
02743 $mainParams.= (t3lib_div::_GET('M') ? '&M='.rawurlencode(t3lib_div::_GET('M')) : '');
02744 }
02745
02746 $options = array();
02747 foreach($menuItems as $value => $label) {
02748 $options[] = '<option value="'.htmlspecialchars($value).'"'.(!strcmp($currentValue, $value)?' selected="selected"':'').'>'.
02749 t3lib_div::deHSCentities(htmlspecialchars($label)).
02750 '</option>';
02751 }
02752 if (count($options)) {
02753 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+this.options[this.selectedIndex].value,this);';
02754 return '
02755
02756 <!-- Function Menu of module -->
02757 <select name="'.$elementName.'" onchange="'.htmlspecialchars($onChange).'">
02758 '.implode('
02759 ',$options).'
02760 </select>
02761 ';
02762 }
02763 }
02764 }
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780 public static function getFuncCheck($mainParams, $elementName, $currentValue, $script = '', $addparams = '', $tagParams = '') {
02781 if (!is_array($mainParams)) {
02782 $mainParams = array('id' => $mainParams);
02783 }
02784 $mainParams = t3lib_div::implodeArrayForUrl('', $mainParams);
02785
02786 if (!$script) {
02787 $script = basename(PATH_thisScript);
02788 $mainParams.= (t3lib_div::_GET('M') ? '&M='.rawurlencode(t3lib_div::_GET('M')) : '');
02789 }
02790
02791 $onClick = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+(this.checked?1:0),this);';
02792 return '<input type="checkbox" class="checkbox" name="'.$elementName.'"'.($currentValue?' checked="checked"':'').' onclick="'.htmlspecialchars($onClick).'"'.($tagParams?' '.$tagParams:'').' />';
02793 }
02794
02795
02796
02797
02798
02799
02800
02801
02802
02803
02804
02805
02806
02807
02808
02809 public static function getFuncInput($mainParams, $elementName, $currentValue, $size = 10, $script = "", $addparams = "") {
02810 if (!is_array($mainParams)) {
02811 $mainParams = array('id' => $mainParams);
02812 }
02813 $mainParams = t3lib_div::implodeArrayForUrl('', $mainParams);
02814
02815 if (!$script) {
02816 $script = basename(PATH_thisScript);
02817 $mainParams.= (t3lib_div::_GET('M') ? '&M='.rawurlencode(t3lib_div::_GET('M')) : '');
02818 }
02819
02820 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+escape(this.value),this);';
02821 return '<input type="text"'.$GLOBALS['TBE_TEMPLATE']->formWidth($size).' name="'.$elementName.'" value="'.htmlspecialchars($currentValue).'" onchange="'.htmlspecialchars($onChange).'" />';
02822 }
02823
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834 public static function unsetMenuItems($modTSconfig, $itemArray, $TSref) {
02835
02836 $conf = $GLOBALS['BE_USER']->getTSConfig($TSref, $modTSconfig);
02837 if (is_array($conf['properties'])) {
02838 foreach ($conf['properties'] as $key => $val) {
02839 if (!$val) {
02840 unset($itemArray[$key]);
02841 }
02842 }
02843 }
02844 return $itemArray;
02845 }
02846
02847
02848
02849
02850
02851
02852
02853
02854
02855
02856
02857
02858
02859
02860 public static function getSetUpdateSignal($set = '') {
02861 t3lib_div::logDeprecatedFunction();
02862
02863
02864 if ($set) {
02865 return self::setUpdateSignal($set);
02866 } else {
02867 return self::getUpdateSignalCode();
02868 }
02869 }
02870
02871
02872
02873
02874
02875
02876
02877
02878
02879
02880
02881
02882 public static function setUpdateSignal($set = '', $params = '') {
02883 global $BE_USER;
02884 $modData = $BE_USER->getModuleData('t3lib_BEfunc::getUpdateSignal', 'ses');
02885
02886 if ($set) {
02887 $modData[$set] = array(
02888 'set' => $set,
02889 'parameter' => $params);
02890 } else {
02891 $modData = array();
02892 }
02893 $BE_USER->pushModuleData('t3lib_BEfunc::getUpdateSignal', $modData);
02894 }
02895
02896
02897
02898
02899
02900
02901
02902
02903
02904
02905 public static function getUpdateSignalCode() {
02906 $signals = array();
02907 $modData = $GLOBALS['BE_USER']->getModuleData('t3lib_BEfunc::getUpdateSignal', 'ses');
02908 if (!count($modData)) {
02909 return '';
02910 }
02911
02912
02913 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['updateSignalHook'])) {
02914 $updateSignals = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['updateSignalHook'];
02915 } else {
02916 $updateSignals = array();
02917 }
02918
02919
02920 foreach ($modData as $set => $val) {
02921 if (isset($updateSignals[$set])) {
02922 $params = array('set' => $set, 'parameter' => $val['parameter'], 'JScode' => '');
02923 $ref = NULL;
02924 t3lib_div::callUserFunction($updateSignals[$set], $params, $ref);
02925 $signals[] = $params['JScode'];
02926 } else if ($set == 'updatePageTree' || $set == 'updateFolderTree') {
02927 $signals[] = '
02928 if (top && top.content && top.content.nav_frame && top.content.nav_frame.Tree) {
02929 top.content.nav_frame.Tree.refresh();
02930 }';
02931 }
02932 }
02933
02934 $content = implode(LF, $signals);
02935
02936 self::setUpdateSignal();
02937 return $content;
02938 }
02939
02940
02941
02942
02943
02944
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956 public static function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type = '', $dontValidateList = '', $setDefaultList = '') {
02957
02958 if ($modName && is_string($modName)) {
02959
02960 $settings = $GLOBALS['BE_USER']->getModuleData($modName, $type);
02961
02962 $changed = 0;
02963 if (!is_array($settings)) {
02964 $changed = 1;
02965 $settings = array();
02966 }
02967 if (is_array($MOD_MENU)) {
02968 foreach ($MOD_MENU as $key=>$var) {
02969
02970
02971 if (is_array($CHANGED_SETTINGS) && isset($CHANGED_SETTINGS[$key])) {
02972 if (is_array($CHANGED_SETTINGS[$key])) {
02973 $serializedSettings = serialize($CHANGED_SETTINGS[$key]);
02974 if (strcmp($settings[$key], $serializedSettings)) {
02975 $settings[$key] = $serializedSettings;
02976 $changed = 1;
02977 }
02978 } else {
02979 if (strcmp($settings[$key], $CHANGED_SETTINGS[$key]) ) {
02980 $settings[$key] = $CHANGED_SETTINGS[$key];
02981 $changed = 1;
02982 }
02983 }
02984 }
02985
02986
02987 if (is_array($var) && (!$dontValidateList || !t3lib_div::inList($dontValidateList, $key))) {
02988
02989 if (is_array($settings[$key]) || !isset($MOD_MENU[$key][$settings[$key]])) {
02990 $settings[$key] = (string)key($var);
02991 $changed = 1;
02992 }
02993 }
02994 if ($setDefaultList && !is_array($var)) {
02995 if (t3lib_div::inList($setDefaultList, $key) && !isset($settings[$key])) {
02996 $settings[$key] = (string)$var;
02997 }
02998 }
02999 }
03000 } else {die ('No menu!');}
03001
03002 if ($changed) {
03003 $GLOBALS['BE_USER']->pushModuleData($modName, $settings);
03004 }
03005
03006 return $settings;
03007 } else {die ('Wrong module name: "'.$modName.'"');}
03008 }
03009
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019
03020
03021
03022
03023
03024
03025
03026
03027
03028
03029
03030
03031
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042 public static function compilePreviewKeyword($getVarsStr, $beUserUid, $ttl = 172800, $fullWorkspace = NULL) {
03043 $field_array = array(
03044 'keyword' => md5(uniqid(microtime())),
03045 'tstamp' => $GLOBALS['EXEC_TIME'],
03046 'endtime' => $GLOBALS['EXEC_TIME'] + $ttl,
03047 'config' => serialize(array(
03048 'fullWorkspace' => $fullWorkspace,
03049 'getVars' => $getVarsStr,
03050 'BEUSER_uid' => $beUserUid
03051 ))
03052 );
03053
03054 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_preview', $field_array);
03055
03056 return $field_array['keyword'];
03057 }
03058
03059
03060
03061
03062
03063
03064
03065
03066
03067
03068
03069
03070
03071 public static function lockRecords($table = '', $uid = 0, $pid = 0) {
03072 $user_id = intval($GLOBALS['BE_USER']->user['uid']);
03073 if ($table && $uid) {
03074 $fields_values = array(
03075 'userid' => $user_id,
03076 'feuserid' => 0,
03077 'tstamp' => $GLOBALS['EXEC_TIME'],
03078 'record_table' => $table,
03079 'record_uid' => $uid,
03080 'username' => $GLOBALS['BE_USER']->user['username'],
03081 'record_pid' => $pid
03082 );
03083
03084 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values);
03085 } else {
03086 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'userid='.intval($user_id));
03087 }
03088 }
03089
03090
03091
03092
03093
03094
03095
03096
03097
03098
03099
03100
03101 public static function isRecordLocked($table, $uid) {
03102 global $LOCKED_RECORDS;
03103 if (!is_array($LOCKED_RECORDS)) {
03104 $LOCKED_RECORDS = array();
03105 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
03106 '*',
03107 'sys_lockedrecords',
03108 'sys_lockedrecords.userid!='.intval($GLOBALS['BE_USER']->user['uid']).'
03109 AND sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600)
03110 );
03111 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
03112
03113 if ($row['userid']) {
03114 $userTypeLabel = 'beUser';
03115 } elseif ($row['feuserid']) {
03116 $userTypeLabel = 'feUser';
03117 } else {
03118 $userTypeLabel = 'user';
03119 }
03120 $userType = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.' . $userTypeLabel);
03121
03122 if ($row['username']) {
03123 $userName = $row['username'];
03124 } else {
03125 $userName = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.unknownUser');
03126 }
03127
03128 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']] = $row;
03129 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg'] = sprintf(
03130 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser'),
03131 $userType,
03132 $userName,
03133 self::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
03134 );
03135 if ($row['record_pid'] && !isset($LOCKED_RECORDS[$row['record_table'].':'.$row['record_pid']])) {
03136 $LOCKED_RECORDS['pages:'.$row['record_pid']]['msg'] = sprintf(
03137 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser_content'),
03138 $userType,
03139 $userName,
03140 self::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
03141 );
03142 }
03143 }
03144 $GLOBALS['TYPO3_DB']->sql_free_result($res);
03145 }
03146 return $LOCKED_RECORDS[$table.':'.$uid];
03147 }
03148
03149
03150
03151
03152
03153
03154
03155
03156
03157
03158
03159
03160
03161 public static function exec_foreign_table_where_query($fieldValue, $field = '', $TSconfig = array(), $prefix = '') {
03162 global $TCA;
03163
03164 t3lib_div::loadTCA($foreign_table);
03165 $foreign_table = $fieldValue['config'][$prefix.'foreign_table'];
03166 $rootLevel = $TCA[$foreign_table]['ctrl']['rootLevel'];
03167
03168 $fTWHERE = $fieldValue['config'][$prefix.'foreign_table_where'];
03169 if (strstr($fTWHERE, '###REC_FIELD_')) {
03170 $fTWHERE_parts = explode('###REC_FIELD_', $fTWHERE);
03171 foreach ($fTWHERE_parts as $kk => $vv) {
03172 if ($kk) {
03173 $fTWHERE_subpart = explode('###', $vv, 2);
03174 $fTWHERE_parts[$kk] = $TSconfig['_THIS_ROW'][$fTWHERE_subpart[0]].$fTWHERE_subpart[1];
03175 }
03176 }
03177 $fTWHERE = implode('', $fTWHERE_parts);
03178 }
03179
03180 $fTWHERE = str_replace('###CURRENT_PID###', intval($TSconfig['_CURRENT_PID']), $fTWHERE);
03181 $fTWHERE = str_replace('###THIS_UID###', intval($TSconfig['_THIS_UID']), $fTWHERE);
03182 $fTWHERE = str_replace('###THIS_CID###', intval($TSconfig['_THIS_CID']), $fTWHERE);
03183 $fTWHERE = str_replace('###STORAGE_PID###', intval($TSconfig['_STORAGE_PID']), $fTWHERE);
03184 $fTWHERE = str_replace('###SITEROOT###', intval($TSconfig['_SITEROOT']), $fTWHERE);
03185 $fTWHERE = str_replace('###PAGE_TSCONFIG_ID###', intval($TSconfig[$field]['PAGE_TSCONFIG_ID']), $fTWHERE);
03186 $fTWHERE = str_replace('###PAGE_TSCONFIG_IDLIST###', $GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']), $fTWHERE);
03187 $fTWHERE = str_replace('###PAGE_TSCONFIG_STR###', $GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $foreign_table), $fTWHERE);
03188
03189
03190 $wgolParts = $GLOBALS['TYPO3_DB']->splitGroupOrderLimit($fTWHERE);
03191 if ($rootLevel) {
03192 $queryParts = array(
03193 'SELECT' => self::getCommonSelectFields($foreign_table, $foreign_table . '.'),
03194 'FROM' => $foreign_table,
03195 'WHERE' => $foreign_table.'.pid=0 '.
03196 self::deleteClause($foreign_table) . ' ' .
03197 $wgolParts['WHERE'],
03198 'GROUPBY' => $wgolParts['GROUPBY'],
03199 'ORDERBY' => $wgolParts['ORDERBY'],
03200 'LIMIT' => $wgolParts['LIMIT']
03201 );
03202 } else {
03203 $pageClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
03204 if ($foreign_table!='pages') {
03205 $queryParts = array(
03206 'SELECT' => self::getCommonSelectFields($foreign_table, $foreign_table . '.'),
03207 'FROM' => $foreign_table.', pages',
03208 'WHERE' => 'pages.uid='.$foreign_table.'.pid
03209 AND pages.deleted=0 '.
03210 self::deleteClause($foreign_table) .
03211 ' AND '.$pageClause.' '.
03212 $wgolParts['WHERE'],
03213 'GROUPBY' => $wgolParts['GROUPBY'],
03214 'ORDERBY' => $wgolParts['ORDERBY'],
03215 'LIMIT' => $wgolParts['LIMIT']
03216 );
03217 } else {
03218 $queryParts = array(
03219 'SELECT' => self::getCommonSelectFields($foreign_table, $foreign_table . '.'),
03220 'FROM' => 'pages',
03221 'WHERE' => 'pages.deleted=0
03222 AND '.$pageClause.' '.
03223 $wgolParts['WHERE'],
03224 'GROUPBY' => $wgolParts['GROUPBY'],
03225 'ORDERBY' => $wgolParts['ORDERBY'],
03226 'LIMIT' => $wgolParts['LIMIT']
03227 );
03228 }
03229 }
03230
03231 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
03232 }
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243
03244 public static function getTCEFORM_TSconfig($table, $row) {
03245 self::fixVersioningPid($table, $row);
03246
03247 $res = array();
03248 $typeVal = self::getTCAtypeValue($table, $row);
03249
03250
03251 list($TScID, $cPid) = self::getTSCpid($table, $row['uid'], $row['pid']);
03252
03253 $rootLine = self::BEgetRootLine($TScID, '', TRUE);
03254 if ($TScID>=0) {
03255 $tempConf = $GLOBALS['BE_USER']->getTSConfig('TCEFORM.' . $table, self::getPagesTSconfig($TScID, $rootLine));
03256 if (is_array($tempConf['properties'])) {
03257 foreach ($tempConf['properties'] as $key => $val) {
03258 if (is_array($val)) {
03259 $fieldN = substr($key, 0, -1);
03260 $res[$fieldN] = $val;
03261 unset($res[$fieldN]['types.']);
03262 if (strcmp($typeVal, '') && is_array($val['types.'][$typeVal.'.'])) {
03263 $res[$fieldN] = t3lib_div::array_merge_recursive_overrule($res[$fieldN], $val['types.'][$typeVal.'.']);
03264 }
03265 }
03266 }
03267 }
03268 }
03269 $res['_CURRENT_PID'] = $cPid;
03270 $res['_THIS_UID'] = $row['uid'];
03271 $res['_THIS_CID'] = $row['cid'];
03272 $res['_THIS_ROW'] = $row;
03273
03274 foreach ($rootLine as $rC) {
03275 if (!$res['_STORAGE_PID']) $res['_STORAGE_PID'] = intval($rC['storage_pid']);
03276 if (!$res['_SITEROOT']) $res['_SITEROOT'] = $rC['is_siteroot']?intval($rC['uid']):0;
03277 }
03278
03279 return $res;
03280 }
03281
03282
03283
03284
03285
03286
03287
03288
03289
03290
03291
03292
03293
03294 public static function getTSconfig_pidValue($table, $uid, $pid) {
03295
03296 if (t3lib_div::testInt($pid)) {
03297 $thePidValue = intval($pid);
03298 if ($thePidValue<0) {
03299 $pidRec = self::getRecord($table, abs($thePidValue), 'pid');
03300 $thePidValue = is_array($pidRec) ? $pidRec['pid'] : -2;
03301 }
03302
03303 } else {
03304 $rr = self::getRecord($table, $uid);
03305
03306 if (is_array($rr)) {
03307
03308 if ($rr['pid']=='-1') {
03309 $rr = self::getRecord($table, $rr['t3ver_oid'], 'pid');
03310 if (is_array($rr)) {
03311 $thePidValue = $rr['pid'];
03312 }
03313 } else {
03314 $thePidValue = $rr['pid'];
03315 }
03316 }
03317
03318 if (!$thePidValue) $thePidValue = -1;
03319 }
03320
03321 return $thePidValue;
03322 }
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335 public static function getPidForModTSconfig($table, $uid, $pid) {
03336 $retVal = ($table=='pages' && t3lib_div::testInt($uid)) ? $uid : $pid;
03337 return $retVal;
03338 }
03339
03340
03341
03342
03343
03344
03345
03346
03347
03348
03349
03350
03351 public static function getTSCpid($table, $uid, $pid) {
03352
03353 $cPid = self::getTSconfig_pidValue($table, $uid, $pid);
03354
03355 $TScID = self::getPidForModTSconfig($table, $uid, $cPid);
03356
03357 return array($TScID, $cPid);
03358 }
03359
03360
03361
03362
03363
03364
03365
03366
03367 public static function firstDomainRecord($rootLine) {
03368 if (t3lib_extMgm::isLoaded('cms')) {
03369 foreach ($rootLine as $row) {
03370 $dRec = self::getRecordsByField('sys_domain', 'pid', $row['uid'], ' AND redirectTo=\'\' AND hidden=0', '', 'sorting');
03371 if (is_array($dRec)) {
03372 reset($dRec);
03373 $dRecord = current($dRec);
03374 return rtrim($dRecord['domainName'], '/');
03375 }
03376 }
03377 }
03378 }
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388 public static function getDomainStartPage($domain, $path = '') {
03389 if (t3lib_extMgm::isLoaded('cms')) {
03390 $domain = explode(':', $domain);
03391 $domain = strtolower(preg_replace('/\.$/', '', $domain[0]));
03392
03393 $path = trim(preg_replace('/\/[^\/]*$/', '', $path));
03394
03395 $domain.=$path;
03396
03397 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_domain.*', 'pages,sys_domain', '
03398 pages.uid=sys_domain.pid
03399 AND sys_domain.hidden=0
03400 AND (sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain, 'sys_domain').' OR sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain.'/', 'sys_domain').')'.
03401 self::deleteClause('pages'),
03402 '', '', '1');
03403 $result = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
03404 $GLOBALS['TYPO3_DB']->sql_free_result($res);
03405 return $result;
03406 }
03407 }
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417
03418
03419
03420 public static function RTEsetup($RTEprop, $table, $field, $type = '') {
03421 $thisConfig = is_array($RTEprop['default.']) ? $RTEprop['default.'] : array();
03422 $thisFieldConf = $RTEprop['config.'][$table.'.'][$field.'.'];
03423 if (is_array($thisFieldConf)) {
03424 unset($thisFieldConf['types.']);
03425 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig, $thisFieldConf);
03426 }
03427 if ($type && is_array($RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.'])) {
03428 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig, $RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.']);
03429 }
03430 return $thisConfig;
03431 }
03432
03433
03434
03435
03436
03437
03438
03439 public static function &RTEgetObj() {
03440
03441
03442 if (!isset($GLOBALS['T3_VAR']['RTEobj'])) {
03443
03444
03445 $GLOBALS['T3_VAR']['RTEobj'] = array();
03446
03447
03448 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'])) {
03449 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'] as $extKey => $rteObjCfg) {
03450 $rteObj = t3lib_div::getUserObj($rteObjCfg['objRef']);
03451 if (is_object($rteObj)) {
03452 if ($rteObj->isAvailable()) {
03453 $GLOBALS['T3_VAR']['RTEobj'] = $rteObj;
03454 break;
03455 } else {
03456 $GLOBALS['T3_VAR']['RTEobj'] = array_merge($GLOBALS['T3_VAR']['RTEobj'], $rteObj->errorLog);
03457 }
03458 }
03459 }
03460 }
03461
03462 if (!count($GLOBALS['T3_VAR']['RTEobj'])) {
03463 $GLOBALS['T3_VAR']['RTEobj'][] = 'No RTEs configured at all';
03464 }
03465 }
03466
03467
03468 return $GLOBALS['T3_VAR']['RTEobj'];
03469 }
03470
03471
03472
03473
03474
03475
03476
03477
03478 public static function &softRefParserObj($spKey) {
03479
03480
03481 if (!isset($GLOBALS['T3_VAR']['softRefParser'][$spKey])) {
03482
03483
03484 $GLOBALS['T3_VAR']['softRefParser'][$spKey] = '';
03485
03486
03487 $objRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser'][$spKey] ?
03488 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser'][$spKey] :
03489 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'][$spKey];
03490 if ($objRef) {
03491 $softRefParserObj = t3lib_div::getUserObj($objRef, '');
03492 if (is_object($softRefParserObj)) {
03493 $GLOBALS['T3_VAR']['softRefParser'][$spKey] = $softRefParserObj;
03494 }
03495 }
03496 }
03497
03498
03499 return $GLOBALS['T3_VAR']['softRefParser'][$spKey];
03500 }
03501
03502
03503
03504
03505
03506
03507
03508
03509
03510 public static function explodeSoftRefParserList($parserList) {
03511
03512
03513 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'])) {
03514 $parserList = implode(',', array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'])).','.$parserList;
03515 }
03516
03517
03518 if (!strlen($parserList)) return FALSE;
03519
03520
03521 $keyList = t3lib_div::trimExplode(',', $parserList, 1);
03522 $output = array();
03523
03524 foreach($keyList as $val) {
03525 $reg = array();
03526 if (preg_match('/^([[:alnum:]_-]+)\[(.*)\]$/', $val, $reg)) {
03527 $output[$reg[1]] = t3lib_div::trimExplode(';', $reg[2], 1);
03528 } else {
03529 $output[$val] = '';
03530 }
03531 }
03532 return $output;
03533 }
03534
03535
03536
03537
03538
03539
03540
03541
03542 public static function isModuleSetInTBE_MODULES($modName) {
03543 $loaded = array();
03544
03545 foreach ($GLOBALS['TBE_MODULES'] as $mkey => $list) {
03546 $loaded[$mkey] = 1;
03547 if (!is_array($list) && trim($list)) {
03548 $subList = t3lib_div::trimExplode(',', $list, 1);
03549 foreach ($subList as $skey) {
03550 $loaded[$mkey.'_'.$skey] = 1;
03551 }
03552 }
03553 }
03554 return $modName && isset($loaded[$modName]);
03555 }
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566 public static function referenceCount($table, $ref, $msg = '', $count = NULL) {
03567 if ($count === NULL) {
03568
03569
03570 if ($table=='_FILE') {
03571 if (t3lib_div::isFirstPartOfStr($ref, PATH_site)) {
03572 $ref = substr($ref, strlen(PATH_site));
03573 $condition = 'ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($ref, 'sys_refindex');
03574 } else {
03575 return '';
03576 }
03577 } else {
03578 $condition = 'ref_uid=' . intval($ref);
03579 }
03580
03581 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
03582 '*',
03583 'sys_refindex',
03584 'ref_table=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_refindex') .
03585 ' AND ' . $condition .
03586 ' AND deleted=0'
03587 );
03588 }
03589
03590 return ($count ? ($msg ? sprintf($msg, $count) : $count) : '');
03591 }
03592
03593
03594
03595
03596
03597
03598
03599
03600
03601
03602 public static function translationCount($table, $ref, $msg = '') {
03603 if (empty($GLOBALS['TCA'][$table]['ctrl']['transForeignTable']) &&
03604 $GLOBALS['TCA'][$table]['ctrl']['languageField'] &&
03605 $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] &&
03606 !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
03607
03608 $where = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($ref) .
03609 ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '!=0';
03610
03611 if (!empty($GLOBALS['TCA'][$table]['ctrl']['delete'])) {
03612 $where .= ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0';
03613 }
03614
03615 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
03616 '*',
03617 $table,
03618 $where
03619 );
03620 }
03621
03622 return ($count ? ($msg ? sprintf($msg, $count) : $count) : '');
03623 }
03624
03625
03626
03627
03628
03629
03630
03631
03632
03633
03634
03635
03636
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651
03652 public static function selectVersionsOfRecord($table, $uid, $fields = '*', $workspace = 0, $includeDeletedRecords = FALSE, $row = NULL) {
03653 global $TCA;
03654
03655 $realPid = 0;
03656 $outputRows = array();
03657
03658 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
03659
03660 if (is_array($row) && !$includeDeletedRecords) {
03661 $row['_CURRENT_VERSION'] = TRUE;
03662 $realPid = $row['pid'];
03663 $outputRows[] = $row;
03664 } else {
03665
03666 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
03667 $fields,
03668 $table,
03669 'uid=' . intval($uid) .
03670 ($includeDeletedRecords ? '' : self::deleteClause($table))
03671 );
03672
03673
03674 if ($res) {
03675 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
03676 if ($row) {
03677 $row['_CURRENT_VERSION'] = TRUE;
03678 $realPid = $row['pid'];
03679 $outputRows[] = $row;
03680 }
03681 $GLOBALS['TYPO3_DB']->sql_free_result($res);
03682 }
03683 }
03684
03685
03686 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
03687 $fields,
03688 $table,
03689 'pid=-1 AND uid!='.intval($uid).' AND t3ver_oid='.intval($uid).($workspace!=0?' AND t3ver_wsid='.intval($workspace):'').
03690 ($includeDeletedRecords ? '' : self::deleteClause($table)),
03691 '',
03692 't3ver_id DESC'
03693 );
03694
03695
03696 while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))) {
03697 $outputRows[] = $row;
03698 }
03699
03700 $GLOBALS['TYPO3_DB']->sql_free_result($res);
03701
03702
03703 foreach ($outputRows as $idx => $oRow) {
03704 $outputRows[$idx]['_REAL_PID'] = $realPid;
03705 }
03706
03707 return $outputRows;
03708 }
03709 }
03710
03711
03712
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724 public static function fixVersioningPid($table, &$rr, $ignoreWorkspaceMatch = FALSE) {
03725 global $TCA;
03726
03727 if (t3lib_extMgm::isLoaded('version')) {
03728
03729 if (is_array($rr) && $rr['pid'] == -1 && $TCA[$table]['ctrl']['versioningWS']) {
03730
03731
03732 if (isset($rr['t3ver_oid']) && isset($rr['t3ver_wsid'])) {
03733 $oid = $rr['t3ver_oid'];
03734 $wsid = $rr['t3ver_wsid'];
03735 } else {
03736 $newPidRec = self::getRecord($table, $rr['uid'], 't3ver_oid,t3ver_wsid');
03737 if (is_array($newPidRec)) {
03738 $oid = $newPidRec['t3ver_oid'];
03739 $wsid = $newPidRec['t3ver_wsid'];
03740 }
03741 }
03742
03743
03744 if ($oid && ($ignoreWorkspaceMatch || !strcmp((int)$wsid, $GLOBALS['BE_USER']->workspace))) {
03745 $oidRec = self::getRecord($table, $oid, 'pid');
03746 if (is_array($oidRec)) {
03747 $rr['_ORIG_pid'] = $rr['pid'];
03748 $rr['pid'] = $oidRec['pid'];
03749 }
03750 }
03751 }
03752 }
03753 }
03754
03755
03756
03757
03758
03759
03760
03761
03762
03763
03764
03765
03766
03767 public static function workspaceOL($table, &$row, $wsid = -99, $unsetMovePointers = FALSE) {
03768 global $TCA;
03769 if (t3lib_extMgm::isLoaded('version')) {
03770
03771 $previewMovePlaceholders = TRUE;
03772
03773
03774 if ($wsid == -99) $wsid = $GLOBALS['BE_USER']->workspace;
03775
03776
03777 if ($wsid !== 0 && is_array($row)) {
03778
03779
03780 if ($previewMovePlaceholders) {
03781 $orig_uid = $row['uid'];
03782 $orig_pid = $row['pid'];
03783 $movePldSwap = self::movePlhOL($table, $row);
03784 # if (!is_array($row)) return;
03785 }
03786
03787 $wsAlt = self::getWorkspaceVersionOfRecord($wsid, $table, $row['uid'], implode(',', array_keys($row)));
03788
03789
03790 if (is_array($wsAlt)) {
03791
03792
03793 if ($previewMovePlaceholders && !$movePldSwap && ($table=='pages' || (int)$TCA[$table]['ctrl']['versioningWS']>=2) && $unsetMovePointers) {
03794
03795
03796 if (!isset($wsAlt['t3ver_state'])) {
03797 $stateRec = self::getRecord($table, $wsAlt['uid'], 't3ver_state');
03798 $state = $stateRec['t3ver_state'];
03799 } else {
03800 $state = $wsAlt['t3ver_state'];
03801 }
03802 if ((int)$state===4) {
03803
03804 $row = FALSE;
03805 return;
03806 }
03807 }
03808
03809
03810 if (isset($wsAlt['pid'])) {
03811 $wsAlt['_ORIG_pid'] = $wsAlt['pid'];
03812 $wsAlt['pid'] = $row['pid'];
03813 }
03814
03815
03816 if ($table!=='pages' || $wsAlt['t3ver_swapmode']<=0) {
03817 $wsAlt['_ORIG_uid'] = $wsAlt['uid'];
03818 $wsAlt['uid'] = $row['uid'];
03819
03820
03821 $wsAlt['_CSSCLASS'] = $table==='pages' && $wsAlt['t3ver_swapmode']==0 ? 'ver-page' : 'ver-element';
03822 } else {
03823 $wsAlt['_ONLINE_uid'] = $row['uid'];
03824
03825
03826 $wsAlt['_CSSCLASS'] = 'ver-branchpoint';
03827 $wsAlt['_SUBCSSCLASS'] = 'ver-branch';
03828 }
03829
03830
03831 $row = $wsAlt;
03832 }
03833
03834
03835 if ($movePldSwap) {
03836 $row['_MOVE_PLH'] = TRUE;
03837 $row['_MOVE_PLH_uid'] = $orig_uid;
03838 $row['_MOVE_PLH_pid'] = $orig_pid;
03839 $row['t3ver_state'] = 3;
03840 }
03841 }
03842 }
03843 }
03844
03845
03846
03847
03848
03849
03850
03851
03852
03853 public static function movePlhOL($table, &$row) {
03854 global $TCA;
03855
03856 if ($table=='pages' || (int)$TCA[$table]['ctrl']['versioningWS']>=2) {
03857
03858
03859 if (!isset($row['t3ver_move_id']) || !isset($row['t3ver_state'])) {
03860 $moveIDRec = self::getRecord($table, $row['uid'], 't3ver_move_id, t3ver_state');
03861 $moveID = $moveIDRec['t3ver_move_id'];
03862 $state = $moveIDRec['t3ver_state'];
03863 } else {
03864 $moveID = $row['t3ver_move_id'];
03865 $state = $row['t3ver_state'];
03866 }
03867
03868
03869 if ((int)$state===3 && $moveID) {
03870 if ($origRow = self::getRecord($table, $moveID, implode(',', array_keys($row)))) {
03871 $row = $origRow;
03872 return TRUE;
03873 }
03874 }
03875 }
03876 return FALSE;
03877 }
03878
03879
03880
03881
03882
03883
03884
03885
03886
03887
03888 public static function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields = '*') {
03889 global $TCA;
03890
03891 if (t3lib_extMgm::isLoaded('version')) {
03892 if ($workspace !== 0 && $TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
03893
03894
03895 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
03896 $fields,
03897 $table,
03898 'pid=-1 AND
03899 t3ver_oid=' . intval($uid) . ' AND
03900 t3ver_wsid=' . intval($workspace) .
03901 self::deleteClause($table)
03902 );
03903
03904 if (is_array($rows[0])) return $rows[0];
03905 }
03906 }
03907 return FALSE;
03908 }
03909
03910
03911
03912
03913
03914
03915
03916
03917
03918 public static function getLiveVersionOfRecord($table, $uid, $fields = '*') {
03919 global $TCA;
03920
03921
03922 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) {
03923 $rec = self::getRecord($table, $uid, 'pid,t3ver_oid');
03924
03925 if ($rec['pid']==-1) {
03926 return self::getRecord($table, $rec['t3ver_oid'], $fields);
03927 }
03928 }
03929 }
03930
03931
03932
03933
03934
03935
03936
03937
03938
03939
03940 public static function isPidInVersionizedBranch($pid, $table = '', $returnStage = FALSE) {
03941 $rl = self::BEgetRootLine($pid);
03942 $c = 0;
03943
03944 foreach($rl as $rec) {
03945 if ($rec['_ORIG_pid']==-1) {
03946
03947 if ($rec['t3ver_swapmode']>0) {
03948 return $returnStage ? (int)$rec['t3ver_stage'] : 'branchpoint';
03949 } elseif ($c==0 && $rec['t3ver_swapmode']==0 && $table && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages']) {
03950 return $returnStage ? (int)$rec['t3ver_stage'] : 'first';
03951 }
03952 }
03953 $c++;
03954 }
03955 }
03956
03957
03958
03959
03960
03961
03962
03963 public static function versioningPlaceholderClause($table) {
03964 if ($GLOBALS['BE_USER']->workspace!==0 && $GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
03965 return ' AND ('.$table.'.t3ver_state<=0 OR '.$table.'.t3ver_wsid='.intval($GLOBALS['BE_USER']->workspace).')';
03966 }
03967 }
03968
03969
03970
03971
03972
03973
03974
03975
03976
03977 public static function countVersionsOfRecordsOnPage($workspace, $pageId, $allTables = FALSE) {
03978 $output = array();
03979 if ($workspace!=0) {
03980 foreach($GLOBALS['TCA'] as $tableName => $cfg) {
03981 if ($tableName!='pages' && $cfg['ctrl']['versioningWS'] && ($cfg['ctrl']['versioning_followPages'] || $allTables)) {
03982
03983
03984
03985 $output[$tableName] = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows (
03986 'B.uid as live_uid, A.uid as offline_uid',
03987 $tableName.' A,'.$tableName.' B',
03988 'A.pid=-1'.
03989 ' AND B.pid='.intval($pageId).
03990 ' AND A.t3ver_wsid='.intval($workspace).
03991 ' AND A.t3ver_oid=B.uid'.
03992 self::deleteClause($tableName, 'A').
03993 self::deleteClause($tableName, 'B')
03994 );
03995
03996 if (!is_array($output[$tableName]) || !count($output[$tableName])) {
03997 unset($output[$tableName]);
03998 }
03999 }
04000 }
04001 }
04002 return $output;
04003 }
04004
04005
04006
04007
04008
04009
04010
04011
04012 public static function wsMapId($table, $uid) {
04013 if ($wsRec = self::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid')) {
04014 return $wsRec['uid'];
04015 } else {
04016 return $uid;
04017 }
04018 }
04019
04020
04021
04022
04023
04024
04025
04026
04027
04028 public static function getMovePlaceholder($table, $uid, $fields = '*') {
04029 global $TCA;
04030
04031 $workspace = $GLOBALS['BE_USER']->workspace;
04032 if ($workspace!==0 && $TCA[$table] && (int)$TCA[$table]['ctrl']['versioningWS']>=2) {
04033
04034
04035 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
04036 $fields,
04037 $table,
04038 'pid!=-1 AND
04039 t3ver_state=3 AND
04040 t3ver_move_id='.intval($uid).' AND
04041 t3ver_wsid='.intval($workspace).
04042 self::deleteClause($table)
04043 );
04044
04045 if (is_array($rows[0])) return $rows[0];
04046 }
04047
04048 return FALSE;
04049 }
04050
04051
04052
04053
04054
04055
04056
04057
04058
04059
04060
04061
04062
04063
04064
04065
04066
04067
04068
04069
04070
04071 public static function typo3PrintError($header, $text, $js = '', $head = 1) {
04072
04073
04074 if ($js) {
04075 echo "alert('".t3lib_div::slashJS($header.'\n'.$text)."');";
04076 } else {
04077 echo $head?'<html>
04078 <head>
04079 <title>Error!</title>
04080 </head>
04081 <body bgcolor="white" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">':'';
04082 echo '<div align="center">
04083 <table border="0" cellspacing="0" cellpadding="0" width="333">
04084 <tr>
04085 <td align="center">'.
04086 ($GLOBALS['TBE_STYLES']['logo_login']?'<img src="'.$GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login'].'" alt="" />':'<img src="'.$GLOBALS['BACK_PATH'].'gfx/typo3logo.gif" width="123" height="34" vspace="10" />').
04087 '</td>
04088 </tr>
04089 <tr>
04090 <td bgcolor="black">
04091 <table width="100%" border="0" cellspacing="1" cellpadding="10">
04092 <tr>
04093 <td bgcolor="#F4F0E8">
04094 <font face="verdana,arial,helvetica" size="2">';
04095 echo '<strong><center><font size="+1">'.$header.'</font></center></strong><br />'.$text;
04096 echo ' </font>
04097 </td>
04098 </tr>
04099 </table>
04100 </td>
04101 </tr>
04102 </table>
04103 </div>';
04104 echo $head?'
04105 </body>
04106 </html>':'';
04107 }
04108 }
04109
04110
04111
04112
04113
04114
04115 public static function TYPO3_copyRightNotice() {
04116 global $TYPO3_CONF_VARS;
04117
04118
04119 $loginCopyrightWarrantyProvider = strip_tags(trim($TYPO3_CONF_VARS['SYS']['loginCopyrightWarrantyProvider']));
04120 $loginCopyrightWarrantyURL = strip_tags(trim($TYPO3_CONF_VARS['SYS']['loginCopyrightWarrantyURL']));
04121
04122 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) {
04123 $warrantyNote = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:warranty.by'),
04124 htmlspecialchars($loginCopyrightWarrantyProvider),
04125 '<a href="' . htmlspecialchars($loginCopyrightWarrantyURL) . '" target="_blank">', '</a>'
04126 );
04127 } else {
04128 $warrantyNote = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:no.warranty'),
04129 '<a href="http://typo3.com/1316.0.html" target="_blank">', '</a>'
04130 );
04131 }
04132 $cNotice = '<a href="http://typo3.com/" target="_blank">' .
04133 '<img' . t3lib_iconWorks::skinImg($BACK_PATH, 'gfx/loginlogo_transp.gif', 'width="75" height="19" vspace="2" hspace="4"') . ' alt="' .
04134 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:typo3.logo') . '" align="left" />' .
04135 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:typo3.cms') . ' ' .
04136 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:version.short') . ' ' .
04137 htmlspecialchars(TYPO3_version) . '</a>. ' .
04138 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:copyright') . ' © ' .
04139 htmlspecialchars(TYPO3_copyright_year) . ' Kasper Skårhøj. ' .
04140 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:extension.copyright') . ' ' .
04141 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:details.link'),
04142 '<a href="http://typo3.com/" target="_blank">http:
04143 ) . ' ' .
04144 strip_tags($warrantyNote, '<a>') . ' ' .
04145 sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:free.software'),
04146 '<a href="http://typo3.com/1316.0.html" target="_blank">', '</a> '
04147 ) .
04148 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_login.xml:keep.notice');
04149
04150 return $cNotice;
04151 }
04152
04153
04154
04155
04156
04157
04158
04159 public static function displayWarningMessages() {
04160 if ($GLOBALS['BE_USER']->isAdmin()) {
04161 $warnings = array();
04162 $enableInstallToolFile = PATH_site . 'typo3conf/ENABLE_INSTALL_TOOL';
04163
04164 $cmd = t3lib_div::_GET('adminWarning_cmd');
04165 switch($cmd) {
04166 case 'remove_ENABLE_INSTALL_TOOL':
04167 if (unlink($enableInstallToolFile)) {
04168 unset($enableInstallToolFile);
04169 }
04170 break;
04171 }
04172
04173
04174 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword']==md5('joh316')) {
04175 $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=about');
04176 $warnings["install_password"] = sprintf(
04177 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_password'),
04178 '<a href="'.$url.'">',
04179 '</a>');
04180 }
04181
04182
04183 $where_clause = 'username=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('admin', 'be_users') . ' AND password=' .
04184 $GLOBALS['TYPO3_DB']->fullQuoteStr('5f4dcc3b5aa765d61d8327deb882cf99', 'be_users') . self::deleteClause('be_users');
04185 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, username, password', 'be_users', $where_clause);
04186 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
04187 $url = "alt_doc.php?returnUrl=index.php&edit[be_users][".$row['uid']."]=edit";
04188 $warnings["backend_admin"] = sprintf(
04189 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_admin'),
04190 '<a href="' . htmlspecialchars($url) . '">',
04191 '</a>');
04192
04193 }
04194 $GLOBALS['TYPO3_DB']->sql_free_result($res);
04195
04196
04197 if (is_file($enableInstallToolFile) && trim(file_get_contents($enableInstallToolFile)) === 'KEEP_FILE') {
04198 $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT').'?adminWarning_cmd=remove_ENABLE_INSTALL_TOOL';
04199 $warnings['install_enabled'] = sprintf(
04200 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_enabled'),
04201 '<span style="white-space:nowrap;">'.$enableInstallToolFile.'</span>');
04202 $warnings['install_enabled'].= ' <a href="'.$url.'">'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_enabled_cmd').'</a>';
04203 }
04204
04205
04206 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] == '') {
04207 $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=config#set_encryptionKey');
04208 $warnings["install_encryption"] = sprintf(
04209 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_encryption'),
04210 '<a href="'.$url.'">',
04211 '</a>');
04212 }
04213
04214
04215 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] != FILE_DENY_PATTERN_DEFAULT ) {
04216 $warnings['file_deny_pattern'] = sprintf(
04217 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_pattern'),
04218 '<br /><pre>'.htmlspecialchars(FILE_DENY_PATTERN_DEFAULT).'</pre><br />');
04219 }
04220
04221
04222 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] != FILE_DENY_PATTERN_DEFAULT && t3lib_div::verifyFilenameAgainstDenyPattern(".htaccess")) {
04223 $warnings['file_deny_htaccess'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_htaccess');
04224 }
04225
04226
04227 if (!t3lib_div::compat_version(TYPO3_branch)) {
04228 $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=update');
04229 $warnings["install_update"] = sprintf(
04230 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.install_update'),
04231 '<a href="'.$url.'">',
04232 '</a>');
04233 }
04234
04235
04236 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'sys_refindex');
04237 $registry = t3lib_div::makeInstance('t3lib_Registry');
04238 $lastRefIndexUpdate = $registry->get('core', 'sys_refindex_lastUpdate');
04239 if (!$count && $lastRefIndexUpdate) {
04240 $url = 'sysext/lowlevel/dbint/index.php?&id=0&SET[function]=refindex';
04241 $warnings["backend_reference"] = sprintf(
04242 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_reference_index'),
04243 '<a href="'.$url.'">',
04244 '</a>',
04245 self::dateTime($lastRefIndexUpdate));
04246 }
04247
04248
04249 $memCacheUse = false;
04250 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'])) {
04251 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $table => $conf) {
04252 if (is_array($conf)) {
04253 foreach ($conf as $key => $value) {
04254 if (!is_array($value) && $value === 't3lib_cache_backend_MemcachedBackend') {
04255 $servers = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$table]['options']['servers'];
04256 $memCacheUse = true;
04257 break;
04258 }
04259 }
04260 }
04261 }
04262 if ($memCacheUse) {
04263 $failed = array();
04264 $defaultPort = ini_get('memcache.default_port');
04265 if (function_exists('memcache_connect')) {
04266 if (is_array($servers)) {
04267 foreach ($servers as $testServer) {
04268 $configuredServer = $testServer;
04269 if (substr($testServer, 0, 7) == 'unix:
04270 $host = $testServer;
04271 $port = 0;
04272 } else {
04273 if (substr($testServer, 0, 6) === 'tcp:
04274 $testServer = substr($testServer, 6);
04275 }
04276 if (strstr($testServer, ':') !== FALSE) {
04277 list($host, $port) = explode(':', $testServer, 2);
04278 } else {
04279 $host = $testServer;
04280 $port = $defaultPort;
04281 }
04282 }
04283 $memcache_obj = @memcache_connect($host, $port);
04284 if ($memcache_obj != null) {
04285 memcache_close($memcache_obj);
04286 } else {
04287 $failed[] = $configuredServer;
04288 }
04289 }
04290 }
04291 }
04292 if (count($failed) > 0) {
04293 $warnings['memcached'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.memcache_not_usable') . '<br/>' .
04294 implode(', ', $failed);
04295 }
04296 }
04297 }
04298
04299
04300 if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'])) {
04301 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages'] as $classRef) {
04302 $hookObj = t3lib_div::getUserObj($classRef);
04303 if (method_exists($hookObj, 'displayWarningMessages_postProcess')) {
04304 $hookObj->displayWarningMessages_postProcess($warnings);
04305 }
04306 }
04307 }
04308
04309 if (count($warnings)) {
04310 $style = ' style="margin-bottom:10px;"';
04311 $securityWarnings = '<ul><li' . $style . '>'
04312 . implode('</li><li' . $style . '>', $warnings)
04313 . '</li></ul>';
04314
04315 $securityMessage = t3lib_div::makeInstance(
04316 't3lib_FlashMessage',
04317 $securityWarnings,
04318 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.header'),
04319 t3lib_FlashMessage::ERROR
04320 );
04321 $content = '<div style="margin: 20px 0px;">'
04322 . $securityMessage->render()
04323 . '</div>';
04324
04325 unset($warnings);
04326 return $content;
04327 }
04328 }
04329 return '<p> </p>';
04330 }
04331
04332
04333
04334
04335
04336
04337
04338
04339 public static function getPathType_web_nonweb($path) {
04340 return t3lib_div::isFirstPartOfStr($path, t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT')) ? 'web' : '';
04341 }
04342
04343
04344
04345
04346
04347
04348
04349
04350
04351 public static function ADMCMD_previewCmds($pageinfo) {
04352 if ($pageinfo['fe_group']>0) {
04353 $simUser = '&ADMCMD_simUser='.$pageinfo['fe_group'];
04354 }
04355 if ($pageinfo['starttime'] > $GLOBALS['EXEC_TIME']) {
04356 $simTime = '&ADMCMD_simTime='.$pageinfo['starttime'];
04357 }
04358 if ($pageinfo['endtime'] < $GLOBALS['EXEC_TIME'] && $pageinfo['endtime'] != 0) {
04359 $simTime = '&ADMCMD_simTime='.($pageinfo['endtime']-1);
04360 }
04361 return $simUser.$simTime;
04362 }
04363
04364
04365
04366
04367
04368
04369
04370
04371
04372
04373 public static function processParams($params) {
04374 $paramArr = array();
04375 $lines = explode(LF, $params);
04376 foreach ($lines as $val) {
04377 $val = trim($val);
04378 if ($val) {
04379 $pair = explode('=', $val, 2);
04380 $paramArr[trim($pair[0])] = trim($pair[1]);
04381 }
04382 }
04383 return $paramArr;
04384 }
04385
04386
04387
04388
04389
04390
04391
04392
04393
04394
04395
04396
04397
04398
04399 public static function getListOfBackendModules($name, $perms_clause, $backPath = '', $script = 'index.php') {
04400 t3lib_div::logDeprecatedFunction();
04401
04402 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'doktype!=255 AND module IN (\'' . implode('\',\'', $name) . '\') AND' . $perms_clause . self::deleteClause('pages'));
04403 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) return false;
04404
04405 $out = '';
04406 $theRows = array();
04407 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
04408 $theRows[] = $row;
04409 $out.='<span class="nobr"><a href="'.htmlspecialchars($script.'?id='.$row['uid']).'">'.
04410 t3lib_iconWorks::getSpriteIconForRecord('pages', $row, array('title' => htmlspecialchars(self::getRecordPath($row['uid'], $perms_clause, 20)))) .
04411 htmlspecialchars(