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