Added support for NULL fields in the database
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_befunc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
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.
13 *
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.
18 *
19 *
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.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Standard functions available for the TYPO3 backend.
29 * You are encouraged to use this class in your own applications (Backend Modules)
30 *
31 * Call ALL methods without making an object!
32 * Eg. to get a page-record 51 do this: 't3lib_BEfunc::getRecord('pages',51)'
33 *
34 * $Id$
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
37 * XHTML compliant
38 *
39 * @author Kasper Skaarhoj <kasper@typo3.com>
40 */
41 /**
42 * [CLASS/FUNCTION INDEX of SCRIPT]
43 *
44 *
45 *
46 * 160: class t3lib_BEfunc
47 *
48 * SECTION: SQL-related, selecting records, searching
49 * 181: function deleteClause($table)
50 * 205: function getRecord($table,$uid,$fields='*',$where='')
51 * 228: function getRecordRaw($table,$where='',$fields='*')
52 * 251: function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='')
53 * 284: function searchQuery($searchWords,$fields,$table='')
54 * 300: function listQuery($field,$value)
55 * 313: function splitTable_Uid($str)
56 * 329: function getSQLselectableList ($in_list,$tablename,$default_tablename)
57 * 358: function BEenableFields($table,$inv=0)
58 *
59 * SECTION: SQL-related, DEPRECIATED functions
60 * 422: function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='')
61 * 444: function DBcompileInsert($table,$fields_values)
62 * 458: function DBcompileUpdate($table,$where,$fields_values)
63 *
64 * SECTION: Page tree, TCA related
65 * 488: function BEgetRootLine ($uid,$clause='')
66 * 539: function getRecordPath($uid,$clause,$titleLimit)
67 * 564: function getExcludeFields()
68 * 599: function readPageAccess($id,$perms_clause)
69 * 629: function getTCAtypes($table,$rec,$useFieldNameAsKey=0)
70 * 675: function getTCAtypeValue($table,$rec)
71 * 698: function getSpecConfParts($str)
72 * 723: function getSpecConfParametersFromArray($pArr)
73 * 748: function getFlexFormDS($conf,$row,$table)
74 *
75 * SECTION: Caching related
76 * 853: function storeHash($hash,$data,$ident)
77 * 874: function getHash($hash,$expTime)
78 *
79 * SECTION: TypoScript related
80 * 911: function getPagesTSconfig($id,$rootLine='',$returnPartArray=0)
81 * 962: function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='')
82 * 1018: function implodeTSParams($p,$k='')
83 *
84 * SECTION: Users / Groups related
85 * 1056: function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='')
86 * 1075: function getGroupNames($fields='title,uid', $where='')
87 * 1093: function getListGroupNames($fields='title,uid')
88 * 1113: function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0)
89 * 1147: function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0)
90 *
91 * SECTION: Output related
92 * 1191: function daysUntil($tstamp)
93 * 1204: function date($tstamp)
94 * 1216: function datetime($value)
95 * 1229: function time($value)
96 * 1246: function calcAge ($seconds,$labels)
97 * 1273: function dateTimeAge($tstamp,$prefix=1,$date='')
98 * 1292: function titleAttrib($content='',$hsc=0)
99 * 1304: function titleAltAttrib($content)
100 * 1329: function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir='',$abs=0,$tparams='',$size='')
101 * 1398: function getThumbNail($thumbScript,$theFile,$tparams='',$size='')
102 * 1416: function titleAttribForPages($row,$perms_clause='',$includeAttrib=1)
103 * 1471: function getRecordIconAltText($row,$table='pages')
104 * 1506: function getLabelFromItemlist($table,$col,$key)
105 * 1533: function getItemLabel($table,$col,$printAllWrap='')
106 * 1559: function getRecordTitle($table,$row,$prep=0)
107 * 1596: function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0)
108 * 1691: function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0)
109 * 1716: function getFileIcon($ext)
110 * 1731: function getCommonSelectFields($table,$prefix)
111 * 1758: function makeConfigForm($configArray,$defaults,$dataPrefix)
112 *
113 * SECTION: Backend Modules API functions
114 * 1835: function helpTextIcon($table,$field,$BACK_PATH,$force=0)
115 * 1857: function helpText($table,$field,$BACK_PATH)
116 * 1878: function editOnClick($params,$backPath='',$requestUri='')
117 * 1895: function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='')
118 * 1922: function getModTSconfig($id,$TSref)
119 * 1944: function getFuncMenu($id,$elementName,$currentValue,$menuItems,$script='',$addparams='')
120 * 1974: function getFuncCheck($id,$elementName,$currentValue,$script='',$addparams='',$tagParams='')
121 * 1995: function getFuncInput($id,$elementName,$currentValue,$size=10,$script="",$addparams="")
122 * 2012: function unsetMenuItems($modTSconfig,$itemArray,$TSref)
123 * 2036: function getSetUpdateSignal($set='')
124 * 2087: function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
125 *
126 * SECTION: Core
127 * 2164: function lockRecords($table='',$uid=0,$pid=0)
128 * 2194: function isRecordLocked($table,$uid)
129 * 2235: function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='')
130 * 2317: function getTCEFORM_TSconfig($table,$row)
131 * 2365: function getTSconfig_pidValue($table,$uid,$pid)
132 * 2394: function getPidForModTSconfig($table,$uid,$pid)
133 * 2411: function getTSCpid($table,$uid,$pid)
134 * 2428: function firstDomainRecord($rootLine)
135 * 2451: function getDomainStartPage($domain, $path='')
136 * 2482: function RTEsetup($RTEprop,$table,$field,$type='')
137 * 2503: function isModuleSetInTBE_MODULES($modName)
138 *
139 * SECTION: Miscellaneous
140 * 2553: function typo3PrintError ($header,$text,$js='',$head=1)
141 * 2600: function getPathType_web_nonweb($path)
142 * 2613: function ADMCMD_previewCmds($pageinfo)
143 * 2636: function processParams($params)
144 * 2663: function getListOfBackendModules($name,$perms_clause,$backPath='',$script='index.php')
145 *
146 * TOTAL FUNCTIONS: 78
147 * (This index is automatically created/updated by the extension "extdeveval")
148 *
149 */
150
151
152 /**
153 * Standard functions available for the TYPO3 backend.
154 * Don't instantiate - call functions with "t3lib_BEfunc::" prefixed the function name.
155 *
156 * @author Kasper Skaarhoj <kasper@typo3.com>
157 * @package TYPO3
158 * @subpackage t3lib
159 */
160 class t3lib_BEfunc {
161
162
163
164 /*******************************************
165 *
166 * SQL-related, selecting records, searching
167 *
168 *******************************************/
169
170
171 /**
172 * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field is configured in $TCA for the tablename, $table
173 * 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!)
174 * 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.
175 *
176 * Usage: 80
177 *
178 * @param string Table name present in $TCA
179 * @return string WHERE clause for filtering out deleted records, eg " AND NOT tablename.deleted"
180 */
181 function deleteClause($table) {
182 global $TCA;
183 if ($TCA[$table]['ctrl']['delete']) {
184 return ' AND NOT '.$table.'.'.$TCA[$table]['ctrl']['delete'];
185 } else {
186 return '';
187 }
188 }
189
190 /**
191 * Gets record with uid=$uid from $table
192 * You can set $field to a list of fields (default is '*')
193 * Additional WHERE clauses can be added by $where (fx. ' AND blabla=1')
194 * Will automatically check if records has been deleted and if so, not return anything.
195 * $table must be found in $TCA
196 *
197 * Usage: 168
198 *
199 * @param string Table name present in $TCA
200 * @param integer UID of record
201 * @param string List of fields to select
202 * @param string Additional WHERE clause, eg. " AND blablabla=0"
203 * @return array Returns the row if found, otherwise nothing
204 */
205 function getRecord($table,$uid,$fields='*',$where='') {
206 if ($GLOBALS['TCA'][$table]) {
207 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid='.intval($uid).t3lib_BEfunc::deleteClause($table).$where);
208 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
209 return $row;
210 }
211 }
212 }
213
214 /**
215 * Returns the first record found from $table with $where as WHERE clause
216 * This function does NOT check if a record has the deleted flag set.
217 * $table does NOT need to be configured in $TCA
218 * The query used is simply this:
219 * $query='SELECT '.$fields.' FROM '.$table.' WHERE '.$where;
220 *
221 * Usage: 5 (ext: sys_todos)
222 *
223 * @param string Table name (not necessarily in TCA)
224 * @param string WHERE clause
225 * @param string $fields is a list of fields to select, default is '*'
226 * @return array First row found, if any
227 */
228 function getRecordRaw($table,$where='',$fields='*') {
229 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where);
230 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
231 return $row;
232 }
233 }
234
235 /**
236 * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
237 * The records are returned in an array
238 * If no records were selected, the function returns nothing
239 *
240 * Usage: 8
241 *
242 * @param string Table name present in $TCA
243 * @param string Field to select on
244 * @param string Value that $theField must match
245 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
246 * @param string Optional GROUP BY field(s), if none, supply blank string.
247 * @param string Optional ORDER BY field(s), if none, supply blank string.
248 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
249 * @return mixed Multidimensional array with selected records (if any is selected)
250 */
251 function getRecordsByField($theTable,$theField,$theValue,$whereClause='',$groupBy='',$orderBy='',$limit='') {
252 global $TCA;
253 if (is_array($TCA[$theTable])) {
254 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
255 '*',
256 $theTable,
257 $theField.'="'.$GLOBALS['TYPO3_DB']->quoteStr($theValue, $theTable).'"'.
258 t3lib_BEfunc::deleteClause($theTable).' '.
259 $whereClause, // whereClauseMightContainGroupOrderBy
260 $groupBy,
261 $orderBy,
262 $limit
263 );
264 $rows = array();
265 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
266 $rows[] = $row;
267 }
268 $GLOBALS['TYPO3_DB']->sql_free_result($res);
269 if (count($rows)) return $rows;
270 }
271 }
272
273 /**
274 * 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.
275 *
276 * Usage: 1 (class t3lib_fullsearch)
277 *
278 * @param array Array of search words
279 * @param array Array of fields
280 * @param string Table in which we are searching (for DBAL detection of quoteStr() method)
281 * @return string WHERE clause for search
282 * @depreciated Use $GLOBALS['TYPO3_DB']->searchQuery() directly!
283 */
284 function searchQuery($searchWords,$fields,$table='') {
285 return $GLOBALS['TYPO3_DB']->searchQuery($searchWords,$fields,$table);
286 }
287
288 /**
289 * Returns a WHERE clause that can find a value ($value) in a list field ($field)
290 * 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).
291 * Is nice to look up list-relations to records or files in TYPO3 database tables.
292 *
293 * Usage: 3
294 *
295 * @param string Table field name
296 * @param string Value to find in list
297 * @return string WHERE clause for a query
298 * @depreciated Use $GLOBALS['TYPO3_DB']->listQuery() directly!
299 */
300 function listQuery($field,$value) {
301 return $GLOBALS['TYPO3_DB']->listQuery($field,$value,'');
302 }
303
304 /**
305 * Makes an backwards explode on the $str and returns an array with ($table,$uid).
306 * Example: tt_content_45 => array('tt_content',45)
307 *
308 * Usage: 1
309 *
310 * @param string [tablename]_[uid] string to explode
311 * @return array
312 */
313 function splitTable_Uid($str) {
314 list($uid,$table) = explode('_',strrev($str),2);
315 return array(strrev($table),strrev($uid));
316 }
317
318 /**
319 * Returns a list of pure integers based on $in_list being a list of records with table-names prepended.
320 * 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.
321 *
322 * Usage: 1 (t3lib_userauthgroup)
323 *
324 * @param string Input list
325 * @param string Table name from which ids is returned
326 * @param string $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
327 * @return string List of ids
328 */
329 function getSQLselectableList ($in_list,$tablename,$default_tablename) {
330 $list = Array();
331 if ((string)trim($in_list)!='') {
332 $tempItemArray = explode(',',trim($in_list));
333 while(list($key,$val)=each($tempItemArray)) {
334 $val = strrev($val);
335 $parts = explode('_',$val,2);
336 if ((string)trim($parts[0])!='') {
337 $theID = intval(strrev($parts[0]));
338 $theTable = trim($parts[1]) ? strrev(trim($parts[1])) : $default_tablename;
339 if ($theTable==$tablename) {$list[]=$theID;}
340 }
341 }
342 }
343 return implode(',',$list);
344 }
345
346 /**
347 * Backend implementation of enableFields()
348 * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
349 * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
350 * $GLOBALS["SIM_EXEC_TIME"] is used for date.
351 *
352 * Usage: 5
353 *
354 * @param string $table is the table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $TCA.
355 * @param boolean $inv means that the query will select all records NOT VISIBLE records (inverted selection)
356 * @return string WHERE clause part
357 */
358 function BEenableFields($table,$inv=0) {
359 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
360 $query=array();
361 $invQuery=array();
362 if (is_array($ctrl)) {
363 if (is_array($ctrl['enablecolumns'])) {
364 if ($ctrl['enablecolumns']['disabled']) {
365 $field = $table.'.'.$ctrl['enablecolumns']['disabled'];
366 $query[]='NOT '.$field;
367 $invQuery[]=$field;
368 }
369 if ($ctrl['enablecolumns']['starttime']) {
370 $field = $table.'.'.$ctrl['enablecolumns']['starttime'];
371 $query[]='('.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
372 $invQuery[]='('.$field.'!=0 AND '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
373 }
374 if ($ctrl['enablecolumns']['endtime']) {
375 $field = $table.'.'.$ctrl['enablecolumns']['endtime'];
376 $query[]='('.$field.'=0 OR '.$field.'>'.$GLOBALS['SIM_EXEC_TIME'].')';
377 $invQuery[]='('.$field.'!=0 AND '.$field.'<='.$GLOBALS['SIM_EXEC_TIME'].')';
378 }
379 }
380 }
381 $outQ = ' AND '.($inv ? '('.implode(' OR ',$invQuery).')' : implode(' AND ',$query));
382
383 return $outQ;
384 }
385
386
387
388
389
390
391
392
393
394
395 /*******************************************
396 *
397 * SQL-related, DEPRECIATED functions
398 * (use t3lib_DB functions instead)
399 *
400 *******************************************/
401
402
403 /**
404 * Returns a SELECT query, selecting fields ($select) from two/three tables joined
405 * $local_table and $mm_table is mandatory. $foreign_table is optional.
406 * The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid
407 * 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.
408 * DEPRECIATED - 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.
409 *
410 * @param string Field list for SELECT
411 * @param string Tablename, local table
412 * @param string Tablename, relation table
413 * @param string Tablename, foreign table
414 * @param string Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
415 * @param string Optional GROUP BY field(s), if none, supply blank string.
416 * @param string Optional ORDER BY field(s), if none, supply blank string.
417 * @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
418 * @return string Full SQL query
419 * @depreciated
420 * @see t3lib_DB::exec_SELECT_mm_query()
421 */
422 function mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
423 $query = $GLOBALS['TYPO3_DB']->SELECTquery(
424 $select,
425 $local_table.','.$mm_table.($foreign_table?','.$foreign_table:''),
426 $local_table.'.uid='.$mm_table.'.uid_local'.($foreign_table?' AND '.$foreign_table.'.uid='.$mm_table.'.uid_foreign':'').' '.
427 $whereClause, // whereClauseMightContainGroupOrderBy
428 $groupBy,
429 $orderBy,
430 $limit
431 );
432 return $query;
433 }
434
435 /**
436 * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.
437 * DEPRECIATED - $GLOBALS['TYPO3_DB']->INSERTquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_INSERTquery()
438 *
439 * @param string Table name
440 * @param array Field values as key=>value pairs.
441 * @return string Full SQL query for INSERT
442 * @depreciated
443 */
444 function DBcompileInsert($table,$fields_values) {
445 return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
446 }
447
448 /**
449 * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values.
450 * DEPRECIATED - $GLOBALS['TYPO3_DB']->UPDATEquery() directly instead! But better yet, use $GLOBALS['TYPO3_DB']->exec_UPDATEquery()
451 *
452 * @param string Database tablename
453 * @param string WHERE clause, eg. "uid=1"
454 * @param array Field values as key=>value pairs.
455 * @return string Full SQL query for UPDATE
456 * @depreciated
457 */
458 function DBcompileUpdate($table,$where,$fields_values) {
459 return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
460 }
461
462
463
464
465
466
467
468
469
470
471 /*******************************************
472 *
473 * Page tree, TCA related
474 *
475 *******************************************/
476
477 /**
478 * 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.
479 * By default deleted pages are filtered.
480 * 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.
481 *
482 * Usage: 13
483 *
484 * @param integer Page id for which to create the root line.
485 * @param string $clause can be used to select other criteria. It would typically be where-clauses that stops the proces if we meet a page, the user has no reading access to.
486 * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
487 */
488 function BEgetRootLine ($uid,$clause='') {
489 $loopCheck = 100;
490 $theRowArray = Array();
491 $output=Array();
492 while ($uid!=0 && $loopCheck>0) {
493 $loopCheck--;
494 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
495 'pid,uid,title,TSconfig,is_siteroot,storage_pid',
496 'pages',
497 'uid='.intval($uid).' '.
498 t3lib_BEfunc::deleteClause('pages').' '.
499 $clause // whereClauseMightContainGroupOrderBy
500 );
501 if ($GLOBALS['TYPO3_DB']->sql_error()) {
502 debug($GLOBALS['TYPO3_DB']->sql_error(),1);
503 }
504 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
505 $uid = $row['pid'];
506 $theRowArray[]=$row;
507 } else {
508 break;
509 }
510 }
511 if ($uid==0) {$theRowArray[]=Array('uid'=>0,'title'=>'');}
512 if (is_array($theRowArray)) {
513 reset($theRowArray);
514 $c=count($theRowArray);
515 while(list($key,$val)=each($theRowArray)) {
516 $c--;
517 $output[$c]['uid'] = $val['uid'];
518 $output[$c]['title'] = $val['title'];
519 $output[$c]['TSconfig'] = $val['TSconfig'];
520 $output[$c]['is_siteroot'] = $val['is_siteroot'];
521 $output[$c]['storage_pid'] = $val['storage_pid'];
522 }
523 }
524 return $output;
525 }
526
527 /**
528 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
529 * Each part of the path will be limited to $titleLimit characters
530 * Deleted pages are filtered out.
531 *
532 * Usage: 23
533 *
534 * @param integer Page uid for which to create record path
535 * @param string $clause is additional where clauses, eg. "
536 * @param integer Title limit
537 * @param integer Title limit of Full title (typ. set to 1000 or so)
538 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
539 */
540 function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0) {
541 if (!$titleLimit) { $titleLimit=1000; }
542
543 $loopCheck = 100;
544 $output = $fullOutput = '/';
545 while ($uid!=0 && $loopCheck>0) {
546 $loopCheck--;
547 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid,title', 'pages', 'uid='.intval($uid).t3lib_BEfunc::deleteClause('pages').' AND '.$clause);
548 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
549 $uid = $row['pid'];
550 $output = '/'.t3lib_div::fixed_lgd(strip_tags($row['title']),$titleLimit).$output;
551 if ($fullTitleLimit) $fullOutput = '/'.t3lib_div::fixed_lgd(strip_tags($row['title']),$fullTitleLimit).$fullOutput;
552 } else {
553 break;
554 }
555 }
556
557 if ($fullTitleLimit) {
558 return array($output, $fullOutput);
559 } else {
560 return $output;
561 }
562 }
563
564 /**
565 * Returns an array with the exclude-fields as defined in TCA
566 * Used for listing the exclude-fields in be_groups forms
567 *
568 * Usage: 2 (t3lib_tceforms + t3lib_transferdata)
569 *
570 * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries
571 */
572 function getExcludeFields() {
573 global $TCA;
574 // All TCA keys:
575 $theExcludeArray = Array();
576 $tc_keys = array_keys($TCA);
577 foreach($tc_keys as $table) {
578 // Load table
579 t3lib_div::loadTCA($table);
580 // All field names configured:
581 if (is_array($TCA[$table]['columns'])) {
582 $f_keys = array_keys($TCA[$table]['columns']);
583 foreach($f_keys as $field) {
584 if ($TCA[$table]['columns'][$field]['exclude']) {
585 // Get Human Readable names of fields and table:
586 $Fname=$GLOBALS['LANG']->sl($TCA[$table]['ctrl']['title']).': '.$GLOBALS['LANG']->sl($TCA[$table]['columns'][$field]['label']);
587 // add entry:
588 $theExcludeArray[] = Array($Fname , $table.':'.$field);
589 }
590 }
591 }
592 }
593 return $theExcludeArray;
594 }
595
596 /**
597 * 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.
598 * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
599 * In any case ->isInWebMount must return true for the user (regardless of $perms_clause)
600 *
601 * Usage: 21
602 *
603 * @param integer Page uid for which to check read-access
604 * @param string $perms_clause is typically a value generated with $BE_USER->getPagePermsClause(1);
605 * @return array Returns page record if OK, otherwise false.
606 */
607 function readPageAccess($id,$perms_clause) {
608 if ((string)$id!='') {
609 $id = intval($id);
610 if (!$id) {
611 if ($GLOBALS['BE_USER']->isAdmin()) {
612 $path = '/';
613 $pageinfo['_thePath'] = $path;
614 return $pageinfo;
615 }
616 } else {
617 $pageinfo = t3lib_BEfunc::getRecord('pages',$id,'*',($perms_clause ? ' AND '.$perms_clause : ''));
618 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id,$perms_clause)) {
619 list($pageinfo['_thePath'],$pageinfo['_thePathFull']) = t3lib_BEfunc::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
620 return $pageinfo;
621 }
622 }
623 }
624 return false;
625 }
626
627 /**
628 * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
629 *
630 * Usage: 6
631 *
632 * @param string Table name (present in TCA)
633 * @param array Record from $table
634 * @param boolean If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
635 * @return array
636 */
637 function getTCAtypes($table,$rec,$useFieldNameAsKey=0) {
638 global $TCA;
639
640 t3lib_div::loadTCA($table);
641 if ($TCA[$table]) {
642
643 // Get type value:
644 $fieldValue = t3lib_BEfunc::getTCAtypeValue($table,$rec);
645
646 // Get typesConf
647 $typesConf = $TCA[$table]['types'][$fieldValue];
648
649 // Get fields list and traverse it
650 $fieldList = explode(',', $typesConf['showitem']);
651 $altFieldList = array();
652
653 // Traverse fields in types config and parse the configuration into a nice array:
654 foreach($fieldList as $k => $v) {
655 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = t3lib_div::trimExplode(';', $v);
656 $defaultExtras = is_array($TCA[$table]['columns'][$pFieldName]) ? $TCA[$table]['columns'][$pFieldName]['defaultExtras'] : '';
657 $specConfParts = t3lib_BEfunc::getSpecConfParts($pSpec, $defaultExtras);
658
659 $fieldList[$k]=array(
660 'field' => $pFieldName,
661 'title' => $pAltTitle,
662 'palette' => $pPalette,
663 'spec' => $specConfParts,
664 'origString' => $v
665 );
666 if ($useFieldNameAsKey) {
667 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
668 }
669 }
670 if ($useFieldNameAsKey) {
671 $fieldList = $altFieldList;
672 }
673
674 // Return array:
675 return $fieldList;
676 }
677 }
678
679 /**
680 * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $TCA
681 * If no "type" field is configured in the "ctrl"-section of the $TCA for the table, zero is used.
682 * 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)
683 *
684 * Usage: 7
685 *
686 * @param string Table name present in TCA
687 * @param array Record from $table
688 * @return string Field value
689 * @see getTCAtypes()
690 */
691 function getTCAtypeValue($table,$rec) {
692 global $TCA;
693
694 // 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.
695 t3lib_div::loadTCA($table);
696 if ($TCA[$table]) {
697 $field = $TCA[$table]['ctrl']['type'];
698 $fieldValue = $field ? ($rec[$field] ? $rec[$field] : 0) : 0;
699 if (!is_array($TCA[$table]['types'][$fieldValue])) $fieldValue = 1;
700 return $fieldValue;
701 }
702 }
703
704 /**
705 * Parses a part of the field lists in the "types"-section of $TCA arrays, namely the "special configuration" at index 3 (position 4)
706 * Elements are splitted by ":" and within those parts, parameters are splitted by "|".
707 * 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
708 *
709 * Usage: 3
710 *
711 * @param string Content from the "types" configuration of TCA (the special configuration) - see description of function
712 * @param string The ['defaultExtras'] value from field configuration
713 * @return array
714 */
715 function getSpecConfParts($str, $defaultExtras) {
716
717 // Add defaultExtras:
718 $specConfParts = t3lib_div::trimExplode(':', $defaultExtras.':'.$str, 1);
719
720 if (count($specConfParts)) {
721 foreach($specConfParts as $k2 => $v2) {
722 unset($specConfParts[$k2]);
723 if (ereg('(.*)\[(.*)\]',$v2,$reg)) {
724 $specConfParts[trim($reg[1])] = array(
725 'parameters' => t3lib_div::trimExplode('|', $reg[2], 1)
726 );
727 } else {
728 $specConfParts[trim($v2)] = 1;
729 }
730 }
731 } else {
732 $specConfParts = array();
733 }
734 return $specConfParts;
735 }
736
737 /**
738 * Takes an array of "[key]=[value]" strings and returns an array with the keys set as keys pointing to the value.
739 * Better see it in action! Find example in Inside TYPO3
740 *
741 * Usage: 6
742 *
743 * @param array Array of "[key]=[value]" strings to convert.
744 * @return array
745 */
746 function getSpecConfParametersFromArray($pArr) {
747 $out=array();
748 if (is_array($pArr)) {
749 reset($pArr);
750 while(list($k,$v)=each($pArr)) {
751 $parts=explode('=',$v,2);
752 if (count($parts)==2) {
753 $out[trim($parts[0])]=trim($parts[1]);
754 } else {
755 $out[$k]=$v;
756 }
757 }
758 }
759 return $out;
760 }
761
762 /**
763 * Finds the Data Structure for a FlexForm field
764 *
765 * @param array Field config array
766 * @param array Record data
767 * @param string The table name
768 * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
769 * @see t3lib_TCEforms::getSingleField_typeFlex()
770 */
771 function getFlexFormDS($conf,$row,$table) {
772
773 // Get pointer field etc from TCA-config:
774 $ds_pointerField = $conf['ds_pointerField'];
775 $ds_array = $conf['ds'];
776 $ds_tableField = $conf['ds_tableField'];
777 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
778
779
780 // Find source value:
781 $dataStructArray='';
782 if (is_array($ds_array)) { // If there is a data source array, that takes precedence
783 // If a pointer field is set, take the value from that field in the $row array and use as key.
784 if ($ds_pointerField) {
785 $srcPointer = $row[$ds_pointerField];
786 $srcPointer = isset($ds_array[$srcPointer]) ? $srcPointer : 'default';
787 } else $srcPointer='default';
788
789 // 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.
790 if (substr($ds_array[$srcPointer],0,5)=='FILE:') {
791 $file = t3lib_div::getFileAbsFileName(substr($ds_array[$srcPointer],5));
792 if ($file && @is_file($file)) {
793 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
794 } else $dataStructArray = 'The file "'.substr($dsSrc,5).'" in ds-array key "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
795 } else {
796 $dataStructArray = t3lib_div::xml2array($ds_array[$srcPointer]);
797 }
798
799 } elseif ($ds_pointerField) { // If pointer field AND possibly a table/field is set:
800 // Value of field pointed to:
801 $srcPointer = $row[$ds_pointerField];
802
803 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
804 if ($ds_searchParentField && !$srcPointer) {
805 $rr = t3lib_BEfunc::getRecord($table,$row['uid'],$ds_searchParentField); // Get the "pid" field - we cannot know that it is in the input record!
806 $uidAcc=array(); // Used to avoid looping, if any should happen.
807 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
808 while(!$srcPointer) {
809 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
810 'uid,'.$ds_pointerField.','.$ds_searchParentField.($subFieldPointer?','.$subFieldPointer:''),
811 $table,
812 'uid='.intval($rr[$ds_searchParentField]).t3lib_BEfunc::deleteClause($table)
813 );
814 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
815 if (!is_array($rr) || isset($uidAcc[$rr['uid']])) break; // break if no result from SQL db or if looping...
816 $uidAcc[$rr['uid']]=1;
817
818 $srcPointer = ($subFieldPointer && $rr[$subFieldPointer]) ? $rr[$subFieldPointer] : $rr[$ds_pointerField];
819 }
820 }
821
822 // If there is a srcPointer value:
823 if ($srcPointer) {
824 if (t3lib_div::testInt($srcPointer)) { // If integer, then its a record we will look up:
825 list($tName,$fName) = explode(':',$ds_tableField,2);
826 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
827 $dataStructRec = t3lib_BEfunc::getRecord($tName, $srcPointer);
828 $dataStructArray = t3lib_div::xml2array($dataStructRec[$fName]);
829 } else $dataStructArray = 'No tablename ('.$tName.') or fieldname ('.$fName.') was found an valid!';
830 } else { // Otherwise expect it to be a file:
831 $file = t3lib_div::getFileAbsFileName($srcPointer);
832 if ($file && @is_file($file)) {
833 $dataStructArray = t3lib_div::xml2array(t3lib_div::getUrl($file));
834 } else $dataStructArray='The file "'.$srcPointer.'" was not found ("'.$file.'")'; // Error message.
835 }
836 } else $dataStructArray='No source value in fieldname "'.$ds_pointerField.'"'; // Error message.
837 } else $dataStructArray='No proper configuration!';
838
839 return $dataStructArray;
840 }
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859 /*******************************************
860 *
861 * Caching related
862 *
863 *******************************************/
864
865 /**
866 * Stores the string value $data in the 'cache_hash' table with the hash key, $hash, and visual/symbolic identification, $ident
867 * IDENTICAL to the function by same name found in t3lib_page:
868 *
869 * Usage: 2
870 *
871 * @param string Hash key, 32 bytes hex
872 * @param string $data must be serialized before function call
873 * @param string Visual/symbolic identification (informational only)
874 * @return void
875 */
876 function storeHash($hash,$data,$ident) {
877 $insertFields = array(
878 'hash' => $hash,
879 'content' => $data,
880 'ident' => $ident,
881 'tstamp' => time()
882 );
883 $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"');
884 $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
885 }
886
887 /**
888 * Retrieves the string content stored with hash key, $hash, in cache_hash
889 * IDENTICAL to the function by same name found in t3lib_page:
890 *
891 * Usage: 2
892 *
893 * @param string Hash key, 32 bytes hex
894 * @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.
895 * @return string
896 */
897 function getHash($hash,$expTime) {
898 // if expTime is not set, the hash will never expire
899 $expTime = intval($expTime);
900 if ($expTime) {
901 $whereAdd = ' AND tstamp > '.(time()-$expTime);
902 }
903 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash="'.$GLOBALS['TYPO3_DB']->quoteStr($hash, 'cache_hash').'"'.$whereAdd);
904 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
905 return $row['content'];
906 }
907 }
908
909
910
911
912
913
914
915
916 /*******************************************
917 *
918 * TypoScript related
919 *
920 *******************************************/
921
922 /**
923 * Returns the Page TSconfig for page with id, $id
924 * Requires class "t3lib_TSparser"
925 *
926 * Usage: 26 (spec. in ext info_pagetsconfig)
927 *
928 * @param integer Page uid for which to create Page TSconfig
929 * @param array If $rootLine is an array, that is used as rootline, otherwise rootline is just calculated
930 * @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.
931 * @return array Page TSconfig
932 * @see t3lib_TSparser
933 */
934 function getPagesTSconfig($id,$rootLine='',$returnPartArray=0) {
935 $id=intval($id);
936 if (!is_array($rootLine)) {
937 $rootLine = t3lib_BEfunc::BEgetRootLine($id,'');
938 }
939 ksort($rootLine); // Order correctly, changed 030102
940 reset($rootLine);
941 $TSdataArray = array();
942 $TSdataArray['defaultPageTSconfig']=$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig']; // Setting default configuration:
943 while(list($k,$v)=each($rootLine)) {
944 $TSdataArray['uid_'.$v['uid']]=$v['TSconfig'];
945 }
946 $TSdataArray = t3lib_TSparser::checkIncludeLines_array($TSdataArray);
947 if ($returnPartArray) {
948 return $TSdataArray;
949 }
950
951 // Parsing the user TS (or getting from cache)
952 $userTS = implode($TSdataArray,chr(10).'[GLOBAL]'.chr(10));
953 $hash = md5('pageTS:'.$userTS);
954 $cachedContent = t3lib_BEfunc::getHash($hash,0);
955 $TSconfig = array();
956 if (isset($cachedContent)) {
957 $TSconfig = unserialize($cachedContent);
958 } else {
959 $parseObj = t3lib_div::makeInstance('t3lib_TSparser');
960 $parseObj->parse($userTS);
961 $TSconfig = $parseObj->setup;
962 t3lib_BEfunc::storeHash($hash,serialize($TSconfig),'PAGES_TSconfig');
963 }
964 return $TSconfig;
965 }
966
967 /**
968 * Updates Page TSconfig for a page with $id
969 * 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.
970 * $impParams can be supplied as already known Page TSconfig, otherwise it's calculated.
971 *
972 * THIS DOES NOT CHECK ANY PERMISSIONS. SHOULD IT?
973 * More documentation is needed.
974 *
975 * Usage: 1 (ext. direct_mail)
976 *
977 * @param integer Page id
978 * @param array Page TS array to write
979 * @param string Prefix for object paths
980 * @param array [Description needed.]
981 * @return void
982 * @internal
983 * @see implodeTSParams(), getPagesTSconfig()
984 */
985 function updatePagesTSconfig($id,$pageTS,$TSconfPrefix,$impParams='') {
986 $id=intval($id);
987 if (is_array($pageTS) && $id>0) {
988 if (!is_array($impParams)) {
989 $impParams =t3lib_BEfunc::implodeTSParams(t3lib_BEfunc::getPagesTSconfig($id));
990 }
991 reset($pageTS);
992 $set=array();
993 while(list($f,$v)=each($pageTS)) {
994 $f = $TSconfPrefix.$f;
995 if ((!isset($impParams[$f])&&trim($v)) || strcmp(trim($impParams[$f]),trim($v))) {
996 $set[$f]=trim($v);
997 }
998 }
999 if (count($set)) {
1000 // Get page record and TS config lines
1001 $pRec = t3lib_befunc::getRecord('pages',$id);
1002 $TSlines = explode(chr(10),$pRec['TSconfig']);
1003 $TSlines = array_reverse($TSlines);
1004 // Reset the set of changes.
1005 reset($set);
1006 while(list($f,$v)=each($set)) {
1007 reset($TSlines);
1008 $inserted=0;
1009 while(list($ki,$kv)=each($TSlines)) {
1010 if (substr($kv,0,strlen($f)+1)==$f.'=') {
1011 $TSlines[$ki]=$f.'='.$v;
1012 $inserted=1;
1013 break;
1014 }
1015 }
1016 if (!$inserted) {
1017 $TSlines = array_reverse($TSlines);
1018 $TSlines[]=$f.'='.$v;
1019 $TSlines = array_reverse($TSlines);
1020 }
1021 }
1022 $TSlines = array_reverse($TSlines);
1023
1024 // store those changes
1025 $TSconf = implode(chr(10),$TSlines);
1026
1027 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid='.intval($id), array('TSconfig' => $TSconf));
1028 }
1029 }
1030 }
1031
1032 /**
1033 * Implodes a multi dimensional TypoScript array, $p, into a one-dimentional array (return value)
1034 *
1035 * Usage: 3
1036 *
1037 * @param array TypoScript structure
1038 * @param string Prefix string
1039 * @return array Imploded TypoScript objectstring/values
1040 */
1041 function implodeTSParams($p,$k='') {
1042 $implodeParams=array();
1043 if (is_array($p)) {
1044 reset($p);
1045 while(list($kb,$val)=each($p)) {
1046 if (is_array($val)) {
1047 $implodeParams = array_merge($implodeParams,t3lib_BEfunc::implodeTSParams($val,$k.$kb));
1048 } else {
1049 $implodeParams[$k.$kb]=$val;
1050 }
1051 }
1052 }
1053 return $implodeParams;
1054 }
1055
1056
1057
1058
1059
1060
1061
1062
1063 /*******************************************
1064 *
1065 * Users / Groups related
1066 *
1067 *******************************************/
1068
1069 /**
1070 * Returns an array with be_users records of all user NOT DELETED sorted by their username
1071 * Keys in the array is the be_users uid
1072 *
1073 * Usage: 14 (spec. ext. "beuser" and module "web_perm")
1074 *
1075 * @param string Optional $fields list (default: username,usergroup,usergroup_cached_list,uid) can be used to set the selected fields
1076 * @param string Optional $where clause (fx. "AND username='pete'") can be used to limit query
1077 * @return array
1078 */
1079 function getUserNames($fields='username,usergroup,usergroup_cached_list,uid',$where='') {
1080 $be_user_Array=Array();
1081
1082 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_users'), '', 'username');
1083 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1084 $be_user_Array[$row['uid']]=$row;
1085 }
1086 return $be_user_Array;
1087 }
1088
1089 /**
1090 * Returns an array with be_groups records (title, uid) of all groups NOT DELETED sorted by their title
1091 *
1092 * Usage: 8 (spec. ext. "beuser" and module "web_perm")
1093 *
1094 * @param string Field list
1095 * @param string WHERE clause
1096 * @return array
1097 */
1098 function getGroupNames($fields='title,uid', $where='') {
1099 $be_group_Array = Array();
1100 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
1101 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1102 $be_group_Array[$row['uid']] = $row;
1103 }
1104 return $be_group_Array;
1105 }
1106
1107 /**
1108 * Returns an array with be_groups records (like ->getGroupNames) but:
1109 * - 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.
1110 *
1111 * Usage: 2 (module "web_perm" and ext. taskcenter)
1112 *
1113 * @param string Field list; $fields specify the fields selected (default: title,uid)
1114 * @return array
1115 */
1116 function getListGroupNames($fields='title,uid') {
1117 $exQ=' AND hide_in_lists=0';
1118 if (!$GLOBALS['BE_USER']->isAdmin()) {
1119 $exQ.=' AND uid IN ('.($GLOBALS['BE_USER']->user['usergroup_cached_list']?$GLOBALS['BE_USER']->user['usergroup_cached_list']:0).')';
1120 }
1121 return t3lib_BEfunc::getGroupNames($fields,$exQ);
1122 }
1123
1124 /**
1125 * Returns the array $usernames with the names of all users NOT IN $groupArray changed to the uid (hides the usernames!).
1126 * If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1127 * Takes $usernames (array made by t3lib_BEfunc::getUserNames()) and a $groupArray (array with the groups a certain user is member of) as input
1128 *
1129 * Usage: 8
1130 *
1131 * @param array User names
1132 * @param array Group names
1133 * @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1134 * @return array User names, blinded
1135 */
1136 function blindUserNames($usernames,$groupArray,$excludeBlindedFlag=0) {
1137 if (is_array($usernames) && is_array($groupArray)) {
1138 while(list($uid,$row)=each($usernames)) {
1139 $userN=$uid;
1140 $set=0;
1141 if ($row['uid']!=$GLOBALS['BE_USER']->user['uid']) {
1142 reset($groupArray);
1143 while(list(,$v)=each($groupArray)) {
1144 if ($v && t3lib_div::inList($row['usergroup_cached_list'],$v)) {
1145 $userN = $row['username'];
1146 $set=1;
1147 }
1148 }
1149 } else {
1150 $userN = $row['username'];
1151 $set=1;
1152 }
1153 $usernames[$uid]['username']=$userN;
1154 if ($excludeBlindedFlag && !$set) {unset($usernames[$uid]);}
1155 }
1156 }
1157 return $usernames;
1158 }
1159
1160 /**
1161 * Corresponds to blindUserNames but works for groups instead
1162 *
1163 * Usage: 2 (module web_perm)
1164 *
1165 * @param array Group names
1166 * @param array Group names (reference)
1167 * @param boolean If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1168 * @return array
1169 */
1170 function blindGroupNames($groups,$groupArray,$excludeBlindedFlag=0) {
1171 if (is_array($groups) && is_array($groupArray)) {
1172 while(list($uid,$row)=each($groups)) {
1173 $groupN=$uid;
1174 $set=0;
1175 if (t3lib_div::inArray($groupArray,$uid)) {
1176 $groupN=$row['title'];
1177 $set=1;
1178 }
1179 $groups[$uid]['title']=$groupN;
1180 if ($excludeBlindedFlag && !$set) {unset($groups[$uid]);}
1181 }
1182 }
1183 return $groups;
1184 }
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198 /*******************************************
1199 *
1200 * Output related
1201 *
1202 *******************************************/
1203
1204
1205
1206 /**
1207 * Returns the difference in days between input $tstamp and $EXEC_TIME
1208 *
1209 * Usage: 2 (class t3lib_BEfunc)
1210 *
1211 * @param integer Time stamp, seconds
1212 * @return integer
1213 */
1214 function daysUntil($tstamp) {
1215 $delta_t = $tstamp-$GLOBALS['EXEC_TIME'];
1216 return ceil($delta_t/(3600*24));
1217 }
1218
1219 /**
1220 * Returns $tstamp formatted as "ddmmyy" (According to $TYPO3_CONF_VARS['SYS']['ddmmyy'])
1221 *
1222 * Usage: 11
1223 *
1224 * @param integer Time stamp, seconds
1225 * @return string Formatted time
1226 */
1227 function date($tstamp) {
1228 return Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$tstamp);
1229 }
1230
1231 /**
1232 * Returns $tstamp formatted as "ddmmyy hhmm" (According to $TYPO3_CONF_VARS['SYS']['ddmmyy'] AND $TYPO3_CONF_VARS['SYS']['hhmm'])
1233 *
1234 * Usage: 28
1235 *
1236 * @param integer Time stamp, seconds
1237 * @return string Formatted time
1238 */
1239 function datetime($value) {
1240 return Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'].' '.$GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'],$value);
1241 }
1242
1243 /**
1244 * Returns $value (in seconds) formatted as hh:mm:ss
1245 * For instance $value = 3600 + 60*2 + 3 should return "01:02:03"
1246 *
1247 * Usage: 1 (class t3lib_BEfunc)
1248 *
1249 * @param integer Time stamp, seconds
1250 * @return string Formatted time
1251 */
1252 function time($value) {
1253 $hh = floor($value/3600);
1254 $min = floor(($value-$hh*3600)/60);
1255 $sec = $value-$hh*3600-$min*60;
1256 $l = sprintf('%02d',$hh).':'.sprintf('%02d',$min).':'.sprintf('%02d',$sec);
1257 return $l;
1258 }
1259
1260 /**
1261 * Returns the "age" of the number of $seconds inputted.
1262 *
1263 * Usage: 15
1264 *
1265 * @param integer $seconds could be the difference of a certain timestamp and time()
1266 * @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")
1267 * @return string Formatted time
1268 */
1269 function calcAge ($seconds,$labels) {
1270 $labelArr = explode('|',$labels);
1271 $prefix='';
1272 if ($seconds<0) {$prefix='-'; $seconds=abs($seconds);}
1273 if ($seconds<3600) {
1274 $seconds = round ($seconds/60).$labelArr[0];
1275 } elseif ($seconds<24*3600) {
1276 $seconds = round ($seconds/3600).$labelArr[1];
1277 } elseif ($seconds<365*24*3600) {
1278 $seconds = round ($seconds/(24*3600)).$labelArr[2];
1279 } else {
1280 $seconds = round ($seconds/(365*24*3600)).$labelArr[3];
1281 }
1282 return $prefix.$seconds;
1283 }
1284
1285 /**
1286 * Returns a formatted timestamp if $tstamp is set.
1287 * The date/datetime will be followed by the age in parenthesis.
1288 *
1289 * Usage: 3
1290 *
1291 * @param integer Time stamp, seconds
1292 * @param integer 1/-1 depending on polarity of age.
1293 * @param string $date=="date" will yield "dd:mm:yy" formatting, otherwise "dd:mm:yy hh:mm"
1294 * @return string
1295 */
1296 function dateTimeAge($tstamp,$prefix=1,$date='') {
1297 return $tstamp ?
1298 ($date=='date' ? t3lib_BEfunc::date($tstamp) : t3lib_BEfunc::datetime($tstamp)).
1299 ' ('.t3lib_BEfunc::calcAge($prefix*(time()-$tstamp),$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears')).')' : '';
1300 }
1301
1302 /**
1303 * Returns either title='' or alt='' attribute. This depends on the client browser and whether it supports title='' or not (which is the default)
1304 * If no $content is given only the attribute name is returned.
1305 * The returned attribute with content will have a leading space char.
1306 * Warning: Be careful to submit empty $content var - that will return just the attribute name!
1307 *
1308 * Usage: 203
1309 *
1310 * @param string String to set as title-attribute. If no $content is given only the attribute name is returned.
1311 * @param boolean If $hsc is set, then content of the attribute is htmlspecialchar()'ed (which is good for XHTML and other reasons...)
1312 * @return string
1313 * @depreciated The idea made sense with older browsers, but now all browsers should support the "title" attribute - so just hardcode the title attribute instead!
1314 */
1315 function titleAttrib($content='',$hsc=0) {
1316 global $CLIENT;
1317 $attrib= ($CLIENT['BROWSER']=='net'&&$CLIENT['VERSION']<5)||$CLIENT['BROWSER']=='konqu' ? 'alt' : 'title';
1318 return strcmp($content,'')?' '.$attrib.'="'.($hsc?htmlspecialchars($content):$content).'"' : $attrib;
1319 }
1320
1321 /**
1322 * Returns alt="" and title="" attributes with the value of $content.
1323 *
1324 * @param string Value for 'alt' and 'title' attributes (will be htmlspecialchars()'ed before output)
1325 * @return string
1326 */
1327 function titleAltAttrib($content) {
1328 $out='';
1329 $out.=' alt="'.htmlspecialchars($content).'"';
1330 $out.=' title="'.htmlspecialchars($content).'"';
1331 return $out;
1332 }
1333
1334 /**
1335 * Returns a linked image-tag for thumbnail(s) from a database row with a list of image files in a field
1336 * All $TYPO3_CONF_VARS['GFX']['imagefile_ext'] extension are made to thumbnails + ttf file (renders font-example)
1337 * Thumbsnails are linked to the show_item.php script which will display further details.
1338 *
1339 * Usage: 7
1340 *
1341 * @param array $row is the database row from the table, $table.
1342 * @param string Table name for $row (present in TCA)
1343 * @param string $field is pointing to the field with the list of image files
1344 * @param string Back path prefix for image tag src="" field
1345 * @param string Optional: $thumbScript os by default 'thumbs.php' if you don't set it otherwise
1346 * @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!)
1347 * @param boolean If set, uploaddir is NOT prepended with "../"
1348 * @param string Optional: $tparams is additional attributes for the image tags
1349 * @param integer Optional: $size is [w]x[h] of the thumbnail. 56 is default.
1350 * @return string Thumbnail image tag.
1351 */
1352 function thumbCode($row,$table,$field,$backPath,$thumbScript='',$uploaddir='',$abs=0,$tparams='',$size='') {
1353 global $TCA;
1354 // Load table.
1355 t3lib_div::loadTCA($table);
1356
1357 // Find uploaddir automatically
1358 $uploaddir = $uploaddir ? $uploaddir : $TCA[$table]['columns'][$field]['config']['uploadfolder'];
1359
1360 // Set thumbs-script:
1361 if (!$GLOBALS['TYPO3_CONF_VARS']['GFX']['thumbnails']) {
1362 $thumbScript='gfx/notfound_thumb.gif';
1363 } elseif(!$thumbScript) {
1364 $thumbScript='thumbs.php';
1365 }
1366 // Check and parse the size parameter
1367 $sizeParts=array();
1368 if ($size = trim($size)) {
1369 $sizeParts = explode('x', $size.'x'.$size);
1370 if(!intval($sizeParts[0])) $size='';
1371 }
1372
1373 // Traverse files:
1374 $thumbs = explode(',', $row[$field]);
1375 $thumbData='';
1376 while(list(,$theFile)=each($thumbs)) {
1377 if (trim($theFile)) {
1378 $fI = t3lib_div::split_fileref($theFile);
1379 $ext = $fI['fileext'];
1380 // New 190201 start
1381 $max=0;
1382 if (t3lib_div::inList('gif,jpg,png',$ext)) {
1383 $imgInfo=@getimagesize(PATH_site.$uploaddir.'/'.$theFile);
1384 if (is_array($imgInfo)) {$max = max($imgInfo);}
1385 }
1386 // use the original image if it's size fits to the thumbnail size
1387 if ($max && $max<=(count($sizeParts)&&max($sizeParts)?max($sizeParts):56)) {
1388 $url = $uploaddir.'/'.trim($theFile);
1389 $theFile = '../'.$url;
1390 $onClick='top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
1391 $thumbData.='<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="../'.$backPath.$url.'" '.$imgInfo[3].' hspace="2" border="0" title="'.trim($url).'"'.$tparams.' alt="" /></a> ';
1392 // New 190201 stop
1393 } elseif ($ext=='ttf' || t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],$ext)) {
1394 $theFile = ($abs?'':'../').$uploaddir.'/'.trim($theFile);
1395 $params = '&file='.rawurlencode($theFile);
1396 $params .= $size?'&size='.$size:'';
1397 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
1398 $onClick='top.launchView(\''.$theFile.'\',\'\',\''.$backPath.'\');return false;';
1399 $thumbData.='<a href="#" onclick="'.htmlspecialchars($onClick).'"><img src="'.htmlspecialchars($backPath.$url).'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /></a> ';
1400 } else {
1401 $icon = t3lib_BEfunc::getFileIcon($ext);
1402 $url = 'gfx/fileicons/'.$icon;
1403 $thumbData.='<img src="'.$backPath.$url.'" hspace="2" border="0" title="'.trim($theFile).'"'.$tparams.' alt="" /> ';
1404 }
1405 }
1406 }
1407 return $thumbData;
1408 }
1409
1410 /**
1411 * Returns single image tag to thumbnail
1412 *
1413 * Usage: 3
1414 *
1415 * @param string $thumbScript must point to "thumbs.php" relative to the script position
1416 * @param string $theFile must be the proper reference to the file thumbs.php should show
1417 * @param string $tparams are additional attributes for the image tag
1418 * @param integer $size is the size of the thumbnail send along to "thumbs.php"
1419 * @return string Image tag
1420 */
1421 function getThumbNail($thumbScript,$theFile,$tparams='',$size='') {
1422 $params = '&file='.rawurlencode($theFile);
1423 $params .= trim($size)?'&size='.trim($size):'';
1424 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
1425 $th='<img src="'.htmlspecialchars($url).'" title="'.trim(basename($theFile)).'"'.($tparams?" ".$tparams:"").' alt="" />';
1426 return $th;
1427 }
1428
1429 /**
1430 * Returns title-attribute information for a page-record informing about id, alias, doktype, hidden, starttime, endtime, fe_group etc.
1431 *
1432 * Usage: 8
1433 *
1434 * @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)
1435 * @param string $perms_clause is used to get the record path of the shortcut page, if any (and doktype==4)
1436 * @param boolean If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
1437 * @return string
1438 */
1439 function titleAttribForPages($row,$perms_clause='',$includeAttrib=1) {
1440 global $TCA,$LANG;
1441 $parts=array();
1442 $parts[] = 'id='.$row['uid'];
1443 if ($row['alias']) $parts[]=$LANG->sL($TCA['pages']['columns']['alias']['label']).' '.$row['alias'];
1444 if ($row['doktype']=='3') {
1445 $parts[]=$LANG->sL($TCA['pages']['columns']['url']['label']).' '.$row['url'];
1446 } elseif ($row['doktype']=='4') {
1447 if ($perms_clause) {
1448 $label = t3lib_BEfunc::getRecordPath(intval($row['shortcut']),$perms_clause,20);
1449 } else {
1450 $lRec = t3lib_BEfunc::getRecord('pages',intval($row['shortcut']),'title');
1451 $label = $lRec['title'];
1452 }
1453 if ($row['shortcut_mode']>0) {
1454 $label.=', '.$LANG->sL($TCA['pages']['columns']['shortcut_mode']['label']).' '.
1455 $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','shortcut_mode',$row['shortcut_mode']));
1456 }
1457 $parts[]=$LANG->sL($TCA['pages']['columns']['shortcut']['label']).' '.$label;
1458 } elseif ($row['doktype']=='7') {
1459 if ($perms_clause) {
1460 $label = t3lib_BEfunc::getRecordPath(intval($row['mount_pid']),$perms_clause,20);
1461 } else {
1462 $lRec = t3lib_BEfunc::getRecord('pages',intval($row['mount_pid']),'title');
1463 $label = $lRec['title'];
1464 }
1465 $parts[]=$LANG->sL($TCA['pages']['columns']['mount_pid']['label']).' '.$label;
1466 }
1467 if ($row['hidden']) $parts[]=$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.hidden');
1468 if ($row['starttime']) $parts[]=$LANG->sL($TCA['pages']['columns']['starttime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['starttime'],-1,'date');
1469 if ($row['endtime']) $parts[]=$LANG->sL($TCA['pages']['columns']['endtime']['label']).' '.t3lib_BEfunc::dateTimeAge($row['endtime'],-1,'date');
1470 if ($row['fe_group']) {
1471 if ($row['fe_group']<0) {
1472 $label = $LANG->sL(t3lib_BEfunc::getLabelFromItemlist('pages','fe_group',$row['fe_group']));
1473 } else {
1474 $lRec = t3lib_BEfunc::getRecord('fe_groups',$row['fe_group'],'title');
1475 $label = $lRec['title'];
1476 }
1477 $parts[]=$LANG->sL($TCA['pages']['columns']['fe_group']['label']).' '.$label;
1478 }
1479 $out = htmlspecialchars(implode(' - ',$parts));
1480 return $includeAttrib ? 'title="'.$out.'"' : $out;
1481 }
1482
1483 /**
1484 * Returns title-attribute information for ANY record (from a table defined in TCA of course)
1485 * 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.
1486 * "pages" table can be used as well and will return the result of ->titleAttribForPages() for that page.
1487 *
1488 * Usage: 10
1489 *
1490 * @param array Table row; $row is a row from the table, $table
1491 * @param string Table name
1492 * @return string
1493 */
1494 function getRecordIconAltText($row,$table='pages') {
1495 if ($table=='pages') {
1496 $out = t3lib_BEfunc::titleAttribForPages($row,'',0);
1497 } else {
1498 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1499
1500 $out='id='.$row['uid']; // Uid is added
1501 if ($table=='pages' && $row['alias']) {
1502 $out.=' / '.$row['alias'];
1503 }
1504 if ($ctrl['disabled']) { // Hidden ...
1505 $out.=($row[$ctrl['disabled']]?' - '.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.hidden'):'');
1506 }
1507 if ($ctrl['starttime']) {
1508 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
1509 $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').')';
1510 }
1511 }
1512 if ($row[$ctrl['endtime']]) {
1513 $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').')';
1514 }
1515 }
1516 return htmlspecialchars($out);
1517 }
1518
1519 /**
1520 * Returns the label of the first found entry in an "items" array from $TCA (tablename=$table/fieldname=$col) where the value is $key
1521 *
1522 * Usage: 9
1523 *
1524 * @param string Table name, present in $TCA
1525 * @param string Field name, present in $TCA
1526 * @param string items-array value to match
1527 * @return string Label for item entry
1528 */
1529 function getLabelFromItemlist($table,$col,$key) {
1530 global $TCA;
1531 // Load full TCA for $table
1532 t3lib_div::loadTCA($table);
1533
1534 // Check, if there is an "items" array:
1535 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col]) && is_array($TCA[$table]['columns'][$col]['config']['items'])) {
1536 // Traverse the items-array...
1537 reset($TCA[$table]['columns'][$col]['config']['items']);
1538 while(list($k,$v)=each($TCA[$table]['columns'][$col]['config']['items'])) {
1539 // ... and return the first found label where the value was equal to $key
1540 if (!strcmp($v[1],$key)) return $v[0];
1541 }
1542 }
1543 }
1544
1545 /**
1546 * Returns the label-value for fieldname $col in table, $table
1547 * 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>'
1548 *
1549 * Usage: 17
1550 *
1551 * @param string Table name, present in $TCA
1552 * @param string Field name
1553 * @param string Wrap value - set function description
1554 * @return string
1555 */
1556 function getItemLabel($table,$col,$printAllWrap='') {
1557 global $TCA;
1558 // Load full TCA for $table
1559 t3lib_div::loadTCA($table);
1560 // Check if column exists
1561 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
1562 // Re
1563 return $TCA[$table]['columns'][$col]['label'];
1564 }
1565 if ($printAllWrap) {
1566 $parts = explode('|',$printAllWrap);
1567 return $parts[0].$col.$parts[1];
1568 }
1569 }
1570
1571 /**
1572 * Returns the "title"-value in record, $row, from table, $table
1573 * The field(s) from which the value is taken is determined by the "ctrl"-entries 'label', 'label_alt' and 'label_alt_force'
1574 *
1575 * Usage: 26
1576 *
1577 * @param string Table name, present in TCA
1578 * @param array Row from table
1579 * @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
1580 * @return string
1581 */
1582 function getRecordTitle($table,$row,$prep=0) {
1583 global $TCA;
1584 if (is_array($TCA[$table])) {
1585 $t = $row[$TCA[$table]['ctrl']['label']];
1586 if ($TCA[$table]['ctrl']['label_alt'] && ($TCA[$table]['ctrl']['label_alt_force'] || !strcmp($t,''))) {
1587 $altFields=t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1);
1588 $tA=array();
1589 $tA[]=$t;
1590 while(list(,$fN)=each($altFields)) {
1591 $t = $tA[] = trim(strip_tags($row[$fN]));
1592 if (strcmp($t,'') && !$TCA[$table]['ctrl']['label_alt_force']) break;
1593 }
1594 if ($TCA[$table]['ctrl']['label_alt_force']) $t=implode(', ',$tA);
1595 }
1596 if ($prep) {
1597 $t = htmlspecialchars(t3lib_div::fixed_lgd($t,$GLOBALS['BE_USER']->uc['titleLen']));
1598 if (!strcmp(trim($t),'')) $t='<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>';
1599 }
1600 return $t;
1601 }
1602 }
1603
1604 /**
1605 * Returns a human readable output of a value from a record
1606 * 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.
1607 * $table/$col is tablename and fieldname
1608 * REMEMBER to pass the output through htmlspecialchars() if you output it to the browser! (To protect it from XSS attacks and be XHTML compliant)
1609 *
1610 * Usage: 24
1611 *
1612 * @param string Table name, present in TCA
1613 * @param string Field name, present in TCA
1614 * @param string $value is the value of that field from a selected record
1615 * @param integer $fixed_lgd_chars is the max amount of characters the value may occupy
1616 * @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")
1617 * @return string
1618 */
1619 function getProcessedValue($table,$col,$value,$fixed_lgd_chars=0,$defaultPassthrough=0) {
1620 global $TCA;
1621 // Load full TCA for $table
1622 t3lib_div::loadTCA($table);
1623 // Check if table and field is configured:
1624 if (is_array($TCA[$table]) && is_array($TCA[$table]['columns'][$col])) {
1625 // Depending on the fields configuration, make a meaningful output value.
1626 $theColConf = $TCA[$table]['columns'][$col]['config'];
1627 $l='';
1628 switch((string)$theColConf['type']) {
1629 case 'radio':
1630 $l=t3lib_BEfunc::getLabelFromItemlist($table,$col,$value);
1631 break;
1632 case 'select':
1633 if ($theColConf['MM']) {
1634 $l='N/A';
1635 } else {
1636 $l=t3lib_BEfunc::getLabelFromItemlist($table,$col,$value);
1637 $l=$GLOBALS['LANG']->sL($l);
1638 if ($theColConf['foreign_table'] && !$l && $TCA[$theColConf['foreign_table']]) {
1639 $rParts = t3lib_div::trimExplode(',',$value,1);
1640 reset($rParts);
1641 $lA=array();
1642 while(list(,$rVal)=each($rParts)) {
1643 $rVal = intval($rVal);
1644 if ($rVal>0) {
1645 $r=t3lib_BEfunc::getRecord($theColConf['foreign_table'],$rVal);
1646 } else {
1647 $r=t3lib_BEfunc::getRecord($theColConf['neg_foreign_table'],-$rVal);
1648 }
1649 if (is_array($r)) {
1650 $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);
1651 } else {
1652 $lA[]=$rVal?'['.$rVal.'!]':'';
1653 }
1654 }
1655 $l=implode(',',$lA);
1656 }
1657 }
1658 break;
1659 case 'check':
1660 if (!is_array($theColConf['items']) || count($theColConf['items'])==1) {
1661 $l = $value ? 'Yes' : '';
1662 } else {
1663 reset($theColConf['items']);
1664 $lA=Array();
1665 while(list($key,$val)=each($theColConf['items'])) {
1666 if ($value & pow(2,$key)) {$lA[]=$GLOBALS['LANG']->sL($val[0]);}
1667 }
1668 $l = implode($lA,', ');
1669 }
1670 break;
1671 case 'input':
1672 if ($value) {
1673 if (t3lib_div::inList($theColConf['eval'],'date')) {
1674 $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')).')';
1675 } elseif (t3lib_div::inList($theColConf['eval'],'time')) {
1676 $l = t3lib_BEfunc::time($value);
1677 } elseif (t3lib_div::inList($theColConf['eval'],'datetime')) {
1678 $l = t3lib_BEfunc::datetime($value);
1679 } else {
1680 $l = $value;
1681 }
1682 }
1683 break;
1684 default:
1685 if ($defaultPassthrough) {
1686 $l=$value;
1687 } elseif ($theColConf['MM']) {
1688 $l='N/A';
1689 } elseif ($value) {
1690 $l=t3lib_div::fixed_lgd(strip_tags($value),200);
1691 }
1692 break;
1693 }
1694 if ($fixed_lgd_chars) {
1695 return t3lib_div::fixed_lgd($l,$fixed_lgd_chars);
1696 } else {
1697 return $l;
1698 }
1699 }
1700 }
1701
1702 /**
1703 * 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.
1704 *
1705 * Usage: 2
1706 *
1707 * @param string Table name, present in TCA
1708 * @param string Field name
1709 * @param string Field value
1710 * @param integer $fixed_lgd_chars is the max amount of characters the value may occupy
1711 * @return string
1712 * @see getProcessedValue()
1713 */
1714 function getProcessedValueExtra($table,$fN,$fV,$fixed_lgd_chars=0) {
1715 global $TCA;
1716 $fVnew = t3lib_BEfunc::getProcessedValue($table,$fN,$fV,$fixed_lgd_chars);
1717 if (!isset($fVnew)) {
1718 if (is_array($TCA[$table])) {
1719 if ($fN==$TCA[$table]['ctrl']['tstamp'] || $fN==$TCA[$table]['ctrl']['crdate']) {
1720 $fVnew = t3lib_BEfunc::datetime($fV);
1721 } elseif ($fN=='pid'){
1722 $fVnew = t3lib_BEfunc::getRecordPath($fV,'1',20); // Fetches the path with no regard to the users permissions to select pages.
1723 } else {
1724 $fVnew = $fV;
1725 }
1726 }
1727 }
1728 return $fVnew;
1729 }
1730
1731 /**
1732 * Returns file icon name (from $FILEICONS) for the fileextension $ext
1733 *
1734 * Usage: 10
1735 *
1736 * @param string File extension, lowercase
1737 * @return string File icon filename
1738 */
1739 function getFileIcon($ext) {
1740 return $GLOBALS['FILEICONS'][$ext] ? $GLOBALS['FILEICONS'][$ext] : $GLOBALS['FILEICONS']['default'];
1741 }
1742
1743 /**
1744 * Returns fields for a table, $table, which would typically be interesting to select
1745 * This includes uid, the fields defined for title, icon-field.
1746 * 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)
1747 *
1748 * Usage: 3
1749 *
1750 * @param string Table name, present in TCA
1751 * @param string Table prefix
1752 * @return string List of fields.
1753 */
1754 function getCommonSelectFields($table,$prefix) {
1755 global $TCA;
1756 $fields=array();
1757 $fields[]=$prefix.'uid';
1758 $fields[]=$prefix.$TCA[$table]['ctrl']['label'];
1759 if ($TCA[$table]['ctrl']['label_alt']) {
1760 $secondFields = t3lib_div::trimExplode(',',$TCA[$table]['ctrl']['label_alt'],1);
1761 while(list(,$fieldN)=each($secondFields)) {
1762 $fields[]=$prefix.$fieldN;
1763 }
1764 }
1765 if ($TCA[$table]['ctrl']['selicon_field']) $fields[]=$prefix.$TCA[$table]['ctrl']['selicon_field'];
1766 return implode(',',$fields);
1767 }
1768
1769 /**
1770 * 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
1771 * <form>-tags must be supplied separately
1772 * 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.
1773 *
1774 * Usage: 1 (ext. direct_mail)
1775 *
1776 * @param array Field configuration code.
1777 * @param array Defaults
1778 * @param string Prefix for formfields
1779 * @return string HTML for a form.
1780 */
1781 function makeConfigForm($configArray,$defaults,$dataPrefix) {
1782 $params = $defaults;
1783 if (is_array($configArray)) {
1784 reset($configArray);
1785 $lines=array();
1786 while(list($fname,$config)=each($configArray)) {
1787 if (is_array($config)) {
1788 $lines[$fname]='<strong>'.htmlspecialchars($config[1]).'</strong><br />';
1789 $lines[$fname].=$config[2].'<br />';
1790 switch($config[0]) {
1791 case 'string':
1792 case 'short':
1793 $formEl = '<input type="text" name="'.$dataPrefix.'['.$fname.']" value="'.$params[$fname].'"'.$GLOBALS['TBE_TEMPLATE']->formWidth($config[0]=='short'?24:48).' />';
1794 break;
1795 case 'check':
1796 $formEl = '<input type="hidden" name="'.$dataPrefix.'['.$fname.']" value="0" /><input type="checkbox" name="'.$dataPrefix.'['.$fname.']" value="1"'.($params[$fname]?' checked="checked"':'').' />';
1797 break;
1798 case 'comment':
1799 $formEl = '';
1800 break;
1801 case 'select':
1802 reset($config[3]);
1803 $opt=array();
1804 while(list($k,$v)=each($config[3])) {
1805 $opt[]='<option value="'.htmlspecialchars($k).'"'.($params[$fname]==$k?' selected="selected"':'').'>'.htmlspecialchars($v).'</option>';
1806 }
1807 $formEl = '<select name="'.$dataPrefix.'['.$fname.']">'.implode('',$opt).'</select>';
1808 break;
1809 default:
1810 debug($config);
1811 break;
1812 }
1813 $lines[$fname].=$formEl;
1814 $lines[$fname].='<br /><br />';
1815 } else {
1816 $lines[$fname]='<hr />';
1817 if ($config) $lines[$fname].='<strong>'.strtoupper(htmlspecialchars($config)).'</strong><br />';
1818 if ($config) $lines[$fname].='<br />';
1819 }
1820 }
1821 }
1822 $out = implode('',$lines);
1823 $out.='<input type="submit" name="submit" value="Update configuration" />';
1824 return $out;
1825 }
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839 /*******************************************
1840 *
1841 * Backend Modules API functions
1842 *
1843 *******************************************/
1844
1845
1846 /**
1847 * Returns help-text icon if configured for.
1848 * TCA_DESCR must be loaded prior to this function and $BE_USER must have 'edit_showFieldHelp' set to 'icon', otherwise nothing is returned
1849 *
1850 * Usage: 6
1851 *
1852 * @param string Table name
1853 * @param string Field name
1854 * @param string Back path
1855 * @param boolean Force display of icon nomatter BE_USER setting for help
1856 * @return string HTML content for a help icon/text
1857 */
1858 function helpTextIcon($table,$field,$BACK_PATH,$force=0) {
1859 global $TCA_DESCR,$BE_USER;
1860 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && ($BE_USER->uc['edit_showFieldHelp']=='icon' || $force)) {
1861 $onClick = 'vHWin=window.open(\''.$BACK_PATH.'view_help.php?tfID='.($table.'.'.$field).'\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
1862 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
1863 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/helpbubble.gif','width="14" height="14"').' hspace="2" border="0" class="absmiddle"'.($GLOBALS['CLIENT']['FORMSTYLE']?' style="cursor:help;"':'').' alt="" />'.
1864 '</a>';
1865 }
1866 }
1867
1868 /**
1869 * Returns CSH help text (description), if configured for.
1870 * TCA_DESCR must be loaded prior to this function and $BE_USER must have "edit_showFieldHelp" set to "text", otherwise nothing is returned
1871 * Will automatically call t3lib_BEfunc::helpTextIcon() to get the icon for the text.
1872 *
1873 * Usage: 10
1874 *
1875 * @param string Table name
1876 * @param string Field name
1877 * @param string Back path
1878 * @return string HTML content for help text
1879 */
1880 function helpText($table,$field,$BACK_PATH) {
1881 global $TCA_DESCR,$BE_USER;
1882 if (is_array($TCA_DESCR[$table]) && is_array($TCA_DESCR[$table]['columns'][$field]) && $BE_USER->uc['edit_showFieldHelp']=='text') {
1883 $fDat = $TCA_DESCR[$table]['columns'][$field];
1884 return '<table border="0" cellpadding="2" cellspacing="0" width="90%"><tr><td valign="top" width="14">'.t3lib_BEfunc::helpTextIcon($table,$field,$BACK_PATH,
1885 $fDat['details']||$fDat['syntax']||$fDat['image_descr']||$fDat['image']||$fDat['seeAlso']
1886 ).'</td><td valign="top">'.$fDat['description'].'</td></tr></table>';
1887 }
1888 }
1889
1890 /**
1891 * 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.
1892 * REMEMBER to always htmlspecialchar() content in href-properties to ampersands get converted to entities (XHTML requirement and XSS precaution)
1893 *
1894 * Usage: 35
1895 *
1896 * @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.
1897 * @param string $backPath must point back to the TYPO3_mainDir directory (where alt_doc.php is)
1898 * @param string $requestUri is an optional returnUrl you can set - automatically set to REQUEST_URI.
1899 * @return string
1900 */
1901 function editOnClick($params,$backPath='',$requestUri='') {
1902 $retUrl = 'returnUrl='.($requestUri==-1?"'+T3_THIS_LOCATION+'":rawurlencode($requestUri?$requestUri:t3lib_div::getIndpEnv('REQUEST_URI')));
1903 return "document.location='".$backPath."alt_doc.php?".$retUrl.$params."'; return false;";
1904 }
1905
1906 /**
1907 * Returns a JavaScript string for viewing the page id, $id
1908 *
1909 * Usage: 8
1910 *
1911 * @param integer $id is page id
1912 * @param string $backpath must point back to TYPO3_mainDir (where the site is assumed to be one level above)
1913 * @param array If root line is supplied the function will look for the first found domain record and use that URL instead (if found)
1914 * @param string $anchor is optional anchor to the URL
1915 * @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!
1916 * @return string
1917 */
1918 function viewOnClick($id,$backPath='',$rootLine='',$anchor='',$altUrl='') {
1919 if ($altUrl) {
1920 $url = $altUrl;
1921 } else {
1922 if ($rootLine) {
1923 $parts = parse_url(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
1924 if (t3lib_BEfunc::getDomainStartPage($parts['host'],$parts['path'])) {
1925 $preUrl_temp = t3lib_BEfunc::firstDomainRecord($rootLine);
1926 }
1927 }
1928 $preUrl = $preUrl_temp ? 'http://'.$preUrl_temp : $backPath.'..';
1929 $url = $preUrl.'/index.php?id='.$id.$anchor;
1930 }
1931
1932 return "previewWin=window.open('".$url."','newTypo3FrontendWindow','status=1,menubar=1,resizable=1,location=1,scrollbars=1,toolbar=1');previewWin.focus();";
1933 }
1934
1935 /**
1936 * Returns the merged User/Page TSconfig for page id, $id.
1937 * Please read details about module programming elsewhere!
1938 *
1939 * Usage: 15
1940 *
1941 * @param integer Page uid
1942 * @param string $TSref is an object string which determines the path of the TSconfig to return.
1943 * @return array
1944 */
1945 function getModTSconfig($id,$TSref) {
1946 $pageTS_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref,t3lib_BEfunc::getPagesTSconfig($id));
1947 $BE_USER_modOptions = $GLOBALS['BE_USER']->getTSConfig($TSref);
1948 $modTSconfig = t3lib_div::array_merge_recursive_overrule($pageTS_modOptions,$BE_USER_modOptions);
1949 return $modTSconfig;
1950 }
1951
1952 /**
1953 * Returns a selector box "function menu" for a module
1954 * Requires the JS function jumpToUrl() to be available
1955 * See Inside TYPO3 for details about how to use / make Function menus
1956 *
1957 * Usage: 50
1958 *
1959 * @param string $id is the "&id=" parameter value to be sent to the module
1960 * @param string $elementName it the form elements name, probably something like "SET[...]"
1961 * @param string $currentValue is the value to be selected currently.
1962 * @param array $menuItems is an array with the menu items for the selector box
1963 * @param string $script is the script to send the &id to, if empty it's automatically found
1964 * @param string $addParams is additional parameters to pass to the script.
1965 * @return string HTML code for selector box
1966 */
1967 function getFuncMenu($id,$elementName,$currentValue,$menuItems,$script='',$addparams='') {
1968 if (is_array($menuItems)) {
1969 if (!$script) { $script=basename(PATH_thisScript); }
1970 $options='';
1971 reset($menuItems);
1972 while(list($value,$label)=each($menuItems)) {
1973 $options.='<option value="'.htmlspecialchars($value).'"'.(!strcmp($currentValue,$value)?' selected="selected"':'').'>'.t3lib_div::deHSCentities(htmlspecialchars($label)).'</option>';
1974 }
1975 if ($options) {
1976 $onChange= 'jumpToUrl(\''.$script.'?id='.rawurlencode($id).$addparams.'&'.$elementName.'=\'+this.options[this.selectedIndex].value,this);';
1977 return '<select name="'.$elementName.'" onchange="'.htmlspecialchars($onChange).'">'.$options.'</select>';
1978 }
1979 }
1980 }
1981
1982 /**
1983 * Checkbox function menu.
1984 * Works like ->getFuncMenu() but takes no $menuItem array since this is a simple checkbox.
1985 *
1986 * Usage: 34
1987 *
1988 * @param string $id is the "&id=" parameter value to be sent to the module
1989 * @param string $elementName it the form elements name, probably something like "SET[...]"
1990 * @param string $currentValue is the value to be selected currently.
1991 * @param string $script is the script to send the &id to, if empty it's automatically found
1992 * @param string $addParams is additional parameters to pass to the script.
1993 * @param string Additional attributes for the checkbox input tag
1994 * @return string HTML code for checkbox
1995 * @see getFuncMenu()
1996 */
1997 function getFuncCheck($id,$elementName,$currentValue,$script='',$addparams='',$tagParams='') {
1998 if (!$script) {basename(PATH_thisScript);}
1999 $onClick = 'jumpToUrl(\''.$script.'?id='.$id.$addparams.'&'.$elementName.'=\'+(this.checked?1:0),this);';
2000 return '<input type="checkbox" name="'.$elementName.'"'.($currentValue?' checked="checked"':'').' onclick="'.htmlspecialchars($onClick).'"'.($tagParams?' '.$tagParams:'').' />';
2001 }
2002
2003 /**
2004 * Input field function menu
2005 * Works like ->getFuncMenu() / ->getFuncCheck() but displays a input field instead which updates the script "onchange"
2006 *
2007 * Usage: 1
2008 *
2009 * @param string $id is the "&id=" parameter value to be sent to the module
2010 * @param string $elementName it the form elements name, probably something like "SET[...]"
2011 * @param string $currentValue is the value to be selected currently.
2012 * @param integer Relative size of input field, max is 48
2013 * @param string $script is the script to send the &id to, if empty it's automatically found
2014 * @param string $addParams is additional parameters to pass to the script.
2015 * @return string HTML code for input text field.
2016 * @see getFuncMenu()
2017 */
2018 function getFuncInput($id,$elementName,$currentValue,$size=10,$script="",$addparams="") {
2019 if (!$script) {basename(PATH_thisScript);}
2020 $onChange = 'jumpToUrl(\''.$script.'?id='.$id.$addparams.'&'.$elementName.'=\'+escape(this.value),this);';
2021 return '<input type="text"'.$GLOBALS['TBE_TEMPLATE']->formWidth($size).' name="'.$elementName.'" value="'.htmlspecialchars($currentValue).'" onchange="'.htmlspecialchars($onChange).'" />';
2022 }
2023
2024 /**
2025 * Removes menu items from $itemArray if they are configured to be removed by TSconfig for the module ($modTSconfig)
2026 * See Inside TYPO3 about how to program modules and use this API.
2027 *
2028 * Usage: 4
2029 *
2030 * @param array Module TS config array
2031 * @param array Array of items from which to remove items.
2032 * @param string $TSref points to the "object string" in $modTSconfig
2033 * @return array The modified $itemArray is returned.
2034 */
2035 function unsetMenuItems($modTSconfig,$itemArray,$TSref) {
2036 // Getting TS-config options for this module for the Backend User:
2037 $conf = $GLOBALS['BE_USER']->getTSConfig($TSref,$modTSconfig);
2038 if (is_array($conf['properties'])) {
2039 reset($conf['properties']);
2040 while(list($key,$val)=each($conf['properties'])) {
2041 if (!$val) {
2042 unset($itemArray[$key]);
2043 }
2044 }
2045 }
2046 return $itemArray;
2047 }
2048
2049 /**
2050 * Call to update the page tree frame (or something else..?) after
2051 * t3lib_BEfunc::getSetUpdateSignal('updatePageTree') -> will set the page tree to be updated.
2052 * t3lib_BEfunc::getSetUpdateSignal() -> will return some JavaScript that does the update (called in the typo3/template.php file, end() function)
2053 *
2054 * Usage: 11
2055 *
2056 * @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.
2057 * @return string HTML code (<script> section)
2058 */
2059 function getSetUpdateSignal($set='') {
2060 global $BE_USER;
2061 $key = 't3lib_BEfunc::getSetUpdateSignal';
2062 $out='';
2063 if ($set) {
2064 $modData=array();
2065 $modData['set']=$set;
2066 $BE_USER->pushModuleData($key,$modData);
2067 } else {
2068 $modData = $BE_USER->getModuleData($key,'ses');
2069 if (trim($modData['set'])) {
2070 $l=explode(',',$modData['set']);
2071 while(list(,$v)=each($l)) {
2072 switch($v) {
2073 case 'updatePageTree':
2074 case 'updateFolderTree':
2075 $out.='
2076 <script type="text/javascript">
2077 /*<![CDATA[*/
2078 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
2079 top.content.nav_frame.refresh_nav();
2080 }
2081 /*]]>*/
2082 </script>';
2083 break;
2084 }
2085 }
2086 $modData=array();
2087 $modData['set']='';
2088 $BE_USER->pushModuleData($key,$modData);
2089 }
2090 }
2091 return $out;
2092 }
2093
2094
2095 /**
2096 * Returns an array which is most backend modules becomes MOD_SETTINGS containing values from function menus etc. determining the function of the module.
2097 * This is kind of session variable management framework for the backend users.
2098 * 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
2099 * Ultimately, see Inside TYPO3 for how to use this function in relation to your modules.
2100 * Usage: 23
2101 *
2102 * @param array MOD_MENU is an array that defines the options in menus.
2103 * @param array CHANGED_SETTINGS represents the array used when passing values to the script from the menus.
2104 * @param string modName is the name of this module. Used to get the correct module data.
2105 * @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.
2106 * @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.
2107 * @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)
2108 * @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
2109 */
2110 function getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='') {
2111
2112 if ($modName && is_string($modName)) {
2113 // GETTING stored user-data from this module:
2114 $settings = $GLOBALS['BE_USER']->getModuleData($modName,$type);
2115
2116 $changed=0;
2117 if (!is_array($settings)) {
2118 $changed=1;
2119 $settings=array();
2120 }
2121 if (is_array($MOD_MENU)) {
2122 reset($MOD_MENU);
2123 while(list($key,$var)=each($MOD_MENU)) {
2124 // If a global var is set before entering here. eg if submitted, then it's substituting the current value the array.
2125 if (is_array($CHANGED_SETTINGS) && isset($CHANGED_SETTINGS[$key]) && strcmp($settings[$key],$CHANGED_SETTINGS[$key])) {
2126 $settings[$key] = (string)$CHANGED_SETTINGS[$key];
2127 $changed=1;
2128 }
2129 // If the $var is an array, which denotes the existence of a menu, we check if the value is permitted
2130 if (is_array($var) && (!$dontValidateList || !t3lib_div::inList($dontValidateList,$key))) {
2131 // If the setting is an array or not present in the menu-array, MOD_MENU, then the default value is inserted.
2132 if (is_array($settings[$key]) || !isset($MOD_MENU[$key][$settings[$key]])) {
2133 $settings[$key]=(string)key($var);
2134 $changed=1;
2135 }
2136 }
2137 if ($setDefaultList && !is_array($var)) { // Sets default values (only strings/checkboxes, not menus)
2138 if (t3lib_div::inList($setDefaultList,$key) && !isset($settings[$key])) {
2139 $settings[$key]=$var;
2140 }
2141 }
2142 }
2143 } else {die ('No menu!');}
2144
2145 if ($changed) {
2146 $GLOBALS['BE_USER']->pushModuleData($modName,$settings);
2147 }
2148
2149 return $settings;
2150 } else {die ('Wrong module name: "'.$modName.'"');}
2151 }
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165 /*******************************************
2166 *
2167 * Core
2168 *
2169 *******************************************/
2170
2171
2172
2173 /**
2174 * Unlock or Lock a record from $table with $uid
2175 * If $table and $uid is not set, then all locking for the current BE_USER is removed!
2176 *
2177 * Usage: 5
2178 *
2179 * @param string Table name
2180 * @param integer Record uid
2181 * @param integer Record pid
2182 * @return void
2183 * @internal
2184 * @see t3lib_transferData::lockRecord(), alt_doc.php, db_layout.php, db_list.php, wizard_rte.php
2185 */
2186 function lockRecords($table='',$uid=0,$pid=0) {
2187 $user_id = intval($GLOBALS['BE_USER']->user['uid']);
2188 if ($table && $uid) {
2189 $fields_values = array(
2190 'userid' => $user_id,
2191 'tstamp' => $GLOBALS['EXEC_TIME'],
2192 'record_table' => $table,
2193 'record_uid' => $uid,
2194 'username' => $GLOBALS['BE_USER']->user['username'],
2195 'record_pid' => $pid
2196 );
2197
2198 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_lockedrecords', $fields_values);
2199 } else {
2200 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_lockedrecords', 'userid='.intval($user_id));
2201 }
2202 }
2203
2204 /**
2205 * Returns information about whether the record from table, $table, with uid, $uid is currently locked (edited by another user - which should issue a warning).
2206 * 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.
2207 *
2208 * Usage: 5
2209 *
2210 * @param string Table name
2211 * @param integer Record uid
2212 * @return array
2213 * @internal
2214 * @see class.db_layout.inc, alt_db_navframe.php, alt_doc.php, db_layout.php
2215 */
2216 function isRecordLocked($table,$uid) {
2217 global $LOCKED_RECORDS;
2218 if (!is_array($LOCKED_RECORDS)) {
2219 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
2220 '*',
2221 'sys_lockedrecords',
2222 'sys_lockedrecords.userid!='.intval($GLOBALS['BE_USER']->user['uid']).'
2223 AND sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600)
2224 );
2225 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2226 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]=$row;
2227 $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg']=sprintf(
2228 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord'),
2229 $row['username'],
2230 t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
2231 );
2232 if ($row['record_pid'] && !isset($LOCKED_RECORDS[$row['record_table'].':'.$row['record_pid']])) {
2233 $LOCKED_RECORDS['pages:'.$row['record_pid']]['msg']=sprintf(
2234 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord_content'),
2235 $row['username'],
2236 t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
2237 );
2238 }
2239 }
2240 }
2241 return $LOCKED_RECORDS[$table.':'.$uid];
2242 }
2243
2244 /**
2245 * Returns select statement for MM relations (as used by TCEFORMs etc)
2246 *
2247 * Usage: 3
2248 *
2249 * @param array Configuration array for the field, taken from $TCA
2250 * @param string Field name
2251 * @param array TSconfig array from which to get further configuration settings for the field name
2252 * @param string Prefix string for the key "*foreign_table_where" from $fieldValue array
2253 * @return string Part of query
2254 * @internal
2255 * @see t3lib_transferData::renderRecord(), t3lib_TCEforms::foreignTable()
2256 */
2257 function exec_foreign_table_where_query($fieldValue,$field='',$TSconfig=array(),$prefix='') {
2258 global $TCA;
2259 $foreign_table = $fieldValue['config'][$prefix.'foreign_table'];
2260 $rootLevel = $TCA[$foreign_table]['ctrl']['rootLevel'];
2261
2262 $fTWHERE = $fieldValue['config'][$prefix.'foreign_table_where'];
2263 if (strstr($fTWHERE,'###REC_FIELD_')) {
2264 $fTWHERE_parts = explode('###REC_FIELD_',$fTWHERE);
2265 while(list($kk,$vv)=each($fTWHERE_parts)) {
2266 if ($kk) {
2267 $fTWHERE_subpart = explode('###',$vv,2);
2268 $fTWHERE_parts[$kk]=$TSconfig['_THIS_ROW'][$fTWHERE_subpart[0]].$fTWHERE_subpart[1];
2269 }
2270 }
2271 $fTWHERE = implode('',$fTWHERE_parts);
2272 }
2273
2274 $fTWHERE = str_replace('###CURRENT_PID###',intval($TSconfig['_CURRENT_PID']),$fTWHERE);
2275 $fTWHERE = str_replace('###THIS_UID###',intval($TSconfig['_THIS_UID']),$fTWHERE);
2276 $fTWHERE = str_replace('###THIS_CID###',intval($TSconfig['_THIS_CID']),$fTWHERE);
2277 $fTWHERE = str_replace('###STORAGE_PID###',intval($TSconfig['_STORAGE_PID']),$fTWHERE);
2278 $fTWHERE = str_replace('###SITEROOT###',intval($TSconfig['_SITEROOT']),$fTWHERE);
2279 $fTWHERE = str_replace('###PAGE_TSCONFIG_ID###',intval($TSconfig[$field]['PAGE_TSCONFIG_ID']),$fTWHERE);
2280 $fTWHERE = str_replace('###PAGE_TSCONFIG_IDLIST###',$GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']),$fTWHERE);
2281 $fTWHERE = str_replace('###PAGE_TSCONFIG_STR###',$GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $foreign_table),$fTWHERE);
2282
2283 // rootLevel = -1 is not handled 'properly' here - it goes as if it was rootLevel = 1 (that is pid=0)
2284 $wgolParts = $GLOBALS['TYPO3_DB']->splitGroupOrderLimit($fTWHERE);
2285 if ($rootLevel) {
2286 $queryParts = array(
2287 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2288 'FROM' => $foreign_table,
2289 'WHERE' => $foreign_table.'.pid=0 '.
2290 t3lib_BEfunc::deleteClause($foreign_table).' '.
2291 $wgolParts['WHERE'],
2292 'GROUPBY' => $wgolParts['GROUPBY'],
2293 'ORDERBY' => $wgolParts['ORDERBY'],
2294 'LIMIT' => $wgolParts['LIMIT']
2295 );
2296 } else {
2297 $pageClause = $GLOBALS['BE_USER']->getPagePermsClause(1);
2298 if ($foreign_table!='pages') {
2299 $queryParts = array(
2300 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2301 'FROM' => $foreign_table.',pages',
2302 'WHERE' => 'pages.uid='.$foreign_table.'.pid
2303 AND NOT pages.deleted '.
2304 t3lib_BEfunc::deleteClause($foreign_table).
2305 ' AND '.$pageClause.' '.
2306 $wgolParts['WHERE'],
2307 'GROUPBY' => $wgolParts['GROUPBY'],
2308 'ORDERBY' => $wgolParts['ORDERBY'],
2309 'LIMIT' => $wgolParts['LIMIT']
2310 );
2311 } else {
2312 $queryParts = array(
2313 'SELECT' => t3lib_BEfunc::getCommonSelectFields($foreign_table,$foreign_table.'.'),
2314 'FROM' => 'pages',
2315 'WHERE' => 'NOT pages.deleted
2316 AND '.$pageClause.' '.
2317 $wgolParts['WHERE'],
2318 'GROUPBY' => $wgolParts['GROUPBY'],
2319 'ORDERBY' => $wgolParts['ORDERBY'],
2320 'LIMIT' => $wgolParts['LIMIT']
2321 );
2322 }
2323 }
2324
2325 return $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
2326 }
2327
2328 /**
2329 * Returns TSConfig for the TCEFORM object in Page TSconfig.
2330 * Used in TCEFORMs
2331 *
2332 * Usage: 4
2333 *
2334 * @param string Table name present in TCA
2335 * @param array Row from table
2336 * @return array
2337 * @see t3lib_transferData::renderRecord(), t3lib_TCEforms::setTSconfig(), SC_wizard_list::main(), SC_wizard_add::main()
2338 */
2339 function getTCEFORM_TSconfig($table,$row) {
2340 $res = array();
2341 $typeVal = t3lib_BEfunc::getTCAtypeValue($table,$row);
2342
2343 // Get main config for the table
2344 list($TScID,$cPid) = t3lib_BEfunc::getTSCpid($table,$row['uid'],$row['pid']);
2345
2346 $rootLine = t3lib_BEfunc::BEgetRootLine($TScID,'');
2347 if ($TScID>=0) {
2348 $tempConf = $GLOBALS['BE_USER']->getTSConfig('TCEFORM.'.$table,t3lib_BEfunc::getPagesTSconfig($TScID,$rootLine));
2349 if (is_array($tempConf['properties'])) {
2350 while(list($key,$val)=each($tempConf['properties'])) {
2351 if (is_array($val)) {
2352 $fieldN = substr($key,0,-1);
2353 $res[$fieldN] = $val;
2354 unset($res[$fieldN]['types.']);
2355 if (strcmp($typeVal,'') && is_array($val['types.'][$typeVal.'.'])) {
2356 $res[$fieldN] = t3lib_div::array_merge_recursive_overrule($res[$fieldN],$val['types.'][$typeVal.'.']);
2357 }
2358 }
2359 }
2360 }
2361 }
2362 $res['_CURRENT_PID']=$cPid;
2363 $res['_THIS_UID']=$row['uid'];
2364 $res['_THIS_CID']=$row['cid'];
2365 $res['_THIS_ROW']=$row; // So the row will be passed to foreign_table_where_query()
2366 reset($rootLine);
2367 while(list(,$rC)=each($rootLine)) {
2368 if (!$res['_STORAGE_PID']) $res['_STORAGE_PID']=intval($rC['storage_pid']);
2369 if (!$res['_SITEROOT']) $res['_SITEROOT']=$rC['is_siteroot']?intval($rC['uid']):0;
2370 }
2371
2372 return $res;
2373 }
2374
2375 /**
2376 * 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).
2377 *
2378 * Usage: 2
2379 *
2380 * @param string Table name
2381 * @param integer Record uid
2382 * @param integer Record pid
2383 * @return integer
2384 * @internal
2385 * @see t3lib_TCEmain::copyRecord(), getTSCpid()
2386 */
2387 function getTSconfig_pidValue($table,$uid,$pid) {
2388 if (t3lib_div::testInt($pid)) { // If pid is an integer this takes precedence in our lookup.
2389 $thePidValue = intval($pid);
2390 if ($thePidValue<0) { // If ref to another record, look that record up.
2391 $pidRec = t3lib_BEfunc::getRecord($table,abs($thePidValue),'pid');
2392 $thePidValue= is_array($pidRec) ? $pidRec['pid'] : -2; // Returns -2 if the record did not exist.
2393 }
2394 // ... else the pos/zero pid is just returned here.
2395 } else { // No integer pid and we are forced to look up the $pid
2396 $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...
2397 if (is_array($rr)) {
2398 $thePidValue = $rr['pid']; // Returning the 'pid' of the record
2399 } else $thePidValue=-1; // Returns -1 if the record with the pid was not found.
2400 }
2401 return $thePidValue;
2402 }
2403
2404 /**
2405 * Return $uid if $table is pages and $uid is integer - otherwise the $pid
2406 *
2407 * Usage: 1
2408 *
2409 * @param string Table name
2410 * @param integer Record uid
2411 * @param integer Record pid
2412 * @return integer
2413 * @internal
2414 * @see t3lib_TCEforms::getTSCpid()
2415 */
2416 function getPidForModTSconfig($table,$uid,$pid) {
2417 $retVal = ($table=='pages' && t3lib_div::testInt($uid)) ? $uid : $pid;
2418 return $retVal;
2419 }
2420
2421 /**
2422 * 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.
2423 *
2424 * Usage: 8
2425 *
2426 * @param string Table name
2427 * @param integer Record uid
2428 * @param integer Record pid
2429 * @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)
2430 * @internal
2431 * @see t3lib_TCEmain::setHistory(), t3lib_TCEmain::process_datamap()
2432 */
2433 function getTSCpid($table,$uid,$pid) {
2434 // If pid is negative (referring to another record) the pid of the other record is fetched and returned.
2435 $cPid = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$pid);
2436 // $TScID is the id of $table=pages, else it's the pid of the record.
2437 $TScID = t3lib_BEfunc::getPidForModTSconfig($table,$uid,$cPid);
2438
2439 return array($TScID,$cPid);
2440 }
2441
2442 /**
2443 * Returns first found domain record "domainName" (without trailing slash) if found in the input $rootLine
2444 *
2445 * Usage: 2
2446 *
2447 * @param array Root line array
2448 * @return string Domain name, if found.
2449 */
2450 function firstDomainRecord($rootLine) {
2451 if (t3lib_extMgm::isLoaded('cms')) {
2452 reset($rootLine);
2453 while(list(,$row)=each($rootLine)) {
2454 $dRec = t3lib_BEfunc::getRecordsByField('sys_domain','pid',$row['uid'],' AND redirectTo="" AND hidden=0', '', 'sorting');
2455 if (is_array($dRec)) {
2456 reset($dRec);
2457 $dRecord = current($dRec);
2458 return ereg_replace('\/$','',$dRecord['domainName']);
2459 }
2460 }
2461 }
2462 }
2463
2464 /**
2465 * Returns the sys_domain record for $domain, optionally with $path appended.
2466 *
2467 * Usage: 2
2468 *
2469 * @param string Domain name
2470 * @param string Appended path
2471 * @return array Domain record, if found
2472 */
2473 function getDomainStartPage($domain, $path='') {
2474 if (t3lib_extMgm::isLoaded('cms')) {
2475 $domain = explode(':',$domain);
2476 $domain = strtolower(ereg_replace('\.$','',$domain[0]));
2477 // path is calculated.
2478 $path = trim(ereg_replace('\/[^\/]*$','',$path));
2479 // stuff:
2480 $domain.=$path;
2481
2482 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('sys_domain.*', 'pages,sys_domain', '
2483 pages.uid=sys_domain.pid
2484 AND NOT sys_domain.hidden
2485 AND (sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain, 'sys_domain').'" or sys_domain.domainName="'.$GLOBALS['TYPO3_DB']->quoteStr($domain.'/', 'sys_domain').'")'.
2486 t3lib_BEfunc::deleteClause('pages'),
2487 '', '', '1');
2488 return $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
2489 }
2490 }
2491
2492 /**
2493 * Returns overlayered RTE setup from an array with TSconfig. Used in TCEforms and TCEmain
2494 *
2495 * Usage: 8
2496 *
2497 * @param array The properties of Page TSconfig in the key "RTE."
2498 * @param string Table name
2499 * @param string Field name
2500 * @param string Type value of the current record (like from CType of tt_content)
2501 * @return array Array with the configuration for the RTE
2502 * @internal
2503 */
2504 function RTEsetup($RTEprop,$table,$field,$type='') {
2505 $thisConfig = is_array($RTEprop['default.']) ? $RTEprop['default.'] : array();
2506 $thisFieldConf = $RTEprop['config.'][$table.'.'][$field.'.'];
2507 if (is_array($thisFieldConf)) {
2508 unset($thisFieldConf['types.']);
2509 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig,$thisFieldConf);
2510 }
2511 if ($type && is_array($RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.'])) {
2512 $thisConfig = t3lib_div::array_merge_recursive_overrule($thisConfig,$RTEprop['config.'][$table.'.'][$field.'.']['types.'][$type.'.']);
2513 }
2514 return $thisConfig;
2515 }
2516
2517 /**
2518 * Returns first possible RTE object if available.
2519 *
2520 * @return mixed If available, returns RTE object, otherwise an array of messages from possible RTEs
2521 */
2522 function &RTEgetObj() {
2523
2524 // If no RTE object has been set previously, try to create it:
2525 if (!isset($GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'])) {
2526
2527 // Set the object string to blank by default:
2528 $GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'] = array();
2529
2530 // Traverse registered RTEs:
2531 if (is_array($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'])) {
2532 foreach($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_reg'] as $extKey => $rteObjCfg) {
2533 $rteObj = &t3lib_div::getUserObj($rteObjCfg['objRef']);
2534 if (is_object($rteObj)) {
2535 if ($rteObj->isAvailable()) {
2536 $GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'] = &$rteObj;
2537 break;
2538 } else {
2539 $GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'], $rteObj->errorLog);
2540 }
2541 }
2542 }
2543 }
2544
2545 if (!count($GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'])) {
2546 $GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'][] = 'No RTEs configured at all';
2547 }
2548 }
2549
2550 // Return RTE object (if any!)
2551 return $GLOBALS['TYPO3_CONF_VARS']['T3_VAR']['RTEobj'];
2552 }
2553
2554 /**
2555 * Returns true if $modName is set and is found as a main- or submodule in $TBE_MODULES array
2556 *
2557 * Usage: 1
2558 *
2559 * @param string Module name
2560 * @return boolean
2561 */
2562 function isModuleSetInTBE_MODULES($modName) {
2563 reset($GLOBALS['TBE_MODULES']);
2564 $loaded=array();
2565 while(list($mkey,$list)=each($GLOBALS['TBE_MODULES'])) {
2566 $loaded[$mkey]=1;
2567 if (trim($list)) {
2568 $subList = t3lib_div::trimExplode(',',$list,1);
2569 while(list(,$skey)=each($subList)) {
2570 $loaded[$mkey.'_'.$skey]=1;
2571 }
2572 }
2573 }
2574 return $modName && isset($loaded[$modName]);
2575 }
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594 /*******************************************
2595 *
2596 * Miscellaneous
2597 *
2598 *******************************************/
2599
2600
2601 /**
2602 * Print error message with header, text etc.
2603 *
2604 * Usage: 19
2605 *
2606 * @param string Header string
2607 * @param string Content string
2608 * @param boolean Will return an alert() with the content of header and text.
2609 * @param boolean Print header.
2610 * @return void
2611 */
2612 function typo3PrintError ($header,$text,$js='',$head=1) {
2613 // This prints out a TYPO3 error message.
2614 // If $js is set the message will be output in JavaScript
2615 if ($js) {
2616 echo"alert('".t3lib_div::slashJS($header.'\n'.$text)."');";
2617 } else {
2618 echo $head?'<html>
2619 <head>
2620 <title>Error!</title>
2621 </head>
2622 <body bgcolor="white" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">':'';
2623 echo '<div align="center">
2624 <table border="0" cellspacing="0" cellpadding="0" width="333">
2625 <tr>
2626 <td align="center">'.
2627 ($GLOBALS['TBE_STYLES']['logo_login']?'<img src="'.$GLOBALS['BACK_PATH'].$GLOBALS['TBE_STYLES']['logo_login'].'" alt="" />':'<img src="'.$GLOBALS['BACK_PATH'].'gfx/typo3logo.gif" width="333" height="43" vspace="10" />').
2628 '</td>
2629 </tr>
2630 <tr>
2631 <td bgcolor="black">
2632 <table width="100%" border="0" cellspacing="1" cellpadding="10">
2633 <tr>
2634 <td bgcolor="#F4F0E8">
2635 <font face="verdana,arial,helvetica" size="2">';
2636 echo '<b><center><font size="+1">'.$header.'</font></center></b><br />'.$text;
2637 echo ' </font>
2638 </td>
2639 </tr>
2640 </table>
2641 </td>
2642 </tr>
2643 </table>
2644 </div>';
2645 echo $head?'
2646 </body>
2647 </html>':'';
2648 }
2649 }
2650
2651 /**
2652 * Returns "web" if the $path (absolute) is within the DOCUMENT ROOT - and thereby qualifies as a "web" folder.
2653 *
2654 * Usage: 4
2655 *
2656 * @param string Path to evaluate
2657 * @return boolean
2658 */
2659 function getPathType_web_nonweb($path) {
2660 return t3lib_div::isFirstPartOfStr($path,t3lib_div::getIndpEnv('TYPO3_DOCUMENT_ROOT')) ? 'web' : '';
2661 }
2662
2663 /**
2664 * Creates ADMCMD parameters for the "viewpage" extension / "cms" frontend
2665 *
2666 * Usage: 1
2667 *
2668 * @param array Page record
2669 * @return string Query-parameters
2670 * @internal
2671 */
2672 function ADMCMD_previewCmds($pageinfo) {
2673 if ($pageinfo['fe_group']>0) {
2674 $simUser = '&ADMCMD_simUser='.$pageinfo['fe_group'];
2675 }
2676 if ($pageinfo['starttime']>time()) {
2677 $simTime = '&ADMCMD_simTime='.$pageinfo['starttime'];
2678 }
2679 if ($pageinfo['endtime']<time() && $pageinfo['endtime']!=0) {
2680 $simTime = '&ADMCMD_simTime='.($pageinfo['endtime']-1);
2681 }
2682 return $simUser.$simTime;
2683 }
2684
2685 /**
2686 * Returns an array with key=>values based on input text $params
2687 * $params is exploded by line-breaks and each line is supposed to be on the syntax [key] = [some value]
2688 * These pairs will be parsed into an array an returned.
2689 *
2690 * Usage: 1
2691 *
2692 * @param string String of parameters on multiple lines to parse into key-value pairs (see function description)
2693 * @return array
2694 */
2695 function processParams($params) {
2696 $paramArr=array();
2697 $lines=explode(chr(10),$params);
2698 while(list(,$val)=each($lines)) {
2699 $val = trim($val);
2700 if ($val) {
2701 $pair = explode('=',$val,2);
2702 $paramArr[trim($pair[0])] = trim($pair[1]);
2703 }
2704 }
2705 return $paramArr;
2706 }
2707
2708 /**
2709 * Returns "list of backend modules". Most likely this will be obsolete soon / removed. Don't use.
2710 *
2711 * Usage: 3
2712 *
2713 * @param array Module names in array. Must be "addslashes()"ed
2714 * @param string Perms clause for SQL query
2715 * @param string Backpath
2716 * @param string The URL/script to jump to (used in A tag)
2717 * @return array Two keys, rows and list
2718 * @internal
2719 * @depreciated
2720 * @obsolete
2721 */
2722 function getListOfBackendModules($name,$perms_clause,$backPath='',$script='index.php') {
2723 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'doktype!=255 AND module IN ("'.implode('","',$name).'") AND'.$perms_clause.t3lib_BEfunc::deleteClause('pages'));
2724 if (!$GLOBALS['TYPO3_DB']->sql_num_rows($res)) return false;
2725
2726 $out='';
2727 $theRows=array();
2728 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
2729 $theRows[]=$row;
2730 $out.='<span class="nobr"><a href="'.htmlspecialchars($script.'?id='.$row['uid']).'">'.
2731 t3lib_iconWorks::getIconImage('pages',$row,$backPath,'title="'.htmlspecialchars(t3lib_BEfunc::getRecordPath($row['uid'],$perms_clause,20)).'" align="top"').
2732 htmlspecialchars($row['title']).
2733 '</a></span><br />';
2734 }
2735 return array('rows'=>$theRows,'list'=>$out);
2736 }
2737 }
2738 ?>