<!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] [2216] trunk: Removing activity posting logic from the theme,
  where it doesn't belong.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2216</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-12-27 14:46:30 +0000 (Sun, 27 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Removing activity posting logic from the theme, where it doesn't belong.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
<li><a href="#trunkbpxprofilephp">trunk/bp-xprofile.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2215 => 2216)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2009-12-27 14:11:10 UTC (rev 2215)
+++ trunk/bp-groups.php        2009-12-27 14:46:30 UTC (rev 2216)
</span><span class="lines">@@ -1976,8 +1976,40 @@
</span><span class="cx">         return BP_Groups_Member::check_is_banned( $user_id, $group_id );
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-/*** Group Wire ****************************************************************/
</del><ins>+/*** Group Activity Posting **************************************************/
</ins><span class="cx"> 
</span><ins>+function groups_post_update( $content, $user_id = false, $group_id = false ) {
+        global $bp;
+
+        if ( !$user_id )
+                $user_id = $bp-&gt;loggedin_user-&gt;id;
+
+        if ( !$group_id )
+                $group_id = $bp-&gt;groups-&gt;current_group-&gt;id;
+
+        if ( !$group_id )
+                return false;
+
+        if ( !$bp-&gt;groups-&gt;current_group )
+                $bp-&gt;groups-&gt;current_group = new BP_Groups_Group( $group_id );
+
+        /* Record this in activity streams */
+        $activity_content = sprintf( __( '%s posted an update in the group %s:', 'buddypress'), bp_core_get_userlink( $user_id ), '&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;' );
+        $activity_content .= '&lt;div class=&quot;activity-inner&quot;&gt;' . $content . '&lt;/div&gt;';
+
+        $activity_id = groups_record_activity( array(
+                'user_id' =&gt; $user_id,
+                'content' =&gt; apply_filters( 'groups_activity_new_wire_post', $activity_content ),
+                'primary_link' =&gt; apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) ),
+                'component_action' =&gt; 'new_wire_post',
+                'item_id' =&gt; $item_id
+        ) );
+
+        return $activity_id;
+}
+
+/*** Group Wire [DEPRECATED] ****************************************************************/
+
</ins><span class="cx"> function groups_new_wire_post( $group_id, $content ) {
</span><span class="cx">         global $bp;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (2215 => 2216)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2009-12-27 14:11:10 UTC (rev 2215)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2009-12-27 14:46:30 UTC (rev 2216)
</span><span class="lines">@@ -177,56 +177,13 @@
</span><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        if ( !(int)$_POST['group'] ) {
-                $item_id = $bp-&gt;loggedin_user-&gt;id;
-                $component = $bp-&gt;profile-&gt;id;
-        } else {
-                $item_id = $_POST['group'];
-                $component = $bp-&gt;groups-&gt;id;
-        }
</del><ins>+        if ( (int)$_POST['group'] )
+                $activity_id = groups_post_update( $_POST['content'], $bp-&gt;loggedin_user-&gt;id, $_POST['group'] );
+        else
+                $activity_id = xprofile_post_update( $_POST['content'], $bp-&gt;loggedin_user-&gt;id );
</ins><span class="cx"> 
</span><del>-        /* TODO - move the business login to the activity plugin and make it extensible */
-
-        if ( $bp-&gt;profile-&gt;id == $component ) {
-                /* Record this on the poster's activity screen */
-                $from_user_link = bp_core_get_userlink($bp-&gt;loggedin_user-&gt;id);
-                $activity_content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;&lt;/p&gt;&lt;p&gt;
-                ';
-                $primary_link = bp_core_get_userlink( $wire_post-&gt;user_id, false, true );
-                $activity_content .= '&lt;div class=&quot;activity-inner&quot;&gt;' . $_POST['content'] . '&lt;/div&gt;';
-
-                /* Now write the values */
-                $activity_id = xprofile_record_activity( array(
-                        'user_id' =&gt; $bp-&gt;loggedin_user-&gt;id,
-                        'content' =&gt; apply_filters( 'xprofile_activity_new_wire_post', $activity_content, &amp;$wire_post ),
-                        'primary_link' =&gt; apply_filters( 'xprofile_activity_new_wire_post_primary_link', $primary_link ),
-                        'component_action' =&gt; 'new_wire_post'
-                ) );
-
-                /* Add this update to the &quot;latest update&quot; usermeta so it can be fetched anywhere. */
-                update_usermeta( $bp-&gt;loggedin_user-&gt;id, 'bp_latest_update', array( 'id' =&gt; $activity_id, 'content' =&gt; wp_filter_kses( $_POST['content'] ) ) );
-
-                do_action( 'xprofile_new_wire_post', &amp;$wire_post );
-        } else {
-                $bp-&gt;groups-&gt;current_group = new BP_Groups_Group( $item_id );
-
-                /* Record this in activity streams */
-                $activity_content = sprintf( __( '%s posted an update in the group %s:', 'buddypress'), bp_core_get_userlink( $bp-&gt;loggedin_user-&gt;id ), '&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;' ) . ' &lt;span class=&quot;time-since&quot;&gt;%s&lt;/span&gt;
-                ';
-                $activity_content .= '&lt;div class=&quot;activity-inner&quot;&gt;' . $_POST['content'] . '&lt;/div&gt;';
-
-                $activity_id = groups_record_activity( array(
-                        'content' =&gt; apply_filters( 'groups_activity_new_wire_post', $activity_content ),
-                        'primary_link' =&gt; apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $bp-&gt;groups-&gt;current_group ) ),
-                        'component_action' =&gt; 'new_wire_post',
-                        'item_id' =&gt; $item_id
-                ) );
-
-                do_action( 'groups_new_wire_post', $item_id, $wire_post-&gt;id );
-        }
-
</del><span class="cx">         if ( !$activity_id ) {
</span><del>-                echo '-1&lt;div class=&quot;error&quot;&gt;&lt;p&gt;' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</del><ins>+                echo '-1&lt;div id=&quot;message&quot; class=&quot;error&quot;&gt;&lt;p&gt;' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</ins><span class="cx">                 return false;
</span><span class="cx">         }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkbpxprofilephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile.php (2215 => 2216)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile.php        2009-12-27 14:11:10 UTC (rev 2215)
+++ trunk/bp-xprofile.php        2009-12-27 14:46:30 UTC (rev 2216)
</span><span class="lines">@@ -742,7 +742,33 @@
</span><span class="cx">  * true or false on success or failure.
</span><span class="cx">  */
</span><span class="cx"> 
</span><ins>+function xprofile_post_update( $content, $user_id = false ) {
+        global $bp;
</ins><span class="cx"> 
</span><ins>+        if ( !$user_id )
+                $user_id = $bp-&gt;loggedin_user-&gt;id;
+
+        /* Record this on the user's profile */
+        $from_user_link = bp_core_get_userlink( $user_id );
+        $activity_content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link );
+        $activity_content .= '&lt;div class=&quot;activity-inner&quot;&gt;' . $content . '&lt;/div&gt;';
+
+        $primary_link = bp_core_get_userlink( $user_id, false, true );
+
+        /* Now write the values */
+        $activity_id = xprofile_record_activity( array(
+                'user_id' =&gt; $user_id,
+                'content' =&gt; apply_filters( 'xprofile_activity_new_update', $activity_content ),
+                'primary_link' =&gt; apply_filters( 'xprofile_activity_new_update_primary_link', $primary_link ),
+                'component_action' =&gt; 'new_wire_post'
+        ) );
+
+        /* Add this update to the &quot;latest update&quot; usermeta so it can be fetched anywhere. */
+        update_usermeta( $bp-&gt;loggedin_user-&gt;id, 'bp_latest_update', array( 'id' =&gt; $activity_id, 'content' =&gt; wp_filter_kses( $content ) ) );
+
+        return $activity_id;
+}
+
</ins><span class="cx"> /*** Field Group Management **************************************************/
</span><span class="cx"> 
</span><span class="cx"> function xprofile_insert_field_group( $args = '' ) {
</span></span></pre>
</div>
</div>

</body>
</html>