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