caf12a47c3984e0f61bced91a0a2d3509a4a51dd
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / ModuleTemplate.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 TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
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\Utility\ExtensionManagementUtility;
24 use TYPO3\CMS\Core\Utility\GeneralUtility;
25 use TYPO3\CMS\Fluid\View\Exception\InvalidTemplateResourceException;
26 use TYPO3\CMS\Fluid\View\StandaloneView;
27 use TYPO3\CMS\Lang\LanguageService;
28 use TYPO3\CMS\Version\View\VersionView;
29
30 /**
31 * A class taking care of the "outer" HTML of a module, especially
32 * the doc header and other related parts.
33 *
34 * @internal This API is not yet carved in stone and may be adapted later.
35 */
36 class ModuleTemplate
37 {
38 /**
39 * Error Icon Constant
40 *
41 * @internal
42 */
43 const STATUS_ICON_ERROR = 3;
44
45 /**
46 * Warning Icon Constant
47 *
48 * @internal
49 */
50 const STATUS_ICON_WARNING = 2;
51
52 /**
53 * Notification Icon Constant
54 *
55 * @internal
56 */
57 const STATUS_ICON_NOTIFICATION = 1;
58
59 /**
60 * OK Icon Constant
61 *
62 * @internal
63 */
64 const STATUS_ICON_OK = -1;
65
66 /**
67 * DocHeaderComponent
68 *
69 * @var DocHeaderComponent
70 */
71 protected $docHeaderComponent;
72
73 /**
74 * Javascript Code Array
75 * Used for inline JS
76 *
77 * @var array
78 */
79 protected $javascriptCodeArray = [];
80
81 /**
82 * Expose the pageRenderer
83 *
84 * @var PageRenderer
85 */
86 protected $pageRenderer;
87
88 /**
89 * TemplateRootPath
90 *
91 * @var string[]
92 */
93 protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];
94
95 /**
96 * PartialRootPath
97 *
98 * @var string[]
99 */
100 protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];
101
102 /**
103 * LayoutRootPath
104 *
105 * @var string[]
106 */
107 protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];
108
109 /**
110 * Template name
111 *
112 * @var string
113 */
114 protected $templateFile = 'Module.html';
115
116 /**
117 * Fluid Standalone View
118 *
119 * @var StandaloneView
120 */
121 protected $view;
122
123 /**
124 * Content String
125 *
126 * @var string
127 */
128 protected $content = '';
129
130 /**
131 * Defines whether a section has been opened before
132 *
133 * @var int
134 */
135 protected $sectionFlag = 0;
136
137 /**
138 * IconFactory Member
139 *
140 * @var IconFactory
141 */
142 protected $iconFactory;
143
144 /**
145 * Module ID
146 *
147 * @var string
148 */
149 protected $moduleId = '';
150
151 /**
152 * Module Name
153 *
154 * @var string
155 */
156 protected $moduleName = '';
157
158 /**
159 * Title Tag
160 *
161 * @var string
162 */
163 protected $title = '';
164
165 /**
166 * Gets the standalone view.
167 *
168 * @return StandaloneView
169 */
170 public function getView()
171 {
172 return $this->view;
173 }
174
175 /**
176 * Set content
177 *
178 * @param string $content Content of the module
179 * @return void
180 */
181 public function setContent($content)
182 {
183 $this->view->assign('content', $content);
184 }
185
186 /**
187 * Set title tag
188 *
189 * @param string $title
190 */
191 public function setTitle($title)
192 {
193 $this->title = $title;
194 }
195
196 /**
197 * Returns the IconFactory
198 *
199 * @return IconFactory
200 */
201 public function getIconFactory()
202 {
203 return $this->iconFactory;
204 }
205
206 /**
207 * Class constructor
208 * Sets up view and property objects
209 *
210 * @throws InvalidTemplateResourceException In case a template is invalid
211 */
212 public function __construct()
213 {
214 $this->view = GeneralUtility::makeInstance(StandaloneView::class);
215 $this->view->setPartialRootPaths($this->partialRootPaths);
216 $this->view->setTemplateRootPaths($this->templateRootPaths);
217 $this->view->setLayoutRootPaths($this->layoutRootPaths);
218 $this->view->setTemplate($this->templateFile);
219 $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
220 $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
221 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
222 }
223
224 /**
225 * Loads all necessary Javascript Files
226 *
227 * @return void
228 */
229 protected function loadJavaScripts()
230 {
231 $this->pageRenderer->loadJquery();
232 $this->pageRenderer->loadRequireJsModule('bootstrap');
233 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
234 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
235 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/SplitButtons');
236 }
237
238 /**
239 * Loads all necessary stylesheets
240 *
241 * @return void
242 */
243 protected function loadStylesheets()
244 {
245 if ($GLOBALS['TBE_STYLES']['stylesheet']) {
246 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
247 }
248 if ($GLOBALS['TBE_STYLES']['stylesheet2']) {
249 $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
250 }
251 }
252
253 /**
254 * Sets mandatory parameters for the view (pageRenderer)
255 *
256 * @return void
257 */
258 protected function setupPage()
259 {
260 // Yes, hardcoded on purpose
261 $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
262 $this->pageRenderer->setCharSet('utf-8');
263 $this->pageRenderer->setLanguage('default');
264 $this->pageRenderer->addMetaTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
265 }
266
267 /**
268 * Wrapper function for adding JS inline blocks
269 *
270 * @return void
271 */
272 protected function setJavaScriptCodeArray()
273 {
274 foreach ($this->javascriptCodeArray as $name => $code) {
275 $this->pageRenderer->addJsInlineCode($name, $code, false);
276 }
277 }
278
279 /**
280 * Adds JS inline blocks of code to the internal registry
281 *
282 * @param string $name Javascript code block name
283 * @param string $code Inline Javascript
284 *
285 * @return void
286 */
287 public function addJavaScriptCode($name = '', $code = '')
288 {
289 $this->javascriptCodeArray[$name] = $code;
290 }
291
292 /**
293 * Get the DocHeader
294 *
295 * @return DocHeaderComponent
296 */
297 public function getDocHeaderComponent()
298 {
299 return $this->docHeaderComponent;
300 }
301
302 /**
303 * Returns the fully rendered view
304 *
305 * @return string
306 */
307 public function renderContent()
308 {
309 $this->setupPage();
310 $this->pageRenderer->setTitle($this->title);
311 $this->loadJavaScripts();
312 $this->setJavaScriptCodeArray();
313 $this->loadStylesheets();
314
315 $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
316 if ($this->moduleId) {
317 $this->view->assign('moduleId', $this->moduleId);
318 }
319 if ($this->moduleName) {
320 $this->view->assign('moduleName', $this->moduleName);
321 }
322
323 $renderedPage = $this->pageRenderer->render(PageRenderer::PART_HEADER);
324 $renderedPage .= $this->view->render();
325 $renderedPage .= $this->pageRenderer->render(PageRenderer::PART_FOOTER);
326
327 return $renderedPage;
328 }
329
330 /**
331 * Get PageRenderer
332 *
333 * @return PageRenderer
334 */
335 public function getPageRenderer()
336 {
337 return $this->pageRenderer;
338 }
339
340 /**
341 * Set form tag
342 *
343 * @param string $formTag Form tag to add
344 *
345 * @return void
346 */
347 public function setForm($formTag = '')
348 {
349 $this->view->assign('formTag', $formTag);
350 }
351
352 /**
353 * Sets the ModuleId
354 *
355 * @param string $moduleId ID of the module
356 *
357 * @return void
358 */
359 public function setModuleId($moduleId)
360 {
361 $this->moduleId = $moduleId;
362 $this->registerModuleMenu($moduleId);
363 }
364
365 /**
366 * Sets the ModuleName
367 *
368 * @param string $moduleName Name of the module
369 *
370 * @return void
371 */
372 public function setModuleName($moduleName)
373 {
374 $this->moduleName = $moduleName;
375 }
376
377 /**
378 * Generates the Menu for things like Web->Info
379 *
380 * @param $moduleMenuIdentifier
381 */
382 public function registerModuleMenu($moduleMenuIdentifier)
383 {
384 if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
385 $menuEntries =
386 $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
387 $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
388 foreach ($menuEntries as $menuEntry) {
389 $menuItem = $menu->makeMenuItem()
390 ->setTitle($menuEntry['title'])
391 ->setHref('#');
392 $menu->addMenuItem($menuItem);
393 }
394 $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
395 }
396 }
397
398 /**
399 * Creates a DYNAMIC tab-menu where the tabs or collapsible are rendered with bootstrap markup
400 *
401 * @param array $menuItems Numeric array where each entry is an array in itself with associative keys: "label"
402 * contains the label for the TAB, "content" contains the HTML content that goes into the
403 * div-layer of the tabs content. "description" contains description text to be shown in the
404 * layer. "linkTitle" is short text for the title attribute of the tab-menu link (mouse-over
405 * text of tab). "stateIcon" indicates a standard status icon (see ->icon(),
406 * values: -1, 1, 2, 3). "icon" is an image tag placed before the text.
407 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
408 * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1
409 * (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing
410 * will result in no default tab open.
411 * @param bool $collapsible If set, the tabs are rendered as headers instead over each sheet. Effectively this means
412 * there is no tab menu, but rather a foldout/fold-in menu.
413 * @param bool $wrapContent If set, the content is wrapped in div structure which provides a padding and border
414 * style. Set this FALSE to get unstyled content pane with fullsize content area.
415 * @param bool $storeLastActiveTab If set, the last open tab is stored in local storage and will be re-open again.
416 * If you don't need this feature, e.g. for wizards like import/export you can
417 * disable this behaviour.
418 * @return string
419 */
420 public function getDynamicTabMenu(array $menuItems, $identString, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
421 {
422 $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
423 $templatePathAndFileName = 'EXT:backend/Resources/Private/Templates/DocumentTemplate/' . ($collapsible ? 'Collapse.html' : 'Tabs.html');
424 $view = GeneralUtility::makeInstance(StandaloneView::class);
425 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFileName));
426 $view->assignMultiple(array(
427 'id' => $this->getDynTabMenuId($identString),
428 'items' => $menuItems,
429 'defaultTabIndex' => $defaultTabIndex,
430 'wrapContent' => $wrapContent,
431 'storeLastActiveTab' => $storeLastActiveTab,
432 'BACK_PATH' => $GLOBALS['BACK_PATH']
433 ));
434 return $view->render();
435 }
436
437 /**
438 * Creates the id for dynTabMenus.
439 *
440 * @param string $identString Identification string. This should be unique for every instance of a dynamic menu!
441 * @return string The id with a short MD5 of $identString and prefixed "DTM-", like "DTM-2e8791854a
442 */
443 public function getDynTabMenuId($identString)
444 {
445 $id = 'DTM-' . GeneralUtility::shortMD5($identString);
446 return $id;
447 }
448
449
450
451 /*******************************************
452 * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
453 *
454 * These methods have been copied over from DocumentTemplate and enables
455 * core modules to drop the dependency to DocumentTemplate altogether without
456 * rewriting these modules now.
457 * The methods below are marked as internal and will be removed
458 * one-by-one with further refactoring of modules.
459 *
460 * Do not use these methods within own extensions if possible or
461 * be prepared to change this later again.
462 *******************************************/
463
464 /**
465 * Makes click menu link (context sensitive menu)
466 * Returns $str (possibly an <|img> tag/icon) wrapped in a link which will
467 * activate the context sensitive menu for the record ($table/$uid) or
468 * file ($table = file)
469 * The link will load the top frame with the parameter "&item" which is
470 * the table,uid and listFr arguments imploded
471 * by "|": rawurlencode($table.'|'.$uid.'|'.$listFr)
472 *
473 * @param string $content String to be wrapped in link, typ. image tag.
474 * @param string $table Table name/File path. If the icon is for a database
475 * record, enter the tablename from $GLOBALS['TCA']. If a file then enter
476 * the absolute filepath
477 * @param int $uid If icon is for database record this is the UID for the
478 * record from $table
479 * @param bool $listFr Tells the top frame script that the link is coming
480 * from a "list" frame which means a frame from within the backend content frame.
481 * @param string $addParams Additional GET parameters for the link to the
482 * ClickMenu AJAX request
483 * @param string $enDisItems Enable / Disable click menu items.
484 * Example: "+new,view" will display ONLY these two items (and any spacers
485 * in between), "new,view" will display all BUT these two items.
486 * @param bool $returnTagParameters If set, will return only the onclick
487 * JavaScript, not the whole link.
488 *
489 * @return string The link-wrapped input string.
490 * @internal
491 */
492 public function wrapClickMenuOnIcon(
493 $content,
494 $table,
495 $uid = 0,
496 $listFr = true,
497 $addParams = '',
498 $enDisItems = '',
499 $returnTagParameters = false
500 ) {
501 $tagParameters = array(
502 'class' => 't3-js-clickmenutrigger',
503 'data-table' => $table,
504 'data-uid' => (int)$uid !== 0 ? (int)$uid : '',
505 'data-listframe' => $listFr,
506 'data-iteminfo' => str_replace('+', '%2B', $enDisItems),
507 'data-parameters' => $addParams,
508 );
509
510 if ($returnTagParameters) {
511 return $tagParameters;
512 }
513 return '<a href="#" ' . GeneralUtility::implodeAttributes($tagParameters, true) . '>' . $content . '</a>';
514 }
515
516 /**
517 * Includes a javascript library that exists in the core /typo3/ directory
518 *
519 * @param string $lib Library name. Call it with the full path like
520 * "sysext/core/Resources/Public/JavaScript/QueryGenerator.js" to load it
521 *
522 * @return void
523 * @internal
524 */
525 public function loadJavascriptLib($lib)
526 {
527 // @todo: maybe we can remove this one as well
528 $this->pageRenderer->addJsFile($lib);
529 }
530
531 /**
532 * Returns a linked shortcut-icon which will call the shortcut frame and set a
533 * shortcut there back to the calling page/module
534 *
535 * @param string $gvList Is the list of GET variables to store (if any)
536 * @param string $setList Is the list of SET[] variables to store
537 * (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS
538 * for backend modules
539 * @param string $modName Module name string
540 * @param string|int $motherModName Is used to enter the "parent module
541 * name" if the module is a submodule under eg. Web>* or File>*. You
542 * can also set this value to 1 in which case the currentLoadedModule
543 * is sent to the shortcut script (so - not a fixed value!) - that is used
544 * in file_edit and wizard_rte modules where those are really running as
545 * a part of another module.
546 *
547 * @return string HTML content
548 * @todo Make this thing return a button object
549 * @internal
550 */
551 public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '')
552 {
553 $storeUrl = $this->makeShortcutUrl($gvList, $setList);
554 $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
555 // Fallback for alt_mod. We still pass in the old xMOD... stuff,
556 // but TBE_MODULES only knows about "record_edit".
557 // We still need to pass the xMOD name to createShortcut below,
558 // since this is used for icons.
559 $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
560 // Add the module identifier automatically if typo3/index.php is used:
561 if (GeneralUtility::_GET('M') !== null && isset($GLOBALS['TBE_MODULES']['_PATHS'][$moduleName])) {
562 $storeUrl = '&M=' . $moduleName . $storeUrl;
563 }
564 if ((int)$motherModName === 1) {
565 $motherModule = 'top.currentModuleLoaded';
566 } elseif ($motherModName) {
567 $motherModule = GeneralUtility::quoteJSvalue($motherModName);
568 } else {
569 $motherModule = '\'\'';
570 }
571 $confirmationText = GeneralUtility::quoteJSvalue(
572 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark')
573 );
574
575 $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
576 $shortcutExist = BackendUtility::shortcutExists($shortcutUrl);
577
578 if ($shortcutExist) {
579 return '<a class="active" title="">' .
580 $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
581 }
582
583 $url = GeneralUtility::quoteJSvalue(rawurlencode($shortcutUrl));
584 $onClick = 'top.TYPO3.ShortcutMenu.createShortcut(' . GeneralUtility::quoteJSvalue(rawurlencode($modName)) .
585 ', ' . $url . ', ' . $confirmationText . ', ' . $motherModule . ', this);return false;';
586
587 return '<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="' .
588 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.makeBookmark', true) . '">' .
589 $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
590 }
591
592 /**
593 * MAKE url for storing
594 * Internal func
595 *
596 * @param string $gvList Is the list of GET variables to store (if any)
597 * @param string $setList Is the list of SET[] variables to store (if any)
598 * - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend
599 * modules
600 *
601 * @return string
602 * @internal
603 */
604 public function makeShortcutUrl($gvList, $setList)
605 {
606 $getParams = GeneralUtility::_GET();
607 $storeArray = array_merge(
608 GeneralUtility::compileSelectedGetVarsFromArray($gvList, $getParams),
609 array('SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS))
610 );
611 return GeneralUtility::implodeArrayForUrl('', $storeArray);
612 }
613
614 /**
615 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
616 * See description of the API elsewhere.
617 *
618 * @param string $params Is a set of GET params to send to tce_db.php.
619 * Example: "&cmd[tt_content][123][move]=456" or
620 * "&data[tt_content][123][hidden]=1&data[tt_content][123][title]=Hello%20World
621 * @param string|int $redirectUrl Redirect URL, default is to use
622 * GeneralUtility::getIndpEnv('REQUEST_URI'), -1 means to generate
623 * an URL for JavaScript using T3_THIS_LOCATION
624 *
625 * @return string URL to BackendUtility::getModuleUrl('tce_db') + parameters
626 * @internal
627 */
628 public function issueCommand($params, $redirectUrl = '')
629 {
630 $urlParameters = [
631 'prErr' => 1,
632 'uPT' => 1,
633 'vC' => $this->getBackendUserAuthentication()->veriCode()
634 ];
635 $url = BackendUtility::getModuleUrl('tce_db', $urlParameters) . $params . '&redirect=';
636 if ((int)$redirectUrl === -1) {
637 $url = GeneralUtility::quoteJSvalue($url) . '+T3_THIS_LOCATION';
638 } else {
639 $url .= rawurlencode($redirectUrl ?: GeneralUtility::getIndpEnv('REQUEST_URI'));
640 }
641 return $url;
642 }
643
644 /**
645 * Creates the version selector for the page id inputted.
646 * Requires the core version management extension, "version" to be loaded.
647 *
648 * @param int $id Page id to create selector for.
649 * @param bool $noAction If set, there will be no button for swapping page.
650 *
651 * @return string
652 * @internal
653 */
654 public function getVersionSelector($id, $noAction = false)
655 {
656 if (ExtensionManagementUtility::isLoaded('version')
657 && !ExtensionManagementUtility::isLoaded('workspaces')
658 ) {
659 /**
660 * For Code Completion
661 *
662 * @var $versionGuiObj VersionView
663 */
664 $versionGuiObj = GeneralUtility::makeInstance(VersionView::class);
665 return $versionGuiObj->getVersionSelector($id, $noAction);
666 }
667 return '';
668 }
669
670 /**
671 * Begins an output section and sets header and content
672 *
673 * @param string $label The header
674 * @param string $text The HTML-content
675 * @param bool $noStrToUpper A flag that will prevent the header from
676 * being converted to uppercase
677 * @param bool $sH Defines the type of header (if set, "<h3>" rather
678 * than the default "h4")
679 * @param int $type The number of an icon to show with the header
680 * (see the icon-function). -1,1,2,3
681 * @param bool $allowHtmlInHeader If set, HTML tags are allowed in
682 * $label (otherwise this value is by default htmlspecialchars()'ed)
683 *
684 * @return string HTML content
685 * @internal
686 */
687 public function section($label, $text, $noStrToUpper = false, $sH = false, $type = 0, $allowHtmlInHeader = false)
688 {
689 $str = '';
690 // Setting header
691 if ($label) {
692 if (!$allowHtmlInHeader) {
693 $label = htmlspecialchars($label);
694 }
695 $str .= $this->sectionHeader($this->icons($type) . $label, $sH, $noStrToUpper ? '' : ' class="uppercase"');
696 }
697 // Setting content
698 $str .= '
699
700 <!-- Section content -->
701 ' . $text;
702 return $this->sectionBegin() . $str;
703 }
704
705 /**
706 * Inserts a divider image
707 * Ends a section (if open) before inserting the image
708 *
709 * @param int $dist The margin-top/-bottom of the <hr> ruler.
710 *
711 * @return string HTML content
712 * @internal
713 */
714 public function divider($dist)
715 {
716 $dist = (int)$dist;
717 $str = '
718
719 <!-- DIVIDER -->
720 <hr style="margin-top: ' . $dist . 'px; margin-bottom: ' . $dist . 'px;" />
721 ';
722 return $this->sectionEnd() . $str;
723 }
724
725 /**
726 * Returns a blank <div>-section with a height
727 *
728 * @param int $dist Padding-top for the div-section
729 *
730 * @return string HTML content
731 * @internal
732 */
733 public function spacer($dist)
734 {
735 if ($dist > 0) {
736 return '
737
738 <!-- Spacer element -->
739 <div style="padding-top: ' . (int)$dist . 'px;"></div>
740 ';
741 }
742 return '';
743 }
744
745 /**
746 * Make a section header.
747 * Begins a section if not already open.
748 *
749 * @param string $label The label between the <h3> or <h4> tags. (Allows HTML)
750 * @param bool $sH If set, <h3> is used, otherwise <h4>
751 * @param string $addAttribute Additional attributes to h-tag, eg. ' class=""'
752 *
753 * @return string HTML content
754 * @internal
755 */
756 public function sectionHeader($label, $sH = false, $addAttribute = '')
757 {
758 $tag = $sH ? 'h2' : 'h3';
759 if ($addAttribute && $addAttribute[0] !== ' ') {
760 $addAttribute = ' ' . $addAttribute;
761 }
762 $str = '
763
764 <!-- Section header -->
765 <' . $tag . $addAttribute . '>' . $label . '</' . $tag . '>
766 ';
767 return $this->sectionBegin() . $str;
768 }
769
770 /**
771 * Begins an output section.
772 * Returns the <div>-begin tag AND sets the ->sectionFlag TRUE
773 * (if the ->sectionFlag is not already set!)
774 * You can call this function even if a section is already begun
775 * since the function will only return something if the sectionFlag
776 * is not already set!
777 *
778 * @return string HTML content
779 * @internal
780 */
781 public function sectionBegin()
782 {
783 if (!$this->sectionFlag) {
784 $this->sectionFlag = 1;
785 $str = '
786
787 <!-- ***********************
788 Begin output section.
789 *********************** -->
790 <div>
791 ';
792 return $str;
793 }
794 return '';
795 }
796
797 /**
798 * Ends and output section
799 * Returns the </div>-end tag AND clears the ->sectionFlag
800 * (but does so only IF the sectionFlag is set - that is a section is 'open')
801 * See sectionBegin() also.
802 *
803 * @return string HTML content
804 * @internal
805 */
806 public function sectionEnd()
807 {
808 if ($this->sectionFlag) {
809 $this->sectionFlag = 0;
810 return '
811 </div>
812 <!-- *********************
813 End output section.
814 ********************* -->
815 ';
816 }
817 return '';
818 }
819
820
821
822 /**
823 * Returns the BE USER Object
824 *
825 * @return BackendUserAuthentication
826 */
827 protected function getBackendUserAuthentication()
828 {
829 return $GLOBALS['BE_USER'];
830 }
831
832 /**
833 * Returns the LanguageService
834 *
835 * @return LanguageService
836 */
837 protected function getLanguageService()
838 {
839 return $GLOBALS['LANG'];
840 }
841
842 /**
843 * Returns an image-tag with an 18x16 icon of the following types:
844 *
845 * $type:
846 * -1:» OK icon (Check-mark)
847 * 1:» Notice (Speach-bubble)
848 * 2:» Warning (Yellow triangle)
849 * 3:» Fatal error (Red stop sign)
850 *
851 * @param int $type See description
852 *
853 * @return string HTML image tag (if applicable)
854 * @internal
855 */
856 public function icons($type)
857 {
858 $icon = '';
859 switch ($type) {
860 case self::STATUS_ICON_ERROR:
861 $icon = 'status-dialog-error';
862 break;
863 case self::STATUS_ICON_WARNING:
864 $icon = 'status-dialog-warning';
865 break;
866 case self::STATUS_ICON_NOTIFICATION:
867 $icon = 'status-dialog-notification';
868 break;
869 case self::STATUS_ICON_OK:
870 $icon = 'status-dialog-ok';
871 break;
872 default:
873 // Do nothing
874 }
875 if ($icon != '') {
876 return $this->iconFactory->getIcon($icon, Icon::SIZE_SMALL)->render();
877 }
878 return '';
879 }
880
881 /**
882 * Returns JavaScript variables setting the returnUrl and thisScript location for use by JavaScript on the page.
883 * Used in fx. db_list.php (Web>List)
884 *
885 * @param string $thisLocation URL to "this location" / current script
886 * @return string Urls are returned as JavaScript variables T3_RETURN_URL and T3_THIS_LOCATION
887 * @see typo3/db_list.php
888 * @internal
889 */
890 public function redirectUrls($thisLocation = '')
891 {
892 $thisLocation = $thisLocation ? $thisLocation : GeneralUtility::linkThisScript(array(
893 'CB' => '',
894 'SET' => '',
895 'cmd' => '',
896 'popViewId' => ''
897 ));
898 $out = '
899 var T3_RETURN_URL = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode(GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'))))) . ';
900 var T3_THIS_LOCATION = ' . GeneralUtility::quoteJSvalue(str_replace('%20', '', rawurlencode($thisLocation))) . '
901 ';
902 return $out;
903 }
904
905 /**
906 * Returns the header-bar in the top of most backend modules
907 * Closes section if open.
908 *
909 * @param string $text The text string for the header
910 * @return string HTML content
911 * @internal
912 */
913 public function header($text)
914 {
915 $str = '
916
917 <!-- MAIN Header in page top -->
918 <h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
919 ';
920 return $this->sectionEnd() . $str;
921 }
922 }