TYPO3 CMS  TYPO3_7-6
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 
24 
29 {
35  protected $taskObject;
36 
43  {
44  $this->taskObject = $taskObject;
45  $this->getLanguageService()->includeLLFile('EXT:impexp/Resources/Private/Language/locallang_csh.xlf');
46  }
47 
53  public function getTask()
54  {
55  return $this->main();
56  }
57 
64  public function getOverview()
65  {
66  return '';
67  }
68 
74  public function main()
75  {
76  $content = '';
77  $id = (int)GeneralUtility::_GP('display');
78  // If a preset is found, it is rendered using an iframe
79  if ($id > 0) {
80  $url = BackendUtility::getModuleUrl(
81  'xMOD_tximpexp',
82  [
83  'tx_impexp[action]' => 'export',
84  'preset[load]' => 1,
85  'preset[select]' => $id]
86  );
87  return $this->taskObject->urlInIframe($url);
88  } else {
89  // Header
90  $lang = $this->getLanguageService();
91  $content .= $this->taskObject->description($lang->getLL('.alttitle'), $lang->getLL('.description'));
92  $clause = $this->getBackendUser()->getPagePermsClause(1);
93  $usernames = BackendUtility::getUserNames();
94  // Create preset links:
95  $presets = $this->getPresets();
96  // If any presets found
97  if (is_array($presets) && !empty($presets)) {
98  $lines = [];
99  foreach ($presets as $key => $presetCfg) {
100  $configuration = unserialize($presetCfg['preset_data']);
101  $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
102  $icon = 'EXT:impexp/Resources/Public/Images/export.gif';
103  $description = [];
104  // Is public?
105  if ($presetCfg['public']) {
106  $description[] = $lang->getLL('task.public') . ': ' . $lang->sL('LLL:EXT:lang/locallang_common.xlf:yes');
107  }
108  // Owner
109  $description[] = $lang->getLL('task.owner') . ': '
110  . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid']
111  ? $lang->getLL('task.own')
112  : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']'
113  );
114  // Page & path
115  if ($configuration['pagetree']['id']) {
116  $description[] = $lang->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
117  $description[] = $lang->getLL('task.path') . ': ' . htmlspecialchars(
118  BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
119  } else {
120  $description[] = $lang->getLL('single-record');
121  }
122  // Meta information
123  if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
124  $metaInformation = '';
125  if ($configuration['meta']['title']) {
126  $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
127  }
128  if ($configuration['meta']['description']) {
129  $metaInformation .= htmlspecialchars($configuration['meta']['description']);
130  }
131  if ($configuration['meta']['notes']) {
132  $metaInformation .= '<br /><br />
133  <strong>' . $lang->getLL('notes') . ': </strong>
134  <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
135  }
136  $description[] = '<br />' . $metaInformation;
137  }
138  // Collect all preset information
139  $lines[$key] = [
140  'icon' => $icon,
141  'title' => $title,
142  'descriptionHtml' => implode('<br />', $description),
143  'link' => BackendUtility::getModuleUrl('user_task') . '&SET[function]=impexp.TYPO3\\CMS\\Impexp\\Task\\ImportExportTask&display=' . $presetCfg['uid']
144  ];
145  }
146  // Render preset list
147  $content .= $this->taskObject->renderListMenu($lines);
148  } else {
149  // No presets found
150  $flashMessage = GeneralUtility::makeInstance(
151  FlashMessage::class,
152  $lang->getLL('no-presets'),
153  $lang->getLL('.alttitle'),
155  );
157  $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
159  $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
160  $defaultFlashMessageQueue->enqueue($flashMessage);
161  }
162  }
163  return $content;
164  }
165 
171  protected function getPresets()
172  {
173  $db = $this->getDatabase();
174  $presets = $db->exec_SELECTgetRows(
175  '*',
176  'tx_impexp_presets',
177  '(public > 0 OR user_uid=' . $this->getBackendUser()->user['uid'] . ')',
178  '',
179  'item_uid DESC, title'
180  );
181  return $presets;
182  }
183 
191  protected function getDefaultImportExportFolder()
192  {
193  $defaultImportExportFolder = null;
194 
195  $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
196  if ($defaultTemporaryFolder !== null) {
197  $importExportFolderName = 'importexport';
198  $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
199  if ($createFolder === true) {
200  try {
201  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
202  } catch (Exception $folderAccessException) {
203  }
204  } else {
205  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
206  }
207  }
208 
209  return $defaultImportExportFolder;
210  }
211 
215  protected function getBackendUser()
216  {
217  return $GLOBALS['BE_USER'];
218  }
219 
223  protected function getLanguageService()
224  {
225  return $GLOBALS['LANG'];
226  }
227 
231  protected function getDatabase()
232  {
233  return $GLOBALS['TYPO3_DB'];
234  }
235 }
__construct(TaskModuleController $taskObject)
static getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
static getRecordPath($uid, $clause, $titleLimit, $fullTitleLimit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']