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