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