Passed
Push — master ( 62e46d...e4833f )
by
unknown
15:08
created

ModuleTemplate::getBackendUserAuthentication()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the TYPO3 CMS project.
5
 *
6
 * It is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License, either version 2
8
 * of the License, or any later version.
9
 *
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 *
13
 * The TYPO3 project - inspiring people to share!
14
 */
15
16
namespace TYPO3\CMS\Backend\Template;
17
18
use TYPO3\CMS\Backend\Backend\Shortcut\ShortcutRepository;
19
use TYPO3\CMS\Backend\Routing\Router;
20
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
21
use TYPO3\CMS\Backend\Utility\BackendUtility;
22
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
23
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
24
use TYPO3\CMS\Core\Imaging\Icon;
25
use TYPO3\CMS\Core\Imaging\IconFactory;
26
use TYPO3\CMS\Core\Localization\LanguageService;
27
use TYPO3\CMS\Core\Messaging\AbstractMessage;
28
use TYPO3\CMS\Core\Messaging\FlashMessage;
29
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
30
use TYPO3\CMS\Core\Messaging\FlashMessageService;
31
use TYPO3\CMS\Core\Page\PageRenderer;
32
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
33
use TYPO3\CMS\Core\Utility\GeneralUtility;
34
use TYPO3\CMS\Core\Utility\HttpUtility;
35
use TYPO3\CMS\Core\Utility\PathUtility;
36
use TYPO3\CMS\Fluid\View\StandaloneView;
37
use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
38
39
/**
40
 * A class taking care of the "outer" HTML of a module, especially
41
 * the doc header and other related parts.
42
 */
