2 namespace TYPO3\CMS\Recordlist\Controller
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use Psr\Http\Message\ServerRequestInterface
;
18 use Psr\Http\Message\ResponseInterface
;
19 use TYPO3\CMS\Backend\Template\DocumentTemplate
;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication
;
21 use TYPO3\CMS\Core\Http\Response
;
22 use TYPO3\CMS\Core\Utility\GeneralUtility
;
23 use TYPO3\CMS\Lang\LanguageService
;
24 use TYPO3\CMS\Recordlist\Browser\ElementBrowser
;
27 * Script class for the Element Browser window.
29 class ElementBrowserController
implements \TYPO3\CMS\Core\Http\ControllerInterface
{
32 * The mode determines the main kind of output of the element browser.
33 * There are these options for values:
34 * - "rte" will show the link selector for the Rich Text Editor (see main_rte())
35 * - "wizard" will allow you to browse for links (like "rte") which are passed back to FormEngine (see main_rte(TRUE))
36 * - "db" will allow you to browse for pages or records in the page tree for FormEngine select fields (see main_db())
37 * - "file"/"filedrag" will allow you to browse for files in the folder mounts for FormEngine file selections (main_file())
38 * - "folder" will allow you to browse for folders in the folder mounts for FormEngine folder selecitons (see main_folder())
45 * Document template object
47 * @var DocumentTemplate
59 public function __construct() {
60 $GLOBALS['SOBE'] = $this;
62 // Creating backend template object:
63 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
64 $this->doc
= GeneralUtility
::makeInstance(DocumentTemplate
::class);
65 // Apply the same styles as those of the base script
66 $this->doc
->bodyTagId
= 'typo3-browse-links-php';
71 protected function init() {
72 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_browse_links.xlf');
74 $this->mode
= GeneralUtility
::_GP('mode');
81 * Injects the request object for the current request or subrequest
82 * As this controller goes only through the main() method, it is rather simple for now
84 * @param ServerRequestInterface $request
85 * @return ResponseInterface $response
87 public function processRequest(ServerRequestInterface
$request) {
90 /** @var Response $response */
91 $response = GeneralUtility
::makeInstance(Response
::class);
92 $response->getBody()->write($this->content
);
97 * Main function, detecting the current mode of the element browser and branching out to internal methods.
101 public function main() {
102 $this->setTemporaryDbMounts();
106 // Render type by user func
107 $browserRendered = FALSE
;
108 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
109 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
110 $browserRenderObj = GeneralUtility
::getUserObj($classRef);
111 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
112 if ($browserRenderObj->isValid($this->mode
, $this)) {
113 $this->content
.= $browserRenderObj->render($this->mode
, $this);
114 $browserRendered = TRUE
;
120 // if type was not rendered use default rendering functions
121 if (!$browserRendered) {
122 $browser = $this->getElementBrowserInstance();
124 $backendUser = $this->getBackendUser();
125 $modData = $backendUser->getModuleData('browse_links.php', 'ses');
126 list($modData) = $browser->processSessionData($modData);
127 $backendUser->pushModuleData('browse_links.php', $modData);
129 // Output the correct content according to $this->mode
130 switch ((string)$this->mode
) {
132 $this->content
= $browser->main_rte();
135 $this->content
= $browser->main_db();
139 $this->content
= $browser->main_file();
142 $this->content
= $browser->main_folder();
145 $this->content
= $browser->main_rte(TRUE
);
154 protected function setTemporaryDbMounts() {
155 $backendUser = $this->getBackendUser();
157 // Clear temporary DB mounts
158 $tmpMount = GeneralUtility
::_GET('setTempDBmount');
159 if (isset($tmpMount)) {
160 $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
162 // Set temporary DB mounts
163 $alternativeWebmountPoint = (int)$backendUser->getSessionData('pageTree_temporaryMountPoint');
164 if ($alternativeWebmountPoint) {
165 $alternativeWebmountPoint = GeneralUtility
::intExplode(',', $alternativeWebmountPoint);
166 $backendUser->setWebmounts($alternativeWebmountPoint);
168 switch ((string)$this->mode
) {
172 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
173 $alternativeWebmountPoints = trim($backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
174 $appendAlternativeWebmountPoints = $backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints.append');
175 if ($alternativeWebmountPoints) {
176 $alternativeWebmountPoints = GeneralUtility
::intExplode(',', $alternativeWebmountPoints);
177 $this->getBackendUser()->setWebmounts($alternativeWebmountPoints, $appendAlternativeWebmountPoints);
184 * Get instance of ElementBrowser
186 * This method shall be overwritten in subclasses
188 * @return ElementBrowser
190 protected function getElementBrowserInstance() {
191 return GeneralUtility
::makeInstance(ElementBrowser
::class);
195 * Print module content
198 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use processRequest() instead
200 public function printContent() {
201 GeneralUtility
::logDeprecatedFunction();
206 * @return LanguageService
208 protected function getLanguageService() {
209 return $GLOBALS['LANG'];
213 * @return BackendUserAuthentication
215 protected function getBackendUser() {
216 return $GLOBALS['BE_USER'];