fcc697a9850a19de26840a15dfe1ac41585d9e9b
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Controller / ElementBrowserController.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Script class for the Element Browser window.
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class ElementBrowserController {
36
37 /**
38 * The mode determines the main kind of output from the element browser.
39 * There are these options for values: rte, db, file, filedrag, wizard.
40 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
41 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
42 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
43 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
44 *
45 * @see main()
46 * @todo Define visibility
47 */
48 public $mode;
49
50 /**
51 * Holds Instance of main browse_links class
52 * needed fo intercommunication between various classes that need access to variables via $GLOBALS['SOBE']
53 * Not the most nice solution but introduced since we don't have another general way to return class-instances or registry for now
54 *
55 * @var \TYPO3\CMS\Recordlist\Browser\ElementBrowser
56 * @todo Define visibility
57 */
58 public $browser;
59
60 /**
61 * Document template object
62 *
63 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
64 * @todo Define visibility
65 */
66 public $doc;
67
68 /**
69 * Not really needed but for backwards compatibility ...
70 *
71 * @return void
72 * @todo Define visibility
73 */
74 public function init() {
75 // Find "mode"
76 $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
77 if (!$this->mode) {
78 $this->mode = 'rte';
79 }
80 // Creating backend template object:
81 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
82 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
83 $this->doc->backPath = $GLOBALS['BACK_PATH'];
84 }
85
86 /**
87 * Main function, detecting the current mode of the element browser and branching out to internal methods.
88 *
89 * @return void
90 * @todo Define visibility
91 */
92 public function main() {
93 // Clear temporary DB mounts
94 $tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
95 if (isset($tmpMount)) {
96 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', intval($tmpMount));
97 }
98 // Set temporary DB mounts
99 $tempDBmount = intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'));
100 if ($tempDBmount) {
101 $altMountPoints = $tempDBmount;
102 }
103 if ($altMountPoints) {
104 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
105 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
106 }
107 $this->content = '';
108 // Look for alternative mountpoints
109 switch ((string) $this->mode) {
110 case 'rte':
111
112 case 'db':
113
114 case 'wizard':
115 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
116 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
117 if ($altMountPoints) {
118 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
119 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
120 }
121 case 'file':
122
123 case 'filedrag':
124
125 case 'folder':
126 // Setting additional read-only browsing file mounts
127 // @todo: add this feature for FAL and TYPO3 6.0
128 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
129 if ($altMountPoints) {
130 $altMountPoints = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $altMountPoints);
131 foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
132 $GLOBALS['BE_USER']->addFileMount('', $filePathRelativeToFileadmindir, $filePathRelativeToFileadmindir, 1, 'readonly');
133 }
134 $GLOBALS['BE_USER']->getFileStorages();
135 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->groupData['filemounts'];
136 }
137 break;
138 }
139 // Render type by user func
140 $browserRendered = FALSE;
141 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
142 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
143 $browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
144 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
145 if ($browserRenderObj->isValid($this->mode, $this)) {
146 $this->content .= $browserRenderObj->render($this->mode, $this);
147 $browserRendered = TRUE;
148 break;
149 }
150 }
151 }
152 }
153 // if type was not rendered use default rendering functions
154 if (!$browserRendered) {
155 $this->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser');
156 $this->browser->init();
157 $modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
158 list($modData, $store) = $this->browser->processSessionData($modData);
159 $GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
160 // Output the correct content according to $this->mode
161 switch ((string) $this->mode) {
162 case 'rte':
163 $this->content = $this->browser->main_rte();
164 break;
165 case 'db':
166 $this->content = $this->browser->main_db();
167 break;
168 case 'file':
169
170 case 'filedrag':
171 $this->content = $this->browser->main_file();
172 break;
173 case 'folder':
174 $this->content = $this->browser->main_folder();
175 break;
176 case 'wizard':
177 $this->content = $this->browser->main_rte(1);
178 break;
179 }
180 }
181 }
182
183 /**
184 * Print module content
185 *
186 * @return void
187 * @todo Define visibility
188 */
189 public function printContent() {
190 echo $this->content;
191 }
192
193 }
194
195
196 ?>