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
00174 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php');
00175
00176
00185 class t3lib_BEfunc {
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00206 function deleteClause($table,$tableAlias='') {
00207 global $TCA;
00208 if ($TCA[$table]['ctrl']['delete']) {
00209 return ' AND '.($tableAlias ? $tableAlias : $table).'.'.$TCA[$table]['ctrl']['delete'].'=0';
00210 } else {
00211 return '';
00212 }
00213 }
00214
00230 function getRecord($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
00231 if ($GLOBALS['TCA'][$table]) {
00232 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00233 $fields,
00234 $table,
00235 'uid='.intval($uid).($useDeleteClause ? t3lib_BEfunc::deleteClause($table) : '').$where
00236 );
00237 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00238 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00239 if ($row) {
00240 return $row;
00241 }
00242 }
00243 }
00244
00255 function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
00256 if ($fields !== '*') {
00257 $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
00258 $row = t3lib_BEfunc::getRecord($table,$uid,$internalFields,$where,$useDeleteClause);
00259 t3lib_BEfunc::workspaceOL($table,$row);
00260
00261 if (is_array ($row)) {
00262 foreach (array_keys($row) as $key) {
00263 if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
00264 unset ($row[$key]);
00265 }
00266 }
00267 }
00268 } else {
00269 $row = t3lib_BEfunc::getRecord($table,$uid,$fields,$where);
00270 t3lib_BEfunc::workspaceOL($table,$row);
00271 }
00272 return $row;
00273 }
00274
00288 function getRecordRaw($table,$where='',$fields='*') {
00289 $row = FALSE;
00290 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
00291 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00292 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00293 }
00294 return $row;
00295 }
00296
00313 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true) {
00314 global $TCA;
00315 if (is_array($TCA[$theTable])) {
00316 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00317 '*',
00318 $theTable,
00319 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
00320 ($useDeleteClause ? t3lib_BEfunc::deleteClause($theTable).' ' : '').
00321 t3lib_BEfunc::versioningPlaceholderClause($theTable).' '.
00322 $whereClause,
00323 $groupBy,
00324 $orderBy,
00325 $limit
00326 );
00327 $rows = array();
00328 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00329 $rows[] = $row;
00330 }
00331 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00332 if (count($rows)) return $rows;
00333 }
00334 }
00335
00346 function searchQuery($searchWords,$fields,$table='') {
00347 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
00348 }
00349
00361 function listQuery($field,$value) {
00362 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
00363 }
00364
00373 function splitTable_Uid($str) {
00374 list($uid,$table) = explode('_',strrev($str),2);
00375 return array(strrev($table),strrev($uid));
00376 }
00377
00388 function getSQLselectableList($in_list,$tablename,$default_tablename) {
00389 $list = Array();
00390 if ((string)trim($in_list)!='') {
00391 $tempItemArray = explode(',',trim($in_list));
00392 while(list($key,$val)=each($tempItemArray)) {
00393 $val = strrev($val);
00394 $parts = explode('_',$val,2);
00395 if ((string)trim($parts[0])!='') {
00396 $theID = intval(strrev($parts[0]));
00397 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
00398 if ($theTable==$tablename) {$list[]=$theID;}
00399 }
00400 }
00401 }
00402 return implode(',',$list);
00403 }
00404
00416 function BEenableFields($table,$inv=0) {
00417 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00418 $query=array();
00419 $invQuery=array();
00420 if (is_array($ctrl)) {
00421 if (is_array($ctrl['enablecolumns'])) {
00422 if ($ctrl['enablecolumns']['disabled']) {
00423 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00424 $query[]=$field.'=0';
00425 $invQuery[]=$field.'!=0';
00426 }
00427 if ($ctrl['enablecolumns']['starttime']) {
00428 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00429 $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00430 $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00431 }
00432 if ($ctrl['enablecolumns']['endtime']) {
00433 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00434 $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00435 $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00436 }
00437 }
00438 }
00439 $outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
00440
00441 return $outQ;
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00480 function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
00481 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00482 $select,
00483 $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
00484 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
00485 $whereClause,
00486 $groupBy,
00487 $orderBy,
00488 $limit
00489 );
00490 return $query;
00491 }
00492
00502 function DBcompileInsert($table,$fields_values) {
00503 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
00504 }
00505
00516 function DBcompileUpdate($table,$where,$fields_values) {
00517 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
00518 }
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00546 function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE) {
00547 if (is_array($GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0])) {
00548 return $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0];
00549 }
00550 $pid = $uid;
00551 $loopCheck = 100;
00552 $theRowArray = Array();
00553 $output = Array();
00554 while ($uid!=0 && $loopCheck>0) {
00555 $loopCheck--;
00556 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00557 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
00558 'pages',
00559 'uid='.intval($uid).' '.
00560 t3lib_BEfunc::deleteClause('pages').' '.
00561 $clause
00562 );
00563 if ($GLOBALS['TYPO3_DB']->sql_error()) {
00564 debug($GLOBALS['TYPO3_DB']->sql_error(),1);
00565 }
00566 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00567 if($workspaceOL) t3lib_BEfunc::workspaceOL('pages',$row);
00568 if (is_array($row)) {
00569 t3lib_BEfunc::fixVersioningPid('pages',$row);
00570 $uid = $row['pid'];
00571 $theRowArray[] = $row;
00572 } else break;
00573 } else {
00574 break;
00575 }
00576 }
00577 if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');}
00578 if (is_array($theRowArray)) {
00579 reset($theRowArray);
00580 $c=count($theRowArray);
00581 while(list($key,$val)=each($theRowArray)) {
00582 $c--;
00583 $output[$c]['uid'] = $val['uid'];
00584 $output[$c]['pid'] = $val['pid'];
00585 if (isset($val['_ORIG_pid'])) $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
00586 $output[$c]['title'] = $val['title'];
00587 $output[$c]['TSconfig'] = $val['TSconfig'];
00588 $output[$c]['is_siteroot'] = $val['is_siteroot'];
00589 $output[$c]['storage_pid'] = $val['storage_pid'];
00590 $output[$c]['t3ver_oid'] = $val['t3ver_oid'];
00591 $output[$c]['t3ver_wsid'] = $val['t3ver_wsid'];
00592 $output[$c]['t3ver_state'] = $val['t3ver_state'];
00593 $output[$c]['t3ver_swapmode'] = $val['t3ver_swapmode'];
00594 $output[$c]['t3ver_stage'] = $val['t3ver_stage'];
00595 }
00596 }
00597 $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$pid][$clause][$workspaceOL?1:0] = $output;
00598
00599 return $output;
00600 }
00601
00609 function openPageTree($pid,$clearExpansion) {
00610 global $BE_USER;
00611
00612
00613 if ($clearExpansion) {
00614 $expandedPages = array();
00615 } else {
00616 $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
00617 }
00618
00619
00620 $rL = t3lib_BEfunc::BEgetRootLine($pid);
00621
00622
00623 $mountIndex = 0;
00624 $mountKeys = array_flip($BE_USER->returnWebmounts());
00625 foreach($rL as $rLDat) {
00626 if (isset($mountKeys[$rLDat['uid']])) {
00627 $mountIndex = $mountKeys[$rLDat['uid']];
00628 break;
00629 }
00630 }
00631
00632
00633 foreach($rL as $rLDat) {
00634 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
00635 }
00636
00637
00638 $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
00639 $BE_USER->writeUC();
00640 }
00641
00654 function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) {
00655 if (!$titleLimit) { $titleLimit=1000; }
00656
00657 $loopCheck = 100;
00658 $output = $fullOutput = '/';
00659 while ($uid!=0 && $loopCheck>0) {
00660 $loopCheck--;
00661 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00662 'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode',
00663 'pages',
00664 'uid='.intval($uid).
00665 t3lib_BEfunc::deleteClause('pages').
00666 (strlen(trim($clause)) ? ' AND '.$clause : '')
00667 );
00668 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00669 t3lib_BEfunc::workspaceOL('pages',$row);
00670 if (is_array($row)) {
00671 t3lib_BEfunc::fixVersioningPid('pages',$row);
00672
00673 if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0) {
00674 $output = ' [#VEP#]'.$output;
00675 }
00676 $uid = $row['pid'];
00677 $output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output;
00678 if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
00679 } else break;
00680 } else {
00681 break;
00682 }
00683 }
00684
00685 if ($fullTitleLimit) {
00686 return array($output, $fullOutput);
00687 } else {
00688 return $output;
00689 }
00690 }
00691
00699 function getExcludeFields() {
00700 global $TCA;
00701
00702 $theExcludeArray = Array();
00703 $tc_keys = array_keys($TCA);
00704 foreach($tc_keys as $table) {
00705
00706 t3lib_div::loadTCA($table);
00707
00708 if (is_array($TCA[$table]['columns'])) {
00709 $f_keys = array_keys($TCA[$table]['columns']);
00710 foreach($f_keys as $field) {
00711 if ($TCA[$table]['columns'][$field]['exclude']) {
00712
00713 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00714
00715 $theExcludeArray[] = Array($Fname , $table.':'.$field);
00716 }
00717 }
00718 }
00719 }
00720 return $theExcludeArray;
00721 }
00722
00729 function getExplicitAuthFieldValues() {
00730 global $TCA;
00731
00732
00733 $adLabel = array(
00734 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
00735 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
00736 );
00737
00738
00739 $allowDenyOptions = Array();
00740 $tc_keys = array_keys($TCA);
00741 foreach($tc_keys as $table) {
00742
00743
00744 t3lib_div::loadTCA($table);
00745
00746
00747 if (is_array($TCA[$table]['columns'])) {
00748 $f_keys = array_keys($TCA[$table]['columns']);
00749 foreach($f_keys as $field) {
00750 $fCfg = $TCA[$table]['columns'][$field]['config'];
00751 if ($fCfg['type']=='select' && $fCfg['authMode']) {
00752
00753
00754 if (is_array($fCfg['items'])) {
00755
00756 $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00757
00758
00759 foreach($fCfg['items'] as $iVal) {
00760 if (strcmp($iVal[1],'')) {
00761
00762
00763 $iMode = '';
00764 switch((string)$fCfg['authMode']) {
00765 case 'explicitAllow':
00766 $iMode = 'ALLOW';
00767 break;
00768 case 'explicitDeny':
00769 $iMode = 'DENY';
00770 break;
00771 case 'individual':
00772 if (!strcmp($iVal[4],'EXPL_ALLOW')) {
00773 $iMode = 'ALLOW';
00774 } elseif (!strcmp($iVal[4],'EXPL_DENY')) {
00775 $iMode = 'DENY';
00776 }
00777 break;
00778 }
00779
00780
00781 if ($iMode) {
00782 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
00783 }
00784 }
00785 }
00786 }
00787 }
00788 }
00789 }
00790 }
00791
00792 return $allowDenyOptions;
00793 }
00794
00800 function getSystemLanguages() {
00801
00802
00803 $sysLanguages = array();
00804 $sysLanguages[] = array('Default language', 0);
00805
00806
00807 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language'));
00808 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00809 $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
00810 }
00811
00812 return $sysLanguages;
00813 }
00814
00825 function readPageAccess($id,$perms_clause) {
00826 if ((string)$id!='') {
00827 $id = intval($id);
00828 if (!$id) {
00829 if ($GLOBALS['BE_USER']->isAdmin()) {
00830 $path = '/';
00831 $pageinfo['_thePath'] = $path;
00832 return $pageinfo;
00833 }
00834 } else {
00835 $pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : ''));
00836 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) {
00837 t3lib_BEfunc::workspaceOL('pages', $pageinfo);
00838 if (is_array($pageinfo)) {
00839 t3lib_BEfunc::fixVersioningPid('pages', $pageinfo);
00840 list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
00841 return $pageinfo;
00842 }
00843 }
00844 }
00845 }
00846 return false;
00847 }
00848
00858 function getTCAtypes($table,$rec,$useFieldNameAsKey=0) {
00859 global $TCA;
00860
00861 t3lib_div::loadTCA($table);
00862 if ($TCA[$table]) {
00863
00864
00865 $fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec);
00866
00867
00868 $typesConf = $TCA[$table]['types'][$fieldValue];
00869
00870
00871 $fieldList = explode(',', $typesConf['showitem']);
00872 $altFieldList = array();
00873
00874
00875 foreach($fieldList as $k => $v) {
00876 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
00877 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
00878 $specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
00879
00880 $fieldList[$k]=array(
00881 'field' => $pFieldName,
00882 'title' => $pAltTitle,
00883 'palette' => $pPalette,
00884 'spec' => $specConfParts,
00885 'origString' => $v
00886 );
00887 if ($useFieldNameAsKey) {
00888 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
00889 }
00890 }
00891 if ($useFieldNameAsKey) {
00892 $fieldList = $altFieldList;
00893 }
00894
00895
00896 return $fieldList;
00897 }
00898 }
00899
00911 function getTCAtypeValue($table,$rec) {
00912 global $TCA;
00913
00914
00915 t3lib_div::loadTCA($table);
00916 if ($TCA[$table]) {
00917 $field = $TCA[$table]['ctrl']['type'];
00918 $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
00919 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
00920 return $fieldValue;
00921 }
00922 }
00923
00934 function getSpecConfParts($str, $defaultExtras) {
00935
00936
00937 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
00938
00939 $reg = array();
00940 if (count($specConfParts)) {
00941 foreach($specConfParts as $k2 => $v2) {
00942 unset($specConfParts[$k2]);
00943 if (ereg('(.*)\[(.*)\]',$v2,$reg)) {
00944 $specConfParts[trim($reg[1])] = array(
00945 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
00946 );
00947 } else {
00948 $specConfParts[trim($v2)] = 1;
00949 }
00950 }
00951 } else {
00952 $specConfParts = array();
00953 }
00954 return $specConfParts;
00955 }
00956
00965 function getSpecConfParametersFromArray($pArr) {
00966 $out=array();
00967 if (is_array($pArr)) {
00968 reset($pArr);
00969 while(list($k,$v)=each($pArr)) {
00970 $parts=explode('=',$v,2);
00971 if (count($parts)==2) {
00972 $out[trim($parts[0])]=trim($parts[1]);
00973 } else {
00974 $out[$k]=$v;
00975 }
00976 }
00977 }
00978 return $out;
00979 }
00980
00995 function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE,$newRecordPidValue=0) {
00996 global $TYPO3_CONF_VARS;
00997
00998
00999 $ds_pointerField = $conf['ds_pointerField'];
01000 $ds_array = $conf['ds'];
01001 $ds_tableField = $conf['ds_tableField'];
01002 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
01003
01004
01005 $dataStructArray='';
01006 if (is_array($ds_array)) {
01007
01008 if ($ds_pointerField) {
01009 $srcPointer = $row[$ds_pointerField];
01010 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
01011 } else $srcPointer='default';
01012
01013
01014 if (substr($ds_array[$srcPointer],0,5)=='FILE:') {
01015 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5));
01016 if ($file && @is_file($file)) {
01017 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01018 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")';
01019 } else {
01020 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
01021 }
01022
01023 } elseif ($ds_pointerField) {
01024
01025 $srcPointer = $row[$ds_pointerField];
01026
01027
01028 if ($ds_searchParentField && !$srcPointer) {
01029 $rr = t3lib_BEfunc::getRecord($table,$row['uid'],'uid,'.$ds_searchParentField);
01030 if ($WSOL) {
01031 t3lib_BEfunc::workspaceOL($table,$rr);
01032 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
01033 }
01034 $uidAcc=array();
01035 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
01036 while(!$srcPointer) {
01037
01038 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01039 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),
01040 $table,
01041 'uid='.intval($newRecordPidValue ? $newRecordPidValue : $rr[$ds_searchParentField]).t3lib_BEfunc::deleteClause($table) ###NOTE_A###
01042 );
01043 $newRecordPidValue = 0;
01044 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01045
01046
01047 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break;
01048 $uidAcc[$rr['uid']]=1;
01049
01050 if ($WSOL) {
01051 t3lib_BEfunc::workspaceOL($table,$rr);
01052 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
01053 }
01054 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
01055 }
01056 }
01057
01058
01059 if ($srcPointer) {
01060 if (t3lib_div::testInt($srcPointer)) {
01061 list($tName,$fName) = explode(':',$ds_tableField,2);
01062 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
01063 $dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer);
01064 if ($WSOL) {
01065 t3lib_BEfunc::workspaceOL($tName,$dataStructRec);
01066 }
01067 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
01068 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
01069 } else {
01070 $file = t3lib_div::getFileAbsFileName($srcPointer);
01071 if ($file && @is_file($file)) {
01072 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01073 } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")';
01074 }
01075 } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"';
01076 } else $dataStructArray='No proper configuration!';
01077
01078
01079 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
01080 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
01081 $hookObj = &t3lib_div::getUserObj($classRef);
01082 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
01083 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
01084 }
01085 }
01086 }
01087
01088 return $dataStructArray;
01089 }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01124 function storeHash($hash,$data,$ident) {
01125 $insertFields = array(
01126 'hash' => $hash,
01127 'content' => $data,
01128 'ident' => $ident,
01129 'tstamp' => time()
01130 );
01131 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
01132 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
01133 }
01134
01144 function getHash($hash,$expTime=0) {
01145
01146 $expTime = intval($expTime);
01147 if ($expTime) {
01148 $whereAdd = ' AND tstamp > '.(time()-$expTime);
01149 }
01150 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
01151 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01152 return $row['content'];
01153 }
01154 }
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01180 function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) {
01181 $id=intval($id);
01182 if (!is_array($rootLine)) {
01183 $rootLine = t3lib_BEfunc::BEgetRootLine($id,'',TRUE);
01184 }
01185 ksort($rootLine);
01186 $TSdataArray = array();
01187 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
01188 foreach($rootLine as $k => $v) {
01189 $TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
01190 }
01191 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
01192 if ($returnPartArray) {
01193 return $TSdataArray;
01194 }
01195
01196
01197 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
01198 $hash = md5('pageTS:'.$userTS);
01199 $cachedContent = t3lib_BEfunc::getHash($hash,0);
01200 $TSconfig = array();
01201 if (isset($cachedContent)) {
01202 $TSconfig = unserialize($cachedContent);
01203 } else {
01204 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
01205 $parseObj->parse($userTS);
01206 $TSconfig = $parseObj->setup;
01207 t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
01208 }
01209
01210
01211 $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
01212 if (is_array($userTSconfig)) {
01213 $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
01214 }
01215 return $TSconfig;
01216 }
01217
01236 function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') {
01237 $id=intval($id);
01238 if (is_array($pageTS) && $id>0) {
01239 if (!is_array($impParams)) {
01240 $impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id));
01241 }
01242 reset($pageTS);
01243 $set=array();
01244 while(list($f,$v)=each($pageTS)) {
01245 $f = $TSconfPrefix.$f;
01246 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v))) {
01247 $set[$f]=trim($v);
01248 }
01249 }
01250 if (count($set)) {
01251
01252 $pRec = t3lib_befunc::getRecord('pages',$id);
01253 $TSlines = explode(chr(10),$pRec['TSconfig']);
01254 $TSlines = array_reverse($TSlines);
01255
01256 reset($set);
01257 while(list($f,$v)=each($set)) {
01258 reset($TSlines);
01259 $inserted=0;
01260 while(list($ki,$kv)=each($TSlines)) {
01261 if (substr($kv,0,strlen($f)+1)==$f.'=') {
01262 $TSlines[$ki]=$f.'='.$v;
01263 $inserted=1;
01264 break;
01265 }
01266 }
01267 if (!$inserted) {
01268 $TSlines = array_reverse($TSlines);
01269 $TSlines[]=$f.'='.$v;
01270 $TSlines = array_reverse($TSlines);
01271 }
01272 }
01273 $TSlines = array_reverse($TSlines);
01274
01275
01276 $TSconf = implode(chr(10),$TSlines);
01277
01278 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
01279 }
01280 }
01281 }
01282
01291 function implodeTSParams($p,$k='') {
01292 $implodeParams=array();
01293 if (is_array($p)) {
01294 reset($p);
01295 while(list($kb,$val)=each($p)) {
01296 if (is_array($val)) {
01297 $implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb));
01298 } else {
01299 $implodeParams[$k.$kb]=$val;
01300 }
01301 }
01302 }
01303 return $implodeParams;
01304 }
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01328 function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
01329 $be_user_Array=Array();
01330
01331 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username');
01332 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01333 $be_user_Array[$row['uid']]=$row;
01334 }
01335 return $be_user_Array;
01336 }
01337
01346 function getGroupNames($fields='title,uid', $where='') {
01347 $be_group_Array = Array();
01348 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
01349 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01350 $be_group_Array[$row['uid']] = $row;
01351 }
01352 return $be_group_Array;
01353 }
01354
01363 function getListGroupNames($fields='title,uid') {
01364 $exQ=' AND hide_in_lists=0';
01365 if (!$GLOBALS['BE_USER']->isAdmin()) {
01366 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
01367 }
01368 return t3lib_BEfunc::getGroupNames($fields,$exQ);
01369 }
01370
01382 function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) {
01383 if (is_array($usernames) && is_array($groupArray)) {
01384 while(list($uid,$row)=each($usernames)) {
01385 $userN=$uid;
01386 $set=0;
01387 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
01388 reset($groupArray);
01389 while(list(,$v)=each($groupArray)) {
01390 if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v)) {
01391 $userN = $row['username'];
01392 $set=1;
01393 }
01394 }
01395 } else {
01396 $userN = $row['username'];
01397 $set=1;
01398 }
01399 $usernames[$uid]['username']=$userN;
01400 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
01401 }
01402 }
01403 return $usernames;
01404 }
01405
01415 function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) {
01416 if (is_array($groups) && is_array($groupArray)) {
01417 while(list($uid,$row)=each($groups)) {
01418 $groupN=$uid;
01419 $set=0;
01420 if (t3lib_div::inArray($groupArray,$uid)) {
01421 $groupN=$row['title'];
01422 $set=1;
01423 }
01424 $groups[$uid]['title']=$groupN;
01425 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
01426 }
01427 }
01428 return $groups;
01429 }
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01456 function daysUntil($tstamp) {
01457 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
01458 return ceil($delta_t/(3600*24));
01459 }
01460
01468 function date($tstamp) {
01469 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
01470 }
01471
01479 function datetime($value) {
01480 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
01481 }
01482
01491 function time($value) {
01492 $hh = floor($value/3600);
01493 $min = floor(($value-$hh*3600)/60);
01494 $sec = $value-$hh*3600-$min*60;
01495 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
01496 return $l;
01497 }
01498
01507 function calcAge($seconds,$labels = 'min|hrs|days|yrs') {
01508 $labelArr = explode('|',$labels);
01509 $prefix='';
01510 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
01511 if ($seconds<3600) {
01512 $seconds = round ($seconds/60).' '.trim($labelArr[0]);
01513 } elseif ($seconds<24*3600) {
01514 $seconds = round ($seconds/3600).' '.trim($labelArr[1]);
01515 } elseif ($seconds<365*24*3600) {
01516 $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
01517 } else {
01518 $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
01519 }
01520 return $prefix.$seconds;
01521 }
01522
01533 function dateTimeAge($tstamp,$prefix=1,$date='') {
01534 return $tstamp ?
01535 ($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)).
01536 ' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
01537 }
01538
01551 function titleAttrib($content='',$hsc=0) {
01552 global $CLIENT;
01553 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
01554 return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
01555 }
01556
01564 function titleAltAttrib($content) {
01565 $out='';
01566 $out.=' alt="'.htmlspecialchars($content).'"';
01567 $out.=' title="'.htmlspecialchars($content).'"';
01568 return $out;
01569 }
01570
01588 function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='') {
01589 global $TCA;
01590
01591 t3lib_div::loadTCA($table);
01592
01593
01594 $uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
01595 $uploaddir = preg_replace('#/$#','',$uploaddir);
01596
01597
01598 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
01599 $thumbScript='gfx/notfound_thumb.gif';
01600 } elseif(!$thumbScript) {
01601 $thumbScript='thumbs.php';
01602 }
01603
01604 $sizeParts=array();
01605 if ($size = trim($size)) {
01606 $sizeParts = explode('x', $size.'x'.$size);
01607 if(!intval($sizeParts[0])) $size='';
01608 }
01609
01610
01611 $thumbs = explode(',', $row[$field]);
01612 $thumbData='';
01613 while(list(,$theFile)=each($thumbs)) {
01614 if (trim($theFile)) {
01615 $fI = t3lib_div::split_fileref($theFile);
01616 $ext = $fI['fileext'];
01617
01618 $max=0;
01619 if (t3lib_div::inList('gif,jpg,png',$ext)) {
01620 $imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile);
01621 if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);}
01622 }
01623
01624 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
01625 $theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01626 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01627 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
01628
01629 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
01630 $theFile_abs = PATH_site.($uploaddir?$uploaddir.'/':'').trim($theFile);
01631 $theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01632
01633 $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01634 $params = '&file='.rawurlencode($theFile);
01635 $params.= $size?'&size='.$size:'';
01636 $params.= '&md5sum='.t3lib_div::shortMD5($check);
01637
01638 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01639 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01640 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
01641 } else {
01642 $icon = t3lib_BEfunc::getFileIcon($ext);
01643 $url = 'gfx/fileicons/'.$icon;
01644 $thumbData.= '<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
01645 }
01646 }
01647 }
01648 return $thumbData;
01649 }
01650
01661 function getThumbNail($thumbScript,$theFile,$tparams='',$size='') {
01662 $check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01663 $params = '&file='.rawurlencode($theFile);
01664 $params.= trim($size)?'&size='.trim($size):'';
01665 $params.= '&md5sum='.t3lib_div::shortMD5($check);
01666
01667 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01668 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
01669 return $th;
01670 }
01671
01681 function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) {
01682 global $TCA,$LANG;
01683 $parts=array();
01684 $parts[] = 'id='.$row['uid'];
01685 if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
01686 if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id'];
01687
01688 switch($row['t3ver_state']) {
01689 case 1:
01690 $parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
01691 break;
01692 case 2:
01693 $parts[] = 'Deleted element!';
01694 break;
01695 case 3:
01696 $parts[] = 'NEW LOCATION (PLH) WSID#'.$row['t3ver_wsid'];
01697 break;
01698 case 4:
01699 $parts[] = 'OLD LOCATION (PNT) WSID#'.$row['t3ver_wsid'];
01700 break;
01701 case -1:
01702 $parts[] = 'New element!';
01703 break;
01704 }
01705
01706 if ($row['doktype']=='3') {
01707 $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
01708 } elseif ($row['doktype']=='4') {
01709 if ($perms_clause) {
01710 $label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20);
01711 } else {
01712 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['shortcut']),'title');
01713 $label = $lRec['title'];
01714 }
01715 if ($row['shortcut_mode']>0) {
01716 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
01717 $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
01718 }
01719 $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
01720 } elseif ($row['doktype']=='7') {
01721 if ($perms_clause) {
01722 $label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
01723 } else {
01724 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['mount_pid']),'title');
01725 $label = $lRec['title'];
01726 }
01727 $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
01728 if ($row['mount_pid_ol']) {
01729 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
01730 }
01731 }
01732 if ($row['nav_hide']) $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
01733 if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
01734 if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date');
01735 if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date');
01736 if ($row['fe_group']) {
01737 $fe_groups = array();
01738 foreach (t3lib_div::intExplode(',',$row['fe_group']) as $fe_group) {
01739 if ($fe_group<0) {
01740 $fe_groups[] = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$fe_group));
01741 } else {
01742 $lRec = t3lib_BEfunc::getRecordWSOL('fe_groups',$fe_group,'title');
01743 $fe_groups[] = $lRec['title'];
01744 }
01745 }
01746 $label = implode(', ',$fe_groups);
01747 $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
01748 }
01749 $out = htmlspecialchars(implode(' - ',$parts));
01750 return $includeAttrib ? 'title="'.$out.'"' : $out;
01751 }
01752
01763 function getRecordIconAltText($row,$table='pages') {
01764 if ($table=='pages') {
01765 $out = t3lib_BEfunc::titleAttribForPages($row,'',0);
01766 } else {
01767 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
01768
01769 $out='id='.$row['uid'];
01770 if ($table=='pages' && $row['alias']) {
01771 $out.=' / '.$row['alias'];
01772 }
01773 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
01774 $out.=' - v#1.'.$row['t3ver_id'];
01775 }
01776 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
01777 switch($row['t3ver_state']) {
01778 case 1:
01779 $out.= ' - PLH WSID#'.$row['t3ver_wsid'];
01780 break;
01781 case 2:
01782 $out.= ' - Deleted element!';
01783 break;
01784 case 3:
01785 $out.= ' - NEW LOCATION (PLH) WSID#'.$row['t3ver_wsid'];
01786 break;
01787 case 4:
01788 $out.= ' - OLD LOCATION (PNT) WSID#'.$row['t3ver_wsid'];
01789 break;
01790 case -1:
01791 $out.= ' - New element!';
01792 break;
01793 }
01794 }
01795
01796 if ($ctrl['disabled']) {
01797 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
01798 }
01799 if ($ctrl['starttime']) {
01800 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
01801 $out.=' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.starttime').':'.t3lib_BEfunc::date($row[$ctrl['starttime']]).' ('.t3lib_BEfunc::daysUntil($row[$ctrl['starttime']]).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.days').')';
01802