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