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