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