[TASK] Cleanup ext:recordlist
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / RecordList.php
1 <?php
2 namespace TYPO3\CMS\Recordlist;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
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 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Script Class for the Web > List module; rendering the listing of records on a page
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class RecordList {
36
37 // Internal, GPvars:
38 // Page Id for which to make the listing
39 /**
40 * @var integer
41 * @todo Define visibility
42 */
43 public $id;
44
45 // Pointer - for browsing list of records.
46 /**
47 * @todo Define visibility
48 */
49 public $pointer;
50
51 // Thumbnails or not
52 /**
53 * @todo Define visibility
54 */
55 public $imagemode;
56
57 // Which table to make extended listing for
58 /**
59 * @todo Define visibility
60 */
61 public $table;
62
63 // Search-fields
64 /**
65 * @todo Define visibility
66 */
67 public $search_field;
68
69 // Search-levels
70 /**
71 * @todo Define visibility
72 */
73 public $search_levels;
74
75 // Show-limit
76 /**
77 * @todo Define visibility
78 */
79 public $showLimit;
80
81 // Return URL
82 /**
83 * @todo Define visibility
84 */
85 public $returnUrl;
86
87 // Clear-cache flag - if set, clears page cache for current id.
88 /**
89 * @todo Define visibility
90 */
91 public $clear_cache;
92
93 // Command: Eg. "delete" or "setCB" (for TCEmain / clipboard operations)
94 /**
95 * @todo Define visibility
96 */
97 public $cmd;
98
99 // Table on which the cmd-action is performed.
100 /**
101 * @todo Define visibility
102 */
103 public $cmd_table;
104
105 // Internal, static:
106 // Page select perms clause
107 /**
108 * @todo Define visibility
109 */
110 public $perms_clause;
111
112 // Module TSconfig
113 /**
114 * @todo Define visibility
115 */
116 public $modTSconfig;
117
118 // Current ids page record
119 /**
120 * @todo Define visibility
121 */
122 public $pageinfo;
123
124 /**
125 * Document template object
126 *
127 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
128 * @todo Define visibility
129 */
130 public $doc;
131
132 // Module configuration
133 /**
134 * @todo Define visibility
135 */
136 public $MCONF = array();
137
138 // Menu configuration
139 /**
140 * @todo Define visibility
141 */
142 public $MOD_MENU = array();
143
144 // Module settings (session variable)
145 /**
146 * @todo Define visibility
147 */
148 public $MOD_SETTINGS = array();
149
150 // Array, where files to include is accumulated in the init() function
151 /**
152 * @todo Define visibility
153 */
154 public $include_once = array();
155
156 // Internal, dynamic:
157 // Module output accumulation
158 /**
159 * @todo Define visibility
160 */
161 public $content;
162
163 /**
164 * Constructor
165 */
166 public function __construct() {
167 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
168 $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], 1);
169 }
170
171 /**
172 * Initializing the module
173 *
174 * @return void
175 * @todo Define visibility
176 */
177 public function init() {
178 // Setting module configuration / page select clause
179 $this->MCONF = $GLOBALS['MCONF'];
180 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
181 // GPvars:
182 $this->id = (int) \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
183 $this->pointer = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('pointer');
184 $this->imagemode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('imagemode');
185 $this->table = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('table');
186 $this->search_field = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_field');
187 $this->search_levels = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('search_levels');
188 $this->showLimit = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('showLimit');
189 $this->returnUrl = \TYPO3\CMS\Core\Utility\GeneralUtility::sanitizeLocalUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('returnUrl'));
190 $this->clear_cache = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('clear_cache');
191 $this->cmd = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd');
192 $this->cmd_table = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cmd_table');
193 // Initialize menu
194 $this->menuConfig();
195 }
196
197 /**
198 * Initialize function menu array
199 *
200 * @return void
201 * @todo Define visibility
202 */
203 public function menuConfig() {
204 // MENU-ITEMS:
205 $this->MOD_MENU = array(
206 'bigControlPanel' => '',
207 'clipBoard' => '',
208 'localization' => ''
209 );
210 // Loading module configuration:
211 $this->modTSconfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getModTSconfig($this->id, 'mod.' . $this->MCONF['name']);
212 // Clean up settings:
213 $this->MOD_SETTINGS = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleData($this->MOD_MENU, \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('SET'), $this->MCONF['name']);
214 }
215
216 /**
217 * Clears page cache for the current id, $this->id
218 *
219 * @return void
220 * @todo Define visibility
221 */
222 public function clearCache() {
223 if ($this->clear_cache) {
224 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
225 $tce->stripslashes_values = 0;
226 $tce->start(array(), array());
227 $tce->clear_cacheCmd($this->id);
228 }
229 }
230
231 /**
232 * Main function, starting the rendering of the list.
233 *
234 * @return void
235 * @todo Define visibility
236 */
237 public function main() {
238 // Start document template object:
239 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
240 $this->doc->backPath = $GLOBALS['BACK_PATH'];
241 $this->doc->setModuleTemplate('EXT:recordlist/Resources/Private/Templates/db_list.html');
242 // Loading current page record and checking access:
243 $this->pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $this->perms_clause);
244 $access = is_array($this->pageinfo) ? 1 : 0;
245 // Apply predefined values for hidden checkboxes
246 // Set predefined value for DisplayBigControlPanel:
247 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
248 $this->MOD_SETTINGS['bigControlPanel'] = TRUE;
249 } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
250 $this->MOD_SETTINGS['bigControlPanel'] = FALSE;
251 }
252 // Set predefined value for Clipboard:
253 if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
254 $this->MOD_SETTINGS['clipBoard'] = TRUE;
255 } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
256 $this->MOD_SETTINGS['clipBoard'] = FALSE;
257 }
258 // Set predefined value for LocalizationView:
259 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
260 $this->MOD_SETTINGS['localization'] = TRUE;
261 } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
262 $this->MOD_SETTINGS['localization'] = FALSE;
263 }
264 // Initialize the dblist object:
265 /** @var $dblist \TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList */
266 $dblist = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\RecordList\\DatabaseRecordList');
267 $dblist->backPath = $GLOBALS['BACK_PATH'];
268 $dblist->script = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_list', array(), '');
269 $dblist->calcPerms = $GLOBALS['BE_USER']->calcPerms($this->pageinfo);
270 $dblist->thumbs = $GLOBALS['BE_USER']->uc['thumbnailsByDefault'];
271 $dblist->returnUrl = $this->returnUrl;
272 $dblist->allFields = $this->MOD_SETTINGS['bigControlPanel'] || $this->table ? 1 : 0;
273 $dblist->localizationView = $this->MOD_SETTINGS['localization'];
274 $dblist->showClipboard = 1;
275 $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
276 $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
277 $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
278 $dblist->hideTranslations = $this->modTSconfig['properties']['hideTranslations'];
279 $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
280 $dblist->alternateBgColors = $this->modTSconfig['properties']['alternateBgColors'] ? 1 : 0;
281 $dblist->allowedNewTables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], 1);
282 $dblist->deniedNewTables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], 1);
283 $dblist->newWizards = $this->modTSconfig['properties']['newWizards'] ? 1 : 0;
284 $dblist->pageRow = $this->pageinfo;
285 $dblist->counter++;
286 $dblist->MOD_MENU = array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
287 $dblist->modTSconfig = $this->modTSconfig;
288 $clickTitleMode = trim($this->modTSconfig['properties']['clickTitleMode']);
289 $dblist->clickTitleMode = $clickTitleMode === '' ? 'edit' : $clickTitleMode;
290 // Clipboard is initialized:
291 // Start clipboard
292 $dblist->clipObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Clipboard\\Clipboard');
293 // Initialize - reads the clipboard content from the user session
294 $dblist->clipObj->initializeClipboard();
295 // Clipboard actions are handled:
296 // CB is the clipboard command array
297 $CB = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('CB');
298 if ($this->cmd == 'setCB') {
299 // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked.
300 // By merging we get a full array of checked/unchecked elements
301 // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
302 $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge((array) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('CBH'), (array) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('CBC')), $this->cmd_table);
303 }
304 if (!$this->MOD_SETTINGS['clipBoard']) {
305 // If the clipboard is NOT shown, set the pad to 'normal'.
306 $CB['setP'] = 'normal';
307 }
308 // Execute commands.
309 $dblist->clipObj->setCmd($CB);
310 // Clean up pad
311 $dblist->clipObj->cleanCurrent();
312 // Save the clipboard content
313 $dblist->clipObj->endClipboard();
314 // This flag will prevent the clipboard panel in being shown.
315 // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
316 $dblist->dontShowClipControlPanels = $GLOBALS['CLIENT']['FORMSTYLE'] && !$this->MOD_SETTINGS['bigControlPanel'] && $dblist->clipObj->current == 'normal' && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers'];
317 // If there is access to the page, then render the list contents and set up the document template object:
318 if ($access) {
319 // Deleting records...:
320 // Has not to do with the clipboard but is simply the delete action. The clipboard object is used to clean up the submitted entries to only the selected table.
321 if ($this->cmd == 'delete') {
322 $items = $dblist->clipObj->cleanUpCBC(\TYPO3\CMS\Core\Utility\GeneralUtility::_POST('CBC'), $this->cmd_table, 1);
323 if (count($items)) {
324 $cmd = array();
325 foreach ($items as $iK => $value) {
326 $iKParts = explode('|', $iK);
327 $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
328 }
329 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
330 $tce->stripslashes_values = 0;
331 $tce->start(array(), $cmd);
332 $tce->process_cmdmap();
333 if (isset($cmd['pages'])) {
334 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
335 }
336 $tce->printLogErrorMessages(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
337 }
338 }
339 // Initialize the listing object, dblist, for rendering the list:
340 $this->pointer = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
341 $dblist->start($this->id, $this->table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
342 $dblist->setDispFields();
343 // Render versioning selector:
344 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('version')) {
345 $dblist->HTMLcode .= $this->doc->getVersionSelector($this->id);
346 }
347 // Render the list of tables:
348 $dblist->generateList();
349 // Write the bottom of the page:
350 $dblist->writeBottom();
351 $listUrl = substr($dblist->listURL(), strlen($GLOBALS['BACK_PATH']));
352 // Add JavaScript functions to the page:
353 $this->doc->JScode = $this->doc->wrapScriptTags('
354 function jumpToUrl(URL) { //
355 window.location.href = URL;
356 return false;
357 }
358 function jumpExt(URL,anchor) { //
359 var anc = anchor?anchor:"";
360 window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
361 return false;
362 }
363 function jumpSelf(URL) { //
364 window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
365 return false;
366 }
367
368 function setHighlight(id) { //
369 top.fsMod.recentIds["web"]=id;
370 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
371
372 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
373 top.content.nav_frame.refresh_nav();
374 }
375 }
376 ' . $this->doc->redirectUrls($listUrl) . '
377 ' . $dblist->CBfunctions() . '
378 function editRecords(table,idList,addParams,CBflag) { //
379 window.location.href="' . $GLOBALS['BACK_PATH'] . 'alt_doc.php?returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI')) . '&edit["+table+"]["+idList+"]=edit"+addParams;
380 }
381 function editList(table,idList) { //
382 var list="";
383
384 // Checking how many is checked, how many is not
385 var pointer=0;
386 var pos = idList.indexOf(",");
387 while (pos!=-1) {
388 if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
389 list+=idList.substr(pointer,pos-pointer)+",";
390 }
391 pointer=pos+1;
392 pos = idList.indexOf(",",pointer);
393 }
394 if (cbValue(table+"|"+idList.substr(pointer))) {
395 list+=idList.substr(pointer)+",";
396 }
397
398 return list ? list : idList;
399 }
400
401 if (top.fsMod) top.fsMod.recentIds["web"] = ' . intval($this->id) . ';
402 ');
403 // Setting up the context sensitive menu:
404 $this->doc->getContextMenuCode();
405 }
406 // access
407 // Begin to compile the whole page, starting out with page header:
408 $this->body = $this->doc->header($this->pageinfo['title']);
409 $this->body .= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
410 $this->body .= $dblist->HTMLcode;
411 $this->body .= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
412 // If a listing was produced, create the page footer with search form etc:
413 if ($dblist->HTMLcode) {
414 // Making field select box (when extended view for a single table is enabled):
415 if ($dblist->table) {
416 $this->body .= $dblist->fieldSelectBox($dblist->table);
417 }
418 // Adding checkbox options for extended listing and clipboard display:
419 $this->body .= '
420
421 <!--
422 Listing options for extended view, clipboard and localization view
423 -->
424 <div id="typo3-listOptions">
425 <form action="" method="post">';
426 // Add "display bigControlPanel" checkbox:
427 if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
428 $this->body .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLargeControl"');
429 $this->body .= '<label for="checkLargeControl">' . \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('largeControl', TRUE)) . '</label><br />';
430 }
431 // Add "clipboard" checkbox:
432 if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
433 if ($dblist->showClipboard) {
434 $this->body .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', $this->table ? '&table=' . $this->table : '', 'id="checkShowClipBoard"');
435 $this->body .= '<label for="checkShowClipBoard">' . \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('showClipBoard', TRUE)) . '</label><br />';
436 }
437 }
438 // Add "localization view" checkbox:
439 if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
440 $this->body .= \TYPO3\CMS\Backend\Utility\BackendUtility::getFuncCheck($this->id, 'SET[localization]', $this->MOD_SETTINGS['localization'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLocalization"');
441 $this->body .= '<label for="checkLocalization">' . \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $GLOBALS['LANG']->getLL('localization', TRUE)) . '</label><br />';
442 }
443 $this->body .= '
444 </form>
445 </div>';
446 // Printing clipboard if enabled:
447 if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard) {
448 $this->body .= '<div class="db_list-dashboard">' . $dblist->clipObj->printClipboard() . '</div>';
449 }
450 // Search box:
451 if (!$this->modTSconfig['properties']['disableSearchBox']) {
452 $sectionTitle = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_searchbox', $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.search', TRUE));
453 $this->body .= '<div class="db_list-searchbox">' . $this->doc->section($sectionTitle, $dblist->getSearchBox(), FALSE, TRUE, FALSE, TRUE) . '</div>';
454 }
455 // Additional footer content
456 $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/mod1/index.php']['drawFooterHook'];
457 if (is_array($footerContentHook)) {
458 foreach ($footerContentHook as $hook) {
459 $params = array();
460 $this->body .= \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($hook, $params, $this);
461 }
462 }
463 }
464 // Setting up the buttons and markers for docheader
465 $docHeaderButtons = $dblist->getButtons();
466 $markers = array(
467 'CSH' => $docHeaderButtons['csh'],
468 'CONTENT' => $this->body,
469 'EXTRACONTAINERCLASS' => $this->table ? 'singletable' : ''
470 );
471 // Build the <body> for the module
472 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
473 // Renders the module page
474 $this->content = $this->doc->render('DB list', $this->content);
475 }
476
477 /**
478 * Outputting the accumulated content to screen
479 *
480 * @return void
481 * @todo Define visibility
482 */
483 public function printContent() {
484 echo $this->content;
485 }
486
487 }
488
489
490 ?>