43
class ModuleTemplate
44
{
45
    /**
46
     * DocHeaderComponent
47
     *
48
     * @var DocHeaderComponent
49
     */
50
    protected $docHeaderComponent;
51
52
    /**
53
     * Javascript Code Array
54
     * Used for inline JS
55
     *
56
     * @var array
57
     */
58
    protected $javascriptCodeArray = [];
59
60
    /**
61
     * Expose the pageRenderer
62
     *
63
     * @var PageRenderer
64
     */
65
    protected $pageRenderer;
66
67
    /**
68
     * @var bool
69
     */
70
    protected $uiBlock = false;
71
72
    /**
73
     * TemplateRootPath
74
     *
75
     * @var string[]
76
     */
77
    protected $templateRootPaths = ['EXT:backend/Resources/Private/Templates'];
78
79
    /**
80
     * PartialRootPath
81
     *
82
     * @var string[]
83
     */
84
    protected $partialRootPaths = ['EXT:backend/Resources/Private/Partials'];
85
86
    /**
87
     * LayoutRootPath
88
     *
89
     * @var string[]
90
     */
91
    protected $layoutRootPaths = ['EXT:backend/Resources/Private/Layouts'];
92
93
    /**
94
     * Template name
95
     *
96
     * @var string
97
     */
98
    protected $templateFile = 'Module.html';
99
100
    /**
101
     * Fluid Standalone View
102
     *
103
     * @var StandaloneView
104
     */
105
    protected $view;
106
107
    /**
108
     * Content String
109
     *
110
     * @var string
111
     */
112
    protected $content = '';
113
114
    /**
115
     * IconFactory Member
116
     *
117
     * @var IconFactory
118
     */
119
    protected $iconFactory;
120
121
    /**
122
     * @var FlashMessageService
123
     */
124
    protected $flashMessageService;
125
126
    /**
127
     * Module ID
128
     *
129
     * @var string
130
     */
131
    protected $moduleId = '';
132
133
    /**
134
     * Module Name
135
     *
136
     * @var string
137
     */
138
    protected $moduleName = '';
139
140
    /**
141
     * Title Tag
142
     *
143
     * @var string
144
     */
145
    protected $title = '';
146
147
    /**
148
     * Body Tag
149
     *
150
     * @var string
151
     */
152
    protected $bodyTag = '<body>';
153
154
    /**
155
     * Flash message queue
156
     *
157
     * @var FlashMessageQueue
158
     */
159
    protected $flashMessageQueue;
160
161
    /**
162
     * Returns the current body tag
163
     *
164
     * @return string
165
     */
166
    public function getBodyTag()
167
    {
168
        return $this->bodyTag;
169
    }
170
171
    /**
172
     * Sets the body tag
173
     *
174
     * @param string $bodyTag
175
     * @return self
176
     */
177
    public function setBodyTag($bodyTag): self
178
    {
179
        $this->bodyTag = $bodyTag;
180
        return $this;
181
    }
182
183
    /**
184
     * Gets the standalone view.
185
     *
186
     * @return StandaloneView
187
     */
188
    public function getView()
189
    {
190
        return $this->view;
191
    }
192
193
    /**
194
     * Set content
195
     *
196
     * @param string $content Content of the module
197
     * @return self
198
     */
199
    public function setContent($content): self
200
    {
201
        $this->view->assign('content', $content);
202
        return $this;
203
    }
204
205
    /**
206
     * Set title tag
207
     *
208
     * @param string $title
209
     * @return self
210
     */
211
    public function setTitle($title): self
212
    {
213
        $this->title = $title;
214
        return $this;
215
    }
216
217
    /**
218
     * Returns the IconFactory
219
     *
220
     * @return IconFactory
221
     */
222
    public function getIconFactory()
223
    {
224
        return $this->iconFactory;
225
    }
226
227
    /**
228
     * Class constructor
229
     * Sets up view and property objects
230
     *
231
     * @param PageRenderer $pageRenderer
232
     * @param IconFactory $iconFactory
233
     * @param FlashMessageService $flashMessageService
234
     * @throws InvalidTemplateResourceException In case a template is invalid
235
     */
236
    public function __construct(
237
        PageRenderer $pageRenderer,
238
        IconFactory $iconFactory,
239
        FlashMessageService $flashMessageService
240
    ) {
241
        $this->view = GeneralUtility::makeInstance(StandaloneView::class);
242
        $this->view->setPartialRootPaths($this->partialRootPaths);
243
        $this->view->setTemplateRootPaths($this->templateRootPaths);
244
        $this->view->setLayoutRootPaths($this->layoutRootPaths);
245
        $this->view->setTemplate($this->templateFile);
246
        $this->pageRenderer = $pageRenderer;
247
        $this->iconFactory = $iconFactory;
248
        $this->flashMessageService = $flashMessageService;
249
        $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
250
        $this->setupPage();
251
        $this->loadJavaScripts();
252
        $this->loadStylesheets();
253
    }
254
255
    /**
256
     * Loads all necessary Javascript Files
257
     */
258
    protected function loadJavaScripts()
259
    {
260
        $this->pageRenderer->loadRequireJsModule('bootstrap');
261
262
        if ($this->getBackendUserAuthentication() && !empty($this->getBackendUserAuthentication()->user)) {
263
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ContextHelp');
264
            $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/DocumentHeader');
265
        }
266
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/GlobalEventHandler');
267
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/ActionDispatcher');
268
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Element/ImmediateActionElement');
269
    }
270
271
    /**
272
     * Loads all necessary stylesheets
273
     */
274
    protected function loadStylesheets()
275
    {
276
        if (!empty($GLOBALS['TBE_STYLES']['stylesheet'])) {
277
            $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet']);
278
        }
279
        if (!empty($GLOBALS['TBE_STYLES']['stylesheet2'])) {
280
            $this->pageRenderer->addCssFile($GLOBALS['TBE_STYLES']['stylesheet2']);
281
        }
282
        // Add all *.css files of the directory $path to the stylesheets
283
        foreach ($this->getRegisteredStylesheetFolders() as $folder) {
284
            // Read all files in directory and sort them alphabetically
285
            foreach (GeneralUtility::getFilesInDir($folder, 'css', true) as $cssFile) {
0 ignored issues
show
Bug introduced by
The expression TYPO3\CMS\Core\Utility\G...r($folder, 'css', true) of type string is not traversable.
Loading history...
286
                $this->pageRenderer->addCssFile($cssFile);
287
            }
288
        }
289
    }
290
291
    /**
292
     * Returns an array of all stylesheet directories registered via $TBE_STYLES['skins']
293
     */
294
    protected function getRegisteredStylesheetFolders(): array
295
    {
296
        $stylesheetDirectories = [];
297
        foreach ($GLOBALS['TBE_STYLES']['skins'] ?? [] as $skin) {
298
            foreach ($skin['stylesheetDirectories'] ?? [] as $stylesheetDir) {
299
                $directory = GeneralUtility::getFileAbsFileName($stylesheetDir);
300
                if (!empty($directory)) {
301
                    $stylesheetDirectories[] = $directory;
302
                }
303
            }
304
        }
305
        return $stylesheetDirectories;
306
    }
307
308
    /**
309
     * Sets mandatory parameters for the view (pageRenderer)
310
     */
311
    protected function setupPage()
312
    {
313
        // Yes, hardcoded on purpose
314
        $this->pageRenderer->setXmlPrologAndDocType('<!DOCTYPE html>');
315
        $this->pageRenderer->setCharSet('utf-8');
316
        $this->pageRenderer->setLanguage($this->getLanguageService()->lang);
317
        $this->pageRenderer->setMetaTag('name', 'viewport', 'width=device-width, initial-scale=1');
318
        $this->pageRenderer->setFavIcon($this->getBackendFavicon());
319
        $this->pageRenderer->enableConcatenateCss();
320
        $this->pageRenderer->enableConcatenateJavascript();
321
        $this->pageRenderer->enableCompressCss();
322
        $this->pageRenderer->enableCompressJavascript();
323
        $languageCode = $this->pageRenderer->getLanguage() === 'default' ? 'en' : $this->pageRenderer->getLanguage();
324
        $this->pageRenderer->setHtmlTag('<html lang="' . htmlspecialchars($languageCode) . '">');
325
        if ($GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
326
            $this->pageRenderer->enableDebugMode();
327
        }
328
    }
329
330
    /**
331
     * Wrapper function for adding JS inline blocks
332
     */
333
    protected function setJavaScriptCodeArray()
334
    {
335
        foreach ($this->javascriptCodeArray as $name => $code) {
336
            $this->pageRenderer->addJsInlineCode($name, $code, false);
337
        }
338
    }
339
340
    /**
341
     * Adds JS inline blocks of code to the internal registry
342
     *
343
     * @param string $name Javascript code block name
344
     * @param string $code Inline Javascript
345
     * @return self
346
     */
347
    public function addJavaScriptCode($name = '', $code = ''): self
348
    {
349
        $this->javascriptCodeArray[$name] = $code;
350
        return $this;
351
    }
352
353
    /**
354
     * Get the DocHeader
355
     *
356
     * @return DocHeaderComponent
357
     */
358
    public function getDocHeaderComponent()
359
    {
360
        return $this->docHeaderComponent;
361
    }
362
363
    /**
364
     * Returns the fully rendered view
365
     *
366
     * @return string
367
     */
368
    public function renderContent()
369
    {
370
        $this->setJavaScriptCodeArray();
371
        $this->pageRenderer->setTitle($this->title);
372
373
        $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
374
        if ($this->moduleId) {
375
            $this->view->assign('moduleId', $this->moduleId);
376
        }
377
        if ($this->moduleName) {
378
            $this->view->assign('moduleName', $this->moduleName);
379
        }
380
        $this->view->assign('uiBlock', $this->uiBlock);
381
        $this->view->assign('flashMessageQueueIdentifier', $this->getFlashMessageQueue()->getIdentifier());
382
        $this->pageRenderer->addBodyContent($this->bodyTag . $this->view->render());
383
        $this->pageRenderer->addJsFooterInlineCode('updateSignals', BackendUtility::getUpdateSignalCode());
384
        return $this->pageRenderer->render();
385
    }
386
387
    /**
388
     * Get PageRenderer
389
     *
390
     * @return PageRenderer
391
     */
392
    public function getPageRenderer()
393
    {
394
        return $this->pageRenderer;
395
    }
396
397
    /**
398
     * Set form tag
399
     *
400
     * @param string $formTag Form tag to add
401
     * @return self
402
     */
403
    public function setForm($formTag = ''): self
404
    {
405
        $this->view->assign('formTag', $formTag);
406
        return $this;
407
    }
408
409
    /**
410
     * Sets the ModuleId
411
     *
412
     * @param string $moduleId ID of the module
413
     * @return self
414
     */
415
    public function setModuleId($moduleId): self
416
    {
417
        $this->moduleId = $moduleId;
418
        $this->registerModuleMenu($moduleId);
419
        return $this;
420
    }
421
422
    /**
423
     * Sets the ModuleName
424
     *
425
     * @param string $moduleName Name of the module
426
     * @return self
427
     */
428
    public function setModuleName($moduleName): self
429
    {
430
        $this->moduleName = $moduleName;
431
        return $this;
432
    }
433
434
    /**
435
     * Generates the Menu for things like Web->Info
436
     *
437
     * @param string $moduleMenuIdentifier
438
     * @return self
439
     */
440
    public function registerModuleMenu($moduleMenuIdentifier): self
441
    {
442
        if (isset($GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier])) {
443
            $menuEntries =
444
                $GLOBALS['TBE_MODULES_EXT'][$moduleMenuIdentifier]['MOD_MENU']['function'];
445
            $menu = $this->getDocHeaderComponent()->getMenuRegistry()->makeMenu()->setIdentifier('MOD_FUNC');
446
            foreach ($menuEntries as $menuEntry) {
447
                $menuItem = $menu->makeMenuItem()
448
                    ->setTitle($menuEntry['title'])
449
                    ->setHref('#');
450
                $menu->addMenuItem($menuItem);
451
            }
452
            $this->docHeaderComponent->getMenuRegistry()->addMenu($menu);
453
        }
454
        return $this;
455
    }
