[BUGFIX] Respect edit content permissions in Web->Page
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Controller\PageLayoutController;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Database\DatabaseConnection;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Messaging\FlashMessage;
24 use TYPO3\CMS\Core\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="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
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 $lPLabel = $this->getPageLayoutController()->getModuleTemplate()->wrapClickMenuOnIcon(
731 $this->iconFactory->getIconForRecord('pages_language_overlay', $lpRecord, Icon::SIZE_SMALL)->render(),
732 'pages_language_overlay',
733 $lpRecord['uid']
734 ) . $viewLink . ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
735 ? '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
736 . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
737 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'
738 : ''
739 ) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
740 } else {
741 $params = '&edit[pages][' . $this->id . ']=edit';
742 $lPLabel = $this->getPageLayoutController()->getModuleTemplate()->wrapClickMenuOnIcon(
743 $this->iconFactory->getIconForRecord('pages', $this->pageRecord, Icon::SIZE_SMALL)->render(),
744 'pages',
745 $this->id
746 ) . $viewLink . ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
747 ? '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
748 . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
749 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>'
750 : ''
751 ) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
752 }
753 $sCont[$lP] = '
754 <td nowrap="nowrap" class="t3-page-column t3-page-lang-label">' . $lPLabel . '</td>';
755 }
756 // Add headers:
757 $out .= '<tr>' . implode($cCont) . '</tr>';
758 $out .= '<tr>' . implode($sCont) . '</tr>';
759 unset($cCont, $sCont);
760
761 // Traverse previously built content for the columns:
762 foreach ($languageColumn as $cKey => $cCont) {
763 $out .= '<tr>';
764 foreach ($cCont as $languageId => $columnContent) {
765 $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>';
766 }
767 $out .= '</tr>';
768 if ($this->defLangBinding) {
769 // "defLangBinding" mode
770 foreach ($defLanguageCount[$cKey] as $defUid) {
771 $cCont = array();
772 foreach ($langListArr as $lP) {
773 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
774 $this->getNonTranslatedTTcontentUids(array($defUid), $id, $lP),
775 $lP,
776 $cKey
777 );
778 }
779 $out .= '
780 <tr>
781 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
782 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
783 </tr>';
784 }
785 }
786 }
787 // Finally, wrap it all in a table and add the language selector on top of it:
788 $out = $languageSelector . '
789 <div class="t3-grid-container">
790 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
791 ' . $out . '
792 </table>
793 </div>';
794 // CSH:
795 $out .= BackendUtility::cshItem($this->descrTable, 'language_list');
796 }
797
798 return $out;
799 }
800
801 /**********************************
802 *
803 * Generic listing of items
804 *
805 **********************************/
806 /**
807 * Creates a standard list of elements from a table.
808 *
809 * @param string $table Table name
810 * @param int $id Page id.
811 * @param string $fList Comma list of fields to display
812 * @param bool $icon If TRUE, icon is shown
813 * @param string $addWhere Additional WHERE-clauses.
814 * @return string HTML table
815 */
816 public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
817 {
818 // Initialize
819 $queryParts = $this->makeQueryArray($table, $id, $addWhere);
820 $this->setTotalItems($queryParts);
821 $dbCount = 0;
822 $result = false;
823 // Make query for records if there were any records found in the count operation
824 if ($this->totalItems) {
825 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
826 // Will return FALSE, if $result is invalid
827 $dbCount = $this->getDatabase()->sql_num_rows($result);
828 }
829 // If records were found, render the list
830 if (!$dbCount) {
831 return '';
832 }
833 // Set fields
834 $out = '';
835 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
836 $theData = array();
837 $theData = $this->headerFields($this->fieldArray, $table, $theData);
838 // Title row
839 $localizedTableTitle = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'], true);
840 $out .= '<tr class="t3-row-header">' . '<th class="col-icon"></th>'
841 . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
842 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
843 . '</tr>';
844 // Column's titles
845 if ($this->doEdit) {
846 $onClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $this->id . ']=new');
847 $theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" '
848 . 'title="' . $this->getLanguageService()->getLL('new', true) . '">'
849 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
850 }
851 $out .= $this->addelement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
852 // Render Items
853 $this->eCounter = $this->firstElementNumber;
854 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
855 BackendUtility::workspaceOL($table, $row);
856 if (is_array($row)) {
857 list($flag, $code) = $this->fwd_rwd_nav();
858 $out .= $code;
859 if ($flag) {
860 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
861 $Nrow = array();
862 // Setting icons links
863 if ($icon) {
864 $Nrow['__cmds__'] = $this->getIcon($table, $row);
865 }
866 // Get values:
867 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
868 // Attach edit icon
869 if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
870 $Nrow['__editIconLink__'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
871 . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
872 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
873 } else {
874 $Nrow['__editIconLink__'] = $this->noEditIcon();
875 }
876 $out .= $this->addelement(1, '', $Nrow);
877 }
878 $this->eCounter++;
879 }
880 }
881 $this->getDatabase()->sql_free_result($result);
882 // Wrap it all in a table:
883 $out = '
884 <!--
885 Standard list of table "' . $table . '"
886 -->
887 <div class="table-fit"><table class="table table-striped">
888 ' . $out . '
889 </table></div>';
890 return $out;
891 }
892
893 /**
894 * Adds content to all data fields in $out array
895 *
896 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
897 * Eg. "field1,field2;field3".
898 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
899 *
900 * @param array $fieldArr Array of fields to display
901 * @param string $table Table name
902 * @param array $row Record array
903 * @param array $out Array to which the data is added
904 * @return array $out array returned after processing.
905 * @see makeOrdinaryList()
906 */
907 public function dataFields($fieldArr, $table, $row, $out = array())
908 {
909 // Check table validity
910 if (!isset($GLOBALS['TCA'][$table])) {
911 return $out;
912 }
913
914 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
915 // Traverse fields
916 foreach ($fieldArr as $fieldName) {
917 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
918 // Each field has its own cell (if configured in TCA)
919 // If the column is a thumbnail column:
920 if ($fieldName == $thumbsCol) {
921 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
922 } else {
923 // ... otherwise just render the output:
924 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
925 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
926 250
927 ))));
928 }
929 } else {
930 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
931 // the field name with ";" and check each value there as a TCA configured field)
932 $theFields = explode(';', $fieldName);
933 // Traverse fields, separated by ";" (displayed in a single cell).
934 foreach ($theFields as $fName2) {
935 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
936 $out[$fieldName] .= '<strong>' . $this->getLanguageService()->sL(
937 $GLOBALS['TCA'][$table]['columns'][$fName2]['label'],
938 true
939 ) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
940 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
941 25
942 )) . '<br />';
943 }
944 }
945 }
946 // If no value, add a nbsp.
947 if (!$out[$fieldName]) {
948 $out[$fieldName] = '&nbsp;';
949 }
950 // Wrap in dimmed-span tags if record is "disabled"
951 if ($this->isDisabled($table, $row)) {
952 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
953 }
954 }
955 return $out;
956 }
957
958 /**
959 * Header fields made for the listing of records
960 *
961 * @param array $fieldArr Field names
962 * @param string $table The table name
963 * @param array $out Array to which the headers are added.
964 * @return array $out returned after addition of the header fields.
965 * @see makeOrdinaryList()
966 */
967 public function headerFields($fieldArr, $table, $out = array())
968 {
969 foreach ($fieldArr as $fieldName) {
970 $ll = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label'], true);
971 $out[$fieldName] = $ll ? $ll : '&nbsp;';
972 }
973 return $out;
974 }
975
976 /**
977 * Gets content records per column.
978 * This is required for correct workspace overlays.
979 *
980 * @param string $table UNUSED (will always be queried from tt_content)
981 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
982 * @param array $columns colPos values to be considered to be shown
983 * @param string $additionalWhereClause Additional where clause for database select
984 * @return array Associative array for each column (colPos)
985 */
986 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
987 {
988 $columns = array_map('intval', $columns);
989 $contentRecordsPerColumn = array_fill_keys($columns, array());
990
991 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos IN (' . implode(',', $columns) . ')' . $additionalWhereClause);
992 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
993 // Traverse any selected elements and render their display code:
994 $rowArr = $this->getResult($result);
995
996 foreach ($rowArr as $record) {
997 $columnValue = $record['colPos'];
998 $contentRecordsPerColumn[$columnValue][] = $record;
999 }
1000
1001 return $contentRecordsPerColumn;
1002 }
1003
1004 /**********************************
1005 *
1006 * Additional functions; Pages
1007 *
1008 **********************************/
1009 /**
1010 * Adds pages-rows to an array, selecting recursively in the page tree.
1011 *
1012 * @param array $theRows Array which will accumulate page rows
1013 * @param int $pid Pid to select from
1014 * @param string $qWhere Query-where clause
1015 * @param string $treeIcons Prefixed icon code.
1016 * @param int $depth Depth (decreasing)
1017 * @return array $theRows, but with added rows.
1018 */
1019 public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth)
1020 {
1021 $depth--;
1022 if ($depth >= 0) {
1023 $res = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'pid=' . (int)$pid . $qWhere, '', 'sorting');
1024 $c = 0;
1025 $rc = $this->getDatabase()->sql_num_rows($res);
1026 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1027 BackendUtility::workspaceOL('pages', $row);
1028 if (is_array($row)) {
1029 $c++;
1030 $row['treeIcons'] = $treeIcons . '<span class="treeline-icon treeline-icon-join' . ($rc === $c ? 'bottom' : '') . '"></span>';
1031 $theRows[] = $row;
1032 // Get the branch
1033 $spaceOutIcons = '<span class="treeline-icon treeline-icon-' . ($rc === $c ? 'clear' : 'line') . '"></span>';
1034 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1035 }
1036 }
1037 } else {
1038 $count = $this->getDatabase()->exec_SELECTcountRows('uid', 'pages', 'pid=' . (int)$pid . $qWhere);
1039 if ($count) {
1040 $this->plusPages[$pid] = $count;
1041 }
1042 }
1043 return $theRows;
1044 }
1045
1046 /**
1047 * Adds a list item for the pages-rendering
1048 *
1049 * @param array $row Record array
1050 * @param array $fieldArr Field list
1051 * @return string HTML for the item
1052 */
1053 public function pages_drawItem($row, $fieldArr)
1054 {
1055 // Initialization
1056 $theIcon = $this->getIcon('pages', $row);
1057 // Preparing and getting the data-array
1058 $theData = array();
1059 foreach ($fieldArr as $field) {
1060 switch ($field) {
1061 case 'title':
1062 $red = $this->plusPages[$row['uid']] ? '<span class="text-danger"><strong>+</strong></span>' : '';
1063 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1064 if ($red) {
1065 $pTitle = '<a href="'
1066 . htmlspecialchars($this->script . ((strpos($this->script, '?') !== false) ? '&' : '?')
1067 . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1068 }
1069 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1070 break;
1071 case 'php_tree_stop':
1072 // Intended fall through
1073 case 'TSconfig':
1074 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1075 break;
1076 case 'uid':
1077 if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
1078 $params = '&edit[pages][' . $row['uid'] . ']=edit';
1079 $eI = '<a href="#" onclick="'
1080 . htmlspecialchars(BackendUtility::editOnClick($params))
1081 . '" title="' . $this->getLanguageService()->getLL('editThisPage', true) . '">'
1082 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1083 } else {
1084 $eI = '';
1085 }
1086 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1087 break;
1088 case 'shortcut':
1089 case 'shortcut_mode':
1090 if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1091 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1092 }
1093 break;
1094 default:
1095 if (substr($field, 0, 6) == 'table_') {
1096 $f2 = substr($field, 6);
1097 if ($GLOBALS['TCA'][$f2]) {
1098 $c = $this->numberOfRecords($f2, $row['uid']);
1099 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1100 }
1101 } else {
1102 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1103 }
1104 }
1105 }
1106 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1107 return $this->addelement(1, '', $theData);
1108 }
1109
1110 /**
1111 * Returns the HTML code for rendering a field in the pages table.
1112 * The row value is processed to a human readable form and the result is parsed through htmlspecialchars().
1113 *
1114 * @param string $field The name of the field of which the value should be rendered.
1115 * @param array $row The pages table row as an associative array.
1116 * @return string The rendered table field value.
1117 */
1118 protected function getPagesTableFieldValue($field, array $row)
1119 {
1120 return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1121 }
1122
1123 /**********************************
1124 *
1125 * Additional functions; Content Elements
1126 *
1127 **********************************/
1128 /**
1129 * Draw header for a content element column:
1130 *
1131 * @param string $colName Column name
1132 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1133 * @param string $newParams New element params (Syntax: &edit[...] for FormEngine) OBSOLETE
1134 * @param array|NULL $pasteParams Paste element params (i.e. array(colPos => 1, sys_language_uid => 2))
1135 * @return string HTML table
1136 */
1137 public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = null)
1138 {
1139 $iconsArr = array();
1140 // Create command links:
1141 if ($this->tt_contentConfig['showCommands']) {
1142 // Edit whole of column:
1143 if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1144 $iconsArr['edit'] = '<a href="#" onclick="'
1145 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1146 . $this->getLanguageService()->getLL('editColumn', true) . '">'
1147 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1148 }
1149 if ($pasteParams) {
1150 $elFromTable = $this->clipboard->elFromTable('tt_content');
1151 if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1152 $iconsArr['paste'] = '<a href="'
1153 . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, true, $pasteParams))
1154 . '" onclick="' . htmlspecialchars(('return '
1155 . $this->clipboard->confirmMsg('pages', $this->pageRecord, 'into', $elFromTable, $colName)))
1156 . '" title="' . $this->getLanguageService()->getLL('pasteIntoColumn', true) . '">'
1157 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
1158 }
1159 }
1160 }
1161 $icons = '';
1162 if (!empty($iconsArr)) {
1163 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1164 }
1165 // Create header row:
1166 $out = '<div class="t3-page-column-header">
1167 ' . $icons . '
1168 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1169 </div>';
1170 return $out;
1171 }
1172
1173 /**
1174 * Draw the footer for a single tt_content element
1175 *
1176 * @param array $row Record array
1177 * @return string HTML of the footer
1178 * @throws \UnexpectedValueException
1179 */
1180 protected function tt_content_drawFooter(array $row)
1181 {
1182 $content = '';
1183 // Get processed values:
1184 $info = array();
1185 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1186
1187 // Content element annotation
1188 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1189 $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1190 }
1191
1192 // Call drawFooter hooks
1193 $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1194 if (is_array($drawFooterHooks)) {
1195 foreach ($drawFooterHooks as $hookClass) {
1196 $hookObject = GeneralUtility::getUserObj($hookClass);
1197 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1198 throw new \UnexpectedValueException('$hookObject must implement interface TYPO3\\CMS\\Backend\\View\\PageLayoutViewDrawFooterHookInterface', 1404378171);
1199 }
1200 $hookObject->preProcess($this, $info, $row);
1201 }
1202 }
1203
1204 // Display info from records fields:
1205 if (!empty($info)) {
1206 $content = '<div class="t3-page-ce-info">
1207 ' . implode('<br>', $info) . '
1208 </div>';
1209 }
1210 // Wrap it
1211 if (!empty($content)) {
1212 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1213 }
1214 return $content;
1215 }
1216
1217 /**
1218 * Draw the header for a single tt_content element
1219 *
1220 * @param array $row Record array
1221 * @param int $space Amount of pixel space above the header. UNUSED
1222 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1223 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1224 * @param bool $dragDropEnabled If set the move button must be hidden
1225 * @return string HTML table with the record header.
1226 */
1227 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1228 {
1229 $out = '';
1230 // If show info is set...;
1231 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1232 // Render control panel for the element:
1233 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1234 // Edit content element:
1235 $params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
1236 $out .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
1237 $params,
1238 '',
1239 GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
1240 )) . '" title="' . htmlspecialchars($this->nextThree > 1
1241 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1242 : $this->getLanguageService()->getLL('edit'))
1243 . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1244 // Hide element:
1245 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1246 if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1247 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1248 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1249 ) {
1250 if ($row[$hiddenField]) {
1251 $value = 0;
1252 $label = 'unHide';
1253 } else {
1254 $value = 1;
1255 $label = 'hide';
1256 }
1257 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1258 . '][' . $hiddenField . ']=' . $value;
1259 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($this->getPageLayoutController()->getModuleTemplate()->issueCommand($params))
1260 . '" title="' . $this->getLanguageService()->getLL($label, true) . '">'
1261 . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1262 }
1263 // Delete
1264 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1265 $confirm = $this->getLanguageService()->getLL('deleteWarning')
1266 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1267 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')));
1268 $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars($this->getPageLayoutController()->getModuleTemplate()->issueCommand($params)) . '"'
1269 . ' data-severity="warning"'
1270 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1271 . ' data-content="' . htmlspecialchars($confirm) . '" '
1272 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
1273 . ' title="' . $this->getLanguageService()->getLL('deleteItem', true) . '">'
1274 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1275 if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1276 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1277 } else {
1278 $out = '';
1279 }
1280 if (!$disableMoveAndNewButtons) {
1281 $moveButtonContent = '';
1282 $displayMoveButtons = false;
1283 // Move element up:
1284 if ($this->tt_contentData['prev'][$row['uid']]) {
1285 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1286 $moveButtonContent .= '<a class="btn btn-default" href="'
1287 . htmlspecialchars($this->getPageLayoutController()->getModuleTemplate()->issueCommand($params))
1288 . '" title="' . $this->getLanguageService()->getLL('moveUp', true) . '">'
1289 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1290 if (!$dragDropEnabled) {
1291 $displayMoveButtons = true;
1292 }
1293 } else {
1294 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1295 }
1296 // Move element down:
1297 if ($this->tt_contentData['next'][$row['uid']]) {
1298 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1299 $moveButtonContent .= '<a class="btn btn-default" href="'
1300 . htmlspecialchars($this->getPageLayoutController()->getModuleTemplate()->issueCommand($params))
1301 . '" title="' . $this->getLanguageService()->getLL('moveDown', true) . '">'
1302 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1303 if (!$dragDropEnabled) {
1304 $displayMoveButtons = true;
1305 }
1306 } else {
1307 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1308 }
1309 if ($displayMoveButtons) {
1310 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1311 }
1312 }
1313 }
1314 }
1315 $additionalIcons = array();
1316 $additionalIcons[] = $this->getIcon('tt_content', $row) . ' ';
1317 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
1318 // Get record locking status:
1319 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1320 $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1321 . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1322 . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
1323 }
1324 // Call stats information hook
1325 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1326 $_params = array('tt_content', $row['uid'], &$row);
1327 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1328 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1329 }
1330 }
1331 // Wrap the whole header
1332 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1333 return '<div class="t3-page-ce-header ' . ($this->isDragAndDropAllowed($row) ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
1334 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
1335 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' .$out . '</div>' : '') . '</div>
1336 </div>
1337 <div class="t3-page-ce-body">';
1338 }
1339
1340 /**
1341 * Determine whether Drag & Drop should be allowed
1342 *
1343 * @param array $row
1344 * @return bool
1345 */
1346 protected function isDragAndDropAllowed(array $row)
1347 {
1348 if ($this->getBackendUser()->user['admin']
1349 || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
1350 && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
1351 ) {
1352 return true;
1353 }
1354 return false;
1355 }
1356
1357 /**
1358 * Draws the preview content for a content element
1359 *
1360 * @param array $row Content element
1361 * @return string HTML
1362 * @throws \UnexpectedValueException
1363 */
1364 public function tt_content_drawItem($row)
1365 {
1366 $out = '';
1367 $outHeader = '';
1368 // Make header:
1369
1370 if ($row['header']) {
1371 $infoArr = array();
1372 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1373 $hiddenHeaderNote = '';
1374 // If header layout is set to 'hidden', display an accordant note:
1375 if ($row['header_layout'] == 100) {
1376 $hiddenHeaderNote = ' <em>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden', true) . ']</em>';
1377 }
1378 $outHeader = $row['date']
1379 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1380 : '';
1381 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1382 . $hiddenHeaderNote . '</strong><br />';
1383 }
1384 // Make content:
1385 $infoArr = array();
1386 $drawItem = true;
1387 // Hook: Render an own preview of a record
1388 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1389 if (is_array($drawItemHooks)) {
1390 foreach ($drawItemHooks as $hookClass) {
1391 $hookObject = GeneralUtility::getUserObj($hookClass);
1392 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1393 throw new \UnexpectedValueException('$hookObject must implement interface ' . \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface::class, 1218547409);
1394 }
1395 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1396 }
1397 }
1398
1399 // If the previous hook did not render something,
1400 // then check if a Fluid-based preview template was defined for this CType
1401 // and render it via Fluid. Possible option:
1402 // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
1403 if ($drawItem) {
1404 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
1405 if (!empty($tsConfig['properties'][$row['CType']])) {
1406 $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
1407 $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
1408 if ($fluidTemplateFile) {
1409 try {
1410 /** @var StandaloneView $view */
1411 $view = GeneralUtility::makeInstance(StandaloneView::class);
1412 $view->setTemplatePathAndFilename($fluidTemplateFile);
1413 $view->assignMultiple($row);
1414 if (!empty($row['pi_flexform'])) {
1415 /** @var FlexFormService $flexFormService */
1416 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
1417 $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
1418 }
1419 $out = $view->render();
1420 $drawItem = false;
1421 } catch (\Exception $e) {
1422 // Catch any exception to avoid breaking the view
1423 }
1424 }
1425 }
1426 }
1427
1428 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1429 if ($drawItem) {
1430 switch ($row['CType']) {
1431 case 'header':
1432 if ($row['subheader']) {
1433 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1434 }
1435 break;
1436 case 'bullets':
1437 case 'table':
1438 if ($row['bodytext']) {
1439 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1440 }
1441 break;
1442 case 'uploads':
1443 if ($row['media']) {
1444 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
1445 }
1446 break;
1447 case 'menu':
1448 $contentType = $this->CType_labels[$row['CType']];
1449 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1450 // Add Menu Type
1451 $menuTypeLabel = $this->getLanguageService()->sL(
1452 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
1453 );
1454 $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
1455 $out .= $this->linkEditContent($menuTypeLabel, $row);
1456 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
1457 // Show pages if menu type is not "Sitemap"
1458 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
1459 }
1460 break;
1461 case 'shortcut':
1462 if (!empty($row['records'])) {
1463 $shortcutContent = array();
1464 $recordList = explode(',', $row['records']);
1465 foreach ($recordList as $recordIdentifier) {
1466 $split = BackendUtility::splitTable_Uid($recordIdentifier);
1467 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1468 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1469 if (is_array($shortcutRecord)) {
1470 $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
1471 $icon = $this->getPageLayoutController()->getModuleTemplate()->wrapClickMenuOnIcon(
1472 $icon,
1473 $tableName,
1474 $shortcutRecord['uid'],
1475 1,
1476 '',
1477 '+copy,info,edit,view'
1478 );
1479 $shortcutContent[] = $icon
1480 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1481 }
1482 }
1483 $out .= implode('<br />', $shortcutContent) . '<br />';
1484 }
1485 break;
1486 case 'list':
1487 $hookArr = array();
1488 $hookOut = '';
1489 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1490 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1491 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1492 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1493 }
1494 if (!empty($hookArr)) {
1495 $_params = array('pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr);
1496 foreach ($hookArr as $_funcRef) {
1497 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1498 }
1499 }
1500 if ((string)$hookOut !== '') {
1501 $out .= $hookOut;
1502 } elseif (!empty($row['list_type'])) {
1503 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
1504 if (!empty($label)) {
1505 $out .= $this->linkEditContent('<strong>' . $this->getLanguageService()->sL($label, true) . '</strong>', $row) . '<br />';
1506 } else {
1507 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1508 $out .= GeneralUtility::makeInstance(
1509 FlashMessage::class,
1510 htmlspecialchars($message),
1511 '',
1512 FlashMessage::WARNING
1513 )->render();
1514 }
1515 } elseif (!empty($row['select_key'])) {
1516 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), true)
1517 . ' ' . $row['select_key'] . '<br />';
1518 } else {
1519 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1520 }
1521 $out .= $this->getLanguageService()->sL(
1522 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages']),
1523 true
1524 ) . '<br />';
1525 break;
1526 default:
1527 $contentType = $this->CType_labels[$row['CType']];
1528
1529 if (isset($contentType)) {
1530 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1531 if ($row['bodytext']) {
1532 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1533 }
1534 if ($row['image']) {
1535 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
1536 }
1537 } else {
1538 $message = sprintf(
1539 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1540 $row['CType']
1541 );
1542 $out .= GeneralUtility::makeInstance(
1543 FlashMessage::class,
1544 htmlspecialchars($message),
1545 '',
1546 FlashMessage::WARNING
1547 )->render();
1548 }
1549 }
1550 }
1551 // Wrap span-tags:
1552 $out = '
1553 <span class="exampleContent">' . $out . '</span>';
1554 // Add header:
1555 $out = $outHeader . $out;
1556 // Return values:
1557 if ($this->isDisabled('tt_content', $row)) {
1558 return '<span class="text-muted">' . $out . '</span>';
1559 } else {
1560 return $out;
1561 }
1562 }
1563
1564 /**
1565 * Generates a list of selected pages or categories for the CType menu
1566 *
1567 * @param array $row row from pages
1568 * @return string
1569 */
1570 protected function generateListForCTypeMenu(array $row)
1571 {
1572 $table = 'pages';
1573 $field = 'pages';
1574 // get categories instead of pages
1575 if (strpos($row['menu_type'], 'categorized_') !== false) {
1576 $table = 'sys_category';
1577 $field = 'selected_categories';
1578 }
1579 if (trim($row[$field]) === '') {
1580 return '';
1581 }
1582 $content = '';
1583 $uidList = explode(',', $row[$field]);
1584 foreach ($uidList as $uid) {
1585 $uid = (int)$uid;
1586 $record = BackendUtility::getRecord($table, $uid, 'title');
1587 $content .= '<br>' . $record['title'] . ' (' .$uid. ')';
1588 }
1589 return $content;
1590 }
1591
1592 /**
1593 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1594 * Selects across columns, but within in the same PID. Columns are expect to be the same
1595 * for translations and original but this may be a conceptual error (?)
1596 *
1597 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1598 * @param int $id Page pid
1599 * @param int $lP Sys language UID
1600 * @return array Modified $defLanguageCount
1601 */
1602 public function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP)
1603 {
1604 if ($lP && !empty($defLanguageCount)) {
1605 // Select all translations here:
1606 $where = 'sys_language_uid=' . intval($lP) . ' AND l18n_parent IN ('
1607 . implode(',', $defLanguageCount) . ')'
1608 . BackendUtility::deleteClause('tt_content');
1609 $rowArr = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tt_content', $where);
1610
1611 // Flip uids:
1612 $defLanguageCount = array_flip($defLanguageCount);
1613 // Traverse any selected elements and unset original UID if any:
1614 foreach ($rowArr as $row) {
1615 BackendUtility::workspaceOL('tt_content', $row);
1616 unset($defLanguageCount[$row['l18n_parent']]);
1617 }
1618 // Flip again:
1619 $defLanguageCount = array_keys($defLanguageCount);
1620 }
1621 return $defLanguageCount;
1622 }
1623
1624 /**
1625 * Creates button which is used to create copies of records..
1626 *
1627 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1628 * @param int $lP Sys language UID
1629 * @param int $colPos Column position
1630 * @return string "Copy languages" button, if available.
1631 */
1632 public function newLanguageButton($defLanguageCount, $lP, $colPos = 0)
1633 {
1634 if (!$this->doEdit || !$lP) {
1635 return '';
1636 }
1637
1638 $copyFromLanguageMenu = '';
1639 foreach ($this->getLanguagesToCopyFrom(GeneralUtility::_GP('id'), $lP, $colPos) as $languageId => $label) {
1640 $elementsInColumn = $languageId === 0 ? $defLanguageCount : $this->getElementsFromColumnAndLanguage(GeneralUtility::_GP('id'), $colPos, $languageId);
1641 if (!empty($elementsInColumn)) {
1642 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue($this->getPageLayoutController()->getModuleTemplate()->issueCommand('&cmd[tt_content][' . implode(',', $elementsInColumn) . '][copyFromLanguage]=' . GeneralUtility::_GP('id') . ',' . $lP)) . '; return false;';
1643 $copyFromLanguageMenu .= '<li><a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $this->languageFlag($languageId, false) . ' ' . htmlspecialchars($label) . '</a></li>' . LF;
1644 }
1645 }
1646 if ($copyFromLanguageMenu !== '') {
1647 $copyFromLanguageMenu =
1648 '<ul class="dropdown-menu">'
1649 . $copyFromLanguageMenu
1650 . '</ul>';
1651 }
1652
1653 if (!empty($defLanguageCount)) {
1654 $params = '';
1655 foreach ($defLanguageCount as $uidVal) {
1656 $params .= '&cmd[tt_content][' . $uidVal . '][localize]=' . $lP;
1657 }
1658
1659 // We have content in the default language, create a split button
1660 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue($this->getPageLayoutController()->getModuleTemplate()->issueCommand($params)) . '; return false;';
1661 $theNewButton =
1662 '<div class="btn-group">
1663 <input
1664 class="btn btn-default"
1665 type="submit" onclick="' . htmlspecialchars($onClick) . '; return false;"
1666 value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_copyForLang', true) . ' [' . count($defLanguageCount) . ']') . '"
1667 />';
1668 if ($copyFromLanguageMenu !== '' && $this->isColumnEmpty($colPos, $lP)) {
1669 $theNewButton .= '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
1670 . '<span class="caret"></span>'
1671 . '<span class="sr-only">Toggle Dropdown</span>'
1672 . '</button>'
1673 . $copyFromLanguageMenu;
1674 }
1675 $theNewButton .= '</div>';
1676 } else {
1677 if ($copyFromLanguageMenu !== '' && $this->isColumnEmpty($colPos, $lP)) {
1678 $theNewButton =
1679 '<div class="btn-group">'
1680 . '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
1681 . $this->getLanguageService()->getLL('newPageContent_copyFromAnotherLang_button', true) . ' <span class="caret"></span>'
1682 . '</button>'
1683 . $copyFromLanguageMenu
1684 . '</div>';
1685 } else {
1686 $theNewButton = '';
1687 }
1688 }
1689
1690 return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
1691 }
1692
1693 /**
1694 * Creates onclick-attribute content for a new content element
1695 *
1696 * @param int $id Page id where to create the element.
1697 * @param int $colPos Preset: Column position value
1698 * @param int $sys_language Preset: Sys langauge value
1699 * @return string String for onclick attribute.
1700 * @see getTable_tt_content()
1701 */
1702 public function newContentElementOnClick($id, $colPos, $sys_language)
1703 {
1704 if ($this->option_newWizard) {
1705 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $id . '&colPos=' . $colPos
1706 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
1707 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
1708 } else {
1709 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
1710 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
1711 }
1712 return $onClick;
1713 }
1714
1715 /**
1716 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
1717 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
1718 *
1719 * @param string $str String to link. Must be prepared for HTML output.
1720 * @param array $row The row.
1721 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
1722 * @see getTable_tt_content()
1723 */
1724 public function linkEditContent($str, $row)
1725 {
1726 $addButton = '';
1727 $onClick = '';
1728 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1729 // Setting onclick action for content link:
1730 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit');
1731 }
1732 // Return link
1733 return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick)
1734 . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">' . $str . '</a>' . $addButton : $str;
1735 }
1736
1737 /**
1738 * Get available languages for a page
1739 *
1740 * @param int $pageId
1741 * @return array
1742 */
1743 protected function getAvailableLanguages($pageId)
1744 {
1745 // First, select all
1746 $res = $this->getPageLayoutController()->exec_languageQuery(0);
1747 $langSelItems = array();
1748 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1749 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1750 $langSelItems[$row['uid']] = $row['title'];
1751 }
1752 }
1753 $this->getDatabase()->sql_free_result($res);
1754
1755 // Remove disallowed languages
1756 if (count($langSelItems) > 1
1757 && !$this->getBackendUser()->user['admin']
1758 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
1759 ) {
1760 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1761 if (!empty($allowed_languages)) {
1762 foreach ($langSelItems as $key => $value) {
1763 if (!isset($allowed_languages[$key]) && $key != 0) {
1764 unset($langSelItems[$key]);
1765 }
1766 }
1767 }
1768 }
1769 // Remove disabled languages
1770 $modSharedTSconfig = BackendUtility::getModTSconfig($pageId, 'mod.SHARED');
1771 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1772 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
1773 : array();
1774 if (!empty($langSelItems) && !empty($disableLanguages)) {
1775 foreach ($disableLanguages as $language) {
1776 if ($language != 0 && isset($langSelItems[$language])) {
1777 unset($langSelItems[$language]);
1778 }
1779 }
1780 }
1781
1782 return $langSelItems;
1783 }
1784
1785 /**
1786 * Get available languages for copying into another language
1787 *
1788 * @param int $pageId
1789 * @param int $excludeLanguage
1790 * @param int $colPos
1791 * @return array
1792 */
1793 protected function getLanguagesToCopyFrom($pageId, $excludeLanguage = null, $colPos = 0)
1794 {
1795 $langSelItems = array();
1796 if (!$this->isColumnEmpty($colPos, 0)) {
1797 $langSelItems[0] = $this->getLanguageService()->getLL('newPageContent_translateFromDefault', true);
1798 }
1799
1800 $languages = $this->getUsedLanguagesInPageAndColumn($pageId, $colPos);
1801 foreach ($languages as $uid => $language) {
1802 $langSelItems[$uid] = sprintf($this->getLanguageService()->getLL('newPageContent_copyFromAnotherLang'), htmlspecialchars($language['title']));
1803 }
1804
1805 if (isset($langSelItems[$excludeLanguage])) {
1806 unset($langSelItems[$excludeLanguage]);
1807 }
1808
1809 return $langSelItems;
1810 }
1811
1812 /**
1813 * Get used languages in a colPos of a page
1814 *
1815 * @param int $pageId
1816 * @param int $colPos
1817 * @return bool|\mysqli_result|object
1818 */
1819 protected function getUsedLanguagesInPageAndColumn($pageId, $colPos)
1820 {
1821 if (!isset($this->languagesInColumnCache[$pageId])) {
1822 $this->languagesInColumnCache[$pageId] = array();
1823 }
1824 if (!isset($this->languagesInColumnCache[$pageId][$colPos])) {
1825 $this->languagesInColumnCache[$pageId][$colPos] = array();
1826 }
1827
1828 if (empty($this->languagesInColumnCache[$pageId][$colPos])) {
1829 $exQ = BackendUtility::deleteClause('tt_content') .
1830 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1831
1832 $databaseConnection = $this->getDatabaseConnection();
1833 $res = $databaseConnection->exec_SELECTquery(
1834 'sys_language.*',
1835 'tt_content,sys_language',
1836 'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
1837 BackendUtility::versioningPlaceholderClause('tt_content'),
1838 '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',
1839 'sys_language.title'
1840 );
1841 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1842 $this->languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
1843 }
1844 $databaseConnection->sql_free_result($res);
1845 }
1846
1847 return $this->languagesInColumnCache[$pageId][$colPos];
1848 }
1849
1850 /**
1851 * Check if a column of a page for a language is empty. Translation records are ignored here!
1852 *
1853 * @param int $colPos
1854 * @param int $languageId
1855 * @return bool
1856 */
1857 protected function isColumnEmpty($colPos, $languageId)
1858 {
1859 foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1860 if ((int)$row['l18n_parent'] === 0) {
1861 return false;
1862 }
1863 }
1864 return true;
1865 }
1866
1867 /**
1868 * Get elements for a column and a language
1869 *
1870 * @param int $pageId
1871 * @param int $colPos
1872 * @param int $languageId
1873 * @return array
1874 */
1875 protected function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId)
1876 {
1877 if (!isset($this->contentElementCache[$languageId][$colPos])) {
1878 $languageId = (int)$languageId;
1879 $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1880 if ($languageId > 0) {
1881 $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1882 }
1883
1884 $databaseConnection = $this->getDatabaseConnection();
1885 $res = $databaseConnection->exec_SELECTquery(
1886 'tt_content.uid',
1887 'tt_content,sys_language',
1888 $whereClause
1889 );
1890 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1891 $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1892 }
1893 $databaseConnection->sql_free_result($res);
1894 }
1895 if (is_array($this->contentElementCache[$languageId][$colPos])) {
1896 return array_keys($this->contentElementCache[$languageId][$colPos]);
1897 }
1898 return array();
1899 }
1900
1901 /**
1902 * Make selector box for creating new translation in a language
1903 * Displays only languages which are not yet present for the current page and
1904 * that are not disabled with page TS.
1905 *
1906 * @param int $id Page id for which to create a new language (pages_language_overlay record)
1907 * @return string <select> HTML element (if there were items for the box anyways...)
1908 * @see getTable_tt_content()
1909 */
1910 public function languageSelector($id)
1911 {
1912 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
1913 // First, select all
1914 $res = $this->getPageLayoutController()->exec_languageQuery(0);
1915 $langSelItems = array();
1916 $langSelItems[0] = '
1917 <option value="0"></option>';
1918 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1919 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1920 $langSelItems[$row['uid']] = '
1921 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
1922 }
1923 }
1924 // Then, subtract the languages which are already on the page:
1925 $res = $this->getPageLayoutController()->exec_languageQuery($id);
1926 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1927 unset($langSelItems[$row['uid']]);
1928 }
1929 // Remove disallowed languages
1930 if (count($langSelItems) > 1
1931 && !$this->getBackendUser()->user['admin']
1932 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
1933 ) {
1934 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1935 if (!empty($allowed_languages)) {
1936 foreach ($langSelItems as $key => $value) {
1937 if (!isset($allowed_languages[$key]) && $key != 0) {
1938 unset($langSelItems[$key]);
1939 }
1940 }
1941 }
1942 }
1943 // Remove disabled languages
1944 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
1945 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1946 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
1947 : array();
1948 if (!empty($langSelItems) && !empty($disableLanguages)) {
1949 foreach ($disableLanguages as $language) {
1950 if ($language != 0 && isset($langSelItems[$language])) {
1951 unset($langSelItems[$language]);
1952 }
1953 }
1954 }
1955 // If any languages are left, make selector:
1956 if (count($langSelItems) > 1) {
1957 $url = BackendUtility::getModuleUrl('record_edit', array(
1958 'edit[pages_language_overlay]['. $id . ']' => 'new',
1959 'overrideVals[pages_language_overlay][doktype]' => (int)$this->pageRecord['doktype'],
1960 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1961 ));
1962 $onChangeContent = 'window.location.href=' . GeneralUtility::quoteJSvalue($url . '&overrideVals[pages_language_overlay][sys_language_uid]=') . '+this.options[this.selectedIndex].value';
1963 return '<div class="form-inline form-inline-spaced">'
1964 . '<div class="form-group">'
1965 . '<label for="createNewLanguage">'
1966 . $this->getLanguageService()->getLL('new_language', true)
1967 . '</label>'
1968 . '<select class="form-control input-sm" name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">'
1969 . implode('', $langSelItems)
1970 . '</select></div></div>';
1971 }
1972 }
1973 return '';
1974 }
1975
1976 /**
1977 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
1978 *
1979 * @param bool|\mysqli_result|object $result MySQLi result object / DBAL object
1980 * @param string $table Table name defaulting to tt_content
1981 * @return array The selected rows returned in this array.
1982 */
1983 public function getResult($result, $table = 'tt_content')
1984 {
1985 $output = array();
1986 // Traverse the result:
1987 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
1988 BackendUtility::workspaceOL($table, $row, -99, true);
1989 if ($row) {
1990 // Add the row to the array:
1991 $output[] = $row;
1992 }
1993 }
1994 $this->generateTtContentDataArray($output);
1995 // Return selected records
1996 return $output;
1997 }
1998
1999 /********************************
2000 *
2001 * Various helper functions
2002 *
2003 ********************************/
2004
2005 /**
2006 * Initializes the clipboard for generating paste links
2007 *
2008 * @return void
2009 *
2010 * @see \TYPO3\CMS\Recordlist\RecordList::main()
2011 * @see \TYPO3\CMS\Backend\Controller\ClickMenuController::main()
2012 * @see \TYPO3\CMS\Filelist\Controller\FileListController::main()
2013 */
2014 protected function initializeClipboard()
2015 {
2016 // Start clipboard
2017 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
2018
2019 // Initialize - reads the clipboard content from the user session
2020 $this->clipboard->initializeClipboard();
2021
2022 // This locks the clipboard to the Normal for this request.
2023 $this->clipboard->lockToNormal();
2024
2025 // Clean up pad
2026 $this->clipboard->cleanCurrent();
2027
2028 // Save the clipboard content
2029 $this->clipboard->endClipboard();
2030 }
2031
2032 /**
2033 * Generates the data for previous and next elements which is needed for movements.
2034 *
2035 * @param array $rowArray
2036 * @return void
2037 */
2038 protected function generateTtContentDataArray(array $rowArray)
2039 {
2040 if (empty($this->tt_contentData)) {
2041 $this->tt_contentData = array(
2042 'nextThree' => array(),
2043 'next' => array(),
2044 'prev' => array(),
2045 );
2046 }
2047 foreach ($rowArray as $key => $value) {
2048 // Create the list of the next three ids (for editing links...)
2049 for ($i = 0; $i < $this->nextThree; $i++) {
2050 if (isset($rowArray[$key - $i])
2051 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
2052 ) {
2053 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
2054 }
2055 }
2056
2057 // Create information for next and previous content elements
2058 if (isset($rowArray[$key - 1])) {
2059 if (isset($rowArray[$key - 2])) {
2060 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
2061 } else {
2062 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
2063 }
2064 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
2065 }
2066 }
2067 }
2068
2069 /**
2070 * Counts and returns the number of records on the page with $pid
2071 *
2072 * @param string $table Table name
2073 * @param int $pid Page id
2074 * @return int Number of records.
2075 */
2076 public function numberOfRecords($table, $pid)
2077 {
2078 $count = 0;
2079 if ($GLOBALS['TCA'][$table]) {
2080 $where = 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table);
2081 $count = $this->getDatabase()->exec_SELECTcountRows('uid', $table, $where);
2082 }
2083 return (int)$count;
2084 }
2085
2086 /**
2087 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2088 *
2089 * @param string $input Input string
2090 * @return string Output string
2091 */
2092 public function renderText($input)
2093 {
2094 $input = strip_tags($input);
2095 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
2096 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
2097 }
2098
2099 /**
2100 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2101 *
2102 * @param string $table Table name
2103 * @param array $row Record array
2104 * @return string HTML for the icon
2105 */
2106 public function getIcon($table, $row)
2107 {
2108 // Initialization
2109 $altText = BackendUtility::getRecordIconAltText($row, $table);
2110 $icon = '<span title="' . $altText . '">' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
2111 $this->counter++;
2112 // The icon with link
2113 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
2114 $icon = $this->getPageLayoutController()->getModuleTemplate()->wrapClickMenuOnIcon($icon, $table, $row['uid']);
2115 }
2116 return $icon;
2117 }
2118
2119 /**
2120 * Creates processed values for all field names in $fieldList based on values from $row array.
2121 * The result is 'returned' through $info which is passed as a reference
2122 *
2123 * @param string $table Table name
2124 * @param string $fieldList Comma separated list of fields.
2125 * @param array $row Record from which to take values for processing.
2126 * @param array $info Array to which the processed values are added.
2127 * @return void
2128 */
2129 public function getProcessedValue($table, $fieldList, array $row, array &$info)
2130 {
2131 // Splitting values from $fieldList
2132 $fieldArr = explode(',', $fieldList);
2133 // Traverse fields from $fieldList
2134 foreach ($fieldArr as $field) {
2135 if ($row[$field]) {
2136 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2137 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2138 }
2139 }
2140 }
2141
2142 /**
2143 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2144 *
2145 * @param string $table Tablename of table to test
2146 * @param array $row Record row.
2147 * @return bool Returns TRUE, if disabled.
2148 */
2149 public function isDisabled($table, $row)
2150 {
2151 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2152 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2153 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2154 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2155 }
2156
2157 /**
2158 * Returns icon for "no-edit" of a record.
2159 * Basically, the point is to signal that this record could have had an edit link if
2160 * the circumstances were right. A placeholder for the regular edit icon...
2161 *
2162 * @param string $label Label key from LOCAL_LANG
2163 * @return string IMG tag for icon.
2164 */
2165 public function noEditIcon($label = 'noEditItems')
2166 {
2167 $title = $this->getLanguageService()->getLL($label, true);
2168 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2169 }
2170
2171 /**
2172 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
2173 * which the user has access. Also a set of standard tables (pages, static_template, sys_filemounts, etc...)
2174 * are filtered out. So what is left is basically all tables which makes sense to list content from.
2175 *
2176 * @return array
2177 */
2178 protected function cleanTableNames()
2179 {
2180 // Get all table names:
2181 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2182 // Unset common names:
2183 unset($tableNames['pages']);
2184 unset($tableNames['static_template']);
2185 unset($tableNames['sys_filemounts']);
2186 unset($tableNames['sys_action']);
2187 unset($tableNames['sys_workflows']);
2188 unset($tableNames['be_users']);
2189 unset($tableNames['be_groups']);
2190 $allowedTableNames = array();
2191 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2192 if (is_array($tableNames)) {
2193 foreach ($tableNames as $k => $v) {
2194 if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
2195 $allowedTableNames['table_' . $k] = $k;
2196 }
2197 }
2198 }
2199 return $allowedTableNames;
2200 }
2201
2202 /*****************************************
2203 *
2204 * External renderings
2205 *
2206 *****************************************/
2207
2208 /**
2209 * Creates a menu of the tables that can be listed by this function
2210 * Only tables which has records on the page will be included.
2211 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2212 *
2213 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2214 * @return string HTML output.
2215 */
2216 public function getTableMenu($id)
2217 {
2218 // Initialize:
2219 $this->activeTables = array();
2220 $theTables = array('tt_content');
2221 // External tables:
2222 if (is_array($this->externalTables)) {
2223 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2224 }
2225 $out = '';
2226 // Traverse tables to check:
2227 foreach ($theTables as $tName) {
2228 // Check access and whether the proper extensions are loaded:
2229 if ($this->getBackendUser()->check('tables_select', $tName)
2230 && (isset($this->externalTables[$tName])
2231 || GeneralUtility::inList('fe_users,tt_content', $tName)
2232 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2233 )
2234 ) {
2235 // Make query to count records from page:
2236 $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int)$id
2237 . BackendUtility::deleteClause($tName) . BackendUtility::versioningPlaceholderClause($tName));
2238 // If records were found (or if "tt_content" is the table...):
2239 if ($c || GeneralUtility::inList('tt_content', $tName)) {
2240 // Add row to menu:
2241 $out .= '
2242 <td><a href="#' . $tName . '" title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true) . '"></a>'
2243 . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render()
2244 . '</td>';
2245 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2246 $title = $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true)
2247 . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', true);
2248 $this->activeTables[$tName] = '<span title="' . $title. '">'
2249 . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render()
2250 . '</span>'
2251 . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true);
2252 }
2253 }
2254 }
2255 // Wrap cells in table tags:
2256 $out = '
2257 <!--
2258 Menu of tables on the page (table menu)
2259 -->
2260 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2261 <tr>' . $out . '
2262 </tr>
2263 </table>';
2264 // Return the content:
2265 return $out;
2266 }
2267
2268 /**
2269 * Create thumbnail code for record/field but not linked
2270 *
2271 * @param mixed[] $row Record array
2272 * @param string $table Table (record is from)
2273 * @param string $field Field name for which thumbnail are to be rendered.
2274 * @return string HTML for thumbnails, if any.
2275 */
2276 public function getThumbCodeUnlinked($row, $table, $field)
2277 {
2278 return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2279 }
2280
2281 /**
2282 * @return BackendLayoutView
2283 */
2284 protected function getBackendLayoutView()
2285 {
2286 return GeneralUtility::makeInstance(BackendLayoutView::class);
2287 }
2288
2289 /**
2290 * @return BackendUserAuthentication
2291 */
2292 protected function getBackendUser()
2293 {
2294 return $GLOBALS['BE_USER'];
2295 }
2296
2297 /**
2298 * @return DatabaseConnection
2299 */
2300 protected function getDatabase()
2301 {
2302 return $GLOBALS['TYPO3_DB'];
2303 }
2304
2305 /**
2306 * @return PageLayoutController
2307 */
2308 protected function getPageLayoutController()
2309 {
2310 return $GLOBALS['SOBE'];
2311 }
2312 }