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