[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / Controller / ElementBrowserController.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\Controller;
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 /**
18 * Script class for the Element Browser window.
19 *
20 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
21 */
22 class ElementBrowserController {
23
24 /**
25 * The mode determines the main kind of output from the element browser.
26 * There are these options for values: rte, db, file, filedrag, wizard.
27 * "rte" will show the link selector for the Rich Text Editor (see main_rte())
28 * "db" will allow you to browse for pages or records in the page tree (for TCEforms, see main_db())
29 * "file"/"filedrag" will allow you to browse for files or folders in the folder mounts (for TCEforms, main_file())
30 * "wizard" will allow you to browse for links (like "rte") which are passed back to TCEforms (see main_rte(1))
31 *
32 * @see main()
33 * @todo Define visibility
34 */
35 public $mode;
36
37 /**
38 * Holds Instance of main browse_links class
39 * needed fo intercommunication between various classes that need access to variables via $GLOBALS['SOBE']
40 * Not the most nice solution but introduced since we don't have another general way to return class-instances or registry for now
41 *
42 * @var \TYPO3\CMS\Recordlist\Browser\ElementBrowser
43 * @todo Define visibility
44 */
45 public $browser;
46
47 /**
48 * Document template object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 * @todo Define visibility
52 */
53 public $doc;
54
55 /**
56 * Constructor
57 */
58 public function __construct() {
59 $GLOBALS['SOBE'] = $this;
60 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_browse_links.xlf');
61 $GLOBALS['BACK_PATH'] = '';
62
63 $this->init();
64 }
65
66 /**
67 * Not really needed but for backwards compatibility ...
68 *
69 * @return void
70 */
71 protected function init() {
72 // Find "mode"
73 $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
74 if (!$this->mode) {
75 $this->mode = 'rte';
76 }
77 // Creating backend template object:
78 // this might not be needed but some classes refer to $GLOBALS['SOBE']->doc, so ...
79 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
80 $this->doc->backPath = $GLOBALS['BACK_PATH'];
81 // Apply the same styles as those of the base script
82 $this->doc->bodyTagId = 'typo3-browse-links-php';
83
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 */
91 public function main() {
92 // Clear temporary DB mounts
93 $tmpMount = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('setTempDBmount');
94 if (isset($tmpMount)) {
95 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
96 }
97 // Set temporary DB mounts
98 $tempDBmount = (int)$GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint');
99 if ($tempDBmount) {
100 $altMountPoints = $tempDBmount;
101 }
102 if ($altMountPoints) {
103 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
104 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
105 }
106 $this->content = '';
107 // Look for alternative mountpoints
108 switch ((string) $this->mode) {
109 case 'rte':
110 case 'db':
111 case 'wizard':
112 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
113 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
114 if ($altMountPoints) {
115 $GLOBALS['BE_USER']->groupData['webmounts'] = implode(',', array_unique(\TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $altMountPoints)));
116 $GLOBALS['WEBMOUNTS'] = $GLOBALS['BE_USER']->returnWebmounts();
117 }
118 case 'file':
119 case 'filedrag':
120 case 'folder':
121 // Setting additional read-only browsing file mounts
122 $altMountPoints = trim($GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.altElementBrowserMountPoints'));
123 if ($altMountPoints) {
124 $altMountPoints = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $altMountPoints);
125 foreach ($altMountPoints as $filePathRelativeToFileadmindir) {
126 // @todo: add this feature for FAL and TYPO3 6.2
127 }
128 }
129 break;
130 }
131 // Render type by user func
132 $browserRendered = FALSE;
133 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'])) {
134 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/browse_links.php']['browserRendering'] as $classRef) {
135 $browserRenderObj = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classRef);
136 if (is_object($browserRenderObj) && method_exists($browserRenderObj, 'isValid') && method_exists($browserRenderObj, 'render')) {
137 if ($browserRenderObj->isValid($this->mode, $this)) {
138 $this->content .= $browserRenderObj->render($this->mode, $this);
139 $browserRendered = TRUE;
140 break;
141 }
142 }
143 }
144 }
145 // if type was not rendered use default rendering functions
146 if (!$browserRendered) {
147 $this->browser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\Browser\\ElementBrowser');
148 $this->browser->init();
149 $modData = $GLOBALS['BE_USER']->getModuleData('browse_links.php', 'ses');
150 list($modData, $store) = $this->browser->processSessionData($modData);
151 $GLOBALS['BE_USER']->pushModuleData('browse_links.php', $modData);
152 // Output the correct content according to $this->mode
153 switch ((string) $this->mode) {
154 case 'rte':
155 $this->content = $this->browser->main_rte();
156 break;
157 case 'db':
158 $this->content = $this->browser->main_db();
159 break;
160 case 'file':
161 case 'filedrag':
162 $this->content = $this->browser->main_file();
163 break;
164 case 'folder':
165 $this->content = $this->browser->main_folder();
166 break;
167 case 'wizard':
168 $this->content = $this->browser->main_rte(1);
169 break;
170 }
171 }
172 }
173
174 /**
175 * Print module content
176 *
177 * @return void
178 */
179 public function printContent() {
180 echo $this->content;
181 }
182
183 }