<!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->loggedin_user->id;
+
+        if ( !$group_id )
+                $group_id = $bp->groups->current_group->id;
+
+        if ( !$group_id )
+                return false;
+
+        if ( !$bp->groups->current_group )
+                $bp->groups->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 ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' );
+        $activity_content .= '<div class="activity-inner">' . $content . '</div>';
+
+        $activity_id = groups_record_activity( array(
+                'user_id' => $user_id,
+                'content' => apply_filters( 'groups_activity_new_wire_post', $activity_content ),
+                'primary_link' => apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
+                'component_action' => 'new_wire_post',
+                'item_id' => $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->loggedin_user->id;
-                $component = $bp->profile->id;
-        } else {
-                $item_id = $_POST['group'];
-                $component = $bp->groups->id;
-        }
</del><ins>+        if ( (int)$_POST['group'] )
+                $activity_id = groups_post_update( $_POST['content'], $bp->loggedin_user->id, $_POST['group'] );
+        else
+                $activity_id = xprofile_post_update( $_POST['content'], $bp->loggedin_user->id );
</ins><span class="cx">
</span><del>-        /* TODO - move the business login to the activity plugin and make it extensible */
-
-        if ( $bp->profile->id == $component ) {
-                /* Record this on the poster's activity screen */
-                $from_user_link = bp_core_get_userlink($bp->loggedin_user->id);
-                $activity_content = sprintf( __('%s posted an update:', 'buddypress'), $from_user_link ) . ' <span class="time-since">%s</span></p><p>
-                ';
-                $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true );
-                $activity_content .= '<div class="activity-inner">' . $_POST['content'] . '</div>';
-
-                /* Now write the values */
-                $activity_id = xprofile_record_activity( array(
-                        'user_id' => $bp->loggedin_user->id,
-                        'content' => apply_filters( 'xprofile_activity_new_wire_post', $activity_content, &$wire_post ),
-                        'primary_link' => apply_filters( 'xprofile_activity_new_wire_post_primary_link', $primary_link ),
-                        'component_action' => 'new_wire_post'
-                ) );
-
-                /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
-                update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => wp_filter_kses( $_POST['content'] ) ) );
-
-                do_action( 'xprofile_new_wire_post', &$wire_post );
-        } else {
-                $bp->groups->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->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . attribute_escape( $bp->groups->current_group->name ) . '</a>' ) . ' <span class="time-since">%s</span>
-                ';
-                $activity_content .= '<div class="activity-inner">' . $_POST['content'] . '</div>';
-
-                $activity_id = groups_record_activity( array(
-                        'content' => apply_filters( 'groups_activity_new_wire_post', $activity_content ),
-                        'primary_link' => apply_filters( 'groups_activity_new_wire_post_primary_link', bp_get_group_permalink( $bp->groups->current_group ) ),
-                        'component_action' => 'new_wire_post',
-                        'item_id' => $item_id
-                ) );
-
-                do_action( 'groups_new_wire_post', $item_id, $wire_post->id );
-        }
-
</del><span class="cx">         if ( !$activity_id ) {
</span><del>-                echo '-1<div class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
</del><ins>+                echo '-1<div id="message" class="error"><p>' . __( 'There was a problem posting your update, please try again.', 'buddypress' ) . '</p></div>';
</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->loggedin_user->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 .= '<div class="activity-inner">' . $content . '</div>';
+
+        $primary_link = bp_core_get_userlink( $user_id, false, true );
+
+        /* Now write the values */
+        $activity_id = xprofile_record_activity( array(
+                'user_id' => $user_id,
+                'content' => apply_filters( 'xprofile_activity_new_update', $activity_content ),
+                'primary_link' => apply_filters( 'xprofile_activity_new_update_primary_link', $primary_link ),
+                'component_action' => 'new_wire_post'
+        ) );
+
+        /* Add this update to the "latest update" usermeta so it can be fetched anywhere. */
+        update_usermeta( $bp->loggedin_user->id, 'bp_latest_update', array( 'id' => $activity_id, 'content' => 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>