|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2007-2011 Ingo Renner <ingo@typo3.org> 00006 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces) 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * A copy is found in the textfile GPL.txt and important notices to the license 00018 * from the author is found in LICENSE.txt distributed with these scripts. 00019 * 00020 * 00021 * This script is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * This copyright notice MUST APPEAR in all copies of the script! 00027 ***************************************************************/ 00028 00029 if(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) { 00030 require_once(PATH_typo3 . 'interfaces/interface.backend_toolbaritem.php'); 00031 } 00032 00033 /** 00034 * class to render the workspace selector 00035 * 00036 * @author Ingo Renner <ingo@typo3.org> 00037 * @package Workspaces 00038 * @subpackage BackendUserInterface 00039 */ 00040 class WorkspaceSelectorToolbarItem implements backend_toolbarItem { 00041 00042 protected $changeWorkspace; 00043 protected $changeWorkspacePreview; 00044 00045 /** 00046 * reference back to the backend object 00047 * 00048 * @var TYPO3backend 00049 */ 00050 protected $backendReference; 00051 00052 protected $checkAccess = NULL; 00053 00054 /** 00055 * constructor 00056 * 00057 * @param TYPO3backend TYPO3 backend object reference 00058 */ 00059 public function __construct(TYPO3backend &$backendReference = null) { 00060 $this->backendReference = $backendReference; 00061 $this->changeWorkspace = t3lib_div::_GP('changeWorkspace'); 00062 $this->changeWorkspacePreview = t3lib_div::_GP('changeWorkspacePreview'); 00063 00064 $pageRenderer = t3lib_div::makeInstance('t3lib_pageRenderer'); 00065 $this->backendReference->addJavaScript("TYPO3.Workspaces = { workspaceTitle : '" . tx_Workspaces_Service_Workspaces::getWorkspaceTitle($GLOBALS['BE_USER']->workspace) . "'};\n"); 00066 } 00067 00068 /** 00069 * checks whether the user has access to this toolbar item 00070 * 00071 * @see typo3/alt_shortcut.php 00072 * @return boolean true if user has access, false if not 00073 */ 00074 public function checkAccess() { 00075 if (t3lib_extMgm::isLoaded('workspaces')) { 00076 if ($this->checkAccess == NULL) { 00077 $availableWorkspaces = tx_Workspaces_Service_Workspaces::getAvailableWorkspaces(); 00078 if (count($availableWorkspaces) > 0) { 00079 $this->checkAccess = TRUE; 00080 } else { 00081 $this->checkAccess = FALSE; 00082 } 00083 } 00084 return $this->checkAccess; 00085 } 00086 return FALSE; 00087 } 00088 00089 /** 00090 * Creates the selector for workspaces 00091 * 00092 * @return string workspace selector as HTML select 00093 */ 00094 public function render() { 00095 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.workspace', true); 00096 $this->addJavascriptToBackend(); 00097 $availableWorkspaces = tx_Workspaces_Service_Workspaces::getAvailableWorkspaces(); 00098 $workspaceMenu = array(); 00099 00100 $stateCheckedIcon = t3lib_iconWorks::getSpriteIcon('status-status-checked'); 00101 00102 $stateUncheckedIcon = t3lib_iconWorks::getSpriteIcon('empty-empty', array( 00103 'title' => $GLOBALS['LANG']->getLL('bookmark_inactive') 00104 )); 00105 00106 $workspaceMenu[] = '<a href="#" class="toolbar-item">' . 00107 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-workspace', array('title' => $title)) . 00108 '</a>'; 00109 $workspaceMenu[] = '<ul class="toolbar-item-menu" style="display: none;">'; 00110 00111 if (count($availableWorkspaces)) { 00112 foreach($availableWorkspaces as $workspaceId => $label) { 00113 $selected = ''; 00114 $icon = $stateUncheckedIcon; 00115 if((int) $GLOBALS['BE_USER']->workspace === $workspaceId) { 00116 $selected = ' class="selected"'; 00117 $icon = $stateCheckedIcon; 00118 } 00119 00120 $workspaceMenu[] = '<li' . $selected . '>' . $icon . 00121 ' <a href="backend.php?changeWorkspace=' . 00122 intval($workspaceId) . '" id="ws-' . intval($workspaceId) . 00123 '" class="ws">' . $label . '</a></li>'; 00124 } 00125 } else { 00126 $workspaceMenu[] = '<li>' . $stateUncheckedIcon . ' ' . 00127 $GLOBALS['LANG']->getLL('bookmark_noWSfound', true) . 00128 '</li>'; 00129 } 00130 00131 if ($GLOBALS['BE_USER']->check('modules', 'web_WorkspacesWorkspaces')) { 00132 // go to workspace module link 00133 $workspaceMenu[] = '<li class="divider">' . $stateUncheckedIcon . ' ' . 00134 '<a href="javascript:top.goToModule(\'web_WorkspacesWorkspaces\');" target="content" id="goToWsModule">' . 00135 ' '. $GLOBALS['LANG']->getLL('bookmark_workspace', true) . '</a></li>'; 00136 } 00137 00138 $workspaceMenu[] = '</ul>'; 00139 00140 return implode(LF, $workspaceMenu); 00141 } 00142 00143 /** 00144 * adds the necessary JavaScript to the backend 00145 * 00146 * @return void 00147 */ 00148 protected function addJavascriptToBackend() { 00149 $this->backendReference->addJavascriptFile(t3lib_extMgm::extRelPath('workspaces') . 'Resources/Public/JavaScript/workspacemenu.js'); 00150 } 00151 00152 /** 00153 * returns additional attributes for the list item in the toolbar 00154 * 00155 * @return string list item HTML attibutes 00156 */ 00157 public function getAdditionalAttributes() { 00158 return ' id="workspace-selector-menu"'; 00159 } 00160 } 00161 00162 00163 if(!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) { 00164 $GLOBALS['TYPO3backend']->addToolbarItem('workSpaceSelector', 'WorkspaceSelectorToolbarItem'); 00165 } 00166 00167 00168 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/BackendUserInterface/WorkspaceSelectorToolbarItem.php'])) { 00169 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/BackendUserInterface/WorkspaceSelectorToolbarItem.php']); 00170 } 00171 ?>
1.8.0