2 namespace TYPO3\CMS\Backend\Utility
;
4 /***************************************************************
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
30 * Standard functions available for the TYPO3 backend.
31 * You are encouraged to use this class in your own applications (Backend Modules)
32 * Don't instantiate - call functions with "\TYPO3\CMS\Backend\Utility\BackendUtility::" prefixed the function name.
34 * Call ALL methods without making an object!
35 * Eg. to get a page-record 51 do this: '\TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages',51)'
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 class BackendUtility
{
41 /*******************************************
43 * SQL-related, selecting records, searching
45 *******************************************/
47 * Returns the WHERE clause " AND NOT [tablename].[deleted-field]" if a deleted-field is configured in $GLOBALS['TCA'] for the tablename, $table
48 * This function should ALWAYS be called in the backend for selection on tables which are configured in $GLOBALS['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!)
49 * 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.
51 * @param string $table Table name present in $GLOBALS['TCA']
52 * @param string $tableAlias Table alias if any
53 * @return string WHERE clause for filtering out deleted records, eg " AND tablename.deleted=0
55 static public function deleteClause($table, $tableAlias = '') {
56 if ($GLOBALS['TCA'][$table]['ctrl']['delete']) {
57 return ' AND ' . ($tableAlias ?
$tableAlias : $table) . '.' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0';
64 * Gets record with uid = $uid from $table
65 * You can set $field to a list of fields (default is '*')
66 * Additional WHERE clauses can be added by $where (fx. ' AND blabla = 1')
67 * Will automatically check if records has been deleted and if so, not return anything.
68 * $table must be found in $GLOBALS['TCA']
70 * @param string $table Table name present in $GLOBALS['TCA']
71 * @param integer $uid UID of record
72 * @param string $fields List of fields to select
73 * @param string $where Additional WHERE clause, eg. " AND blablabla = 0
74 * @param boolean $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
75 * @return array Returns the row if found, otherwise nothing
77 static public function getRecord($table, $uid, $fields = '*', $where = '', $useDeleteClause = TRUE) {
78 if ($GLOBALS['TCA'][$table]) {
79 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, 'uid=' . intval($uid) . ($useDeleteClause ? self
::deleteClause($table) : '') . $where);
80 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
81 $GLOBALS['TYPO3_DB']->sql_free_result($res);
89 * Like getRecord(), but overlays workspace version if any.
91 * @param string $table Table name present in $GLOBALS['TCA']
92 * @param integer $uid UID of record
93 * @param string $fields List of fields to select
94 * @param string $where Additional WHERE clause, eg. " AND blablabla = 0
95 * @param boolean $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
96 * @param boolean $unsetMovePointers If TRUE the function does not return a "pointer" row for moved records in a workspace
97 * @return array Returns the row if found, otherwise nothing
99 static public function getRecordWSOL($table, $uid, $fields = '*', $where = '', $useDeleteClause = TRUE, $unsetMovePointers = FALSE) {
100 if ($fields !== '*') {
101 $internalFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::uniqueList($fields . ',uid,pid');
102 $row = self
::getRecord($table, $uid, $internalFields, $where, $useDeleteClause);
103 self
::workspaceOL($table, $row, -99, $unsetMovePointers);
104 if (is_array($row)) {
105 foreach (array_keys($row) as $key) {
106 if (!\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($fields, $key) && $key[0] !== '_') {
112 $row = self
::getRecord($table, $uid, $fields, $where, $useDeleteClause);
113 self
::workspaceOL($table, $row, -99, $unsetMovePointers);
119 * Returns the first record found from $table with $where as WHERE clause
120 * This function does NOT check if a record has the deleted flag set.
121 * $table does NOT need to be configured in $GLOBALS['TCA']
122 * The query used is simply this:
123 * $query = 'SELECT ' . $fields . ' FROM ' . $table . ' WHERE ' . $where;
125 * @param string $table Table name (not necessarily in TCA)
126 * @param string $where WHERE clause
127 * @param string $fields $fields is a list of fields to select, default is '*'
128 * @return array First row found, if any, FALSE otherwise
130 static public function getRecordRaw($table, $where = '', $fields = '*') {
132 if (FALSE !== ($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $table, $where, '', '', '1'))) {
133 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
134 $GLOBALS['TYPO3_DB']->sql_free_result($res);
140 * Returns records from table, $theTable, where a field ($theField) equals the value, $theValue
141 * The records are returned in an array
142 * If no records were selected, the function returns nothing
144 * @param string $theTable Table name present in $GLOBALS['TCA']
145 * @param string $theField Field to select on
146 * @param string $theValue Value that $theField must match
147 * @param string $whereClause Optional additional WHERE clauses put in the end of the query. DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!
148 * @param string $groupBy Optional GROUP BY field(s), if none, supply blank string.
149 * @param string $orderBy Optional ORDER BY field(s), if none, supply blank string.
150 * @param string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.
151 * @param boolean $useDeleteClause Use the deleteClause to check if a record is deleted (default TRUE)
152 * @return mixed Multidimensional array with selected records (if any is selected)
154 static public function getRecordsByField($theTable, $theField, $theValue, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '', $useDeleteClause = TRUE) {
155 if (is_array($GLOBALS['TCA'][$theTable])) {
156 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
159 $theField . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($theValue, $theTable) .
160 ($useDeleteClause ? self
::deleteClause($theTable) . ' ' : '') .
161 self
::versioningPlaceholderClause($theTable) . ' ' .
168 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
171 $GLOBALS['TYPO3_DB']->sql_free_result($res);
179 * Makes an backwards explode on the $str and returns an array with ($table, $uid).
180 * Example: tt_content_45 => array('tt_content', 45)
182 * @param string $str [tablename]_[uid] string to explode
185 static public function splitTable_Uid($str) {
186 list($uid, $table) = explode('_', strrev($str), 2);
187 return array(strrev($table), strrev($uid));
191 * Returns a list of pure integers based on $in_list being a list of records with table-names prepended.
192 * 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.
194 * @param string $in_list Input list
195 * @param string $tablename Table name from which ids is returned
196 * @param string $default_tablename $default_tablename denotes what table the number '45' is from (if nothing is prepended on the value)
197 * @return string List of ids
199 static public function getSQLselectableList($in_list, $tablename, $default_tablename) {
201 if ((string) trim($in_list) != '') {
202 $tempItemArray = explode(',', trim($in_list));
203 foreach ($tempItemArray as $key => $val) {
205 $parts = explode('_', $val, 2);
206 if ((string) trim($parts[0]) != '') {
207 $theID = intval(strrev($parts[0]));
208 $theTable = trim($parts[1]) ?
strrev(trim($parts[1])) : $default_tablename;
209 if ($theTable == $tablename) {
215 return implode(',', $list);
219 * Backend implementation of enableFields()
220 * Notice that "fe_groups" is not selected for - only disabled, starttime and endtime.
221 * Notice that deleted-fields are NOT filtered - you must ALSO call deleteClause in addition.
222 * $GLOBALS["SIM_ACCESS_TIME"] is used for date.
224 * @param string $table The table from which to return enableFields WHERE clause. Table name must have a 'ctrl' section in $GLOBALS['TCA'].
225 * @param boolean $inv Means that the query will select all records NOT VISIBLE records (inverted selection)
226 * @return string WHERE clause part
228 static public function BEenableFields($table, $inv = 0) {
229 $ctrl = $GLOBALS['TCA'][$table]['ctrl'];
232 if (is_array($ctrl)) {
233 if (is_array($ctrl['enablecolumns'])) {
234 if ($ctrl['enablecolumns']['disabled']) {
235 $field = $table . '.' . $ctrl['enablecolumns']['disabled'];
236 $query[] = $field . '=0';
237 $invQuery[] = $field . '<>0';
239 if ($ctrl['enablecolumns']['starttime']) {
240 $field = $table . '.' . $ctrl['enablecolumns']['starttime'];
241 $query[] = '(' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
242 $invQuery[] = '(' . $field . '<>0 AND ' . $field . '>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
244 if ($ctrl['enablecolumns']['endtime']) {
245 $field = $table . '.' . $ctrl['enablecolumns']['endtime'];
246 $query[] = '(' . $field . '=0 OR ' . $field . '>' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
247 $invQuery[] = '(' . $field . '<>0 AND ' . $field . '<=' . $GLOBALS['SIM_ACCESS_TIME'] . ')';
251 $outQ = $inv ?
'(' . implode(' OR ', $invQuery) . ')' : implode(' AND ', $query);
252 return $outQ ?
' AND ' . $outQ : '';
256 * Fetches the localization for a given record.
258 * @param string $table Table name present in $GLOBALS['TCA']
259 * @param integer $uid The uid of the record
260 * @param integer $language The uid of the language record in sys_language
261 * @param string $andWhereClause Optional additional WHERE clause (default: '')
262 * @return mixed Multidimensional array with selected records; if none exist, FALSE is returned
264 static public function getRecordLocalization($table, $uid, $language, $andWhereClause = '') {
265 $recordLocalization = FALSE;
266 if (self
::isTableLocalizable($table)) {
267 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
268 $recordLocalization = self
::getRecordsByField($table, $tcaCtrl['transOrigPointerField'], $uid, 'AND ' . $tcaCtrl['languageField'] . '=' . intval($language) . ($andWhereClause ?
' ' . $andWhereClause : ''), '', '', '1');
270 return $recordLocalization;
273 /*******************************************
275 * Page tree, TCA related
277 *******************************************/
279 * 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.
280 * By default deleted pages are filtered.
281 * 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.
283 * @param integer $uid Page id for which to create the root line.
284 * @param string $clause Clause can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
285 * @param boolean $workspaceOL If TRUE, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
286 * @return array Root line array, all the way to the page tree root (or as far as $clause allows!)
288 static public function BEgetRootLine($uid, $clause = '', $workspaceOL = FALSE) {
289 static $BEgetRootLine_cache = array();
292 $ident = $pid . '-' . $clause . '-' . $workspaceOL;
293 if (is_array($BEgetRootLine_cache[$ident])) {
294 $output = $BEgetRootLine_cache[$ident];
297 $theRowArray = array();
298 while ($uid != 0 && $loopCheck) {
300 $row = self
::getPageForRootline($uid, $clause, $workspaceOL);
301 if (is_array($row)) {
303 $theRowArray[] = $row;
309 $theRowArray[] = array('uid' => 0, 'title' => '');
311 $c = count($theRowArray);
312 foreach ($theRowArray as $val) {
315 'uid' => $val['uid'],
316 'pid' => $val['pid'],
317 'title' => $val['title'],
318 'TSconfig' => $val['TSconfig'],
319 'is_siteroot' => $val['is_siteroot'],
320 'storage_pid' => $val['storage_pid'],
321 't3ver_oid' => $val['t3ver_oid'],
322 't3ver_wsid' => $val['t3ver_wsid'],
323 't3ver_state' => $val['t3ver_state'],
324 't3ver_stage' => $val['t3ver_stage'],
325 'backend_layout_next_level' => $val['backend_layout_next_level']
327 if (isset($val['_ORIG_pid'])) {
328 $output[$c]['_ORIG_pid'] = $val['_ORIG_pid'];
331 $BEgetRootLine_cache[$ident] = $output;
337 * Gets the cached page record for the rootline
339 * @param integer $uid Page id for which to create the root line.
340 * @param string $clause Clause can be used to select other criteria. It would typically be where-clauses that stops the process if we meet a page, the user has no reading access to.
341 * @param boolean $workspaceOL If TRUE, version overlay is applied. This must be requested specifically because it is usually only wanted when the rootline is used for visual output while for permission checking you want the raw thing!
342 * @return array Cached page record for the rootline
345 static protected function getPageForRootline($uid, $clause, $workspaceOL) {
346 static $getPageForRootline_cache = array();
347 $ident = $uid . '-' . $clause . '-' . $workspaceOL;
348 if (is_array($getPageForRootline_cache[$ident])) {
349 $row = $getPageForRootline_cache[$ident];
351 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid,uid,title,TSconfig,is_siteroot,storage_pid,t3ver_oid,t3ver_wsid,t3ver_state,t3ver_stage,backend_layout_next_level', 'pages', 'uid=' . intval($uid) . ' ' . self
::deleteClause('pages') . ' ' . $clause);
352 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
355 self
::workspaceOL('pages', $row);
357 if (is_array($row)) {
358 self
::fixVersioningPid('pages', $row);
359 $getPageForRootline_cache[$ident] = $row;
362 $GLOBALS['TYPO3_DB']->sql_free_result($res);
368 * Opens the page tree to the specified page id
370 * @param integer $pid Page id.
371 * @param boolean $clearExpansion If set, then other open branches are closed.
374 static public function openPageTree($pid, $clearExpansion) {
375 // Get current expansion data:
376 if ($clearExpansion) {
377 $expandedPages = array();
379 $expandedPages = unserialize($GLOBALS['BE_USER']->uc
['browseTrees']['browsePages']);
382 $rL = self
::BEgetRootLine($pid);
383 // First, find out what mount index to use (if more than one DB mount exists):
385 $mountKeys = array_flip($GLOBALS['BE_USER']->returnWebmounts());
386 foreach ($rL as $rLDat) {
387 if (isset($mountKeys[$rLDat['uid']])) {
388 $mountIndex = $mountKeys[$rLDat['uid']];
392 // Traverse rootline and open paths:
393 foreach ($rL as $rLDat) {
394 $expandedPages[$mountIndex][$rLDat['uid']] = 1;
397 $GLOBALS['BE_USER']->uc
['browseTrees']['browsePages'] = serialize($expandedPages);
398 $GLOBALS['BE_USER']->writeUC();
402 * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
403 * Each part of the path will be limited to $titleLimit characters
404 * Deleted pages are filtered out.
406 * @param integer $uid Page uid for which to create record path
407 * @param string $clause Clause is additional where clauses, eg.
408 * @param integer $titleLimit Title limit
409 * @param integer $fullTitleLimit Title limit of Full title (typ. set to 1000 or so)
410 * @return mixed Path of record (string) OR array with short/long title if $fullTitleLimit is set.
412 static public function getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit = 0) {
417 $output = ($fullOutput = '/');
418 $clause = trim($clause);
419 if ($clause !== '' && substr($clause, 0, 3) !== 'AND') {
420 $clause = 'AND ' . $clause;
422 $data = self
::BEgetRootLine($uid, $clause);
423 foreach ($data as $record) {
424 if ($record['uid'] === 0) {
427 $output = '/' . \TYPO3\CMS\Core\Utility\GeneralUtility
::fixed_lgd_cs(strip_tags($record['title']), $titleLimit) . $output;
428 if ($fullTitleLimit) {
429 $fullOutput = '/' . \TYPO3\CMS\Core\Utility\GeneralUtility
::fixed_lgd_cs(strip_tags($record['title']), $fullTitleLimit) . $fullOutput;
432 if ($fullTitleLimit) {
433 return array($output, $fullOutput);
440 * Returns an array with the exclude-fields as defined in TCA and FlexForms
441 * Used for listing the exclude-fields in be_groups forms
443 * @return array Array of arrays with excludeFields (fieldname, table:fieldname) from all TCA entries and from FlexForms (fieldname, table:extkey;sheetname;fieldname)
445 static public function getExcludeFields() {
447 $theExcludeArray = array();
448 $tc_keys = array_keys($GLOBALS['TCA']);
449 foreach ($tc_keys as $table) {
450 // All field names configured and not restricted to admins
451 if (is_array($GLOBALS['TCA'][$table]['columns'])
452 && empty($GLOBALS['TCA'][$table]['ctrl']['adminOnly'])
453 && (empty($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) ||
!empty($GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction']))
455 $f_keys = array_keys($GLOBALS['TCA'][$table]['columns']);
456 foreach ($f_keys as $field) {
457 if ($GLOBALS['TCA'][$table]['columns'][$field]['exclude']) {
458 // Get human readable names of fields and table
459 $Fname = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['ctrl']['title']) . ': ' . $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$field]['label']);
461 $theExcludeArray[] = array($Fname, $table . ':' . $field);
465 // All FlexForm fields
466 $flexFormArray = self
::getRegisteredFlexForms($table);
467 foreach ($flexFormArray as $tableField => $flexForms) {
468 // Prefix for field label, e.g. "Plugin Options:"
470 if (!empty($GLOBALS['TCA'][$table]['columns'][$tableField]['label'])) {
471 $labelPrefix = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$tableField]['label']);
473 // Get all sheets and title
474 foreach ($flexForms as $extIdent => $extConf) {
475 $extTitle = $GLOBALS['LANG']->sl($extConf['title']);
476 // Get all fields in sheet
477 foreach ($extConf['ds']['sheets'] as $sheetName => $sheet) {
478 if (empty($sheet['ROOT']['el']) ||
!is_array($sheet['ROOT']['el'])) {
481 foreach ($sheet['ROOT']['el'] as $fieldName => $field) {
482 // Use only excludeable fields
483 if (empty($field['TCEforms']['exclude'])) {
486 $fieldLabel = !empty($field['TCEforms']['label']) ?
$GLOBALS['LANG']->sl($field['TCEforms']['label']) : $fieldName;
487 $fieldIdent = $table . ':' . $tableField . ';' . $extIdent . ';' . $sheetName . ';' . $fieldName;
488 $theExcludeArray[] = array(trim(($labelPrefix . ' ' . $extTitle), ': ') . ': ' . $fieldLabel, $fieldIdent);
494 // Sort fields by label
495 usort($theExcludeArray, array('TYPO3\\CMS\\Backend\\Form\\FlexFormsHelper', 'compareArraysByFirstValue'));
496 return $theExcludeArray;
500 * Returns an array with explicit Allow/Deny fields.
501 * Used for listing these field/value pairs in be_groups forms
503 * @return array Array with information from all of $GLOBALS['TCA']
505 static public function getExplicitAuthFieldValues() {
508 'ALLOW' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.allow'),
509 'DENY' => $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xlf:labels.deny')
512 $allowDenyOptions = array();
513 $tc_keys = array_keys($GLOBALS['TCA']);
514 foreach ($tc_keys as $table) {
515 // All field names configured:
516 if (is_array($GLOBALS['TCA'][$table]['columns'])) {
517 $f_keys = array_keys($GLOBALS['TCA'][$table]['columns']);
518 foreach ($f_keys as $field) {
519 $fCfg = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
520 if ($fCfg['type'] == 'select' && $fCfg['authMode']) {
522 if (is_array($fCfg['items'])) {
523 // Get Human Readable names of fields and table:
524 $allowDenyOptions[$table . ':' . $field]['tableFieldLabel'] = $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['ctrl']['title']) . ': ' . $GLOBALS['LANG']->sl($GLOBALS['TCA'][$table]['columns'][$field]['label']);
526 foreach ($fCfg['items'] as $iVal) {
527 // Values '' is not controlled by this setting.
528 if (strcmp($iVal[1], '')) {
531 switch ((string) $fCfg['authMode']) {
532 case 'explicitAllow':
539 if (!strcmp($iVal[4], 'EXPL_ALLOW')) {
541 } elseif (!strcmp($iVal[4], 'EXPL_DENY')) {
548 $allowDenyOptions[$table . ':' . $field]['items'][$iVal[1]] = array($iMode, $GLOBALS['LANG']->sl($iVal[0]), $adLabel[$iMode]);
557 return $allowDenyOptions;
561 * Returns an array with system languages:
563 * Since TYPO3 4.5 the flagIcon is not returned as a filename in "gfx/flags/*" anymore,
564 * but as a string <flags-xx>. The calling party should call
565 * \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon(<flags-xx>) to get an HTML
566 * which will represent the flag of this language.
568 * @return array Array with languages (title, uid, flagIcon)
570 static public function getSystemLanguages() {
571 $languages = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
572 $sysLanguages = array();
573 foreach ($languages as $language) {
574 if ($language['uid'] !== -1) {
575 $sysLanguages[] = array(
576 0 => htmlspecialchars($language['title']) . ' [' . $language['uid'] . ']',
577 1 => $language['uid'],
578 2 => $language['flagIcon']
582 return $sysLanguages;
586 * Gets the original translation pointer table.
587 * For e.g. pages_language_overlay this would be pages.
589 * @param string $table Name of the table
590 * @return string Pointer table (if any)
592 static public function getOriginalTranslationTable($table) {
593 if (!empty($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'])) {
594 $table = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable'];
601 * Determines whether a table is localizable and has the languageField and transOrigPointerField set in $GLOBALS['TCA'].
603 * @param string $table The table to check
604 * @return boolean Whether a table is localizable
606 static public function isTableLocalizable($table) {
607 $isLocalizable = FALSE;
608 if (isset($GLOBALS['TCA'][$table]['ctrl']) && is_array($GLOBALS['TCA'][$table]['ctrl'])) {
609 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
610 $isLocalizable = isset($tcaCtrl['languageField']) && $tcaCtrl['languageField'] && isset($tcaCtrl['transOrigPointerField']) && $tcaCtrl['transOrigPointerField'];
612 return $isLocalizable;
616 * Returns the value of the property localizationMode in the given $config array ($GLOBALS['TCA'][<table>]['columns'][<field>]['config']).
617 * If the table is prepared for localization and no localizationMode is set, 'select' is returned by default.
618 * If the table is not prepared for localization or not defined at all in $GLOBALS['TCA'], FALSE is returned.
620 * @param string $table The name of the table to lookup in TCA
621 * @param mixed $fieldOrConfig The fieldname (string) or the configuration of the field to check (array)
622 * @return mixed If table is localizable, the set localizationMode is returned (if property is not set, 'select' is returned by default); if table is not localizable, FALSE is returned
624 static public function getInlineLocalizationMode($table, $fieldOrConfig) {
625 $localizationMode = FALSE;
626 if (is_array($fieldOrConfig) && count($fieldOrConfig)) {
627 $config = $fieldOrConfig;
628 } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
629 $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
631 if (is_array($config) && isset($config['type']) && $config['type'] == 'inline' && self
::isTableLocalizable($table)) {
632 $localizationMode = isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode'] ?
$config['behaviour']['localizationMode'] : 'select';
633 // The mode 'select' is not possible when child table is not localizable at all:
634 if ($localizationMode == 'select' && !self
::isTableLocalizable($config['foreign_table'])) {
635 $localizationMode = FALSE;
638 return $localizationMode;
642 * 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.
643 * If $id is zero a pseudo root-page with "_thePath" set is returned IF the current BE_USER is admin.
644 * In any case ->isInWebMount must return TRUE for the user (regardless of $perms_clause)
646 * @param integer $id Page uid for which to check read-access
647 * @param string $perms_clause This is typically a value generated with $GLOBALS['BE_USER']->getPagePermsClause(1);
648 * @return array Returns page record if OK, otherwise FALSE.
650 static public function readPageAccess($id, $perms_clause) {
651 if ((string) $id != '') {
654 if ($GLOBALS['BE_USER']->isAdmin()) {
656 $pageinfo['_thePath'] = $path;
660 $pageinfo = self
::getRecord('pages', $id, '*', $perms_clause ?
' AND ' . $perms_clause : '');
661 if ($pageinfo['uid'] && $GLOBALS['BE_USER']->isInWebMount($id, $perms_clause)) {
662 self
::workspaceOL('pages', $pageinfo);
663 if (is_array($pageinfo)) {
664 self
::fixVersioningPid('pages', $pageinfo);
665 list($pageinfo['_thePath'], $pageinfo['_thePathFull']) = self
::getRecordPath(intval($pageinfo['uid']), $perms_clause, 15, 1000);
675 * Returns the "types" configuration parsed into an array for the record, $rec, from table, $table
677 * @param string $table Table name (present in TCA)
678 * @param array $rec Record from $table
679 * @param boolean $useFieldNameAsKey If $useFieldNameAsKey is set, then the fieldname is associative keys in the return array, otherwise just numeric keys.
682 static public function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
683 if ($GLOBALS['TCA'][$table]) {
685 $fieldValue = self
::getTCAtypeValue($table, $rec);
687 $typesConf = $GLOBALS['TCA'][$table]['types'][$fieldValue];
688 // Get fields list and traverse it
689 $fieldList = explode(',', $typesConf['showitem']);
690 $altFieldList = array();
691 // Traverse fields in types config and parse the configuration into a nice array:
692 foreach ($fieldList as $k => $v) {
693 list($pFieldName, $pAltTitle, $pPalette, $pSpec) = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(';', $v);
694 $defaultExtras = is_array($GLOBALS['TCA'][$table]['columns'][$pFieldName]) ?
$GLOBALS['TCA'][$table]['columns'][$pFieldName]['defaultExtras'] : '';
695 $specConfParts = self
::getSpecConfParts($pSpec, $defaultExtras);
696 $fieldList[$k] = array(
697 'field' => $pFieldName,
698 'title' => $pAltTitle,
699 'palette' => $pPalette,
700 'spec' => $specConfParts,
703 if ($useFieldNameAsKey) {
704 $altFieldList[$fieldList[$k]['field']] = $fieldList[$k];
707 if ($useFieldNameAsKey) {
708 $fieldList = $altFieldList;
716 * Returns the "type" value of $rec from $table which can be used to look up the correct "types" rendering section in $GLOBALS['TCA']
717 * If no "type" field is configured in the "ctrl"-section of the $GLOBALS['TCA'] for the table, zero is used.
718 * If zero is not an index in the "types" section of $GLOBALS['TCA'] for the table, then the $fieldValue returned will default to 1 (no matter if that is an index or not)
720 * Note: This method is very similar to \TYPO3\CMS\Backend\Form\FormEngine::getRTypeNum(),
721 * however, it has two differences:
722 * 1) The method in TCEForms also takes care of localization (which is difficult to do here as the whole infrastructure for language overlays is only in TCEforms).
723 * 2) The $rec array looks different in TCEForms, as in there it's not the raw record but the \TYPO3\CMS\Backend\Form\DataPreprocessor version of it, which changes e.g. how "select"
724 * and "group" field values are stored, which makes different processing of the "foreign pointer field" type field variant necessary.
726 * @param string $table Table name present in TCA
727 * @param array $row Record from $table
728 * @return string Field value
731 static public function getTCAtypeValue($table, $row) {
733 if ($GLOBALS['TCA'][$table]) {
734 $field = $GLOBALS['TCA'][$table]['ctrl']['type'];
735 if (strpos($field, ':') !== FALSE) {
736 list($pointerField, $foreignTableTypeField) = explode(':', $field);
737 // Get field value from database if field is not in the $row array
738 if (!isset($row[$pointerField])) {
739 $localRow = self
::getRecord($table, $row['uid'], $pointerField);
740 $foreignUid = $localRow[$pointerField];
742 $foreignUid = $row[$pointerField];
745 $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$pointerField]['config'];
746 $relationType = $fieldConfig['type'];
747 if ($relationType === 'select') {
748 $foreignTable = $fieldConfig['foreign_table'];
749 } elseif ($relationType === 'group') {
750 $allowedTables = explode(',', $fieldConfig['allowed']);
751 $foreignTable = $allowedTables[0];
753 throw new \
RuntimeException('TCA foreign field pointer fields are only allowed to be used with group or select field types.', 1325862240);
755 $foreignRow = self
::getRecord($foreignTable, $foreignUid, $foreignTableTypeField);
756 if ($foreignRow[$foreignTableTypeField]) {
757 $typeNum = $foreignRow[$foreignTableTypeField];
761 $typeNum = $row[$field];
763 // If that value is an empty string, set it to "0" (zero)
764 if (!strcmp($typeNum, '')) {
768 // If current typeNum doesn't exist, set it to 0 (or to 1 for historical reasons, if 0 doesn't exist)
769 if (!$GLOBALS['TCA'][$table]['types'][$typeNum]) {
770 $typeNum = $GLOBALS['TCA'][$table]['types']['0'] ?
0 : 1;
772 // Force to string. Necessary for eg '-1' to be recognized as a type value.
773 $typeNum = (string) $typeNum;
778 * Parses a part of the field lists in the "types"-section of $GLOBALS['TCA'] arrays, namely the "special configuration" at index 3 (position 4)
779 * Elements are splitted by ":" and within those parts, parameters are splitted by "|".
780 * 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
782 * @param string $str Content from the "types" configuration of TCA (the special configuration) - see description of function
783 * @param string $defaultExtras The ['defaultExtras'] value from field configuration
786 static public function getSpecConfParts($str, $defaultExtras) {
787 // Add defaultExtras:
788 $specConfParts = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(':', $defaultExtras . ':' . $str, 1);
790 if (count($specConfParts)) {
791 foreach ($specConfParts as $k2 => $v2) {
792 unset($specConfParts[$k2]);
793 if (preg_match('/(.*)\\[(.*)\\]/', $v2, $reg)) {
794 $specConfParts[trim($reg[1])] = array(
795 'parameters' => \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode('|', $reg[2], 1)
798 $specConfParts[trim($v2)] = 1;
802 $specConfParts = array();
804 return $specConfParts;
808 * Takes an array of "[key] = [value]" strings and returns an array with the keys set as keys pointing to the value.
809 * Better see it in action! Find example in Inside TYPO3
811 * @param array $pArr Array of "[key] = [value]" strings to convert.
814 static public function getSpecConfParametersFromArray($pArr) {
816 if (is_array($pArr)) {
817 foreach ($pArr as $k => $v) {
818 $parts = explode('=', $v, 2);
819 if (count($parts) == 2) {
820 $out[trim($parts[0])] = trim($parts[1]);
830 * Finds the Data Structure for a FlexForm field
831 * NOTE ON data structures for deleted records: This function may fail to deliver the data structure for a record for a few reasons: a) The data structure could be deleted (either with deleted-flagged or hard-deleted), b) the data structure is fetched using the ds_pointerField_searchParent in which case any deleted record on the route to the final location of the DS will make it fail. In theory, we can solve the problem in the case where records that are deleted-flagged keeps us from finding the DS - this is done at the markers ###NOTE_A### where we make sure to also select deleted records. However, we generally want the DS lookup to fail for deleted records since for the working website we expect a deleted-flagged record to be as inaccessible as one that is completely deleted from the DB. Any way we look at it, this may lead to integrity problems of the reference index and even lost files if attached. However, that is not really important considering that a single change to a data structure can instantly invalidate large amounts of the reference index which we do accept as a cost for the flexform features. Other than requiring a reference index update, deletion of/changes in data structure or the failure to look them up when completely deleting records may lead to lost files in the uploads/ folders since those are now without a proper reference.
833 * @param array $conf Field config array
834 * @param array $row Record data
835 * @param string $table The table name
836 * @param string $fieldName Optional fieldname passed to hook object
837 * @param boolean $WSOL Boolean; If set, workspace overlay is applied to records. This is correct behaviour for all presentation and export, but NOT if you want a TRUE reflection of how things are in the live workspace.
838 * @param integer $newRecordPidValue SPECIAL CASES: Use this, if the DataStructure may come from a parent record and the INPUT row doesn't have a uid yet (hence, the pid cannot be looked up). Then it is necessary to supply a PID value to search recursively in for the DS (used from TCEmain)
839 * @return mixed If array, the data structure was found and returned as an array. Otherwise (string) it is an error message.
840 * @see \TYPO3\CMS\Backend\Form\FormEngine::getSingleField_typeFlex()
842 static public function getFlexFormDS($conf, $row, $table, $fieldName = '', $WSOL = TRUE, $newRecordPidValue = 0) {
843 // Get pointer field etc from TCA-config:
844 $ds_pointerField = $conf['ds_pointerField'];
845 $ds_array = $conf['ds'];
846 $ds_tableField = $conf['ds_tableField'];
847 $ds_searchParentField = $conf['ds_pointerField_searchParent'];
848 // Find source value:
849 $dataStructArray = '';
850 // If there is a data source array, that takes precedence
851 if (is_array($ds_array)) {
852 // If a pointer field is set, take the value from that field in the $row array and use as key.
853 if ($ds_pointerField) {
854 // Up to two pointer fields can be specified in a comma separated list.
855 $pointerFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $ds_pointerField);
856 // If we have two pointer fields, the array keys should contain both field values separated by comma. The asterisk "*" catches all values. For backwards compatibility, it's also possible to specify only the value of the first defined ds_pointerField.
857 if (count($pointerFields) == 2) {
858 if ($ds_array[$row[$pointerFields[0]] . ',' . $row[$pointerFields[1]]]) {
859 // Check if we have a DS for the combination of both pointer fields values
860 $srcPointer = $row[$pointerFields[0]] . ',' . $row[$pointerFields[1]];
861 } elseif ($ds_array[$row[$pointerFields[1]] . ',*']) {
862 // Check if we have a DS for the value of the first pointer field suffixed with ",*"
863 $srcPointer = $row[$pointerFields[1]] . ',*';
864 } elseif ($ds_array['*,' . $row[$pointerFields[1]]]) {
865 // Check if we have a DS for the value of the second pointer field prefixed with "*,"
866 $srcPointer = '*,' . $row[$pointerFields[1]];
867 } elseif ($ds_array[$row[$pointerFields[0]]]) {
868 // Check if we have a DS for just the value of the first pointer field (mainly for backwards compatibility)
869 $srcPointer = $row[$pointerFields[0]];
872 $srcPointer = $row[$pointerFields[0]];
874 $srcPointer = isset($ds_array[$srcPointer]) ?
$srcPointer : 'default';
876 $srcPointer = 'default';
878 // 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.
879 if (substr($ds_array[$srcPointer], 0, 5) == 'FILE:') {
880 $file = \TYPO3\CMS\Core\Utility\GeneralUtility
::getFileAbsFileName(substr($ds_array[$srcPointer], 5));
881 if ($file && @is_file
($file)) {
882 $dataStructArray = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array(\TYPO3\CMS\Core\Utility\GeneralUtility
::getUrl($file));
884 $dataStructArray = 'The file "' . substr($ds_array[$srcPointer], 5) . '" in ds-array key "' . $srcPointer . '" was not found ("' . $file . '")';
887 $dataStructArray = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array($ds_array[$srcPointer]);
889 } elseif ($ds_pointerField) {
890 // If pointer field AND possibly a table/field is set:
891 // Value of field pointed to:
892 $srcPointer = $row[$ds_pointerField];
893 // Searching recursively back if 'ds_pointerField_searchParent' is defined (typ. a page rootline, or maybe a tree-table):
894 if ($ds_searchParentField && !$srcPointer) {
895 $rr = self
::getRecord($table, $row['uid'], 'uid,' . $ds_searchParentField);
896 // Get the "pid" field - we cannot know that it is in the input record! ###NOTE_A###
898 self
::workspaceOL($table, $rr);
899 self
::fixVersioningPid($table, $rr, TRUE);
902 // Used to avoid looping, if any should happen.
903 $subFieldPointer = $conf['ds_pointerField_searchParent_subField'];
904 while (!$srcPointer) {
905 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,' . $ds_pointerField . ',' . $ds_searchParentField . ($subFieldPointer ?
',' . $subFieldPointer : ''), $table, 'uid=' . intval(($newRecordPidValue ?
$newRecordPidValue : $rr[$ds_searchParentField])) . self
::deleteClause($table));
906 $newRecordPidValue = 0;
907 $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
908 $GLOBALS['TYPO3_DB']->sql_free_result($res);
909 // Break if no result from SQL db or if looping...
910 if (!is_array($rr) ||
isset($uidAcc[$rr['uid']])) {
913 $uidAcc[$rr['uid']] = 1;
915 self
::workspaceOL($table, $rr);
916 self
::fixVersioningPid($table, $rr, TRUE);
918 $srcPointer = $subFieldPointer && $rr[$subFieldPointer] ?
$rr[$subFieldPointer] : $rr[$ds_pointerField];
921 // If there is a srcPointer value:
923 if (\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($srcPointer)) {
924 // If integer, then its a record we will look up:
925 list($tName, $fName) = explode(':', $ds_tableField, 2);
926 if ($tName && $fName && is_array($GLOBALS['TCA'][$tName])) {
927 $dataStructRec = self
::getRecord($tName, $srcPointer);
929 self
::workspaceOL($tName, $dataStructRec);
931 if (strpos($dataStructRec[$fName], '<') === FALSE) {
932 if (is_file(PATH_site
. $dataStructRec[$fName])) {
933 // The value is a pointer to a file
934 $dataStructArray = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array(\TYPO3\CMS\Core\Utility\GeneralUtility
::getUrl(PATH_site
. $dataStructRec[$fName]));
936 $dataStructArray = sprintf('File \'%s\' was not found', $dataStructRec[$fName]);
939 // No file pointer, handle as being XML (default behaviour)
940 $dataStructArray = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array($dataStructRec[$fName]);
943 $dataStructArray = 'No tablename (' . $tName . ') or fieldname (' . $fName . ') was found an valid!';
946 // Otherwise expect it to be a file:
947 $file = \TYPO3\CMS\Core\Utility\GeneralUtility
::getFileAbsFileName($srcPointer);
948 if ($file && @is_file
($file)) {
949 $dataStructArray = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array(\TYPO3\CMS\Core\Utility\GeneralUtility
::getUrl($file));
952 $dataStructArray = 'The file "' . $srcPointer . '" was not found ("' . $file . '")';
957 $dataStructArray = 'No source value in fieldname "' . $ds_pointerField . '"';
960 $dataStructArray = 'No proper configuration!';
962 // Hook for post-processing the Flexform DS. Introduces the possibility to configure Flexforms via TSConfig
963 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'])) {
964 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['getFlexFormDSClass'] as $classRef) {
965 $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($classRef);
966 if (method_exists($hookObj, 'getFlexFormDS_postProcessDS')) {
967 $hookObj->getFlexFormDS_postProcessDS($dataStructArray, $conf, $row, $table, $fieldName);
971 return $dataStructArray;
975 * Returns all registered FlexForm definitions with title and fields
977 * @param string $table The content table
978 * @return array The data structures with speaking extension title
979 * @see \TYPO3\CMS\Backend\Utility\BackendUtility::getExcludeFields()
981 static public function getRegisteredFlexForms($table = 'tt_content') {
982 if (empty($table) ||
empty($GLOBALS['TCA'][$table]['columns'])) {
985 $flexForms = array();
986 foreach ($GLOBALS['TCA'][$table]['columns'] as $tableField => $fieldConf) {
987 if (!empty($fieldConf['config']['type']) && !empty($fieldConf['config']['ds']) && $fieldConf['config']['type'] == 'flex') {
988 $flexForms[$tableField] = array();
989 unset($fieldConf['config']['ds']['default']);
990 // Get pointer fields
991 $pointerFields = !empty($fieldConf['config']['ds_pointerField']) ?
$fieldConf['config']['ds_pointerField'] : 'list_type,CType';
992 $pointerFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $pointerFields);
994 foreach ($fieldConf['config']['ds'] as $flexFormKey => $dataStruct) {
995 // Get extension identifier (uses second value if it's not empty, "list" or "*", else first one)
996 $identFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $flexFormKey);
997 $extIdent = $identFields[0];
998 if (!empty($identFields[1]) && $identFields[1] != 'list' && $identFields[1] != '*') {
999 $extIdent = $identFields[1];
1001 // Load external file references
1002 if (!is_array($dataStruct)) {
1003 $file = \TYPO3\CMS\Core\Utility\GeneralUtility
::getFileAbsFileName(str_ireplace('FILE:', '', $dataStruct));
1004 if ($file && @is_file
($file)) {
1005 $dataStruct = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUrl($file);
1007 $dataStruct = \TYPO3\CMS\Core\Utility\GeneralUtility
::xml2array($dataStruct);
1008 if (!is_array($dataStruct)) {
1012 // Get flexform content
1013 $dataStruct = \TYPO3\CMS\Core\Utility\GeneralUtility
::resolveAllSheetsInDS($dataStruct);
1014 if (empty($dataStruct['sheets']) ||
!is_array($dataStruct['sheets'])) {
1017 // Use DS pointer to get extension title from TCA
1019 $keyFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $flexFormKey);
1020 foreach ($pointerFields as $pointerKey => $pointerName) {
1021 if (empty($keyFields[$pointerKey]) ||
$keyFields[$pointerKey] == '*' ||
$keyFields[$pointerKey] == 'list') {
1024 if (!empty($GLOBALS['TCA'][$table]['columns'][$pointerName]['config']['items'])) {
1025 $items = $GLOBALS['TCA'][$table]['columns'][$pointerName]['config']['items'];
1026 if (!is_array($items)) {
1029 foreach ($items as $itemConf) {
1030 if (!empty($itemConf[0]) && !empty($itemConf[1]) && $itemConf[1] == $keyFields[$pointerKey]) {
1031 $title = $itemConf[0];
1037 $flexForms[$tableField][$extIdent] = array(
1047 /*******************************************
1051 *******************************************/
1053 * Stores the string value $data in the 'cache_hash' cache with the
1054 * hash key, $hash, and visual/symbolic identification, $ident
1055 * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
1057 * @param string $hash 32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
1058 * @param string $data The data string. If you want to store an array, then just serialize it first.
1059 * @param string $ident $ident is just a textual identification in order to inform about the content!
1062 static public function storeHash($hash, $data, $ident) {
1063 $GLOBALS['typo3CacheManager']->getCache('cache_hash')->set($hash, $data, array('ident_' . $ident), 0);
1067 * Returns string value stored for the hash string in the cache "cache_hash"
1068 * Can be used to retrieved a cached value
1070 * IDENTICAL to the function by same name found in \TYPO3\CMS\Frontend\Page\PageRepository
1072 * @param string $hash The hash-string which was used to store the data value
1073 * @param integer $expTime Variabele is not used in the function
1076 static public function getHash($hash, $expTime = 0) {
1077 $hashContent = NULL;
1078 $cacheEntry = $GLOBALS['typo3CacheManager']->getCache('cache_hash')->get($hash);
1080 $hashContent = $cacheEntry;
1082 return $hashContent;
1085 /*******************************************
1087 * TypoScript related
1089 *******************************************/
1091 * Returns the Page TSconfig for page with id, $id
1093 * @param $id integer Page uid for which to create Page TSconfig
1094 * @param $rootLine array If $rootLine is an array, that is used as rootline, otherwise rootline is just calculated
1095 * @param boolean $returnPartArray 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.
1096 * @return array Page TSconfig
1097 * @see \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
1099 static public function getPagesTSconfig($id, $rootLine = '', $returnPartArray = 0) {
1101 if (!is_array($rootLine)) {
1102 $rootLine = self
::BEgetRootLine($id, '', TRUE);
1106 $TSdataArray = array();
1107 // Setting default configuration
1108 $TSdataArray['defaultPageTSconfig'] = $GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'];
1109 foreach ($rootLine as $k => $v) {
1110 $TSdataArray['uid_' . $v['uid']] = $v['TSconfig'];
1112 $TSdataArray = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
::checkIncludeLines_array($TSdataArray);
1113 if ($returnPartArray) {
1114 return $TSdataArray;
1116 // Parsing the page TS-Config (or getting from cache)
1117 $pageTS = implode(LF
. '[GLOBAL]' . LF
, $TSdataArray);
1118 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['TSconfigConditions']) {
1119 /* @var $parseObj \TYPO3\CMS\Backend\Configuration\TsConfigParser */
1120 $parseObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TsConfigParser');
1121 $res = $parseObj->parseTSconfig($pageTS, 'PAGES', $id, $rootLine);
1123 $TSconfig = $res['TSconfig'];
1126 $hash = md5('pageTS:' . $pageTS);
1127 $cachedContent = self
::getHash($hash);
1128 $TSconfig = array();
1129 if (isset($cachedContent)) {
1130 $TSconfig = unserialize($cachedContent);
1132 $parseObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
1133 $parseObj->parse($pageTS);
1134 $TSconfig = $parseObj->setup
;
1135 self
::storeHash($hash, serialize($TSconfig), 'PAGES_TSconfig');
1138 // Get User TSconfig overlay
1139 $userTSconfig = $GLOBALS['BE_USER']->userTS
['page.'];
1140 if (is_array($userTSconfig)) {
1141 $TSconfig = \TYPO3\CMS\Core\Utility\GeneralUtility
::array_merge_recursive_overrule($TSconfig, $userTSconfig);
1147 * Updates Page TSconfig for a page with $id
1148 * 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.
1149 * $impParams can be supplied as already known Page TSconfig, otherwise it's calculated.
1151 * THIS DOES NOT CHECK ANY PERMISSIONS. SHOULD IT?
1152 * More documentation is needed.
1154 * @param integer $id Page id
1155 * @param array $pageTS Page TS array to write
1156 * @param string $TSconfPrefix Prefix for object paths
1157 * @param array $impParams [Description needed.]
1160 * @see implodeTSParams(), getPagesTSconfig()
1162 static public function updatePagesTSconfig($id, $pageTS, $TSconfPrefix, $impParams = '') {
1164 if (is_array($pageTS) && $id > 0) {
1165 if (!is_array($impParams)) {
1166 $impParams = self
::implodeTSParams(self
::getPagesTSconfig($id));
1169 foreach ($pageTS as $f => $v) {
1170 $f = $TSconfPrefix . $f;
1171 if (!isset($impParams[$f]) && trim($v) ||
strcmp(trim($impParams[$f]), trim($v))) {
1172 $set[$f] = trim($v);
1176 // Get page record and TS config lines
1177 $pRec = self
::getRecord('pages', $id);
1178 $TSlines = explode(LF
, $pRec['TSconfig']);
1179 $TSlines = array_reverse($TSlines);
1180 // Reset the set of changes.
1181 foreach ($set as $f => $v) {
1183 foreach ($TSlines as $ki => $kv) {
1184 if (substr($kv, 0, strlen($f) +
1) == $f . '=') {
1185 $TSlines[$ki] = $f . '=' . $v;
1191 $TSlines = array_reverse($TSlines);
1192 $TSlines[] = $f . '=' . $v;
1193 $TSlines = array_reverse($TSlines);
1196 $TSlines = array_reverse($TSlines);
1197 // Store those changes
1198 $TSconf = implode(LF
, $TSlines);
1199 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('pages', 'uid=' . intval($id), array('TSconfig' => $TSconf));
1205 * Implodes a multi dimensional TypoScript array, $p, into a one-dimentional array (return value)
1207 * @param array $p TypoScript structure
1208 * @param string $k Prefix string
1209 * @return array Imploded TypoScript objectstring/values
1211 static public function implodeTSParams($p, $k = '') {
1212 $implodeParams = array();
1214 foreach ($p as $kb => $val) {
1215 if (is_array($val)) {
1216 $implodeParams = array_merge($implodeParams, self
::implodeTSParams($val, $k . $kb));
1218 $implodeParams[$k . $kb] = $val;
1222 return $implodeParams;
1225 /*******************************************
1227 * Users / Groups related
1229 *******************************************/
1231 * Returns an array with be_users records of all user NOT DELETED sorted by their username
1232 * Keys in the array is the be_users uid
1234 * @param string $fields Optional $fields list (default: username,usergroup,usergroup_cached_list,uid) can be used to set the selected fields
1235 * @param string $where Optional $where clause (fx. "AND username='pete'") can be used to limit query
1238 static public function getUserNames($fields = 'username,usergroup,usergroup_cached_list,uid', $where = '') {
1239 $be_user_Array = array();
1240 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_users', 'pid=0 ' . $where . self
::deleteClause('be_users'), '', 'username');
1241 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1242 $be_user_Array[$row['uid']] = $row;
1244 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1245 return $be_user_Array;
1249 * Returns an array with be_groups records (title, uid) of all groups NOT DELETED sorted by their title
1251 * @param string $fields Field list
1252 * @param string $where WHERE clause
1255 static public function getGroupNames($fields = 'title,uid', $where = '') {
1256 $be_group_Array = array();
1257 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 ' . $where . self
::deleteClause('be_groups'), '', 'title');
1258 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
1259 $be_group_Array[$row['uid']] = $row;
1261 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1262 return $be_group_Array;
1266 * Returns an array with be_groups records (like ->getGroupNames) but:
1267 * - 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.
1269 * @param string $fields Field list; $fields specify the fields selected (default: title,uid)
1272 static public function getListGroupNames($fields = 'title, uid') {
1273 $exQ = ' AND hide_in_lists=0';
1274 if (!$GLOBALS['BE_USER']->isAdmin()) {
1275 $exQ .= ' AND uid IN (' . ($GLOBALS['BE_USER']->user
['usergroup_cached_list'] ?
$GLOBALS['BE_USER']->user
['usergroup_cached_list'] : 0) . ')';
1277 return self
::getGroupNames($fields, $exQ);
1281 * Returns the array $usernames with the names of all users NOT IN $groupArray changed to the uid (hides the usernames!).
1282 * If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1283 * Takes $usernames (array made by \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames()) and a $groupArray (array with the groups a certain user is member of) as input
1285 * @param array $usernames User names
1286 * @param array $groupArray Group names
1287 * @param boolean $excludeBlindedFlag If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1288 * @return array User names, blinded
1290 static public function blindUserNames($usernames, $groupArray, $excludeBlindedFlag = 0) {
1291 if (is_array($usernames) && is_array($groupArray)) {
1292 foreach ($usernames as $uid => $row) {
1295 if ($row['uid'] != $GLOBALS['BE_USER']->user
['uid']) {
1296 foreach ($groupArray as $v) {
1297 if ($v && \TYPO3\CMS\Core\Utility\GeneralUtility
::inList($row['usergroup_cached_list'], $v)) {
1298 $userN = $row['username'];
1303 $userN = $row['username'];
1306 $usernames[$uid]['username'] = $userN;
1307 if ($excludeBlindedFlag && !$set) {
1308 unset($usernames[$uid]);
1316 * Corresponds to blindUserNames but works for groups instead
1318 * @param array $groups Group names
1319 * @param array $groupArray Group names (reference)
1320 * @param boolean $excludeBlindedFlag If $excludeBlindedFlag is set, then these records are unset from the array $usernames
1323 static public function blindGroupNames($groups, $groupArray, $excludeBlindedFlag = 0) {
1324 if (is_array($groups) && is_array($groupArray)) {
1325 foreach ($groups as $uid => $row) {
1328 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::inArray($groupArray, $uid)) {
1329 $groupN = $row['title'];
1332 $groups[$uid]['title'] = $groupN;
1333 if ($excludeBlindedFlag && !$set) {
1334 unset($groups[$uid]);
1341 /*******************************************
1345 *******************************************/
1347 * Returns the difference in days between input $tstamp and $EXEC_TIME
1349 * @param integer $tstamp Time stamp, seconds
1352 static public function daysUntil($tstamp) {
1353 $delta_t = $tstamp - $GLOBALS['EXEC_TIME'];
1354 return ceil($delta_t / (3600 * 24));
1358 * Returns $tstamp formatted as "ddmmyy" (According to $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'])
1360 * @param integer $tstamp Time stamp, seconds
1361 * @return string Formatted time
1363 static public function date($tstamp) {
1364 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], (int) $tstamp);
1368 * Returns $tstamp formatted as "ddmmyy hhmm" (According to $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] AND $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'])
1370 * @param integer $value Time stamp, seconds
1371 * @return string Formatted time
1373 static public function datetime($value) {
1374 return date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $value);
1378 * Returns $value (in seconds) formatted as hh:mm:ss
1379 * For instance $value = 3600 + 60*2 + 3 should return "01:02:03"
1381 * @param integer $value Time stamp, seconds
1382 * @param boolean $withSeconds Output hh:mm:ss. If FALSE: hh:mm
1383 * @return string Formatted time
1385 static public function time($value, $withSeconds = TRUE) {
1386 $hh = floor($value / 3600);
1387 $min = floor(($value - $hh * 3600) / 60);
1388 $sec = $value - $hh * 3600 - $min * 60;
1389 $l = sprintf('%02d', $hh) . ':' . sprintf('%02d', $min);
1391 $l .= ':' . sprintf('%02d', $sec);
1397 * Returns the "age" in minutes / hours / days / years of the number of $seconds inputted.
1399 * @param integer $seconds Seconds could be the difference of a certain timestamp and time()
1400 * @param string $labels Labels should be something like ' min| hrs| days| yrs| min| hour| day| year'. This value is typically delivered by this function call: $GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears")
1401 * @return string Formatted time
1403 static public function calcAge($seconds, $labels = ' min| hrs| days| yrs| min| hour| day| year') {
1404 $labelArr = explode('|', $labels);
1405 $absSeconds = abs($seconds);
1406 $sign = $seconds < 0 ?
-1 : 1;
1407 if ($absSeconds < 3600) {
1408 $val = round($absSeconds / 60);
1409 $seconds = $sign * $val . ($val == 1 ?
$labelArr[4] : $labelArr[0]);
1410 } elseif ($absSeconds < 24 * 3600) {
1411 $val = round($absSeconds / 3600);
1412 $seconds = $sign * $val . ($val == 1 ?
$labelArr[5] : $labelArr[1]);
1413 } elseif ($absSeconds < 365 * 24 * 3600) {
1414 $val = round($absSeconds / (24 * 3600));
1415 $seconds = $sign * $val . ($val == 1 ?
$labelArr[6] : $labelArr[2]);
1417 $val = round($absSeconds / (365 * 24 * 3600));
1418 $seconds = $sign * $val . ($val == 1 ?
$labelArr[7] : $labelArr[3]);
1424 * Returns a formatted timestamp if $tstamp is set.
1425 * The date/datetime will be followed by the age in parenthesis.
1427 * @param integer $tstamp Time stamp, seconds
1428 * @param integer $prefix 1/-1 depending on polarity of age.
1429 * @param string $date $date=="date" will yield "dd:mm:yy" formatting, otherwise "dd:mm:yy hh:mm
1432 static public function dateTimeAge($tstamp, $prefix = 1, $date = '') {
1433 return $tstamp ?
($date == 'date' ? self
::date($tstamp) : self
::datetime($tstamp)) . ' (' . self
::calcAge($prefix * ($GLOBALS['EXEC_TIME'] - $tstamp), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')' : '';
1437 * Returns alt="" and title="" attributes with the value of $content.
1439 * @param string $content Value for 'alt' and 'title' attributes (will be htmlspecialchars()'ed before output)
1442 static public function titleAltAttrib($content) {
1444 $out .= ' alt="' . htmlspecialchars($content) . '"';
1445 $out .= ' title="' . htmlspecialchars($content) . '"';
1450 * 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
1451 * All $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] extension are made to thumbnails + ttf file (renders font-example)
1452 * Thumbsnails are linked to the show_item.php script which will display further details.
1454 * @param array $row Row is the database row from the table, $table.
1455 * @param string $table Table name for $row (present in TCA)
1456 * @param string $field Field is pointing to the list of image files
1457 * @param string $backPath Back path prefix for image tag src="" field
1458 * @param string $thumbScript Optional: $thumbScript - not used anymore since FAL
1459 * @param string $uploaddir 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 $GLOBALS['TCA'] for that field! so you don't have to!)
1460 * @param boolean $abs If set, uploaddir is NOT prepended with "../
1461 * @param string $tparams Optional: $tparams is additional attributes for the image tags
1462 * @param integer $size Optional: $size is [w]x[h] of the thumbnail. 56 is default.
1463 * @param boolean $linkInfoPopup Whether to wrap with a link opening the info popup
1464 * @return string Thumbnail image tag.
1466 static public function thumbCode($row, $table, $field, $backPath, $thumbScript = '', $uploaddir = NULL, $abs = 0, $tparams = '', $size = '', $linkInfoPopup = TRUE) {
1467 $tcaConfig = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
1468 // Check and parse the size parameter
1469 $sizeParts = array(64, 64);
1470 if ($size = trim($size)) {
1471 $sizeParts = explode('x', $size . 'x' . $size);
1472 if (!intval($sizeParts[0])) {
1478 if ($tcaConfig['type'] === 'inline') {
1479 $referenceUids = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'sys_file_reference', 'tablenames = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_file_reference') . ' AND fieldname=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($field, 'sys_file_reference') . ' AND uid_foreign=' . intval($row['uid']) . self
::deleteClause('sys_file_reference') . self
::versioningPlaceholderClause('sys_file_reference'));
1480 foreach ($referenceUids as $referenceUid) {
1481 $fileReferenceObject = \TYPO3\CMS\Core\
Resource\ResourceFactory
::getInstance()->getFileReferenceObject($referenceUid['uid']);
1482 $fileObject = $fileReferenceObject->getOriginalFile();
1484 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileReferenceObject->getExtension())) {
1485 $imageUrl = $fileObject->process(\TYPO3\CMS\Core\
Resource\ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array(
1486 'width' => $sizeParts[0],
1487 'height' => $sizeParts[1]
1488 ))->getPublicUrl(TRUE);
1489 $imgTag = '<img src="' . $imageUrl . '" alt="' . htmlspecialchars($fileReferenceObject->getName()) . '" />';
1492 $imgTag = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIconForFile(strtolower($fileObject->getExtension()), array('title' => $fileObject->getName()));
1494 if ($linkInfoPopup) {
1495 $onClick = 'top.launchView(\'_FILE\',\'' . $fileObject->getUid() . '\',\'' . $backPath . '\'); return false;';
1496 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $imgTag . '</a> ';
1498 $thumbData .= $imgTag;
1502 // Find uploaddir automatically
1503 if (is_null($uploaddir)) {
1504 $uploaddir = $GLOBALS['TCA'][$table]['columns'][$field]['config']['uploadfolder'];
1506 $uploaddir = rtrim($uploaddir, '/');
1508 $thumbs = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $row[$field], TRUE);
1510 foreach ($thumbs as $theFile) {
1512 $fileName = trim($uploaddir . '/' . $theFile, '/');
1513 $fileObject = \TYPO3\CMS\Core\
Resource\ResourceFactory
::getInstance()->retrieveFileOrFolderObject($fileName);
1514 $fileExtension = $fileObject->getExtension();
1515 if ($fileExtension == 'ttf' || \TYPO3\CMS\Core\Utility\GeneralUtility
::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileExtension)) {
1516 $imageUrl = $fileObject->process(\TYPO3\CMS\Core\
Resource\ProcessedFile
::CONTEXT_IMAGEPREVIEW
, array(
1517 'width' => $sizeParts[0],
1518 'height' => $sizeParts[1]
1519 ))->getPublicUrl(TRUE);
1520 if (!$fileObject->checkActionPermission('read')) {
1521 /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
1522 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing_text') . ' <abbr title="' . htmlspecialchars($fileObject->getName()) . '">' . htmlspecialchars($fileObject->getName()) . '</abbr>', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.file_missing'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
);
1523 $thumbData .= $flashMessage->render();
1526 $image = '<img src="' . htmlspecialchars($imageUrl) . '" hspace="2" border="0" title="' . htmlspecialchars($fileObject->getName()) . '"' . $tparams . ' alt="" />';
1527 if ($linkInfoPopup) {
1528 $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\');return false;';
1529 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $image . '</a> ';
1531 $thumbData .= $image;
1535 $fileIcon = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName()));
1536 if ($linkInfoPopup) {
1537 $onClick = 'top.launchView(\'_FILE\', \'' . $fileName . '\',\'\',\'' . $backPath . '\'); return false;';
1538 $thumbData .= '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $fileIcon . '</a> ';
1540 $thumbData .= $fileIcon;
1550 * Returns single image tag to thumbnail using a thumbnail script (like thumbs.php)
1552 * @param string $thumbScript Must point to "thumbs.php" relative to the script position
1553 * @param string $theFile Must be the proper reference to the file that thumbs.php should show
1554 * @param string $tparams The additional attributes for the image tag
1555 * @param integer $size The size of the thumbnail send along to "thumbs.php
1556 * @return string Image tag
1558 static public function getThumbNail($thumbScript, $theFile, $tparams = '', $size = '') {
1559 $check = basename($theFile) . ':' . filemtime($theFile) . ':' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
1560 $params = '&file=' . rawurlencode($theFile);
1561 $params .= trim($size) ?
'&size=' . trim($size) : '';
1562 $params .= '&md5sum=' . md5($check);
1563 $url = $thumbScript . '?' . $params;
1564 $th = '<img src="' . htmlspecialchars($url) . '" title="' . trim(basename($theFile)) . '"' . ($tparams ?
' ' . $tparams : '') . ' alt="" />';
1569 * Returns title-attribute information for a page-record informing about id, alias, doktype, hidden, starttime, endtime, fe_group etc.
1571 * @param array $row Input must be a page row ($row) with the proper fields set (be sure - send the full range of fields for the table)
1572 * @param string $perms_clause This is used to get the record path of the shortcut page, if any (and doktype==4)
1573 * @param boolean $includeAttrib If $includeAttrib is set, then the 'title=""' attribute is wrapped about the return value, which is in any case htmlspecialchar()'ed already
1576 static public function titleAttribForPages($row, $perms_clause = '', $includeAttrib = 1) {
1578 $parts[] = 'id=' . $row['uid'];
1579 if ($row['alias']) {
1580 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['alias']['label']) . ' ' . $row['alias'];
1582 if ($row['pid'] < 0) {
1583 $parts[] = 'v#1.' . $row['t3ver_id'];
1585 switch ($row['t3ver_state']) {
1587 $parts[] = 'PLH WSID#' . $row['t3ver_wsid'];
1590 $parts[] = 'Deleted element!';
1593 $parts[] = 'NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1596 $parts[] = 'OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1599 $parts[] = 'New element!';
1602 if ($row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_LINK
) {
1603 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['url']['label']) . ' ' . $row['url'];
1604 } elseif ($row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_SHORTCUT
) {
1605 if ($perms_clause) {
1606 $label = self
::getRecordPath(intval($row['shortcut']), $perms_clause, 20);
1608 $row['shortcut'] = intval($row['shortcut']);
1609 $lRec = self
::getRecordWSOL('pages', $row['shortcut'], 'title');
1610 $label = $lRec['title'] . ' (id=' . $row['shortcut'] . ')';
1612 if ($row['shortcut_mode'] != \TYPO3\CMS\Frontend\Page\PageRepository
::SHORTCUT_MODE_NONE
) {
1613 $label .= ', ' . $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['shortcut_mode']['label']) . ' ' . $GLOBALS['LANG']->sL(self
::getLabelFromItemlist('pages', 'shortcut_mode', $row['shortcut_mode']));
1615 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['shortcut']['label']) . ' ' . $label;
1616 } elseif ($row['doktype'] == \TYPO3\CMS\Frontend\Page\PageRepository
::DOKTYPE_MOUNTPOINT
) {
1617 if ($perms_clause) {
1618 $label = self
::getRecordPath(intval($row['mount_pid']), $perms_clause, 20);
1620 $lRec = self
::getRecordWSOL('pages', intval($row['mount_pid']), 'title');
1621 $label = $lRec['title'];
1623 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['mount_pid']['label']) . ' ' . $label;
1624 if ($row['mount_pid_ol']) {
1625 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['mount_pid_ol']['label']);
1628 if ($row['nav_hide']) {
1629 $parts[] = rtrim($GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['nav_hide']['label']), ':');
1631 if ($row['hidden']) {
1632 $parts[] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden');
1634 if ($row['starttime']) {
1635 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['starttime']['label']) . ' ' . self
::dateTimeAge($row['starttime'], -1, 'date');
1637 if ($row['endtime']) {
1638 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['endtime']['label']) . ' ' . self
::dateTimeAge($row['endtime'], -1, 'date');
1640 if ($row['fe_group']) {
1641 $fe_groups = array();
1642 foreach (\TYPO3\CMS\Core\Utility\GeneralUtility
::intExplode(',', $row['fe_group']) as $fe_group) {
1643 if ($fe_group < 0) {
1644 $fe_groups[] = $GLOBALS['LANG']->sL(self
::getLabelFromItemlist('pages', 'fe_group', $fe_group));
1646 $lRec = self
::getRecordWSOL('fe_groups', $fe_group, 'title');
1647 $fe_groups[] = $lRec['title'];
1650 $label = implode(', ', $fe_groups);
1651 $parts[] = $GLOBALS['LANG']->sL($GLOBALS['TCA']['pages']['columns']['fe_group']['label']) . ' ' . $label;
1653 $out = htmlspecialchars(implode(' - ', $parts));
1654 return $includeAttrib ?
'title="' . $out . '"' : $out;
1658 * Returns title-attribute information for ANY record (from a table defined in TCA of course)
1659 * 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.
1660 * "pages" table can be used as well and will return the result of ->titleAttribForPages() for that page.
1662 * @param array $row Table row; $row is a row from the table, $table
1663 * @param string $table Table name
1666 static public function getRecordIconAltText($row, $table = 'pages') {
1667 if ($table == 'pages') {
1668 $out = self
::titleAttribForPages($row, '', 0);
1670 $ctrl = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1672 $out = 'id=' . $row['uid'];
1673 if ($table == 'pages' && $row['alias']) {
1674 $out .= ' / ' . $row['alias'];
1676 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] && $row['pid'] < 0) {
1677 $out .= ' - v#1.' . $row['t3ver_id'];
1679 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
1680 switch ($row['t3ver_state']) {
1682 $out .= ' - PLH WSID#' . $row['t3ver_wsid'];
1685 $out .= ' - Deleted element!';
1688 $out .= ' - NEW LOCATION (PLH) WSID#' . $row['t3ver_wsid'];
1691 $out .= ' - OLD LOCATION (PNT) WSID#' . $row['t3ver_wsid'];
1694 $out .= ' - New element!';
1699 if ($ctrl['disabled']) {
1700 $out .= $row[$ctrl['disabled']] ?
' - ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden') : '';
1702 if ($ctrl['starttime']) {
1703 if ($row[$ctrl['starttime']] > $GLOBALS['EXEC_TIME']) {
1704 $out .= ' - ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.starttime') . ':' . self
::date($row[$ctrl['starttime']]) . ' (' . self
::daysUntil($row[$ctrl['starttime']]) . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.days') . ')';
1707 if ($row[$ctrl['endtime']]) {
1708 $out .= ' - ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.endtime') . ': ' . self
::date($row[$ctrl['endtime']]) . ' (' . self
::daysUntil($row[$ctrl['endtime']]) . ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.days') . ')';
1711 return htmlspecialchars($out);
1715 * Returns the label of the first found entry in an "items" array from $GLOBALS['TCA'] (tablename = $table/fieldname = $col) where the value is $key
1717 * @param string $table Table name, present in $GLOBALS['TCA']
1718 * @param string $col Field name, present in $GLOBALS['TCA']
1719 * @param string $key items-array value to match
1720 * @return string Label for item entry
1722 static public function getLabelFromItemlist($table, $col, $key) {
1723 // Check, if there is an "items" array:
1724 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$col]) && is_array($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'])) {
1725 // Traverse the items-array...
1726 foreach ($GLOBALS['TCA'][$table]['columns'][$col]['config']['items'] as $k => $v) {
1727 // ... and return the first found label where the value was equal to $key
1728 if (!strcmp($v[1], $key)) {
1736 * Return the label of a field by additionally checking TsConfig values
1738 * @param integer $pageId Page id
1739 * @param string $table Table name
1740 * @param string $column Field Name
1741 * @param string $key item value
1742 * @return string Label for item entry
1744 static public function getLabelFromItemListMerged($pageId, $table, $column, $key) {
1745 $pageTsConfig = self
::getPagesTSconfig($pageId);
1747 if (is_array($pageTsConfig['TCEFORM.']) && is_array($pageTsConfig['TCEFORM.'][$table . '.']) && is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.'])) {
1748 if (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.']) && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key])) {
1749 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['addItems.'][$key];
1750 } elseif (is_array($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.']) && isset($pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key])) {
1751 $label = $pageTsConfig['TCEFORM.'][$table . '.'][$column . '.']['altLabels.'][$key];
1754 if (empty($label)) {
1755 $tcaValue = self
::getLabelFromItemlist($table, $column, $key);
1756 if (!empty($tcaValue)) {
1764 * Splits the given key with commas and returns the list of all the localized items labels, separated by a comma.
1765 * NOTE: this does not take itemsProcFunc into account
1767 * @param string $table Table name, present in TCA
1768 * @param string $column Field name
1769 * @param string $key Key or comma-separated list of keys.
1770 * @return string Comma-separated list of localized labels
1772 static public function getLabelsFromItemsList($table, $column, $key) {
1774 $values = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $key, TRUE);
1775 if (count($values) > 0) {
1776 // Check if there is an "items" array
1777 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]) && is_array($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'])) {
1778 // Loop on all selected values
1779 foreach ($values as $aValue) {
1780 foreach ($GLOBALS['TCA'][$table]['columns'][$column]['config']['items'] as $itemConfiguration) {
1781 // Loop on all available items
1782 // Keep matches and move on to next value
1783 if ($aValue == $itemConfiguration[1]) {
1784 $labels[] = $GLOBALS['LANG']->sL($itemConfiguration[0]);
1791 return implode(', ', $labels);
1795 * Returns the label-value for fieldname $col in table, $table
1796 * 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 = '<strong>|</strong>' and the fieldname was 'not_found_field' then the return value would be '<strong>not_found_field</strong>'
1798 * @param string $table Table name, present in $GLOBALS['TCA']
1799 * @param string $col Field name
1800 * @param string $printAllWrap Wrap value - set function description
1803 static public function getItemLabel($table, $col, $printAllWrap = '') {
1804 // Check if column exists
1805 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
1806 return $GLOBALS['TCA'][$table]['columns'][$col]['label'];
1808 if ($printAllWrap) {
1809 $parts = explode('|', $printAllWrap);
1810 return $parts[0] . $col . $parts[1];
1815 * Returns the "title"-value in record, $row, from table, $table
1816 * The field(s) from which the value is taken is determined by the "ctrl"-entries 'label', 'label_alt' and 'label_alt_force'
1818 * @param string $table Table name, present in TCA
1819 * @param array $row Row from table
1820 * @param boolean $prep If set, result is prepared for output: The output is cropped to a limited lenght (depending on BE_USER->uc['titleLen']) and if no value is found for the title, '<em>[No title]</em>' is returned (localized). Further, the output is htmlspecialchars()'ed
1821 * @param boolean $forceResult If set, the function always returns an output. If no value is found for the title, '[No title]' is returned (localized).
1824 static public function getRecordTitle($table, $row, $prep = FALSE, $forceResult = TRUE) {
1825 if (is_array($GLOBALS['TCA'][$table])) {
1826 // If configured, call userFunc
1827 if ($GLOBALS['TCA'][$table]['ctrl']['label_userFunc']) {
1828 $params['table'] = $table;
1829 $params['row'] = $row;
1830 $params['title'] = '';
1831 // Create NULL-reference
1833 \TYPO3\CMS\Core\Utility\GeneralUtility
::callUserFunction($GLOBALS['TCA'][$table]['ctrl']['label_userFunc'], $params, $null);
1834 $t = $params['title'];
1836 // No userFunc: Build label
1837 $t = self
::getProcessedValue($table, $GLOBALS['TCA'][$table]['ctrl']['label'], $row[$GLOBALS['TCA'][$table]['ctrl']['label']], 0, 0, FALSE, $row['uid'], $forceResult);
1838 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt'] && ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force'] ||
!strcmp($t, ''))) {
1839 $altFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], 1);
1844 foreach ($altFields as $fN) {
1845 $t = trim(strip_tags($row[$fN]));
1846 if (strcmp($t, '')) {
1847 $t = self
::getProcessedValue($table, $fN, $t, 0, 0, FALSE, $row['uid']);
1848 if (!$GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
1854 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt_force']) {
1855 $t = implode(', ', $tA);
1859 // If the current result is empty, set it to '[No title]' (localized) and prepare for output if requested
1860 if ($prep ||
$forceResult) {
1862 $t = self
::getRecordTitlePrep($t);
1864 if (!strcmp(trim($t), '')) {
1865 $t = self
::getNoRecordTitle($prep);
1873 * Crops a title string to a limited lenght and if it really was cropped, wrap it in a <span title="...">|</span>,
1874 * which offers a tooltip with the original title when moving mouse over it.
1876 * @param string $title The title string to be cropped
1877 * @param integer $titleLength Crop title after this length - if not set, BE_USER->uc['titleLen'] is used
1878 * @return string The processed title string, wrapped in <span title="...">|</span> if cropped
1880 static public function getRecordTitlePrep($title, $titleLength = 0) {
1881 // If $titleLength is not a valid positive integer, use BE_USER->uc['titleLen']:
1882 if (!$titleLength ||
!\TYPO3\CMS\Core\Utility\MathUtility
::canBeInterpretedAsInteger($titleLength) ||
$titleLength < 0) {
1883 $titleLength = $GLOBALS['BE_USER']->uc
['titleLen'];
1885 $titleOrig = htmlspecialchars($title);
1886 $title = htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility
::fixed_lgd_cs($title, $titleLength));
1887 // If title was cropped, offer a tooltip:
1888 if ($titleOrig != $title) {
1889 $title = '<span title="' . $titleOrig . '">' . $title . '</span>';
1895 * Get a localized [No title] string, wrapped in <em>|</em> if $prep is TRUE.
1897 * @param boolean $prep Wrap result in <em>|</em>
1898 * @return string Localized [No title] string
1900 static public function getNoRecordTitle($prep = FALSE) {
1901 $noTitle = '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', 1) . ']';
1903 $noTitle = '<em>' . $noTitle . '</em>';
1909 * Returns a human readable output of a value from a record
1910 * 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.
1911 * $table/$col is tablename and fieldname
1912 * REMEMBER to pass the output through htmlspecialchars() if you output it to the browser! (To protect it from XSS attacks and be XHTML compliant)
1914 * @param string $table Table name, present in TCA
1915 * @param string $col Field name, present in TCA
1916 * @param string $value The value of that field from a selected record
1917 * @param integer $fixed_lgd_chars The max amount of characters the value may occupy
1918 * @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")
1919 * @param boolean $noRecordLookup If set, no records will be looked up, UIDs are just shown.
1920 * @param integer $uid Uid of the current record
1921 * @param boolean $forceResult If \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
1924 static public function getProcessedValue($table, $col, $value, $fixed_lgd_chars = 0, $defaultPassthrough = 0, $noRecordLookup = FALSE, $uid = 0, $forceResult = TRUE) {
1925 if ($col == 'uid') {
1926 // No need to load TCA as uid is not in TCA-array
1929 // Check if table and field is configured:
1930 if (is_array($GLOBALS['TCA'][$table]) && is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
1931 // Depending on the fields configuration, make a meaningful output value.
1932 $theColConf = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
1934 *HOOK: pre-processing the human readable output from a record
1936 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'])) {
1937 // Create NULL-reference
1939 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['preProcessValue'] as $_funcRef) {
1940 \TYPO3\CMS\Core\Utility\GeneralUtility
::callUserFunction($_funcRef, $theColConf, $null);
1944 switch ((string) $theColConf['type']) {
1946 $l = self
::getLabelFromItemlist($table, $col, $value);
1947 $l = $GLOBALS['LANG']->sL($l);
1950 if ($theColConf['MM']) {
1952 // Display the title of MM related records in lists
1953 if ($noRecordLookup) {
1954 $MMfield = $theColConf['foreign_table'] . '.uid';
1956 $MMfields = array($theColConf['foreign_table'] . '.' . $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label']);
1957 foreach (\TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$theColConf['foreign_table']]['ctrl']['label_alt'], 1) as $f) {
1958 $MMfields[] = $theColConf['foreign_table'] . '.' . $f;
1960 $MMfield = join(',', $MMfields);
1962 /** @var $dbGroup \TYPO3\CMS\Core\Database\RelationHandler */
1963 $dbGroup = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
1964 $dbGroup->start($value, $theColConf['foreign_table'], $theColConf['MM'], $uid, $table, $theColConf);
1965 $selectUids = $dbGroup->tableArray
[$theColConf['foreign_table']];
1966 if (is_array($selectUids) && count($selectUids) > 0) {
1967 $MMres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, ' . $MMfield, $theColConf['foreign_table'], 'uid IN (' . implode(',', $selectUids) . ')' . self
::deleteClause($theColConf['foreign_table']));
1968 while ($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres)) {
1969 $mmlA[] = $noRecordLookup ?
$MMrow['uid'] : self
::getRecordTitle($theColConf['foreign_table'], $MMrow, FALSE, $forceResult);
1971 $GLOBALS['TYPO3_DB']->sql_free_result($MMres);
1972 if (is_array($mmlA)) {
1973 $l = implode('; ', $mmlA);
1984 $l = self
::getLabelsFromItemsList($table, $col, $value);
1985 if ($theColConf['foreign_table'] && !$l && $GLOBALS['TCA'][$theColConf['foreign_table']]) {
1986 if ($noRecordLookup) {
1989 $rParts = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $value, 1);
1991 foreach ($rParts as $rVal) {
1992 $rVal = intval($rVal);
1994 $r = self
::getRecordWSOL($theColConf['foreign_table'], $rVal);
1996 $r = self
::getRecordWSOL($theColConf['neg_foreign_table'], -$rVal);
1999 $lA[] = $GLOBALS['LANG']->sL(($rVal > 0 ?
$theColConf['foreign_table_prefix'] : $theColConf['neg_foreign_table_prefix'])) . self
::getRecordTitle(($rVal > 0 ?
$theColConf['foreign_table'] : $theColConf['neg_foreign_table']), $r, FALSE, $forceResult);
2001 $lA[] = $rVal ?
'[' . $rVal . '!]' : '';
2004 $l = implode(', ', $lA);
2010 $l = implode(', ', \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $value, 1));
2013 if (!is_array($theColConf['items']) ||
count($theColConf['items']) == 1) {
2014 $l = $value ?
$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes') : $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:no');
2017 foreach ($theColConf['items'] as $key => $val) {
2018 if ($value & pow(2, $key)) {
2019 $lA[] = $GLOBALS['LANG']->sL($val[0]);
2022 $l = implode(', ', $lA);
2026 // Hide value 0 for dates, but show it for everything else
2027 if (isset($value)) {
2028 if (\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($theColConf['eval'], 'date')) {
2029 // Handle native date field
2030 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'date') {
2031 $dateTimeFormats = $GLOBALS['TYPO3_DB']->getDateTimeFormats($table);
2032 $emptyValue = $dateTimeFormats['date']['empty'];
2033 $value = $value !== $emptyValue ?
strtotime($value) : 0;
2035 if (!empty($value)) {
2036 $l = self
::date($value) . ' (' . ($GLOBALS['EXEC_TIME'] - $value > 0 ?
'-' : '') . self
::calcAge(abs(($GLOBALS['EXEC_TIME'] - $value)), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')) . ')';
2038 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($theColConf['eval'], 'time')) {
2039 if (!empty($value)) {
2040 $l = self
::time($value, FALSE);
2042 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($theColConf['eval'], 'timesec')) {
2043 if (!empty($value)) {
2044 $l = self
::time($value);
2046 } elseif (\TYPO3\CMS\Core\Utility\GeneralUtility
::inList($theColConf['eval'], 'datetime')) {
2047 // Handle native date/time field
2048 if (isset($theColConf['dbType']) && $theColConf['dbType'] === 'datetime') {
2049 $dateTimeFormats = $GLOBALS['TYPO3_DB']->getDateTimeFormats($table);
2050 $emptyValue = $dateTimeFormats['datetime']['empty'];
2051 $value = $value !== $emptyValue ?
strtotime($value) : 0;
2053 if (!empty($value)) {
2054 $l = self
::datetime($value);
2062 $l = strip_tags($value);
2065 if ($defaultPassthrough) {
2067 } elseif ($theColConf['MM']) {
2070 $l = \TYPO3\CMS\Core\Utility\GeneralUtility
::fixed_lgd_cs(strip_tags($value), 200);
2074 // If this field is a password field, then hide the password by changing it to a random number of asterisk (*)
2075 if (stristr($theColConf['eval'], 'password')) {
2077 $randomNumber = rand(5, 12);
2078 for ($i = 0; $i < $randomNumber; $i++
) {
2083 *HOOK: post-processing the human readable output from a record
2085 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'])) {
2086 // Create NULL-reference
2088 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['postProcessValue'] as $_funcRef) {
2091 'colConf' => $theColConf
2093 $l = \TYPO3\CMS\Core\Utility\GeneralUtility
::callUserFunction($_funcRef, $params, $null);
2096 if ($fixed_lgd_chars) {
2097 return \TYPO3\CMS\Core\Utility\GeneralUtility
::fixed_lgd_cs($l, $fixed_lgd_chars);
2105 * 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.
2107 * @param string $table Table name, present in TCA
2108 * @param string $fN Field name
2109 * @param string $fV Field value
2110 * @param integer $fixed_lgd_chars The max amount of characters the value may occupy
2111 * @param integer $uid Uid of the current record
2112 * @param boolean $forceResult If \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle is used to process the value, this parameter is forwarded.
2114 * @see getProcessedValue()
2116 static public function getProcessedValueExtra($table, $fN, $fV, $fixed_lgd_chars = 0, $uid = 0, $forceResult = TRUE) {
2117 $fVnew = self
::getProcessedValue($table, $fN, $fV, $fixed_lgd_chars, 1, 0, $uid, $forceResult);
2118 if (!isset($fVnew)) {
2119 if (is_array($GLOBALS['TCA'][$table])) {
2120 if ($fN == $GLOBALS['TCA'][$table]['ctrl']['tstamp'] ||
$fN == $GLOBALS['TCA'][$table]['ctrl']['crdate']) {
2121 $fVnew = self
::datetime($fV);
2122 } elseif ($fN == 'pid') {
2123 // Fetches the path with no regard to the users permissions to select pages.
2124 $fVnew = self
::getRecordPath($fV, '1=1', 20);
2134 * Returns file icon name (from $FILEICONS) for the fileextension $ext
2136 * @param string $ext File extension, lowercase
2137 * @return string File icon filename
2139 static public function getFileIcon($ext) {
2140 return $GLOBALS['FILEICONS'][$ext] ?
$GLOBALS['FILEICONS'][$ext] : $GLOBALS['FILEICONS']['default'];
2144 * Returns fields for a table, $table, which would typically be interesting to select
2145 * This includes uid, the fields defined for title, icon-field.
2146 * 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)
2148 * @param string $table Table name, present in $GLOBALS['TCA']
2149 * @param string $prefix Table prefix
2150 * @param array $fields Preset fields (must include prefix if that is used)
2151 * @return string List of fields.
2153 static public function getCommonSelectFields($table, $prefix = '', $fields = array()) {
2154 $fields[] = $prefix . 'uid';
2155 if (isset($GLOBALS['TCA'][$table]['ctrl']['label']) && $GLOBALS['TCA'][$table]['ctrl']['label'] != '') {
2156 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['label'];
2158 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
2159 $secondFields = \TYPO3\CMS\Core\Utility\GeneralUtility
::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], 1);
2160 foreach ($secondFields as $fieldN) {
2161 $fields[] = $prefix . $fieldN;
2164 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
2165 $fields[] = $prefix . 't3ver_id';
2166 $fields[] = $prefix . 't3ver_state';
2167 $fields[] = $prefix . 't3ver_wsid';
2168 $fields[] = $prefix . 't3ver_count';
2170 if ($GLOBALS['TCA'][$table]['ctrl']['selicon_field']) {
2171 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['selicon_field'];
2173 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
2174 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
2176 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
2177 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {
2178 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
2180 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']) {
2181 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'];
2183 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']) {
2184 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'];
2186 if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']) {
2187 $fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'];
2190 return implode(',', array_unique($fields));
2194 * Makes a form for configuration of some values based on configuration found in the array $configArray,
2195 * with default values from $defaults and a data-prefix $dataPrefix
2196 * <form>-tags must be supplied separately
2197 * Needs more documentation and examples, in particular syntax for configuration array. See Inside TYPO3.
2198 * That's were you can expect to find example, if anywhere.
2200 * @param array $configArray Field configuration code.
2201 * @param array $defaults Defaults
2202 * @param string $dataPrefix Prefix for formfields
2203 * @return string HTML for a form.
2205 static public function makeConfigForm($configArray, $defaults, $dataPrefix) {
2206 $params = $defaults;
2207 if (is_array($configArray)) {
2209 foreach ($configArray as $fname => $config) {
2210 if (is_array($config)) {
2211 $lines[$fname] = '<strong>' . htmlspecialchars($config[1]) . '</strong><br />';
2212 $lines[$fname] .= $config[2] . '<br />';
2213 switch ($config[0]) {
2217 $formEl = '<input type="text" name="' . $dataPrefix . '[' . $fname . ']" value="' . $params[$fname] . '"' . $GLOBALS['TBE_TEMPLATE']->formWidth(($config[0] == 'short' ?
24 : 48)) . ' />';
2220 $formEl = '<input type="hidden" name="' . $dataPrefix . '[' . $fname . ']" value="0" /><input type="checkbox" name="' . $dataPrefix . '[' . $fname . ']" value="1"' . ($params[$fname] ?
' checked="checked"' : '') . ' />';
2227 foreach ($config[3] as $k => $v) {
2228 $opt[] = '<option value="' . htmlspecialchars($k) . '"' . ($params[$fname] == $k ?
' selected="selected"' : '') . '>' . htmlspecialchars($v) . '</option>';
2230 $formEl = '<select name="' . $dataPrefix . '[' . $fname . ']">' . implode('', $opt) . '</select>';
2236 $lines[$fname] .= $formEl;
2237 $lines[$fname] .= '<br /><br />';
2239 $lines[$fname] = '<hr />';
2241 $lines[$fname] .= '<strong>' . strtoupper(htmlspecialchars($config)) . '</strong><br />';
2244 $lines[$fname] .= '<br />';
2249 $out = implode('', $lines);
2250 $out .= '<input type="submit" name="submit" value="Update configuration" />';
2254 /*******************************************
2256 * Backend Modules API functions
2258 *******************************************/
2260 * Returns help-text icon if configured for.
2261 * TCA_DESCR must be loaded prior to this function and $GLOBALS['BE_USER'] must
2262 * have 'edit_showFieldHelp' set to 'icon', otherwise nothing is returned
2264 * Please note: since TYPO3 4.5 the UX team decided to not use CSH in its former way,
2265 * but to wrap the given text (where before the help icon was, and you could hover over it)
2266 * Please also note that since TYPO3 4.5 the option to enable help (none, icon only, full text)
2267 * was completely removed.
2269 * @param string $table Table name
2270 * @param string $field Field name
2271 * @param string $BACK_PATH Back path
2272 * @param boolean $force Force display of icon no matter BE_USER setting for help
2273 * @return string HTML content for a help icon/text
2275 static public function helpTextIcon($table, $field, $BACK_PATH, $force = 0) {
2276 if (is_array($GLOBALS['TCA_DESCR'][$table]) && is_array($GLOBALS['TCA_DESCR'][$table]['columns'][$field]) && (isset($GLOBALS['BE_USER']->uc
['edit_showFieldHelp']) ||
$force)) {
2277 return self
::wrapInHelp($table, $field);
2282 * Returns CSH help text (description), if configured for, as an array (title, description)
2284 * @param string $table Table name
2285 * @param string $field Field name
2286 * @return array With keys 'description' (raw, as available in locallang), 'title' (optional), 'moreInfo'
2288 static public function helpTextArray($table, $field) {
2289 if (!isset($GLOBALS['TCA_DESCR'][$table]['columns'])) {
2290 $GLOBALS['LANG']->loadSingleTableDescription($table);
2293 'description' => NULL,
2297 if (is_array($GLOBALS['TCA_DESCR'][$table]) && is_array($GLOBALS['TCA_DESCR'][$table]['columns'][$field])) {
2298 $data = $GLOBALS['TCA_DESCR'][$table]['columns'][$field];
2299 // Add alternative title, if defined
2300 if ($data['alttitle']) {
2301 $output['title'] = $data['alttitle'];
2303 // If we have more information to show
2304 if ($data['image_descr'] ||
$data['seeAlso'] ||
$data['details'] ||
$data['syntax']) {
2305 $output['moreInfo'] = TRUE;
2308 if ($data['description']) {
2309 $output['description'] = $data['description'];
2316 * Returns CSH help text
2318 * @param string $table Table name
2319 * @param string $field Field name
2320 * @return string HTML content for help text
2323 static public function helpText($table, $field) {
2324 $helpTextArray = self
::helpTextArray($table, $field);
2327 // Put header before the rest of the text
2328 if ($helpTextArray['title'] !== NULL) {
2329 $output .= '<h2 class="t3-row-header">' . $helpTextArray['title'] . '</h2>';
2331 // Add see also arrow if we have more info
2332 if ($helpTextArray['moreInfo']) {
2333 $arrow = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-view-go-forward');
2335 // Wrap description and arrow in p tag
2336 if ($helpTextArray['description'] !== NULL ||
$arrow) {
2337 $output .= '<p class="t3-help-short">' . nl2br(htmlspecialchars($helpTextArray['description'])) . $arrow . '</p>';
2343 * API function that wraps the text / html in help text, so if a user hovers over it
2344 * the help text will show up
2345 * This is the new help API function since TYPO3 4.5, and uses the new behaviour
2346 * (hover over text, no icon, no fulltext option, no option to disable the help)
2348 * @param string $table The table name for which the help should be shown
2349 * @param string $field The field name for which the help should be shown
2350 * @param string $text The text which should be wrapped with the help text
2351 * @param array $overloadHelpText Array with text to overload help text
2352 * @return string the HTML code ready to render
2354 static public function wrapInHelp($table, $field, $text = '', array $overloadHelpText = array()) {
2355 // Initialize some variables
2358 $wrappedText = $text;
2359 $hasHelpTextOverload = count($overloadHelpText) > 0;
2360 // Get the help text that should be shown on hover
2361 if (!$hasHelpTextOverload) {
2362 $helpText = self
::helpText($table, $field);
2364 // If there's a help text or some overload information, proceed with preparing an output
2365 if (!empty($helpText) ||
$hasHelpTextOverload) {
2366 // If no text was given, just use the regular help icon
2368 $text = \TYPO3\CMS\Backend\Utility\IconUtility
::getSpriteIcon('actions-system-help-open');
2369 $abbrClassAdd = '-icon';
2371 $text = '<abbr class="t3-help-teaser' . $abbrClassAdd . '">' . $text . '</abbr>';
2372 $wrappedText = '<span class="t3-help-link" href="#" data-table="' . $table . '" data-field="' . $field . '"';
2373 // The overload array may provide a title and a description
2374 // If either one is defined, add them to the "data" attributes
2375 if ($hasHelpTextOverload) {
2376 if (isset($overloadHelpText['title'])) {
2377 $wrappedText .= ' data-title="' . htmlspecialchars($overloadHelpText['title']) . '"';
2379 if (isset($overloadHelpText['description'])) {
2380 $wrappedText .= ' data-description="' . htmlspecialchars($overloadHelpText['description']) . '"';
2383 $wrappedText .= '>' . $text . '</span>';
2385 return $wrappedText;
2389 * API for getting CSH icons/text for use in backend modules.
2390 * TCA_DESCR will be loaded if it isn't already
2392 * @param string $table Table name ('_MOD_'+module name)
2393 * @param string $field Field name (CSH locallang main key)
2394 * @param string $BACK_PATH Back path
2395 * @param string $wrap Wrap code for icon-mode, splitted by "|". Not used for full-text mode.
2396 * @param boolean $onlyIconMode 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.
2397 * @param string $styleAttrib Additional style-attribute content for wrapping table (full text mode only)
2398 * @return string HTML content for help text
2399 * @see helpTextIcon()
2401 static public function cshItem($table, $field, $BACK_PATH, $wrap = '', $onlyIconMode = FALSE, $styleAttrib = '') {
2402 if (!$GLOBALS['BE_USER']->uc
['edit_showFieldHelp']) {
2405 $GLOBALS['LANG']->loadSingleTableDescription($table);
2406 if (is_array($GLOBALS['TCA_DESCR'][$table])) {
2407 // Creating CSH icon and short description:
2408 $output = self
::helpTextIcon($table, $field, $BACK_PATH);
2409 if ($output && $wrap) {
2410 $wrParts = explode('|', $wrap);
2411 $output = $wrParts[0] . $output . $wrParts[1];
2418 * 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.
2419 * REMEMBER to always htmlspecialchar() content in href-properties to ampersands get converted to entities (XHTML requirement and XSS precaution)
2421 * @param string $params 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.
2422 * @param string $backPath Must point back to the TYPO3_mainDir directory (where alt_doc.php is)
2423 * @param string $requestUri An optional returnUrl you can set - automatically set to REQUEST_URI.
2425 * @see template::issueCommand()
2427 static public function editOnClick($params, $backPath = '', $requestUri = '') {
2428 $retUrl = 'returnUrl=' . ($requestUri == -1 ?
'\'+T3_THIS_LOCATION+\'' : rawurlencode(($requestUri ?
$requestUri : \TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('REQUEST_URI'))));
2429 return 'window.location.href=\'' . $backPath . 'alt_doc.php?' . $retUrl . $params . '\'; return false;';
2433 * Returns a JavaScript string for viewing the page id, $id
2434 * It will detect the correct domain name if needed and provide the link with the right back path.
2435 * Also it will re-use any window already open.
2437 * @param integer $pageUid Page id
2438 * @param string $backPath Must point back to TYPO3_mainDir (where the site is assumed to be one level above)
2439 * @param array $rootLine If root line is supplied the function will look for the first found domain record and use that URL instead (if found)
2440 * @param string $anchorSection Optional anchor to the URL
2441 * @param string $alternativeUrl 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!
2442 * @param string $additionalGetVars Additional GET variables.
2443 * @param boolean $switchFocus If TRUE, then the preview window will gain the focus.
2446 static public function viewOnClick($pageUid, $backPath = '', $rootLine = '', $anchorSection = '', $alternativeUrl = '', $additionalGetVars = '', $switchFocus = TRUE) {
2447 $viewScript = '/index.php?id=';
2448 if ($alternativeUrl) {
2449 $viewScript = $alternativeUrl;
2451 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'])) {
2452 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['viewOnClickClass'] as $funcRef) {
2453 $hookObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::getUserObj($funcRef);
2454 if (method_exists($hookObj, 'preProcess')) {
2455 $hookObj->preProcess($pageUid, $backPath, $rootLine, $anchorSection, $viewScript, $additionalGetVars, $switchFocus);
2459 // Look if a fixed preview language should be added:
2460 $viewLanguageOrder = $GLOBALS['BE_USER']->getTSConfigVal('options.view.languageOrder');
2461 if (strlen($viewLanguageOrder)) {
2463 // Find allowed languages (if none, all are allowed!)
2464 if (!$GLOBALS['BE_USER']->user
['admin'] && strlen($GLOBALS['BE_USER']->groupData
['allowed_languages'])) {
2465 $allowedLanguages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData
['allowed_languages']));
2467 // Traverse the view order, match first occurence:
2468 $languageOrder = \TYPO3\CMS\Core\Utility\GeneralUtility
::intExplode(',', $viewLanguageOrder);
2469 foreach ($languageOrder as $langUid) {
2470 if (is_array($allowedLanguages) && count($allowedLanguages)) {
2472 if (isset($allowedLanguages[$langUid])) {
2473 $suffix = '&L=' . $langUid;
2477 // All allowed since no lang. are listed.
2478 $suffix = '&L=' . $langUid;
2483 $additionalGetVars .= $suffix;
2485 // Check a mount point needs to be previewed
2486 $sys_page = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
2487 $sys_page->init(FALSE);
2488 $mountPointInfo = $sys_page->getMountPointInfo($pageUid);
2489 if ($mountPointInfo && $mountPointInfo['overlay']) {
2490 $pageUid = $mountPointInfo['mount_pid'];
2491 $additionalGetVars .= '&MP=' . $mountPointInfo['MPvar'];
2493 $viewDomain = self
::getViewDomain($pageUid, $rootLine);
2494 $previewUrl = $viewDomain . $viewScript . $pageUid . $additionalGetVars . $anchorSection;
2495 $onclickCode = 'var previewWin = window.open(\'' . $previewUrl . '\',\'newTYPO3frontendWindow\');' . ($switchFocus ?
'previewWin.focus();' : '');
2496 return $onclickCode;
2500 * Builds the frontend view domain for a given page ID with a given root
2503 * @param integer $pageId The page ID to use, must be > 0
2504 * @param array $rootLine The root line structure to use
2505 * @return string The full domain including the protocol http:// or https://, but without the trailing '/'
2506 * @author Michael Klapper <michael.klapper@aoemedia.de>
2508 static public function getViewDomain($pageId, $rootLine = NULL) {
2509 $domain = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SITE_URL'), '/');
2510 if (!is_array($rootLine)) {
2511 $rootLine = self
::BEgetRootLine($pageId);
2513 // Checks alternate domains
2514 if (count($rootLine) > 0) {
2515 $urlParts = parse_url($domain);
2516 /** @var \TYPO3\CMS\Frontend\Page\PageRepository $sysPage */
2517 $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
2518 $page = (array) $sysPage->getPage($pageId);
2520 if ($page['url_scheme'] == \TYPO3\CMS\Core\Utility\HttpUtility
::SCHEME_HTTPS ||
$page['url_scheme'] == 0 && \TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SSL')) {
2521 $protocol = 'https';
2523 $domainName = self
::firstDomainRecord($rootLine);
2525 $domain = $domainName;
2527 $domainRecord = self
::getDomainStartPage($urlParts['host'], $urlParts['path']);
2528 $domain = $domainRecord['domainName'];
2531 $domain = $protocol . '://' . $domain;
2533 $domain = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility
::getIndpEnv('TYPO3_SITE_URL'), '/');
2535 // Append port number if lockSSLPort is not the standard port 443
2536 $portNumber = intval($GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']);
2537 if ($portNumber > 0 && $portNumber !== 443 && $portNumber < 65536 && $protocol === 'https') {
2538 $domain .= ':' . strval($portNumber);
2545 * Returns the merged User/Page TSconfig for page id, $id.
2546 * Please read details about module programming elsewhere!
2548 * @param integer $id Page uid
2549 * @param string $TSref An object string which determines the path of the TSconfig to return.
2552 static public function getModTSconfig($i