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