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