TYPO3  7.6
RecordList.php
Go to the documentation of this file.
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 
37 
42 {
48  public $id;
49 
55  public $pointer;
56 
62  public $imagemode;
63 
69  public $table;
70 
76  public $search_field;
77 
84 
90  public $showLimit;
91 
97  public $returnUrl;
98 
104  public $clear_cache;
105 
111  public $cmd;
112 
118  public $cmd_table;
119 
126 
132  public $modTSconfig;
133 
139  public $pageinfo;
140 
146  public $doc;
147 
154  public $MCONF = array();
155 
161  public $MOD_MENU = array();
162 
168  public $MOD_SETTINGS = array();
169 
175  public $content;
176 
182  protected $moduleName = 'web_list';
183 
187  public $body = '';
188 
192  protected $pageRenderer = null;
193 
197  protected $iconFactory;
198 
202  public function __construct()
203  {
204  parent::__construct();
205  $this->getLanguageService()->includeLLFile('EXT:lang/locallang_mod_web_list.xlf');
206  $this->moduleTemplate->getPageRenderer()->loadJquery();
207  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
208  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Recordlist');
209  }
210 
216  public function init()
217  {
218  $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
219  $backendUser = $this->getBackendUserAuthentication();
220  $this->perms_clause = $backendUser->getPagePermsClause(1);
221  // Get session data
222  $sessionData = $backendUser->getSessionData(__CLASS__);
223  $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
224  // GPvars:
225  $this->id = (int)GeneralUtility::_GP('id');
226  $this->pointer = GeneralUtility::_GP('pointer');
227  $this->imagemode = GeneralUtility::_GP('imagemode');
228  $this->table = GeneralUtility::_GP('table');
229  $this->search_field = GeneralUtility::_GP('search_field');
230  $this->search_levels = (int)GeneralUtility::_GP('search_levels');
231  $this->showLimit = GeneralUtility::_GP('showLimit');
232  $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
233  $this->clear_cache = GeneralUtility::_GP('clear_cache');
234  $this->cmd = GeneralUtility::_GP('cmd');
235  $this->cmd_table = GeneralUtility::_GP('cmd_table');
236  $sessionData['search_field'] = $this->search_field;
237  // Initialize menu
238  $this->menuConfig();
239  // Store session data
240  $backendUser->setAndSaveSessionData(RecordList::class, $sessionData);
241  $this->getPageRenderer()->addInlineLanguageLabelFile('EXT:lang/locallang_mod_web_list.xlf');
242  }
243 
249  public function menuConfig()
250  {
251  // MENU-ITEMS:
252  $this->MOD_MENU = array(
253  'bigControlPanel' => '',
254  'clipBoard' => '',
255  'localization' => ''
256  );
257  // Loading module configuration:
258  $this->modTSconfig = BackendUtility::getModTSconfig($this->id, 'mod.' . $this->moduleName);
259  // Clean up settings:
260  $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, GeneralUtility::_GP('SET'), $this->moduleName);
261  }
262 
268  public function clearCache()
269  {
270  if ($this->clear_cache) {
271  $tce = GeneralUtility::makeInstance(DataHandler::class);
272  $tce->stripslashes_values = 0;
273  $tce->start(array(), array());
274  $tce->clear_cacheCmd($this->id);
275  }
276  }
277 
283  public function main()
284  {
285  $backendUser = $this->getBackendUserAuthentication();
286  $lang = $this->getLanguageService();
287  // Loading current page record and checking access:
288  $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
289  $access = is_array($this->pageinfo) ? 1 : 0;
290  // Start document template object:
291  // We need to keep this due to deeply nested dependencies
292  $this->doc = GeneralUtility::makeInstance(DocumentTemplate::class);
293 
294  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/AjaxDataHandler');
295  $calcPerms = $backendUser->calcPerms($this->pageinfo);
296  $userCanEditPage = $calcPerms & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
297  if ($userCanEditPage) {
298  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
299  PageActions.setPageId(' . (int)$this->id . ');
300  PageActions.initializePageTitleRenaming();
301  }');
302  }
303  $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Recordlist/Tooltip');
304  // Apply predefined values for hidden checkboxes
305  // Set predefined value for DisplayBigControlPanel:
306  if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'activated') {
307  $this->MOD_SETTINGS['bigControlPanel'] = true;
308  } elseif ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'deactivated') {
309  $this->MOD_SETTINGS['bigControlPanel'] = false;
310  }
311  // Set predefined value for Clipboard:
312  if ($this->modTSconfig['properties']['enableClipBoard'] === 'activated') {
313  $this->MOD_SETTINGS['clipBoard'] = true;
314  } elseif ($this->modTSconfig['properties']['enableClipBoard'] === 'deactivated') {
315  $this->MOD_SETTINGS['clipBoard'] = false;
316  } else {
317  if ($this->MOD_SETTINGS['clipBoard'] === null) {
318  $this->MOD_SETTINGS['clipBoard'] = true;
319  }
320  }
321  // Set predefined value for LocalizationView:
322  if ($this->modTSconfig['properties']['enableLocalizationView'] === 'activated') {
323  $this->MOD_SETTINGS['localization'] = true;
324  } elseif ($this->modTSconfig['properties']['enableLocalizationView'] === 'deactivated') {
325  $this->MOD_SETTINGS['localization'] = false;
326  }
327 
328  // Initialize the dblist object:
330  $dblist = GeneralUtility::makeInstance(RecordList\DatabaseRecordList::class);
331  $dblist->script = BackendUtility::getModuleUrl('web_list');
332  $dblist->calcPerms = $calcPerms;
333  $dblist->thumbs = $backendUser->uc['thumbnailsByDefault'];
334  $dblist->returnUrl = $this->returnUrl;
335  $dblist->allFields = $this->MOD_SETTINGS['bigControlPanel'] || $this->table ? 1 : 0;
336  $dblist->localizationView = $this->MOD_SETTINGS['localization'];
337  $dblist->showClipboard = 1;
338  $dblist->disableSingleTableView = $this->modTSconfig['properties']['disableSingleTableView'];
339  $dblist->listOnlyInSingleTableMode = $this->modTSconfig['properties']['listOnlyInSingleTableView'];
340  $dblist->hideTables = $this->modTSconfig['properties']['hideTables'];
341  $dblist->hideTranslations = $this->modTSconfig['properties']['hideTranslations'];
342  $dblist->tableTSconfigOverTCA = $this->modTSconfig['properties']['table.'];
343  $dblist->allowedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['allowedNewTables'], true);
344  $dblist->deniedNewTables = GeneralUtility::trimExplode(',', $this->modTSconfig['properties']['deniedNewTables'], true);
345  $dblist->newWizards = $this->modTSconfig['properties']['newWizards'] ? 1 : 0;
346  $dblist->pageRow = $this->pageinfo;
347  $dblist->counter++;
348  $dblist->MOD_MENU = array('bigControlPanel' => '', 'clipBoard' => '', 'localization' => '');
349  $dblist->modTSconfig = $this->modTSconfig;
350  $clickTitleMode = trim($this->modTSconfig['properties']['clickTitleMode']);
351  $dblist->clickTitleMode = $clickTitleMode === '' ? 'edit' : $clickTitleMode;
352  if (isset($this->modTSconfig['properties']['tableDisplayOrder.'])) {
353  $typoScriptService = GeneralUtility::makeInstance(TypoScriptService::class);
354  $dblist->setTableDisplayOrder($typoScriptService->convertTypoScriptArrayToPlainArray($this->modTSconfig['properties']['tableDisplayOrder.']));
355  }
356  // Clipboard is initialized:
357  // Start clipboard
358  $dblist->clipObj = GeneralUtility::makeInstance(Clipboard::class);
359  // Initialize - reads the clipboard content from the user session
360  $dblist->clipObj->initializeClipboard();
361  // Clipboard actions are handled:
362  // CB is the clipboard command array
363  $CB = GeneralUtility::_GET('CB');
364  if ($this->cmd == 'setCB') {
365  // CBH is all the fields selected for the clipboard, CBC is the checkbox fields which were checked.
366  // By merging we get a full array of checked/unchecked elements
367  // This is set to the 'el' array of the CB after being parsed so only the table in question is registered.
368  $CB['el'] = $dblist->clipObj->cleanUpCBC(array_merge(GeneralUtility::_POST('CBH'), (array)GeneralUtility::_POST('CBC')), $this->cmd_table);
369  }
370  if (!$this->MOD_SETTINGS['clipBoard']) {
371  // If the clipboard is NOT shown, set the pad to 'normal'.
372  $CB['setP'] = 'normal';
373  }
374  // Execute commands.
375  $dblist->clipObj->setCmd($CB);
376  // Clean up pad
377  $dblist->clipObj->cleanCurrent();
378  // Save the clipboard content
379  $dblist->clipObj->endClipboard();
380  // This flag will prevent the clipboard panel in being shown.
381  // It is set, if the clickmenu-layer is active AND the extended view is not enabled.
382  $dblist->dontShowClipControlPanels = ($dblist->clipObj->current == 'normal' && !$this->modTSconfig['properties']['showClipControlPanelsDespiteOfCMlayers']);
383  // 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:
384  if ($access || ($this->id === 0 && $this->search_levels > 0 && $this->search_field !== '')) {
385  // Deleting records...:
386  // 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.
387  if ($this->cmd == 'delete') {
388  $items = $dblist->clipObj->cleanUpCBC(GeneralUtility::_POST('CBC'), $this->cmd_table, 1);
389  if (!empty($items)) {
390  $cmd = array();
391  foreach ($items as $iK => $value) {
392  $iKParts = explode('|', $iK);
393  $cmd[$iKParts[0]][$iKParts[1]]['delete'] = 1;
394  }
395  $tce = GeneralUtility::makeInstance(DataHandler::class);
396  $tce->stripslashes_values = 0;
397  $tce->start(array(), $cmd);
398  $tce->process_cmdmap();
399  if (isset($cmd['pages'])) {
400  BackendUtility::setUpdateSignal('updatePageTree');
401  }
402  $tce->printLogErrorMessages(GeneralUtility::getIndpEnv('REQUEST_URI'));
403  }
404  }
405  // Initialize the listing object, dblist, for rendering the list:
406  $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
407  $dblist->start($this->id, $this->table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
408  $dblist->setDispFields();
409  // Render versioning selector:
410  if (ExtensionManagementUtility::isLoaded('version')) {
411  $dblist->HTMLcode .= $this->moduleTemplate->getVersionSelector($this->id);
412  }
413  // Render the list of tables:
414  $dblist->generateList();
415  $listUrl = $dblist->listURL();
416  // Add JavaScript functions to the page:
417 
418  $this->moduleTemplate->addJavaScriptCode(
419  'RecordListInlineJS',
420  '
421  function jumpExt(URL,anchor) { //
422  var anc = anchor?anchor:"";
423  window.location.href = URL+(T3_THIS_LOCATION?"&returnUrl="+T3_THIS_LOCATION:"")+anc;
424  return false;
425  }
426  function jumpSelf(URL) { //
427  window.location.href = URL+(T3_RETURN_URL?"&returnUrl="+T3_RETURN_URL:"");
428  return false;
429  }
430  function jumpToUrl(URL) {
431  window.location.href = URL;
432  return false;
433  }
434 
435  function setHighlight(id) { //
436  top.fsMod.recentIds["web"]=id;
437  top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_"+top.fsMod.currentBank; // For highlighting
438 
439  if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
440  top.content.nav_frame.refresh_nav();
441  }
442  }
443  ' . $this->moduleTemplate->redirectUrls($listUrl) . '
444  ' . $dblist->CBfunctions() . '
445  function editRecords(table,idList,addParams,CBflag) { //
446  window.location.href="' . BackendUtility::getModuleUrl('record_edit', array('returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'))) . '&edit["+table+"]["+idList+"]=edit"+addParams;
447  }
448  function editList(table,idList) { //
449  var list="";
450 
451  // Checking how many is checked, how many is not
452  var pointer=0;
453  var pos = idList.indexOf(",");
454  while (pos!=-1) {
455  if (cbValue(table+"|"+idList.substr(pointer,pos-pointer))) {
456  list+=idList.substr(pointer,pos-pointer)+",";
457  }
458  pointer=pos+1;
459  pos = idList.indexOf(",",pointer);
460  }
461  if (cbValue(table+"|"+idList.substr(pointer))) {
462  list+=idList.substr(pointer)+",";
463  }
464 
465  return list ? list : idList;
466  }
467 
468  if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
469  '
470  );
471 
472  // Setting up the context sensitive menu:
473  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
474  }
475  // access
476  // Begin to compile the whole page, starting out with page header:
477  if (!$this->id) {
478  $this->body = $this->moduleTemplate->header($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
479  } else {
480  $this->body = $this->moduleTemplate->header($this->pageinfo['title']);
481  }
482 
483  if (!empty($dblist->HTMLcode)) {
484  $output = $dblist->HTMLcode;
485  } else {
486  $output = $flashMessage = GeneralUtility::makeInstance(
487  FlashMessage::class,
488  $lang->getLL('noRecordsOnThisPage'),
489  '',
491  )->render();
492  }
493 
494  $this->body .= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
495  $this->body .= $output;
496  $this->body .= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
497  // If a listing was produced, create the page footer with search form etc:
498  if ($dblist->HTMLcode) {
499  // Making field select box (when extended view for a single table is enabled):
500  if ($dblist->table) {
501  $this->body .= $dblist->fieldSelectBox($dblist->table);
502  }
503  // Adding checkbox options for extended listing and clipboard display:
504  $this->body .= '
505 
506  <!--
507  Listing options for extended view, clipboard and localization view
508  -->
509  <div class="typo3-listOptions">
510  <form action="" method="post">';
511 
512  // Add "display bigControlPanel" checkbox:
513  if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
514  $this->body .= '<div class="checkbox">' .
515  '<label for="checkLargeControl">' .
516  BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLargeControl"') .
517  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('largeControl', true)) .
518  '</label>' .
519  '</div>';
520  }
521 
522  // Add "clipboard" checkbox:
523  if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
524  if ($dblist->showClipboard) {
525  $this->body .= '<div class="checkbox">' .
526  '<label for="checkShowClipBoard">' .
527  BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', $this->table ? '&table=' . $this->table : '', 'id="checkShowClipBoard"') .
528  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('showClipBoard', true)) .
529  '</label>' .
530  '</div>';
531  }
532  }
533 
534  // Add "localization view" checkbox:
535  if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
536  $this->body .= '<div class="checkbox">' .
537  '<label for="checkLocalization">' .
538  BackendUtility::getFuncCheck($this->id, 'SET[localization]', $this->MOD_SETTINGS['localization'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLocalization"') .
539  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('localization', true)) .
540  '</label>' .
541  '</div>';
542  }
543 
544  $this->body .= '
545  </form>
546  </div>';
547  }
548  // Printing clipboard if enabled
549  if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard && ($dblist->HTMLcode || $dblist->clipObj->hasElements())) {
550  $this->body .= '<div class="db_list-dashboard">' . $dblist->clipObj->printClipboard() . '</div>';
551  }
552  // Additional footer content
553  $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook'];
554  if (is_array($footerContentHook)) {
555  foreach ($footerContentHook as $hook) {
556  $params = array();
557  $this->body .= GeneralUtility::callUserFunction($hook, $params, $this);
558  }
559  }
560  // Setting up the buttons for docheader
561  $dblist->getDocHeaderButtons($this->moduleTemplate);
562  // searchbox toolbar
563  if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dblist->HTMLcode || !empty($dblist->searchString))) {
564  $this->content = $dblist->getSearchBox();
565  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
566  }
567  $searchButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeLinkButton();
568  $searchButton
569  ->setHref('#')
570  ->setClasses('t3js-toggle-search-toolbox')
571  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon', true))
572  ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL));
573  $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($searchButton, ButtonBar::BUTTON_POSITION_LEFT, 90);
574 
575  if ($this->pageinfo) {
576  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
577  }
578 
579  // Build the <body> for the module
580  $this->content .= $this->body;
581  }
582 
592  {
594  $GLOBALS['SOBE'] = $this;
595  $this->init();
596  $this->clearCache();
597  $this->main();
598  $this->moduleTemplate->setContent($this->content);
599  $response->getBody()->write($this->moduleTemplate->renderContent());
600  return $response;
601  }
602 
609  public function printContent()
610  {
612  echo $this->content;
613  }
614 
618  public function getModuleTemplate()
619  {
620  return $this->moduleTemplate;
621  }
622 
626  protected function getBackendUserAuthentication()
627  {
628  return $GLOBALS['BE_USER'];
629  }
630 
634  protected function getLanguageService()
635  {
636  return $GLOBALS['LANG'];
637  }
638 
642  protected function getPageRenderer()
643  {
644  if ($this->pageRenderer === null) {
645  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
646  }
647 
648  return $this->pageRenderer;
649  }
650 }