Documentation TYPO3 par Ameos

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                         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);