-layer in the calling document (which then appears as a layer/context sensitive menu) * Writing content back into a
-layer is necessary if we want individualized context menus with any specific content for any specific element. * Context menus can appear for either database elements or files * The input to this script is basically the "&init" var which is divided by "|" - each part is a reference to table|uid|listframe-flag. * * $Id$ * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj * XHTML compliant * * @author Kasper Skaarhoj */ /** * [CLASS/FUNCTION INDEX of SCRIPT] * * * * 122: class clickMenu * 147: function init($item) * 182: function doDisplayTopFrameCM() * * SECTION: DATABASE * 210: function printDBClickMenu($table,$uid) * 299: function printNewDBLevel($table,$uid) * 338: function externalProcessingOfDBMenuItems($menuItems) * 350: function processingByExtClassArray($menuItems,$table,$uid) * 369: function urlRefForCM($url,$retUrl='',$hideCM=1) * 386: function DB_copycut($table,$uid,$type) * 409: function DB_paste($table,$uid,$type,$elInfo) * 430: function DB_info($table,$uid) * 446: function DB_history($table,$uid) * 465: function DB_perms($table,$uid,$rec) * 484: function DB_db_list($table,$uid,$rec) * 503: function DB_moveWizard($table,$uid,$rec) * 524: function DB_newWizard($table,$uid,$rec) * 542: function DB_editAccess($table,$uid) * 560: function DB_editPageHeader($uid) * 578: function DB_edit($table,$uid) * 617: function DB_new($table,$uid) * 642: function DB_hideUnhide($table,$rec,$hideField) * 666: function DB_delete($table,$uid,$elInfo) * 687: function DB_view($id,$anchor='') * * SECTION: FILE * 716: function printFileClickMenu($path) * 784: function externalProcessingOfFileMenuItems($menuItems) * 798: function FILE_launch($path,$script,$type,$image) * 817: function FILE_copycut($path,$type) * 837: function FILE_delete($path) * 859: function FILE_paste($path,$target,$elInfo) * * SECTION: COMMON * 899: function printItems($menuItems,$item) * 930: function printLayerJScode($menuItems) * 963: function wrapColorTableCM($str) * 977: function wrapColorTable($str) * 993: function menuItemsForTopFrame($menuItems) * 1010: function menuItemsForClickMenu($menuItems) * 1052: function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0) * 1073: function excludeIcon($iconCode) * 1083: function label($label) * 1092: function isCMlayers() * 1102: function frameLocation($str) * * * 1126: class SC_alt_clickmenu * 1138: function init() * 1219: function main() * 1259: function printContent() * * TOTAL FUNCTIONS: 42 * (This index is automatically created/updated by the extension "extdeveval") * */ require ('init.php'); require ('template.php'); require_once (PATH_t3lib.'class.t3lib_clipboard.php'); $LANG->includeLLFile('EXT:lang/locallang_misc.php'); /** * Class for generating the click menu * * @author Kasper Skaarhoj * @package TYPO3 * @subpackage core * @internal */ class clickMenu { var $backPath=''; var $elCount=0; var $listFrame=0; // If set, the calling document should be in the listframe of a frameset. var $isDBmenu=0; // If set, the menu is about databsae records, not files. (set if part 2 [1] of the item-var is NOT blank) var $alwaysContentFrame=0; var $iParts=array(); var $disabledItems=array(); var $editPageIconSet=0; var $dontDisplayTopFrameCM=0; var $leftIcons=0; var $cmLevel=0; var $extClassArray=array(); var $editOK=0; var $rec=array(); /** * Initialize click menu * * @param string Input "item" GET var. * @return string The clickmenu HTML content */ function init($item) { // Explode the incoming command: $this->iParts = explode('|',$item); // Setting flags: if ($this->iParts[2]) $this->listFrame=1; if ($GLOBALS['BE_USER']->uc['condensedMode']) $this->alwaysContentFrame=1; if (strcmp($this->iParts[1],'')) $this->isDBmenu=1; $TSkey =($this->isDBmenu?'page':'folder').($this->listFrame?'List':'Tree'); $this->disabledItems = t3lib_div::trimExplode(',',$GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.'.$TSkey.'.disableItems'),1); $this->leftIcons = $GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.leftIcons'); // &cmLevel flag detected (2nd level menu) $this->cmLevel = intval(t3lib_div::GPvar('cmLevel')); if (!$this->cmLevel) { // Make 1st level clickmenu: if ($this->isDBmenu) { return $this->printDBClickMenu($this->iParts[0],$this->iParts[1]); } else { return $this->printFileClickMenu($this->iParts[0]); } } else { // Make 2nd level clickmenu (only for DBmenus) if ($this->isDBmenu) { return $this->printNewDBLevel($this->iParts[0],$this->iParts[1]); } } } /** * Returns true if the menu should (also?) be displayed in topframe, not just
-layers * * @return boolean */ function doDisplayTopFrameCM() { return !$GLOBALS['SOBE']->doc->isCMlayers() || !$this->dontDisplayTopFrameCM; } /*************************************** * * DATABASE * ***************************************/ /** * Make 1st level clickmenu: * * @param string Table name * @param integer UID for the current record. * @return string HTML content */ function printDBClickMenu($table,$uid) { global $TCA, $BE_USER; // Get record: $this->rec = t3lib_BEfunc::getRecord($table,$uid); $menuItems=array(); $root=0; if ($table=='pages' && !strcmp($uid,'0')) { // Rootlevel $root=1; } // If record found (or root), go ahead and fill the $menuItems array which will contain data for the elements to render. if (is_array($this->rec) || $root) { // Get permissions $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid']))); // View if (!in_array('view',$this->disabledItems)) { if ($table=='pages') $menuItems['view']=$this->DB_view($uid); if ($table==$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) $menuItems['view']=$this->DB_view($this->rec['pid'],'#'.$uid); } // Edit: if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent'))) { if (!in_array('edit',$this->disabledItems)) $menuItems['edit']=$this->DB_edit($table,$uid); $this->editOK=1; } // New: if (!in_array('new',$this->disabledItems) && $BE_USER->isPSet($lCP,$table,'new')) $menuItems['new']=$this->DB_new($table,$uid); // Info: if(!in_array('info',$this->disabledItems) && !$root) $menuItems['info']=$this->DB_info($table,$uid); $menuItems[]='spacer'; // Copy: if(!in_array('copy',$this->disabledItems) && !$root) $menuItems['copy']=$this->DB_copycut($table,$uid,'copy'); // Cut: if(!in_array('cut',$this->disabledItems) && !$root) $menuItems['cut']=$this->DB_copycut($table,$uid,'cut'); // Paste: $elFromAllTables = count($this->clipObj->elFromTable('')); if (!in_array('paste',$this->disabledItems) && $elFromAllTables) { $selItem = $this->clipObj->getSelectedRecord(); $elInfo=array( $selItem['_RECORD_TITLE'], ($root?$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']:t3lib_div::fixed_lgd(t3lib_BEfunc::getRecordTitle($table,$this->rec),$GLOBALS['BE_USER']->uc['titleLen'])), $this->clipObj->currentMode() ); if ($table=='pages' && ($lCP & 8)) { if ($elFromAllTables) $menuItems['pasteinto']=$this->DB_paste('',$uid,'into',$elInfo); } $elFromTable = count($this->clipObj->elFromTable($table)); if (!$root && $elFromTable && $TCA[$table]['ctrl']['sortby']) $menuItems['pasteafter']=$this->DB_paste($table,-$uid,'after',$elInfo); } // Delete: $elInfo=array(t3lib_div::fixed_lgd(t3lib_BEfunc::getRecordTitle($table,$this->rec),$GLOBALS['BE_USER']->uc['titleLen'])); if(!in_array('delete',$this->disabledItems) && !$root && $BE_USER->isPSet($lCP,$table,'delete')) { $menuItems[]='spacer'; $menuItems['delete']=$this->DB_delete($table,$uid,$elInfo); } } // Adding external elements to the menuItems array $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid); // Processing by external functions? $menuItems = $this->externalProcessingOfDBMenuItems($menuItems); // Return the printed elements: return $this->printItems($menuItems, $this->wrapColorTable( $root? ''.htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']).'': t3lib_iconWorks::getIconImage($table,$this->rec,$this->backPath,' hspace="5" align="absmiddle"'.t3lib_BEfunc::titleAttrib(t3lib_BEfunc::getRecordIconAltText($this->rec,$table))).''.t3lib_BEfunc::getRecordTitle($table,$this->rec,1).'' ) ); } /** * Make 2nd level clickmenu (only for DBmenus) * * @param string Table name * @param integer UID for the current record. * @return string HTML content */ function printNewDBLevel($table,$uid) { global $TCA, $BE_USER; // Setting internal record to the table/uid : $this->rec = t3lib_BEfunc::getRecord($table,$uid); $menuItems=array(); $root=0; if ($table=='pages' && !strcmp($uid,'0')) { // Rootlevel $root=1; } // If record was found, check permissions and get menu items. if (is_array($this->rec) || $root) { $lCP = $BE_USER->calcPerms(t3lib_BEfunc::getRecord('pages',($table=='pages'?$this->rec['uid']:$this->rec['pid']))); // Edit: if(!$root && ($BE_USER->isPSet($lCP,$table,'edit')||$BE_USER->isPSet($lCP,$table,'editcontent'))) { $this->editOK=1; } $menuItems = $this->processingByExtClassArray($menuItems,$table,$uid); } // Return the printed elements: if (!is_array($menuItems)) $menuItems=array(); return $this->printItems($menuItems, $this->wrapColorTable( $root? ''.htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']).'': t3lib_iconWorks::getIconImage($table,$this->rec,$this->backPath,' hspace="5" align="absmiddle"'.t3lib_BEfunc::titleAttrib(t3lib_BEfunc::getRecordIconAltText($this->rec,$table))).''.t3lib_BEfunc::getRecordTitle($table,$this->rec,1).'' ) ); } /** * Processing the $menuItems array (for extension classes) (DATABASE RECORDS) * * @param array $menuItems array for manipulation. * @return array Processed $menuItems array */ function externalProcessingOfDBMenuItems($menuItems) { return $menuItems; } /** * Processing the $menuItems array by external classes (typ. adding items) * * @param array $menuItems array for manipulation. * @param string Table name * @param integer UID for the current record. * @return array Processed $menuItems array */ function processingByExtClassArray($menuItems,$table,$uid) { if (is_array($this->extClassArray)) { reset($this->extClassArray); while(list(,$conf)=each($this->extClassArray)) { $obj=t3lib_div::makeInstance($conf['name']); $menuItems = $obj->main($this,$menuItems,$table,$uid); } } return $menuItems; } /** * Returning JavaScript for the onClick event linking to the input URL. * * @param string The URL relative to TYPO3_mainDir * @param string The return_url-parameter * @param boolean If set, the "hideCM()" will be called * @return string JavaScript for an onClick event. */ function urlRefForCM($url,$retUrl='',$hideCM=1) { $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $editOnClick='var docRef=(top.content.list_frame)?top.content.list_frame:'.$loc.'; docRef.document.location=top.TS.PATH_typo3+\''.$url.'\''. ($retUrl?"+'&".$retUrl."='+top.rawurlencode(".$this->frameLocation('docRef.document').')':'').';'. ($hideCM?'return hideCM();':''); return $editOnClick; } /** * Adding CM element for Clipboard "copy" and "cut" * * @param string Table name * @param integer UID for the current record. * @param string Type: "copy" or "cut" * @return array Item array, element in $menuItems * @internal */ function DB_copycut($table,$uid,$type) { if ($this->clipObj->current=='normal') { $isSel = $this->clipObj->isSelected($table,$uid); } return $this->linkItem( $this->label($type), $this->excludeIcon(''), "top.loadTopMenu('".$this->clipObj->selUrlDB($table,$uid,($type=='copy'?1:0),($isSel==$type))."');return false;" ); } /** * Adding CM element for Clipboard "paste into"/"paste after" * NOTICE: $table and $uid should follow the special syntax for paste, see clipboard-class :: pasteUrl(); * * @param string Table name * @param integer UID for the current record. NOTICE: Special syntax! * @param string Type: "into" or "after" * @param array Contains instructions about whether to copy or cut an element. * @return array Item array, element in $menuItems * @see t3lib_clipboard::pasteUrl() * @internal */ function DB_paste($table,$uid,$type,$elInfo) { $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $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])).')'; $editOnClick='if('.$conf.'){'.$loc.'.document.location=top.TS.PATH_typo3+\''.$this->clipObj->pasteUrl($table,$uid,0).'&redirect=\'+top.rawurlencode('.$this->frameLocation($loc.'.document').'); hideCM();}'; return $this->linkItem( $this->label('paste'.$type), $this->excludeIcon(''), $editOnClick.'return false;' ); } /** * Adding CM element for Info * * @param string Table name * @param integer UID for the current record. * @return array Item array, element in $menuItems * @internal */ function DB_info($table,$uid) { return $this->linkItem( $this->label('info'), $this->excludeIcon(''), "top.launchView('".$table."', '".$uid."'); return hideCM();" ); } /** * Adding CM element for History * * @param string Table name * @param integer UID for the current record. * @return array Item array, element in $menuItems * @internal */ function DB_history($table,$uid) { $url = 'show_rechis.php?element='.rawurlencode($table.':'.$uid); return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_history')), $this->excludeIcon(''), $this->urlRefForCM($url,'returnUrl'), 0 ); } /** * Adding CM element for Permission setting * * @param string Table name * @param integer UID for the current record. * @param array The "pages" record with "perms_*" fields inside. * @return array Item array, element in $menuItems * @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':''); return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_perms')), $this->excludeIcon(''), $this->urlRefForCM($url), 0 ); } /** * Adding CM element for DBlist * * @param string Table name * @param integer UID for the current record. * @param array Record of the element (needs "pid" field if not pages-record) * @return array Item array, element in $menuItems * @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']); return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_db_list')), $this->excludeIcon(''), "top.nextLoadModuleUrl='".$url."';top.goToModule('web_list',1);", 0 ); } /** * Adding CM element for Moving wizard * * @param string Table name * @param integer UID for the current record. * @param array Record. Needed for tt-content elements which will have the sys_language_uid sent * @return array Item array, element in $menuItems * @internal */ function DB_moveWizard($table,$uid,$rec) { $url = 'move_el.php?table='.$table.'&uid='.$uid. ($table=='tt_content'?'&sys_language_uid='.intval($rec['sys_language_uid']):''); // Hardcoded field for tt_content elements. return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_moveWizard'.($table=='pages'?'_page':''))), $this->excludeIcon(''), $this->urlRefForCM($url,'returnUrl'), 0 ); } /** * Adding CM element for Create new wizard (either db_new.php or db_new_content_el.php) * * @param string Table name * @param integer UID for the current record. * @param array Record. * @return array Item array, element in $menuItems * @internal */ function DB_newWizard($table,$uid,$rec) { $url = ($table=='pages') ? 'db_new.php?id='.$uid.'&pagesOnly=1' : 'db_new_content_el.php?id='.$rec['pid'].'&sys_language_uid='.intval($rec['sys_language_uid']); return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_newWizard')), $this->excludeIcon(''), $this->urlRefForCM($url,'returnUrl'), 0 ); } /** * Adding CM element for Editing of the access related fields of a table (disable, starttime, endtime, fe_groups) * * @param string Table name * @param integer UID for the current record. * @return array Item array, element in $menuItems * @internal */ function DB_editAccess($table,$uid) { $addParam='&columnsOnly='.implode(',',$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']); $url = 'alt_doc.php?edit['.$table.']['.$uid.']=edit'.$addParam; return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editAccess')), $this->excludeIcon(''), $this->urlRefForCM($url,'returnUrl'), 1 // no top frame CM! ); } /** * Adding CM element for edit page header * * @param integer page uid to edit (PID) * @return array Item array, element in $menuItems * @internal */ function DB_editPageHeader($uid) { $url = 'alt_doc.php?edit[pages]['.$uid.']=edit'; return $this->linkItem( $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->getLL('CM_editPageHeader')), $this->excludeIcon(''), $this->urlRefForCM($url,'returnUrl'), 1 // no top frame CM! ); } /** * Adding CM element for regular editing of the element! * * @param string Table name * @param integer UID for the current record. * @return array Item array, element in $menuItems * @internal */ function DB_edit($table,$uid) { global $BE_USER; $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $addParam=''; $theIcon = 'gfx/edit2.gif" width="11" height="12"'; if ( $this->iParts[0]=='pages' && $this->iParts[1] && $GLOBALS['BE_USER']->check('modules','web_layout') ) { $theIcon = 'gfx/edit_page.gif" width="12" height="12"'; $this->editPageIconSet=1; if ($BE_USER->uc['classicPageEditMode'] || !t3lib_extMgm::isLoaded('cms')) { $addParam='&editRegularContentFromId='.intval($this->iParts[1]); } else { $editOnClick="top.fsMod.recentIds['web']=".intval($this->iParts[1]).";top.goToModule('web_layout',1);"; } } if (!$editOnClick) { $editOnClick="if(".$loc."){".$loc.".document.location=top.TS.PATH_typo3+'alt_doc.php?returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'&edit[".$table."][".$uid."]=edit".$addParam."';}"; } return $this->linkItem( $this->label('edit'), $this->excludeIcon(''), $editOnClick.'return hideCM();' ); } /** * Adding CM element for regular Create new element * * @param string Table name * @param integer UID for the current record. * @return array Item array, element in $menuItems * @internal */ function DB_new($table,$uid) { $editOnClick=''; $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':''); $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'". ($this->listFrame? $this->backPath."alt_doc.php?returnUrl='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'&edit[".$table."][-".$uid."]=new'": $this->backPath.'db_new.php?id='.intval($uid)."'"). ';}'; return $this->linkItem( $this->label('new'), $this->excludeIcon(''), $editOnClick.'return hideCM();' ); } /** * Adding CM element for hide/unhide of the input record * * @param string Table name * @param array Record * @param string Name of the hide field * @return array Item array, element in $menuItems * @internal */ function DB_hideUnhide($table,$rec,$hideField) { $uid=$rec['uid']; $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'tce_db.php?redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').")+'". "&data[".$table.']['.$uid.']['.$hideField.']='.($rec[$hideField]?0:1).'&prErr=1&vC='.$GLOBALS['BE_USER']->veriCode()."';hideCM();}"; return $this->linkItem( $this->label(($rec[$hideField]?'un':'').'hide'), $this->excludeIcon(''), $editOnClick.'return false;', 1 ); } /** * Adding CM element for Delete * * @param string Table name * @param integer UID for the current record. * @param array Label for including in the confirmation message, EXT:lang/locallang_core.php:mess.delete * @return array Item array, element in $menuItems * @internal */ function DB_delete($table,$uid,$elInfo) { $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $editOnClick='if('.$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),$elInfo[0])).")){".$loc.".document.location=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();}"; return $this->linkItem( $this->label('delete'), $this->excludeIcon(''), $editOnClick.'return false;' ); } /** * Adding CM element for View Page * * @param integer Page uid (PID) * @param string Anchor, if any * @return array Item array, element in $menuItems * @internal */ function DB_view($id,$anchor='') { return $this->linkItem( $this->label('view'), $this->excludeIcon(''), t3lib_BEfunc::viewOnClick($id,$this->backPath,t3lib_BEfunc::BEgetRootLine($id),$anchor).'return hideCM();' ); } /*************************************** * * FILE * ***************************************/ /** * Make 1st level clickmenu: * * @param string The absolute path * @return string HTML content */ function printFileClickMenu($path) { $menuItems=array(); if (@file_exists($path) && t3lib_div::isAllowedAbsPath($path)) { $fI = pathinfo($path); $icon = is_dir($path) ? 'folder.gif' : t3lib_BEfunc::getFileIcon(strtolower($fI['extension'])); $size=' ('.t3lib_div::formatSize(filesize($path)).'bytes)'; $icon = ''; // edit 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'); // rename if (!in_array('rename',$this->disabledItems)) $menuItems['rename']=$this->FILE_launch($path,'file_rename.php','rename','rename.gif'); // upload if (!in_array('upload',$this->disabledItems) && is_dir($path)) $menuItems['upload']=$this->FILE_launch($path,'file_upload.php','upload','upload.gif'); // new if (!in_array('new',$this->disabledItems) && is_dir($path)) $menuItems['new']=$this->FILE_launch($path,'file_newfolder.php','new','new_file.gif'); // info if (!in_array('info',$this->disabledItems)) $menuItems['info']=$this->DB_info($path,''); $menuItems[]='spacer'; // copy: if (!in_array('copy',$this->disabledItems)) $menuItems['copy']=$this->FILE_copycut($path,'copy'); // cut: if (!in_array('cut',$this->disabledItems)) $menuItems['cut']=$this->FILE_copycut($path,'cut'); // Paste: $elFromAllTables = count($this->clipObj->elFromTable('_FILE')); if (!in_array('paste',$this->disabledItems) && $elFromAllTables && is_dir($path)) { $elArr = $this->clipObj->elFromTable('_FILE'); reset($elArr); $selItem = current($elArr); $elInfo=array( basename($selItem), basename($path), $this->clipObj->currentMode() ); $menuItems['pasteinto']=$this->FILE_paste($path,$selItem,$elInfo); } $menuItems[]='spacer'; // delete: if (!in_array('delete',$this->disabledItems)) $menuItems['delete']=$this->FILE_delete($path); } // Adding external elements to the menuItems array $menuItems = $this->processingByExtClassArray($menuItems,$path,0); // Processing by external functions? $menuItems = $this->externalProcessingOfFileMenuItems($menuItems); // Return the printed elements: return $this->printItems($menuItems, $this->wrapColorTable( $icon.''.basename($path).'' ) ); } /** * Processing the $menuItems array (for extension classes) (FILES) * * @param array $menuItems array for manipulation. * @return array Processed $menuItems array */ function externalProcessingOfFileMenuItems($menuItems) { return $menuItems; } /** * Multi-function for adding an entry to the $menuItems array * * @param string Path to the file/directory (target) * @param string Script (eg. file_edit.php) to pass &target= to * @param string "type" is the code which fetches the correct label for the element from "cm." * @param string icon image-filename from "gfx/" (12x12 icon) * @return array Item array, element in $menuItems * @internal */ function FILE_launch($path,$script,$type,$image) { $loc='top.content'.(!$this->alwaysContentFrame?'.list_frame':''); $editOnClick='if('.$loc.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$script.'?target='.rawurlencode($path)."';}"; return $this->linkItem( $this->label($type), $this->excludeIcon(''), $editOnClick.'return hideCM();' ); } /** * Returns element for copy or cut of files. * * @param string Path to the file/directory (target) * @param string Type: "copy" or "cut" * @return array Item array, element in $menuItems * @internal */ function FILE_copycut($path,$type) { $table='_FILE'; // Pseudo table name for use in the clipboard. $uid = t3lib_div::shortmd5($path); if ($this->clipObj->current=='normal') { $isSel = $this->clipObj->isSelected($table,$uid); } return $this->linkItem( $this->label($type), $this->excludeIcon(''), "top.loadTopMenu('".$this->clipObj->selUrlFile($path,($type=='copy'?1:0),($isSel==$type))."');return false;" ); } /** * Creates element for deleting of target * * @param string Path to the file/directory (target) * @return array Item array, element in $menuItems * @internal */ function FILE_delete($path) { $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $editOnClick='if('.$loc." && confirm(".$GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:mess.delete'),basename($path))).")){".$loc.".document.location=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();}"; return $this->linkItem( $this->label('delete'), $this->excludeIcon(''), $editOnClick.'return false;' ); } /** * Creates element for pasting files. * * @param string Path to the file/directory (target) * @param string target - NOT USED. * @param array Various values for the labels. * @return array Item array, element in $menuItems * @internal */ function FILE_paste($path,$target,$elInfo) { $editOnClick=''; $loc='top.content'.($this->listFrame && !$this->alwaysContentFrame ?'.list_frame':''); $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])).")"; $editOnClick='if('.$conf.'){'.$loc.".document.location=top.TS.PATH_typo3+'".$this->clipObj->pasteUrl('_FILE',$path,0). "&redirect='+top.rawurlencode(".$this->frameLocation($loc.'.document').'); hideCM();}'; return $this->linkItem( $this->label('pasteinto'), $this->excludeIcon(''), $editOnClick.'return false;' ); } /*************************************** * * COMMON * **************************************/ /** * Prints the items from input $menuItems array - both as topframe menu AND the JS section for writing to the div-layers. * Of course the topframe menu will appear only if $this->doDisplayTopFrameCM() returns true * * @param array $menuItems array * @param string HTML code for the element which was clicked - shown in the end of the horizontal menu in topframe after the close-button. * @return string HTML code */ function printItems($menuItems,$item) { $out=''; // Adding topframe part (horizontal clickmenu) if ($this->doDisplayTopFrameCM()) { $out.= '
'. implode('',$this->menuItemsForTopFrame($menuItems)). ' sL('LLL:EXT:lang/locallang_core.php:labels.close'),1).' alt="" /> '.$item.'


'; } // Adding JS part: $out.=$this->printLayerJScode($menuItems); // Return the content return $out; } /** * Create the JavaScript section * * @param array The $menuItems array to print * @return string The JavaScript section which will print the content of the CM to the div-layer in the target frame. */ function printLayerJScode($menuItems) { $script=''; if ($this->isCMlayers()) { // Clipboard must not be submitted - then it's probably a copy/cut situation. $frameName = '.'.($this->listFrame ? 'list_frame' : 'nav_frame'); if ($this->alwaysContentFrame) $frameName=''; // Create the table displayed in the clickmenu layer: $CMtable = ''. implode('',$this->menuItemsForClickMenu($menuItems)). '
'; // Wrap the inner table in another table to create outer border: $CMtable = $this->wrapColorTableCM($CMtable); // Create JavaScript section: $script=$GLOBALS['TBE_TEMPLATE']->wrapScriptTags(' if (top.content && top.content'.$frameName.' && top.content'.$frameName.'.setLayerObj) { top.content'.$frameName.'.setLayerObj(unescape("'.t3lib_div::rawurlencodeJS($CMtable).'"),'.$this->cmLevel.'); } '.(!$this->doDisplayTopFrameCM()?'hideCM();':'') ); } return $script; } /** * Wrapping the input string in a table with background color 4 and a black border style. * * @param string * @return string */ function wrapColorTableCM($str) { $str = '
'.$str.'
'; return $str; } /** * Wrapping the input string in a table with background color 2 and a black border style. * * @param string * @return string */ function wrapColorTable($str) { return '
'.$str.'
'; } /** * Traverses the menuItems and generates an output array for implosion in the topframe horizontal menu * * @param array $menuItem array * @param array Array with HTML content to be imploded between -tags * @return array Array of menu items for top frame. */ function menuItemsForTopFrame($menuItems) { reset($menuItems); $out=array(); while(list(,$i)=each($menuItems)) { 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) if (is_array($i) && !$i[4]) $out[]=$i[0]; } return $out; } /** * Traverses the menuItems and generates an output array for implosion in the CM div-layers table. * * @param array $menuItem array * @param array Array with HTML content to be imploded between -tags * @return array array for implosion in the CM div-layers table. */ function menuItemsForClickMenu($menuItems) { reset($menuItems); $out=array(); while(list($cc,$i)=each($menuItems)) { if (is_string($i) && $i=='spacer') { // MAKE horizontal spacer $out[]=' '; } else { // Just make normal element: $onClick=$i[3]; $onClick=eregi_replace('return[[:space:]]+hideCM\(\)[[:space:]]*;','',$onClick); $onClick=eregi_replace('return[[:space:]]+false[[:space:]]*;','',$onClick); $onClick=eregi_replace('hideCM\(\);','',$onClick); if (!$i[5]) $onClick.='hideEmpty();'; $out[]=''. (!$this->leftIcons?'  '.$i[1].' '.$i[2].'  ' : ' '.$i[2].'  '.$i[1].'  '). ''; } } return $out; } /** * Creating an array with various elements for the clickmenu entry * * @param string The label, htmlspecialchar'ed already * @param string -tag for the icon * @param string JavaScript onclick event for label/icon * @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) * @param boolean If set, the clickmenu layer will not hide itself onclick - used for secondary menus to appear... * @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! */ function linkItem($str,$icon,$onClick,$onlyCM=0,$dontHide=0) { $this->elCount++; return array( ''. ''. $str.$icon. '', $str, $icon, $onClick, $onlyCM, $dontHide ); } /** * Returns the input string IF not a user setting has disabled display of icons. * * @param string The icon-image tag * @return string The icon-image tag prefixed with space char IF the icon should be printed at all due to user settings */ function excludeIcon($iconCode) { return ($GLOBALS['BE_USER']->uc['noMenuMode'] && strcmp($GLOBALS['BE_USER']->uc['noMenuMode'],'icons')) ? '' : ' '.$iconCode; } /** * Get label from locallang_core.php:cm.* * * @param string The "cm."-suffix to get. * @return string */ function label($label) { return $GLOBALS['LANG']->makeEntities($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.'.$label,1)); } /** * Returns true if there should be writing to the div-layers (commands sent to clipboard MUST NOT write to div-layers) * * @return boolean */ function isCMlayers() { return $GLOBALS['SOBE']->doc->isCMlayers() && !t3lib_div::GPvar('CB'); } /** * Appends ".location" to input string * * @param string * @return string */ function frameLocation($str) { return $str.'.location'; } } /** * Main Script Class * * @author Kasper Skaarhoj * @package TYPO3 * @subpackage core */ class SC_alt_clickmenu { var $content=''; // Content accumulation var $doc; // Template object var $include_once=array(); // Files to include_once() - set in init() function var $extClassArray=array(); // Internal array of classes for extending the clickmenu var $dontDisplayTopFrameCM=0; // If set, then the clickmenu will NOT display in the top frame. /** * Constructor: * * @return void */ function init() { global $BE_USER,$BACK_PATH; // Setting pseudo module name $this->MCONF['name']='xMOD_alt_clickmenu.php'; // Setting internal array of classes for extending the clickmenu: $this->extClassArray = $GLOBALS['TBE_MODULES_EXT']['xMOD_alt_clickmenu']['extendCMclasses']; // Traversing that array and setting files for inclusion: if (is_array($this->extClassArray)) { reset($this->extClassArray); while(list(,$extClassConf)=each($this->extClassArray)) { if ($extClassConf['path']) $this->include_once[]=$extClassConf['path']; } } // Initialize template object $this->doc = t3lib_div::makeInstance('template'); $this->doc->docType='xhtml_trans'; $this->doc->inDocStyles = 'BODY {background-color: '.$this->doc->bgColor2.'; background-image: url(gfx/alt_topmenu_back_full.gif)}'; $this->doc->backPath = $BACK_PATH; // Setting mode for display and background image in the top frame $this->dontDisplayTopFrameCM= $this->doc->isCMlayers() && !$GLOBALS['BE_USER']->getTSConfigVal('options.contextMenu.options.alwaysShowClickMenuInTopFrame'); if ($this->dontDisplayTopFrameCM) { $this->doc->inDocStyles = 'BODY {background-color: '.$this->doc->bgColor2.'; background-image: url(gfx/alt_topmenu_back_dummy.gif)}'; } // Setting clickmenu timeout $secs = t3lib_div::intInRange($BE_USER->getTSConfigVal('options.contextMenu.options.clickMenuTimeOut'),1,100,5); // default is 5 // Setting the JavaScript controlling the timer on the page $this->doc->JScode.=$this->doc->wrapScriptTags(' var date = new Date(); var mo_timeout = Math.floor(date.getTime()/1000); roImg =new Image(); roImg.src = "gfx/content_client.gif"; routImg =new Image(); routImg.src = "clear.gif"; function mo(c) { // var name="roimg_"+c; document[name].src = roImg.src; updateTime(); } function mout(c) { // var name="roimg_"+c; document[name].src = routImg.src; updateTime(); } function updateTime() { // date = new Date(); mo_timeout = Math.floor(date.getTime()/1000); } function timeout_func() { // date = new Date(); if (Math.floor(date.getTime()/1000)-mo_timeout > '.$secs.') { hideCM(); return false; } else { window.setTimeout("timeout_func();",1*1000); } } function hideCM() { // document.location="alt_topmenu_dummy.php"; return false; } // Start timer timeout_func(); '); } /** * Main function - generating the click menu in whatever form it has. * * @return void */ function main() { global $HTTP_GET_VARS; // Initialize Clipboard object: $clipObj = t3lib_div::makeInstance('t3lib_clipboard'); $clipObj->initializeClipboard(); $clipObj->lockToNormal(); // This locks the clipboard to the Normal for this request. // Update clipboard if some actions are sent. $CB = $HTTP_GET_VARS['CB']; $clipObj->setCmd($CB); $clipObj->cleanCurrent(); $clipObj->endClipboard(); // Saves // Create clickmenu object $clickMenu = t3lib_div::makeInstance('clickMenu'); // Set internal vars in clickmenu object: $clickMenu->clipObj = $clipObj; $clickMenu->extClassArray = $this->extClassArray; $clickMenu->dontDisplayTopFrameCM = $this->dontDisplayTopFrameCM; // 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: $inputBP = explode('|',t3lib_div::GPvar('backPath')); if (count($inputBP)==2 && $inputBP[1]==md5($inputBP[0].'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) { $clickMenu->backPath = $inputBP[0]; } // Start page $this->content.=$this->doc->startPage('Context Sensitive Menu'); // Set content of the clickmenu with the incoming var, "item" $this->content.= $clickMenu->init(t3lib_div::GPvar('item')); } /** * End page and output content. * * @return void */ function printContent() { $this->content.= $this->doc->endPage(); echo $this->content; } } // Include extension? 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']); } // Make instance: $SOBE = t3lib_div::makeInstance('SC_alt_clickmenu'); $SOBE->init(); // Include files? reset($SOBE->include_once); while(list(,$INC_FILE)=each($SOBE->include_once)) {include_once($INC_FILE);} $SOBE->main(); $SOBE->printContent(); ?>