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