$role) { if(!private_forums_check_user_access_to_forum($role)) $private_forums_for_user[$forum] = $role; } $private_forums_options['private_forums'] = $private_forums_for_user; } return $private_forums_options[$option]; } function private_forums_upgrade() { $private_forums_options = bb_get_option('private_forums_options'); if(!isset($private_forums_options['version']) || $private_forums_options['version'] < 40) { private_forums_upgrade_4_0(); $private_forums_options = bb_get_option('private_forums_options'); } if($private_forums_options['version'] < 41) { private_forums_upgrade_4_1(); } } function private_forums_upgrade_4_0() { $private_forums_options = array(); $forum_access_private_forums = bb_get_option('forum_access_private_forums'); $private_forums_options['private_forums'] = ($forum_access_private_forums) ? $forum_access_private_forums : array() ; $private_forums_options['failure_msg'] = bb_get_option('forum_access_failure_msg'); $private_forums_options['hide_show_flag'] = bb_get_option('forum_access_private_forums_option'); $private_forums_options['user_role'] = "MEMBER"; $private_forums_options['private_text'] = bb_get_option('forum_access_private_text'); $private_forums_options['version'] = 40; bb_delete_option('forum_access_private_forums'); bb_delete_option('forum_access_failure_msg'); bb_delete_option('forum_access_private_forums_option'); bb_delete_option('forum_access_private_text'); bb_update_option('private_forums_options', $private_forums_options); } function private_forums_upgrade_4_1() { $private_forums_options = bb_get_option('private_forums_options'); $private_forums = $private_forums_options['private_forums']; $user_role = $private_forums_options['user_role']; if('ADMINSTRATOR' == $user_role) $user_role = 'ADMINISTRATOR'; foreach($private_forums as $forums => $role) { $private_forums[$forums] = $user_role; } $private_forums_options['private_forums'] = $private_forums; $private_forums_options['version'] = 41; unset($private_forums_options['user_role']); bb_update_option('private_forums_options', $private_forums_options); } function private_forums_display_role_dropdown($name, $index, $role) { ?>

Private Forums

Forum Restrict to Role
forum_id, $private_forums[$forum->forum_id]); ?>

Privacy Options

/>

/>

Error Options

When a user tries to access a private forum without having access he will be redirected to a error page with the following text.

Usage:

path . 'bb-login.php'; if ($_SERVER['PHP_SELF'] != $login_page) { $private_forums = private_forums_custom_get_options('private_forums'); if ( !empty($private_forums)) { add_action( 'bb_forum.php_pre_db', 'private_forums_check_private_forum' ); add_action( 'bb_topic.php_pre_db', 'private_forums_check_private_topic' ); add_action( 'bb_tag-single.php', 'private_forums_check_private_tag' ); add_action( 'bb_rss.php', 'private_forums_filter_stuff_in_rss' ); if (private_forums_custom_get_options('hide_show_flag') == 'SHOW_PRIVATE') { add_filter( 'get_forum_name', 'private_forums_add_private_name_to_forums', 10,2); add_filter( 'get_topic_title', 'private_forums_add_private_name_to_topics', 10,2); } else { add_filter( 'get_forums_where','private_forums_filter_query_with_where'); add_filter( 'get_forum_where','private_forums_filter_query_with_and'); add_filter( 'get_topic_where','private_forums_filter_query_with_and'); add_filter( 'get_latest_topics_where','private_forums_filter_query_with_and'); add_filter( 'get_thread_where','private_forums_filter_query_with_and'); add_filter( 'get_recent_user_replies_where','private_forums_filter_query_with_and'); add_filter( 'get_sticky_topics_where','private_forums_filter_query_with_and'); add_filter( 'get_recent_user_threads_where','private_forums_filter_query_with_and'); add_filter( 'get_latest_posts_where','private_forums_filter_query_with_and'); add_filter( 'get_latest_forum_posts_where','private_forums_filter_query_with_and'); add_filter( 'bb_template','private_forums_filter_favorites', 10, 2); } } } } function private_forums_filter_favorites($template, $file) { if ($file == 'favorites.php') { global $topics, $favorites_total; $topics = private_forums_filter_topics($topics); $favorites_total = count($topics); } return $template; } function private_forums_get_restricted_forums_list() { $private_forums = implode(",", array_keys(private_forums_custom_get_options('private_forums'))); return 'forum_id NOT IN (' . $private_forums . ') '; } function private_forums_filter_query_with_where($where) { return 'WHERE ' . private_forums_get_restricted_forums_list() ; } function private_forums_filter_query_with_and($where) { return $where . ' AND ' . private_forums_get_restricted_forums_list() ; } function private_forums_format_error($err_msg){ global $bb; if(empty($err_msg)) $err_msg = "This %s requires access to private forum. \r\nPlease login to access it."; $err_msg = trim($err_msg); $err_msg = strip_tags ( $err_msg ); $order = array("\r\n", "\n", "\r"); $replace = '
'; $err_msg = str_replace($order, $replace, $err_msg); $replace = 'login'; $err_msg = str_replace('login', $replace, $err_msg); return $err_msg; } function private_forums_filter_stuff_in_rss() { global $posts, $forum_id, $topic; $private_forums = private_forums_custom_get_options('private_forums'); if(array_key_exists($forum_id,$private_forums) || array_key_exists($topic->forum_id,$private_forums)) { exit(); } $posts = private_forums_filter_posts($posts); } function private_forums_check_private_forum($forum_id) { $private_forums = private_forums_custom_get_options('private_forums'); if(array_key_exists($forum_id,$private_forums)) { bb_die(__(sprintf(private_forums_format_error(private_forums_custom_get_options('failure_msg')), 'forum'))); } } function private_forums_check_private_topic($topic_id) { global $topic; $private_forums = private_forums_custom_get_options('private_forums'); if(array_key_exists($topic->forum_id,$private_forums)) { bb_die(__(sprintf(private_forums_format_error(private_forums_custom_get_options('failure_msg')), 'topic'))); } } function private_forums_check_private_tag($tag_id) { global $topics; $topics = private_forums_filter_topics($topics); } function private_forums_filter_topics($topics) { $new_topics = array(); if ($topics) { $private_forums = private_forums_custom_get_options('private_forums'); foreach($topics as $topic) { if(!array_key_exists($topic->forum_id,$private_forums)) { $new_topics[] = $topic; } } return $new_topics ; } return $topics; } function private_forums_filter_posts($posts) { $new_posts = array(); if ($posts) { $private_forums = private_forums_custom_get_options('private_forums'); foreach($posts as $post) { if(!array_key_exists($post->forum_id,$private_forums)) { $new_posts[] = $post; } } return $new_posts ; } return $posts; } function private_forums_add_private_name_to_forums($text, $id) { $private_forums = private_forums_custom_get_options('private_forums'); if(array_key_exists($id,$private_forums)) { return '[' . private_forums_custom_get_options('private_text') . '] ' . $text; } else { return $text; } } function private_forums_add_private_name_to_topics($text, $id) { $topic = get_topic( $id ); $id = $topic->forum_id; $private_forums = private_forums_custom_get_options('private_forums'); if(array_key_exists($id,$private_forums)) { return '[' . private_forums_custom_get_options('private_text') . '] ' . $text; } else { return $text; } } function private_forums_check_user_access_to_forum($access) { switch($access) { case 'MODERATOR': return bb_current_user_can('moderate'); break; case 'ADMINISTRATOR': return bb_current_user_can('administrate'); break; case 'MEMBER': return bb_current_user_can('participate'); break; case 'OPEN': return true; break; default: return true; } } ?>