Skip to content

Commit

Permalink
Fixes #10506: Provide the ability to disable the News feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed May 20, 2009
1 parent ac71e94 commit fe66a36
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 38 deletions.
5 changes: 5 additions & 0 deletions config_defaults_inc.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/html_api.php
Expand Up @@ -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 ) ) ) {
Expand Down
15 changes: 15 additions & 0 deletions core/news_api.php
Expand Up @@ -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();
}
}
8 changes: 8 additions & 0 deletions docbook/adminguide/en/configuration.sgml
Expand Up @@ -990,6 +990,14 @@
</para>

<variablelist>
<varlistentry>
<term>$g_news_enabled</term>
<listitem>
<para>Indicates whether the news feature should be enabled or disabled.
The default is ON.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>$g_news_limit_method</term>
<listitem>
Expand Down
77 changes: 40 additions & 37 deletions main_page.php
Expand Up @@ -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 );
}
Expand All @@ -70,45 +70,48 @@

echo '<br />';
echo '<br />';
echo '<br />';

$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 '<br />';
} # end for loop

echo '<div align="center">';

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 '<br />';
} # end for loop

echo '<div align="center">';

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 '</div>';
}

echo '</div>';

html_page_bottom( __FILE__ );

2 changes: 2 additions & 0 deletions news_add.php
Expand Up @@ -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' ) );
Expand Down
2 changes: 2 additions & 0 deletions news_edit_page.php
Expand Up @@ -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', '' );

Expand Down
2 changes: 2 additions & 0 deletions news_list_page.php
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions news_menu_page.php
Expand Up @@ -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' ) );
Expand Down
2 changes: 2 additions & 0 deletions news_rss.php
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions news_update.php
Expand Up @@ -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' );
Expand Down
2 changes: 2 additions & 0 deletions news_view_page.php
Expand Up @@ -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();
Expand Down

0 comments on commit fe66a36

Please sign in to comment.