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