6bd56c355c9c39941ecd78b3813393af40290181
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / ViewHelpers / IssueCommandViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Beuser\ViewHelpers;
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\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
23
24 /**
25 * Issue command ViewHelper, see TYPO3 Core Engine method issueCommand
26 *
27 * @author Felix Kopp <felix-source@phorax.com>
28 * @internal
29 */
30 class IssueCommandViewHelper extends AbstractViewHelper implements CompilableInterface{
31
32 /**
33 * Returns a URL with a command to TYPO3 Core Engine (tce_db.php)
34 *
35 * @param string $parameters 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
36 * @param string $redirectUrl Redirect URL if any other that \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') is wished
37 *
38 * @return string URL to tce_db.php + parameters
39 * @see \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick()
40 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate::issueCommand()
41 */
42 public function render($parameters, $redirectUrl = '') {
43 return self::renderStatic(
44 array(
45 'parameters' => $parameters,
46 'redirectUrl' => $redirectUrl
47 ),
48 $this->buildRenderChildrenClosure(),
49 $this->renderingContext
50 );
51 }
52
53 /**
54 * @param array $arguments
55 * @param callable $renderChildrenClosure
56 * @param RenderingContextInterface $renderingContext
57 *
58 * @return string
59 */
60 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
61 /** @var BackendUserAuthentication $beUser */
62 $beUser = $GLOBALS['BE_USER'];
63 $urlParameters = [
64 'vC' => $beUser->veriCode(),
65 'prErr' => 1,
66 'uPT' => 1,
67 'redirect' => $arguments['redirectUrl'] ?: GeneralUtility::getIndpEnv('REQUEST_URI')
68 ];
69 return htmlspecialchars(BackendUtility::getModuleUrl('tce_db', $urlParameters) . $arguments['parameters'] . BackendUtility::getUrlToken('tceAction'));
70 }
71 }