|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZTopMenuOperator class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZTopMenuOperator eztopmenuoperator.php 00013 \brief The class eZTopMenuOperator does 00014 00015 */ 00016 00017 00018 class eZTopMenuOperator 00019 { 00020 /*! 00021 Constructor 00022 */ 00023 function eZTopMenuOperator( $name = 'topmenu' ) 00024 { 00025 $this->Operators = array( $name ); 00026 $this->DefaultNames = array( 00027 'content' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00028 'Content structure' ), 00029 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00030 'Manage the main content structure of the site.' ) ), 00031 'media' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00032 'Media library' ), 00033 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00034 'Manage images, files, documents, etc.' ) ), 00035 'users' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00036 'User accounts' ), 00037 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00038 'Manage users, user groups and permission settings.' ) ), 00039 'shop' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00040 'Webshop' ), 00041 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00042 'Manage customers, orders, discounts and VAT types; view sales statistics.' ) ), 00043 'design' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00044 'Design' ), 00045 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00046 'Manage templates, menus, toolbars and other things related to appearence.' ) ), 00047 'setup' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00048 'Setup' ), 00049 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00050 'Configure settings and manage advanced functionality.' ) ), 00051 'dashboard' => array( 'name' => ezpI18n::tr( 'design/admin/pagelayout', 00052 'Dashboard' ), 00053 'tooltip'=> ezpI18n::tr( 'design/admin/pagelayout', 00054 'Manage items and settings that belong to your account.' ) ) ); 00055 } 00056 00057 /*! 00058 Returns the operators in this class. 00059 */ 00060 function operatorList() 00061 { 00062 return $this->Operators; 00063 } 00064 00065 /*! 00066 See eZTemplateOperator::namedParameterList() 00067 */ 00068 function namedParameterList() 00069 { 00070 return array( 'context' => array( 'type' => 'string', 00071 'required' => true, 00072 'default' => 'content' ), 00073 'filter_on_access' => array( 'type' => 'bool', 00074 'required' => false, 00075 'default' => false ) ); 00076 } 00077 00078 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 00079 { 00080 00081 $ini = eZINI::instance( 'menu.ini' ); 00082 00083 if ( !$ini->hasVariable( 'TopAdminMenu', 'Tabs' ) ) 00084 { 00085 eZDebug::writeError( 'Top Admin menu is not configured. Ini setting [TopAdminMenu] Tabs[] is missing' ); 00086 $operatorValue = array(); 00087 return; 00088 } 00089 00090 $menu = array(); 00091 $context = $namedParameters['context']; 00092 $tabIDs = $ini->variable( 'TopAdminMenu', 'Tabs' ); 00093 foreach ( $tabIDs as $tabID ) 00094 { 00095 $shownList = $ini->variable( 'Topmenu_' . $tabID , 'Shown' ); 00096 if ( isset( $shownList[$context] ) && $shownList[$context] === 'false' ) 00097 { 00098 continue; 00099 } 00100 00101 $menuItem = array(); 00102 $menuItem['access'] = true; 00103 if ( $ini->hasVariable( 'Topmenu_' . $tabID , 'PolicyList' ) ) 00104 { 00105 $policyList = $ini->variable( 'Topmenu_' . $tabID , 'PolicyList' ); 00106 foreach( $policyList as $policy ) 00107 { 00108 // Value is either "<node_id>" or "<module>/<function>" 00109 if ( strpos( $policy, '/' ) !== false ) 00110 { 00111 if ( !isset( $user ) ) 00112 $user = eZUser::currentUser(); 00113 00114 list( $module, $function ) = explode( '/', $policy ); 00115 $result = $user->hasAccessTo( $module, $function ); 00116 00117 if ( $result['accessWord'] === 'no' ) 00118 { 00119 $menuItem['access'] = false; 00120 break; 00121 } 00122 } 00123 else 00124 { 00125 $node = eZContentObjectTreeNode::fetch( $policy ); 00126 if ( !$node instanceof eZContentObjectTreeNode || !$node->attribute('can_read') ) 00127 { 00128 $menuItem['access'] = false; 00129 break; 00130 } 00131 } 00132 } 00133 } 00134 00135 if ( $namedParameters['filter_on_access'] && !$menuItem['access'] ) 00136 { 00137 continue; 00138 } 00139 00140 $urlList = $ini->variable( 'Topmenu_' . $tabID , 'URL' ); 00141 if ( isset( $urlList[$context] ) ) 00142 { 00143 $menuItem['url'] = $urlList[$context]; 00144 } 00145 else 00146 { 00147 $menuItem['url'] = $urlList['default']; 00148 } 00149 00150 $enabledList = $ini->variable( 'Topmenu_' . $tabID , 'Enabled' ); 00151 if ( isset( $enabledList[$context] ) ) 00152 { 00153 if ( $enabledList[$context] == 'true' ) 00154 $menuItem['enabled'] = true; 00155 else 00156 $menuItem['enabled'] = false; 00157 } 00158 else 00159 { 00160 if ( $enabledList['default'] == true ) 00161 $menuItem['enabled'] = true; 00162 else 00163 $menuItem['enabled'] = false; 00164 } 00165 00166 if ( $ini->hasVariable( 'Topmenu_' . $tabID , 'Name' ) && $ini->variable( 'Topmenu_' . $tabID , 'Name' ) != '' ) 00167 { 00168 $menuItem['name'] = $ini->variable( 'Topmenu_' . $tabID , 'Name' ); 00169 } 00170 else 00171 { 00172 $menuItem['name'] = $this->DefaultNames[$tabID]['name']; 00173 } 00174 00175 if ( $ini->hasVariable( 'Topmenu_' . $tabID , 'Tooltip' ) && $ini->variable( 'Topmenu_' . $tabID , 'Tooltip' ) != '' ) 00176 { 00177 $menuItem['tooltip'] = $ini->variable( 'Topmenu_' . $tabID , 'Tooltip' ); 00178 } 00179 else 00180 { 00181 $menuItem['tooltip'] = isset( $this->DefaultNames[$tabID]['tooltip'] ) ? $this->DefaultNames[$tabID]['tooltip'] : ''; 00182 } 00183 00184 $menuItem['navigationpart_identifier'] = $ini->variable( 'Topmenu_' . $tabID , 'NavigationPartIdentifier' ); 00185 $menuItem['position'] = 'middle'; 00186 $menu[] = $menuItem; 00187 00188 } 00189 $menu[0]['position'] = 'first'; 00190 $menu[count($menu) - 1]['position'] = 'last'; 00191 00192 $operatorValue = $menu; 00193 } 00194 00195 /// \privatesection 00196 public $Operators; 00197 public $DefaultNames; 00198 } 00199 00200 00201 ?>