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