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