456
457
    /**
458
     * Creates a tab menu where the tabs or collapsible are rendered with bootstrap markup
459
     *
460
     * @param array $menuItems Tab elements, each element is an array with "label" and "content"
461
     * @param string $domId DOM id attribute, will be appended with an iteration number per tab.
462
     * @param int $defaultTabIndex Default tab to open (for toggle <=0). Value corresponds to integer-array index + 1
463
     *                             (index zero is "1", index "1" is 2 etc.). A value of zero (or something non-existing
464
     *                             will result in no default tab open.
465
     * @param bool $collapsible If set, the tabs are rendered as headers instead over each sheet. Effectively this means
466
     *                          there is no tab menu, but rather a foldout/fold-in menu.
467
     * @param bool $wrapContent If set, the content is wrapped in div structure which provides a padding and border
468
     *                          style. Set this FALSE to get unstyled content pane with fullsize content area.
469
     * @param bool $storeLastActiveTab If set, the last open tab is stored in local storage and will be re-open again.
470
     *                                 If you don't need this feature, e.g. for wizards like import/export you can
471
     *                                 disable this behaviour.
472
     * @return string
473
     */
474
    public function getDynamicTabMenu(array $menuItems, $domId, $defaultTabIndex = 1, $collapsible = false, $wrapContent = true, $storeLastActiveTab = true)
