[BUGFIX] Fix 1-2-3(-4) wizard
[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 // Print header and content for the NORMAL tab:
306 $out[] = '
307 <tr class="bgColor5">
308 <td colspan="3"><a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('CB' => array('setP' => 'normal')))) . '#clip_head">' .
309 t3lib_iconWorks::getSpriteIcon('actions-view-table-' . (($this->current == 'normal') ? 'collapse' : 'expand')) .
310 $this->padTitleWrap('Normal', 'normal') .
311 '</a></td>
312 </tr>';
313 if ($this->current == 'normal') {
314 $out = array_merge($out, $this->printContentFromTab('normal'));
315 }
316
317 // Print header and content for the NUMERIC tabs:
318 for ($a = 1; $a <= $this->numberTabs; $a++) {
319 $out[] = '
320 <tr class="bgColor5">
321 <td colspan="3"><a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('CB' => array('setP' => 'tab_' . $a)))) . '#clip_head">' .
322 t3lib_iconWorks::getSpriteIcon('actions-view-table-' . (($this->current == 'tab_' . $a) ? 'collapse' : 'expand')) .
323 $this->padTitleWrap($this->clLabel('cliptabs') . $a, 'tab_' . $a) .
324 '</a></td>
325 </tr>';
326 if ($this->current == 'tab_' . $a) {
327 $out = array_merge($out, $this->printContentFromTab('tab_' . $a));
328 }
329 }
330
331 // Wrap accumulated rows in a table:
332 $output = '<a name="clip_head"></a>
333
334 <!--
335 TYPO3 Clipboard:
336 -->
337 <table cellpadding="0" cellspacing="1" border="0" width="290" id="typo3-clipboard">
338 ' . implode('', $out) . '
339 </table>';
340
341 // Wrap in form tag:
342 $output = '<form action="">' . $output . '</form>';
343
344 // Return the accumulated content:
345 return $output;
346 }
347
348 /**
349 * Print the content on a pad. Called from ->printClipboard()
350 *
351 * @access private
352 * @param string $pad Pad reference
353 * @return array Array with table rows for the clipboard.
354 */
355 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
363 // Rendering files/directories on the clipboard
364 if ($table == '_FILE') {
365 $fileObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($v);
366 if ($fileObject) {
367 $thumb = '';
368 $folder = $fileObject instanceof t3lib_file_Folder;
369 $size = ($folder ? '' : '(' . t3lib_div::formatSize($fileObject->getSize()) . 'bytes)');
370 $icon = t3lib_iconWorks::getSpriteIconForFile(
371 $folder ? 'folder' : strtolower($fileObject->getExtension()),
372 array('style' => 'margin: 0 20px;', 'title' => $fileObject->getName() . ' ' . $size)
373 );
374
375 if ($this->clipData['_setThumb'] && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $fileObject->getExtension())) {
376 $thumb = '<br />' . t3lib_BEfunc::getThumbNail($this->backPath . 'thumbs.php', $v, ' vspace="4"');
377 }
378
379 $lines[] = '
380 <tr>
381 <td class="' . $bgColClass . '">' . $icon . '</td>
382 <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()) .
383 ($pad == 'normal' ? (' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>') : '') . '&nbsp;' . $thumb . '</td>
384 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' .
385 '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . $v . '\'); return false;') . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' .
386 '<a href="' . htmlspecialchars($this->removeUrl('_FILE', t3lib_div::shortmd5($v))) . '#clip_head">' . t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' .
387 '</td>
388 </tr>';
389 } else {
390 // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
391 unset($this->clipData[$pad]['el'][$k]);
392 $this->changed = 1;
393 }
394 } else { // Rendering records:
395 $rec = t3lib_BEfunc::getRecordWSOL($table, $uid);
396 if (is_array($rec)) {
397 $lines[] = '
398 <tr>
399 <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>
400 <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) .
401 ($pad == 'normal' ? (' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) . ')</strong>') : '') . '&nbsp;</td>
402 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">' .
403 '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . intval($uid) . '\'); return false;') . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>' .
404 '<a href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head">' . t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>' .
405 '</td>
406 </tr>';
407
408 $localizationData = $this->getLocalizations($table, $rec, $bgColClass, $pad);
409 if ($localizationData) {
410 $lines[] = $localizationData;
411 }
412
413 } else {
414 unset($this->clipData[$pad]['el'][$k]);
415 $this->changed = 1;
416 }
417 }
418 }
419 }
420 }
421 if (!count($lines)) {
422 $lines[] = '
423 <tr>
424 <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td>
425 <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%">&nbsp;<em>(' . $this->clLabel('clipNoEl') . ')</em>&nbsp;</td>
426 </tr>';
427 }
428
429 $this->endClipboard();
430 return $lines;
431 }
432
433
434 /**
435 * Gets all localizations of the current record.
436 *
437 * @param string $table The table
438 * @param array $parentRec The current record
439 * @param string $bgColClass Class for the background color of a column
440 * @param string $pad Pad reference
441 * @return string HTML table rows
442 */
443 function getLocalizations($table, $parentRec, $bgColClass, $pad) {
444 $lines = array();
445 $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
446
447 if ($table != 'pages' && t3lib_BEfunc::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
448 $where = array();
449 $where[] = $tcaCtrl['transOrigPointerField'] . '=' . intval($parentRec['uid']);
450 $where[] = $tcaCtrl['languageField'] . '<>0';
451
452 if (isset($tcaCtrl['delete']) && $tcaCtrl['delete']) {
453 $where[] = $tcaCtrl['delete'] . '=0';
454 }
455
456 if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
457 $where[] = 't3ver_wsid=' . $parentRec['t3ver_wsid'];
458 }
459
460 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, implode(' AND ', $where));
461
462 if (is_array($rows)) {
463 $modeData = '';
464 if ($pad == 'normal') {
465 $mode = ($this->clipData['normal']['mode'] == 'copy' ? 'copy' : 'cut');
466 $modeData = ' <strong>(' . $this->clLabel($mode, 'cm') . ')</strong>';
467 }
468
469 foreach ($rows as $rec) {
470 $lines[] = '
471 <tr>
472 <td class="' . $bgColClass . '">' .
473 t3lib_iconWorks::getSpriteIconForRecord($table, $rec, array('style' => 'margin-left: 38px;')) . '</td>
474 <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . htmlspecialchars(
475 t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])) .
476 $modeData . '&nbsp;</td>
477 <td class="' . $bgColClass . '" align="center" nowrap="nowrap">&nbsp;</td>
478 </tr>';
479 }
480 }
481 }
482 return implode('', $lines);
483 }
484
485
486 /**
487 * Wraps title of pad in bold-tags and maybe the number of elements if any.
488 *
489 * @param string $str String (already htmlspecialchars()'ed)
490 * @param string $pad Pad reference
491 * @return string HTML output (htmlspecialchar'ed content inside of tags.)
492 */
493 function padTitleWrap($str, $pad) {
494 $el = count($this->elFromTable($this->fileMode ? '_FILE' : '', $pad));
495 if ($el) {
496 return '<strong>' . $str . '</strong> (' . ($pad == 'normal' ? ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') : $this->clLabel('cut', 'cm')) : htmlspecialchars($el)) . ')';
497 } else {
498 return $GLOBALS['TBE_TEMPLATE']->dfw($str);
499 }
500 }
501
502 /**
503 * Wraps the title of the items listed in link-tags. The items will link to the page/folder where they originate from
504 *
505 * @param string $str Title of element - must be htmlspecialchar'ed on beforehand.
506 * @param mixed $rec If array, a record is expected. If string, its a path
507 * @param string $table Table name
508 * @return string
509 */
510 function linkItemText($str, $rec, $table = '') {
511 if (is_array($rec) && $table) {
512 if ($this->fileMode) {
513 $str = $GLOBALS['TBE_TEMPLATE']->dfw($str);
514 } else {
515 if (t3lib_extMgm::isLoaded('recordlist')) {
516 $str = '<a href="' . htmlspecialchars(
517 t3lib_BEfunc::getModuleUrl(
518 'web_list',
519 array('id' => $rec['pid']),
520 $this->backPath)
521 ) . '">' . $str . '</a>';
522 }
523 }
524 } elseif (file_exists($rec)) {
525 if (!$this->fileMode) {
526 $str = $GLOBALS['TBE_TEMPLATE']->dfw($str);
527 } else {
528 if (t3lib_extMgm::isLoaded('filelist')) {
529 $str = '<a href="' . htmlspecialchars(
530 $this->backPath . t3lib_BEfunc::getModuleUrl('file_list') . '&id=' . dirname($rec)
531 ) . '">' . $str . '</a>';
532 }
533 }
534 }
535 return $str;
536 }
537
538 /**
539 * Returns the select-url for database elements
540 *
541 * @param string $table Table name
542 * @param integer $uid Uid of record
543 * @param boolean $copy If set, copymode will be enabled
544 * @param boolean $deselect If set, the link will deselect, otherwise select.
545 * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
546 * @return string URL linking to the current script but with the CB array set to select the element with table/uid
547 */
548 function selUrlDB($table, $uid, $copy = 0, $deselect = 0, $baseArray = array()) {
549 $CB = array('el' => array(rawurlencode($table . '|' . $uid) => $deselect ? 0 : 1));
550 if ($copy) {
551 $CB['setCopyMode'] = 1;
552 }
553 $baseArray['CB'] = $CB;
554 return t3lib_div::linkThisScript($baseArray);
555 }
556
557 /**
558 * Returns the select-url for files
559 *
560 * @param string $path Filepath
561 * @param boolean $copy If set, copymode will be enabled
562 * @param boolean $deselect If set, the link will deselect, otherwise select.
563 * @param array $baseArray The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
564 * @return string URL linking to the current script but with the CB array set to select the path
565 */
566 function selUrlFile($path, $copy = 0, $deselect = 0, $baseArray = array()) {
567 $CB = array('el' => array(rawurlencode('_FILE|' . t3lib_div::shortmd5($path)) => $deselect ? '' : $path));
568 if ($copy) {
569 $CB['setCopyMode'] = 1;
570 }
571 $baseArray['CB'] = $CB;
572 return t3lib_div::linkThisScript($baseArray);
573 }
574
575 /**
576 * pasteUrl of the element (database and file)
577 * For the meaning of $table and $uid, please read from ->makePasteCmdArray!!!
578 * The URL will point to tce_file or tce_db depending in $table
579 *
580 * @param string $table Tablename (_FILE for files)
581 * @param mixed $uid "destination": can be positive or negative indicating how the paste is done (paste into / paste after)
582 * @param boolean $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
583 * @return string
584 */
585 function pasteUrl($table, $uid, $setRedirect = 1) {
586 $rU = $this->backPath . ($table == '_FILE' ? 'tce_file.php' : 'tce_db.php') . '?' .
587 ($setRedirect ? 'redirect=' . rawurlencode(t3lib_div::linkThisScript(array('CB' => ''))) : '') .
588 '&vC=' . $GLOBALS['BE_USER']->veriCode() .
589 '&prErr=1&uPT=1' .
590 '&CB[paste]=' . rawurlencode($table . '|' . $uid) .
591 '&CB[pad]=' . $this->current .
592 t3lib_BEfunc::getUrlToken('tceAction');
593 return $rU;
594 }
595
596 /**
597 * deleteUrl for current pad
598 *
599 * @param boolean $setRedirect If set, then the redirect URL will point back to the current script, but with CB reset.
600 * @param boolean $file If set, then the URL will link to the tce_file.php script in the typo3/ dir.
601 * @return string
602 */
603 function deleteUrl($setRedirect = 1, $file = 0) {
604 $rU = $this->backPath . ($file ? 'tce_file.php' : 'tce_db.php') . '?' .
605 ($setRedirect ? 'redirect=' . rawurlencode(t3lib_div::linkThisScript(array('CB' => ''))) : '') .
606 '&vC=' . $GLOBALS['BE_USER']->veriCode() .
607 '&prErr=1&uPT=1' .
608 '&CB[delete]=1' .
609 '&CB[pad]=' . $this->current .
610 t3lib_BEfunc::getUrlToken('tceAction');
611 return $rU;
612 }
613
614 /**
615 * editUrl of all current elements
616 * ONLY database
617 * Links to alt_doc.php
618 *
619 * @return string The URL to alt_doc.php with parameters.
620 */
621 function editUrl() {
622 // All records
623 $elements = $this->elFromTable('');
624 $editCMDArray = array();
625 foreach ($elements as $tP => $value) {
626 list($table, $uid) = explode('|', $tP);
627 $editCMDArray[] = '&edit[' . $table . '][' . $uid . ']=edit';
628 }
629
630 $rU = $this->backPath . 'alt_doc.php?' . implode('', $editCMDArray);
631 return $rU;
632 }
633
634 /**
635 * Returns the remove-url (file and db)
636 * for file $table='_FILE' and $uid = shortmd5 hash of path
637 *
638 * @param string $table Tablename
639 * @param string $uid Uid integer/shortmd5 hash
640 * @return string URL
641 */
642 function removeUrl($table, $uid) {
643 return t3lib_div::linkThisScript(array('CB' => array('remove' => $table . '|' . $uid)));
644 }
645
646 /**
647 * Returns confirm JavaScript message
648 *
649 * @param string $table Table name
650 * @param mixed $rec For records its an array, for files its a string (path)
651 * @param string $type Type-code
652 * @param array $clElements Array of selected elements
653 * @return string JavaScript "confirm" message
654 */
655 function confirmMsg($table, $rec, $type, $clElements) {
656 if ($GLOBALS['BE_USER']->jsConfirmation(2)) {
657 $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.' . ($this->currentMode() == 'copy' ? 'copy' : 'move') . ($this->current == 'normal' ? '' : 'cb') . '_' . $type;
658 $msg = $GLOBALS['LANG']->sL($labelKey);
659
660 if ($table == '_FILE') {
661 $thisRecTitle = basename($rec);
662 if ($this->current == 'normal') {
663 $selItem = reset($clElements);
664 $selRecTitle = basename($selItem);
665 } else {
666 $selRecTitle = count($clElements);
667 }
668 } else {
669 $thisRecTitle = (
670 $table == 'pages' && !is_array($rec) ?
671 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] :
672 t3lib_BEfunc::getRecordTitle($table, $rec)
673 );
674
675 if ($this->current == 'normal') {
676 $selItem = $this->getSelectedRecord();
677 $selRecTitle = $selItem['_RECORD_TITLE'];
678 } else {
679 $selRecTitle = count($clElements);
680 }
681 }
682
683 // Message
684 $conf = 'confirm(' . $GLOBALS['LANG']->JScharCode(sprintf(
685 $msg,
686 t3lib_div::fixed_lgd_cs($selRecTitle, 30),
687 t3lib_div::fixed_lgd_cs($thisRecTitle, 30)
688 )) . ')';
689 } else {
690 $conf = '';
691 }
692 return $conf;
693 }
694
695 /**
696 * Clipboard label - getting from "EXT:lang/locallang_core.php:"
697 *
698 * @param string $key Label Key
699 * @param string $Akey Alternative key to "labels"
700 * @return string
701 */
702 function clLabel($key, $Akey = 'labels') {
703 return htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:' . $Akey . '.' . $key));
704 }
705
706 /**
707 * Creates GET parameters for linking to the export module.
708 *
709 * @return string GET parameters for current clipboard content to be exported.
710 */
711 function exportClipElementParameters() {
712
713 // Init
714 $pad = $this->current;
715 $params = array();
716 $params[] = 'tx_impexp[action]=export';
717
718 // Traverse items:
719 if (is_array($this->clipData[$pad]['el'])) {
720 foreach ($this->clipData[$pad]['el'] as $k => $v) {
721 if ($v) {
722 list($table, $uid) = explode('|', $k);
723
724 // Rendering files/directories on the clipboard
725 if ($table == '_FILE') {
726 if (file_exists($v) && t3lib_div::isAllowedAbsPath($v)) {
727 $params[] = 'tx_impexp[' . (is_dir($v) ? 'dir' : 'file') . '][]=' . rawurlencode($v);
728 }
729 } else { // Rendering records:
730 $rec = t3lib_BEfunc::getRecord($table, $uid);
731 if (is_array($rec)) {
732 $params[] = 'tx_impexp[record][]=' . rawurlencode($table . ':' . $uid);
733 }
734 }
735 }
736 }
737 }
738
739 return '?' . implode('&', $params);
740 }
741
742 /*****************************************
743 *
744 * Helper functions
745 *
746 ****************************************/
747
748 /**
749 * Removes element on clipboard
750 *
751 * @param string $el Key of element in ->clipData array
752 * @return void
753 */
754 function removeElement($el) {
755 unset($this->clipData[$this->current]['el'][$el]);
756 $this->changed = 1;
757 }
758
759 /**
760 * Saves the clipboard, no questions asked.
761 * Use ->endClipboard normally (as it checks if changes has been done so saving is necessary)
762 *
763 * @access private
764 * @return void
765 */
766 function saveClipboard() {
767 $GLOBALS['BE_USER']->pushModuleData('clipboard', $this->clipData);
768 }
769
770 /**
771 * Returns the current mode, 'copy' or 'cut'
772 *
773 * @return string "copy" or "cut"
774 */
775 function currentMode() {
776 return $this->clipData[$this->current]['mode'] == 'copy' ? 'copy' : 'cut';
777 }
778
779 /**
780 * This traverses the elements on the current clipboard pane
781 * and unsets elements which does not exist anymore or are disabled.
782 *
783 * @return void
784 */
785 function cleanCurrent() {
786 if (is_array($this->clipData[$this->current]['el'])) {
787 foreach ($this->clipData[$this->current]['el'] as $k => $v) {
788 list($table, $uid) = explode('|', $k);
789 if ($table != '_FILE') {
790 if (!$v || !is_array(t3lib_BEfunc::getRecord($table, $uid, 'uid'))) {
791 unset($this->clipData[$this->current]['el'][$k]);
792 $this->changed = 1;
793 }
794 } else {
795 if (!$v || t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($v) === NULL) {
796 unset($this->clipData[$this->current]['el'][$k]);
797 $this->changed = 1;
798 }
799 }
800 }
801 }
802 }
803
804 /**
805 * Counts the number of elements from the table $matchTable. If $matchTable is blank, all tables (except '_FILE' of course) is counted.
806 *
807 * @param string $matchTable Table to match/count for.
808 * @param string $pad Can optionally be used to set another pad than the current.
809 * @return array Array with keys from the CB.
810 */
811 function elFromTable($matchTable = '', $pad = '') {
812 $pad = $pad ? $pad : $this->current;
813 $list = array();
814 if (is_array($this->clipData[$pad]['el'])) {
815 foreach ($this->clipData[$pad]['el'] as $k => $v) {
816 if ($v) {
817 list($table, $uid) = explode('|', $k);
818 if ($table != '_FILE') {
819 if ((!$matchTable || (string) $table == (string) $matchTable) && $GLOBALS['TCA'][$table]) {
820 $list[$k] = ($pad == 'normal' ? $v : $uid);
821 }
822 } else {
823 if ((string) $table == (string) $matchTable) {
824 $list[$k] = $v;
825 }
826 }
827 }
828 }
829 }
830 return $list;
831 }
832
833 /**
834 * Verifies if the item $table/$uid is on the current pad.
835 * 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...
836 *
837 * @param string $table Table name, (_FILE for files...)
838 * @param integer $uid Element uid (path for files)
839 * @return string
840 */
841 function isSelected($table, $uid) {
842 $k = $table . '|' . $uid;
843 return $this->clipData[$this->current]['el'][$k] ? ($this->current == 'normal' ? $this->currentMode() : 1) : '';
844 }
845
846 /**
847 * Returns item record $table,$uid if selected on current clipboard
848 * If table and uid is blank, the first element is returned.
849 * Makes sense only for DB records - not files!
850 *
851 * @param string $table Table name
852 * @param integer $uid Element uid
853 * @return array Element record with extra field _RECORD_TITLE set to the title of the record
854 */
855 function getSelectedRecord($table = '', $uid = '') {
856 if (!$table && !$uid) {
857 $elArr = $this->elFromTable('');
858 reset($elArr);
859 list($table, $uid) = explode('|', key($elArr));
860 }
861 if ($this->isSelected($table, $uid)) {
862 $selRec = t3lib_BEfunc::getRecordWSOL($table, $uid);
863 $selRec['_RECORD_TITLE'] = t3lib_BEfunc::getRecordTitle($table, $selRec);
864 return $selRec;
865 }
866 }
867
868 /**
869 * Reports if the current pad has elements (does not check file/DB type OR if file/DBrecord exists or not. Only counting array)
870 *
871 * @return boolean TRUE if elements exist.
872 */
873 function isElements() {
874 return is_array($this->clipData[$this->current]['el']) && count($this->clipData[$this->current]['el']);
875 }
876
877 /*****************************************
878 *
879 * FOR USE IN tce_db.php:
880 *
881 ****************************************/
882
883 /**
884 * Applies the proper paste configuration in the $cmd array send to tce_db.php.
885 * $ref is the target, see description below.
886 * The current pad is pasted
887 *
888 * $ref: [tablename]:[paste-uid].
889 * Tablename is the name of the table from which elements *on the current clipboard* is pasted with the 'pid' paste-uid.
890 * No tablename means that all items on the clipboard (non-files) are pasted. This requires paste-uid to be positive though.
891 * so 'tt_content:-3' means 'paste tt_content elements on the clipboard to AFTER tt_content:3 record
892 * 'tt_content:30' means 'paste tt_content elements on the clipboard into page with id 30
893 * ':30' means 'paste ALL database elements on the clipboard into page with id 30
894 * ':-30' not valid.
895 *
896 * @param string $ref [tablename]:[paste-uid], see description
897 * @param array $CMD Command-array
898 * @return array Modified Command-array
899 */
900 function makePasteCmdArray($ref, $CMD) {
901 list($pTable, $pUid) = explode('|', $ref);
902 $pUid = intval($pUid);
903
904 // pUid must be set and if pTable is not set (that means paste ALL elements)
905 // the uid MUST be positive/zero (pointing to page id)
906 if ($pTable || $pUid >= 0) {
907 $elements = $this->elFromTable($pTable);
908
909 // So the order is preserved.
910 $elements = array_reverse($elements);
911 $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
912
913 // Traverse elements and make CMD array
914 foreach ($elements as $tP => $value) {
915 list($table, $uid) = explode('|', $tP);
916 if (!is_array($CMD[$table])) {
917 $CMD[$table] = array();
918 }
919 $CMD[$table][$uid][$mode] = $pUid;
920 if ($mode == 'move') {
921 $this->removeElement($tP);
922 }
923 }
924 $this->endClipboard();
925 }
926 return $CMD;
927 }
928
929 /**
930 * Delete record entries in CMD array
931 *
932 * @param array $CMD Command-array
933 * @return array Modified Command-array
934 */
935 function makeDeleteCmdArray($CMD) {
936 // all records
937 $elements = $this->elFromTable('');
938 foreach ($elements as $tP => $value) {
939 list($table, $uid) = explode('|', $tP);
940 if (!is_array($CMD[$table])) {
941 $CMD[$table] = array();
942 }
943 $CMD[$table][$uid]['delete'] = 1;
944 $this->removeElement($tP);
945 }
946 $this->endClipboard();
947 return $CMD;
948 }
949
950 /*****************************************
951 *
952 * FOR USE IN tce_file.php:
953 *
954 ****************************************/
955
956 /**
957 * Applies the proper paste configuration in the $file array send to tce_file.php.
958 * The current pad is pasted
959 *
960 * @param string $ref Reference to element (splitted by "|")
961 * @param array $FILE Command-array
962 * @return array Modified Command-array
963 */
964 function makePasteCmdArray_file($ref, $FILE) {
965 list($pTable, $pUid) = explode('|', $ref);
966 $elements = $this->elFromTable('_FILE');
967 $mode = $this->currentMode() == 'copy' ? 'copy' : 'move';
968
969 // Traverse elements and make CMD array
970 foreach ($elements as $tP => $path) {
971 $FILE[$mode][] = array('data' => $path, 'target' => $pUid, 'altName' => 1);
972 if ($mode == 'move') {
973 $this->removeElement($tP);
974 }
975 }
976 $this->endClipboard();
977
978 return $FILE;
979 }
980
981 /**
982 * Delete files in CMD array
983 *
984 * @param array $FILE Command-array
985 * @return array Modified Command-array
986 */
987 function makeDeleteCmdArray_file($FILE) {
988 $elements = $this->elFromTable('_FILE');
989 // Traverse elements and make CMD array
990 foreach ($elements as $tP => $path) {
991 $FILE['delete'][] = array('data' => $path);
992 $this->removeElement($tP);
993 }
994 $this->endClipboard();
995
996 return $FILE;
997 }
998 }
999
1000 ?>