/src/typo3_src-4.1.2/t3lib/class.t3lib_befunc.php

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                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00238                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00239                         if ($row) {
00240                                 return $row;
00241                         }
00242                 }
00243         }
00244 
00255         function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
00256                 if ($fields !== '*') {
00257                         $internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
00258                         $row = t3lib_BEfunc::getRecord($table,$uid,$internalFields,$where,$useDeleteClause);
00259                         t3lib_BEfunc::workspaceOL($table,$row);
00260 
00261                         if (is_array ($row)) {
00262                                 foreach (array_keys($row) as $key) {
00263                                         if (!t3lib_div::inList($fields, $key) && $key{0} !== '_') {
00264                                                 unset ($row[$key]);
00265                                         }
00266                                 }
00267                         }
00268                 } else {
00269                         $row = t3lib_BEfunc::getRecord($table,$uid,$fields,$where);
00270                         t3lib_BEfunc::workspaceOL($table,$row);
00271                 }
00272                 return $row;
00273         }
00274 
00288         function getRecordRaw($table,$where='',$fields='*')     {
00289                 $row = FALSE;
00290                 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1')))    {
00291                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00292                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00293                 }
00294                 return $row;
00295         }
00296 
00313         function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true)       {
00314                 global $TCA;
00315                 if (is_array($TCA[$theTable])) {
00316                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00317                                                 '*',
00318                                                 $theTable,
00319                                                 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
00320                                                         ($useDeleteClause ? t3lib_BEfunc::deleteClause($theTable).' ' : '').
00321                                                         t3lib_BEfunc::versioningPlaceholderClause($theTable).' '.
00322                                                         $whereClause,   // whereClauseMightContainGroupOrderBy
00323                                                 $groupBy,
00324                                                 $orderBy,
00325                                                 $limit
00326                                         );
00327                         $rows = array();
00328                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00329                                 $rows[] = $row;
00330                         }
00331                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
00332                         if (count($rows))       return $rows;
00333                 }
00334         }
00335 
00346         function searchQuery($searchWords,$fields,$table='')    {
00347                 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
00348         }
00349 
00361         function listQuery($field,$value)       {
00362                 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
00363         }
00364 
00373         function splitTable_Uid($str)   {
00374                 list($uid,$table) = explode('_',strrev($str),2);
00375                 return array(strrev($table),strrev($uid));
00376         }
00377 
00388         function getSQLselectableList($in_list,$tablename,$default_tablename)   {
00389                 $list = Array();
00390                 if ((string)trim($in_list)!='') {
00391                         $tempItemArray = explode(',',trim($in_list));
00392                         while(list($key,$val)=each($tempItemArray))     {
00393                                 $val = strrev($val);
00394                                 $parts = explode('_',$val,2);
00395                                 if ((string)trim($parts[0])!='')        {
00396                                         $theID = intval(strrev($parts[0]));
00397                                         $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
00398                                         if ($theTable==$tablename)      {$list[]=$theID;}
00399                                 }
00400                         }
00401                 }
00402                 return implode(',',$list);
00403         }
00404 
00416         function BEenableFields($table,$inv=0)  {
00417                 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
00418                 $query=array();
00419                 $invQuery=array();
00420                 if (is_array($ctrl))    {
00421                         if (is_array($ctrl['enablecolumns']))   {
00422                                 if ($ctrl['enablecolumns']['disabled']) {
00423                                         $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
00424                                         $query[]=$field.'=0';
00425                                         $invQuery[]=$field.'!=0';
00426                                 }
00427                                 if ($ctrl['enablecolumns']['starttime'])        {
00428                                         $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
00429                                         $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00430                                         $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00431                                 }
00432                                 if ($ctrl['enablecolumns']['endtime'])  {
00433                                         $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
00434                                         $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
00435                                         $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
00436                                 }
00437                         }
00438                 }
00439                 $outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
00440 
00441                 return $outQ;
00442         }
00443 
00444 
00445 
00446 
00447 
00448 
00449 
00450 
00451 
00452 
00453         /*******************************************
00454          *
00455          * SQL-related, DEPRECATED functions
00456          * (use t3lib_DB functions instead)
00457          *
00458          *******************************************/
00459 
00460 
00480         function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')      {
00481                 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
00482                                         $select,
00483                                         $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
00484                                         $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
00485                                                 $whereClause,   // whereClauseMightContainGroupOrderBy
00486                                         $groupBy,
00487                                         $orderBy,
00488                                         $limit
00489                                 );
00490                 return $query;
00491         }
00492 
00502         function DBcompileInsert($table,$fields_values) {
00503                 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
00504         }
00505 
00516         function DBcompileUpdate($table,$where,$fields_values)  {
00517                 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
00518         }
00519 
00520 
00521 
00522 
00523 
00524 
00525 
00526 
00527 
00528 
00529         /*******************************************
00530          *
00531          * Page tree, TCA related
00532          *
00533          *******************************************/
00534 
00546         function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE)      {
00547                 if (is_array($GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0]))       {
00548                         return $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0];
00549                 }
00550                 $pid = $uid;
00551                 $loopCheck = 100;
00552                 $theRowArray = Array();
00553                 $output = Array();
00554                 while ($uid!=0 && $loopCheck>0) {
00555                         $loopCheck--;
00556                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00557                                 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
00558                                 'pages',
00559                                 'uid='.intval($uid).' '.
00560                                         t3lib_BEfunc::deleteClause('pages').' '.
00561                                         $clause         // whereClauseMightContainGroupOrderBy
00562                         );
00563                         if ($GLOBALS['TYPO3_DB']->sql_error())  {
00564                                 debug($GLOBALS['TYPO3_DB']->sql_error(),1);
00565                         }
00566                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00567                                 if($workspaceOL)        t3lib_BEfunc::workspaceOL('pages',$row);
00568                                 t3lib_BEfunc::fixVersioningPid('pages',$row);
00569                                 $uid = $row['pid'];
00570                                 $theRowArray[] = $row;
00571                         } else {
00572                                 break;
00573                         }
00574                 }
00575                 if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');}
00576                 if (is_array($theRowArray))     {
00577                         reset($theRowArray);
00578                         $c=count($theRowArray);
00579                         while(list($key,$val)=each($theRowArray))       {
00580                                 $c--;
00581                                 $output[$c]['uid'] = $val['uid'];
00582                                 $output[$c]['pid'] = $val['pid'];
00583                                 if (isset($val['_ORIG_pid'])) $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
00584                                 $output[$c]['title'] = $val['title'];
00585                                 $output[$c]['TSconfig'] = $val['TSconfig'];
00586                                 $output[$c]['is_siteroot'] = $val['is_siteroot'];
00587                                 $output[$c]['storage_pid'] = $val['storage_pid'];
00588                                 $output[$c]['t3ver_oid'] = $val['t3ver_oid'];
00589                                 $output[$c]['t3ver_wsid'] = $val['t3ver_wsid'];
00590                                 $output[$c]['t3ver_state'] = $val['t3ver_state'];
00591                                 $output[$c]['t3ver_swapmode'] = $val['t3ver_swapmode'];
00592                                 $output[$c]['t3ver_stage'] = $val['t3ver_stage'];
00593                         }
00594                 }
00595                 $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$pid][$clause][$workspaceOL?1:0] = $output;
00596 
00597                 return $output;
00598         }
00599 
00607         function openPageTree($pid,$clearExpansion)     {
00608                 global $BE_USER;
00609 
00610                         // Get current expansion data:
00611                 if ($clearExpansion)    {
00612                         $expandedPages = array();
00613                 } else {
00614                         $expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
00615                 }
00616 
00617                         // Get rootline:
00618                 $rL = t3lib_BEfunc::BEgetRootLine($pid);
00619 
00620                         // First, find out what mount index to use (if more than one DB mount exists):
00621                 $mountIndex = 0;
00622                 $mountKeys = array_flip($BE_USER->returnWebmounts());
00623                 foreach($rL as $rLDat)  {
00624                         if (isset($mountKeys[$rLDat['uid']]))   {
00625                                 $mountIndex = $mountKeys[$rLDat['uid']];
00626                                 break;
00627                         }
00628                 }
00629 
00630                         // Traverse rootline and open paths:
00631                 foreach($rL as $rLDat)  {
00632                         $expandedPages[$mountIndex][$rLDat['uid']] = 1;
00633                 }
00634 
00635                         // Write back:
00636                 $BE_USER->uc['browseTrees']['browsePages'] = serialize($expandedPages);
00637                 $BE_USER->writeUC();
00638         }
00639 
00652         function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)   {
00653                 if (!$titleLimit) { $titleLimit=1000; }
00654 
00655                 $loopCheck = 100;
00656                 $output = $fullOutput = '/';
00657                 while ($uid!=0 && $loopCheck>0) {
00658                         $loopCheck--;
00659                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00660                                                 'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode',
00661                                                 'pages',
00662                                                 'uid='.intval($uid).
00663                                                         t3lib_BEfunc::deleteClause('pages').
00664                                                         (strlen(trim($clause)) ? ' AND '.$clause : '')
00665                                         );
00666                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00667                                 t3lib_BEfunc::workspaceOL('pages',$row);
00668                                 t3lib_BEfunc::fixVersioningPid('pages',$row);
00669 
00670                                 if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0)      {       // Branch points
00671                                         $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...
00672                                 }
00673                                 $uid = $row['pid'];
00674                                 $output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output;
00675                                 if ($fullTitleLimit)    $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
00676                         } else {
00677                                 break;
00678                         }
00679                 }
00680 
00681                 if ($fullTitleLimit)    {
00682                         return array($output, $fullOutput);
00683                 } else {
00684                         return $output;
00685                 }
00686         }
00687 
00695         function getExcludeFields()     {
00696                 global $TCA;
00697                         // All TCA keys:
00698                 $theExcludeArray = Array();
00699                 $tc_keys = array_keys($TCA);
00700                 foreach($tc_keys as $table)     {
00701                                 // Load table
00702                         t3lib_div::loadTCA($table);
00703                                 // All field names configured:
00704                         if (is_array($TCA[$table]['columns']))  {
00705                                 $f_keys = array_keys($TCA[$table]['columns']);
00706                                 foreach($f_keys as $field)      {
00707                                         if ($TCA[$table]['columns'][$field]['exclude']) {
00708                                                         // Get Human Readable names of fields and table:
00709                                                 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00710                                                         // add entry:
00711                                                 $theExcludeArray[] = Array($Fname , $table.':'.$field);
00712                                         }
00713                                 }
00714                         }
00715                 }
00716                 return $theExcludeArray;
00717         }
00718 
00725         function getExplicitAuthFieldValues()   {
00726                 global $TCA;
00727 
00728                         // Initialize:
00729                 $adLabel = array(
00730                         'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
00731                         'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
00732                 );
00733 
00734                         // All TCA keys:
00735                 $allowDenyOptions = Array();
00736                 $tc_keys = array_keys($TCA);
00737                 foreach($tc_keys as $table)     {
00738 
00739                                 // Load table
00740                         t3lib_div::loadTCA($table);
00741 
00742                                 // All field names configured:
00743                         if (is_array($TCA[$table]['columns']))  {
00744                                 $f_keys = array_keys($TCA[$table]['columns']);
00745                                 foreach($f_keys as $field)      {
00746                                         $fCfg = $TCA[$table]['columns'][$field]['config'];
00747                                         if ($fCfg['type']=='select' && $fCfg['authMode'])       {
00748 
00749                                                         // Check for items:
00750                                                 if (is_array($fCfg['items']))   {
00751                                                                 // Get Human Readable names of fields and table:
00752                                                         $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
00753 
00754                                                                 // Check for items:
00755                                                         foreach($fCfg['items'] as $iVal)        {
00756                                                                 if (strcmp($iVal[1],''))        {       // Values '' is not controlled by this setting.
00757 
00758                                                                                 // Find iMode:
00759                                                                         $iMode = '';
00760                                                                         switch((string)$fCfg['authMode'])       {
00761                                                                                 case 'explicitAllow':
00762                                                                                         $iMode = 'ALLOW';
00763                                                                                 break;
00764                                                                                 case 'explicitDeny':
00765                                                                                         $iMode = 'DENY';
00766                                                                                 break;
00767                                                                                 case 'individual':
00768                                                                                         if (!strcmp($iVal[4],'EXPL_ALLOW'))     {
00769                                                                                                 $iMode = 'ALLOW';
00770                                                                                         } elseif (!strcmp($iVal[4],'EXPL_DENY'))        {
00771                                                                                                 $iMode = 'DENY';
00772                                                                                         }
00773                                                                                 break;
00774                                                                         }
00775 
00776                                                                                 // Set iMode:
00777                                                                         if ($iMode)     {
00778                                                                                 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
00779                                                                         }
00780                                                                 }
00781                                                         }
00782                                                 }
00783                                         }
00784                                 }
00785                         }
00786                 }
00787 
00788                 return $allowDenyOptions;
00789         }
00790 
00796         function getSystemLanguages()   {
00797 
00798                         // Initialize, add default language:
00799                 $sysLanguages = array();
00800                 $sysLanguages[] = array('Default language', 0);
00801 
00802                         // Traverse languages
00803                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language'));
00804                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00805                         $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
00806                 }
00807 
00808                 return $sysLanguages;
00809         }
00810 
00821         function readPageAccess($id,$perms_clause)      {
00822                 if ((string)$id!='')    {
00823                         $id = intval($id);
00824                         if (!$id)       {
00825                                 if ($GLOBALS['BE_USER']->isAdmin())     {
00826                                         $path = '/';
00827                                         $pageinfo['_thePath'] = $path;
00828                                         return $pageinfo;
00829                                 }
00830                         } else {
00831                                 $pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : ''));
00832                                 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause))   {
00833                                         t3lib_BEfunc::workspaceOL('pages', $pageinfo);
00834                                         t3lib_BEfunc::fixVersioningPid('pages', $pageinfo);
00835                                         list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
00836                                         return $pageinfo;
00837                                 }
00838                         }
00839                 }
00840                 return false;
00841         }
00842 
00852         function getTCAtypes($table,$rec,$useFieldNameAsKey=0)  {
00853                 global $TCA;
00854 
00855                 t3lib_div::loadTCA($table);
00856                 if ($TCA[$table])       {
00857 
00858                                 // Get type value:
00859                         $fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec);
00860 
00861                                 // Get typesConf
00862                         $typesConf = $TCA[$table]['types'][$fieldValue];
00863 
00864                                 // Get fields list and traverse it
00865                         $fieldList = explode(',', $typesConf['showitem']);
00866                         $altFieldList = array();
00867 
00868                                 // Traverse fields in types config and parse the configuration into a nice array:
00869                         foreach($fieldList as $k => $v) {
00870                                 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
00871                                 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
00872                                 $specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
00873 
00874                                 $fieldList[$k]=array(
00875                                         'field' => $pFieldName,
00876                                         'title' => $pAltTitle,
00877                                         'palette' => $pPalette,
00878                                         'spec' => $specConfParts,
00879                                         'origString' => $v
00880                                 );
00881                                 if ($useFieldNameAsKey) {
00882                                         $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
00883                                 }
00884                         }
00885                         if ($useFieldNameAsKey) {
00886                                 $fieldList = $altFieldList;
00887                         }
00888 
00889                                 // Return array:
00890                         return $fieldList;
00891                 }
00892         }
00893 
00905         function getTCAtypeValue($table,$rec)   {
00906                 global $TCA;
00907 
00908                         // 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.
00909                 t3lib_div::loadTCA($table);
00910                 if ($TCA[$table])       {
00911                         $field = $TCA[$table]['ctrl']['type'];
00912                         $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
00913                         if (!is_array($TCA[$table]['types'][$fieldValue]))      $fieldValue = 1;
00914                         return $fieldValue;
00915                 }
00916         }
00917 
00928         function getSpecConfParts($str, $defaultExtras) {
00929 
00930                         // Add defaultExtras:
00931                 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
00932 
00933                 $reg = array();
00934                 if (count($specConfParts))      {
00935                         foreach($specConfParts as $k2 => $v2)   {
00936                                 unset($specConfParts[$k2]);
00937                                 if (ereg('(.*)\[(.*)\]',$v2,$reg))      {
00938                                         $specConfParts[trim($reg[1])] = array(
00939                                                 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
00940                                         );
00941                                 } else {
00942                                         $specConfParts[trim($v2)] = 1;
00943                                 }
00944                         }
00945                 } else {
00946                         $specConfParts = array();
00947                 }
00948                 return $specConfParts;
00949         }
00950 
00959         function getSpecConfParametersFromArray($pArr)  {
00960                 $out=array();
00961                 if (is_array($pArr))    {
00962                         reset($pArr);
00963                         while(list($k,$v)=each($pArr))  {
00964                                 $parts=explode('=',$v,2);
00965                                 if (count($parts)==2)   {
00966                                         $out[trim($parts[0])]=trim($parts[1]);
00967                                 } else {
00968                                         $out[$k]=$v;
00969                                 }
00970                         }
00971                 }
00972                 return $out;
00973         }
00974 
00989         function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE,$newRecordPidValue=0) {
00990                 global $TYPO3_CONF_VARS;
00991 
00992                         // Get pointer field etc from TCA-config:
00993                 $ds_pointerField =      $conf['ds_pointerField'];
00994                 $ds_array =             $conf['ds'];
00995                 $ds_tableField =        $conf['ds_tableField'];
00996                 $ds_searchParentField =         $conf['ds_pointerField_searchParent'];
00997 
00998                         // Find source value:
00999                 $dataStructArray='';
01000                 if (is_array($ds_array))        {       // If there is a data source array, that takes precedence
01001                                 // If a pointer field is set, take the value from that field in the $row array and use as key.
01002                         if ($ds_pointerField)   {
01003                                 $srcPointer = $row[$ds_pointerField];
01004                                 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
01005                         } else $srcPointer='default';
01006 
01007                                 // 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.
01008                         if (substr($ds_array[$srcPointer],0,5)=='FILE:')        {
01009                                 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5));
01010                                 if ($file && @is_file($file))   {
01011                                         $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01012                                 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")';      // Error message.
01013                         } else {
01014                                 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
01015                         }
01016 
01017                 } elseif ($ds_pointerField) {   // If pointer field AND possibly a table/field is set:
01018                                 // Value of field pointed to:
01019                         $srcPointer = $row[$ds_pointerField];
01020 
01021                                 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
01022                         if ($ds_searchParentField && !$srcPointer)      {
01023                                 $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###
01024                                 if ($WSOL)      {
01025                                         t3lib_BEfunc::workspaceOL($table,$rr);
01026                                         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!
01027                                 }
01028                                 $uidAcc=array();        // Used to avoid looping, if any should happen.
01029                                 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
01030                                 while(!$srcPointer)             {
01031 
01032                                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
01033                                                                         'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),
01034                                                                         $table,
01035                                                                         'uid='.intval($newRecordPidValue ? $newRecordPidValue : $rr[$ds_searchParentField]).t3lib_BEfunc::deleteClause($table)  ###NOTE_A###
01036                                                                 );
01037                                         $newRecordPidValue = 0;
01038                                         $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
01039 
01040                                                 // break if no result from SQL db or if looping...
01041                                         if (!is_array($rr) || isset($uidAcc[$rr['uid']]))       break;
01042                                         $uidAcc[$rr['uid']]=1;
01043 
01044                                         if ($WSOL)      {
01045                                                 t3lib_BEfunc::workspaceOL($table,$rr);
01046                                                 t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
01047                                         }
01048                                         $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
01049                                 }
01050                         }
01051 
01052                                 // If there is a srcPointer value:
01053                         if ($srcPointer)        {
01054                                 if (t3lib_div::testInt($srcPointer))    {       // If integer, then its a record we will look up:
01055                                         list($tName,$fName) = explode(':',$ds_tableField,2);
01056                                         if ($tName && $fName && is_array($GLOBALS['TCA'][$tName]))      {
01057                                                 $dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer);
01058                                                 if ($WSOL)      {
01059                                                         t3lib_BEfunc::workspaceOL($tName,$dataStructRec);
01060                                                 }
01061                                                 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
01062                                         } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
01063                                 } else {        // Otherwise expect it to be a file:
01064                                         $file = t3lib_div::getFileAbsFileName($srcPointer);
01065                                         if ($file && @is_file($file))   {
01066                                                 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
01067                                         } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")';       // Error message.
01068                                 }
01069                         } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"';  // Error message.
01070                 } else $dataStructArray='No proper configuration!';
01071 
01072                         // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
01073                 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
01074                         foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
01075                                 $hookObj = &t3lib_div::getUserObj($classRef);
01076                                 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
01077                                         $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
01078                                 }
01079                         }
01080                 }
01081 
01082                 return $dataStructArray;
01083         }
01084 
01085 
01086 
01087 
01088 
01089 
01090 
01091 
01092 
01093 
01094 
01095 
01096 
01097 
01098 
01099 
01100 
01101 
01102         /*******************************************
01103          *
01104          * Caching related
01105          *
01106          *******************************************/
01107 
01118         function storeHash($hash,$data,$ident)  {
01119                 $insertFields = array(
01120                         'hash' => $hash,
01121                         'content' => $data,
01122                         'ident' => $ident,
01123                         'tstamp' => time()
01124                 );
01125                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
01126                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
01127         }
01128 
01138         function getHash($hash,$expTime=0)      {
01139                         // if expTime is not set, the hash will never expire
01140                 $expTime = intval($expTime);
01141                 if ($expTime)   {
01142                         $whereAdd = ' AND tstamp > '.(time()-$expTime);
01143                 }
01144                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
01145                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
01146                         return $row['content'];
01147                 }
01148         }
01149 
01150 
01151 
01152 
01153 
01154 
01155 
01156 
01157         /*******************************************
01158          *
01159          * TypoScript related
01160          *
01161          *******************************************/
01162 
01174         function getPagesTSconfig($id,$rootLine='',$returnPartArray=0)  {
01175                 $id=intval($id);
01176                 if (!is_array($rootLine))       {
01177                         $rootLine = t3lib_BEfunc::BEgetRootLine($id,'',TRUE);
01178                 }
01179                 ksort($rootLine);       // Order correctly
01180                 $TSdataArray = array();
01181                 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];   // Setting default configuration:
01182                 foreach($rootLine as $k => $v)  {
01183                         $TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
01184                 }
01185                 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
01186                 if ($returnPartArray)   {
01187                         return $TSdataArray;
01188                 }
01189 
01190                         // Parsing the user TS (or getting from cache)
01191                 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
01192                 $hash = md5('pageTS:'.$userTS);
01193                 $cachedContent = t3lib_BEfunc::getHash($hash,0);
01194                 $TSconfig = array();
01195                 if (isset($cachedContent))      {
01196                         $TSconfig = unserialize($cachedContent);
01197                 } else {
01198                         $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
01199                         $parseObj->parse($userTS);
01200                         $TSconfig = $parseObj->setup;
01201                         t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
01202                 }
01203 
01204                         // get User TSconfig overlay
01205                 $userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
01206                 if (is_array($userTSconfig))    {
01207                         $TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
01208                 }
01209                 return $TSconfig;
01210         }
01211 
01230         function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='')   {
01231                 $id=intval($id);
01232                 if (is_array($pageTS) && $id>0) {
01233                         if (!is_array($impParams))      {
01234                                 $impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id));
01235                         }
01236                         reset($pageTS);
01237                         $set=array();
01238                         while(list($f,$v)=each($pageTS))        {
01239                                 $f = $TSconfPrefix.$f;
01240                                 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v)))        {
01241                                         $set[$f]=trim($v);
01242                                 }
01243                         }
01244                         if (count($set))        {
01245                                         // Get page record and TS config lines
01246                                 $pRec = t3lib_befunc::getRecord('pages',$id);
01247                                 $TSlines = explode(chr(10),$pRec['TSconfig']);
01248                                 $TSlines = array_reverse($TSlines);
01249                                         // Reset the set of changes.
01250                                 reset($set);
01251                                 while(list($f,$v)=each($set))   {
01252                                         reset($TSlines);
01253                                         $inserted=0;
01254                                         while(list($ki,$kv)=each($TSlines))     {
01255                                                 if (substr($kv,0,strlen($f)+1)==$f.'=') {
01256                                                         $TSlines[$ki]=$f.'='.$v;
01257                                                         $inserted=1;
01258                                                         break;
01259                                                 }
01260                                         }
01261                                         if (!$inserted) {
01262                                                 $TSlines = array_reverse($TSlines);
01263                                                 $TSlines[]=$f.'='.$v;
01264                                                 $TSlines = array_reverse($TSlines);
01265                                         }
01266                                 }
01267                                 $TSlines = array_reverse($TSlines);
01268 
01269                                         // store those changes
01270                                 $TSconf = implode(chr(10),$TSlines);
01271 
01272                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
01273                         }
01274                 }
01275         }
01276 
01285         function implodeTSParams($p,$k='')      {
01286                 $implodeParams=array();
01287                 if (is_array($p))       {
01288                         reset($p);
01289                         while(list($kb,$val)=each($p))  {
01290                                 if (is_array($val))     {
01291                                         $implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb));
01292                                 } else {
01293                                         $implodeParams[$k.$kb]=$val;
01294                                 }
01295                         }
01296                 }
01297                 return $implodeParams;
01298         }
01299 
01300 
01301 
01302 
01303 
01304 
01305 
01306 
01307         /*******************************************
01308          *
01309          * Users / Groups related
01310          *
01311          *******************************************/
01312 
01322         function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
01323                 $be_user_Array=Array();
01324 
01325                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username');
01326                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01327                         $be_user_Array[$row['uid']]=$row;
01328                 }
01329                 return $be_user_Array;
01330         }
01331 
01340         function getGroupNames($fields='title,uid', $where='')  {
01341                 $be_group_Array = Array();
01342                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
01343                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
01344                         $be_group_Array[$row['uid']] = $row;
01345                 }
01346                 return $be_group_Array;
01347         }
01348 
01357         function getListGroupNames($fields='title,uid') {
01358                 $exQ=' AND hide_in_lists=0';
01359                 if (!$GLOBALS['BE_USER']->isAdmin())    {
01360                         $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
01361                 }
01362                 return t3lib_BEfunc::getGroupNames($fields,$exQ);
01363         }
01364 
01376         function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0)   {
01377                 if (is_array($usernames) && is_array($groupArray))      {
01378                         while(list($uid,$row)=each($usernames)) {
01379                                 $userN=$uid;
01380                                 $set=0;
01381                                 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid'])      {
01382                                         reset($groupArray);
01383                                         while(list(,$v)=each($groupArray))      {
01384                                                 if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v))  {
01385                                                         $userN = $row['username'];
01386                                                         $set=1;
01387                                                 }
01388                                         }
01389                                 } else {
01390                                         $userN = $row['username'];
01391                                         $set=1;
01392                                 }
01393                                 $usernames[$uid]['username']=$userN;
01394                                 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
01395                         }
01396                 }
01397                 return $usernames;
01398         }
01399 
01409         function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0)     {
01410                 if (is_array($groups) && is_array($groupArray)) {
01411                         while(list($uid,$row)=each($groups))    {
01412                                 $groupN=$uid;
01413                                 $set=0;
01414                                 if (t3lib_div::inArray($groupArray,$uid))       {
01415                                         $groupN=$row['title'];
01416                                         $set=1;
01417                                 }
01418                                 $groups[$uid]['title']=$groupN;
01419                                 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
01420                         }
01421                 }
01422                 return $groups;
01423         }
01424 
01425 
01426 
01427 
01428 
01429 
01430 
01431 
01432 
01433 
01434 
01435 
01436 
01437         /*******************************************
01438          *
01439          * Output related
01440          *
01441          *******************************************/
01442 
01450         function daysUntil($tstamp)     {
01451                 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
01452                 return ceil($delta_t/(3600*24));
01453         }
01454 
01462         function date($tstamp)  {
01463                 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
01464         }
01465 
01473         function datetime($value)       {
01474                 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
01475         }
01476 
01485         function time($value)   {
01486                 $hh = floor($value/3600);
01487                 $min = floor(($value-$hh*3600)/60);
01488                 $sec = $value-$hh*3600-$min*60;
01489                 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
01490                 return $l;
01491         }
01492 
01501         function calcAge($seconds,$labels = 'min|hrs|days|yrs') {
01502                 $labelArr = explode('|',$labels);
01503                 $prefix='';
01504                 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
01505                 if ($seconds<3600)      {
01506                         $seconds = round ($seconds/60).' '.trim($labelArr[0]);
01507                 } elseif ($seconds<24*3600)     {
01508                         $seconds = round ($seconds/3600).' '.trim($labelArr[1]);
01509                 } elseif ($seconds<365*24*3600) {
01510                         $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
01511                 } else {
01512                         $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
01513                 }
01514                 return $prefix.$seconds;
01515         }
01516 
01527         function dateTimeAge($tstamp,$prefix=1,$date='')        {
01528                 return $tstamp ?
01529                                 ($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)).
01530                                 ' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
01531         }
01532 
01545         function titleAttrib($content='',$hsc=0)        {
01546                 global $CLIENT;
01547                 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
01548                 return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
01549         }
01550 
01558         function titleAltAttrib($content)       {
01559                 $out='';
01560                 $out.=' alt="'.htmlspecialchars($content).'"';
01561                 $out.=' title="'.htmlspecialchars($content).'"';
01562                 return $out;
01563         }
01564 
01582         function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='')    {
01583                 global $TCA;
01584                         // Load table.
01585                 t3lib_div::loadTCA($table);
01586 
01587                         // Find uploaddir automatically
01588                 $uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
01589                 $uploaddir = preg_replace('#/$#','',$uploaddir);
01590 
01591                         // Set thumbs-script:
01592                 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails'])  {
01593                         $thumbScript='gfx/notfound_thumb.gif';
01594                 } elseif(!$thumbScript) {
01595                         $thumbScript='thumbs.php';
01596                 }
01597                         // Check and parse the size parameter
01598                 $sizeParts=array();
01599                 if ($size = trim($size)) {
01600                         $sizeParts = explode('x', $size.'x'.$size);
01601                         if(!intval($sizeParts[0])) $size='';
01602                 }
01603 
01604                         // Traverse files:
01605                 $thumbs = explode(',', $row[$field]);
01606                 $thumbData='';
01607                 while(list(,$theFile)=each($thumbs))    {
01608                         if (trim($theFile))     {
01609                                 $fI = t3lib_div::split_fileref($theFile);
01610                                 $ext = $fI['fileext'];
01611                                                 // New 190201 start
01612                                 $max=0;
01613                                 if (t3lib_div::inList('gif,jpg,png',$ext)) {
01614                                         $imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile);
01615                                         if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);}
01616                                 }
01617                                         // use the original image if it's size fits to the thumbnail size
01618                                 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56))      {
01619                                         $theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01620                                         $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01621                                         $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
01622                                                 // New 190201 stop
01623                                 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
01624                                         $theFile_abs = PATH_site.($uploaddir?$uploaddir.'/':'').trim($theFile);
01625                                         $theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
01626 
01627                                         $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01628                                         $params = '&file='.rawurlencode($theFile);
01629                                         $params.= $size?'&size='.$size:'';
01630                                         $params.= '&md5sum='.t3lib_div::shortMD5($check);
01631 
01632                                         $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01633                                         $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
01634                                         $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
01635                                 } else {
01636                                         $icon = t3lib_BEfunc::getFileIcon($ext);
01637                                         $url = 'gfx/fileicons/'.$icon;
01638                                         $thumbData.= '<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
01639                                 }
01640                         }
01641                 }
01642                 return $thumbData;
01643         }
01644 
01655         function getThumbNail($thumbScript,$theFile,$tparams='',$size='')       {
01656                 $check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
01657                 $params = '&file='.rawurlencode($theFile);
01658                 $params.= trim($size)?'&size='.trim($size):'';
01659                 $params.= '&md5sum='.t3lib_div::shortMD5($check);
01660 
01661                 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
01662                 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
01663                 return $th;
01664         }
01665 
01675         function titleAttribForPages($row,$perms_clause='',$includeAttrib=1)    {
01676                 global $TCA,$LANG;
01677                 $parts=array();
01678                 $parts[] = 'id='.$row['uid'];
01679                 if ($row['alias'])      $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
01680                 if ($row['pid']<0)      $parts[] = 'v#1.'.$row['t3ver_id'];
01681                 if ($row['t3ver_state']==1)     $parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
01682                 if ($row['t3ver_state']==-1)    $parts[] = 'New element!';
01683 
01684                 if ($row['doktype']=='3')       {
01685                         $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
01686                 } elseif ($row['doktype']=='4') {
01687                         if ($perms_clause)      {
01688                                 $label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20);
01689                         } else {
01690                                 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['shortcut']),'title');
01691                                 $label = $lRec['title'];
01692                         }
01693                         if ($row['shortcut_mode']>0)    {
01694                                 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
01695                                                         $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
01696                         }
01697                         $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
01698                 } elseif ($row['doktype']=='7') {
01699                         if ($perms_clause)      {
01700                                 $label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
01701                         } else {
01702                                 $lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['mount_pid']),'title');
01703                                 $label = $lRec['title'];
01704                         }
01705                         $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
01706                         if ($row['mount_pid_ol'])       {
01707                                 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
01708                         }
01709                 }
01710                 if ($row['nav_hide'])   $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
01711                 if ($row['hidden'])     $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
01712                 if ($row['starttime'])  $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date');
01713                 if ($row['endtime'])    $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date');
01714                 if ($row['fe_group'])   {
01715                         $fe_groups = array();
01716                         foreach (t3lib_div::intExplode(',',$row['fe_group']) as $fe_group)      {
01717                                 if ($fe_group<0)        {
01718                                         $fe_groups[] = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$fe_group));
01719                                 } else {
01720                                         $lRec = t3lib_BEfunc::getRecordWSOL('fe_groups',$fe_group,'title');
01721                                         $fe_groups[] = $lRec['title'];
01722                                 }
01723                         }
01724                         $label = implode(', ',$fe_groups);
01725                         $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
01726                 }
01727                 $out = htmlspecialchars(implode(' - ',$parts));
01728                 return $includeAttrib ? 'title="'.$out.'"' : $out;
01729         }
01730 
01741         function getRecordIconAltText($row,$table='pages')      {
01742                 if ($table=='pages')    {
01743                         $out = t3lib_BEfunc::titleAttribForPages($row,'',0);
01744                 } else {
01745                         $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
01746 
01747                         $out='id='.$row['uid']; // Uid is added
01748                         if ($table=='pages' && $row['alias'])   {
01749                                 $out.=' / '.$row['alias'];
01750                         }
01751                         if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0)   {
01752                                 $out.=' - v#1.'.$row['t3ver_id'];
01753                         }
01754                         if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'])    {
01755                                 if ($row['t3ver_state']==1)     $out.= ' - PLH WSID#'.$row['t3ver_wsid'];
01756                                 if ($row['t3ver_state']==-1)    $out.= ' - New element!';
01757                         }
01758 
01759                         if ($ctrl['disabled'])  {               // Hidden ...
01760                                 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
01761                         }
01762                         if ($ctrl['starttime']) {
01763                                 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME'])   {
01764                                         $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').')';
01765                                 }
01766                         }
01767                         if ($row[$ctrl['endtime']])     {
01768                                 $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').')';
01769                         }
01770                 }
01771                 return htmlspecialchars($out);
01772         }
01773 
01783         function getLabelFromItemlist($table,$col,$key) {
01784                 global $TCA;
01785                         // Load full TCA for $table
01786                 t3lib_div::loadTCA($table);
01787 
01788                         // Check, if there is an "items" array:
01789                 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items']))    {
01790                                 // Traverse the items-array...
01791                         reset($TCA[$table]['columns'][$col]['config']['items']);
01792                         while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items']))       {
01793                                         // ... and return the first found label where the value was equal to $key
01794                                 if (!strcmp($v[1],$key))        return $v[0];
01795                         }
01796                 }
01797         }
01798 
01809         function getItemLabel($table,$col,$printAllWrap='')     {
01810                 global $TCA;
01811                         // Load full TCA for $table
01812                 t3lib_div::loadTCA($table);
01813                         // Check if column exists
01814                 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]))  {
01815                                 // Re
01816