class.t3lib_clipboard.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2010 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 ***************************************************************/
00027 /**
00028  * Contains class for TYPO3 clipboard for records and files
00029  *
00030  * $Id: class.t3lib_clipboard.php 8254 2010-07-23 21:39:21Z steffenk $
00031  * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
00032  * XHTML compliant
00033  *
00034  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00035  */
00036 /**
00037  * [CLASS/FUNCTION INDEX of SCRIPT]
00038  *
00039  *
00040  *
00041  *   97: class t3lib_clipboard
00042  *
00043  *              SECTION: Initialize
00044  *  150:     function initializeClipboard()
00045  *  179:     function lockToNormal()
00046  *  196:     function setCmd($cmd)
00047  *  243:     function setCurrentPad($padIdent)
00048  *  258:     function endClipboard()
00049  *  271:     function cleanUpCBC($CBarr,$table,$removeDeselected=0)
00050  *
00051  *              SECTION: Clipboard HTML renderings
00052  *  306:     function printClipboard()
00053  *  413:     function printContentFromTab($pad)
00054  *  487:     function padTitleWrap($str,$pad)
00055  *  504:     function linkItemText($str,$rec,$table='')
00056  *  531:     function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())
00057  *  547:     function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())
00058  *  564:     function pasteUrl($table,$uid,$setRedirect=1)
00059  *  581:     function deleteUrl($setRedirect=1,$file=0)
00060  *  598:     function editUrl()
00061  *  619:     function removeUrl($table,$uid)
00062  *  632:     function confirmMsg($table,$rec,$type,$clElements)
00063  *  680:     function clLabel($key,$Akey='labels')
00064  *  689:     function exportClipElementParameters()
00065  *
00066  *              SECTION: Helper functions
00067  *  739:     function removeElement($el)
00068  *  751:     function saveClipboard()
00069  *  761:     function currentMode()
00070  *  771:     function cleanCurrent()
00071  *  798:     function elFromTable($matchTable='',$pad='')
00072  *  829:     function isSelected($table,$uid)
00073  *  843:     function getSelectedRecord($table='',$uid='')
00074  *  861:     function isElements()
00075  *
00076  *              SECTION: FOR USE IN tce_db.php:
00077  *  902:     function makePasteCmdArray($ref,$CMD)
00078  *  931:     function makeDeleteCmdArray($CMD)
00079  *
00080  *              SECTION: FOR USE IN tce_file.php:
00081  *  974:     function makePasteCmdArray_file($ref,$FILE)
00082  *  996:     function makeDeleteCmdArray_file($FILE)
00083  *
00084  * TOTAL FUNCTIONS: 31
00085  * (This index is automatically created/updated by the extension "extdeveval")
00086  *
00087  */
00088 
00089 
00090 /**
00091  * TYPO3 clipboard for records and files
00092  *
00093  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00094  * @package TYPO3
00095  * @subpackage t3lib
00096  */
00097 class t3lib_clipboard {
00098     var $numberTabs = 3;
00099 
00100     /**
00101      * Clipboard data kept here
00102      *
00103      * Keys:
00104      *          'normal'
00105      *          'tab_[x]' where x is >=1 and denotes the pad-number
00106      *              \   'mode'  :   'copy' means copy-mode, default = moving ('cut')
00107      *              \   'el'    :   Array of elements:
00108      *                              DB: keys = '[tablename]|[uid]'  eg. 'tt_content:123'
00109      *                              DB: values = 1 (basically insignificant)
00110      *                              FILE: keys = '_FILE|[shortmd5 of path]' eg. '_FILE|9ebc7e5c74'
00111      *                              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'
00112      *
00113      *          'current' pointer to current tab (among the above...)
00114      *          '_setThumb' boolean: If set, file thumbnails are shown.
00115      *
00116      *      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)
00117      *
00118      */
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 
00145     /**
00146      * Initialize the clipboard from the be_user session
00147      *
00148      * @return  void
00149      */
00150     function initializeClipboard()  {
00151         global $BE_USER;
00152 
00153         $this->backPath = $GLOBALS['BACK_PATH'];
00154 
00155             // Get data
00156         $clipData = $BE_USER->getModuleData('clipboard',$BE_USER->getTSConfigVal('options.saveClipboard')?'':'ses');
00157 
00158             // NumberTabs
00159         $clNP = $BE_USER->getTSConfigVal('options.clipboardNumberPads');
00160         if (t3lib_div::testInt($clNP) && $clNP>=0)  {
00161             $this->numberTabs = t3lib_div::intInRange($clNP,0,20);
00162         }
00163 
00164             // Resets/reinstates the clipboard pads
00165         $this->clipData['normal'] = is_array($clipData['normal']) ? $clipData['normal'] : array();
00166         for ($a=1;$a<=$this->numberTabs;$a++)   {
00167             $this->clipData['tab_'.$a] = is_array($clipData['tab_'.$a]) ? $clipData['tab_'.$a] : array();
00168         }
00169 
00170             // Setting the current pad pointer ($this->current) and _setThumb (which determines whether or not do show file thumbnails)
00171         $this->clipData['current'] = $this->current = isset($this->clipData[$clipData['current']]) ? $clipData['current'] : 'normal';
00172         $this->clipData['_setThumb'] = $clipData['_setThumb'];
00173     }
00174 
00175     /**
00176      * 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
00177      * This is used by the clickmenu since it only allows operation on single elements at a time (that is the "normal" pad)
00178      *
00179      * @return  void
00180      */
00181     function lockToNormal() {
00182         $this->lockToNormal = 1;
00183         $this->current = 'normal';
00184     }
00185 
00186     /**
00187      * The array $cmd may hold various keys which notes some action to take.
00188      * Normally perform only one action at a time.
00189      * In scripts like db_list.php / file_list.php the GET-var CB is used to control the clipboard.
00190      *
00191      *      Selecting / Deselecting elements
00192      *      Array $cmd['el'] has keys = element-ident, value = element value (see description of clipData array in header)
00193      *      Selecting elements for 'copy' should be done by simultaneously setting setCopyMode.
00194      *
00195      * @param   array       Array of actions, see function description
00196      * @return  void
00197      */
00198     function setCmd($cmd)   {
00199         if (is_array($cmd['el']))   {
00200             foreach ($cmd['el'] as $k => $v) {
00201                 if ($this->current=='normal')   {
00202                     unset($this->clipData['normal']);
00203                 }
00204                 if ($v) {
00205                     $this->clipData[$this->current]['el'][$k]=$v;
00206                 } else {
00207                     $this->removeElement($k);
00208                 }
00209                 $this->changed=1;
00210             }
00211         }
00212             // Change clipboard pad (if not locked to normal)
00213         if ($cmd['setP'])   {
00214             $this->setCurrentPad($cmd['setP']);
00215         }
00216             // Remove element   (value = item ident: DB; '[tablename]|[uid]'    FILE: '_FILE|[shortmd5 hash of path]'
00217         if ($cmd['remove']) {
00218             $this->removeElement($cmd['remove']);
00219             $this->changed=1;
00220         }
00221             // Remove all on current pad (value = pad-ident)
00222         if ($cmd['removeAll'])  {
00223             $this->clipData[$cmd['removeAll']]=array();
00224             $this->changed=1;
00225         }
00226             // Set copy mode of the tab
00227         if (isset($cmd['setCopyMode'])) {
00228             $this->clipData[$this->current]['mode']=$this->isElements()?($cmd['setCopyMode']?'copy':''):'';
00229             $this->changed=1;
00230         }
00231             // Toggle thumbnail display for files on/off
00232         if (isset($cmd['setThumb']))    {
00233             $this->clipData['_setThumb']=$cmd['setThumb'];
00234             $this->changed=1;
00235         }
00236     }
00237 
00238     /**
00239      * Setting the current pad on clipboard
00240      *
00241      * @param   string      Key in the array $this->clipData
00242      * @return  void
00243      */
00244     function setCurrentPad($padIdent)   {
00245             // Change clipboard pad (if not locked to normal)
00246         if (!$this->lockToNormal && $this->current!=$padIdent)  {
00247             if (isset($this->clipData[$padIdent]))  $this->clipData['current'] = $this->current = $padIdent;
00248             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'
00249             $this->changed=1;
00250         }
00251     }
00252 
00253     /**
00254      * Call this after initialization and setCmd in order to save the clipboard to the user session.
00255      * The function will check if the internal flag ->changed has been set and if so, save the clipboard. Else not.
00256      *
00257      * @return  void
00258      */
00259     function endClipboard() {
00260         if ($this->changed) $this->saveClipboard();
00261         $this->changed=0;
00262     }
00263 
00264     /**
00265      * Cleans up an incoming element array $CBarr (Array selecting/deselecting elements)
00266      *
00267      * @param   array       Element array from outside ("key" => "selected/deselected")
00268      * @param   string      $table is the 'table which is allowed'. Must be set.
00269      * @param   boolean     $removeDeselected can be set in order to remove entries which are marked for deselection.
00270      * @return  array       Processed input $CBarr
00271      */
00272     function cleanUpCBC($CBarr,$table,$removeDeselected=0)  {
00273         if (is_array($CBarr))   {
00274             foreach ($CBarr as $k => $v) {
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 
00301     /**
00302      * Prints the clipboard
00303      *
00304      * @return  string      HTML output
00305      */
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="t3-row-header">
00315                 <td colspan="3" nowrap="nowrap" align="center"><strong>' . $this->clLabel('clipboard', 'buttons') . '</strong></td>
00316             </tr>';
00317 
00318             // Button/menu header:
00319         $thumb_url = t3lib_div::linkThisScript(array('CB'=>array('setThumb'=>$this->clipData['_setThumb']?0:1)));
00320         $rmall_url = t3lib_div::linkThisScript(array('CB'=>array('removeAll'=>$this->current)));
00321 
00322             // Copymode Selector menu
00323         $copymode_url = t3lib_div::linkThisScript();
00324         $moveLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:moveElements'));
00325         $copyLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:copyElements'));
00326         $opt=array();
00327         $opt[]='<option style="padding-left: 20px; background-image: url(\''.t3lib_iconWorks::skinImg($this->backPath, 'gfx/clip_cut.gif', '', 1).'\'); background-repeat: no-repeat;" value="" '.(($this->currentMode()=='copy')?'':'selected="selected"').'>'.$moveLabel .'</option>';
00328         $opt[]='<option style="padding-left: 20px; background-image: url(\''.t3lib_iconWorks::skinImg($this->backPath, 'gfx/clip_copy.gif', '', 1).'\'); background-repeat: no-repeat;" value="1" '.(($this->currentMode()=='copy')?'selected="selected"':'').'>'.$copyLabel .'</option>';
00329 
00330         $copymode_selector = ' <select name="CB[setCopyMode]" onchange="this.form.method=\'POST\'; this.form.action=\''.htmlspecialchars($copymode_url.'&CB[setCopyMode]=').'\'+(this.options[this.selectedIndex].value); this.form.submit(); return true;" >'.implode('',$opt).'</select>';
00331 
00332             // Selector menu + clear button
00333         $opt=array();
00334         $opt[]='<option value="" selected="selected">'.$this->clLabel('menu','rm').'</option>';
00335                 // Import / Export link:
00336         if ($elCount && t3lib_extMgm::isLoaded('impexp'))   {
00337             $opt[] = '<option value="'.htmlspecialchars("window.location.href='".$this->backPath.t3lib_extMgm::extRelPath('impexp').'app/index.php'.$this->exportClipElementParameters().'\';').'">'.$this->clLabel('export','rm').'</option>';
00338         }
00339                 // Edit:
00340         if (!$this->fileMode && $elCount)   {
00341             $opt[]='<option value="' . htmlspecialchars("window.location.href='" . $this->editUrl() . "&returnUrl='+top.rawurlencode(window.location.href);") . '">' . $this->clLabel('edit', 'rm') . '</option>';
00342         }
00343                 // Delete:
00344         if ($elCount)   {
00345             if($GLOBALS['BE_USER']->jsConfirmation(4))  {
00346                 $js = "
00347             if(confirm(".$GLOBALS['LANG']->JScharCode(sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.deleteClip'),$elCount)).")){
00348                 window.location.href='" . $this->deleteUrl(0, $this->fileMode ? 1 : 0) . "&redirect='+top.rawurlencode(window.location.href);
00349             }
00350                     ";
00351             } else {
00352                 $js = " window.location.href='" . $this->deleteUrl(0, $this->fileMode ? 1 : 0) . "&redirect='+top.rawurlencode(window.location.href); ";
00353             }
00354             $opt[]='<option value="'.htmlspecialchars($js).'">'.$this->clLabel('delete','rm').'</option>';
00355         }
00356         $selector_menu = '<select name="_clipMenu" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$opt).'</select>';
00357 
00358         $out[]='
00359             <tr class="typo3-clipboard-head">
00360                 <td nowrap="nowrap">'.
00361                 '<a href="'.htmlspecialchars($thumb_url).'#clip_head">'.
00362                     '<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="" />'.
00363                     '</a>'.
00364                 '</td>
00365                 <td width="95%" nowrap="nowrap">'.
00366                     $copymode_selector.' '.
00367                     $selector_menu.
00368                 '</td>
00369                 <td>'.
00370                 '<a href="'.htmlspecialchars($rmall_url).'#clip_head">'.
00371                     t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $LANG->sL('LLL:EXT:lang/locallang_core.php:buttons.clear', TRUE))) .
00372                 '</a></td>
00373             </tr>';
00374 
00375 
00376             // Print header and content for the NORMAL tab:
00377         $out[]='
00378             <tr class="bgColor5">
00379                 <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'normal')))).'#clip_head">'.
00380                     t3lib_iconWorks::getSpriteIcon('actions-view-table-' . (($this->current == 'normal') ? 'collapse' : 'expand')) .
00381                     $this->padTitleWrap('Normal','normal').
00382                     '</a></td>
00383             </tr>';
00384         if ($this->current=='normal')   $out=array_merge($out,$this->printContentFromTab('normal'));
00385 
00386             // Print header and content for the NUMERIC tabs:
00387         for ($a=1;$a<=$this->numberTabs;$a++)   {
00388             $out[]='
00389                 <tr class="bgColor5">
00390                     <td colspan="3"><a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('CB'=>array('setP'=>'tab_'.$a)))).'#clip_head">'.
00391                         t3lib_iconWorks::getSpriteIcon('actions-view-table-' . (($this->current == 'tab_' . $a) ? 'collapse' : 'expand')) .
00392                         $this->padTitleWrap($this->clLabel('cliptabs').$a,'tab_'.$a).
00393                         '</a></td>
00394                 </tr>';
00395             if ($this->current=='tab_'.$a)  $out=array_merge($out,$this->printContentFromTab('tab_'.$a));
00396         }
00397 
00398             // Wrap accumulated rows in a table:
00399         $output = '<a name="clip_head"></a>
00400 
00401             <!--
00402                 TYPO3 Clipboard:
00403             -->
00404             <table cellpadding="0" cellspacing="1" border="0" width="290" id="typo3-clipboard">
00405                 '.implode('',$out).'
00406             </table>';
00407 
00408             // Wrap in form tag:
00409         $output = '<form action="">'.$output.'</form>';
00410 
00411             // Return the accumulated content:
00412         return $output;
00413     }
00414 
00415     /**
00416      * Print the content on a pad. Called from ->printClipboard()
00417      *
00418      * @param   string      Pad reference
00419      * @return  array       Array with table rows for the clipboard.
00420      * @access private
00421      */
00422     function printContentFromTab($pad)  {
00423         global $TBE_TEMPLATE;
00424 
00425         $lines=array();
00426         if (is_array($this->clipData[$pad]['el']))  {
00427             foreach ($this->clipData[$pad]['el'] as $k => $v) {
00428                 if ($v) {
00429                     list($table,$uid) = explode('|',$k);
00430                     $bgColClass = ($table=='_FILE'&&$this->fileMode)||($table!='_FILE'&&!$this->fileMode) ? 'bgColor4-20' : 'bgColor4';
00431 
00432                     if ($table=='_FILE')    {   // Rendering files/directories on the clipboard:
00433                         if (file_exists($v) && t3lib_div::isAllowedAbsPath($v)) {
00434                             $fI = pathinfo($v);
00435                             $icon = is_dir($v) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
00436                             $size = ' ('.t3lib_div::formatSize(filesize($v)).'bytes)';
00437                             $icon = t3lib_iconWorks::getSpriteIconForFile(is_dir($v) ? 'folder' : strtolower($fI['extension']), array('style' => 'margin: 0 20px;', 'title' => htmlspecialchars($fI['basename'] . $size)));
00438                             $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"') : '') :'';
00439 
00440                             $lines[]='
00441                                 <tr>
00442                                     <td class="'.$bgColClass.'">'.$icon.'</td>
00443                                     <td class="'.$bgColClass.'" nowrap="nowrap" width="95%">&nbsp;'.$this->linkItemText(htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($v),$GLOBALS['BE_USER']->uc['titleLen'])),$v).
00444                                         ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;'.($thumb?'<br />'.$thumb:'').'</td>
00445                                     <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00446                                         '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $v . '\', \'\'); return false;') . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info', 'cm'))) . '</a>'.
00447                                         '<a href="' . htmlspecialchars($this->removeUrl('_FILE', t3lib_div::shortmd5($v))) . '#clip_head">' . t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) .  '</a>'.
00448                                     '</td>
00449                                 </tr>';
00450                         } else {
00451                                 // If the file did not exist (or is illegal) then it is removed from the clipboard immediately:
00452                             unset($this->clipData[$pad]['el'][$k]);
00453                             $this->changed=1;
00454                         }
00455                     } else {    // Rendering records:
00456                         $rec=t3lib_BEfunc::getRecordWSOL($table,$uid);
00457                         if (is_array($rec)) {
00458                             $lines[]='
00459                                 <tr>
00460                                     <td class="' . $bgColClass . '">' . $this->linkItemText(t3lib_iconWorks::getSpriteIconForRecord($table, $rec, array('style' => 'margin: 0 20px;', 'title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($rec, $table)))), $rec, $table) . '</td>
00461                                     <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).
00462                                         ($pad=='normal'?(' <strong>('.($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')).')</strong>'):'').'&nbsp;</td>
00463                                     <td class="'.$bgColClass.'" align="center" nowrap="nowrap">'.
00464                                         '<a href="#" onclick="' . htmlspecialchars('top.launchView(\'' . $table . '\', \'' . intval($uid) . '\'); return false;') . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-info', array('title' => $this->clLabel('info','cm'))) . '</a>'.
00465                                         '<a href="' . htmlspecialchars($this->removeUrl($table, $uid)) . '#clip_head">' . t3lib_iconWorks::getSpriteIcon('actions-selection-delete', array('title' => $this->clLabel('removeItem'))) . '</a>'.
00466                                     '</td>
00467                                 </tr>';
00468 
00469                             $localizationData = $this->getLocalizations($table, $rec, $bgColClass, $pad);
00470                             if ($localizationData) {
00471                                 $lines[] = $localizationData;
00472                             }
00473 
00474                         } else {
00475                             unset($this->clipData[$pad]['el'][$k]);
00476                             $this->changed=1;
00477                         }
00478                     }
00479                 }
00480             }
00481         }
00482         if (!count($lines)) {
00483             $lines[]='
00484                                 <tr>
00485                                     <td class="bgColor4"><img src="clear.gif" width="56" height="1" alt="" /></td>
00486                                     <td colspan="2" class="bgColor4" nowrap="nowrap" width="95%">&nbsp;<em>('.$this->clLabel('clipNoEl').')</em>&nbsp;</td>
00487                                 </tr>';
00488         }
00489 
00490         $this->endClipboard();
00491         return $lines;
00492     }
00493 
00494 
00495     /**
00496      * Gets all localizations of the current record.
00497      *
00498      * @param   string      the table
00499      * @param   array       the current record
00500      * @return  string      HTML table rows
00501      */
00502     function getLocalizations($table, $parentRec, $bgColClass, $pad) {
00503         $lines = array();
00504         $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
00505 
00506         if ($table != 'pages' && t3lib_BEfunc::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
00507             $where = array();
00508             $where[] = $tcaCtrl['transOrigPointerField'] . '=' . intval($parentRec['uid']);
00509             $where[] = $tcaCtrl['languageField'] . '!=0';
00510 
00511             if (isset($tcaCtrl['delete']) && $tcaCtrl['delete']) {
00512                 $where[] = $tcaCtrl['delete'] . '=0';
00513             }
00514 
00515             if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
00516                 $where[] = 't3ver_wsid=' . $parentRec['t3ver_wsid'];
00517             }
00518 
00519             $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, implode(' AND ', $where));
00520 
00521             if (is_array($rows)) {
00522                 $modeData = '';
00523                 if ($pad == 'normal') {
00524                     $mode = ($this->clipData['normal']['mode'] == 'copy' ? 'copy' : 'cut');
00525                     $modeData = ' <strong>(' . $this->clLabel($mode, 'cm') . ')</strong>';
00526                 }
00527 
00528                 foreach ($rows as $rec) {
00529                     $lines[]='
00530                     <tr>
00531                         <td class="' . $bgColClass . '">' .
00532                             t3lib_iconWorks::getSpriteIconForRecord($table, $rec, array('style' => "margin-left: 38px;")) . '</td>
00533                         <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . htmlspecialchars(
00534                                 t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])) .
00535                                 $modeData . '&nbsp;</td>
00536                         <td class="' . $bgColClass . '" align="center" nowrap="nowrap">&nbsp;</td>
00537                     </tr>';
00538                 }
00539             }
00540         }
00541         return implode('',$lines);
00542     }
00543 
00544 
00545 
00546     /**
00547      * Wraps title of pad in bold-tags and maybe the number of elements if any.
00548      *
00549      * @param   string      String (already htmlspecialchars()'ed)
00550      * @param   string      Pad reference
00551      * @return  string      HTML output (htmlspecialchar'ed content inside of tags.)
00552      */
00553     function padTitleWrap($str,$pad)    {
00554         $el = count($this->elFromTable($this->fileMode?'_FILE':'',$pad));
00555         if ($el)    {
00556             return '<strong>'.$str.'</strong> ('.($pad=='normal'?($this->clipData['normal']['mode']=='copy'?$this->clLabel('copy','cm'):$this->clLabel('cut','cm')):htmlspecialchars($el)).')';
00557         } else {
00558             return $GLOBALS['TBE_TEMPLATE']->dfw($str);
00559         }
00560     }
00561 
00562     /**
00563      * Wraps the title of the items listed in link-tags. The items will link to the page/folder where they originate from
00564      *
00565      * @param   string      Title of element - must be htmlspecialchar'ed on beforehand.
00566      * @param   mixed       If array, a record is expected. If string, its a path
00567      * @param   string      Table name
00568      * @return  string
00569      */
00570     function linkItemText($str,$rec,$table='')  {
00571         if (is_array($rec) && $table)   {
00572             if ($this->fileMode)    {
00573                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00574             } else {
00575                 if (t3lib_extMgm::isLoaded('list')) {
00576                     $str = '<a href="' . htmlspecialchars(
00577                         $this->backPath . t3lib_extMgm::extRelPath('list') . 'mod1/db_list.php?id=' . $rec['pid']
00578                     ) . '">' . $str . '</a>';
00579                 }
00580             }
00581         } elseif (file_exists($rec))    {
00582             if (!$this->fileMode)   {
00583                 $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
00584             } else {
00585                 if (t3lib_extMgm::isLoaded('filelist')) {
00586                     $str = '<a href="' . htmlspecialchars(
00587                         $this->backPath . t3lib_extMgm::extRelPath('filelist') . 'mod1/file_list.php?id=' . dirname($rec)
00588                     ) . '">' . $str . '</a>';
00589                 }
00590             }
00591         }
00592         return $str;
00593     }
00594 
00595     /**
00596      * Returns the select-url for database elements
00597      *
00598      * @param   string      Table name
00599      * @param   integer     Uid of record
00600      * @param   boolean     If set, copymode will be enabled
00601      * @param   boolean     If set, the link will deselect, otherwise select.
00602      * @param   array       The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
00603      * @return  string      URL linking to the current script but with the CB array set to select the element with table/uid
00604      */
00605     function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())   {
00606         $CB = array('el'=>array(rawurlencode($table.'|'.$uid)=>$deselect?0:1));
00607         if ($copy)  $CB['setCopyMode'] = 1;
00608         $baseArray['CB'] = $CB;
00609         return t3lib_div::linkThisScript($baseArray);
00610     }
00611 
00612     /**
00613      * Returns the select-url for files
00614      *
00615      * @param   string      Filepath
00616      * @param   boolean     If set, copymode will be enabled
00617      * @param   boolean     If set, the link will deselect, otherwise select.
00618      * @param   array       The base array of GET vars to be sent in addition. Notice that current GET vars WILL automatically be included.
00619      * @return  string      URL linking to the current script but with the CB array set to select the path
00620      */
00621     function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())   {
00622         $CB=array('el'=>array(rawurlencode('_FILE|'.t3lib_div::shortmd5($path))=>$deselect?'':$path));
00623         if ($copy)  $CB['setCopyMode']=1;
00624         $baseArray['CB']=$CB;
00625         return t3lib_div::linkThisScript($baseArray);
00626     }
00627 
00628     /**
00629      * pasteUrl of the element (database and file)
00630      * For the meaning of $table and $uid, please read from ->makePasteCmdArray!!!
00631      * The URL will point to tce_file or tce_db depending in $table
00632      *
00633      * @param   string      Tablename (_FILE for files)
00634      * @param   mixed       "destination": can be positive or negative indicating how the paste is done (paste into / paste after)
00635      * @param   boolean     If set, then the redirect URL will point back to the current script, but with CB reset.
00636      * @return  string
00637      */
00638     function pasteUrl($table,$uid,$setRedirect=1)   {
00639         $rU = $this->backPath.($table=='_FILE'?'tce_file.php':'tce_db.php').'?'.
00640             ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00641             '&vC='.$GLOBALS['BE_USER']->veriCode().
00642             '&prErr=1&uPT=1'.
00643             '&CB[paste]='.rawurlencode($table.'|'.$uid).
00644             '&CB[pad]='.$this->current;
00645         return $rU;
00646     }
00647 
00648     /**
00649      * deleteUrl for current pad
00650      *
00651      * @param   boolean     If set, then the redirect URL will point back to the current script, but with CB reset.
00652      * @param   boolean     If set, then the URL will link to the tce_file.php script in the typo3/ dir.
00653      * @return  string
00654      */
00655     function deleteUrl($setRedirect=1,$file=0)  {
00656         $rU = $this->backPath.($file?'tce_file.php':'tce_db.php').'?'.
00657             ($setRedirect ? 'redirect='.rawurlencode(t3lib_div::linkThisScript(array('CB'=>''))) : '').
00658             '&vC='.$GLOBALS['BE_USER']->veriCode().
00659             '&prErr=1&uPT=1'.
00660             '&CB[delete]=1'.
00661             '&CB[pad]='.$this->current;
00662         return $rU;
00663     }
00664 
00665     /**
00666      * editUrl of all current elements
00667      * ONLY database
00668      * Links to alt_doc.php
00669      *
00670      * @return  string      The URL to alt_doc.php with parameters.
00671      */
00672     function editUrl()  {
00673         $elements = $this->elFromTable(''); // all records
00674         $editCMDArray=array();
00675         foreach ($elements as $tP => $value) {
00676             list($table,$uid) = explode('|',$tP);
00677             $editCMDArray[] = '&edit['.$table.']['.$uid.']=edit';
00678         }
00679 
00680         $rU = $this->backPath.'alt_doc.php?'.implode('',$editCMDArray);
00681         return $rU;
00682     }
00683 
00684     /**
00685      * Returns the remove-url (file and db)
00686      * for file $table='_FILE' and $uid = shortmd5 hash of path
00687      *
00688      * @param   string      Tablename
00689      * @param   string      uid integer/shortmd5 hash
00690      * @return  string      URL
00691      */
00692     function removeUrl($table,$uid) {
00693         return t3lib_div::linkThisScript(array('CB'=>array('remove'=>$table.'|'.$uid)));
00694     }
00695 
00696     /**
00697      * Returns confirm JavaScript message
00698      *
00699      * @param   string      Table name
00700      * @param   mixed       For records its an array, for files its a string (path)
00701      * @param   string      Type-code
00702      * @param   array       Array of selected elements
00703      * @return  string      JavaScript "confirm" message
00704      */
00705     function confirmMsg($table,$rec,$type,$clElements)  {
00706         if($GLOBALS['BE_USER']->jsConfirmation(2))  {
00707         $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.'.($this->currentMode()=='copy'?'copy':'move').($this->current=='normal'?'':'cb').'_'.$type;
00708         $msg = $GLOBALS['LANG']->sL($labelKey);
00709 
00710         if ($table=='_FILE')    {
00711             $thisRecTitle = basename($rec);
00712             if ($this->current=='normal')   {
00713                 reset($clElements);
00714                 $selItem = current($clElements);
00715                 $selRecTitle = basename($selItem);
00716             } else {
00717                 $selRecTitle=count($clElements);
00718             }
00719         } else {
00720             $thisRecTitle = (
00721                 $table=='pages' && !is_array($rec) ?
00722                 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] :
00723                 t3lib_BEfunc::getRecordTitle($table,$rec)
00724             );
00725 
00726             if ($this->current=='normal')   {
00727                 $selItem = $this->getSelectedRecord();
00728                 $selRecTitle=$selItem['_RECORD_TITLE'];
00729             } else {
00730                 $selRecTitle=count($clElements);
00731             }
00732         }
00733 
00734             // Message:
00735         $conf='confirm('.$GLOBALS['LANG']->JScharCode(sprintf(
00736             $msg,
00737             t3lib_div::fixed_lgd_cs($selRecTitle,30),
00738             t3lib_div::fixed_lgd_cs($thisRecTitle,30)
00739             )).')';
00740         } else {
00741             $conf = '';
00742         }
00743         return $conf;
00744     }
00745 
00746     /**
00747      * Clipboard label - getting from "EXT:lang/locallang_core.php:"
00748      *
00749      * @param   string      Label Key
00750      * @param   string      Alternative key to "labels"
00751      * @return  string
00752      */
00753     function clLabel($key,$Akey='labels')   {
00754         return htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:'.$Akey.'.'.$key));
00755     }
00756 
00757     /**
00758      * Creates GET parameters for linking to the export module.
00759      *
00760      * @return  string      GET parameters for current clipboard content to be exported.
00761      */
00762     function exportClipElementParameters()  {
00763 
00764             // Init:
00765         $pad = $this->current;
00766         $params = array();
00767         $params[] = 'tx_impexp[action]=export';
00768 
00769             // Traverse items:
00770         if (is_array($this->clipData[$pad]['el']))  {
00771             foreach ($this->clipData[$pad]['el'] as $k => $v) {
00772                 if ($v) {
00773                     list($table,$uid) = explode('|',$k);
00774 
00775                     if ($table=='_FILE')    {   // Rendering files/directories on the clipboard:
00776                         if (file_exists($v) && t3lib_div::isAllowedAbsPath($v)) {
00777                             $params[] = 'tx_impexp['.(is_dir($v) ? 'dir' : 'file').'][]='.rawurlencode($v);
00778                         }
00779                     } else {    // Rendering records:
00780                         $rec = t3lib_BEfunc::getRecord($table,$uid);
00781                         if (is_array($rec)) {
00782                             $params[] = 'tx_impexp[record][]='.rawurlencode($table.':'.$uid);
00783                         }
00784                     }
00785                 }
00786             }
00787         }
00788 
00789         return '?'.implode('&', $params);
00790     }
00791 
00792 
00793 
00794 
00795 
00796 
00797 
00798 
00799     /*****************************************
00800      *
00801      * Helper functions
00802      *
00803      ****************************************/
00804 
00805     /**
00806      * Removes element on clipboard
00807      *
00808      * @param   string      Key of element in ->clipData array
00809      * @return  void
00810      */
00811     function removeElement($el) {
00812         unset($this->clipData[$this->current]['el'][$el]);
00813         $this->changed=1;
00814     }
00815 
00816     /**
00817      * Saves the clipboard, no questions asked.
00818      * Use ->endClipboard normally (as it checks if changes has been done so saving is necessary)
00819      *
00820      * @return  void
00821      * @access private
00822      */
00823     function saveClipboard()    {
00824         global $BE_USER;
00825         $BE_USER->pushModuleData('clipboard',$this->clipData);
00826     }
00827 
00828     /**
00829      * Returns the current mode, 'copy' or 'cut'
00830      *
00831      * @return  string      "copy" or "cut"
00832      */
00833     function currentMode()  {
00834         return $this->clipData[$this->current]['mode']=='copy' ? 'copy' : 'cut';
00835     }
00836 
00837     /**
00838      * This traverses the elements on the current clipboard pane
00839      * and unsets elements which does not exist anymore or are disabled.
00840      *
00841      * @return  void
00842      */
00843     function cleanCurrent() {
00844         if (is_array($this->clipData[$this->current]['el']))    {
00845             foreach ($this->clipData[$this->current]['el'] as $k => $v) {
00846                 list($table,$uid) = explode('|',$k);
00847                 if ($table!='_FILE')    {
00848                     if (!$v || !is_array(t3lib_BEfunc::getRecord($table,$uid,'uid')))   {
00849                         unset($this->clipData[$this->current]['el'][$k]);
00850                         $this->changed=1;
00851                     }
00852                 } else {
00853                     if (!$v || !file_exists($v))    {
00854                         unset($this->clipData[$this->current]['el'][$k]);
00855                         $this->changed=1;
00856                     }
00857                 }
00858             }
00859         }
00860     }
00861 
00862     /**
00863      * Counts the number of elements from the table $matchTable. If $matchTable is blank, all tables (except '_FILE' of course) is counted.
00864      *
00865      * @param   string      Table to match/count for.
00866      * @param   string      $pad can optionally be used to set another pad than the current.
00867      * @return  array       Array with keys from the CB.
00868      */
00869     function elFromTable($matchTable='',$pad='')    {
00870         $pad = $pad ? $pad : $this->current;
00871         $list=array();
00872         if (is_array($this->clipData[$pad]['el']))  {
00873             foreach ($this->clipData[$pad]['el'] as $k => $v) {
00874                 if ($v) {
00875                     list($table,$uid) = explode('|',$k);
00876                     if ($table!='_FILE')    {
00877                         if ((!$matchTable || (string)$table==(string)$matchTable) && $GLOBALS['TCA'][$table])   {
00878                             $list[$k]= ($pad=='normal'?$v:$uid);
00879                         }
00880                     } else {
00881                         if ((string)$table==(string)$matchTable)    {
00882                             $list[$k]=$v;
00883                         }
00884                     }
00885                 }
00886             }
00887         }
00888         return $list;
00889     }
00890 
00891     /**
00892      * Verifies if the item $table/$uid is on the current pad.
00893      * 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...
00894      *
00895      * @param   string      Table name, (_FILE for files...)
00896      * @param   integer     Element uid (path for files)
00897      * @return  string
00898      */
00899     function isSelected($table,$uid)    {
00900         $k=$table.'|'.$uid;
00901         return $this->clipData[$this->current]['el'][$k] ? ($this->current=='normal'?$this->currentMode():1) : '';
00902     }
00903 
00904     /**
00905      * Returns item record $table,$uid if selected on current clipboard
00906      * If table and uid is blank, the first element is returned.
00907      * Makes sense only for DB records - not files!
00908      *
00909      * @param   string      Table name
00910      * @param   integer     Element uid
00911      * @return  array       Element record with extra field _RECORD_TITLE set to the title of the record...
00912      */
00913     function getSelectedRecord($table='',$uid='')   {
00914         if (!$table && !$uid)   {
00915             $elArr = $this->elFromTable('');
00916             reset($elArr);
00917             list($table,$uid) = explode('|',key($elArr));
00918         }
00919         if ($this->isSelected($table,$uid)) {
00920             $selRec = t3lib_BEfunc::getRecordWSOL($table,$uid);
00921             $selRec['_RECORD_TITLE'] = t3lib_BEfunc::getRecordTitle($table,$selRec);
00922             return $selRec;
00923         }
00924     }
00925 
00926     /**
00927      * Reports if the current pad has elements (does not check file/DB type OR if file/DBrecord exists or not. Only counting array)
00928      *
00929      * @return  boolean     True if elements exist.
00930      */
00931     function isElements()   {
00932         return is_array($this->clipData[$this->current]['el']) && count($this->clipData[$this->current]['el']);
00933     }
00934 
00935 
00936 
00937 
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 
00946 
00947 
00948 
00949     /*****************************************
00950      *
00951      * FOR USE IN tce_db.php:
00952      *
00953      ****************************************/
00954 
00955     /**
00956      * Applies the proper paste configuration in the $cmd array send to tce_db.php.
00957      * $ref is the target, see description below.
00958      * The current pad is pasted
00959      *
00960      *      $ref: [tablename]:[paste-uid].
00961      *      tablename is the name of the table from which elements *on the current clipboard* is pasted with the 'pid' paste-uid.
00962      *      No tablename means that all items on the clipboard (non-files) are pasted. This requires paste-uid to be positive though.
00963      *      so 'tt_content:-3'  means 'paste tt_content elements on the clipboard to AFTER tt_content:3 record
00964      *      'tt_content:30' means 'paste tt_content elements on the clipboard into page with id 30
00965      *      ':30'   means 'paste ALL database elements on the clipboard into page with id 30
00966      *      ':-30'  not valid.
00967      *
00968      * @param   string      [tablename]:[paste-uid], see description
00969      * @param   array       Command-array
00970      * @return  array       Modified Command-array
00971      */
00972     function makePasteCmdArray($ref,$CMD)   {
00973         list($pTable,$pUid) = explode('|',$ref);
00974         $pUid = intval($pUid);
00975 
00976         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)
00977             $elements = $this->elFromTable($pTable);
00978 
00979             $elements = array_reverse($elements);   // So the order is preserved.
00980             $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
00981 
00982                 // Traverse elements and make CMD array
00983             foreach ($elements as $tP => $value) {
00984                 list($table,$uid) = explode('|',$tP);
00985                 if (!is_array($CMD[$table]))    $CMD[$table]=array();
00986                 $CMD[$table][$uid][$mode]=$pUid;
00987                 if ($mode=='move')  $this->removeElement($tP);
00988             }
00989             $this->endClipboard();
00990         }
00991         return $CMD;
00992     }
00993 
00994     /**
00995      * Delete record entries in CMD array
00996      *
00997      * @param   array       Command-array
00998      * @return  array       Modified Command-array
00999      */
01000     function makeDeleteCmdArray($CMD)   {
01001         $elements = $this->elFromTable(''); // all records
01002         foreach ($elements as $tP => $value) {
01003             list($table,$uid) = explode('|',$tP);
01004             if (!is_array($CMD[$table]))    $CMD[$table]=array();
01005             $CMD[$table][$uid]['delete']=1;
01006             $this->removeElement($tP);
01007         }
01008         $this->endClipboard();
01009         return $CMD;
01010     }
01011 
01012 
01013 
01014 
01015 
01016 
01017 
01018 
01019 
01020 
01021 
01022 
01023 
01024 
01025 
01026 
01027 
01028     /*****************************************
01029      *
01030      * FOR USE IN tce_file.php:
01031      *
01032      ****************************************/
01033 
01034     /**
01035      * Applies the proper paste configuration in the $file array send to tce_file.php.
01036      * The current pad is pasted
01037      *
01038      * @param   string      Reference to element (splitted by "|")
01039      * @param   array       Command-array
01040      * @return  array       Modified Command-array
01041      */
01042     function makePasteCmdArray_file($ref,$FILE) {
01043         list($pTable,$pUid) = explode('|',$ref);
01044         $elements = $this->elFromTable('_FILE');
01045         $mode = $this->currentMode()=='copy' ? 'copy' : 'move';
01046 
01047             // Traverse elements and make CMD array
01048         foreach ($elements as $tP => $path) {
01049             $FILE[$mode][]=array('data'=>$path,'target'=>$pUid,'altName'=>1);
01050             if ($mode=='move')  $this->removeElement($tP);
01051         }
01052         $this->endClipboard();
01053 
01054         return $FILE;
01055     }
01056 
01057     /**
01058      * Delete files in CMD array
01059      *
01060      * @param   array       Command-array
01061      * @return  array       Modified Command-array
01062      */
01063     function makeDeleteCmdArray_file($FILE) {
01064         $elements = $this->elFromTable('_FILE');
01065             // Traverse elements and make CMD array
01066         foreach ($elements as $tP => $path) {
01067             $FILE['delete'][]=array('data'=>$path);
01068             $this->removeElement($tP);
01069         }
01070         $this->endClipboard();
01071 
01072         return $FILE;
01073     }
01074 }
01075 
01076 
01077 
01078 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']) {
01079     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']);
01080 }
01081 
01082 ?>

Generated on Sat Jul 24 04:17:16 2010 for TYPO3 API by  doxygen 1.4.7