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