Updating version number to 4.3-dev after release of 4.3.0RC1
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_clipboard.php
old mode 100755 (executable)
new mode 100644 (file)
index fbfae53..b82a1c0
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  *              SECTION: Clipboard HTML renderings
  *  306:     function printClipboard()
- *  408:     function printContentFromTab($pad)
- *  482:     function padTitleWrap($str,$pad)
- *  499:     function linkItemText($str,$rec,$table='')
- *  526:     function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())
- *  542:     function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())
- *  559:     function pasteUrl($table,$uid,$setRedirect=1)
- *  576:     function deleteUrl($setRedirect=1,$file=0)
- *  593:     function editUrl()
- *  614:     function removeUrl($table,$uid)
- *  627:     function confirmMsg($table,$rec,$type,$clElements)
- *  671:     function clLabel($key,$Akey='labels')
- *  680:     function exportClipElementParameters()
+ *  413:     function printContentFromTab($pad)
+ *  487:     function padTitleWrap($str,$pad)
+ *  504:     function linkItemText($str,$rec,$table='')
+ *  531:     function selUrlDB($table,$uid,$copy=0,$deselect=0,$baseArray=array())
+ *  547:     function selUrlFile($path,$copy=0,$deselect=0,$baseArray=array())
+ *  564:     function pasteUrl($table,$uid,$setRedirect=1)
+ *  581:     function deleteUrl($setRedirect=1,$file=0)
+ *  598:     function editUrl()
+ *  619:     function removeUrl($table,$uid)
+ *  632:     function confirmMsg($table,$rec,$type,$clElements)
+ *  680:     function clLabel($key,$Akey='labels')
+ *  689:     function exportClipElementParameters()
  *
  *              SECTION: Helper functions
- *  730:     function removeElement($el)
- *  742:     function saveClipboard()
- *  752:     function currentMode()
- *  762:     function cleanCurrent()
- *  789:     function elFromTable($matchTable='',$pad='')
- *  820:     function isSelected($table,$uid)
- *  834:     function getSelectedRecord($table='',$uid='')
- *  852:     function isElements()
+ *  739:     function removeElement($el)
+ *  751:     function saveClipboard()
+ *  761:     function currentMode()
+ *  771:     function cleanCurrent()
+ *  798:     function elFromTable($matchTable='',$pad='')
+ *  829:     function isSelected($table,$uid)
+ *  843:     function getSelectedRecord($table='',$uid='')
+ *  861:     function isElements()
  *
  *              SECTION: FOR USE IN tce_db.php:
- *  893:     function makePasteCmdArray($ref,$CMD)
- *  922:     function makeDeleteCmdArray($CMD)
+ *  902:     function makePasteCmdArray($ref,$CMD)
+ *  931:     function makeDeleteCmdArray($CMD)
  *
  *              SECTION: FOR USE IN tce_file.php:
- *  965:     function makePasteCmdArray_file($ref,$FILE)
- *  987:     function makeDeleteCmdArray_file($FILE)
+ *  974:     function makePasteCmdArray_file($ref,$FILE)
+ *  996:     function makeDeleteCmdArray_file($FILE)
  *
  * TOTAL FUNCTIONS: 31
  * (This index is automatically created/updated by the extension "extdeveval")
