Fixed bug #17279: Old Contextmenu: Partly broken - Mount as TreeRoot / Hide / Unhide...
[Packages/TYPO3.CMS.git] / typo3 / alt_clickmenu.php
index 78997ce..e964508 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * If you want to integrate a context menu in your scripts, please see template::getContextMenuCode()
  *
  * $Id$
- * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -126,7 +126,7 @@ $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
 /**
  * Class for generating the click menu
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  * @internal
@@ -342,6 +342,10 @@ class clickMenu {
                        // Processing by external functions?
                $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
 
+               if (!is_array($this->rec)) {
+                       $this->rec = array();
+               }
+
                        // Return the printed elements:
                return $this->printItems($menuItems,
                        $root?
@@ -428,7 +432,7 @@ class clickMenu {
         * @return      string          JavaScript for an onClick event.
         */
        function urlRefForCM($url,$retUrl='',$hideCM=1,$overrideLoc='') {
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                $editOnClick= ($overrideLoc ? 'var docRef='.$overrideLoc : 'var docRef=(top.content.list_frame)?top.content.list_frame:'.$loc).'; docRef.location.href=top.TS.PATH_typo3+\''.$url.'\''.
                        ($retUrl ? "+'&" . $retUrl . "='+top.rawurlencode(" . $this->frameLocation('docRef.document') . ')' :'') . ';' .
                        ($hideCM ? 'return hideCM();' : '');
@@ -475,7 +479,7 @@ class clickMenu {
         */
        function DB_paste($table,$uid,$type,$elInfo)    {
                $editOnClick = '';
-               $loc = 'top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                if($GLOBALS['BE_USER']->jsConfirmation(2))      {
                $conf = $loc.' && confirm('.$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.'.($elInfo[2]=='copy'?'copy':'move').'_'.$type),$elInfo[0],$elInfo[1])).')';
                } else {
@@ -534,7 +538,10 @@ class clickMenu {
         * @internal
         */
        function DB_perms($table,$uid,$rec)     {
-               $url = 'mod/web/perm/index.php?id=' . $uid . ($rec['perms_userid'] == $GLOBALS['BE_USER']->user['uid'] || $GLOBALS['BE_USER']->isAdmin() ? '&return_id=' . $uid . '&edit=1' : '');
+               if (!t3lib_extMgm::isLoaded('perm')) {
+            return '';
+        }
+        $url = t3lib_extMgm::extRelPath('perm') . 'mod1/index.php?id=' . $uid . ($rec['perms_userid'] == $GLOBALS['BE_USER']->user['uid'] || $GLOBALS['BE_USER']->isAdmin() ? '&return_id=' . $uid . '&edit=1' : '');
                return $this->linkItem(
                        $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_perms')),
                        $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('status-status-locked')),
@@ -553,7 +560,10 @@ class clickMenu {
         * @internal
         */
        function DB_db_list($table,$uid,$rec)   {
-               $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_DIR') . 'db_list.php?table='.($table=='pages'? '' : $table) . '&id=' . ($table == 'pages' ? $uid : $rec['pid']);
+               $urlParams = array();
+               $urlParams['id'] = ($table == 'pages') ? $uid : $rec['pid'];
+               $urlParams['table'] = $table == 'pages' ? '' : $table;
+               $url = t3lib_BEfunc::getModuleUrl('web_list', $urlParams, '', TRUE);
                return $this->linkItem(
                        $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_db_list')),
                        $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-system-list-open')),
@@ -632,9 +642,10 @@ class clickMenu {
         * @param       integer         page uid to edit (PID)
         * @return      array           Item array, element in $menuItems
         * @internal
-        * @deprecated since TYPO3 4.0 - Use DB_editPageProperties instead
+        * @deprecated since TYPO3 4.0, will be removed in TYPO3 4.6 - Use DB_editPageProperties instead
         */
        function DB_editPageHeader($uid)        {
+               t3lib_div::logDeprecatedFunction();
                return $this->DB_editPageProperties($uid);
        }
 
@@ -670,7 +681,7 @@ class clickMenu {
                $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
 
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ? '.list_frame':'');
+               $loc = 'top.content.list_frame';
                $addParam='';
                $theIcon = 'actions-document-open';
                if (
@@ -707,7 +718,7 @@ class clickMenu {
         */
        function DB_new($table,$uid)    {
                $editOnClick='';
-               $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                $editOnClick='if('.$loc.'){'.$loc.".location.href=top.TS.PATH_typo3+'".
                        ($this->listFrame?
                                "alt_doc.php?returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'&edit[".$table."][-".$uid."]=new'":
@@ -732,7 +743,7 @@ class clickMenu {
         */
        function DB_delete($table,$uid,$elInfo) {
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                if($GLOBALS['BE_USER']->jsConfirmation(4))      {
                        $conf = "confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),$elInfo[0]) .
                                                t3lib_BEfunc::referenceCount($table,$uid,' (There are %s reference(s) to this record!)') .
@@ -742,7 +753,7 @@ class clickMenu {
                        $conf = '1==1';
                }
                $editOnClick = 'if(' . $loc . " && " . $conf . " ){" . $loc . ".location.href=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'".
-                       "&cmd[".$table.']['.$uid.'][delete]=1&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
+                       "&cmd[" . $table . '][' . $uid . '][delete]=1&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . "';}hideCM();top.nav.refresh.defer(500, top.nav);";
 
                return $this->linkItem(
                        $this->label('delete'),
@@ -778,7 +789,24 @@ class clickMenu {
                return $this->linkItem(
                        $this->label('tempMountPoint'),
                        $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('apps-pagetree-page-mountpoint')),
-                       "if (top.content.nav_frame) { top.content.nav_frame.location.href = 'alt_db_navframe.php?setTempDBmount=".intval($page_id)."'; } return hideCM();"
+                       "if (top.content.nav_frame) {
+                               var node = top.TYPO3.Backend.NavigationContainer.PageTree.getSelected();
+                               if (node === null) {
+                                       return false;
+                               }
+
+                               var useNode = {
+                                       attributes: {
+                                               nodeData: {
+                                                       id: " . intval($page_id) . "
+                                               }
+                                       }
+                               };
+
+                               node.ownerTree.commandProvider.mountAsTreeRoot(useNode, node.ownerTree);
+                        }
+                        return hideCM();
+                       "
                );
        }
 
@@ -809,9 +837,10 @@ class clickMenu {
        function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/')    {
                $uid = $rec['_ORIG_uid'] ? $rec['_ORIG_uid'] : $rec['uid'];
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                $editOnClick = 'if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'" .
-                       "&data[".$table.']['.$uid.']['.$flagField.']='.($rec[$flagField]?0:1).'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
+                       "&data[" . $table . '][' . $uid . '][' . $flagField . ']=' .
+                ($rec[$flagField] ? 0 : 1) . '&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . "';}hideCM();top.nav.refresh.defer(500, top.nav);";
 
                return $this->linkItem(
                        $title,
@@ -923,14 +952,14 @@ class clickMenu {
         * @internal
         */
        function FILE_launch($path,$script,$type,$image,$noReturnUrl=FALSE)     {
-               $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
+               $loc = 'top.content.list_frame';
 
                $editOnClick = 'if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'".$script.'?target=' . rawurlencode($path) . ($noReturnUrl ? "'" : "&returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")") . ";}";
 
                return $this->linkItem(
                        $this->label($type),
                        $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
-                       $editOnClick.'return hideCM();'
+                       $editOnClick . 'top.nav.refresh();return hideCM();'
                );
        }
 
@@ -946,14 +975,14 @@ class clickMenu {
                $type = 'upload';
                $image = 'upload.gif';
                if ($GLOBALS['BE_USER']->uc['enableFlashUploader']) {
-                       $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':'');
+                       $loc = 'top.content.list_frame';
 
                        $editOnClick = 'if (top.TYPO3.FileUploadWindow.isFlashAvailable()) { initFlashUploader("' . rawurlencode($path) . '"); } else if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'".$script.'?target=' . rawurlencode($path) . "';}";
 
                        return $this->linkItem(
                                $this->label($type),
                                $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
-                               $editOnClick.'return hideCM();'
+                               $editOnClick . 'return hideCM();'
                                );
                } else {
                        return $this->FILE_launch($path, $script, $type, $image, true);
@@ -996,14 +1025,14 @@ class clickMenu {
         */
        function FILE_delete($path)     {
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                if($GLOBALS['BE_USER']->jsConfirmation(4))      {
                        $conf = "confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),basename($path)).t3lib_BEfunc::referenceCount('_FILE',$path,' (There are %s reference(s) to this file!)')).")";
                } else {
                        $conf = '1==1';
                }
                $editOnClick = 'if(' . $loc . " && " . $conf . " ){" . $loc . ".location.href=top.TS.PATH_typo3+'tce_file.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'" .
-                       "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}";
+                       "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';}hideCM();";
 
                return $this->linkItem(
                        $this->label('delete'),
@@ -1023,7 +1052,7 @@ class clickMenu {
         */
        function FILE_paste($path,$target,$elInfo)      {
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                if($GLOBALS['BE_USER']->jsConfirmation(2))      {
                $conf=$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.'.($elInfo[2]=='copy'?'copy':'move').'_into'),$elInfo[0],$elInfo[1])).")";
                } else {
@@ -1031,7 +1060,7 @@ class clickMenu {
                }
 
                $editOnClick='if('.$conf.'){'.$loc.".location.href=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0).
-                       "&redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') .'); hideCM();}';
+                       "&redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') .'); }hideCM();top.nav.refresh();';
 
                return $this->linkItem(
                        $this->label('pasteinto'),
@@ -1089,7 +1118,7 @@ class clickMenu {
 
                        // Return the printed elements:
                return $this->printItems($menuItems,
-                       t3lib_iconWorks::getIconImage($table,$this->rec,$this->PH_backPath,' class="absmiddle" title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($this->rec,$table)).'"').t3lib_BEfunc::getRecordTitle($table,$this->rec,TRUE)
+                       t3lib_iconWorks::getSpriteIconForRecord($table,$this->rec,array('title'=> t3lib_BEfunc::getRecordTitle($table,$this->rec,TRUE)))
                );
        }
 
@@ -1118,9 +1147,9 @@ class clickMenu {
        function dragDrop_copymovepage($srcUid,$dstUid,$action,$into)   {
                $negativeSign = ($into == 'into') ? '' : '-';
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=top.TS.PATH_typo3+"tce_db.php?redirect="+top.rawurlencode(' . $this->frameLocation($loc . '.document') . ')+"' .
-                       '&cmd[pages]['.$srcUid.']['.$action.']='.$negativeSign.$dstUid.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode().'";hideCM();}';
+                       '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . '";}hideCM();top.nav.refresh();';
 
                return $this->linkItem(
                        $this->label($action.'Page_'.$into),
@@ -1142,9 +1171,9 @@ class clickMenu {
         */
        function dragDrop_copymovefolder($srcPath,$dstPath,$action)     {
                $editOnClick='';
-               $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':'');
+               $loc = 'top.content.list_frame';
                $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=top.TS.PATH_typo3+"tce_file.php?redirect="+top.rawurlencode(' . $this->frameLocation($loc . '.document') .')+"' .
-                       '&file['.$action.'][0][data]='.$srcPath.'&file['.$action.'][0][target]='.$dstPath.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode().'";hideCM();}';
+                       '&file['.$action.'][0][data]='.$srcPath.'&file['.$action.'][0][target]='.$dstPath.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode().'";}hideCM();top.nav.refresh();';
 
                return $this->linkItem(
                        $this->label($action.'Folder_into'),
@@ -1579,7 +1608,7 @@ class clickMenu {
 /**
  * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  * @see template::getContextMenuCode()
@@ -1742,6 +1771,7 @@ class SC_alt_clickmenu {
                        $this->content = $this->doc->insertStylesAndJS($this->content);
                        echo $this->content;
                } else {
+                       t3lib_formprotection_Factory::get()->persistTokens();
                        $this->content = $GLOBALS['LANG']->csConvObj->utf8_encode($this->content,$GLOBALS['LANG']->charSet);
                        t3lib_ajax::outputXMLreply($this->content);
                }
@@ -1749,8 +1779,8 @@ class SC_alt_clickmenu {
 }
 
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php'])        {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
 }