‪TYPO3CMS  9.5
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 
26 
32 {
38  protected ‪$taskObject;
39 
45  protected ‪$moduleUrl;
46 
53  {
55  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
56  $this->moduleUrl = (string)$uriBuilder->buildUriFromRoute('user_task');
57  $this->taskObject = ‪$taskObject;
58  $this->‪getLanguageService()->includeLLFile('EXT:impexp/Resources/Private/Language/locallang_csh.xlf');
59  }
60 
66  public function ‪getTask()
67  {
68  return $this->‪main();
69  }
70 
77  public function ‪getOverview()
78  {
79  return '';
80  }
81 
87  public function ‪main()
88  {
89  $content = '';
90  $id = (int)GeneralUtility::_GP('display');
92  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
93  // If a preset is found, it is rendered using an iframe
94  if ($id > 0) {
95  $url = (string)$uriBuilder->buildUriFromRoute(
96  'xMOD_tximpexp',
97  [
98  'tx_impexp[action]' => 'export',
99  'preset[load]' => 1,
100  'preset[select]' => $id,
101  'returnUrl' => $this->moduleUrl
102  ]
103  );
105  } else {
106  // Header
107  $lang = $this->‪getLanguageService();
108  $content .= $this->taskObject->description($lang->getLL('.alttitle'), $lang->getLL('.description'));
110  $usernames = ‪BackendUtility::getUserNames();
111  // Create preset links:
112  $presets = $this->‪getPresets();
113  // If any presets found
114  if (is_array($presets) && !empty($presets)) {
115  $lines = [];
116  foreach ($presets as $key => $presetCfg) {
117  $configuration = unserialize($presetCfg['preset_data'], ['allowed_classes' => false]);
118  $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
119  $icon = 'EXT:impexp/Resources/Public/Images/export.gif';
120  $description = [];
121  // Is public?
122  if ($presetCfg['public']) {
123  $description[] = $lang->getLL('task.public') . ': ' . $lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_common.xlf:yes');
124  }
125  // Owner
126  $description[] = $lang->getLL('task.owner') . ': '
127  . (
128  $presetCfg['user_uid'] === ‪$GLOBALS['BE_USER']->user['uid']
129  ? $lang->getLL('task.own')
130  : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']'
131  );
132  // Page & path
133  if ($configuration['pagetree']['id']) {
134  $description[] = $lang->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
135  $description[] = $lang->getLL('task.path') . ': ' . htmlspecialchars(
136  ‪BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20)
137  );
138  } else {
139  $description[] = $lang->getLL('single-record');
140  }
141  // Meta information
142  if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
143  $metaInformation = '';
144  if ($configuration['meta']['title']) {
145  $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
146  }
147  if ($configuration['meta']['description']) {
148  $metaInformation .= htmlspecialchars($configuration['meta']['description']);
149  }
150  if ($configuration['meta']['notes']) {
151  $metaInformation .= '<br /><br />
152  <strong>' . $lang->getLL('notes') . ': </strong>
153  <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
154  }
155  $description[] = '<br />' . $metaInformation;
156  }
157  // Collect all preset information
158  $lines[$key] = [
159  'uid' => 'impexp' . $key,
160  'icon' => $icon,
161  'title' => $title,
162  'descriptionHtml' => implode('<br />', $description),
163  'link' => (string)$uriBuilder->buildUriFromRoute('user_task') . '&SET[function]=impexp.TYPO3\\CMS\\Impexp\\Task\\ImportExportTask&display=' . $presetCfg['uid']
164  ];
165  }
166  // Render preset list
167  $content .= $this->taskObject->renderListMenu($lines);
168  } else {
169  // No presets found
170  $flashMessage = GeneralUtility::makeInstance(
171  FlashMessage::class,
172  $lang->getLL('no-presets'),
173  $lang->getLL('.alttitle'),
175  );
177  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
179  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
180  $defaultFlashMessageQueue->enqueue($flashMessage);
181  }
182  }
183  return $content;
184  }
185 
191  protected function ‪getPresets()
192  {
193  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
194  ->getQueryBuilderForTable('tx_impexp_presets');
195 
196  return $queryBuilder->select('*')
197  ->from('tx_impexp_presets')
198  ->where(
199  $queryBuilder->expr()->orX(
200  $queryBuilder->expr()->gt(
201  'public',
202  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
203  ),
204  $queryBuilder->expr()->eq(
205  'user_uid',
206  $queryBuilder->createNamedParameter($this->getBackendUser()->user['uid'], \PDO::PARAM_INT)
207  )
208  )
209  )
210  ->orderBy('item_uid', 'DESC')
211  ->addOrderBy('title')
212  ->execute()
213  ->fetchAll();
214  }
215 
223  protected function ‪getDefaultImportExportFolder()
224  {
225  $defaultImportExportFolder = null;
226 
227  $defaultTemporaryFolder = $this->‪getBackendUser()->‪getDefaultUploadTemporaryFolder();
228  if ($defaultTemporaryFolder !== null) {
229  $importExportFolderName = 'importexport';
230  $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
231  if ($createFolder === true) {
232  try {
233  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
234  } catch (‪Exception $folderAccessException) {
235  }
236  } else {
237  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
238  }
239  }
240 
241  return $defaultImportExportFolder;
242  }
243 
247  protected function ‪getBackendUser()
248  {
249  return ‪$GLOBALS['BE_USER'];
250  }
251 
255  protected function ‪getLanguageService()
256  {
257  return ‪$GLOBALS['LANG'];
258  }
259 }
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getDefaultImportExportFolder
‪TYPO3 CMS Core Resource Folder null getDefaultImportExportFolder()
Definition: ImportExportTask.php:221
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getPresets
‪array bool getPresets()
Definition: ImportExportTask.php:189
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getPagePermsClause
‪string getPagePermsClause($perms)
Definition: BackendUserAuthentication.php:523
‪TYPO3\CMS\Taskcenter\Controller\TaskModuleController
Definition: TaskModuleController.php:40
‪TYPO3
‪TYPO3\CMS\Impexp\Task\ImportExportTask\$taskObject
‪TaskModuleController $taskObject
Definition: ImportExportTask.php:37
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getLanguageService
‪mixed getLanguageService()
Definition: ImportExportTask.php:253
‪TYPO3\CMS\Impexp\Task\ImportExportTask\main
‪string main()
Definition: ImportExportTask.php:85
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getOverview
‪string getOverview()
Definition: ImportExportTask.php:75
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getDefaultUploadTemporaryFolder
‪TYPO3 CMS Core Resource Folder null getDefaultUploadTemporaryFolder()
Definition: BackendUserAuthentication.php:2063
‪TYPO3\CMS\Backend\Utility\BackendUtility\getUserNames
‪static array getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
Definition: BackendUtility.php:1003
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Impexp\Task\ImportExportTask\$moduleUrl
‪string $moduleUrl
Definition: ImportExportTask.php:43
‪TYPO3\CMS\Impexp\Task\ImportExportTask\__construct
‪__construct(TaskModuleController $taskObject)
Definition: ImportExportTask.php:50
‪TYPO3\CMS\Taskcenter\TaskInterface
Definition: TaskInterface.php:21
‪TYPO3\CMS\Impexp\Task\ImportExportTask
Definition: ImportExportTask.php:32
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Core\Resource\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getTask
‪string getTask()
Definition: ImportExportTask.php:64
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordPath
‪static mixed getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
Definition: BackendUtility.php:572
‪TYPO3\CMS\Impexp\Task\ImportExportTask\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: ImportExportTask.php:245
‪TYPO3\CMS\Core\Utility\HttpUtility\redirect
‪static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:103
‪TYPO3\CMS\Core\Resource\Exception
Definition: AbstractFileOperationException.php:2
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:25
‪TYPO3\CMS\Impexp\Task
Definition: ImportExportTask.php:2