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