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