475
    {
476
        $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tabs');
477
        $templatePath = ExtensionManagementUtility::extPath('backend')
478
            . 'Resources/Private/Templates/DocumentTemplate/';
479
        $view = GeneralUtility::makeInstance(StandaloneView::class);
480
        $view->setTemplatePathAndFilename($templatePath . ($collapsible ? 'Collapse.html' : 'Tabs.html'));
481
        $view->setPartialRootPaths([$templatePath . 'Partials']);
482
        $view->assignMultiple([
483
            'id' => 'DTM-' . GeneralUtility::shortMD5($domId),
484
            'items' => $menuItems,
485
            'defaultTabIndex' => $defaultTabIndex,
486
            'wrapContent' => $wrapContent,
487
            'storeLastActiveTab' => $storeLastActiveTab,
488
        ]);
489
        return $view->render();
490
    }
491
492
    /*******************************************
493
     * THE FOLLOWING METHODS ARE SUBJECT TO BE DEPRECATED / DROPPED!
494
     *
495
     * These methods have been copied over from DocumentTemplate and enables
496
     * core modules to drop the dependency to DocumentTemplate altogether without
497
     * rewriting these modules now.
498
     * The methods below are marked as internal and will be removed
499
     * one-by-one with further refactoring of modules.
500
     *
501
     * Do not use these methods within own extensions if possible or
502
     * be prepared to change this later again.
503
     *******************************************/
