TYPO3 CMS  TYPO3_8-7
ImportExportTask.php
Go to the documentation of this file.
1 <?php
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 
25 
30 {
36  protected $taskObject;
37 
43  protected $moduleUrl;
44 
51  {
52  $this->moduleUrl = BackendUtility::getModuleUrl('user_task');
53  $this->taskObject = $taskObject;
54  $this->getLanguageService()->includeLLFile('EXT:impexp/Resources/Private/Language/locallang_csh.xlf');
55  }
56 
62  public function getTask()
63  {
64  return $this->main();
65  }
66 
73  public function getOverview()
74  {
75  return '';
76  }
77 
83  public function main()
84  {
85  $content = '';
86  $id = (int)GeneralUtility::_GP('display');
87  // If a preset is found, it is rendered using an iframe
88  if ($id > 0) {
89  $url = BackendUtility::getModuleUrl(
90  'xMOD_tximpexp',
91  [
92  'tx_impexp[action]' => 'export',
93  'preset[load]' => 1,
94  'preset[select]' => $id,
95  'returnUrl' => $this->moduleUrl
96  ]
97  );
99  } else {
100  // Header
101  $lang = $this->getLanguageService();
102  $content .= $this->taskObject->description($lang->getLL('.alttitle'), $lang->getLL('.description'));
103  $clause = $this->getBackendUser()->getPagePermsClause(1);
104  $usernames = BackendUtility::getUserNames();
105  // Create preset links:
106  $presets = $this->getPresets();
107  // If any presets found
108  if (is_array($presets) && !empty($presets)) {
109  $lines = [];
110  foreach ($presets as $key => $presetCfg) {
111  $configuration = unserialize($presetCfg['preset_data'], ['allowed_classes' => false]);
112  $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
113  $icon = 'EXT:impexp/Resources/Public/Images/export.gif';
114  $description = [];
115  // Is public?
116  if ($presetCfg['public']) {
117  $description[] = $lang->getLL('task.public') . ': ' . $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:yes');
118  }
119  // Owner
120  $description[] = $lang->getLL('task.owner') . ': '
121  . (
122  $presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid']
123  ? $lang->getLL('task.own')
124  : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']'
125  );
126  // Page & path
127  if ($configuration['pagetree']['id']) {
128  $description[] = $lang->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
129  $description[] = $lang->getLL('task.path') . ': ' . htmlspecialchars(
130  BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20)
131  );
132  } else {
133  $description[] = $lang->getLL('single-record');
134  }
135  // Meta information
136  if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
137  $metaInformation = '';
138  if ($configuration['meta']['title']) {
139  $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
140  }
141  if ($configuration['meta']['description']) {
142  $metaInformation .= htmlspecialchars($configuration['meta']['description']);
143  }
144  if ($configuration['meta']['notes']) {
145  $metaInformation .= '<br /><br />
146  <strong>' . $lang->getLL('notes') . ': </strong>
147  <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
148  }
149  $description[] = '<br />' . $metaInformation;
150  }
151  // Collect all preset information
152  $lines[$key] = [
153  'uid' => 'impexp' . $key,
154  'icon' => $icon,
155  'title' => $title,
156  'descriptionHtml' => implode('<br />', $description),
157  'link' => BackendUtility::getModuleUrl('user_task') . '&SET[function]=impexp.TYPO3\\CMS\\Impexp\\Task\\ImportExportTask&display=' . $presetCfg['uid']
158  ];
159  }
160  // Render preset list
161  $content .= $this->taskObject->renderListMenu($lines);
162  } else {
163  // No presets found
164  $flashMessage = GeneralUtility::makeInstance(
165  FlashMessage::class,
166  $lang->getLL('no-presets'),
167  $lang->getLL('.alttitle'),
169  );
171  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
173  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
174  $defaultFlashMessageQueue->enqueue($flashMessage);
175  }
176  }
177  return $content;
178  }
179 
185  protected function getPresets()
186  {
187  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
188  ->getQueryBuilderForTable('tx_impexp_presets');
189 
190  return $queryBuilder->select('*')
191  ->from('tx_impexp_presets')
192  ->where(
193  $queryBuilder->expr()->orX(
194  $queryBuilder->expr()->gt(
195  'public',
196  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
197  ),
198  $queryBuilder->expr()->eq(
199  'user_uid',
200  $queryBuilder->createNamedParameter($this->getBackendUser()->user['uid'], \PDO::PARAM_INT)
201  )
202  )
203  )
204  ->orderBy('item_uid', 'DESC')
205  ->addOrderBy('title')
206  ->execute()
207  ->fetchAll();
208  }
209 
217  protected function getDefaultImportExportFolder()
218  {
219  $defaultImportExportFolder = null;
220 
221  $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
222  if ($defaultTemporaryFolder !== null) {
223  $importExportFolderName = 'importexport';
224  $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
225  if ($createFolder === true) {
226  try {
227  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
228  } catch (Exception $folderAccessException) {
229  }
230  } else {
231  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
232  }
233  }
234 
235  return $defaultImportExportFolder;
236  }
237 
241  protected function getBackendUser()
242  {
243  return $GLOBALS['BE_USER'];
244  }
245 
249  protected function getLanguageService()
250  {
251  return $GLOBALS['LANG'];
252  }
253 }
__construct(TaskModuleController $taskObject)
static makeInstance($className,... $constructorArguments)
static getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
static redirect($url, $httpStatus=self::HTTP_STATUS_303)
static getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']