TYPO3  7.6
PageLayoutView.php
Go to the documentation of this file.
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 
32 
36 class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList
37 {
38 
44  public $pI_showUser = 0;
45 
51  public $nextThree = 3;
52 
59 
65  public $option_newWizard = 1;
66 
72  public $ext_function = 0;
73 
79  public $doEdit = 1;
80 
86  public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
87 
93  public $externalTables = array();
94 
100  public $descrTable;
101 
108  public $defLangBinding = false;
109 
115  public $tt_contentConfig = array(
116  // Boolean: Display info-marks or not
117  'showInfo' => 1,
118  // Boolean: Display up/down arrows and edit icons for tt_content records
119  'showCommands' => 1,
120  'languageCols' => 0,
121  'languageMode' => 0,
122  'languageColsPointer' => 0,
123  'showHidden' => 1,
124  // Displays hidden records as well
125  'sys_language_uid' => 0,
126  // Which language
127  'cols' => '1,0,2,3',
128  'activeCols' => '1,0,2,3'
129  // Which columns can be accessed by current BE user
130  );
131 
137  public $activeTables = array();
138 
142  public $tt_contentData = array(
143  'nextThree' => array(),
144  'prev' => array(),
145  'next' => array()
146  );
147 
153  public $CType_labels = array();
154 
160  public $itemLabels = array();
161 
165  protected $clipboard;
166 
170  protected $plusPages = array();
171 
178 
184  protected $pageinfo;
185 
191  protected $languagesInColumnCache = array();
192 
199  protected $contentElementCache = array();
200 
204  protected $iconFactory;
205 
211  protected $languageHasTranslationsCache = array();
212 
216  public function __construct()
217  {
218  parent::__construct();
219  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
220  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
221  $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
222  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
223  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
224 
225  }
226 
227  /*****************************************
228  *
229  * Renderings
230  *
231  *****************************************/
240  public function getTable($table, $id, $fields = '')
241  {
242  if (isset($this->externalTables[$table])) {
243  return $this->getExternalTables($id, $table);
244  } else {
245  // Branch out based on table name:
246  switch ($table) {
247  case 'pages':
248  return $this->getTable_pages($id);
249  break;
250  case 'tt_content':
251  return $this->getTable_tt_content($id);
252  break;
253  default:
254  return '';
255  }
256  }
257  }
258 
266  public function getExternalTables($id, $table)
267  {
268  $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
269  if (!isset($type)) {
270  $type = 0;
271  }
272  // eg. "name;title;email;company,image"
273  $fList = $this->externalTables[$table][$type]['fList'];
274  // The columns are separeted by comma ','.
275  // Values separated by semicolon ';' are shown in the same column.
276  $icon = $this->externalTables[$table][$type]['icon'];
277  $addWhere = $this->externalTables[$table][$type]['addWhere'];
278  // Create listing
279  $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
280  return $out;
281  }
282 
290  public function getTable_pages($id)
291  {
292  // Initializing:
293  $out = '';
294  // Select clause for pages:
295  $delClause = BackendUtility::deleteClause('pages') . ' AND ' . $this->getBackendUser()->getPagePermsClause(1);
296  // Select current page:
297  if (!$id) {
298  // The root has a pseudo record in pageinfo...
299  $row = $this->getPageLayoutController()->pageinfo;
300  } else {
301  $result = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'uid=' . (int)$id . $delClause);
302  $row = $this->getDatabase()->sql_fetch_assoc($result);
303  BackendUtility::workspaceOL('pages', $row);
304  }
305  // If there was found a page:
306  if (is_array($row)) {
307  // Select which fields to show:
308  $pKey = $this->getPageLayoutController()->MOD_SETTINGS['pages'];
309  switch ($pKey) {
310  case 1:
311  $this->fieldArray = array('title','uid') + array_keys($this->cleanTableNames());
312  break;
313  case 2:
314  $this->fieldArray = array(
315  'title',
316  'uid',
317  'lastUpdated',
318  'newUntil',
319  'no_cache',
320  'cache_timeout',
321  'php_tree_stop',
322  'TSconfig',
323  'is_siteroot',
324  'fe_login_mode'
325  );
326  break;
327  default:
328  $this->fieldArray = array(
329  'title',
330  'uid',
331  'alias',
332  'starttime',
333  'endtime',
334  'fe_group',
335  'target',
336  'url',
337  'shortcut',
338  'shortcut_mode'
339  );
340  }
341  // Getting select-depth:
342  $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
343  // Overriding a few things:
344  $this->no_noWrap = 0;
345  // Items
346  $this->eCounter = $this->firstElementNumber;
347  // Creating elements:
348  list($flag, $code) = $this->fwd_rwd_nav();
349  $out .= $code;
350  $editUids = array();
351  if ($flag) {
352  // Getting children:
353  $theRows = array();
354  $theRows = $this->pages_getTree($theRows, $row['uid'], $delClause . BackendUtility::versioningPlaceholderClause('pages'), '', $depth);
355  if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
356  $editUids[] = $row['uid'];
357  }
358  $out .= $this->pages_drawItem($row, $this->fieldArray);
359  // Traverse all pages selected:
360  foreach ($theRows as $sRow) {
361  if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
362  $editUids[] = $sRow['uid'];
363  }
364  $out .= $this->pages_drawItem($sRow, $this->fieldArray);
365  }
366  $this->eCounter++;
367  }
368  // Header line is drawn
369  $theData = array();
370  $editIdList = implode(',', $editUids);
371  // Traverse fields (as set above) in order to create header values:
372  foreach ($this->fieldArray as $field) {
373  if ($editIdList && isset($GLOBALS['TCA']['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
374  $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=' . $field;
375  $iTitle = sprintf(
376  $this->getLanguageService()->getLL('editThisColumn'),
377  rtrim(trim($this->getLanguageService()->sL(BackendUtility::getItemLabel('pages', $field))), ':')
378  );
379  $eI = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
380  . '" title="' . htmlspecialchars($iTitle) . '">'
381  . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
382  } else {
383  $eI = '';
384  }
385  switch ($field) {
386  case 'title':
387  $theData[$field] = '&nbsp;<strong>'
388  . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
389  . '</strong>' . $eI;
390  break;
391  case 'uid':
392  $theData[$field] = '&nbsp;<strong>ID:</strong>';
393  break;
394  default:
395  if (substr($field, 0, 6) == 'table_') {
396  $f2 = substr($field, 6);
397  if ($GLOBALS['TCA'][$f2]) {
398  $theData[$field] = '&nbsp;' . '<span title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$f2]['ctrl']['title'], true) . '">' . $this->iconFactory->getIconForRecord($f2, array(), Icon::SIZE_SMALL)->render() . '</span>';
399  }
400  } else {
401  $theData[$field] = '&nbsp;&nbsp;<strong>'
402  . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'], true)
403  . '</strong>' . $eI;
404  }
405  }
406  }
407  // CSH:
408  $out = BackendUtility::cshItem($this->descrTable, ('func_' . $pKey)) . '
409  <div class="table-fit">
410  <table class="table table-striped table-hover typo3-page-pages">' .
411  '<thead>' .
412  $this->addElement(1, '', $theData) .
413  '</thead>' .
414  '<tbody>' .
415  $out .
416  '</tbody>' .
417  '</table>
418  </div>';
419  }
420  return $out;
421  }
422 
429  public function getTable_tt_content($id)
430  {
431  $backendUser = $this->getBackendUser();
432  $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
433  $this->initializeLanguages();
434  $this->initializeClipboard();
435  $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
437  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
438  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
439  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
440  $userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
441  if ($this->tt_contentConfig['languageColsPointer'] > 0) {
442  $userCanEditPage = $this->getBackendUser()->check('tables_modify', 'pages_language_overlay');
443  }
444  if ($userCanEditPage) {
445  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
446  PageActions.setPageId(' . (int)$this->id . ');
447  PageActions.setLanguageOverlayId(' . $this->tt_contentConfig['languageColsPointer'] . ');
448  PageActions.initializePageTitleRenaming();
449  }');
450  }
451  // Get labels for CTypes and tt_content element fields in general:
452  $this->CType_labels = array();
453  foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
454  $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
455  }
456  $this->itemLabels = array();
457  foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
458  $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
459  }
460  $languageColumn = array();
461  $out = '';
462 
463  // Setting language list:
464  $langList = $this->tt_contentConfig['sys_language_uid'];
465  if ($this->tt_contentConfig['languageMode']) {
466  if ($this->tt_contentConfig['languageColsPointer']) {
467  $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
468  } else {
469  $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
470  }
471  $languageColumn = array();
472  }
473  $langListArr = GeneralUtility::intExplode(',', $langList);
474  $defLanguageCount = array();
475  $defLangBinding = array();
476  // For each languages... :
477  // If not languageMode, then we'll only be through this once.
478  foreach ($langListArr as $lP) {
479  $lP = (int)$lP;
480 
481  if (!isset($this->contentElementCache[$lP])) {
482  $this->contentElementCache[$lP] = array();
483  }
484 
485  if (count($langListArr) === 1 || $lP === 0) {
486  $showLanguage = ' AND sys_language_uid IN (' . $lP . ',-1)';
487  } else {
488  $showLanguage = ' AND sys_language_uid=' . $lP;
489  }
490  $cList = explode(',', $this->tt_contentConfig['cols']);
491  $content = array();
492  $head = array();
493 
494  // Select content records per column
495  $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, array_values($cList), $showLanguage);
496  // For each column, render the content into a variable:
497  foreach ($cList as $key) {
498  if (!isset($this->contentElementCache[$lP][$key])) {
499  $this->contentElementCache[$lP][$key] = array();
500  }
501 
502  if (!$lP) {
503  $defLanguageCount[$key] = array();
504  }
505  // Start wrapping div
506  $content[$key] .= '<div data-colpos="' . $key . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
507  if (empty($contentRecordsPerColumn[$key])) {
508  $content[$key] .= ' t3-page-ce-empty';
509  }
510  $content[$key] .= '">';
511  // Add new content at the top most position
512  $link = '';
513  if ($this->getPageLayoutController()->pageIsNotLockedForEditors()
514  && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
515  && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
516  ) {
517  $link = '<a href="#" onclick="' . htmlspecialchars($this->newContentElementOnClick($id, $key, $lP))
518  . '" title="' . $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
519  . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
520  . ' '
521  . $this->getLanguageService()->getLL('content', true) . '</a>';
522  }
523  $content[$key] .= '
524  <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
525  <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id . '-' . StringUtility::getUniqueId() . '">'
526  . $link
527  . '</div>
528  <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
529  </div>
530  ';
531  $editUidList = '';
532  $rowArr = $contentRecordsPerColumn[$key];
533  $this->generateTtContentDataArray($rowArr);
534 
535  foreach ((array)$rowArr as $rKey => $row) {
536  $this->contentElementCache[$lP][$key][$row['uid']] = $row;
537  if ($this->tt_contentConfig['languageMode']) {
538  $languageColumn[$key][$lP] = $head[$key] . $content[$key];
539  if (!$this->defLangBinding) {
540  $languageColumn[$key][$lP] .= $this->newLanguageButton(
541  $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
542  $lP,
543  $key
544  );
545  }
546  }
547  if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
548  $singleElementHTML = '';
549  if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
550  $defLanguageCount[$key][] = (isset($row['_ORIG_uid']) ? $row['_ORIG_uid'] : $row['uid']);
551  }
552  $editUidList .= $row['uid'] . ',';
553  $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
554  if (!$this->tt_contentConfig['languageMode']) {
555  $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
556  }
557  $singleElementHTML .= $this->tt_content_drawHeader(
558  $row,
559  $this->tt_contentConfig['showInfo'] ? 15 : 5,
560  $disableMoveAndNewButtons,
561  !$this->tt_contentConfig['languageMode'],
562  $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
563  );
564  $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
565  . $this->tt_content_drawItem($row) . '</div>';
566  $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
567  . $this->tt_content_drawFooter($row);
568  $isDisabled = $this->isDisabled('tt_content', $row);
569  $statusHidden = $isDisabled ? ' t3-page-ce-hidden t3js-hidden-record' : '';
570  $displayNone = !$this->tt_contentConfig['showHidden'] && $isDisabled ? ' style="display: none;"' : '';
571  $highlightHeader = false;
572  if ($this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid']) && (int)$row['l18n_parent'] === 0) {
573  $highlightHeader = true;
574  }
575  $singleElementHTML = '<div class="t3-page-ce ' . ($highlightHeader ? 't3-page-ce-danger' : '') . ' t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
576  . $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '"' . $displayNone . '>' . $singleElementHTML . '</div>';
577 
578  if ($this->tt_contentConfig['languageMode']) {
579  $singleElementHTML .= '<div class="t3-page-ce t3js-page-ce">';
580  }
581  $singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id .
582  '-' . StringUtility::getUniqueId() . '">';
583  // Add icon "new content element below"
584  if (!$disableMoveAndNewButtons
585  && $this->getPageLayoutController()->pageIsNotLockedForEditors()
586  && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
587  && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
588  ) {
589  // New content element:
590  if ($this->option_newWizard) {
591  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $row['pid']
592  . '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos']
593  . '&uid_pid=' . -$row['uid'] .
594  '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
595  } else {
596  $params = '&edit[tt_content][' . -$row['uid'] . ']=new';
597  $onClick = BackendUtility::editOnClick($params);
598  }
599  $singleElementHTML .= '
600  <a href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
601  . $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
602  . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
603  . ' '
604  . $this->getLanguageService()->getLL('content', true) . '</a>
605  ';
606  }
607  $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
608  if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
609  $defLangBinding[$key][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
610  } else {
611  $content[$key] .= $singleElementHTML;
612  }
613  } else {
614  unset($rowArr[$rKey]);
615  }
616  }
617  $content[$key] .= '</div>';
618  // Add new-icon link, header:
619  $newP = $this->newContentElementOnClick($id, $key, $lP);
620  $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $key);
621  $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
622  foreach ($tcaItems as $item) {
623  if ($item[1] == $key) {
624  $colTitle = $this->getLanguageService()->sL($item[0]);
625  }
626  }
627 
628  $pasteP = array('colPos' => $key, 'sys_language_uid' => $lP);
629  $editParam = $this->doEdit && !empty($rowArr)
630  ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
631  : '';
632  $head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, $newP, $pasteP);
633  }
634  // For each column, fit the rendered content into a table cell:
635  $out = '';
636  if ($this->tt_contentConfig['languageMode']) {
637  // in language mode process the content elements, but only fill $languageColumn. output will be generated later
638  $sortedLanguageColumn = array();
639  foreach ($cList as $key) {
640  $languageColumn[$key][$lP] = $head[$key] . $content[$key];
641  if (!$this->defLangBinding) {
642  $languageColumn[$key][$lP] .= $this->newLanguageButton(
643  $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
644  $lP,
645  $key
646  );
647  }
648  // We sort $languageColumn again according to $cList as it may contain data already from above.
649  $sortedLanguageColumn[$key] = $languageColumn[$key];
650  }
651  $languageColumn = $sortedLanguageColumn;
652  } else {
653  $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
654  // GRID VIEW:
655  $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">';
656  // Add colgroups
657  $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
658  $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
659  $grid .= '<colgroup>';
660  for ($i = 0; $i < $colCount; $i++) {
661  $grid .= '<col style="width:' . 100 / $colCount . '%"></col>';
662  }
663  $grid .= '</colgroup>';
664  // Cycle through rows
665  for ($row = 1; $row <= $rowCount; $row++) {
666  $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
667  if (!isset($rowConfig)) {
668  continue;
669  }
670  $grid .= '<tr>';
671  for ($col = 1; $col <= $colCount; $col++) {
672  $columnConfig = $rowConfig['columns.'][$col . '.'];
673  if (!isset($columnConfig)) {
674  continue;
675  }
676  // Which tt_content colPos should be displayed inside this cell
677  $columnKey = (int)$columnConfig['colPos'];
678  // Render the grid cell
679  $colSpan = (int)$columnConfig['colspan'];
680  $rowSpan = (int)$columnConfig['rowspan'];
681  $grid .= '<td valign="top"' .
682  ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
683  ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
684  ' 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 .
685  ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
686  ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
687  ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
688  ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
689 
690  // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
691  // If not, a new header without any buttons will be generated.
692  if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
693  && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
694  ) {
695  $grid .= $head[$columnKey] . $content[$columnKey];
696  } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
697  && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
698  ) {
699  $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'), '', '');
700  } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
701  && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
702  ) {
703  $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
704  ' (' . $this->getLanguageService()->getLL('noAccess') . ')', '', '');
705  } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
706  $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
707  . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '');
708  } else {
709  $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'), '', '');
710  }
711 
712  $grid .= '</td>';
713  }
714  $grid .= '</tr>';
715  }
716  $out .= $grid . '</table></div>';
717  }
718  // CSH:
719  $out .= BackendUtility::cshItem($this->descrTable, 'columns_multi');
720  }
721  // If language mode, then make another presentation:
722  // Notice that THIS presentation will override the value of $out!
723  // But it needs the code above to execute since $languageColumn is filled with content we need!
724  if ($this->tt_contentConfig['languageMode']) {
725  // Get language selector:
726  $languageSelector = $this->languageSelector($id);
727  // Reset out - we will make new content here:
728  $out = '';
729  // Traverse languages found on the page and build up the table displaying them side by side:
730  $cCont = array();
731  $sCont = array();
732  foreach ($langListArr as $lP) {
733  // Header:
734  $lP = (int)$lP;
735  $cCont[$lP] = '
736  <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
737  <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
738  </td>';
739 
740  // "View page" icon is added:
741  $viewLink = '';
742  if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
743  $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
744  $viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
745  }
746  // Language overlay page header:
747  if ($lP) {
748  list($lpRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . $lP);
749  BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
750  $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
752  $this->iconFactory->getIconForRecord('pages_language_overlay', $lpRecord, Icon::SIZE_SMALL)->render(),
753  'pages_language_overlay',
754  $lpRecord['uid']
755  );
756  $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
757  ? '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
758  . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
759  . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
760  : ''
761  );
762 
763  $lPLabel =
764  '<div class="btn-group">'
765  . $viewLink
766  . $editLink
767  . '</div>'
768  . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
769  } else {
770  $params = '&edit[pages][' . $this->id . ']=edit';
771 
773  $this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(),
774  'pages',
775  $this->id
776  );
777  $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
778  ? '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
779  . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
780  . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
781  : ''
782  );
783 
784  $lPLabel =
785  '<div class="btn-group">'
786  . $viewLink
787  . $editLink
788  . '</div>'
789  . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
790  }
791  $sCont[$lP] = '
792  <td nowrap="nowrap" class="t3-page-column t3-page-lang-label">' . $lPLabel . '</td>';
793  }
794  // Add headers:
795  $out .= '<tr>' . implode($cCont) . '</tr>';
796  $out .= '<tr>' . implode($sCont) . '</tr>';
797  unset($cCont, $sCont);
798 
799  // Traverse previously built content for the columns:
800  foreach ($languageColumn as $cKey => $cCont) {
801  $out .= '<tr>';
802  foreach ($cCont as $languageId => $columnContent) {
803  $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>';
804  }
805  $out .= '</tr>';
806  if ($this->defLangBinding) {
807  // "defLangBinding" mode
808  foreach ($defLanguageCount[$cKey] as $defUid) {
809  $cCont = array();
810  foreach ($langListArr as $lP) {
811  $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
812  $this->getNonTranslatedTTcontentUids(array($defUid), $id, $lP),
813  $lP,
814  $cKey
815  );
816  }
817  $out .= '
818  <tr>
819  <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
820  <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
821  </tr>';
822  }
823  }
824  }
825  // Finally, wrap it all in a table and add the language selector on top of it:
826  $out = $languageSelector . '
827  <div class="t3-grid-container">
828  <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
829  ' . $out . '
830  </table>
831  </div>';
832  // CSH:
833  $out .= BackendUtility::cshItem($this->descrTable, 'language_list');
834  }
835 
836  return $out;
837  }
838 
839  /**********************************
840  *
841  * Generic listing of items
842  *
843  **********************************/
854  public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
855  {
856  // Initialize
857  $queryParts = $this->makeQueryArray($table, $id, $addWhere);
858  $this->setTotalItems($queryParts);
859  $dbCount = 0;
860  $result = false;
861  // Make query for records if there were any records found in the count operation
862  if ($this->totalItems) {
863  $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
864  // Will return FALSE, if $result is invalid
865  $dbCount = $this->getDatabase()->sql_num_rows($result);
866  }
867  // If records were found, render the list
868  if (!$dbCount) {
869  return '';
870  }
871  // Set fields
872  $out = '';
873  $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
874  $theData = array();
875  $theData = $this->headerFields($this->fieldArray, $table, $theData);
876  // Title row
877  $localizedTableTitle = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'], true);
878  $out .= '<tr class="t3-row-header">' . '<th class="col-icon"></th>'
879  . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
880  . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
881  . '</tr>';
882  // Column's titles
883  if ($this->doEdit) {
884  $onClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $this->id . ']=new');
885  $theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" '
886  . 'title="' . $this->getLanguageService()->getLL('new', true) . '">'
887  . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
888  }
889  $out .= $this->addElement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
890  // Render Items
891  $this->eCounter = $this->firstElementNumber;
892  while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
893  BackendUtility::workspaceOL($table, $row);
894  if (is_array($row)) {
895  list($flag, $code) = $this->fwd_rwd_nav();
896  $out .= $code;
897  if ($flag) {
898  $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
899  $Nrow = array();
900  // Setting icons links
901  if ($icon) {
902  $Nrow['__cmds__'] = $this->getIcon($table, $row);
903  }
904  // Get values:
905  $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
906  // Attach edit icon
907  if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
908  $Nrow['__editIconLink__'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
909  . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
910  . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
911  } else {
912  $Nrow['__editIconLink__'] = $this->noEditIcon();
913  }
914  $out .= $this->addElement(1, '', $Nrow);
915  }
916  $this->eCounter++;
917  }
918  }
919  $this->getDatabase()->sql_free_result($result);
920  // Wrap it all in a table:
921  $out = '
922  <!--
923  Standard list of table "' . $table . '"
924  -->
925  <div class="table-fit"><table class="table table-striped">
926  ' . $out . '
927  </table></div>';
928  return $out;
929  }
930 
945  public function dataFields($fieldArr, $table, $row, $out = array())
946  {
947  // Check table validity
948  if (!isset($GLOBALS['TCA'][$table])) {
949  return $out;
950  }
951 
952  $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
953  // Traverse fields
954  foreach ($fieldArr as $fieldName) {
955  if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
956  // Each field has its own cell (if configured in TCA)
957  // If the column is a thumbnail column:
958  if ($fieldName == $thumbsCol) {
959  $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
960  } else {
961  // ... otherwise just render the output:
962  $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
963  BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
964  250
965  ))));
966  }
967  } else {
968  // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
969  // the field name with ";" and check each value there as a TCA configured field)
970  $theFields = explode(';', $fieldName);
971  // Traverse fields, separated by ";" (displayed in a single cell).
972  foreach ($theFields as $fName2) {
973  if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
974  $out[$fieldName] .= '<strong>' . $this->getLanguageService()->sL(
975  $GLOBALS['TCA'][$table]['columns'][$fName2]['label'],
976  true
977  ) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
978  BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
979  25
980  )) . '<br />';
981  }
982  }
983  }
984  // If no value, add a nbsp.
985  if (!$out[$fieldName]) {
986  $out[$fieldName] = '&nbsp;';
987  }
988  // Wrap in dimmed-span tags if record is "disabled"
989  if ($this->isDisabled($table, $row)) {
990  $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
991  }
992  }
993  return $out;
994  }
995 
1005  public function headerFields($fieldArr, $table, $out = array())
1006  {
1007  foreach ($fieldArr as $fieldName) {
1008  $ll = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label'], true);
1009  $out[$fieldName] = $ll ? $ll : '&nbsp;';
1010  }
1011  return $out;
1012  }
1013 
1024  protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
1025  {
1026  $columns = array_map('intval', $columns);
1027  $contentRecordsPerColumn = array_fill_keys($columns, array());
1028 
1029  $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos IN (' . implode(',', $columns) . ')' . $additionalWhereClause);
1030  $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1031  // Traverse any selected elements and render their display code:
1032  $rowArr = $this->getResult($result);
1033 
1034  foreach ($rowArr as $record) {
1035  $columnValue = $record['colPos'];
1036  $contentRecordsPerColumn[$columnValue][] = $record;
1037  }
1038 
1039  return $contentRecordsPerColumn;
1040  }
1041 
1042  /**********************************
1043  *
1044  * Additional functions; Pages
1045  *
1046  **********************************/
1057  public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth)
1058  {
1059  $depth--;
1060  if ($depth >= 0) {
1061  $res = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'pid=' . (int)$pid . $qWhere, '', 'sorting');
1062  $c = 0;
1063  $rc = $this->getDatabase()->sql_num_rows($res);
1064  while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1065  BackendUtility::workspaceOL('pages', $row);
1066  if (is_array($row)) {
1067  $c++;
1068  $row['treeIcons'] = $treeIcons . '<span class="treeline-icon treeline-icon-join' . ($rc === $c ? 'bottom' : '') . '"></span>';
1069  $theRows[] = $row;
1070  // Get the branch
1071  $spaceOutIcons = '<span class="treeline-icon treeline-icon-' . ($rc === $c ? 'clear' : 'line') . '"></span>';
1072  $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1073  }
1074  }
1075  } else {
1076  $count = $this->getDatabase()->exec_SELECTcountRows('uid', 'pages', 'pid=' . (int)$pid . $qWhere);
1077  if ($count) {
1078  $this->plusPages[$pid] = $count;
1079  }
1080  }
1081  return $theRows;
1082  }
1083 
1091  public function pages_drawItem($row, $fieldArr)
1092  {
1093  // Initialization
1094  $theIcon = $this->getIcon('pages', $row);
1095  // Preparing and getting the data-array
1096  $theData = array();
1097  foreach ($fieldArr as $field) {
1098  switch ($field) {
1099  case 'title':
1100  $red = $this->plusPages[$row['uid']] ? '<span class="text-danger"><strong>+</strong></span>' : '';
1101  $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1102  if ($red) {
1103  $pTitle = '<a href="'
1104  . htmlspecialchars($this->script . ((strpos($this->script, '?') !== false) ? '&' : '?')
1105  . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1106  }
1107  $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1108  break;
1109  case 'php_tree_stop':
1110  // Intended fall through
1111  case 'TSconfig':
1112  $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1113  break;
1114  case 'uid':
1115  if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
1116  $params = '&edit[pages][' . $row['uid'] . ']=edit';
1117  $eI = '<a href="#" onclick="'
1118  . htmlspecialchars(BackendUtility::editOnClick($params))
1119  . '" title="' . $this->getLanguageService()->getLL('editThisPage', true) . '">'
1120  . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1121  } else {
1122  $eI = '';
1123  }
1124  $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1125  break;
1126  case 'shortcut':
1127  case 'shortcut_mode':
1128  if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1129  $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1130  }
1131  break;
1132  default:
1133  if (substr($field, 0, 6) == 'table_') {
1134  $f2 = substr($field, 6);
1135  if ($GLOBALS['TCA'][$f2]) {
1136  $c = $this->numberOfRecords($f2, $row['uid']);
1137  $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1138  }
1139  } else {
1140  $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1141  }
1142  }
1143  }
1144  $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1145  return $this->addElement(1, '', $theData);
1146  }
1147 
1156  protected function getPagesTableFieldValue($field, array $row)
1157  {
1158  return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1159  }
1160 
1161  /**********************************
1162  *
1163  * Additional functions; Content Elements
1164  *
1165  **********************************/
1175  public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = null)
1176  {
1177  $iconsArr = array();
1178  // Create command links:
1179  if ($this->tt_contentConfig['showCommands']) {
1180  // Edit whole of column:
1181  if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1182  $iconsArr['edit'] = '<a href="#" onclick="'
1183  . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1184  . $this->getLanguageService()->getLL('editColumn', true) . '">'
1185  . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1186  }
1187  if ($pasteParams) {
1188  $elFromTable = $this->clipboard->elFromTable('tt_content');
1189  if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1190  $iconsArr['paste'] = '<a href="'
1191  . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, true, $pasteParams))
1192  . '" onclick="' . htmlspecialchars(('return '
1193  . $this->clipboard->confirmMsg('pages', $this->pageRecord, 'into', $elFromTable, $colName)))
1194  . '" title="' . $this->getLanguageService()->getLL('pasteIntoColumn', true) . '">'
1195  . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
1196  }
1197  }
1198  }
1199  $icons = '';
1200  if (!empty($iconsArr)) {
1201  $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1202  }
1203  // Create header row:
1204  $out = '<div class="t3-page-column-header">
1205  ' . $icons . '
1206  <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1207  </div>';
1208  return $out;
1209  }
1210 
1218  protected function tt_content_drawFooter(array $row)
1219  {
1220  $content = '';
1221  // Get processed values:
1222  $info = array();
1223  $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1224 
1225  // Content element annotation
1226  if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1227  $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1228  }
1229 
1230  // Call drawFooter hooks
1231  $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1232  if (is_array($drawFooterHooks)) {
1233  foreach ($drawFooterHooks as $hookClass) {
1234  $hookObject = GeneralUtility::getUserObj($hookClass);
1235  if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1236  throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\View\\PageLayoutViewDrawFooterHookInterface', 1404378171);
1237  }
1238  $hookObject->preProcess($this, $info, $row);
1239  }
1240  }
1241 
1242  // Display info from records fields:
1243  if (!empty($info)) {
1244  $content = '<div class="t3-page-ce-info">
1245  ' . implode('<br>', $info) . '
1246  </div>';
1247  }
1248  // Wrap it
1249  if (!empty($content)) {
1250  $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1251  }
1252  return $content;
1253  }
1254 
1265  public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1266  {
1267  $out = '';
1268  // If show info is set...;
1269  if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1270  // Render control panel for the element:
1271  if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1272  // Edit content element:
1273  $params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
1274  $out .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
1275  $params,
1276  '',
1277  GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
1278  )) . '" title="' . htmlspecialchars($this->nextThree > 1
1279  ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1280  : $this->getLanguageService()->getLL('edit'))
1281  . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1282  // Hide element:
1283  $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1284  if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1285  && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1286  || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1287  ) {
1288  if ($row[$hiddenField]) {
1289  $value = 0;
1290  $label = 'unHide';
1291  } else {
1292  $value = 1;
1293  $label = 'hide';
1294  }
1295  $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1296  . '][' . $hiddenField . ']=' . $value;
1297  $out .= '<a class="btn btn-default" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1298  . '" title="' . $this->getLanguageService()->getLL($label, true) . '">'
1299  . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1300  }
1301  // Delete
1302  $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1303  $confirm = $this->getLanguageService()->getLL('deleteWarning')
1304  . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1305  . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')));
1306  $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params)) . '"'
1307  . ' data-severity="warning"'
1308  . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1309  . ' data-content="' . htmlspecialchars($confirm) . '" '
1310  . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
1311  . ' title="' . $this->getLanguageService()->getLL('deleteItem', true) . '">'
1312  . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1313  if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1314  $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1315  } else {
1316  $out = '';
1317  }
1318  if (!$disableMoveAndNewButtons) {
1319  $moveButtonContent = '';
1320  $displayMoveButtons = false;
1321  // Move element up:
1322  if ($this->tt_contentData['prev'][$row['uid']]) {
1323  $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1324  $moveButtonContent .= '<a class="btn btn-default" href="'
1325  . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1326  . '" title="' . $this->getLanguageService()->getLL('moveUp', true) . '">'
1327  . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1328  if (!$dragDropEnabled) {
1329  $displayMoveButtons = true;
1330  }
1331  } else {
1332  $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1333  }
1334  // Move element down:
1335  if ($this->tt_contentData['next'][$row['uid']]) {
1336  $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1337  $moveButtonContent .= '<a class="btn btn-default" href="'
1338  . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1339  . '" title="' . $this->getLanguageService()->getLL('moveDown', true) . '">'
1340  . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1341  if (!$dragDropEnabled) {
1342  $displayMoveButtons = true;
1343  }
1344  } else {
1345  $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1346  }
1347  if ($displayMoveButtons) {
1348  $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1349  }
1350  }
1351  }
1352  }
1353  $allowDragAndDrop = $this->isDragAndDropAllowed($row);
1354  $additionalIcons = array();
1355  if ($row['sys_language_uid'] > 0 && $this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid'])) {
1356  $disabledClickMenuItems = 'new,move';
1357  $allowDragAndDrop = false;
1358  }
1359  $additionalIcons[] = $this->getIcon('tt_content', $row, $disabledClickMenuItems) . ' ';
1360  $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
1361  // Get record locking status:
1362  if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1363  $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1364  . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1365  . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
1366  }
1367  // Call stats information hook
1368  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1369  $_params = array('tt_content', $row['uid'], &$row);
1370  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1371  $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1372  }
1373  }
1374  // Wrap the whole header
1375  // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1376  return '<div class="t3-page-ce-header ' . ($allowDragAndDrop ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
1377  <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
1378  <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' .$out . '</div>' : '') . '</div>
1379  </div>
1380  <div class="t3-page-ce-body">';
1381  }
1382 
1389  protected function isDragAndDropAllowed(array $row)
1390  {
1391  if ($this->getBackendUser()->user['admin']
1392  || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
1393  && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
1394  ) {
1395  return true;
1396  }
1397  return false;
1398  }
1399 
1407  public function tt_content_drawItem($row)
1408  {
1409  $out = '';
1410  $outHeader = '';
1411  // Make header:
1412 
1413  if ($row['header']) {
1414  $infoArr = array();
1415  $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1416  $hiddenHeaderNote = '';
1417  // If header layout is set to 'hidden', display an accordant note:
1418  if ($row['header_layout'] == 100) {
1419  $hiddenHeaderNote = ' <em>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden', true) . ']</em>';
1420  }
1421  $outHeader = $row['date']
1422  ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1423  : '';
1424  $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1425  . $hiddenHeaderNote . '</strong><br />';
1426  }
1427  // Make content:
1428  $infoArr = array();
1429  $drawItem = true;
1430  // Hook: Render an own preview of a record
1431  $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1432  if (is_array($drawItemHooks)) {
1433  foreach ($drawItemHooks as $hookClass) {
1434  $hookObject = GeneralUtility::getUserObj($hookClass);
1435  if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1436  throw new \UnexpectedValueException('$hookObject must implement interface ' . \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::class, 1218547409);
1437  }
1438  $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1439  }
1440  }
1441 
1442  // If the previous hook did not render something,
1443  // then check if a Fluid-based preview template was defined for this CType
1444  // and render it via Fluid. Possible option:
1445  // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
1446  if ($drawItem) {
1447  $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
1448  if (!empty($tsConfig['properties'][$row['CType']])) {
1449  $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
1450  $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
1451  if ($fluidTemplateFile) {
1452  try {
1454  $view = GeneralUtility::makeInstance(StandaloneView::class);
1455  $view->setTemplatePathAndFilename($fluidTemplateFile);
1456  $view->assignMultiple($row);
1457  if (!empty($row['pi_flexform'])) {
1459  $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
1460  $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
1461  }
1462  $out = $view->render();
1463  $drawItem = false;
1464  } catch (\Exception $e) {
1465  // Catch any exception to avoid breaking the view
1466  }
1467  }
1468  }
1469  }
1470 
1471  // Draw preview of the item depending on its CType (if not disabled by previous hook):
1472  if ($drawItem) {
1473  switch ($row['CType']) {
1474  case 'header':
1475  if ($row['subheader']) {
1476  $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1477  }
1478  break;
1479  case 'bullets':
1480  case 'table':
1481  if ($row['bodytext']) {
1482  $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1483  }
1484  break;
1485  case 'uploads':
1486  if ($row['media']) {
1487  $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
1488  }
1489  break;
1490  case 'menu':
1491  $contentType = $this->CType_labels[$row['CType']];
1492  $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1493  // Add Menu Type
1494  $menuTypeLabel = $this->getLanguageService()->sL(
1495  BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
1496  );
1497  $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
1498  $out .= $this->linkEditContent($menuTypeLabel, $row);
1499  if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
1500  // Show pages if menu type is not "Sitemap"
1501  $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
1502  }
1503  break;
1504  case 'shortcut':
1505  if (!empty($row['records'])) {
1506  $shortcutContent = array();
1507  $recordList = explode(',', $row['records']);
1508  foreach ($recordList as $recordIdentifier) {
1509  $split = BackendUtility::splitTable_Uid($recordIdentifier);
1510  $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1511  $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1512  if (is_array($shortcutRecord)) {
1513  $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
1515  $icon,
1516  $tableName,
1517  $shortcutRecord['uid'],
1518  1,
1519  '',
1520  '+copy,info,edit,view'
1521  );
1522  $shortcutContent[] = $icon
1523  . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1524  }
1525  }
1526  $out .= implode('<br />', $shortcutContent) . '<br />';
1527  }
1528  break;
1529  case 'list':
1530  $hookArr = array();
1531  $hookOut = '';
1532  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1533  $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1534  } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1535  $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1536  }
1537  if (!empty($hookArr)) {
1538  $_params = array('pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr);
1539  foreach ($hookArr as $_funcRef) {
1540  $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1541  }
1542  }
1543  if ((string)$hookOut !== '') {
1544  $out .= $hookOut;
1545  } elseif (!empty($row['list_type'])) {
1546  $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
1547  if (!empty($label)) {
1548  $out .= $this->linkEditContent('<strong>' . $this->getLanguageService()->sL($label, true) . '</strong>', $row) . '<br />';
1549  } else {
1550  $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1552  FlashMessage::class,
1553  htmlspecialchars($message),
1554  '',
1556  )->render();
1557  }
1558  } elseif (!empty($row['select_key'])) {
1559  $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), true)
1560  . ' ' . $row['select_key'] . '<br />';
1561  } else {
1562  $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1563  }
1564  $out .= $this->getLanguageService()->sL(
1565  BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages']),
1566  true
1567  ) . '<br />';
1568  break;
1569  default:
1570  $contentType = $this->CType_labels[$row['CType']];
1571 
1572  if (isset($contentType)) {
1573  $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1574  if ($row['bodytext']) {
1575  $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1576  }
1577  if ($row['image']) {
1578  $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
1579  }
1580  } else {
1581  $message = sprintf(
1582  $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1583  $row['CType']
1584  );
1586  FlashMessage::class,
1587  htmlspecialchars($message),
1588  '',
1590  )->render();
1591  }
1592  }
1593  }
1594  // Wrap span-tags:
1595  $out = '
1596  <span class="exampleContent">' . $out . '</span>';
1597  // Add header:
1598  $out = $outHeader . $out;
1599  // Return values:
1600  if ($this->isDisabled('tt_content', $row)) {
1601  return '<span class="text-muted">' . $out . '</span>';
1602  } else {
1603  return $out;
1604  }
1605  }
1606 
1613  protected function generateListForCTypeMenu(array $row)
1614  {
1615  $table = 'pages';
1616  $field = 'pages';
1617  // get categories instead of pages
1618  if (strpos($row['menu_type'], 'categorized_') !== false) {
1619  $table = 'sys_category';
1620  $field = 'selected_categories';
1621  }
1622  if (trim($row[$field]) === '') {
1623  return '';
1624  }
1625  $content = '';
1626  $uidList = explode(',', $row[$field]);
1627  foreach ($uidList as $uid) {
1628  $uid = (int)$uid;
1629  $record = BackendUtility::getRecord($table, $uid, 'title');
1630  $content .= '<br>' . $record['title'] . ' (' .$uid. ')';
1631  }
1632  return $content;
1633  }
1634 
1645  public function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP)
1646  {
1647  if ($lP && !empty($defLanguageCount)) {
1648  // Select all translations here:
1649  $where = 'sys_language_uid=' . intval($lP) . ' AND l18n_parent IN ('
1650  . implode(',', $defLanguageCount) . ')'
1651  . BackendUtility::deleteClause('tt_content');
1652  $rowArr = $this->getDatabase()->exec_SELECTgetRows('*', 'tt_content', $where);
1653 
1654  // Flip uids:
1655  $defLanguageCount = array_flip($defLanguageCount);
1656  // Traverse any selected elements and unset original UID if any:
1657  foreach ($rowArr as $row) {
1658  BackendUtility::workspaceOL('tt_content', $row);
1659  unset($defLanguageCount[$row['l18n_parent']]);
1660  }
1661  // Flip again:
1662  $defLanguageCount = array_keys($defLanguageCount);
1663  }
1664  return $defLanguageCount;
1665  }
1666 
1675  public function newLanguageButton($defLanguageCount, $lP, $colPos = 0)
1676  {
1677  $lP = (int)$lP;
1678  if (!$this->doEdit || !$lP) {
1679  return '';
1680  }
1681  $theNewButton = '';
1682 
1683  if (!empty($defLanguageCount)) {
1684  $theNewButton =
1685  '<input'
1686  . ' class="btn btn-default t3js-localize"'
1687  . ' type="button"'
1688  . ' disabled'
1689  . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate', true)) . '"'
1690  . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
1691  . ' data-table="tt_content"'
1692  . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
1693  . ' data-language-id="' . $lP . '"'
1694  . ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
1695  . ' data-colpos-id="' . $colPos . '"'
1696  . ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
1697  . '/>';
1698  }
1699 
1700  return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
1701  }
1702 
1712  public function newContentElementOnClick($id, $colPos, $sys_language)
1713  {
1714  if ($this->option_newWizard) {
1715  $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $id . '&colPos=' . $colPos
1716  . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
1717  . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
1718  } else {
1719  $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
1720  . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
1721  }
1722  return $onClick;
1723  }
1724 
1734  public function linkEditContent($str, $row)
1735  {
1736  $addButton = '';
1737  $onClick = '';
1738  if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1739  // Setting onclick action for content link:
1740  $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit');
1741  }
1742  // Return link
1743  return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick)
1744  . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">' . $str . '</a>' . $addButton : $str;
1745  }
1746 
1756  public function languageSelector($id)
1757  {
1758  if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
1759  // First, select all
1760  $res = $this->getPageLayoutController()->exec_languageQuery(0);
1761  $langSelItems = array();
1762  $langSelItems[0] = '
1763  <option value="0"></option>';
1764  while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1765  if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1766  $langSelItems[$row['uid']] = '
1767  <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
1768  }
1769  }
1770  // Then, subtract the languages which are already on the page:
1771  $res = $this->getPageLayoutController()->exec_languageQuery($id);
1772  while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1773  unset($langSelItems[$row['uid']]);
1774  }
1775  // Remove disallowed languages
1776  if (count($langSelItems) > 1
1777  && !$this->getBackendUser()->user['admin']
1778  && $this->getBackendUser()->groupData['allowed_languages'] !== ''
1779  ) {
1780  $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1781  if (!empty($allowed_languages)) {
1782  foreach ($langSelItems as $key => $value) {
1783  if (!isset($allowed_languages[$key]) && $key != 0) {
1784  unset($langSelItems[$key]);
1785  }
1786  }
1787  }
1788  }
1789  // Remove disabled languages
1791  $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1792  ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
1793  : array();
1794  if (!empty($langSelItems) && !empty($disableLanguages)) {
1795  foreach ($disableLanguages as $language) {
1796  if ($language != 0 && isset($langSelItems[$language])) {
1797  unset($langSelItems[$language]);
1798  }
1799  }
1800  }
1801  // If any languages are left, make selector:
1802  if (count($langSelItems) > 1) {
1803  $url = BackendUtility::getModuleUrl('record_edit', array(
1804  'edit[pages_language_overlay]['. $id . ']' => 'new',
1805  'overrideVals[pages_language_overlay][doktype]' => (int)$this->pageRecord['doktype'],
1806  'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1807  ));
1808  $onChangeContent = 'window.location.href=' . GeneralUtility::quoteJSvalue($url . '&overrideVals[pages_language_overlay][sys_language_uid]=') . '+this.options[this.selectedIndex].value';
1809  return '<div class="form-inline form-inline-spaced">'
1810  . '<div class="form-group">'
1811  . '<label for="createNewLanguage">'
1812  . $this->getLanguageService()->getLL('new_language', true)
1813  . '</label>'
1814  . '<select class="form-control input-sm" name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">'
1815  . implode('', $langSelItems)
1816  . '</select></div></div>';
1817  }
1818  }
1819  return '';
1820  }
1821 
1829  public function getResult($result, $table = 'tt_content')
1830  {
1831  $output = array();
1832  // Traverse the result:
1833  while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
1834  BackendUtility::workspaceOL($table, $row, -99, true);
1835  if ($row) {
1836  // Add the row to the array:
1837  $output[] = $row;
1838  }
1839  }
1840  $this->generateTtContentDataArray($output);
1841  // Return selected records
1842  return $output;
1843  }
1844 
1845  /********************************
1846  *
1847  * Various helper functions
1848  *
1849  ********************************/
1850 
1860  protected function initializeClipboard()
1861  {
1862  // Start clipboard
1863  $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
1864 
1865  // Initialize - reads the clipboard content from the user session
1866  $this->clipboard->initializeClipboard();
1867 
1868  // This locks the clipboard to the Normal for this request.
1869  $this->clipboard->lockToNormal();
1870 
1871  // Clean up pad
1872  $this->clipboard->cleanCurrent();
1873 
1874  // Save the clipboard content
1875  $this->clipboard->endClipboard();
1876  }
1877 
1884  protected function generateTtContentDataArray(array $rowArray)
1885  {
1886  if (empty($this->tt_contentData)) {
1887  $this->tt_contentData = array(
1888  'nextThree' => array(),
1889  'next' => array(),
1890  'prev' => array(),
1891  );
1892  }
1893  foreach ($rowArray as $key => $value) {
1894  // Create the list of the next three ids (for editing links...)
1895  for ($i = 0; $i < $this->nextThree; $i++) {
1896  if (isset($rowArray[$key - $i])
1897  && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
1898  ) {
1899  $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
1900  }
1901  }
1902 
1903  // Create information for next and previous content elements
1904  if (isset($rowArray[$key - 1])) {
1905  if (isset($rowArray[$key - 2])) {
1906  $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
1907  } else {
1908  $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
1909  }
1910  $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
1911  }
1912  }
1913  }
1914 
1922  public function numberOfRecords($table, $pid)
1923  {
1924  $count = 0;
1925  if ($GLOBALS['TCA'][$table]) {
1926  $where = 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table);
1927  $count = $this->getDatabase()->exec_SELECTcountRows('uid', $table, $where);
1928  }
1929  return (int)$count;
1930  }
1931 
1938  public function renderText($input)
1939  {
1940  $input = strip_tags($input);
1941  $input = GeneralUtility::fixed_lgd_cs($input, 1500);
1942  return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
1943  }
1944 
1953  public function getIcon($table, $row, $enabledClickMenuItems = '')
1954  {
1955  // Initialization
1956  $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
1957  $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
1958  $this->counter++;
1959  // The icon with link
1960  if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
1961  $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid'], true, '', $enabledClickMenuItems);
1962  }
1963  return $icon;
1964  }
1965 
1976  public function getProcessedValue($table, $fieldList, array $row, array &$info)
1977  {
1978  // Splitting values from $fieldList
1979  $fieldArr = explode(',', $fieldList);
1980  // Traverse fields from $fieldList
1981  foreach ($fieldArr as $field) {
1982  if ($row[$field]) {
1983  $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
1984  . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
1985  }
1986  }
1987  }
1988 
1996  public function isDisabled($table, $row)
1997  {
1998  $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
1999  return $enableCols['disabled'] && $row[$enableCols['disabled']]
2000  || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2001  || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2002  }
2003 
2012  public function noEditIcon($label = 'noEditItems')
2013  {
2014  $title = $this->getLanguageService()->getLL($label, true);
2015  return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2016  }
2017 
2025  protected function cleanTableNames()
2026  {
2027  // Get all table names:
2028  $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2029  // Unset common names:
2030  unset($tableNames['pages']);
2031  unset($tableNames['static_template']);
2032  unset($tableNames['sys_filemounts']);
2033  unset($tableNames['sys_action']);
2034  unset($tableNames['sys_workflows']);
2035  unset($tableNames['be_users']);
2036  unset($tableNames['be_groups']);
2037  $allowedTableNames = array();
2038  // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2039  if (is_array($tableNames)) {
2040  foreach ($tableNames as $k => $v) {
2041  if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
2042  $allowedTableNames['table_' . $k] = $k;
2043  }
2044  }
2045  }
2046  return $allowedTableNames;
2047  }
2048 
2049  /*****************************************
2050  *
2051  * External renderings
2052  *
2053  *****************************************/
2054 
2063  public function getTableMenu($id)
2064  {
2065  // Initialize:
2066  $this->activeTables = array();
2067  $theTables = array('tt_content');
2068  // External tables:
2069  if (is_array($this->externalTables)) {
2070  $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2071  }
2072  $out = '';
2073  // Traverse tables to check:
2074  foreach ($theTables as $tName) {
2075  // Check access and whether the proper extensions are loaded:
2076  if ($this->getBackendUser()->check('tables_select', $tName)
2077  && (isset($this->externalTables[$tName])
2078  || GeneralUtility::inList('fe_users,tt_content', $tName)
2079  || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2080  )
2081  ) {
2082  // Make query to count records from page:
2083  $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int)$id
2085  // If records were found (or if "tt_content" is the table...):
2086  if ($c || GeneralUtility::inList('tt_content', $tName)) {
2087  // Add row to menu:
2088  $out .= '
2089  <td><a href="#' . $tName . '" title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true) . '"></a>'
2090  . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render()
2091  . '</td>';
2092  // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2093  $title = $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true)
2094  . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', true);
2095  $this->activeTables[$tName] = '<span title="' . $title. '">'
2096  . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render()
2097  . '</span>'
2098  . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true);
2099  }
2100  }
2101  }
2102  // Wrap cells in table tags:
2103  $out = '
2104  <!--
2105  Menu of tables on the page (table menu)
2106  -->
2107  <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2108  <tr>' . $out . '
2109  </tr>
2110  </table>';
2111  // Return the content:
2112  return $out;
2113  }
2114 
2123  public function getThumbCodeUnlinked($row, $table, $field)
2124  {
2125  return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2126  }
2127 
2136  protected function checkIfTranslationsExistInLanguage(array $contentElements, $language)
2137  {
2138  // If in default language, you may always create new entries
2139  // Also, you may override this strict behavior via user TS Config
2140  // If you do so, you're on your own and cannot rely on any support by the TYPO3 core
2141  // We jump out here since we don't need to do the expensive loop operations
2142  $allowInconsistentLanguageHandling = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.allowInconsistentLanguageHandling');
2143  if ($language === 0 || $allowInconsistentLanguageHandling['value'] === '1') {
2144  return false;
2145  }
2149  if (!isset($this->languageHasTranslationsCache[$language])) {
2150  foreach ($contentElements as $columns) {
2151  foreach ($columns as $contentElement) {
2152  if ((int)$contentElement['l18n_parent'] === 0) {
2153  $this->languageHasTranslationsCache[$language]['hasStandAloneContent'] = true;
2154  }
2155  if ((int)$contentElement['l18n_parent'] > 0) {
2156  $this->languageHasTranslationsCache[$language]['hasTranslations'] = true;
2157  }
2158  }
2159  }
2160  // Check whether we have a mix of both
2161  if ($this->languageHasTranslationsCache[$language]['hasStandAloneContent']
2162  && $this->languageHasTranslationsCache[$language]['hasTranslations']
2163  ) {
2164  $message = GeneralUtility::makeInstance(
2165  FlashMessage::class,
2166  sprintf($this->getLanguageService()->getLL('staleTranslationWarning'), $this->languageIconTitles[$language]['title']),
2167  sprintf($this->getLanguageService()->getLL('staleTranslationWarningTitle'), $this->languageIconTitles[$language]['title']),
2169  );
2170  $service = GeneralUtility::makeInstance(FlashMessageService::class);
2171  $queue = $service->getMessageQueueByIdentifier();
2172  $queue->addMessage($message);
2173  }
2174  }
2175  if ($this->languageHasTranslationsCache[$language]['hasTranslations']) {
2176  return true;
2177  }
2178  return false;
2179  }
2180 
2184  protected function getBackendLayoutView()
2185  {
2186  return GeneralUtility::makeInstance(BackendLayoutView::class);
2187  }
2188 
2192  protected function getBackendUser()
2193  {
2194  return $GLOBALS['BE_USER'];
2195  }
2196 
2200  protected function getDatabase()
2201  {
2202  return $GLOBALS['TYPO3_DB'];
2203  }
2204 
2208  protected function getPageLayoutController()
2209  {
2210  return $GLOBALS['SOBE'];
2211  }
2212 }