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