[TASK] Rename ExtensionManager class Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Clipboard / Clipboard.php
1 <?php
2 namespace TYPO3\CMS\Backend\Clipboard;
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 * Contains class for TYPO3 clipboard for records and files
31 *
32 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
33 * XHTML compliant
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 /**
38 * TYPO3 clipboard for records and files
39 *
40 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
41 * @package TYPO3
42 * @subpackage t3lib
43 */
44 class Clipboard {
45
46 /**
47 * @todo Define visibility
48 */
49 public $numberTabs = 3;
50
51 /**
52 * Clipboard data kept here
53 *
54 * Keys:
55 * 'normal'
56 * 'tab_[x]' where x is >=1 and denotes the pad-number
57 * 'mode' : 'copy' means copy-mode, default = moving ('cut')
58 * 'el' : Array of elements:
59 * DB: keys = '[tablename]|[uid]' eg. 'tt_content:123'
60 * DB: values = 1 (basically insignificant)
61 * FILE: keys = '_FILE|[shortmd5 of path]' eg. '_FILE|9ebc7e5c74'
62 * FILE: values = The full filepath, eg. '/www/htdocs/typo3/32/dummy/fileadmin/sem1_3_examples/alternative_index.php'
63 * or 'C:/www/htdocs/typo3/32/dummy/fileadmin/sem1_3_examples/alternative_index.php'
64 *
65 * 'current' pointer to current tab (among the above...)
66 * '_setThumb' boolean: If set, file thumbnails are shown.
67 *
68 * The virtual tablename '_FILE' will always indicate files/folders. When checking for elements from eg. 'all tables'
69 * (by using an empty string) '_FILE' entries are excluded (so in effect only DB elements are counted)
70 *
71 * @todo Define visibility
72 */
73 public $clipData = array();
74
75 /**
76 * @todo Define visibility
77 */
78 public $changed = 0;
79
80 /**
81 * @todo Define visibility
82 */
83 public $current = '';
84
85 /**
86 * @todo Define visibility
87 */
88 public $backPath = '';
89
90 /**
91 * @todo Define visibility
92 */
93 public $lockToNormal = 0;
94
95 // If set, clipboard is displaying files.
96 /**
97 * @todo Define visibility
98 */
99 public $fileMode = 0;
100
101 /*****************************************
102 *
103 * Initialize
104 *
105 ****************************************/
106 /**
107 * Initialize the clipboard from the be_user session
108 *
109 * @return void
110 * @todo Define visibility
111 */
112 public function initializeClipboard() {
113 $this->backPath = $GLOBALS['BACK_PATH'];
114 // Get data
115 $clipData = $GLOBALS['BE_USER']->getModuleData('clipboard', $GLOBALS['BE_USER']->getTSConfigVal('options.saveClipboard') ? '' : 'ses');
116 // NumberTabs
117 $clNP = $GLOBALS['BE_USER']->getTSConfigVal('options.clipboardNumberPads');
118 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($clNP) && $clNP >= 0) {
119 $this->numberTabs = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($clNP, 0, 20);
120 }
121 // Resets/reinstates the clipboard pads
122 $this->clipData['normal'] = is_array($clipData['normal']) ? $clipData['normal'] : array();
123 for ($a = 1; $a <= $this->numberTabs; $a++) {
124 $this->clipData['tab_' . $a] = is_array($clipData['tab_' . $a]) ? $clipData['tab_' . $a] : array();
125 }
126 // Setting the current pad pointer ($this->current) and _setThumb (which determines whether or not do show file thumbnails)
127 $this->clipData['current'] = ($this->current = isset($this->clipData[$clipData['current']]) ? $clipData['current'] : 'normal');
128 $this->clipData['_setThumb'] = $clipData['_setThumb'];
129 }
130
131 /**
132 * Call this method after initialization if you want to lock the clipboard to operate on the normal pad only.
133 * Trying to switch pad through ->setCmd will not work.
134 * This is used by the clickmenu since it only allows operation on single elements at a time (that is the "normal" pad)
135 *
136 * @return void
137 * @todo Define visibility
138 */
139 public function lockToNormal() {
140 $this->lockToNormal = 1;
141 $this->current = 'normal';
142 }
143
144 /**
145 * The array $cmd may hold various keys which notes some action to take.
146 * Normally perform only one action at a time.
147 * In scripts like db_list.php / filelist/mod1/index.php the GET-var CB is used to control the clipboard.
148 *
149 * Selecting / Deselecting elements
150 * Array $cmd['el'] has keys = element-ident, value = element value (see description of clipData array in header)
151 * Selecting elements for 'copy' should be done by simultaneously setting setCopyMode.
152 *
153 * @param array $cmd Array of actions, see function description
154 * @return void
155 * @todo Define visibility
156 */
157 public function setCmd($cmd) {
158 if (is_array($cmd['el'])) {
159 foreach ($cmd['el'] as $k => $v) {
160 if ($this->current == 'normal') {
161 unset($this->clipData['normal']);
162 }
163 if ($v) {
164 $this->clipData[$this->current]['el'][$k] = $v;
165 } else {
166 $this->removeElement($k);
167 }
168 $this->changed = 1;
169 }
170 }
171 // Change clipboard pad (if not locked to normal)
172 if ($cmd['setP']) {
173 $this->setCurrentPad($cmd['setP']);
174 }
175 // Remove element (value = item ident: DB; '[tablename]|[uid]' FILE: '_FILE|[shortmd5 hash of path]'
176 if ($cmd['remove']) {
177 $this->removeElement($cmd['remove']);
178 $this->changed = 1;
179 }
180 // Remove all on current pad (value = pad-ident)
181 if ($cmd['removeAll']) {
182 $this->clipData[$cmd['removeAll']] = array();
183 $this->changed = 1;
184 }
185 // Set copy mode of the tab
186 if (isset($cmd['setCopyMode'])) {
187 $this->clipData[$this->current]['mode'] = $this->isElements() ? ($cmd['setCopyMode'] ? 'copy' : '') : '';
188 $this->changed = 1;
189 }
190 // Toggle thumbnail display for files on/off
191 if (isset($cmd['setThumb'])) {
192 $this->clipData['_setThumb'] = $cmd['setThumb'];
193 $this->changed = 1;
194 }
195 }
196
197 /**
198 * Setting the current pad on clipboard
199 *
200 * @param string $padIdent Key in the array $this->clipData
201 * @return void
202 * @todo Define visibility
203 */
204 public function setCurrentPad($padIdent) {
205 // Change clipboard pad (if not locked to normal)
206 if (!$this->lockToNormal && $this->current != $padIdent) {
207 if (isset($this->clipData[$padIdent])) {
208 $this->clipData['current'] = ($this->current = $padIdent);
209 }
210 if ($this->current != 'normal' || !$this->isElements()) {
211 $this->clipData[$this->current]['mode'] = '';
212 }
213 // Setting mode to default (move) if no items on it or if not 'normal'
214 $this->changed = 1;
215 }
216 }
217
218 /**
219 * Call this after initialization and setCmd in order to save the clipboard to the user session.
220 * The function will check if the internal flag ->changed has been set and if so, save the clipboard. Else not.
221 *
222 * @return void
223 * @todo Define visibility
224 */
225 public function endClipboard() {
226 if ($this->changed) {
227 $this->saveClipboard();
228 }
229 $this->changed = 0;
230 }
231
232 /**
233 * Cleans up an incoming element array $CBarr (Array selecting/deselecting elements)
234 *
235 * @param array $CBarr Element array from outside ("key" => "selected/deselected")
236 * @param string $table The 'table which is allowed'. Must be set.
237 * @param boolean $removeDeselected Can be set in order to remove entries which are marked for deselection.
238 * @return array Processed input $CBarr
239 * @todo Define visibility
240 */
241 public function cleanUpCBC($CBarr, $table, $removeDeselected = 0) {
242 if (is_array($CBarr)) {
243 foreach ($CBarr as $k => $v) {
244 $p = explode('|', $k);
245 if ((string) $p[0] != (string) $table || $removeDeselected && !$v) {
246 unset($CBarr[$k]);
247 }
248 }
249 }
250 return $CBarr;
251 }
252
253 /*****************************************
254 *
255 * Clipboard HTML renderings
256 *
257 ****************************************/
258 /**
259 * Prints the clipboard
260 *
261 * @return string HTML output
262 * @todo Define visibility
263 */
264 public function printClipboard() {
265 $out = array();
266 $elCount = count($this->elFromTable($this->fileMode ? '_FILE' : ''));
267 // Upper header
268 $out[] = '
269 <tr class="t3-row-header">
270 <td colspan="3">' . \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('xMOD_csh_corebe', 'list_clipboard', $this->clLabel('clipboard', 'buttons')) . '</td>
271 </tr>';
272 // Button/menu header:
273 $thumb_url = \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => array('setThumb' => $this->clipData['_setThumb'] ? 0 : 1)));
274 $rmall_url = \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => array('removeAll' => $this->current)));
275 // Copymode Selector menu
276 $copymode_url = \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript();
277 $moveLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:moveElements'));
278 $copyLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:copyElements'));
279 $opt = array();
280 $opt[] = '<option style="padding-left: 20px; background-image: url(\'' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/clip_cut.gif', '', 1) . '\'); background-repeat: no-repeat;" value="" ' . ($this->currentMode() == 'copy' ? '' : 'selected="selected"') . '>' . $moveLabel . '</option>';
281 $opt[] = '<option style="padding-left: 20px; background-image: url(\'' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, 'gfx/clip_copy.gif', '', 1) . '\'); background-repeat: no-repeat;" value="1" ' . ($this->currentMode() == 'copy' ? 'selected="selected"' : '') . '>' . $copyLabel . '</option>';
282 $copymode_selector = ' <select name="CB[setCopyMode]" onchange="this.form.method=\'POST\'; this.form.action=\'' . htmlspecialchars(($copymode_url . '&CB[setCopyMode]=')) . '\'+(this.options[this.selectedIndex].value); this.form.submit(); return true;" >' . implode('', $opt) . '</select>';
283 // Selector menu + clear button
284 $opt = array();
285 $opt[] = '<option value="" selected="selected">' . $this->clLabel('menu', 'rm') . '</option>';
286 // Import / Export link:
287 if ($elCount && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('impexp')) {
288 $opt[] = '<option value="' . htmlspecialchars(('window.location.href=\'' . $this->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('impexp') . 'app/index.php' . $this->exportClipElementParameters() . '\';')) . '">' . $this->clLabel('export', 'rm') . '</option>';
289 }
290 // Edit:
291 if (!$this->fileMode && $elCount) {
292 $opt[] = '<option value="' . htmlspecialchars(('window.location.href=\'' . $this->editUrl() . '&returnUrl=\'+top.rawurlencode(window.location.href);')) . '">' . $this->clLabel('edit', 'rm') . '</option>';
293 }
294 // Delete:
295 if ($elCount) {
296 if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
297 $js = '
298 if (confirm(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.deleteClip'), $elCount)) . ')){
299 window.location.href=\'' . $this->deleteUrl(0, ($this->fileMode ? 1 : 0)) . '&redirect=\'+top.rawurlencode(window.location.href);
300 }
301 ';
302 } else {
303 $js = ' window.location.href=\'' . $this->deleteUrl(0, ($this->fileMode ? 1 : 0)) . '&redirect=\'+top.rawurlencode(window.location.href); ';
304 }
305 $opt[] = '<option value="' . htmlspecialchars($js) . '">' . $this->clLabel('delete', 'rm') . '</option>';
306 }
307 $selector_menu = '<select name="_clipMenu" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">' . implode('', $opt) . '</select>';
308 $out[] = '
309 <tr class="typo3-clipboard-head">
310 <td nowrap="nowrap">' . '<a href="' . htmlspecialchars($thumb_url) . '#clip_head">' . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, ('gfx/thumb_' . ($this->clipData['_setThumb'] ? 's' : 'n') . '.gif'), 'width="21" height="16"') . ' vspace="2" border="0" title="' . $this->clLabel('thumbmode_clip') . '" alt="" />' . '</a>' . '</td>
311 <td width="95%" nowrap="nowrap">' . $copymode_selector . ' ' . $selector_menu . '</td>
312 <td>' . '<a href="' . htmlspecialchars($rmall_url) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:buttons.clear', TRUE))) . '</a></td>
313 </tr>';
314 // Print header and content for the NORMAL tab:
315 $out[] = '
316 <tr class="bgColor5">
317 <td colspan="3"><a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => array('setP' => 'normal')))) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon(('actions-view-table-' . ($this->current == 'normal' ? 'collapse' : 'expand'))) . $this->padTitleWrap('Normal', 'normal') . '</a></td>
318 </tr>';
319 if ($this->current == 'normal') {
320 $out = array_merge($out, $this->printContentFromTab('normal'));
321 }
322 // Print header and content for the NUMERIC tabs:
323 for ($a = 1; $a <= $this->numberTabs; $a++) {
324 $out[] = '
325 <tr class="bgColor5">
326 <td colspan="3"><a href="' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => array('setP' => ('tab_' . $a))))) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon(('actions-view-table-' . ($this->current == 'tab_' . $a ? 'collapse' : 'expand'))) . $this->padTitleWrap(($this->clLabel('cliptabs') . $a), ('tab_' . $a)) . '</a></td>
327 </tr>';
328 if ($this->current == 'tab_' . $a) {
329 $out = array_merge($out, $this->printContentFromTab('tab_' . $a));
330 }
331 }
332 // Wrap accumulated rows in a table:
333 $output = '<a name="clip_head"></a>
334
335 <!--
336 TYPO3 Clipboard:
337 -->
338 <table cellpadding="0" cellspacing="1" border="0" width="290" id="typo3-clipboard">
339 ' . implode('', $out) . '
340 </table>';
341 // Wrap in form tag:
342 $output = '<form action="">' . $output . '</form>';
343 // Return the accumulated content:
344 return $output;
345 }
346
347 /**
348 * Print the content on a pad. Called from ->printClipboard()
349 *
350 * @access private
351 * @param string $pad Pad reference
352 * @return array Array with table rows for the clipboard.
353 * @todo Define visibility
354 */
355 public function printContentFromTab($pad) {
356 $lines = array();
357 if (is_array($this->clipData[$pad]['el'])) {
358 foreach ($this->clipData[$pad]['el'] as $k => $v) {
359 if ($v) {
360 list($table, $uid) = explode('|', $k);
361 $bgColClass = $table == '_FILE' && $this->fileMode || $table != '_FILE' && !$this->fileMode ? 'bgColor4-20' : 'bgColor4';
362 // Rendering files/directories on the clipboard
363 if ($table == '_FILE') {
364 $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($v);
365 if ($fileObject) {
366 $thumb = '';
367 $folder = $fileObject instanceof \TYPO3\CMS\Core\Resource\Folder;
368 $size = $folder ? '' : '(' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes)';
369 $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($folder ? 'folder' : strtolower($fileObject->getExtension()), array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size));
370 if ($this->clipData['_setThumb'] && \TYPO3\CMS\Core\Utility\GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
371 $thumb = '<br />' . \TYPO3\CMS\Backend\Utility\BackendUtility::getThumbNail(($this->backPath . 'thumbs.php'), $v, ' vspace="4"');
372 }
373 $lines[] = '
374 <tr>
375 <td class="' . $bgColClass . '">' . $icon . '</td>
376 <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . $this->linkItemText(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $GLOBALS['BE_USER']->uc['titleLen'])), $fileObject->getName()) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . '&nbsp;' . $thumb . '</td>
377 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars(('top.launchView(\'' . $table . '\', \'' . $v . '\'); return false;')) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl('_FILE', \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($v))) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' . '</td>
378 </tr>';
379 } else {
380 // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
381 unset($this->clipData[$pad]['el'][$k]);
382 $this->changed = 1;
383 }
384 } else {
385 // Rendering records:
386 $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($table, $uid);
387 if (is_array($rec)) {
388 $lines[] = '
389 <tr>
390 <td class="' . $bgColClass . '">' . $this->linkItemText(\TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $rec, array('style' => 'margin: 0 20px;', 'title' => htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordIconAltText($rec, $table)))), $rec, $table) . '</td>
391 <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . $this->linkItemText(htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])), $rec, $table) . ($pad == 'normal' ? ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>' : '') . '&nbsp;</td>
392 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' . '<a href="#" onclick="' . htmlspecialchars(('top.launchView(\'' . $table . '\', \'' . intval($uid) . '\'); return false;')) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' . '<a href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' . '</td>
393 </tr>';
394 $localizationData = $this->getLocalizations($table, $rec, $bgColClass, $pad);
395 if ($localizationData) {
396 $lines[] = $localizationData;
397 }
398 } else {
399 unset($this->clipData[$pad]['el'][$k]);
400 $this->changed = 1;
401 }
402 }
403 }
404 }
405 }
406 if (!count($lines)) {
407 $lines[] = '
408 <tr>
409 <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td>
410 <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%">&nbsp;<em>(' . $this->clLabel('clipNoEl') . ')</em>&nbsp;</td>
411 </tr>';
412 }
413 $this->endClipboard();
414 return $lines;
415 }
416
417 /**
418 * Gets all localizations of the current record.
419 *
420 * @param string $table The table
421 * @param array $parentRec The current record
422 * @param string $bgColClass Class for the background color of a column
423 * @param string $pad Pad reference
424 * @return string HTML table rows
425 * @todo Define visibility
426 */
427 public function getLocalizations($table, $parentRec, $bgColClass, $pad) {
428 $lines = array();
429 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
430 if ($table != 'pages' && \TYPO3\CMS\Backend\Utility\BackendUtility::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
431 $where = array();
432 $where[] = $tcaCtrl['transOrigPointerField'] . '=' . intval($parentRec['uid']);
433 $where[] = $tcaCtrl['languageField'] . '<>0';
434 if (isset($tcaCtrl['delete']) && $tcaCtrl['delete']) {
435 $where[] = $tcaCtrl['delete'] . '=0';
436 }
437 if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
438 $where[] = 't3ver_wsid=' . $parentRec['t3ver_wsid'];
439 }
440 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, implode(' AND ', $where));
441 if (is_array($rows)) {
442 $modeData = '';
443 if ($pad == 'normal') {
444 $mode = $this->clipData['normal']['mode'] == 'copy' ? 'copy' : 'cut';
445 $modeData = ' <strong>(' . $this->clLabel($mode, 'cm') . ')</strong>';
446 }
447 foreach ($rows as $rec) {
448 $lines[] = '
449 <tr>
450 <td class="' . $bgColClass . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord($table, $rec, array('style' => 'margin-left: 38px;')) . '</td>
451 <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])) . $modeData . '&nbsp;</td>
452 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">&nbsp;</td>
453 </tr>';
454 }
455 }
456 }
457 return implode('', $lines);
458 }
459
460 /**
461 * Wraps title of pad in bold-tags and maybe the number of elements if any.
462 *
463 * @param string $str String (already htmlspecialchars()'ed)
464 * @param string $pad Pad reference
465 * @return string HTML output (htmlspecialchar'ed content inside of tags.)
466 * @todo Define visibility
467 */
468 public function padTitleWrap($str, $pad) {
469 $el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
470 if ($el) {
471 return '<strong>' . $str . '</strong> (' . ($pad == 'normal' ? ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars($el)) . ')';
472 } else {
473 return $GLOBALS['TBE_TEMPLATE']->dfw($str);
474 }
475 }
476
477 /**
478 * Wraps the title of the items listed in link-tags. The items will link to the page/folder where they originate from
479 *
480 * @param string $str Title of element - must be htmlspecialchar'ed on beforehand.
481 * @param mixed $rec If array, a record is expected. If string, its a path
482 * @param string $table Table name
483 * @return string
484 * @todo Define visibility
485 */
486 public function linkItemText($str, $rec, $table = '') {
487 if (is_array($rec) && $table) {
488 if ($this->fileMode) {
489 $str = $GLOBALS['TBE_TEMPLATE']->dfw($str);
490 } else {
491 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('recordlist')) {
492 $str = '<a href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_list', array('id' => $rec['pid']), $this->backPath)) . '">' . $str . '</a>';
493 }
494 }
495 } elseif (file_exists($rec)) {
496 if (!$this->fileMode) {
497 $str = $GLOBALS['TBE_TEMPLATE']->dfw($str);
498 } else {
499 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('filelist')) {
500 $str = '<a href="' . htmlspecialchars(($this->backPath . \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('file_list') . '&id=' . dirname($rec))) . '">' . $str . '</a>';
501 }
502 }
503 }
504 return $str;
505 }
506
507 /**
508 * Returns the select-url for database elements
509 *
510 * @param string $table Table name
511 * @param integer $uid Uid of record
512 * @param boolean $copy If set, copymode will be enabled
513 * @param boolean $deselect If set, the link will deselect, otherwise select.
514 * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
515 * @return string URL linking to the current script but with the CB array set to select the element with table/uid
516 * @todo Define visibility
517 */
518 public function selUrlDB($table, $uid, $copy = 0, $deselect = 0, $baseArray = array()) {
519 $CB = array('el' => array(rawurlencode($table . '|' . $uid) => $deselect ? 0 : 1));
520 if ($copy) {
521 $CB['setCopyMode'] = 1;
522 }
523 $baseArray['CB'] = $CB;
524 return \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript($baseArray);
525 }
526
527 /**
528 * Returns the select-url for files
529 *
530 * @param string $path Filepath
531 * @param boolean $copy If set, copymode will be enabled
532 * @param boolean $deselect If set, the link will deselect, otherwise select.
533 * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
534 * @return string URL linking to the current script but with the CB array set to select the path
535 * @todo Define visibility
536 */
537 public function selUrlFile($path, $copy = 0, $deselect = 0, $baseArray = array()) {
538 $CB = array('el' => array(rawurlencode('_FILE|' . \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($path)) => $deselect ? '' : $path));
539 if ($copy) {
540 $CB['setCopyMode'] = 1;
541 }
542 $baseArray['CB'] = $CB;
543 return \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript($baseArray);
544 }
545
546 /**
547 * pasteUrl of the element (database and file)
548 * For the meaning of $table and $uid, please read from ->makePasteCmdArray!!!
549 * The URL will point to tce_file or tce_db depending in $table
550 *
551 * @param string $table Tablename (_FILE for files)
552 * @param mixed $uid "destination": can be positive or negative indicating how the paste is done (paste into / paste after)
553 * @param boolean $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
554 * @return string
555 * @todo Define visibility
556 */
557 public function pasteUrl($table, $uid, $setRedirect = 1) {
558 $rU = $this->backPath . ($table == '_FILE' ? 'tce_file.php' : 'tce_db.php') . '?' . ($setRedirect ? 'redirect=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => ''))) : '') . '&vC=' . $GLOBALS['BE_USER']->veriCode() . '&prErr=1&uPT=1' . '&CB[paste]=' . rawurlencode(($table . '|' . $uid)) . '&CB[pad]=' . $this->current . \TYPO3\CMS\Backend\Utility\BackendUtility::getUrlToken('tceAction');
559 return $rU;
560 }
561
562 /**
563 * deleteUrl for current pad
564 *
565 * @param boolean $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
566 * @param boolean $file If set, then the URL will link to the tce_file.php script in the typo3/ dir.
567 * @return string
568 * @todo Define visibility
569 */
570 public function deleteUrl($setRedirect = 1, $file = 0) {
571 $rU = $this->backPath . ($file ? 'tce_file.php' : 'tce_db.php') . '?' . ($setRedirect ? 'redirect=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => ''))) : '') . '&vC=' . $GLOBALS['BE_USER']->veriCode() . '&prErr=1&uPT=1' . '&CB[delete]=1' . '&CB[pad]=' . $this->current . \TYPO3\CMS\Backend\Utility\BackendUtility::getUrlToken('tceAction');
572 return $rU;
573 }
574
575 /**
576 * editUrl of all current elements
577 * ONLY database
578 * Links to alt_doc.php
579 *
580 * @return string The URL to alt_doc.php with parameters.
581 * @todo Define visibility
582 */
583 public function editUrl() {
584 // All records
585 $elements = $this->elFromTable('');
586 $editCMDArray = array();
587 foreach ($elements as $tP => $value) {
588 list($table, $uid) = explode('|', $tP);
589 $editCMDArray[] = '&edit[' . $table . '][' . $uid . ']=edit';
590 }
591 $rU = $this->backPath . 'alt_doc.php?' . implode('', $editCMDArray);
592 return $rU;
593 }
594
595 /**
596 * Returns the remove-url (file and db)
597 * for file $table='_FILE' and $uid = shortmd5 hash of path
598 *
599 * @param string $table Tablename
600 * @param string $uid Uid integer/shortmd5 hash
601 * @return string URL
602 * @todo Define visibility
603 */
604 public function removeUrl($table, $uid) {
605 return \TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(array('CB' => array('remove' => $table . '|' . $uid)));
606 }
607
608 /**
609 * Returns confirm JavaScript message
610 *
611 * @param string $table Table name
612 * @param mixed $rec For records its an array, for files its a string (path)
613 * @param string $type Type-code
614 * @param array $clElements Array of selected elements
615 * @return string JavaScript "confirm" message
616 * @todo Define visibility
617 */
618 public function confirmMsg($table, $rec, $type, $clElements) {
619 if ($GLOBALS['BE_USER']->jsConfirmation(2)) {
620 $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.' . ($this->currentMode() == 'copy' ? 'copy' : 'move') . ($this->current == 'normal' ? '' : 'cb') . '_' . $type;
621 $msg = $GLOBALS['LANG']->sL($labelKey);
622 if ($table == '_FILE') {
623 $thisRecTitle = basename($rec);
624 if ($this->current == 'normal') {
625 $selItem = reset($clElements);
626 $selRecTitle = basename($selItem);
627 } else {
628 $selRecTitle = count($clElements);
629 }
630 } else {
631 $thisRecTitle = $table == 'pages' && !is_array($rec) ? $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] : \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $rec);
632 if ($this->current == 'normal') {
633 $selItem = $this->getSelectedRecord();
634 $selRecTitle = $selItem['_RECORD_TITLE'];
635 } else {
636 $selRecTitle = count($clElements);
637 }
638 }
639 // Message
640 $conf = 'confirm(' . $GLOBALS['LANG']->JScharCode(sprintf($msg, \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($selRecTitle, 30), \TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($thisRecTitle, 30))) . ')';
641 } else {
642 $conf = '';
643 }
644 return $conf;
645 }
646
647 /**
648 * Clipboard label - getting from "EXT:lang/locallang_core.php:"
649 *
650 * @param string $key Label Key
651 * @param string $Akey Alternative key to "labels
652 * @return string
653 * @todo Define visibility
654 */
655 public function clLabel($key, $Akey = 'labels') {
656 return htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:' . $Akey . '.' . $key));
657 }
658
659 /**
660 * Creates GET parameters for linking to the export module.
661 *
662 * @return string GET parameters for current clipboard content to be exported.
663 * @todo Define visibility
664 */
665 public function exportClipElementParameters() {
666 // Init
667 $pad = $this->current;
668 $params = array();
669 $params[] = 'tx_impexp[action]=export';
670 // Traverse items:
671 if (is_array($this->clipData[$pad]['el'])) {
672 foreach ($this->clipData[$pad]['el'] as $k => $v) {
673 if ($v) {
674 list($table, $uid) = explode('|', $k);
675 // Rendering files/directories on the clipboard
676 if ($table == '_FILE') {
677 if (file_exists($v) && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($v)) {
678 $params[] = 'tx_impexp[' . (is_dir($v) ? 'dir' : 'file') . '][]=' . rawurlencode($v);
679 }
680 } else {
681 // Rendering records:
682 $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $uid);
683 if (is_array($rec)) {
684 $params[] = 'tx_impexp[record][]=' . rawurlencode(($table . ':' . $uid));
685 }
686 }
687 }
688 }
689 }
690 return '?' . implode('&', $params);
691 }
692
693 /*****************************************
694 *
695 * Helper functions
696 *
697 ****************************************/
698 /**
699 * Removes element on clipboard
700 *
701 * @param string $el Key of element in ->clipData array
702 * @return void
703 * @todo Define visibility
704 */
705 public function removeElement($el) {
706 unset($this->clipData[$this->current]['el'][$el]);
707 $this->changed = 1;
708 }
709
710 /**
711 * Saves the clipboard, no questions asked.
712 * Use ->endClipboard normally (as it checks if changes has been done so saving is necessary)
713 *
714 * @access private
715 * @return void
716 * @todo Define visibility
717 */
718 public function saveClipboard() {
719 $GLOBALS['BE_USER']->pushModuleData('clipboard', $this->clipData);
720 }
721
722 /**
723 * Returns the current mode, 'copy' or 'cut'
724 *
725 * @return string "copy" or "cut
726 * @todo Define visibility
727 */
728 public function currentMode() {
729 return $this->clipData[$this->current]['mode'] == 'copy' ? 'copy' : 'cut';
730 }
731
732 /**
733 * This traverses the elements on the current clipboard pane
734 * and unsets elements which does not exist anymore or are disabled.
735 *
736 * @return void
737 * @todo Define visibility
738 */
739 public function cleanCurrent() {
740 if (is_array($this->clipData[$this->current]['el'])) {
741 foreach ($this->clipData[$this->current]['el'] as $k => $v) {
742 list($table, $uid) = explode('|', $k);
743 if ($table != '_FILE') {
744 if (!$v || !is_array(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $uid, 'uid'))) {
745 unset($this->clipData[$this->current]['el'][$k]);
746 $this->changed = 1;
747 }
748 } else {
749 if (!$v || \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($v) === NULL) {
750 unset($this->clipData[$this->current]['el'][$k]);
751 $this->changed = 1;
752 }
753 }
754 }
755 }
756 }
757
758 /**
759 * Counts the number of elements from the table $matchTable. If $matchTable is blank, all tables (except '_FILE' of course) is counted.
760 *
761 * @param string $matchTable Table to match/count for.
762 * @param string $pad Can optionally be used to set another pad than the current.
763 * @return array Array with keys from the CB.
764 * @todo Define visibility
765 */
766 public function elFromTable($matchTable = '', $pad = '') {
767 $pad = $pad ? $pad : $this->current;
768 $list = array();
769 if (is_array($this->clipData[$pad]['el'])) {
770 foreach ($this->clipData[$pad]['el'] as $k => $v) {
771 if ($v) {
772 list($table, $uid) = explode('|', $k);
773 if ($table != '_FILE') {
774 if ((!$matchTable || (string) $table == (string) $matchTable) && $GLOBALS['TCA'][$table]) {
775 $list[$k] = $pad == 'normal' ? $v : $uid;
776 }
777 } else {
778 if ((string) $table == (string) $matchTable) {
779 $list[$k] = $v;
780 }
781 }
782 }
783 }
784 }
785 return $list;
786 }
787
788 /**
789 * Verifies if the item $table/$uid is on the current pad.
790 * If the pad is "normal", the mode value is returned if the element existed. Thus you'll know if the item was copy or cut moded...
791 *
792 * @param string $table Table name, (_FILE for files...)
793 * @param integer $uid Element uid (path for files)
794 * @return string
795 * @todo Define visibility
796 */
797 public function isSelected($table, $uid) {
798 $k = $table . '|' . $uid;
799 return $this->clipData[$this->current]['el'][$k] ? ($this->current == 'normal' ? $this->currentMode() : 1) : '';
800 }
801
802 /**
803 * Returns item record $table,$uid if selected on current clipboard
804 * If table and uid is blank, the first element is returned.
805 * Makes sense only for DB records - not files!
806 *
807 * @param string $table Table name
808 * @param integer $uid Element uid
809 * @return array Element record with extra field _RECORD_TITLE set to the title of the record
810 * @todo Define visibility
811 */
812 public function getSelectedRecord($table = '', $uid = '') {
813 if (!$table && !$uid) {
814 $elArr = $this->elFromTable('');
815 reset($elArr);
816 list($table, $uid) = explode('|', key($elArr));
817 }
818 if ($this->isSelected($table, $uid)) {
819 $selRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordWSOL($table, $uid);
820 $selRec['_RECORD_TITLE'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle($table, $selRec);
821 return $selRec;
822 }
823 }
824
825 /**
826 * Reports if the current pad has elements (does not check file/DB type OR if file/DBrecord exists or not. Only counting array)
827 *
828 * @return boolean TRUE if elements exist.
829 * @todo Define visibility
830 */
831 public function isElements() {
832 return is_array($this->clipData[$this->current]['el']) && count($this->clipData[$this->current]['el']);
833 }
834
835 /*****************************************
836 *
837 * FOR USE IN tce_db.php:
838 *
839 ****************************************/
840 /**
841 * Applies the proper paste configuration in the $cmd array send to tce_db.php.
842 * $ref is the target, see description below.
843 * The current pad is pasted
844 *
845 * $ref: [tablename]:[paste-uid].
846 * Tablename is the name of the table from which elements *on the current clipboard* is pasted with the 'pid' paste-uid.
847 * No tablename means that all items on the clipboard (non-files) are pasted. This requires paste-uid to be positive though.
848 * so 'tt_content:-3' means 'paste tt_content elements on the clipboard to AFTER tt_content:3 record
849 * 'tt_content:30' means 'paste tt_content elements on the clipboard into page with id 30
850 * ':30' means 'paste ALL database elements on the clipboard into page with id 30
851 * ':-30' not valid.
852 *
853 * @param string $ref [tablename]:[paste-uid], see description
854 * @param array $CMD Command-array
855 * @return array Modified Command-array
856 * @todo Define visibility
857 */
858 public function makePasteCmdArray($ref, $CMD) {
859 list($pTable, $pUid) = explode('|', $ref);
860 $pUid = intval($pUid);
861 // pUid must be set and if pTable is not set (that means paste ALL elements)
862 // the uid MUST be positive/zero (pointing to page id)
863 if ($pTable || $pUid >= 0) {
864 $elements = $this->elFromTable($pTable);
865 // So the order is preserved.
866 $elements = array_reverse($elements);
867 $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
868 // Traverse elements and make CMD array
869 foreach ($elements as $tP => $value) {
870 list($table, $uid) = explode('|', $tP);
871 if (!is_array($CMD[$table])) {
872 $CMD[$table] = array();
873 }
874 $CMD[$table][$uid][$mode] = $pUid;
875 if ($mode == 'move') {
876 $this->removeElement($tP);
877 }
878 }
879 $this->endClipboard();
880 }
881 return $CMD;
882 }
883
884 /**
885 * Delete record entries in CMD array
886 *
887 * @param array $CMD Command-array
888 * @return array Modified Command-array
889 * @todo Define visibility
890 */
891 public function makeDeleteCmdArray($CMD) {
892 // all records
893 $elements = $this->elFromTable('');
894 foreach ($elements as $tP => $value) {
895 list($table, $uid) = explode('|', $tP);
896 if (!is_array($CMD[$table])) {
897 $CMD[$table] = array();
898 }
899 $CMD[$table][$uid]['delete'] = 1;
900 $this->removeElement($tP);
901 }
902 $this->endClipboard();
903 return $CMD;
904 }
905
906 /*****************************************
907 *
908 * FOR USE IN tce_file.php:
909 *
910 ****************************************/
911 /**
912 * Applies the proper paste configuration in the $file array send to tce_file.php.
913 * The current pad is pasted
914 *
915 * @param string $ref Reference to element (splitted by "|")
916 * @param array $FILE Command-array
917 * @return array Modified Command-array
918 * @todo Define visibility
919 */
920 public function makePasteCmdArray_file($ref, $FILE) {
921 list($pTable, $pUid) = explode('|', $ref);
922 $elements = $this->elFromTable('_FILE');
923 $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
924 // Traverse elements and make CMD array
925 foreach ($elements as $tP => $path) {
926 $FILE[$mode][] = array('data' => $path, 'target' => $pUid);
927 if ($mode == 'move') {
928 $this->removeElement($tP);
929 }
930 }
931 $this->endClipboard();
932 return $FILE;
933 }
934
935 /**
936 * Delete files in CMD array
937 *
938 * @param array $FILE Command-array
939 * @return array Modified Command-array
940 * @todo Define visibility
941 */
942 public function makeDeleteCmdArray_file($FILE) {
943 $elements = $this->elFromTable('_FILE');
944 // Traverse elements and make CMD array
945 foreach ($elements as $tP => $path) {
946 $FILE['delete'][] = array('data' => $path);
947 $this->removeElement($tP);
948 }
949 $this->endClipboard();
950 return $FILE;
951 }
952
953 }
954
955
956 ?>