From b39075ed3fd86931843194be33ebf9776655eb2c Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Sat, 23 Jul 2016 17:59:30 +1000 Subject: [PATCH] =?UTF-8?q?Show=20=E2=80=98main=5Fmenu=5Fcustom=5Foptions?= =?UTF-8?q?=E2=80=99=20in=20main=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #21414 --- core/html_api.php | 21 --------------- core/layout_api.php | 62 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/core/html_api.php b/core/html_api.php index 937a34ada1..daad017a9c 100644 --- a/core/html_api.php +++ b/core/html_api.php @@ -415,27 +415,6 @@ function html_end() { } } -/** - * Prepare an array of additional menu options from a configuration variable - * @param string $p_config Configuration variable name. - * @return array - */ -function prepare_custom_menu_options( $p_config ) { - $t_custom_menu_options = config_get( $p_config ); - $t_options = array(); - - foreach( $t_custom_menu_options as $t_custom_option ) { - $t_access_level = $t_custom_option[1]; - if( access_has_project_level( $t_access_level ) ) { - $t_caption = string_html_specialchars( lang_get_defaulted( $t_custom_option[0] ) ); - $t_link = string_attribute( $t_custom_option[2] ); - $t_options[] = '' . $t_caption . ''; - } - } - - return $t_options; -} - /** * Print the menu bar with a list of projects to which the user has access * @return void diff --git a/core/layout_api.php b/core/layout_api.php index a030676323..6a163d0657 100644 --- a/core/layout_api.php +++ b/core/layout_api.php @@ -706,17 +706,15 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) { # Starting sidebar markup layout_sidebar_begin(); - $t_menu_options = array(); + # Plugin / Event added options + $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN_FRONT' ); + layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page ); # Main Page if( config_get( 'news_enabled' ) == ON ) { layout_sidebar_menu( 'main_page.php', 'main_link', 'fa-bullhorn', $p_active_sidebar_page ); } - # Plugin / Event added options - $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN_FRONT' ); - layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page ); - # My View layout_sidebar_menu( 'my_view_page.php', 'my_view_link', 'fa-dashboard', $p_active_sidebar_page ); @@ -754,10 +752,6 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) { layout_sidebar_menu( 'wiki.php?type=project&id=' . $t_current_project, 'wiki', 'fa-book', $p_active_sidebar_page ); } - # Plugin / Event added options - $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN' ); - layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page ); - # Manage Users (admins) or Manage Project (managers) or Manage Custom Fields if( access_has_global_level( config_get( 'manage_site_threshold' ) ) ) { layout_sidebar_menu( 'manage_overview_page.php', 'manage_link', 'fa-gears', $p_active_sidebar_page ); @@ -778,15 +772,18 @@ function layout_print_sidebar( $p_active_sidebar_page = null ) { } } - # Add custom options - $t_custom_options = prepare_custom_menu_options( 'main_menu_custom_options' ); - $t_menu_options = array_merge( $t_menu_options, $t_custom_options ); - # Time Tracking / Billing if( config_get( 'time_tracking_enabled' ) && access_has_global_level( config_get( 'time_tracking_reporting_threshold' ) ) ) { layout_sidebar_menu( 'billing_page.php', 'time_tracking_billing_link', 'fa-clock-o', $p_active_sidebar_page ); } + # Plugin / Event added options + $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN' ); + layout_plugin_menu_options_for_sidebar( $t_event_menu_options, $p_active_sidebar_page ); + + # Config based custom options + layout_config_menu_options_for_sidebar( $p_active_sidebar_page ); + # Ending sidebar markup layout_sidebar_end(); } @@ -813,12 +810,49 @@ function layout_plugin_menu_options_for_sidebar( $p_plugin_event_response, $p_ac } } - foreach( $t_menu_options as $t_menu_option ) { + layout_options_for_sidebar( $t_menu_options, $p_active_sidebar_page ); +} + +/** + * Process main menu options from config. + * @param string $p_active_sidebar_page The active page on the sidebar. + * @return void + */ +function layout_config_menu_options_for_sidebar( $p_active_sidebar_page ) { + $t_menu_options = array(); + $t_custom_options = config_get( 'main_menu_custom_options' ); + + foreach( $t_custom_options as $t_custom_option ) { + $t_menu_option = array(); + $t_menu_option['title'] = $t_custom_option[0]; + $t_menu_option['access_level'] = $t_custom_option[1]; + $t_menu_option['icon'] = 'fa-plug'; + $t_menu_option['url'] = $t_custom_option[2]; + $t_menu_options[] = $t_menu_option; + } + + layout_options_for_sidebar( $t_menu_options, $p_active_sidebar_page ); +} + +/** + * Process main menu options + * @param array $p_menu_options Array of menu options to output. + * @param string $p_active_sidebar_page The active page on the sidebar. + * @return void + */ +function layout_options_for_sidebar( $p_menu_options, $p_active_sidebar_page ) { + foreach( $p_menu_options as $t_menu_option ) { $t_icon = isset( $t_menu_option['icon'] ) ? $t_menu_option['icon'] : 'fa-plug'; if( !isset( $t_menu_option['url'] ) || !isset( $t_menu_option['title'] ) ) { continue; } + if( isset( $t_menu_option['access_level'] ) ) { + if( !access_has_project_level( $t_menu_option['access_level'] ) ) { + continue; + } + } + layout_sidebar_menu( $t_menu_option['url'], $t_menu_option['title'], $t_icon, $p_active_sidebar_page ); } }