TYPO3 CMS  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 = [];
155 
161  public $MOD_MENU = [];
162 
168  public $MOD_SETTINGS = [];
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(self::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 = [
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([], []);
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 = ['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 = [];
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([], $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 = max(0, (int)$this->pointer);
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', ['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  $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
479  } else {
480  $title = $this->pageinfo['title'];
481  }
482  $this->body = $this->moduleTemplate->header($title);
483  $this->moduleTemplate->setTitle($title);
484 
485  if (!empty($dblist->HTMLcode)) {
486  $output = $dblist->HTMLcode;
487  } else {
488  $output = '';
489  $flashMessage = GeneralUtility::makeInstance(
490  FlashMessage::class,
491  $lang->getLL('noRecordsOnThisPage'),
492  '',
494  );
496  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
498  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
499  $defaultFlashMessageQueue->enqueue($flashMessage);
500  }
501 
502  $this->body .= '<form action="' . htmlspecialchars($dblist->listURL()) . '" method="post" name="dblistForm">';
503  $this->body .= $output;
504  $this->body .= '<input type="hidden" name="cmd_table" /><input type="hidden" name="cmd" /></form>';
505  // If a listing was produced, create the page footer with search form etc:
506  if ($dblist->HTMLcode) {
507  // Making field select box (when extended view for a single table is enabled):
508  if ($dblist->table) {
509  $this->body .= $dblist->fieldSelectBox($dblist->table);
510  }
511  // Adding checkbox options for extended listing and clipboard display:
512  $this->body .= '
513 
514  <!--
515  Listing options for extended view, clipboard and localization view
516  -->
517  <div class="typo3-listOptions">
518  <form action="" method="post">';
519 
520  // Add "display bigControlPanel" checkbox:
521  if ($this->modTSconfig['properties']['enableDisplayBigControlPanel'] === 'selectable') {
522  $this->body .= '<div class="checkbox">' .
523  '<label for="checkLargeControl">' .
524  BackendUtility::getFuncCheck($this->id, 'SET[bigControlPanel]', $this->MOD_SETTINGS['bigControlPanel'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLargeControl"') .
525  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('largeControl', true)) .
526  '</label>' .
527  '</div>';
528  }
529 
530  // Add "clipboard" checkbox:
531  if ($this->modTSconfig['properties']['enableClipBoard'] === 'selectable') {
532  if ($dblist->showClipboard) {
533  $this->body .= '<div class="checkbox">' .
534  '<label for="checkShowClipBoard">' .
535  BackendUtility::getFuncCheck($this->id, 'SET[clipBoard]', $this->MOD_SETTINGS['clipBoard'], '', $this->table ? '&table=' . $this->table : '', 'id="checkShowClipBoard"') .
536  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('showClipBoard', true)) .
537  '</label>' .
538  '</div>';
539  }
540  }
541 
542  // Add "localization view" checkbox:
543  if ($this->modTSconfig['properties']['enableLocalizationView'] === 'selectable') {
544  $this->body .= '<div class="checkbox">' .
545  '<label for="checkLocalization">' .
546  BackendUtility::getFuncCheck($this->id, 'SET[localization]', $this->MOD_SETTINGS['localization'], '', $this->table ? '&table=' . $this->table : '', 'id="checkLocalization"') .
547  BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_options', $lang->getLL('localization', true)) .
548  '</label>' .
549  '</div>';
550  }
551 
552  $this->body .= '
553  </form>
554  </div>';
555  }
556  // Printing clipboard if enabled
557  if ($this->MOD_SETTINGS['clipBoard'] && $dblist->showClipboard && ($dblist->HTMLcode || $dblist->clipObj->hasElements())) {
558  $this->body .= '<div class="db_list-dashboard">' . $dblist->clipObj->printClipboard() . '</div>';
559  }
560  // Additional footer content
561  $footerContentHook = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['recordlist/Modules/Recordlist/index.php']['drawFooterHook'];
562  if (is_array($footerContentHook)) {
563  foreach ($footerContentHook as $hook) {
564  $params = [];
565  $this->body .= GeneralUtility::callUserFunction($hook, $params, $this);
566  }
567  }
568  // Setting up the buttons for docheader
569  $dblist->getDocHeaderButtons($this->moduleTemplate);
570  // searchbox toolbar
571  if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dblist->HTMLcode || !empty($dblist->searchString))) {
572  $this->content = $dblist->getSearchBox();
573  $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
574 
575  $searchButton = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->makeLinkButton();
576  $searchButton
577  ->setHref('#')
578  ->setClasses('t3js-toggle-search-toolbox')
579  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.title.searchIcon'))
580  ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL));
581  $this->moduleTemplate->getDocHeaderComponent()->getButtonBar()->addButton($searchButton,
583  }
584 
585  if ($this->pageinfo) {
586  $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
587  }
588 
589  // Build the <body> for the module
590  $this->content .= $this->body;
591  }
592 
601  public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
602  {
604  $GLOBALS['SOBE'] = $this;
605  $this->init();
606  $this->clearCache();
607  $this->main();
608  $this->moduleTemplate->setContent($this->content);
609  $response->getBody()->write($this->moduleTemplate->renderContent());
610  return $response;
611  }
612 
619  public function printContent()
620  {
622  echo $this->content;
623  }
624 
628  public function getModuleTemplate()
629  {
630  return $this->moduleTemplate;
631  }
632 
636  protected function getBackendUserAuthentication()
637  {
638  return $GLOBALS['BE_USER'];
639  }
640 
644  protected function getLanguageService()
645  {
646  return $GLOBALS['LANG'];
647  }
648 
652  protected function getPageRenderer()
653  {
654  if ($this->pageRenderer === null) {
655  $this->pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
656  }
657 
658  return $this->pageRenderer;
659  }
660 }
static getFuncCheck($mainParams, $elementName, $currentValue, $script='', $addParams='', $tagParams='')
static readPageAccess($id, $perms_clause)
static lockRecords($table='', $uid=0, $pid=0)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static callUserFunction($funcName, &$params, &$ref, $checkPrefix='', $errorMode=0)
static getModuleData($MOD_MENU, $CHANGED_SETTINGS, $modName, $type='', $dontValidateList='', $setDefaultList='')
static setUpdateSignal($set='', $params='')
mainAction(ServerRequestInterface $request, ResponseInterface $response)
Definition: RecordList.php:601
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']