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