TYPO3 API  SVNRelease
alt_clickmenu.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (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  * Context menu
00029  *
00030  * The script is called in the top frame of the backend typically by a click on an icon for which a context menu should appear.
00031  * Either this script displays the context menu horizontally in the top frame or alternatively (default in MSIE, Mozilla) it writes the output to a <div>-layer in the calling document (which then appears as a layer/context sensitive menu)
00032  * Writing content back into a <div>-layer is necessary if we want individualized context menus with any specific content for any specific element.
00033  * Context menus can appear for either database elements or files
00034  * The input to this script is basically the "&init" var which is divided by "|" - each part is a reference to table|uid|listframe-flag.
00035  *
00036  * If you want to integrate a context menu in your scripts, please see template::getContextMenuCode()
00037  *
00038  * $Id: alt_clickmenu.php 10547 2011-02-22 20:03:57Z lolli $
00039  * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
00040  * XHTML compliant
00041  *
00042  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00043  */
00044 /**
00045  * [CLASS/FUNCTION INDEX of SCRIPT]
00046  *
00047  *
00048  *
00049  *  136: class clickMenu
00050  *  168:     function init()
00051  *  222:     function doDisplayTopFrameCM()
00052  *
00053  *              SECTION: DATABASE
00054  *  254:     function printDBClickMenu($table,$uid)
00055  *  346:     function printNewDBLevel($table,$uid)
00056  *  383:     function externalProcessingOfDBMenuItems($menuItems)
00057  *  395:     function processingByExtClassArray($menuItems,$table,$uid)
00058  *  414:     function urlRefForCM($url,$retUrl='',$hideCM=1)
00059  *  431:     function DB_copycut($table,$uid,$type)
00060  *  460:     function DB_paste($table,$uid,$type,$elInfo)
00061  *  485:     function DB_info($table,$uid)
00062  *  501:     function DB_history($table,$uid)
00063  *  520:     function DB_perms($table,$uid,$rec)
00064  *  539:     function DB_db_list($table,$uid,$rec)
00065  *  558:     function DB_moveWizard($table,$uid,$rec)
00066  *  579:     function DB_newWizard($table,$uid,$rec)
00067  *  602:     function DB_editAccess($table,$uid)
00068  *  621:     function DB_editPageHeader($uid)
00069  *  632:     function DB_editPageProperties($uid)
00070  *  650:     function DB_edit($table,$uid)
00071  *  692:     function DB_new($table,$uid)
00072  *  717:     function DB_delete($table,$uid,$elInfo)
00073  *  743:     function DB_view($id,$anchor='')
00074  *  758:     function DB_tempMountPoint($page_id)
00075  *  775:     function DB_hideUnhide($table,$rec,$hideField)
00076  *  790:     function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/')
00077  *
00078  *              SECTION: FILE
00079  *  824:     function printFileClickMenu($path)
00080  *  888:     function externalProcessingOfFileMenuItems($menuItems)
00081  *  902:     function FILE_launch($path,$script,$type,$image)
00082  *  922:     function FILE_copycut($path,$type)
00083  *  948:     function FILE_delete($path)
00084  *  975:     function FILE_paste($path,$target,$elInfo)
00085  *
00086  *              SECTION: DRAG AND DROP
00087  * 1012:     function printDragDropClickMenu($table,$srcId,$dstId)
00088  * 1054:     function externalProcessingOfDragDropMenuItems($menuItems)
00089  * 1069:     function dragDrop_copymovepage($srcUid,$dstUid,$action,$into)
00090  * 1094:     function dragDrop_copymovefolder($srcPath,$dstPath,$action)
00091  *
00092  *              SECTION: COMMON
00093  * 1130:     function printItems($menuItems,$item)
00094  * 1182:     function printLayerJScode($menuItems)
00095  * 1223:     function wrapColorTableCM($str)
00096  * 1246:     function menuItemsForTopFrame($menuItems)
00097  * 1263:     function menuItemsForClickMenu($menuItems)
00098  * 1301:     function addMenuItems($menuItems,$newMenuItems,$position='')
00099  * 1377:     function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0)
00100  * 1406:     function excludeIcon($iconCode)
00101  * 1416:     function enableDisableItems($menuItems)
00102  * 1454:     function cleanUpSpacers($menuItems)
00103  * 1496:     function label($label)
00104  * 1505:     function isCMlayers()
00105  * 1519:     function frameLocation($str)
00106  *
00107  *
00108  * 1544: class SC_alt_clickmenu
00109  * 1563:     function init()
00110  * 1663:     function main()
00111  * 1699:     function printContent()
00112  *
00113  * TOTAL FUNCTIONS: 51
00114  * (This index is automatically created/updated by the extension "extdeveval")
00115  *
00116  */
00117 
00118 
00119 require ('init.php');
00120 require ('template.php');
00121 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00122 
00123 
00124 
00125 
00126 /**
00127  * Class for generating the click menu
00128  *
00129  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00130  * @package TYPO3
00131  * @subpackage core
00132  * @internal
00133  */
00134 class clickMenu {
00135 
00136         // Internal, static: GPvar:
00137     var $cmLevel=0;             // Defines if the click menu is first level or second. Second means the click menu is triggered from another menu.
00138     var $CB;                    // Clipboard array (submitted by eg. pressing the paste button)
00139 
00140         // Internal, static:
00141     var $backPath='';           // Backpath for scripts/images.
00142     var $PH_backPath='###BACK_PATH###';     // BackPath place holder: We need different backPath set whether the clickmenu is written back to a frame which is not in typo3/ dir or if the clickmenu is shown in the top frame (no backpath)
00143     var $listFrame=0;           // If set, the calling document should be in the listframe of a frameset.
00144     var $isDBmenu=0;            // If set, the menu is about database records, not files. (set if part 2 [1] of the item-var is NOT blank)
00145     var $alwaysContentFrame=0;  // If true, the "content" frame is always used for reference (when condensed mode is enabled)
00146     var $iParts=array();        // Stores the parts of the input $item string, splitted by "|": [0] = table/file, [1] = uid/blank, [2] = flag: If set, listFrame, If "2" then "content frame" is forced  [3] = ("+" prefix = disable all by default, enable these. Default is to disable) Items key list
00147     var $disabledItems=array(); // Contains list of keywords of items to disable in the menu
00148     var $dontDisplayTopFrameCM=0;   // If true, the context sensitive menu will not appear in the top frame, only as a layer.
00149     var $leftIcons=0;           // If true, Show icons on the left.
00150     var $extClassArray=array();     // Array of classes to be used for user processing of the menu content. This is for the API of adding items to the menu from outside.
00151     var $ajax=0; // enable/disable ajax behavior
00152 
00153         // Internal, dynamic:
00154     var $elCount=0;             // Counter for elements in the menu. Used to number the name / id of the mouse-over icon.
00155     var $editPageIconSet=0;     // Set, when edit icon is drawn.
00156     var $editOK=0;              // Set to true, if editing of the element is OK.
00157     var $rec=array();
00158 
00159 
00160 
00161     /**
00162      * Initialize click menu
00163      *
00164      * @return  string      The clickmenu HTML content
00165      */
00166     function init() {
00167             // Setting GPvars:
00168         $this->cmLevel = intval(t3lib_div::_GP('cmLevel'));
00169         $this->CB = t3lib_div::_GP('CB');
00170         if(t3lib_div::_GP('ajax'))  {
00171             $this->ajax = 1;
00172             // XML has to be parsed, no parse errors allowed
00173             @ini_set('display_errors', 0);
00174         }
00175 
00176             // Deal with Drag&Drop context menus
00177         if (strcmp(t3lib_div::_GP('dragDrop'),''))  {
00178             $CMcontent = $this->printDragDropClickMenu(t3lib_div::_GP('dragDrop'),t3lib_div::_GP('srcId'),t3lib_div::_GP('dstId'));
00179             return $CMcontent;
00180         }
00181 
00182             // can be set differently as well
00183         $this->iParts[0] = t3lib_div::_GP('table');
00184         $this->iParts[1] = t3lib_div::_GP('uid');
00185         $this->iParts[2] = t3lib_div::_GP('listFr');
00186         $this->iParts[3] = t3lib_div::_GP('enDisItems');
00187 
00188             // Setting flags:
00189         if ($this->iParts[2])   $this->listFrame=1;
00190         if ($GLOBALS['BE_USER']->uc['condensedMode'] || $this->iParts[2]==2) $this->alwaysContentFrame=1;
00191         if (strcmp($this->iParts[1],''))    $this->isDBmenu=1;
00192 
00193         $TSkey =($this->isDBmenu?'page':'folder').($this->listFrame?'List':'Tree');
00194         $this->disabledItems = t3lib_div::trimExplode(',',$GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.'.$TSkey.'.disableItems'),1);
00195         $this->leftIcons = $GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.leftIcons');
00196 
00197             // &cmLevel flag detected (2nd level menu)
00198         if (!$this->cmLevel)    {
00199                 // Make 1st level clickmenu:
00200             if ($this->isDBmenu)    {
00201                 $CMcontent = $this->printDBClickMenu($this->iParts[0],$this->iParts[1]);
00202             } else {
00203                 $CMcontent = $this->printFileClickMenu($this->iParts[0]);
00204             }
00205         } else {
00206                 // Make 2nd level clickmenu (only for DBmenus)
00207             if ($this->isDBmenu)    {
00208                 $CMcontent = $this->printNewDBLevel($this->iParts[0],$this->iParts[1]);
00209             }
00210         }
00211 
00212             // Return clickmenu content:
00213         return $CMcontent;
00214     }
00215 
00216     /**
00217      * Returns true if the menu should (also?) be displayed in topframe, not just <div>-layers
00218      *
00219      * @return  boolean
00220      */
00221     function doDisplayTopFrameCM()  {
00222         if($this->ajax) {
00223             return false;
00224         } else {
00225             return !$GLOBALS['SOBE']->doc->isCMlayers() || !$this->dontDisplayTopFrameCM;
00226         }
00227     }
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240     /***************************************
00241      *
00242      * DATABASE
00243      *
00244      ***************************************/
00245 
00246     /**
00247      * Make 1st level clickmenu:
00248      *
00249      * @param   string      Table name
00250      * @param   integer     UID for the current record.
00251      * @return  string      HTML content
00252      */
00253     function printDBClickMenu($table,$uid)  {
00254         global $TCA, $BE_USER;
00255 
00256             // Get record:
00257         $this->rec = t3lib_BEfunc::getRecordWSOL($table,$uid);
00258         $menuItems=array();
00259 
00260         $root=0;
00261         $DBmount = FALSE;
00262         if ($table=='pages' && !strcmp($uid,'0'))   {   // Rootlevel
00263             $root=1;
00264         }
00265 
00266         if ($table=='pages' && in_array($uid,$GLOBALS['BE_USER']->returnWebmounts()))   {   // DB mount
00267             $DBmount = TRUE;
00268         }
00269             // used to hide cut,copy icons for l10n-records
00270         $l10nOverlay = false;
00271             // should only be performed for overlay-records within the same table
00272         if (t3lib_BEfunc::isTableLocalizable($table) && !isset($TCA[$table]['ctrl']['transOrigPointerTable'])) {
00273             $l10nOverlay = intval($this->rec[$TCA[$table]['ctrl']['transOrigPointerField']]) != 0;
00274         }
00275 
00276             // If record found (or root), go ahead and fill the $menuItems array which will contain data for the elements to render.
00277         if (is_array($this->rec) || $root)  {
00278 
00279                 // Get permissions
00280             $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid'])));
00281 
00282                 // View
00283             if (!in_array('view',$this->disabledItems)) {
00284                 if ($table=='pages')    $menuItems['view']=$this->DB_view($uid);
00285                 if ($table==$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) {
00286                     $ws_rec = t3lib_BEfunc::getRecordWSOL($table, $this->rec['uid']);
00287                     $menuItems['view']=$this->DB_view($ws_rec['pid']);
00288                 }
00289             }
00290 
00291                 // Edit:
00292             if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent')))   {
00293                 if (!in_array('edit',$this->disabledItems))     $menuItems['edit']=$this->DB_edit($table,$uid);
00294                 $this->editOK=1;
00295             }
00296 
00297                 // New:
00298             if (!in_array('new',$this->disabledItems) && $BE_USER->isPSet($lCP,$table,'new'))   $menuItems['new']=$this->DB_new($table,$uid);
00299 
00300                 // Info:
00301             if(!in_array('info',$this->disabledItems) && !$root)    $menuItems['info']=$this->DB_info($table,$uid);
00302 
00303             $menuItems['spacer1']='spacer';
00304 
00305                 // Copy:
00306             if (!in_array('copy', $this->disabledItems) && !$root && !$DBmount && !$l10nOverlay)    $menuItems['copy'] = $this->DB_copycut($table, $uid, 'copy');
00307                 // Cut:
00308             if (!in_array('cut', $this->disabledItems) && !$root && !$DBmount && !$l10nOverlay) $menuItems['cut'] = $this->DB_copycut($table, $uid, 'cut');
00309 
00310                 // Paste:
00311             $elFromAllTables = count($this->clipObj->elFromTable(''));
00312             if (!in_array('paste',$this->disabledItems) && $elFromAllTables)    {
00313                 $selItem = $this->clipObj->getSelectedRecord();
00314                 $elInfo=array(
00315                     t3lib_div::fixed_lgd_cs($selItem['_RECORD_TITLE'],$BE_USER->uc['titleLen']),
00316                     ($root?$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']:t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$this->rec),$BE_USER->uc['titleLen'])),
00317                     $this->clipObj->currentMode()
00318                 );
00319                 if ($table=='pages' && ($lCP & 8))  {
00320                     if ($elFromAllTables)   $menuItems['pasteinto']=$this->DB_paste('',$uid,'into',$elInfo);
00321                 }
00322 
00323                 $elFromTable = count($this->clipObj->elFromTable($table));
00324                 if (!$root && !$DBmount && $elFromTable  && $TCA[$table]['ctrl']['sortby']) $menuItems['pasteafter']=$this->DB_paste($table,-$uid,'after',$elInfo);
00325             }
00326 
00327                 // Delete:
00328             $elInfo=array(t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$this->rec),$BE_USER->uc['titleLen']));
00329             if(!in_array('delete',$this->disabledItems) && !$root && !$DBmount && $BE_USER->isPSet($lCP,$table,'delete'))   {
00330                 $menuItems['spacer2']='spacer';
00331                 $menuItems['delete']=$this->DB_delete($table,$uid,$elInfo);
00332             }
00333 
00334             if(!in_array('history',$this->disabledItems))   {
00335                 $menuItems['history']=$this->DB_history($table,$uid,$elInfo);
00336             }
00337         }
00338 
00339             // Adding external elements to the menuItems array
00340         $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid);
00341 
00342             // Processing by external functions?
00343         $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
00344 
00345         if (!is_array($this->rec)) {
00346             $this->rec = array();
00347         }
00348 
00349             // Return the printed elements:
00350         return $this->printItems($menuItems,
00351             $root?
00352             t3lib_iconWorks::getSpriteIcon('apps-pagetree-root') . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) :
00353             t3lib_iconWorks::getSpriteIconForRecord($table, $this->rec, array('title'=> htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($this->rec, $table)))) . t3lib_BEfunc::getRecordTitle($table, $this->rec, TRUE)
00354         );
00355     }
00356 
00357     /**
00358      * Make 2nd level clickmenu (only for DBmenus)
00359      *
00360      * @param   string      Table name
00361      * @param   integer     UID for the current record.
00362      * @return  string      HTML content
00363      */
00364     function printNewDBLevel($table,$uid)   {
00365         global $TCA, $BE_USER;
00366 
00367             // Setting internal record to the table/uid :
00368         $this->rec = t3lib_BEfunc::getRecordWSOL($table,$uid);
00369         $menuItems=array();
00370         $root=0;
00371         if ($table=='pages' && !strcmp($uid,'0'))   {   // Rootlevel
00372             $root=1;
00373         }
00374 
00375             // If record was found, check permissions and get menu items.
00376         if (is_array($this->rec) || $root)  {
00377             $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid'])));
00378                 // Edit:
00379             if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent')))   {
00380                 $this->editOK=1;
00381             }
00382 
00383             $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid);
00384         }
00385 
00386             // Return the printed elements:
00387         if (!is_array($menuItems))  $menuItems=array();
00388         return $this->printItems($menuItems,
00389             $root?
00390             t3lib_iconWorks::getSpriteIcon('apps-pagetree-root') . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']):
00391             t3lib_iconWorks::getSpriteIconForRecord($table, $this->rec,
00392                 array('title' => htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($this->rec, $table)))) .
00393                 t3lib_BEfunc::getRecordTitle($table, $this->rec, TRUE)
00394         );
00395     }
00396 
00397     /**
00398      * Processing the $menuItems array (for extension classes) (DATABASE RECORDS)
00399      *
00400      * @param   array       $menuItems array for manipulation.
00401      * @return  array       Processed $menuItems array
00402      */
00403     function externalProcessingOfDBMenuItems($menuItems)    {
00404         return $menuItems;
00405     }
00406 
00407     /**
00408      * Processing the $menuItems array by external classes (typ. adding items)
00409      *
00410      * @param   array       $menuItems array for manipulation.
00411      * @param   string      Table name
00412      * @param   integer     UID for the current record.
00413      * @return  array       Processed $menuItems array
00414      */
00415     function processingByExtClassArray($menuItems,$table,$uid)  {
00416         if (is_array($this->extClassArray)) {
00417             foreach ($this->extClassArray as $conf) {
00418                 $obj=t3lib_div::makeInstance($conf['name']);
00419                 $menuItems = $obj->main($this,$menuItems,$table,$uid);
00420             }
00421         }
00422         return $menuItems;
00423     }
00424 
00425     /**
00426      * Returning JavaScript for the onClick event linking to the input URL.
00427      *
00428      * @param   string      The URL relative to TYPO3_mainDir
00429      * @param   string      The return_url-parameter
00430      * @param   boolean     If set, the "hideCM()" will be called
00431      * @param   string      If set, gives alternative location to load in (for example top frame or somewhere else)
00432      * @return  string      JavaScript for an onClick event.
00433      */
00434     function urlRefForCM($url,$retUrl='',$hideCM=1,$overrideLoc='') {
00435         $loc = 'top.content.list_frame';
00436         $editOnClick= ($overrideLoc ? 'var docRef='.$overrideLoc : 'var docRef=(top.content.list_frame)?top.content.list_frame:'.$loc).'; docRef.location.href=top.TS.PATH_typo3+\''.$url.'\''.
00437             ($retUrl ? "+'&" . $retUrl . "='+top.rawurlencode(" . $this->frameLocation('docRef.document') . ')' :'') . ';' .
00438             ($hideCM ? 'return hideCM();' : '');
00439         return $editOnClick;
00440     }
00441 
00442     /**
00443      * Adding CM element for Clipboard "copy" and "cut"
00444      *
00445      * @param   string      Table name
00446      * @param   integer     UID for the current record.
00447      * @param   string      Type: "copy" or "cut"
00448      * @return  array       Item array, element in $menuItems
00449      * @internal
00450      */
00451     function DB_copycut($table,$uid,$type)  {
00452         if ($this->clipObj->current=='normal')  {
00453             $isSel = $this->clipObj->isSelected($table,$uid);
00454         }
00455 
00456         $addParam = array();
00457         if ($this->listFrame)   {
00458             $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
00459         }
00460 
00461         return $this->linkItem(
00462             $this->label($type),
00463             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''))),
00464             "top.loadTopMenu('" . $this->clipObj->selUrlDB($table, $uid, ($type == 'copy' ? 1: 0), ($isSel==$type), $addParam) . "');return false;"
00465         );
00466     }
00467 
00468     /**
00469      * Adding CM element for Clipboard "paste into"/"paste after"
00470      * NOTICE: $table and $uid should follow the special syntax for paste, see clipboard-class :: pasteUrl();
00471      *
00472      * @param   string      Table name
00473      * @param   integer     UID for the current record. NOTICE: Special syntax!
00474      * @param   string      Type: "into" or "after"
00475      * @param   array       Contains instructions about whether to copy or cut an element.
00476      * @return  array       Item array, element in $menuItems
00477      * @see t3lib_clipboard::pasteUrl()
00478      * @internal
00479      */
00480     function DB_paste($table,$uid,$type,$elInfo)    {
00481         $editOnClick = '';
00482         $loc = 'top.content.list_frame';
00483         if($GLOBALS['BE_USER']->jsConfirmation(2))  {
00484         $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])).')';
00485         } else {
00486             $conf = $loc;
00487         }
00488         $editOnClick = 'if(' . $conf . '){' . $loc . '.location.href=top.TS.PATH_typo3+\'' . $this->clipObj->pasteUrl($table, $uid, 0) . '&redirect=\'+top.rawurlencode(' . $this->frameLocation($loc . '.document') . '); hideCM();}';
00489 
00490         return $this->linkItem(
00491             $this->label('paste'.$type),
00492             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-paste-' . $type)),
00493             $editOnClick.'return false;'
00494         );
00495     }
00496 
00497     /**
00498      * Adding CM element for Info
00499      *
00500      * @param   string      Table name
00501      * @param   integer     UID for the current record.
00502      * @return  array       Item array, element in $menuItems
00503      * @internal
00504      */
00505     function DB_info($table,$uid)   {
00506         return $this->linkItem(
00507             $this->label('info'),
00508             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-info')),
00509             "top.launchView('".$table."', '".$uid."'); return hideCM();"
00510         );
00511     }
00512 
00513     /**
00514      * Adding CM element for History
00515      *
00516      * @param   string      Table name
00517      * @param   integer     UID for the current record.
00518      * @return  array       Item array, element in $menuItems
00519      * @internal
00520      */
00521     function DB_history($table,$uid)    {
00522         $url = 'show_rechis.php?element='.rawurlencode($table.':'.$uid);
00523         return $this->linkItem(
00524             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_history')),
00525             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-history-open')),
00526             $this->urlRefForCM($url,'returnUrl'),
00527             0
00528         );
00529     }
00530 
00531     /**
00532      * Adding CM element for Permission setting
00533      *
00534      * @param   string      Table name
00535      * @param   integer     UID for the current record.
00536      * @param   array       The "pages" record with "perms_*" fields inside.
00537      * @return  array       Item array, element in $menuItems
00538      * @internal
00539      */
00540     function DB_perms($table,$uid,$rec) {
00541         if (!t3lib_extMgm::isLoaded('perm')) {
00542             return '';
00543         }
00544         $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' : '');
00545         return $this->linkItem(
00546             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_perms')),
00547             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('status-status-locked')),
00548             $this->urlRefForCM($url),
00549             0
00550         );
00551     }
00552 
00553     /**
00554      * Adding CM element for DBlist
00555      *
00556      * @param   string      Table name
00557      * @param   integer     UID for the current record.
00558      * @param   array       Record of the element (needs "pid" field if not pages-record)
00559      * @return  array       Item array, element in $menuItems
00560      * @internal
00561      */
00562     function DB_db_list($table,$uid,$rec)   {
00563         $urlParams = array();
00564         $urlParams['id'] = ($table == 'pages') ? $uid : $rec['pid'];
00565         $urlParams['table'] = $table == 'pages' ? '' : $table;
00566         $url = t3lib_BEfunc::getModuleUrl('web_list', $urlParams, '', TRUE);
00567         return $this->linkItem(
00568             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_db_list')),
00569             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-system-list-open')),
00570             "top.nextLoadModuleUrl='".$url."';top.goToModule('web_list',1);",
00571             0
00572         );
00573     }
00574 
00575     /**
00576      * Adding CM element for Moving wizard
00577      *
00578      * @param   string      Table name
00579      * @param   integer     UID for the current record.
00580      * @param   array       Record. Needed for tt-content elements which will have the sys_language_uid sent
00581      * @return  array       Item array, element in $menuItems
00582      * @internal
00583      */
00584     function DB_moveWizard($table,$uid,$rec)    {
00585         $url = 'move_el.php?table=' . $table . '&uid=' . $uid .
00586                 ($table=='tt_content' ? '&sys_language_uid=' . intval($rec['sys_language_uid']) : '');  // Hardcoded field for tt_content elements.
00587 
00588         return $this->linkItem(
00589             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_moveWizard' . ($table=='pages' ? '_page' : ''))),
00590             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-' . ($table === 'pages' ? 'page' : 'document' ) . '-move')),
00591             $this->urlRefForCM($url,'returnUrl'),
00592             0
00593         );
00594     }
00595 
00596     /**
00597      * Adding CM element for Create new wizard (either db_new.php or sysext/cms/layout/db_new_content_el.php or custom wizard)
00598      *
00599      * @param   string      Table name
00600      * @param   integer     UID for the current record.
00601      * @param   array       Record.
00602      * @return  array       Item array, element in $menuItems
00603      * @internal
00604      */
00605     function DB_newWizard($table,$uid,$rec) {
00606             //  If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's create new content wizard instead:
00607         $tmpTSc = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
00608         $tmpTSc = $tmpTSc ['properties']['newContentWiz.']['overrideWithExtension'];
00609         $newContentWizScriptPath = t3lib_extMgm::isLoaded($tmpTSc) ? (t3lib_extMgm::extRelPath($tmpTSc).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
00610 
00611         $url = ($table=='pages' || !t3lib_extMgm::isLoaded('cms')) ? 'db_new.php?id='.$uid.'&pagesOnly=1' : $newContentWizScriptPath.'?id='.$rec['pid'].'&sys_language_uid='.intval($rec['sys_language_uid']);
00612         return $this->linkItem(
00613             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_newWizard')),
00614             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-' . ($table === 'pages' ? 'page' : 'document' ) . '-new')),
00615             $this->urlRefForCM($url,'returnUrl'),
00616             0
00617         );
00618     }
00619 
00620     /**
00621      * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups)
00622      *
00623      * @param   string      Table name
00624      * @param   integer     UID for the current record.
00625      * @return  array       Item array, element in $menuItems
00626      * @internal
00627      */
00628     function DB_editAccess($table,$uid) {
00629         $addParam='&columnsOnly='.rawurlencode(implode(',',$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']).($table=='pages' ? ',extendToSubpages' :''));
00630         $url = 'alt_doc.php?edit['.$table.']['.$uid.']=edit'.$addParam;
00631         return $this->linkItem(
00632             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editAccess')),
00633             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-edit-access')),
00634             $this->urlRefForCM($url,'returnUrl'),
00635             1   // no top frame CM!
00636         );
00637     }
00638 
00639     /**
00640      * Adding CM element for edit page properties
00641      *
00642      * @param   integer     page uid to edit (PID)
00643      * @return  array       Item array, element in $menuItems
00644      * @internal
00645      */
00646     function DB_editPageProperties($uid)    {
00647         $url = 'alt_doc.php?edit[pages]['.$uid.']=edit';
00648         return $this->linkItem(
00649             $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editPageProperties')),
00650             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-page-open')),
00651             $this->urlRefForCM($url,'returnUrl'),
00652             1   // no top frame CM!
00653         );
00654     }
00655 
00656     /**
00657      * Adding CM element for regular editing of the element!
00658      *
00659      * @param   string      Table name
00660      * @param   integer     UID for the current record.
00661      * @return  array       Item array, element in $menuItems
00662      * @internal
00663      */
00664     function DB_edit($table,$uid)   {
00665         global $BE_USER;
00666             // If another module was specified, replace the default Page module with the new one
00667         $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
00668         $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00669 
00670         $editOnClick='';
00671         $loc = 'top.content.list_frame';
00672         $addParam='';
00673         $theIcon = 'actions-document-open';
00674         if (
00675                 $this->iParts[0]=='pages' &&
00676                 $this->iParts[1] &&
00677                 $BE_USER->check('modules', $pageModule)
00678             )   {
00679             $theIcon = 'actions-page-open';
00680             $this->editPageIconSet=1;
00681             if ($BE_USER->uc['classicPageEditMode'] || !t3lib_extMgm::isLoaded('cms'))  {
00682                 $addParam='&editRegularContentFromId='.intval($this->iParts[1]);
00683             } else {
00684                 $editOnClick='if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'alt_doc.php?returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'&edit[".$table."][".$uid."]=edit".$addParam."';}";
00685             }
00686         }
00687         if (!$editOnClick)  {
00688             $editOnClick='if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'alt_doc.php?returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'&edit[".$table."][".$uid."]=edit".$addParam."';}";
00689         }
00690 
00691         return $this->linkItem(
00692             $this->label('edit'),
00693             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon($theIcon)),
00694             $editOnClick.'return hideCM();'
00695         );
00696     }
00697 
00698     /**
00699      * Adding CM element for regular Create new element
00700      *
00701      * @param   string      Table name
00702      * @param   integer     UID for the current record.
00703      * @return  array       Item array, element in $menuItems
00704      * @internal
00705      */
00706     function DB_new($table,$uid)    {
00707         $editOnClick='';
00708         $loc = 'top.content.list_frame';
00709         $editOnClick='if('.$loc.'){'.$loc.".location.href=top.TS.PATH_typo3+'".
00710             ($this->listFrame?
00711                 "alt_doc.php?returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'&edit[".$table."][-".$uid."]=new'":
00712                 'db_new.php?id='.intval($uid)."'").
00713             ';}';
00714 
00715         return $this->linkItem(
00716             $this->label('new'),
00717             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-' . ($table === 'pages' ? 'page' : 'document' ) . '-new')),
00718             $editOnClick.'return hideCM();'
00719         );
00720     }
00721 
00722     /**
00723      * Adding CM element for Delete
00724      *
00725      * @param   string      Table name
00726      * @param   integer     UID for the current record.
00727      * @param   array       Label for including in the confirmation message, EXT:lang/locallang_core.php:mess.delete
00728      * @return  array       Item array, element in $menuItems
00729      * @internal
00730      */
00731     function DB_delete($table,$uid,$elInfo) {
00732         $editOnClick='';
00733         $loc = 'top.content.list_frame';
00734         if($GLOBALS['BE_USER']->jsConfirmation(4))  {
00735             $conf = "confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),$elInfo[0]) .
00736                         t3lib_BEfunc::referenceCount($table,$uid,' (There are %s reference(s) to this record!)') .
00737                         t3lib_BEfunc::translationCount($table, $uid, ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.translationsOfRecord'))
00738                     ) . ")";
00739         } else {
00740             $conf = '1==1';
00741         }
00742         $editOnClick = 'if(' . $loc . " && " . $conf . " ){" . $loc . ".location.href=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'".
00743             "&cmd[" . $table . '][' . $uid . '][delete]=1&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . "';}hideCM();top.nav.refresh.defer(500, top.nav);";
00744 
00745         return $this->linkItem(
00746             $this->label('delete'),
00747             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-delete')),
00748             $editOnClick.'return false;'
00749         );
00750     }
00751 
00752     /**
00753      * Adding CM element for View Page
00754      *
00755      * @param   integer     Page uid (PID)
00756      * @param   string      Anchor, if any
00757      * @return  array       Item array, element in $menuItems
00758      * @internal
00759      */
00760     function DB_view($id,$anchor='')    {
00761         return $this->linkItem(
00762             $this->label('view'),
00763             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-view')),
00764             t3lib_BEfunc::viewOnClick($id,$this->PH_backPath,t3lib_BEfunc::BEgetRootLine($id),$anchor).'return hideCM();'
00765         );
00766     }
00767 
00768     /**
00769      * Adding element for setting temporary mount point.
00770      *
00771      * @param   integer     Page uid (PID)
00772      * @return  array       Item array, element in $menuItems
00773      * @internal
00774      */
00775     function DB_tempMountPoint($page_id)    {
00776         return $this->linkItem(
00777             $this->label('tempMountPoint'),
00778             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('apps-pagetree-page-mountpoint')),
00779             "if (top.content.nav_frame) {
00780                 var node = top.TYPO3.Backend.NavigationContainer.PageTree.getSelected();
00781                 if (node === null) {
00782                     return false;
00783                 }
00784 
00785                 var useNode = {
00786                     attributes: {
00787                         nodeData: {
00788                             id: " . intval($page_id) . "
00789                         }
00790                     }
00791                 };
00792 
00793                 node.ownerTree.commandProvider.mountAsTreeRoot(useNode, node.ownerTree);
00794              }
00795              return hideCM();
00796             "
00797         );
00798     }
00799 
00800     /**
00801      * Adding CM element for hide/unhide of the input record
00802      *
00803      * @param   string      Table name
00804      * @param   array       Record array
00805      * @param   string      Name of the hide field
00806      * @return  array       Item array, element in $menuItems
00807      * @internal
00808      */
00809     function DB_hideUnhide($table,$rec,$hideField)  {
00810         return $this->DB_changeFlag($table, $rec, $hideField, $this->label(($rec[$hideField]?'un':'').'hide'), 'hide');
00811     }
00812 
00813     /**
00814      * Adding CM element for a flag field of the input record
00815      *
00816      * @param   string      Table name
00817      * @param   array       Record array
00818      * @param   string      Name of the flag field
00819      * @param   string      Menu item Title
00820      * @param   string      Name of the item used for icons and labels
00821      * @param   string      Icon path relative to typo3/ folder
00822      * @return  array       Item array, element in $menuItems
00823      */
00824     function DB_changeFlag($table, $rec, $flagField, $title, $name, $iconRelPath='gfx/')    {
00825         $uid = $rec['_ORIG_uid'] ? $rec['_ORIG_uid'] : $rec['uid'];
00826         $editOnClick='';
00827         $loc = 'top.content.list_frame';
00828         $editOnClick = 'if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'" .
00829             "&data[" . $table . '][' . $uid . '][' . $flagField . ']=' .
00830                 ($rec[$flagField] ? 0 : 1) . '&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . "';}hideCM();top.nav.refresh.defer(500, top.nav);";
00831 
00832         return $this->linkItem(
00833             $title,
00834             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-' . ( $rec[$flagField] ? 'un' : '') . 'hide')),
00835             $editOnClick.'return false;',
00836             1
00837         );
00838     }
00839 
00840 
00841 
00842 
00843 
00844 
00845 
00846 
00847     /***************************************
00848      *
00849      * FILE
00850      *
00851      ***************************************/
00852 
00853     /**
00854      * Make 1st level clickmenu:
00855      *
00856      * @param   string      The absolute path
00857      * @return  string      HTML content
00858      */
00859     function printFileClickMenu($path)  {
00860         $menuItems=array();
00861 
00862         if (file_exists($path) && t3lib_div::isAllowedAbsPath($path))   {
00863             $fI = pathinfo($path);
00864             $size=' ('.t3lib_div::formatSize(filesize($path)).'bytes)';
00865             $icon = t3lib_iconWorks::getSpriteIconForFile(is_dir($path) ? 'folder' : strtolower($fI['extension']),
00866                 array('class'=>'absmiddle', 'title' => htmlspecialchars($fI['basename'] . $size)));
00867 
00868                 // edit
00869             if (!in_array('edit',$this->disabledItems) && is_file($path) && t3lib_div::inList($GLOBALS['TYPO3_CONF_VARS']['SYS']['textfile_ext'],$fI['extension'])) $menuItems['edit']=$this->FILE_launch($path,'file_edit.php','edit','edit_file.gif');
00870                 // rename
00871             if (!in_array('rename',$this->disabledItems))   $menuItems['rename']=$this->FILE_launch($path,'file_rename.php','rename','rename.gif');
00872                 // upload
00873             if (!in_array('upload',$this->disabledItems) && is_dir($path)) {
00874                 $menuItems['upload'] = $this->FILE_upload($path);
00875             }
00876 
00877                 // new
00878             if (!in_array('new',$this->disabledItems) && is_dir($path)) $menuItems['new']=$this->FILE_launch($path,'file_newfolder.php','new','new_file.gif');
00879                 // info
00880             if (!in_array('info',$this->disabledItems)) $menuItems['info']=$this->DB_info($path,'');
00881 
00882             $menuItems[]='spacer';
00883 
00884                 // copy:
00885             if (!in_array('copy',$this->disabledItems)) $menuItems['copy']=$this->FILE_copycut($path,'copy');
00886                 // cut:
00887             if (!in_array('cut',$this->disabledItems))  $menuItems['cut']=$this->FILE_copycut($path,'cut');
00888 
00889                 // Paste:
00890             $elFromAllTables = count($this->clipObj->elFromTable('_FILE'));
00891             if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path))   {
00892                 $elArr = $this->clipObj->elFromTable('_FILE');
00893                 reset($elArr);
00894                 $selItem = current($elArr);
00895                 $elInfo=array(
00896                     basename($selItem),
00897                     basename($path),
00898                     $this->clipObj->currentMode()
00899                 );
00900                 $menuItems['pasteinto']=$this->FILE_paste($path,$selItem,$elInfo);
00901             }
00902 
00903             $menuItems[]='spacer';
00904 
00905                 // delete:
00906             if (!in_array('delete',$this->disabledItems))   $menuItems['delete']=$this->FILE_delete($path);
00907         }
00908 
00909             // Adding external elements to the menuItems array
00910         $menuItems = $this->processingByExtClassArray($menuItems,$path,0);
00911 
00912             // Processing by external functions?
00913         $menuItems = $this->externalProcessingOfFileMenuItems($menuItems);
00914 
00915             // Return the printed elements:
00916         return $this->printItems($menuItems,$icon.basename($path));
00917     }
00918 
00919 
00920     /**
00921      * Processing the $menuItems array (for extension classes) (FILES)
00922      *
00923      * @param   array       $menuItems array for manipulation.
00924      * @return  array       Processed $menuItems array
00925      */
00926     function externalProcessingOfFileMenuItems($menuItems)  {
00927         return $menuItems;
00928     }
00929 
00930     /**
00931      * Multi-function for adding an entry to the $menuItems array
00932      *
00933      * @param   string      Path to the file/directory (target)
00934      * @param   string      Script (eg. file_edit.php) to pass &target= to
00935      * @param   string      "type" is the code which fetches the correct label for the element from "cm."
00936      * @param   string      icon image-filename from "gfx/" (12x12 icon)
00937      * @param   boolean     If set, the return URL parameter will not be set in the link
00938      * @return  array       Item array, element in $menuItems
00939      * @internal
00940      */
00941     function FILE_launch($path,$script,$type,$image,$noReturnUrl=FALSE) {
00942         $loc = 'top.content.list_frame';
00943 
00944         $editOnClick = 'if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'".$script.'?target=' . rawurlencode($path) . ($noReturnUrl ? "'" : "&returnUrl='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")") . ";}";
00945 
00946         return $this->linkItem(
00947             $this->label($type),
00948             $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
00949             $editOnClick . 'top.nav.refresh();return hideCM();'
00950         );
00951     }
00952 
00953     /**
00954      * function for adding an upload entry to the $menuItems array
00955      *
00956      * @param   string      Path to the file/directory (target)
00957      * @return  array       Item array, element in $menuItems
00958      * @internal
00959      */
00960     function FILE_upload($path) {
00961         $script = 'file_upload.php';
00962         $type = 'upload';
00963         $image = 'upload.gif';
00964         if ($GLOBALS['BE_USER']->uc['enableFlashUploader']) {
00965             $loc = 'top.content.list_frame';
00966 
00967             $editOnClick = 'if (top.TYPO3.FileUploadWindow.isFlashAvailable()) { initFlashUploader("' . rawurlencode($path) . '"); } else if(' . $loc . '){' . $loc . ".location.href=top.TS.PATH_typo3+'".$script.'?target=' . rawurlencode($path) . "';}";
00968 
00969             return $this->linkItem(
00970                 $this->label($type),
00971                 $this->excludeIcon('<img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/'.$image,'width="12" height="12"').' alt="" />'),
00972                 $editOnClick . 'return hideCM();'
00973                 );
00974         } else {
00975             return $this->FILE_launch($path, $script, $type, $image, true);
00976         }
00977     }
00978 
00979     /**
00980      * Returns element for copy or cut of files.
00981      *
00982      * @param   string      Path to the file/directory (target)
00983      * @param   string      Type: "copy" or "cut"
00984      * @return  array       Item array, element in $menuItems
00985      * @internal
00986      */
00987     function FILE_copycut($path,$type)  {
00988         $table = '_FILE';       // Pseudo table name for use in the clipboard.
00989         $uid = t3lib_div::shortmd5($path);
00990         if ($this->clipObj->current=='normal')  {
00991             $isSel = $this->clipObj->isSelected($table,$uid);
00992         }
00993 
00994         $addParam = array();
00995         if ($this->listFrame)   {
00996             $addParam['reloadListFrame'] = ($this->alwaysContentFrame ? 2 : 1);
00997         }
00998 
00999         return $this->linkItem(
01000             $this->label($type),
01001             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-' . $type . ($isSel === $type ? '-release' : ''))),
01002             "top.loadTopMenu('".$this->clipObj->selUrlFile($path,($type=='copy'?1:0),($isSel==$type),$addParam)."');return false;"
01003         );
01004     }
01005 
01006     /**
01007      * Creates element for deleting of target
01008      *
01009      * @param   string      Path to the file/directory (target)
01010      * @return  array       Item array, element in $menuItems
01011      * @internal
01012      */
01013     function FILE_delete($path) {
01014         $editOnClick='';
01015         $loc = 'top.content.list_frame';
01016         if($GLOBALS['BE_USER']->jsConfirmation(4))  {
01017             $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!)')).")";
01018         } else {
01019             $conf = '1==1';
01020         }
01021         $editOnClick = 'if(' . $loc . " && " . $conf . " ){" . $loc . ".location.href=top.TS.PATH_typo3+'tce_file.php?redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') . ")+'" .
01022             "&file[delete][0][data]=".rawurlencode($path).'&vC='.$GLOBALS['BE_USER']->veriCode()."';}hideCM();";
01023 
01024         return $this->linkItem(
01025             $this->label('delete'),
01026             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-edit-delete')),
01027             $editOnClick.'return false;'
01028         );
01029     }
01030 
01031     /**
01032      * Creates element for pasting files.
01033      *
01034      * @param   string      Path to the file/directory (target)
01035      * @param   string      target - NOT USED.
01036      * @param   array       Various values for the labels.
01037      * @return  array       Item array, element in $menuItems
01038      * @internal
01039      */
01040     function FILE_paste($path,$target,$elInfo)  {
01041         $editOnClick='';
01042         $loc = 'top.content.list_frame';
01043         if($GLOBALS['BE_USER']->jsConfirmation(2))  {
01044         $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])).")";
01045         } else {
01046             $conf=$loc;
01047         }
01048 
01049         $editOnClick='if('.$conf.'){'.$loc.".location.href=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0).
01050             "&redirect='+top.rawurlencode(" . $this->frameLocation($loc . '.document') .'); }hideCM();top.nav.refresh();';
01051 
01052         return $this->linkItem(
01053             $this->label('pasteinto'),
01054             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-paste-into')),
01055             $editOnClick.'return false;'
01056         );
01057     }
01058 
01059 
01060 
01061 
01062 
01063     /***************************************
01064      *
01065      * DRAG AND DROP
01066      *
01067      ***************************************/
01068 
01069     /**
01070      * Make 1st level clickmenu:
01071      *
01072      * @param   string      The absolute path
01073      * @param   integer     UID for the current record.
01074      * @param   integer     Destination ID
01075      * @return  string      HTML content
01076      */
01077     function printDragDropClickMenu($table,$srcId,$dstId)   {
01078         $menuItems=array();
01079 
01080             // If the drag and drop menu should apply to PAGES use this set of menu items
01081         if ($table == 'pages')  {
01082                 // Move Into:
01083             $menuItems['movePage_into']=$this->dragDrop_copymovepage($srcId,$dstId,'move','into');
01084                 // Move After:
01085             $menuItems['movePage_after']=$this->dragDrop_copymovepage($srcId,$dstId,'move','after');
01086                 // Copy Into:
01087             $menuItems['copyPage_into']=$this->dragDrop_copymovepage($srcId,$dstId,'copy','into');
01088                 // Copy After:
01089             $menuItems['copyPage_after']=$this->dragDrop_copymovepage($srcId,$dstId,'copy','after');
01090         }
01091 
01092             // If the drag and drop menu should apply to FOLDERS use this set of menu items
01093         if ($table == 'folders')    {
01094                 // Move Into:
01095             $menuItems['moveFolder_into']=$this->dragDrop_copymovefolder($srcId,$dstId,'move');
01096                 // Copy Into:
01097             $menuItems['copyFolder_into']=$this->dragDrop_copymovefolder($srcId,$dstId,'copy');
01098         }
01099 
01100             // Adding external elements to the menuItems array
01101         $menuItems = $this->processingByExtClassArray($menuItems,"dragDrop_".$table,$srcId);  // to extend this, you need to apply a Context Menu to a "virtual" table called "dragDrop_pages" or similar
01102 
01103             // Processing by external functions?
01104         $menuItems = $this->externalProcessingOfDBMenuItems($menuItems);
01105 
01106             // Return the printed elements:
01107         return $this->printItems($menuItems,
01108             t3lib_iconWorks::getSpriteIconForRecord($table,$this->rec,array('title'=> t3lib_BEfunc::getRecordTitle($table,$this->rec,TRUE)))
01109         );
01110     }
01111 
01112 
01113     /**
01114      * Processing the $menuItems array (for extension classes) (DRAG'N DROP)
01115      *
01116      * @param   array       $menuItems array for manipulation.
01117      * @return  array       Processed $menuItems array
01118      */
01119     function externalProcessingOfDragDropMenuItems($menuItems)  {
01120         return $menuItems;
01121     }
01122 
01123 
01124     /**
01125      * Adding CM element for Copying/Moving a Page Into/After from a drag & drop action
01126      *
01127      * @param   integer     source UID code for the record to modify
01128      * @param   integer     destination UID code for the record to modify
01129      * @param   string      Action code: either "move" or "copy"
01130      * @param   string      Parameter code: either "into" or "after"
01131      * @return  array       Item array, element in $menuItems
01132      * @internal
01133      */
01134     function dragDrop_copymovepage($srcUid,$dstUid,$action,$into)   {
01135         $negativeSign = ($into == 'into') ? '' : '-';
01136         $editOnClick='';
01137         $loc = 'top.content.list_frame';
01138         $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=top.TS.PATH_typo3+"tce_db.php?redirect="+top.rawurlencode(' . $this->frameLocation($loc . '.document') . ')+"' .
01139             '&cmd[pages][' . $srcUid . '][' . $action . ']=' . $negativeSign . $dstUid . '&prErr=1&vC=' . $GLOBALS['BE_USER']->veriCode() . t3lib_BEfunc::getUrlToken('tceAction') . '";}hideCM();top.nav.refresh();';
01140 
01141         return $this->linkItem(
01142             $this->label($action.'Page_'.$into),
01143             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('actions-document-paste-' . $into)),
01144             $editOnClick.'return false;',
01145             0
01146         );
01147     }
01148 
01149 
01150     /**
01151      * Adding CM element for Copying/Moving a Folder Into from a drag & drop action
01152      *
01153      * @param   string      source path for the record to modify
01154      * @param   string      destination path for the records to modify
01155      * @param   string      Action code: either "move" or "copy"
01156      * @return  array       Item array, element in $menuItems
01157      * @internal
01158      */
01159     function dragDrop_copymovefolder($srcPath,$dstPath,$action) {
01160         $editOnClick='';
01161         $loc = 'top.content.list_frame';
01162         $editOnClick = 'if(' . $loc . '){' . $loc . '.document.location=top.TS.PATH_typo3+"tce_file.php?redirect="+top.rawurlencode(' . $this->frameLocation($loc . '.document') .')+"' .
01163             '&file['.$action.'][0][data]='.$srcPath.'&file['.$action.'][0][target]='.$dstPath.'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode().'";}hideCM();top.nav.refresh();';
01164 
01165         return $this->linkItem(
01166             $this->label($action.'Folder_into'),
01167             $this->excludeIcon(t3lib_iconWorks::getSpriteIcon('apps-pagetree-drag-move-into')),
01168             $editOnClick.'return false;',
01169             0
01170         );
01171     }
01172 
01173 
01174 
01175 
01176 
01177 
01178 
01179 
01180 
01181     /***************************************
01182      *
01183      * COMMON
01184      *
01185      **************************************/
01186 
01187     /**
01188      * Prints the items from input $menuItems array - both as topframe menu AND the JS section for writing to the div-layers.
01189      * Of course the topframe menu will appear only if $this->doDisplayTopFrameCM() returns true
01190      *
01191      * @param   array       $menuItems array
01192      * @param   string      HTML code for the element which was clicked - shown in the end of the horizontal menu in topframe after the close-button.
01193      * @return  string      HTML code
01194      */
01195     function printItems($menuItems,$item)   {
01196 
01197         $out='';
01198 
01199             // Enable/Disable items:
01200         $menuItems = $this->enableDisableItems($menuItems);
01201 
01202             // Clean up spacers:
01203         $menuItems = $this->cleanUpSpacers($menuItems);
01204 
01205             // Adding topframe part (horizontal clickmenu)
01206         if ($this->doDisplayTopFrameCM())   {
01207             $out.= '
01208 
01209                 <!--
01210                     Table, which contains the click menu when shown in the top frame of the backend:
01211                 -->
01212                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-CSM-top">
01213                     <tr>
01214 
01215                             <!-- Items: -->
01216                         <td class="c-item">'.
01217                             implode('</td>
01218                         <td><img'.t3lib_iconWorks::skinImg($this->PH_backPath,'gfx/acm_spacer2.gif','width="8" height="12"').' alt="" /></td>
01219                         <td class="c-item">',$this->menuItemsForTopFrame($menuItems)).
01220                         '</td>
01221 
01222                             <!-- Close button: -->
01223                         <td class="c-closebutton"><a href="#" onclick="hideCM();return false;">' .
01224                             t3lib_iconWorks::getSpriteIcon('actions-document-close', array(
01225                                 'title'=> $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.close', 1)
01226                             )) . '</a></td>
01227 
01228                             <!-- The item of the clickmenu: -->
01229                         <td class="c-itemicon">'.$item.'</td>
01230                     </tr>
01231                 </table>
01232             ';
01233 
01234                 // Set remaining BACK_PATH to blank (if any)
01235             $out = str_replace($this->PH_backPath,'',$out);
01236         }
01237             // Adding JS part:
01238         $out.=$this->printLayerJScode($menuItems);
01239 
01240             // Return the content
01241         return $out;
01242     }
01243 
01244     /**
01245      * Create the JavaScript section
01246      *
01247      * @param   array       The $menuItems array to print
01248      * @return  string      The JavaScript section which will print the content of the CM to the div-layer in the target frame.
01249      */
01250     function printLayerJScode($menuItems)   {
01251         $script='';
01252         if ($this->isCMlayers())    {   // Clipboard must not be submitted - then it's probably a copy/cut situation.
01253             $frameName = '.'.($this->listFrame ? 'list_frame' : 'nav_frame');
01254             if ($this->alwaysContentFrame)  $frameName='';
01255 
01256                 // Create the table displayed in the clickmenu layer:
01257             $CMtable = '
01258                 <table border="0" cellpadding="0" cellspacing="0" class="typo3-CSM">
01259                     '.implode('',$this->menuItemsForClickMenu($menuItems)).'
01260                 </table>';
01261 
01262                 // Wrap the inner table in another table to create outer border:
01263             $CMtable = $this->wrapColorTableCM($CMtable);
01264 
01265                 // Set back path place holder to real back path
01266             $CMtable = str_replace($this->PH_backPath,$this->backPath,$CMtable);
01267             if ($this->ajax)    {
01268                 $innerXML = '<data><clickmenu><htmltable><![CDATA['.$CMtable.']]></htmltable><cmlevel>'.$this->cmLevel.'</cmlevel></clickmenu></data>';
01269                 return $innerXML;
01270             } else {
01271                     // Create JavaScript section:
01272                 $script=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
01273 
01274                 if (top.content && top.content'.$frameName.' && top.content'.$frameName.'.Clickmenu)    {
01275                     top.content'.$frameName.'.Clickmenu.populateData(unescape("'.t3lib_div::rawurlencodeJS($CMtable).'"),'.$this->cmLevel.');
01276                 }
01277                 '.(!$this->doDisplayTopFrameCM()?'hideCM();':'')
01278                 );
01279                 return $script;
01280             }
01281         }
01282     }
01283 
01284     /**
01285      * Wrapping the input string in a table with background color 4 and a black border style.
01286      * For the pop-up menu
01287      *
01288      * @param   string      HTML content to wrap in table.
01289      * @return  string
01290      */
01291     function wrapColorTableCM($str) {
01292 
01293         return '<div class="typo3-CSM-wrapperCM">
01294             ' . $str . '
01295             </div>';
01296     }
01297 
01298     /**
01299      * Traverses the menuItems and generates an output array for implosion in the topframe horizontal menu
01300      *
01301      * @param   array       $menuItem array
01302      * @param   array       Array with HTML content to be imploded between <td>-tags
01303      * @return  array       Array of menu items for top frame.
01304      */
01305     function menuItemsForTopFrame($menuItems)   {
01306         $out=array();
01307         foreach ($menuItems as $i) {
01308             if ($i[4]==1 && !$GLOBALS['SOBE']->doc->isCMlayers())   $i[4]=0;    // IF the topbar is the ONLY means of the click menu, then items normally disabled from the top menu will appear anyways IF they are disabled with a "1" (2+ will still disallow them in the topbar)
01309             if (is_array($i) && !$i[4]) $out[]=$i[0];
01310         }
01311         return $out;
01312     }
01313 
01314     /**
01315      * Traverses the menuItems and generates an output array for implosion in the CM div-layers table.
01316      *
01317      * @param   array       $menuItem array
01318      * @param   array       Array with HTML content to be imploded between <td>-tags
01319      * @return  array       array for implosion in the CM div-layers table.
01320      */
01321     function menuItemsForClickMenu($menuItems)  {
01322         $out=array();
01323         foreach ($menuItems as $cc => $i) {
01324             if (is_string($i) && $i=='spacer')  {   // MAKE horizontal spacer
01325                 $out[]='
01326                     <tr class="bgColor2">
01327                         <td colspan="2"><img src="clear.gif" width="1" height="1" alt="" /></td>
01328                     </tr>';
01329             } else {    // Just make normal element:
01330                 $onClick=$i[3];
01331                 $onClick=preg_replace('/return[[:space:]]+hideCM\(\)[[:space:]]*;/i','',$onClick);
01332                 $onClick=preg_replace('/return[[:space:]]+false[[:space:]]*;/i','',$onClick);
01333                 $onClick=preg_replace('/hideCM\(\);/i','',$onClick);
01334                 if (!$i[5]) $onClick.='Clickmenu.hideAll();';
01335 
01336                 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['useOnContextMenuHandler'])   {
01337                     $CSM = ' oncontextmenu="'.htmlspecialchars($onClick).';return false;"';
01338                 }
01339 
01340                 $out[]='
01341                     <tr class="typo3-CSM-itemRow" onclick="'.htmlspecialchars($onClick).'" onmouseover="this.bgColor=\''.$GLOBALS['TBE_TEMPLATE']->bgColor5.'\';" onmouseout="this.bgColor=\'\';"'.$CSM.'>
01342                         '.(!$this->leftIcons?'<td class="typo3-CSM-item">'.$i[1].'</td><td align="center">'.$i[2].'</td>' : '<td align="center">'.$i[2].'</td><td class="typo3-CSM-item">'.$i[1].'</td>').'
01343                     </tr>';
01344             }
01345         }
01346         return $out;
01347     }
01348 
01349     /**
01350      * Adds or inserts a menu item
01351      * Can be used to set the position of new menu entries within the list of existing menu entries. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
01352      *
01353      * @param   array       Menu items array
01354      * @param   array       Menu items array to insert
01355      * @param   string      Position command string. Has this syntax: [cmd]:[menu entry key],[cmd].... cmd can be "after", "before" or "top" (or blank/"bottom" which is default). If "after"/"before" then menu items will be inserted after/before the existing entry with [menu entry key] if found. "after-spacer" and "before-spacer" do the same, but inserts before or after an item and a spacer. If not found, the bottom of list. If "top" the items are inserted in the top of the list.
01356      * @return  array       Menu items array, processed.
01357      */
01358     function addMenuItems($menuItems,$newMenuItems,$position='')    {
01359         if (is_array($newMenuItems))    {
01360 
01361             if($position) {
01362 
01363                 $posArr = t3lib_div::trimExplode(',', $position, 1);
01364                 foreach($posArr as $pos) {
01365                     list($place,$menuEntry) = t3lib_div::trimExplode(':', $pos, 1);
01366                     list($place,$placeExtra) = t3lib_div::trimExplode('-', $place, 1);
01367 
01368                         // bottom
01369                     $pointer = count($menuItems);
01370 
01371                     $found=FALSE;
01372 
01373                     if ($place) {
01374                         switch(strtolower($place))  {
01375                             case 'after':
01376                             case 'before':
01377                                 if ($menuEntry) {
01378                                     $p=1;
01379                                     reset ($menuItems);
01380                                     while (true) {
01381                                         if (!strcmp(key($menuItems), $menuEntry))   {
01382                                             $pointer = $p;
01383                                             $found=TRUE;
01384                                             break;
01385                                         }
01386                                         if (!next($menuItems)) break;
01387                                         $p++;
01388                                     }
01389                                     if (!$found) break;
01390 
01391                                     if ($place=='before') {
01392                                         $pointer--;
01393                                         if ($placeExtra=='spacer' AND prev($menuItems)=='spacer') {
01394                                             $pointer--;
01395                                         }
01396                                     } elseif ($place=='after') {
01397                                         if ($placeExtra=='spacer' AND next($menuItems)=='spacer') {
01398                                             $pointer++;
01399                                         }
01400                                     }
01401                                 }
01402                             break;
01403                             default:
01404                                 if (strtolower($place)=='top')  {
01405                                     $pointer = 0;
01406                                 } else {
01407                                     $pointer = count($menuItems);
01408                                 }
01409                                 $found=TRUE;
01410                             break;
01411                         }
01412                     }
01413                     if($found) break;
01414                 }
01415             }
01416             $pointer=max(0,$pointer);
01417             $menuItemsBefore = array_slice($menuItems, 0, ($pointer?$pointer:0));
01418             $menuItemsAfter = array_slice($menuItems, $pointer);
01419             $menuItems = $menuItemsBefore + $newMenuItems + $menuItemsAfter;
01420         }
01421         return $menuItems;
01422     }
01423 
01424     /**
01425      * Creating an array with various elements for the clickmenu entry
01426      *
01427      * @param   string      The label, htmlspecialchar'ed already
01428      * @param   string      <img>-tag for the icon
01429      * @param   string      JavaScript onclick event for label/icon
01430      * @param   boolean     ==1 and the element will NOT appear in clickmenus in the topframe (unless clickmenu is totally unavailable)! ==2 and the item will NEVER appear in top frame. (This is mostly for "less important" options since the top frame is not capable of holding so many elements horizontally)
01431      * @param   boolean     If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear...
01432      * @return  array       $menuItem entry with 6 numerical entries: [0] is the HTML for display of the element with link and icon an mouseover etc., [1]-[5] is simply the input params passed through!
01433      */
01434     function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0)    {
01435         global $BACK_PATH;
01436 
01437         $this->elCount++;
01438         if($this->ajax) {
01439             $onClick = str_replace('top.loadTopMenu', 'showClickmenu_raw', $onClick);
01440         }
01441 
01442 
01443         return array(
01444             t3lib_iconWorks::getSpriteIcon('empty-empty', array(
01445                 'class' => 'c-roimg',
01446                 'id'=> 'roimg_' . $this->elCount
01447             )) .
01448                 '<a href="#" onclick="'.htmlspecialchars($onClick).'" onmouseover="mo('.$this->elCount.');" onmouseout="mout('.$this->elCount.');">'.
01449                 $str.$icon.
01450                 '</a>',
01451             $str,
01452             $icon,
01453             $onClick,
01454             $onlyCM,
01455             $dontHide
01456         );
01457     }
01458 
01459     /**
01460      * Returns the input string IF not a user setting has disabled display of icons.
01461      *
01462      * @param   string      The icon-image tag
01463      * @return  string      The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings
01464      */
01465     function excludeIcon($iconCode) {
01466         return ($GLOBALS['BE_USER']->uc['noMenuMode'] && strcmp($GLOBALS['BE_USER']->uc['noMenuMode'],'icons')) ? '' : ' '.$iconCode;
01467     }
01468 
01469     /**
01470      * Enabling / Disabling items based on list provided from GET var ($this->iParts[3])
01471      *
01472      * @param   array       Menu items array
01473      * @return  array       Menu items array, processed.
01474      */
01475     function enableDisableItems($menuItems) {
01476         if ($this->iParts[3])   {
01477 
01478                 // Detect "only" mode: (only showing listed items)
01479             if (substr($this->iParts[3],0,1)=='+')  {
01480                 $this->iParts[3] = substr($this->iParts[3],1);
01481                 $only = TRUE;
01482             } else {
01483                 $only = FALSE;
01484             }
01485 
01486                 // Do filtering:
01487             if ($only)  {   // Transfer ONLY elements which are mentioned (or are spacers)
01488                 $newMenuArray = array();
01489                 foreach($menuItems as $key => $value)   {
01490                     if (t3lib_div::inList($this->iParts[3], $key) || (is_string($value) && $value=='spacer'))   {
01491                         $newMenuArray[$key] = $value;
01492                     }
01493                 }
01494                 $menuItems = $newMenuArray;
01495             } else {    // Traverse all elements except those listed (just unsetting them):
01496                 $elements = t3lib_div::trimExplode(',',$this->iParts[3],1);
01497                 foreach($elements as $value)    {
01498                     unset($menuItems[$value]);
01499                 }
01500             }
01501         }
01502 
01503             // Return processed menu items:
01504         return $menuItems;
01505     }
01506 
01507     /**
01508      * Clean up spacers; Will remove any spacers in the start/end of menu items array plus any duplicates.
01509      *
01510      * @param   array       Menu items array
01511      * @return  array       Menu items array, processed.
01512      */
01513     function cleanUpSpacers($menuItems) {
01514 
01515             // Remove doubles:
01516         $prevItemWasSpacer = FALSE;
01517         foreach($menuItems as $key => $value)   {
01518             if (is_string($value) && $value=='spacer')  {
01519                 if ($prevItemWasSpacer) {
01520                     unset($menuItems[$key]);
01521                 }
01522                 $prevItemWasSpacer = TRUE;
01523             } else {
01524                 $prevItemWasSpacer = FALSE;
01525             }
01526         }
01527 
01528             // Remove first:
01529         reset($menuItems);
01530         $key = key($menuItems);
01531         $value = current($menuItems);
01532         if (is_string($value) && $value=='spacer')  {
01533             unset($menuItems[$key]);
01534         }
01535 
01536 
01537             // Remove last:
01538         end($menuItems);
01539         $key = key($menuItems);
01540         $value = current($menuItems);
01541         if (is_string($value) && $value=='spacer')  {
01542             unset($menuItems[$key]);
01543         }
01544 
01545             // Return processed menu items:
01546         return $menuItems;
01547     }
01548 
01549     /**
01550      * Get label from locallang_core.php:cm.*
01551      *
01552      * @param   string      The "cm."-suffix to get.
01553      * @return  string
01554      */
01555     function label($label)  {
01556         return $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.'.$label,1));
01557     }
01558 
01559     /**
01560      * Returns true if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers)
01561      *
01562      * @return  boolean
01563      */
01564     function isCMlayers()   {
01565         if($this->ajax) {
01566             return !$this->CB;
01567         } else {
01568             return $GLOBALS['SOBE']->doc->isCMlayers() && !$this->CB;
01569         }
01570     }
01571 
01572     /**
01573      * Appends ".location" to input string
01574      *
01575      * @param   string      Input string, probably a JavaScript document reference
01576      * @return  string
01577      */
01578     function frameLocation($str)    {
01579         return $str.'.location';
01580     }
01581 }
01582 
01583 
01584 
01585 
01586 
01587 
01588 
01589 
01590 
01591 
01592 
01593 
01594 
01595 /**
01596  * Script Class for the Context Sensitive Menu in TYPO3 (rendered in top frame, normally writing content dynamically to list frames).
01597  *
01598  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
01599  * @package TYPO3
01600  * @subpackage core
01601  * @see template::getContextMenuCode()
01602  */
01603 class SC_alt_clickmenu {
01604 
01605         // Internal, static: GPvar:
01606     var $backPath;                  // Back path.
01607     var $item;                      // Definition of which item the click menu should be made for.
01608     var $reloadListFrame;           // Defines the name of the document object for which to reload the URL.
01609 
01610         // Internal:
01611     var $content='';                // Content accumulation
01612     var $doc;                       // Template object
01613     var $include_once=array();      // Files to include_once() - set in init() function
01614     var $extClassArray=array();     // Internal array of classes for extending the clickmenu
01615     var $dontDisplayTopFrameCM=0;   // If set, then the clickmenu will NOT display in the top frame.
01616 
01617     /**
01618      * Constructor function for script class.
01619      *
01620      * @return  void
01621      */
01622     function init() {
01623         global $BE_USER,$BACK_PATH;
01624 
01625             // Setting GPvars:
01626         $this->backPath = t3lib_div::_GP('backPath');
01627         $this->item = t3lib_div::_GP('item');
01628         $this->reloadListFrame = t3lib_div::_GP('reloadListFrame');
01629 
01630             // Setting pseudo module name
01631         $this->MCONF['name']='xMOD_alt_clickmenu.php';
01632 
01633             // Takes the backPath as a parameter BUT since we are worried about someone forging a backPath (XSS security hole) we will check with sent md5 hash:
01634         $inputBP = explode('|',$this->backPath);
01635         if (count($inputBP)==2 && $inputBP[1]==t3lib_div::shortMD5($inputBP[0].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
01636             $this->backPath = $inputBP[0];
01637         } else {
01638             $this->backPath = $BACK_PATH;
01639         }
01640 
01641             // Setting internal array of classes for extending the clickmenu:
01642         $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses'];
01643 
01644             // Traversing that array and setting files for inclusion:
01645         if (is_array($this->extClassArray)) {
01646             foreach($this->extClassArray as $extClassConf)  {
01647                 if ($extClassConf['path'])  $this->include_once[]=$extClassConf['path'];
01648             }
01649         }
01650 
01651             // Initialize template object
01652         if (!$this->ajax)   {
01653             $this->doc = t3lib_div::makeInstance('template');
01654             $this->doc->backPath = $BACK_PATH;
01655         }
01656 
01657             // Setting mode for display and background image in the top frame
01658         $this->dontDisplayTopFrameCM= $this->doc->isCMlayers() && !$BE_USER->getTSConfigVal('options.contextMenu.options.alwaysShowClickMenuInTopFrame');
01659         if ($this->dontDisplayTopFrameCM)   {
01660             $this->doc->bodyTagId.= '-notop';
01661         }
01662 
01663             // Setting clickmenu timeout
01664         $secs = t3lib_div::intInRange($BE_USER->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'),1,100,5);    // default is 5
01665 
01666             // Setting the JavaScript controlling the timer on the page
01667         $listFrameDoc = $this->reloadListFrame!=2 ? 'top.content.list_frame' : 'top.content';
01668         $this->doc->JScode.=$this->doc->wrapScriptTags('
01669     var date = new Date();
01670     var mo_timeout = Math.floor(date.getTime()/1000);
01671 
01672     roImg = "' . t3lib_iconWorks::getSpriteIconClasses('status-status-current') . '";
01673 
01674     routImg = "t3-icon-empty";
01675 
01676     function mo(c)  {   //
01677         var name="roimg_"+c;
01678         document.getElementById(name).className = roImg;
01679         updateTime();
01680     }
01681     function mout(c)    {   //
01682         var name="roimg_"+c;
01683         document[name].src = routImg;
01684         updateTime();
01685     }
01686     function updateTime()   {   //
01687         date = new Date();
01688         mo_timeout = Math.floor(date.getTime()/1000);
01689     }
01690     function timeout_func() {   //
01691         date = new Date();
01692         if (Math.floor(date.getTime()/1000)-mo_timeout > '.$secs.') {
01693             hideCM();
01694             return false;
01695         } else {
01696             window.setTimeout("timeout_func();",1*1000);
01697         }
01698     }
01699     function hideCM()   {   //
01700         window.location.href="alt_topmenu_dummy.php";
01701         return false;
01702     }
01703 
01704         // Start timer
01705     timeout_func();
01706 
01707     '.($this->reloadListFrame ? '
01708         // Reload list frame:
01709     if('.$listFrameDoc.'){'.$listFrameDoc.'.location.href='.$listFrameDoc.'.location.href;}' :
01710     '').'
01711         ');
01712     }
01713 
01714     /**
01715      * Main function - generating the click menu in whatever form it has.
01716      *
01717      * @return  void
01718      */
01719     function main() {
01720         $this->ajax = t3lib_div::_GP('ajax') ? TRUE : FALSE;
01721 
01722             // Initialize Clipboard object:
01723         $clipObj = t3lib_div::makeInstance('t3lib_clipboard');
01724         $clipObj->initializeClipboard();
01725         $clipObj->lockToNormal();   // This locks the clipboard to the Normal for this request.
01726 
01727             // Update clipboard if some actions are sent.
01728         $CB = t3lib_div::_GET('CB');
01729         $clipObj->setCmd($CB);
01730         $clipObj->cleanCurrent();
01731         $clipObj->endClipboard();   // Saves
01732 
01733             // Create clickmenu object
01734         $clickMenu = t3lib_div::makeInstance('clickMenu');
01735 
01736             // Set internal vars in clickmenu object:
01737         $clickMenu->clipObj = $clipObj;
01738         $clickMenu->extClassArray = $this->extClassArray;
01739         $clickMenu->dontDisplayTopFrameCM = $this->dontDisplayTopFrameCM;
01740         $clickMenu->backPath = $this->backPath;
01741 
01742             // Start page
01743         if(!$this->ajax)    {
01744             $this->content.= $this->doc->startPage('Context Sensitive Menu');
01745         }
01746             // Set content of the clickmenu with the incoming var, "item"
01747         $this->content.= $clickMenu->init();
01748     }
01749 
01750     /**
01751      * End page and output content.
01752      *
01753      * @return  void
01754      */
01755     function printContent() {
01756         if (!$this->ajax)   {
01757             $this->content.= $this->doc->endPage();
01758             $this->content = $this->doc->insertStylesAndJS($this->content);
01759             echo $this->content;
01760         } else {
01761             t3lib_formprotection_Factory::get()->persistTokens();
01762             $this->content = $GLOBALS['LANG']->csConvObj->utf8_encode($this->content,$GLOBALS['LANG']->charSet);
01763             t3lib_ajax::outputXMLreply($this->content);
01764         }
01765     }
01766 }
01767 
01768 
01769 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php'])) {
01770     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/alt_clickmenu.php']);
01771 }
01772 
01773 
01774 
01775 // Make instance:
01776 $SOBE = t3lib_div::makeInstance('SC_alt_clickmenu');
01777 $SOBE->init();
01778 
01779 // Include files?
01780 foreach($SOBE->include_once as $INC_FILE)   include_once($INC_FILE);
01781 
01782 $SOBE->main();
01783 $SOBE->printContent();
01784 
01785 ?>