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