504
    /**
505
     * Returns a linked shortcut-icon which will call the shortcut frame and set a
506
     * shortcut there back to the calling page/module
507
     *
508
     * @param string $gvList Is the list of GET variables to store (if any)
509
     * @param string $setList Is the list of SET[] variables to store
510
     * (if any) - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS
511
     * for backend modules
512
     * @param string $modName Module name string
513
     * @param string|int $motherModName Is used to enter the "parent module
514
     * name" if the module is a submodule under eg. Web>* or File>*. You
515
     * can also set this value to 1 in which case the currentLoadedModule
516
     * is sent to the shortcut script (so - not a fixed value!) - that is used
517
     * in file_edit and wizard_rte modules where those are really running as
518
     * a part of another module.
519
     * @param string $displayName When given this name is used instead of the
520
     * module name.
521
     * @param string $classes Additional CSS classes for the link around the icon
522
     *
523
     * @return string HTML content
524
     * @todo Make this thing return a button object
525
     * @internal
526
     * @deprecated since v11, will be removed in v12
527
     */
528
    public function makeShortcutIcon($gvList, $setList, $modName, $motherModName = '', $displayName = '', $classes = 'btn btn-default btn-sm')
529
    {
530
        trigger_error('Method makeShortcutIcon() is deprecated and will be removed in v12. Please use ShortcutButton->setArguments() instead.', E_USER_DEPRECATED);
531
        $gvList = 'route,id,' . $gvList;
532
        $storeUrl = $this->makeShortcutUrl($gvList, $setList);
533
        $pathInfo = parse_url(GeneralUtility::getIndpEnv('REQUEST_URI'));
534
        // Fallback for alt_mod. We still pass in the old xMOD... stuff,
535
        // but TBE_MODULES only knows about "record_edit".
536
        // We still need to pass the xMOD name to createShortcut below,
537
        // since this is used for icons.
538
        $moduleName = $modName === 'xMOD_alt_doc.php' ? 'record_edit' : $modName;
539
        // Add the module identifier automatically if typo3/index.php is used:
540
        // @todo: routing
541
        if (GeneralUtility::_GET('route') !== null) {
542
            $storeUrl = '&route=' . $moduleName . $storeUrl;
543
        }
544
545
        $shortcutUrl = $pathInfo['path'] . '?' . $storeUrl;
546
547
        // We simply let the above functionality as it is for maximum backwards compatibility and now
548
        // just process the generated $shortcutUrl to match the new format (routeIdentifier & arguments)
549
        [$routeIdentifier, $arguments] = $this->getCreateShortcutProperties($shortcutUrl);
550
551
        if (GeneralUtility::makeInstance(ShortcutRepository::class)->shortcutExists($routeIdentifier, $arguments)) {
552
            return '<a class="active ' . htmlspecialchars($classes) . '" title="">' .
553
            $this->iconFactory->getIcon('actions-system-shortcut-active', Icon::SIZE_SMALL)->render() . '</a>';
554
        }
555
556
        $confirmationText =  $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.makeBookmark');
557
        $onClick = 'top.TYPO3.ShortcutMenu.createShortcut('
558
            . GeneralUtility::quoteJSvalue($routeIdentifier)
559
            . ', ' . GeneralUtility::quoteJSvalue($arguments)
560
            . ', ' . GeneralUtility::quoteJSvalue($displayName)
561
            . ', ' . GeneralUtility::quoteJSvalue($confirmationText)
562
            . ', this);return false;';
563
564
        return '<a href="#" class="' . htmlspecialchars($classes) . '" onclick="' . htmlspecialchars($onClick) . '" title="' .
565
        htmlspecialchars($confirmationText) . '">' .
566
        $this->iconFactory->getIcon('actions-system-shortcut-new', Icon::SIZE_SMALL)->render() . '</a>';
567
    }
