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