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
00183 class t3lib_BEfunc {
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00204 function deleteClause($table,$tableAlias='') {
00205 global $TCA;
00206 if ($TCA[$table]['ctrl']['delete']) {
00207 return ' AND '.($tableAlias ? $tableAlias : $table).'.'.$TCA[$table]['ctrl']['delete'].'=0';
00208 } else {
00209 return '';
00210 }
00211 }
00212
00227 function getRecord($table,$uid,$fields='*',$where='') {
00228 if ($GLOBALS['TCA'][$table]) {
00229 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).t3lib_BEfunc::deleteClause($table).$where);
00230 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00231 return $row;
00232 }
00233 }
00234 }
00235
00245 function getRecordWSOL($table,$uid,$fields='*',$where='') {
00246 if ($fields !== '*') {
00247 $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
00248 $row = t3lib_BEfunc::getRecord($table,$uid,$internalFields,$where);
00249 t3lib_BEfunc::workspaceOL($table,$row);
00250
00251 if (is_array ($row)) {
00252 foreach (array_keys($row) as $key) {
00253 if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
00254 unset ($row[$key]);
00255 }
00256 }
00257 }
00258 } else {
00259 $row = t3lib_BEfunc::getRecord($table,$uid,$fields,$where);
00260 t3lib_BEfunc::workspaceOL($table,$row);
00261 }
00262 return $row;
00263 }
00264
00278 function getRecordRaw($table,$where='',$fields='*') {
00279 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where);
00280 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00281 return $row;
00282 }
00283 }
00284
00300 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='') {
00301 global $TCA;
00302 if (is_array($TCA[$theTable])) {
00303 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00304 '*',
00305 $theTable,
00306 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
00307 t3lib_BEfunc::deleteClause($theTable).' '.
00308 t3lib_BEfunc::versioningPlaceholderClause($theTable).' '.
00309 $whereClause,
00310 $groupBy,
00311 $orderBy,
00312 $limit
00313 );
00314 $rows = array();
00315 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00316 $rows[] = $row;
00317 }
00318 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00319 if (count($rows)) return $rows;
00320 }
00321 }
00322
00333 function searchQuery($searchWords,$fields,$table='') {
00334 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
00335 }
00336
00348 function listQuery($field,$value) {
00349 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
00350 }
00351
00360 function splitTable_Uid($str) {
00361 list($uid,$table) = explode('_',strrev($str),2);
00362 return array(strrev($table),strrev($uid));
00363 }
00364
00375 function getSQLselectableList($in_list,$tablename,$default_tablename) {
00376 $list = Array();
00377 if ((string)trim($in_list)!='') {
00378 $tempItemArray = explode(',',trim($in_list));
00379 while(list($key,$val)=each($tempItemArray)) {
00380 $val = strrev($val);
00381 $parts = explode('_',$val,2);
00382 if ((string)trim($parts[0])!='') {
00383 $theID = intval(strrev($parts[0]));
00384 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
00385 if ($theTable==$tablename) {$list[]=$theID;}
00386 }
00387 }
00388 }
00389 return implode(',',$list);
00390 }
00391
00403 function BEenableFields($table,$inv=0) {
00404 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00405 $query=array();
00406 $invQuery=array();
00407 if (is_array($ctrl)) {
00408 if (is_array($ctrl['enablecolumns'])) {
00409 if ($ctrl['enablecolumns']['disabled']) {
00410 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00411 $query[]=$field.'=0';
00412 $invQuery[]=$field.'!=0';
00413 }
00414 if ($ctrl['enablecolumns']['starttime']) {
00415 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00416 $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00417 $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00418 }
00419 if ($ctrl['enablecolumns']['endtime']) {
00420 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00421 $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00422 $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00423 }
00424 }
00425 }
00426 $outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
00427
00428 return $outQ;
00429 }
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00467 function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
00468 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00469 $select,
00470 $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
00471 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
00472 $whereClause,
00473 $groupBy,
00474 $orderBy,
00475 $limit
00476 );
00477 return $query;
00478 }
00479
00489 function DBcompileInsert($table,$fields_values) {
00490 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
00491 }
00492
00503 function DBcompileUpdate($table,$where,$fields_values) {
00504 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
00505 }
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00533 function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE) {
00534 $loopCheck = 100;
00535 $theRowArray = Array();
00536 $output = Array();
00537 while ($uid!=0 && $loopCheck>0) {
00538 $loopCheck--;
00539 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00540 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
00541 'pages',
00542 'uid='.intval($uid).' '.
00543 t3lib_BEfunc::deleteClause('pages').' '.
00544 $clause
00545 );
00546 if ($GLOBALS['TYPO3_DB']->sql_error()) {
00547 debug($GLOBALS['TYPO3_DB']->sql_error(),1);
00548 }
00549 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00550 if($workspaceOL) t3lib_BEfunc::workspaceOL('pages',$row);
00551 t3lib_BEfunc::fixVersioningPid('pages',$row);
00552 $uid = $row['pid'];
00553 $theRowArray[] = $row;
00554 } else {
00555 break;
00556 }
00557 }
00558 if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');}
00559 if (is_array($theRowArray)) {
00560 reset($theRowArray);
00561 $c=count($theRowArray);
00562 while(list($key,$val)=each($theRowArray)) {
00563 $c--;
00564 $output[$c]['uid'] = $val['uid'];
00565 $output[$c]['pid'] = $val['pid'];
00566 if (isset($val['_ORIG_pid'])) $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
00567 $output[$c]['title'] = $val['title'];
00568 $output[$c]['TSconfig'] = $val['TSconfig'];
00569 $output[$c]['is_siteroot'] = $val['is_siteroot'];
00570 $output[$c]['storage_pid'] = $val['storage_pid'];
00571 $output[$c]['t3ver_oid'] = $val['t3ver_oid'];
00572 $output[$c]['t3ver_wsid'] = $val['t3ver_wsid'];
00573 $output[$c]['t3ver_state'] = $val['t3ver_state'];
00574 $output[$c]['t3ver_swapmode'] = $val['t3ver_swapmode'];
00575 $output[$c]['t3ver_stage'] = $val['t3ver_stage'];
00576 }
00577 }
00578
00579 return $output;
00580 }
00581
00589 function openPageTree($pid,$clearExpansion) {
00590 global $BE_USER;
00591
00592
00593 if ($clearExpansion) {
00594 $expandedPages = array();
00595 } else {
00596 $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
00597 }
00598
00599
00600 $rL = t3lib_BEfunc::BEgetRootLine($pid);
00601
00602
00603 $mountIndex = 0;
00604 $mountKeys = array_flip($BE_USER->returnWebmounts());
00605 foreach($rL as $rLDat) {
00606 if (isset($mountKeys[$rLDat['uid']])) {
00607 $mountIndex = $mountKeys[$rLDat['uid']];
00608 break;
00609 }
00610 }
00611
00612
00613 foreach($rL as $rLDat) {
00614 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
00615 }
00616
00617
00618 $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
00619 $BE_USER->writeUC();
00620 }
00621
00634 function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) {
00635 if (!$titleLimit) { $titleLimit=1000; }
00636
00637 $loopCheck = 100;
00638 $output = $fullOutput = '/';
00639 while ($uid!=0 && $loopCheck>0) {
00640 $loopCheck--;
00641 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00642 'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode',
00643 'pages',
00644 'uid='.intval($uid).
00645 t3lib_BEfunc::deleteClause('pages').
00646 (strlen(trim($clause)) ? ' AND '.$clause : '')
00647 );
00648 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00649 t3lib_BEfunc::workspaceOL('pages',$row);
00650 t3lib_BEfunc::fixVersioningPid('pages',$row);
00651
00652 if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0) {
00653 $output = ' [#VEP#]'.$output;
00654 }
00655 $uid = $row['pid'];
00656 $output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output;
00657 if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
00658 } else {
00659 break;
00660 }
00661 }
00662
00663 if ($fullTitleLimit) {
00664 return array($output, $fullOutput);
00665 } else {
00666 return $output;
00667 }
00668 }
00669
00677 function getExcludeFields() {
00678 global $TCA;
00679
00680 $theExcludeArray = Array();
00681 $tc_keys = array_keys($TCA);
00682 foreach($tc_keys as $table) {
00683
00684 t3lib_div::loadTCA($table);
00685
00686 if (is_array($TCA[$table]['columns'])) {
00687 $f_keys = array_keys($TCA[$table]['columns']);
00688 foreach($f_keys as $field) {
00689 if ($TCA[$table]['columns'][$field]['exclude']) {
00690
00691 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00692
00693 $theExcludeArray[] = Array($Fname , $table.':'.$field);
00694 }
00695 }
00696 }
00697 }
00698 return $theExcludeArray;
00699 }
00700
00707 function getExplicitAuthFieldValues() {
00708 global $TCA;
00709
00710
00711 $adLabel = array(
00712 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
00713 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
00714 );
00715
00716
00717 $allowDenyOptions = Array();
00718 $tc_keys = array_keys($TCA);
00719 foreach($tc_keys as $table) {
00720
00721
00722 t3lib_div::loadTCA($table);
00723
00724
00725 if (is_array($TCA[$table]['columns'])) {
00726 $f_keys = array_keys($TCA[$table]['columns']);
00727 foreach($f_keys as $field) {
00728 $fCfg = $TCA[$table]['columns'][$field]['config'];
00729 if ($fCfg['type']=='select' && $fCfg['authMode']) {
00730
00731
00732 if (is_array($fCfg['items'])) {
00733
00734 $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00735
00736
00737 foreach($fCfg['items'] as $iVal) {
00738 if (strcmp($iVal[1],'')) {
00739
00740
00741 $iMode = '';
00742 switch((string)$fCfg['authMode']) {
00743 case 'explicitAllow':
00744 $iMode = 'ALLOW';
00745 break;
00746 case 'explicitDeny':
00747 $iMode = 'DENY';
00748 break;
00749 case 'individual':
00750 if (!strcmp($iVal[4],'EXPL_ALLOW')) {
00751 $iMode = 'ALLOW';
00752 } elseif (!strcmp($iVal[4],'EXPL_DENY')) {
00753 $iMode = 'DENY';
00754 }
00755 break;
00756 }
00757
00758
00759 if ($iMode) {
00760 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
00761 }
00762 }
00763 }
00764 }
00765 }
00766 }
00767 }
00768 }
00769
00770 return $allowDenyOptions;
00771 }
00772
00778 function getSystemLanguages() {
00779
00780
00781 $sysLanguages = array();
00782 $sysLanguages[] = array('Default language', 0);
00783
00784
00785 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language'));
00786 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00787 $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
00788 }
00789
00790 return $sysLanguages;
00791 }
00792
00803 function readPageAccess($id,$perms_clause) {
00804 if ((string)$id!='') {
00805 $id = intval($id);
00806 if (!$id) {
00807 if ($GLOBALS['BE_USER']->isAdmin()) {
00808 $path = '/';
00809 $pageinfo['_thePath'] = $path;
00810 return $pageinfo;
00811 }
00812 } else {
00813 $pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : ''));
00814 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) {
00815 t3lib_BEfunc::workspaceOL('pages', $pageinfo);
00816 t3lib_BEfunc::fixVersioningPid('pages', $pageinfo);
00817 list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
00818 return $pageinfo;
00819 }
00820 }
00821 }
00822 return false;
00823 }
00824
00834 function getTCAtypes($table,$rec,$useFieldNameAsKey=0) {
00835 global $TCA;
00836
00837 t3lib_div::loadTCA($table);
00838 if ($TCA[$table]) {
00839
00840
00841 $fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec);
00842
00843
00844 $typesConf = $TCA[$table]['types'][$fieldValue];
00845
00846
00847 $fieldList = explode(',', $typesConf['showitem']);
00848 $altFieldList = array();
00849
00850
00851 foreach($fieldList as $k => $v) {
00852 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
00853 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
00854 $specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
00855
00856 $fieldList[$k]=array(
00857 'field' => $pFieldName,
00858 'title' => $pAltTitle,
00859 'palette' => $pPalette,
00860 'spec' => $specConfParts,
00861 'origString' => $v
00862 );
00863 if ($useFieldNameAsKey) {
00864 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
00865 }
00866 }
00867 if ($useFieldNameAsKey) {
00868 $fieldList = $altFieldList;
00869 }
00870
00871
00872 return $fieldList;
00873 }
00874 }
00875
00887 function getTCAtypeValue($table,$rec) {
00888 global $TCA;
00889
00890
00891 t3lib_div::loadTCA($table);
00892 if ($TCA[$table]) {
00893 $field = $TCA[$table]['ctrl']['type'];
00894 $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
00895 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
00896 return $fieldValue;
00897 }
00898 }
00899
00910 function getSpecConfParts($str, $defaultExtras) {
00911
00912
00913 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
00914
00915 $reg = array();
00916 if (count($specConfParts)) {
00917 foreach($specConfParts as $k2 => $v2) {
00918 unset($specConfParts[$k2]);
00919 if (ereg('(.*)\[(.*)\]',$v2,$reg)) {
00920 $specConfParts[trim($reg[1])] = array(
00921 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
00922 );
00923 } else {
00924 $specConfParts[trim($v2)] = 1;
00925 }
00926 }
00927 } else {
00928 $specConfParts = array();
00929 }
00930 return $specConfParts;
00931 }
00932
00941 function getSpecConfParametersFromArray($pArr) {
00942 $out=array();
00943 if (is_array($pArr)) {
00944 reset($pArr);
00945 while(list($k,$v)=each($pArr)) {
00946 $parts=explode('=',$v,2);
00947 if (count($parts)==2) {
00948 $out[trim($parts[0])]=trim($parts[1]);
00949 } else {
00950 $out[$k]=$v;
00951 }
00952 }
00953 }
00954 return $out;
00955 }
00956
00969 function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE) {
00970 global $TYPO3_CONF_VARS;
00971
00972
00973 $ds_pointerField = $conf['ds_pointerField'];
00974 $ds_array = $conf['ds'];
00975 $ds_tableField = $conf['ds_tableField'];
00976 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
00977
00978
00979 $dataStructArray='';
00980 if (is_array($ds_array)) {
00981
00982 if ($ds_pointerField) {
00983 $srcPointer = $row[$ds_pointerField];
00984 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
00985 } else $srcPointer='default';
00986
00987
00988 if (substr($ds_array[$srcPointer],0,5)=='FILE:') {
00989 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5));
00990 if ($file && @is_file($file)) {
00991 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
00992 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")';
00993 } else {
00994 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
00995 }
00996
00997 } elseif ($ds_pointerField) {
00998
00999 $srcPointer = $row[$ds_pointerField];
01000
01001
01002 if ($ds_searchParentField && !$srcPointer) {
01003 $rr = t3lib_BEfunc::getRecord($table,$row['uid'],'uid,'.$ds_searchParentField);
01004 if ($WSOL) {
01005 t3lib_BEfunc::workspaceOL($table,$rr);
01006 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
01007 }
01008 $uidAcc=array();
01009 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
01010 while(!$srcPointer) {
01011 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01012 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),
01013 $table,
01014 'uid='.intval($rr[$ds_searchParentField]).t3lib_BEfunc::deleteClause($table)
01015 );
01016 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01017
01018
01019 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break;
01020 $uidAcc[$rr['uid']]=1;
01021
01022 if ($WSOL) {
01023 t3lib_BEfunc::workspaceOL($table,$rr);
01024 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
01025 }
01026 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
01027 }
01028 }
01029
01030
01031 if ($srcPointer) {
01032 if (t3lib_div::testInt($srcPointer)) {
01033 list($tName,$fName) = explode(':',$ds_tableField,2);
01034 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
01035 $dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer);
01036 if ($WSOL) {
01037 t3lib_BEfunc::workspaceOL($tName,$dataStructRec);
01038 }
01039 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
01040 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
01041 } else {
01042 $file = t3lib_div::getFileAbsFileName($srcPointer);
01043 if ($file && @is_file($file)) {
01044 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01045 } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")';
01046 }
01047 } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"';
01048 } else $dataStructArray='No proper configuration!';
01049
01050
01051 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
01052 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
01053 $hookObj = &t3lib_div::getUserObj($classRef);
01054 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
01055 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
01056 }
01057 }
01058 }
01059
01060 return $dataStructArray;
01061 }
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01096 function storeHash($hash,$data,$ident) {
01097 $insertFields = array(
01098 'hash' => $hash,
01099 'content' => $data,
01100 'ident' => $ident,
01101 'tstamp' => time()
01102 );
01103 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
01104 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
01105 }
01106
01116 function getHash($hash,$expTime=0) {
01117
01118 $expTime = intval($expTime);
01119 if ($expTime) {
01120 $whereAdd = ' AND tstamp > '.(time()-$expTime);
01121 }
01122 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
01123 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01124 return $row['content'];
01125 }
01126 }
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01152 function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) {
01153 $id=intval($id);
01154 if (!is_array($rootLine)) {
01155 $rootLine = t3lib_BEfunc::BEgetRootLine($id,'',TRUE);
01156 }
01157 ksort($rootLine);
01158 $TSdataArray = array();
01159 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
01160 foreach($rootLine as $k => $v) {
01161 $TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
01162 }
01163 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
01164 if ($returnPartArray) {
01165 return $TSdataArray;
01166 }
01167
01168
01169 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
01170 $hash = md5('pageTS:'.$userTS);
01171 $cachedContent = t3lib_BEfunc::getHash($hash,0);
01172 $TSconfig = array();
01173 if (isset($cachedContent)) {
01174 $TSconfig = unserialize($cachedContent);
01175 } else {
01176 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
01177 $parseObj->parse($userTS);
01178 $TSconfig = $parseObj->setup;
01179 t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
01180 }
01181
01182
01183 $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
01184 if (is_array($userTSconfig)) {
01185 $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
01186 }
01187 return $TSconfig;
01188 }
01189
01208 function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') {
01209 $id=intval($id);
01210 if (is_array($pageTS) && $id>0) {
01211 if (!is_array($impParams)) {
01212 $impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id));
01213 }
01214 reset($pageTS);
01215 $set=array();
01216 while(list($f,$v)=each($pageTS)) {
01217 $f = $TSconfPrefix.$f;
01218 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v))) {
01219 $set[$f]=trim($v);
01220 }
01221 }
01222 if (count($set)) {
01223
01224 $pRec = t3lib_befunc::getRecord('pages',$id);
01225 $TSlines = explode(chr(10),$pRec['TSconfig']);
01226 $TSlines = array_reverse($TSlines);
01227
01228 reset($set);
01229 while(list($f,$v)=each($set)) {
01230 reset($TSlines);
01231 $inserted=0;
01232 while(list($ki,$kv)=each($TSlines)) {
01233 if (substr($kv,0,strlen($f)+1)==$f.'=') {
01234 $TSlines[$ki]=$f.'='.$v;
01235 $inserted=1;
01236 break;
01237 }
01238 }
01239 if (!$inserted) {
01240 $TSlines = array_reverse($TSlines);
01241 $TSlines[]=$f.'='.$v;
01242 $TSlines = array_reverse($TSlines);
01243 }
01244 }
01245 $TSlines = array_reverse($TSlines);
01246
01247
01248 $TSconf = implode(chr(10),$TSlines);
01249
01250 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
01251 }
01252 }
01253 }
01254
01263 function implodeTSParams($p,$k='') {
01264 $implodeParams=array();
01265 if (is_array($p)) {
01266 reset($p);
01267 while(list($kb,$val)=each($p)) {
01268 if (is_array($val)) {
01269 $implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb));
01270 } else {
01271 $implodeParams[$k.$kb]=$val;
01272 }
01273 }
01274 }
01275 return $implodeParams;
01276 }
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290
01300 function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
01301 $be_user_Array=Array();
01302
01303 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username');
01304 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01305 $be_user_Array[$row['uid']]=$row;
01306 }
01307 return $be_user_Array;
01308 }
01309
01318 function getGroupNames($fields='title,uid', $where='') {
01319 $be_group_Array = Array();
01320 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
01321 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01322 $be_group_Array[$row['uid']] = $row;
01323 }
01324 return $be_group_Array;
01325 }
01326
01335 function getListGroupNames($fields='title,uid') {
01336 $exQ=' AND hide_in_lists=0';
01337 if (!$GLOBALS['BE_USER']->isAdmin()) {
01338 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
01339 }
01340 return t3lib_BEfunc::getGroupNames($fields,$exQ);
01341 }
01342
01354 function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) {
01355 if (is_array($usernames) && is_array($groupArray)) {
01356 while(list($uid,$row)=each($usernames)) {
01357 $userN=$uid;
01358 $set=0;
01359 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
01360 reset($groupArray);
01361 while(list(,$v)=each($groupArray)) {
01362 if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v)) {
01363 $userN = $row['username'];
01364 $set=1;
01365 }
01366 }
01367 } else {
01368 $userN = $row['username'];
01369 $set=1;
01370 }
01371 $usernames[$uid]['username']=$userN;
01372 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
01373 }
01374 }
01375 return $usernames;
01376 }
01377
01387 function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) {
01388 if (is_array($groups) && is_array($groupArray)) {
01389 while(list($uid,$row)=each($groups)) {
01390 $groupN=$uid;
01391 $set=0;
01392 if (t3lib_div::inArray($groupArray,$uid)) {
01393 $groupN=$row['title'];
01394 $set=1;
01395 }
01396 $groups[$uid]['title']=$groupN;
01397 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
01398 }
01399 }
01400 return $groups;
01401 }
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01428 function daysUntil($tstamp) {
01429 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
01430 return ceil($delta_t/(3600*24));
01431 }
01432
01440 function date($tstamp) {
01441 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
01442 }
01443
01451 function datetime($value) {
01452 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
01453 }
01454
01463 function time($value) {
01464 $hh = floor($value/3600);
01465 $min = floor(($value-$hh*3600)/60);
01466 $sec = $value-$hh*3600-$min*60;
01467 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
01468 return $l;
01469 }
01470
01479 function calcAge($seconds,$labels = 'min|hrs|days|yrs') {
01480 $labelArr = explode('|',$labels);
01481 $prefix='';
01482 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
01483 if ($seconds<3600) {
01484 $seconds = round ($seconds/60).' '.trim($labelArr[0]);
01485 } elseif ($seconds<24*3600) {
01486 $seconds = round ($seconds/3600).' '.trim($labelArr[1]);
01487 } elseif ($seconds<365*24*3600) {
01488 $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
01489 } else {
01490 $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
01491 }
01492 return $prefix.$seconds;
01493 }
01494
01505 function dateTimeAge($tstamp,$prefix=1,$date='') {
01506 return $tstamp ?
01507 ($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)).
01508 ' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
01509 }
01510
01523 function titleAttrib($content='',$hsc=0) {
01524 global $CLIENT;
01525 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
01526 return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
01527 }
01528
01536 function titleAltAttrib($content) {
01537 $out='';
01538 $out.=' alt="'.htmlspecialchars($content).'"';
01539 $out.=' title="'.htmlspecialchars($content).'"';
01540 return $out;
01541 }
01542
01560 function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='') {
01561 global $TCA;
01562
01563 t3lib_div::loadTCA($table);
01564
01565
01566 $uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
01567 $uploaddir = preg_replace('#/$#','',$uploaddir);
01568
01569
01570 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
01571 $thumbScript='gfx/notfound_thumb.gif';
01572 } elseif(!$thumbScript) {
01573 $thumbScript='thumbs.php';
01574 }
01575
01576 $sizeParts=array();
01577 if ($size = trim($size)) {
01578 $sizeParts = explode('x', $size.'x'.$size);
01579 if(!intval($sizeParts[0])) $size='';
01580 }
01581
01582
01583 $thumbs = explode(',', $row[$field]);
01584 $thumbData='';
01585 while(list(,$theFile)=each($thumbs)) {
01586 if (trim($theFile)) {
01587 $fI = t3lib_div::split_fileref($theFile);
01588 $ext = $fI['fileext'];
01589
01590 $max=0;
01591 if (t3lib_div::inList('gif,jpg,png',$ext)) {
01592 $imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile);
01593 if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);}
01594 }
01595
01596 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
01597 $theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01598 $onClick='top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01599 $thumbData.='<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
01600
01601 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
01602 $theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01603 $params = '&file='.rawurlencode($theFile);
01604 $params .= $size?'&size='.$size:'';
01605 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01606 $onClick='top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01607 $thumbData.='<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
01608 } else {
01609 $icon = t3lib_BEfunc::getFileIcon($ext);
01610 $url = 'gfx/fileicons/'.$icon;
01611 $thumbData.='<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
01612 }
01613 }
01614 }
01615 return $thumbData;
01616 }
01617
01628 function getThumbNail($thumbScript,$theFile,$tparams='',$size='') {
01629 $params = '&file='.rawurlencode($theFile);
01630 $params .= trim($size)?'&size='.trim($size):'';
01631 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01632 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
01633 return $th;
01634 }
01635
01645 function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) {
01646 global $TCA,$LANG;
01647 $parts=array();
01648 $parts[] = 'id='.$row['uid'];
01649 if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
01650 if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id'];
01651 if ($row['t3ver_state']==1) $parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
01652 if ($row['t3ver_state']==-1) $parts[] = 'New element!';
01653
01654 if ($row['doktype']=='3') {
01655 $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
01656 } elseif ($row['doktype']=='4') {
01657 if ($perms_clause) {
01658 $label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20);
01659 } else {
01660 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['shortcut']),'title');
01661 $label = $lRec['title'];
01662 }
01663 if ($row['shortcut_mode']>0) {
01664 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
01665 $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
01666 }
01667 $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
01668 } elseif ($row['doktype']=='7') {
01669 if ($perms_clause) {
01670 $label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
01671 } else {
01672 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['mount_pid']),'title');
01673 $label = $lRec['title'];
01674 }
01675 $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
01676 if ($row['mount_pid_ol']) {
01677 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
01678 }
01679 }
01680 if ($row['nav_hide']) $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
01681 if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
01682 if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date');
01683 if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date');
01684 if ($row['fe_group']) {
01685 if ($row['fe_group']<0) {
01686 $label = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$row['fe_group']));
01687 } else {
01688 $lRec = t3lib_BEfunc::getRecordWSOL('fe_groups',$row['fe_group'],'title');
01689 $label = $lRec['title'];
01690 }
01691 $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
01692 }
01693 $out = htmlspecialchars(implode(' - ',$parts));
01694 return $includeAttrib ? 'title="'.$out.'"' : $out;
01695 }
01696
01707 function getRecordIconAltText($row,$table='pages') {
01708 if ($table=='pages') {
01709 $out = t3lib_BEfunc::titleAttribForPages($row,'',0);
01710 } else {
01711 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
01712
01713 $out='id='.$row['uid'];
01714 if ($table=='pages' && $row['alias']) {
01715 $out.=' / '.$row['alias'];
01716 }
01717 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
01718 $out.=' - v#1.'.$row['t3ver_id'];
01719 }
01720 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
01721 if ($row['t3ver_state']==1) $out.= ' - PLH WSID#'.$row['t3ver_wsid'];
01722 if ($row['t3ver_state']==-1) $out.= ' - New element!';
01723 }
01724
01725 if ($ctrl['disabled']) {
01726 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
01727 }
01728 if ($ctrl['starttime']) {
01729 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
01730 $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').')';
01731 }
01732 }
01733 if ($row[$ctrl['endtime']]) {
01734 $out.=' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.endtime').': '.t3lib_BEfunc::date($row[$ctrl['endtime']]).' ('.t3lib_BEfunc::daysUntil($row[$ctrl['endtime']]).' '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.days').')';
01735 }
01736 }
01737 return htmlspecialchars($out);
01738 }
01739
01749 function getLabelFromItemlist($table,$col,$key) {
01750 global $TCA;
01751
01752 t3lib_div::loadTCA($table);
01753
01754
01755 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
01756
01757 reset($TCA[$table]['columns'][$col]['config']['items']);
01758 while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items'])) {
01759
01760 if (!strcmp($v[1],$key)) return $v[0];
01761 }
01762 }
01763 }
01764
01775 function getItemLabel($table,$col,$printAllWrap='') {
01776 global $TCA;
01777
01778 t3lib_div::loadTCA($table);
01779
01780 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
01781
01782 return $TCA[$table]['columns'][$col]['label'];
01783 }
01784 if ($printAllWrap) {
01785 $parts = explode('|',$printAllWrap);
01786 return $parts[0].$col.$parts[1];
01787 }
01788 }
01789
01800 function getRecordTitle($table,$row,$prep=0) {
01801 global $TCA;
01802 if (is_array($TCA[$table])) {
01803 $t = $row[$TCA[$table]['ctrl']['label']];
01804 if ($TCA[$table]['ctrl']['label_alt'] && ($TCA[$table]['ctrl']['label_alt_force'] || !strcmp($t,''))) {
01805 $altFields=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1);
01806 $tA=array();
01807 $tA[]=$t;
01808 while(list(,$fN)=each($altFields)) {
01809 $t = $tA[] = trim(strip_tags($row[$fN]));
01810 if (strcmp($t,'') && !$TCA[$table]['ctrl']['label_alt_force']) break;
01811 }
01812 if ($TCA[$table]['ctrl']['label_alt_force']) $t=implode(', ',$tA);
01813 }
01814 if ($prep) {
01815 $t = htmlspecialchars(t3lib_div::fixed_lgd_cs($t,$GLOBALS['BE_USER']->uc['titleLen']));
01816 if (!strcmp(trim($t),'')) $t='<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>';
01817 }
01818 return $t;
01819 }
01820 }
01821
01838 function