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