568
569
    /**
570
     * MAKE url for storing
571
     * Internal func
572
     *
573
     * @param string $gvList Is the list of GET variables to store (if any)
574
     * @param string $setList Is the list of SET[] variables to store (if any)
575
     * - SET[] variables a stored in $GLOBALS["SOBE"]->MOD_SETTINGS for backend
576
     * modules
577
     *
578
     * @return string GET-parameters for the shortcut-url only(!). String starts with '&'
579
     * @internal
580
     * @deprecated since v11, will be removed in v12. Deprecation logged by parent method makeShortcutIcon()
581
     */
582
    public function makeShortcutUrl($gvList, $setList)
583
    {
584
        $getParams = GeneralUtility::_GET();
585
        $storeArray = array_merge(
586
            GeneralUtility::compileSelectedGetVarsFromArray($gvList, $getParams),
587
            ['SET' => GeneralUtility::compileSelectedGetVarsFromArray($setList, (array)$GLOBALS['SOBE']->MOD_SETTINGS)]
588
        );
589
        return HttpUtility::buildQueryString($storeArray, '&');
590
    }
591
592
    /**
593
     * Process the generated shortcut url and return properties needed for the
594
     * shortcut registration with route identifier and JSON encoded arguments.
595
     *
596
     * @param string $shortcutUrl
597
     *
598
     * @return array
599
     * @deprecated Only for backwards compatibility. Can be removed in v12
600
     */
601
    protected function getCreateShortcutProperties(string $shortcutUrl): array
602
    {
603
        $routeIdentifier = '';
604
        $arguments = [];
605
606
        parse_str(parse_url($shortcutUrl)['query'] ?? '', $arguments);
607
        $routePath = (string)($arguments['route'] ?? '');
608
609
        if ($routePath !== '') {
610
            foreach (GeneralUtility::makeInstance(Router::class)->getRoutes() as $identifier => $route) {
611
                if ($route->getPath() === $routePath
612
                    && (
613
                        $route->hasOption('moduleName')
614
                        || in_array($identifier, ['record_edit', 'file_edit', 'wizard_rte'], true)
615
                    )
616
                ) {
617
                    $routeIdentifier = $identifier;
618
                }
619
            }
620
        }
621
622
        unset($arguments['route'], $arguments['returnUrl']);
623
624
        return [$routeIdentifier, json_encode($arguments)];
625
    }
626
627
    /**
628
     * Retrieves configured favicon for backend (with fallback)
629
     *
630
     * @return string
631
     */
632
    protected function getBackendFavicon()
633
    {
634
        $backendFavicon = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('backend', 'backendFavicon');
635
        if (!empty($backendFavicon)) {
636
            $path = $this->getUriForFileName($backendFavicon);
637
        } else {
638
            $path = ExtensionManagementUtility::extPath('backend') . 'Resources/Public/Icons/favicon.ico';
639
        }
640
        return PathUtility::getAbsoluteWebPath($path);
641
    }
642
643
    /**
644
     * Returns the uri of a relative reference, resolves the "EXT:" prefix
645
     * (way of referring to files inside extensions) and checks that the file is inside
646
     * the project root of the TYPO3 installation
647
     *
648
     * @param string $filename The input filename/filepath to evaluate
649
     * @return string Returns the filename of $filename if valid, otherwise blank string.
650
     */
