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