<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][3537] trunk: Prevent banned group users posting new topics, and re-joining groups.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>3537</dd>
<dt>Author</dt> <dd>djpaul</dd>
<dt>Date</dt> <dd>2010-12-18 16:03:10 +0000 (Sat, 18 Dec 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Prevent banned group users posting new topics, and re-joining groups. Fixes #2661 and #2957, props r-a-y for initial patch.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupstemplatetagsphp">trunk/bp-groups/bp-groups-templatetags.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
<li><a href="#trunkbpthemesbpdefaultgroupssingleforumtopicphp">trunk/bp-themes/bp-default/groups/single/forum/topic.php</a></li>
<li><a href="#trunkbpthemesbpdefaultgroupssingleforumphp">trunk/bp-themes/bp-default/groups/single/forum.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-templatetags.php (3536 => 3537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-templatetags.php        2010-12-18 00:45:24 UTC (rev 3536)
+++ trunk/bp-groups/bp-groups-templatetags.php        2010-12-18 16:03:10 UTC (rev 3537)
</span><span class="lines">@@ -31,9 +31,7 @@
</span><span class="cx">                 if ( 'invites' == $type ) {
</span><span class="cx">                         $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page, $exclude );
</span><span class="cx">                 } else if ( 'single-group' == $type ) {
</span><del>-                        $group = new stdClass;
-                        $group->group_id = BP_Groups_Group::get_id_from_slug($slug);
-                        $this->groups = array( $group );
</del><ins>+                        $this->groups = array( $bp->groups->current_group );
</ins><span class="cx">                 } else {
</span><span class="cx">                         $this->groups = groups_get_groups( array( 'type' => $type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'include' => $include, 'exclude' => $exclude, 'populate_extras' => $populate_extras ) );
</span><span class="cx">                 }
</span><span class="lines">@@ -120,9 +118,6 @@
</span><span class="cx">                 $this->in_the_loop = true;
</span><span class="cx">                 $this->group = $this->next_group();
</span><span class="cx">
</span><del>-                if ( $this->single_group )
-                        $this->group = new BP_Groups_Group( $this->group->group_id, true );
-
</del><span class="cx">                 if ( 0 == $this->current_group ) // loop has just started
</span><span class="cx">                         do_action('loop_start');
</span><span class="cx">         }
</span><span class="lines">@@ -1010,21 +1005,43 @@
</span><span class="cx">         global $bp, $groups_template;
</span><span class="cx">
</span><span class="cx">         // Site admins always have access
</span><del>-        if ( is_super_admin() )
</del><ins>+        if ( $bp->loggedin_user->is_super_admin )
</ins><span class="cx">                 return true;
</span><span class="cx">
</span><del>-        // Load group if none passed
</del><span class="cx">         if ( !$group )
</span><span class="cx">                 $group =& $groups_template->group;
</span><span class="cx">
</span><del>-        // Check membership
-        if ( null == $group->is_member )
-                $is_member = false;
-        else
-                $is_member = true;
</del><ins>+        return apply_filters( 'bp_group_is_member', !empty( $group->is_member ) );
+}
</ins><span class="cx">
</span><del>-        // Return
-        return apply_filters( 'bp_group_is_member', $is_member );
</del><ins>+/**
+ * Checks if a user is banned from a group.
+ *
+ * @global object $bp BuddyPress global settings
+ * @global BP_Groups_Template $groups_template Group template loop object
+ * @param object $group Group to check if user is banned from the group
+ * @param int $user_id
+ * @return bool If user is banned from the group or not
+ * @since 1.3
+ */
+function bp_group_is_user_banned( $group = false, $user_id = false ) {
+        global $bp, $groups_template;
+
+        // Site admins always have access
+        if ( $bp->loggedin_user->is_super_admin )
+                return true;
+
+        if ( !$group ) {
+                $group =& $groups_template->group;
+
+                if ( !$user_id )
+                        return apply_filters( 'bp_group_is_member_banned', !empty( $group->is_banned ) );
+        }
+
+        if ( !$user_id )
+                $user_id = $bp->loggedin_user->id;
+
+        return apply_filters( 'bp_group_is_user_banned', groups_is_user_banned( $user_id, $group->id ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_group_accept_invite_link() {
</span><span class="lines">@@ -1102,9 +1119,19 @@
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-function bp_group_new_topic_button() {
-        if ( bp_is_group_forum() && is_user_logged_in() && !bp_is_group_forum_topic() ) {
-                bp_button( array (
</del><ins>+function bp_group_new_topic_button( $group = false ) {
+        echo bp_get_group_new_topic_button();
+}
+        function bp_get_group_new_topic_button( $group = false ) {
+                global $groups_template;
+
+                if ( !$group )
+                        $group =& $groups_template->group;
+
+                if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() )
+                        return false;
+
+                $button = bp_button( array (
</ins><span class="cx">                         'id' => 'new_topic',
</span><span class="cx">                         'component' => 'groups',
</span><span class="cx">                         'must_be_logged_in' => true,
</span><span class="lines">@@ -1116,8 +1143,10 @@
</span><span class="cx">                         'link_text' => __( 'New Topic', 'buddypress' ),
</span><span class="cx">                         'link_title' => __( 'New Topic', 'buddypress' ),
</span><span class="cx">                 ) );
</span><ins>+
+                // Filter and return the HTML button
+                return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button ) );
</ins><span class="cx">         }
</span><del>-}
</del><span class="cx">
</span><span class="cx"> function bp_group_join_button( $group = false ) {
</span><span class="cx">         echo bp_get_group_join_button();
</span><span class="lines">@@ -1128,8 +1157,7 @@
</span><span class="cx">                 if ( !$group )
</span><span class="cx">                         $group =& $groups_template->group;
</span><span class="cx">
</span><del>-                // If they're not logged in or are banned from the group, no join button.
-                if ( !is_user_logged_in() || isset( $group->is_banned ) )
</del><ins>+                if ( !is_user_logged_in() || bp_group_is_user_banned() )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 // Group creation was not completed or status is unknown
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (3536 => 3537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2010-12-18 00:45:24 UTC (rev 3536)
+++ trunk/bp-groups.php        2010-12-18 16:03:10 UTC (rev 3537)
</span><span class="lines">@@ -51,7 +51,8 @@
</span><span class="cx">
</span><span class="cx">                 /* This is a single group page. */
</span><span class="cx">                 $bp->is_single_item = true;
</span><del>-                $bp->groups->current_group = new BP_Groups_Group( $group_id );
</del><ins>+                $bp->groups->current_group = groups_get_groups( array( 'type' => 'active', 'include' => $group_id ) );
+                $bp->groups->current_group = $bp->groups->current_group['groups'][0];
</ins><span class="cx">
</span><span class="cx">                 /* Using "item" not "group" for generic support in other components. */
</span><span class="cx">                 if ( is_super_admin() )
</span><span class="lines">@@ -291,10 +292,14 @@
</span><span class="cx">                 $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug );
</span><span class="cx">                 $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
</span><span class="cx">
</span><ins>+                $user_is_banned = false;
+                if ( !is_super_admin() && groups_is_user_banned( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
+                        $user_is_banned = true;
+
</ins><span class="cx">                 if ( $topic_slug && $topic_id ) {
</span><span class="cx">
</span><span class="cx">                         /* Posting a reply */
</span><del>-                        if ( !isset( $bp->action_variables[2] ) && isset( $_POST['submit_reply'] ) ) {
</del><ins>+                        if ( !$user_is_banned && !isset( $bp->action_variables[2] ) && isset( $_POST['submit_reply'] ) ) {
</ins><span class="cx">                                 /* Check the nonce */
</span><span class="cx">                                 check_admin_referer( 'bp_forums_new_reply' );
</span><span class="cx">
</span><span class="lines">@@ -372,7 +377,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         /* Delete a topic */
</span><del>-                        else if ( isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
</del><ins>+                        else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
</ins><span class="cx">                                 /* Fetch the topic */
</span><span class="cx">                                 $topic = bp_forums_get_topic_details( $topic_id );
</span><span class="cx">
</span><span class="lines">@@ -386,14 +391,13 @@
</span><span class="cx">                                 if ( !groups_delete_group_forum_topic( $topic_id ) )
</span><span class="cx">                                         bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
</span><span class="cx">                                 else
</span><del>-                                        bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
</del><span class="cx">
</span><span class="cx">                                 do_action( 'groups_delete_forum_topic', $topic_id );
</span><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         /* Editing a topic */
</span><del>-                        else if ( isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
</del><ins>+                        else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
</ins><span class="cx">                                 /* Fetch the topic */
</span><span class="cx">                                 $topic = bp_forums_get_topic_details( $topic_id );
</span><span class="cx">
</span><span class="lines">@@ -418,7 +422,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         /* Delete a post */
</span><del>-                        else if ( isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
</del><ins>+                        else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
</ins><span class="cx">                                 /* Fetch the post */
</span><span class="cx">                                 $post = bp_forums_get_post( $post_id );
</span><span class="cx">
</span><span class="lines">@@ -439,7 +443,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         /* Editing a post */
</span><del>-                        else if ( isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
</del><ins>+                        else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
</ins><span class="cx">                                 /* Fetch the post */
</span><span class="cx">                                 $post = bp_forums_get_post( $bp->action_variables[4] );
</span><span class="cx">
</span><span class="lines">@@ -468,19 +472,25 @@
</span><span class="cx">
</span><span class="cx">                         /* Standard topic display */
</span><span class="cx">                         else {
</span><ins>+                                if ( $user_is_banned )
+                                        bp_core_add_message( __( "You have been banned from this group.", 'buddypress' ) );
+
</ins><span class="cx">                                 bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) );
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                 } else {
</span><del>-
</del><span class="cx">                         /* Posting a topic */
</span><span class="cx">                         if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic') ) {
</span><span class="cx">                                 /* Check the nonce */
</span><span class="cx">                                 check_admin_referer( 'bp_forums_new_topic' );
</span><span class="cx">
</span><del>-                                /* Auto join this user if they are not yet a member of this group */
-                                if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
</del><ins>+                                if ( $user_is_banned ) {
+                                         $error_message = __( "You have been banned from this group.", 'buddypress' );
+
+                                } elseif ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
+                                        // Auto join this user if they are not yet a member of this group
</ins><span class="cx">                                         groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
</span><ins>+                                }
</ins><span class="cx">
</span><span class="cx">                                 if ( empty( $_POST['topic_title'] ) )
</span><span class="cx">                                         $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
</span><span class="lines">@@ -499,9 +509,8 @@
</span><span class="cx">                                                 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
</span><span class="cx">                                         }
</span><span class="cx">                                 }
</span><del>-                                
</del><ins>+
</ins><span class="cx">                                 bp_core_redirect( $redirect );
</span><del>-                                
</del><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         do_action( 'groups_screen_group_forum', $topic_id, $forum_id );
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultgroupssingleforumtopicphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/groups/single/forum/topic.php (3536 => 3537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/groups/single/forum/topic.php        2010-12-18 00:45:24 UTC (rev 3536)
+++ trunk/bp-themes/bp-default/groups/single/forum/topic.php        2010-12-18 16:03:10 UTC (rev 3537)
</span><span class="lines">@@ -78,7 +78,7 @@
</span><span class="cx">
</span><span class="cx">                         <?php if ( bp_get_the_topic_is_last_page() ) : ?>
</span><span class="cx">
</span><del>-                                <?php if ( bp_get_the_topic_is_topic_open() ) : ?>
</del><ins>+                                <?php if ( bp_get_the_topic_is_topic_open() && !bp_group_is_user_banned() ) : ?>
</ins><span class="cx">
</span><span class="cx">                                         <div id="post-topic-reply">
</span><span class="cx">                                                 <p id="post-reply"></p>
</span><span class="lines">@@ -102,7 +102,7 @@
</span><span class="cx">                                                 <?php wp_nonce_field( 'bp_forums_new_reply' ) ?>
</span><span class="cx">                                         </div>
</span><span class="cx">
</span><del>-                                <?php else : ?>
</del><ins>+                                <?php elseif ( !bp_group_is_user_banned() ) : ?>
</ins><span class="cx">
</span><span class="cx">                                         <div id="message" class="info">
</span><span class="cx">                                                 <p><?php _e( 'This topic is closed, replies are no longer accepted.', 'buddypress' ) ?></p>
</span></span></pre></div>
<a id="trunkbpthemesbpdefaultgroupssingleforumphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/groups/single/forum.php (3536 => 3537)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/groups/single/forum.php        2010-12-18 00:45:24 UTC (rev 3536)
+++ trunk/bp-themes/bp-default/groups/single/forum.php        2010-12-18 16:03:10 UTC (rev 3537)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx">
</span><span class="cx"> <?php if ( !bp_is_group_forum_topic_edit() && !bp_is_group_forum_topic() ) : ?>
</span><span class="cx">
</span><del>-        <?php if ( ( is_user_logged_in() && 'public' == bp_get_group_status() ) || bp_group_is_member() ) : ?>
</del><ins>+        <?php if ( !bp_group_is_user_banned() && ( ( is_user_logged_in() && 'public' == bp_get_group_status() ) || bp_group_is_member() ) ) : ?>
</ins><span class="cx">
</span><span class="cx">                 <form action="" method="post" id="forum-topic-form" class="standard-form">
</span><span class="cx">                         <div id="new-topic-post">
</span></span></pre>
</div>
</div>
</body>
</html>