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