Documentation TYPO3 par Ameos

class.t3lib_clipboard.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2007 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("window.location.href='".$this->backPath.'mod.php?M=xMOD_tximpexp'.$this->exportClipElementParameters().'\';').'">'.$this->clLabel('export','rm').'</option>';
00329                 }
00330                                 // Edit:
00331                 if (!$this->fileMode && $elCount)       {
00332                         $opt[]='<option value="'.htmlspecialchars("window.location.href='".$this->editUrl()."&returnUrl='+top.rawurlencode(window.location.href);").'">'.$this->clLabel('edit','rm').'</option>';
00333                 }
00334                                 // Delete:
00335                 if ($elCount)   {
00336                         if($GLOBALS['BE_USER']->jsConfirmation(4))      {
00337                                 $js = "
00338                         if(confirm(".$GLOBALS['LANG']->JScharCode(sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.deleteClip'),$elCount)).")){
00339                                 window.location.href='".$this->deleteUrl(0,$this->fileMode?1:0)."&redirect='+top.rawurlencode(window.location.href);
00340                         }
00341                                         ";
00342                         } else {
00343                                 $js = " window.location.href='".$this->deleteUrl(0,$this->fileMode?1:0)."&redirect='+top.rawurlencode(window.location.href); ";
00344                         }
00345                         $opt[]='<option value="'.htmlspecialchars($js).'">'.$this->clLabel('delete','rm').'</option>';
00346                 }
00347                 $selector_menu = '<select name="_clipMenu" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$opt).'</select>';
00348 
00349                 $out[]='
00350                         <tr class="typo3-clipboard-head">
00351                                 <td nowrap="nowrap">'.
00352                                 '<a href="'.htmlspecialchars($thumb_url).'#clip_head">'.
00353                                         '<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="" />'.
00354                                         '</a>'.
00355                                 '<a href="'.htmlspecialchars($copymode_url).'#clip_head">'.
00356                                         '<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="" />'.
00357                                         '</a>'.
00358                                 '</td>
00359                                 <td width="95%">'.$selector_menu.'</td>
00360                                 <td>'.
00361                                 '<a href="'.htmlspecialchars($rmall_url).'#clip_head">'.
00362                                         '<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="" />'.
00363                                         '</a></td>
00364                         </tr>';
00365 
00366 
00367                         // Print header and content for the NORMAL tab:
00368                 $out[]='
00369                         <tr class="bgColor5">
00370                                 <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'normal')))).'#clip_head">'.
00371                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.($this->current=='normal'?'minus':'plus').'bullet.gif','width="18" height="16"').' border="0" align="top" alt="" />'.
00372                                         $this->padTitleWrap('Normal','normal').
00373                                         '</a></td>
00374                         </tr>';
00375                 if ($this->current=='normal')   $out=array_merge($out,$this->printContentFromTab('normal'));
00376 
00377                         // Print header and content for the NUMERIC tabs:
00378                 for ($a=1;$a<=$this->numberTabs;$a++)   {
00379                         $out[]='
00380                                 <tr class="bgColor5">
00381                                         <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'tab_'.$a)))).'#clip_head">'.
00382                                                 '<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="" />'.
00383                                                 $this->padTitleWrap($this->clLabel('cliptabs').$a,'tab_'.$a).
00384                                                 '</a></td>
00385                                 </tr>';
00386                         if ($this->current=='tab_'.$a)  $out=array_merge($out,$this->printContentFromTab('tab_'.$a));
00387                 }
00388 
00389                         // Wrap accumulated rows in a table:
00390                 $output = '<a name="clip_head"></a>
00391 
00392                         <!--
00393                                 TYPO3 Clipboard:
00394                         -->
00395                         <table cellpadding="0" cellspacing="1" border="0" width="290" id="typo3-clipboard">
00396                                 '.implode('',$out).'
00397                         </table>';
00398 
00399                         // Wrap in form tag:
00400                 $output = '<form action="">'.$output.'</form>';
00401 
00402                         // Return the accumulated content:
00403                 return $output;
00404         }
00405 
00413         function printContentFromTab($pad)      {
00414                 global $TBE_TEMPLATE;
00415 
00416                 $lines=array();
00417                 if (is_array($this->clipData[$pad]['el']))      {
00418                         reset($this->clipData[$pad]['el']);
00419                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00420                                 if ($v) {
00421                                         list($table,$uid) = explode('|',$k);
00422                                         $bgColClass = ($table=='_FILE'&&$this->fileMode)||($table!='_FILE'&&!$this->fileMode) ? 'bgColor4-20' : 'bgColor4';
00423 
00424                                         if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
00425                                                 if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
00426                                                         $fI = pathinfo($v);
00427                                                         $icon = is_dir($v) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
00428                                                         $size = ' ('.t3lib_div::formatSize(filesize($v)).'bytes)';
00429                                                         $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="" />';
00430                                                         $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"') : '') :'';
00431 
00432                                                         $lines[]='
00433                                                                 <tr>
00434                                                                         <td class="'.$bgColClass.'">'.$icon.'</td>
00435                                                                         <td class="'.$bgColClass.'" nowrap="nowrap" width="95%">&nbsp;'.$this->linkItemText(htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($v),$GLOBALS['BE_USER']->uc['titleLen'])),$v).
00436                                                                                 ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;'.($thumb?'<br />'.$thumb:'').'</td>
00437                                                                         <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00438                                                                         '<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>'.
00439                                                                         '<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>'.
00440                                                                         '</td>
00441                                                                 </tr>';
00442                                                 } else {
00443                                                                 // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
00444                                                         unset($this->clipData[$pad]['el'][$k]);
00445                                                         $this->changed=1;
00446                                                 }
00447                                         } else {        // Rendering records:
00448                                                 $rec=t3lib_BEfunc::getRecordWSOL($table,$uid);
00449                                                 if (is_array($rec))     {
00450                                                         $lines[]='
00451                                                                 <tr>
00452                                                                         <td class="'.$bgColClass.'">'.$this->linkItemText(t3lib_iconWorks::getIconImage($table,$rec,$this->backPath,'hspace="20" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($rec,$table)).'"'),$rec,$table).'</td>
00453                                                                         <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).
00454                                                                                 ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;</td>
00455                                                                         <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00456                                                                         '<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>'.
00457                                                                         '<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>'.
00458                                                                         '</td>
00459                                                                 </tr>';
00460                                                 } else {
00461                                                         unset($this->clipData[$pad]['el'][$k]);
00462                                                         $this->changed=1;
00463                                                 }
00464                                         }
00465                                 }
00466                         }
00467                 }
00468                 if (!count($lines))     {
00469                         $lines[]='
00470                                                                 <tr>
00471                                                                         <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td>
00472                                                                         <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%">&nbsp;<em>('.$this->clLabel('clipNoEl').')</em>&nbsp;</td>
00473                                                                 </tr>';
00474                 }
00475 
00476                 $this->endClipboard();
00477                 return $lines;
00478         }
00479 
00487         function padTitleWrap($str,$pad)        {
00488                 $el = count($this->elFromTable($this->fileMode?'_FILE':'',$pad));
00489                 if ($el)        {
00490                         return '<strong>'.$str.'</strong> ('.($pad=='normal'?($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')):htmlspecialchars($el)).')';
00491                 } else {
00492                         return $GLOBALS['TBE_TEMPLATE']->dfw($str);
00493                 }
00494         }
00495 
00504         function linkItemText($str,$rec,$table='')      {
00505                 if (is_array($rec) && $table)   {
00506                         if ($this->fileMode)    {
00507                                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00508                         } else {
00509                                 $str='<a href="'.htmlspecialchars($this->backPath.'db_list.php?id='.$rec['pid']).'">'.$str.'</a>';
00510                         }
00511                 } elseif (@file_exists($rec))   {
00512                         if (!$this->fileMode)   {
00513                                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00514                         } else {
00515                                 $str='<a href="'.htmlspecialchars($this->backPath.'file_list.php?id='.dirname($rec)).'">'.$str.'</a>';
00516                         }
00517                 }
00518                 return $str;
00519         }
00520 
00531         function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())   {
00532                 $CB = array('el'=>array(rawurlencode($table.'|'.$uid)=>$deselect?0:1));
00533                 if ($copy)      $CB['setCopyMode'] = 1;
00534                 $baseArray['CB'] = $CB;
00535                 return t3lib_div::linkThisScript($baseArray);
00536         }
00537 
00547         function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())       {
00548                 $CB=array('el'=>array(rawurlencode('_FILE|'.t3lib_div::shortmd5($path))=>$deselect?'':$path));
00549                 if ($copy)      $CB['setCopyMode']=1;
00550                 $baseArray['CB']=$CB;
00551                 return t3lib_div::linkThisScript($baseArray);
00552         }
00553 
00564         function pasteUrl($table,$uid,$setRedirect=1)   {
00565                 $rU = $this->backPath.($table=='_FILE'?'tce_file.php':'tce_db.php').'?'.
00566                         ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00567                         '&vC='.$GLOBALS['BE_USER']->veriCode().
00568                         '&prErr=1&uPT=1'.
00569                         '&CB[paste]='.rawurlencode($table.'|'.$uid).
00570                         '&CB[pad]='.$this->current;
00571                 return $rU;
00572         }
00573 
00581         function deleteUrl($setRedirect=1,$file=0)      {
00582                 $rU = $this->backPath.($file?'tce_file.php':'tce_db.php').'?'.
00583                         ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00584                         '&vC='.$GLOBALS['BE_USER']->veriCode().
00585                         '&prErr=1&uPT=1'.
00586                         '&CB[delete]=1'.
00587                         '&CB[pad]='.$this->current;
00588                 return $rU;
00589         }
00590 
00598         function editUrl()      {
00599                 $elements = $this->elFromTable('');     // all records
00600                 reset($elements);
00601                 $editCMDArray=array();
00602                 while(list($tP)=each($elements))        {
00603                         list($table,$uid) = explode('|',$tP);
00604                         $editCMDArray[] = '&edit['.$table.']['.$uid.']=edit';
00605                 }
00606 
00607                 $rU = $this->backPath.'alt_doc.php?'.implode('',$editCMDArray);
00608                 return $rU;
00609         }
00610 
00619         function removeUrl($table,$uid) {
00620                 return t3lib_div::linkThisScript(array('CB'=>array('remove'=>$table.'|'.$uid)));
00621         }
00622 
00632         function confirmMsg($table,$rec,$type,$clElements)      {
00633                 if($GLOBALS['BE_USER']->jsConfirmation(2))      {
00634                 $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.'.($this->currentMode()=='copy'?'copy':'move').($this->current=='normal'?'':'cb').'_'.$type;
00635                 $msg = $GLOBALS['LANG']->sL($labelKey);
00636 
00637                 if ($table=='_FILE')    {
00638                         $thisRecTitle = basename($rec);
00639                         if ($this->current=='normal')   {
00640                                 reset($clElements);
00641                                 $selItem = current($clElements);
00642                                 $selRecTitle = basename($selItem);
00643                         } else {
00644                                 $selRecTitle=count($clElements);
00645                         }
00646                 } else {
00647                         $thisRecTitle = (
00648                                 $table=='pages' && !is_array($rec) ?
00649                                 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] :
00650                                 t3lib_BEfunc::getRecordTitle($table,$rec)
00651                         );
00652 
00653                         if ($this->current=='normal')   {
00654                                 $selItem = $this->getSelectedRecord();
00655                                 $selRecTitle=$selItem['_RECORD_TITLE'];
00656                         } else {
00657                                 $selRecTitle=count($clElements);
00658                         }
00659                 }
00660 
00661                         // Message:
00662                 $conf='confirm('.$GLOBALS['LANG']->JScharCode(sprintf(
00663                         $msg,
00664                         t3lib_div::fixed_lgd_cs($selRecTitle,30),
00665                         t3lib_div::fixed_lgd_cs($thisRecTitle,30)
00666                         )).')';
00667                 } else {
00668                         $conf = '';
00669                 }
00670                 return $conf;
00671         }
00672 
00680         function clLabel($key,$Akey='labels')   {
00681                 return htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:'.$Akey.'.'.$key));
00682         }
00683 
00689         function exportClipElementParameters()  {
00690 
00691                         // Init:
00692                 $pad = $this->current;
00693                 $params = array();
00694                 $params[] = 'tx_impexp[action]=export';
00695 
00696                         // Traverse items:
00697                 if (is_array($this->clipData[$pad]['el']))      {
00698                         reset($this->clipData[$pad]['el']);
00699                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00700                                 if ($v) {
00701                                         list($table,$uid) = explode('|',$k);
00702 
00703                                         if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
00704                                                 if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
00705                                                         $params[] = 'tx_impexp['.(is_dir($v) ? 'dir' : 'file').'][]='.rawurlencode($v);
00706                                                 }
00707                                         } else {        // Rendering records:
00708                                                 $rec = t3lib_BEfunc::getRecord($table,$uid);
00709                                                 if (is_array($rec))     {
00710                                                         $params[] = 'tx_impexp[record][]='.rawurlencode($table.':'.$uid);
00711                                                 }
00712                                         }
00713                                 }
00714                         }
00715                 }
00716 
00717                 return '&'.implode('&', $params);
00718         }
00719 
00720 
00721 
00722 
00723 
00724 
00725 
00726 
00727         /*****************************************
00728          *
00729          * Helper functions
00730          *
00731          ****************************************/
00732 
00739         function removeElement($el)     {
00740                 unset($this->clipData[$this->current]['el'][$el]);
00741                 $this->changed=1;
00742         }
00743 
00751         function saveClipboard()        {
00752                 global $BE_USER;
00753                 $BE_USER->pushModuleData('clipboard',$this->clipData);
00754         }
00755 
00761         function currentMode()  {
00762                 return $this->clipData[$this->current]['mode']=='copy' ? 'copy' : 'cut';
00763         }
00764 
00771         function cleanCurrent() {
00772                 if (is_array($this->clipData[$this->current]['el']))    {
00773                         reset($this->clipData[$this->current]['el']);
00774                         while(list($k,$v)=each($this->clipData[$this->current]['el']))  {
00775                                 list($table,$uid) = explode('|',$k);
00776                                 if ($table!='_FILE')    {
00777                                         if (!$v || !is_array(t3lib_BEfunc::getRecord($table,$uid,'uid')))       {
00778                                                 unset($this->clipData[$this->current]['el'][$k]);
00779                                                 $this->changed=1;
00780                                         }
00781                                 } else {
00782                                         if (!$v || !@file_exists($v))   {
00783                                                 unset($this->clipData[$this->current]['el'][$k]);
00784                                                 $this->changed=1;
00785                                         }
00786                                 }
00787                         }
00788                 }
00789         }
00790 
00798         function elFromTable($matchTable='',$pad='')    {
00799                 $pad = $pad ? $pad : $this->current;
00800                 $list=array();
00801                 if (is_array($this->clipData[$pad]['el']))      {
00802                         reset($this->clipData[$pad]['el']);
00803                         while(list($k,$v)=each($this->clipData[$pad]['el']))    {
00804                                 if ($v) {
00805                                         list($table,$uid) = explode('|',$k);
00806                                         if ($table!='_FILE')    {
00807                                                 if ((!$matchTable || (string)$table==(string)$matchTable) && $GLOBALS['TCA'][$table])   {
00808                                                         $list[$k]= ($pad=='normal'?$v:$uid);
00809                                                 }
00810                                         } else {
00811                                                 if ((string)$table==(string)$matchTable)        {
00812                                                         $list[$k]=$v;
00813                                                 }
00814                                         }
00815                                 }
00816                         }
00817                 }
00818                 return $list;
00819         }
00820 
00829         function isSelected($table,$uid)        {
00830                 $k=$table.'|'.$uid;
00831                 return $this->clipData[$this->current]['el'][$k] ? ($this->current=='normal'?$this->currentMode():1) : '';
00832         }
00833 
00843         function getSelectedRecord($table='',$uid='')   {
00844                 if (!$table && !$uid)   {
00845                         $elArr = $this->elFromTable('');
00846                         reset($elArr);
00847                         list($table,$uid) = explode('|',key($elArr));
00848                 }
00849                 if ($this->isSelected($table,$uid))     {
00850                         $selRec = t3lib_BEfunc::getRecordWSOL($table,$uid);
00851                         $selRec['_RECORD_TITLE'] = t3lib_BEfunc::getRecordTitle($table,$selRec);
00852                         return $selRec;
00853                 }
00854         }
00855 
00861         function isElements()   {
00862                 return is_array($this->clipData[$this->current]['el']) && count($this->clipData[$this->current]['el']);
00863         }
00864 
00865 
00866 
00867 
00868 
00869 
00870 
00871 
00872 
00873 
00874 
00875 
00876 
00877 
00878 
00879         /*****************************************
00880          *
00881          * FOR USE IN tce_db.php:
00882          *
00883          ****************************************/
00884 
00902         function makePasteCmdArray($ref,$CMD)   {
00903                 list($pTable,$pUid) = explode('|',$ref);
00904                 $pUid = intval($pUid);
00905 
00906                 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)
00907                         $elements = $this->elFromTable($pTable);
00908 
00909                         $elements = array_reverse($elements);   // So the order is preserved.
00910                         $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
00911 
00912                                 // Traverse elements and make CMD array
00913                         reset($elements);
00914                         while(list($tP)=each($elements))        {
00915                                 list($table,$uid) = explode('|',$tP);
00916                                 if (!is_array($CMD[$table]))    $CMD[$table]=array();
00917                                 $CMD[$table][$uid][$mode]=$pUid;
00918                                 if ($mode=='move')      $this->removeElement($tP);
00919                         }
00920                         $this->endClipboard();
00921                 }
00922                 return $CMD;
00923         }
00924 
00931         function makeDeleteCmdArray($CMD)       {
00932                 $elements = $this->elFromTable('');     // all records
00933                 reset($elements);
00934                 while(list($tP)=each($elements))        {
00935                         list($table,$uid) = explode('|',$tP);
00936                         if (!is_array($CMD[$table]))    $CMD[$table]=array();
00937                         $CMD[$table][$uid]['delete']=1;
00938                         $this->removeElement($tP);
00939                 }
00940                 $this->endClipboard();
00941                 return $CMD;
00942         }
00943 
00944 
00945 
00946 
00947 
00948 
00949 
00950 
00951 
00952 
00953 
00954 
00955 
00956 
00957 
00958 
00959 
00960         /*****************************************
00961          *
00962          * FOR USE IN tce_file.php:
00963          *
00964          ****************************************/
00965 
00974         function makePasteCmdArray_file($ref,$FILE)     {
00975                 list($pTable,$pUid) = explode('|',$ref);
00976                 $elements = $this->elFromTable('_FILE');
00977                 $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
00978 
00979                         // Traverse elements and make CMD array
00980                 reset($elements);
00981                 while(list($tP,$path)=each($elements))  {
00982                         $FILE[$mode][]=array('data'=>$path,'target'=>$pUid,'altName'=>1);
00983                         if ($mode=='move')      $this->removeElement($tP);
00984                 }
00985                 $this->endClipboard();
00986 
00987                 return $FILE;
00988         }
00989 
00996         function makeDeleteCmdArray_file($FILE) {
00997                 $elements = $this->elFromTable('_FILE');
00998                         // Traverse elements and make CMD array
00999                 reset($elements);
01000                 while(list($tP,$path)=each($elements))  {
01001                         $FILE['delete'][]=array('data'=>$path);
01002                         $this->removeElement($tP);
01003                 }
01004                 $this->endClipboard();
01005 
01006                 return $FILE;
01007         }
01008 }
01009 
01010 
01011 
01012 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']) {
01013         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']);
01014 }
01015 ?>


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