[TASK] Cleanup entry classes in typo3/ part2
[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 * Constructor
70 */
71 public function __construct() {
72 $GLOBALS['SOBE'] = $this;
73 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_browse_links.xlf');
74 $GLOBALS['BACK_PATH'] = '';
75
76 $this->init();
77 }
78
79 /**
80 * Not really needed but for backwards compatibility ...
81 *
82 * @return void
83 */
84 protected function init() {
85 // Find "mode"
86 $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
87 if (!$this->mode) {
88 $this->mode = 'rte';
89 }
90 // Creating backend template object:
91 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
92 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
93 $this->doc->backPath = $GLOBALS['BACK_PATH'];
94 }
95
96 /**
97 * Main function, detecting the current mode of the element browser and branching out to internal methods.
98 *
99 * @return void
100 */
101 public function main() {
102 // Clear temporary DB mounts
103 $tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
104 if (isset($tmpMount)) {
105 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', intval($tmpMount));
106 }
107 // Set temporary DB mounts
108 $tempDBmount = intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint'));
109 if ($tempDBmount) {
110 $altMountPoints = $tempDBmount;
111 }
112 if ($altMountPoints) {
113 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
114 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
115 }
116 $this->content = '';
117 // Look for alternative mountpoints
118 switch ((string) $this->mode) {
119 case 'rte':
120 case 'db':
121 case 'wizard':
122 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
123 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
124 if ($altMountPoints) {
125 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
126 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
127 }
128 case 'file':
129 case 'filedrag':
130 case 'folder':
131 // Setting additional read-only browsing file mounts
132 // @todo: add this feature for FAL and TYPO3 6.0
133 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
134 if ($altMountPoints) {
135 $altMountPoints = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $altMountPoints);
136 foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
137 $GLOBALS['BE_USER']->addFileMount('', $filePathRelativeToFileadmindir, $filePathRelativeToFileadmindir, 1, 'readonly');
138 }
139 $GLOBALS['BE_USER']->getFileStorages();
140 $GLOBALS['FILEMOUNTS'] = $GLOBALS['BE_USER']->groupData['filemounts'];
141 }
142 break;
143 }
144 // Render type by user func
145 $browserRendered = FALSE;
146 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
147 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
148 $browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
149 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
150 if ($browserRenderObj->isValid($this->mode, $this)) {
151 $this->content .= $browserRenderObj->render($this->mode, $this);
152 $browserRendered = TRUE;
153 break;
154 }
155 }
156 }
157 }
158 // if type was not rendered use default rendering functions
159 if (!$browserRendered) {
160 $this->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser');
161 $this->browser->init();
162 $modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
163 list($modData, $store) = $this->browser->processSessionData($modData);
164 $GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
165 // Output the correct content according to $this->mode
166 switch ((string) $this->mode) {
167 case 'rte':
168 $this->content = $this->browser->main_rte();
169 break;
170 case 'db':
171 $this->content = $this->browser->main_db();
172 break;
173 case 'file':
174 case 'filedrag':
175 $this->content = $this->browser->main_file();
176 break;
177 case 'folder':
178 $this->content = $this->browser->main_folder();
179 break;
180 case 'wizard':
181 $this->content = $this->browser->main_rte(1);
182 break;
183 }
184 }
185 }
186
187 /**
188 * Print module content
189 *
190 * @return void
191 */
192 public function printContent() {
193 echo $this->content;
194 }
195
196 }
197
198 ?>