Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00174 require_once (PATH_t3lib.'class.t3lib_loaddbgroup.php'); 00175 00176 00185 class t3lib_BEfunc { 00186 00187 00188 00189 /******************************************* 00190 * 00191 * SQL-related, selecting records, searching 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 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00238 return $row; 00239 } 00240 } 00241 } 00242 00253 function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true) { 00254 if ($fields !== '*') { 00255 $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : '')); 00256 $row = t3lib_BEfunc::getRecord($table,$uid,$internalFields,$where,$useDeleteClause); 00257 t3lib_BEfunc::workspaceOL($table,$row); 00258 00259 if (is_array ($row)) { 00260 foreach (array_keys($row) as $key) { 00261 if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') { 00262 unset ($row[$key]); 00263 } 00264 } 00265 } 00266 } else { 00267 $row = t3lib_BEfunc::getRecord($table,$uid,$fields,$where); 00268 t3lib_BEfunc::workspaceOL($table,$row); 00269 } 00270 return $row; 00271 } 00272 00286 function getRecordRaw($table,$where='',$fields='*') { 00287 $row = FALSE; 00288 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) { 00289 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); 00290 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00291 } 00292 return $row; 00293 } 00294 00311 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true) { 00312 global $TCA; 00313 if (is_array($TCA[$theTable])) { 00314 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00315 '*', 00316 $theTable, 00317 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable). 00318 ($useDeleteClause ? t3lib_BEfunc::deleteClause($theTable).' ' : ''). 00319 t3lib_BEfunc::versioningPlaceholderClause($theTable).' '. 00320 $whereClause, // whereClauseMightContainGroupOrderBy 00321 $groupBy, 00322 $orderBy, 00323 $limit 00324 ); 00325 $rows = array(); 00326 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00327 $rows[] = $row; 00328 } 00329 $GLOBALS['TYPO3_DB']->sql_free_result($res); 00330 if (count($rows)) return $rows; 00331 } 00332 } 00333 00344 function searchQuery($searchWords,$fields,$table='') { 00345 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table); 00346 } 00347 00359 function listQuery($field,$value) { 00360 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,''); 00361 } 00362 00371 function splitTable_Uid($str) { 00372 list($uid,$table) = explode('_',strrev($str),2); 00373 return array(strrev($table),strrev($uid)); 00374 } 00375 00386 function getSQLselectableList($in_list,$tablename,$default_tablename) { 00387 $list = Array(); 00388 if ((string)trim($in_list)!='') { 00389 $tempItemArray = explode(',',trim($in_list)); 00390 while(list($key,$val)=each($tempItemArray)) { 00391 $val = strrev($val); 00392 $parts = explode('_',$val,2); 00393 if ((string)trim($parts[0])!='') { 00394 $theID = intval(strrev($parts[0])); 00395 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename; 00396 if ($theTable==$tablename) {$list[]=$theID;} 00397 } 00398 } 00399 } 00400 return implode(',',$list); 00401 } 00402 00414 function BEenableFields($table,$inv=0) { 00415 $ctrl = $GLOBALS['TCA'][$table]['ctrl']; 00416 $query=array(); 00417 $invQuery=array(); 00418 if (is_array($ctrl)) { 00419 if (is_array($ctrl['enablecolumns'])) { 00420 if ($ctrl['enablecolumns']['disabled']) { 00421 $field = $table.'.'.$ctrl['enablecolumns']['disabled']; 00422 $query[]=$field.'=0'; 00423 $invQuery[]=$field.'!=0'; 00424 } 00425 if ($ctrl['enablecolumns']['starttime']) { 00426 $field = $table.'.'.$ctrl['enablecolumns']['starttime']; 00427 $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')'; 00428 $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')'; 00429 } 00430 if ($ctrl['enablecolumns']['endtime']) { 00431 $field = $table.'.'.$ctrl['enablecolumns']['endtime']; 00432 $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')'; 00433 $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')'; 00434 } 00435 } 00436 } 00437 $outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query)); 00438 00439 return $outQ; 00440 } 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 /******************************************* 00452 * 00453 * SQL-related, DEPRECATED functions 00454 * (use t3lib_DB functions instead) 00455 * 00456 *******************************************/ 00457 00458 00478 function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') { 00479 $query = $GLOBALS['TYPO3_DB']->SELECTquery( 00480 $select, 00481 $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''), 00482 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '. 00483 $whereClause, // whereClauseMightContainGroupOrderBy 00484 $groupBy, 00485 $orderBy, 00486 $limit 00487 ); 00488 return $query; 00489 } 00490 00500 function DBcompileInsert($table,$fields_values) { 00501 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values); 00502 } 00503 00514 function DBcompileUpdate($table,$where,$fields_values) { 00515 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values); 00516 } 00517 00518 00519 00520 00521 00522 00523 00524 00525 00526 00527 /******************************************* 00528 * 00529 * Page tree, TCA related 00530 * 00531 *******************************************/ 00532 00544 function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE) { 00545 if (is_array($GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0])) { 00546 return $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0]; 00547 } 00548 $pid = $uid; 00549 $loopCheck = 100; 00550 $theRowArray = Array(); 00551 $output = Array(); 00552 while ($uid!=0 && $loopCheck>0) { 00553 $loopCheck--; 00554 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00555 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage', 00556 'pages', 00557 'uid='.intval($uid).' '. 00558 t3lib_BEfunc::deleteClause('pages').' '. 00559 $clause // whereClauseMightContainGroupOrderBy 00560 ); 00561 if ($GLOBALS['TYPO3_DB']->sql_error()) { 00562 debug($GLOBALS['TYPO3_DB']->sql_error(),1); 00563 } 00564 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00565 if($workspaceOL) t3lib_BEfunc::workspaceOL('pages',$row); 00566 t3lib_BEfunc::fixVersioningPid('pages',$row); 00567 $uid = $row['pid']; 00568 $theRowArray[] = $row; 00569 } else { 00570 break; 00571 } 00572 } 00573 if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');} 00574 if (is_array($theRowArray)) { 00575 reset($theRowArray); 00576 $c=count($theRowArray); 00577 while(list($key,$val)=each($theRowArray)) { 00578 $c--; 00579 $output[$c]['uid'] = $val['uid']; 00580 $output[$c]['pid'] = $val['pid']; 00581 if (isset($val['_ORIG_pid'])) $output[$c]['_ORIG_pid'] = $val['_ORIG_pid']; 00582 $output[$c]['title'] = $val['title']; 00583 $output[$c]['TSconfig'] = $val['TSconfig']; 00584 $output[$c]['is_siteroot'] = $val['is_siteroot']; 00585 $output[$c]['storage_pid'] = $val['storage_pid']; 00586 $output[$c]['t3ver_oid'] = $val['t3ver_oid']; 00587 $output[$c]['t3ver_wsid'] = $val['t3ver_wsid']; 00588 $output[$c]['t3ver_state'] = $val['t3ver_state']; 00589 $output[$c]['t3ver_swapmode'] = $val['t3ver_swapmode']; 00590 $output[$c]['t3ver_stage'] = $val['t3ver_stage']; 00591 } 00592 } 00593 $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$pid][$clause][$workspaceOL?1:0] = $output; 00594 00595 return $output; 00596 } 00597 00605 function openPageTree($pid,$clearExpansion) { 00606 global $BE_USER; 00607 00608 // Get current expansion data: 00609 if ($clearExpansion) { 00610 $expandedPages = array(); 00611 } else { 00612 $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']); 00613 } 00614 00615 // Get rootline: 00616 $rL = t3lib_BEfunc::BEgetRootLine($pid); 00617 00618 // First, find out what mount index to use (if more than one DB mount exists): 00619 $mountIndex = 0; 00620 $mountKeys = array_flip($BE_USER->returnWebmounts()); 00621 foreach($rL as $rLDat) { 00622 if (isset($mountKeys[$rLDat['uid']])) { 00623 $mountIndex = $mountKeys[$rLDat['uid']]; 00624 break; 00625 } 00626 } 00627 00628 // Traverse rootline and open paths: 00629 foreach($rL as $rLDat) { 00630 $expandedPages[$mountIndex][$rLDat['uid']] = 1; 00631 } 00632 00633 // Write back: 00634 $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages); 00635 $BE_USER->writeUC(); 00636 } 00637 00650 function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) { 00651 if (!$titleLimit) { $titleLimit=1000; } 00652 00653 $loopCheck = 100; 00654 $output = $fullOutput = '/'; 00655 while ($uid!=0 && $loopCheck>0) { 00656 $loopCheck--; 00657 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00658 'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode', 00659 'pages', 00660 'uid='.intval($uid). 00661 t3lib_BEfunc::deleteClause('pages'). 00662 (strlen(trim($clause)) ? ' AND '.$clause : '') 00663 ); 00664 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00665 t3lib_BEfunc::workspaceOL('pages',$row); 00666 t3lib_BEfunc::fixVersioningPid('pages',$row); 00667 00668 if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0) { // Branch points 00669 $output = ' [#VEP#]'.$output; // Adding visual token - Versioning Entry Point - that tells that THIS position was where the versionized branch got connected to the main tree. I will have to find a better name or something... 00670 } 00671 $uid = $row['pid']; 00672 $output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output; 00673 if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput; 00674 } else { 00675 break; 00676 } 00677 } 00678 00679 if ($fullTitleLimit) { 00680 return array($output, $fullOutput); 00681 } else { 00682 return $output; 00683 } 00684 } 00685 00693 function getExcludeFields() { 00694 global $TCA; 00695 // All TCA keys: 00696 $theExcludeArray = Array(); 00697 $tc_keys = array_keys($TCA); 00698 foreach($tc_keys as $table) { 00699 // Load table 00700 t3lib_div::loadTCA($table); 00701 // All field names configured: 00702 if (is_array($TCA[$table]['columns'])) { 00703 $f_keys = array_keys($TCA[$table]['columns']); 00704 foreach($f_keys as $field) { 00705 if ($TCA[$table]['columns'][$field]['exclude']) { 00706 // Get Human Readable names of fields and table: 00707 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']); 00708 // add entry: 00709 $theExcludeArray[] = Array($Fname , $table.':'.$field); 00710 } 00711 } 00712 } 00713 } 00714 return $theExcludeArray; 00715 } 00716 00723 function getExplicitAuthFieldValues() { 00724 global $TCA; 00725 00726 // Initialize: 00727 $adLabel = array( 00728 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'), 00729 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'), 00730 ); 00731 00732 // All TCA keys: 00733 $allowDenyOptions = Array(); 00734 $tc_keys = array_keys($TCA); 00735 foreach($tc_keys as $table) { 00736 00737 // Load table 00738 t3lib_div::loadTCA($table); 00739 00740 // All field names configured: 00741 if (is_array($TCA[$table]['columns'])) { 00742 $f_keys = array_keys($TCA[$table]['columns']); 00743 foreach($f_keys as $field) { 00744 $fCfg = $TCA[$table]['columns'][$field]['config']; 00745 if ($fCfg['type']=='select' && $fCfg['authMode']) { 00746 00747 // Check for items: 00748 if (is_array($fCfg['items'])) { 00749 // Get Human Readable names of fields and table: 00750 $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']); 00751 00752 // Check for items: 00753 foreach($fCfg['items'] as $iVal) { 00754 if (strcmp($iVal[1],'')) { // Values '' is not controlled by this setting. 00755 00756 // Find iMode: 00757 $iMode = ''; 00758 switch((string)$fCfg['authMode']) { 00759 case 'explicitAllow': 00760 $iMode = 'ALLOW'; 00761 break; 00762 case 'explicitDeny': 00763 $iMode = 'DENY'; 00764 break; 00765 case 'individual': 00766 if (!strcmp($iVal[4],'EXPL_ALLOW')) { 00767 $iMode = 'ALLOW'; 00768 } elseif (!strcmp($iVal[4],'EXPL_DENY')) { 00769 $iMode = 'DENY'; 00770 } 00771 break; 00772 } 00773 00774 // Set iMode: 00775 if ($iMode) { 00776 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]); 00777 } 00778 } 00779 } 00780 } 00781 } 00782 } 00783 } 00784 } 00785 00786 return $allowDenyOptions; 00787 } 00788 00794 function getSystemLanguages() { 00795 00796 // Initialize, add default language: 00797 $sysLanguages = array(); 00798 $sysLanguages[] = array('Default language', 0); 00799 00800 // Traverse languages 00801 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language')); 00802 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00803 $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : '')); 00804 } 00805 00806 return $sysLanguages; 00807 } 00808 00819 function readPageAccess($id,$perms_clause) { 00820 if ((string)$id!='') { 00821 $id = intval($id); 00822 if (!$id) { 00823 if ($GLOBALS['BE_USER']->isAdmin()) { 00824 $path = '/'; 00825 $pageinfo['_thePath'] = $path; 00826 return $pageinfo; 00827 } 00828 } else { 00829 $pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : '')); 00830 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) { 00831 t3lib_BEfunc::workspaceOL('pages', $pageinfo); 00832 t3lib_BEfunc::fixVersioningPid('pages', $pageinfo); 00833 list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000); 00834 return $pageinfo; 00835 } 00836 } 00837 } 00838 return false; 00839 } 00840 00850 function getTCAtypes($table,$rec,$useFieldNameAsKey=0) { 00851 global $TCA; 00852 00853 t3lib_div::loadTCA($table); 00854 if ($TCA[$table]) { 00855 00856 // Get type value: 00857 $fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec); 00858 00859 // Get typesConf 00860 $typesConf = $TCA[$table]['types'][$fieldValue]; 00861 00862 // Get fields list and traverse it 00863 $fieldList = explode(',', $typesConf['showitem']); 00864 $altFieldList = array(); 00865 00866 // Traverse fields in types config and parse the configuration into a nice array: 00867 foreach($fieldList as $k => $v) { 00868 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v); 00869 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : ''; 00870 $specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras); 00871 00872 $fieldList[$k]=array( 00873 'field' => $pFieldName, 00874 'title' => $pAltTitle, 00875 'palette' => $pPalette, 00876 'spec' => $specConfParts, 00877 'origString' => $v 00878 ); 00879 if ($useFieldNameAsKey) { 00880 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k]; 00881 } 00882 } 00883 if ($useFieldNameAsKey) { 00884 $fieldList = $altFieldList; 00885 } 00886 00887 // Return array: 00888 return $fieldList; 00889 } 00890 } 00891 00903 function getTCAtypeValue($table,$rec) { 00904 global $TCA; 00905 00906 // If no field-value, set it to zero. If there is no type matching the field-value (which now may be zero...) test field-value '1' as default. 00907 t3lib_div::loadTCA($table); 00908 if ($TCA[$table]) { 00909 $field = $TCA[$table]['ctrl']['type']; 00910 $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0; 00911 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1; 00912 return $fieldValue; 00913 } 00914 } 00915 00926 function getSpecConfParts($str, $defaultExtras) { 00927 00928 // Add defaultExtras: 00929 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1); 00930 00931 $reg = array(); 00932 if (count($specConfParts)) { 00933 foreach($specConfParts as $k2 => $v2) { 00934 unset($specConfParts[$k2]); 00935 if (ereg('(.*)\[(.*)\]',$v2,$reg)) { 00936 $specConfParts[trim($reg[1])] = array( 00937 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1) 00938 ); 00939 } else { 00940 $specConfParts[trim($v2)] = 1; 00941 } 00942 } 00943 } else { 00944 $specConfParts = array(); 00945 } 00946 return $specConfParts; 00947 } 00948 00957 function getSpecConfParametersFromArray($pArr) { 00958 $out=array(); 00959 if (is_array($pArr)) { 00960 reset($pArr); 00961 while(list($k,$v)=each($pArr)) { 00962 $parts=explode('=',$v,2); 00963 if (count($parts)==2) { 00964 $out[trim($parts[0])]=trim($parts[1]); 00965 } else { 00966 $out[$k]=$v; 00967 } 00968 } 00969 } 00970 return $out; 00971 } 00972 00987 function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE,$newRecordPidValue=0) { 00988 global $TYPO3_CONF_VARS; 00989 00990 // Get pointer field etc from TCA-config: 00991 $ds_pointerField = $conf['ds_pointerField']; 00992 $ds_array = $conf['ds']; 00993 $ds_tableField = $conf['ds_tableField']; 00994 $ds_searchParentField = $conf['ds_pointerField_searchParent']; 00995 00996 // Find source value: 00997 $dataStructArray=''; 00998 if (is_array($ds_array)) { // If there is a data source array, that takes precedence 00999 // If a pointer field is set, take the value from that field in the $row array and use as key. 01000 if ($ds_pointerField) { 01001 $srcPointer = $row[$ds_pointerField]; 01002 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default'; 01003 } else $srcPointer='default'; 01004 01005 // Get Data Source: Detect if it's a file reference and in that case read the file and parse as XML. Otherwise the value is expected to be XML. 01006 if (substr($ds_array[$srcPointer],0,5)=='FILE:') { 01007 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5)); 01008 if ($file && @is_file($file)) { 01009 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file)); 01010 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message. 01011 } else { 01012 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]); 01013 } 01014 01015 } elseif ($ds_pointerField) { // If pointer field AND possibly a table/field is set: 01016 // Value of field pointed to: 01017 $srcPointer = $row[$ds_pointerField]; 01018 01019 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table): 01020 if ($ds_searchParentField && !$srcPointer) { 01021 $rr = t3lib_BEfunc::getRecord($table,$row['uid'],'uid,'.$ds_searchParentField); // Get the "pid" field - we cannot know that it is in the input record! ###NOTE_A### 01022 if ($WSOL) { 01023 t3lib_BEfunc::workspaceOL($table,$rr); 01024 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE); // Added "TRUE" 23/03/06 before 4.0. (Also to similar call below!). Reason: When t3lib_refindex is scanning the system in Live workspace all Pages with FlexForms will not find their inherited datastructure. Thus all references from workspaces are removed! Setting TRUE means that versioning PID doesn't check workspace of the record. I can't see that this should give problems anywhere. See more information inside t3lib_refindex! 01025 } 01026 $uidAcc=array(); // Used to avoid looping, if any should happen. 01027 $subFieldPointer = $conf['ds_pointerField_searchParent_subField']; 01028 while(!$srcPointer) { 01029 01030 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 01031 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''), 01032 $table, 01033 'uid='.intval($newRecordPidValue ? $newRecordPidValue : $rr[$ds_searchParentField]).t3lib_BEfunc::deleteClause($table) ###NOTE_A### 01034 ); 01035 $newRecordPidValue = 0; 01036 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); 01037 01038 // break if no result from SQL db or if looping... 01039 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break; 01040 $uidAcc[$rr['uid']]=1; 01041 01042 if ($WSOL) { 01043 t3lib_BEfunc::workspaceOL($table,$rr); 01044 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE); 01045 } 01046 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField]; 01047 } 01048 } 01049 01050 // If there is a srcPointer value: 01051 if ($srcPointer) { 01052 if (t3lib_div::testInt($srcPointer)) { // If integer, then its a record we will look up: 01053 list($tName,$fName) = explode(':',$ds_tableField,2); 01054 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) { 01055 $dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer); 01056 if ($WSOL) { 01057 t3lib_BEfunc::workspaceOL($tName,$dataStructRec); 01058 } 01059 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]); 01060 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!'; 01061 } else { // Otherwise expect it to be a file: 01062 $file = t3lib_div::getFileAbsFileName($srcPointer); 01063 if ($file && @is_file($file)) { 01064 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file)); 01065 } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message. 01066 } 01067 } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"'; // Error message. 01068 } else $dataStructArray='No proper configuration!'; 01069 01070 // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig 01071 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) { 01072 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) { 01073 $hookObj = &t3lib_div::getUserObj($classRef); 01074 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) { 01075 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName); 01076 } 01077 } 01078 } 01079 01080 return $dataStructArray; 01081 } 01082 01083 01084 01085 01086 01087 01088 01089 01090 01091 01092 01093 01094 01095 01096 01097 01098 01099 01100 /******************************************* 01101 * 01102 * Caching related 01103 * 01104 *******************************************/ 01105 01116 function storeHash($hash,$data,$ident) { 01117 $insertFields = array( 01118 'hash' => $hash, 01119 'content' => $data, 01120 'ident' => $ident, 01121 'tstamp' => time() 01122 ); 01123 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash')); 01124 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields); 01125 } 01126 01136 function getHash($hash,$expTime=0) { 01137 // if expTime is not set, the hash will never expire 01138 $expTime = intval($expTime); 01139 if ($expTime) { 01140 $whereAdd = ' AND tstamp > '.(time()-$expTime); 01141 } 01142 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd); 01143 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01144 return $row['content']; 01145 } 01146 } 01147 01148 01149 01150 01151 01152 01153 01154 01155 /******************************************* 01156 * 01157 * TypoScript related 01158 * 01159 *******************************************/ 01160 01172 function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) { 01173 $id=intval($id); 01174 if (!is_array($rootLine)) { 01175 $rootLine = t3lib_BEfunc::BEgetRootLine($id,'',TRUE); 01176 } 01177 ksort($rootLine); // Order correctly 01178 $TSdataArray = array(); 01179 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration: 01180 foreach($rootLine as $k => $v) { 01181 $TSdataArray['uid_'.$v['uid']]=$v['TSconfig']; 01182 } 01183 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray); 01184 if ($returnPartArray) { 01185 return $TSdataArray; 01186 } 01187 01188 // Parsing the user TS (or getting from cache) 01189 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10)); 01190 $hash = md5('pageTS:'.$userTS); 01191 $cachedContent = t3lib_BEfunc::getHash($hash,0); 01192 $TSconfig = array(); 01193 if (isset($cachedContent)) { 01194 $TSconfig = unserialize($cachedContent); 01195 } else { 01196 $parseObj = t3lib_div::makeInstance('t3lib_TSparser'); 01197 $parseObj->parse($userTS); 01198 $TSconfig = $parseObj->setup; 01199 t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig'); 01200 } 01201 01202 // get User TSconfig overlay 01203 $userTSconfig = $GLOBALS['BE_USER']->userTS['page.']; 01204 if (is_array($userTSconfig)) { 01205 $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig); 01206 } 01207 return $TSconfig; 01208 } 01209 01228 function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') { 01229 $id=intval($id); 01230 if (is_array($pageTS) && $id>0) { 01231 if (!is_array($impParams)) { 01232 $impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id)); 01233 } 01234 reset($pageTS); 01235 $set=array(); 01236 while(list($f,$v)=each($pageTS)) { 01237 $f = $TSconfPrefix.$f; 01238 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v))) { 01239 $set[$f]=trim($v); 01240 } 01241 } 01242 if (count($set)) { 01243 // Get page record and TS config lines 01244 $pRec = t3lib_befunc::getRecord('pages',$id); 01245 $TSlines = explode(chr(10),$pRec['TSconfig']); 01246 $TSlines = array_reverse($TSlines); 01247 // Reset the set of changes. 01248 reset($set); 01249 while(list($f,$v)=each($set)) { 01250 reset($TSlines); 01251 $inserted=0; 01252 while(list($ki,$kv)=each($TSlines)) { 01253 if (substr($kv,0,strlen($f)+1)==$f.'=') { 01254 $TSlines[$ki]=$f.'='.$v; 01255 $inserted=1; 01256 break; 01257 } 01258 } 01259 if (!$inserted) { 01260 $TSlines = array_reverse($TSlines); 01261 $TSlines[]=$f.'='.$v; 01262 $TSlines = array_reverse($TSlines); 01263 } 01264 } 01265 $TSlines = array_reverse($TSlines); 01266 01267 // store those changes 01268 $TSconf = implode(chr(10),$TSlines); 01269 01270 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf)); 01271 } 01272 } 01273 } 01274 01283 function implodeTSParams($p,$k='') { 01284 $implodeParams=array(); 01285 if (is_array($p)) { 01286 reset($p); 01287 while(list($kb,$val)=each($p)) { 01288 if (is_array($val)) { 01289 $implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb)); 01290 } else { 01291 $implodeParams[$k.$kb]=$val; 01292 } 01293 } 01294 } 01295 return $implodeParams; 01296 } 01297 01298 01299 01300 01301 01302 01303 01304 01305 /******************************************* 01306 * 01307 * Users / Groups related 01308 * 01309 *******************************************/ 01310 01320 function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') { 01321 $be_user_Array=Array(); 01322 01323 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username'); 01324 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01325 $be_user_Array[$row['uid']]=$row; 01326 } 01327 return $be_user_Array; 01328 } 01329 01338 function getGroupNames($fields='title,uid', $where='') { 01339 $be_group_Array = Array(); 01340 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title'); 01341 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01342 $be_group_Array[$row['uid']] = $row; 01343 } 01344 return $be_group_Array; 01345 } 01346 01355 function getListGroupNames($fields='title,uid') { 01356 $exQ=' AND hide_in_lists=0'; 01357 if (!$GLOBALS['BE_USER']->isAdmin()) { 01358 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')'; 01359 } 01360 return t3lib_BEfunc::getGroupNames($fields,$exQ); 01361 } 01362 01374 function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) { 01375 if (is_array($usernames) && is_array($groupArray)) { 01376 while(list($uid,$row)=each($usernames)) { 01377 $userN=$uid; 01378 $set=0; 01379 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) { 01380 reset($groupArray); 01381 while(list(,$v)=each($groupArray)) { 01382 if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v)) { 01383 $userN = $row['username']; 01384 $set=1; 01385 } 01386 } 01387 } else { 01388 $userN = $row['username']; 01389 $set=1; 01390 } 01391 $usernames[$uid]['username']=$userN; 01392 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);} 01393 } 01394 } 01395 return $usernames; 01396 } 01397 01407 function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) { 01408 if (is_array($groups) && is_array($groupArray)) { 01409 while(list($uid,$row)=each($groups)) { 01410 $groupN=$uid; 01411 $set=0; 01412 if (t3lib_div::inArray($groupArray,$uid)) { 01413 $groupN=$row['title']; 01414 $set=1; 01415 } 01416 $groups[$uid]['title']=$groupN; 01417 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);} 01418 } 01419 } 01420 return $groups; 01421 } 01422 01423 01424 01425 01426 01427 01428 01429 01430 01431 01432 01433 01434 01435 /******************************************* 01436 * 01437 * Output related 01438 * 01439 *******************************************/ 01440 01448 function daysUntil($tstamp) { 01449 $delta_t = $tstamp-$GLOBALS['EXEC_TIME']; 01450 return ceil($delta_t/(3600*24)); 01451 } 01452 01460 function date($tstamp) { 01461 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp); 01462 } 01463 01471 function datetime($value) { 01472 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value); 01473 } 01474 01483 function time($value) { 01484 $hh = floor($value/3600); 01485 $min = floor(($value-$hh*3600)/60); 01486 $sec = $value-$hh*3600-$min*60; 01487 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec); 01488 return $l; 01489 } 01490 01499 function calcAge($seconds,$labels = 'min|hrs|days|yrs') { 01500 $labelArr = explode('|',$labels); 01501 $prefix=''; 01502 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);} 01503 if ($seconds<3600) { 01504 $seconds = round ($seconds/60).' '.trim($labelArr[0]); 01505 } elseif ($seconds<24*3600) { 01506 $seconds = round ($seconds/3600).' '.trim($labelArr[1]); 01507 } elseif ($seconds<365*24*3600) { 01508 $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]); 01509 } else { 01510 $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]); 01511 } 01512 return $prefix.$seconds; 01513 } 01514 01525 function dateTimeAge($tstamp,$prefix=1,$date='') { 01526 return $tstamp ? 01527 ($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)). 01528 ' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : ''; 01529 } 01530 01543 function titleAttrib($content='',$hsc=0) { 01544 global $CLIENT; 01545 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title'; 01546 return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib; 01547 } 01548 01556 function titleAltAttrib($content) { 01557 $out=''; 01558 $out.=' alt="'.htmlspecialchars($content).'"'; 01559 $out.=' title="'.htmlspecialchars($content).'"'; 01560 return $out; 01561 } 01562 01580 function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='') { 01581 global $TCA; 01582 // Load table. 01583 t3lib_div::loadTCA($table); 01584 01585 // Find uploaddir automatically 01586 $uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir; 01587 $uploaddir = preg_replace('#/$#','',$uploaddir); 01588 01589 // Set thumbs-script: 01590 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) { 01591 $thumbScript='gfx/notfound_thumb.gif'; 01592 } elseif(!$thumbScript) { 01593 $thumbScript='thumbs.php'; 01594 } 01595 // Check and parse the size parameter 01596 $sizeParts=array(); 01597 if ($size = trim($size)) { 01598 $sizeParts = explode('x', $size.'x'.$size); 01599 if(!intval($sizeParts[0])) $size=''; 01600 } 01601 01602 // Traverse files: 01603 $thumbs = explode(',', $row[$field]); 01604 $thumbData=''; 01605 while(list(,$theFile)=each($thumbs)) { 01606 if (trim($theFile)) { 01607 $fI = t3lib_div::split_fileref($theFile); 01608 $ext = $fI['fileext']; 01609 // New 190201 start 01610 $max=0; 01611 if (t3lib_div::inList('gif,jpg,png',$ext)) { 01612 $imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile); 01613 if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);} 01614 } 01615 // use the original image if it's size fits to the thumbnail size 01616 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) { 01617 $theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile); 01618 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;'; 01619 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> '; 01620 // New 190201 stop 01621 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) { 01622 $theFile_abs = PATH_site.($uploaddir?$uploaddir.'/':'').trim($theFile); 01623 $theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile); 01624 01625 $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']; 01626 $params = '&file='.rawurlencode($theFile); 01627 $params.= $size?'&size='.$size:''; 01628 $params.= '&md5sum='.t3lib_div::shortMD5($check); 01629 01630 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params; 01631 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;'; 01632 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> '; 01633 } else { 01634 $icon = t3lib_BEfunc::getFileIcon($ext); 01635 $url = 'gfx/fileicons/'.$icon; 01636 $thumbData.= '<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> '; 01637 } 01638 } 01639 } 01640 return $thumbData; 01641 } 01642 01653 function getThumbNail($thumbScript,$theFile,$tparams='',$size='') { 01654 $check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']; 01655 $params = '&file='.rawurlencode($theFile); 01656 $params.= trim($size)?'&size='.trim($size):''; 01657 $params.= '&md5sum='.t3lib_div::shortMD5($check); 01658 01659 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params; 01660 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />'; 01661 return $th; 01662 } 01663 01673 function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) { 01674 global $TCA,$LANG; 01675 $parts=array(); 01676 $parts[] = 'id='.$row['uid']; 01677 if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias']; 01678 if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id']; 01679 if ($row['t3ver_state']==1) $parts[] = 'PLH WSID#'.$row['t3ver_wsid']; 01680 if ($row['t3ver_state']==-1) $parts[] = 'New element!'; 01681 01682 if ($row['doktype']=='3') { 01683 $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url']; 01684 } elseif ($row['doktype']=='4') { 01685 if ($perms_clause) { 01686 $label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20); 01687 } else { 01688 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['shortcut']),'title'); 01689 $label = $lRec['title']; 01690 } 01691 if ($row['shortcut_mode']>0) { 01692 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '. 01693 $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode'])); 01694 } 01695 $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label; 01696 } elseif ($row['doktype']=='7') { 01697 if ($perms_clause) { 01698 $label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20); 01699 } else { 01700 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['mount_pid']),'title'); 01701 $label = $lRec['title']; 01702 } 01703 $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label; 01704 if ($row['mount_pid_ol']) { 01705 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']); 01706 } 01707 } 01708 if ($row['nav_hide']) $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label'])); 01709 if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'); 01710 if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date'); 01711 if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date'); 01712 if ($row['fe_group']) { 01713 $fe_groups = array(); 01714 foreach (t3lib_div::intExplode(',',$row['fe_group']) as $fe_group) { 01715 if ($fe_group<0) { 01716 $fe_groups[] = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$fe_group)); 01717 } else { 01718 $lRec = t3lib_BEfunc::getRecordWSOL('fe_groups',$fe_group,'title'); 01719 $fe_groups[] = $lRec['title']; 01720 } 01721 } 01722 $label = implode(', ',$fe_groups); 01723 $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label; 01724 } 01725 $out = htmlspecialchars(implode(' - ',$parts)); 01726 return $includeAttrib ? 'title="'.$out.'"' : $out; 01727 } 01728 01739 function getRecordIconAltText($row,$table='pages') { 01740 if ($table=='pages') { 01741 $out = t3lib_BEfunc::titleAttribForPages($row,'',0); 01742 } else { 01743 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']; 01744 01745 $out='id='.$row['uid']; // Uid is added 01746 if ($table=='pages' && $row['alias']) { 01747 $out.=' / '.$row['alias']; 01748 } 01749 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) { 01750 $out.=' - v#1.'.$row['t3ver_id']; 01751 } 01752 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) { 01753 if ($row['t3ver_state']==1) $out.= ' - PLH WSID#'.$row['t3ver_wsid']; 01754 if ($row['t3ver_state']==-1) $out.= ' - New element!'; 01755 } 01756 01757 if ($ctrl['disabled']) { // Hidden ... 01758 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):''); 01759 } 01760 if ($ctrl['starttime']) { 01761 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) { 01762 $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').')'; 01763 } 01764 } 01765 if ($row[$ctrl['endtime']]) { 01766 $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').')'; 01767 } 01768 } 01769 return htmlspecialchars($out); 01770 } 01771 01781 function getLabelFromItemlist($table,$col,$key) { 01782 global $TCA; 01783 // Load full TCA for $table 01784 t3lib_div::loadTCA($table); 01785 01786 // Check, if there is an "items" array: 01787 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) { 01788 // Traverse the items-array... 01789 reset($TCA[$table]['columns'][$col]['config']['items']); 01790 while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items'])) { 01791 // ... and return the first found label where the value was equal to $key 01792 if (!strcmp($v[1],$key)) return $v[0]; 01793 } 01794 } 01795 } 01796 01807 function getItemLabel($table,$col,$printAllWrap='') { 01808 global $TCA; 01809 // Load full TCA for $table 01810 t3lib_div::loadTCA($table); 01811 // Check if column exists 01812 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) { 01813 // Re 01814 return $TCA[$table]['columns'][$col]['label']; 01815 } 01816 if ($printAllWrap) { 01817 $parts = explode('|',$printAllWrap); 01818 return $parts[0].$col.$parts[1]; 01819 } 01820 } 01821 01833 function getRecordTitle($table,$row,$prep=FALSE,$forceResult=TRUE) { 01834 global $TCA; 01835 if (is_array($TCA[$table])) { 01836 01837 // If configured, call userFunc 01838 if ($TCA[$table]['ctrl']['label_userFunc']) { 01839 $params['table'] = $table; 01840 $params['row'] = $row; 01841 $params['title'] = ''; 01842 01843 t3lib_div::callUserFunction($TCA[$table]['ctrl']['label_userFunc'],$params,$this); 01844 $t = $params['title']; 01845 } else { 01846 01847 // No userFunc: Build label 01848 $t = $row[$TCA[$table]['ctrl']['label']]; 01849 if ($TCA[$table]['ctrl']['label_alt'] && ($TCA[$table]['ctrl']['label_alt_force'] || !strcmp($t,''))) { 01850 $altFields=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1); 01851 $tA=array(); 01852 $tA[]=$t; 01853 if ($TCA[$table]['ctrl']['label_alt_force']) { 01854 foreach ($altFields as $fN) { 01855 $t = trim(strip_tags($row[$fN])); 01856 if (!empty($t)) $tA[] = $t; 01857 } 01858 $t=implode(', ',$tA); 01859 } 01860 } 01861 } 01862 01863 // If the current result is empty, set it to '[No title]' (localized) and prepare for output if requested 01864 if ($prep || $forceResult) { 01865 if ($prep) { 01866 $t = t3lib_BEfunc::getRecordTitlePrep($t); 01867 } 01868 if (!strcmp(trim($t),'')) { 01869 $t = t3lib_BEfunc::getNoRecordTitle($prep); 01870 } 01871 } 01872 01873 return $t; 01874 } 01875 } 01876 01885 function getRecordTitlePrep($title, $titleLength=0) { 01886 // If $titleLength is not a valid positive integer, use BE_USER->uc['titleLen']: 01887 if (!$titleLength || !t3lib_div::testInt($titleLength) || $titleLength < 0) { 01888 $titleLength = $GLOBALS['BE_USER']->uc['titleLen']; 01889 } 01890 $titleOrig = htmlspecialchars($title); 01891 $title = htmlspecialchars(t3lib_div::fixed_lgd_cs($title, $titleLength)); 01892 // If title was cropped, offer a tooltip: 01893 if ($titleOrig != $title) { 01894 $title = '<span title="'.$titleOrig.'">'.$title.'</span>'; 01895 } 01896 return $title; 01897 } 01898 01905 function getNoRecordTitle($prep=FALSE) { 01906 $noTitle = '['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']'; 01907 if ($prep) $noTitle = '<em>'.$noTitle.'</em>'; 01908 return $noTitle; 01909 } 01910 01928 function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0,$noRecordLookup=FALSE,$uid=0,$forceResult=TRUE) { 01929 global $TCA; 01930 global $TYPO3_CONF_VARS; 01931 // Load full TCA for $table 01932 t3lib_div::loadTCA($table); 01933 // Check if table and field is configured: 01934 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) { 01935 // Depending on the fields configuration, make a meaningful output value. 01936 $theColConf = $TCA[$table]['columns'][$col]['config']; 01937 01938 /***************** 01939 *HOOK: pre-processing the human readable output from a record 01940 ****************/ 01941 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) { 01942 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) { 01943 t3lib_div::callUserFunction($_funcRef,$theColConf,$this); 01944 } 01945 } 01946 01947 $l=''; 01948 switch((string)$theColConf['type']) { 01949 case 'radio': 01950 $l=t3lib_BEfunc::getLabelFromItemlist($table,$col,$value); 01951 $l=$GLOBALS['LANG']->sL($l); 01952 break; 01953 case 'select': 01954 if ($theColConf['MM']) { 01955 // Display the title of MM related records in lists 01956 if ($noRecordLookup) { 01957 $MMfield = $theColConf['foreign_table'].'.uid'; 01958 } else { 01959 $MMfields = array($theColConf['foreign_table'].'.'.$TCA[$theColConf['foreign_table']]['ctrl']['label']); 01960 foreach (t3lib_div::trimExplode(',', $TCA[$theColConf['foreign_table']]['ctrl']['label_alt'], 1) as $f) { 01961 $MMfields[] = $theColConf['foreign_table'].'.'.$f; 01962 } 01963 $MMfield = join(',',$MMfields); 01964 } 01965 01966 $dbGroup = t3lib_div::makeInstance('t3lib_loadDBGroup'); 01967 $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf); 01968 $selectUids = $dbGroup->tableArray[$theColConf['foreign_table']]; 01969 01970 if (is_array($selectUids) && count($selectUids)>0) { 01971 $MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 01972 'uid, '.$MMfield, 01973 $theColConf['foreign_table'], 01974 'uid IN ('.implode(',', $selectUids).')' 01975 ); 01976 while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres)) { 01977 $mmlA[] = ($noRecordLookup?$MMrow['uid']:t3lib_BEfunc::getRecordTitle($theColConf['foreign_table'], $MMrow, FALSE, $forceResult)); 01978 } 01979 if (is_array($mmlA)) { 01980 $l=implode('; ',$mmlA); 01981 } else { 01982 $l = ''; 01983 } 01984 } else { 01985 $l = 'n/A'; 01986 } 01987 } else { 01988 $l = t3lib_BEfunc::getLabelFromItemlist($table,$col,$value); 01989 $l = $GLOBALS['LANG']->sL($l); 01990 if ($theColConf['foreign_table'] && !$l && $TCA[$theColConf['foreign_table']]) { 01991 if ($noRecordLookup) { 01992 $l = $value; 01993 } else { 01994 $rParts = t3lib_div::trimExplode(',',$value,1); 01995 reset($rParts); 01996 $lA = array(); 01997 while(list(,$rVal)=each($rParts)) { 01998 $rVal = intval($rVal); 01999 if ($rVal>0) { 02000 $r=t3lib_BEfunc::getRecordWSOL($theColConf['foreign_table'],$rVal); 02001 } else { 02002 $r=t3lib_BEfunc::getRecordWSOL($theColConf['neg_foreign_table'],-$rVal); 02003 } 02004 if (is_array($r)) { 02005 $lA[]=$GLOBALS['LANG']->sL($rVal>0?$theColConf['foreign_table_prefix']:$theColConf['neg_foreign_table_prefix']).t3lib_BEfunc::getRecordTitle($rVal>0?$theColConf['foreign_table']:$theColConf['neg_foreign_table'],$r,FALSE,$forceResult); 02006 } else { 02007 $lA[]=$rVal?'['.$rVal.'!]':''; 02008 } 02009 } 02010 $l = implode(', ',$lA); 02011 } 02012 } 02013 } 02014 break; 02015 case 'group': 02016 $l = implode(', ',t3lib_div::trimExplode(',',$value,1)); 02017 break; 02018 case 'check': 02019 if (!is_array($theColConf['items']) || count($theColConf['items'])==1) { 02020 $l = $value ? 'Yes' : ''; 02021 } else { 02022 reset($theColConf['items']); 02023 $lA=Array(); 02024 while(list($key,$val)=each($theColConf['items'])) { 02025 if ($value & pow(2,$key)) {$lA[]=$GLOBALS['LANG']->sL($val[0]);} 02026 } 02027 $l = implode(', ',$lA); 02028 } 02029 break; 02030 case 'input': 02031 if ($value) { 02032 if (t3lib_div::inList($theColConf['eval'],'date')) { 02033 $l = t3lib_BEfunc::date($value).' ('.(time()-$value>0?'-':'').t3lib_BEfunc::calcAge(abs(time()-$value), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')'; 02034 } elseif (t3lib_div::inList($theColConf['eval'],'time')) { 02035 $l = t3lib_BEfunc::time($value); 02036 } elseif (t3lib_div::inList($theColConf['eval'],'datetime')) { 02037 $l = t3lib_BEfunc::datetime($value); 02038 } else { 02039 $l = $value; 02040 } 02041 } 02042 break; 02043 case 'flex': 02044 $l = strip_tags($value); 02045 break; 02046 default: 02047 if ($defaultPassthrough) { 02048 $l=$value; 02049 } elseif ($theColConf['MM']) { 02050 $l='N/A'; 02051 } elseif ($value) { 02052 $l=t3lib_div::fixed_lgd_cs(strip_tags($value),200); 02053 } 02054 break; 02055 } 02056 02057 /***************** 02058 *HOOK: post-processing the human readable output from a record 02059 ****************/ 02060 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) { 02061 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) { 02062 $params = array( 02063 'value' => $l, 02064 'colConf' => $theColConf 02065 ); 02066 $l = t3lib_div::callUserFunction($_funcRef,$params,$this); 02067 } 02068 } 02069 02070 if ($fixed_lgd_chars) { 02071 return t3lib_div::fixed_lgd_cs($l,$fixed_lgd_chars); 02072 } else { 02073 return $l; 02074 } 02075 } 02076 } 02077 02091 function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0,$uid=0,$forceResult=TRUE) { 02092 global $TCA; 02093 $fVnew = t3lib_BEfunc::getProcessedValue($table,$fN,$fV,$fixed_lgd_chars,0,0,$uid,$forceResult); 02094 if (!isset($fVnew)) { 02095 if (is_array($TCA[$table])) { 02096 if ($fN==$TCA[$table]['ctrl']['tstamp'] || $fN==$TCA[$table]['ctrl']['crdate']) { 02097 $fVnew = t3lib_BEfunc::datetime($fV); 02098 } elseif ($fN=='pid'){ 02099 $fVnew = t3lib_BEfunc::getRecordPath($fV,'1=1',20); // Fetches the path with no regard to the users permissions to select pages. 02100 } else { 02101 $fVnew = $fV; 02102 } 02103 } 02104 } 02105 return $fVnew; 02106 } 02107 02115 function getFileIcon($ext) { 02116 return $GLOBALS['FILEICONS'][$ext] ? $GLOBALS['FILEICONS'][$ext] : $GLOBALS['FILEICONS']['default']; 02117 } 02118 02130 function getCommonSelectFields($table,$prefix='',$fields = array()) { 02131 global $TCA; 02132 $fields[] = $prefix.'uid'; 02133 $fields[] = $prefix.$TCA[$table]['ctrl']['label']; 02134 02135 if ($TCA[$table]['ctrl']['label_alt']) { 02136 $secondFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1); 02137 foreach($secondFields as $fieldN) { 02138 $fields[] = $prefix.$fieldN; 02139 } 02140 } 02141 if ($TCA[$table]['ctrl']['versioningWS']) { 02142 $fields[] = $prefix.'t3ver_id'; 02143 $fields[] = $prefix.'t3ver_state'; 02144 $fields[] = $prefix.'t3ver_wsid'; 02145 $fields[] = $prefix.'t3ver_count'; 02146 } 02147 02148 if ($TCA[$table]['ctrl']['selicon_field']) $fields[] = $prefix.$TCA[$table]['ctrl']['selicon_field']; 02149 if ($TCA[$table]['ctrl']['typeicon_column']) $fields[] = $prefix.$TCA[$table]['ctrl']['typeicon_column']; 02150 02151 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) { 02152 if ($TCA[$table]['ctrl']['enablecolumns']['disabled']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['disabled']; 02153 if ($TCA[$table]['ctrl']['enablecolumns']['starttime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['starttime']; 02154 if ($TCA[$table]['ctrl']['enablecolumns']['endtime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['endtime']; 02155 if ($TCA[$table]['ctrl']['enablecolumns']['fe_group']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['fe_group']; 02156 } 02157 02158 return implode(',', array_unique($fields)); 02159 } 02160 02172 function makeConfigForm($configArray,$defaults,$dataPrefix) { 02173 $params = $defaults; 02174 if (is_array($configArray)) { 02175 reset($configArray); 02176 $lines=array(); 02177 while(list($fname,$config)=each($configArray)) { 02178 if (is_array($config)) { 02179 $lines[$fname]='<strong>'.htmlspecialchars($config[1]).'</strong><br />'; 02180 $lines[$fname].=$config[2].'<br />'; 02181 switch($config[0]) { 02182 case 'string': 02183 case 'short': 02184 $formEl = '<input type="text" name="'.$dataPrefix.'['.$fname.']" value="'.$params[$fname].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($config[0]=='short'?24:48).' />'; 02185 break; 02186 case 'check': 02187 $formEl = '<input type="hidden" name="'.$dataPrefix.'['.$fname.']" value="0" /><input type="checkbox" name="'.$dataPrefix.'['.$fname.']" value="1"'.($params[$fname]?' checked="checked"':'').' />'; 02188 break; 02189 case 'comment': 02190 $formEl = ''; 02191 break; 02192 case 'select': 02193 reset($config[3]); 02194 $opt=array(); 02195 while(list($k,$v)=each($config[3])) { 02196 $opt[]='<option value="'.htmlspecialchars($k).'"'.($params[$fname]==$k?' selected="selected"':'').'>'.htmlspecialchars($v).'</option>'; 02197 } 02198 $formEl = '<select name="'.$dataPrefix.'['.$fname.']">'.implode('',$opt).'</select>'; 02199 break; 02200 default: 02201 debug($config); 02202 break; 02203 } 02204 $lines[$fname].=$formEl; 02205 $lines[$fname].='<br /><br />'; 02206 } else { 02207 $lines[$fname]='<hr />'; 02208 if ($config) $lines[$fname].='<strong>'.strtoupper(htmlspecialchars($config)).'</strong><br />'; 02209 if ($config) $lines[$fname].='<br />'; 02210 } 02211 } 02212 } 02213 $out = implode('',$lines); 02214 $out.='<input type="submit" name="submit" value="Update configuration" />'; 02215 return $out; 02216 } 02217 02218 02219 02220 02221 02222 02223 02224 02225 02226 02227 02228 02229 02230 /******************************************* 02231 * 02232 * Backend Modules API functions 02233 * 02234 *******************************************/ 02235 02247 function helpTextIcon($table,$field,$BACK_PATH,$force=0) { 02248 global $TCA_DESCR,$BE_USER; 02249 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && ($BE_USER->uc['edit_showFieldHelp']=='icon' || $force)) { 02250 $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;'; 02251 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'. 02252 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/helpbubble.gif','width="14" height="14"').' hspace="2" border="0" class="typo3-csh-icon" alt="" />'. 02253 '</a>'; 02254 } 02255 } 02256 02269 function helpText($table,$field,$BACK_PATH,$styleAttrib='') { 02270 global $TCA_DESCR,$BE_USER; 02271 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && $BE_USER->uc['edit_showFieldHelp']=='text') { 02272 $fDat = $TCA_DESCR[$table]['columns'][$field]; 02273 02274 // Get Icon: 02275 $editIcon = t3lib_BEfunc::helpTextIcon( 02276 $table, 02277 $field, 02278 $BACK_PATH, 02279 TRUE 02280 ); 02281 // Add title? 02282 $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;'; 02283 $text = 02284 ($fDat['alttitle'] ? '<h4><a href="#" onclick="'.htmlspecialchars($onClick).'">'.$fDat['alttitle'].'</a></h4>' : ''). 02285 $fDat['description']; 02286 02287 // More information to get? 02288 if ($fDat['image_descr'] || $fDat['seeAlso'] || $fDat['details'] || $fDat['syntax']) { // || $fDat['image']; 02289 $text.=' <a href="#" onclick="'.htmlspecialchars($onClick).'">'. 02290 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/rel_db.gif','width="13" height="12"').' class="absmiddle typo3-csh-more" alt="" />'. 02291 '</a>'; 02292 } 02293 02294 // Additional styles? 02295 $params = $styleAttrib ? ' style="'.$styleAttrib.'"' : ''; 02296 02297 // Compile table with CSH information: 02298 return '<table border="0" cellpadding="2" cellspacing="0" class="typo3-csh-inline"'.$params.'> 02299 <tr> 02300 <td valign="top" width="14">'.$editIcon.'</td> 02301 <td valign="top">'.$text.'</td> 02302 </tr> 02303 </table>'; 02304 } 02305 } 02306 02321 function cshItem($table,$field,$BACK_PATH,$wrap='',$onlyIconMode=FALSE, $styleAttrib='') { 02322 global $TCA_DESCR, $LANG, $BE_USER; 02323 if ($BE_USER->uc['edit_showFieldHelp']) { 02324 $LANG->loadSingleTableDescription($table); 02325 02326 if (is_array($TCA_DESCR[$table])) { 02327 // Creating CSH icon and short description: 02328 $fullText = t3lib_BEfunc::helpText($table,$field,$BACK_PATH,$styleAttrib); 02329 $icon = t3lib_BEfunc::helpTextIcon($table,$field,$BACK_PATH,$onlyIconMode); 02330 02331 if ($fullText && !$onlyIconMode) { 02332 $output = $GLOBALS['LANG']->hscAndCharConv($fullText, false); 02333 } else { 02334 #$output = '<span style="position:absolute; filter: alpha(opacity=50); -moz-opacity: 0.50;">'.$icon.'</span>'; 02335 $output = $icon; 02336 02337 if ($output && $wrap) { 02338 $wrParts = explode('|',$wrap); 02339 $output = $wrParts[0].$output.$wrParts[1]; 02340 } 02341 } 02342 02343 return $output; 02344 } 02345 } 02346 } 02347 02359 function editOnClick($params,$backPath='',$requestUri='') { 02360 $retUrl = 'returnUrl='.($requestUri==-1?"'+T3_THIS_LOCATION+'":rawurlencode($requestUri?$requestUri:t3lib_div::getIndpEnv('REQUEST_URI'))); 02361 return "window.location.href='".$backPath."alt_doc.php?".$retUrl.$params."'; return false;"; 02362 } 02363 02378 function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='',$addGetVars='',$switchFocus=TRUE) { 02379 if ($altUrl) { 02380 $url = $altUrl; 02381 } else { 02382 02383 if ($GLOBALS['BE_USER']->workspace!=0) { 02384 $url = t3lib_div::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir.'mod/user/ws/wsol_preview.php?id='.$id.$addGetVars.$anchor; 02385 } else { 02386 if ($rootLine) { 02387 $parts = parse_url(t3lib_div::getIndpEnv('TYPO3_SITE_URL')); 02388 if (t3lib_BEfunc::getDomainStartPage($parts['host'],$parts['path'])) { 02389 $preUrl_temp = t3lib_BEfunc::firstDomainRecord($rootLine); 02390 } 02391 } 02392 $preUrl = $preUrl_temp ? (t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://').$preUrl_temp : $backPath.'..'; 02393 $url = $preUrl.'/index.php?id='.$id.$addGetVars.$anchor; 02394 } 02395 } 02396 02397 return "previewWin=window.open('".$url."','newTYPO3frontendWindow');". 02398 ($switchFocus ? 'previewWin.focus();' : ''); 02399 } 02400 02410 function getModTSconfig($id,$TSref) { 02411 $pageTS_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref,t3lib_BEfunc::getPagesTSconfig($id)); 02412 $BE_USER_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref); 02413 $modTSconfig = t3lib_div::array_merge_recursive_overrule($pageTS_modOptions,$BE_USER_modOptions); 02414 return $modTSconfig; 02415 } 02416 02431 function getFuncMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='') { 02432 if (is_array($menuItems)) { 02433 if (!is_array($mainParams)) { 02434 $mainParams = array('id' => $mainParams); 02435 } 02436 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams); 02437 02438 if (!$script) { 02439 $script = basename(PATH_thisScript); 02440 $mainParams.= (t3lib_div::_GET('M') ? '&M='.rawurlencode(t3lib_div::_GET('M')) : ''); 02441 } 02442 02443 $options = array(); 02444 foreach($menuItems as $value => $label) { 02445 $options[] = '<option value="'.htmlspecialchars($value).'"'.(!strcmp($currentValue,$value)?' selected="selected"':'').'>'. 02446 t3lib_div::deHSCentities(htmlspecialchars($label)). 02447 '</option>'; 02448 } 02449 if (count($options)) { 02450 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+this.options[this.selectedIndex].value,this);'; 02451 return ' 02452 02453 <!-- Function Menu of module --> 02454 <select name="'.$elementName.'" onchange="'.htmlspecialchars($onChange).'"> 02455 '.implode(' 02456 ',$options).' 02457 </select> 02458 '; 02459 } 02460 } 02461 } 02462 02477 function getFuncCheck($mainParams,$elementName,$currentValue,$script='',$addparams='',$tagParams='') { 02478 if (!is_array($mainParams)) { 02479 $mainParams = array('id' => $mainParams); 02480 } 02481 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams); 02482 02483 if (!$script) {basename(PATH_thisScript);} 02484 $onClick = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+(this.checked?1:0),this);'; 02485 return '<input type="checkbox" name="'.$elementName.'"'.($currentValue?' checked="checked"':'').' onclick="'.htmlspecialchars($onClick).'"'.($tagParams?' '.$tagParams:'').' />'; 02486 } 02487 02502 function getFuncInput($mainParams,$elementName,$currentValue,$size=10,$script="",$addparams="") { 02503 if (!is_array($mainParams)) { 02504 $mainParams = array('id' => $mainParams); 02505 } 02506 $mainParams = t3lib_div::implodeArrayForUrl('',$mainParams); 02507 02508 if (!$script) {basename(PATH_thisScript);} 02509 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+escape(this.value),this);'; 02510 return '<input type="text"'.$GLOBALS['TBE_TEMPLATE']->formWidth($size).' name="'.$elementName.'" value="'.htmlspecialchars($currentValue).'" onchange="'.htmlspecialchars($onChange).'" />'; 02511 } 02512 02523 function unsetMenuItems($modTSconfig,$itemArray,$TSref) { 02524 // Getting TS-config options for this module for the Backend User: 02525 $conf = $GLOBALS['BE_USER']->getTSConfig($TSref,$modTSconfig); 02526 if (is_array($conf['properties'])) { 02527 reset($conf['properties']); 02528 while(list($key,$val)=each($conf['properties'])) { 02529 if (!$val) { 02530 unset($itemArray[$key]); 02531 } 02532 } 02533 } 02534 return $itemArray; 02535 } 02536 02546 function getSetUpdateSignal($set='') { 02547 global $BE_USER; 02548 $key = 't3lib_BEfunc::getSetUpdateSignal'; 02549 $out=''; 02550 if ($set) { 02551 $modData=array(); 02552 $modData['set']=$set; 02553 $BE_USER->pushModuleData($key,$modData); 02554 } else { 02555 $modData = $BE_USER->getModuleData($key,'ses'); 02556 if (trim($modData['set'])) { 02557 $l=explode(',',$modData['set']); 02558 while(list(,$v)=each($l)) { 02559 switch($v) { 02560 case 'updatePageTree': 02561 case 'updateFolderTree': 02562 $out.=' 02563 <script type="text/javascript"> 02564 /*<![CDATA[*/ 02565 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) { 02566 top.content.nav_frame.refresh_nav(); 02567 } 02568 /*]]>*/ 02569 </script>'; 02570 break; 02571 } 02572 } 02573 $modData=array(); 02574 $modData['set']=''; 02575 $BE_USER->pushModuleData($key,$modData); 02576 } 02577 } 02578 return $out; 02579 } 02580 02581 02597 function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='') { 02598 02599 if ($modName && is_string($modName)) { 02600 // GETTING stored user-data from this module: 02601 $settings = $GLOBALS['BE_USER']->getModuleData($modName,$type); 02602 02603 $changed=0; 02604 if (!is_array($settings)) { 02605 $changed=1; 02606 $settings=array(); 02607 } 02608 if (is_array($MOD_MENU)) { 02609 foreach ($MOD_MENU as $key=>$var) { 02610 // If a global var is set before entering here. eg if submitted, then it's substituting the current value the array. 02611 if (is_array($CHANGED_SETTINGS) && isset($CHANGED_SETTINGS[$key]) && strcmp($settings[$key],$CHANGED_SETTINGS[$key])) { 02612 $settings[$key] = (string)$CHANGED_SETTINGS[$key]; 02613 $changed=1; 02614 } 02615 // If the $var is an array, which denotes the existence of a menu, we check if the value is permitted 02616 if (is_array($var) && (!$dontValidateList || !t3lib_div::inList($dontValidateList,$key))) { 02617 // If the setting is an array or not present in the menu-array, MOD_MENU, then the default value is inserted. 02618 if (is_array($settings[$key]) || !isset($MOD_MENU[$key][$settings[$key]])) { 02619 $settings[$key]=(string)key($var); 02620 $changed=1; 02621 } 02622 } 02623 if ($setDefaultList && !is_array($var)) { // Sets default values (only strings/checkboxes, not menus) 02624 if (t3lib_div::inList($setDefaultList,$key) && !isset($settings[$key])) { 02625 $settings[$key]=$var; 02626 } 02627 } 02628 } 02629 } else {die ('No menu!');} 02630 02631 if ($changed) { 02632 $GLOBALS['BE_USER']->pushModuleData($modName,$settings); 02633 } 02634 02635 return $settings; 02636 } else {die ('Wrong module name: "'.$modName.'"');} 02637 } 02638 02639 02640 02641 02642 02643 02644 02645 02646 02647 02648 02649 02650 02651 /******************************************* 02652 * 02653 * Core 02654 * 02655 *******************************************/ 02656 02670 function compilePreviewKeyword($getVarsStr, $beUserUid, $ttl=172800) { 02671 $field_array = array( 02672 'keyword' => md5(uniqid(microtime())), 02673 'tstamp' => time(), 02674 'endtime' => time()+$ttl, 02675 'config' => serialize(array( 02676 'getVars' => $getVarsStr, 02677 'BEUSER_uid' => $beUserUid 02678 )) 02679 ); 02680 02681 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_preview', $field_array); 02682 02683 return $field_array['keyword']; 02684 } 02685 02698 function lockRecords($table='',$uid=0,$pid=0) { 02699 $user_id = intval($GLOBALS['BE_USER']->user['uid']); 02700 if ($table && $uid) { 02701 $fields_values = array( 02702 'userid' => $user_id, 02703 'tstamp' => $GLOBALS['EXEC_TIME'], 02704 'record_table' => $table, 02705 'record_uid' => $uid, 02706 'username' => $GLOBALS['BE_USER']->user['username'], 02707 'record_pid' => $pid 02708 ); 02709 02710 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values); 02711 } else { 02712 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'userid='.intval($user_id)); 02713 } 02714 } 02715 02727 function isRecordLocked($table,$uid) { 02728 global $LOCKED_RECORDS; 02729 if (!is_array($LOCKED_RECORDS)) { 02730 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 02731 '*', 02732 'sys_lockedrecords', 02733 'sys_lockedrecords.userid!='.intval($GLOBALS['BE_USER']->user['uid']).' 02734 AND sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600) 02735 ); 02736 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 02737 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]=$row; 02738 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg']=sprintf( 02739 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord'), 02740 $row['username'], 02741 t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) 02742 ); 02743 if ($row['record_pid'] && !isset($LOCKED_RECORDS[$row['record_table'].':'.$row['record_pid']])) { 02744 $LOCKED_RECORDS['pages:'.$row['record_pid']]['msg']=sprintf( 02745 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord_content'), 02746 $row['username'], 02747 t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')) 02748 ); 02749 } 02750 } 02751 } 02752 return $LOCKED_RECORDS[$table.':'.$uid]; 02753 } 02754 02767 function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='') { 02768 global $TCA; 02769 $foreign_table = $fieldValue['config'][$prefix.'foreign_table']; 02770 $rootLevel = $TCA[$foreign_table]['ctrl']['rootLevel']; 02771 02772 $fTWHERE = $fieldValue['config'][$prefix.'foreign_table_where']; 02773 if (strstr($fTWHERE,'###REC_FIELD_')) { 02774 $fTWHERE_parts = explode('###REC_FIELD_',$fTWHERE); 02775 while(list($kk,$vv)=each($fTWHERE_parts)) { 02776 if ($kk) { 02777 $fTWHERE_subpart = explode('###',$vv,2); 02778 $fTWHERE_parts[$kk]=$TSconfig['_THIS_ROW'][$fTWHERE_subpart[0]].$fTWHERE_subpart[1]; 02779 } 02780 } 02781 $fTWHERE = implode('',$fTWHERE_parts); 02782 } 02783 02784 $fTWHERE = str_replace('###CURRENT_PID###',intval($TSconfig['_CURRENT_PID']),$fTWHERE); 02785 $fTWHERE = str_replace('###THIS_UID###',intval($TSconfig['_THIS_UID']),$fTWHERE); 02786 $fTWHERE = str_replace('###THIS_CID###',intval($TSconfig['_THIS_CID']),$fTWHERE); 02787 $fTWHERE = str_replace('###STORAGE_PID###',intval($TSconfig['_STORAGE_PID']),$fTWHERE); 02788 $fTWHERE = str_replace('###SITEROOT###',intval($TSconfig['_SITEROOT']),$fTWHERE); 02789 $fTWHERE = str_replace('###PAGE_TSCONFIG_ID###',intval($TSconfig[$field]['PAGE_TSCONFIG_ID']),$fTWHERE); 02790 $fTWHERE = str_replace('###PAGE_TSCONFIG_IDLIST###',$GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']),$fTWHERE); 02791 $fTWHERE = str_replace('###PAGE_TSCONFIG_STR###',$GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $foreign_table),$fTWHERE); 02792 02793 // rootLevel = -1 is not handled 'properly' here - it goes as if it was rootLevel = 1 (that is pid=0) 02794 $wgolParts = $GLOBALS['TYPO3_DB']->splitGroupOrderLimit($fTWHERE); 02795 if ($rootLevel) { 02796 $queryParts = array( 02797 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'), 02798 'FROM' => $foreign_table, 02799 'WHERE' => $foreign_table.'.pid=0 '. 02800 t3lib_BEfunc::deleteClause($foreign_table).' '. 02801 $wgolParts['WHERE'], 02802 'GROUPBY' => $wgolParts['GROUPBY'], 02803 'ORDERBY' => $wgolParts['ORDERBY'], 02804 'LIMIT' => $wgolParts['LIMIT'] 02805 ); 02806 } else { 02807 $pageClause = $GLOBALS['BE_USER']->getPagePermsClause(1); 02808 if ($foreign_table!='pages') { 02809 $queryParts = array( 02810 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'), 02811 'FROM' => $foreign_table.',pages', 02812 'WHERE' => 'pages.uid='.$foreign_table.'.pid 02813 AND pages.deleted=0 '. 02814 t3lib_BEfunc::deleteClause($foreign_table). 02815 ' AND '.$pageClause.' '. 02816 $wgolParts['WHERE'], 02817 'GROUPBY' => $wgolParts['GROUPBY'], 02818 'ORDERBY' => $wgolParts['ORDERBY'], 02819 'LIMIT' => $wgolParts['LIMIT'] 02820 ); 02821 } else { 02822 $queryParts = array( 02823 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'), 02824 'FROM' => 'pages', 02825 'WHERE' => 'pages.deleted=0 02826 AND '.$pageClause.' '. 02827 $wgolParts['WHERE'], 02828 'GROUPBY' => $wgolParts['GROUPBY'], 02829 'ORDERBY' => $wgolParts['ORDERBY'], 02830 'LIMIT' => $wgolParts['LIMIT'] 02831 ); 02832 } 02833 } 02834 02835 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); 02836 } 02837 02848 function getTCEFORM_TSconfig($table,$row) { 02849 t3lib_BEfunc::fixVersioningPid($table,$row); 02850 02851 $res = array(); 02852 $typeVal = t3lib_BEfunc::getTCAtypeValue($table,$row); 02853 02854 // Get main config for the table 02855 list($TScID,$cPid) = t3lib_BEfunc::getTSCpid($table,$row['uid'],$row['pid']); 02856 02857 $rootLine = t3lib_BEfunc::BEgetRootLine($TScID,'',TRUE); 02858 if ($TScID>=0) { 02859 $tempConf = $GLOBALS['BE_USER']->getTSConfig('TCEFORM.'.$table,t3lib_BEfunc::getPagesTSconfig($TScID,$rootLine)); 02860 if (is_array($tempConf['properties'])) { 02861 while(list($key,$val)=each($tempConf['properties'])) { 02862 if (is_array($val)) { 02863 $fieldN = substr($key,0,-1); 02864 $res[$fieldN] = $val; 02865 unset($res[$fieldN]['types.']); 02866 if (strcmp($typeVal,'') && is_array($val['types.'][$typeVal.'.'])) { 02867 $res[$fieldN] = t3lib_div::array_merge_recursive_overrule($res[$fieldN],$val['types.'][$typeVal.'.']); 02868 } 02869 } 02870 } 02871 } 02872 } 02873 $res['_CURRENT_PID']=$cPid; 02874 $res['_THIS_UID']=$row['uid']; 02875 $res['_THIS_CID']=$row['cid']; 02876 $res['_THIS_ROW']=$row; // So the row will be passed to foreign_table_where_query() 02877 02878 reset($rootLine); 02879 while(list(,$rC)=each($rootLine)) { 02880 if (!$res['_STORAGE_PID']) $res['_STORAGE_PID']=intval($rC['storage_pid']); 02881 if (!$res['_SITEROOT']) $res['_SITEROOT']=$rC['is_siteroot']?intval($rC['uid']):0; 02882 } 02883 02884 return $res; 02885 } 02886 02899 function getTSconfig_pidValue($table,$uid,$pid) { 02900 02901 if (t3lib_div::testInt($pid)) { // If pid is an integer this takes precedence in our lookup. 02902 $thePidValue = intval($pid); 02903 if ($thePidValue<0) { // If ref to another record, look that record up. 02904 $pidRec = t3lib_BEfunc::getRecord($table,abs($thePidValue),'pid'); 02905 $thePidValue = is_array($pidRec) ? $pidRec['pid'] : -2; // Returns -2 if the record did not exist. 02906 } 02907 // ... else the pos/zero pid is just returned here. 02908 } else { // No integer pid and we are forced to look up the $pid 02909 $rr = t3lib_BEfunc::getRecord($table,$uid); // Try to fetch the record pid from uid. If the uid is 'NEW...' then this will of course return nothing... 02910 02911 if (is_array($rr)) { 02912 // First check if the pid is -1 which means it is a workspaced element. Get the "real" record: 02913 if ($rr['pid']=='-1') { 02914 $rr = t3lib_BEfunc::getRecord($table,$rr['t3ver_oid'],'pid'); 02915 if (is_array($rr)) { 02916 $thePidValue = $rr['pid']; 02917 } 02918 } else { 02919 $thePidValue = $rr['pid']; // Returning the "pid" of the record 02920 } 02921 } 02922 02923 if (!$thePidValue) $thePidValue = -1; // Returns -1 if the record with this pid was not found. 02924 } 02925 02926 return $thePidValue; 02927 } 02928 02940 function getPidForModTSconfig($table,$uid,$pid) { 02941 $retVal = ($table=='pages' && t3lib_div::testInt($uid)) ? $uid : $pid; 02942 return $retVal; 02943 } 02944 02956 function getTSCpid($table,$uid,$pid) { 02957 // If pid is negative (referring to another record) the pid of the other record is fetched and returned. 02958 $cPid = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$pid); 02959 // $TScID is the id of $table=pages, else it's the pid of the record. 02960 $TScID = t3lib_BEfunc::getPidForModTSconfig($table,$uid,$cPid); 02961 02962 return array($TScID,$cPid); 02963 } 02964 02972 function firstDomainRecord($rootLine) { 02973 if (t3lib_extMgm::isLoaded('cms')) { 02974 reset($rootLine); 02975 while(list(,$row)=each($rootLine)) { 02976 $dRec = t3lib_BEfunc::getRecordsByField('sys_domain','pid',$row['uid'],' AND redirectTo=\'\' AND hidden=0', '', 'sorting'); 02977 if (is_array($dRec)) { 02978 reset($dRec); 02979 $dRecord = current($dRec); 02980 return ereg_replace('\/$','',$dRecord['domainName']); 02981 } 02982 } 02983 } 02984 } 02985 02994 function getDomainStartPage($domain, $path='') { 02995 if (t3lib_extMgm::isLoaded('cms')) { 02996 $domain = explode(':',$domain); 02997 $domain = strtolower(ereg_replace('\.$','',$domain[0])); 02998 // path is calculated. 02999 $path = trim(ereg_replace('\/[^\/]*$','',$path)); 03000 // stuff: 03001 $domain.=$path; 03002 03003 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_domain.*', 'pages,sys_domain', ' 03004 pages.uid=sys_domain.pid 03005 AND sys_domain.hidden=0 03006 AND (sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain, 'sys_domain').' or sys_domain.domainName='.$GLOBALS['TYPO3_DB']->fullQuoteStr($domain.'/', 'sys_domain').')'. 03007 t3lib_BEfunc::deleteClause('pages'), 03008 '', '', '1'); 03009 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); 03010 } 03011 } 03012 03024 function RTEsetup($RTEprop,$table,$field,$type='') { 03025 $thisConfig = is_array($RTEprop['default.']) ? $RTEprop['default.'] : array(); 03026 $thisFieldConf = $RTEprop['config.'][$table.'.'][$field.'.']; 03027 if (is_array($thisFieldConf)) { 03028 unset($thisFieldConf['types.']); 03029 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig,$thisFieldConf); 03030 } 03031 if ($type && is_array($RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.'])) { 03032 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig,$RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.']); 03033 } 03034 return $thisConfig; 03035 } 03036 03043 function &RTEgetObj() { 03044 03045 // If no RTE object has been set previously, try to create it: 03046 if (!isset($GLOBALS['T3_VAR']['RTEobj'])) { 03047 03048 // Set the object string to blank by default: 03049 $GLOBALS['T3_VAR']['RTEobj'] = array(); 03050 03051 // Traverse registered RTEs: 03052 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'])) { 03053 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'] as $extKey => $rteObjCfg) { 03054 $rteObj = &t3lib_div::getUserObj($rteObjCfg['objRef']); 03055 if (is_object($rteObj)) { 03056 if ($rteObj->isAvailable()) { 03057 $GLOBALS['T3_VAR']['RTEobj'] = &$rteObj; 03058 break; 03059 } else { 03060 $GLOBALS['T3_VAR']['RTEobj'] = array_merge($GLOBALS['T3_VAR']['RTEobj'], $rteObj->errorLog); 03061 } 03062 } 03063 } 03064 } 03065 03066 if (!count($GLOBALS['T3_VAR']['RTEobj'])) { 03067 $GLOBALS['T3_VAR']['RTEobj'][] = 'No RTEs configured at all'; 03068 } 03069 } 03070 03071 // Return RTE object (if any!) 03072 return $GLOBALS['T3_VAR']['RTEobj']; 03073 } 03074 03082 function &softRefParserObj($spKey) { 03083 03084 // If no softRef parser object has been set previously, try to create it: 03085 if (!isset($GLOBALS['T3_VAR']['softRefParser'][$spKey])) { 03086 03087 // Set the object string to blank by default: 03088 $GLOBALS['T3_VAR']['softRefParser'][$spKey] = ''; 03089 03090 // Now, try to create parser object: 03091 $objRef = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser'][$spKey] ? 03092 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser'][$spKey] : 03093 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'][$spKey]; 03094 if ($objRef) { 03095 $softRefParserObj = &t3lib_div::getUserObj($objRef,''); 03096 if (is_object($softRefParserObj)) { 03097 $GLOBALS['T3_VAR']['softRefParser'][$spKey] = &$softRefParserObj; 03098 } 03099 } 03100 } 03101 03102 // Return RTE object (if any!) 03103 return $GLOBALS['T3_VAR']['softRefParser'][$spKey]; 03104 } 03105 03114 function explodeSoftRefParserList($parserList) { 03115 03116 // Looking for global parsers: 03117 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'])) { 03118 $parserList = implode(',',array_keys($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser_GL'])).','.$parserList; 03119 } 03120 03121 // Return immediately if list is blank: 03122 if (!strlen($parserList)) return FALSE; 03123 03124 // Otherwise parse the list: 03125 $keyList = t3lib_div::trimExplode(',', $parserList, 1); 03126 $output = array(); 03127 03128 foreach($keyList as $val) { 03129 $reg = array(); 03130 if (ereg('^([[:alnum:]_-]+)\[(.*)\]$', $val, $reg)) { 03131 $output[$reg[1]] = t3lib_div::trimExplode(';', $reg[2], 1); 03132 } else { 03133 $output[$val] = ''; 03134 } 03135 } 03136 return $output; 03137 } 03138 03146 function isModuleSetInTBE_MODULES($modName) { 03147 reset($GLOBALS['TBE_MODULES']); 03148 $loaded=array(); 03149 while(list($mkey,$list)=each($GLOBALS['TBE_MODULES'])) { 03150 $loaded[$mkey]=1; 03151 if (trim($list)) { 03152 $subList = t3lib_div::trimExplode(',',$list,1); 03153 while(list(,$skey)=each($subList)) { 03154 $loaded[$mkey.'_'.$skey]=1; 03155 } 03156 } 03157 } 03158 return $modName && isset($loaded[$modName]); 03159 } 03160 03169 function referenceCount($table,$ref,$msg='') { 03170 03171 if ($table=='_FILE') { 03172 03173 if (t3lib_div::isFirstPartOfStr($ref,PATH_site)) { 03174 $ref = substr($ref,strlen(PATH_site)); 03175 } else return ''; 03176 03177 // Look up the path: 03178 list($res) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 03179 'count(*) as count', 03180 'sys_refindex', 03181 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex'). 03182 ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($ref,'sys_refindex'). 03183 ' AND deleted=0' 03184 ); 03185 03186 } else { 03187 // Look up the path: 03188 list($res) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 03189 'count(*) as count', 03190 'sys_refindex', 03191 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex'). 03192 ' AND ref_uid='.intval($ref). 03193 ' AND deleted=0' 03194 ); 03195 } 03196 03197 return $res['count'] ? ($msg ? sprintf($msg,$res['count']) : $res['count']) : ''; 03198 } 03199 03200 03201 03202 03203 03204 03205 03206 03207 03208 03209 03210 03211 03212 03213 /******************************************* 03214 * 03215 * Workspaces / Versioning 03216 * 03217 *******************************************/ 03218 03229 function selectVersionsOfRecord($table, $uid, $fields='*', $workspace=0, $includeDeletedRecords=FALSE) { 03230 global $TCA; 03231 03232 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) { 03233 03234 // Select all versions of record: 03235 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 03236 $fields, 03237 $table, 03238 '((t3ver_oid='.intval($uid).($workspace!=0?' AND t3ver_wsid='.intval($workspace):'').') OR uid='.intval($uid).')'. 03239 ($includeDeletedRecords ? '' : t3lib_BEfunc::deleteClause($table)), 03240 '', 03241 't3ver_id DESC' 03242 ); 03243 03244 // Add rows to output array: 03245 $realPid = 0; 03246 $outputRows = array(); 03247 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 03248 if ($uid==$row['uid']) { 03249 $row['_CURRENT_VERSION']=TRUE; 03250 $realPid = $row['pid']; 03251 } 03252 $outputRows[] = $row; 03253 } 03254 03255 // Set real-pid: 03256 foreach($outputRows as $idx => $oRow) { 03257 $outputRows[$idx]['_REAL_PID'] = $realPid; 03258 } 03259 03260 return $outputRows; 03261 } 03262 } 03263 03277 function fixVersioningPid($table,&$rr,$ignoreWorkspaceMatch=FALSE) { 03278 global $TCA; 03279 03280 // Check that the input record is an offline version from a table that supports versioning: 03281 if (is_array($rr) && $rr['pid']==-1 && $TCA[$table]['ctrl']['versioningWS']) { 03282 03283 // Check values for t3ver_oid and t3ver_wsid: 03284 if (isset($rr['t3ver_oid']) && isset($rr['t3ver_wsid'])) { // If "t3ver_oid" is already a field, just set this: 03285 $oid = $rr['t3ver_oid']; 03286 $wsid = $rr['t3ver_wsid']; 03287 } else { // Otherwise we have to expect "uid" to be in the record and look up based on this: 03288 $newPidRec = t3lib_BEfunc::getRecord($table,$rr['uid'],'t3ver_oid,t3ver_wsid'); 03289 if (is_array($newPidRec)) { 03290 $oid = $newPidRec['t3ver_oid']; 03291 $wsid = $newPidRec['t3ver_wsid']; 03292 } 03293 } 03294 03295 // If ID of current online version is found, look up the PID value of that: 03296 if ($oid && ($ignoreWorkspaceMatch || !strcmp((int)$wsid,$GLOBALS['BE_USER']->workspace))) { 03297 $oidRec = t3lib_BEfunc::getRecord($table,$oid,'pid'); 03298 if (is_array($oidRec)) { 03299 $rr['_ORIG_pid'] = $rr['pid']; 03300 $rr['pid'] = $oidRec['pid']; 03301 } 03302 } 03303 } 03304 } 03305 03317 function workspaceOL($table,&$row,$wsid=-99) { 03318 03319 // Initialize workspace ID: 03320 if ($wsid == -99) $wsid = $GLOBALS['BE_USER']->workspace; 03321 03322 // Check if workspace is different from zero and record is set: 03323 if ($wsid!==0 && is_array($row)) { 03324 $wsAlt = t3lib_BEfunc::getWorkspaceVersionOfRecord($wsid, $table, $row['uid'], implode(',',array_keys($row))); 03325 03326 // If version was found, swap the default record with that one. 03327 if (is_array($wsAlt)) { 03328 03329 // Always correct PID from -1 to what it should be: 03330 if (isset($wsAlt['pid'])) { 03331 $wsAlt['_ORIG_pid'] = $wsAlt['pid']; // Keep the old (-1) - indicates it was a version... 03332 $wsAlt['pid'] = $row['pid']; // Set in the online versions PID. 03333 } 03334 03335 // For versions of single elements or page+content, swap UID and PID: 03336 if ($table!=='pages' || $wsAlt['t3ver_swapmode']<=0) { 03337 $wsAlt['_ORIG_uid'] = $wsAlt['uid']; 03338 $wsAlt['uid'] = $row['uid']; 03339 03340 // Backend css class: 03341 $wsAlt['_CSSCLASS'] = $table==='pages' && $wsAlt['t3ver_swapmode']==0 ? 'ver-page' : 'ver-element'; 03342 } else { // This is only for page-versions with BRANCH below! 03343 $wsAlt['_ONLINE_uid'] = $row['uid']; 03344 03345 // Backend css class: 03346 $wsAlt['_CSSCLASS'] = 'ver-branchpoint'; 03347 $wsAlt['_SUBCSSCLASS'] = 'ver-branch'; 03348 } 03349 03350 // Changing input record to the workspace version alternative: 03351 $row = $wsAlt; 03352 } 03353 } 03354 } 03355 03365 function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields='*') { 03366 global $TCA; 03367 03368 if ($workspace!==0 && $TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) { 03369 03370 // Select workspace version of record: 03371 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 03372 $fields, 03373 $table, 03374 'pid=-1 AND 03375 t3ver_oid='.intval($uid).' AND 03376 t3ver_wsid='.intval($workspace). 03377 t3lib_BEfunc::deleteClause($table) 03378 ); 03379 03380 if (is_array($rows[0])) return $rows[0]; 03381 } 03382 03383 return FALSE; 03384 } 03385 03394 function getLiveVersionOfRecord($table,$uid,$fields='*') { 03395 global $TCA; 03396 03397 // Check that table supports versioning: 03398 if ($TCA[$table] && $TCA[$table]['ctrl']['versioningWS']) { 03399 $rec = t3lib_BEfunc::getRecord($table,$uid,'pid,t3ver_oid'); 03400 03401 if ($rec['pid']==-1) { 03402 return t3lib_BEfunc::getRecord($table,$rec['t3ver_oid'],$fields); 03403 } 03404 } 03405 } 03406 03416 function isPidInVersionizedBranch($pid, $table='',$returnStage=FALSE) { 03417 $rl = t3lib_BEfunc::BEgetRootLine($pid); 03418 $c = 0; 03419 03420 foreach($rl as $rec) { 03421 if ($rec['_ORIG_pid']==-1) { 03422 // In any case: is it a branchpoint, then OK... 03423 if ($rec['t3ver_swapmode']>0) { 03424 return $returnStage ? (int)$rec['t3ver_stage'] : 'branchpoint'; // OK, we are in a versionized branch 03425 } elseif ($c==0 && $rec['t3ver_swapmode']==0 && $table && $GLOBALS['TCA'][$table]['ctrl']['versioning_followPages']) { // First level: So $table must be versioning_followPages 03426 return $returnStage ? (int)$rec['t3ver_stage'] : 'first'; // OK, we are in a versionized branch 03427 } 03428 } 03429 $c++; 03430 } 03431 } 03432 03439 function versioningPlaceholderClause($table) { 03440 if ($GLOBALS['BE_USER']->workspace!==0 && $GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) { 03441 return ' AND ('.$table.'.t3ver_state!=1 OR '.$table.'.t3ver_wsid='.intval($GLOBALS['BE_USER']->workspace).')'; 03442 } 03443 } 03444 03453 function countVersionsOfRecordsOnPage($workspace,$pageId, $allTables=FALSE) { 03454 $output = array(); 03455 if ($workspace!=0) { 03456 foreach($GLOBALS['TCA'] as $tableName => $cfg) { 03457 if ($tableName!='pages' && $cfg['ctrl']['versioningWS'] && ($cfg['ctrl']['versioning_followPages'] || $allTables)) { 03458 03459 // Select all records from this table in the database from the workspace 03460 // This joins the online version with the offline version as tables A and B 03461 $output[$tableName] = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows ( 03462 'B.uid as live_uid, A.uid as offline_uid', 03463 $tableName.' A,'.$tableName.' B', 03464 'A.pid=-1'. // Table A is the offline version and pid=-1 defines offline 03465 ' AND B.pid='.intval($pageId). 03466 ' AND A.t3ver_wsid='.intval($workspace). 03467 ' AND A.t3ver_oid=B.uid'. // ... and finally the join between the two tables. 03468 t3lib_BEfunc::deleteClause($tableName,'A'). 03469 t3lib_BEfunc::deleteClause($tableName,'B') 03470 ); 03471 03472 if (!is_array($output[$tableName]) || !count($output[$tableName])) { 03473 unset($output[$tableName]); 03474 } 03475 } 03476 } 03477 } 03478 return $output; 03479 } 03480 03488 function wsMapId($table,$uid) { 03489 if ($wsRec = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace,$table,$uid,'uid')) { 03490 return $wsRec['uid']; 03491 } else { 03492 return $uid; 03493 } 03494 } 03495 03496 03497 03498 03499 03500 03501 03502 /******************************************* 03503 * 03504 * Miscellaneous 03505 * 03506 *******************************************/ 03507 03518 function typo3PrintError($header,$text,$js='',$head=1) { 03519 // This prints out a TYPO3 error message. 03520 // If $js is set the message will be output in JavaScript 03521 if ($js) { 03522 echo "alert('".t3lib_div::slashJS($header.'\n'.$text)."');"; 03523 } else { 03524 echo $head?'<html> 03525 <head> 03526 <title>Error!</title> 03527 </head> 03528 <body bgcolor="white" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">':''; 03529 echo '<div align="center"> 03530 <table border="0" cellspacing="0" cellpadding="0" width="333"> 03531 <tr> 03532 <td align="center">'. 03533 ($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" />'). 03534 '</td> 03535 </tr> 03536 <tr> 03537 <td bgcolor="black"> 03538 <table width="100%" border="0" cellspacing="1" cellpadding="10"> 03539 <tr> 03540 <td bgcolor="#F4F0E8"> 03541 <font face="verdana,arial,helvetica" size="2">'; 03542 echo '<b><center><font size="+1">'.$header.'</font></center></b><br />'.$text; 03543 echo ' </font> 03544 </td> 03545 </tr> 03546 </table> 03547 </td> 03548 </tr> 03549 </table> 03550 </div>'; 03551 echo $head?' 03552 </body> 03553 </html>':''; 03554 } 03555 } 03556 03562 function TYPO3_copyRightNotice() { 03563 global $TYPO3_CONF_VARS; 03564 03565 // COPYRIGHT NOTICE: 03566 $loginCopyrightWarrantyProvider = strip_tags(trim($TYPO3_CONF_VARS['SYS']['loginCopyrightWarrantyProvider'])); 03567 $loginCopyrightWarrantyURL = strip_tags(trim($TYPO3_CONF_VARS['SYS']['loginCopyrightWarrantyURL'])); 03568 03569 if (strlen($loginCopyrightWarrantyProvider)>=2 && strlen($loginCopyrightWarrantyURL)>=10) { 03570 $warrantyNote='Warranty is supplied by '.htmlspecialchars($loginCopyrightWarrantyProvider).'; <a href="'.htmlspecialchars($loginCopyrightWarrantyURL).'" target="_blank">click for details.</a>'; 03571 } else { 03572 $warrantyNote='TYPO3 comes with ABSOLUTELY NO WARRANTY; <a href="http://typo3.com/1316.0.html" target="_blank">click for details.</a>'; 03573 } 03574 $cNotice = '<a href="http://typo3.com/" target="_blank"><img src="gfx/loginlogo_transp.gif" width="75" vspace="2" hspace="4" height="19" alt="TYPO3 logo" align="left" />TYPO3 CMS ver. '.htmlspecialchars(TYPO3_version).'</a>. Copyright © '.htmlspecialchars(TYPO3_copyright_year).' Kasper Skårhøj. Extensions are copyright of their respective owners. Go to <a href="http://typo3.com/" target="_blank">http://typo3.com/</a> for details. 03575 '.strip_tags($warrantyNote,'<a>').' This is free software, and you are welcome to redistribute it under certain conditions; <a href="http://typo3.com/1316.0.html" target="_blank">click for details</a>. Obstructing the appearance of this notice is prohibited by law.'; 03576 03577 return $cNotice; 03578 } 03579 03586 function displayWarningMessages() { 03587 if ($GLOBALS['BE_USER']->isAdmin()) { 03588 $warnings = array(); 03589 03590 // Check if the Install Tool Password is still default: joh316 03591 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword']==md5('joh316')) { 03592 $warnings[] = 'The password of your Install Tool is still using the default value "joh316"'; 03593 } 03594 03595 // Check if there is still a default user 'admin' with password 'password' (MD5sum = 5f4dcc3b5aa765d61d8327deb882cf99) 03596 $where_clause = 'username='.$GLOBALS['TYPO3_DB']->fullQuoteStr('admin','be_users').' AND password='.$GLOBALS['TYPO3_DB']->fullQuoteStr('5f4dcc3b5aa765d61d8327deb882cf99','be_users').t3lib_BEfunc::deleteClause('be_users'); 03597 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('username, password', 'be_users', $where_clause); 03598 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res)) { 03599 $warnings[] = 'The backend user "admin" with password "password" is still existing'; 03600 } 03601 03602 // Check if the Install Tool is enabled 03603 $enableInstallToolFile = PATH_site.'typo3conf/ENABLE_INSTALL_TOOL'; 03604 if (@is_file($enableInstallToolFile)) { 03605 $warnings[] = 'The Install Tool is enabled. Make sure to delete the file "'.$enableInstallToolFile.'" when you have finished setting up TYPO3'; 03606 } 03607 03608 // Check if the encryption key is empty 03609 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] == '') { 03610 $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=config#set_encryptionKey'); 03611 $warnings[] = 'The encryption key is not set! Set it in <a href="'.$url.'">$TYPO3_CONF_VARS[SYS][encryptionKey]</a>'; 03612 } 03613 03614 // Check if there are still updates to perform 03615 if (!t3lib_div::compat_version(TYPO3_branch)) { 03616 $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=update'); 03617 $warnings[] = 'This installation is not configured for the TYPO3 version it is running. You probably did so by intention, in this case you can safely ignore this message. If unsure, visit the <a href="'.$url.'" target="_blank">Update Wizard</a> in the Install Tool to see which changes would be affected.'; 03618 } 03619 03620 // Check if sys_refindex is empty 03621 list($count) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('count(*) as rcount','sys_refindex','1=1'); 03622 if (!$count['rcount']) { 03623 $warnings[] = 'The Reference Index table is empty which is likely to be the case because you just upgraded your TYPO3 source. Please go to Tools>DB Check and update the reference index.'; 03624 } 03625 03626 if (count($warnings)) { 03627 $style = ' style="margin-bottom:10px;"'; 03628 $content = '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>'. 03629 $GLOBALS['TBE_TEMPLATE']->icons(3).'Important notice!<br /><ul><li'.$style.'>'. 03630 implode('</li><li'.$style.'>', $warnings).'</li></ul>'. 03631 'It is highly recommended that you change this immediately.'. 03632 '</td></tr></table>'; 03633 03634 unset($warnings); 03635 return $content; 03636 } 03637 } 03638 return '<p> </p>'; 03639 } 03640 03648 function getPathType_web_nonweb($path) { 03649 return t3lib_div::isFirstPartOfStr($path,t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT')) ? 'web' : ''; 03650 } 03651 03660 function ADMCMD_previewCmds($pageinfo) { 03661 if ($pageinfo['fe_group']>0) { 03662 $simUser = '&ADMCMD_simUser='.$pageinfo['fe_group']; 03663 } 03664 if ($pageinfo['starttime']>time()) { 03665 $simTime = '&ADMCMD_simTime='.$pageinfo['starttime']; 03666 } 03667 if ($pageinfo['endtime']<time() && $pageinfo['endtime']!=0) { 03668 $simTime = '&ADMCMD_simTime='.($pageinfo['endtime']-1); 03669 } 03670 return $simUser.$simTime; 03671 } 03672 03682 function processParams($params) { 03683 $paramArr=array(); 03684 $lines=explode(chr(10),$params); 03685 while(list(,$val)=each($lines)) { 03686 $val = trim($val); 03687 if ($val) { 03688 $pair = explode('=',$val,2); 03689 $paramArr[trim($pair[0])] = trim($pair[1]); 03690 } 03691 } 03692 return $paramArr; 03693 } 03694 03708 function getListOfBackendModules($name,$perms_clause,$backPath='',$script='index.php') { 03709 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'doktype!=255 AND module IN (\''.implode('\',\'',$name).'\') AND'.$perms_clause.t3lib_BEfunc::deleteClause('pages')); 03710 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) return false; 03711 03712 $out=''; 03713 $theRows=array(); 03714 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 03715 $theRows[]=$row; 03716 $out.='<span class="nobr"><a href="'.htmlspecialchars($script.'?id='.$row['uid']).'">'. 03717 t3lib_iconWorks::getIconImage('pages',$row,$backPath,'title="'.htmlspecialchars(t3lib_BEfunc::getRecordPath($row['uid'],$perms_clause,20)).'" align="top"'). 03718 htmlspecialchars($row['title']). 03719 '</a></span><br />'; 03720 } 03721 return array('rows'=>$theRows,'list'=>$out); 03722 } 03723 } 03724 ?>