0ed9f04513e3cc1e92b25b9c909bcfa7aab06bb9
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Controller\PageLayoutController;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\Utility\IconUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Database\DatabaseConnection;
22 use TYPO3\CMS\Core\Messaging\FlashMessage;
23 use TYPO3\CMS\Core\Type\Bitmask\Permission;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Core\Versioning\VersionState;
26
27 /**
28 * Child class for the Web > Page module
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32 class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList {
33
34 /**
35 * If TRUE, users/groups are shown in the page info box.
36 *
37 * @var int
38 */
39 public $pI_showUser = 0;
40
41 /**
42 * The number of successive records to edit when showing content elements.
43 *
44 * @var int
45 */
46 public $nextThree = 3;
47
48 /**
49 * If TRUE, disables the edit-column icon for tt_content elements
50 *
51 * @var int
52 */
53 public $pages_noEditColumns = 0;
54
55 /**
56 * If TRUE, shows big buttons for editing page properties, moving, creating elements etc. in the columns view.
57 *
58 * @var int
59 */
60 public $option_showBigButtons = 1;
61
62 /**
63 * If TRUE, new-wizards are linked to rather than the regular new-element list.
64 *
65 * @var int
66 */
67 public $option_newWizard = 1;
68
69 /**
70 * If set to "1", will link a big button to content element wizard.
71 *
72 * @var int
73 */
74 public $ext_function = 0;
75
76 /**
77 * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
78 *
79 * @var int
80 */
81 public $doEdit = 1;
82
83 /**
84 * Age prefixes for displaying times. May be set externally to localized values.
85 *
86 * @var string
87 */
88 public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
89
90 /**
91 * Array of tables to be listed by the Web > Page module in addition to the default tables.
92 *
93 * @var array
94 */
95 public $externalTables = array();
96
97 /**
98 * "Pseudo" Description -table name
99 *
100 * @var string
101 */
102 public $descrTable;
103
104 /**
105 * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
106 * default language content elements and their translations!
107 *
108 * @var bool
109 */
110 public $defLangBinding = FALSE;
111
112 /**
113 * External, static: Configuration of tt_content element display:
114 *
115 * @var array
116 */
117 public $tt_contentConfig = array(
118 // Boolean: Display info-marks or not
119 'showInfo' => 1,
120 // Boolean: Display up/down arrows and edit icons for tt_content records
121 'showCommands' => 1,
122 'languageCols' => 0,
123 'languageMode' => 0,
124 'languageColsPointer' => 0,
125 'showHidden' => 1,
126 // Displays hidden records as well
127 'sys_language_uid' => 0,
128 // Which language
129 'cols' => '1,0,2,3',
130 'activeCols' => '1,0,2,3'
131 // Which columns can be accessed by current BE user
132 );
133
134 /**
135 * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
136 *
137 * @var array
138 */
139 public $activeTables = array();
140
141 /**
142 * @var array
143 */
144 public $tt_contentData = array(
145 'nextThree' => array(),
146 'prev' => array(),
147 'next' => array()
148 );
149
150 /**
151 * Used to store labels for CTypes for tt_content elements
152 *
153 * @var array
154 */
155 public $CType_labels = array();
156
157 /**
158 * Used to store labels for the various fields in tt_content elements
159 *
160 * @var array
161 */
162 public $itemLabels = array();
163
164 /**
165 * Used to store the RTE setup of a particular page
166 *
167 * @var array
168 */
169 protected $rteSetup = array();
170
171 /**
172 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
173 */
174 protected $clipboard;
175
176 /**
177 * @var array
178 */
179 protected $plusPages = array();
180
181 /**
182 * User permissions
183 *
184 * @var int
185 */
186 public $ext_CALC_PERMS;
187
188 /*****************************************
189 *
190 * Renderings
191 *
192 *****************************************/
193 /**
194 * Adds the code of a single table
195 *
196 * @param string $table Table name
197 * @param int $id Current page id
198 * @return string HTML for listing.
199 */
200 public function getTable($table, $id) {
201 if (isset($this->externalTables[$table])) {
202 return $this->getExternalTables($id, $table);
203 } else {
204 // Branch out based on table name:
205 switch ($table) {
206 case 'pages':
207 return $this->getTable_pages($id);
208 break;
209 case 'tt_content':
210 return $this->getTable_tt_content($id);
211 break;
212 default:
213 return '';
214 }
215 }
216 }
217
218 /**
219 * Renders an external table from page id
220 *
221 * @param int $id Page id
222 * @param string $table Name of the table
223 * @return string HTML for the listing
224 */
225 public function getExternalTables($id, $table) {
226 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
227 if (!isset($type)) {
228 $type = 0;
229 }
230 // eg. "name;title;email;company,image"
231 $fList = $this->externalTables[$table][$type]['fList'];
232 // The columns are separeted by comma ','.
233 // Values separated by semicolon ';' are shown in the same column.
234 $icon = $this->externalTables[$table][$type]['icon'];
235 $addWhere = $this->externalTables[$table][$type]['addWhere'];
236 // Create listing
237 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
238 return $out;
239 }
240
241 /**
242 * Renders records from the pages table from page id
243 * (Used to get information about the page tree content by "Web>Info"!)
244 *
245 * @param int $id Page id
246 * @return string HTML for the listing
247 */
248 public function getTable_pages($id) {
249 // Initializing:
250 $out = '';
251 // Select clause for pages:
252 $delClause = BackendUtility::deleteClause('pages') . ' AND ' . $this->getBackendUser()->getPagePermsClause(1);
253 // Select current page:
254 if (!$id) {
255 // The root has a pseudo record in pageinfo...
256 $row = $this->getPageLayoutController()->pageinfo;
257 } else {
258 $result = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'uid=' . (int)$id . $delClause);
259 $row = $this->getDatabase()->sql_fetch_assoc($result);
260 BackendUtility::workspaceOL('pages', $row);
261 }
262 // If there was found a page:
263 if (is_array($row)) {
264 // Select which fields to show:
265 $pKey = $this->getPageLayoutController()->MOD_SETTINGS['pages'];
266 switch ($pKey) {
267 case 1:
268 $this->fieldArray = array('title','uid') + array_keys($this->cleanTableNames());
269 break;
270 case 2:
271 $this->fieldArray = array(
272 'title',
273 'uid',
274 'lastUpdated',
275 'newUntil',
276 'no_cache',
277 'cache_timeout',
278 'php_tree_stop',
279 'TSconfig',
280 'storage_pid',
281 'is_siteroot',
282 'fe_login_mode'
283 );
284 break;
285 default:
286 $this->fieldArray = array(
287 'title',
288 'uid',
289 'alias',
290 'starttime',
291 'endtime',
292 'fe_group',
293 'target',
294 'url',
295 'shortcut',
296 'shortcut_mode'
297 );
298 }
299 // Getting select-depth:
300 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
301 // Overriding a few things:
302 $this->no_noWrap = 0;
303 // Items
304 $this->eCounter = $this->firstElementNumber;
305 // Creating elements:
306 list($flag, $code) = $this->fwd_rwd_nav();
307 $out .= $code;
308 $editUids = array();
309 if ($flag) {
310 // Getting children:
311 $theRows = array();
312 $theRows = $this->pages_getTree($theRows, $row['uid'], $delClause . BackendUtility::versioningPlaceholderClause('pages'), '', $depth);
313 if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
314 $editUids[] = $row['uid'];
315 }
316 $out .= $this->pages_drawItem($row, $this->fieldArray);
317 // Traverse all pages selected:
318 foreach ($theRows as $sRow) {
319 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
320 $editUids[] = $sRow['uid'];
321 }
322 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
323 }
324 $this->eCounter++;
325 }
326 // Header line is drawn
327 $theData = array();
328 $editIdList = implode(',', $editUids);
329 // Traverse fields (as set above) in order to create header values:
330 foreach ($this->fieldArray as $field) {
331 if ($editIdList && isset($GLOBALS['TCA']['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
332 $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=' . $field;
333 $iTitle = sprintf(
334 $this->getLanguageService()->getLL('editThisColumn'),
335 rtrim(trim($this->getLanguageService()->sL(BackendUtility::getItemLabel('pages', $field))), ':')
336 );
337 $eI = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
338 . '" title="' . htmlspecialchars($iTitle) . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
339 } else {
340 $eI = '';
341 }
342 switch ($field) {
343 case 'title':
344 $theData[$field] = '&nbsp;<strong>'
345 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
346 . '</strong>' . $eI;
347 break;
348 case 'uid':
349 $theData[$field] = '&nbsp;<strong>ID:</strong>';
350 break;
351 default:
352 if (substr($field, 0, 6) == 'table_') {
353 $f2 = substr($field, 6);
354 if ($GLOBALS['TCA'][$f2]) {
355 $theData[$field] = '&nbsp;' . IconUtility::getSpriteIconForRecord($f2, array(), array(
356 'title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$f2]['ctrl']['title'], TRUE)
357 ));
358 }
359 } else {
360 $theData[$field] = '&nbsp;&nbsp;<strong>'
361 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'], TRUE)
362 . '</strong>' . $eI;
363 }
364 }
365 }
366 // CSH:
367 $out = BackendUtility::cshItem($this->descrTable, ('func_' . $pKey)) . '
368 <div class="table-fit">
369 <table class="table table-striped table-hover typo3-page-pages">' .
370 '<thead>' .
371 $this->addelement(1, '', $theData) .
372 '</thead>' .
373 '<tbody>' .
374 $out .
375 '</tbody>' .
376 '</table>
377 </div>';
378 }
379 return $out;
380 }
381
382 /**
383 * Renders Content Elements from the tt_content table from page id
384 *
385 * @param int $id Page id
386 * @return string HTML for the listing
387 */
388 public function getTable_tt_content($id) {
389 $this->initializeLanguages();
390 $this->initializeClipboard();
391 // Initialize:
392 $RTE = $this->getBackendUser()->isRTE();
393 $lMarg = 1;
394 $showHidden = $this->tt_contentConfig['showHidden'] ? '' : BackendUtility::BEenableFields('tt_content');
395 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), TRUE));
396 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
397 $pageRenderer = $this->getPageLayoutController()->doc->getPageRenderer();
398 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
399 // Get labels for CTypes and tt_content element fields in general:
400 $this->CType_labels = array();
401 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
402 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
403 }
404 $this->itemLabels = array();
405 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
406 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
407 }
408 $languageColumn = array();
409 $out = '';
410 // Select display mode:
411 // MULTIPLE column display mode, side by side:
412 if (!$this->tt_contentConfig['single']) {
413 // Setting language list:
414 $langList = $this->tt_contentConfig['sys_language_uid'];
415 if ($this->tt_contentConfig['languageMode']) {
416 if ($this->tt_contentConfig['languageColsPointer']) {
417 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
418 } else {
419 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
420 }
421 $languageColumn = array();
422 }
423 $langListArr = GeneralUtility::intExplode(',', $langList);
424 $defLanguageCount = array();
425 $defLangBinding = array();
426 // For each languages... :
427 // If not languageMode, then we'll only be through this once.
428 foreach ($langListArr as $lP) {
429 $lP = (int)$lP;
430 if (count($langListArr) === 1 || $lP === 0) {
431 $showLanguage = ' AND sys_language_uid IN (' . $lP . ',-1)';
432 } else {
433 $showLanguage = ' AND sys_language_uid=' . $lP;
434 }
435 $cList = explode(',', $this->tt_contentConfig['cols']);
436 $content = array();
437 $head = array();
438
439 // Select content records per column
440 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, array_values($cList), $showHidden . $showLanguage);
441 // For each column, render the content into a variable:
442 foreach ($cList as $key) {
443 if (!$lP) {
444 $defLanguageCount[$key] = array();
445 }
446 // Start wrapping div
447 $content[$key] .= '<div data-colpos="' . $key . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
448 if (count($contentRecordsPerColumn[$key]) === 0) {
449 $content[$key] .= ' t3-page-ce-empty';
450 }
451 $content[$key] .= '">';
452 // Add new content at the top most position
453 $content[$key] .= '
454 <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . str_replace('.', '', uniqid('', TRUE)) . '">
455 <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id . '-' . uniqid('', TRUE) . '">
456 <a href="#" onclick="' . htmlspecialchars($this->newContentElementOnClick($id, $key, $lP))
457 . '" title="' . $this->getLanguageService()->getLL('newContentElement', TRUE) . '" class="btn btn-default btn-sm">'
458 . IconUtility::getSpriteIcon('actions-document-new')
459 . ' '
460 . $this->getLanguageService()->getLL('content', TRUE) . '</a>
461 </div>
462 <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
463 </div>
464 ';
465 $editUidList = '';
466 $rowArr = $contentRecordsPerColumn[$key];
467 $this->generateTtContentDataArray($rowArr);
468 foreach ((array)$rowArr as $rKey => $row) {
469 if ($this->tt_contentConfig['languageMode']) {
470 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
471 if (!$this->defLangBinding) {
472 $languageColumn[$key][$lP] .= $this->newLanguageButton(
473 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
474 $lP
475 );
476 }
477 }
478 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
479 $singleElementHTML = '';
480 if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
481 $defLanguageCount[$key][] = $row['uid'];
482 }
483 $editUidList .= $row['uid'] . ',';
484 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
485 if (!$this->tt_contentConfig['languageMode']) {
486 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . str_replace('.', '', uniqid('', TRUE)) . '">';
487 }
488 $singleElementHTML .= $this->tt_content_drawHeader(
489 $row,
490 $this->tt_contentConfig['showInfo'] ? 15 : 5,
491 $disableMoveAndNewButtons,
492 TRUE,
493 !$this->tt_contentConfig['languageMode']
494 );
495 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
496 $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
497 . $this->tt_content_drawItem($row, $isRTE) . '</div>';
498 $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
499 . $this->tt_content_drawFooter($row);
500 $statusHidden = $this->isDisabled('tt_content', $row) ? ' t3-page-ce-hidden' : '';
501 $singleElementHTML = '<div class="t3-page-ce t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
502 . $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '">' . $singleElementHTML . '</div>';
503 if ($this->tt_contentConfig['languageMode']) {
504 $singleElementHTML .= '<div class="t3-page-ce t3js-page-ce">';
505 }
506 $singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id .
507 '-' . str_replace('.', '', uniqid('', TRUE)) . '">';
508 // Add icon "new content element below"
509 if (!$disableMoveAndNewButtons) {
510 // New content element:
511 if ($this->option_newWizard) {
512 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $row['pid']
513 . '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos']
514 . '&uid_pid=' . -$row['uid'] .
515 '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
516 } else {
517 $params = '&edit[tt_content][' . -$row['uid'] . ']=new';
518 $onClick = BackendUtility::editOnClick($params, $this->backPath);
519 }
520 $singleElementHTML .= '
521 <a href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
522 . $this->getLanguageService()->getLL('newContentElement', TRUE) . '" class="btn btn-default btn-sm">'
523 . IconUtility::getSpriteIcon('actions-document-new')
524 . ' '
525 . $this->getLanguageService()->getLL('content', TRUE) . '</a>
526 ';
527 }
528 $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
529 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
530 $defLangBinding[$key][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
531 } else {
532 $content[$key] .= $singleElementHTML;
533 }
534 } else {
535 unset($rowArr[$rKey]);
536 }
537 }
538 $content[$key] .= '</div>';
539 // Add new-icon link, header:
540 $newP = $this->newContentElementOnClick($id, $key, $lP);
541 $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $key);
542 $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
543 foreach ($tcaItems as $item) {
544 if ($item[1] == $key) {
545 $colTitle = $this->getLanguageService()->sL($item[0]);
546 }
547 }
548
549 $pasteP = array('colPos' => $key, 'sys_language_uid' => $lP);
550 $editParam = $this->doEdit && count($rowArr)
551 ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
552 : '';
553 $head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, $newP, $pasteP);
554 }
555 // For each column, fit the rendered content into a table cell:
556 $out = '';
557 if ($this->tt_contentConfig['languageMode']) {
558 // in language mode process the content elements, but only fill $languageColumn. output will be generated later
559 $sortedLanguageColumn = array();
560 foreach ($cList as $key) {
561 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
562 if (!$this->defLangBinding) {
563 $languageColumn[$key][$lP] .= $this->newLanguageButton(
564 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
565 $lP
566 );
567 }
568 // We sort $languageColumn again according to $cList as it may contain data already from above.
569 $sortedLanguageColumn[$key] = $languageColumn[$key];
570 }
571 $languageColumn = $sortedLanguageColumn;
572 } else {
573 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
574 // GRID VIEW:
575 $grid = '<div class="t3-grid-container"><table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" class="t3-page-columns t3-grid-table t3js-page-columns">';
576 // Add colgroups
577 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
578 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
579 $grid .= '<colgroup>';
580 for ($i = 0; $i < $colCount; $i++) {
581 $grid .= '<col style="width:' . 100 / $colCount . '%"></col>';
582 }
583 $grid .= '</colgroup>';
584 // Cycle through rows
585 for ($row = 1; $row <= $rowCount; $row++) {
586 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
587 if (!isset($rowConfig)) {
588 continue;
589 }
590 $grid .= '<tr>';
591 for ($col = 1; $col <= $colCount; $col++) {
592 $columnConfig = $rowConfig['columns.'][$col . '.'];
593 if (!isset($columnConfig)) {
594 continue;
595 }
596 // Which tt_content colPos should be displayed inside this cell
597 $columnKey = (int)$columnConfig['colPos'];
598 // Render the grid cell
599 $colSpan = (int)$columnConfig['colspan'];
600 $rowSpan = (int)$columnConfig['rowspan'];
601 $grid .= '<td valign="top"' .
602 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
603 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
604 ' data-colpos="' . (int)$columnConfig['colPos'] . '" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
605 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
606 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
607 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
608 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
609
610 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
611 // If not, a new header without any buttons will be generated.
612 if (
613 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
614 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
615 ) {
616 $grid .= $head[$columnKey] . $content[$columnKey];
617 } elseif (
618 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
619 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
620 ) {
621 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'), '', '');
622 } elseif (
623 isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
624 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
625 ) {
626 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
627 ' (' . $this->getLanguageService()->getLL('noAccess') . ')', '', '');
628 } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
629 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
630 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '');
631 } else {
632 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'), '', '');
633 }
634
635 $grid .= '</td>';
636 }
637 $grid .= '</tr>';
638 }
639 $out .= $grid . '</table></div>';
640 }
641 // CSH:
642 $out .= BackendUtility::cshItem($this->descrTable, 'columns_multi');
643 }
644 // If language mode, then make another presentation:
645 // Notice that THIS presentation will override the value of $out!
646 // But it needs the code above to execute since $languageColumn is filled with content we need!
647 if ($this->tt_contentConfig['languageMode']) {
648 // Get language selector:
649 $languageSelector = $this->languageSelector($id);
650 // Reset out - we will make new content here:
651 $out = '';
652 // Traverse languages found on the page and build up the table displaying them side by side:
653 $cCont = array();
654 $sCont = array();
655 foreach ($langListArr as $lP) {
656 // Header:
657 $lP = (int)$lP;
658 $cCont[$lP] = '
659 <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
660 <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
661 </td>';
662
663 // "View page" icon is added:
664 $onClick = BackendUtility::viewOnClick($this->id, $this->backPath, BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
665 $viewLink = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
666 // Language overlay page header:
667 if ($lP) {
668 list($lpRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . $lP);
669 BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
670 $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
671 $lPLabel = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon(
672 IconUtility::getSpriteIconForRecord('pages_language_overlay', $lpRecord),
673 'pages_language_overlay',
674 $lpRecord['uid']
675 ) . $viewLink . ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
676 ? '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
677 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">'
678 . IconUtility::getSpriteIcon('actions-document-open') . '</a>'
679 : ''
680 ) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
681 } else {
682 $lPLabel = $viewLink;
683 }
684 $sCont[$lP] = '
685 <td nowrap="nowrap" class="t3-page-column t3-page-lang-label">' . $lPLabel . '</td>';
686 }
687 // Add headers:
688 $out .= '<tr>' . implode($cCont) . '</tr>';
689 $out .= '<tr>' . implode($sCont) . '</tr>';
690 unset($cCont, $sCont);
691
692 // Traverse previously built content for the columns:
693 foreach ($languageColumn as $cKey => $cCont) {
694 $out .= '<tr>';
695 foreach ($cCont as $languageId => $columnContent) {
696 $out .= '<td valign="top" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
697 }
698 $out .= '</tr>';
699 if ($this->defLangBinding) {
700 // "defLangBinding" mode
701 foreach ($defLanguageCount[$cKey] as $defUid) {
702 $cCont = array();
703 foreach ($langListArr as $lP) {
704 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
705 $this->getNonTranslatedTTcontentUids(array($defUid), $id, $lP),
706 $lP
707 );
708 }
709 $out .= '
710 <tr>
711 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
712 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
713 </tr>';
714 }
715 }
716 }
717 // Finally, wrap it all in a table and add the language selector on top of it:
718 $out = $languageSelector . '
719 <div class="t3-grid-container">
720 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
721 ' . $out . '
722 </table>
723 </div>';
724 // CSH:
725 $out .= BackendUtility::cshItem($this->descrTable, 'language_list');
726 }
727 } else {
728 // SINGLE column mode (columns shown beneath each other):
729 if ($this->tt_contentConfig['sys_language_uid'] == 0 || !$this->defLangBinding) {
730 // Initialize:
731 if ($this->defLangBinding && $this->tt_contentConfig['sys_language_uid'] == 0) {
732 $showLanguage = ' AND sys_language_uid IN (0,-1)';
733 $lP = 0;
734 } else {
735 $showLanguage = ' AND sys_language_uid=' . $this->tt_contentConfig['sys_language_uid'];
736 $lP = $this->tt_contentConfig['sys_language_uid'];
737 }
738 $cList = explode(',', $this->tt_contentConfig['showSingleCol']);
739 $out = '';
740 // Expand the table to some preset dimensions:
741 $out .= '
742 <tr>
743 <td><img src="clear.gif" width="' . $lMarg . '" height="1" alt="" /></td>
744 <td valign="top"><img src="clear.gif" width="150" height="1" alt="" /></td>
745 <td><img src="clear.gif" width="10" height="1" alt="" /></td>
746 <td valign="top"><img src="clear.gif" width="300" height="1" alt="" /></td>
747 </tr>';
748
749 // Select content records per column
750 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('tt_content', $id, array_values($cList), $showHidden . $showLanguage);
751 // Traverse columns to display top-on-top
752 foreach ($cList as $counter => $key) {
753 $c = 0;
754 $rowArr = $contentRecordsPerColumn[$key];
755 $this->generateTtContentDataArray($rowArr);
756 $numberOfContentElementsInColumn = count($rowArr);
757 $rowOut = '';
758 // If it turns out that there are not content elements in the column, then display a big button which links directly to the wizard script:
759 if ($this->doEdit && $this->option_showBigButtons && !(int)$key && $numberOfContentElementsInColumn == 0) {
760 $onClick = 'window.location.href='
761 . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $id . '&colPos=' . (int)$key
762 . '&sys_language_uid=' . $lP . '&uid_pid=' . $id . '&returnUrl='
763 . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
764 $theNewButton = $this->getPageLayoutController()->doc->t3Button($onClick, $this->getLanguageService()->getLL('newPageContent'));
765 $theNewButton = '<img src="clear.gif" width="1" height="5" alt="" /><br />' . $theNewButton;
766 } else {
767 $theNewButton = '';
768 }
769 $editUidList = '';
770 // Traverse any selected elements:
771 foreach ($rowArr as $rKey => $row) {
772 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
773 $c++;
774 $editUidList .= $row['uid'] . ',';
775 $isRTE = $RTE && $this->isRTEforField('tt_content', $row, 'bodytext');
776 // Create row output:
777 $rowOut .= '
778 <tr>
779 <td></td>
780 <td valign="top">' . $this->tt_content_drawHeader($row) . '</td>
781 <td>&nbsp;</td>
782 <td' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . ' valign="top">'
783 . $this->tt_content_drawItem($row, $isRTE) . '</td>
784 </tr>';
785 // If the element was not the last element, add a divider line:
786 if ($c != $numberOfContentElementsInColumn) {
787 $rowOut .= '
788 <tr>
789 <td></td>
790 <td colspan="3"><img'
791 . IconUtility::skinImg($this->backPath, 'gfx/stiblet_medium2.gif', 'width="468" height="1"')
792 . ' class="c-divider" alt="" /></td>
793 </tr>';
794 }
795 } else {
796 unset($rowArr[$rKey]);
797 }
798 }
799 // Add spacer between sections in the vertical list
800 if ($counter) {
801 $out .= '
802 <tr>
803 <td></td>
804 <td colspan="3"><br /><br /><br /><br /></td>
805 </tr>';
806 }
807 // Add section header:
808 $newP = $this->newContentElementOnClick($id, $key, $this->tt_contentConfig['sys_language_uid']);
809 $pasteP = array('colPos' => $key, 'sys_language_uid' => $this->tt_contentConfig['sys_language_uid']);
810 $out .= '
811
812 <!-- Column header: -->
813 <tr>
814 <td></td>
815 <td valign="top" colspan="3">' . $this->tt_content_drawColHeader(
816 BackendUtility::getProcessedValue('tt_content', 'colPos', $key),
817 $this->doEdit && count($rowArr) ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc : '',
818 $newP,
819 $pasteP
820 ) . $theNewButton . '<br /></td>
821 </tr>';
822 // Finally, add the content from the records in this column:
823 $out .= $rowOut;
824 }
825 // Finally, wrap all table rows in one, big table:
826 $out = '
827 <table border="0" cellpadding="0" cellspacing="0" width="400" class="t3-page-columns-mode">
828 ' . $out . '
829 </table>';
830 // CSH:
831 $out .= BackendUtility::cshItem($this->descrTable, 'columns_single');
832 } else {
833 $out = '<br/><br/>' . $this->getPageLayoutController()->doc->icons(1)
834 . 'Sorry, you cannot view a single language in this localization mode (Default Language Binding is enabled)<br/><br/>';
835 }
836 }
837 // Add the big buttons to page:
838 if ($this->option_showBigButtons) {
839 $bArray = array();
840 if (!$this->getPageLayoutController()->current_sys_language) {
841 if ($this->ext_CALC_PERMS & Permission::PAGE_EDIT) {
842 $bArray[0] = $this->getPageLayoutController()->doc->t3Button(
843 BackendUtility::editOnClick('&edit[pages][' . $id . ']=edit'),
844 $this->getLanguageService()->getLL('editPageProperties')
845 );
846 }
847 } else {
848 if ($this->doEdit && $this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
849 list($languageOverlayRecord) = BackendUtility::getRecordsByField(
850 'pages_language_overlay',
851 'pid',
852 $id,
853 'AND sys_language_uid=' . (int)$this->getPageLayoutController()->current_sys_language
854 );
855 $bArray[0] = $this->getPageLayoutController()->doc->t3Button(
856 BackendUtility::editOnClick('&edit[pages_language_overlay][' . $languageOverlayRecord['uid'] . ']=edit'),
857 $this->getLanguageService()->getLL('editPageProperties_curLang')
858 );
859 }
860 }
861 if ($this->ext_CALC_PERMS & Permission::PAGE_DELETE || $this->ext_CALC_PERMS & Permission::PAGE_EDIT) {
862 $bArray[1] = $this->getPageLayoutController()->doc->t3Button(
863 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('move_element', ['table' => 'pages', 'uid' => $id, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')])) . ';',
864 $this->getLanguageService()->getLL('move_page')
865 );
866 }
867 if ($this->ext_CALC_PERMS & Permission::PAGE_NEW) {
868 $parameters = [
869 'id' => $id,
870 'pagesOnly' => 1,
871 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
872 ];
873 $bArray[2] = $this->getPageLayoutController()->doc->t3Button(
874 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', $parameters)) . ';',
875 $this->getLanguageService()->getLL('newPage2')
876 );
877 }
878 if ($this->doEdit && $this->ext_function == 1) {
879 $bArray[3] = $this->getPageLayoutController()->doc->t3Button(
880 'window.location.href='
881 . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $id
882 . '&sys_language_uid=' . $this->getPageLayoutController()->current_sys_language
883 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';',
884 $this->getLanguageService()->getLL('newPageContent2')
885 );
886 }
887 $out = '
888 <table border="0" cellpadding="4" cellspacing="0" class="typo3-page-buttons">
889 <tr>
890 <td>' . implode('</td>
891 <td>', $bArray) . '</td>
892 <td>' . BackendUtility::cshItem($this->descrTable, 'button_panel') . '</td>
893 </tr>
894 </table>
895 <br />
896 ' . $out;
897 }
898 // Return content:
899 return $out;
900 }
901
902 /**
903 * Get backend layout configuration
904 *
905 * @return array
906 * @deprecated since TYPO3 CMS 6.2, will be removed two versions later
907 */
908 public function getBackendLayoutConfiguration() {
909 GeneralUtility::logDeprecatedFunction();
910 return $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
911 }
912
913 /**********************************
914 *
915 * Generic listing of items
916 *
917 **********************************/
918 /**
919 * Creates a standard list of elements from a table.
920 *
921 * @param string $table Table name
922 * @param int $id Page id.
923 * @param string $fList Comma list of fields to display
924 * @param bool $icon If TRUE, icon is shown
925 * @param string $addWhere Additional WHERE-clauses.
926 * @return string HTML table
927 */
928 public function makeOrdinaryList($table, $id, $fList, $icon = FALSE, $addWhere = '') {
929 // Initialize
930 $queryParts = $this->makeQueryArray($table, $id, $addWhere);
931 $this->setTotalItems($queryParts);
932 $dbCount = 0;
933 $result = FALSE;
934 // Make query for records if there were any records found in the count operation
935 if ($this->totalItems) {
936 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
937 // Will return FALSE, if $result is invalid
938 $dbCount = $this->getDatabase()->sql_num_rows($result);
939 }
940 // If records were found, render the list
941 if (!$dbCount) {
942 return '';
943 }
944 // Set fields
945 $out = '';
946 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', TRUE);
947 $theData = array();
948 $theData = $this->headerFields($this->fieldArray, $table, $theData);
949 // Title row
950 $localizedTableTitle = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'], TRUE);
951 $out .= '<tr class="t3-row-header">' . '<td nowrap="nowrap" class="col-icon"></td>'
952 . '<td nowrap="nowrap" colspan="' . (count($theData) - 2) . '"><span class="c-table">'
953 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td nowrap="nowrap" class="col-icon"></td>'
954 . '</tr>';
955 // Column's titles
956 if ($this->doEdit) {
957 $onClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $this->id . ']=new');
958 $theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" '
959 . 'title="' . $this->getLanguageService()->getLL('new', TRUE) . '">'
960 . IconUtility::getSpriteIcon('actions-document-new') . '</a>';
961 }
962 $out .= $this->addelement(1, '', $theData, ' class="c-headLine"', 15);
963 // Render Items
964 $this->eCounter = $this->firstElementNumber;
965 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
966 BackendUtility::workspaceOL($table, $row);
967 if (is_array($row)) {
968 list($flag, $code) = $this->fwd_rwd_nav();
969 $out .= $code;
970 if ($flag) {
971 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
972 $Nrow = array();
973 // Setting icons links
974 if ($icon) {
975 $Nrow['__cmds__'] = $this->getIcon($table, $row);
976 }
977 // Get values:
978 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
979 // Attach edit icon
980 if ($this->doEdit) {
981 $Nrow['__editIconLink__'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
982 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">'
983 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
984 } else {
985 $Nrow['__editIconLink__'] = $this->noEditIcon();
986 }
987 $out .= $this->addelement(1, '', $Nrow);
988 }
989 $this->eCounter++;
990 }
991 }
992 // Wrap it all in a table:
993 $out = '
994 <!--
995 Standard list of table "' . $table . '"
996 -->
997 <table border="0" cellpadding="0" cellspacing="0" class="typo3-dblist">
998 ' . $out . '
999 </table>';
1000 return $out;
1001 }
1002
1003 /**
1004 * Adds content to all data fields in $out array
1005 *
1006 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1007 * Eg. "field1,field2;field3".
1008 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1009 *
1010 * @param array $fieldArr Array of fields to display
1011 * @param string $table Table name
1012 * @param array $row Record array
1013 * @param array $out Array to which the data is added
1014 * @return array $out array returned after processing.
1015 * @see makeOrdinaryList()
1016 */
1017 public function dataFields($fieldArr, $table, $row, $out = array()) {
1018 // Check table validity
1019 if (!isset($GLOBALS['TCA'][$table])) {
1020 return $out;
1021 }
1022
1023 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1024 // Traverse fields
1025 foreach ($fieldArr as $fieldName) {
1026 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1027 // Each field has its own cell (if configured in TCA)
1028 // If the column is a thumbnail column:
1029 if ($fieldName == $thumbsCol) {
1030 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1031 } else {
1032 // ... otherwise just render the output:
1033 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1034 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1035 250)
1036 )));
1037 }
1038 } else {
1039 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1040 // the field name with ";" and check each value there as a TCA configured field)
1041 $theFields = explode(';', $fieldName);
1042 // Traverse fields, separated by ";" (displayed in a single cell).
1043 foreach ($theFields as $fName2) {
1044 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1045 $out[$fieldName] .= '<strong>' . $this->getLanguageService()->sL(
1046 $GLOBALS['TCA'][$table]['columns'][$fName2]['label'],
1047 TRUE
1048 ) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1049 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1050 25
1051 )) . '<br />';
1052 }
1053 }
1054 }
1055 // If no value, add a nbsp.
1056 if (!$out[$fieldName]) {
1057 $out[$fieldName] = '&nbsp;';
1058 }
1059 // Wrap in dimmed-span tags if record is "disabled"
1060 if ($this->isDisabled($table, $row)) {
1061 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1062 }
1063 }
1064 return $out;
1065 }
1066
1067 /**
1068 * Header fields made for the listing of records
1069 *
1070 * @param array $fieldArr Field names
1071 * @param string $table The table name
1072 * @param array $out Array to which the headers are added.
1073 * @return array $out returned after addition of the header fields.
1074 * @see makeOrdinaryList()
1075 */
1076 public function headerFields($fieldArr, $table, $out = array()) {
1077 foreach ($fieldArr as $fieldName) {
1078 $ll = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label'], TRUE);
1079 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1080 }
1081 return $out;
1082 }
1083
1084 /**
1085 * Gets content records per column.
1086 * This is required for correct workspace overlays.
1087 *
1088 * @param string $table UNUSED (will always be queried from tt_content)
1089 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1090 * @param array $columns colPos values to be considered to be shown
1091 * @param string $additionalWhereClause Additional where clause for database select
1092 * @return array Associative array for each column (colPos)
1093 */
1094 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '') {
1095 $columns = array_map('intval', $columns);
1096 $contentRecordsPerColumn = array_fill_keys($columns, array());
1097
1098 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos IN (' . implode(',', $columns) . ')' . $additionalWhereClause);
1099 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1100 // Traverse any selected elements and render their display code:
1101 $rowArr = $this->getResult($result);
1102
1103 foreach ($rowArr as $record) {
1104 $columnValue = $record['colPos'];
1105 $contentRecordsPerColumn[$columnValue][] = $record;
1106 }
1107
1108 return $contentRecordsPerColumn;
1109 }
1110
1111 /**********************************
1112 *
1113 * Additional functions; Pages
1114 *
1115 **********************************/
1116 /**
1117 * Adds pages-rows to an array, selecting recursively in the page tree.
1118 *
1119 * @param array $theRows Array which will accumulate page rows
1120 * @param int $pid Pid to select from
1121 * @param string $qWhere Query-where clause
1122 * @param string $treeIcons Prefixed icon code.
1123 * @param int $depth Depth (decreasing)
1124 * @return array $theRows, but with added rows.
1125 */
1126 public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth) {
1127 $depth--;
1128 if ($depth >= 0) {
1129 $res = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'pid=' . (int)$pid . $qWhere, '', 'sorting');
1130 $c = 0;
1131 $rc = $this->getDatabase()->sql_num_rows($res);
1132 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1133 BackendUtility::workspaceOL('pages', $row);
1134 if (is_array($row)) {
1135 $c++;
1136 $row['treeIcons'] = $treeIcons . '<img' . IconUtility::skinImg(
1137 $this->backPath,
1138 'gfx/ol/join' . ($rc == $c ? 'bottom' : '') . '.gif',
1139 'width="18" height="16"'
1140 ) . ' alt="" />';
1141 $theRows[] = $row;
1142 // Get the branch
1143 $spaceOutIcons = '<img' . IconUtility::skinImg(
1144 $this->backPath,
1145 'gfx/ol/' . ($rc == $c ? 'blank.gif' : 'line.gif'),
1146 'width="18" height="16"'
1147 ) . ' alt="" />';
1148 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1149 }
1150 }
1151 } else {
1152 $count = $this->getDatabase()->exec_SELECTcountRows('uid', 'pages', 'pid=' . (int)$pid . $qWhere);
1153 if ($count) {
1154 $this->plusPages[$pid] = $count;
1155 }
1156 }
1157 return $theRows;
1158 }
1159
1160 /**
1161 * Adds a list item for the pages-rendering
1162 *
1163 * @param array $row Record array
1164 * @param array $fieldArr Field list
1165 * @return string HTML for the item
1166 */
1167 public function pages_drawItem($row, $fieldArr) {
1168 // Initialization
1169 $theIcon = $this->getIcon('pages', $row);
1170 // Preparing and getting the data-array
1171 $theData = array();
1172 foreach ($fieldArr as $field) {
1173 switch ($field) {
1174 case 'title':
1175 $red = $this->plusPages[$row['uid']] ? '<font color="red"><strong>+&nbsp;</strong></font>' : '';
1176 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1177 if ($red) {
1178 $pTitle = '<a href="'
1179 . htmlspecialchars($this->script . ((strpos($this->script, '?') !== FALSE) ? '&' : '?')
1180 . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1181 }
1182 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1183 break;
1184 case 'php_tree_stop':
1185 // Intended fall through
1186 case 'TSconfig':
1187 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1188 break;
1189 case 'uid':
1190 if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
1191 $params = '&edit[pages][' . $row['uid'] . ']=edit';
1192 $eI = '<a href="#" onclick="'
1193 . htmlspecialchars(BackendUtility::editOnClick($params))
1194 . '" title="' . $this->getLanguageService()->getLL('editThisPage', TRUE) . '">'
1195 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1196 } else {
1197 $eI = '';
1198 }
1199 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1200 break;
1201 default:
1202 if (substr($field, 0, 6) == 'table_') {
1203 $f2 = substr($field, 6);
1204 if ($GLOBALS['TCA'][$f2]) {
1205 $c = $this->numberOfRecords($f2, $row['uid']);
1206 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1207 }
1208 } else {
1209 $theData[$field] = '&nbsp;&nbsp;'
1210 . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1211 }
1212 }
1213 }
1214 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1215 return $this->addelement(1, '', $theData);
1216 }
1217
1218 /**********************************
1219 *
1220 * Additional functions; Content Elements
1221 *
1222 **********************************/
1223 /**
1224 * Draw header for a content element column:
1225 *
1226 * @param string $colName Column name
1227 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1228 * @param string $newParams New element params (Syntax: &edit[...] for FormEngine) OBSOLETE
1229 * @param array|NULL $pasteParams Paste element params (i.e. array(colPos => 1, sys_language_uid => 2))
1230 * @return string HTML table
1231 */
1232 public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = NULL) {
1233 $iconsArr = array();
1234 // Create command links:
1235 if ($this->tt_contentConfig['showCommands']) {
1236 // Edit whole of column:
1237 if ($editParams) {
1238 $iconsArr['edit'] = '<a href="#" onclick="'
1239 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1240 . $this->getLanguageService()->getLL('editColumn', TRUE) . '">'
1241 . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1242 }
1243 if ($pasteParams) {
1244 $elFromTable = $this->clipboard->elFromTable('tt_content');
1245 if (count($elFromTable)) {
1246 $iconsArr['paste'] = '<a href="'
1247 . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, TRUE, $pasteParams))
1248 . '" onclick="' . htmlspecialchars(('return '
1249 . $this->clipboard->confirmMsg('pages', $this->pageRecord, 'into', $elFromTable, $colName)))
1250 . '" title="' . $this->getLanguageService()->getLL('clip_paste', TRUE) . '">'
1251 . IconUtility::getSpriteIcon('actions-document-paste-into') . '</a>';
1252 }
1253 }
1254 }
1255 $icons = '';
1256 if (count($iconsArr)) {
1257 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1258 }
1259 // Create header row:
1260 $out = '<div class="t3-page-column-header">
1261 ' . $icons . '
1262 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1263 </div>';
1264 return $out;
1265 }
1266
1267 /**
1268 * Draw the footer for a single tt_content element
1269 *
1270 * @param array $row Record array
1271 * @return string HTML of the footer
1272 */
1273 protected function tt_content_drawFooter(array $row) {
1274 $content = '';
1275 // Get processed values:
1276 $info = array();
1277 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1278
1279 // Call drawFooter hooks
1280 $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1281 if (is_array($drawFooterHooks)) {
1282 foreach ($drawFooterHooks as $hookClass) {
1283 $hookObject = GeneralUtility::getUserObj($hookClass);
1284 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1285 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\View\\PageLayoutViewDrawFooterHookInterface', 1404378171);
1286 }
1287 $hookObject->preProcess($this, $info, $row);
1288 }
1289 }
1290
1291 // Display info from records fields:
1292 if (count($info)) {
1293 $content = '<div class="t3-page-ce-info">
1294 ' . implode('<br>', $info) . '
1295 </div>';
1296 }
1297 // Wrap it
1298 if (!empty($content)) {
1299 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1300 }
1301 return $content;
1302 }
1303
1304 /**
1305 * Draw the header for a single tt_content element
1306 *
1307 * @param array $row Record array
1308 * @param int $space Amount of pixel space above the header. UNUSED
1309 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1310 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1311 * @param bool $dragDropEnabled If set the move button must be hidden
1312 * @return string HTML table with the record header.
1313 */
1314 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = FALSE, $langMode = FALSE, $dragDropEnabled = FALSE) {
1315 $out = '';
1316 // If show info is set...;
1317 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1318 // Render control panel for the element:
1319 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1320 // Edit content element:
1321 $params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
1322 $out .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
1323 $params,
1324 '',
1325 GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
1326 )) . '" title="' . htmlspecialchars($this->nextThree > 1
1327 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1328 : $this->getLanguageService()->getLL('edit'))
1329 . '">' . IconUtility::getSpriteIcon('actions-document-open') . '</a>';
1330 // Hide element:
1331 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1332 if (
1333 $hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1334 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1335 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1336 ) {
1337 if ($row[$hiddenField]) {
1338 $value = 0;
1339 $label = 'unHide';
1340 } else {
1341 $value = 1;
1342 $label = 'hide';
1343 }
1344 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1345 . '][' . $hiddenField . ']=' . $value;
1346 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1347 . '" title="' . $this->getLanguageService()->getLL($label, TRUE) . '">'
1348 . IconUtility::getSpriteIcon('actions-edit-' . strtolower($label)) . '</a>';
1349 }
1350 // Delete
1351 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1352 $confirm = GeneralUtility::quoteJSvalue($this->getLanguageService()->getLL('deleteWarning')
1353 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1354 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')))
1355 );
1356 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1357 . '" onclick="' . htmlspecialchars(('return confirm(' . $confirm . ');')) . '" title="'
1358 . $this->getLanguageService()->getLL('deleteItem', TRUE) . '">'
1359 . IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
1360 if ($out) {
1361 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1362 }
1363 if (!$disableMoveAndNewButtons) {
1364 $moveButtonContent = '';
1365 $displayMoveButtons = FALSE;
1366 // Move element up:
1367 if ($this->tt_contentData['prev'][$row['uid']]) {
1368 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1369 $moveButtonContent .= '<a class="btn btn-default" href="'
1370 . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1371 . '" title="' . $this->getLanguageService()->getLL('moveUp', TRUE) . '">'
1372 . IconUtility::getSpriteIcon('actions-move-up') . '</a>';
1373 if (!$dragDropEnabled) {
1374 $displayMoveButtons = TRUE;
1375 }
1376 } else {
1377 $moveButtonContent .= '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>';
1378 }
1379 // Move element down:
1380 if ($this->tt_contentData['next'][$row['uid']]) {
1381 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1382 $moveButtonContent .= '<a class="btn btn-default" href="'
1383 . htmlspecialchars($this->getPageLayoutController()->doc->issueCommand($params))
1384 . '" title="' . $this->getLanguageService()->getLL('moveDown', TRUE) . '">'
1385 . IconUtility::getSpriteIcon('actions-move-down') . '</a>';
1386 if (!$dragDropEnabled) {
1387 $displayMoveButtons = TRUE;
1388 }
1389 } else {
1390 $moveButtonContent .= '<span class="btn btn-default disabled">' . IconUtility::getSpriteIcon('empty-empty') . '</span>';
1391 }
1392 if ($displayMoveButtons) {
1393 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1394 }
1395 }
1396 }
1397 }
1398 $additionalIcons = array();
1399 $additionalIcons[] = $this->getIcon('tt_content', $row) . ' ';
1400 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], FALSE) : '';
1401 // Get record locking status:
1402 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1403 $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1404 . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1405 . IconUtility::getSpriteIcon('status-warning-in-use') . '</a>';
1406 }
1407 // Call stats information hook
1408 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1409 $_params = array('tt_content', $row['uid'], &$row);
1410 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1411 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1412 }
1413 }
1414 // Wrap the whole header
1415 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1416 return '<div class="t3-page-ce-header t3js-page-ce-draghandle">
1417 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
1418 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' .$out . '</div>' : '') . '</div>
1419 </div>
1420 <div class="t3-page-ce-body">';
1421 }
1422
1423 /**
1424 * Draws the preview content for a content element
1425 *
1426 * @param string $row Content element
1427 * @param bool $isRTE Set if the RTE link can be created.
1428 * @return string HTML
1429 * @throws \UnexpectedValueException
1430 */
1431 public function tt_content_drawItem($row, $isRTE = FALSE) {
1432 $out = '';
1433 $outHeader = '';
1434 // Make header:
1435 if ($row['header']) {
1436 $infoArr = array();
1437 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1438 $hiddenHeaderNote = '';
1439 // If header layout is set to 'hidden', display an accordant note:
1440 if ($row['header_layout'] == 100) {
1441 $hiddenHeaderNote = ' <em>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden', TRUE) . ']</em>';
1442 }
1443 $outHeader = $row['date']
1444 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1445 : '';
1446 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1447 . $hiddenHeaderNote . '</strong><br />';
1448 }
1449 // Make content:
1450 $infoArr = array();
1451 $drawItem = TRUE;
1452 // Hook: Render an own preview of a record
1453 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1454 if (is_array($drawItemHooks)) {
1455 foreach ($drawItemHooks as $hookClass) {
1456 $hookObject = GeneralUtility::getUserObj($hookClass);
1457 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1458 throw new \UnexpectedValueException('$hookObject must implement interface ' . \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::class, 1218547409);
1459 }
1460 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1461 }
1462 }
1463 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1464 if ($drawItem) {
1465 switch ($row['CType']) {
1466 case 'header':
1467 if ($row['subheader']) {
1468 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1469 }
1470 break;
1471 case 'text':
1472
1473 case 'textpic':
1474
1475 case 'image':
1476 if ($row['CType'] == 'text' || $row['CType'] == 'textpic') {
1477 if ($row['bodytext']) {
1478 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1479 }
1480 }
1481 if ($row['CType'] == 'textpic' || $row['CType'] == 'image') {
1482 if ($row['image']) {
1483 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1484 $fileReferences = BackendUtility::resolveFileReferences('tt_content', 'image', $row);
1485 if (!empty($fileReferences)) {
1486 $linkedContent = '';
1487 foreach ($fileReferences as $fileReference) {
1488 $linkedContent .= htmlspecialchars($fileReference->getDescription()) . '<br />';
1489 }
1490 $out .= $this->linkEditContent($linkedContent, $row);
1491 unset($linkedContent);
1492 }
1493 }
1494 }
1495 break;
1496 case 'bullets':
1497 case 'table':
1498 if ($row['bodytext']) {
1499 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1500 }
1501 break;
1502 case 'uploads':
1503 if ($row['media']) {
1504 $out .= $this->thumbCode($row, 'tt_content', 'media') . '<br />';
1505 }
1506 break;
1507 case 'multimedia':
1508 if ($row['multimedia']) {
1509 $out .= $this->renderText($row['multimedia']) . '<br />';
1510 $out .= $this->renderText($row['parameters']) . '<br />';
1511 }
1512 break;
1513 case 'menu':
1514 $contentType = $this->CType_labels[$row['CType']];
1515 $out .= '<strong>' . htmlspecialchars($contentType) . '</strong><br />';
1516 // Add Menu Type
1517 $menuTypeLabel = $this->getLanguageService()->sL(
1518 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
1519 );
1520 $out .= $menuTypeLabel !== '' ? $menuTypeLabel : 'invalid menu type';
1521 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
1522 // Show pages if menu type is not "Sitemap"
1523 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
1524 }
1525 break;
1526 case 'shortcut':
1527 if (!empty($row['records'])) {
1528 $shortcutContent = array();
1529 $recordList = explode(',', $row['records']);
1530 foreach ($recordList as $recordIdentifier) {
1531 $split = BackendUtility::splitTable_Uid($recordIdentifier);
1532 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1533 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1534 if (is_array($shortcutRecord)) {
1535 $icon = IconUtility::getSpriteIconForRecord($tableName, $shortcutRecord);
1536 $icon = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon($icon, $tableName,
1537 $shortcutRecord['uid'], 1, '', '+copy,info,edit,view');
1538 $shortcutContent[] = $icon
1539 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1540 }
1541 }
1542 $out .= implode('<br />', $shortcutContent) . '<br />';
1543 }
1544 break;
1545 case 'list':
1546 $hookArr = array();
1547 $hookOut = '';
1548 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1549 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1550 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1551 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1552 }
1553 if (count($hookArr) > 0) {
1554 $_params = array('pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr);
1555 foreach ($hookArr as $_funcRef) {
1556 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1557 }
1558 }
1559 if ((string)$hookOut !== '') {
1560 $out .= $hookOut;
1561 } elseif (!empty($row['list_type'])) {
1562 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
1563 if (!empty($label)) {
1564 $out .= '<strong>' . $this->getLanguageService()->sL($label, TRUE) . '</strong><br />';
1565 } else {
1566 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1567 $out .= GeneralUtility::makeInstance(
1568 FlashMessage::class,
1569 htmlspecialchars($message),
1570 '',
1571 FlashMessage::WARNING
1572 )->render();
1573 }
1574 } elseif (!empty($row['select_key'])) {
1575 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), TRUE)
1576 . ' ' . $row['select_key'] . '<br />';
1577 } else {
1578 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1579 }
1580 $out .= $this->getLanguageService()->sL(
1581 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages']),
1582 TRUE
1583 ) . '<br />';
1584 break;
1585 case 'script':
1586 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), TRUE)
1587 . ' ' . $row['select_key'] . '<br />';
1588 $out .= '<br />' . $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1589 $out .= '<br />' . $this->linkEditContent($this->renderText($row['imagecaption']), $row) . '<br />';
1590 break;
1591 default:
1592 $contentType = $this->CType_labels[$row['CType']];
1593
1594 if (isset($contentType)) {
1595 $out .= '<strong>' . htmlspecialchars($contentType) . '</strong><br />';
1596 if ($row['bodytext']) {
1597 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1598 }
1599 if ($row['image']) {
1600 $out .= $this->thumbCode($row, 'tt_content', 'image') . '<br />';
1601 }
1602 } else {
1603 $message = sprintf(
1604 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1605 $row['CType']
1606 );
1607 $out .= GeneralUtility::makeInstance(
1608 FlashMessage::class,
1609 htmlspecialchars($message),
1610 '',
1611 FlashMessage::WARNING
1612 )->render();
1613 }
1614 }
1615 }
1616 // Wrap span-tags:
1617 $out = '
1618 <span class="exampleContent">' . $out . '</span>';
1619 // Add header:
1620 $out = $outHeader . $out;
1621 // Add RTE button:
1622 if ($isRTE) {
1623 $out .= $this->linkRTEbutton($row);
1624 }
1625 // Return values:
1626 if ($this->isDisabled('tt_content', $row)) {
1627 return '<span class="text-muted">' . $out . '</span>';
1628 } else {
1629 return $out;
1630 }
1631 }
1632
1633 /**
1634 * Generates a list of selected pages or categories for the CType menu
1635 *
1636 * @param array $row row from pages
1637 * @return string
1638 */
1639 protected function generateListForCTypeMenu(array $row) {
1640 $table = 'pages';
1641 $field = 'pages';
1642 // get categories instead of pages
1643 if (strpos($row['menu_type'], 'categorized_') !== FALSE) {
1644 $table = 'sys_category';
1645 $field = 'selected_categories';
1646 }
1647 if (trim($row[$field]) === '') {
1648 return '';
1649 }
1650 $content = '';
1651 $uidList = explode(',', $row[$field]);
1652 foreach ($uidList as $uid) {
1653 $uid = (int)$uid;
1654 $record = BackendUtility::getRecord($table, $uid, 'title');
1655 $content .= '<br>' . $record['title'] . ' (' .$uid. ')';
1656 }
1657 return $content;
1658 }
1659
1660 /**
1661 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1662 * Selects across columns, but within in the same PID. Columns are expect to be the same
1663 * for translations and original but this may be a conceptual error (?)
1664 *
1665 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1666 * @param int $id Page pid
1667 * @param int $lP Sys language UID
1668 * @return array Modified $defLanguageCount
1669 */
1670 public function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP) {
1671 if ($lP && count($defLanguageCount)) {
1672 // Select all translations here:
1673 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND sys_language_uid=' . (int)$lP
1674 . ' AND l18n_parent IN (' . implode(',', $defLanguageCount) . ')');
1675 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1676 // Flip uids:
1677 $defLanguageCount = array_flip($defLanguageCount);
1678 // Traverse any selected elements and unset original UID if any:
1679 $rowArr = $this->getResult($result);
1680 foreach ($rowArr as $row) {
1681 unset($defLanguageCount[$row['l18n_parent']]);
1682 }
1683 // Flip again:
1684 $defLanguageCount = array_keys($defLanguageCount);
1685 }
1686 return $defLanguageCount;
1687 }
1688
1689 /**
1690 * Creates button which is used to create copies of records..
1691 *
1692 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1693 * @param int $lP Sys language UID
1694 * @return string "Copy languages" button, if available.
1695 */
1696 public function newLanguageButton($defLanguageCount, $lP) {
1697 if (!$this->doEdit || count($defLanguageCount) === 0 || !$lP) {
1698 return '';
1699 }
1700 $params = '';
1701 foreach ($defLanguageCount as $uidVal) {
1702 $params .= '&cmd[tt_content][' . $uidVal . '][localize]=' . $lP;
1703 }
1704 // Copy for language:
1705 $onClick = 'window.location.href=\'' . $this->getPageLayoutController()->doc->issueCommand($params) . '\'; return false;';
1706 $theNewButton = '<div class="t3-page-lang-copyce">' .
1707 $this->getPageLayoutController()->doc->t3Button(
1708 $onClick,
1709 $this->getLanguageService()->getLL('newPageContent_copyForLang') . ' [' . count($defLanguageCount) . ']'
1710 ) . '</div>';
1711 return $theNewButton;
1712 }
1713
1714 /**
1715 * Creates onclick-attribute content for a new content element
1716 *
1717 * @param int $id Page id where to create the element.
1718 * @param int $colPos Preset: Column position value
1719 * @param int $sys_language Preset: Sys langauge value
1720 * @return string String for onclick attribute.
1721 * @see getTable_tt_content()
1722 */
1723 public function newContentElementOnClick($id, $colPos, $sys_language) {
1724 if ($this->option_newWizard) {
1725 $onClick = 'window.location.href=\'' . BackendUtility::getModuleUrl('new_content_element') . '&id=' . $id . '&colPos=' . $colPos
1726 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
1727 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI')) . '\';';
1728 } else {
1729 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
1730 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
1731 }
1732 return $onClick;
1733 }
1734
1735 /**
1736 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
1737 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
1738 *
1739 * @param string $str String to link. Must be prepared for HTML output.
1740 * @param array $row The row.
1741 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
1742 * @see getTable_tt_content()
1743 */
1744 public function linkEditContent($str, $row) {
1745 $addButton = '';
1746 $onClick = '';
1747 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1748 // Setting onclick action for content link:
1749 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit');
1750 }
1751 // Return link
1752 return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick)
1753 . '" title="' . $this->getLanguageService()->getLL('edit', TRUE) . '">' . $str . '</a>' . $addButton : $str;
1754 }
1755
1756 /**
1757 * Adds a button to edit the row in RTE wizard
1758 *
1759 * @param array $row The row of tt_content element
1760 * @return string Button to click if you want to edit in RTE wizard.
1761 */
1762 public function linkRTEbutton($row) {
1763 $params = array();
1764 $params['table'] = 'tt_content';
1765 $params['uid'] = $row['uid'];
1766 $params['pid'] = $row['pid'];
1767 $params['field'] = 'bodytext';
1768 $params['returnUrl'] = GeneralUtility::linkThisScript();
1769 $RTEonClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_rte', array('P' => $params))) . ';return false;';
1770 $addButton = $this->option_showBigButtons && $this->doEdit
1771 ? $this->getPageLayoutController()->doc->t3Button($RTEonClick, $this->getLanguageService()->getLL('editInRTE'))
1772 : '';
1773 return $addButton;
1774 }
1775
1776 /**
1777 * Make selector box for creating new translation in a language
1778 * Displays only languages which are not yet present for the current page and
1779 * that are not disabled with page TS.
1780 *
1781 * @param int $id Page id for which to create a new language (pages_language_overlay record)
1782 * @return string <select> HTML element (if there were items for the box anyways...)
1783 * @see getTable_tt_content()
1784 */
1785 public function languageSelector($id) {
1786 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
1787 // First, select all
1788 $res = $this->getPageLayoutController()->exec_languageQuery(0);
1789 $langSelItems = array();
1790 $langSelItems[0] = '
1791 <option value="0"></option>';
1792 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1793 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1794 $langSelItems[$row['uid']] = '
1795 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
1796 }
1797 }
1798 // Then, subtract the languages which are already on the page:
1799 $res = $this->getPageLayoutController()->exec_languageQuery($id);
1800 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1801 unset($langSelItems[$row['uid']]);
1802 }
1803 // Remove disallowed languages
1804 if (count($langSelItems) > 1
1805 && !$this->getBackendUser()->user['admin']
1806 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
1807 ) {
1808 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1809 if (count($allowed_languages)) {
1810 foreach ($langSelItems as $key => $value) {
1811 if (!isset($allowed_languages[$key]) && $key != 0) {
1812 unset($langSelItems[$key]);
1813 }
1814 }
1815 }
1816 }
1817 // Remove disabled languages
1818 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
1819 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1820 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], TRUE)
1821 : array();
1822 if (count($langSelItems) && count($disableLanguages)) {
1823 foreach ($disableLanguages as $language) {
1824 if ($language != 0 && isset($langSelItems[$language])) {
1825 unset($langSelItems[$language]);
1826 }
1827 }
1828 }
1829 // If any languages are left, make selector:
1830 if (count($langSelItems) > 1) {
1831 $url = BackendUtility::getModuleUrl('record_edit', array(
1832 'edit[pages_language_overlay]['. $id . ']' => 'new',
1833 'overrideVals[pages_language_overlay][doktype]' => (int)$this->pageRecord['doktype'],
1834 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1835 ));
1836 $onChangeContent = 'window.location.href=\'' . $url . '&overrideVals[pages_language_overlay][sys_language_uid]=\'+this.options[this.selectedIndex].value';
1837 return '<div class="form-inline form-inline-spaced">'
1838 . '<div class="form-group">'
1839 . '<label for="createNewLanguage">'
1840 . $this->getLanguageService()->getLL('new_language', TRUE)
1841 . '</label>'
1842 . '<select class="form-control input-sm" name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">'
1843 . implode('', $langSelItems)
1844 . '</select></div></div>';
1845 }
1846 }
1847 return '';
1848 }
1849
1850 /**
1851 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
1852 *
1853 * @param bool|\mysqli_result|object $result MySQLi result object / DBAL object
1854 * @param string $table Table name defaulting to tt_content
1855 * @return array The selected rows returned in this array.
1856 */
1857 public function getResult($result, $table = 'tt_content') {
1858 $output = array();
1859 // Traverse the result:
1860 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
1861 BackendUtility::workspaceOL($table, $row, -99, TRUE);
1862 if ($row) {
1863 // Add the row to the array:
1864 $output[] = $row;
1865 }
1866 }
1867 $this->generateTtContentDataArray($output);
1868 // Return selected records
1869 return $output;
1870 }
1871
1872 /********************************
1873 *
1874 * Various helper functions
1875 *
1876 ********************************/
1877
1878 /**
1879 * Initializes the clipboard for generating paste links
1880 *
1881 * @return void
1882 *
1883 * @see \TYPO3\CMS\Recordlist\RecordList::main()
1884 * @see \TYPO3\CMS\Backend\Controller\ClickMenuController::main()
1885 * @see \TYPO3\CMS\Filelist\Controller\FileListController::main()
1886 */
1887 protected function initializeClipboard() {
1888 // Start clipboard
1889 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
1890
1891 // Initialize - reads the clipboard content from the user session
1892 $this->clipboard->initializeClipboard();
1893
1894 // This locks the clipboard to the Normal for this request.
1895 $this->clipboard->lockToNormal();
1896
1897 // Clean up pad
1898 $this->clipboard->cleanCurrent();
1899
1900 // Save the clipboard content
1901 $this->clipboard->endClipboard();
1902 }
1903
1904 /**
1905 * Generates the data for previous and next elements which is needed for movements.
1906 *
1907 * @param array $rowArray
1908 * @return void
1909 */
1910 protected function generateTtContentDataArray(array $rowArray) {
1911 if (empty($this->tt_contentData)) {
1912 $this->tt_contentData = array(
1913 'nextThree' => array(),
1914 'next' => array(),
1915 'prev' => array(),
1916 );
1917 }
1918 foreach ($rowArray as $key => $value) {
1919 // Create the list of the next three ids (for editing links...)
1920 for ($i = 0; $i < $this->nextThree; $i++) {
1921 if (isset($rowArray[$key - $i])
1922 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
1923 ) {
1924 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
1925 }
1926 }
1927
1928 // Create information for next and previous content elements
1929 if (isset($rowArray[$key - 1])) {
1930 if (isset($rowArray[$key - 2])) {
1931 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
1932 } else {
1933 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
1934 }
1935 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
1936 }
1937 }
1938 }
1939
1940 /**
1941 * Counts and returns the number of records on the page with $pid
1942 *
1943 * @param string $table Table name
1944 * @param int $pid Page id
1945 * @return int Number of records.
1946 */
1947 public function numberOfRecords($table, $pid) {
1948 $count = 0;
1949 if ($GLOBALS['TCA'][$table]) {
1950 $where = 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table);
1951 $count = $this->getDatabase()->exec_SELECTcountRows('uid', $table, $where);
1952 }
1953 return (int)$count;
1954 }
1955
1956 /**
1957 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
1958 *
1959 * @param string $input Input string
1960 * @return string Output string
1961 */
1962 public function renderText($input) {
1963 $input = strip_tags($input);
1964 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
1965 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', FALSE));
1966 }
1967
1968 /**
1969 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
1970 *
1971 * @param string $table Table name
1972 * @param array $row Record array
1973 * @return string HTML for the icon
1974 */
1975 public function getIcon($table, $row) {
1976 // Initialization
1977 $altText = BackendUtility::getRecordIconAltText($row, $table);
1978 $icon = IconUtility::getSpriteIconForRecord($table, $row, array('title' => $altText));
1979 $this->counter++;
1980 // The icon with link
1981 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
1982 $icon = $this->getPageLayoutController()->doc->wrapClickMenuOnIcon($icon, $table, $row['uid']);
1983 }
1984 return $icon;
1985 }
1986
1987 /**
1988 * Creates processed values for all field names in $fieldList based on values from $row array.
1989 * The result is 'returned' through $info which is passed as a reference
1990 *
1991 * @param string $table Table name
1992 * @param string $fieldList Comma separated list of fields.
1993 * @param array $row Record from which to take values for processing.
1994 * @param array $info Array to which the processed values are added.
1995 * @return void
1996 */
1997 public function getProcessedValue($table, $fieldList, array $row, array &$info) {
1998 // Splitting values from $fieldList
1999 $fieldArr = explode(',', $fieldList);
2000 // Traverse fields from $fieldList
2001 foreach ($fieldArr as $field) {
2002 if ($row[$field]) {
2003 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2004 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2005 }
2006 }
2007 }
2008
2009 /**
2010 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2011 *
2012 * @param string $table Tablename of table to test
2013 * @param array $row Record row.
2014 * @return bool Returns TRUE, if disabled.
2015 */
2016 public function isDisabled($table, $row) {
2017 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2018 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2019 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2020 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2021 }
2022
2023 /**
2024 * Will perform "word-wrapping" on the input string. What it does is to split by space or line break,
2025 * then find any word longer than $max and if found, a hyphen is inserted.
2026 * Works well on normal texts, little less well when HTML is involved (since much HTML will have
2027 * long strings that will be broken).
2028 *
2029 * @param string $content Content to word-wrap.
2030 * @param int $max Max number of chars in a word before it will be wrapped.
2031 * @param string $char Character to insert when wrapping.
2032 * @return string Processed output.
2033 * @deprecated since 6.2 - will be removed two versions later; use CSS instead (word-break: break-all;)
2034 */
2035 public function wordWrapper($content, $max = 50, $char = ' -') {
2036 GeneralUtility::logDeprecatedFunction();
2037 $array = preg_split('/[ ' . LF . ']/', $content);
2038 foreach ($array as $val) {
2039 if (strlen($val) > $max) {
2040 $content = str_replace($val, substr(chunk_split($val, $max, $char), 0, -1), $content);
2041 }
2042 }
2043 return $content;
2044 }
2045
2046 /**
2047 * Returns icon for "no-edit" of a record.
2048 * Basically, the point is to signal that this record could have had an edit link if
2049 * the circumstances were right. A placeholder for the regular edit icon...
2050 *
2051 * @param string $label Label key from LOCAL_LANG
2052 * @return string IMG tag for icon.
2053 */
2054 public function noEditIcon($label = 'noEditItems') {
2055 return IconUtility::getSpriteIcon(
2056 'status-edit-read-only',
2057 array('title' => $this->getLanguageService()->getLL($label, TRUE))
2058 );
2059 }
2060
2061 /**
2062 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
2063 * which the user has access. Also a set of standard tables (pages, static_template, sys_filemounts, etc...)
2064 * are filtered out. So what is left is basically all tables which makes sense to list content from.
2065 *
2066 * @return array
2067 */
2068 protected function cleanTableNames() {
2069 // Get all table names:
2070 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2071 // Unset common names:
2072 unset($tableNames['pages']);
2073 unset($tableNames['static_template']);
2074 unset($tableNames['sys_filemounts']);
2075 unset($tableNames['sys_action']);
2076 unset($tableNames['sys_workflows']);
2077 unset($tableNames['be_users']);
2078 unset($tableNames['be_groups']);
2079 $allowedTableNames = array();
2080 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2081 if (is_array($tableNames)) {
2082 foreach ($tableNames as $k => $v) {
2083 if ($this->getBackendUser()->check('tables_select', $k)) {
2084 $allowedTableNames['table_' . $k] = $k;
2085 }
2086 }
2087 }
2088 return $allowedTableNames;
2089 }
2090
2091 /**
2092 * Checking if the RTE is available/enabled for a certain table/field and if so, it returns TRUE.
2093 * Used to determine if the RTE button should be displayed.
2094 *
2095 * @param string $table Table name
2096 * @param array $row Record row (needed, if there are RTE dependencies based on other fields in the record)
2097 * @param string $field Field name
2098 * @return bool Returns TRUE if the rich text editor would be enabled/available for the field name specified.
2099 */
2100 public function isRTEforField($table, $row, $field) {
2101 $specConf = $this->getSpecConfForField($table, $row, $field);
2102 if (!count($specConf)) {
2103 return FALSE;
2104 }
2105 $p = BackendUtility::getSpecConfParametersFromArray($specConf['rte_transform']['parameters']);
2106 if (isset($specConf['richtext']) && (!$p['flag'] || !$row[$p['flag']])) {
2107 BackendUtility::fixVersioningPid($table, $row);
2108 list($tscPID, $thePidValue) = BackendUtility::getTSCpid($table, $row['uid'], $row['pid']);
2109 // If the pid-value is not negative (that is, a pid could NOT be fetched)
2110 if ($thePidValue >= 0) {
2111 if (!isset($this->rteSetup[$tscPID])) {
2112 $this->rteSetup[$tscPID] = $this->getBackendUser()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($tscPID));
2113 }
2114 $RTEtypeVal = BackendUtility::getTCAtypeValue($table, $row);
2115 $thisConfig = BackendUtility::RTEsetup($this->rteSetup[$tscPID]['properties'], $table, $field, $RTEtypeVal);
2116 if (!$thisConfig['disabled']) {
2117 return TRUE;
2118 }
2119 }
2120 }
2121 return FALSE;
2122 }
2123
2124 /**
2125 * Returns "special" configuration from the "types" configuration in TCA for the record given by tablename/fieldname.
2126 * Used by isRTEforField() in the process of finding whether a field has RTE enabled or not.
2127 *
2128 * @param string $table Table name
2129 * @param array $row Record array
2130 * @param string $field Field name
2131 * @return array Spec. conf (if available)
2132 * @access private
2133 * @see isRTEforField()
2134 */
2135 public function getSpecConfForField($table, $row, $field) {
2136 // Get types-configuration for the record:
2137 $types_fieldConfig = BackendUtility::getTCAtypes($table, $row);
2138 // Find the given field and return the spec key value if found:
2139 if (is_array($types_fieldConfig)) {
2140 foreach ($types_fieldConfig as $vConf) {
2141 if ($vConf['field'] == $field) {
2142 return $vConf['spec'];
2143 }
2144 }
2145 }
2146 return array();
2147 }
2148
2149 /*****************************************
2150 *
2151 * External renderings
2152 *
2153 *****************************************/
2154
2155 /**
2156 * Creates a menu of the tables that can be listed by this function
2157 * Only tables which has records on the page will be included.
2158 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2159 *
2160 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2161 * @return string HTML output.
2162 */
2163 public function getTableMenu($id) {
2164 // Initialize:
2165 $this->activeTables = array();
2166 $theTables = array('tt_content');
2167 // External tables:
2168 if (is_array($this->externalTables)) {
2169 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2170 }
2171 $out = '';
2172 // Traverse tables to check:
2173 foreach ($theTables as $tName) {
2174 // Check access and whether the proper extensions are loaded:
2175 if ($this->getBackendUser()->check('tables_select', $tName)
2176 && (isset($this->externalTables[$tName])
2177 || GeneralUtility::inList('fe_users,tt_content', $tName)
2178 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2179 )
2180 ) {
2181 // Make query to count records from page:
2182 $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int)$id
2183 . BackendUtility::deleteClause($tName) . BackendUtility::versioningPlaceholderClause($tName));
2184 // If records were found (or if "tt_content" is the table...):
2185 if ($c || GeneralUtility::inList('tt_content', $tName)) {
2186 // Add row to menu:
2187 $out .= '
2188 <td><a href="#' . $tName . '"></a>' . IconUtility::getSpriteIconForRecord(
2189 $tName,
2190 array(),
2191 array('title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE))
2192 ) . '</td>';
2193 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2194 $this->activeTables[$tName] = IconUtility::getSpriteIconForRecord(
2195 $tName,
2196 array(),
2197 array('title' => $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE)
2198 . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', TRUE))
2199 ) . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], TRUE);
2200 }
2201 }
2202 }
2203 // Wrap cells in table tags:
2204 $out = '
2205 <!--
2206 Menu of tables on the page (table menu)
2207 -->
2208 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2209 <tr>' . $out . '
2210 </tr>
2211 </table>';
2212 // Return the content:
2213 return $out;
2214 }
2215
2216 /**
2217 * @return BackendLayoutView
2218 */
2219 protected function getBackendLayoutView() {
2220 return GeneralUtility::makeInstance(BackendLayoutView::class);
2221 }
2222
2223 /**
2224 * @return BackendUserAuthentication
2225 */
2226 protected function getBackendUser() {
2227 return $GLOBALS['BE_USER'];
2228 }
2229
2230 /**
2231 * @return DatabaseConnection
2232 */
2233 protected function getDatabase() {
2234 return $GLOBALS['TYPO3_DB'];
2235 }
2236
2237 /**
2238 * @return PageLayoutController
2239 */
2240 protected function getPageLayoutController() {
2241 return $GLOBALS['SOBE'];
2242 }
2243
2244 }