[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / Classes / Controller / RecyclerModuleController.php
1 <?php
2 namespace TYPO3\CMS\Recycler\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\BackendUtility;
18 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Module 'Recycler' for the 'recycler' extension.
23 *
24 * @author Julian Kleinhans <typo3@kj187.de>
25 */
26 class RecyclerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
27
28 /**
29 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
30 */
31 public $doc;
32
33 /**
34 * @var string
35 */
36 protected $relativePath;
37
38 /**
39 * @var array
40 */
41 protected $pageRecord = array();
42
43 /**
44 * @var bool
45 */
46 protected $isAccessibleForCurrentUser = FALSE;
47
48 /**
49 * @var bool
50 */
51 protected $allowDelete = FALSE;
52
53 /**
54 * @var int
55 */
56 protected $recordsPageLimit = 50;
57
58 /**
59 * @var \TYPO3\CMS\Core\Page\PageRenderer
60 */
61 protected $pageRenderer;
62
63 /**
64 * @var \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
65 */
66 protected $backendUser;
67
68 /**
69 * @var \TYPO3\CMS\Lang\LanguageService
70 */
71 protected $languageService;
72
73 /**
74 * Constructor
75 */
76 public function __construct() {
77 $this->languageService = $GLOBALS['LANG'];
78 $this->languageService->includeLLFile('EXT:recycler/mod1/locallang.xlf');
79
80 $this->backendUser = $GLOBALS['BE_USER'];
81 $this->backendUser->modAccess($GLOBALS['MCONF'], TRUE);
82 }
83
84 /**
85 * Initializes the Module
86 *
87 * @return void
88 */
89 public function initialize() {
90 parent::init();
91 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
92 $this->doc->setModuleTemplate(ExtensionManagementUtility::extPath('recycler') . 'mod1/mod_template.html');
93 $this->doc->backPath = $GLOBALS['BACK_PATH'];
94 $this->doc->setExtDirectStateProvider();
95 $this->pageRenderer = $this->doc->getPageRenderer();
96 $this->relativePath = ExtensionManagementUtility::extRelPath('recycler');
97 $this->pageRecord = BackendUtility::readPageAccess($this->id, $this->perms_clause);
98 $this->isAccessibleForCurrentUser = $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin();
99 //don't access in workspace
100 if ($this->backendUser->workspace !== 0) {
101 $this->isAccessibleForCurrentUser = FALSE;
102 }
103 //read configuration
104 $modTS = $this->backendUser->getTSConfig('mod.recycler');
105 if ($this->isCurrentUserAdmin()) {
106 $this->allowDelete = TRUE;
107 } else {
108 $this->allowDelete = $modTS['properties']['allowDelete'] == '1';
109 }
110 if (isset($modTS['properties']['recordsPageLimit']) && (int)$modTS['properties']['recordsPageLimit'] > 0) {
111 $this->recordsPageLimit = (int)$modTS['properties']['recordsPageLimit'];
112 }
113 }
114
115 /**
116 * Renders the content of the module.
117 *
118 * @return void
119 */
120 public function render() {
121 $this->content .= $this->doc->header($this->languageService->getLL('title'));
122 $this->content .= '<p class="lead">' . $this->languageService->getLL('description') . '</p>';
123 if ($this->isAccessibleForCurrentUser) {
124 $this->loadHeaderData();
125 // div container for renderTo
126 $this->content .= '<div id="recyclerContent"></div>';
127 } else {
128 // If no access or if ID == zero
129 $this->content .= $this->doc->spacer(10);
130 }
131 }
132
133 /**
134 * Flushes the rendered content to browser.
135 *
136 * @return void
137 */
138 public function flush() {
139 $content = $this->doc->moduleBody($this->pageRecord, $this->getDocHeaderButtons(), $this->getTemplateMarkers());
140 // Renders the module page
141 $content = $this->doc->render($this->languageService->getLL('title'), $content);
142 $this->content = NULL;
143 $this->doc = NULL;
144 echo $content;
145 }
146
147 /**
148 * Determines whether the current user is admin.
149 *
150 * @return bool Whether the current user is admin
151 */
152 protected function isCurrentUserAdmin() {
153 return (bool)$this->backendUser->user['admin'];
154 }
155
156 /**
157 * Loads data in the HTML head section (e.g. JavaScript or stylesheet information).
158 *
159 * @return void
160 */
161 protected function loadHeaderData() {
162 // Load CSS Stylesheets:
163 $this->pageRenderer->addCssFile($this->relativePath . 'res/css/customExtJs.css');
164 // Load Ext JS:
165 $this->pageRenderer->loadExtJS();
166 $this->pageRenderer->enableExtJSQuickTips();
167 // Integrate dynamic JavaScript such as configuration or lables:
168 $this->pageRenderer->addInlineSettingArray('Recycler', $this->getJavaScriptConfiguration());
169 $this->pageRenderer->addInlineLanguageLabelArray($this->getJavaScriptLabels());
170 // Load Recycler JavaScript:
171 // Load Plugins
172 $uxPath = $this->doc->backPath . 'js/extjs/ux/';
173 $this->pageRenderer->addJsFile($uxPath . 'Ext.grid.RowExpander.js');
174 $this->pageRenderer->addJsFile($uxPath . 'Ext.app.SearchField.js');
175 $this->pageRenderer->addJsFile($uxPath . 'Ext.ux.FitToParent.js');
176 // Load main script
177 $this->pageRenderer->addJsFile($this->relativePath . 'res/js/t3_recycler.js');
178 }
179
180 /**
181 * Gets the JavaScript configuration for the Ext JS interface.
182 *
183 * @return array The JavaScript configuration
184 */
185 protected function getJavaScriptConfiguration() {
186 $configuration = array(
187 'pagingSize' => $this->recordsPageLimit,
188 'showDepthMenu' => 1,
189 'startUid' => $this->id,
190 'tableDefault' => 'pages',
191 'renderTo' => 'recyclerContent',
192 'isSSL' => GeneralUtility::getIndpEnv('TYPO3_SSL'),
193 'deleteDisable' => $this->allowDelete ? 0 : 1,
194 'depthSelection' => $this->getDataFromSession('depthSelection', 0),
195 'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'),
196 'States' => $this->backendUser->uc['moduleData']['web_recycler']['States']
197 );
198 return $configuration;
199 }
200
201 /**
202 * Gets the labels to be used in JavaScript in the Ext JS interface.
203 *
204 * @return array The labels to be used in JavaScript
205 */
206 protected function getJavaScriptLabels() {
207 $coreLabels = array(
208 'title' => $this->languageService->getLL('title'),
209 'path' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'),
210 'table' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.table'),
211 'depth' => $this->languageService->sL('LLL:EXT:lang/locallang_mod_web_perm.xlf:Depth'),
212 'depth_0' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
213 'depth_1' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
214 'depth_2' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
215 'depth_3' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
216 'depth_4' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_4'),
217 'depth_infi' => $this->languageService->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
218 );
219 $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
220 $javaScriptLabels = array_merge($coreLabels, $extensionLabels);
221 return $javaScriptLabels;
222 }
223
224 /**
225 * Gets labels to be used in JavaScript fetched from the current locallang file.
226 *
227 * @param string $selectionPrefix Prefix to select the correct labels (default: 'js.')
228 * @param string $stripFromSelectionName Sub-prefix to be removed from label names in the result (default: '')
229 * @return array Labels to be used in JavaScript of the current locallang file
230 * @todo Check, whether this method can be moved in a generic way to $GLOBALS['LANG']
231 */
232 protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
233 $extraction = array();
234 $labels = array_merge((array)$GLOBALS['LOCAL_LANG']['default'], (array)$GLOBALS['LOCAL_LANG'][$this->languageService->lang]);
235 // Regular expression to strip the selection prefix and possibly something from the label name:
236 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
237 // Iterate through all locallang labels:
238 foreach ($labels as $label => $value) {
239 if (strpos($label, $selectionPrefix) === 0) {
240 $key = preg_replace($labelPattern, '', $label);
241 $extraction[$key] = $value;
242 }
243 }
244 return $extraction;
245 }
246
247 /**
248 * Gets the buttons that shall be rendered in the docHeader.
249 *
250 * @return array Available buttons for the docHeader
251 */
252 protected function getDocHeaderButtons() {
253 $buttons = array(
254 'csh' => BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
255 'shortcut' => $this->getShortcutButton(),
256 'save' => ''
257 );
258 // SAVE button
259 $buttons['save'] = '';
260 return $buttons;
261 }
262
263 /**
264 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
265 *
266 * @return string HTML representation of the shortcut button
267 */
268 protected function getShortcutButton() {
269 $result = '';
270 if ($this->backendUser->mayMakeShortcut()) {
271 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
272 }
273 return $result;
274 }
275
276 /**
277 * Gets the filled markers that are used in the HTML template.
278 *
279 * @return array The filled marker array
280 */
281 protected function getTemplateMarkers() {
282 $markers = array(
283 'FUNC_MENU' => $this->getFunctionMenu(),
284 'CONTENT' => $this->content,
285 'TITLE' => $this->languageService->getLL('title')
286 );
287 return $markers;
288 }
289
290 /**
291 * Gets the function menu selector for this backend module.
292 *
293 * @return string The HTML representation of the function menu selector
294 */
295 protected function getFunctionMenu() {
296 return BackendUtility::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function']);
297 }
298
299 /**
300 * Gets data from the session of the current backend user.
301 *
302 * @param string $identifier The identifier to be used to get the data
303 * @param string $default The default date to be used if nothing was found in the session
304 * @return string The accordant data in the session of the current backend user
305 */
306 protected function getDataFromSession($identifier, $default = NULL) {
307 $sessionData = &$this->backendUser->uc['tx_recycler'];
308 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
309 $data = $sessionData[$identifier];
310 } else {
311 $data = $default;
312 }
313 return $data;
314 }
315 }