c39aa50b9a73f0cbc52273b610090c26799c603a
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageLayoutController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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\Form\Exception\AccessDeniedException;
18 use TYPO3\CMS\Backend\Form\FormDataCompiler;
19 use TYPO3\CMS\Backend\Form\FormDataGroup\TcaDatabaseRecord;
20 use TYPO3\CMS\Backend\Form\FormResultCompiler;
21 use TYPO3\CMS\Backend\Form\NodeFactory;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Backend\Utility\IconUtility;
24 use TYPO3\CMS\Core\Imaging\Icon;
25 use TYPO3\CMS\Core\Imaging\IconFactory;
26 use TYPO3\CMS\Core\Page\PageRenderer;
27 use TYPO3\CMS\Core\Type\Bitmask\Permission;
28 use TYPO3\CMS\Core\Messaging\FlashMessage;
29 use TYPO3\CMS\Core\Utility\GeneralUtility;
30 use TYPO3\CMS\Core\Utility\HttpUtility;
31 use TYPO3\CMS\Core\Utility\MathUtility;
32 use TYPO3\CMS\Fluid\View\StandaloneView;
33 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
34 use TYPO3\CMS\Recordlist\RecordList;
35 use TYPO3\CMS\Core\DataHandling\DataHandler;
36 use TYPO3\CMS\Frontend\Page\PageRepository;
37 use TYPO3\CMS\Backend\Module\ModuleLoader;
38 use TYPO3\CMS\Backend\Template\DocumentTemplate;
39 use TYPO3\CMS\Backend\View\BackendLayoutView;
40 use TYPO3\CMS\Core\Messaging\FlashMessageService;
41 use TYPO3\CMS\Backend\View\PageLayoutView;
42 use TYPO3\CMS\Backend\Tree\View\ContentLayoutPagePositionMap;
43 use TYPO3\CMS\Core\Versioning\VersionState;
44
45 /**
46 * Script Class for Web > Layout module
47 */
48 class PageLayoutController {
49
50 /**
51 * Page Id for which to make the listing
52 *
53 * @var int
54 */
55 public $id;
56
57 /**
58 * Pointer - for browsing list of records.
59 *
60 * @var int
61 */
62 public $pointer;
63
64 /**
65 * Thumbnails or not
66 *
67 * @var string
68 */
69 public $imagemode;
70
71 /**
72 * Search-fields
73 *
74 * @var string
75 */
76 public $search_field;
77
78 /**
79 * Search-levels
80 *
81 * @var int
82 */
83 public $search_levels;
84
85 /**
86 * Show-limit
87 *
88 * @var int
89 */
90 public $showLimit;
91
92 /**
93 * Return URL
94 *
95 * @var string
96 */
97 public $returnUrl;
98
99 /**
100 * Clear-cache flag - if set, clears page cache for current id.
101 *
102 * @var bool
103 */
104 public $clear_cache;
105
106 /**
107 * PopView id - for opening a window with the page
108 *
109 * @var bool
110 */
111 public $popView;
112
113 /**
114 * QuickEdit: Variable, that tells quick edit what to show/edit etc.
115 * Format is [tablename]:[uid] with some exceptional values for both parameters (with special meanings).
116 *
117 * @var string
118 */
119 public $edit_record;
120
121 /**
122 * QuickEdit: If set, this variable tells quick edit that the last edited record had
123 * this value as UID and we should look up the new, real uid value in sys_log.
124 *
125 * @var string
126 */
127 public $new_unique_uid;
128
129 /**
130 * Page select perms clause
131 *
132 * @var string
133 */
134 public $perms_clause;
135
136 /**
137 * Module TSconfig
138 *
139 * @var array
140 */
141 public $modTSconfig;
142
143 /**
144 * Module shared TSconfig
145 *
146 * @var array
147 */
148 public $modSharedTSconfig;
149
150 /**
151 * Current ids page record
152 *
153 * @var array
154 */
155 public $pageinfo;
156
157 /**
158 * Document template object
159 *
160 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
161 */
162 public $doc;
163
164 /**
165 * "Pseudo" Description -table name
166 *
167 * @var string
168 */
169 public $descrTable;
170
171 /**
172 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
173 *
174 * @var string
175 */
176 public $colPosList;
177
178 /**
179 * Flag: If content can be edited or not.
180 *
181 * @var bool
182 */
183 public $EDIT_CONTENT;
184
185 /**
186 * Users permissions integer for this page.
187 *
188 * @var int
189 */
190 public $CALC_PERMS;
191
192 /**
193 * Currently selected language for editing content elements
194 *
195 * @var int
196 */
197 public $current_sys_language;
198
199 /**
200 * Module configuration
201 *
202 * @var array
203 */
204 public $MCONF = array();
205
206 /**
207 * Menu configuration
208 *
209 * @var array
210 */
211 public $MOD_MENU = array();
212
213 /**
214 * Module settings (session variable)
215 *
216 * @var array
217 */
218 public $MOD_SETTINGS = array();
219
220 /**
221 * Array of tables to be listed by the Web > Page module in addition to the default tables
222 *
223 * @var array
224 */
225 public $externalTables = array();
226
227 /**
228 * Module output accumulation
229 *
230 * @var string
231 */
232 public $content;
233
234 /**
235 * Function menu temporary storage
236 *
237 * @var string
238 */
239 public $topFuncMenu;
240
241 /**
242 * List of column-integers accessible to the current BE user.
243 * Is set from TSconfig, default is $colPosList
244 *
245 * @var string
246 */
247 public $activeColPosList;
248
249 /**
250 * Markers array
251 *
252 * @var array
253 */
254 protected $markers = array();
255
256 /**
257 * @var array
258 */
259 protected $eRParts = array();
260
261 /**
262 * @var string
263 */
264 protected $editSelect;
265
266 /**
267 * @var bool
268 */
269 protected $deleteButton;
270
271 /**
272 * @var bool
273 */
274 protected $undoButton;
275
276 /**
277 * @var array
278 */
279 protected $undoButtonR;
280
281 /**
282 * @var string
283 */
284 protected $R_URI;
285
286 /**
287 * @var string
288 */
289 protected $closeUrl;
290
291 /**
292 * Caches the available languages in a colPos
293 *
294 * @var array
295 */
296 protected $languagesInColumnCache = array();
297
298 /**
299 * Caches the amount of content elements as a matrix
300 *
301 * @var array
302 * @internal
303 */
304 public $contentElementCache = array();
305
306 /**
307 * @var IconFactory
308 */
309 protected $iconFactory;
310
311 /**
312 * Initializing the module
313 *
314 * @return void
315 */
316 public function init() {
317 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
318 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
319
320 // Setting module configuration / page select clause
321 $this->MCONF = $GLOBALS['MCONF'];
322 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
323 // Get session data
324 $sessionData = $this->getBackendUser()->getSessionData(RecordList::class);
325 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
326 // GPvars:
327 $this->id = (int)GeneralUtility::_GP('id');
328 $this->pointer = GeneralUtility::_GP('pointer');
329 $this->imagemode = GeneralUtility::_GP('imagemode');
330 $this->clear_cache = GeneralUtility::_GP('clear_cache');
331 $this->popView = GeneralUtility::_GP('popView');
332 $this->edit_record = GeneralUtility::_GP('edit_record');
333 $this->new_unique_uid = GeneralUtility::_GP('new_unique_uid');
334 $this->search_field = GeneralUtility::_GP('search_field');
335 $this->search_levels = GeneralUtility::_GP('search_levels');
336 $this->showLimit = GeneralUtility::_GP('showLimit');
337 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
338 $this->externalTables = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables'];
339 $sessionData['search_field'] = $this->search_field;
340 // Store session data
341 $this->getBackendUser()->setAndSaveSessionData(RecordList::class, $sessionData);
342 // Load page info array:
343 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
344 // Initialize menu
345 $this->menuConfig();
346 // Setting sys language from session var:
347 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
348 // CSH / Descriptions:
349 $this->descrTable = '_MOD_' . $this->MCONF['name'];
350
351 $this->markers['SEARCHBOX'] = '';
352 $this->markers['BUTTONLIST_ADDITIONAL'] = '';
353 }
354
355 /**
356 * Initialize menu array
357 *
358 * @return void
359 */
360 public function menuConfig() {
361 $lang = $this->getLanguageService();
362 // MENU-ITEMS:
363 $this->MOD_MENU = array(
364 'tt_content_showHidden' => '',
365 'function' => array(
366 0 => $lang->getLL('m_function_0'),
367 1 => $lang->getLL('m_function_1'),
368 2 => $lang->getLL('m_function_2')
369 ),
370 'language' => array(
371 0 => $lang->getLL('m_default')
372 )
373 );
374 // example settings:
375 // $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['cms']['db_layout']['addTables']['tx_myext'] =
376 // array ('default' => array(
377 // 'MENU' => 'LLL:EXT:tx_myext/locallang_db.xlf:menuDefault',
378 // 'fList' => 'title,description,image',
379 // 'icon' => TRUE));
380 if (is_array($this->externalTables)) {
381 foreach ($this->externalTables as $table => $tableSettings) {
382 // delete the default settings from above
383 if (is_array($this->MOD_MENU[$table])) {
384 unset($this->MOD_MENU[$table]);
385 }
386 if (is_array($tableSettings) && count($tableSettings) > 1) {
387 foreach ($tableSettings as $key => $settings) {
388 $this->MOD_MENU[$table][$key] = $lang->sL($settings['MENU']);
389 }
390 }
391 }
392 }
393 // First, select all pages_language_overlay records on the current page. Each represents a possibility for a language on the page. Add these to language selector.
394 $res = $this->exec_languageQuery($this->id);
395 while ($lRow = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
396 if ($this->getBackendUser()->checkLanguageAccess($lRow['uid'])) {
397 $this->MOD_MENU['language'][$lRow['uid']] = $lRow['hidden'] ? '(' . $lRow['title'] . ')' : $lRow['title'];
398 }
399 }
400 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
401 $count = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', $this->getBackendUser()->isAdmin() ? '' : 'hidden=0');
402 if (!$count) {
403 unset($this->MOD_MENU['function']['2']);
404 }
405 // page/be_user TSconfig settings and blinding of menu-items
406 $this->modSharedTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.SHARED');
407 $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
408 if ($this->modTSconfig['properties']['QEisDefault']) {
409 ksort($this->MOD_MENU['function']);
410 }
411 $this->MOD_MENU['function'] = BackendUtility::unsetMenuItems($this->modTSconfig['properties'], $this->MOD_MENU['function'], 'menu.function');
412 // Remove QuickEdit as option if page type is not...
413 if (!GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['FE']['content_doktypes'] . ',6', $this->pageinfo['doktype'])) {
414 unset($this->MOD_MENU['function'][0]);
415 }
416 // Setting alternative default label:
417 if (($this->modSharedTSconfig['properties']['defaultLanguageLabel'] || $this->modTSconfig['properties']['defaultLanguageLabel']) && isset($this->MOD_MENU['language'][0])) {
418 $this->MOD_MENU['language'][0] = $this->modTSconfig['properties']['defaultLanguageLabel'] ? $this->modSharedTSconfig['properties']['defaultLanguageLabel'] : $this->modSharedTSconfig['properties']['defaultLanguageLabel'];
419 }
420 // Clean up settings
421 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), 'web_layout');
422 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
423 if ($this->getBackendUser()->workspace != 0 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0') {
424 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
425 }
426 }
427
428 /**
429 * Clears page cache for the current id, $this->id
430 *
431 * @return void
432 */
433 public function clearCache() {
434 if ($this->clear_cache) {
435 $tce = GeneralUtility::makeInstance(DataHandler::class);
436 $tce->stripslashes_values = FALSE;
437 $tce->start(array(), array());
438 $tce->clear_cacheCmd($this->id);
439 }
440 }
441
442 /**
443 * Generate the flashmessages for current pid
444 *
445 * @return string HTML content with flashmessages
446 */
447 protected function getHeaderFlashMessagesForCurrentPid() {
448 $content = '';
449 $lang = $this->getLanguageService();
450 // If page is a folder
451 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
452 // Access to list module
453 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
454 $moduleLoader->load($GLOBALS['TBE_MODULES']);
455 $modules = $moduleLoader->modules;
456 if (is_array($modules['web']['sub']['list'])) {
457 $title = $lang->getLL('goToListModule');
458 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
459 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
460
461 $view = GeneralUtility::makeInstance(StandaloneView::class);
462 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
463 $view->assignMultiple(array(
464 'title' => $title,
465 'message' => $message,
466 'state' => InfoboxViewHelper::STATE_INFO
467 ));
468 $content .= $view->render();
469 }
470 }
471 // If content from different pid is displayed
472 if ($this->pageinfo['content_from_pid']) {
473 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
474 $title = BackendUtility::getRecordTitle('pages', $contentPage);
475 $linkToPid = $this->local_linkThisScript(array('id' => $this->pageinfo['content_from_pid']));
476 $link = '<a href="' . $linkToPid . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
477 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, sprintf($lang->getLL('content_from_pid_title'), $link), '', FlashMessage::INFO);
478 $content .= $flashMessage->render();
479 }
480 return $content;
481 }
482
483 /**
484 *
485 * @return string $title
486 */
487 protected function getLocalizedPageTitle() {
488 if ($this->current_sys_language > 0) {
489 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
490 'title',
491 'pages_language_overlay',
492 'pid = ' . (int)$this->id .
493 ' AND sys_language_uid = ' . (int)$this->current_sys_language .
494 BackendUtility::deleteClause('pages_language_overlay') .
495 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
496 '',
497 '',
498 '',
499 'sys_language_uid'
500 );
501 return $overlayRecord['title'];
502 } else {
503 return $this->pageinfo['title'];
504 }
505 }
506
507 /**
508 * Main function.
509 * Creates some general objects and calls other functions for the main rendering of module content.
510 *
511 * @return void
512 */
513 public function main() {
514 $lang = $this->getLanguageService();
515 // Access check...
516 // The page will show only if there is a valid page and if this page may be viewed by the user
517 $access = is_array($this->pageinfo) ? 1 : 0;
518 if ($this->id && $access) {
519 // Initialize permission settings:
520 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
521 $this->EDIT_CONTENT = $this->pageIsNotLockedForEditors();
522
523 // Start document template object:
524 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
525 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
526
527 // override the default jumpToUrl
528 $this->doc->JScodeArray['jumpToUrl'] = '
529 function jumpToUrl(URL,formEl) {
530 if (document.editform && TBE_EDITOR.isFormChanged) { // Check if the function exists... (works in all browsers?)
531 if (!TBE_EDITOR.isFormChanged()) {
532 window.location.href = URL;
533 } else if (formEl) {
534 if (formEl.type=="checkbox") formEl.checked = formEl.checked ? 0 : 1;
535 }
536 } else {
537 window.location.href = URL;
538 }
539 }
540 ';
541
542 $this->doc->JScode .= $this->doc->wrapScriptTags('
543 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
544 if (top.fsMod) top.fsMod.navFrameHighlightedID["web"] = "pages' . (int)$this->id . '_"+top.fsMod.currentBank; ' . (int)$this->id . ';
545 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
546
547 function deleteRecord(table,id,url) { //
548 if (confirm(' . GeneralUtility::quoteJSvalue($lang->getLL('deleteWarning')) . ')) {
549 window.location.href = ' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('tce_db') . '&cmd[') . '+table+"]["+id+"][delete]=1&redirect="+escape(url)+"&vC=' . $this->getBackendUser()->veriCode() . '&prErr=1&uPT=1";
550 }
551 return false;
552 }
553 ');
554 // Setting doc-header
555 $this->doc->form = '<form action="' . htmlspecialchars(
556 BackendUtility::getModuleUrl(
557 'web_layout', array('id' => $this->id, 'imagemode' => $this->imagemode)
558 )) . '" method="post">';
559 // Creating the top function menu:
560 $this->topFuncMenu = BackendUtility::getFuncMenu($this->id, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'], '', '');
561 $languageMenu = count($this->MOD_MENU['language']) > 1 ? $lang->sL('LLL:EXT:lang/locallang_general.xlf:LGL.language', TRUE) . BackendUtility::getFuncMenu($this->id, 'SET[language]', $this->current_sys_language, $this->MOD_MENU['language'], '', '') : '';
562 // Find backend layout / coumns
563 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
564 if (!empty($backendLayout['__colPosList'])) {
565 $this->colPosList = implode(',', $backendLayout['__colPosList']);
566 }
567 // Removing duplicates, if any
568 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
569 // Accessible columns
570 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
571 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
572 // Match with the list which is present in the colPosList for the current page
573 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
574 $this->activeColPosList = array_unique(array_intersect(
575 $this->activeColPosList,
576 $this->colPosList
577 ));
578 }
579 } else {
580 $this->activeColPosList = $this->colPosList;
581 }
582 $this->activeColPosList = implode(',', $this->activeColPosList);
583 $this->colPosList = implode(',', $this->colPosList);
584
585 $body = '';
586 $body .= $this->getHeaderFlashMessagesForCurrentPid();
587 // Render the primary module content:
588 if ($this->MOD_SETTINGS['function'] == 0) {
589 // QuickEdit
590 $body .= $this->renderQuickEdit();
591 } else {
592 // Page title
593 $body .= $this->doc->header($this->getLocalizedPageTitle());
594 // All other listings
595 $body .= $this->renderListContent();
596 }
597 // Setting up the buttons and markers for docheader
598 $docHeaderButtons = $this->getButtons($this->MOD_SETTINGS['function'] == 0 ? 'quickEdit' : '');
599 $this->markers['CSH'] = $docHeaderButtons['csh'];
600 $this->markers['TOP_FUNCTION_MENU'] = $this->topFuncMenu . $this->editSelect;
601 $this->markers['LANGSELECTOR'] = $languageMenu;
602 $this->markers['CONTENT'] = $body;
603 // Build the <body> for the module
604 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
605 // Renders the module page
606 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
607 } else {
608 // If no access or id value, create empty document:
609 $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
610 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout.html');
611 $this->doc->JScode = $this->doc->wrapScriptTags('
612 if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
613 ');
614
615 $body = $this->doc->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
616
617 $title = $lang->getLL('clickAPage_header');
618 $message = $lang->getLL('clickAPage_content');
619
620 $view = GeneralUtility::makeInstance(StandaloneView::class);
621 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
622 $view->assignMultiple(array(
623 'title' => $title,
624 'message' => $message,
625 'state' => InfoboxViewHelper::STATE_INFO
626 ));
627 $body .= $view->render();
628
629 // Setting up the buttons and markers for docheader
630 $docHeaderButtons = array(
631 'view' => '',
632 'history_page' => '',
633 'new_content' => '',
634 'move_page' => '',
635 'move_record' => '',
636 'new_page' => '',
637 'edit_page' => '',
638 'csh' => '',
639 'shortcut' => '',
640 'cache' => '',
641 'savedok' => '',
642 'savedokshow' => '',
643 'closedok' => '',
644 'deletedok' => '',
645 'undo' => '',
646 'history_record' => '',
647 'edit_language' => ''
648 );
649 $this->markers['CSH'] = '';
650 $this->markers['TOP_FUNCTION_MENU'] = '';
651 $this->markers['LANGSELECTOR'] = '';
652 $this->markers['CONTENT'] = $body;
653 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $this->markers);
654 // Renders the module page
655 $this->content = $this->doc->render($lang->getLL('title'), $this->content);
656 }
657 }
658
659 /**
660 * Rendering the quick-edit view.
661 *
662 * @return string
663 */
664 public function renderQuickEdit() {
665 $databaseConnection = $this->getDatabaseConnection();
666 $beUser = $this->getBackendUser();
667 $lang = $this->getLanguageService();
668 // Alternative template
669 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_layout_quickedit.html');
670 // Alternative form tag; Quick Edit submits its content to tce_db.php.
671 $this->doc->form = '<form action="' . htmlspecialchars(BackendUtility::getModuleUrl('tce_db', ['prErr' => 1, 'uPT' => 1])) . '" method="post" enctype="multipart/form-data" name="editform" onsubmit="return TBE_EDITOR.checkSubmit(1);">';
672 // Setting up the context sensitive menu:
673 $this->doc->getContextMenuCode();
674 // Set the edit_record value for internal use in this function:
675 $edit_record = $this->edit_record;
676 // If a command to edit all records in a column is issue, then select all those elements, and redirect to FormEngine
677 if (substr($edit_record, 0, 9) == '_EDIT_COL') {
678 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', 'pid=' . (int)$this->id . ' AND colPos=' . (int)substr($edit_record, 10) . ' AND sys_language_uid=' . (int)$this->current_sys_language . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content'), '', 'sorting');
679 $idListA = array();
680 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
681 $idListA[] = $cRow['uid'];
682 }
683 $url = BackendUtility::getModuleUrl('record_edit', array(
684 'edit[tt_content][' . implode(',', $idListA) . ']' => 'edit',
685 'returnUrl' => $this->local_linkThisScript(array('edit_record' => ''))
686 ));
687 HttpUtility::redirect($url);
688 }
689 // If the former record edited was the creation of a NEW record, this will look up the created records uid:
690 if ($this->new_unique_uid) {
691 $res = $databaseConnection->exec_SELECTquery('*', 'sys_log', 'userid=' . (int)$beUser->user['uid'] . ' AND NEWid=' . $databaseConnection->fullQuoteStr($this->new_unique_uid, 'sys_log'));
692 $sys_log_row = $databaseConnection->sql_fetch_assoc($res);
693 if (is_array($sys_log_row)) {
694 $edit_record = $sys_log_row['tablename'] . ':' . $sys_log_row['recuid'];
695 }
696 }
697 // Creating the selector box, allowing the user to select which element to edit:
698 $opt = array();
699 $is_selected = 0;
700 $languageOverlayRecord = '';
701 if ($this->current_sys_language) {
702 list($languageOverlayRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $this->id, 'AND sys_language_uid=' . (int)$this->current_sys_language);
703 }
704 if (is_array($languageOverlayRecord)) {
705 $inValue = 'pages_language_overlay:' . $languageOverlayRecord['uid'];
706 $is_selected += (int)$edit_record == $inValue;
707 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editLanguageHeader', TRUE) . ' ]</option>';
708 } else {
709 $inValue = 'pages:' . $this->id;
710 $is_selected += (int)$edit_record == $inValue;
711 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('editPageProperties', TRUE) . ' ]</option>';
712 }
713 // Selecting all content elements from this language and allowed colPos:
714 $whereClause = 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . ' AND colPos IN (' . $this->colPosList . ')' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? '' : BackendUtility::BEenableFields('tt_content')) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content');
715 if (!$this->getBackendUser()->user['admin']) {
716 $whereClause .= ' AND editlock = 0';
717 }
718 $res = $databaseConnection->exec_SELECTquery('*', 'tt_content', $whereClause, '', 'colPos,sorting');
719 $colPos = NULL;
720 $first = 1;
721 // Page is the pid if no record to put this after.
722 $prev = $this->id;
723 while ($cRow = $databaseConnection->sql_fetch_assoc($res)) {
724 BackendUtility::workspaceOL('tt_content', $cRow);
725 if (is_array($cRow)) {
726 if ($first) {
727 if (!$edit_record) {
728 $edit_record = 'tt_content:' . $cRow['uid'];
729 }
730 $first = 0;
731 }
732 if (!isset($colPos) || $cRow['colPos'] !== $colPos) {
733 $colPos = $cRow['colPos'];
734 $opt[] = '<option value=""></option>';
735 $opt[] = '<option value="_EDIT_COL:' . $colPos . '">__' . $lang->sL(BackendUtility::getLabelFromItemlist('tt_content', 'colPos', $colPos), TRUE) . ':__</option>';
736 }
737 $inValue = 'tt_content:' . $cRow['uid'];
738 $is_selected += (int)$edit_record == $inValue;
739 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(($cRow['header'] ? $cRow['header'] : '[' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title') . '] ' . strip_tags($cRow['bodytext'])), $beUser->uc['titleLen'])) . '</option>';
740 $prev = -$cRow['uid'];
741 }
742 }
743 // If edit_record is not set (meaning, no content elements was found for this language) we simply set it to create a new element:
744 if (!$edit_record) {
745 $edit_record = 'tt_content:new/' . $prev . '/' . $colPos;
746 $inValue = 'tt_content:new/' . $prev . '/' . $colPos;
747 $is_selected += (int)$edit_record == $inValue;
748 $opt[] = '<option value="' . $inValue . '"' . ($edit_record == $inValue ? ' selected="selected"' : '') . '>[ ' . $lang->getLL('newLabel', 1) . ' ]</option>';
749 }
750 // If none is yet selected...
751 if (!$is_selected) {
752 $opt[] = '<option value=""></option>';
753 $opt[] = '<option value="' . $edit_record . '" selected="selected">[ ' . $lang->getLL('newLabel', TRUE) . ' ]</option>';
754 }
755 // Splitting the edit-record cmd value into table/uid:
756 $this->eRParts = explode(':', $edit_record);
757 $tableName = $this->eRParts[0];
758 // Delete-button flag?
759 $this->deleteButton = MathUtility::canBeInterpretedAsInteger($this->eRParts[1]) && $edit_record && ($tableName !== 'pages' && $this->EDIT_CONTENT || $tableName === 'pages' && $this->CALC_PERMS & Permission::PAGE_DELETE);
760 // If undo-button should be rendered (depends on available items in sys_history)
761 $this->undoButton = FALSE;
762 $undoRes = $databaseConnection->exec_SELECTquery('tstamp', 'sys_history', 'tablename=' . $databaseConnection->fullQuoteStr($tableName, 'sys_history') . ' AND recuid=' . (int)$this->eRParts[1], '', 'tstamp DESC', '1');
763 if ($this->undoButtonR = $databaseConnection->sql_fetch_assoc($undoRes)) {
764 $this->undoButton = TRUE;
765 }
766 // Setting up the Return URL for coming back to THIS script (if links take the user to another script)
767 $R_URL_parts = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
768 $R_URL_getvars = GeneralUtility::_GET();
769 unset($R_URL_getvars['popView']);
770 unset($R_URL_getvars['new_unique_uid']);
771 $R_URL_getvars['edit_record'] = $edit_record;
772 $this->R_URI = $R_URL_parts['path'] . '?' . GeneralUtility::implodeArrayForUrl('', $R_URL_getvars);
773 // Setting close url/return url for exiting this script:
774 // Goes to 'Columns' view if close is pressed (default)
775 $this->closeUrl = $this->local_linkThisScript(array('SET' => array('function' => 1)));
776 if ($this->returnUrl) {
777 $this->closeUrl = $this->returnUrl;
778 }
779 // Return-url for JavaScript:
780 $retUrlStr = $this->returnUrl ? '+\'&returnUrl=\'+' . GeneralUtility::quoteJSvalue(rawurlencode($this->returnUrl)) : '';
781 // Drawing the edit record selectbox
782 $this->editSelect = '<select name="edit_record" onchange="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue(
783 BackendUtility::getModuleUrl('web_layout') . '&id=' . $this->id . '&edit_record='
784 ) . '+escape(this.options[this.selectedIndex].value)' . $retUrlStr . ',this);') . '">' . implode('', $opt) . '</select>';
785
786 // Creating editing form:
787 $content = '';
788
789 if ($edit_record) {
790 // Splitting uid parts for special features, if new:
791 list($uidVal, $neighborRecordUid, $ex_colPos) = explode('/', $this->eRParts[1]);
792
793 if ($uidVal === 'new') {
794 $command = 'new';
795 // Page id of this new record
796 $theUid = $this->id;
797 if ($neighborRecordUid) {
798 $theUid = $neighborRecordUid;
799 }
800 } else {
801 $command = 'edit';
802 $theUid = $uidVal;
803 // Convert $uidVal to workspace version if any:
804 $draftRecord = BackendUtility::getWorkspaceVersionOfRecord($beUser->workspace, $tableName, $theUid, 'uid');
805 if ($draftRecord) {
806 $theUid = $draftRecord['uid'];
807 }
808 }
809
810 // @todo: Hack because DatabaseInitializeNewRow reads from _GP directly
811 $GLOBALS['_GET']['defVals'][$tableName] = array(
812 'colPos' => (int)$ex_colPos,
813 'sys_language_uid' => (int)$this->current_sys_language
814 );
815
816 /** @var TcaDatabaseRecord $formDataGroup */
817 $formDataGroup = GeneralUtility::makeInstance(TcaDatabaseRecord::class);
818 /** @var FormDataCompiler $formDataCompiler */
819 $formDataCompiler = GeneralUtility::makeInstance(FormDataCompiler::class, $formDataGroup);
820 /** @var NodeFactory $nodeFactory */
821 $nodeFactory = GeneralUtility::makeInstance(NodeFactory::class);
822
823 try {
824 $formDataCompilerInput = [
825 'tableName' => $tableName,
826 'vanillaUid' => (int)$theUid,
827 'command' => $command,
828 ];
829 $formData = $formDataCompiler->compile($formDataCompilerInput);
830
831 if ($command !== 'new') {
832 BackendUtility::lockRecords($tableName, $formData['databaseRow']['uid'], $tableName === 'tt_content' ? $formData['databaseRow']['pid'] : 0);
833 }
834
835 $formData['renderType'] = 'outerWrapContainer';
836 $formResult = $nodeFactory->create($formData)->render();
837
838 $panel = $formResult['html'];
839 $formResult['html'] = '';
840
841 /** @var FormResultCompiler $formResultCompiler */
842 $formResultCompiler = GeneralUtility::makeInstance(FormResultCompiler::class);
843 $formResultCompiler->mergeResult($formResult);
844
845 $row = $formData['databaseRow'];
846 $new_unique_uid = '';
847 if ($command === 'new') {
848 $new_unique_uid = $row['uid'];
849 }
850
851 // Add hidden fields:
852 if ($uidVal == 'new') {
853 $panel .= '<input type="hidden" name="data[' . $tableName . '][' . $row['uid'] . '][pid]" value="' . $row['pid'] . '" />';
854 }
855 $panel .= '
856 <input type="hidden" name="_serialNumber" value="' . md5(microtime()) . '" />
857 <input type="hidden" name="edit_record" value="' . $edit_record . '" />
858 <input type="hidden" name="redirect" value="' . htmlspecialchars(($uidVal == 'new' ? BackendUtility::getModuleUrl(
859 'web_layout',
860 array(
861 'id' => $this->id,
862 'new_unique_uid' => $new_unique_uid,
863 'returnUrl' => $this->returnUrl
864 )
865 ) : $this->R_URI)) . '" />
866 ';
867 // Add JavaScript as needed around the form:
868 $panel = $formResultCompiler->JStop() . $panel . $formResultCompiler->printNeededJSFunctions();
869 $content = $this->doc->section('', $panel);
870
871 // Display "is-locked" message:
872 if ($command === 'edit') {
873 $lockInfo = BackendUtility::isRecordLocked($tableName, $formData['databaseRow']['uid']);
874 if ($lockInfo) {
875 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
876 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, htmlspecialchars($lockInfo['msg']), '', FlashMessage::WARNING);
877 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
878 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
879 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
880 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
881 $defaultFlashMessageQueue->enqueue($flashMessage);
882 }
883 }
884 } catch (AccessDeniedException $e) {
885 // If no edit access, print error message:
886 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg')
887 . '<br /><br />'
888 . ($beUser->errorMsg ? 'Reason: ' . $beUser->errorMsg . '<br /><br />' : ''), 0, 1
889 );
890 }
891 } else {
892 // If no edit access, print error message:
893 $content = $this->doc->section($lang->getLL('noAccess'), $lang->getLL('noAccess_msg') . '<br /><br />', 0, 1);
894 }
895
896 // Bottom controls (function menus):
897 $q_count = $this->getNumberOfHiddenElements();
898 if ($q_count) {
899 $h_func_b = '<div class="checkbox">' .
900 '<label for="checkTt_content_showHidden">' .
901 BackendUtility::getFuncCheck($this->id, 'SET[tt_content_showHidden]', $this->MOD_SETTINGS['tt_content_showHidden'], '', '', 'id="checkTt_content_showHidden"') .
902 (!$q_count ? ('<span class="text-muted">' . $lang->getLL('hiddenCE', TRUE) . '</span>') : $lang->getLL('hiddenCE', TRUE) . ' (' . $q_count . ')') .
903 '</label>' .
904 '</div>';
905
906 $content .= $this->doc->section('', $h_func_b, 0, 0);
907 $content .= $this->doc->spacer(10);
908 }
909
910 // Select element matrix:
911 if ($tableName === 'tt_content' && MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
912 $posMap = GeneralUtility::makeInstance(ContentLayoutPagePositionMap::class);
913 $posMap->cur_sys_language = $this->current_sys_language;
914 $HTMLcode = '';
915 // CSH:
916 $HTMLcode .= BackendUtility::cshItem($this->descrTable, 'quickEdit_selElement', NULL, '|<br />');
917 $HTMLcode .= $posMap->printContentElementColumns($this->id, $this->eRParts[1], $this->colPosList, $this->MOD_SETTINGS['tt_content_showHidden'], $this->R_URI);
918 $content .= $this->doc->spacer(20);
919 $content .= $this->doc->section($lang->getLL('CEonThisPage'), $HTMLcode, 0, 1);
920 $content .= $this->doc->spacer(20);
921 }
922
923 return $content;
924 }
925
926 /**
927 * Rendering all other listings than QuickEdit
928 *
929 * @return string
930 */
931 public function renderListContent() {
932 /** @var $dbList \TYPO3\CMS\Backend\View\PageLayoutView */
933 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
934 $dbList->thumbs = $this->imagemode;
935 $dbList->no_noWrap = 1;
936 $dbList->descrTable = $this->descrTable;
937 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
938 $dbList->script = BackendUtility::getModuleUrl('web_layout');
939 $dbList->showIcon = 0;
940 $dbList->setLMargin = 0;
941 $dbList->doEdit = $this->EDIT_CONTENT;
942 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
943 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears');
944 $dbList->id = $this->id;
945 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
946 $dbList->option_newWizard = $this->modTSconfig['properties']['disableNewContentElementWizard'] ? 0 : 1;
947 $dbList->defLangBinding = $this->modTSconfig['properties']['defLangBinding'] ? 1 : 0;
948 if (!$dbList->nextThree) {
949 $dbList->nextThree = 1;
950 }
951 $dbList->externalTables = $this->externalTables;
952 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
953 // also fills $dbList->activeTables
954 $dbList->getTableMenu($this->id);
955 // Initialize other variables:
956 $h_func = '';
957 $tableOutput = array();
958 $tableJSOutput = array();
959 $CMcounter = 0;
960 // Traverse the list of table names which has records on this page (that array is populated
961 // by the $dblist object during the function getTableMenu()):
962 foreach ($dbList->activeTables as $table => $value) {
963 $h_func_b = '';
964 if (!isset($dbList->externalTables[$table])) {
965 $q_count = $this->getNumberOfHiddenElements();
966
967 if ($q_count > 0) {
968 $h_func_b =
969 '<div class="checkbox">'
970 . '<label for="checkTt_content_showHidden">'
971 . '<input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />'
972 . $this->getLanguageService()->getLL('hiddenCE', TRUE) . ' (<span class="t3js-hidden-counter">' . $q_count . '</span>)'
973 . '</label>'
974 . '</div>';
975 }
976 // Boolean: Display up/down arrows and edit icons for tt_content records
977 $dbList->tt_contentConfig['showCommands'] = 1;
978 // Boolean: Display info-marks or not
979 $dbList->tt_contentConfig['showInfo'] = 1;
980 // Setting up the tt_content columns to show:
981 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
982 $colList = array();
983 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
984 foreach ($tcaItems as $temp) {
985 $colList[] = $temp[1];
986 }
987 } else {
988 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
989 $colList = array('1', '0', '2', '3');
990 }
991 if ($this->colPosList !== '') {
992 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
993 }
994 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
995 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
996 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
997 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
998 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
999 // If the function menu is set to "Language":
1000 if ($this->MOD_SETTINGS['function'] == 2) {
1001 $dbList->tt_contentConfig['languageMode'] = 1;
1002 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
1003 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
1004 }
1005 } else {
1006 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
1007 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
1008 } else {
1009 $h_func = '';
1010 }
1011 }
1012 // Start the dblist object:
1013 $dbList->itemsLimitSingleTable = 1000;
1014 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
1015 $dbList->counter = $CMcounter;
1016 $dbList->ext_function = $this->MOD_SETTINGS['function'];
1017 // Render versioning selector:
1018 $dbList->HTMLcode .= $this->doc->getVersionSelector($this->id);
1019 // Generate the list of elements here:
1020 $dbList->generateList();
1021 // Adding the list content to the tableOutput variable:
1022 $tableOutput[$table] = ($h_func ? $h_func . '<br /><span style="width: 1px; height: 4px; display: inline-block;"></span><br />' : '') . $dbList->HTMLcode . ($h_func_b ? '<span style="width: 1px; height: 10px; display:inline-block;"></span><br />' . $h_func_b : '');
1023 // ... and any accumulated JavaScript goes the same way!
1024 $tableJSOutput[$table] = $dbList->JScode;
1025 // Increase global counter:
1026 $CMcounter += $dbList->counter;
1027 // Reset variables after operation:
1028 $dbList->HTMLcode = '';
1029 $dbList->JScode = '';
1030 $h_func = '';
1031 }
1032 // END: traverse tables
1033 // For Context Sensitive Menus:
1034 $this->doc->getContextMenuCode();
1035 // Init the content
1036 $content = '';
1037 // Additional header content
1038 $headerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'];
1039 if (is_array($headerContentHook)) {
1040 foreach ($headerContentHook as $hook) {
1041 $params = array();
1042 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1043 }
1044 }
1045 // Add the content for each table we have rendered (traversing $tableOutput variable)
1046 foreach ($tableOutput as $table => $output) {
1047 $content .= $this->doc->section('', $output, TRUE, TRUE, 0, TRUE);
1048 $content .= $this->doc->sectionEnd();
1049 }
1050 // Making search form:
1051 if (!$this->modTSconfig['properties']['disableSearchBox'] && !empty($tableOutput)) {
1052 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
1053 $this->markers['BUTTONLIST_ADDITIONAL'] = '<a href="#" class="t3js-toggle-search-toolbox" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', TRUE) . '">' . $this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL) . '</a>';
1054 $this->markers['SEARCHBOX'] = $dbList->getSearchBox(0);
1055 }
1056 // Additional footer content
1057 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'];
1058 if (is_array($footerContentHook)) {
1059 foreach ($footerContentHook as $hook) {
1060 $params = array();
1061 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
1062 }
1063 }
1064 return $content;
1065 }
1066
1067 /**
1068 * Print accumulated content of module
1069 *
1070 * @return void
1071 */
1072 public function printContent() {
1073 echo $this->content;
1074 }
1075
1076 /***************************
1077 *
1078 * Sub-content functions, rendering specific parts of the module content.
1079 *
1080 ***************************/
1081 /**
1082 * Create the panel of buttons for submitting the form or otherwise perform operations.
1083 *
1084 * @param string $function Identifier for function of module
1085 * @return array all available buttons as an assoc. array
1086 */
1087 protected function getButtons($function = '') {
1088 $lang = $this->getLanguageService();
1089 $buttons = array(
1090 'view' => '',
1091 'history_page' => '',
1092 'new_content' => '',
1093 'move_page' => '',
1094 'move_record' => '',
1095 'new_page' => '',
1096 'edit_page' => '',
1097 'edit_language' => '',
1098 'csh' => '',
1099 'shortcut' => '',
1100 'cache' => '',
1101 'savedok' => '',
1102 'save_close' => '',
1103 'savedokshow' => '',
1104 'closedok' => '',
1105 'deletedok' => '',
1106 'undo' => '',
1107 'history_record' => ''
1108 );
1109 // View page
1110 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
1111 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL) . '</a>';
1112 }
1113 // Shortcut
1114 if ($this->getBackendUser()->mayMakeShortcut()) {
1115 $buttons['shortcut'] = $this->doc->makeShortcutIcon('id, edit_record, pointer, new_unique_uid, search_field, search_levels, showLimit', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']);
1116 }
1117 // Cache
1118 if (!$this->modTSconfig['properties']['disableAdvanced']) {
1119 $buttons['cache'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_layout', array('id' => $this->pageinfo['uid'], 'clear_cache' => '1'))) . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.clear_cache', TRUE) . '">' . $this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)->render() . '</a>';
1120 }
1121 if (!$this->modTSconfig['properties']['disableIconToolbar']) {
1122 // Move record
1123 if (MathUtility::canBeInterpretedAsInteger($this->eRParts[1])) {
1124 $urlParameters = [
1125 'table' => $this->eRParts[0],
1126 'uid' => $this->eRParts[1],
1127 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1128 ];
1129 $buttons['move_record'] = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('move_element', $urlParameters)) . '" title="' . $lang->getLL('move_' . ($this->eRParts[0] == 'tt_content' ? 'record' : 'page'), TRUE) . '">' . $this->iconFactory->getIcon('actions-' . ($this->eRParts[0] == 'tt_content' ? 'document' : 'page') . '-move', Icon::SIZE_SMALL)->render() . '</a>';
1130 }
1131
1132 // Edit page properties and page language overlay icons
1133 if ($this->pageIsNotLockedForEditors()) {
1134
1135 // Edit localized page_language_overlay only when one specific language is selected
1136 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1137 $overlayRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
1138 'uid',
1139 'pages_language_overlay',
1140 'pid = ' . (int)$this->id . ' ' .
1141 'AND sys_language_uid = ' . (int)$this->current_sys_language .
1142 BackendUtility::deleteClause('pages_language_overlay') .
1143 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1144 '',
1145 '',
1146 '',
1147 'sys_language_uid'
1148 );
1149
1150 $editLanguageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'));
1151 $buttons['edit_language'] = '<a href="#" ' .
1152 'onclick="' . $editLanguageOnClick . '"' .
1153 'title="' . $lang->getLL('editPageLanguageOverlayProperties', TRUE) . '">' .
1154 $this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL) .
1155 '</a>';
1156 }
1157
1158
1159 // Edit page properties
1160 $editPageOnClick = htmlspecialchars(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'));
1161 $buttons['edit_page'] = '<a href="#" onclick="' . $editPageOnClick . '" title="' . $lang->getLL('editPageProperties', TRUE) . '">'
1162 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)
1163 . '</a>';
1164 }
1165
1166 // Add CSH (Context Sensitive Help) icon to tool bar
1167 if ($function == 'quickEdit') {
1168 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'quickEdit');
1169 } else {
1170 $buttons['csh'] = BackendUtility::cshItem($this->descrTable, 'columns_' . $this->MOD_SETTINGS['function']);
1171 }
1172 if ($function == 'quickEdit') {
1173 // Save record
1174 $buttons['savedok'] = '<button class="c-inputButton" name="_savedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '">'
1175 . $this->iconFactory->getIcon('actions-document-save', Icon::SIZE_SMALL)
1176 . '</button>';
1177 // Save and close
1178 $buttons['save_close'] = '<button class="c-inputButton" name="_saveandclosedok_x" value="1" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '">'
1179 . $this->iconFactory->getIcon('actions-document-save-close', Icon::SIZE_SMALL)
1180 . '</button>';
1181 // Save record and show page
1182 $buttons['savedokshow'] = '<a href="#" onclick="' . htmlspecialchars('document.editform.redirect.value+=\'&popView=1\'; TBE_EDITOR.checkAndDoSubmit(1); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDocShow', TRUE) . '">'
1183 . $this->iconFactory->getIcon('actions-document-save-view', Icon::SIZE_SMALL)
1184 . '</a>';
1185 // Close record
1186 $buttons['closedok'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(' . GeneralUtility::quoteJSvalue($this->closeUrl) . '); return false;') . '" title="' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '">'
1187 . $this->iconFactory->getIcon('actions-document-close', Icon::SIZE_SMALL)
1188 . '</a>';
1189 // Delete record
1190 if ($this->deleteButton) {
1191 $buttons['deletedok'] = '<a href="#" onclick="' . htmlspecialchars('return deleteRecord(' . GeneralUtility::quoteJSvalue($this->eRParts[0]) . ',' . GeneralUtility::quoteJSvalue($this->eRParts[1]) . ',' . GeneralUtility::quoteJSvalue(GeneralUtility::getIndpEnv('SCRIPT_NAME') . '?id=' . $this->id) . ');') . '" title="' . $lang->getLL('deleteItem', TRUE) . '">'
1192 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)
1193 . '</a>';
1194 }
1195 if ($this->undoButton) {
1196 // Undo button
1197 $buttons['undo'] = '<a href="#"
1198 onclick="' . htmlspecialchars('window.location.href=' .
1199 GeneralUtility::quoteJSvalue(
1200 BackendUtility::getModuleUrl(
1201 'record_history',
1202 array(
1203 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1204 'revert' => 'ALL_FIELDS',
1205 'sumUp' => -1,
1206 'returnUrl' => $this->R_URI,
1207 )
1208 )
1209 ) . '; return false;') . '"
1210 title="' . htmlspecialchars(sprintf($lang->getLL('undoLastChange'), BackendUtility::calcAge($GLOBALS['EXEC_TIME'] - $this->undoButtonR['tstamp'], $lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.minutesHoursDaysYears')))) . '">' . $this->iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL) . '</a>';
1211 // History button
1212 $buttons['history_record'] = '<a href="#"
1213 onclick="' . htmlspecialchars('jumpToUrl(' .
1214 GeneralUtility::quoteJSvalue(
1215 BackendUtility::getModuleUrl(
1216 'record_history',
1217 array(
1218 'element' => $this->eRParts[0] . ':' . $this->eRParts[1],
1219 'returnUrl' => $this->R_URI,
1220 )
1221 ) . '#latest'
1222 ) . ');return false;') . '"
1223 title="' . $lang->getLL('recordHistory', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL) . '</a>';
1224 }
1225 }
1226 }
1227 return $buttons;
1228 }
1229
1230 /*******************************
1231 *
1232 * Other functions
1233 *
1234 ******************************/
1235 /**
1236 * Returns the number of hidden elements (including those hidden by start/end times)
1237 * on the current page (for the current sys_language)
1238 *
1239 * @return int
1240 */
1241 public function getNumberOfHiddenElements() {
1242 return $this->getDatabaseConnection()->exec_SELECTcountRows(
1243 'uid',
1244 'tt_content',
1245 'pid=' . (int)$this->id . ' AND sys_language_uid=' . (int)$this->current_sys_language . BackendUtility::BEenableFields('tt_content', 1) . BackendUtility::deleteClause('tt_content') . BackendUtility::versioningPlaceholderClause('tt_content')
1246 );
1247 }
1248
1249 /**
1250 * Returns URL to the current script.
1251 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1252 *
1253 * @param array $params Parameters array, merged with global GET vars.
1254 * @return string URL
1255 */
1256 public function local_linkThisScript($params) {
1257 $params['popView'] = '';
1258 $params['new_unique_uid'] = '';
1259 return GeneralUtility::linkThisScript($params);
1260 }
1261
1262 /**
1263 * Returns a SQL query for selecting sys_language records.
1264 *
1265 * @param int $id Page id: If zero, the query will select all sys_language records from root level which are NOT hidden. If set to another value, the query will select all sys_language records that has a pages_language_overlay record on that page (and is not hidden, unless you are admin user)
1266 * @return string Return query string.
1267 */
1268 public function exec_languageQuery($id) {
1269 if ($id) {
1270 $exQ = BackendUtility::deleteClause('pages_language_overlay') .
1271 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1272 return $this->getDatabaseConnection()->exec_SELECTquery(
1273 'sys_language.*',
1274 'pages_language_overlay,sys_language',
1275 'pages_language_overlay.sys_language_uid=sys_language.uid AND pages_language_overlay.pid=' . (int)$id . $exQ .
1276 BackendUtility::versioningPlaceholderClause('pages_language_overlay'),
1277 'pages_language_overlay.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
1278 'sys_language.title'
1279 );
1280 } else {
1281 return $this->getDatabaseConnection()->exec_SELECTquery(
1282 'sys_language.*',
1283 'sys_language',
1284 'sys_language.hidden=0',
1285 '',
1286 'sys_language.title'
1287 );
1288 }
1289 }
1290
1291 /**
1292 * Get used languages in a colPos of a page
1293 *
1294 * @param int $pageId
1295 * @param int $colPos
1296 * @return bool|\mysqli_result|object
1297 */
1298 public function getUsedLanguagesInPageAndColumn($pageId, $colPos) {
1299 if (!isset($languagesInColumnCache[$pageId])) {
1300 $languagesInColumnCache[$pageId] = array();
1301 }
1302 if (!isset($languagesInColumnCache[$pageId][$colPos])) {
1303 $languagesInColumnCache[$pageId][$colPos] = array();
1304 }
1305
1306 if (empty($languagesInColumnCache[$pageId][$colPos])) {
1307 $exQ = BackendUtility::deleteClause('tt_content') .
1308 ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1309
1310 $databaseConnection = $this->getDatabaseConnection();
1311 $res = $databaseConnection->exec_SELECTquery(
1312 'sys_language.*',
1313 'tt_content,sys_language',
1314 'tt_content.sys_language_uid=sys_language.uid AND tt_content.colPos = ' . (int)$colPos . ' AND tt_content.pid=' . (int)$pageId . $exQ .
1315 BackendUtility::versioningPlaceholderClause('tt_content'),
1316 'tt_content.sys_language_uid,sys_language.uid,sys_language.pid,sys_language.tstamp,sys_language.hidden,sys_language.title,sys_language.language_isocode,sys_language.static_lang_isocode,sys_language.flag',
1317 'sys_language.title'
1318 );
1319 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1320 $languagesInColumnCache[$pageId][$colPos][$row['uid']] = $row;
1321 }
1322 $databaseConnection->sql_free_result($res);
1323 }
1324
1325 return $languagesInColumnCache[$pageId][$colPos];
1326 }
1327
1328 /**
1329 * Check if a column of a page for a language is empty. Translation records are ignored here!
1330 *
1331 * @param int $colPos
1332 * @param int $languageId
1333 * @return bool
1334 */
1335 public function isColumnEmpty($colPos, $languageId) {
1336 foreach ($this->contentElementCache[$languageId][$colPos] as $uid => $row) {
1337 if ((int)$row['l18n_parent'] === 0) {
1338 return FALSE;
1339 }
1340 }
1341 return TRUE;
1342 }
1343
1344 /**
1345 * Get elements for a column and a language
1346 *
1347 * @param int $pageId
1348 * @param int $colPos
1349 * @param int $languageId
1350 * @return array
1351 */
1352 public function getElementsFromColumnAndLanguage($pageId, $colPos, $languageId) {
1353 if (!isset($this->contentElementCache[$languageId][$colPos])) {
1354 $languageId = (int)$languageId;
1355 $whereClause = 'tt_content.pid=' . (int)$pageId . ' AND tt_content.colPos=' . (int)$colPos . ' AND tt_content.sys_language_uid=' . $languageId . BackendUtility::deleteClause('tt_content');
1356 if ($languageId > 0) {
1357 $whereClause .= ' AND tt_content.l18n_parent=0 AND sys_language.uid=' . $languageId . ($this->getBackendUser()->isAdmin() ? '' : ' AND sys_language.hidden=0');
1358 }
1359
1360 $databaseConnection = $this->getDatabaseConnection();
1361 $res = $databaseConnection->exec_SELECTquery(
1362 'tt_content.uid',
1363 'tt_content,sys_language',
1364 $whereClause
1365 );
1366 while ($row = $databaseConnection->sql_fetch_assoc($res)) {
1367 $this->contentElementCache[$languageId][$colPos][$row['uid']] = $row;
1368 }
1369 $databaseConnection->sql_free_result($res);
1370 }
1371 if (is_array($this->contentElementCache[$languageId][$colPos])) {
1372 return array_keys($this->contentElementCache[$languageId][$colPos]);
1373 }
1374 return array();
1375 }
1376
1377 /**
1378 * Check the editlock access
1379 *
1380 * @return bool
1381 */
1382 public function pageIsNotLockedForEditors() {
1383 return $this->getBackendUser()->isAdmin() || !($this->CALC_PERMS & Permission::PAGE_EDIT && $this->pageinfo['editlock']);
1384 }
1385
1386 /**
1387 * Returns LanguageService
1388 *
1389 * @return \TYPO3\CMS\Lang\LanguageService
1390 */
1391 protected function getLanguageService() {
1392 return $GLOBALS['LANG'];
1393 }
1394
1395 /**
1396 * Returns the current BE user.
1397 *
1398 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1399 */
1400 protected function getBackendUser() {
1401 return $GLOBALS['BE_USER'];
1402 }
1403
1404 /**
1405 * Returns the database connection
1406 *
1407 * @return \TYPO3\CMS\Core\Database\DatabaseConnection
1408 */
1409 protected function getDatabaseConnection() {
1410 return $GLOBALS['TYPO3_DB'];
1411 }
1412
1413 /**
1414 * Returns current PageRenderer
1415 *
1416 * @return PageRenderer
1417 */
1418 protected function getPageRenderer() {
1419 return GeneralUtility::makeInstance(PageRenderer::class);
1420 }
1421 }