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