[TASK] Cleanup impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Task / ImportExportTask.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Task;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2011 Kasper Skårhøj (kasper@typo3.com)
8 * (c) 2010-2011 Georg Ringer (typo3@ringerge.org)
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * This class provides a textarea to save personal notes
30 *
31 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @author Georg Ringer <typo3@ringerge.org>
33 */
34 class ImportExportTask implements \TYPO3\CMS\Taskcenter\TaskInterface {
35
36 /**
37 * Back-reference to the calling reports module
38 *
39 * @var \TYPO3\CMS\Taskcenter\Controller\TaskModuleController $taskObject
40 */
41 protected $taskObject;
42
43 /**
44 * Constructor
45 */
46 public function __construct(\TYPO3\CMS\Taskcenter\Controller\TaskModuleController $taskObject) {
47 $this->taskObject = $taskObject;
48 $GLOBALS['LANG']->includeLLFile('EXT:impexp/locallang_csh.xml');
49 }
50
51 /**
52 * This method renders the report
53 *
54 * @return string The status report as HTML
55 */
56 public function getTask() {
57 return $this->main();
58 }
59
60 /**
61 * Render an optional additional information for the 1st view in taskcenter.
62 * Empty for this task
63 *
64 * @return string Overview as HTML
65 */
66 public function getOverview() {
67 return '';
68 }
69
70 /**
71 * Main Task center module
72 *
73 * @return string HTML content.
74 */
75 public function main() {
76 $content = '';
77 $id = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display'));
78 // If a preset is found, it is rendered using an iframe
79 if ($id > 0) {
80 $url = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id;
81 return $this->taskObject->urlInIframe($url, 1);
82 } else {
83 // Header
84 $content .= $this->taskObject->description($GLOBALS['LANG']->getLL('.alttitle'), $GLOBALS['LANG']->getLL('.description'));
85 $thumbnails = ($lines = array());
86 // Thumbnail folder and files:
87 $tempDir = $this->userTempFolder();
88 if ($tempDir) {
89 $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
90 }
91 $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
92 $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
93 // Create preset links:
94 $presets = $this->getPresets();
95 // If any presets found
96 if (is_array($presets)) {
97 foreach ($presets as $key => $presetCfg) {
98 $configuration = unserialize($presetCfg['preset_data']);
99 $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
100 $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
101 $icon = 'EXT:impexp/export.gif';
102 $description = array();
103 // Is public?
104 if ($presetCfg['public']) {
105 $description[] = $GLOBALS['LANG']->getLL('task.public') . ': ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
106 }
107 // Owner
108 $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']) . ']');
109 // Page & path
110 if ($configuration['pagetree']['id']) {
111 $description[] = $GLOBALS['LANG']->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
112 $description[] = $GLOBALS['LANG']->getLL('task.path') . ': ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
113 } else {
114 $description[] = $GLOBALS['LANG']->getLL('single-record');
115 }
116 // Meta information
117 if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
118 $metaInformation = '';
119 if ($configuration['meta']['title']) {
120 $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
121 }
122 if ($configuration['meta']['description']) {
123 $metaInformation .= htmlspecialchars($configuration['meta']['description']);
124 }
125 if ($configuration['meta']['notes']) {
126 $metaInformation .= '<br /><br />
127 <strong>' . $GLOBALS['LANG']->getLL('notes') . ': </strong>
128 <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
129 }
130 $description[] = '<br />' . $metaInformation;
131 }
132 // Collect all preset information
133 $lines[$key] = array(
134 'icon' => $icon,
135 'title' => $title,
136 'descriptionHtml' => implode('<br />', $description),
137 'link' => 'mod.php?M=user_task&SET[function]=impexp.tx_impexp_task&display=' . $presetCfg['uid']
138 );
139 }
140 // Render preset list
141 $content .= $this->taskObject->renderListMenu($lines);
142 } else {
143 // No presets found
144 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
145 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
146 $GLOBALS['LANG']->getLL('no-presets'),
147 '',
148 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
149 );
150 $content .= $flashMessage->render();
151 }
152 }
153 return $content;
154 }
155
156 /**
157 * Select presets for this user
158 *
159 * @return array Array of preset records
160 */
161 protected function getPresets() {
162 $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
163 '*',
164 'tx_impexp_presets',
165 '(public > 0 OR user_uid=' . $GLOBALS['BE_USER']->user['uid'] . ')',
166 '',
167 'item_uid DESC, title'
168 );
169 return $presets;
170 }
171
172 /**
173 * Returns first temporary folder of the user account (from $FILEMOUNTS)
174 *
175 * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
176 */
177 protected function userTempFolder() {
178 foreach ($GLOBALS['FILEMOUNTS'] as $filePathInfo) {
179 $tempFolder = $filePathInfo['path'] . '_temp_/';
180 if (@is_dir($tempFolder)) {
181 return $tempFolder;
182 }
183 }
184 return '';
185 }
186
187 }
188
189 ?>