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