651
    protected function getUriForFileName($filename)
652
    {
653
        if (strpos($filename, '://')) {
654
            return $filename;
655
        }
656
        $urlPrefix = '';
657
        if (strpos($filename, 'EXT:') === 0) {
658
            $absoluteFilename = GeneralUtility::getFileAbsFileName($filename);
659
            $filename = '';
660
            if ($absoluteFilename !== '') {
661
                $filename = PathUtility::getAbsoluteWebPath($absoluteFilename);
662
            }
663
        } elseif (strpos($filename, '/') !== 0) {
664
            $urlPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
665
        }
666
        return $urlPrefix . $filename;
667
    }
668
669
    /**
670
     * Returns the BE USER Object
671
     *
672
     * @return BackendUserAuthentication
673
     */
674
    protected function getBackendUserAuthentication()
675
    {
676
        return $GLOBALS['BE_USER'];
677
    }
678
679
    /**
680
     * Returns the LanguageService
681
     *
682
     * @return LanguageService
683
     */
684
    protected function getLanguageService()
685
    {
686
        return $GLOBALS['LANG'];
687
    }
688
689
    /**
690
     * Returns the header-bar in the top of most backend modules
691
     * Closes section if open.
692
     *
693
     * @param string $text The text string for the header
694
     * @return string HTML content
695
     * @internal
696
     */
697
    public function header($text)
698
    {
699
        return '
700
701
	<!-- MAIN Header in page top -->
702
	<h1 class="t3js-title-inlineedit">' . htmlspecialchars($text) . '</h1>
703
';
704
    }
705
706
    /**
707
     * Creates a Message object and adds it to the FlashMessageQueue.
708
     *
709
     * @param string $messageBody The message
710
     * @param string $messageTitle Optional message title
711
     * @param int $severity Optional severity, must be one of \TYPO3\CMS\Core\Messaging\FlashMessage constants
712
     * @param bool $storeInSession Optional, defines whether the message should be stored in the session (default)
713
     * @throws \InvalidArgumentException if the message body is no string
714
     * @return self
715
     */
716
    public function addFlashMessage($messageBody, $messageTitle = '', $severity = AbstractMessage::OK, $storeInSession = true): self
717
    {
718
        if (!is_string($messageBody)) {
0 ignored issues
show
introduced by
The condition is_string($messageBody) is always true.
Loading history...
719
            throw new \InvalidArgumentException('The message body must be of type string, "' . gettype($messageBody) . '" given.', 1446483133);
720
        }
721
        /* @var \TYPO3\CMS\Core\Messaging\FlashMessage $flashMessage */
722
        $flashMessage = GeneralUtility::makeInstance(
723
            FlashMessage::class,
724
            $messageBody,
725
            $messageTitle,
726
            $severity,
727
            $storeInSession
728
        );
729
        $this->getFlashMessageQueue()->enqueue($flashMessage);
730
        return $this;
731
    }
732
733
    /**
734
     * @param FlashMessageQueue $flashMessageQueue
735
     * @return self
736
     */
737
    public function setFlashMessageQueue($flashMessageQueue): self
738
    {
739
        $this->flashMessageQueue = $flashMessageQueue;
740
        return $this;
741
    }
742
743
    /**
744
     * @return FlashMessageQueue
745
     */
746
    protected function getFlashMessageQueue()
747
    {
748
        if (!isset($this->flashMessageQueue)) {
749
            $this->flashMessageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
750
        }
751
        return $this->flashMessageQueue;
752
    }
753
754
    /**
755
     * @return bool
756
     */
757
    public function isUiBlock(): bool
758
    {
759
        return $this->uiBlock;
760
    }
761
762
    /**
763
     * @param bool $uiBlock
764
     * @return self
765
     */
766
    public function setUiBlock(bool $uiBlock): self
767
    {
768
        $this->uiBlock = $uiBlock;
769
        return $this;
770
    }
771
}
772