TYPO3  7.6
ImportExportTask.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Impexp\Task;
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 
18 
23 {
29  protected $taskObject;
30 
34  public function __construct(\TYPO3\CMS\Taskcenter\Controller\TaskModuleController $taskObject)
35  {
36  $this->taskObject = $taskObject;
37  $GLOBALS['LANG']->includeLLFile('EXT:impexp/Resources/Private/Language/locallang_csh.xlf');
38  }
39 
45  public function getTask()
46  {
47  return $this->main();
48  }
49 
56  public function getOverview()
57  {
58  return '';
59  }
60 
66  public function main()
67  {
68  $content = '';
69  $id = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display');
70  // If a preset is found, it is rendered using an iframe
71  if ($id > 0) {
72  $url = BackendUtility::getModuleUrl(
73  'xMOD_tximpexp',
74  array(
75  'tx_impexp[action]' => 'export',
76  'preset[load]' => 1,
77  'preset[select]' => $id)
78  );
79  return $this->taskObject->urlInIframe($url, 1);
80  } else {
81  // Header
82  $content .= $this->taskObject->description($GLOBALS['LANG']->getLL('.alttitle'), $GLOBALS['LANG']->getLL('.description'));
83  $thumbnails = ($lines = array());
84  // Thumbnail folder and files:
85  $tempDir = $this->getDefaultImportExportFolder()->getPublicUrl();
86  if ($tempDir) {
87  $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
88  }
89  $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
90  $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
91  // Create preset links:
92  $presets = $this->getPresets();
93  // If any presets found
94  if (is_array($presets)) {
95  foreach ($presets as $key => $presetCfg) {
96  $configuration = unserialize($presetCfg['preset_data']);
97  $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
98  $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
99  $icon = 'EXT:impexp/Resources/Public/Images/export.gif';
100  $description = array();
101  // Is public?
102  if ($presetCfg['public']) {
103  $description[] = $GLOBALS['LANG']->getLL('task.public') . ': ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xlf:yes');
104  }
105  // Owner
106  $description[] = $GLOBALS['LANG']->getLL('task.owner') . ': ' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? $GLOBALS['LANG']->getLL('task.own') : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']');
107  // Page & path
108  if ($configuration['pagetree']['id']) {
109  $description[] = $GLOBALS['LANG']->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
110  $description[] = $GLOBALS['LANG']->getLL('task.path') . ': ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
111  } else {
112  $description[] = $GLOBALS['LANG']->getLL('single-record');
113  }
114  // Meta information
115  if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
116  $metaInformation = '';
117  if ($configuration['meta']['title']) {
118  $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
119  }
120  if ($configuration['meta']['description']) {
121  $metaInformation .= htmlspecialchars($configuration['meta']['description']);
122  }
123  if ($configuration['meta']['notes']) {
124  $metaInformation .= '<br /><br />
125  <strong>' . $GLOBALS['LANG']->getLL('notes') . ': </strong>
126  <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
127  }
128  $description[] = '<br />' . $metaInformation;
129  }
130  // Collect all preset information
131  $lines[$key] = array(
132  'icon' => $icon,
133  'title' => $title,
134  'descriptionHtml' => implode('<br />', $description),
135  'link' => BackendUtility::getModuleUrl('user_task') . '&SET[function]=impexp.TYPO3\\CMS\\Impexp\\Task\\ImportExportTask&display=' . $presetCfg['uid']
136  );
137  }
138  // Render preset list
139  $content .= $this->taskObject->renderListMenu($lines);
140  } else {
141  // No presets found
142  $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
143  \TYPO3\CMS\Core\Messaging\FlashMessage::class,
144  $GLOBALS['LANG']->getLL('no-presets'),
145  '',
146  \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
147  );
148  $content .= $flashMessage->render();
149  }
150  }
151  return $content;
152  }
153 
159  protected function getPresets()
160  {
161  $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
162  '*',
163  'tx_impexp_presets',
164  '(public > 0 OR user_uid=' . $GLOBALS['BE_USER']->user['uid'] . ')',
165  '',
166  'item_uid DESC, title'
167  );
168  return $presets;
169  }
170 
178  protected function getDefaultImportExportFolder()
179  {
180  $defaultImportExportFolder = null;
181 
182  $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
183  if ($defaultTemporaryFolder !== null) {
184  $importExportFolderName = 'importexport';
185  $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
186  if ($createFolder === true) {
187  try {
188  $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
189  } catch (\TYPO3\CMS\Core\Resource\Exception $folderAccessException) {
190  }
191  } else {
192  $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
193  }
194  }
195 
196  return $defaultImportExportFolder;
197  }
198 
202  protected function getBackendUser()
203  {
204  return $GLOBALS['BE_USER'];
205  }
206 }