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