Project

General

Profile

Bug #18482 » public-static-t3lib_befunc-rev2-1.patch

Administrator Admin, 2008-03-19 20:32

View differences:

t3lib/class.t3lib_befunc.php (working copy)
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_BEfunc {
final class t3lib_BEfunc {
......
* @param string Table alias if any
* @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0"
*/
function deleteClause($table,$tableAlias='') {
public static function deleteClause($table,$tableAlias = '') {
global $TCA;
if ($TCA[$table]['ctrl']['delete']) {
if ($TCA[$table]['ctrl']['delete']) {
return ' AND '.($tableAlias ? $tableAlias : $table).'.'.$TCA[$table]['ctrl']['delete'].'=0';
} else {
return '';
......
}
/**
* Gets record with uid=$uid from $table
* Gets record with uid = $uid from $table
* You can set $field to a list of fields (default is '*')
* Additional WHERE clauses can be added by $where (fx. ' AND blabla=1')
* Additional WHERE clauses can be added by $where (fx. ' AND blabla = 1')
* Will automatically check if records has been deleted and if so, not return anything.
* $table must be found in $TCA
* Usage: 99
......
* @param string Table name present in $TCA
* @param integer UID of record
* @param string List of fields to select
* @param string Additional WHERE clause, eg. " AND blablabla=0"
* @param string Additional WHERE clause, eg. " AND blablabla = 0"
* @param boolean Use the deleteClause to check if a record is deleted (default true)
* @return array Returns the row if found, otherwise nothing
*/
function getRecord($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
if ($GLOBALS['TCA'][$table]) {
public static function getRecord($table, $uid, $fields = '*', $where = '', $useDeleteClause = true) {
if ($GLOBALS['TCA'][$table]) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$fields,
$table,
......
* @param string Table name present in $TCA
* @param integer UID of record
* @param string List of fields to select
* @param string Additional WHERE clause, eg. " AND blablabla=0"
* @param string Additional WHERE clause, eg. " AND blablabla = 0"
* @param boolean Use the deleteClause to check if a record is deleted (default true)
* @return array Returns the row if found, otherwise nothing
*/
function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
public static function getRecordWSOL($table, $uid, $fields = '*', $where = '', $useDeleteClause = true) {
if ($fields !== '*') {
$internalFields = t3lib_div::uniqueList($fields.',uid,pid'.($table == 'pages' ? ',t3ver_swapmode' : ''));
$row = t3lib_BEfunc::getRecord($table,$uid,$internalFields,$where,$useDeleteClause);
t3lib_BEfunc::workspaceOL($table,$row);
$row = t3lib_BEfunc::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
t3lib_BEfunc::workspaceOL($table, $row);
if (is_array ($row)) {
foreach (array_keys($row) as $key) {
......
}
}
} else {
$row = t3lib_BEfunc::getRecord($table,$uid,$fields,$where);
t3lib_BEfunc::workspaceOL($table,$row);
$row = t3lib_BEfunc::getRecord($table, $uid, $fields, $where);
t3lib_BEfunc::workspaceOL($table, $row);
}
return $row;
}
......
* This function does NOT check if a record has the deleted flag set.
* $table does NOT need to be configured in $TCA
* The query used is simply this:
* $query='SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
* $query = 'SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
* Usage: 5 (ext: sys_todos)
*
* @param string Table name (not necessarily in TCA)
......
* @param string $fields is a list of fields to select, default is '*'
* @return array First row found, if any, FALSE otherwise
*/
function getRecordRaw($table,$where='',$fields='*') {
public static function getRecordRaw($table, $where = '', $fields = '*') {
$row = FALSE;
if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
$row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
$GLOBALS['TYPO3_DB']->sql_free_result($res);
}
......
* @param boolean Use the deleteClause to check if a record is deleted (default true)
* @return mixed Multidimensional array with selected records (if any is selected)
*/
function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true) {
public static function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = true) {
global $TCA;
if (is_array($TCA[$theTable])) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
......
$limit
);
$rows = array();
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$rows[] = $row;
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
......
* @return string WHERE clause for search
* @deprecated Use $GLOBALS['TYPO3_DB']->searchQuery() directly!
*/
function searchQuery($searchWords,$fields,$table='') {
return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
public static function searchQuery($searchWords, $fields, $table = '') {
return $GLOBALS['TYPO3_DB']->searchQuery($searchWords, $fields, $table);
}
/**
......
* @return string WHERE clause for a query
* @deprecated Use $GLOBALS['TYPO3_DB']->listQuery() directly!
*/
function listQuery($field,$value) {
return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
public static function listQuery($field, $value) {
return $GLOBALS['TYPO3_DB']->listQuery($field, $value, '');
}
/**
* Makes an backwards explode on the $str and returns an array with ($table,$uid).
* Example: tt_content_45 => array('tt_content',45)
* Makes an backwards explode on the $str and returns an array with ($table, $uid).
* Example: tt_content_45 => array('tt_content', 45)
* Usage: 1
*
* @param string [tablename]_[uid] string to explode
......
* @param string [tablename]_[uid] string to explode
* @return array
*/
function splitTable_Uid($str) {
list($uid,$table) = explode('_',strrev($str),2);
return array(strrev($table),strrev($uid));
public static function splitTable_Uid($str) {
list($uid, $table) = explode('_', strrev($str), 2);
return array(strrev($table), strrev($uid));
}
/**
......
* @param string $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
* @return string List of ids
*/
function getSQLselectableList($in_list,$tablename,$default_tablename) {
public static function getSQLselectableList($in_list, $tablename, $default_tablename) {
$list = Array();
if ((string)trim($in_list)!='') {
$tempItemArray = explode(',',trim($in_list));
while(list($key,$val)=each($tempItemArray)) {
if ((string)trim($in_list)!='') {
$tempItemArray = explode(',', trim($in_list));
while(list($key, $val) = each($tempItemArray)) {
$val = strrev($val);
$parts = explode('_',$val,2);
if ((string)trim($parts[0])!='') {
$parts = explode('_', $val, 2);
if ((string)trim($parts[0])!='') {
$theID = intval(strrev($parts[0]));
$theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
if ($theTable==$tablename) {$list[]=$theID;}
if ($theTable==$tablename) {$list[] = $theID;}
}
}
}
return implode(',',$list);
return implode(',', $list);
}
/**
......
* @param boolean $inv means that the query will select all records NOT VISIBLE records (inverted selection)
* @return string WHERE clause part
*/
function BEenableFields($table,$inv=0) {
public static function BEenableFields($table, $inv = 0) {
$ctrl = $GLOBALS['TCA'][$table]['ctrl'];
$query=array();
$invQuery=array();
if (is_array($ctrl)) {
if (is_array($ctrl['enablecolumns'])) {
if ($ctrl['enablecolumns']['disabled']) {
$query = array();
$invQuery = array();
if (is_array($ctrl)) {
if (is_array($ctrl['enablecolumns'])) {
if ($ctrl['enablecolumns']['disabled']) {
$field = $table.'.'.$ctrl['enablecolumns']['disabled'];
$query[]=$field.'=0';
$invQuery[]=$field.'!=0';
$query[] = $field.'=0';
$invQuery[] = $field.'!=0';
}
if ($ctrl['enablecolumns']['starttime']) {
if ($ctrl['enablecolumns']['starttime']) {
$field = $table.'.'.$ctrl['enablecolumns']['starttime'];
$query[]='('.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
$invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
$query[] = '('.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
$invQuery[] = '('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
}
if ($ctrl['enablecolumns']['endtime']) {
if ($ctrl['enablecolumns']['endtime']) {
$field = $table.'.'.$ctrl['enablecolumns']['endtime'];
$query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
$invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
$query[] = '('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_ACCESS_TIME'].')';
$invQuery[] = '('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_ACCESS_TIME'].')';
}
}
}
$outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
$outQ = ' AND '.($inv ? '('.implode(' OR ', $invQuery).')' : implode(' AND ', $query));
return $outQ;
}
......
* @param string $andWhereClause: Optional additional WHERE clause (default: '')
* @return mixed Multidimensional array with selected records; if none exist, false is returned
*/
public function getRecordLocalization($table, $uid, $language, $andWhereClause='') {
public function getRecordLocalization($table, $uid, $language, $andWhereClause = '') {
$recordLocalization = false;
if (isset($GLOBALS['TCA'][$table]['ctrl'])) {
$tcaCtrl =& $GLOBALS['TCA'][$table]['ctrl'];
......
* @deprecated
* @see t3lib_DB::exec_SELECT_mm_query()
*/
function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
public static function mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
$query = $GLOBALS['TYPO3_DB']->SELECTquery(
$select,
$local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
......
* @return string Full SQL query for INSERT
* @deprecated
*/
function DBcompileInsert($table,$fields_values) {
public static function DBcompileInsert($table, $fields_values) {
return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
}
......
* @return string Full SQL query for UPDATE
* @deprecated
*/
function DBcompileUpdate($table,$where,$fields_values) {
public static function DBcompileUpdate($table, $where, $fields_values) {
return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
}
......
* @param boolean If true, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
* @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
*/
function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE) {
if (is_array($GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0])) {
public static function BEgetRootLine($uid, $clause = '', $workspaceOL = FALSE) {
if (is_array($GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0])) {
return $GLOBALS['T3_VAR']['BEgetRootLine_cache'][$uid][$clause][$workspaceOL?1:0];
}
$pid = $uid;
$loopCheck = 100;
$theRowArray = Array();
$output = Array();
while ($uid!=0 && $loopCheck>0) {
while ($uid!=0 && $loopCheck>0) {
$loopCheck--;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
......
t3lib_BEfunc::deleteClause('pages').' '.
$clause // whereClauseMightContainGroupOrderBy
);
if ($GLOBALS['TYPO3_DB']->sql_error()) {
debug($GLOBALS['TYPO3_DB']->sql_error(),1);
if ($GLOBALS['TYPO3_DB']->sql_error()) {
debug($GLOBALS['TYPO3_DB']->sql_error(), 1);
}
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if($workspaceOL) t3lib_BEfunc::workspaceOL('pages',$row);
if (is_array($row)) {
t3lib_BEfunc::fixVersioningPid('pages',$row);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if($workspaceOL) t3lib_BEfunc::workspaceOL('pages', $row);
if (is_array($row)) {
t3lib_BEfunc::fixVersioningPid('pages', $row);
$uid = $row['pid'];
$theRowArray[] = $row;
} else break;
......
break;
}
}
if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');}
if (is_array($theRowArray)) {
if ($uid==0) {$theRowArray[] = Array('uid'=>0, 'title'=>'');}
if (is_array($theRowArray)) {
reset($theRowArray);
$c=count($theRowArray);
while(list($key,$val)=each($theRowArray)) {
$c = count($theRowArray);
while(list($key, $val) = each($theRowArray)) {
$c--;
$output[$c]['uid'] = $val['uid'];
$output[$c]['pid'] = $val['pid'];
......
* @param boolean If set, then other open branches are closed.
* @return void
*/
function openPageTree($pid,$clearExpansion) {
public static function openPageTree($pid, $clearExpansion) {
global $BE_USER;
// Get current expansion data:
if ($clearExpansion) {
if ($clearExpansion) {
$expandedPages = array();
} else {
$expandedPages = unserialize($BE_USER->uc['browseTrees']['browsePages']);
......
// First, find out what mount index to use (if more than one DB mount exists):
$mountIndex = 0;
$mountKeys = array_flip($BE_USER->returnWebmounts());
foreach($rL as $rLDat) {
if (isset($mountKeys[$rLDat['uid']])) {
foreach($rL as $rLDat) {
if (isset($mountKeys[$rLDat['uid']])) {
$mountIndex = $mountKeys[$rLDat['uid']];
break;
}
}
// Traverse rootline and open paths:
foreach($rL as $rLDat) {
foreach($rL as $rLDat) {
$expandedPages[$mountIndex][$rLDat['uid']] = 1;
}
......
* @param integer Title limit of Full title (typ. set to 1000 or so)
* @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
*/
function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) {
if (!$titleLimit) { $titleLimit=1000; }
public static function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0) {
if (!$titleLimit) { $titleLimit = 1000; }
$loopCheck = 100;
$output = $fullOutput = '/';
while ($uid!=0 && $loopCheck>0) {
while ($uid!=0 && $loopCheck>0) {
$loopCheck--;
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode',
......
t3lib_BEfunc::deleteClause('pages').
(strlen(trim($clause)) ? ' AND '.$clause : '')
);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
t3lib_BEfunc::workspaceOL('pages',$row);
if (is_array($row)) {
t3lib_BEfunc::fixVersioningPid('pages',$row);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
t3lib_BEfunc::workspaceOL('pages', $row);
if (is_array($row)) {
t3lib_BEfunc::fixVersioningPid('pages', $row);
if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0) { // Branch points
$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...
......
$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...
}
$uid = $row['pid'];
$output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output;
if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
$output = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $titleLimit).$output;
if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $fullTitleLimit).$fullOutput;
} else break;
} else {
break;
}
}
if ($fullTitleLimit) {
if ($fullTitleLimit) {
return array($output, $fullOutput);
} else {
return $output;
......
*
* @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries
*/
function getExcludeFields() {
public static function getExcludeFields() {
global $TCA;
// All TCA keys:
$theExcludeArray = Array();
......
// All TCA keys:
$theExcludeArray = Array();
$tc_keys = array_keys($TCA);
foreach($tc_keys as $table) {
foreach($tc_keys as $table) {
// Load table
t3lib_div::loadTCA($table);
// All field names configured:
if (is_array($TCA[$table]['columns'])) {
if (is_array($TCA[$table]['columns'])) {
$f_keys = array_keys($TCA[$table]['columns']);
foreach($f_keys as $field) {
if ($TCA[$table]['columns'][$field]['exclude']) {
foreach($f_keys as $field) {
if ($TCA[$table]['columns'][$field]['exclude']) {
// Get Human Readable names of fields and table:
$Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
$Fname = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
// add entry:
$theExcludeArray[] = Array($Fname , $table.':'.$field);
$theExcludeArray[] = Array($Fname, $table.':'.$field);
}
}
}
......
*
* @return array Array with information from all of $TCA
*/
function getExplicitAuthFieldValues() {
public static function getExplicitAuthFieldValues() {
global $TCA;
// Initialize:
......
t3lib_div::loadTCA($table);
// All field names configured:
if (is_array($TCA[$table]['columns'])) {
if (is_array($TCA[$table]['columns'])) {
$f_keys = array_keys($TCA[$table]['columns']);
foreach($f_keys as $field) {
foreach($f_keys as $field) {
$fCfg = $TCA[$table]['columns'][$field]['config'];
if ($fCfg['type']=='select' && $fCfg['authMode']) {
......
if ($fCfg['type']=='select' && $fCfg['authMode']) {
// Check for items:
if (is_array($fCfg['items'])) {
if (is_array($fCfg['items'])) {
// Get Human Readable names of fields and table:
$allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
......
$allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
// Check for items:
foreach($fCfg['items'] as $iVal) {
if (strcmp($iVal[1],'')) { // Values '' is not controlled by this setting.
foreach($fCfg['items'] as $iVal) {
if (strcmp($iVal[1], '')) { // Values '' is not controlled by this setting.
// Find iMode:
$iMode = '';
switch((string)$fCfg['authMode']) {
switch((string)$fCfg['authMode']) {
case 'explicitAllow':
$iMode = 'ALLOW';
break;
......
$iMode = 'DENY';
break;
case 'individual':
if (!strcmp($iVal[4],'EXPL_ALLOW')) {
if (!strcmp($iVal[4], 'EXPL_ALLOW')) {
$iMode = 'ALLOW';
} elseif (!strcmp($iVal[4],'EXPL_DENY')) {
} elseif (!strcmp($iVal[4], 'EXPL_DENY')) {
$iMode = 'DENY';
}
break;
}
// Set iMode:
if ($iMode) {
if ($iMode) {
$allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
}
}
......
*
* @return array Array with languages
*/
function getSystemLanguages() {
public static function getSystemLanguages() {
// Initialize, add default language:
$sysLanguages = array();
$sysLanguages[] = array('Default language', 0);
// Traverse languages
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc::deleteClause('sys_language'));
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag', 'sys_language', 'pid=0'.t3lib_BEfunc::deleteClause('sys_language'));
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
}
......
* @param string $perms_clause is typically a value generated with $BE_USER->getPagePermsClause(1);
* @return array Returns page record if OK, otherwise false.
*/
function readPageAccess($id,$perms_clause) {
if ((string)$id!='') {
public static function readPageAccess($id, $perms_clause) {
if ((string)$id!='') {
$id = intval($id);
if (!$id) {
if ($GLOBALS['BE_USER']->isAdmin()) {
if (!$id) {
if ($GLOBALS['BE_USER']->isAdmin()) {
$path = '/';
$pageinfo['_thePath'] = $path;
return $pageinfo;
......
return $pageinfo;
}
} else {
$pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : ''));
if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) {
$pageinfo = t3lib_BEfunc::getRecord('pages', $id, '*', ($perms_clause ? ' AND '.$perms_clause : ''));
if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id, $perms_clause)) {
t3lib_BEfunc::workspaceOL('pages', $pageinfo);
if (is_array($pageinfo)) {
if (is_array($pageinfo)) {
t3lib_BEfunc::fixVersioningPid('pages', $pageinfo);
list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
return $pageinfo;
}
}
......
* @param boolean If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
* @return array
*/
function getTCAtypes($table,$rec,$useFieldNameAsKey=0) {
public static function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
global $TCA;
t3lib_div::loadTCA($table);
if ($TCA[$table]) {
// Get type value:
$fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec);
$fieldValue = t3lib_BEfunc::getTCAtypeValue($table, $rec);
// Get typesConf
$typesConf = $TCA[$table]['types'][$fieldValue];
......
$altFieldList = array();
// Traverse fields in types config and parse the configuration into a nice array:
foreach($fieldList as $k => $v) {
foreach($fieldList as $k => $v) {
list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
$defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
$specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
......
$defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
$specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
$fieldList[$k]=array(
$fieldList[$k] = array(
'field' => $pFieldName,
'title' => $pAltTitle,
'palette' => $pPalette,
'spec' => $specConfParts,
'origString' => $v
);
if ($useFieldNameAsKey) {
if ($useFieldNameAsKey) {
$altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
}
}
if ($useFieldNameAsKey) {
if ($useFieldNameAsKey) {
$fieldList = $altFieldList;
}
......
* @return string Field value
* @see getTCAtypes()
*/
function getTCAtypeValue($table,$rec) {
public static function getTCAtypeValue($table, $rec) {
global $TCA;
// 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.
......
// 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.
t3lib_div::loadTCA($table);
if ($TCA[$table]) {
if ($TCA[$table]) {
$field = $TCA[$table]['ctrl']['type'];
$fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
......
* @param string The ['defaultExtras'] value from field configuration
* @return array
*/
function getSpecConfParts($str, $defaultExtras) {
public static function getSpecConfParts($str, $defaultExtras) {
// Add defaultExtras:
$specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
......
$specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
$reg = array();
if (count($specConfParts)) {
foreach($specConfParts as $k2 => $v2) {
if (count($specConfParts)) {
foreach($specConfParts as $k2 => $v2) {
unset($specConfParts[$k2]);
if (ereg('(.*)\[(.*)\]',$v2,$reg)) {
if (ereg('(.*)\[(.*)\]', $v2, $reg)) {
$specConfParts[trim($reg[1])] = array(
'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
);
......
}
/**
* Takes an array of "[key]=[value]" strings and returns an array with the keys set as keys pointing to the value.
* Takes an array of "[key] = [value]" strings and returns an array with the keys set as keys pointing to the value.
* Better see it in action! Find example in Inside TYPO3
* Usage: 6
*
* @param array Array of "[key]=[value]" strings to convert.
* @param array Array of "[key] = [value]" strings to convert.
* @return array
*/
function getSpecConfParametersFromArray($pArr) {
$out=array();
if (is_array($pArr)) {
public static function getSpecConfParametersFromArray($pArr) {
$out = array();
if (is_array($pArr)) {
reset($pArr);
while(list($k,$v)=each($pArr)) {
$parts=explode('=',$v,2);
if (count($parts)==2) {
$out[trim($parts[0])]=trim($parts[1]);
while(list($k, $v) = each($pArr)) {
$parts = explode('=', $v, 2);
if (count($parts)==2) {
$out[trim($parts[0])] = trim($parts[1]);
} else {
$out[$k]=$v;
$out[$k] = $v;
}
}
}
......
* @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
* @see t3lib_TCEforms::getSingleField_typeFlex()
*/
function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE,$newRecordPidValue=0) {
public static function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = TRUE, $newRecordPidValue = 0) {
global $TYPO3_CONF_VARS;
// Get pointer field etc from TCA-config:
......
$ds_searchParentField = $conf['ds_pointerField_searchParent'];
// Find source value:
$dataStructArray='';
$dataStructArray = '';
if (is_array($ds_array)) { // If there is a data source array, that takes precedence
// If a pointer field is set, take the value from that field in the $row array and use as key.
if ($ds_pointerField) {
......
}
$srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
} else $srcPointer='default';
} else $srcPointer = 'default';
// 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.
if (substr($ds_array[$srcPointer],0,5)=='FILE:') {
$file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5));
if ($file && @is_file($file)) {
if (substr($ds_array[$srcPointer], 0, 5)=='FILE:') {
$file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
if ($file && @is_file($file)) {
$dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
} else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
} else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer], 5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
} else {
$dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
}
......
$srcPointer = $row[$ds_pointerField];
// Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
if ($ds_searchParentField && !$srcPointer) {
$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###
if ($WSOL) {
t3lib_BEfunc::workspaceOL($table,$rr);
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!
if ($ds_searchParentField && !$srcPointer) {
$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###
if ($WSOL) {
t3lib_BEfunc::workspaceOL($table, $rr);
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!
}
$uidAcc=array(); // Used to avoid looping, if any should happen.
$uidAcc = array(); // Used to avoid looping, if any should happen.
$subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
while(!$srcPointer) {
......
// break if no result from SQL db or if looping...
if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break;
$uidAcc[$rr['uid']]=1;
$uidAcc[$rr['uid']] = 1;
if ($WSOL) {
t3lib_BEfunc::workspaceOL($table,$rr);
t3lib_BEfunc::fixVersioningPid($table,$rr,TRUE);
if ($WSOL) {
t3lib_BEfunc::workspaceOL($table, $rr);
t3lib_BEfunc::fixVersioningPid($table, $rr, TRUE);
}
$srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
}
}
// If there is a srcPointer value:
if ($srcPointer) {
if ($srcPointer) {
if (t3lib_div::testInt($srcPointer)) { // If integer, then its a record we will look up:
list($tName,$fName) = explode(':',$ds_tableField,2);
if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
list($tName, $fName) = explode(':', $ds_tableField, 2);
if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
$dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer);
if ($WSOL) {
t3lib_BEfunc::workspaceOL($tName,$dataStructRec);
if ($WSOL) {
t3lib_BEfunc::workspaceOL($tName, $dataStructRec);
}
$dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
} else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
......
} else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
} else { // Otherwise expect it to be a file:
$file = t3lib_div::getFileAbsFileName($srcPointer);
if ($file && @is_file($file)) {
if ($file && @is_file($file)) {
$dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
} else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
} else $dataStructArray = 'The file "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
}
} else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"'; // Error message.
} else $dataStructArray='No proper configuration!';
} else $dataStructArray = 'No source value in fieldname "'.$ds_pointerField.'"'; // Error message.
} else $dataStructArray = 'No proper configuration!';
// Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS'][' t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
......
* @param string $ident is just a textual identification in order to inform about the content! May be 20 characters long.
* @return void
*/
function storeHash($hash,$data,$ident) {
public static function storeHash($hash, $data, $ident) {
$insertFields = array(
'hash' => $hash,
'content' => $data,
......
* @param integer $expTime represents the expire time in seconds. For instance a value of 3600 would allow cached content within the last hour, otherwise nothing is returned.
* @return string
*/
function getHash($hash,$expTime=0) {
public static function getHash($hash, $expTime = 0) {
// if expTime is not set, the hash will never expire
$expTime = intval($expTime);
if ($expTime) {
......
* @return array Page TSconfig
* @see t3lib_TSparser
*/
function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) {
$id=intval($id);
if (!is_array($rootLine)) {
$rootLine = t3lib_BEfunc::BEgetRootLine($id,'',TRUE);
public static function getPagesTSconfig($id, $rootLine = '', $returnPartArray = 0) {
$id = intval($id);
if (!is_array($rootLine)) {
$rootLine = t3lib_BEfunc::BEgetRootLine($id, '', TRUE);
}
ksort($rootLine); // Order correctly
$TSdataArray = array();
$TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
foreach($rootLine as $k => $v) {
$TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
$TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
foreach($rootLine as $k => $v) {
$TSdataArray['uid_'.$v['uid']] = $v['TSconfig'];
}
$TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
if ($returnPartArray) {
if ($returnPartArray) {
return $TSdataArray;
}
......
}
// Parsing the user TS (or getting from cache)
$userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
$userTS = implode($TSdataArray, chr(10).'[GLOBAL]'.chr(10));
$hash = md5('pageTS:'.$userTS);
$cachedContent = t3lib_BEfunc::getHash($hash,0);
$cachedContent = t3lib_BEfunc::getHash($hash, 0);
$TSconfig = array();
if (isset($cachedContent)) {
if (isset($cachedContent)) {
$TSconfig = unserialize($cachedContent);
} else {
$parseObj = t3lib_div::makeInstance('t3lib_TSparser');
......
$parseObj = t3lib_div::makeInstance('t3lib_TSparser');
$parseObj->parse($userTS);
$TSconfig = $parseObj->setup;
t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
t3lib_BEfunc::storeHash($hash, serialize($TSconfig), 'PAGES_TSconfig');
}
// get User TSconfig overlay
......
// get User TSconfig overlay
$userTSconfig = $GLOBALS['BE_USER']->userTS['page.'];
if (is_array($userTSconfig)) {
if (is_array($userTSconfig)) {
$TSconfig = t3lib_div::array_merge_recursive_overrule($TSconfig, $userTSconfig);
}
return $TSconfig;
......
* @internal
* @see implodeTSParams(), getPagesTSconfig()
*/
function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') {
$id=intval($id);
if (is_array($pageTS) && $id>0) {
if (!is_array($impParams)) {
public static function updatePagesTSconfig($id, $pageTS, $TSconfPrefix, $impParams = '') {
$id = intval($id);
if (is_array($pageTS) && $id>0) {
if (!is_array($impParams)) {
$impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id));
}
reset($pageTS);
$set=array();
while(list($f,$v)=each($pageTS)) {
$set = array();
while(list($f, $v) = each($pageTS)) {
$f = $TSconfPrefix.$f;
if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v))) {
$set[$f]=trim($v);
if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]), trim($v))) {
$set[$f] = trim($v);
}
}
if (count($set)) {
if (count($set)) {
// Get page record and TS config lines
$pRec = t3lib_befunc::getRecord('pages',$id);
$TSlines = explode(chr(10),$pRec['TSconfig']);
$pRec = t3lib_befunc::getRecord('pages', $id);
$TSlines = explode(chr(10), $pRec['TSconfig']);
$TSlines = array_reverse($TSlines);
// Reset the set of changes.
reset($set);
while(list($f,$v)=each($set)) {
while(list($f, $v) = each($set)) {
reset($TSlines);
$inserted=0;
while(list($ki,$kv)=each($TSlines)) {
if (substr($kv,0,strlen($f)+1)==$f.'=') {
$TSlines[$ki]=$f.'='.$v;
$inserted=1;
$inserted = 0;
while(list($ki, $kv) = each($TSlines)) {
if (substr($kv, 0, strlen($f)+1)==$f.'=') {
$TSlines[$ki] = $f.'='.$v;
$inserted = 1;
break;
}
}
if (!$inserted) {
if (!$inserted) {
$TSlines = array_reverse($TSlines);
$TSlines[]=$f.'='.$v;
$TSlines[] = $f.'='.$v;
$TSlines = array_reverse($TSlines);
}
}
$TSlines = array_reverse($TSlines);
// store those changes
$TSconf = implode(chr(10),$TSlines);
$TSconf = implode(chr(10), $TSlines);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
}
......
* @param string Prefix string
* @return array Imploded TypoScript objectstring/values
*/
function implodeTSParams($p,$k='') {
$implodeParams=array();
if (is_array($p)) {
public static function implodeTSParams($p, $k = '') {
$implodeParams = array();
if (is_array($p)) {
reset($p);
while(list($kb,$val)=each($p)) {
if (is_array($val)) {
$implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb));
while(list($kb, $val) = each($p)) {
if (is_array($val)) {
$implodeParams = array_merge($implodeParams, t3lib_BEfunc::implodeTSParams($val, $k.$kb));
} else {
$implodeParams[$k.$kb]=$val;
$implodeParams[$k.$kb] = $val;
}
}
}
......
* @param string Optional $where clause (fx. "AND username='pete'") can be used to limit query
* @return array
*/
function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
$be_user_Array=Array();
public static function getUserNames($fields = 'username,usergroup,usergroup_cached_list,uid', $where = '') {
$be_user_Array = Array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username');
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$be_user_Array[$row['uid']]=$row;
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$be_user_Array[$row['uid']] = $row;
}
return $be_user_Array;
}
......
* @param string WHERE clause
* @return array
*/
function getGroupNames($fields='title,uid', $where='') {
public static function getGroupNames($fields = 'title,uid', $where = '') {
$be_group_Array = Array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$be_group_Array[$row['uid']] = $row;
}
return $be_group_Array;
......
* @param string Field list; $fields specify the fields selected (default: title,uid)
* @return array
*/
function getListGroupNames($fields='title,uid') {
$exQ=' AND hide_in_lists=0';
if (!$GLOBALS['BE_USER']->isAdmin()) {
public static function getListGroupNames($fields = 'title, uid') {
$exQ = ' AND hide_in_lists=0';
if (!$GLOBALS['BE_USER']->isAdmin()) {
$exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
}
return t3lib_BEfunc::getGroupNames($fields,$exQ);
return t3lib_BEfunc::getGroupNames($fields, $exQ);
}
/**
......
* @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
* @return array User names, blinded
*/
function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) {
if (is_array($usernames) && is_array($groupArray)) {
while(list($uid,$row)=each($usernames)) {
$userN=$uid;
$set=0;
if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
public static function blindUserNames($usernames, $groupArray, $excludeBlindedFlag = 0) {
if (is_array($usernames) && is_array($groupArray)) {
while(list($uid, $row) = each($usernames)) {
$userN = $uid;
$set = 0;
if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
reset($groupArray);
while(list(,$v)=each($groupArray)) {
if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v)) {
while(list(,$v) = each($groupArray)) {
if ($v && t3lib_div::inList($row['usergroup_cached_list'], $v)) {
$userN = $row['username'];
$set=1;
$set = 1;
}
}
} else {
......
}
} else {
$userN = $row['username'];
$set=1;
$set = 1;
}
$usernames[$uid]['username']=$userN;
$usernames[$uid]['username'] = $userN;
if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
}
}
......
* @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
* @return array
*/
function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) {
if (is_array($groups) && is_array($groupArray)) {
while(list($uid,$row)=each($groups)) {
$groupN=$uid;
$set=0;
if (t3lib_div::inArray($groupArray,$uid)) {
$groupN=$row['title'];
$set=1;
public static function blindGroupNames($groups, $groupArray, $excludeBlindedFlag = 0) {
if (is_array($groups) && is_array($groupArray)) {
while(list($uid, $row) = each($groups)) {
$groupN = $uid;
$set = 0;
if (t3lib_div::inArray($groupArray, $uid)) {
$groupN = $row['title'];
$set = 1;
}
$groups[$uid]['title']=$groupN;
$groups[$uid]['title'] = $groupN;
if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
}
}
......
* @param integer Time stamp, seconds
* @return integer
*/
function daysUntil($tstamp) {
public static function daysUntil($tstamp) {
$delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
return ceil($delta_t/(3600*24));
}
......
* @param integer Time stamp, seconds
* @return string Formatted time
*/
function date($tstamp) {
return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
public static function date($tstamp) {
return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $tstamp);
}
/**
......
* @param integer Time stamp, seconds
* @return string Formatted time
*/
function datetime($value) {
public static function datetime($value) {
return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
}
......
* @param boolean Output hh:mm:ss. If false: hh:mm
* @return string Formatted time
*/
function time($value, $withSeconds = TRUE) {
public static function time($value, $withSeconds = TRUE) {
$hh = floor($value/3600);
$min = floor(($value-$hh*3600)/60);
$sec = $value-$hh*3600-$min*60;
$l = sprintf('%02d',$hh).':'.sprintf('%02d',$min);
if ($withSeconds) {
$l .= ':'.sprintf('%02d',$sec);
$l = sprintf('%02d', $hh).':'.sprintf('%02d', $min);
if ($withSeconds) {
$l .= ':'.sprintf('%02d', $sec);
}
return $l;
}
......
* @param string $labels should be something like ' min| hrs| days| yrs'. This value is typically delivered by this function call: $GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears")
* @return string Formatted time
*/
function calcAge($seconds,$labels = 'min|hrs|days|yrs') {
$labelArr = explode('|',$labels);
$prefix='';
if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
if ($seconds<3600) {
public static function calcAge($seconds, $labels = 'min|hrs|days|yrs') {
$labelArr = explode('|', $labels);
$prefix = '';
if ($seconds<0) {$prefix = '-'; $seconds = abs($seconds);}
if ($seconds<3600) {
$seconds = round ($seconds/60).' '.trim($labelArr[0]);
} elseif ($seconds<24*3600) {
} elseif ($seconds<24*3600) {
$seconds = round ($seconds/3600).' '.trim($labelArr[1]);
} elseif ($seconds<365*24*3600) {
} elseif ($seconds<365*24*3600) {
$seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
} else {
$seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
......
* @param string $date=="date" will yield "dd:mm:yy" formatting, otherwise "dd:mm:yy hh:mm"
* @return string
*/
function dateTimeAge($tstamp,$prefix=1,$date='') {
public static function dateTimeAge($tstamp, $prefix = 1, $date = '') {
return $tstamp ?
($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)).
' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
}
/**
* Returns either title='' or alt='' attribute. This depends on the client browser and whether it supports title='' or not (which is the default)
* Returns either title = '' or alt = '' attribute. This depends on the client browser and whether it supports title = '' or not (which is the default)
* If no $content is given only the attribute name is returned.
* The returned attribute with content will have a leading space char.
* Warning: Be careful to submit empty $content var - that will return just the attribute name!
......
* @return string
* @deprecated The idea made sense with older browsers, but now all browsers should support the "title" attribute - so just hardcode the title attribute instead!
*/
function titleAttrib($content='',$hsc=0) {
public static function titleAttrib($content = '', $hsc = 0) {
global $CLIENT;
$attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
return strcmp($content, '')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
}
/**
......
* @param string Value for 'alt' and 'title' attributes (will be htmlspecialchars()'ed before output)
* @return string
*/
function titleAltAttrib($content) {
$out='';
public static function titleAltAttrib($content) {
$out = '';
$out.=' alt="'.htmlspecialchars($content).'"';
$out.=' title="'.htmlspecialchars($content).'"';
return $out;
......
* @param integer Optional: $size is [w]x[h] of the thumbnail. 56 is default.
* @return string Thumbnail image tag.
*/
function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='') {
public static function thumbCode($row, $table, $field, $backPath, $thumbScript = '', $uploaddir = NULL, $abs = 0, $tparams = '', $size = '') {
global $TCA;
// Load table.
t3lib_div::loadTCA($table);
// Find uploaddir automatically
$uploaddir = (is_null($uploaddir)) ? $TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
$uploaddir = preg_replace('#/$#','',$uploaddir);
$uploaddir = preg_replace('#/$#','', $uploaddir);
// Set thumbs-script:
if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
$thumbScript='gfx/notfound_thumb.gif';
} elseif(!$thumbScript) {
$thumbScript='thumbs.php';
if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
$thumbScript = 'gfx/notfound_thumb.gif';
} elseif(!$thumbScript) {
$thumbScript = 'thumbs.php';
}
// Check and parse the size parameter
$sizeParts=array();
$sizeParts = array();
if ($size = trim($size)) {
$sizeParts = explode('x', $size.'x'.$size);
if(!intval($sizeParts[0])) $size='';
if(!intval($sizeParts[0])) $size = '';
}
// Traverse files:
......
// Traverse files:
$thumbs = explode(',', $row[$field]);
$thumbData='';
while(list(,$theFile)=each($thumbs)) {
if (trim($theFile)) {
$thumbData = '';
while(list(,$theFile) = each($thumbs)) {
if (trim($theFile)) {
$fI = t3lib_div::split_fileref($theFile);
$ext = $fI['fileext'];
// New 190201 start
$max=0;
if (t3lib_div::inList('gif,jpg,png',$ext)) {
$imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile);
if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);}
$max = 0;
if (t3lib_div::inList('gif,jpg,png', $ext)) {
$imgInfo = @getimagesize(PATH_site.$uploaddir.'/'.$theFile);
if (is_array($imgInfo)) {$max = max($imgInfo[0], $imgInfo[1]);}
}
// use the original image if it's size fits to the thumbnail size
if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
$theFile = $url = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
$onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
$thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
......
$onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
$thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
// New 190201 stop
} elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
} elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $ext)) {
$theFile_abs = PATH_site.($uploaddir?$uploaddir.'/':'').trim($theFile);
$theFile = ($abs?'':'../').($uploaddir?$uploaddir.'/':'').trim($theFile);
......
* @param integer $size is the size of the thumbnail send along to "thumbs.php"
* @return string Image tag
*/
function getThumbNail($thumbScript,$theFile,$tparams='',$size='') {
public static function getThumbNail($thumbScript, $theFile, $tparams = '', $size = '') {
$check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
$params = '&file='.rawurlencode($theFile);
$params.= trim($size)?'&size='.trim($size):'';
$params.= '&md5sum='.t3lib_div::shortMD5($check);
$url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
$th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
$th = '<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
return $th;
}
......
* @param boolean If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
* @return string
*/
function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) {
global $TCA,$LANG;
$parts=array();
public static function titleAttribForPages($row, $perms_clause = '', $includeAttrib = 1) {
global $TCA, $LANG;
$parts = array();
$parts[] = 'id='.$row['uid'];
if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
if ($row['alias']) $parts[] = $LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id'];
switch($row['t3ver_state']) {
switch($row['t3ver_state']) {
case 1:
$parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
break;
......
break;
}
if ($row['doktype']=='3') {
$parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
} elseif ($row['doktype']=='4') {
if ($perms_clause) {
$label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20);
if ($row['doktype']=='3') {
$parts[] = $LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
} elseif ($row['doktype']=='4') {
if ($perms_clause) {
$label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']), $perms_clause, 20);
} else {
$lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['shortcut']),'title');
$lRec = t3lib_BEfunc::getRecordWSOL('pages', intval($row['shortcut']), 'title');
$label = $lRec['title'];
}
if ($row['shortcut_mode']>0) {
if ($row['shortcut_mode']>0) {
$label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
$LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
$LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages', 'shortcut_mode', $row['shortcut_mode']));
}
$parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
} elseif ($row['doktype']=='7') {
if ($perms_clause) {
$label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
$parts[] = $LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
} elseif ($row['doktype']=='7') {
if ($perms_clause) {
$label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']), $perms_clause, 20);
} else {
$lRec = t3lib_BEfunc::getRecordWSOL('pages',intval($row['mount_pid']),'title');
$lRec = t3lib_BEfunc::getRecordWSOL('pages', intval($row['mount_pid']), 'title');
$label = $lRec['title'];
}
$parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
if ($row['mount_pid_ol']) {
$parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
if ($row['mount_pid_ol']) {
$parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
}
}
if ($row['nav_hide']) $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
if ($row['nav_hide']) $parts[] = ereg_replace(':$', '', $LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date');
if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date');
if ($row['fe_group']) {
if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'], -1, 'date');
if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'], -1, 'date');
if ($row['fe_group']) {
$fe_groups = array();
foreach (t3lib_div::intExplode(',',$row['fe_group']) as $fe_group) {
if ($fe_group<0) {
$fe_groups[] = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$fe_group));
foreach (t3lib_div::intExplode(',', $row['fe_group']) as $fe_group) {
if ($fe_group<0) {
$fe_groups[] = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages', 'fe_group', $fe_group));
} else {
$lRec = t3lib_BEfunc::getRecordWSOL('fe_groups',$fe_group,'title');
$lRec = t3lib_BEfunc::getRecordWSOL('fe_groups', $fe_group, 'title');
$fe_groups[] = $lRec['title'];
}
}
$label = implode(', ',$fe_groups);
$label = implode(', ', $fe_groups);
$parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
}
$out = htmlspecialchars(implode(' - ',$parts));
$out = htmlspecialchars(implode(' - ', $parts));
return $includeAttrib ? 'title="'.$out.'"' : $out;
}
......
* @param string Table name
* @return string
*/
function getRecordIconAltText($row,$table='pages') {
if ($table=='pages') {
$out = t3lib_BEfunc::titleAttribForPages($row,'',0);
public static function getRecordIconAltText($row, $table = 'pages') {
if ($table=='pages') {
$out = t3lib_BEfunc::titleAttribForPages($row, '', 0);
} else {
$ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
$out='id='.$row['uid']; // Uid is added
if ($table=='pages' && $row['alias']) {
$out = 'id='.$row['uid']; // Uid is added
if ($table=='pages' && $row['alias']) {
$out.=' / '.$row['alias'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
$out.=' - v#1.'.$row['t3ver_id'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
switch($row['t3ver_state']) {
if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
switch($row['t3ver_state']) {
case 1:
$out.= ' - PLH WSID#'.$row['t3ver_wsid'];
break;
......
if ($ctrl['disabled']) { // Hidden ...
$out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
}
if ($ctrl['starttime']) {
if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
if ($ctrl['starttime']) {
if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
$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').')';
}
}
if ($row[$ctrl['endtime']]) {
if ($row[$ctrl['endtime']]) {
$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').')';
}
}
......
}
/**
* Returns the label of the first found entry in an "items" array from $TCA (tablename=$table/fieldname=$col) where the value is $key
* Returns the label of the first found entry in an "items" array from $TCA (tablename = $table/fieldname = $col) where the value is $key
* Usage: 9
*
* @param string Table name, present in $TCA
......
* @param string items-array value to match
* @return string Label for item entry
*/
function getLabelFromItemlist($table,$col,$key) {
public static function getLabelFromItemlist($table, $col, $key) {
global $TCA;
// Load full TCA for $table
t3lib_div::loadTCA($table);
......
t3lib_div::loadTCA($table);
// Check, if there is an "items" array:
if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
// Traverse the items-array...
reset($TCA[$table]['columns'][$col]['config']['items']);
while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items'])) {
while(list($k, $v) = each($TCA[$table]['columns'][$col]['config']['items'])) {
// ... and return the first found label where the value was equal to $key
if (!strcmp($v[1],$key)) return $v[0];
if (!strcmp($v[1], $key)) return $v[0];
}
}
}
/**
* Returns the label-value for fieldname $col in table, $table
* If $printAllWrap is set (to a "wrap") then it's wrapped around the $col value IF THE COLUMN $col DID NOT EXIST in TCA!, eg. $printAllWrap='<b>|</b>' and the fieldname was 'not_found_field' then the return value would be '<b>not_found_field</b>'
* If $printAllWrap is set (to a "wrap") then it's wrapped around the $col value IF THE COLUMN $col DID NOT EXIST in TCA!, eg. $printAllWrap = '<b>|</b>' and the fieldname was 'not_found_field' then the return value would be '<b>not_found_field</b>'
* Usage: 17
*
* @param string Table name, present in $TCA
......
* @param string Wrap value - set function description
* @return string
*/
function getItemLabel($table,$col,$printAllWrap='') {
public static function getItemLabel($table, $col, $printAllWrap = '') {
global $TCA;
// Load full TCA for $table
t3lib_div::loadTCA($table);
......
// Load full TCA for $table
t3lib_div::loadTCA($table);
// Check if column exists
if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
// Re
return $TCA[$table]['columns'][$col]['label'];
}
if ($printAllWrap) {
$parts = explode('|',$printAllWrap);
if ($printAllWrap) {
$parts = explode('|', $printAllWrap);
return $parts[0].$col.$parts[1];
... This diff was truncated because it exceeds the maximum size that can be displayed.
(3-3/3)