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