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