[CLEANUP] ImportExport classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Task / ImportExportTask.php
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
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Resource\Exception;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Taskcenter\Controller\TaskModuleController;
22 use TYPO3\CMS\Taskcenter\TaskInterface;
23
24 /**
25 * This class provides a textarea to save personal notes
26 */
27 class ImportExportTask implements TaskInterface
28 {
29 /**
30 * Back-reference to the calling reports module
31 *
32 * @var TaskModuleController $taskObject
33 */
34 protected $taskObject;
35
36 /**
37 * Constructor
38 *
39 * @param TaskModuleController $taskObject
40 */
41 public function __construct(TaskModuleController $taskObject)
42 {
43 $this->taskObject = $taskObject;
44 $this->getLanguageService()->includeLLFile('EXT:impexp/Resources/Private/Language/locallang_csh.xlf');
45 }
46
47 /**
48 * This method renders the report
49 *
50 * @return string The status report as HTML
51 */
52 public function getTask()
53 {
54 return $this->main();
55 }
56
57 /**
58 * Render an optional additional information for the 1st view in taskcenter.
59 * Empty for this task
60 *
61 * @return string Overview as HTML
62 */
63 public function getOverview()
64 {
65 return '';
66 }
67
68 /**
69 * Main Task center module
70 *
71 * @return string HTML content.
72 */
73 public function main()
74 {
75 $content = '';
76 $id = (int)GeneralUtility::_GP('display');
77 // If a preset is found, it is rendered using an iframe
78 if ($id > 0) {
79 $url = BackendUtility::getModuleUrl(
80 'xMOD_tximpexp',
81 array(
82 'tx_impexp[action]' => 'export',
83 'preset[load]' => 1,
84 'preset[select]' => $id)
85 );
86 return $this->taskObject->urlInIframe($url);
87 } else {
88 // Header
89 $lang = $this->getLanguageService();
90 $content .= $this->taskObject->description($lang->getLL('.alttitle'), $lang->getLL('.description'));
91 $clause = $this->getBackendUser()->getPagePermsClause(1);
92 $usernames = BackendUtility::getUserNames();
93 // Create preset links:
94 $presets = $this->getPresets();
95 // If any presets found
96 if (is_array($presets)) {
97 $lines = [];
98 foreach ($presets as $key => $presetCfg) {
99 $configuration = unserialize($presetCfg['preset_data']);
100 $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
101 $icon = 'EXT:impexp/Resources/Public/Images/export.gif';
102 $description = array();
103 // Is public?
104 if ($presetCfg['public']) {
105 $description[] = $lang->getLL('task.public') . ': ' . $lang->sL('LLL:EXT:lang/locallang_common.xlf:yes');
106 }
107 // Owner
108 $description[] = $lang->getLL('task.owner') . ': '
109 . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid']
110 ? $lang->getLL('task.own')
111 : '[' . htmlspecialchars($usernames[$presetCfg['user_uid']]['username']) . ']'
112 );
113 // Page & path
114 if ($configuration['pagetree']['id']) {
115 $description[] = $lang->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
116 $description[] = $lang->getLL('task.path') . ': ' . htmlspecialchars(
117 BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
118 } else {
119 $description[] = $lang->getLL('single-record');
120 }
121 // Meta information
122 if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
123 $metaInformation = '';
124 if ($configuration['meta']['title']) {
125 $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
126 }
127 if ($configuration['meta']['description']) {
128 $metaInformation .= htmlspecialchars($configuration['meta']['description']);
129 }
130 if ($configuration['meta']['notes']) {
131 $metaInformation .= '<br /><br />
132 <strong>' . $lang->getLL('notes') . ': </strong>
133 <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
134 }
135 $description[] = '<br />' . $metaInformation;
136 }
137 // Collect all preset information
138 $lines[$key] = array(
139 'icon' => $icon,
140 'title' => $title,
141 'descriptionHtml' => implode('<br />', $description),
142 'link' => BackendUtility::getModuleUrl('user_task') . '&SET[function]=impexp.TYPO3\\CMS\\Impexp\\Task\\ImportExportTask&display=' . $presetCfg['uid']
143 );
144 }
145 // Render preset list
146 $content .= $this->taskObject->renderListMenu($lines);
147 } else {
148 // No presets found
149 $flashMessage = GeneralUtility::makeInstance(
150 FlashMessage::class,
151 $lang->getLL('no-presets'),
152 '',
153 FlashMessage::NOTICE
154 );
155 $content .= $flashMessage->render();
156 }
157 }
158 return $content;
159 }
160
161 /**
162 * Select presets for this user
163 *
164 * @return array Array of preset records
165 */
166 protected function getPresets()
167 {
168 $db = $this->getDatabase();
169 $presets = $db->exec_SELECTgetRows(
170 '*',
171 'tx_impexp_presets',
172 '(public > 0 OR user_uid=' . $this->getBackendUser()->user['uid'] . ')',
173 '',
174 'item_uid DESC, title'
175 );
176 return $presets;
177 }
178
179 /**
180 * Returns a \TYPO3\CMS\Core\Resource\Folder object for saving export files
181 * to the server and is also used for uploading import files.
182 *
183 * @throws \InvalidArgumentException
184 * @return NULL|\TYPO3\CMS\Core\Resource\Folder
185 */
186 protected function getDefaultImportExportFolder()
187 {
188 $defaultImportExportFolder = null;
189
190 $defaultTemporaryFolder = $this->getBackendUser()->getDefaultUploadTemporaryFolder();
191 if ($defaultTemporaryFolder !== null) {
192 $importExportFolderName = 'importexport';
193 $createFolder = !$defaultTemporaryFolder->hasFolder($importExportFolderName);
194 if ($createFolder === true) {
195 try {
196 $defaultImportExportFolder = $defaultTemporaryFolder->createFolder($importExportFolderName);
197 } catch (Exception $folderAccessException) {
198 }
199 } else {
200 $defaultImportExportFolder = $defaultTemporaryFolder->getSubfolder($importExportFolderName);
201 }
202 }
203
204 return $defaultImportExportFolder;
205 }
206
207 /**
208 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
209 */
210 protected function getBackendUser()
211 {
212 return $GLOBALS['BE_USER'];
213 }
214
215 /**
216 * @return mixed
217 */
218 protected function getLanguageService()
219 {
220 return $GLOBALS['LANG'];
221 }
222
223 /**
224 * @return mixed
225 */
226 protected function getDatabase()
227 {
228 return $GLOBALS['TYPO3_DB'];
229 }
230 }