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