Fixed bug #12437: Recycler produces some scroll bars + visual cleanup + js fixes
[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 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('title'), $GLOBALS['LANG']->getLL('description'));
92 if ($this->isAccessibleForCurrentUser) {
93 $this->loadHeaderData();
94 // div container for renderTo
95 $this->content .= '<div id="recyclerContent"></div>';
96 } else {
97 // If no access or if ID == zero
98 $this->content .= $this->doc->spacer(10);
99 }
100 }
101
102 /**
103 * Flushes the rendered content to browser.
104 *
105 * @return void
106 */
107 public function flush() {
108 $content = $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
109 $content.= $this->doc->moduleBody(
110 $this->pageRecord,
111 $this->getDocHeaderButtons(),
112 $this->getTemplateMarkers()
113 );
114 $content.= $this->doc->endPage();
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 $gridHeight = isset($GLOBALS['BE_USER']->uc['recyclerGridHeight']) && intval($GLOBALS['BE_USER']->uc['recyclerGridHeight']) ? intval($GLOBALS['BE_USER']->uc['recyclerGridHeight']) : 600;
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 'gridHeight' => $gridHeight,
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 $extensionLabels = $this->getJavaScriptLabelsFromLocallang('js.', 'label_');
217 return array_merge($coreLabels, $extensionLabels);
218 }
219
220 /**
221 * Gets labels to be used in JavaScript fetched from the current locallang file.
222 *
223 * @param string $selectionPrefix: Prefix to select the correct labels (default: 'js.')
224 * @param string $stripFromSelectionName: Sub-prefix to be removed from label names in the result (default: '')
225 * @return array Lables to be used in JavaScript of the current locallang file
226 * @todo Check, whether this method can be moved in a generic way to $GLOBALS['LANG']
227 */
228 protected function getJavaScriptLabelsFromLocallang($selectionPrefix = 'js.', $stripFromSelectionName = '') {
229 $extraction = array();
230 $labels = array_merge(
231 (array)$GLOBALS['LOCAL_LANG']['default'],
232 (array)$GLOBALS['LOCAL_LANG'][$GLOBALS['LANG']->lang]
233 );
234 // Regular expression to strip the selection prefix and possibly something from the label name:
235 $labelPattern = '#^' . preg_quote($selectionPrefix, '#') . '(' . preg_quote($stripFromSelectionName, '#') . ')?#';
236 // Iterate throuh all locallang lables:
237 foreach ($labels as $label => $value) {
238 if (strpos($label, $selectionPrefix) === 0) {
239 $key = preg_replace($labelPattern, '', $label);
240 $extraction[$key] = $value;
241 }
242 }
243 return $extraction;
244 }
245
246 /**
247 * Gets the buttons that shall be rendered in the docHeader.
248 *
249 * @return array Available buttons for the docHeader
250 */
251 protected function getDocHeaderButtons() {
252 $buttons = array(
253 'csh' => t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
254 'shortcut' => $this->getShortcutButton(),
255 'save' => ''
256 );
257
258 // SAVE button
259 $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) . '" />';
260
261 return $buttons;
262 }
263
264 /**
265 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
266 *
267 * @return string HTML representiation of the shortcut button
268 */
269 protected function getShortcutButton() {
270 $result = '';
271 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
272 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
273 }
274 return $result;
275 }
276
277 /**
278 * Gets the filled markers that are used in the HTML template.
279 *
280 * @return array The filled marker array
281 */
282 protected function getTemplateMarkers() {
283 $markers = array(
284 'FUNC_MENU' => $this->getFunctionMenu(),
285 'CONTENT' => $this->content,
286 'TITLE' => $GLOBALS['LANG']->getLL('title'),
287 );
288 return $markers;
289 }
290
291 /**
292 * Gets the function menu selector for this backend module.
293 *
294 * @return string The HTML representation of the function menu selector
295 */
296 protected function getFunctionMenu() {
297 return t3lib_BEfunc::getFuncMenu(
298 0,
299 'SET[function]',
300 $this->MOD_SETTINGS['function'],
301 $this->MOD_MENU['function']
302 );
303 }
304
305 /**
306 * Gets data from the session of the current backend user.
307 *
308 * @param string $identifier: The identifier to be used to get the data
309 * @param string $default: The default date to be used if nothing was found in the session
310 * @return string The accordant data in the session of the current backend user
311 */
312 protected function getDataFromSession($identifier, $default = NULL) {
313 $sessionData =& $GLOBALS['BE_USER']->uc['tx_recycler'];
314 if (isset($sessionData[$identifier]) && $sessionData[$identifier]) {
315 $data = $sessionData[$identifier];
316 } else {
317 $data = $default;
318 }
319 return $data;
320 }
321 }
322
323
324
325 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']) {
326 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/recycler/mod1/index.php']);
327 }
328
329
330
331 // Make instance:
332 $SOBE = t3lib_div::makeInstance('tx_recycler_module1');
333 $SOBE->initialize();
334
335 // Include files?
336 foreach($SOBE->include_once as $INC_FILE) {
337 include_once($INC_FILE);
338 }
339
340 $SOBE->render();
341 $SOBE->flush();
342 ?>