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