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