[!!!][FEATURE] Introduce PSR-7-based Routing for Backend AJAX Requests
[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\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Page\PageRenderer;
24 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
25 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
26 use TYPO3\CMS\Core\Utility\GeneralUtility;
27 use TYPO3\CMS\Fluid\View\StandaloneView;
28
29 /**
30 * TYPO3 Backend Template Class
31 *
32 * This class contains functions for starting and ending the HTML of backend modules
33 * It also contains methods for outputting sections of content.
34 * Further there are functions for making icons, links, setting form-field widths etc.
35 * Color scheme and stylesheet definitions are also available here.
36 * Finally this file includes the language class for TYPO3's backend.
37 *
38 * After this file $LANG and $TBE_TEMPLATE are global variables / instances of their respective classes.
39 *
40 * Please refer to Inside TYPO3 for a discussion of how to use this API.
41 */
42 class DocumentTemplate {
43
44 // Vars you typically might want to/should set from outside after making instance of this class:
45 /**
46 * This can be set to the HTML-code for a formtag.
47 * Useful when you need a form to span the whole page; Inserted exactly after the body-tag.
48 *
49 * @var string
50 */
51 public $form = '';
52
53 /**
54 * Similar to $JScode (see below) but used as an associative array to prevent double inclusion of JS code.
55 * This is used to include certain external Javascript libraries before the inline JS code.
56 * <script>-Tags are not wrapped around automatically
57 *
58 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use pageRenderer directly
59 */
60 public $JScodeLibArray = array();
61
62 /**
63 * Additional header code (eg. a JavaScript section) could be accommulated in this var. It will be directly outputted in the header.
64 *
65 * @var string
66 */
67 public $JScode = '';
68
69 /**
70 * Additional header code for ExtJS. It will be included in document header and inserted in a Ext.onReady(function()
71 *
72 * @var string
73 */
74 public $extJScode = '';
75
76 /**
77 * 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.
78 *
79 * @var array
80 */
81 public $JScodeArray = array('jumpToUrl' => '
82 function jumpToUrl(URL) {
83 window.location.href = URL;
84 return false;
85 }
86 ');
87
88 /**
89 * 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.
90 *
91 * @var string
92 */
93 public $postCode = '';
94
95 /**
96 * Doc-type used in the header. Default is xhtml_trans. You can also set it to 'html_3', 'xhtml_strict' or 'xhtml_frames'.
97 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, as it is HTML5
98 */
99 public $docType = '';
100
101 /**
102 * HTML template with markers for module
103 *
104 * @var string
105 */
106 public $moduleTemplate = '';
107
108 /**
109 * The base file (not overlaid by TBE_STYLES) for the current module, useful for hooks when finding out which modules is rendered currently
110 *
111 * @var string
112 */
113 protected $moduleTemplateFilename = '';
114
115 /**
116 * Script ID
117 *
118 * @var string
119 */
120 public $scriptID = '';
121
122 /**
123 * Id which can be set for the body tag. Default value is based on script ID
124 *
125 * @var string
126 */
127 public $bodyTagId = '';
128
129 /**
130 * You can add additional attributes to the body-tag through this variable.
131 *
132 * @var string
133 */
134 public $bodyTagAdditions = '';
135
136 /**
137 * Additional CSS styles which will be added to the <style> section in the header
138 *
139 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use the pageRenderer property for adding CSS styles
140 */
141 public $inDocStyles = '';
142
143 /**
144 * Additional CSS styles which will be added to the <style> section in the header
145 * used as array with associative keys to prevent double inclusion of CSS code
146 *
147 * @var array
148 */
149 public $inDocStylesArray = array();
150
151 /**
152 * Compensation for large documents (used in \TYPO3\CMS\Backend\Form\FormEngine)
153 *
154 * @var float
155 */
156 public $form_largeComp = 1.33;
157
158 /**
159 * If set, then a JavaScript section will be outputted in the bottom of page which will try and update the top.busy session expiry object.
160 *
161 * @var int
162 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
163 */
164 public $endJS = 1;
165
166 // TYPO3 Colorscheme.
167 // If you want to change this, please do so through a skin using the global var $GLOBALS['TBE_STYLES']
168
169 /**
170 * Light background color
171 *
172 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
173 */
174 public $bgColor = '#F7F3EF';
175
176 /**
177 * Steel-blue
178 *
179 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
180 */
181 public $bgColor2 = '#9BA1A8';
182
183 /**
184 * dok.color
185 *
186 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
187 */
188 public $bgColor3 = '#F6F2E6';
189
190 /**
191 * light tablerow background, brownish
192 *
193 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
194 */
195 public $bgColor4 = '#D9D5C9';
196
197 /**
198 * light tablerow background, greenish
199 *
200 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
201 */
202 public $bgColor5 = '#ABBBB4';
203
204 /**
205 * light tablerow background, yellowish, for section headers. Light.
206 *
207 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
208 */
209 public $bgColor6 = '#E7DBA8';
210
211 /**
212 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
213 */
214 public $hoverColor = '#254D7B';
215
216 /**
217 * Filename of stylesheet (relative to PATH_typo3)
218 *
219 * @var string
220 */
221 public $styleSheetFile = '';
222
223 /**
224 * Filename of stylesheet #2 - linked to right after the $this->styleSheetFile script (relative to PATH_typo3)
225 *
226 * @var string
227 */
228 public $styleSheetFile2 = '';
229
230 /**
231 * Filename of a post-stylesheet - included right after all inline styles.
232 *
233 * @var string
234 */
235 public $styleSheetFile_post = '';
236
237 /**
238 * Background image of page (relative to PATH_typo3)
239 *
240 * @var string
241 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use a stylesheet instead
242 */
243 public $backGroundImage = '';
244
245 /**
246 * Inline css styling set from TBE_STYLES array
247 *
248 * @var string
249 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use inDocStylesArray['TBEstyle']
250 */
251 public $inDocStyles_TBEstyle = '';
252
253 /**
254 * Whether to use the X-UA-Compatible meta tag
255 *
256 * @var bool
257 */
258 protected $useCompatibilityTag = TRUE;
259
260 /**
261 * X-Ua-Compatible version output in meta tag
262 *
263 * @var string
264 */
265 protected $xUaCompatibilityVersion = 'IE=edge';
266
267 // Skinning
268 /**
269 * stylesheets from core
270 *
271 * @var array
272 */
273 protected $stylesheetsCore = array(
274 'generatedSprites' => '../typo3temp/sprites/'
275 );
276
277 /**
278 * Include these CSS directories from skins by default
279 *
280 * @var array
281 */
282 protected $stylesheetsSkins = array(
283 'structure' => 'Resources/Public/Css/structure/',
284 'visual' => 'Resources/Public/Css/visual/'
285 );
286
287 /**
288 * JavaScript files loaded for every page in the Backend
289 *
290 * @var array
291 */
292 protected $jsFiles = array();
293
294 /**
295 * JavaScript files loaded for every page in the Backend, but explicitly excluded from concatenation (useful for libraries etc.)
296 *
297 * @var array
298 */
299 protected $jsFilesNoConcatenation = array();
300
301 /**
302 * Will output the parsetime of the scripts in milliseconds (for admin-users).
303 * Set this to FALSE when releasing TYPO3. Only for dev.
304 *
305 * @var bool
306 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
307 */
308 public $parseTimeFlag = FALSE;
309
310 /**
311 * internal character set, nowadays utf-8 for everything
312 *
313 * @var string
314 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, as it is always utf-8
315 */
316 protected $charset = 'utf-8';
317
318 /**
319 * Indicates if a <div>-output section is open
320 *
321 * @var int
322 * @internal
323 */
324 public $sectionFlag = 0;
325
326 /**
327 * (Default) Class for wrapping <DIV>-tag of page. Is set in class extensions.
328 *
329 * @var string
330 */
331 public $divClass = '';
332
333 /**
334 * @var string
335 */
336 public $pageHeaderBlock = '';
337
338 /**
339 * @var string
340 */
341 public $endOfPageJsBlock = '';
342
343 /**
344 * @var bool
345 */
346 public $hasDocheader = TRUE;
347
348 /**
349 * @var PageRenderer
350 */
351 protected $pageRenderer = NULL;
352
353 /**
354 * Alternative template file
355 *
356 * @var string
357 */
358 protected $pageHeaderFooterTemplateFile = '';
359
360 /**
361 * @var bool
362 */
363 protected $extDirectStateProvider = FALSE;
364
365 /**
366 * Whether flashmessages should be rendered or not
367 *
368 * @var bool $showFlashMessages
369 */
370 public $showFlashMessages = TRUE;
371
372 /**
373 * @var IconFactory
374 */
375 protected $iconFactory;
376
377 /**
378 * @var MarkerBasedTemplateService
379 */
380 protected $templateService;
381
382 const STATUS_ICON_ERROR = 3;
383 const STATUS_ICON_WARNING = 2;
384 const STATUS_ICON_NOTIFICATION = 1;
385 const STATUS_ICON_OK = -1;
386
387 /**
388 * Constructor
389 */
390 public function __construct() {
391 // Initializes the page rendering object:
392 $this->initPageRenderer();
393
394 // load Legacy CSS Support
395 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyCssClasses');
396 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
397
398 // initialize Marker Support
399 $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
400
401 // Setting default scriptID:
402 if (($temp_M = (string)GeneralUtility::_GET('M')) && $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M]) {
403 $this->scriptID = preg_replace('/^.*\\/(sysext|ext)\\//', 'ext/', $GLOBALS['TBE_MODULES']['_PATHS'][$temp_M] . 'index.php');
404 } else {
405 $this->scriptID = preg_replace('/^.*\\/(sysext|ext)\\//', 'ext/', \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix(PATH_thisScript));
406 }
407 if (TYPO3_mainDir != 'typo3/' && substr($this->scriptID, 0, strlen(TYPO3_mainDir)) == TYPO3_mainDir) {
408 // This fixes if TYPO3_mainDir has been changed so the script ids are STILL "typo3/..."
409 $this->scriptID = 'typo3/' . substr($this->scriptID, strlen(TYPO3_mainDir));
410 }
411 $this->bodyTagId = preg_replace('/[^A-Za-z0-9-]/', '-', $this->scriptID);
412 // Individual configuration per script? If so, make a recursive merge of the arrays:
413 if (is_array($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID])) {
414 // Make copy
415 $ovr = $GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID];
416 // merge styles.
417 \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TBE_STYLES'], $ovr);
418 // Have to unset - otherwise the second instantiation will do it again!
419 unset($GLOBALS['TBE_STYLES']['scriptIDindex'][$this->scriptID]);
420 }
421 // Main Stylesheets:
422 if ($GLOBALS['TBE_STYLES']['stylesheet']) {
423 $this->styleSheetFile = $GLOBALS['TBE_STYLES']['stylesheet'];
424 }
425 if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
426 $this->styleSheetFile2 = $GLOBALS['TBE_STYLES']['stylesheet2'];
427 }
428 if ($GLOBALS['TBE_STYLES']['styleSheetFile_post']) {
429 $this->styleSheetFile_post = $GLOBALS['TBE_STYLES']['styleSheetFile_post'];
430 }
431 if ($GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle']) {
432 $this->inDocStylesArray['TBEstyle'] = $GLOBALS['TBE_STYLES']['inDocStyles_TBEstyle'];
433 }
434 // include all stylesheets
435 foreach ($this->getSkinStylesheetDirectories() as $stylesheetDirectory) {
436 $this->addStylesheetDirectory($stylesheetDirectory);
437 }
438 // Background image
439 if ($GLOBALS['TBE_STYLES']['background']) {
440 GeneralUtility::deprecationLog('Usage of $TBE_STYLES["background"] is deprecated. Please use stylesheets directly.');
441 }
442 }
443
444 /**
445 * Initializes the page renderer object
446 */
447 protected function initPageRenderer() {
448 if ($this->pageRenderer !== NULL) {
449 return;
450 }
451 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
452 $this->pageRenderer->setLanguage($GLOBALS['LANG']->lang);
453 $this->pageRenderer->enableConcatenateFiles();
454 $this->pageRenderer->enableCompressCss();
455 $this->pageRenderer->enableCompressJavascript();
456 // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
457 foreach ($this->jsFilesNoConcatenation as $file) {
458 $this->pageRenderer->addJsFile(
459 $GLOBALS['BACK_PATH'] . $file,
460 'text/javascript',
461 TRUE,
462 FALSE,
463 '',
464 TRUE
465 );
466 }
467 // Add all JavaScript files defined in $this->jsFiles to the PageRenderer
468 foreach ($this->jsFiles as $file) {
469 $this->pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . $file);
470 }
471 if ((int)$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] === 1) {
472 $this->pageRenderer->enableDebugMode();
473 }
474 }
475
476 /**
477 * Gets instance of PageRenderer configured with the current language, file references and debug settings
478 *
479 * @return PageRenderer
480 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8.
481 */
482 public function getPageRenderer() {
483 GeneralUtility::logDeprecatedFunction();
484 $this->initPageRenderer();
485
486 return $this->pageRenderer;
487 }
488
489 /**
490 * Sets inclusion of StateProvider
491 *
492 * @return void
493 */
494 public function setExtDirectStateProvider() {
495 $this->extDirectStateProvider = TRUE;
496 }
497
498 /*****************************************
499 *
500 * EVALUATION FUNCTIONS
501 * Various centralized processing
502 *
503 *****************************************/
504 /**
505 * Makes click menu link (context sensitive menu)
506 * Returns $str (possibly an <|img> tag/icon) wrapped in a link which will activate the context sensitive menu for the record ($table/$uid) or file ($table = file)
507 * The link will load the top frame with the parameter "&item" which is the table,uid and listFr arguments imploded by "|": rawurlencode($table.'|'.$uid.'|'.$listFr)
508 *
509 * @param string $str String to be wrapped in link, typ. image tag.
510 * @param string $table Table name/File path. If the icon is for a database record, enter the tablename from $GLOBALS['TCA']. If a file then enter the absolute filepath
511 * @param int $uid If icon is for database record this is the UID for the record from $table
512 * @param bool $listFr Tells the top frame script that the link is coming from a "list" frame which means a frame from within the backend content frame.
513 * @param string $addParams Additional GET parameters for the link to the ClickMenu AJAX request
514 * @param string $enDisItems Enable / Disable click menu items. Example: "+new,view" will display ONLY these two items (and any spacers in between), "new,view" will display all BUT these two items.
515 * @param bool $returnTagParameters If set, will return only the onclick JavaScript, not the whole link.
516 * @return string The link-wrapped input string.
517 */
518 public function wrapClickMenuOnIcon($content, $table, $uid = 0, $listFr = TRUE, $addParams = '', $enDisItems = '', $returnTagParameters = FALSE) {
519 $tagParameters = array(
520 'class' => 't3-js-clickmenutrigger',
521 'data-table' => $table,
522 'data-uid' => (int)$uid !== 0 ? (int)$uid : '',
523 'data-listframe' => $listFr,
524 'data-iteminfo' => str_replace('+', '%2B', $enDisItems),
525 'data-parameters' => $addParams,
526 );
527
528 if ($returnTagParameters) {
529 return $tagParameters;
530 } else {
531 return '<a href="#" ' . GeneralUtility::implodeAttributes($tagParameters, TRUE) . '>' . $content . '</a>';
532 }
533 }
534
535 /**
536 * Makes link to page $id in frontend (view page)
537 * Returns an icon which links to the frontend index.php document for viewing the page with id $id
538 * $id must be a page-uid
539 * If the BE_USER has access to Web>List then a link to that module is shown as well (with return-url)
540 *
541 * @param int $id The page id
542 * @param string $_ @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
543 * @return string HTML string with linked icon(s)
544 */
545 public function viewPageIcon($id, $_ = '') {
546 // If access to Web>List for user, then link to that module.
547 $str = BackendUtility::getListViewLink(array(
548 'id' => $id,
549 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
550 ), $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showList'));
551 // Make link to view page
552 $str .= '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($id, '', BackendUtility::BEgetRootLine($id))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL) . '</a>';
553 return $str;
554 }
555
556 /**
557 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
558 * See description of the API elsewhere.
559 *
560 * @param string $params is a set of GET params to send to tce_db.php. Example: "&cmd[tt_content][123][move]=456" or "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World
561 * @param string|int $redirectUrl Redirect URL, default is to use GeneralUtility::getIndpEnv('REQUEST_URI'), -1 means to generate an URL for JavaScript using T3_THIS_LOCATION
562 * @return string URL to BackendUtility::getModuleUrl('tce_db') + parameters
563 * @see \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick()
564 */
565 public function issueCommand($params, $redirectUrl = '') {
566 /** @var BackendUserAuthentication $beUser */
567 $beUser = $GLOBALS['BE_USER'];
568 $urlParameters = [
569 'prErr' => 1,
570 'uPT' => 1,
571 'vC' => $beUser->veriCode()
572 ];
573 $url = BackendUtility::getModuleUrl('tce_db', $urlParameters) . $params . '&redirect=';
574 if ((int)$redirectUrl === -1) {
575 $url = GeneralUtility::quoteJSvalue($url) . '+T3_THIS_LOCATION';
576 } else {
577 $url .= rawurlencode($redirectUrl ?: GeneralUtility::getIndpEnv('REQUEST_URI'));
578 }
579 return $url;
580 }
581
582 /**
583 * Makes the header (icon+title) for a page (or other record). Used in most modules under Web>*
584 * $table and $row must be a tablename/record from that table
585 * $path will be shown as alt-text for the icon.
586 * The title will be truncated to 45 chars.
587 *
588 * @param string $table Table name
589 * @param array $row Record row
590 * @param string $path Alt text
591 * @param bool $noViewPageIcon Set $noViewPageIcon TRUE if you don't want a magnifier-icon for viewing the page in the frontend
592 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
593 * @param bool $enableClickMenu If TRUE, render click menu code around icon image
594 * @return string HTML content
595 */
596 public function getHeader($table, $row, $path, $noViewPageIcon = FALSE, $tWrap = array('', ''), $enableClickMenu = TRUE) {
597 $viewPage = '';
598 if (is_array($row) && $row['uid']) {
599 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
600 $title = strip_tags(BackendUtility::getRecordTitle($table, $row));
601 $viewPage = $noViewPageIcon ? '' : $this->viewPageIcon($row['uid']);
602 } else {
603 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIcon('apps-pagetree-page-domain', Icon::SIZE_SMALL) . '</span>';
604 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
605 }
606
607 if ($enableClickMenu) {
608 $iconImgTag = $this->wrapClickMenuOnIcon($iconImgTag, $table, $row['uid']);
609 }
610
611 return '<span class="typo3-moduleHeader">' . $iconImgTag . $viewPage . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, 45)) . $tWrap[1] . '</span>';
612 }
613
614 /**
615 * Like ->getHeader() but for files and folders
616 * Returns the icon with the path of the file/folder set in the alt/title attribute. Shows the name after the icon.
617 *
618 * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resource
619 * @param array $tWrap is an array with indexes 0 and 1 each representing HTML-tags (start/end) which will wrap the title
620 * @param bool $enableClickMenu If TRUE, render click menu code around icon image
621 * @return string
622 */
623 public function getResourceHeader(\TYPO3\CMS\Core\Resource\ResourceInterface $resource, $tWrap = array('', ''), $enableClickMenu = TRUE) {
624 try {
625 $path = $resource->getStorage()->getName() . $resource->getParentFolder()->getIdentifier();
626 $iconImgTag = '<span title="' . htmlspecialchars($path) . '">' . $this->iconFactory->getIconForResource($resource, Icon::SIZE_SMALL) . '</span>';
627 } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $e) {
628 $iconImgTag = '';
629 }
630
631 if ($enableClickMenu && ($resource instanceof \TYPO3\CMS\Core\Resource\File)) {
632 $metaData = $resource->_getMetaData();
633 $iconImgTag = $this->wrapClickMenuOnIcon($iconImgTag, 'sys_file_metadata', $metaData['uid']);
634 }
635
636 return '<span class="typo3-moduleHeader">' . $iconImgTag . $tWrap[0] . htmlspecialchars(GeneralUtility::fixed_lgd_cs($resource->getName(), 45)) . $tWrap[1] . '</span>';
637 }
638
639 /**
640 * Returns a linked shortcut-icon which will call the shortcut frame and set a shortcut there back to the calling page/module
641 *
642 * @param string $gvList Is the list of GET variables to store (if any)
643 * @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
644 * @param string $modName Module name string
645 * @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.
646 * @return string HTML content
647 */
648 public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '') {
649 $storeUrl = $this->makeShortcutUrl($gvList, $setList);
650 $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
651 // Fallback for alt_mod. We still pass in the old xMOD... stuff, but TBE_MODULES only knows about "record_edit".
652 // We still need to pass the xMOD name to createShortcut below, since this is used for icons.
653 $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
654 // Add the module identifier automatically if typo3/index.php is used:
655 if (GeneralUtility::_GET('M') !== NULL && isset($GLOBALS['TBE_MODULES']['_PATHS'][$moduleName])) {
656 $storeUrl = '&M=' . $moduleName . $storeUrl;
657 }
658 if ((int)$motherModName === 1) {
659 $motherModule = 'top.currentModuleLoaded';
660 } elseif ($motherModName) {
661 $motherModule = GeneralUtility::quoteJSvalue($motherModName);
662 } else {
663 $motherModule = '\'\'';
664 }
665 $confirmationText = GeneralUtility::quoteJSvalue($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark'));
666
667 $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
668 $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
669
670 $icon = '<span>' . $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</span>';
671
672 if ($shortcutExist) {
673 return '<a class="active" title="">' . $icon . '</a>';
674 }
675
676 $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
677 $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
678 ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this);return false;';
679
680 return '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' .
681 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark', TRUE) . '">' . $icon . '</a>';
682 }
683
684 /**
685 * MAKE url for storing
686 * Internal func
687 *
688 * @param string $gvList Is the list of GET variables to store (if any)
689 * @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
690 * @return string
691 * @access private
692 * @see makeShortcutIcon()
693 */
694 public function makeShortcutUrl($gvList, $setList) {
695 $GET = GeneralUtility::_GET();
696 $storeArray = array_merge(GeneralUtility::compileSelectedGetVarsFromArray($gvList, $GET), array('SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)));
697 $storeUrl = GeneralUtility::implodeArrayForUrl('', $storeArray);
698 return $storeUrl;
699 }
700
701 /**
702 * Returns <input> attributes to set the width of an text-type input field.
703 * For client browsers with no CSS support the cols/size attribute is returned.
704 * For CSS compliant browsers (recommended) a ' style="width: ...px;"' is returned.
705 *
706 * @param int $size A relative number which multiplied with approx. 10 will lead to the width in pixels
707 * @param bool $textarea A flag you can set for textareas - DEPRECATED as there is no difference any more between the two
708 * @param string $styleOverride A string which will be returned as attribute-value for style="" instead of the calculated width (if CSS is enabled)
709 * @return string Tag attributes for an <input> tag (regarding width)
710 */
711 public function formWidth($size = 48, $textarea = FALSE, $styleOverride = '') {
712 return ' style="' . ($styleOverride ?: 'width:' . ceil($size * 9.58) . 'px;') . '"';
713 }
714
715 /**
716 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
717 * Used in fx. db_list.php (Web>List)
718 *
719 * @param string $thisLocation URL to "this location" / current script
720 * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
721 * @see typo3/db_list.php
722 */
723 public function redirectUrls($thisLocation = '') {
724 $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript(array(
725 'CB' => '',
726 'SET' => '',
727 'cmd' => '',
728 'popViewId' => ''
729 ));
730 $out = '
731 var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
732 var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
733 ';
734 return $out;
735 }
736
737 /**
738 * Returns a formatted string of $tstamp
739 * Uses $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'] and $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'] to format date and time
740 *
741 * @param int $tstamp UNIX timestamp, seconds since 1970
742 * @param int $type How much data to show: $type = 1: hhmm, $type = 10: ddmmmyy
743 * @return string Formatted timestamp
744 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use the corresponding methods in BackendUtility
745 */
746 public function formatTime($tstamp, $type) {
747 GeneralUtility::logDeprecatedFunction();
748 $dateStr = '';
749 switch ($type) {
750 case 1:
751 $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $tstamp);
752 break;
753 case 10:
754 $dateStr = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $tstamp);
755 break;
756 }
757 return $dateStr;
758 }
759
760 /**
761 * Returns script parsetime IF ->parseTimeFlag is set and user is "admin"
762 * Automatically outputted in page end
763 *
764 * @return string HTML formated with <p>-tags
765 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
766 */
767 public function parseTime() {
768 GeneralUtility::logDeprecatedFunction();
769 if ($this->parseTimeFlag && $GLOBALS['BE_USER']->isAdmin()) {
770 return '<p>(ParseTime: ' . (GeneralUtility::milliseconds() - $GLOBALS['PARSETIME_START']) . ' ms</p>
771 <p>REQUEST_URI-length: ' . strlen(GeneralUtility::getIndpEnv('REQUEST_URI')) . ')</p>';
772 }
773 }
774
775 /**
776 * Defines whether to use the X-UA-Compatible meta tag.
777 *
778 * @param bool $useCompatibilityTag Whether to use the tag
779 * @return void
780 */
781 public function useCompatibilityTag($useCompatibilityTag = TRUE) {
782 $this->useCompatibilityTag = (bool)$useCompatibilityTag;
783 }
784
785 /*****************************************
786 *
787 * PAGE BUILDING FUNCTIONS.
788 * Use this to build the HTML of your backend modules
789 *
790 *****************************************/
791 /**
792 * Returns page start
793 * This includes the proper header with charset, title, meta tag and beginning body-tag.
794 *
795 * @param string $title HTML Page title for the header
796 * @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)
797 * @see endPage()
798 */
799 public function startPage($title) {
800 // hook pre start page
801 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'])) {
802 $preStartPageHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preStartPageHook'];
803 if (is_array($preStartPageHook)) {
804 $hookParameters = array(
805 'title' => &$title
806 );
807 foreach ($preStartPageHook as $hookFunction) {
808 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
809 }
810 }
811 }
812 // alternative template for Header and Footer
813 if ($this->pageHeaderFooterTemplateFile) {
814 $file = GeneralUtility::getFileAbsFileName($this->pageHeaderFooterTemplateFile, TRUE);
815 if ($file) {
816 $this->pageRenderer->setTemplateFile($file);
817 }
818 }
819
820 // Disable rendering of XHTML tags
821 $this->pageRenderer->setRenderXhtml(FALSE);
822
823 $languageCode = $this->pageRenderer->getLanguage() === 'default' ? 'en' : $this->pageRenderer->getLanguage();
824 $this->pageRenderer->setHtmlTag('<html lang="' . $languageCode . '">');
825
826 $headerStart = '<!DOCTYPE html>';
827 $this->pageRenderer->setXmlPrologAndDocType($headerStart);
828 $this->pageRenderer->setHeadTag('<head>' . LF . '<!-- TYPO3 Script ID: ' . htmlspecialchars($this->scriptID) . ' -->');
829 header('Content-Type:text/html;charset=utf-8');
830 $this->pageRenderer->setCharSet('utf-8');
831 $this->pageRenderer->addMetaTag($this->generator());
832 $this->pageRenderer->addMetaTag('<meta name="robots" content="noindex,follow">');
833 $this->pageRenderer->addMetaTag('<meta charset="utf-8">');
834 $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
835 $this->pageRenderer->setFavIcon($this->getBackendFavicon());
836 if ($this->useCompatibilityTag) {
837 $this->pageRenderer->addMetaTag($this->xUaCompatible($this->xUaCompatibilityVersion));
838 }
839 $this->pageRenderer->setTitle($title);
840 // add docstyles
841 $this->docStyle();
842 if ($this->extDirectStateProvider) {
843 $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/ExtDirect.StateProvider.js');
844 }
845 // Add jsCode for overriding the console with a debug panel connection
846 $this->pageRenderer->addJsInlineCode('consoleOverrideWithDebugPanel', 'if (typeof top.Ext === "object") {
847 top.Ext.onReady(function() {
848 if (typeof console === "undefined") {
849 if (top && top.TYPO3 && top.TYPO3.Backend && top.TYPO3.Backend.DebugConsole) {
850 console = top.TYPO3.Backend.DebugConsole;
851 } else {
852 console = {
853 log: Ext.log,
854 info: Ext.log,
855 warn: Ext.log,
856 error: Ext.log
857 };
858 }
859 }
860 });
861 }
862 ', FALSE);
863 $this->pageRenderer->addHeaderData($this->JScode);
864 foreach ($this->JScodeArray as $name => $code) {
865 $this->pageRenderer->addJsInlineCode($name, $code, FALSE);
866 }
867 if (!empty($this->JScodeLibArray)) {
868 GeneralUtility::deprecationLog('DocumentTemplate->JScodeLibArray is deprecated since TYPO3 CMS 7. Use the functionality within pageRenderer directly');
869 foreach ($this->JScodeLibArray as $library) {
870 $this->pageRenderer->addHeaderData($library);
871 }
872 }
873 if ($this->extJScode) {
874 $this->pageRenderer->addExtOnReadyCode($this->extJScode);
875 }
876
877 // Load jquery and twbs JS libraries on every backend request
878 $this->pageRenderer->loadJquery();
879 // Note: please do not reference "bootstrap" outside of the TYPO3 Core (not in your own extensions)
880 // as this is preliminary as long as Twitter bootstrap does not support AMD modules
881 // this logic will be changed once Twitter bootstrap 4 is included
882 $this->pageRenderer->addJsFile('sysext/core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap.js');
883
884 // hook for additional headerData
885 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'])) {
886 $preHeaderRenderHook = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['preHeaderRenderHook'];
887 if (is_array($preHeaderRenderHook)) {
888 $hookParameters = array(
889 'pageRenderer' => &$this->pageRenderer
890 );
891 foreach ($preHeaderRenderHook as $hookFunction) {
892 GeneralUtility::callUserFunction($hookFunction, $hookParameters, $this);
893 }
894 }
895 }
896 // Construct page header.
897 $str = $this->pageRenderer->render(PageRenderer::PART_HEADER);
898 $this->JScode = ($this->extJScode = '');
899 $this->JScodeArray = array();
900 $this->endOfPageJsBlock = $this->pageRenderer->render(PageRenderer::PART_FOOTER);
901 $str .= $this->docBodyTagBegin() . ($this->divClass ? '
902
903 <!-- Wrapping DIV-section for whole page BEGIN -->
904 <div class="' . $this->divClass . '">
905 ' : '') . trim($this->form);
906 return $str;
907 }
908
909 /**
910 * Returns page end; This includes finishing form, div, body and html tags.
911 *
912 * @return string The HTML end of a page
913 * @see startPage()
914 */
915 public function endPage() {
916 $str = $this->sectionEnd() . $this->postCode . $this->wrapScriptTags(BackendUtility::getUpdateSignalCode()) . ($this->form ? '
917 </form>' : '');
918 // If something is in buffer like debug, put it to end of page
919 if (ob_get_contents()) {
920 $str .= ob_get_clean();
921 if (!headers_sent()) {
922 header('Content-Encoding: None');
923 }
924 }
925 $str .= ($this->divClass ? '
926
927 <!-- Wrapping DIV-section for whole page END -->
928 </div>' : '') . $this->endOfPageJsBlock;
929
930 // Logging: Can't find better place to put it:
931 if (TYPO3_DLOG) {
932 GeneralUtility::devLog('END of BACKEND session', \TYPO3\CMS\Backend\Template\DocumentTemplate::class, 0, array('_FLUSH' => TRUE));
933 }
934 return $str;
935 }
936
937 /**
938 * Shortcut for render the complete page of a module
939 *
940 * @param string $title page title
941 * @param string $content page content
942 * @return string complete page
943 */
944 public function render($title, $content) {
945 $pageContent = $this->startPage($title);
946 $pageContent .= $content;
947 $pageContent .= $this->endPage();
948 return $this->insertStylesAndJS($pageContent);
949 }
950
951 /**
952 * Returns the header-bar in the top of most backend modules
953 * Closes section if open.
954 *
955 * @param string $text The text string for the header
956 * @return string HTML content
957 */
958 public function header($text) {
959 $str = '
960
961 <!-- MAIN Header in page top -->
962 <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
963 ';
964 return $this->sectionEnd() . $str;
965 }
966
967 /**
968 * Begins an output section and sets header and content
969 *
970 * @param string $label The header
971 * @param string $text The HTML-content
972 * @param bool $nostrtoupper A flag that will prevent the header from being converted to uppercase
973 * @param bool $sH Defines the type of header (if set, "<h3>" rather than the default "h4")
974 * @param int $type The number of an icon to show with the header (see the icon-function). -1,1,2,3
975 * @param bool $allowHTMLinHeader If set, HTML tags are allowed in $label (otherwise this value is by default htmlspecialchars()'ed)
976 * @return string HTML content
977 * @see icons(), sectionHeader()
978 */
979 public function section($label, $text, $nostrtoupper = FALSE, $sH = FALSE, $type = 0, $allowHTMLinHeader = FALSE) {
980 $str = '';
981 // Setting header
982 if ($label) {
983 if (!$allowHTMLinHeader) {
984 $label = htmlspecialchars($label);
985 }
986 $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $nostrtoupper ? '' : ' class="uppercase"');
987 }
988 // Setting content
989 $str .= '
990
991 <!-- Section content -->
992 ' . $text;
993 return $this->sectionBegin() . $str;
994 }
995
996 /**
997 * Inserts a divider image
998 * Ends a section (if open) before inserting the image
999 *
1000 * @param int $dist The margin-top/-bottom of the <hr> ruler.
1001 * @return string HTML content
1002 */
1003 public function divider($dist) {
1004 $dist = (int)$dist;
1005 $str = '
1006
1007 <!-- DIVIDER -->
1008 <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
1009 ';
1010 return $this->sectionEnd() . $str;
1011 }
1012
1013 /**
1014 * Returns a blank <div>-section with a height
1015 *
1016 * @param int $dist Padding-top for the div-section (should be margin-top but konqueror (3.1) doesn't like it :-(
1017 * @return string HTML content
1018 */
1019 public function spacer($dist) {
1020 if ($dist > 0) {
1021 return '
1022
1023 <!-- Spacer element -->
1024 <div style="padding-top: ' . (int)$dist . 'px;"></div>
1025 ';
1026 }
1027 }
1028
1029 /**
1030 * Make a section header.
1031 * Begins a section if not already open.
1032 *
1033 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
1034 * @param bool $sH If set, <h3> is used, otherwise <h4>
1035 * @param string $addAttrib Additional attributes to h-tag, eg. ' class=""'
1036 * @return string HTML content
1037 */
1038 public function sectionHeader($label, $sH = FALSE, $addAttrib = '') {
1039 $tag = $sH ? 'h2' : 'h3';
1040 if ($addAttrib && $addAttrib[0] !== ' ') {
1041 $addAttrib = ' ' . $addAttrib;
1042 }
1043 $str = '
1044
1045 <!-- Section header -->
1046 <' . $tag . $addAttrib . '>' . $label . '</' . $tag . '>
1047 ';
1048 return $this->sectionBegin() . $str;
1049 }
1050
1051 /**
1052 * Begins an output section.
1053 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE (if the ->sectionFlag is not already set!)
1054 * 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!
1055 *
1056 * @return string HTML content
1057 */
1058 public function sectionBegin() {
1059 if (!$this->sectionFlag) {
1060 $this->sectionFlag = 1;
1061 $str = '
1062
1063 <!-- ***********************
1064 Begin output section.
1065 *********************** -->
1066 <div>
1067 ';
1068 return $str;
1069 } else {
1070 return '';
1071 }
1072 }
1073
1074 /**
1075 * Ends and output section
1076 * Returns the </div>-end tag AND clears the ->sectionFlag (but does so only IF the sectionFlag is set - that is a section is 'open')
1077 * See sectionBegin() also.
1078 *
1079 * @return string HTML content
1080 */
1081 public function sectionEnd() {
1082 if ($this->sectionFlag) {
1083 $this->sectionFlag = 0;
1084 return '
1085 </div>
1086 <!-- *********************
1087 End output section.
1088 ********************* -->
1089 ';
1090 } else {
1091 return '';
1092 }
1093 }
1094
1095 /**
1096 * If a form-tag is defined in ->form then and end-tag for that <form> element is outputted
1097 * Further a JavaScript section is outputted which will update the top.busy session-expiry object (unless $this->endJS is set to FALSE)
1098 *
1099 * @return string HTML content (<script> tag section)
1100 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, nothing there to output anymore
1101 */
1102 public function endPageJS() {
1103 GeneralUtility::logDeprecatedFunction();
1104 return '';
1105 }
1106
1107 /**
1108 * Creates the bodyTag.
1109 * You can add to the bodyTag by $this->bodyTagAdditions
1110 *
1111 * @return string HTML body tag
1112 */
1113 public function docBodyTagBegin() {
1114 return '<body ' . trim($this->bodyTagAdditions . ($this->bodyTagId ? ' id="' . $this->bodyTagId . '"' : '')) . '>';
1115 }
1116
1117 /**
1118 * Outputting document style
1119 *
1120 * @return string HTML style section/link tags
1121 */
1122 public function docStyle() {
1123 // Implode it all:
1124 $inDocStyles = implode(LF, $this->inDocStylesArray);
1125
1126 // Reset styles so they won't be added again in insertStylesAndJS()
1127 $this->inDocStylesArray = array();
1128
1129 if ($this->styleSheetFile) {
1130 $this->pageRenderer->addCssFile($this->styleSheetFile);
1131 }
1132 if ($this->styleSheetFile2) {
1133 $this->pageRenderer->addCssFile($this->styleSheetFile2);
1134 }
1135
1136 if ($inDocStyles !== '') {
1137 $this->pageRenderer->addCssInlineBlock('inDocStyles', $inDocStyles . LF . '/*###POSTCSSMARKER###*/');
1138 }
1139
1140 if ($this->styleSheetFile_post) {
1141 $this->pageRenderer->addCssFile($this->styleSheetFile_post);
1142 }
1143 }
1144
1145 /**
1146 * Insert additional style sheet link
1147 *
1148 * @param string $key some key identifying the style sheet
1149 * @param string $href uri to the style sheet file
1150 * @param string $title value for the title attribute of the link element
1151 * @param string $relation value for the rel attribute of the link element
1152 * @return void
1153 */
1154 public function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
1155 $this->pageRenderer->addCssFile($href, $relation, 'screen', $title);
1156 }
1157
1158 /**
1159 * Add all *.css files of the directory $path to the stylesheets
1160 *
1161 * @param string $path directory to add
1162 * @return void
1163 */
1164 public function addStyleSheetDirectory($path) {
1165 // Calculation needed, when TYPO3 source is used via a symlink
1166 // absolute path to the stylesheets
1167 $filePath = dirname(GeneralUtility::getIndpEnv('SCRIPT_FILENAME')) . '/' . $GLOBALS['BACK_PATH'] . $path;
1168 // Clean the path
1169 $resolvedPath = GeneralUtility::resolveBackPath($filePath);
1170 // Read all files in directory and sort them alphabetically
1171 $files = GeneralUtility::getFilesInDir($resolvedPath, 'css', FALSE, 1);
1172 foreach ($files as $file) {
1173 $this->pageRenderer->addCssFile($GLOBALS['BACK_PATH'] . $path . $file, 'stylesheet', 'all');
1174 }
1175 }
1176
1177 /**
1178 * Insert post rendering document style into already rendered content
1179 * This is needed for extobjbase
1180 *
1181 * @param string $content style-content to insert.
1182 * @return string content with inserted styles
1183 */
1184 public function insertStylesAndJS($content) {
1185 $styles = LF . implode(LF, $this->inDocStylesArray);
1186 $content = str_replace('/*###POSTCSSMARKER###*/', $styles, $content);
1187
1188 // Insert accumulated JS
1189 $jscode = $this->JScode . LF . $this->wrapScriptTags(implode(LF, $this->JScodeArray));
1190 $content = str_replace('<!--###POSTJSMARKER###-->', $jscode, $content);
1191 return $content;
1192 }
1193
1194 /**
1195 * Returns an array of all stylesheet directories belonging to core and skins
1196 *
1197 * @return array Stylesheet directories
1198 */
1199 public function getSkinStylesheetDirectories() {
1200 $stylesheetDirectories = array();
1201 // Add default core stylesheets
1202 foreach ($this->stylesheetsCore as $stylesheetDir) {
1203 $stylesheetDirectories[] = $stylesheetDir;
1204 }
1205 // Stylesheets from skins
1206 // merge default css directories ($this->stylesheetsSkin) with additional ones and include them
1207 if (is_array($GLOBALS['TBE_STYLES']['skins'])) {
1208 // loop over all registered skins
1209 foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
1210 $skinStylesheetDirs = $this->stylesheetsSkins;
1211 // Skins can add custom stylesheetDirectories using
1212 // $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
1213 if (is_array($skin['stylesheetDirectories'])) {
1214 $skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
1215 }
1216 // Add all registered directories
1217 foreach ($skinStylesheetDirs as $stylesheetDir) {
1218 // for EXT:myskin/stylesheets/ syntax
1219 if (substr($stylesheetDir, 0, 4) === 'EXT:') {
1220 list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
1221 if (!empty($extKey) && ExtensionManagementUtility::isLoaded($extKey) && !empty($path)) {
1222 $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($extKey) . $path;
1223 }
1224 } else {
1225 // For relative paths
1226 $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($skinExtKey) . $stylesheetDir;
1227 }
1228 }
1229 }
1230 }
1231 return $stylesheetDirectories;
1232 }
1233
1234 /**
1235 * Returns generator meta tag
1236 *
1237 * @return string <meta> tag with name "generator
1238 */
1239 public function generator() {
1240 $str = 'TYPO3 CMS, ' . TYPO3_URL_GENERAL . ', &#169; Kasper Sk&#229;rh&#248;j ' . TYPO3_copyright_year . ', extensions are copyright of their respective owners.';
1241 return '<meta name="generator" content="' . $str . '" />';
1242 }
1243
1244 /**
1245 * Returns X-UA-Compatible meta tag
1246 *
1247 * @param string $content Content of the compatible tag (default: IE-8)
1248 * @return string <meta http-equiv="X-UA-Compatible" content="???" />
1249 */
1250 public function xUaCompatible($content = 'IE=8') {
1251 return '<meta http-equiv="X-UA-Compatible" content="' . $content . '" />';
1252 }
1253
1254 /*****************************************
1255 *
1256 * OTHER ELEMENTS
1257 * Tables, buttons, formatting dimmed/red strings
1258 *
1259 ******************************************/
1260 /**
1261 * Returns an image-tag with an 18x16 icon of the following types:
1262 *
1263 * $type:
1264 * -1: OK icon (Check-mark)
1265 * 1: Notice (Speach-bubble)
1266 * 2: Warning (Yellow triangle)
1267 * 3: Fatal error (Red stop sign)
1268 *
1269 * @param int $type See description
1270 * @param string $styleAttribValue Value for style attribute
1271 * @return string HTML image tag (if applicable)
1272 */
1273 public function icons($type, $styleAttribValue = '') {
1274 switch ($type) {
1275 case self::STATUS_ICON_ERROR:
1276 $icon = 'status-dialog-error';
1277 break;
1278 case self::STATUS_ICON_WARNING:
1279 $icon = 'status-dialog-warning';
1280 break;
1281 case self::STATUS_ICON_NOTIFICATION:
1282 $icon = 'status-dialog-notification';
1283 break;
1284 case self::STATUS_ICON_OK:
1285 $icon = 'status-dialog-ok';
1286 break;
1287 default:
1288 // Do nothing
1289 }
1290 if ($icon) {
1291 return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
1292 }
1293 }
1294
1295 /**
1296 * Returns an <input> button with the $onClick action and $label
1297 *
1298 * @param string $onClick The value of the onclick attribute of the input tag (submit type)
1299 * @param string $label The label for the button (which will be htmlspecialchar'ed)
1300 * @return string A <input> tag of the type "submit
1301 */
1302 public function t3Button($onClick, $label) {
1303 $button = '<input class="btn btn-default" type="submit" onclick="' . htmlspecialchars($onClick) . '; return false;" value="' . htmlspecialchars($label) . '" />';
1304 return $button;
1305 }
1306
1307 /**
1308 * Dimmed-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be gray/dimmed
1309 *
1310 * @param string $string Input string
1311 * @return string Output string
1312 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use proper HTML directly
1313 */
1314 public function dfw($string) {
1315 GeneralUtility::logDeprecatedFunction();
1316 return '<span class="text-muted">' . $string . '</span>';
1317 }
1318
1319 /**
1320 * red-fontwrap. Returns the string wrapped in a <span>-tag defining the color to be red
1321 *
1322 * @param string $string Input string
1323 * @return string Output string
1324 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use proper HTML directly
1325 */
1326 public function rfw($string) {
1327 GeneralUtility::logDeprecatedFunction();
1328 return '<span class="text-danger">' . $string . '</span>';
1329 }
1330
1331 /**
1332 * Returns string wrapped in CDATA "tags" for XML / XHTML (wrap content of <script> and <style> sections in those!)
1333 *
1334 * @param string $string Input string
1335 * @return string Output string
1336 */
1337 public function wrapInCData($string) {
1338 $string = '/*<![CDATA[*/' . $string . '/*]]>*/';
1339 return $string;
1340 }
1341
1342 /**
1343 * Wraps the input string in script tags.
1344 * Automatic re-identing of the JS code is done by using the first line as ident reference.
1345 * This is nice for identing JS code with PHP code on the same level.
1346 *
1347 * @param string $string Input string
1348 * @param bool $linebreak Wrap script element in linebreaks? Default is TRUE.
1349 * @return string Output string
1350 */
1351 public function wrapScriptTags($string, $linebreak = TRUE) {
1352 if (trim($string)) {
1353 // <script wrapped in nl?
1354 $cr = $linebreak ? LF : '';
1355 // Remove nl from the beginning
1356 $string = ltrim($string, LF);
1357 // Re-ident to one tab using the first line as reference
1358 if ($string[0] === TAB) {
1359 $string = TAB . ltrim($string, TAB);
1360 }
1361 $string = $cr . '<script type="text/javascript">
1362 /*<![CDATA[*/
1363 ' . $string . '
1364 /*]]>*/
1365 </script>' . $cr;
1366 }
1367 return trim($string);
1368 }
1369
1370 // These vars defines the layout for the table produced by the table() function.
1371 // You can override these values from outside if you like.
1372 public $tableLayout = array(
1373 'defRow' => array(
1374 'defCol' => array('<td valign="top">', '</td>')
1375 )
1376 );
1377
1378 public $table_TR = '<tr>';
1379
1380 public $table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist" id="typo3-tmpltable">';
1381
1382 /**
1383 * Returns a table based on the input $data
1384 *
1385 * @param array $data Multidim array with first levels = rows, second levels = cells
1386 * @param array $layout If set, then this provides an alternative layout array instead of $this->tableLayout
1387 * @return string The HTML table.
1388 * @internal
1389 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1390 */
1391 public function table($data, $layout = NULL) {
1392 GeneralUtility::logDeprecatedFunction();
1393 $result = '';
1394 if (is_array($data)) {
1395 $tableLayout = is_array($layout) ? $layout : $this->tableLayout;
1396 $rowCount = 0;
1397 foreach ($data as $tableRow) {
1398 if ($rowCount % 2) {
1399 $layout = is_array($tableLayout['defRowOdd']) ? $tableLayout['defRowOdd'] : $tableLayout['defRow'];
1400 } else {
1401 $layout = is_array($tableLayout['defRowEven']) ? $tableLayout['defRowEven'] : $tableLayout['defRow'];
1402 }
1403 $rowLayout = is_array($tableLayout[$rowCount]) ? $tableLayout[$rowCount] : $layout;
1404 $rowResult = '';
1405 if (is_array($tableRow)) {
1406 $cellCount = 0;
1407 foreach ($tableRow as $tableCell) {
1408 $cellWrap = is_array($layout[$cellCount]) ? $layout[$cellCount] : $layout['defCol'];
1409 $cellWrap = is_array($rowLayout['defCol']) ? $rowLayout['defCol'] : $cellWrap;
1410 $cellWrap = is_array($rowLayout[$cellCount]) ? $rowLayout[$cellCount] : $cellWrap;
1411 $rowResult .= $cellWrap[0] . $tableCell . $cellWrap[1];
1412 $cellCount++;
1413 }
1414 }
1415 $rowWrap = is_array($layout['tr']) ? $layout['tr'] : array($this->table_TR, '</tr>');
1416 $rowWrap = is_array($rowLayout['tr']) ? $rowLayout['tr'] : $rowWrap;
1417 $result .= $rowWrap[0] . $rowResult . $rowWrap[1];
1418 $rowCount++;
1419 }
1420 $tableWrap = is_array($tableLayout['table']) ? $tableLayout['table'] : array($this->table_TABLE, '</table>');
1421 $result = $tableWrap[0] . $result . $tableWrap[1];
1422 }
1423 return $result;
1424 }
1425
1426 /**
1427 * Constructs a table with content from the $arr1, $arr2 and $arr3.
1428 *
1429 * @param array $arr1 Menu elements on first level
1430 * @param array $arr2 Secondary items
1431 * @param array $arr3 Third-level items
1432 * @return string HTML content, <table>...</table>
1433 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1434 */
1435 public function menuTable($arr1, $arr2 = array(), $arr3 = array()) {
1436 GeneralUtility::logDeprecatedFunction();
1437 $rows = max(array(count($arr1), count($arr2), count($arr3)));
1438 $menu = '
1439 <table border="0" cellpadding="0" cellspacing="0" id="typo3-tablemenu">';
1440 for ($a = 0; $a < $rows; $a++) {
1441 $menu .= '<tr>';
1442 $cls = array();
1443 $valign = 'middle';
1444 $cls[] = '<td valign="' . $valign . '">' . $arr1[$a][0] . '</td><td>' . $arr1[$a][1] . '</td>';
1445 if (!empty($arr2)) {
1446 $cls[] = '<td valign="' . $valign . '">' . $arr2[$a][0] . '</td><td>' . $arr2[$a][1] . '</td>';
1447 if (!empty($arr3)) {
1448 $cls[] = '<td valign="' . $valign . '">' . $arr3[$a][0] . '</td><td>' . $arr3[$a][1] . '</td>';
1449 }
1450 }
1451 $menu .= implode($cls, '<td>&nbsp;&nbsp;</td>');
1452 $menu .= '</tr>';
1453 }
1454 $menu .= '
1455 </table>
1456 ';
1457 return $menu;
1458 }
1459
1460 /**
1461 * Returns a one-row/two-celled table with $content and $menu side by side.
1462 * The table is a 100% width table and each cell is aligned left / right
1463 *
1464 * @param string $content Content cell content (left)
1465 * @param string $menu Menu cell content (right)
1466 * @return string HTML output
1467 */
1468 public function funcMenu($content, $menu) {
1469 return '
1470 <table border="0" cellpadding="0" cellspacing="0" width="100%" id="typo3-funcmenu">
1471 <tr>
1472 <td valign="top" nowrap="nowrap">' . $content . '</td>
1473 <td valign="top" align="right" nowrap="nowrap">' . $menu . '</td>
1474 </tr>
1475 </table>';
1476 }
1477
1478 /**
1479 * Includes a javascript library that exists in the core /typo3/ directory
1480 *
1481 * @param string $lib: Library name. Call it with the full path like "sysext/core/Resources/Public/JavaScript/QueryGenerator.js" to load it
1482 * @return void
1483 */
1484 public function loadJavascriptLib($lib) {
1485 // @todo: maybe we can remove this one as well
1486 $this->pageRenderer->addJsFile($lib);
1487 }
1488
1489 /**
1490 * Includes the necessary Javascript function for the clickmenu (context sensitive menus) in the document
1491 *
1492 * @return void
1493 */
1494 public function getContextMenuCode() {
1495 $this->pageRenderer->loadJquery();
1496 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
1497 }
1498
1499 /**
1500 * Includes the necessary javascript file for use on pages which have the
1501 * drag and drop functionality (legacy folder tree)
1502 *
1503 * @param string $table indicator of which table the drag and drop function should work on (pages or folders)
1504 * @param string $additionalJavaScriptCode adds more code to the additional javascript code
1505 * @return void
1506 */
1507 public function getDragDropCode($table, $additionalJavaScriptCode = '') {
1508 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function() {
1509 DragDrop.table = "' . $table . '";
1510 ' . $additionalJavaScriptCode . '
1511 }');
1512 }
1513
1514 /**
1515 * Creates a tab menu from an array definition
1516 *
1517 * Returns a tab menu for a module
1518 * Requires the JS function jumpToUrl() to be available
1519 *
1520 * @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=...
1521 * @param string $elementName it the form elements name, probably something like "SET[...]
1522 * @param string $currentValue is the value to be selected currently.
1523 * @param array $menuItems is an array with the menu items for the selector box
1524 * @param string $script is the script to send the &id to, if empty it's automatically found
1525 * @param string $addparams is additional parameters to pass to the script.
1526 * @return string HTML code for tab menu
1527 */
1528 public function getTabMenu($mainParams, $elementName, $currentValue, $menuItems, $script = '', $addparams = '') {
1529 $content = '';
1530 if (is_array($menuItems)) {
1531 if (!is_array($mainParams)) {
1532 $mainParams = array('id' => $mainParams);
1533 }
1534 $mainParams = GeneralUtility::implodeArrayForUrl('', $mainParams);
1535 if (!$script) {
1536 $script = basename(PATH_thisScript);
1537 }
1538 $menuDef = array();
1539 foreach ($menuItems as $value => $label) {
1540 $menuDef[$value]['isActive'] = (string)$currentValue === (string)$value;
1541 $menuDef[$value]['label'] = htmlspecialchars($label, ENT_COMPAT, 'UTF-8', FALSE);
1542 $menuDef[$value]['url'] = $script . '?' . $mainParams . $addparams . '&' . $elementName . '=' . $value;
1543 }
1544 $content = $this->getTabMenuRaw($menuDef);
1545 }
1546 return $content;
1547 }
1548
1549 /**
1550 * Creates the HTML content for the tab menu
1551 *
1552 * @param array $menuItems Menu items for tabs
1553 * @return string Table HTML
1554 * @access private
1555 */
1556 public function getTabMenuRaw($menuItems) {
1557 if (!is_array($menuItems)) {
1558 return '';
1559 }
1560
1561 $options = '';
1562 foreach ($menuItems as $id => $def) {
1563 $class = $def['isActive'] ? 'active' : '';
1564 $label = $def['label'];
1565 $url = htmlspecialchars($def['url']);
1566 $params = $def['addParams'];
1567
1568 $options .= '<li class="' . $class . '">' .
1569 '<a href="' . $url . '" ' . $params . '>' . $label . '</a>' .
1570 '</li>';
1571 }
1572
1573 return '<ul class="nav nav-tabs" role="tablist">' .
1574 $options .
1575 '</ul>';
1576
1577 }
1578
1579 /**
1580 * Creates a DYNAMIC tab-menu where the tabs or collapseable are rendered with bootstrap markup
1581 *
1582 * @param array $menuItems Numeric array where each entry is an array in itself with associative keys: "label" contains the label for the TAB, "content" contains the HTML content that goes into the div-layer of the tabs content. "description" contains description text to be shown in the layer. "linkTitle" is short text for the title attribute of the tab-menu link (mouse-over text of tab). "stateIcon" indicates a standard status icon (see ->icon(), values: -1, 1, 2, 3). "icon" is an image tag placed before the text.
1583 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1584 * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1 (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing) will result in no default tab open.
1585 * @param bool $collapseable If set, the tabs are rendered as headers instead over each sheet. Effectively this means there is no tab menu, but rather a foldout/foldin menu.
1586 * @param bool $wrapContent If set, the content is wrapped in div structure which provides a padding and border style. Set this FALSE to get unstyled content pane with fullsize content area.
1587 * @param bool $storeLastActiveTab If set, the last open tab is stored in local storage and will be re-open again. If you don't need this feature, e.g. for wizards like import/export you can disable this behaviour.
1588 * @return string
1589 */
1590 public function getDynamicTabMenu(array $menuItems, $identString, $defaultTabIndex = 1, $collapseable = FALSE, $wrapContent = TRUE, $storeLastActiveTab = TRUE) {
1591 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
1592 $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/' . ($collapseable ? 'Collapse.html' : 'Tabs.html');
1593 $view = GeneralUtility::makeInstance(StandaloneView::class);
1594 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
1595 $view->assignMultiple(array(
1596 'id' => $this->getDynTabMenuId($identString),
1597 'items' => $menuItems,
1598 'defaultTabIndex' => $defaultTabIndex,
1599 'wrapContent' => $wrapContent,
1600 'storeLastActiveTab' => $storeLastActiveTab,
1601 'BACK_PATH' => $GLOBALS['BACK_PATH']
1602 ));
1603 return $view->render();
1604 }
1605
1606 /**
1607 * Creates a DYNAMIC tab-menu where the tabs are switched between with DHTML.
1608 * Should work in MSIE, Mozilla, Opera and Konqueror. On Konqueror I did find a serious problem: <textarea> fields loose their content when you switch tabs!
1609 *
1610 * @param array $menuItems Numeric array where each entry is an array in itself with associative keys: "label" contains the label for the TAB, "content" contains the HTML content that goes into the div-layer of the tabs content. "description" contains description text to be shown in the layer. "linkTitle" is short text for the title attribute of the tab-menu link (mouse-over text of tab). "stateIcon" indicates a standard status icon (see ->icon(), values: -1, 1, 2, 3). "icon" is an image tag placed before the text.
1611 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1612 * @param int $toggle If "1", then enabling one tab does not hide the others - they simply toggles each sheet on/off. This makes most sense together with the $foldout option. If "-1" then it acts normally where only one tab can be active at a time BUT you can click a tab and it will close so you have no active tabs.
1613 * @param bool $foldout If set, the tabs are rendered as headers instead over each sheet. Effectively this means there is no tab menu, but rather a foldout/foldin menu. Make sure to set $toggle as well for this option.
1614 * @param bool $noWrap Deprecated - delivered by CSS
1615 * @param bool $fullWidth If set, the tabs will span the full width of their position
1616 * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1 (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing) will result in no default tab open.
1617 * @param int $tabBehaviour If set to '1' empty tabs will be remove, If set to '2' empty tabs will be disabled. setting this option to '2' is deprecated since TYPO3 CMS 7, and will be removed iwth CMS 8
1618 * @return string JavaScript section for the HTML header.
1619 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
1620 */
1621 public function getDynTabMenu($menuItems, $identString, $toggle = 0, $foldout = FALSE, $noWrap = TRUE, $fullWidth = FALSE, $defaultTabIndex = 1, $tabBehaviour = 1) {
1622 GeneralUtility::logDeprecatedFunction();
1623 return $this->getDynamicTabMenu($menuItems, $identString, $defaultTabIndex, $foldout, $noWrap);
1624 }
1625
1626 /**
1627 * Creates the id for dynTabMenus.
1628 *
1629 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
1630 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a
1631 */
1632 public function getDynTabMenuId($identString) {
1633 $id = 'DTM-' . GeneralUtility::shortMD5($identString);
1634 return $id;
1635 }
1636
1637 /**
1638 * Creates the version selector for the page id inputted.
1639 * Requires the core version management extension, "version" to be loaded.
1640 *
1641 * @param int $id Page id to create selector for.
1642 * @param bool $noAction If set, there will be no button for swapping page.
1643 * @return string
1644 */
1645 public function getVersionSelector($id, $noAction = FALSE) {
1646 if (
1647 ExtensionManagementUtility::isLoaded('version') &&
1648 !ExtensionManagementUtility::isLoaded('workspaces')
1649 ) {
1650 $versionGuiObj = GeneralUtility::makeInstance(\TYPO3\CMS\Version\View\VersionView::class);
1651 return $versionGuiObj->getVersionSelector($id, $noAction);
1652 }
1653 }
1654
1655 /**
1656 * Function to load a HTML template file with markers.
1657 * When calling from own extension, use syntax getHtmlTemplate('EXT:extkey/template.html')
1658 *
1659 * @param string $filename tmpl name, usually in the typo3/template/ directory
1660 * @return string HTML of template
1661 */
1662 public function getHtmlTemplate($filename) {
1663 // setting the name of the original HTML template
1664 $this->moduleTemplateFilename = $filename;
1665 if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
1666 $filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
1667 }
1668 if (GeneralUtility::isFirstPartOfStr($filename, 'EXT:')) {
1669 $filename = GeneralUtility::getFileAbsFileName($filename, TRUE, TRUE);
1670 } elseif (!GeneralUtility::isAbsPath($filename)) {
1671 $filename = GeneralUtility::resolveBackPath($filename);
1672 } elseif (!GeneralUtility::isAllowedAbsPath($filename)) {
1673 $filename = '';
1674 }
1675 $htmlTemplate = '';
1676 if ($filename !== '') {
1677 $htmlTemplate = GeneralUtility::getUrl($filename);
1678 }
1679 return $htmlTemplate;
1680 }
1681
1682 /**
1683 * Define the template for the module
1684 *
1685 * @param string $filename filename
1686 * @return void
1687 */
1688 public function setModuleTemplate($filename) {
1689 $this->moduleTemplate = $this->getHtmlTemplate($filename);
1690 }
1691
1692 /**
1693 * Put together the various elements for the module <body> using a static HTML
1694 * template
1695 *
1696 * @param array $pageRecord Record of the current page, used for page path and info
1697 * @param array $buttons HTML for all buttons
1698 * @param array $markerArray HTML for all other markers
1699 * @param array $subpartArray HTML for the subparts
1700 * @return string Composite HTML
1701 */
1702 public function moduleBody($pageRecord = array(), $buttons = array(), $markerArray = array(), $subpartArray = array()) {
1703 // Get the HTML template for the module
1704 $moduleBody = $this->templateService->getSubpart($this->moduleTemplate, '###FULLDOC###');
1705 // Add CSS
1706 $this->inDocStylesArray[] = 'html { overflow: hidden; }';
1707 // Get the page path for the docheader
1708 $markerArray['PAGEPATH'] = $this->getPagePath($pageRecord);
1709 // Get the page info for the docheader
1710 $markerArray['PAGEINFO'] = $this->getPageInfo($pageRecord);
1711 // Get all the buttons for the docheader
1712 $docHeaderButtons = $this->getDocHeaderButtons($buttons);
1713 // Merge docheader buttons with the marker array
1714 $markerArray = array_merge($markerArray, $docHeaderButtons);
1715 // replacing subparts
1716 foreach ($subpartArray as $marker => $content) {
1717 $moduleBody = $this->templateService->substituteSubpart($moduleBody, $marker, $content);
1718 }
1719 // adding flash messages
1720 if ($this->showFlashMessages) {
1721 $flashMessages = $this->getFlashMessages();
1722 if (!empty($flashMessages)) {
1723 $markerArray['FLASHMESSAGES'] = $flashMessages;
1724 // If there is no dedicated marker for the messages present
1725 // then force them to appear before the content
1726 if (strpos($moduleBody, '###FLASHMESSAGES###') === FALSE) {
1727 $moduleBody = str_replace('###CONTENT###', '###FLASHMESSAGES######CONTENT###', $moduleBody);
1728 }
1729 }
1730 }
1731 // Hook for adding more markers/content to the page, like the version selector
1732 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'])) {
1733 $params = array(
1734 'moduleTemplateFilename' => &$this->moduleTemplateFilename,
1735 'moduleTemplate' => &$this->moduleTemplate,
1736 'moduleBody' => &$moduleBody,
1737 'markers' => &$markerArray,
1738 'parentObject' => &$this
1739 );
1740 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['moduleBodyPostProcess'] as $funcRef) {
1741 GeneralUtility::callUserFunction($funcRef, $params, $this);
1742 }
1743 }
1744 // Replacing all markers with the finished markers and return the HTML content
1745 return $this->templateService->substituteMarkerArray($moduleBody, $markerArray, '###|###');
1746 }
1747
1748 /**
1749 * Get the default rendered FlashMessages from queue
1750 *
1751 * @return string
1752 */
1753 public function getFlashMessages() {
1754 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
1755 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
1756 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
1757 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
1758 return $defaultFlashMessageQueue->renderFlashMessages();
1759 }
1760
1761 /**
1762 * Renders the FlashMessages from queue and returns them as AJAX.
1763 *
1764 * @param ServerRequestInterface $request
1765 * @param ResponseInterface $response
1766 * @return ResponseInterface
1767 */
1768 public function renderQueuedFlashMessages(ServerRequestInterface $request, ResponseInterface $response) {
1769 $response->getBody()->write($this->getFlashMessages());
1770 return $response;
1771 }
1772
1773 /**
1774 * Fill the button lists with the defined HTML
1775 *
1776 * @param array $buttons HTML for all buttons
1777 * @return array Containing HTML for both buttonlists
1778 */
1779 protected function getDocHeaderButtons($buttons) {
1780 $markers = array();
1781 // Fill buttons for left and right float
1782 $floats = array('left', 'right');
1783 foreach ($floats as $key) {
1784 // Get the template for each float
1785 $buttonTemplate = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUPS_' . strtoupper($key) . '###');
1786 // Fill the button markers in this float
1787 $buttonTemplate = $this->templateService->substituteMarkerArray($buttonTemplate, $buttons, '###|###', TRUE);
1788 // getting the wrap for each group
1789 $buttonWrap = $this->templateService->getSubpart($this->moduleTemplate, '###BUTTON_GROUP_WRAP###');
1790 // looping through the groups (max 6) and remove the empty groups
1791 for ($groupNumber = 1; $groupNumber < 6; $groupNumber++) {
1792 $buttonMarker = '###BUTTON_GROUP' . $groupNumber . '###';
1793 $buttonGroup = $this->templateService->getSubpart($buttonTemplate, $buttonMarker);
1794 if (trim($buttonGroup)) {
1795 if ($buttonWrap) {
1796 $buttonGroup = $this->templateService->substituteMarker($buttonWrap, '###BUTTONS###', $buttonGroup);
1797 }
1798 $buttonTemplate = $this->templateService->substituteSubpart($buttonTemplate, $buttonMarker, trim($buttonGroup));
1799 }
1800 }
1801 // Replace the marker with the template and remove all line breaks (for IE compat)
1802 $markers['BUTTONLIST_' . strtoupper($key)] = str_replace(LF, '', $buttonTemplate);
1803 }
1804 // Hook for manipulating docHeaderButtons
1805 if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'])) {
1806 $params = array(
1807 'buttons' => $buttons,
1808 'markers' => &$markers,
1809 'pObj' => &$this
1810 );
1811 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook'] as $funcRef) {
1812 GeneralUtility::callUserFunction($funcRef, $params, $this);
1813 }
1814 }
1815 return $markers;
1816 }
1817
1818 /**
1819 * Generate the page path for docheader
1820 *
1821 * @param array $pageRecord Current page
1822 * @return string Page path
1823 */
1824 protected function getPagePath($pageRecord) {
1825 // Is this a real page
1826 if (is_array($pageRecord) && $pageRecord['uid']) {
1827 $title = substr($pageRecord['_thePathFull'], 0, -1);
1828 // Remove current page title
1829 $pos = strrpos($title, $pageRecord['title']);
1830 if ($pos !== FALSE) {
1831 $title = substr($title, 0, $pos);
1832 }
1833 } else {
1834 $title = '';
1835 }
1836 // Setting the path of the page
1837 $pagePath = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path', TRUE) . ': <span class="typo3-docheader-pagePath">';
1838 // crop the title to title limit (or 50, if not defined)
1839 $cropLength = empty($GLOBALS['BE_USER']->uc['titleLen']) ? 50 : $GLOBALS['BE_USER']->uc['titleLen'];
1840 $croppedTitle = GeneralUtility::fixed_lgd_cs($title, -$cropLength);
1841 if ($croppedTitle !== $title) {
1842 $pagePath .= '<abbr title="' . htmlspecialchars($title) . '">' . htmlspecialchars($croppedTitle) . '</abbr>';
1843 } else {
1844 $pagePath .= htmlspecialchars($title);
1845 }
1846 $pagePath .= '</span>';
1847 return $pagePath;
1848 }
1849
1850 /**
1851 * Setting page icon with clickmenu + uid for docheader
1852 *
1853 * @param array $pageRecord Current page
1854 * @return string Page info
1855 */
1856 protected function getPageInfo($pageRecord) {
1857 // Add icon with clickmenu, etc:
1858 // If there IS a real page
1859 if (is_array($pageRecord) && $pageRecord['uid']) {
1860 $alttext = BackendUtility::getRecordIconAltText($pageRecord, 'pages');
1861 $iconImg = '<span title="' . htmlspecialchars($alttext) . '">' . $this->iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
1862 // Make Icon:
1863 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', $pageRecord['uid']);
1864 $uid = $pageRecord['uid'];
1865 $title = BackendUtility::getRecordTitle('pages', $pageRecord);
1866 } else {
1867 // On root-level of page tree
1868 // Make Icon
1869 $iconImg = '<span title="' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '">' . $this->iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL) . '</span>';
1870 if ($GLOBALS['BE_USER']->user['admin']) {
1871 $theIcon = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconImg, 'pages', 0);
1872 } else {
1873 $theIcon = $iconImg;
1874 }
1875 $uid = '0';
1876 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
1877 }
1878 // Setting icon with clickmenu + uid
1879 $pageInfo = $theIcon . '<strong>' . htmlspecialchars($title) . '&nbsp;[' . $uid . ']</strong>';
1880 return $pageInfo;
1881 }
1882
1883 /**
1884 * Makes a collapseable section. See reports module for an example
1885 *
1886 * @param string $title
1887 * @param string $html
1888 * @param string $id
1889 * @param string $saveStatePointer
1890 * @return string
1891 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8. Use HTML bootstrap classes, localStorage etc.
1892 */
1893 public function collapseableSection($title, $html, $id, $saveStatePointer = '') {
1894 GeneralUtility::logDeprecatedFunction();
1895 $hasSave = (bool)$saveStatePointer;
1896 $collapsedStyle = ($collapsedClass = '');
1897 if ($hasSave) {
1898 /** @var $userSettingsController \TYPO3\CMS\Backend\Controller\UserSettingsController */
1899 $userSettingsController = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Controller\UserSettingsController::class);
1900 $value = $userSettingsController->process('get', $saveStatePointer . '.' . $id);
1901 if ($value) {
1902 $collapsedStyle = ' style="display: none"';
1903 $collapsedClass = ' collapsed';
1904 } else {
1905 $collapsedStyle = '';
1906 $collapsedClass = ' expanded';
1907 }
1908 }
1909 $this->pageRenderer->loadExtJS();
1910 $this->pageRenderer->addExtOnReadyCode('
1911 Ext.select("h2.section-header").each(function(element){
1912 element.on("click", function(event, tag) {
1913 var state = 0,
1914 el = Ext.fly(tag),
1915 div = el.next("div"),
1916 saveKey = el.getAttribute("rel");
1917 if (el.hasClass("collapsed")) {
1918 el.removeClass("collapsed").addClass("expanded");
1919 div.slideIn("t", {
1920 easing: "easeIn",
1921 duration: .5
1922 });
1923 } else {
1924 el.removeClass("expanded").addClass("collapsed");
1925 div.slideOut("t", {
1926 easing: "easeOut",
1927 duration: .5,
1928 remove: false,
1929 useDisplay: true
1930 });
1931 state = 1;
1932 }
1933 if (saveKey) {
1934 try {
1935 top.TYPO3.Storage.Persistent.set(saveKey + "." + tag.id, state);
1936 } catch(e) {}
1937 }
1938 });
1939 });
1940 ');
1941 return '
1942 <h2 id="' . $id . '" class="section-header' . $collapsedClass . '" rel="' . $saveStatePointer . '"> ' . $title . '</h2>
1943 <div' . $collapsedStyle . '>' . $html . '</div>
1944 ';
1945 }
1946
1947 /**
1948 * Retrieves configured favicon for backend (with fallback)
1949 *
1950 * @return string
1951 */
1952 protected function getBackendFavicon() {
1953 return $GLOBALS['TBE_STYLES']['favicon'] ?: 'sysext/backend/Resources/Public/Icons/favicon.ico';
1954 }
1955
1956 }