From fe66a365f8b08db86128e88ccc702c75fab6cbcb Mon Sep 17 00:00:00 2001 From: Victor Boctor Date: Wed, 20 May 2009 00:36:40 -0700 Subject: [PATCH] Fixes #10506: Provide the ability to disable the News feature. --- config_defaults_inc.php | 5 ++ core/html_api.php | 2 +- core/news_api.php | 15 +++++ docbook/adminguide/en/configuration.sgml | 8 +++ main_page.php | 77 ++++++++++++------------ news_add.php | 2 + news_edit_page.php | 2 + news_list_page.php | 2 + news_menu_page.php | 2 + news_rss.php | 2 + news_update.php | 2 + news_view_page.php | 2 + 12 files changed, 83 insertions(+), 38 deletions(-) diff --git a/config_defaults_inc.php b/config_defaults_inc.php index 5bde2d0edf..e524d6ece9 100644 --- a/config_defaults_inc.php +++ b/config_defaults_inc.php @@ -1113,6 +1113,11 @@ * MantisBT News Settings * **************************/ + /** + * Indicates whether the news feature should be enabled or disabled. + */ + $g_news_enabled = ON; + /** * Limit News Items * limit by entry count or date diff --git a/core/html_api.php b/core/html_api.php index fbe5990b9c..f8e20bd562 100644 --- a/core/html_api.php +++ b/core/html_api.php @@ -757,7 +757,7 @@ function print_menu() { } # News Page - if( access_has_project_level( config_get( 'manage_news_threshold' ) ) ) { + if ( news_is_enabled() && access_has_project_level( config_get( 'manage_news_threshold' ) ) ) { # Admin can edit news for All Projects (site-wide) if(( ALL_PROJECTS != helper_get_current_project() ) || ( access_has_project_level( ADMINISTRATOR ) ) ) { diff --git a/core/news_api.php b/core/news_api.php index a45acbbfa2..f069e52d6e 100644 --- a/core/news_api.php +++ b/core/news_api.php @@ -311,3 +311,18 @@ function news_get_limited_rows( $p_offset, $p_project_id = null ) { return $t_rows; } + +# -------------------- +# Checks if the news feature is enabled or not. +# true: enabled, otherwise false. +function news_is_enabled() { + return config_get( 'news_enabled' ) == ON; +} + +# -------------------- +# Ensures that the news feature is enabled, otherwise generates an access denied error. +function news_ensure_enabled() { + if ( !news_is_enabled() ) { + access_denied(); + } +} \ No newline at end of file diff --git a/docbook/adminguide/en/configuration.sgml b/docbook/adminguide/en/configuration.sgml index e7565c38c2..003dfec6ed 100644 --- a/docbook/adminguide/en/configuration.sgml +++ b/docbook/adminguide/en/configuration.sgml @@ -990,6 +990,14 @@ + + $g_news_enabled + + Indicates whether the news feature should be enabled or disabled. + The default is ON. + + + $g_news_limit_method diff --git a/main_page.php b/main_page.php index d4ad83c22e..1928115ed5 100644 --- a/main_page.php +++ b/main_page.php @@ -44,7 +44,7 @@ $t_rss_enabled = config_get( 'rss_enabled' ); - if ( OFF != $t_rss_enabled ) { + if ( OFF != $t_rss_enabled && news_is_enabled() ) { $t_rss_link = rss_get_news_feed_url( $t_project_id ); html_set_rss_link( $t_rss_link ); } @@ -70,45 +70,48 @@ echo '
'; echo '
'; - echo '
'; - - $t_news_rows = news_get_limited_rows( $f_offset, $t_project_id ); - $t_news_count = count( $t_news_rows ); - - # Loop through results - for ( $i = 0; $i < $t_news_count; $i++ ) { - $t_row = $t_news_rows[$i]; - - # only show VS_PRIVATE posts to configured threshold and above - if ( ( VS_PRIVATE == $t_row[ 'view_state' ] ) && - !access_has_project_level( config_get( 'private_news_threshold' ) ) ) { - continue; - } - print_news_entry_from_row( $t_row ); + if ( news_is_enabled() ) { echo '
'; - } # end for loop - - echo '
'; - - print_bracket_link( 'news_list_page.php', lang_get( 'archives' ) ); - $t_news_view_limit = config_get( 'news_view_limit' ); - $f_offset_next = $f_offset + $t_news_view_limit; - $f_offset_prev = $f_offset - $t_news_view_limit; - - if ( $f_offset_prev >= 0) { - print_bracket_link( 'main_page.php?offset=' . $f_offset_prev, lang_get( 'newer_news_link' ) ); - } - - if ( $t_news_count == $t_news_view_limit ) { - print_bracket_link( 'main_page.php?offset=' . $f_offset_next, lang_get( 'older_news_link' ) ); - } - - if ( OFF != $t_rss_enabled ) { - print_bracket_link( $t_rss_link, lang_get( 'rss' ) ); + + $t_news_rows = news_get_limited_rows( $f_offset, $t_project_id ); + $t_news_count = count( $t_news_rows ); + + # Loop through results + for ( $i = 0; $i < $t_news_count; $i++ ) { + $t_row = $t_news_rows[$i]; + + # only show VS_PRIVATE posts to configured threshold and above + if ( ( VS_PRIVATE == $t_row[ 'view_state' ] ) && + !access_has_project_level( config_get( 'private_news_threshold' ) ) ) { + continue; + } + + print_news_entry_from_row( $t_row ); + echo '
'; + } # end for loop + + echo '
'; + + print_bracket_link( 'news_list_page.php', lang_get( 'archives' ) ); + $t_news_view_limit = config_get( 'news_view_limit' ); + $f_offset_next = $f_offset + $t_news_view_limit; + $f_offset_prev = $f_offset - $t_news_view_limit; + + if ( $f_offset_prev >= 0) { + print_bracket_link( 'main_page.php?offset=' . $f_offset_prev, lang_get( 'newer_news_link' ) ); + } + + if ( $t_news_count == $t_news_view_limit ) { + print_bracket_link( 'main_page.php?offset=' . $f_offset_next, lang_get( 'older_news_link' ) ); + } + + if ( OFF != $t_rss_enabled ) { + print_bracket_link( $t_rss_link, lang_get( 'rss' ) ); + } + + echo '
'; } - echo '
'; - html_page_bottom( __FILE__ ); diff --git a/news_add.php b/news_add.php index 00073abf97..46250de328 100644 --- a/news_add.php +++ b/news_add.php @@ -30,6 +30,8 @@ require_once( $t_core_path.'news_api.php' ); require_once( $t_core_path.'print_api.php' ); + news_ensure_enabled(); + form_security_validate( 'news_add' ); access_ensure_project_level( config_get( 'manage_news_threshold' ) ); diff --git a/news_edit_page.php b/news_edit_page.php index dffa4f35c9..319035dd5c 100644 --- a/news_edit_page.php +++ b/news_edit_page.php @@ -30,6 +30,8 @@ require_once( $t_core_path.'news_api.php' ); require_once( $t_core_path.'string_api.php' ); + news_ensure_enabled(); + $f_news_id = gpc_get_int( 'news_id' ); $f_action = gpc_get_string( 'action', '' ); diff --git a/news_list_page.php b/news_list_page.php index 235a2db6bd..014d1d2528 100644 --- a/news_list_page.php +++ b/news_list_page.php @@ -30,6 +30,8 @@ require_once( $t_core_path.'news_api.php' ); require_once( $t_core_path.'string_api.php' ); + news_ensure_enabled(); + access_ensure_project_level( VIEWER ); html_page_top(); diff --git a/news_menu_page.php b/news_menu_page.php index f93ac717eb..b8d0034f0f 100644 --- a/news_menu_page.php +++ b/news_menu_page.php @@ -25,6 +25,8 @@ */ require_once( 'core.php' ); + news_ensure_enabled(); + access_ensure_project_level( config_get( 'manage_news_threshold' ) ); html_page_top( lang_get( 'edit_news_link' ) ); diff --git a/news_rss.php b/news_rss.php index bf903a99d0..c54b5b09bb 100644 --- a/news_rss.php +++ b/news_rss.php @@ -37,6 +37,8 @@ $f_key = gpc_get_string( 'key', null ); $f_project_id = gpc_get_int( 'project_id', ALL_PROJECTS ); + news_ensure_enabled(); + # make sure RSS syndication is enabled. if ( OFF == config_get( 'rss_enabled' ) ) { access_denied(); diff --git a/news_update.php b/news_update.php index 274310b856..d4b4f67fd0 100644 --- a/news_update.php +++ b/news_update.php @@ -31,6 +31,8 @@ require_once( $t_core_path.'string_api.php' ); require_once( $t_core_path.'print_api.php' ); + news_ensure_enabled(); + form_security_validate( 'news_update' ); $f_news_id = gpc_get_int( 'news_id' ); diff --git a/news_view_page.php b/news_view_page.php index c9a2b4a785..03faa46df5 100644 --- a/news_view_page.php +++ b/news_view_page.php @@ -30,6 +30,8 @@ require_once( $t_core_path . 'news_api.php' ); require_once( $t_core_path . 'print_api.php' ); + news_ensure_enabled(); + $f_news_id = gpc_get_int( 'news_id', null ); html_page_top();