2 /***************************************************************
5 * (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Standard functions available for the TYPO3 backend.
29 * You are encouraged to use this class in your own applications (Backend Modules)
31 * Call ALL methods without making an object!
32 * Eg. to get a page-record 51 do this: 't3lib_BEfunc::getRecord('pages',51)'
35 * Usage counts are based on search 22/2 2003 through whole backend source of typo3/
36 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
39 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
42 * [CLASS/FUNCTION INDEX of SCRIPT]
46 * 185: class t3lib_BEfunc
48 * SECTION: SQL-related, selecting records, searching
49 * 206: function deleteClause($table,$tableAlias='')
50 * 230: function getRecord($table,$uid,$fields='*',$where='',$useDeleteClause=true)
51 * 253: function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true)
52 * 286: function getRecordRaw($table,$where='',$fields='*')
53 * 309: function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true)
54 * 342: function searchQuery($searchWords,$fields,$table='')
55 * 357: function listQuery($field,$value)
56 * 369: function splitTable_Uid($str)
57 * 384: function getSQLselectableList($in_list,$tablename,$default_tablename)
58 * 412: function BEenableFields($table,$inv=0)
60 * SECTION: SQL-related, DEPRECATED functions
61 * 476: function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')
62 * 498: function DBcompileInsert($table,$fields_values)
63 * 512: function DBcompileUpdate($table,$where,$fields_values)
65 * SECTION: Page tree, TCA related
66 * 542: function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE)
67 * 598: function openPageTree($pid,$clearExpansion)
68 * 643: function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
69 * 686: function getExcludeFields()
70 * 716: function getExplicitAuthFieldValues()
71 * 787: function getSystemLanguages()
72 * 812: function readPageAccess($id,$perms_clause)
73 * 843: function getTCAtypes($table,$rec,$useFieldNameAsKey=0)
74 * 896: function getTCAtypeValue($table,$rec)
75 * 919: function getSpecConfParts($str, $defaultExtras)
76 * 950: function getSpecConfParametersFromArray($pArr)
77 * 978: function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE)
79 * SECTION: Caching related
80 * 1105: function storeHash($hash,$data,$ident)
81 * 1125: function getHash($hash,$expTime=0)
83 * SECTION: TypoScript related
84 * 1161: function getPagesTSconfig($id,$rootLine='',$returnPartArray=0)
85 * 1217: function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='')
86 * 1272: function implodeTSParams($p,$k='')
88 * SECTION: Users / Groups related
89 * 1309: function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='')
90 * 1327: function getGroupNames($fields='title,uid', $where='')
91 * 1344: function getListGroupNames($fields='title,uid')
92 * 1363: function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0)
93 * 1396: function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0)
95 * SECTION: Output related
96 * 1437: function daysUntil($tstamp)
97 * 1449: function date($tstamp)
98 * 1460: function datetime($value)
99 * 1472: function time($value)
100 * 1488: function calcAge($seconds,$labels = 'min|hrs|days|yrs')
101 * 1514: function dateTimeAge($tstamp,$prefix=1,$date='')
102 * 1532: function titleAttrib($content='',$hsc=0)
103 * 1545: function titleAltAttrib($content)
104 * 1569: function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='')
105 * 1637: function getThumbNail($thumbScript,$theFile,$tparams='',$size='')
106 * 1654: function titleAttribForPages($row,$perms_clause='',$includeAttrib=1)
107 * 1716: function getRecordIconAltText($row,$table='pages')
108 * 1758: function getLabelFromItemlist($table,$col,$key)
109 * 1784: function getItemLabel($table,$col,$printAllWrap='')
110 * 1809: function getRecordTitle($table,$row,$prep=0)
111 * 1847: function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0,$noRecordLookup=FALSE,$uid=0)
112 * 2009: function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0,$uid=0)
113 * 2033: function getFileIcon($ext)
114 * 2047: function getCommonSelectFields($table,$prefix='')
115 * 2090: function makeConfigForm($configArray,$defaults,$dataPrefix)
117 * SECTION: Backend Modules API functions
118 * 2165: function helpTextIcon($table,$field,$BACK_PATH,$force=0)
119 * 2187: function helpText($table,$field,$BACK_PATH,$styleAttrib='')
120 * 2239: function cshItem($table,$field,$BACK_PATH,$wrap='',$onlyIconMode=FALSE, $styleAttrib='')
121 * 2277: function editOnClick($params,$backPath='',$requestUri='')
122 * 2296: function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='',$addGetVars='',$switchFocus=TRUE)
123 * 2328: function getModTSconfig($id,$TSref)
124 * 2349: function getFuncMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='')
125 * 2392: function getFuncCheck($mainParams,$elementName,$currentValue,$script='',$addparams='',$tagParams='')
126 * 2417: function getFuncInput($mainParams,$elementName,$currentValue,$size=10,$script="",$addparams="")
127 * 2438: function unsetMenuItems($modTSconfig,$itemArray,$TSref)
128 * 2461: function getSetUpdateSignal($set='')
129 * 2512: function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
132 * 2585: function compilePreviewKeyword($getVarsStr, $beUserUid, $ttl=172800)
133 * 2613: function lockRecords($table='',$uid=0,$pid=0)
134 * 2642: function isRecordLocked($table,$uid)
135 * 2682: function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='')
136 * 2763: function getTCEFORM_TSconfig($table,$row)
137 * 2814: function getTSconfig_pidValue($table,$uid,$pid)
138 * 2844: function getPidForModTSconfig($table,$uid,$pid)
139 * 2860: function getTSCpid($table,$uid,$pid)
140 * 2876: function firstDomainRecord($rootLine)
141 * 2898: function getDomainStartPage($domain, $path='')
142 * 2928: function RTEsetup($RTEprop,$table,$field,$type='')
143 * 2947: function &RTEgetObj()
144 * 2986: function &softRefParserObj($spKey)
145 * 3018: function explodeSoftRefParserList($parserList)
146 * 3050: function isModuleSetInTBE_MODULES($modName)
147 * 3073: function referenceCount($table,$ref,$msg='')
149 * SECTION: Workspaces / Versioning
150 * 3132: function selectVersionsOfRecord($table, $uid, $fields='*', $workspace=0)
151 * 3180: function fixVersioningPid($table,&$rr,$ignoreWorkspaceMatch=FALSE)
152 * 3220: function workspaceOL($table,&$row,$wsid=-99)
153 * 3268: function getWorkspaceVersionOfRecord($workspace, $table, $uid, $fields='*')
154 * 3297: function getLiveVersionOfRecord($table,$uid,$fields='*')
155 * 3319: function isPidInVersionizedBranch($pid, $table='',$returnStage=FALSE)
156 * 3342: function versioningPlaceholderClause($table)
157 * 3356: function countVersionsOfRecordsOnPage($workspace,$pageId, $allTables=FALSE)
158 * 3391: function wsMapId($table,$uid)
160 * SECTION: Miscellaneous
161 * 3421: function typo3PrintError($header,$text,$js='',$head=1)
162 * 3465: function TYPO3_copyRightNotice()
163 * 3489: function displayWarningMessages()
164 * 3546: function getPathType_web_nonweb($path)
165 * 3558: function ADMCMD_previewCmds($pageinfo)
166 * 3580: function processParams($params)
167 * 3606: function getListOfBackendModules($name,$perms_clause,$backPath='',$script='index.php')
169 * TOTAL FUNCTIONS: 99
170 * (This index is automatically created/updated by the extension "extdeveval")
174 require_once (PATH_t3lib
.'class.t3lib_loaddbgroup.php');
178 * Standard functions available for the TYPO3 backend.
179 * Don't instantiate - call functions with "t3lib_BEfunc::" prefixed the function name.
181 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
189 /*******************************************
191 * SQL-related, selecting records, searching
193 *******************************************/
197 * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field is configured in $TCA for the tablename, $table
198 * This function should ALWAYS be called in the backend for selection on tables which are configured in TCA since it will ensure consistent selection of records, even if they are marked deleted (in which case the system must always treat them as non-existent!)
199 * In the frontend a function, ->enableFields(), is known to filter hidden-field, start- and endtime and fe_groups as well. But that is a job of the frontend, not the backend. If you need filtering on those fields as well in the backend you can use ->BEenableFields() though.
202 * @param string Table name present in $TCA
203 * @param string Table alias if any
204 * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0"
206 function deleteClause($table,$tableAlias='') {
208 if ($TCA[$table]['ctrl']['delete']) {
209 return ' AND '.($tableAlias ?
$tableAlias : $table).'.'.$TCA[$table]['ctrl']['delete'].'=0';
216 * Gets record with uid=$uid from $table
217 * You can set $field to a list of fields (default is '*')
218 * Additional WHERE clauses can be added by $where (fx. ' AND blabla=1')
219 * Will automatically check if records has been deleted and if so, not return anything.
220 * $table must be found in $TCA
223 * @param string Table name present in $TCA
224 * @param integer UID of record
225 * @param string List of fields to select
226 * @param string Additional WHERE clause, eg. " AND blablabla=0"
227 * @param boolean Use the deleteClause to check if a record is deleted (default true)
228 * @return array Returns the row if found, otherwise nothing
230 function getRecord($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
231 if ($GLOBALS['TCA'][$table]) {
232 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
235 'uid='.intval($uid).($useDeleteClause ? t3lib_BEfunc
::deleteClause($table) : '').$where
237 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
244 * Like getRecord(), but overlays workspace version if any.
246 * @param string Table name present in $TCA
247 * @param integer UID of record
248 * @param string List of fields to select
249 * @param string Additional WHERE clause, eg. " AND blablabla=0"
250 * @param boolean Use the deleteClause to check if a record is deleted (default true)
251 * @return array Returns the row if found, otherwise nothing
253 function getRecordWSOL($table,$uid,$fields='*',$where='',$useDeleteClause=true) {
254 if ($fields !== '*') {
255 $internalFields = t3lib_div
::uniqueList($fields.',uid,pid'.($table == 'pages' ?
',t3ver_swapmode' : ''));
256 $row = t3lib_BEfunc
::getRecord($table,$uid,$internalFields,$where,$useDeleteClause);
257 t3lib_BEfunc
::workspaceOL($table,$row);
259 if (is_array ($row)) {
260 foreach (array_keys($row) as $key) {
261 if (!t3lib_div
::inList($fields, $key) && $key{0} !== '_') {
267 $row = t3lib_BEfunc
::getRecord($table,$uid,$fields,$where);
268 t3lib_BEfunc
::workspaceOL($table,$row);
274 * Returns the first record found from $table with $where as WHERE clause
275 * This function does NOT check if a record has the deleted flag set.
276 * $table does NOT need to be configured in $TCA
277 * The query used is simply this:
278 * $query='SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
279 * Usage: 5 (ext: sys_todos)
281 * @param string Table name (not necessarily in TCA)
282 * @param string WHERE clause
283 * @param string $fields is a list of fields to select, default is '*'
284 * @return array First row found, if any, FALSE otherwise
286 function getRecordRaw($table,$where='',$fields='*') {
288 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
289 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
290 $GLOBALS['TYPO3_DB']->sql_free_result($res);
296 * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
297 * The records are returned in an array
298 * If no records were selected, the function returns nothing
301 * @param string Table name present in $TCA
302 * @param string Field to select on
303 * @param string Value that $theField must match
304 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
305 * @param string Optional GROUP BY field(s), if none, supply blank string.
306 * @param string Optional ORDER BY field(s), if none, supply blank string.
307 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
308 * @param boolean Use the deleteClause to check if a record is deleted (default true)
309 * @return mixed Multidimensional array with selected records (if any is selected)
311 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='',$useDeleteClause=true) {
313 if (is_array($TCA[$theTable])) {
314 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
317 $theField.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable).
318 ($useDeleteClause ? t3lib_BEfunc
::deleteClause($theTable).' ' : '').
319 t3lib_BEfunc
::versioningPlaceholderClause($theTable).' '.
320 $whereClause, // whereClauseMightContainGroupOrderBy
326 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
329 $GLOBALS['TYPO3_DB']->sql_free_result($res);
330 if (count($rows)) return $rows;
335 * Returns a WHERE clause which will make an AND search for the words in the $searchWords array in any of the fields in array $fields.
338 * @param array Array of search words
339 * @param array Array of fields
340 * @param string Table in which we are searching (for DBAL detection of quoteStr() method)
341 * @return string WHERE clause for search
342 * @deprecated Use $GLOBALS['TYPO3_DB']->searchQuery() directly!
344 function searchQuery($searchWords,$fields,$table='') {
345 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
349 * Returns a WHERE clause that can find a value ($value) in a list field ($field)
350 * For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their positioni in the list (left, middle or right).
351 * Is nice to look up list-relations to records or files in TYPO3 database tables.
354 * @param string Table field name
355 * @param string Value to find in list
356 * @return string WHERE clause for a query
357 * @deprecated Use $GLOBALS['TYPO3_DB']->listQuery() directly!
359 function listQuery($field,$value) {
360 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
364 * Makes an backwards explode on the $str and returns an array with ($table,$uid).
365 * Example: tt_content_45 => array('tt_content',45)
368 * @param string [tablename]_[uid] string to explode
371 function splitTable_Uid($str) {
372 list($uid,$table) = explode('_',strrev($str),2);
373 return array(strrev($table),strrev($uid));
377 * Returns a list of pure integers based on $in_list being a list of records with table-names prepended.
378 * Ex: $in_list = "pages_4,tt_content_12,45" would result in a return value of "4,45" if $tablename is "pages" and $default_tablename is 'pages' as well.
379 * Usage: 1 (t3lib_userauthgroup)
381 * @param string Input list
382 * @param string Table name from which ids is returned
383 * @param string $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
384 * @return string List of ids
386 function getSQLselectableList($in_list,$tablename,$default_tablename) {
388 if ((string)trim($in_list)!='') {
389 $tempItemArray = explode(',',trim($in_list));
390 while(list($key,$val)=each($tempItemArray)) {
392 $parts = explode('_',$val,2);
393 if ((string)trim($parts[0])!='') {
394 $theID = intval(strrev($parts[0]));
395 $theTable = trim($parts[1]) ?
strrev(trim($parts[1])) : $default_tablename;
396 if ($theTable==$tablename) {$list[]=$theID;}
400 return implode(',',$list);
404 * Backend implementation of enableFields()
405 * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
406 * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
407 * $GLOBALS["SIM_EXEC_TIME"] is used for date.
410 * @param string $table is the table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $TCA.
411 * @param boolean $inv means that the query will select all records NOT VISIBLE records (inverted selection)
412 * @return string WHERE clause part
414 function BEenableFields($table,$inv=0) {
415 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
418 if (is_array($ctrl)) {
419 if (is_array($ctrl['enablecolumns'])) {
420 if ($ctrl['enablecolumns']['disabled']) {
421 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
422 $query[]=$field.'=0';
423 $invQuery[]=$field.'!=0';
425 if ($ctrl['enablecolumns']['starttime']) {
426 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
427 $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
428 $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
430 if ($ctrl['enablecolumns']['endtime']) {
431 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
432 $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
433 $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
437 $outQ = ' AND '.($inv ?
'('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
451 /*******************************************
453 * SQL-related, DEPRECATED functions
454 * (use t3lib_DB functions instead)
456 *******************************************/
460 * Returns a SELECT query, selecting fields ($select) from two/three tables joined
461 * $local_table and $mm_table is mandatory. $foreign_table is optional.
462 * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid
463 * The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $TCA in Inside TYPO3 for more details.
464 * DEPRECATED - Use $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query() instead since that will return the result pointer while this returns the query. Using this function may make your application less fitted for DBAL later.
466 * @param string Field list for SELECT
467 * @param string Tablename, local table
468 * @param string Tablename, relation table
469 * @param string Tablename, foreign table
470 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
471 * @param string Optional GROUP BY field(s), if none, supply blank string.
472 * @param string Optional ORDER BY field(s), if none, supply blank string.
473 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
474 * @return string Full SQL query
476 * @see t3lib_DB::exec_SELECT_mm_query()
478 function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
479 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
481 $local_table.','.$mm_table.($foreign_table?
','.$foreign_table:''),
482 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?
' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
483 $whereClause, // whereClauseMightContainGroupOrderBy
492 * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.
493 * DEPRECATED - $GLOBALS['TYPO3_DB']->INSERTquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_INSERTquery()
495 * @param string Table name
496 * @param array Field values as key=>value pairs.
497 * @return string Full SQL query for INSERT
500 function DBcompileInsert($table,$fields_values) {
501 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
505 * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values.
506 * DEPRECATED - $GLOBALS['TYPO3_DB']->UPDATEquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_UPDATEquery()
508 * @param string Database tablename
509 * @param string WHERE clause, eg. "uid=1"
510 * @param array Field values as key=>value pairs.
511 * @return string Full SQL query for UPDATE
514 function DBcompileUpdate($table,$where,$fields_values) {
515 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
527 /*******************************************
529 * Page tree, TCA related
531 *******************************************/
534 * Returns what is called the 'RootLine'. That is an array with information about the page records from a page id ($uid) and back to the root.
535 * By default deleted pages are filtered.
536 * This RootLine will follow the tree all the way to the root. This is opposite to another kind of root line known from the frontend where the rootline stops when a root-template is found.
539 * @param integer Page id for which to create the root line.
540 * @param string $clause can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
541 * @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!
542 * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
544 function BEgetRootLine($uid,$clause='',$workspaceOL=FALSE) {
546 $theRowArray = Array();
548 while ($uid!=0 && $loopCheck>0) {
550 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
551 'pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_swapmode,t3ver_stage',
553 'uid='.intval($uid).' '.
554 t3lib_BEfunc
::deleteClause('pages').' '.
555 $clause // whereClauseMightContainGroupOrderBy
557 if ($GLOBALS['TYPO3_DB']->sql_error()) {
558 debug($GLOBALS['TYPO3_DB']->sql_error(),1);
560 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
561 if($workspaceOL) t3lib_BEfunc
::workspaceOL('pages',$row);
562 t3lib_BEfunc
::fixVersioningPid('pages',$row);
564 $theRowArray[] = $row;
569 if ($uid==0) {$theRowArray[] = Array('uid'=>0,'title'=>'');}
570 if (is_array($theRowArray)) {
572 $c=count($theRowArray);
573 while(list($key,$val)=each($theRowArray)) {
575 $output[$c]['uid'] = $val['uid'];
576 $output[$c]['pid'] = $val['pid'];
577 if (isset($val['_ORIG_pid'])) $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
578 $output[$c]['title'] = $val['title'];
579 $output[$c]['TSconfig'] = $val['TSconfig'];
580 $output[$c]['is_siteroot'] = $val['is_siteroot'];
581 $output[$c]['storage_pid'] = $val['storage_pid'];
582 $output[$c]['t3ver_oid'] = $val['t3ver_oid'];
583 $output[$c]['t3ver_wsid'] = $val['t3ver_wsid'];
584 $output[$c]['t3ver_state'] = $val['t3ver_state'];
585 $output[$c]['t3ver_swapmode'] = $val['t3ver_swapmode'];
586 $output[$c]['t3ver_stage'] = $val['t3ver_stage'];
594 * Opens the page tree to the specified page id
596 * @param integer Page id.
597 * @param boolean If set, then other open branches are closed.
600 function openPageTree($pid,$clearExpansion) {
603 // Get current expansion data:
604 if ($clearExpansion) {
605 $expandedPages = array();
607 $expandedPages = unserialize($BE_USER->uc
['browseTrees']['browsePages']);
611 $rL = t3lib_BEfunc
::BEgetRootLine($pid);
613 // First, find out what mount index to use (if more than one DB mount exists):
615 $mountKeys = array_flip($BE_USER->returnWebmounts());
616 foreach($rL as $rLDat) {
617 if (isset($mountKeys[$rLDat['uid']])) {
618 $mountIndex = $mountKeys[$rLDat['uid']];
623 // Traverse rootline and open paths:
624 foreach($rL as $rLDat) {
625 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
629 $BE_USER->uc
['browseTrees']['browsePages'] = serialize($expandedPages);
634 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
635 * Each part of the path will be limited to $titleLimit characters
636 * Deleted pages are filtered out.
639 * @param integer Page uid for which to create record path
640 * @param string $clause is additional where clauses, eg. "
641 * @param integer Title limit
642 * @param integer Title limit of Full title (typ. set to 1000 or so)
643 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
645 function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) {
646 if (!$titleLimit) { $titleLimit=1000; }
649 $output = $fullOutput = '/';
650 while ($uid!=0 && $loopCheck>0) {
652 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
653 'uid,pid,title,t3ver_oid,t3ver_wsid,t3ver_swapmode',
656 t3lib_BEfunc
::deleteClause('pages').
657 (strlen(trim($clause)) ?
' AND '.$clause : '')
659 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
660 t3lib_BEfunc
::workspaceOL('pages',$row);
661 t3lib_BEfunc
::fixVersioningPid('pages',$row);
663 if ($row['_ORIG_pid'] && $row['t3ver_swapmode']>0) { // Branch points
664 $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...
667 $output = '/'.t3lib_div
::fixed_lgd_cs(strip_tags($row['title']),$titleLimit).$output;
668 if ($fullTitleLimit) $fullOutput = '/'.t3lib_div
::fixed_lgd_cs(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
674 if ($fullTitleLimit) {
675 return array($output, $fullOutput);
682 * Returns an array with the exclude-fields as defined in TCA
683 * Used for listing the exclude-fields in be_groups forms
684 * Usage: 2 (t3lib_tceforms + t3lib_transferdata)
686 * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries
688 function getExcludeFields() {
691 $theExcludeArray = Array();
692 $tc_keys = array_keys($TCA);
693 foreach($tc_keys as $table) {
695 t3lib_div
::loadTCA($table);
696 // All field names configured:
697 if (is_array($TCA[$table]['columns'])) {
698 $f_keys = array_keys($TCA[$table]['columns']);
699 foreach($f_keys as $field) {
700 if ($TCA[$table]['columns'][$field]['exclude']) {
701 // Get Human Readable names of fields and table:
702 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
704 $theExcludeArray[] = Array($Fname , $table.':'.$field);
709 return $theExcludeArray;
713 * Returns an array with explicit Allow/Deny fields.
714 * Used for listing these field/value pairs in be_groups forms
716 * @return array Array with information from all of $TCA
718 function getExplicitAuthFieldValues() {
723 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.allow'),
724 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.deny'),
728 $allowDenyOptions = Array();
729 $tc_keys = array_keys($TCA);
730 foreach($tc_keys as $table) {
733 t3lib_div
::loadTCA($table);
735 // All field names configured:
736 if (is_array($TCA[$table]['columns'])) {
737 $f_keys = array_keys($TCA[$table]['columns']);
738 foreach($f_keys as $field) {
739 $fCfg = $TCA[$table]['columns'][$field]['config'];
740 if ($fCfg['type']=='select' && $fCfg['authMode']) {
743 if (is_array($fCfg['items'])) {
744 // Get Human Readable names of fields and table:
745 $allowDenyOptions[$table.':'.$field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
748 foreach($fCfg['items'] as $iVal) {
749 if (strcmp($iVal[1],'')) { // Values '' is not controlled by this setting.
753 switch((string)$fCfg['authMode']) {
754 case 'explicitAllow':
761 if (!strcmp($iVal[4],'EXPL_ALLOW')) {
763 } elseif (!strcmp($iVal[4],'EXPL_DENY')) {
771 $allowDenyOptions[$table.':'.$field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
781 return $allowDenyOptions;
785 * Returns an array with system languages:
787 * @return array Array with languages
789 function getSystemLanguages() {
791 // Initialize, add default language:
792 $sysLanguages = array();
793 $sysLanguages[] = array('Default language', 0);
795 // Traverse languages
796 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,flag','sys_language','pid=0'.t3lib_BEfunc
::deleteClause('sys_language'));
797 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
798 $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ?
'flags/'.$row['flag'] : ''));
801 return $sysLanguages;
805 * Returns a page record (of page with $id) with an extra field "_thePath" set to the record path IF the WHERE clause, $perms_clause, selects the record. Thus is works as an access check that returns a page record if access was granted, otherwise not.
806 * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
807 * In any case ->isInWebMount must return true for the user (regardless of $perms_clause)
810 * @param integer Page uid for which to check read-access
811 * @param string $perms_clause is typically a value generated with $BE_USER->getPagePermsClause(1);
812 * @return array Returns page record if OK, otherwise false.
814 function readPageAccess($id,$perms_clause) {
815 if ((string)$id!='') {
818 if ($GLOBALS['BE_USER']->isAdmin()) {
820 $pageinfo['_thePath'] = $path;
824 $pageinfo = t3lib_BEfunc
::getRecord('pages',$id,'*',($perms_clause ?
' AND '.$perms_clause : ''));
825 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) {
826 t3lib_BEfunc
::workspaceOL('pages', $pageinfo);
827 t3lib_BEfunc
::fixVersioningPid('pages', $pageinfo);
828 list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc
::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
837 * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
840 * @param string Table name (present in TCA)
841 * @param array Record from $table
842 * @param boolean If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
845 function getTCAtypes($table,$rec,$useFieldNameAsKey=0) {
848 t3lib_div
::loadTCA($table);
852 $fieldValue = t3lib_BEfunc
::getTCAtypeValue($table,$rec);
855 $typesConf = $TCA[$table]['types'][$fieldValue];
857 // Get fields list and traverse it
858 $fieldList = explode(',', $typesConf['showitem']);
859 $altFieldList = array();
861 // Traverse fields in types config and parse the configuration into a nice array:
862 foreach($fieldList as $k => $v) {
863 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div
::trimExplode(';', $v);
864 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ?
$TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
865 $specConfParts = t3lib_BEfunc
::getSpecConfParts($pSpec, $defaultExtras);
867 $fieldList[$k]=array(
868 'field' => $pFieldName,
869 'title' => $pAltTitle,
870 'palette' => $pPalette,
871 'spec' => $specConfParts,
874 if ($useFieldNameAsKey) {
875 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
878 if ($useFieldNameAsKey) {
879 $fieldList = $altFieldList;
888 * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $TCA
889 * If no "type" field is configured in the "ctrl"-section of the $TCA for the table, zero is used.
890 * If zero is not an index in the "types" section of $TCA for the table, then the $fieldValue returned will default to 1 (no matter if that is an index or not)
893 * @param string Table name present in TCA
894 * @param array Record from $table
895 * @return string Field value
898 function getTCAtypeValue($table,$rec) {
901 // 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.
902 t3lib_div
::loadTCA($table);
904 $field = $TCA[$table]['ctrl']['type'];
905 $fieldValue = $field ?
($rec[$field] ?
$rec[$field] : 0) : 0;
906 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
912 * Parses a part of the field lists in the "types"-section of $TCA arrays, namely the "special configuration" at index 3 (position 4)
913 * Elements are splitted by ":" and within those parts, parameters are splitted by "|".
914 * Everything is returned in an array and you should rather see it visually than listen to me anymore now... Check out example in Inside TYPO3
917 * @param string Content from the "types" configuration of TCA (the special configuration) - see description of function
918 * @param string The ['defaultExtras'] value from field configuration
921 function getSpecConfParts($str, $defaultExtras) {
923 // Add defaultExtras:
924 $specConfParts = t3lib_div
::trimExplode(':', $defaultExtras.':'.$str, 1);
927 if (count($specConfParts)) {
928 foreach($specConfParts as $k2 => $v2) {
929 unset($specConfParts[$k2]);
930 if (ereg('(.*)\[(.*)\]',$v2,$reg)) {
931 $specConfParts[trim($reg[1])] = array(
932 'parameters' => t3lib_div
::trimExplode('|', $reg[2], 1)
935 $specConfParts[trim($v2)] = 1;
939 $specConfParts = array();
941 return $specConfParts;
945 * Takes an array of "[key]=[value]" strings and returns an array with the keys set as keys pointing to the value.
946 * Better see it in action! Find example in Inside TYPO3
949 * @param array Array of "[key]=[value]" strings to convert.
952 function getSpecConfParametersFromArray($pArr) {
954 if (is_array($pArr)) {
956 while(list($k,$v)=each($pArr)) {
957 $parts=explode('=',$v,2);
958 if (count($parts)==2) {
959 $out[trim($parts[0])]=trim($parts[1]);
969 * Finds the Data Structure for a FlexForm field
970 * NOTE ON data structures for deleted records: This function may fail to deliver the data structure for a record for a few reasons: a) The data structure could be deleted (either with deleted-flagged or hard-deleted), b) the data structure is fetched using the ds_pointerField_searchParent in which case any deleted record on the route to the final location of the DS will make it fail. In theory, we can solve the problem in the case where records that are deleted-flagged keeps us from finding the DS - this is done at the markers ###NOTE_A### where we make sure to also select deleted records. However, we generally want the DS lookup to fail for deleted records since for the working website we expect a deleted-flagged record to be as inaccessible as one that is completely deleted from the DB. Any way we look at it, this may lead to integrity problems of the reference index and even lost files if attached. However, that is not really important considering that a single change to a data structure can instantly invalidate large amounts of the reference index which we do accept as a cost for the flexform features. Other than requiring a reference index update, deletion of/changes in data structure or the failure to look them up when completely deleting records may lead to lost files in the uploads/ folders since those are now without a proper reference.
973 * @param array Field config array
974 * @param array Record data
975 * @param string The table name
976 * @param string Optional fieldname passed to hook object
977 * @param boolean Boolean; If set, workspace overlay is applied to records. This is correct behaviour for all presentation and export, but NOT if you want a true reflection of how things are in the live workspace.
978 * @param integer SPECIAL CASES: Use this, if the DataStructure may come from a parent record and the INPUT row doesn't have a uid yet (hence, the pid cannot be looked up). Then it is necessary to supply a PID value to search recursively in for the DS (used from TCEmain)
979 * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
980 * @see t3lib_TCEforms::getSingleField_typeFlex()
982 function getFlexFormDS($conf,$row,$table,$fieldName='',$WSOL=TRUE,$newRecordPidValue=0) {
983 global $TYPO3_CONF_VARS;
985 // Get pointer field etc from TCA-config:
986 $ds_pointerField = $conf['ds_pointerField'];
987 $ds_array = $conf['ds'];
988 $ds_tableField = $conf['ds_tableField'];
989 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
991 // Find source value:
993 if (is_array($ds_array)) { // If there is a data source array, that takes precedence
994 // If a pointer field is set, take the value from that field in the $row array and use as key.
995 if ($ds_pointerField) {
996 $srcPointer = $row[$ds_pointerField];
997 $srcPointer = isset($ds_array[$srcPointer]) ?
$srcPointer : 'default';
998 } else $srcPointer='default';
1000 // 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.
1001 if (substr($ds_array[$srcPointer],0,5)=='FILE:') {
1002 $file = t3lib_div
::getFileAbsFileName(substr($ds_array[$srcPointer],5));
1003 if ($file && @is_file
($file)) {
1004 $dataStructArray = t3lib_div
::xml2array(t3lib_div
::getUrl($file));
1005 } else $dataStructArray = 'The file "'.substr($ds_array[$srcPointer],5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
1007 $dataStructArray = t3lib_div
::xml2array($ds_array[$srcPointer]);
1010 } elseif ($ds_pointerField) { // If pointer field AND possibly a table/field is set:
1011 // Value of field pointed to:
1012 $srcPointer = $row[$ds_pointerField];
1014 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
1015 if ($ds_searchParentField && !$srcPointer) {
1016 $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###
1018 t3lib_BEfunc
::workspaceOL($table,$rr);
1019 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!
1021 $uidAcc=array(); // Used to avoid looping, if any should happen.
1022 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
1023 while(!$srcPointer) {
1025 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1026 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?
','.$subFieldPointer:''),
1028 'uid='.intval($newRecordPidValue ?
$newRecordPidValue : $rr[$ds_searchParentField]).t3lib_BEfunc
::deleteClause($table) ###NOTE_A###
1030 $newRecordPidValue = 0;
1031 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
1033 // break if no result from SQL db or if looping...
1034 if (!is_array($rr) ||
isset($uidAcc[$rr['uid']])) break;
1035 $uidAcc[$rr['uid']]=1;
1038 t3lib_BEfunc
::workspaceOL($table,$rr);
1039 t3lib_BEfunc
::fixVersioningPid($table,$rr,TRUE);
1041 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ?
$rr[$subFieldPointer] : $rr[$ds_pointerField];
1045 // If there is a srcPointer value:
1047 if (t3lib_div
::testInt($srcPointer)) { // If integer, then its a record we will look up:
1048 list($tName,$fName) = explode(':',$ds_tableField,2);
1049 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
1050 $dataStructRec = t3lib_BEfunc
::getRecord($tName, $srcPointer);
1052 t3lib_BEfunc
::workspaceOL($tName,$dataStructRec);
1054 $dataStructArray = t3lib_div
::xml2array($dataStructRec[$fName]);
1055 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
1056 } else { // Otherwise expect it to be a file:
1057 $file = t3lib_div
::getFileAbsFileName($srcPointer);
1058 if ($file && @is_file
($file)) {
1059 $dataStructArray = t3lib_div
::xml2array(t3lib_div
::getUrl($file));
1060 } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
1062 } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"'; // Error message.
1063 } else $dataStructArray='No proper configuration!';
1065 // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
1066 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
1067 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
1068 $hookObj = &t3lib_div
::getUserObj($classRef);
1069 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
1070 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
1075 return $dataStructArray;
1095 /*******************************************
1099 *******************************************/
1102 * Stores the string value $data in the 'cache_hash' table with the hash key, $hash, and visual/symbolic identification, $ident
1103 * IDENTICAL to the function by same name found in t3lib_page:
1106 * @param string 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
1107 * @param string The data string. If you want to store an array, then just serialize it first.
1108 * @param string $ident is just a textual identification in order to inform about the content! May be 20 characters long.
1111 function storeHash($hash,$data,$ident) {
1112 $insertFields = array(
1118 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
1119 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
1123 * Retrieves the string content stored with hash key, $hash, in cache_hash
1124 * IDENTICAL to the function by same name found in t3lib_page:
1127 * @param string Hash key, 32 bytes hex
1128 * @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.
1131 function getHash($hash,$expTime=0) {
1132 // if expTime is not set, the hash will never expire
1133 $expTime = intval($expTime);
1135 $whereAdd = ' AND tstamp > '.(time()-$expTime);
1137 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
1138 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1139 return $row['content'];
1150 /*******************************************
1152 * TypoScript related
1154 *******************************************/
1157 * Returns the Page TSconfig for page with id, $id
1158 * Requires class "t3lib_TSparser"
1159 * Usage: 26 (spec. in ext info_pagetsconfig)
1161 * @param integer Page uid for which to create Page TSconfig
1162 * @param array If $rootLine is an array, that is used as rootline, otherwise rootline is just calculated
1163 * @param boolean If $returnPartArray is set, then the array with accumulated Page TSconfig is returned non-parsed. Otherwise the output will be parsed by the TypoScript parser.
1164 * @return array Page TSconfig
1165 * @see t3lib_TSparser
1167 function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) {
1169 if (!is_array($rootLine)) {
1170 $rootLine = t3lib_BEfunc
::BEgetRootLine($id,'',TRUE);
1172 ksort($rootLine); // Order correctly
1173 $TSdataArray = array();
1174 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
1175 foreach($rootLine as $k => $v) {
1176 $TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
1178 $TSdataArray = t3lib_TSparser
::checkIncludeLines_array($TSdataArray);
1179 if ($returnPartArray) {
1180 return $TSdataArray;
1183 // Parsing the user TS (or getting from cache)
1184 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
1185 $hash = md5('pageTS:'.$userTS);
1186 $cachedContent = t3lib_BEfunc
::getHash($hash,0);
1187 $TSconfig = array();
1188 if (isset($cachedContent)) {
1189 $TSconfig = unserialize($cachedContent);
1191 $parseObj = t3lib_div
::makeInstance('t3lib_TSparser');
1192 $parseObj->parse($userTS);
1193 $TSconfig = $parseObj->setup
;
1194 t3lib_BEfunc
::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
1197 // get User TSconfig overlay
1198 $userTSconfig = $GLOBALS['BE_USER']->userTS
['page.'];
1199 if (is_array($userTSconfig)) {
1200 $TSconfig = t3lib_div
::array_merge_recursive_overrule($TSconfig, $userTSconfig);
1206 * Updates Page TSconfig for a page with $id
1207 * The function seems to take $pageTS as an array with properties and compare the values with those that already exists for the "object string", $TSconfPrefix, for the page, then sets those values which were not present.
1208 * $impParams can be supplied as already known Page TSconfig, otherwise it's calculated.
1210 * THIS DOES NOT CHECK ANY PERMISSIONS. SHOULD IT?
1211 * More documentation is needed.
1213 * Usage: 1 (ext. direct_mail)
1215 * @param integer Page id
1216 * @param array Page TS array to write
1217 * @param string Prefix for object paths
1218 * @param array [Description needed.]
1221 * @see implodeTSParams(), getPagesTSconfig()
1223 function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') {
1225 if (is_array($pageTS) && $id>0) {
1226 if (!is_array($impParams)) {
1227 $impParams =t3lib_BEfunc
::implodeTSParams(t3lib_BEfunc
::getPagesTSconfig($id));
1231 while(list($f,$v)=each($pageTS)) {
1232 $f = $TSconfPrefix.$f;
1233 if ((!isset($impParams[$f])&&trim($v)) ||
strcmp(trim($impParams[$f]),trim($v))) {
1238 // Get page record and TS config lines
1239 $pRec = t3lib_befunc
::getRecord('pages',$id);
1240 $TSlines = explode(chr(10),$pRec['TSconfig']);
1241 $TSlines = array_reverse($TSlines);
1242 // Reset the set of changes.
1244 while(list($f,$v)=each($set)) {
1247 while(list($ki,$kv)=each($TSlines)) {
1248 if (substr($kv,0,strlen($f)+
1)==$f.'=') {
1249 $TSlines[$ki]=$f.'='.$v;
1255 $TSlines = array_reverse($TSlines);
1256 $TSlines[]=$f.'='.$v;
1257 $TSlines = array_reverse($TSlines);
1260 $TSlines = array_reverse($TSlines);
1262 // store those changes
1263 $TSconf = implode(chr(10),$TSlines);
1265 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
1271 * Implodes a multi dimensional TypoScript array, $p, into a one-dimentional array (return value)
1274 * @param array TypoScript structure
1275 * @param string Prefix string
1276 * @return array Imploded TypoScript objectstring/values
1278 function implodeTSParams($p,$k='') {
1279 $implodeParams=array();
1282 while(list($kb,$val)=each($p)) {
1283 if (is_array($val)) {
1284 $implodeParams = array_merge($implodeParams,t3lib_BEfunc
::implodeTSParams($val,$k.$kb));
1286 $implodeParams[$k.$kb]=$val;
1290 return $implodeParams;
1300 /*******************************************
1302 * Users / Groups related
1304 *******************************************/
1307 * Returns an array with be_users records of all user NOT DELETED sorted by their username
1308 * Keys in the array is the be_users uid
1309 * Usage: 14 (spec. ext. "beuser" and module "web_perm")
1311 * @param string Optional $fields list (default: username,usergroup,usergroup_cached_list,uid) can be used to set the selected fields
1312 * @param string Optional $where clause (fx. "AND username='pete'") can be used to limit query
1315 function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
1316 $be_user_Array=Array();
1318 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc
::deleteClause('be_users'), '', 'username');
1319 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1320 $be_user_Array[$row['uid']]=$row;
1322 return $be_user_Array;
1326 * Returns an array with be_groups records (title, uid) of all groups NOT DELETED sorted by their title
1327 * Usage: 8 (spec. ext. "beuser" and module "web_perm")
1329 * @param string Field list
1330 * @param string WHERE clause
1333 function getGroupNames($fields='title,uid', $where='') {
1334 $be_group_Array = Array();
1335 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc
::deleteClause('be_groups'), '', 'title');
1336 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1337 $be_group_Array[$row['uid']] = $row;
1339 return $be_group_Array;
1343 * Returns an array with be_groups records (like ->getGroupNames) but:
1344 * - if the current BE_USER is admin, then all groups are returned, otherwise only groups that the current user is member of (usergroup_cached_list) will be returned.
1345 * Usage: 2 (module "web_perm" and ext. taskcenter)
1347 * @param string Field list; $fields specify the fields selected (default: title,uid)
1350 function getListGroupNames($fields='title,uid') {
1351 $exQ=' AND hide_in_lists=0';
1352 if (!$GLOBALS['BE_USER']->isAdmin()) {
1353 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user
['usergroup_cached_list']?
$GLOBALS['BE_USER']->user
['usergroup_cached_list']:0).')';
1355 return t3lib_BEfunc
::getGroupNames($fields,$exQ);
1359 * Returns the array $usernames with the names of all users NOT IN $groupArray changed to the uid (hides the usernames!).
1360 * If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1361 * Takes $usernames (array made by t3lib_BEfunc::getUserNames()) and a $groupArray (array with the groups a certain user is member of) as input
1364 * @param array User names
1365 * @param array Group names
1366 * @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1367 * @return array User names, blinded
1369 function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) {
1370 if (is_array($usernames) && is_array($groupArray)) {
1371 while(list($uid,$row)=each($usernames)) {
1374 if ($row['uid']!=$GLOBALS['BE_USER']->user
['uid']) {
1376 while(list(,$v)=each($groupArray)) {
1377 if ($v && t3lib_div
::inList($row['usergroup_cached_list'],$v)) {
1378 $userN = $row['username'];
1383 $userN = $row['username'];
1386 $usernames[$uid]['username']=$userN;
1387 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
1394 * Corresponds to blindUserNames but works for groups instead
1395 * Usage: 2 (module web_perm)
1397 * @param array Group names
1398 * @param array Group names (reference)
1399 * @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1402 function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) {
1403 if (is_array($groups) && is_array($groupArray)) {
1404 while(list($uid,$row)=each($groups)) {
1407 if (t3lib_div
::inArray($groupArray,$uid)) {
1408 $groupN=$row['title'];
1411 $groups[$uid]['title']=$groupN;
1412 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
1430 /*******************************************
1434 *******************************************/
1437 * Returns the difference in days between input $tstamp and $EXEC_TIME
1438 * Usage: 2 (class t3lib_BEfunc)
1440 * @param integer Time stamp, seconds
1443 function daysUntil($tstamp) {
1444 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
1445 return ceil($delta_t/(3600*24));
1449 * Returns $tstamp formatted as "ddmmyy" (According to $TYPO3_CONF_VARS['SYS']['ddmmyy'])
1452 * @param integer Time stamp, seconds
1453 * @return string Formatted time
1455 function date($tstamp) {
1456 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
1460 * Returns $tstamp formatted as "ddmmyy hhmm" (According to $TYPO3_CONF_VARS['SYS']['ddmmyy'] AND $TYPO3_CONF_VARS['SYS']['hhmm'])
1463 * @param integer Time stamp, seconds
1464 * @return string Formatted time
1466 function datetime($value) {
1467 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
1471 * Returns $value (in seconds) formatted as hh:mm:ss
1472 * For instance $value = 3600 + 60*2 + 3 should return "01:02:03"
1473 * Usage: 1 (class t3lib_BEfunc)
1475 * @param integer Time stamp, seconds
1476 * @return string Formatted time
1478 function time($value) {
1479 $hh = floor($value/3600);
1480 $min = floor(($value-$hh*3600)/60);
1481 $sec = $value-$hh*3600-$min*60;
1482 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
1487 * Returns the "age" in minutes / hours / days / years of the number of $seconds inputted.
1490 * @param integer $seconds could be the difference of a certain timestamp and time()
1491 * @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")
1492 * @return string Formatted time
1494 function calcAge($seconds,$labels = 'min|hrs|days|yrs') {
1495 $labelArr = explode('|',$labels);
1497 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
1498 if ($seconds<3600) {
1499 $seconds = round ($seconds/60).' '.trim($labelArr[0]);
1500 } elseif ($seconds<24*3600) {
1501 $seconds = round ($seconds/3600).' '.trim($labelArr[1]);
1502 } elseif ($seconds<365*24*3600) {
1503 $seconds = round ($seconds/(24*3600)).' '.trim($labelArr[2]);
1505 $seconds = round ($seconds/(365*24*3600)).' '.trim($labelArr[3]);
1507 return $prefix.$seconds;
1511 * Returns a formatted timestamp if $tstamp is set.
1512 * The date/datetime will be followed by the age in parenthesis.
1515 * @param integer Time stamp, seconds
1516 * @param integer 1/-1 depending on polarity of age.
1517 * @param string $date=="date" will yield "dd:mm:yy" formatting, otherwise "dd:mm:yy hh:mm"
1520 function dateTimeAge($tstamp,$prefix=1,$date='') {
1522 ($date=='date' ? t3lib_BEfunc
::date($tstamp) : t3lib_BEfunc
::datetime($tstamp)).
1523 ' ('.t3lib_BEfunc
::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
1527 * Returns either title='' or alt='' attribute. This depends on the client browser and whether it supports title='' or not (which is the default)
1528 * If no $content is given only the attribute name is returned.
1529 * The returned attribute with content will have a leading space char.
1530 * Warning: Be careful to submit empty $content var - that will return just the attribute name!
1533 * @param string String to set as title-attribute. If no $content is given only the attribute name is returned.
1534 * @param boolean If $hsc is set, then content of the attribute is htmlspecialchar()'ed (which is good for XHTML and other reasons...)
1536 * @deprecated The idea made sense with older browsers, but now all browsers should support the "title" attribute - so just hardcode the title attribute instead!
1538 function titleAttrib($content='',$hsc=0) {
1540 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||
$CLIENT['BROWSER']=='konqu' ?
'alt' : 'title';
1541 return strcmp($content,'')?
' '.$attrib.'="'.($hsc?
htmlspecialchars($content):$content).'"' : $attrib;
1545 * Returns alt="" and title="" attributes with the value of $content.
1548 * @param string Value for 'alt' and 'title' attributes (will be htmlspecialchars()'ed before output)
1551 function titleAltAttrib($content) {
1553 $out.=' alt="'.htmlspecialchars($content).'"';
1554 $out.=' title="'.htmlspecialchars($content).'"';
1559 * Returns a linked image-tag for thumbnail(s)/fileicons/truetype-font-previews from a database row with a list of image files in a field
1560 * All $TYPO3_CONF_VARS['GFX']['imagefile_ext'] extension are made to thumbnails + ttf file (renders font-example)
1561 * Thumbsnails are linked to the show_item.php script which will display further details.
1564 * @param array $row is the database row from the table, $table.
1565 * @param string Table name for $row (present in TCA)
1566 * @param string $field is pointing to the field with the list of image files
1567 * @param string Back path prefix for image tag src="" field
1568 * @param string Optional: $thumbScript os by default 'thumbs.php' if you don't set it otherwise
1569 * @param string Optional: $uploaddir is the directory relative to PATH_site where the image files from the $field value is found (Is by default set to the entry in $TCA for that field! so you don't have to!)
1570 * @param boolean If set, uploaddir is NOT prepended with "../"
1571 * @param string Optional: $tparams is additional attributes for the image tags
1572 * @param integer Optional: $size is [w]x[h] of the thumbnail. 56 is default.
1573 * @return string Thumbnail image tag.
1575 function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir=NULL,$abs=0,$tparams='',$size='') {
1578 t3lib_div
::loadTCA($table);
1580 // Find uploaddir automatically
1581 $uploaddir = (is_null($uploaddir)) ?
$TCA[$table]['columns'][$field]['config']['uploadfolder'] : $uploaddir;
1582 $uploaddir = preg_replace('#/$#','',$uploaddir);
1584 // Set thumbs-script:
1585 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
1586 $thumbScript='gfx/notfound_thumb.gif';
1587 } elseif(!$thumbScript) {
1588 $thumbScript='thumbs.php';
1590 // Check and parse the size parameter
1592 if ($size = trim($size)) {
1593 $sizeParts = explode('x', $size.'x'.$size);
1594 if(!intval($sizeParts[0])) $size='';
1598 $thumbs = explode(',', $row[$field]);
1600 while(list(,$theFile)=each($thumbs)) {
1601 if (trim($theFile)) {
1602 $fI = t3lib_div
::split_fileref($theFile);
1603 $ext = $fI['fileext'];
1606 if (t3lib_div
::inList('gif,jpg,png',$ext)) {
1607 $imgInfo=@getimagesize
(PATH_site
.$uploaddir.'/'.$theFile);
1608 if (is_array($imgInfo)) {$max = max($imgInfo[0],$imgInfo[1]);}
1610 // use the original image if it's size fits to the thumbnail size
1611 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?
max($sizeParts):56)) {
1612 $theFile = $url = ($abs?
'':'../').($uploaddir?
$uploaddir.'/':'').trim($theFile);
1613 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
1614 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
1616 } elseif ($ext=='ttf' || t3lib_div
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
1617 $theFile_abs = PATH_site
.($uploaddir?
$uploaddir.'/':'').trim($theFile);
1618 $theFile = ($abs?
'':'../').($uploaddir?
$uploaddir.'/':'').trim($theFile);
1620 $check = basename($theFile_abs).':'.filemtime($theFile_abs).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1621 $params = '&file='.rawurlencode($theFile);
1622 $params.= $size?
'&size='.$size:'';
1623 $params.= '&md5sum='.t3lib_div
::shortMD5($check);
1625 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
1626 $onClick = 'top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
1627 $thumbData.= '<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
1629 $icon = t3lib_BEfunc
::getFileIcon($ext);
1630 $url = 'gfx/fileicons/'.$icon;
1631 $thumbData.= '<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
1639 * Returns single image tag to thumbnail using a thumbnail script (like thumbs.php)
1642 * @param string $thumbScript must point to "thumbs.php" relative to the script position
1643 * @param string $theFile must be the proper reference to the file thumbs.php should show
1644 * @param string $tparams are additional attributes for the image tag
1645 * @param integer $size is the size of the thumbnail send along to "thumbs.php"
1646 * @return string Image tag
1648 function getThumbNail($thumbScript,$theFile,$tparams='',$size='') {
1649 $check = basename($theFile).':'.filemtime($theFile).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1650 $params = '&file='.rawurlencode($theFile);
1651 $params.= trim($size)?
'&size='.trim($size):'';
1652 $params.= '&md5sum='.t3lib_div
::shortMD5($check);
1654 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
1655 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?
" ".$tparams:"").' alt="" />';
1660 * Returns title-attribute information for a page-record informing about id, alias, doktype, hidden, starttime, endtime, fe_group etc.
1663 * @param array Input must be a page row ($row) with the proper fields set (be sure - send the full range of fields for the table)
1664 * @param string $perms_clause is used to get the record path of the shortcut page, if any (and doktype==4)
1665 * @param boolean If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
1668 function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) {
1671 $parts[] = 'id='.$row['uid'];
1672 if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
1673 if ($row['pid']<0) $parts[] = 'v#1.'.$row['t3ver_id'];
1674 if ($row['t3ver_state']==1) $parts[] = 'PLH WSID#'.$row['t3ver_wsid'];
1675 if ($row['t3ver_state']==-1) $parts[] = 'New element!';
1677 if ($row['doktype']=='3') {
1678 $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
1679 } elseif ($row['doktype']=='4') {
1680 if ($perms_clause) {
1681 $label = t3lib_BEfunc
::getRecordPath(intval($row['shortcut']),$perms_clause,20);
1683 $lRec = t3lib_BEfunc
::getRecordWSOL('pages',intval($row['shortcut']),'title');
1684 $label = $lRec['title'];
1686 if ($row['shortcut_mode']>0) {
1687 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
1688 $LANG->sL(t3lib_BEfunc
::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
1690 $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
1691 } elseif ($row['doktype']=='7') {
1692 if ($perms_clause) {
1693 $label = t3lib_BEfunc
::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
1695 $lRec = t3lib_BEfunc
::getRecordWSOL('pages',intval($row['mount_pid']),'title');
1696 $label = $lRec['title'];
1698 $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
1699 if ($row['mount_pid_ol']) {
1700 $parts[] = $LANG->sL($TCA['pages']['columns']['mount_pid_ol']['label']);
1703 if ($row['nav_hide']) $parts[] = ereg_replace(':$','',$LANG->sL($TCA['pages']['columns']['nav_hide']['label']));
1704 if ($row['hidden']) $parts[] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
1705 if ($row['starttime']) $parts[] = $LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc
::dateTimeAge($row['starttime'],-1,'date');
1706 if ($row['endtime']) $parts[] = $LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc
::dateTimeAge($row['endtime'],-1,'date');
1707 if ($row['fe_group']) {
1708 if ($row['fe_group']<0) {
1709 $label = $LANG->sL(t3lib_BEfunc
::getLabelFromItemlist('pages','fe_group',$row['fe_group']));
1711 $lRec = t3lib_BEfunc
::getRecordWSOL('fe_groups',$row['fe_group'],'title');
1712 $label = $lRec['title'];
1714 $parts[] = $LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
1716 $out = htmlspecialchars(implode(' - ',$parts));
1717 return $includeAttrib ?
'title="'.$out.'"' : $out;
1721 * Returns title-attribute information for ANY record (from a table defined in TCA of course)
1722 * The included information depends on features of the table, but if hidden, starttime, endtime and fe_group fields are configured for, information about the record status in regard to these features are is included.
1723 * "pages" table can be used as well and will return the result of ->titleAttribForPages() for that page.
1726 * @param array Table row; $row is a row from the table, $table
1727 * @param string Table name
1730 function getRecordIconAltText($row,$table='pages') {
1731 if ($table=='pages') {
1732 $out = t3lib_BEfunc
::titleAttribForPages($row,'',0);
1734 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1736 $out='id='.$row['uid']; // Uid is added
1737 if ($table=='pages' && $row['alias']) {
1738 $out.=' / '.$row['alias'];
1740 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid']<0) {
1741 $out.=' - v#1.'.$row['t3ver_id'];
1743 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1744 if ($row['t3ver_state']==1) $out.= ' - PLH WSID#'.$row['t3ver_wsid'];
1745 if ($row['t3ver_state']==-1) $out.= ' - New element!';
1748 if ($ctrl['disabled']) { // Hidden ...
1749 $out.=($row[$ctrl['disabled']]?
' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
1751 if ($ctrl['starttime']) {
1752 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
1753 $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').')';
1756 if ($row[$ctrl['endtime']]) {
1757 $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').')';
1760 return htmlspecialchars($out);
1764 * Returns the label of the first found entry in an "items" array from $TCA (tablename=$table/fieldname=$col) where the value is $key
1767 * @param string Table name, present in $TCA
1768 * @param string Field name, present in $TCA
1769 * @param string items-array value to match
1770 * @return string Label for item entry
1772 function getLabelFromItemlist($table,$col,$key) {
1774 // Load full TCA for $table
1775 t3lib_div
::loadTCA($table);
1777 // Check, if there is an "items" array:
1778 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
1779 // Traverse the items-array...
1780 reset($TCA[$table]['columns'][$col]['config']['items']);
1781 while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items'])) {
1782 // ... and return the first found label where the value was equal to $key
1783 if (!strcmp($v[1],$key)) return $v[0];
1789 * Returns the label-value for fieldname $col in table, $table
1790 * 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>'
1793 * @param string Table name, present in $TCA
1794 * @param string Field name
1795 * @param string Wrap value - set function description
1798 function getItemLabel($table,$col,$printAllWrap='') {
1800 // Load full TCA for $table
1801 t3lib_div
::loadTCA($table);
1802 // Check if column exists
1803 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
1805 return $TCA[$table]['columns'][$col]['label'];
1807 if ($printAllWrap) {
1808 $parts = explode('|',$printAllWrap);
1809 return $parts[0].$col.$parts[1];
1814 * Returns the "title"-value in record, $row, from table, $table
1815 * The field(s) from which the value is taken is determined by the "ctrl"-entries 'label', 'label_alt' and 'label_alt_force'
1818 * @param string Table name, present in TCA
1819 * @param array Row from table
1820 * @param boolean If set, result is prepared for output: The output is cropped to a limited lenght (depending on BE_USER->uc['titleLen']) and if no value is found for the title, '<em>[No title]</em>' is returned (localized). Further, the output is htmlspecialchars()'ed
1821 * @param boolean If set, the function always returns an output. If no value is found for the title, '[No title]' is returned (localized).
1824 function getRecordTitle($table,$row,$prep=FALSE,$forceResult=TRUE) {
1826 if (is_array($TCA[$table])) {
1828 // If configured, call userFunc
1829 if ($TCA[$table]['ctrl']['label_userFunc']) {
1830 $params['table'] = $table;
1831 $params['row'] = $row;
1832 $params['title'] = '';
1834 t3lib_div
::callUserFunction($TCA[$table]['ctrl']['label_userFunc'],$params,$this);
1835 $t = $params['title'];
1838 // No userFunc: Build label
1839 $t = $row[$TCA[$table]['ctrl']['label']];
1840 if ($TCA[$table]['ctrl']['label_alt'] && ($TCA[$table]['ctrl']['label_alt_force'] ||
!strcmp($t,''))) {
1841 $altFields=t3lib_div
::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1);
1844 foreach ($altFields as $fN) {
1845 $t = $tA[] = trim(strip_tags($row[$fN]));
1846 if (strcmp($t,'') && !$TCA[$table]['ctrl']['label_alt_force']) break;
1848 if ($TCA[$table]['ctrl']['label_alt_force']) $t=implode(', ',$tA);
1852 // If the current result is empty, set it to '[No title]' (localized) and prepare for output if requested
1853 if ($prep ||
$forceResult) {
1855 $t = t3lib_BEfunc
::getRecordTitlePrep($t);
1857 if (!strcmp(trim($t),'')) {
1858 $t = t3lib_BEfunc
::getNoRecordTitle($prep);
1867 * Crops a title string to a limited lenght and if it really was cropped, wrap it in a <span title="...">|</span>,
1868 * which offers a tooltip with the original title when moving mouse over it.
1870 * @param string $title: The title string to be cropped
1871 * @param integer $titleLength: Crop title after this length - if not set, BE_USER->uc['titleLen'] is used
1872 * @return string The processed title string, wrapped in <span title="...">|</span> if cropped
1874 function getRecordTitlePrep($title, $titleLength=0) {
1875 // If $titleLength is not a valid positive integer, use BE_USER->uc['titleLen']:
1876 if (!$titleLength ||
!t3lib_div
::testInt($titleLength) ||
$titleLength < 0) {
1877 $titleLength = $GLOBALS['BE_USER']->uc
['titleLen'];
1879 $titleOrig = htmlspecialchars($title);
1880 $title = htmlspecialchars(t3lib_div
::fixed_lgd_cs($title, $titleLength));
1881 // If title was cropped, offer a tooltip:
1882 if ($titleOrig != $title) {
1883 $title = '<span title="'.$titleOrig.'">'.$title.'</span>';
1889 * Get a localized [No title] string, wrapped in <em>|</em> if $prep is true.
1891 * @param boolean $prep: Wrap result in <em>|</em>
1892 * @return string Localized [No title] string
1894 function getNoRecordTitle($prep=FALSE) {
1895 $noTitle = '['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']';
1896 if ($prep) $noTitle = '<em>'.$noTitle.'</em>';
1901 * Returns a human readable output of a value from a record
1902 * For instance a database record relation would be looked up to display the title-value of that record. A checkbox with a "1" value would be "Yes", etc.
1903 * $table/$col is tablename and fieldname
1904 * REMEMBER to pass the output through htmlspecialchars() if you output it to the browser! (To protect it from XSS attacks and be XHTML compliant)
1907 * @param string Table name, present in TCA
1908 * @param string Field name, present in TCA
1909 * @param string $value is the value of that field from a selected record
1910 * @param integer $fixed_lgd_chars is the max amount of characters the value may occupy
1911 * @param boolean $defaultPassthrough flag means that values for columns that has no conversion will just be pass through directly (otherwise cropped to 200 chars or returned as "N/A")
1912 * @param boolean If set, no records will be looked up, UIDs are just shown.
1913 * @param integer uid of the current record
1914 * @param boolean If t3lib_BEfunc::getRecordTitle is used to process the value, this parameter is forwarded.
1917 function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0,$noRecordLookup=FALSE,$uid=0,$forceResult=TRUE) {
1919 global $TYPO3_CONF_VARS;
1920 // Load full TCA for $table
1921 t3lib_div
::loadTCA($table);
1922 // Check if table and field is configured:
1923 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
1924 // Depending on the fields configuration, make a meaningful output value.
1925 $theColConf = $TCA[$table]['columns'][$col]['config'];
1928 *HOOK: pre-processing the human readable output from a record
1930 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) {
1931 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) {
1932 t3lib_div
::callUserFunction($_funcRef,$theColConf,$this);
1937 switch((string)$theColConf['type']) {
1939 $l=t3lib_BEfunc
::getLabelFromItemlist($table,$col,$value);
1940 $l=$GLOBALS['LANG']->sL($l);
1943 if ($theColConf['MM']) {
1944 // Display the title of MM related records in lists
1945 if ($noRecordLookup) {
1946 $MMfield = $theColConf['foreign_table'].'.uid';
1948 $MMfields = array($theColConf['foreign_table'].'.'.$TCA[$theColConf['foreign_table']]['ctrl']['label']);
1949 foreach (t3lib_div
::trimExplode(',', $TCA[$theColConf['foreign_table']]['ctrl']['label_alt'], 1) as $f) {
1950 $MMfields[] = $theColConf['foreign_table'].'.'.$f;
1952 $MMfield = join(',',$MMfields);
1955 $dbGroup = t3lib_div
::makeInstance('t3lib_loadDBGroup');
1956 $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
1957 $selectUids = $dbGroup->tableArray
[$theColConf['foreign_table']];
1959 if (is_array($selectUids) && count($selectUids)>0) {
1960 $MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
1962 $theColConf['foreign_table'],
1963 'uid IN ('.implode(',', $selectUids).')'
1965 while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres)) {
1966 $mmlA[] = ($noRecordLookup?
$MMrow['uid']:t3lib_BEfunc
::getRecordTitle($theColConf['foreign_table'], $MMrow, FALSE, $forceResult));
1968 if (is_array($mmlA)) {
1969 $l=implode('; ',$mmlA);
1977 $l = t3lib_BEfunc
::getLabelFromItemlist($table,$col,$value);
1978 $l = $GLOBALS['LANG']->sL($l);
1979 if ($theColConf['foreign_table'] && !$l && $TCA[$theColConf['foreign_table']]) {
1980 if ($noRecordLookup) {
1983 $rParts = t3lib_div
::trimExplode(',',$value,1);
1986 while(list(,$rVal)=each($rParts)) {
1987 $rVal = intval($rVal);
1989 $r=t3lib_BEfunc
::getRecordWSOL($theColConf['foreign_table'],$rVal);
1991 $r=t3lib_BEfunc
::getRecordWSOL($theColConf['neg_foreign_table'],-$rVal);
1994 $lA[]=$GLOBALS['LANG']->sL($rVal>0?
$theColConf['foreign_table_prefix']:$theColConf['neg_foreign_table_prefix']).t3lib_BEfunc
::getRecordTitle($rVal>0?
$theColConf['foreign_table']:$theColConf['neg_foreign_table'],$r,FALSE,$forceResult);
1996 $lA[]=$rVal?
'['.$rVal.'!]':'';
1999 $l = implode(', ',$lA);
2005 $l = implode(', ',t3lib_div
::trimExplode(',',$value,1));
2008 if (!is_array($theColConf['items']) ||
count($theColConf['items'])==1) {
2009 $l = $value ?
'Yes' : '';
2011 reset($theColConf['items']);
2013 while(list($key,$val)=each($theColConf['items'])) {
2014 if ($value & pow(2,$key)) {$lA[]=$GLOBALS['LANG']->sL($val[0]);}
2016 $l = implode(', ',$lA);
2021 if (t3lib_div
::inList($theColConf['eval'],'date')) {
2022 $l = t3lib_BEfunc
::date($value).' ('.(time()-$value>0?
'-':'').t3lib_BEfunc
::calcAge(abs(time()-$value), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')';
2023 } elseif (t3lib_div
::inList($theColConf['eval'],'time')) {
2024 $l = t3lib_BEfunc
::time($value);
2025 } elseif (t3lib_div
::inList($theColConf['eval'],'datetime')) {
2026 $l = t3lib_BEfunc
::datetime($value);
2033 $l = strip_tags($value);
2036 if ($defaultPassthrough) {
2038 } elseif ($theColConf['MM']) {
2041 $l=t3lib_div
::fixed_lgd_cs(strip_tags($value),200);
2047 *HOOK: post-processing the human readable output from a record
2049 if (is_array ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) {
2050 foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) {
2053 'colConf' => $theColConf
2055 $l = t3lib_div
::callUserFunction($_funcRef,$params,$this);
2059 if ($fixed_lgd_chars) {
2060 return t3lib_div
::fixed_lgd_cs($l,$fixed_lgd_chars);
2068 * Same as ->getProcessedValue() but will go easy on fields like "tstamp" and "pid" which are not configured in TCA - they will be formatted by this function instead.
2071 * @param string Table name, present in TCA
2072 * @param string Field name
2073 * @param string Field value
2074 * @param integer $fixed_lgd_chars is the max amount of characters the value may occupy
2075 * @param integer uid of the current record
2076 * @param boolean If t3lib_BEfunc::getRecordTitle is used to process the value, this parameter is forwarded.
2078 * @see getProcessedValue()
2080 function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0,$uid=0,$forceResult=TRUE) {
2082 $fVnew = t3lib_BEfunc
::getProcessedValue($table,$fN,$fV,$fixed_lgd_chars,0,0,$uid,$forceResult);
2083 if (!isset($fVnew)) {
2084 if (is_array($TCA[$table])) {
2085 if ($fN==$TCA[$table]['ctrl']['tstamp'] ||
$fN==$TCA[$table]['ctrl']['crdate']) {
2086 $fVnew = t3lib_BEfunc
::datetime($fV);
2087 } elseif ($fN=='pid'){
2088 $fVnew = t3lib_BEfunc
::getRecordPath($fV,'1=1',20); // Fetches the path with no regard to the users permissions to select pages.
2098 * Returns file icon name (from $FILEICONS) for the fileextension $ext
2101 * @param string File extension, lowercase
2102 * @return string File icon filename
2104 function getFileIcon($ext) {
2105 return $GLOBALS['FILEICONS'][$ext] ?
$GLOBALS['FILEICONS'][$ext] : $GLOBALS['FILEICONS']['default'];
2109 * Returns fields for a table, $table, which would typically be interesting to select
2110 * This includes uid, the fields defined for title, icon-field.
2111 * Returned as a list ready for query ($prefix can be set to eg. "pages." if you are selecting from the pages table and want the table name prefixed)
2114 * @param string Table name, present in TCA
2115 * @param string Table prefix
2116 * @param array Preset fields (must include prefix if that is used)
2117 * @return string List of fields.
2119 function getCommonSelectFields($table,$prefix='',$fields = array()) {
2121 $fields[] = $prefix.'uid';
2122 $fields[] = $prefix.$TCA[$table]['ctrl']['label'];
2124 if ($TCA[$table]['ctrl']['label_alt']) {
2125 $secondFields = t3lib_div
::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1);
2126 foreach($secondFields as $fieldN) {
2127 $fields[] = $prefix.$fieldN;
2130 if ($TCA[$table]['ctrl']['versioningWS']) {
2131 $fields[] = $prefix.'t3ver_id';
2132 $fields[] = $prefix.'t3ver_state';
2133 $fields[] = $prefix.'t3ver_wsid';
2134 $fields[] = $prefix.'t3ver_count';
2137 if ($TCA[$table]['ctrl']['selicon_field']) $fields[] = $prefix.$TCA[$table]['ctrl']['selicon_field'];
2138 if ($TCA[$table]['ctrl']['typeicon_column']) $fields[] = $prefix.$TCA[$table]['ctrl']['typeicon_column'];
2140 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
2141 if ($TCA[$table]['ctrl']['enablecolumns']['disabled']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['disabled'];
2142 if ($TCA[$table]['ctrl']['enablecolumns']['starttime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['starttime'];
2143 if ($TCA[$table]['ctrl']['enablecolumns']['endtime']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['endtime'];
2144 if ($TCA[$table]['ctrl']['enablecolumns']['fe_group']) $fields[] = $prefix.$TCA[$table]['ctrl']['enablecolumns']['fe_group'];
2147 return implode(',', array_unique($fields));
2151 * Makes a form for configuration of some values based on configuration found in the array $configArray, with default values from $defaults and a data-prefix $dataPrefix
2152 * <form>-tags must be supplied separately
2153 * Needs more documentation and examples, in particular syntax for configuration array. See Inside TYPO3. That's were you can expect to find example, if anywhere.
2154 * Usage: 1 (ext. direct_mail)
2156 * @param array Field configuration code.
2157 * @param array Defaults
2158 * @param string Prefix for formfields
2159 * @return string HTML for a form.
2161 function makeConfigForm($configArray,$defaults,$dataPrefix) {
2162 $params = $defaults;
2163 if (is_array($configArray)) {
2164 reset($configArray);
2166 while(list($fname,$config)=each($configArray)) {
2167 if (is_array($config)) {
2168 $lines[$fname]='<strong>'.htmlspecialchars($config[1]).'</strong><br />';
2169 $lines[$fname].=$config[2].'<br />';
2170 switch($config[0]) {
2173 $formEl = '<input type="text" name="'.$dataPrefix.'['.$fname.']" value="'.$params[$fname].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($config[0]=='short'?
24:48).' />';
2176 $formEl = '<input type="hidden" name="'.$dataPrefix.'['.$fname.']" value="0" /><input type="checkbox" name="'.$dataPrefix.'['.$fname.']" value="1"'.($params[$fname]?
' checked="checked"':'').' />';
2184 while(list($k,$v)=each($config[3])) {
2185 $opt[]='<option value="'.htmlspecialchars($k).'"'.($params[$fname]==$k?
' selected="selected"':'').'>'.htmlspecialchars($v).'</option>';
2187 $formEl = '<select name="'.$dataPrefix.'['.$fname.']">'.implode('',$opt).'</select>';
2193 $lines[$fname].=$formEl;
2194 $lines[$fname].='<br /><br />';
2196 $lines[$fname]='<hr />';
2197 if ($config) $lines[$fname].='<strong>'.strtoupper(htmlspecialchars($config)).'</strong><br />';
2198 if ($config) $lines[$fname].='<br />';
2202 $out = implode('',$lines);
2203 $out.='<input type="submit" name="submit" value="Update configuration" />';
2219 /*******************************************
2221 * Backend Modules API functions
2223 *******************************************/
2226 * Returns help-text icon if configured for.
2227 * TCA_DESCR must be loaded prior to this function and $BE_USER must have 'edit_showFieldHelp' set to 'icon', otherwise nothing is returned
2230 * @param string Table name
2231 * @param string Field name
2232 * @param string Back path
2233 * @param boolean Force display of icon nomatter BE_USER setting for help
2234 * @return string HTML content for a help icon/text
2236 function helpTextIcon($table,$field,$BACK_PATH,$force=0) {
2237 global $TCA_DESCR,$BE_USER;
2238 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && ($BE_USER->uc
['edit_showFieldHelp']=='icon' ||
$force)) {
2239 $onClick = 'vHWin=window.open(\''.$BACK_PATH.'view_help.php?tfID='.($table.'.'.$field).'\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
2240 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
2241 '<img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/helpbubble.gif','width="14" height="14"').' hspace="2" border="0" class="typo3-csh-icon" alt="" />'.
2247 * Returns CSH help text (description), if configured for.
2248 * TCA_DESCR must be loaded prior to this function and $BE_USER must have "edit_showFieldHelp" set to "text", otherwise nothing is returned
2249 * Will automatically call t3lib_BEfunc::helpTextIcon() to get the icon for the text.
2252 * @param string Table name
2253 * @param string Field name
2254 * @param string Back path
2255 * @param string Additional style-attribute content for wrapping table
2256 * @return string HTML content for help text
2258 function helpText($table,$field,$BACK_PATH,$styleAttrib='') {
2259 global $TCA_DESCR,$BE_USER;
2260 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && $BE_USER->uc
['edit_showFieldHelp']=='text') {
2261 $fDat = $TCA_DESCR[$table]['columns'][$field];
2264 $editIcon = t3lib_BEfunc
::helpTextIcon(
2271 $onClick = 'vHWin=window.open(\''.$BACK_PATH.'view_help.php?tfID='.($table.'.'.$field).'\',\'viewFieldHelp\',\'height=400,width=600,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
2273 ($fDat['alttitle'] ?
'<h4><a href="#" onclick="'.htmlspecialchars($onClick).'">'.$fDat['alttitle'].'</a></h4>' : '').
2274 $fDat['description'];
2276 // More information to get?
2277 if ($fDat['image_descr'] ||
$fDat['seeAlso'] ||
$fDat['details'] ||
$fDat['syntax']) { // || $fDat['image'];
2278 $text.=' <a href="#" onclick="'.htmlspecialchars($onClick).'">'.
2279 '<img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/rel_db.gif','width="13" height="12"').' class="absmiddle typo3-csh-more" alt="" />'.
2283 // Additional styles?
2284 $params = $styleAttrib ?
' style="'.$styleAttrib.'"' : '';
2286 // Compile table with CSH information:
2287 return '<table border="0" cellpadding="2" cellspacing="0" class="typo3-csh-inline"'.$params.'>
2289 <td valign="top" width="14">'.$editIcon.'</td>
2290 <td valign="top">'.$text.'</td>
2297 * API for getting CSH icons/text for use in backend modules.
2298 * TCA_DESCR will be loaded if it isn't already
2301 * @param string Table name ('_MOD_'+module name)
2302 * @param string Field name (CSH locallang main key)
2303 * @param string Back path
2304 * @param string Wrap code for icon-mode, splitted by "|". Not used for full-text mode.
2305 * @param boolean If set, the full text will never be shown (only icon). Useful for places where it will break the page if the table with full text is shown.
2306 * @param string Additional style-attribute content for wrapping table (full text mode only)
2307 * @return string HTML content for help text
2308 * @see helpText(), helpTextIcon()
2310 function cshItem($table,$field,$BACK_PATH,$wrap='',$onlyIconMode=FALSE, $styleAttrib='') {
2311 global $TCA_DESCR, $LANG, $BE_USER;
2312 if ($BE_USER->uc
['edit_showFieldHelp']) {
2313 $LANG->loadSingleTableDescription($table);
2315 if (is_array($TCA_DESCR[$table])) {
2316 // Creating CSH icon and short description:
2317 $fullText = t3lib_BEfunc
::helpText($table,$field,$BACK_PATH,$styleAttrib);
2318 $icon = t3lib_BEfunc
::helpTextIcon($table,$field,$BACK_PATH,$onlyIconMode);
2320 if ($fullText && !$onlyIconMode) {
2321 $output = $GLOBALS['LANG']->hscAndCharConv($fullText, false);
2323 #$output = '<span style="position:absolute; filter: alpha(opacity=50); -moz-opacity: 0.50;">'.$icon.'</span>';
2326 if ($output && $wrap) {
2327 $wrParts = explode('|',$wrap);
2328 $output = $wrParts[0].$output.$wrParts[1];
2338 * Returns a JavaScript string (for an onClick handler) which will load the alt_doc.php script that shows the form for editing of the record(s) you have send as params.
2339 * REMEMBER to always htmlspecialchar() content in href-properties to ampersands get converted to entities (XHTML requirement and XSS precaution)
2342 * @param string $params is parameters sent along to alt_doc.php. This requires a much more details description which you must seek in Inside TYPO3s documentation of the alt_doc.php API. And example could be '&edit[pages][123]=edit' which will show edit form for page record 123.
2343 * @param string $backPath must point back to the TYPO3_mainDir directory (where alt_doc.php is)
2344 * @param string $requestUri is an optional returnUrl you can set - automatically set to REQUEST_URI.
2346 * @see template::issueCommand()
2348 function editOnClick($params,$backPath='',$requestUri='') {
2349 $retUrl = 'returnUrl='.($requestUri==-1?
"'+T3_THIS_LOCATION+'":rawurlencode($requestUri?
$requestUri:t3lib_div
::getIndpEnv('REQUEST_URI')));
2350 return "window.location.href='".$backPath."alt_doc.php?".$retUrl.$params."'; return false;";
2354 * Returns a JavaScript string for viewing the page id, $id
2355 * It will detect the correct domain name if needed and provide the link with the right back path. Also it will re-use any window already open.
2358 * @param integer $id is page id
2359 * @param string $backpath must point back to TYPO3_mainDir (where the site is assumed to be one level above)
2360 * @param array If root line is supplied the function will look for the first found domain record and use that URL instead (if found)
2361 * @param string $anchor is optional anchor to the URL
2362 * @param string $altUrl is an alternative URL which - if set - will make all other parameters ignored: The function will just return the window.open command wrapped around this URL!
2363 * @param string Additional GET variables.
2364 * @param boolean If true, then the preview window will gain the focus.
2367 function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='',$addGetVars='',$switchFocus=TRUE) {
2372 if ($GLOBALS['BE_USER']->workspace
!=0) {
2373 $url = t3lib_div
::getIndpEnv('TYPO3_SITE_URL').TYPO3_mainDir
.'mod/user/ws/wsol_preview.php?id='.$id.$addGetVars.$anchor;
2376 $parts = parse_url(t3lib_div
::getIndpEnv('TYPO3_SITE_URL'));
2377 if (t3lib_BEfunc
::getDomainStartPage($parts['host'],$parts['path'])) {
2378 $preUrl_temp = t3lib_BEfunc
::firstDomainRecord($rootLine);
2381 $preUrl = $preUrl_temp ?
(t3lib_div
::getIndpEnv('TYPO3_SSL') ?
'https://' : 'http://').$preUrl_temp : $backPath.'..';
2382 $url = $preUrl.'/index.php?id='.$id.$addGetVars.$anchor;
2386 return "previewWin=window.open('".$url."','newTYPO3frontendWindow');".
2387 ($switchFocus ?
'previewWin.focus();' : '');
2391 * Returns the merged User/Page TSconfig for page id, $id.
2392 * Please read details about module programming elsewhere!
2395 * @param integer Page uid
2396 * @param string $TSref is an object string which determines the path of the TSconfig to return.
2399 function getModTSconfig($id,$TSref) {
2400 $pageTS_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref,t3lib_BEfunc
::getPagesTSconfig($id));
2401 $BE_USER_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref);
2402 $modTSconfig = t3lib_div
::array_merge_recursive_overrule($pageTS_modOptions,$BE_USER_modOptions);
2403 return $modTSconfig;
2407 * Returns a selector box "function menu" for a module
2408 * Requires the JS function jumpToUrl() to be available
2409 * See Inside TYPO3 for details about how to use / make Function menus
2412 * @param mixed $id is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
2413 * @param string $elementName it the form elements name, probably something like "SET[...]"
2414 * @param string $currentValue is the value to be selected currently.
2415 * @param array $menuItems is an array with the menu items for the selector box
2416 * @param string $script is the script to send the &id to, if empty it's automatically found
2417 * @param string $addParams is additional parameters to pass to the script.
2418 * @return string HTML code for selector box
2420 function getFuncMenu($mainParams,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
2421 if (is_array($menuItems)) {
2422 if (!is_array($mainParams)) {
2423 $mainParams = array('id' => $mainParams);
2425 $mainParams = t3lib_div
::implodeArrayForUrl('',$mainParams);
2428 $script = basename(PATH_thisScript
);
2429 $mainParams.= (t3lib_div
::_GET('M') ?
'&M='.rawurlencode(t3lib_div
::_GET('M')) : '');
2433 foreach($menuItems as $value => $label) {
2434 $options[] = '<option value="'.htmlspecialchars($value).'"'.(!strcmp($currentValue,$value)?
' selected="selected"':'').'>'.
2435 t3lib_div
::deHSCentities(htmlspecialchars($label)).
2438 if (count($options)) {
2439 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+this.options[this.selectedIndex].value,this);';
2442 <!-- Function Menu of module -->
2443 <select name="'.$elementName.'" onchange="'.htmlspecialchars($onChange).'">
2453 * Checkbox function menu.
2454 * Works like ->getFuncMenu() but takes no $menuItem array since this is a simple checkbox.
2457 * @param mixed $mainParams $id is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
2458 * @param string $elementName it the form elements name, probably something like "SET[...]"
2459 * @param string $currentValue is the value to be selected currently.
2460 * @param string $script is the script to send the &id to, if empty it's automatically found
2461 * @param string $addParams is additional parameters to pass to the script.
2462 * @param string Additional attributes for the checkbox input tag
2463 * @return string HTML code for checkbox
2464 * @see getFuncMenu()
2466 function getFuncCheck($mainParams,$elementName,$currentValue,$script='',$addparams='',$tagParams='') {
2467 if (!is_array($mainParams)) {
2468 $mainParams = array('id' => $mainParams);
2470 $mainParams = t3lib_div
::implodeArrayForUrl('',$mainParams);
2472 if (!$script) {basename(PATH_thisScript
);}
2473 $onClick = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+(this.checked?1:0),this);';
2474 return '<input type="checkbox" name="'.$elementName.'"'.($currentValue?
' checked="checked"':'').' onclick="'.htmlspecialchars($onClick).'"'.($tagParams?
' '.$tagParams:'').' />';
2478 * Input field function menu
2479 * Works like ->getFuncMenu() / ->getFuncCheck() but displays a input field instead which updates the script "onchange"
2482 * @param mixed $id is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
2483 * @param string $elementName it the form elements name, probably something like "SET[...]"
2484 * @param string $currentValue is the value to be selected currently.
2485 * @param integer Relative size of input field, max is 48
2486 * @param string $script is the script to send the &id to, if empty it's automatically found
2487 * @param string $addParams is additional parameters to pass to the script.
2488 * @return string HTML code for input text field.
2489 * @see getFuncMenu()
2491 function getFuncInput($mainParams,$elementName,$currentValue,$size=10,$script="",$addparams="") {
2492 if (!is_array($mainParams)) {
2493 $mainParams = array('id' => $mainParams);
2495 $mainParams = t3lib_div
::implodeArrayForUrl('',$mainParams);
2497 if (!$script) {basename(PATH_thisScript
);}
2498 $onChange = 'jumpToUrl(\''.$script.'?'.$mainParams.$addparams.'&'.$elementName.'=\'+escape(this.value),this);';
2499 return '<input type="text"'.$GLOBALS['TBE_TEMPLATE']->formWidth($size).' name="'.$elementName.'" value="'.htmlspecialchars($currentValue).'" onchange="'.htmlspecialchars($onChange).'" />';
2503 * Removes menu items from $itemArray if they are configured to be removed by TSconfig for the module ($modTSconfig)
2504 * See Inside TYPO3 about how to program modules and use this API.
2507 * @param array Module TS config array
2508 * @param array Array of items from which to remove items.
2509 * @param string $TSref points to the "object string" in $modTSconfig
2510 * @return array The modified $itemArray is returned.
2512 function unsetMenuItems($modTSconfig,$itemArray,$TSref) {
2513 // Getting TS-config options for this module for the Backend User:
2514 $conf = $GLOBALS['BE_USER']->getTSConfig($TSref,$modTSconfig);
2515 if (is_array($conf['properties'])) {
2516 reset($conf['properties']);
2517 while(list($key,$val)=each($conf['properties'])) {
2519 unset($itemArray[$key]);
2527 * Call to update the page tree frame (or something else..?) after
2528 * t3lib_BEfunc::getSetUpdateSignal('updatePageTree') -> will set the page tree to be updated.
2529 * t3lib_BEfunc::getSetUpdateSignal() -> will return some JavaScript that does the update (called in the typo3/template.php file, end() function)
2532 * @param string Whether to set or clear the update signal. When setting, this value contains strings telling WHAT to set. At this point it seems that the value "updatePageTree" is the only one it makes sense to set.
2533 * @return string HTML code (<script> section)
2535 function getSetUpdateSignal($set='') {
2537 $key = 't3lib_BEfunc::getSetUpdateSignal';
2541 $modData['set']=$set;
2542 $BE_USER->pushModuleData($key,$modData);
2544 $modData = $BE_USER->getModuleData($key,'ses');
2545 if (trim($modData['set'])) {
2546 $l=explode(',',$modData['set']);
2547 while(list(,$v)=each($l)) {
2549 case 'updatePageTree':
2550 case 'updateFolderTree':
2552 <script type="text/javascript">
2554 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
2555 top.content.nav_frame.refresh_nav();
2564 $BE_USER->pushModuleData($key,$modData);
2572 * Returns an array which is most backend modules becomes MOD_SETTINGS containing values from function menus etc. determining the function of the module.
2573 * This is kind of session variable management framework for the backend users.
2574 * If a key from MOD_MENU is set in the CHANGED_SETTINGS array (eg. a value is passed to the script from the outside), this value is put into the settings-array
2575 * Ultimately, see Inside TYPO3 for how to use this function in relation to your modules.
2578 * @param array MOD_MENU is an array that defines the options in menus.
2579 * @param array CHANGED_SETTINGS represents the array used when passing values to the script from the menus.
2580 * @param string modName is the name of this module. Used to get the correct module data.
2581 * @param string If type is 'ses' then the data is stored as session-lasting data. This means that it'll be wiped out the next time the user logs in.
2582 * @param string dontValidateList can be used to list variables that should not be checked if their value is found in the MOD_MENU array. Used for dynamically generated menus.
2583 * @param string List of default values from $MOD_MENU to set in the output array (only if the values from MOD_MENU are not arrays)
2584 * @return array The array $settings, which holds a key for each MOD_MENU key and the values of each key will be within the range of values for each menuitem
2586 function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='') {
2588 if ($modName && is_string($modName)) {
2589 // GETTING stored user-data from this module:
2590 $settings = $GLOBALS['BE_USER']->getModuleData($modName,$type);
2593 if (!is_array($settings)) {
2597 if (is_array($MOD_MENU)) {
2598 foreach ($MOD_MENU as $key=>$var) {
2599 // If a global var is set before entering here. eg if submitted, then it's substituting the current value the array.
2600 if (is_array($CHANGED_SETTINGS) && isset($CHANGED_SETTINGS[$key]) && strcmp($settings[$key],$CHANGED_SETTINGS[$key])) {
2601 $settings[$key] = (string)$CHANGED_SETTINGS[$key];
2604 // If the $var is an array, which denotes the existence of a menu, we check if the value is permitted
2605 if (is_array($var) && (!$dontValidateList ||
!t3lib_div
::inList($dontValidateList,$key))) {
2606 // If the setting is an array or not present in the menu-array, MOD_MENU, then the default value is inserted.
2607 if (is_array($settings[$key]) ||
!isset($MOD_MENU[$key][$settings[$key]])) {
2608 $settings[$key]=(string)key($var);
2612 if ($setDefaultList && !is_array($var)) { // Sets default values (only strings/checkboxes, not menus)
2613 if (t3lib_div
::inList($setDefaultList,$key) && !isset($settings[$key])) {
2614 $settings[$key]=$var;
2618 } else {die ('No menu!');}
2621 $GLOBALS['BE_USER']->pushModuleData($modName,$settings);
2625 } else {die ('Wrong module name: "'.$modName.'"');}
2640 /*******************************************
2644 *******************************************/
2647 * Set preview keyword, eg:
2648 * $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword('id='.$pageId.'&L='.$language.'&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS='.$this->workspace, $GLOBALS['BE_USER']->user['uid'], 120);
2650 * todo for sys_preview:
2651 * - Add a comment which can be shown to previewer in frontend in some way (plus maybe ability to write back, take other action?)
2652 * - Add possibility for the preview keyword to work in the backend as well: So it becomes a quick way to a certain action of sorts?
2654 * @param string Get variables to preview, eg. 'id=1150&L=0&ADMCMD_view=1&ADMCMD_editIcons=1&ADMCMD_previewWS=8'
2655 * @param string 32 byte MD5 hash keyword for the URL: "?ADMCMD_prev=[keyword]"
2656 * @param integer Time-To-Live for keyword
2657 * @return string Returns keyword to use in URL for ADMCMD_prev=
2659 function compilePreviewKeyword($getVarsStr, $beUserUid, $ttl=172800) {
2660 $field_array = array(
2661 'keyword' => md5(uniqid(microtime())),
2663 'endtime' => time()+
$ttl,
2664 'config' => serialize(array(
2665 'getVars' => $getVarsStr,
2666 'BEUSER_uid' => $beUserUid
2670 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_preview', $field_array);
2672 return $field_array['keyword'];
2676 * Unlock or Lock a record from $table with $uid
2677 * If $table and $uid is not set, then all locking for the current BE_USER is removed!
2680 * @param string Table name
2681 * @param integer Record uid
2682 * @param integer Record pid
2685 * @see t3lib_transferData::lockRecord(), alt_doc.php, db_layout.php, db_list.php, wizard_rte.php
2687 function lockRecords($table='',$uid=0,$pid=0) {
2688 $user_id = intval($GLOBALS['BE_USER']->user
['uid']);
2689 if ($table && $uid) {
2690 $fields_values = array(
2691 'userid' => $user_id,
2692 'tstamp' => $GLOBALS['EXEC_TIME'],
2693 'record_table' => $table,
2694 'record_uid' => $uid,
2695 'username' => $GLOBALS['BE_USER']->user
['username'],
2696 'record_pid' => $pid
2699 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values);
2701 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'userid='.intval($user_id));
2706 * Returns information about whether the record from table, $table, with uid, $uid is currently locked (edited by another user - which should issue a warning).
2707 * Notice: Locking is not strictly carried out since locking is abandoned when other backend scripts are activated - which means that a user CAN have a record "open" without having it locked. So this just serves as a warning that counts well in 90% of the cases, which should be sufficient.
2710 * @param string Table name
2711 * @param integer Record uid
2714 * @see class.db_layout.inc, alt_db_navframe.php, alt_doc.php, db_layout.php
2716 function isRecordLocked($table,$uid) {
2717 global $LOCKED_RECORDS;
2718 if (!is_array($LOCKED_RECORDS)) {
2719 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
2721 'sys_lockedrecords',
2722 'sys_lockedrecords.userid!='.intval($GLOBALS['BE_USER']->user
['uid']).'
2723 AND sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600)
2725 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2726 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]=$row;
2727 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg']=sprintf(
2728 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord'),
2730 t3lib_BEfunc
::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
2732 if ($row['record_pid'] && !isset($LOCKED_RECORDS[$row['record_table'].':'.$row['record_pid']])) {
2733 $LOCKED_RECORDS['pages:'.$row['record_pid']]['msg']=sprintf(
2734 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord_content'),
2736 t3lib_BEfunc
::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
2741 return $LOCKED_RECORDS[$table.':'.$uid];
2745 * Returns select statement for MM relations (as used by TCEFORMs etc)
2748 * @param array Configuration array for the field, taken from $TCA
2749 * @param string Field name
2750 * @param array TSconfig array from which to get further configuration settings for the field name
2751 * @param string Prefix string for the key "*foreign_table_where" from $fieldValue array
2752 * @return string Part of query
2754 * @see t3lib_transferData::renderRecord(), t3lib_TCEforms::foreignTable()
2756 function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='') {
2758 $foreign_table = $fieldValue['config'][$prefix.'foreign_table'];
2759 $rootLevel = $TCA[$foreign_table]['ctrl']['rootLevel'];
2761 $fTWHERE = $fieldValue['config'][$prefix.'foreign_table_where'];
2762 if (strstr($fTWHERE,'###REC_FIELD_')) {
2763 $fTWHERE_parts = explode('###REC_FIELD_',$fTWHERE);
2764 while(list($kk,$vv)=each($fTWHERE_parts)) {
2766 $fTWHERE_subpart = explode('###',$vv,2);
2767 $fTWHERE_parts[$kk]=$TSconfig['_THIS_ROW'][$fTWHERE_subpart[0]].$fTWHERE_subpart[1];
2770 $fTWHERE = implode('',$fTWHERE_parts);
2773 $fTWHERE = str_replace('###CURRENT_PID###',intval($TSconfig['_CURRENT_PID']),$fTWHERE);
2774 $fTWHERE = str_replace('###THIS_UID###',intval($TSconfig['_THIS_UID']),$fTWHERE);
2775 $fTWHERE = str_replace('###THIS_CID###',intval($TSconfig['_THIS_CID']),$fTWHERE);
2776 $fTWHERE = str_replace('###STORAGE_PID###',intval($TSconfig['_STORAGE_PID']),$fTWHERE);
2777 $fTWHERE = str_replace('###SITEROOT###',intval($TSconfig['_SITEROOT']),$fTWHERE);
2778 $fTWHERE = str_replace('###PAGE_TSCONFIG_ID###',intval($TSconfig[$field]['PAGE_TSCONFIG_ID']),$fTWHERE);
2779 $fTWHERE = str_replace('###PAGE_TSCONFIG_IDLIST###',$GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']),$fTWHERE);
2780 $fTWHERE = str_replace('###PAGE_TSCONFIG_STR###',$GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $foreign_table),$fTWHERE);
2782 // rootLevel = -1 is not handled 'properly' here - it goes as if it was rootLevel = 1 (that is pid=0)
2783 $wgolParts = $GLOBALS['TYPO3_DB']->splitGroupOrderLimit($fTWHERE);
2785 $queryParts = array(
2786 'SELECT' => t3lib_BEfunc
::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2787 'FROM' => $foreign_table,
2788 'WHERE' => $foreign_table.'.pid=0 '.
2789 t3lib_BEfunc
::deleteClause($foreign_table).' '.
2790 $wgolParts['WHERE'],
2791 'GROUPBY' => $wgolParts['GROUPBY'],
2792 'ORDERBY' => $wgolParts['ORDERBY'],
2793 'LIMIT' => $wgolParts['LIMIT']
2796 $pageClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
2797 if ($foreign_table!='pages') {
2798 $queryParts = array(
2799 'SELECT' => t3lib_BEfunc
::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2800 'FROM' => $foreign_table.',pages',
2801 'WHERE' => 'pages.uid='.$foreign_table.'.pid
2802 AND pages.deleted=0 '.
2803 t3lib_BEfunc
::deleteClause($foreign_table).
2804 ' AND '.$pageClause.' '.
2805 $wgolParts['WHERE'],
2806 'GROUPBY' => $wgolParts['GROUPBY'],
2807 'ORDERBY' => $wgolParts['ORDERBY'],
2808 'LIMIT' => $wgolParts['LIMIT']
2811 $queryParts = array(
2812 'SELECT' => t3lib_BEfunc
::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2814 'WHERE' => 'pages.deleted=0
2815 AND '.$pageClause.' '.
2816 $wgolParts['WHERE'],
2817 'GROUPBY' => $wgolParts['GROUPBY'],
2818 'ORDERBY' => $wgolParts['ORDERBY'],
2819 'LIMIT' => $wgolParts['LIMIT']
2824 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
2828 * Returns TSConfig for the TCEFORM object in Page TSconfig.
2832 * @param string Table name present in TCA
2833 * @param array Row from table
2835 * @see t3lib_transferData::renderRecord(), t3lib_TCEforms::setTSconfig(), SC_wizard_list::main(), SC_wizard_add::main()
2837 function getTCEFORM_TSconfig($table,$row) {
2838 t3lib_BEfunc
::fixVersioningPid($table,$row);
2841 $typeVal = t3lib_BEfunc
::getTCAtypeValue($table,$row);
2843 // Get main config for the table
2844 list($TScID,$cPid) = t3lib_BEfunc
::getTSCpid($table,$row['uid'],$row['pid']);
2846 $rootLine = t3lib_BEfunc
::BEgetRootLine($TScID,'',TRUE);
2848 $tempConf = $GLOBALS['BE_USER']->getTSConfig('TCEFORM.'.$table,t3lib_BEfunc
::getPagesTSconfig($TScID,$rootLine));
2849 if (is_array($tempConf['properties'])) {
2850 while(list($key,$val)=each($tempConf['properties'])) {
2851 if (is_array($val)) {
2852 $fieldN = substr($key,0,-1);
2853 $res[$fieldN] = $val;
2854 unset($res[$fieldN]['types.']);
2855 if (strcmp($typeVal,'') && is_array($val['types.'][$typeVal.'.'])) {
2856 $res[$fieldN] = t3lib_div
::array_merge_recursive_overrule($res[$fieldN],$val['types.'][$typeVal.'.']);
2862 $res['_CURRENT_PID']=$cPid;
2863 $res['_THIS_UID']=$row['uid'];
2864 $res['_THIS_CID']=$row['cid'];
2865 $res['_THIS_ROW']=$row; // So the row will be passed to foreign_table_where_query()
2868 while(list(,$rC)=each($rootLine)) {
2869 if (!$res['_STORAGE_PID']) $res['_STORAGE_PID']=intval($rC['storage_pid']);
2870 if (!$res['_SITEROOT']) $res['_SITEROOT']=$rC['is_siteroot']?
intval($rC['uid']):0;
2877 * Find the real PID of the record (with $uid from $table). This MAY be impossible if the pid is set as a reference to the former record or a page (if two records are created at one time).
2878 * NOTICE: Make sure that the input PID is never negative because the record was an offline version! Therefore, you should always use t3lib_BEfunc::fixVersioningPid($table,$row); on the data you input before calling this function!
2881 * @param string Table name
2882 * @param integer Record uid
2883 * @param integer Record pid, could be negative then pointing to a record from same table whose pid to find and return.
2886 * @see t3lib_TCEmain::copyRecord(), getTSCpid()
2888 function getTSconfig_pidValue($table,$uid,$pid) {
2890 if (t3lib_div
::testInt($pid)) { // If pid is an integer this takes precedence in our lookup.
2891 $thePidValue = intval($pid);
2892 if ($thePidValue<0) { // If ref to another record, look that record up.
2893 $pidRec = t3lib_BEfunc
::getRecord($table,abs($thePidValue),'pid');
2894 $thePidValue = is_array($pidRec) ?
$pidRec['pid'] : -2; // Returns -2 if the record did not exist.
2896 // ... else the pos/zero pid is just returned here.
2897 } else { // No integer pid and we are forced to look up the $pid
2898 $rr = t3lib_BEfunc
::getRecord($table,$uid,'pid'); // Try to fetch the record pid from uid. If the uid is 'NEW...' then this will of course return nothing...
2899 if (is_array($rr)) {
2900 $thePidValue = $rr['pid']; // Returning the 'pid' of the record
2901 } else $thePidValue=-1; // Returns -1 if the record with the pid was not found.
2904 return $thePidValue;
2908 * Return $uid if $table is pages and $uid is integer - otherwise the $pid
2911 * @param string Table name
2912 * @param integer Record uid
2913 * @param integer Record pid
2916 * @see t3lib_TCEforms::getTSCpid()
2918 function getPidForModTSconfig($table,$uid,$pid) {
2919 $retVal = ($table=='pages' && t3lib_div
::testInt($uid)) ?
$uid : $pid;
2924 * Returns the REAL pid of the record, if possible. If both $uid and $pid is strings, then pid=-1 is returned as an error indication.
2927 * @param string Table name
2928 * @param integer Record uid
2929 * @param integer Record pid
2930 * @return array Array of two integers; first is the REAL PID of a record and if its a new record negative values are resolved to the true PID, second value is the PID value for TSconfig (uid if table is pages, otherwise the pid)
2932 * @see t3lib_TCEmain::setHistory(), t3lib_TCEmain::process_datamap()
2934 function getTSCpid($table,$uid,$pid) {
2935 // If pid is negative (referring to another record) the pid of the other record is fetched and returned.
2936 $cPid = t3lib_BEfunc
::getTSconfig_pidValue($table,$uid,$pid);
2937 // $TScID is the id of $table=pages, else it's the pid of the record.
2938 $TScID = t3lib_BEfunc
::getPidForModTSconfig($table,