[TASK] Styling of Page module
[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 * This class provides a textarea to save personal notes
29 *
30 * @author Kasper Skårhøj <kasper@typo3.com>
31 * @author Georg Ringer <typo3@ringerge.org>
32 */
33 class ImportExportTask implements \TYPO3\CMS\Taskcenter\TaskInterface {
34
35 /**
36 * Back-reference to the calling reports module
37 *
38 * @var tx_reports_Module $taskObject
39 */
40 protected $taskObject;
41
42 /**
43 * Constructor
44 */
45 public function __construct(\TYPO3\CMS\Taskcenter\Controller\TaskModuleController $taskObject) {
46 $this->taskObject = $taskObject;
47 $GLOBALS['LANG']->includeLLFile('EXT:impexp/locallang_csh.xml');
48 }
49
50 /**
51 * This method renders the report
52 *
53 * @return string The status report as HTML
54 */
55 public function getTask() {
56 return $this->main();
57 }
58
59 /**
60 * Render an optional additional information for the 1st view in taskcenter.
61 * Empty for this task
62 *
63 * @return string Overview as HTML
64 */
65 public function getOverview() {
66 return '';
67 }
68
69 /**
70 * Main Task center module
71 *
72 * @return string HTML content.
73 */
74 public function main() {
75 $content = '';
76 $id = intval(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display'));
77 // If a preset is found, it is rendered using an iframe
78 if ($id > 0) {
79 $url = $GLOBALS['BACK_PATH'] . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id;
80 return $this->taskObject->urlInIframe($url, 1);
81 } else {
82 // Header
83 $content .= $this->taskObject->description($GLOBALS['LANG']->getLL('.alttitle'), $GLOBALS['LANG']->getLL('.description'));
84 $thumbnails = ($lines = array());
85 // Thumbnail folder and files:
86 $tempDir = $this->userTempFolder();
87 if ($tempDir) {
88 $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
89 }
90 $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
91 $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
92 // Create preset links:
93 $presets = $this->getPresets();
94 // If any presets found
95 if (is_array($presets)) {
96 foreach ($presets as $key => $presetCfg) {
97 $configuration = unserialize($presetCfg['preset_data']);
98 $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
99 $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
100 $icon = 'EXT:impexp/export.gif';
101 $description = array();
102 // Is public?
103 if ($presetCfg['public']) {
104 $description[] = $GLOBALS['LANG']->getLL('task.public') . ': ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes');
105 }
106 // Owner
107 $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']) . ']');
108 // Page & path
109 if ($configuration['pagetree']['id']) {
110 $description[] = $GLOBALS['LANG']->getLL('task.page') . ': ' . $configuration['pagetree']['id'];
111 $description[] = $GLOBALS['LANG']->getLL('task.path') . ': ' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20));
112 } else {
113 $description[] = $GLOBALS['LANG']->getLL('single-record');
114 }
115 // Meta information
116 if ($configuration['meta']['title'] || $configuration['meta']['description'] || $configuration['meta']['notes']) {
117 $metaInformation = '';
118 if ($configuration['meta']['title']) {
119 $metaInformation .= '<strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />';
120 }
121 if ($configuration['meta']['description']) {
122 $metaInformation .= htmlspecialchars($configuration['meta']['description']);
123 }
124 if ($configuration['meta']['notes']) {
125 $metaInformation .= '<br /><br />
126 <strong>' . $GLOBALS['LANG']->getLL('notes') . ': </strong>
127 <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>';
128 }
129 $description[] = '<br />' . $metaInformation;
130 }
131 // Collect all preset information
132 $lines[$key] = array(
133 'icon' => $icon,
134 'title' => $title,
135 'descriptionHtml' => implode('<br />', $description),
136 'link' => 'mod.php?M=user_task&SET[function]=impexp.tx_impexp_task&display=' . $presetCfg['uid']
137 );
138 }
139 // Render preset list
140 $content .= $this->taskObject->renderListMenu($lines);
141 } else {
142 // No presets found
143 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('no-presets'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE);
144 $content .= $flashMessage->render();
145 }
146 }
147 return $content;
148 }
149
150 /**
151 * Select presets for this user
152 *
153 * @return array Array of preset records
154 */
155 protected function getPresets() {
156 $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_impexp_presets', '(public > 0 OR user_uid=' . $GLOBALS['BE_USER']->user['uid'] . ')', '', 'item_uid DESC, title');
157 return $presets;
158 }
159
160 /**
161 * Returns first temporary folder of the user account (from $FILEMOUNTS)
162 *
163 * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
164 */
165 protected function userTempFolder() {
166 foreach ($GLOBALS['FILEMOUNTS'] as $filePathInfo) {
167 $tempFolder = $filePathInfo['path'] . '_temp_/';
168 if (@is_dir($tempFolder)) {
169 return $tempFolder;
170 }
171 }
172 return '';
173 }
174
175 }
176
177
178 ?>