‪TYPO3CMS  10.4
LinkBrowserController.php
Go to the documentation of this file.
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 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
28 
33 {
37  protected function ‪initCurrentUrl()
38  {
39  $currentLink = isset($this->parameters['currentValue']) ? trim($this->parameters['currentValue']) : '';
41  ‪$currentLinkParts = GeneralUtility::makeInstance(TypoLinkCodecService::class)->decode($currentLink);
42  ‪$currentLinkParts['params'] = ‪$currentLinkParts['additionalParams'];
43  unset(‪$currentLinkParts['additionalParams']);
44 
45  if (!empty(‪$currentLinkParts['url'])) {
46  $linkService = GeneralUtility::makeInstance(LinkService::class);
47  $data = $linkService->resolve(‪$currentLinkParts['url']);
48  ‪$currentLinkParts['type'] = $data['type'];
49  unset($data['type']);
50  ‪$currentLinkParts['url'] = $data;
51  }
52 
53  $this->currentLinkParts = ‪$currentLinkParts;
54 
55  parent::initCurrentUrl();
56  }
57 
58  protected function ‪initDocumentTemplate()
59  {
60  parent::initDocumentTemplate();
61 
63  $this->parameters['fieldChangeFunc'] = [];
64  }
65  unset($this->parameters['fieldChangeFunc']['alert']);
66  $update = [];
67  foreach ($this->parameters['fieldChangeFunc'] as $v) {
68  $update[] = 'FormEngineLinkBrowserAdapter.getParent().' . $v;
69  }
70  $inlineJS = implode(LF, $update);
71 
72  $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
73  $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/FormEngineLinkBrowserAdapter', 'function(FormEngineLinkBrowserAdapter) {
74  FormEngineLinkBrowserAdapter.updateFunctions = function() {' . $inlineJS . '};
75  }');
76  }
77 
86  public function ‪encodeTypoLink(ServerRequestInterface $request): ResponseInterface
87  {
88  $typoLinkParts = $request->getQueryParams();
89  if (isset($typoLinkParts['params'])) {
90  $typoLinkParts['additionalParams'] = $typoLinkParts['params'];
91  unset($typoLinkParts['params']);
92  }
93 
94  $typoLink = GeneralUtility::makeInstance(TypoLinkCodecService::class)->encode($typoLinkParts);
95  return new ‪JsonResponse(['typoLink' => $typoLink]);
96  }
97 
105  protected function ‪areFieldChangeFunctionsValid($handleFlexformSections = false)
106  {
107  $result = false;
108  if (isset($this->parameters['fieldChangeFunc']) && is_array($this->parameters['fieldChangeFunc']) && isset($this->parameters['fieldChangeFuncHash'])) {
109  $matches = [];
110  $pattern = '#\\[el\\]\\[(([^]-]+-[^]-]+-)(idx\\d+-)([^]]+))\\]#i';
111  $fieldChangeFunctions = $this->parameters['fieldChangeFunc'];
112  // Special handling of flexform sections:
113  // Field change functions are modified in JavaScript, thus the hash is always invalid
114  if ($handleFlexformSections && preg_match($pattern, $this->parameters['itemName'], $matches)) {
115  $originalName = $matches[1];
116  $cleanedName = $matches[2] . $matches[4];
117  foreach ($fieldChangeFunctions as &$value) {
118  $value = str_replace($originalName, $cleanedName, $value);
119  }
120  unset($value);
121  }
122  $result = hash_equals(GeneralUtility::hmac(serialize($fieldChangeFunctions), 'backend-link-browser'), $this->parameters['fieldChangeFuncHash']);
123  }
124  return $result;
125  }
126 
132  protected function ‪getBodyTagAttributes()
133  {
134  $formEngineParameters = [];
135  ‪$parameters = parent::getBodyTagAttributes();
136 
137  $formEngineParameters['fieldChangeFunc'] = $this->parameters['fieldChangeFunc'];
138  $formEngineParameters['fieldChangeFuncHash'] = GeneralUtility::hmac(serialize($this->parameters['fieldChangeFunc']), 'backend-link-browser');
139 
140  ‪$parameters['data-add-on-params'] .= ‪HttpUtility::buildQueryString(['P' => $formEngineParameters], '&');
141 
142  return ‪$parameters;
143  }
144 
150  protected function ‪getCurrentPageId()
151  {
152  $pageId = 0;
153  $browserParameters = ‪$this->parameters;
154  if (isset($browserParameters['pid'])) {
155  $pageId = $browserParameters['pid'];
156  } elseif (isset($browserParameters['itemName'])) {
157  // parse data[<table>][<uid>]
158  if (preg_match('~data\[([^]]*)\]\[([^]]*)\]~', $browserParameters['itemName'], $matches)) {
159  $recordArray = ‪BackendUtility::getRecord($matches['1'], $matches['2']);
160  if (is_array($recordArray)) {
161  $pageId = $recordArray['pid'];
162  }
163  }
164  }
165  return (int)‪BackendUtility::getTSCpidCached($browserParameters['table'], $browserParameters['uid'], $pageId)[0];
166  }
167 
172  public function ‪getConfiguration(): array
173  {
175  return $tsConfig['TCEMAIN.']['linkHandler.']['page.']['configuration.'] ?? [];
176  }
177 }
‪TYPO3\CMS\Backend\Utility\BackendUtility\getTSCpidCached
‪static array getTSCpidCached($table, $uid, $pid)
Definition: BackendUtility.php:3184
‪TYPO3\CMS\Core\Page\PageRenderer
Definition: PageRenderer.php:42
‪TYPO3\CMS\Core\Utility\HttpUtility\buildQueryString
‪static string buildQueryString(array $parameters, string $prependCharacter='', bool $skipEmptyParameters=false)
Definition: HttpUtility.php:163
‪TYPO3\CMS\Backend\Utility\BackendUtility\getPagesTSconfig
‪static array getPagesTSconfig($id)
Definition: BackendUtility.php:698
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18