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