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