<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[BuddyPress] [2004] trunk: Group forum editing and activity recording fixes
 .</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2004</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-30 16:42:06 +0000 (Wed, 30 Sep 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Group forum editing and activity recording fixes.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpforumsbpforumstemplatetagsphp">trunk/bp-forums/bp-forums-templatetags.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpforumsbpforumstemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-forums/bp-forums-templatetags.php (2003 => 2004)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-forums/bp-forums-templatetags.php        2009-09-30 14:11:06 UTC (rev 2003)
+++ trunk/bp-forums/bp-forums-templatetags.php        2009-09-30 16:42:06 UTC (rev 2004)
</span><span class="lines">@@ -237,7 +237,7 @@
</span><span class="cx">         function bp_get_the_topic_text() {
</span><span class="cx">                 global $forum_template;
</span><span class="cx"> 
</span><del>-                $post = bb_get_first_post( $forum_template-&gt;topic-&gt;topic_id );
</del><ins>+                $post = bb_get_first_post( (int)$forum_template-&gt;topic-&gt;topic_id, false );
</ins><span class="cx">                 return apply_filters( 'bp_get_the_topic_text', $post-&gt;post_text );
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -873,6 +873,10 @@
</span><span class="cx">         function bp_get_the_topic_post_admin_links( $args = '' ) {
</span><span class="cx">                 global $topic_template;        
</span><span class="cx">                 
</span><ins>+                /* Never show for the first post in a topic. */
+                if ( 0 == $topic_template-&gt;current_post )
+                        return;
+                
</ins><span class="cx">                 $defaults = array(
</span><span class="cx">                         'seperator' =&gt; '|'
</span><span class="cx">                 );
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2003 => 2004)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-09-30 14:11:06 UTC (rev 2003)
+++ trunk/bp-groups.php        2009-09-30 16:42:06 UTC (rev 2004)
</span><span class="lines">@@ -600,6 +600,8 @@
</span><span class="cx">         global $bp;
</span><span class="cx">         
</span><span class="cx">         if ( $bp-&gt;is_single_item &amp;&amp; $bp-&gt;groups-&gt;current_group-&gt;user_has_access ) {
</span><ins>+                
+                /* Fetch the details we need */
</ins><span class="cx">                 $topic_slug = $bp-&gt;action_variables[1];
</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-&gt;groups-&gt;current_group-&gt;id, 'forum_id' );
</span><span class="lines">@@ -636,7 +638,7 @@
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
</span><span class="cx">                         
</span><del>-                                do_action( 'groups_stick_topic', $topic_id );
</del><ins>+                                do_action( 'groups_stick_forum_topic', $topic_id );
</ins><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx">                         
</span><span class="lines">@@ -650,7 +652,7 @@
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
</span><span class="cx">                         
</span><del>-                                do_action( 'groups_unstick_topic', $topic_id );
</del><ins>+                                do_action( 'groups_unstick_forum_topic', $topic_id );
</ins><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx">                         
</span><span class="lines">@@ -664,7 +666,7 @@
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
</span><span class="cx">                         
</span><del>-                                do_action( 'groups_close_topic', $topic_id );
</del><ins>+                                do_action( 'groups_close_forum_topic', $topic_id );
</ins><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="lines">@@ -678,12 +680,19 @@
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
</span><span class="cx">                         
</span><del>-                                do_action( 'groups_open_topic', $topic_id );
</del><ins>+                                do_action( 'groups_open_forum_topic', $topic_id );
</ins><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         /* Delete a topic */
</span><del>-                        else if ( 'delete' == $bp-&gt;action_variables[2] &amp;&amp; empty( $bp-&gt;action_variables[3] ) &amp;&amp; ( $bp-&gt;is_item_admin || $bp-&gt;is_item_mod ) ) {
</del><ins>+                        else if ( 'delete' == $bp-&gt;action_variables[2] &amp;&amp; empty( $bp-&gt;action_variables[3] ) ) {
+                                /* Fetch the topic */
+                                $topic = bp_forums_get_topic_details( $topic_id );
+
+                                /* Check the logged in user can delete this topic */
+                                if ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod &amp;&amp; (int)$bp-&gt;loggedin_user-&gt;id != (int)$topic-&gt;topic_poster )
+                                        bp_core_redirect( wp_get_referer() );
+                                
</ins><span class="cx">                                 /* Check the nonce */
</span><span class="cx">                                 check_admin_referer( 'bp_forums_delete_topic' );
</span><span class="cx">         
</span><span class="lines">@@ -691,12 +700,20 @@
</span><span class="cx">                                         bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress'), 'error' );
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress') );
</span><del>-
</del><ins>+                                
+                                do_action( 'groups_delete_forum_topic', $topic_id );
</ins><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 ( 'edit' == $bp-&gt;action_variables[2] &amp;&amp; empty( $bp-&gt;action_variables[3] ) &amp;&amp; ( $bp-&gt;is_item_admin || $bp-&gt;is_item_mod ) ) {
</del><ins>+                        else if ( 'edit' == $bp-&gt;action_variables[2] &amp;&amp; empty( $bp-&gt;action_variables[3] ) ) {
+                                /* Fetch the topic */
+                                $topic = bp_forums_get_topic_details( $topic_id );
+
+                                /* Check the logged in user can edit this topic */
+                                if ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod &amp;&amp; (int)$bp-&gt;loggedin_user-&gt;id != (int)$topic-&gt;topic_poster )
+                                        bp_core_redirect( wp_get_referer() );
+
</ins><span class="cx">                                 if ( isset( $_POST['save_changes'] ) ) {
</span><span class="cx">                                         /* Check the nonce */
</span><span class="cx">                                         check_admin_referer( 'bp_forums_edit_topic' );
</span><span class="lines">@@ -706,19 +723,22 @@
</span><span class="cx">                                         else
</span><span class="cx">                                                 bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
</span><span class="cx">                                 
</span><ins>+                                        do_action( 'groups_edit_forum_topic', $topic_id );
</ins><span class="cx">                                         bp_core_redirect( bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic_slug . '/' );
</span><span class="cx">                                 }
</span><del>-
-                                /* Check that the user has access to edit this topic, if not, redirect. */
-                                $topic = bp_forums_get_topic_details( $topic_id );
-                                if ( ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod ) &amp;&amp; $bp-&gt;loggedin_user-&gt;id != $topic-&gt;topic_poster )
-                                        bp_core_redirect( bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic_slug . '/' );
-
</del><ins>+                                
</ins><span class="cx">                                 bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
</span><span class="cx">                         }
</span><span class="cx">                         
</span><span class="cx">                         /* Delete a post */
</span><del>-                        else if ( 'delete' == $bp-&gt;action_variables[2] &amp;&amp; $bp-&gt;action_variables[4] &amp;&amp; ( $bp-&gt;is_item_admin || $bp-&gt;is_item_mod ) ) {
</del><ins>+                        else if ( 'delete' == $bp-&gt;action_variables[2] &amp;&amp; $post_id = $bp-&gt;action_variables[4] ) {
+                                /* Fetch the post */
+                                $post = bp_forums_get_post( $post_id );
+
+                                /* Check the logged in user can edit this topic */
+                                if ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod &amp;&amp; (int)$bp-&gt;loggedin_user-&gt;id != (int)$post-&gt;poster_id )
+                                        bp_core_redirect( wp_get_referer() );
+
</ins><span class="cx">                                 /* Check the nonce */
</span><span class="cx">                                 check_admin_referer( 'bp_forums_delete_post' );
</span><span class="cx"> 
</span><span class="lines">@@ -726,12 +746,20 @@
</span><span class="cx">                                         bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' );
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
</span><del>-
</del><ins>+                                
+                                do_action( 'groups_delete_forum_post', $post_id );
</ins><span class="cx">                                 bp_core_redirect( wp_get_referer() );
</span><span class="cx">                         }
</span><span class="cx">                                 
</span><span class="cx">                         /* Editing a post */
</span><span class="cx">                         else if ( 'edit' == $bp-&gt;action_variables[2] &amp;&amp; $post_id = $bp-&gt;action_variables[4] ) {
</span><ins>+                                /* Fetch the post */
+                                $post = bp_forums_get_post( $bp-&gt;action_variables[4] );
+
+                                /* Check the logged in user can edit this topic */
+                                if ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod &amp;&amp; (int)$bp-&gt;loggedin_user-&gt;id != (int)$post-&gt;poster_id )
+                                        bp_core_redirect( wp_get_referer() );
+
</ins><span class="cx">                                 if ( isset( $_POST['save_changes'] ) ) {
</span><span class="cx">                                         /* Check the nonce */
</span><span class="cx">                                         check_admin_referer( 'bp_forums_edit_post' );
</span><span class="lines">@@ -740,15 +768,11 @@
</span><span class="cx">                                                 bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
</span><span class="cx">                                         else
</span><span class="cx">                                                 bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
</span><del>-                                
</del><ins>+                                        
+                                        do_action( 'groups_edit_forum_post', $post_id );
</ins><span class="cx">                                         bp_core_redirect( bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic_slug . '/' );
</span><span class="cx">                                 }
</span><span class="cx">                                 
</span><del>-                                /* Check that the user has access to edit this post, if not, redirect. */
-                                $post = bp_forums_get_post( $post_id );
-                                if ( ( !$bp-&gt;is_item_admin &amp;&amp; !$bp-&gt;is_item_mod ) &amp;&amp; $bp-&gt;loggedin_user-&gt;id != $post-&gt;poster_id )
-                                        bp_core_redirect( bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic_slug . '/' );
-
</del><span class="cx">                                 bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/forum/edit' ) );
</span><span class="cx">                         }
</span><span class="cx"> 
</span><span class="lines">@@ -759,6 +783,7 @@
</span><span class="cx">                                 else
</span><span class="cx">                                         bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/forum/topic' ) );
</span><span class="cx">                         }
</span><ins>+                        
</ins><span class="cx">                 } else {
</span><span class="cx"> 
</span><span class="cx">                         /* Posting a topic */
</span><span class="lines">@@ -2097,7 +2122,7 @@
</span><span class="cx">                         'primary_link' =&gt; apply_filters( 'groups_activity_new_forum_post_primary_link', bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) ),
</span><span class="cx">                         'component_action' =&gt; 'new_forum_post',
</span><span class="cx">                         'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id,
</span><del>-                        'secondary_item_id' =&gt; $forum_post-&gt;id
</del><ins>+                        'secondary_item_id' =&gt; $forum_post
</ins><span class="cx">                 ) );
</span><span class="cx"> 
</span><span class="cx">                 do_action( 'groups_new_forum_topic_post', $bp-&gt;groups-&gt;current_group-&gt;id, $forum_post );
</span><span class="lines">@@ -2142,7 +2167,8 @@
</span><span class="cx">         
</span><span class="cx">         if ( $topic = bp_forums_update_topic( array( 'topic_title' =&gt; $topic_title, 'topic_text' =&gt; $topic_text, 'topic_id' =&gt; $topic_id ) ) ) {
</span><span class="cx">                 /* Update the activity stream item */
</span><del>-                bp_activity_delete_by_item_id( array( 'item_id' =&gt; $topic_id, 'component_name' =&gt; 'groups', 'component_action' =&gt; 'new_forum_topic' ) );
</del><ins>+                if ( function_exists( 'bp_activity_delete_by_item_id' ) )
+                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id, 'secondary_item_id' =&gt; $topic_id, 'component_name' =&gt; $bp-&gt;groups-&gt;id, 'component_action' =&gt; 'new_forum_topic' ) );
</ins><span class="cx">                 
</span><span class="cx">                 $activity_content = sprintf( __( '%s started the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $topic-&gt;topic_poster ), '&lt;a href=&quot;' . bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic-&gt;topic_slug .'&quot;&gt;' . attribute_escape( $topic-&gt;topic_title ) . '&lt;/a&gt;', '&lt;a href=&quot;' . bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '&quot;&gt;' . attribute_escape( $bp-&gt;groups-&gt;current_group-&gt;name ) . '&lt;/a&gt;' );
</span><span class="cx">                 $activity_content .= '&lt;blockquote&gt;' . bp_create_excerpt( attribute_escape( $topic_text ) ) . '&lt;/blockquote&gt;';
</span><span class="lines">@@ -2171,12 +2197,13 @@
</span><span class="cx">         
</span><span class="cx">         $post = bp_forums_get_post( $post_id );
</span><span class="cx">                 
</span><del>-        if ( $post_id = bp_forums_insert_post( array( 'post_id' =&gt; $post_id, 'post_text' =&gt; $post_text, 'post_time' =&gt; $post-&gt;post_time, 'topic_id' =&gt; $topic_id ) ) ) {
</del><ins>+        if ( $post_id = bp_forums_insert_post( array( 'post_id' =&gt; $post_id, 'post_text' =&gt; $post_text, 'post_time' =&gt; $post-&gt;post_time, 'topic_id' =&gt; $topic_id, 'poster_id' =&gt; $post-&gt;poster_id ) ) ) {
</ins><span class="cx">                 $topic = bp_forums_get_topic_details( $topic_id );
</span><span class="cx"> 
</span><span class="cx">                 /* Update the activity stream item */
</span><del>-                bp_activity_delete_by_item_id( array( 'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id, 'secondary_item_id' =&gt; $post_id, 'component_name' =&gt; 'groups', 'component_action' =&gt; 'new_forum_post' ) );
-                
</del><ins>+                if ( function_exists( 'bp_activity_delete_by_item_id' ) )
+                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id, 'secondary_item_id' =&gt; $post_id, 'component_name' =&gt; $bp-&gt;groups-&gt;id, 'component_action' =&gt; 'new_forum_post' ) );
+                        
</ins><span class="cx">                 $activity_content = sprintf( __( '%s posted on the forum topic %s in the group %s:', 'buddypress'), bp_core_get_userlink( $post-&gt;poster_id ), '&lt;a href=&quot;' . bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '/forum/topic/' . $topic-&gt;topic_slug .'&quot;&gt;' . attribute_escape( $topic-&gt;topic_title ) . '&lt;/a&gt;', '&lt;a href=&quot;' . bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) . '&quot;&gt;' . attribute_escape( $bp-&gt;groups-&gt;current_group-&gt;name ) . '&lt;/a&gt;' );
</span><span class="cx">                 $activity_content .= '&lt;blockquote&gt;' . bp_create_excerpt( attribute_escape( $post_text ) ) . '&lt;/blockquote&gt;';
</span><span class="cx">                 
</span><span class="lines">@@ -2185,7 +2212,8 @@
</span><span class="cx">                         'content' =&gt; apply_filters( 'groups_activity_new_forum_post', $activity_content, $post_text, &amp;$topic, &amp;$forum_post ), 
</span><span class="cx">                         'primary_link' =&gt; apply_filters( 'groups_activity_new_forum_post_primary_link', bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) ),
</span><span class="cx">                         'component_action' =&gt; 'new_forum_post',
</span><del>-                        'item_id' =&gt; $bp-&gt;groups-&gt;current_group-&gt;id,
</del><ins>+                        'item_id' =&gt; (int)$bp-&gt;groups-&gt;current_group-&gt;id,
+                        'user_id' =&gt; (int)$post-&gt;poster_id,
</ins><span class="cx">                         'secondary_item_id' =&gt; $post_id,
</span><span class="cx">                         'recorded_time' =&gt; strtotime( $post-&gt;post_time )
</span><span class="cx">                 ) );
</span><span class="lines">@@ -2204,8 +2232,8 @@
</span><span class="cx">         if ( bp_forums_delete_topic( array( 'topic_id' =&gt; $topic_id ) ) ) {
</span><span class="cx">                 /* Delete the activity stream item */
</span><span class="cx">                 if ( function_exists( 'bp_activity_delete_by_item_id' ) ) {
</span><del>-                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $topic_id, 'component_name' =&gt; 'groups', 'component_action' =&gt; 'new_forum_topic' ) );
-                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $topic_id, 'component_name' =&gt; 'groups', 'component_action' =&gt; 'new_forum_post' ) );
</del><ins>+                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $topic_id, 'component_name' =&gt; $bp-&gt;groups-&gt;id, 'component_action' =&gt; 'new_forum_topic' ) );
+                        bp_activity_delete_by_item_id( array( 'item_id' =&gt; $topic_id, 'component_name' =&gt; $bp-&gt;groups-&gt;id, 'component_action' =&gt; 'new_forum_post' ) );
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 do_action( 'groups_delete_group_forum_topic', $topic_id );
</span></span></pre>
</div>
</div>

</body>
</html>