Documentation TYPO3 par Ameos

class.t3lib_clipboard.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00097 class t3lib_clipboard {
00098         var $numberTabs = 3;
00099 
00119         var $clipData=array();
00120 
00121         var $changed=0;
00122         var $current='';
00123         var $backPath='';
00124         var $lockToNormal=0;
00125         var $fileMode=0;                // If set, clipboard is displaying files.
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139         /*****************************************
00140          *
00141          * Initialize
00142          *
00143          ****************************************/
00144 
00150         function initializeClipboard()  {
00151                 global $BE_USER;
00152 
00153                         // Get data
00154                 $clipData = $BE_USER->getModuleData('clipboard',$BE_USER->getTSConfigVal('options.saveClipboard')?'':'ses');
00155 
00156                         // NumberTabs
00157                 $clNP = $BE_USER->getTSConfigVal('options.clipboardNumberPads');
00158                 if (t3lib_div::testInt($clNP) && $clNP>=0)      {
00159                         $this->numberTabs = t3lib_div::intInRange($clNP,0,20);
00160                 }
00161 
00162                         // Resets/reinstates the clipboard pads
00163                 $this->clipData['normal'] = is_array($clipData['normal']) ? $clipData['normal'] : array();
00164                 for ($a=1;$a<=$this->numberTabs;$a++)   {
00165                         $this->clipData['tab_'.$a] = is_array($clipData['tab_'.$a]) ? $clipData['tab_'.$a] : array();
00166                 }
00167 
00168                         // Setting the current pad pointer ($this->current) and _setThumb (which determines whether or not do show file thumbnails)
00169                 $this->clipData['current'] = $this->current = isset($this->clipData[$clipData['current']]) ? $clipData['current'] : 'normal';
00170                 $this->clipData['_setThumb'] = $clipData['_setThumb'];
00171         }
00172 
00179         function lockToNormal() {
00180                 $this->lockToNormal = 1;
00181                 $this->current = 'normal';
00182         }
00183 
00196         function setCmd($cmd)   {
00197                 if (is_array($cmd['el']))       {
00198                         reset($cmd['el']);
00199                         while(list($k,$v)=each($cmd['el']))     {
00200                                 if ($this->current=='normal')   {
00201                                         unset($this->clipData['normal']);
00202                                 }
00203                                 if ($v) {
00204                                         $this->clipData[$this->current]['el'][$k]=$v;
00205                                 } else {
00206                                         $this->removeElement($k);
00207                                 }
00208                                 $this->changed=1;
00209                         }
00210                 }
00211                         // Change clipboard pad (if not locked to normal)
00212                 if ($cmd['setP'])       {
00213                         $this->setCurrentPad($cmd['setP']);
00214                 }
00215                         // Remove element       (value = item ident: DB; '[tablename]|[uid]'    FILE: '_FILE|[shortmd5 hash of path]'
00216                 if ($cmd['remove'])     {
00217                         $this->removeElement($cmd['remove']);
00218                         $this->changed=1;
00219                 }
00220                         // Remove all on current pad (value = pad-ident)
00221                 if ($cmd['removeAll'])  {
00222                         $this->clipData[$cmd['removeAll']]=array();
00223                         $this->changed=1;
00224                 }
00225                         // Set copy mode of the tab
00226                 if (isset($cmd['setCopyMode'])) {
00227                         $this->clipData[$this->current]['mode']=$this->isElements()?($cmd['setCopyMode']?'copy':''):'';
00228                         $this->changed=1;
00229                 }
00230                         // Toggle thumbnail display for files on/off
00231                 if (isset($cmd['setThumb']))    {
00232                         $this->clipData['_setThumb']=$cmd['setThumb'];
00233                         $this->changed=1;
00234                 }
00235         }
00236 
00243         function setCurrentPad($padIdent)       {
00244                         // Change clipboard pad (if not locked to normal)
00245                 if (!$this->lockToNormal && $this->current!=$padIdent)  {
00246                         if (isset($this->clipData[$padIdent]))  $this->clipData['current'] = $this->current = $padIdent;
00247                         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'
00248                         $this->changed=1;
00249                 }
00250         }
00251 
00258         function endClipboard() {
00259                 if ($this->changed)     $this->saveClipboard();
00260                 $this->changed=0;
00261         }
00262 
00271         function cleanUpCBC($CBarr,$table,$removeDeselected=0)  {
00272                 if (is_array($CBarr))   {
00273                         reset($CBarr);
00274                         while(list($k,$v)=each($CBarr)) {
00275                                 $p=explode('|',$k);
00276                                 if ((string)$p[0]!=(string)$table || ($removeDeselected && !$v))        {
00277                                         unset($CBarr[$k]);
00278                                 }
00279                         }
00280                 }
00281                 return $CBarr;
00282         }
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295         /*****************************************
00296          *
00297          * Clipboard HTML renderings
00298          *
00299          ****************************************/
00300 
00306         function printClipboard()       {
00307                 global $TBE_TEMPLATE,$LANG;
00308 
00309                 $out=array();
00310                 $elCount = count($this->elFromTable($this->fileMode?'_FILE':''));
00311 
00312                         // Upper header
00313                 $out[]='
00314                         <tr class="bgColor2">
00315                                 <td colspan="3" nowrap="nowrap" align="center"><span class="uppercase"><strong>'.$this->clLabel('clipboard','buttons').'</strong></span></td>
00316                         </tr>';
00317 
00318                         // Button/menu header:
00319                 $thumb_url = t3lib_div::linkThisScript(array('CB'=>array('setThumb'=>$this->clipData['_setThumb']?0:1)));
00320                 $copymode_url = t3lib_div::linkThisScript(array('CB'=>array('setCopyMode'=>($this->currentMode()=='copy'?'':'copy'))));
00321                 $rmall_url = t3lib_div::linkThisScript(array('CB'=>array('removeAll'=>$this->current)));
00322 
00323                         // Selector menu + clear button
00324                 $opt=array();
00325                 $opt[]='<option value="" selected="selected">'.$this->clLabel('menu','rm').'</option>';
00326                                 // Import / Export link:
00327                 if ($elCount && t3lib_extMgm::isLoaded('impexp'))       {
00328                         $opt[] = '<option value="'.htmlspecialchars("document.location='".$this->backPath.t3lib_extMgm::extRelPath('impexp').'app/index.php'.$this->exportClipElementParameters().'\';').'">'.$this->clLabel('export','rm').'</option>';
00329                 }
00330                                 // Edit:
00331                 if (!$this->fileMode && $elCount)       {
00332                         $opt[]='<option value="'.htmlspecialchars("document.location='".$this->editUrl()."&returnUrl='+top.rawurlencode(document.location);").'">'.$this->clLabel('edit','rm').'</option>';
00333                 }
00334                                 // Delete:
00335                 if ($elCount)   {
00336                         $opt[]='<option value="'.htmlspecialchars("
00337                         if(confirm(".$GLOBALS['LANG']->JScharCode(sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.deleteClip'),$elCount)).")){
00338                                 document.location='".$this->deleteUrl(0,$this->fileMode?1:0)."&redirect='+top.rawurlencode(document.location);
00339                         }
00340                         ").'">'.$this->clLabel('delete','rm').'</option>';
00341                 }
00342                 $selector_menu = '<select name="_clipMenu" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$opt).'</select>';
00343 
00344                 $out[]='
00345                         <tr class="typo3-clipboard-head">
00346                                 <td nowrap="nowrap">'.
00347                                 '<a href="'.htmlspecialchars($thumb_url).'#clip_head">'.
00348                                         '<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="" />'.
00349                                         '</a>'.
00350                                 '<a href="'.htmlspecialchars($copymode_url).'#clip_head">'.
00351                                         '<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="" />'.
00352                                         '</a>'.
00353                                 '</td>
00354                                 <td width="95%">'.$selector_menu.'</td>
00355                                 <td>'.
00356                                 '<a href="'.htmlspecialchars($rmall_url).'#clip_head">'.
00357                                         '<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="" />'.
00358                                         '</a></td>
00359                         </tr>';
00360 
00361 
00362                         // Print header and content for the NORMAL tab:
00363                 $out[]='
00364                         <tr class="bgColor5">
00365                                 <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'normal')))).'#clip_head">'.
00366                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($this->current=='normal'?'minus':'plus').'bullet.gif','width="18" height="16"').' border="0" align="top" alt="" />'.
00367                                         $this->padTitleWrap('Normal','normal').
00368                                         '</a></td>
00369                         </tr>';
00370                 if ($this->current=='normal')   $out=array_merge($out,$this->printContentFromTab('normal'));
00371 
00372                         // Print header and content for the NUMERIC tabs:
00373                 for ($a=1;$a<=$this->numberTabs;$a++)   {
00374                         $out[]='
00375                                 <tr class="bgColor5">
00376                                         <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'tab_'.$a)))).'#clip_head">'.
00377                                                 '<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="" />'.
00378                                                 $this->padTitleWrap($this->clLabel('cliptabs').$a,'tab_'.$a).
00379                                                 '</a></td>
00380                                 </tr>';
00381                         if ($this->current=='tab_'.$a)  $out=array_merge($out,$this->printContentFromTab('tab_'.$a));
00382                 }
00383 
00384                         // Wrap accumulated rows in a table:
00385                 $output = '<a name="clip_head"></a>
00386 
00387                         <!--
00388                                 TYPO3 Clipboard:
00389                         -->
00390                         <table cellpadding="0" cellspacing="1" border="0" width="290" id="typo3-clipboard">
00391                                 '.implode('',$out).'
00392                         </table>';
00393 
00394                         // Wrap in form tag:
00395                 $output = '<form action="">'.$output.'</form>';
00396 
00397                         // Return the accumulated content:
00398                 return $output;
00399         }
00400 
00408         function printContentFromTab($pad)      {
00409                 global $TBE_TEMPLATE;
00410 
00411                 $lines=array();
00412                 if (is_array($this->clipData[$pad]['el']))      {
00413                         reset($this->clipData[$pad]['el']);
00414                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00415                                 if ($v) {
00416                                         list($table,$uid) = explode('|',$k);
00417                                         $bgColClass = ($table=='_FILE'&&$this->fileMode)||($table!='_FILE'&&!$this->fileMode) ? 'bgColor4-20' : 'bgColor4';
00418 
00419                                         if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
00420                                                 if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
00421                                                         $fI = pathinfo($v);
00422                                                         $icon = is_dir($v) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
00423                                                         $size = ' ('.t3lib_div::formatSize(filesize($v)).'bytes)';
00424                                                         $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="" />';
00425                                                         $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"') : '') :'';
00426 
00427                                                         $lines[]='
00428                                                                 <tr>
00429                                                                         <td class="'.$bgColClass.'">'.$icon.'</td>
00430                                                                         <td class="'.$bgColClass.'" nowrap="nowrap" width="95%">&nbsp;'.$this->linkItemText(htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($v),$GLOBALS['BE_USER']->uc['titleLen'])),$v).
00431                                                                                 ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;'.($thumb?'<br />'.$thumb:'').'</td>
00432                                                                         <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00433                                                                         '<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>'.
00434                                                                         '<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>'.
00435                                                                         '</td>
00436                                                                 </tr>';
00437                                                 } else {
00438                                                                 // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
00439                                                         unset($this->clipData[$pad]['el'][$k]);
00440                                                         $this->changed=1;
00441                                                 }
00442                                         } else {        // Rendering records:
00443                                                 $rec=t3lib_BEfunc::getRecord($table,$uid);
00444                                                 if (is_array($rec))     {
00445                                                         $lines[]='
00446                                                                 <tr>
00447                                                                         <td class="'.$bgColClass.'">'.$this->linkItemText(t3lib_iconWorks::getIconImage($table,$rec,$this->backPath,'hspace="20" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($rec,$table)).'"'),$rec,$table).'</td>
00448                                                                         <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).
00449                                                                                 ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;</td>
00450                                                                         <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00451                                                                         '<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>'.
00452                                                                         '<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>'.
00453                                                                         '</td>
00454                                                                 </tr>';
00455                                                 } else {
00456                                                         unset($this->clipData[$pad]['el'][$k]);
00457                                                         $this->changed=1;
00458                                                 }
00459                                         }
00460                                 }
00461                         }
00462                 }
00463                 if (!count($lines))     {
00464                         $lines[]='
00465                                                                 <tr>
00466                                                                         <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td>
00467                                                                         <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%">&nbsp;<em>('.$this->clLabel('clipNoEl').')</em>&nbsp;</td>
00468                                                                 </tr>';
00469                 }
00470 
00471                 $this->endClipboard();
00472                 return $lines;
00473         }
00474 
00482         function padTitleWrap($str,$pad)        {
00483                 $el = count($this->elFromTable($this->fileMode?'_FILE':'',$pad));
00484                 if ($el)        {
00485                         return '<strong>'.$str.'</strong> ('.($pad=='normal'?($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')):htmlspecialchars($el)).')';
00486                 } else {
00487                         return $GLOBALS['TBE_TEMPLATE']->dfw($str);
00488                 }
00489         }
00490 
00499         function linkItemText($str,$rec,$table='')      {
00500                 if (is_array($rec) && $table)   {
00501                         if ($this->fileMode)    {
00502                                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00503                         } else {
00504                                 $str='<a href="'.htmlspecialchars($this->backPath.'db_list.php?id='.$rec['pid']).'">'.$str.'</a>';
00505                         }
00506                 } elseif (@file_exists($rec))   {
00507                         if (!$this->fileMode)   {
00508                                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00509                         } else {
00510                                 $str='<a href="'.htmlspecialchars($this->backPath.'file_list.php?id='.dirname($rec)).'">'.$str.'</a>';
00511                         }
00512                 }
00513                 return $str;
00514         }
00515 
00526         function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())   {
00527                 $CB = array('el'=>array(rawurlencode($table.'|'.$uid)=>$deselect?0:1));
00528                 if ($copy)      $CB['setCopyMode'] = 1;
00529                 $baseArray['CB'] = $CB;
00530                 return t3lib_div::linkThisScript($baseArray);
00531         }
00532 
00542         function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())       {
00543                 $CB=array('el'=>array(rawurlencode('_FILE|'.t3lib_div::shortmd5($path))=>$deselect?'':$path));
00544                 if ($copy)      $CB['setCopyMode']=1;
00545                 $baseArray['CB']=$CB;
00546                 return t3lib_div::linkThisScript($baseArray);
00547         }
00548 
00559         function pasteUrl($table,$uid,$setRedirect=1)   {
00560                 $rU = $this->backPath.($table=='_FILE'?'tce_file.php':'tce_db.php').'?'.
00561                         ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00562                         '&vC='.$GLOBALS['BE_USER']->veriCode().
00563                         '&prErr=1&uPT=1'.
00564                         '&CB[paste]='.rawurlencode($table.'|'.$uid).
00565                         '&CB[pad]='.$this->current;
00566                 return $rU;
00567         }
00568 
00576         function deleteUrl($setRedirect=1,$file=0)      {
00577                 $rU = $this->backPath.($file?'tce_file.php':'tce_db.php').'?'.
00578                         ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00579                         '&vC='.$GLOBALS['BE_USER']->veriCode().
00580                         '&prErr=1&uPT=1'.
00581                         '&CB[delete]=1'.
00582                         '&CB[pad]='.$this->current;
00583                 return $rU;
00584         }
00585 
00593         function editUrl()      {
00594                 $elements = $this->elFromTable('');     // all records
00595                 reset($elements);
00596                 $editCMDArray=array();
00597                 while(list($tP)=each($elements))        {
00598                         list($table,$uid) = explode('|',$tP);
00599                         $editCMDArray[] = '&edit['.$table.']['.$uid.']=edit';
00600                 }
00601 
00602                 $rU = $this->backPath.'alt_doc.php?'.implode('',$editCMDArray);
00603                 return $rU;
00604         }
00605 
00614         function removeUrl($table,$uid) {
00615                 return t3lib_div::linkThisScript(array('CB'=>array('remove'=>$table.'|'.$uid)));
00616         }
00617 
00627         function confirmMsg($table,$rec,$type,$clElements)      {
00628                 $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.'.($this->currentMode()=='copy'?'copy':'move').($this->current=='normal'?'':'cb').'_'.$type;
00629                 $msg = $GLOBALS['LANG']->sL($labelKey);
00630 
00631                 if ($table=='_FILE')    {
00632                         $thisRecTitle = basename($rec);
00633                         if ($this->current=='normal')   {
00634                                 reset($clElements);
00635                                 $selItem = current($clElements);
00636                                 $selRecTitle = basename($selItem);
00637                         } else {
00638                                 $selRecTitle=count($clElements);
00639                         }
00640                 } else {
00641                         $thisRecTitle = (
00642                                 $table=='pages' && !is_array($rec) ?
00643                                 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] :
00644                                 t3lib_BEfunc::getRecordTitle($table,$rec)
00645                         );
00646 
00647                         if ($this->current=='normal')   {
00648                                 $selItem = $this->getSelectedRecord();
00649                                 $selRecTitle=$selItem['_RECORD_TITLE'];
00650                         } else {
00651                                 $selRecTitle=count($clElements);
00652                         }
00653                 }
00654 
00655                         // Message:
00656                 $conf='confirm('.$GLOBALS['LANG']->JScharCode(sprintf(
00657                         $msg,
00658                         t3lib_div::fixed_lgd_cs($selRecTitle,30),
00659                         t3lib_div::fixed_lgd_cs($thisRecTitle,30)
00660                         )).')';
00661                 return $conf;
00662         }
00663 
00671         function clLabel($key,$Akey='labels')   {
00672                 return htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:'.$Akey.'.'.$key));
00673         }
00674 
00680         function exportClipElementParameters()  {
00681 
00682                         // Init:
00683                 $pad = $this->current;
00684                 $params = array();
00685                 $params[] = 'tx_impexp[action]=export';
00686 
00687                         // Traverse items:
00688                 if (is_array($this->clipData[$pad]['el']))      {
00689                         reset($this->clipData[$pad]['el']);
00690                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00691                                 if ($v) {
00692                                         list($table,$uid) = explode('|',$k);
00693 
00694                                         if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
00695                                                 if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
00696                                                         $params[] = 'tx_impexp['.(is_dir($v) ? 'dir' : 'file').'][]='.rawurlencode($v);
00697                                                 }
00698                                         } else {        // Rendering records:
00699                                                 $rec = t3lib_BEfunc::getRecord($table,$uid);
00700                                                 if (is_array($rec))     {
00701                                                         $params[] = 'tx_impexp[record][]='.rawurlencode($table.':'.$uid);
00702                                                 }
00703                                         }
00704                                 }
00705                         }
00706                 }
00707 
00708                 return '?'.implode('&', $params);
00709         }
00710 
00711 
00712 
00713 
00714 
00715 
00716 
00717 
00718         /*****************************************
00719          *
00720          * Helper functions
00721          *
00722          ****************************************/
00723 
00730         function removeElement($el)     {
00731                 unset($this->clipData[$this->current]['el'][$el]);
00732                 $this->changed=1;
00733         }
00734 
00742         function saveClipboard()        {
00743                 global $BE_USER;
00744                 $BE_USER->pushModuleData('clipboard',$this->clipData);
00745         }
00746 
00752         function currentMode()  {
00753                 return $this->clipData[$this->current]['mode']=='copy' ? 'copy' : 'cut';
00754         }
00755 
00762         function cleanCurrent() {
00763                 if (is_array($this->clipData[$this->current]['el']))    {
00764                         reset($this->clipData[$this->current]['el']);
00765                         while(list($k,$v)=each($this->clipData[$this->current]['el']))  {
00766                                 list($table,$uid) = explode('|',$k);
00767                                 if ($table!='_FILE')    {
00768                                         if (!$v || !is_array(t3lib_BEfunc::getRecord($table,$uid,'uid')))       {
00769                                                 unset($this->clipData[$this->current]['el'][$k]);
00770                                                 $this->changed=1;
00771                                         }
00772                                 } else {
00773                                         if (!$v || !@file_exists($v))   {
00774                                                 unset($this->clipData[$this->current]['el'][$k]);
00775                                                 $this->changed=1;
00776                                         }
00777                                 }
00778                         }
00779                 }
00780         }
00781 
00789         function elFromTable($matchTable='',$pad='')    {
00790                 $pad = $pad ? $pad : $this->current;
00791                 $list=array();
00792                 if (is_array($this->clipData[$pad]['el']))      {
00793                         reset($this->clipData[$pad]['el']);
00794                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00795                                 if ($v) {
00796                                         list($table,$uid) = explode('|',$k);
00797                                         if ($table!='_FILE')    {
00798                                                 if ((!$matchTable || (string)$table==(string)$matchTable) && $GLOBALS['TCA'][$table])   {
00799                                                         $list[$k]= ($pad=='normal'?$v:$uid);
00800                                                 }
00801                                         } else {
00802                                                 if ((string)$table==(string)$matchTable)        {
00803                                                         $list[$k]=$v;
00804                                                 }
00805                                         }
00806                                 }
00807                         }
00808                 }
00809                 return $list;
00810         }
00811 
00820         function isSelected($table,$uid)        {
00821                 $k=$table.'|'.$uid;
00822                 return $this->clipData[$this->current]['el'][$k] ? ($this->current=='normal'?$this->currentMode():1) : '';
00823         }
00824 
00834         function getSelectedRecord($table='',$uid='')   {
00835                 if (!$table && !$uid)   {
00836                         $elArr = $this->elFromTable('');
00837                         reset($elArr);
00838                         list($table,$uid) = explode('|',key($elArr));
00839                 }
00840                 if ($this->isSelected($table,$uid))     {
00841                         $selRec = t3lib_BEfunc::getRecord($table,$uid);
00842                         $selRec['_RECORD_TITLE'] = t3lib_BEfunc::getRecordTitle($table,$selRec);
00843                         return $selRec;
00844                 }
00845         }
00846 
00852         function isElements()   {
00853                 return is_array($this->clipData[$this->current]['el']) && count($this->clipData[$this->current]['el']);
00854         }
00855 
00856 
00857 
00858 
00859 
00860 
00861 
00862 
00863 
00864 
00865 
00866 
00867 
00868 
00869 
00870         /*****************************************
00871          *
00872          * FOR USE IN tce_db.php:
00873          *
00874          ****************************************/
00875 
00893         function makePasteCmdArray($ref,$CMD)   {
00894                 list($pTable,$pUid) = explode('|',$ref);
00895                 $pUid = intval($pUid);
00896 
00897                 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)
00898                         $elements = $this->elFromTable($pTable);
00899 
00900                         $elements = array_reverse($elements);   // So the order is preserved.
00901                         $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
00902 
00903                                 // Traverse elements and make CMD array
00904                         reset($elements);
00905                         while(list($tP)=each($elements))        {
00906                                 list($table,$uid) = explode('|',$tP);
00907                                 if (!is_array($CMD[$table]))    $CMD[$table]=array();
00908                                 $CMD[$table][$uid][$mode]=$pUid;
00909                                 if ($mode=='move')      $this->removeElement($tP);
00910                         }
00911                         $this->endClipboard();
00912                 }
00913                 return $CMD;
00914         }
00915 
00922         function makeDeleteCmdArray($CMD)       {
00923                 $elements = $this->elFromTable('');     // all records
00924                 reset($elements);
00925                 while(list($tP)=each($elements))        {
00926                         list($table,$uid) = explode('|',$tP);
00927                         if (!is_array($CMD[$table]))    $CMD[$table]=array();
00928                         $CMD[$table][$uid]['delete']=1;
00929                         $this->removeElement($tP);
00930                 }
00931                 $this->endClipboard();
00932                 return $CMD;
00933         }
00934 
00935 
00936 
00937 
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 
00946 
00947 
00948 
00949 
00950 
00951         /*****************************************
00952          *
00953          * FOR USE IN tce_file.php:
00954          *
00955          ****************************************/
00956 
00965         function makePasteCmdArray_file($ref,$FILE)     {
00966                 list($pTable,$pUid) = explode('|',$ref);
00967                 $elements = $this->elFromTable('_FILE');
00968                 $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
00969 
00970                         // Traverse elements and make CMD array
00971                 reset($elements);
00972                 while(list($tP,$path)=each($elements))  {
00973                         $FILE[$mode][]=array('data'=>$path,'target'=>$pUid);
00974                         if ($mode=='move')      $this->removeElement($tP);
00975                 }
00976                 $this->endClipboard();
00977 
00978                 return $FILE;
00979         }
00980 
00987         function makeDeleteCmdArray_file($FILE) {
00988                 $elements = $this->elFromTable('_FILE');
00989                         // Traverse elements and make CMD array
00990                 reset($elements);
00991                 while(list($tP,$path)=each($elements))  {
00992                         $FILE['delete'][]=array('data'=>$path);
00993                         $this->removeElement($tP);
00994                 }
00995                 $this->endClipboard();
00996 
00997                 return $FILE;
00998         }
00999 }
01000 
01001 
01002 
01003 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']) {
01004         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']);
01005 }
01006 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6