[TASK] Cleanup impexp
[Packages/TYPO3.CMS.git] / typo3 / sysext / impexp / Classes / Controller / ModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\Impexp\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Export Preset listing for the task center
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 class ModuleFunctionController extends mod_user_task {
36
37 /**
38 * Create preset overview for task center overview.
39 *
40 * @return string HTML for the task center overview listing.
41 * @todo Define visibility
42 */
43 public function overview_main() {
44 global $LANG;
45 // Create preset links:
46 $presets = $this->getPresets();
47 $opt = array();
48 if (is_array($presets)) {
49 foreach ($presets as $presetCfg) {
50 $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
51 $opt[] = '
52 <tr class="bgColor4">
53 <td nowrap="nowrap"><a href="index.php?SET[function]=tx_impexp&display=' . $presetCfg['uid'] . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>&nbsp;</td>
54 <td>' . ($presetCfg['item_uid'] ? $presetCfg['item_uid'] : '&nbsp;') . '</td>
55 <td>' . ($presetCfg['public'] ? '[Public]' : '&nbsp;') . '</td>
56 <td>' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? '[Own]' : '&nbsp;') . '</td>
57 </tr>';
58 }
59 if (sizeof($opt) > 0) {
60 $presets = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding">' . implode('', $opt) . '</table>';
61 $presets .= '<a href="index.php?SET[function]=tx_impexp"><em>' . $LANG->getLL('link_allRecs') . '</em></a>';
62 } else {
63 $presets = '';
64 }
65 $icon = '<img src="' . $this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'export.gif" width="18" height="16" class="absmiddle" alt="" />';
66 $config = $this->mkMenuConfig($icon . $this->headLink('tx_impexp_modfunc1', 1), '', $presets);
67 }
68 return $config;
69 }
70
71 /**
72 * Main Task center module
73 *
74 * @return string HTML content.
75 * @todo Define visibility
76 */
77 public function main() {
78 if ($id = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('display')) {
79 return $this->urlInIframe($this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php?tx_impexp[action]=export&preset[load]=1&preset[select]=' . $id, 1);
80 } else {
81 // Thumbnail folder and files:
82 $tempDir = $this->userTempFolder();
83 if ($tempDir) {
84 $thumbnails = \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir($tempDir, 'png,gif,jpg', 1);
85 }
86 $clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
87 $usernames = \TYPO3\CMS\Backend\Utility\BackendUtility::getUserNames();
88 // Create preset links:
89 $presets = $this->getPresets();
90 $opt = array();
91 $opt[] = '
92 <tr class="bgColor5 tableheader">
93 <td>Icon:</td>
94 <td>Preset Title:</td>
95 <td>Public</td>
96 <td>Owner:</td>
97 <td>Page:</td>
98 <td>Path:</td>
99 <td>Meta data:</td>
100 </tr>';
101 if (is_array($presets)) {
102 foreach ($presets as $presetCfg) {
103 $configuration = unserialize($presetCfg['preset_data']);
104 $thumbnailFile = $thumbnails[$configuration['meta']['thumbnail']];
105 $title = strlen($presetCfg['title']) ? $presetCfg['title'] : '[' . $presetCfg['uid'] . ']';
106 $opt[] = '
107 <tr class="bgColor4">
108 <td>' . ($thumbnailFile ? '<img src="' . $this->backPath . '../' . substr($tempDir, strlen(PATH_site)) . basename($thumbnailFile) . '" hspace="2" width="70" style="border: solid black 1px;" alt="" /><br />' : '&nbsp;') . '</td>
109 <td nowrap="nowrap"><a href="index.php?SET[function]=tx_impexp&display=' . $presetCfg['uid'] . '">' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($title, 30)) . '</a>&nbsp;</td>
110 <td>' . ($presetCfg['public'] ? 'Yes' : '&nbsp;') . '</td>
111 <td>' . ($presetCfg['user_uid'] === $GLOBALS['BE_USER']->user['uid'] ? 'Own' : '[' . $usernames[$presetCfg['user_uid']]['username'] . ']') . '</td>
112 <td>' . ($configuration['pagetree']['id'] ? $configuration['pagetree']['id'] : '&nbsp;') . '</td>
113 <td>' . htmlspecialchars(($configuration['pagetree']['id'] ? \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($configuration['pagetree']['id'], $clause, 20) : '[Single Records]')) . '</td>
114 <td>
115 <strong>' . htmlspecialchars($configuration['meta']['title']) . '</strong><br />' . htmlspecialchars($configuration['meta']['description']) . ($configuration['meta']['notes'] ? '<br /><br /><strong>Notes:</strong> <em>' . htmlspecialchars($configuration['meta']['notes']) . '</em>' : '') . '
116 </td>
117 </tr>';
118 }
119 $content = '<table border="0" cellpadding="0" cellspacing="1" class="lrPadding">' . implode('', $opt) . '</table>';
120 }
121 }
122 // Output:
123 $theOutput .= $this->pObj->doc->spacer(5);
124 $theOutput .= $this->pObj->doc->section('Export presets', $content, 0, 1);
125 return $theOutput;
126 }
127
128 /*****************************
129 * Helper functions
130 *****************************/
131
132 /**
133 * Select presets for this user
134 *
135 * @return array Array of preset records
136 * @todo Define visibility
137 */
138 public function getPresets() {
139 $presets = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_impexp_presets', '(public>0 OR user_uid=' . intval($GLOBALS['BE_USER']->user['uid']) . ')', '', 'item_uid DESC, title');
140 return $presets;
141 }
142
143 /**
144 * Returns first temporary folder of the user account (from $FILEMOUNTS)
145 *
146 * @return string Absolute path to first "_temp_" folder of the current user, otherwise blank.
147 * @todo Define visibility
148 */
149 public function userTempFolder() {
150 global $FILEMOUNTS;
151 foreach ($FILEMOUNTS as $filePathInfo) {
152 $tempFolder = $filePathInfo['path'] . '_temp_/';
153 if (@is_dir($tempFolder)) {
154 return $tempFolder;
155 }
156 }
157 }
158
159 }
160
161 ?>