[TASK] Fix some typos
[Packages/TYPO3.CMS.git] / typo3 / sysext / recycler / mod1 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009-2011 Julian Kleinhans <typo3@kj187.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 $LANG->includeLLFile('EXT:recycler/mod1/locallang.xml');
26 $BE_USER->modAccess($MCONF, 1); // This checks permissions and exits if the users has no permission for entry.
27
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 tx_recycler_module1 extends t3lib_SCbase {
36 /**
37 * @var template
38 */
39 public $doc;
40
41 protected $relativePath;
42 protected $pageRecord = array();
43 protected $isAccessibleForCurrentUser = false;
44
45 protected $allowDelete = false;
46 protected $recordsPageLimit = 50;
47
48 /**
49 * @var t3lib_pageRenderer
50 */
51 protected $pageRenderer;
52
53 /**
54 * Initializes the Module
55 *
56 * @return void
57 */
58 public function initialize() {
59 parent::init();
60 $this->doc = t3lib_div::makeInstance('template');
61 $this->doc->setModuleTemplate(t3lib_extMgm::extPath('recycler') . 'mod1/mod_template.html');
62 $this->doc->backPath = $GLOBALS['BACK_PATH'];
63 $this->doc->setExtDirectStateProvider();
64
65 $this->pageRenderer = $this->doc->getPageRenderer();
66
67 $this->relativePath = t3lib_extMgm::extRelPath('recycler');
68 $this->pageRecord = t3lib_BEfunc::readPageAccess($this->id, $this->perms_clause);
69 $this->isAccessibleForCurrentUser = (
70 $this->id && is_array($this->pageRecord) || !$this->id && $this->isCurrentUserAdmin()
71 );
72
73 //don't access in workspace
74 if ($GLOBALS['BE_USER']->workspace !== 0) {
75 $this->isAccessibleForCurrentUser = false;
76 }
77
78 //read configuration
79 $modTS = $GLOBALS['BE_USER']->getTSConfig('mod.recycler');
80 if ($this->isCurrentUserAdmin()) {
81 $this->allowDelete = true;
82 } else {
83 $this->allowDelete = ($modTS['properties']['allowDelete'] == '1');
84 }
85 if (isset($modTS['properties']['recordsPageLimit']) && intval($modTS['properties']['recordsPageLimit']) > 0) {
86 $this->recordsPageLimit = intval($modTS['properties']['recordsPageLimit']);
87 }
88 }
89
90 /**
91 * Renders the content of the module.
92 *
93 * @return void
94 */
95 public function render() {
96 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('title'), $GLOBALS['LANG']->getLL('description'));
97 if ($this->isAccessibleForCurrentUser) {
98 $this->loadHeaderData();
99 // div container for renderTo
100 $this->content .= '<div id="recyclerContent"></div>';
101 } else {
102 // If no access or if ID == zero
103 $this->content .= $this->doc->spacer(10);
104 }
105 }
106
107 /**
108 * Flushes the rendered content to browser.
109 *
110 * @return void
111 */
112 public function flush() {
113 $content = $this->doc->moduleBody(
114 $this->pageRecord,
115 $this->getDocHeaderButtons(),
116 $this->getTemplateMarkers()
117 );
118 // Renders the module page
119 $content = $this->doc->render(
120 $GLOBALS['LANG']->getLL('title'),
121 $content
122 );
123
124 $this->content = null;
125 $this->doc = null;
126
127 echo $content;
128 }
129
130 /**
131 * Determines whether the current user is admin.
132 *
133 * @return boolean Whether the current user is admin
134 */
135 protected function isCurrentUserAdmin() {
136 return (bool)$GLOBALS['BE_USER']->user['admin'];
137 }
138
139 /**
140 * Loads data in the HTML head section (e.g. JavaScript or stylesheet information).
141 *
142 * @return void
143 */
144 protected function loadHeaderData() {
145 // Load CSS Stylesheets:
146 $this->pageRenderer->addCssFile($this->relativePath . 'res/css/customExtJs.css');
147
148 // Load Ext JS:
149 $this->pageRenderer->loadExtJS();
150 $this->pageRenderer->enableExtJSQuickTips();
151
152 // Integrate dynamic JavaScript such as configuration or lables:
153 $this->pageRenderer->addInlineSettingArray(
154 'Recycler',
155 $this->getJavaScriptConfiguration()
156 );
157 $this->pageRenderer->addInlineLanguageLabelArray(
158 $this->getJavaScriptLabels()
159 );
160
161
162 // Load Recycler JavaScript:
163
164 // Load Plugins
165 $uxPath = $this->doc->backpath . '../t3lib/js/extjs/ux/';
166 $this->pageRenderer->addJsFile($uxPath . 'Ext.grid.RowExpander.js');
167 $this->pageRenderer->addJsFile($uxPath . 'Ext.app.SearchField.js');
168 $this->pageRenderer->addJsFile($uxPath . 'Ext.ux.FitToParent.js');
169 // Load main script
170 $this->pageRenderer->addJsFile($this->relativePath . 'res/js/t3_recycler.js');
171 }
172
173 /**
174 * Gets the JavaScript configuration for the Ext JS interface.
175 *
176 * @return array The JavaScript configuration
177 */
178 protected function getJavaScriptConfiguration() {
179 $configuration = array(
180 'pagingSize' => $this->recordsPageLimit,
181 'showDepthMenu' => 1,
182 'startUid' => $this->id,
183 'tableDefault' => 'pages',
184 'renderTo' => 'recyclerContent',
185 'isSSL' => t3lib_div::getIndpEnv('TYPO3_SSL'),
186 'ajaxController' => $this->doc->backPath . 'ajax.php?ajaxID=tx_recycler::controller',
187 'deleteDisable' => $this->allowDelete ? 0 : 1,
188 'depthSelection' => $this->getDataFromSession('depthSelection', 0),
189 'tableSelection' => $this->getDataFromSession('tableSelection', 'pages'),
190 'States' => $GLOBALS['BE_USER']->uc['moduleData']['web_recycler']['States'],
191 );
192 return $configuration;
193 }
194
195 /**
196 * Gets the labels to be used in JavaScript in the Ext JS interface.
197 *
198 * @return array The labels to be used in JavaScript
199 */
200 protected function getJavaScriptLabels() {
201 $coreLabels = array(
202 'title' => $GLOBALS['LANG']->getLL('title'),
203 'path' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.path'),
204 'table' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.table'),
205 'depth' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_web_perm.xml:Depth'),
206 'depth_0' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'),
207 'depth_1' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'),
208 'depth_2' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'),
209 'depth_3' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'),
210 'depth_4' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_4'),
211 'depth_infi' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'),
212 );
213
214 $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
215 $javaScriptLabels = array_merge($coreLabels, $extensionLabels);
216
217 // Convert labels back to UTF-8 since json_encode() only works with UTF-8:
218 if ($GLOBALS['LANG']->charSet !== 'utf-8') {
219 $GLOBALS['LANG']->csConvObj->convArray($javaScriptLabels, $GLOBALS['LANG']->charSet, 'utf-8');
220 }
221
222 return $javaScriptLabels;
223 }
224
225 /**
226 * Gets labels to be used in JavaScript fetched from the current locallang file.
227 *
228 * @param string $selectionPrefix: Prefix to select the correct labels (default: 'js.')
229 * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
230 * @return array Lables to be used in JavaScript of the current locallang file
231 * @todo Check, whether this method can be moved in a generic way to $GLOBALS['LANG']
232 */
233 protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
234 $extraction = array();
235 $labels = array_merge(
236 (array)$GLOBALS['LOCAL_LANG']['default'],
237 (array)$GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]
238 );
239 // Regular expression to strip the selection prefix and possibly something from the label name:
240 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
241 // Iterate through all locallang lables:
242 foreach ($labels as $label => $value) {
243 if (strpos($label, $selectionPrefix) === 0) {
244 $key = preg_replace($labelPattern, '', $label);
245 $extraction[$key] = $value;
246 }
247 }
248 return $extraction;
249 }
250
251 /**
252 * Gets the buttons that shall be rendered in the docHeader.
253 *
254 * @return array Available buttons for the docHeader
255 */
256 protected function getDocHeaderButtons() {
257 $buttons = array(
258 'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
259 'shortcut' => $this->getShortcutButton(),
260 'save' => ''
261 );
262
263 // SAVE button
264 $buttons['save'] = ''; //<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) . '" />';
265
266 return $buttons;
267 }
268
269 /**
270 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
271 *
272 * @return string HTML representation of the shortcut button
273 */
274 protected function getShortcutButton() {
275 $result = '';
276 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
277 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
278 }
279 return $result;
280 }
281
282 /**
283 * Gets the filled markers that are used in the HTML template.
284 *
285 * @return array The filled marker array
286 */
287 protected function getTemplateMarkers() {
288 $markers = array(
289 'FUNC_MENU' => $this->getFunctionMenu(),
290 'CONTENT' => $this->content,
291 'TITLE' => $GLOBALS['LANG']->getLL('title'),
292 );
293 return $markers;
294 }
295
296 /**
297 * Gets the function menu selector for this backend module.
298 *
299 * @return string The HTML representation of the function menu selector
300 */
301 protected function getFunctionMenu() {
302 return t3lib_BEfunc::getFuncMenu(
303 0,
304 'SET[function]',
305 $this->MOD_SETTINGS['function'],
306 $this->MOD_MENU['function']
307 );
308 }
309
310 /**
311 * Gets data from the session of the current backend user.
312 *
313 * @param string $identifier: The identifier to be used to get the data
314 * @param string $default: The default date to be used if nothing was found in the session
315 * @return string The accordant data in the session of the current backend user
316 */
317 protected function getDataFromSession($identifier, $default = NULL) {
318 $sessionData =& $GLOBALS['BE_USER']->uc['tx_recycler'];
319 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
320 $data = $sessionData[$identifier];
321 } else {
322 $data = $default;
323 }
324 return $data;
325 }
326 }
327
328
329
330 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php'])) {
331 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']);
332 }
333
334
335
336 // Make instance:
337 $SOBE = t3lib_div::makeInstance('tx_recycler_module1');
338 $SOBE->initialize();
339
340 // Include files?
341 foreach($SOBE->include_once as $INC_FILE) {
342 include_once($INC_FILE);
343 }
344
345 $SOBE->render();
346 $SOBE->flush();
347 ?>