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