18c6eafcd75d4f3c48d28c56f0d88b245fdbb8c7
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / DocumentTemplate.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template;
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\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Imaging\Icon;
21 use TYPO3\CMS\Core\Imaging\IconFactory;
22 use TYPO3\CMS\Core\Page\PageRenderer;
23 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
24 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\PathUtility;
27
28 /**
29 * TYPO3 Backend Template Class
30 *
31 * This class contains functions for starting and ending the HTML of backend modules
32 * It also contains methods for outputting sections of content.
33 * Further there are functions for making icons, links, setting form-field widths etc.
34 * Color scheme and stylesheet definitions are also available here.
35 * Finally this file includes the language class for TYPO3's backend.
36 *
37 * After this file $LANG and $TBE_TEMPLATE are global variables / instances of their respective classes.
38 *
39 * Please refer to Inside TYPO3 for a discussion of how to use this API.
40 */
41 class DocumentTemplate
42 {
43 // Vars you typically might want to/should set from outside after making instance of this class:
44 /**
45 * This can be set to the HTML-code for a formtag.
46 * Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
47 *
48 * @var string
49 */
50 public $form = '';
51
52 /**
53 * Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
54 *
55 * @var string
56 */
57 public $JScode = '';
58
59 /**
60 * Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
61 *
62 * @var string
63 */
64 public $extJScode = '';
65
66 /**
67 * Similar to $JScode but for use as array with associative keys to prevent double inclusion of JS code. a <script> tag is automatically wrapped around.
68 *
69 * @var array
70 */
71 public $JScodeArray = array('jumpToUrl' => '
72 function jumpToUrl(URL) {
73 window.location.href = URL;
74 return false;
75 }
76 ');
77
78 /**
79 * Additional 'page-end' code could be accumulated in this var. It will be outputted at the end of page before </body> and some other internal page-end code.
80 *
81 * @var string
82 */
83 public $postCode = '';
84
85 /**
86 * HTML template with markers for module
87 *
88 * @var string
89 */
90 public $moduleTemplate = '';
91
92 /**
93 * The base file (not overlaid by TBE_STYLES) for the current module, useful for hooks when finding out which modules is rendered currently
94 *
95 * @var string
96 */
97 protected $moduleTemplateFilename = '';
98
99 /**
100 * Script ID
101 *
102 * @var string
103 */
104 public $scriptID = '';
105
106 /**
107 * Id which can be set for the body tag. Default value is based on script ID
108 *
109 * @var string
110 */
111 public $bodyTagId = '';
112
113 /**
114 * You can add additional attributes to the body-tag through this variable.
115 *
116 * @var string
117 */
118 public $bodyTagAdditions = '';
119
120 /**
121 * Additional CSS styles which will be added to the <style> section in the header
122 * used as array with associative keys to prevent double inclusion of CSS code
123 *
124 * @var array
125 */
126 public $inDocStylesArray = array();
127
128 /**
129 * Compensation for large documents (used in \TYPO3\CMS\Backend\Form\FormEngine)
130 *
131 * @var float
132 */
133 public $form_largeComp = 1.33;
134
135 /**
136 * Filename of stylesheet (relative to PATH_typo3)
137 *
138 * @var string
139 */
140 public $styleSheetFile = '';
141
142 /**
143 * Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
144 *
145 * @var string
146 */
147 public $styleSheetFile2 = '';
148
149 /**
150 * Filename of a post-stylesheet - included right after all inline styles.
151 *
152 * @var string
153 */
154 public $styleSheetFile_post = '';
155
156 /**
157 * Whether to use the X-UA-Compatible meta tag
158 *
159 * @var bool
160 */
161 protected $useCompatibilityTag = true;
162
163 /**
164 * X-Ua-Compatible version output in meta tag
165 *
166 * @var string
167 */
168 protected $xUaCompatibilityVersion = 'IE=edge';
169
170 // Skinning
171 /**
172 * Include these CSS directories from skins by default
173 *
174 * @var array
175 */
176 protected $stylesheetsSkins = array(
177 'structure' => 'Resources/Public/Css/structure/',
178 'visual' => 'Resources/Public/Css/visual/'
179 );
180
181 /**
182 * JavaScript files loaded for every page in the Backend
183 *
184 * @var array
185 */
186 protected $jsFiles = array();
187
188 /**
189 * JavaScript files loaded for every page in the Backend, but explicitly excluded from concatenation (useful for libraries etc.)
190 *
191 * @var array
192 */
193 protected $jsFilesNoConcatenation = array();
194
195 /**
196 * Indicates if a <div>-output section is open
197 *
198 * @var int
199 * @internal will be removed in TYPO3 v9
200 */
201 public $sectionFlag = 0;
202
203 /**
204 * (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
205 *
206 * @var string
207 */
208 public $divClass = '';
209
210 /**
211 * @var string
212 */
213 public $pageHeaderBlock = '';
214
215 /**
216 * @var string
217 */
218 public $endOfPageJsBlock = '';
219
220 /**
221 * @var bool
222 */
223 public $hasDocheader = true;
224
225 /**
226 * @var PageRenderer
227 */
228 protected $pageRenderer = null;
229
230 /**
231 * Alternative template file
232 *
233 * @var string
234 */
235 protected $pageHeaderFooterTemplateFile = '';
236
237 /**
238 * @var bool
239 */
240 protected $extDirectStateProvider = false;
241
242 /**
243 * Whether flashmessages should be rendered or not
244 *
245 * @var bool $showFlashMessages
246 */
247 public $showFlashMessages = true;
248
249 /**
250 * @var IconFactory
251 */
252 protected $iconFactory;
253
254 /**
255 * @var MarkerBasedTemplateService
256 */
257 protected $templateService;
258
259 const STATUS_ICON_ERROR = 3;
260 const STATUS_ICON_WARNING = 2;
261 const STATUS_ICON_NOTIFICATION = 1;
262 const STATUS_ICON_OK = -1;
263
264 /**
265 * Constructor
266 */
267 public function __construct()
268 {
269 // Initializes the page rendering object:
270 $this->initPageRenderer();
271
272 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
273
274 // initialize Marker Support
275 $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
276
277 // Setting default scriptID, trim forward slash from route
278 $this->scriptID = GeneralUtility::_GET('M') !== null ? GeneralUtility::_GET('M') : ltrim(GeneralUtility::_GET('route'), '/');
279 $this->bodyTagId = preg_replace('/[^A-Za-z0-9-]/', '-', $this->scriptID);
280 // Individual configuration per script? If so, make a recursive merge of the arrays:
281 if (is_array($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID])) {
282 // Make copy
283 $ovr = $GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID];
284 // merge styles.
285 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TBE_STYLES'], $ovr);
286 // Have to unset - otherwise the second instantiation will do it again!
287 unset($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID]);
288 }
289 // Main Stylesheets:
290 if ($GLOBALS['TBE_STYLES']['stylesheet']) {
291 $this->styleSheetFile = $GLOBALS['TBE_STYLES']['stylesheet'];
292 }
293 if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
294 $this->styleSheetFile2 = $GLOBALS['TBE_STYLES']['stylesheet2'];
295 }
296 if ($GLOBALS['TBE_STYLES']['styleSheetFile_post']) {
297 $this->styleSheetFile_post = $GLOBALS['TBE_STYLES']['styleSheetFile_post'];
298 }
299 if ($GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle']) {
300 $this->inDocStylesArray['TBEstyle'] = $GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle'];
301 }
302 // include all stylesheets
303 foreach ($this->getSkinStylesheetDirectories() as $stylesheetDirectory) {
304 $this->addStyleSheetDirectory($stylesheetDirectory);
305 }
306 }
307
308 /**
309 * Initializes the page renderer object
310 */
311 protected function initPageRenderer()
312 {
313 if ($this->pageRenderer !== null) {
314 return;
315 }
316 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
317 $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
318 $this->pageRenderer->enableConcatenateFiles();
319 $this->pageRenderer->enableCompressCss();
320 $this->pageRenderer->enableCompressJavascript();
321 // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
322 foreach ($this->jsFilesNoConcatenation as $file) {
323 $this->pageRenderer->addJsFile(
324 $file,
325 'text/javascript',
326 true,
327 false,
328 '',
329 true
330 );
331 }
332 // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
333 foreach ($this->jsFiles as $file) {
334 $this->pageRenderer->addJsFile($file);
335 }
336 if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1) {
337 $this->pageRenderer->enableDebugMode();
338 }
339 }
340
341 /**
342 * Sets inclusion of StateProvider
343 *
344 * @return void
345 */
346 public function setExtDirectStateProvider()
347 {
348 $this->extDirectStateProvider = true;
349 }
350
351 /*****************************************
352 *
353 * EVALUATION FUNCTIONS
354 * Various centralized processing
355 *
356 *****************************************/
357
358 /**
359 * Makes link to page $id in frontend (view page)
360 * Returns an icon which links to the frontend index.php document for viewing the page with id $id
361 * $id must be a page-uid
362 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
363 *
364 * @param int $id The page id
365 * @return string HTML string with linked icon(s)
366 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
367 */
368 public function viewPageIcon($id)
369 {
370 GeneralUtility::logDeprecatedFunction();
371 // If access to Web>List for user, then link to that module.
372 $str = '<a href="' . htmlspecialchars(BackendUtility::getModuleUrl('web_list', [
373 'id' => $id,
374 'returnUrl' > GeneralUtility::getIndpEnv('REQUEST_URI')
375 ])) . '" title="' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showList')) . '">' . $this->iconFactory->getIcon('actions-system-list-open', Icon::SIZE_SMALL)->render() . '</a>';
376
377 // Make link to view page
378 $str .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($id, '', BackendUtility::BEgetRootLine($id))) . '" title="' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage')) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
379 return $str;
380 }
381
382 /**
383 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
384 * $table and $row must be a tablename/record from that table
385 * $path will be shown as alt-text for the icon.
386 * The title will be truncated to 45 chars.
387 *
388 * @param string $table Table name
389 * @param array $row Record row
390 * @param string $path Alt text
391 * @param bool $noViewPageIcon Set $noViewPageIcon TRUE if you don't want a magnifier-icon for viewing the page in the frontend
392 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
393 * @param bool $enableClickMenu If TRUE, render click menu code around icon image
394 * @return string HTML content
395 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
396 */
397 public function getHeader($table, $row, $path, $noViewPageIcon = false, $tWrap = array('', ''), $enableClickMenu = true)
398 {
399 GeneralUtility::logDeprecatedFunction();
400 $viewPage = '';
401 if (is_array($row) && $row['uid']) {
402 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
403 $title = strip_tags(BackendUtility::getRecordTitle($table, $row));
404 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid']);
405 } else {
406 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIcon('apps-pagetree-page-domain', Icon::SIZE_SMALL)->render() . '</span>';
407 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
408 }
409
410 if ($enableClickMenu) {
411 $iconImgTag = BackendUtility::wrapClickMenuOnIcon($iconImgTag, $table, $row['uid']);
412 }
413
414 return '<span class="typo3-moduleHeader">' . $iconImgTag . $viewPage . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, 45)) . $tWrap[1] . '</span>';
415 }
416
417 /**
418 * Like ->getHeader() but for files and folders
419 * Returns the icon with the path of the file/folder set in the alt/title attribute. Shows the name after the icon.
420 *
421 * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
422 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
423 * @param bool $enableClickMenu If TRUE, render click menu code around icon image
424 * @return string
425 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
426 */
427 public function getResourceHeader(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $tWrap = array('', ''), $enableClickMenu = true)
428 {
429 GeneralUtility::logDeprecatedFunction();
430 try {
431 $path = $resource->getStorage()->getName() . $resource->getParentFolder()->getIdentifier();
432 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIconForResource($resource, Icon::SIZE_SMALL)->render() . '</span>';
433 } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
434 $iconImgTag = '';
435 }
436
437 if ($enableClickMenu && ($resource instanceof \TYPO3\CMS\Core\Resource\File)) {
438 $metaData = $resource->_getMetaData();
439 $iconImgTag = BackendUtility::wrapClickMenuOnIcon($iconImgTag, 'sys_file_metadata', $metaData['uid']);
440 }
441
442 return '<span class="typo3-moduleHeader">' . $iconImgTag . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($resource->getName(), 45)) . $tWrap[1] . '</span>';
443 }
444
445 /**
446 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
447 *
448 * @param string $gvList Is the list of GET variables to store (if any)
449 * @param string $setList Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
450 * @param string $modName Module name string
451 * @param string|int $motherModName Is used to enter the "parent module name" if the module is a submodule under eg. Web>* or File>*. You can also set this value to 1 in which case the currentLoadedModule is sent to the shortcut script (so - not a fixed value!) - that is used in file_edit and wizard_rte modules where those are really running as a part of another module.
452 * @param string $classes
453 * @return string HTML content
454 */
455 public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $classes = '')
456 {
457 $gvList = 'route,' . $gvList;
458 $storeUrl = $this->makeShortcutUrl($gvList, $setList);
459 $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
460 // Fallback for alt_mod. We still pass in the old xMOD... stuff, but TBE_MODULES only knows about "record_edit".
461 // We still need to pass the xMOD name to createShortcut below, since this is used for icons.
462 $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
463 // Add the module identifier automatically if typo3/index.php is used:
464 if (GeneralUtility::_GET('M') !== null) {
465 $storeUrl = '&M=' . $moduleName . $storeUrl;
466 }
467 if ((int)$motherModName === 1) {
468 $motherModule = 'top.currentModuleLoaded';
469 } elseif ($motherModName) {
470 $motherModule = GeneralUtility::quoteJSvalue($motherModName);
471 } else {
472 $motherModule = '\'\'';
473 }
474 $confirmationText = GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark'));
475
476 $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
477 $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
478
479 if ($shortcutExist) {
480 return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
481 $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
482 }
483 $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
484 $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
485 ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this);return false;';
486
487 return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
488 htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark')) . '">' .
489 $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
490 }
491
492 /**
493 * MAKE url for storing
494 * Internal func
495 *
496 * @param string $gvList Is the list of GET variables to store (if any)
497 * @param string $setList Is the list of SET[] variables to store (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend modules
498 * @return string
499 * @access private
500 * @see makeShortcutIcon()
501 */
502 public function makeShortcutUrl($gvList, $setList)
503 {
504 $GET = GeneralUtility::_GET();
505 $storeArray = array_merge(GeneralUtility::compileSelectedGetVarsFromArray($gvList, $GET), array('SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)));
506 $storeUrl = GeneralUtility::implodeArrayForUrl('', $storeArray);
507 return $storeUrl;
508 }
509
510 /**
511 * Returns <input> attributes to set the width of an text-type input field.
512 * For client browsers with no CSS support the cols/size attribute is returned.
513 * For CSS compliant browsers (recommended) a ' style="width: ...px;"' is returned.
514 *
515 * @param int $size A relative number which multiplied with approx. 10 will lead to the width in pixels
516 * @param bool $textarea A flag you can set for textareas - DEPRECATED as there is no difference any more between the two
517 * @param string $styleOverride A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
518 * @return string Tag attributes for an <input> tag (regarding width)
519 */
520 public function formWidth($size = 48, $textarea = false, $styleOverride = '')
521 {
522 return ' style="' . ($styleOverride ?: 'width:' . ceil($size * 9.58) . 'px;') . '"';
523 }
524
525 /**
526 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
527 * Used in fx. db_list.php (Web>List)
528 *
529 * @param string $thisLocation URL to "this location" / current script
530 * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
531 * @see typo3/db_list.php
532 */
533 public function redirectUrls($thisLocation = '')
534 {
535 $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript(array(
536 'CB' => '',
537 'SET' => '',
538 'cmd' => '',
539 'popViewId' => ''
540 ));
541 $out = '
542 var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
543 var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
544 ';
545 return $out;
546 }
547
548 /**
549 * Defines whether to use the X-UA-Compatible meta tag.
550 *
551 * @param bool $useCompatibilityTag Whether to use the tag
552 * @return void
553 */
554 public function useCompatibilityTag($useCompatibilityTag = true)
555 {
556 $this->useCompatibilityTag = (bool)$useCompatibilityTag;
557 }
558
559 /*****************************************
560 *
561 * PAGE BUILDING FUNCTIONS.
562 * Use this to build the HTML of your backend modules
563 *
564 *****************************************/
565 /**
566 * Returns page start
567 * This includes the proper header with charset, title, meta tag and beginning body-tag.
568 *
569 * @param string $title HTML Page title for the header
570 * @return string Returns the whole header section of a HTML-document based on settings in internal variables (like styles, javascript code, charset, generator and docType)
571 * @see endPage()
572 */
573 public function startPage($title)
574 {
575 // hook pre start page
576 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'])) {
577 $preStartPageHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'];
578 if (is_array($preStartPageHook)) {
579 $hookParameters = array(
580 'title' => &$title
581 );
582 foreach ($preStartPageHook as $hookFunction) {
583 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
584 }
585 }
586 }
587 // alternative template for Header and Footer
588 if ($this->pageHeaderFooterTemplateFile) {
589 $file = GeneralUtility::getFileAbsFileName($this->pageHeaderFooterTemplateFile);
590 if ($file) {
591 $this->pageRenderer->setTemplateFile($file);
592 }
593 }
594
595 // Disable rendering of XHTML tags
596 $this->pageRenderer->setRenderXhtml(false);
597
598 $languageCode = $this->pageRenderer->getLanguage() === 'default' ? 'en' : $this->pageRenderer->getLanguage();
599 $this->pageRenderer->setHtmlTag('<html lang="' . $languageCode . '">');
600
601 $headerStart = '<!DOCTYPE html>';
602 $this->pageRenderer->setXmlPrologAndDocType($headerStart);
603 $this->pageRenderer->setHeadTag('<head>' . LF . '<!-- TYPO3 Script ID: ' . htmlspecialchars($this->scriptID) . ' -->');
604 header('Content-Type:text/html;charset=utf-8');
605 $this->pageRenderer->setCharSet('utf-8');
606 $this->pageRenderer->addMetaTag($this->generator());
607 $this->pageRenderer->addMetaTag('<meta name="robots" content="noindex,follow">');
608 $this->pageRenderer->addMetaTag('<meta charset="utf-8">');
609 $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
610 $this->pageRenderer->setFavIcon($this->getBackendFavicon());
611 if ($this->useCompatibilityTag) {
612 $this->pageRenderer->addMetaTag($this->xUaCompatible($this->xUaCompatibilityVersion));
613 }
614 $this->pageRenderer->setTitle($title);
615 // add docstyles
616 $this->docStyle();
617 if ($this->extDirectStateProvider) {
618 $this->pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/JavaScript/ExtDirect.StateProvider.js');
619 }
620 $this->pageRenderer->addHeaderData($this->JScode);
621 foreach ($this->JScodeArray as $name => $code) {
622 $this->pageRenderer->addJsInlineCode($name, $code, false);
623 }
624
625 if ($this->extJScode) {
626 $this->pageRenderer->addExtOnReadyCode($this->extJScode);
627 }
628
629 // Load jquery and twbs JS libraries on every backend request
630 $this->pageRenderer->loadJquery();
631 // Note: please do not reference "bootstrap" outside of the TYPO3 Core (not in your own extensions)
632 // as this is preliminary as long as Twitter bootstrap does not support AMD modules
633 // this logic will be changed once Twitter bootstrap 4 is included
634 $this->pageRenderer->addJsFile(ExtensionManagementUtility::extRelPath('core') . 'Resources/Public/JavaScript/Contrib/bootstrap/bootstrap.js');
635
636 // hook for additional headerData
637 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'])) {
638 $preHeaderRenderHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'];
639 if (is_array($preHeaderRenderHook)) {
640 $hookParameters = array(
641 'pageRenderer' => &$this->pageRenderer
642 );
643 foreach ($preHeaderRenderHook as $hookFunction) {
644 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
645 }
646 }
647 }
648 // Construct page header.
649 $str = $this->pageRenderer->render(PageRenderer::PART_HEADER);
650 $this->JScode = ($this->extJScode = '');
651 $this->JScodeArray = array();
652 $this->endOfPageJsBlock = $this->pageRenderer->render(PageRenderer::PART_FOOTER);
653 $str .= $this->docBodyTagBegin() . ($this->divClass ? '
654
655 <!-- Wrapping DIV-section for whole page BEGIN -->
656 <div class="' . $this->divClass . '">
657 ' : '') . trim($this->form);
658 return $str;
659 }
660
661 /**
662 * Returns page end; This includes finishing form, div, body and html tags.
663 *
664 * @return string The HTML end of a page
665 * @see startPage()
666 */
667 public function endPage()
668 {
669 $str = $this->postCode . GeneralUtility::wrapJS(BackendUtility::getUpdateSignalCode()) . ($this->form ? '
670 </form>' : '');
671 // If something is in buffer like debug, put it to end of page
672 if (ob_get_contents()) {
673 $str .= ob_get_clean();
674 if (!headers_sent()) {
675 header('Content-Encoding: None');
676 }
677 }
678 $str .= ($this->divClass ? '
679
680 <!-- Wrapping DIV-section for whole page END -->
681 </div>' : '') . $this->endOfPageJsBlock;
682
683 // Logging: Can't find better place to put it:
684 if (TYPO3_DLOG) {
685 GeneralUtility::devLog('END of BACKEND session', \TYPO3\CMS\Backend\Template\DocumentTemplate::class, 0, array('_FLUSH' => true));
686 }
687 return $str;
688 }
689
690 /**
691 * Shortcut for render the complete page of a module
692 *
693 * @param string $title page title
694 * @param string $content page content
695 * @return string complete page
696 */
697 public function render($title, $content)
698 {
699 $pageContent = $this->startPage($title);
700 $pageContent .= $content;
701 $pageContent .= $this->endPage();
702 return $this->insertStylesAndJS($pageContent);
703 }
704
705 /**
706 * Returns the header-bar in the top of most backend modules
707 * Closes section if open.
708 *
709 * @param string $text The text string for the header
710 * @return string HTML content
711 * @deprecated since TYPO3 v8, will be removed in TYPO3 9
712 */
713 public function header($text)
714 {
715 GeneralUtility::logDeprecatedFunction();
716 $str = '
717
718 <!-- MAIN Header in page top -->
719 <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
720 ';
721 return $this->sectionEnd() . $str;
722 }
723
724 /**
725 * Begins an output section and sets header and content
726 *
727 * @param string $label The header
728 * @param string $text The HTML-content
729 * @param bool $nostrtoupper A flag that will prevent the header from being converted to uppercase
730 * @param bool $sH Defines the type of header (if set, "<h3>" rather than the default "h4")
731 * @param int $type The number of an icon to show with the header (see the icon-function). -1,1,2,3
732 * @param bool $allowHTMLinHeader If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
733 * @return string HTML content
734 * @see icons(), sectionHeader()
735 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
736 */
737 public function section($label, $text, $nostrtoupper = false, $sH = false, $type = 0, $allowHTMLinHeader = false)
738 {
739 GeneralUtility::logDeprecatedFunction();
740 $str = '';
741 // Setting header
742 if ($label) {
743 if (!$allowHTMLinHeader) {
744 $label = htmlspecialchars($label);
745 }
746 $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
747 }
748 // Setting content
749 $str .= '
750
751 <!-- Section content -->
752 ' . $text;
753 return $this->sectionBegin() . $str;
754 }
755
756 /**
757 * Inserts a divider image
758 * Ends a section (if open) before inserting the image
759 *
760 * @param int $dist The margin-top/-bottom of the <hr> ruler.
761 * @return string HTML content
762 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
763 */
764 public function divider($dist)
765 {
766 GeneralUtility::logDeprecatedFunction();
767 $dist = (int)$dist;
768 $str = '
769
770 <!-- DIVIDER -->
771 <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
772 ';
773 return $this->sectionEnd() . $str;
774 }
775
776 /**
777 * Make a section header.
778 * Begins a section if not already open.
779 *
780 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
781 * @param bool $sH If set, <h3> is used, otherwise <h4>
782 * @param string $addAttrib Additional attributes to h-tag, eg. ' class=""'
783 * @return string HTML content
784 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
785 */
786 public function sectionHeader($label, $sH = false, $addAttrib = '')
787 {
788 GeneralUtility::logDeprecatedFunction();
789 $tag = $sH ? 'h2' : 'h3';
790 if ($addAttrib && $addAttrib[0] !== ' ') {
791 $addAttrib = ' ' . $addAttrib;
792 }
793 $str = '
794
795 <!-- Section header -->
796 <' . $tag . $addAttrib . '>' . $label . '</' . $tag . '>
797 ';
798 return $this->sectionBegin() . $str;
799 }
800
801 /**
802 * Begins an output section.
803 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE (if the ->sectionFlag is not already set!)
804 * You can call this function even if a section is already begun since the function will only return something if the sectionFlag is not already set!
805 *
806 * @return string HTML content
807 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
808 */
809 public function sectionBegin()
810 {
811 GeneralUtility::logDeprecatedFunction();
812 if (!$this->sectionFlag) {
813 $this->sectionFlag = 1;
814 $str = '
815
816 <!-- ***********************
817 Begin output section.
818 *********************** -->
819 <div>
820 ';
821 return $str;
822 } else {
823 return '';
824 }
825 }
826
827 /**
828 * Ends and output section
829 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
830 * See sectionBegin() also.
831 *
832 * @return string HTML content
833 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
834 */
835 public function sectionEnd()
836 {
837 if ($this->sectionFlag) {
838 GeneralUtility::logDeprecatedFunction();
839 $this->sectionFlag = 0;
840 return '
841 </div>
842 <!-- *********************
843 End output section.
844 ********************* -->
845 ';
846 } else {
847 return '';
848 }
849 }
850
851 /**
852 * Creates the bodyTag.
853 * You can add to the bodyTag by $this->bodyTagAdditions
854 *
855 * @return string HTML body tag
856 */
857 public function docBodyTagBegin()
858 {
859 return '<body ' . trim($this->bodyTagAdditions . ($this->bodyTagId ? ' id="' . $this->bodyTagId . '"' : '')) . '>';
860 }
861
862 /**
863 * Outputting document style
864 *
865 * @return string HTML style section/link tags
866 */
867 public function docStyle()
868 {
869 // Implode it all:
870 $inDocStyles = implode(LF, $this->inDocStylesArray);
871
872 // Reset styles so they won't be added again in insertStylesAndJS()
873 $this->inDocStylesArray = array();
874
875 if ($this->styleSheetFile) {
876 $this->pageRenderer->addCssFile($this->styleSheetFile);
877 }
878 if ($this->styleSheetFile2) {
879 $this->pageRenderer->addCssFile($this->styleSheetFile2);
880 }
881
882 if ($inDocStyles !== '') {
883 $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
884 }
885
886 if ($this->styleSheetFile_post) {
887 $this->pageRenderer->addCssFile($this->styleSheetFile_post);
888 }
889 }
890
891 /**
892 * Insert additional style sheet link
893 *
894 * @param string $key some key identifying the style sheet
895 * @param string $href uri to the style sheet file
896 * @param string $title value for the title attribute of the link element
897 * @param string $relation value for the rel attribute of the link element
898 * @return void
899 */
900 public function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet')
901 {
902 $this->pageRenderer->addCssFile($href, $relation, 'screen', $title);
903 }
904
905 /**
906 * Add all *.css files of the directory $path to the stylesheets
907 *
908 * @param string $path directory to add
909 * @return void
910 */
911 public function addStyleSheetDirectory($path)
912 {
913 $path = GeneralUtility::getFileAbsFileName($path);
914 // Read all files in directory and sort them alphabetically
915 $cssFiles = GeneralUtility::getFilesInDir($path, 'css');
916 foreach ($cssFiles as $cssFile) {
917 $this->pageRenderer->addCssFile(PathUtility::getRelativePathTo($path) . $cssFile);
918 }
919 }
920
921 /**
922 * Insert post rendering document style into already rendered content
923 * This is needed for extobjbase
924 *
925 * @param string $content style-content to insert.
926 * @return string content with inserted styles
927 */
928 public function insertStylesAndJS($content)
929 {
930 $styles = LF . implode(LF, $this->inDocStylesArray);
931 $content = str_replace('/*###POSTCSSMARKER###*/', $styles, $content);
932
933 // Insert accumulated JS
934 $jscode = $this->JScode . LF . GeneralUtility::wrapJS(implode(LF, $this->JScodeArray));
935 $content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
936 return $content;
937 }
938
939 /**
940 * Returns an array of all stylesheet directories belonging to core and skins
941 *
942 * @return array Stylesheet directories
943 */
944 public function getSkinStylesheetDirectories()
945 {
946 $stylesheetDirectories = array();
947 // Stylesheets from skins
948 // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
949 if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
950 // loop over all registered skins
951 foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
952 $skinStylesheetDirs = $this->stylesheetsSkins;
953 // Skins can add custom stylesheetDirectories using
954 // $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
955 if (is_array($skin['stylesheetDirectories'])) {
956 $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
957 }
958 // Add all registered directories
959 foreach ($skinStylesheetDirs as $stylesheetDir) {
960 // for EXT:myskin/stylesheets/ syntax
961 if (substr($stylesheetDir, 0, 4) === 'EXT:') {
962 list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
963 if (!empty($extKey) && ExtensionManagementUtility::isLoaded($extKey) && !empty($path)) {
964 $stylesheetDirectories[] = ExtensionManagementUtility::extPath($extKey) . $path;
965 }
966 } else {
967 // For relative paths
968 $stylesheetDirectories[] = ExtensionManagementUtility::extPath($skinExtKey) . $stylesheetDir;
969 }
970 }
971 }
972 }
973 return $stylesheetDirectories;
974 }
975
976 /**
977 * Returns generator meta tag
978 *
979 * @return string <meta> tag with name "generator
980 */
981 public function generator()
982 {
983 $str = 'TYPO3 CMS, ' . TYPO3_URL_GENERAL . ', &#169; Kasper Sk&#229;rh&#248;j ' . TYPO3_copyright_year . ', extensions are copyright of their respective owners.';
984 return '<meta name="generator" content="' . $str . '" />';
985 }
986
987 /**
988 * Returns X-UA-Compatible meta tag
989 *
990 * @param string $content Content of the compatible tag (default: IE-8)
991 * @return string <meta http-equiv="X-UA-Compatible" content="???" />
992 */
993 public function xUaCompatible($content = 'IE=8')
994 {
995 return '<meta http-equiv="X-UA-Compatible" content="' . $content . '" />';
996 }
997
998 /*****************************************
999 *
1000 * OTHER ELEMENTS
1001 * Tables, buttons, formatting dimmed/red strings
1002 *
1003 ******************************************/
1004 /**
1005 * Returns an image-tag with an 18x16 icon of the following types:
1006 *
1007 * $type:
1008 * -1: OK icon (Check-mark)
1009 * 1: Notice (Speach-bubble)
1010 * 2: Warning (Yellow triangle)
1011 * 3: Fatal error (Red stop sign)
1012 *
1013 * @param int $type See description
1014 * @param string $styleAttribValue Value for style attribute
1015 * @return string HTML image tag (if applicable)
1016 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
1017 */
1018 public function icons($type, $styleAttribValue = '')
1019 {
1020 GeneralUtility::logDeprecatedFunction();
1021 switch ($type) {
1022 case self::STATUS_ICON_ERROR:
1023 $icon = 'status-dialog-error';
1024 break;
1025 case self::STATUS_ICON_WARNING:
1026 $icon = 'status-dialog-warning';
1027 break;
1028 case self::STATUS_ICON_NOTIFICATION:
1029 $icon = 'status-dialog-notification';
1030 break;
1031 case self::STATUS_ICON_OK:
1032 $icon = 'status-dialog-ok';
1033 break;
1034 default:
1035 // Do nothing
1036 }
1037 if ($icon) {
1038 return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
1039 }
1040 }
1041
1042 /**
1043 * Returns an <input> button with the $onClick action and $label
1044 *
1045 * @param string $onClick The value of the onclick attribute of the input tag (submit type)
1046 * @param string $label The label for the button (which will be htmlspecialchar'ed)
1047 * @return string A <input> tag of the type "submit
1048 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
1049 */
1050 public function t3Button($onClick, $label)
1051 {
1052 GeneralUtility::logDeprecatedFunction();
1053 $button = '<input class="btn btn-default" type="submit" onclick="' . htmlspecialchars($onClick) . '; return false;" value="' . htmlspecialchars($label) . '" />';
1054 return $button;
1055 }
1056
1057 /**
1058 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1059 *
1060 * @param string $string Input string
1061 * @return string Output string
1062 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1063 */
1064 public function wrapInCData($string)
1065 {
1066 GeneralUtility::logDeprecatedFunction();
1067 $string = '/*<![CDATA[*/' . $string . '/*]]>*/';
1068 return $string;
1069 }
1070
1071 /**
1072 * Wraps the input string in script tags.
1073 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1074 * This is nice for identing JS code with PHP code on the same level.
1075 *
1076 * @param string $string Input string
1077 * @param bool $linebreak Wrap script element in linebreaks? Default is TRUE.
1078 * @return string Output string
1079 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9, use GeneralUtility::wrapJS()
1080 */
1081 public function wrapScriptTags($string, $linebreak = true)
1082 {
1083 GeneralUtility::logDeprecatedFunction();
1084 if (trim($string)) {
1085 // <script wrapped in nl?
1086 $cr = $linebreak ? LF : '';
1087 // Remove nl from the beginning
1088 $string = ltrim($string, LF);
1089 // Re-ident to one tab using the first line as reference
1090 if ($string[0] === TAB) {
1091 $string = TAB . ltrim($string, TAB);
1092 }
1093 $string = $cr . '<script type="text/javascript">
1094 /*<![CDATA[*/
1095 ' . $string . '
1096 /*]]>*/
1097 </script>' . $cr;
1098 }
1099 return trim($string);
1100 }
1101
1102 /**
1103 * Returns a one-row/two-celled table with $content and $menu side by side.
1104 * The table is a 100% width table and each cell is aligned left / right
1105 *
1106 * @param string $content Content cell content (left)
1107 * @param string $menu Menu cell content (right)
1108 * @return string HTML output
1109 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1110 */
1111 public function funcMenu($content, $menu)
1112 {
1113 GeneralUtility::logDeprecatedFunction();
1114 return '
1115 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1116 <tr>
1117 <td valign="top" nowrap="nowrap">' . $content . '</td>
1118 <td valign="top" align="right" nowrap="nowrap">' . $menu . '</td>
1119 </tr>
1120 </table>';
1121 }
1122
1123 /**
1124 * Includes a javascript library that exists in the core /typo3/ directory
1125 *
1126 * @param string $lib: Library name. Call it with the full path like "sysext/core/Resources/Public/JavaScript/QueryGenerator.js" to load it
1127 * @return void
1128 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
1129 */
1130 public function loadJavascriptLib($lib)
1131 {
1132 GeneralUtility::logDeprecatedFunction();
1133 $this->pageRenderer->addJsFile($lib);
1134 }
1135
1136 /**
1137 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1138 *
1139 * @return void
1140 * @deprecated since TYPO3 v8, will be removed in TYPO3 v9
1141 */
1142 public function getContextMenuCode()
1143 {
1144 GeneralUtility::logDeprecatedFunction();
1145 $this->pageRenderer->loadJquery();
1146 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
1147 }
1148
1149 /**
1150 * Includes the necessary javascript file for use on pages which have the
1151 * drag and drop functionality (legacy folder tree)
1152 *
1153 * @param string $table indicator of which table the drag and drop function should work on (pages or folders)
1154 * @param string $additionalJavaScriptCode adds more code to the additional javascript code
1155 * @return void
1156 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1157 */
1158 public function getDragDropCode($table, $additionalJavaScriptCode = '')
1159 {
1160 GeneralUtility::logDeprecatedFunction();
1161 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
1162 DragDrop.table = "' . $table . '";
1163 ' . $additionalJavaScriptCode . '
1164 }');
1165 }
1166
1167 /**
1168 * Creates a tab menu from an array definition
1169 *
1170 * Returns a tab menu for a module
1171 * Requires the JS function jumpToUrl() to be available
1172 *
1173 * @param mixed $mainParams is the "&id=" parameter value to be sent to the module, but it can be also a parameter array which will be passed instead of the &id=...
1174 * @param string $elementName it the form elements name, probably something like "SET[...]
1175 * @param string $currentValue is the value to be selected currently.
1176 * @param array $menuItems is an array with the menu items for the selector box
1177 * @param string $script is the script to send the &id to, if empty it's automatically found
1178 * @param string $addparams is additional parameters to pass to the script.
1179 * @return string HTML code for tab menu
1180 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1181 */
1182 public function getTabMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '')
1183 {
1184 GeneralUtility::logDeprecatedFunction();
1185 $content = '';
1186 if (is_array($menuItems)) {
1187 if (!is_array($mainParams)) {
1188 $mainParams = array('id' => $mainParams);
1189 }
1190 $mainParams = GeneralUtility::implodeArrayForUrl('', $mainParams);
1191 if (!$script) {
1192 $script = basename(PATH_thisScript);
1193 }
1194 $menuDef = array();
1195 foreach ($menuItems as $value => $label) {
1196 $menuDef[$value]['isActive'] = (string)$currentValue === (string)$value;
1197 $menuDef[$value]['label'] = htmlspecialchars($label, ENT_COMPAT, 'UTF-8', false);
1198 $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
1199 }
1200 $content = $this->getTabMenuRaw($menuDef);
1201 }
1202 return $content;
1203 }
1204
1205 /**
1206 * Creates the HTML content for the tab menu
1207 *
1208 * @param array $menuItems Menu items for tabs
1209 * @return string Table HTML
1210 * @access private
1211 */
1212 public function getTabMenuRaw($menuItems)
1213 {
1214 if (!is_array($menuItems)) {
1215 return '';
1216 }
1217
1218 $options = '';
1219 foreach ($menuItems as $id => $def) {
1220 $class = $def['isActive'] ? 'active' : '';
1221 $label = $def['label'];
1222 $url = htmlspecialchars($def['url']);
1223 $params = $def['addParams'];
1224
1225 $options .= '<li class="' . $class . '">' .
1226 '<a href="' . $url . '" ' . $params . '>' . $label . '</a>' .
1227 '</li>';
1228 }
1229
1230 return '<ul class="nav nav-tabs" role="tablist">' .
1231 $options .
1232 '</ul>';
1233 }
1234
1235 /**
1236 * Creates the version selector for the page id inputted.
1237 * Requires the core version management extension, "version" to be loaded.
1238 *
1239 * @param int $id Page id to create selector for.
1240 * @param bool $noAction If set, there will be no button for swapping page.
1241 * @return string
1242 * @deprecated since TYPO3 CMS 8, will be removed in TYPO3 CMS 9.
1243 */
1244 public function getVersionSelector($id, $noAction = false)
1245 {
1246 GeneralUtility::logDeprecatedFunction();
1247 if (
1248 ExtensionManagementUtility::isLoaded('version') &&
1249 !ExtensionManagementUtility::isLoaded('workspaces')
1250 ) {
1251 $versionGuiObj = GeneralUtility::makeInstance(\TYPO3\CMS\Version\View\VersionView::class);
1252 return $versionGuiObj->getVersionSelector($id, $noAction);
1253 }
1254 }
1255
1256 /**
1257 * Function to load a HTML template file with markers.
1258 * When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
1259 *
1260 * @param string $filename tmpl name, usually in the typo3/template/ directory
1261 * @return string HTML of template
1262 */
1263 public function getHtmlTemplate($filename)
1264 {
1265 // setting the name of the original HTML template
1266 $this->moduleTemplateFilename = $filename;
1267 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1268 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1269 }
1270 if (GeneralUtility::isFirstPartOfStr($filename, 'EXT:')) {
1271 $filename = GeneralUtility::getFileAbsFileName($filename);
1272 } elseif (!GeneralUtility::isAbsPath($filename)) {
1273 $filename = GeneralUtility::resolveBackPath($filename);
1274 } elseif (!GeneralUtility::isAllowedAbsPath($filename)) {
1275 $filename = '';
1276 }
1277 $htmlTemplate = '';
1278 if ($filename !== '') {
1279 $htmlTemplate = file_get_contents($filename);
1280 }
1281 return $htmlTemplate;
1282 }
1283
1284 /**
1285 * Define the template for the module
1286 *
1287 * @param string $filename filename
1288 * @return void
1289 */
1290 public function setModuleTemplate($filename)
1291 {
1292 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1293 }
1294
1295 /**
1296 * Put together the various elements for the module <body> using a static HTML
1297 * template
1298 *
1299 * @param array $pageRecord Record of the current page, used for page path and info
1300 * @param array $buttons HTML for all buttons
1301 * @param array $markerArray HTML for all other markers
1302 * @param array $subpartArray HTML for the subparts
1303 * @return string Composite HTML
1304 */
1305 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array(), $subpartArray = array())
1306 {
1307 // Get the HTML template for the module
1308 $moduleBody = $this->templateService->getSubpart($this->moduleTemplate, '###FULLDOC###');
1309 // Add CSS
1310 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1311 // Get the page path for the docheader
1312 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1313 // Get the page info for the docheader
1314 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1315 // Get all the buttons for the docheader
1316 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1317 // Merge docheader buttons with the marker array
1318 $markerArray = array_merge($markerArray, $docHeaderButtons);
1319 // replacing subparts
1320 foreach ($subpartArray as $marker => $content) {
1321 $moduleBody = $this->templateService->substituteSubpart($moduleBody, $marker, $content);
1322 }
1323 // adding flash messages
1324 if ($this->showFlashMessages) {
1325 $flashMessages = $this->getFlashMessages();
1326 if (!empty($flashMessages)) {
1327 $markerArray['FLASHMESSAGES'] = $flashMessages;
1328 // If there is no dedicated marker for the messages present
1329 // then force them to appear before the content
1330 if (strpos($moduleBody, '###FLASHMESSAGES###') === false) {
1331 $moduleBody = str_replace('###CONTENT###', '###FLASHMESSAGES######CONTENT###', $moduleBody);
1332 }
1333 }
1334 }
1335 // Hook for adding more markers/content to the page, like the version selector
1336 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
1337 $params = array(
1338 'moduleTemplateFilename' => &$this->moduleTemplateFilename,
1339 'moduleTemplate' => &$this->moduleTemplate,
1340 'moduleBody' => &$moduleBody,
1341 'markers' => &$markerArray,
1342 'parentObject' => &$this
1343 );
1344 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
1345 GeneralUtility::callUserFunction($funcRef, $params, $this);
1346 }
1347 }
1348 // Replacing all markers with the finished markers and return the HTML content
1349 return $this->templateService->substituteMarkerArray($moduleBody, $markerArray, '###|###');
1350 }
1351
1352 /**
1353 * Get the default rendered FlashMessages from queue
1354 *
1355 * @return string
1356 */
1357 public function getFlashMessages()
1358 {
1359 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1360 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
1361 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1362 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1363 return $defaultFlashMessageQueue->renderFlashMessages();
1364 }
1365
1366 /**
1367 * Renders the FlashMessages from queue and returns them as AJAX.
1368 *
1369 * @param ServerRequestInterface $request
1370 * @param ResponseInterface $response
1371 * @return ResponseInterface
1372 */
1373 public function renderQueuedFlashMessages(ServerRequestInterface $request, ResponseInterface $response)
1374 {
1375 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1376 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
1377 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1378 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1379 $flashMessages = $defaultFlashMessageQueue->getAllMessagesAndFlush();
1380
1381 $messages = [];
1382 foreach ($flashMessages as $flashMessage) {
1383 $messages[] = [
1384 'title' => $flashMessage->getTitle(),
1385 'message' => $flashMessage->getMessage(),
1386 'severity' => $flashMessage->getSeverity()
1387 ];
1388 }
1389
1390 $response->getBody()->write(json_encode($messages));
1391 return $response;
1392 }
1393
1394 /**
1395 * Fill the button lists with the defined HTML
1396 *
1397 * @param array $buttons HTML for all buttons
1398 * @return array Containing HTML for both buttonlists
1399 */
1400 protected function getDocHeaderButtons($buttons)
1401 {
1402 $markers = array();
1403 // Fill buttons for left and right float
1404 $floats = array('left', 'right');
1405 foreach ($floats as $key) {
1406 // Get the template for each float
1407 $buttonTemplate = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1408 // Fill the button markers in this float
1409 $buttonTemplate = $this->templateService->substituteMarkerArray($buttonTemplate, $buttons, '###|###', true);
1410 // getting the wrap for each group
1411 $buttonWrap = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1412 // looping through the groups (max 6) and remove the empty groups
1413 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1414 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1415 $buttonGroup = $this->templateService->getSubpart($buttonTemplate, $buttonMarker);
1416 if (trim($buttonGroup)) {
1417 if ($buttonWrap) {
1418 $buttonGroup = $this->templateService->substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1419 }
1420 $buttonTemplate = $this->templateService->substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1421 }
1422 }
1423 // Replace the marker with the template and remove all line breaks (for IE compat)
1424 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
1425 }
1426 // Hook for manipulating docHeaderButtons
1427 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
1428 $params = array(
1429 'buttons' => $buttons,
1430 'markers' => &$markers,
1431 'pObj' => &$this
1432 );
1433 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
1434 GeneralUtility::callUserFunction($funcRef, $params, $this);
1435 }
1436 }
1437 return $markers;
1438 }
1439
1440 /**
1441 * Generate the page path for docheader
1442 *
1443 * @param array $pageRecord Current page
1444 * @return string Page path
1445 */
1446 protected function getPagePath($pageRecord)
1447 {
1448 // Is this a real page
1449 if (is_array($pageRecord) && $pageRecord['uid']) {
1450 $title = substr($pageRecord['_thePathFull'], 0, -1);
1451 // Remove current page title
1452 $pos = strrpos($title, $pageRecord['title']);
1453 if ($pos !== false) {
1454 $title = substr($title, 0, $pos);
1455 }
1456 } else {
1457 $title = '';
1458 }
1459 // Setting the path of the page
1460 $pagePath = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path')) . ': <span class="typo3-docheader-pagePath">';
1461 // crop the title to title limit (or 50, if not defined)
1462 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
1463 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
1464 if ($croppedTitle !== $title) {
1465 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
1466 } else {
1467 $pagePath .= htmlspecialchars($title);
1468 }
1469 $pagePath .= '</span>';
1470 return $pagePath;
1471 }
1472
1473 /**
1474 * Setting page icon with clickmenu + uid for docheader
1475 *
1476 * @param array $pageRecord Current page
1477 * @return string Page info
1478 */
1479 protected function getPageInfo($pageRecord)
1480 {
1481 // Add icon with clickmenu, etc:
1482 // If there IS a real page
1483 if (is_array($pageRecord) && $pageRecord['uid']) {
1484 $alttext = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
1485 $iconImg = '<span title="' . htmlspecialchars($alttext) . '">' . $this->iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
1486 // Make Icon:
1487 $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
1488 $uid = $pageRecord['uid'];
1489 $title = BackendUtility::getRecordTitle('pages', $pageRecord);
1490 } else {
1491 // On root-level of page tree
1492 // Make Icon
1493 $iconImg = '<span title="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '">' . $this->iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render() . '</span>';
1494 if ($GLOBALS['BE_USER']->user['admin']) {
1495 $theIcon = BackendUtility::wrapClickMenuOnIcon($iconImg, 'pages', 0);
1496 } else {
1497 $theIcon = $iconImg;
1498 }
1499 $uid = '0';
1500 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
1501 }
1502 // Setting icon with clickmenu + uid
1503 $pageInfo = $theIcon . '<strong>' . htmlspecialchars($title) . '&nbsp;[' . $uid . ']</strong>';
1504 return $pageInfo;
1505 }
1506
1507 /**
1508 * Retrieves configured favicon for backend (with fallback)
1509 *
1510 * @return string
1511 */
1512 protected function getBackendFavicon()
1513 {
1514 return PathUtility::getAbsoluteWebPath($GLOBALS['TBE_STYLES']['favicon'] ?: ExtensionManagementUtility::extPath('backend') . 'Resources/Public/Icons/favicon.ico');
1515 }
1516 }