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