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