[CLEANUP] Use correct casting syntax
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / FileSystemNavigationFrameController.php
1 <?php
2 namespace TYPO3\CMS\Backend\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 use TYPO3\CMS\Backend\Utility\IconUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Main script class for rendering of the folder tree
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class FileSystemNavigationFrameController {
26
27 // Internal, dynamic:
28 // Content accumulates in this variable.
29 /**
30 * @var string
31 */
32 public $content;
33
34 /**
35 * @var \TYPO3\CMS\Filelist\FileListFolderTree $foldertree the folder tree object
36 */
37 public $foldertree;
38
39 /**
40 * document template object
41 *
42 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
43 */
44 public $doc;
45
46 /**
47 * @var string
48 */
49 public $backPath;
50
51 // Internal, static: GPvar:
52 /**
53 * @var string
54 */
55 public $currentSubScript;
56
57 /**
58 * @var bool
59 */
60 public $cMR;
61
62 /**
63 * @var array
64 */
65 protected $scopeData;
66
67 /**
68 * Constructor
69 */
70 public function __construct() {
71 $GLOBALS['SOBE'] = $this;
72 $GLOBALS['BACK_PATH'] = '';
73 $this->init();
74 }
75
76 /**
77 * Initialiation of the script class
78 *
79 * @return void
80 */
81 protected function init() {
82 // Setting backPath
83 $this->backPath = $GLOBALS['BACK_PATH'];
84 // Setting GPvars:
85 $this->currentSubScript = GeneralUtility::_GP('currentSubScript');
86 $this->cMR = GeneralUtility::_GP('cMR');
87
88 $scopeData = (string)GeneralUtility::_GP('scopeData');
89 $scopeHash = (string)GeneralUtility::_GP('scopeHash');
90
91 if (!empty($scopeData) && GeneralUtility::hmac($scopeData) === $scopeHash) {
92 $this->scopeData = unserialize($scopeData);
93 }
94
95 // Create folder tree object:
96 if (!empty($this->scopeData)) {
97 $this->foldertree = GeneralUtility::makeInstance($this->scopeData['class']);
98 $this->foldertree->thisScript = $this->scopeData['script'];
99 $this->foldertree->ext_noTempRecyclerDirs = $this->scopeData['ext_noTempRecyclerDirs'];
100 $GLOBALS['SOBE']->browser = new \stdClass();
101 $GLOBALS['SOBE']->browser->mode = $this->scopeData['browser']['mode'];
102 $GLOBALS['SOBE']->browser->act = $this->scopeData['browser']['act'];
103 } else {
104 $this->foldertree = GeneralUtility::makeInstance('TYPO3\\CMS\\Filelist\\FileListFolderTree');
105 $this->foldertree->thisScript = 'alt_file_navframe.php';
106 }
107
108 $this->foldertree->ext_IconMode = $GLOBALS['BE_USER']->getTSConfigVal('options.folderTree.disableIconLinkToContextmenu');
109 }
110
111 /**
112 * initialization for the visual parts of the class
113 * Use template rendering only if this is a non-AJAX call
114 *
115 * @return void
116 */
117 public function initPage() {
118 // Setting highlight mode:
119 $this->doHighlight = !$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.disableTitleHighlight');
120 // Create template object:
121 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
122 $this->doc->backPath = $GLOBALS['BACK_PATH'];
123 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/alt_file_navframe.html');
124 $this->doc->showFlashMessages = FALSE;
125 // Adding javascript code for AJAX (prototype), drag&drop and the filetree as well as the click menu code
126 $this->doc->getDragDropCode('folders');
127 $this->doc->getContextMenuCode();
128 // Setting JavaScript for menu.
129 $this->doc->JScode .= $this->doc->wrapScriptTags(($this->currentSubScript ? 'top.currentSubScript=unescape("' . rawurlencode($this->currentSubScript) . '");' : '') . '
130
131 // setting prefs for foldertree
132 Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
133
134 // Function, loading the list frame from navigation tree:
135 function jumpTo(id, linkObj, highlightID, bank) {
136 var theUrl = top.TS.PATH_typo3 + top.currentSubScript ;
137 if (theUrl.indexOf("?") != -1) {
138 theUrl += "&id=" + id
139 } else {
140 theUrl += "?id=" + id
141 }
142 top.fsMod.currentBank = bank;
143 top.TYPO3.Backend.ContentContainer.setUrl(theUrl);
144
145 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("file", highlightID + "_" + bank);' : '') . '
146 if (linkObj) { linkObj.blur(); }
147 return false;
148 }
149 ' . ($this->cMR ? ' jumpTo(top.fsMod.recentIds[\'file\'],\'\');' : ''));
150 }
151
152 /**
153 * Main function, rendering the folder tree
154 *
155 * @return void
156 */
157 public function main() {
158 // Produce browse-tree:
159 $tree = $this->foldertree->getBrowsableTree();
160 // Outputting page tree:
161 $this->content .= $tree;
162 // Adding javascript for drag & drop activation and highlighting
163 $this->content .= $this->doc->wrapScriptTags('
164 ' . ($this->doHighlight ? 'Tree.highlightActiveItem("", top.fsMod.navFrameHighlightedID["file"]);' : '') . '
165 Tree.registerDragDropHandlers();');
166 // Setting up the buttons and markers for docheader
167 $docHeaderButtons = $this->getButtons();
168 $markers = array(
169 'IMG_RESET' => '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/close_gray.gif', ' width="16" height="16"') . ' id="treeFilterReset" alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.resetFilter') . '" ' . 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.resetFilter') . '" />',
170 'CONTENT' => $this->content
171 );
172 $subparts = array();
173 // Possible filter/search like in page tree
174 $subparts['###SECOND_ROW###'] = '';
175 // Build the <body> for the module
176 $this->content = $this->doc->startPage('TYPO3 Folder Tree');
177 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers, $subparts);
178 $this->content .= $this->doc->endPage();
179 $this->content = $this->doc->insertStylesAndJS($this->content);
180 }
181
182 /**
183 * Outputting the accumulated content to screen
184 *
185 * @return void
186 */
187 public function printContent() {
188 echo $this->content;
189 }
190
191 /**
192 * Create the panel of buttons for submitting the form or otherwise perform operations.
193 *
194 * @return array All available buttons as an assoc. array
195 */
196 protected function getButtons() {
197 $buttons = array(
198 'csh' => '',
199 'refresh' => ''
200 );
201 // Refresh
202 $buttons['refresh'] = '<a href="' . htmlspecialchars(GeneralUtility::getIndpEnv('REQUEST_URI')) . '">' . IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
203 // CSH
204 $buttons['csh'] = str_replace('typo3-csh-inline', 'typo3-csh-inline show-right', \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('xMOD_csh_corebe', 'filetree', $GLOBALS['BACK_PATH']));
205 return $buttons;
206 }
207
208 /**********************************
209 *
210 * AJAX Calls
211 *
212 **********************************/
213 /**
214 * Makes the AJAX call to expand or collapse the foldertree.
215 * Called by typo3/ajax.php
216 *
217 * @param array $params Additional parameters (not used here)
218 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj The AjaxRequestHandler object of this request
219 * @return void
220 */
221 public function ajaxExpandCollapse($params, $ajaxObj) {
222 $this->init();
223 $tree = $this->foldertree->getBrowsableTree();
224 if ($this->foldertree->getAjaxStatus() === FALSE) {
225 $ajaxObj->setError($tree);
226 } else {
227 $ajaxObj->addContent('tree', $tree);
228 }
229 }
230
231 }