@@ -317,27 +317,41 @@ class t3lib_clipboard {
 
                        // Button/menu header:
                $thumb_url = t3lib_div::linkThisScript(array('CB'=>array('setThumb'=>$this->clipData['_setThumb']?0:1)));
-               $copymode_url = t3lib_div::linkThisScript(array('CB'=>array('setCopyMode'=>($this->currentMode()=='copy'?'':'copy'))));
                $rmall_url = t3lib_div::linkThisScript(array('CB'=>array('removeAll'=>$this->current)));
 
+                       // Copymode Selector menu
+               $copymode_url = t3lib_div::linkThisScript();
+               $moveLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:moveElements'));
+               $copyLabel = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:copyElements'));
+               $opt=array();
+               $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>';
+               $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>';
+
+               $copymode_selector = ' <select name="CB[setCopyMode]" onchange="this.form.method=\'POST\'; this.form.action=\''.$copymode_url.'&CB[setCopyMode]=\'+(this.options[this.selectedIndex].value); this.form.submit(); return true;" >'.implode('',$opt).'</select>';
+
                        // Selector menu + clear button
                $opt=array();
                $opt[]='<option value="" selected="selected">'.$this->clLabel('menu','rm').'</option>';
                                // Import / Export link:
                if ($elCount && t3lib_extMgm::isLoaded('impexp'))       {
-                       $opt[] = '<option value="'.htmlspecialchars("document.location='".$this->backPath.t3lib_extMgm::extRelPath('impexp').'app/index.php'.$this->exportClipElementParameters().'\';').'">'.$this->clLabel('export','rm').'</option>';
+                       $opt[] = '<option value="'.htmlspecialchars("window.location.href='".$this->backPath.'mod.php?M=xMOD_tximpexp'.$this->exportClipElementParameters().'\';').'">'.$this->clLabel('export','rm').'</option>';
                }
                                // Edit:
                if (!$this->fileMode && $elCount)       {
-                       $opt[]='<option value="'.htmlspecialchars("document.location='".$this->editUrl()."&returnUrl='+top.rawurlencode(document.location);").'">'.$this->clLabel('edit','rm').'</option>';
+                       $opt[]='<option value="' . htmlspecialchars("window.location.href='" . $this->editUrl() . "&returnUrl='+top.rawurlencode(window.location.href);") . '">' . $this->clLabel('edit', 'rm') . '</option>';
                }
                                // Delete:
                if ($elCount)   {
-                       $opt[]='<option value="'.htmlspecialchars("
+                       if($GLOBALS['BE_USER']->jsConfirmation(4))      {
+                               $js = "
                        if(confirm(".$GLOBALS['LANG']->JScharCode(sprintf($LANG->sL('LLL:EXT:lang/locallang_core.php:mess.deleteClip'),$elCount)).")){
-                               document.location='".$this->deleteUrl(0,$this->fileMode?1:0)."&redirect='+top.rawurlencode(document.location);
+                               window.location.href='" . $this->deleteUrl(0, $this->fileMode ? 1 : 0) . "&redirect='+top.rawurlencode(window.location.href);
+                       }
+                                       ";
+                       } else {
+                               $js = " window.location.href='" . $this->deleteUrl(0, $this->fileMode ? 1 : 0) . "&redirect='+top.rawurlencode(window.location.href); ";
                        }
-                       ").'">'.$this->clLabel('delete','rm').'</option>';
+                       $opt[]='<option value="'.htmlspecialchars($js).'">'.$this->clLabel('delete','rm').'</option>';
                }
                $selector_menu = '<select name="_clipMenu" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$opt).'</select>';
 
@@ -347,11 +361,11 @@ class t3lib_clipboard {
                                '<a href="'.htmlspecialchars($thumb_url).'#clip_head">'.
                                        '<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="" />'.
                                        '</a>'.
-                               '<a href="'.htmlspecialchars($copymode_url).'#clip_head">'.
-                                       '<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="" />'.
-                                       '</a>'.
                                '</td>
-                               <td width="95%">'.$selector_menu.'</td>
+                               <td width="95%" nowrap="nowrap">'.
+                                       $copymode_selector.' '.
+                                       $selector_menu.
+                               '</td>
                                <td>'.
                                '<a href="'.htmlspecialchars($rmall_url).'#clip_head">'.
                                        '<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="" />'.
@@ -417,7 +431,7 @@ class t3lib_clipboard {
                                        $bgColClass = ($table=='_FILE'&&$this->fileMode)||($table!='_FILE'&&!$this->fileMode) ? 'bgColor4-20' : 'bgColor4';
 
                                        if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
-                                               if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
+                                               if (file_exists($v) && t3lib_div::isAllowedAbsPath($v)) {
                                                        $fI = pathinfo($v);
                                                        $icon = is_dir($v) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
                                                        $size = ' ('.t3lib_div::formatSize(filesize($v)).'bytes)';
@@ -440,7 +454,7 @@ class t3lib_clipboard {
                                                        $this->changed=1;
                                                }
                                        } else {        // Rendering records:
-                                               $rec=t3lib_BEfunc::getRecord($table,$uid);
+                                               $rec=t3lib_BEfunc::getRecordWSOL($table,$uid);
                                                if (is_array($rec))     {
                                                        $lines[]='
                                                                <tr>
@@ -452,6 +466,12 @@ class t3lib_clipboard {
                                                                        '<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>'.
                                                                        '</td>
                                                                </tr>';
+
+                                                       $localizationData = $this->getLocalizations($table, $rec, $bgColClass, $pad);
+                                                       if ($localizationData) {
+                                                               $lines[] = $localizationData;
+                                                       }
+
                                                } else {
                                                        unset($this->clipData[$pad]['el'][$k]);
                                                        $this->changed=1;
@@ -472,6 +492,58 @@ class t3lib_clipboard {
                return $lines;
        }
 
+
+       /**
+        * Gets all localizations of the current record.
+        *
+        * @param       string          the table
+        * @param       array           the current record
+        * @return      string          HTML table rows
+        */
+       function getLocalizations($table, $parentRec, $bgColClass, $pad) {
+               $lines = array();
+               $tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
+
+               if ($table != 'pages' && t3lib_BEfunc::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
+                       $where = array();
+                       $where[] = $tcaCtrl['transOrigPointerField'] . '=' . intval($parentRec['uid']);
+                       $where[] = $tcaCtrl['languageField'] . '!=0';
+
+                       if (isset($tcaCtrl['delete']) && $tcaCtrl['delete']) {
+                               $where[] = $tcaCtrl['delete'] . '=0';
+                       }
+
+                       if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
+                               $where[] = 't3ver_wsid=' . $parentRec['t3ver_wsid'];
+                       }
+
+                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', $table, implode(' AND ', $where));
+
+                       if (is_array($rows)) {
+                               $modeData = '';
+                               if ($pad == 'normal') {
+                                       $mode = ($this->clipData['normal']['mode'] == 'copy' ? 'copy' : 'cut');
+                                       $modeData = ' <strong>(' . $this->clLabel($mode, 'cm') . ')</strong>';
+                               }
+
+                               foreach ($rows as $rec) {
+                                       $lines[]='
+                                       <tr>
+                                               <td class="' . $bgColClass . '">' .
+                                                       t3lib_iconWorks::getIconImage($table, $rec, $this->backPath,' style="margin-left: 38px;"') . '</td>
+                                               <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . htmlspecialchars(
+                                                               t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])) .
+                                                               $modeData . '&nbsp;</td>
+                                               <td class="' . $bgColClass . '" align="center" nowrap="nowrap">&nbsp;</td>
+                                       </tr>';
+                               }
+                       }
+               }
+               return implode('',$lines);
+       }
+
+
+
        /**
         * Wraps title of pad in bold-tags and maybe the number of elements if any.
         *
@@ -503,7 +575,7 @@ class t3lib_clipboard {
                        } else {
                                $str='<a href="'.htmlspecialchars($this->backPath.'db_list.php?id='.$rec['pid']).'">'.$str.'</a>';
                        }
-               } elseif (@file_exists($rec))   {
+               } elseif (file_exists($rec))    {
                        if (!$this->fileMode)   {
                                $str=$GLOBALS['TBE_TEMPLATE']->dfw($str);
                        } else {
@@ -625,6 +697,7 @@ class t3lib_clipboard {
         * @return      string          JavaScript "confirm" message
         */
        function confirmMsg($table,$rec,$type,$clElements)      {
+               if($GLOBALS['BE_USER']->jsConfirmation(2))      {
                $labelKey = 'LLL:EXT:lang/locallang_core.php:mess.'.($this->currentMode()=='copy'?'copy':'move').($this->current=='normal'?'':'cb').'_'.$type;
                $msg = $GLOBALS['LANG']->sL($labelKey);
 
@@ -658,6 +731,9 @@ class t3lib_clipboard {
                        t3lib_div::fixed_lgd_cs($selRecTitle,30),
                        t3lib_div::fixed_lgd_cs($thisRecTitle,30)
                        )).')';
+               } else {
+                       $conf = '';
+               }
                return $conf;
        }
 
@@ -692,7 +768,7 @@ class t3lib_clipboard {
                                        list($table,$uid) = explode('|',$k);
 
                                        if ($table=='_FILE')    {       // Rendering files/directories on the clipboard:
-                                               if (@file_exists($v) && t3lib_div::isAllowedAbsPath($v))        {
+                                               if (file_exists($v) && t3lib_div::isAllowedAbsPath($v)) {
                                                        $params[] = 'tx_impexp['.(is_dir($v) ? 'dir' : 'file').'][]='.rawurlencode($v);
                                                }
                                        } else {        // Rendering records:
@@ -705,7 +781,7 @@ class t3lib_clipboard {
                        }
                }
 
-               return '?'.implode('&', $params);
+               return '&'.implode('&', $params);
        }
 
 
@@ -770,7 +846,7 @@ class t3lib_clipboard {
                                                $this->changed=1;
                                        }
                                } else {
-                                       if (!$v || !@file_exists($v))   {
+                                       if (!$v || !file_exists($v))    {
                                                unset($this->clipData[$this->current]['el'][$k]);
                                                $this->changed=1;
                                        }
@@ -838,7 +914,7 @@ class t3lib_clipboard {
                        list($table,$uid) = explode('|',key($elArr));
                }
                if ($this->isSelected($table,$uid))     {
-                       $selRec = t3lib_BEfunc::getRecord($table,$uid);
+                       $selRec = t3lib_BEfunc::getRecordWSOL($table,$uid);
                        $selRec['_RECORD_TITLE'] = t3lib_BEfunc::getRecordTitle($table,$selRec);
                        return $selRec;
                }
@@ -970,7 +1046,7 @@ class t3lib_clipboard {
                        // Traverse elements and make CMD array
                reset($elements);
                while(list($tP,$path)=each($elements))  {
-                       $FILE[$mode][]=array('data'=>$path,'target'=>$pUid);
+                       $FILE[$mode][]=array('data'=>$path,'target'=>$pUid,'altName'=>1);
                        if ($mode=='move')      $this->removeElement($tP);
                }
                $this->endClipboard();
@@ -1003,4 +1079,5 @@ class t3lib_clipboard {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php'])        {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_clipboard.php']);
 }
+
 ?>