<!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] [1693] trunk: Updated xprofile activity record function.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1693</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-08-25 01:17:25 +0000 (Tue, 25 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Updated xprofile activity record function.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpwiredeprecatedbpwiredeprecatedphp">trunk/bp-wire/deprecated/bp-wire-deprecated.php</a></li>
<li><a href="#trunkbpwirephp">trunk/bp-wire.php</a></li>
<li><a href="#trunkbpxprofilephp">trunk/bp-xprofile.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpwiredeprecatedbpwiredeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-wire/deprecated/bp-wire-deprecated.php (1692 => 1693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-wire/deprecated/bp-wire-deprecated.php        2009-08-25 00:58:09 UTC (rev 1692)
+++ trunk/bp-wire/deprecated/bp-wire-deprecated.php        2009-08-25 01:17:25 UTC (rev 1693)
</span><span class="lines">@@ -82,4 +82,20 @@
</span><span class="cx"> }
</span><span class="cx"> add_action( 'wp_ajax_get_wire_posts', 'bp_wire_ajax_get_wire_posts' );
</span><span class="cx">
</span><ins>+/* Use activity record functions in your specific component */
+function bp_wire_record_activity( $args = true ) {
+        if ( function_exists('bp_activity_record') ) {
+                extract($args);
+
+                bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
+        }
+}
+
+/* Use activity delete functions in your specific component */
+function bp_wire_delete_activity( $args = true ) {
+        if ( function_exists('bp_activity_delete') ) {
+                extract($args);
+                bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
+        }
+}
</ins><span class="cx"> ?>
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkbpwirephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-wire.php (1692 => 1693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-wire.php        2009-08-25 00:58:09 UTC (rev 1692)
+++ trunk/bp-wire.php        2009-08-25 01:17:25 UTC (rev 1693)
</span><span class="lines">@@ -68,29 +68,6 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> /********************************************************************************
</span><del>- * Activity & Notification Functions
- *
- * These functions handle the recording, deleting and formatting of activity and
- * notifications for the user and for this specific component.
- */
-
-function bp_wire_record_activity( $args = true ) {
-        if ( function_exists('bp_activity_record') ) {
-                extract($args);
-
-                bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
-        }
-}
-
-function bp_wire_delete_activity( $args = true ) {
-        if ( function_exists('bp_activity_delete') ) {
-                extract($args);
-                bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
-        }
-}
-
-
-/********************************************************************************
</del><span class="cx"> * Business Functions
</span><span class="cx"> *
</span><span class="cx"> * Business functions are where all the magic happens in BuddyPress. They will
</span><span class="lines">@@ -123,7 +100,7 @@
</span><span class="cx">         
</span><span class="cx">         do_action( 'bp_wire_post_posted', $wire_post->id, $wire_post->item_id, $wire_post->user_id );
</span><span class="cx">         
</span><del>-        return $wire_post->id;
</del><ins>+        return $wire_post;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function bp_wire_delete_post( $wire_post_id, $component_name, $table_name = null ) {
</span></span></pre></div>
<a id="trunkbpxprofilephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile.php (1692 => 1693)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile.php        2009-08-25 00:58:09 UTC (rev 1692)
+++ trunk/bp-xprofile.php        2009-08-25 01:17:25 UTC (rev 1693)
</span><span class="lines">@@ -132,18 +132,18 @@
</span><span class="cx"> function xprofile_setup_globals() {
</span><span class="cx">         global $bp, $wpdb;
</span><span class="cx">         
</span><ins>+        /* For internal identification */
+        $bp->profile->id = 'profile';
+                
</ins><span class="cx">         $bp->profile->table_name_groups = $wpdb->base_prefix . 'bp_xprofile_groups';
</span><span class="cx">         $bp->profile->table_name_fields = $wpdb->base_prefix . 'bp_xprofile_fields';
</span><span class="cx">         $bp->profile->table_name_data = $wpdb->base_prefix . 'bp_xprofile_data';
</span><del>-        $bp->profile->format_activity_function = 'xprofile_format_activity';
</del><ins>+
</ins><span class="cx">         $bp->profile->format_notification_function = 'xprofile_format_notifications';
</span><del>-        $bp->profile->image_base = BP_PLUGIN_URL . '/bp-xprofile/images';
</del><span class="cx">         $bp->profile->slug = BP_XPROFILE_SLUG;
</span><span class="cx">         
</span><span class="cx">         $bp->profile->field_types = apply_filters( 'xprofile_field_types', array( 'textbox', 'textarea', 'radio', 'checkbox', 'selectbox', 'multiselectbox', 'datebox' ) );
</span><span class="cx">
</span><del>-        $bp->version_numbers->profile = BP_XPROFILE_VERSION;
-        
</del><span class="cx">         if ( function_exists('bp_wire_install') )
</span><span class="cx">                 $bp->profile->table_name_wire = $wpdb->base_prefix . 'bp_xprofile_wire';
</span><span class="cx"> }
</span><span class="lines">@@ -481,17 +481,39 @@
</span><span class="cx">         if ( !check_admin_referer( 'bp_wire_post' ) )
</span><span class="cx">                 return false;
</span><span class="cx">                 
</span><del>-        if ( !$wire_post_id = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
</del><ins>+        if ( !$wire_post = bp_wire_new_post( $bp->displayed_user->id, $_POST['wire-post-textarea'], $bp->profile->slug, false, $bp->profile->table_name_wire ) ) {
</ins><span class="cx">                 bp_core_add_message( __( 'Wire message could not be posted. Please try again.', 'buddypress' ), 'error' );
</span><span class="cx">         } else {
</span><span class="cx">                 bp_core_add_message( __( 'Wire message successfully posted.', 'buddypress' ) );
</span><del>-
-                if ( !bp_is_home() ) {
-                        /* Record the notification for the user */
</del><ins>+                
+                /* Record the notification for the reciever if it's not on their own wire */
+                if ( !bp_is_home() )
</ins><span class="cx">                         bp_core_add_notification( $bp->loggedin_user->id, $bp->displayed_user->id, 'profile', 'new_wire_post' );        
</span><del>-                }
</del><span class="cx">                 
</span><del>-                do_action( 'xprofile_new_wire_post', $wire_post_id );        
</del><ins>+                /* Record this on the poster's activity screen */
+                if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
+                        $from_user_link = bp_core_get_userlink($wire_post->user_id);
+                        $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';                                
+                        $primary_link = bp_core_get_userlink( $wire_post->user_id, false, true );        
+                } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
+                        $from_user_link = bp_core_get_userlink($wire_post->user_id);
+                        $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true );
+                        $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';                        
+                        $primary_link = bp_core_get_userlink( $wire_post->item_id, false, true );
+                }
+                
+                $content .= '<blockquote>' . bp_create_excerpt($wire_post->content) . '</blockquote>';
+
+                /* Now write the values */
+                xprofile_record_activity( array(
+                        'user_id' => $bp->loggedin_user->id,
+                        'content' => $content,
+                        'primary_link' => $primary_link,
+                        'component_action' => 'new_wire_post',
+                        'item_id' => $wire_post->item_id
+                ) );
+                                
+                do_action( 'xprofile_new_wire_post', &$wire_post );        
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( !strpos( $_SERVER['HTTP_REFERER'], $bp->wire->slug ) ) {
</span><span class="lines">@@ -564,10 +586,27 @@
</span><span class="cx"> * @uses bp_activity_record() Adds an entry to the activity component tables for a specific activity
</span><span class="cx"> */
</span><span class="cx"> function xprofile_record_activity( $args = true ) {
</span><del>-        if ( function_exists('bp_activity_record') ) {
-                extract($args);
-                bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
-        }
</del><ins>+        global $bp;
+        
+        if ( !function_exists( 'bp_activity_add' ) )
+                return false;
+
+        $defaults = array(
+                'user_id' => $bp->loggedin_user->id,
+                'content' => false,
+                'primary_link' => false,
+                'component_name' => $bp->profile->id,
+                'component_action' => false,
+                'item_id' => false,
+                'secondary_item_id' => false,
+                'recorded_time' => time(),
+                'hide_sitewide' => false
+        );
+
+        $r = wp_parse_args( $args, $defaults );
+        extract( $r, EXTR_SKIP );        
+        
+        return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -589,89 +628,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * xprofile_format_activity()
- *
- * The function xprofile_record_activity() simply records ID's, which component and action, and dates into
- * the database. These variables need to be formatted into something that can be read and displayed to
- * the user.
- *
- * This function will format an activity item based on the component action and return it for saving
- * in the activity cache database tables. It can then be selected and displayed with far less load on
- * the server.
- *
- * @package BuddyPress Xprofile
- * @param $item_id The ID of the specific item for which the activity is recorded (could be a wire post id, user id etc)
- * @param $action The component action name e.g. 'new_wire_post' or 'updated_profile'
- * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
- * @global $current_user WordPress global variable containing current logged in user information
- * @uses BP_Wire_Post Class Creates a new wire post object based on the table name and ID.
- * @uses BP_XProfile_Group Class Creates a new group object based on the group ID.
- * @return The readable activity item
- */
-function xprofile_format_activity( $item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false ) {
-        global $bp;
-        
-        switch( $action ) {
-                case 'new_wire_post':
-                        if ( class_exists('BP_Wire_Post') ) {
-                                $wire_post = new BP_Wire_Post( $bp->profile->table_name_wire, $item_id );
-                        }
-                        
-                        if ( !$wire_post )
-                                return false;
-                        
-                        if ( ( $wire_post->item_id == $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id == $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
-                                
-                                $from_user_link = bp_core_get_userlink($wire_post->user_id);
-                                $to_user_link = false;
-                                                                
-                                $content = sprintf( __('%s wrote on their own wire', 'buddypress'), $from_user_link ) . ': <span class="time-since">%s</span>';                                
-                                $return_values['primary_link'] = bp_core_get_userlink( $wire_post->user_id, false, true );
-                        
-                        } else if ( ( $wire_post->item_id != $bp->loggedin_user->id && $wire_post->user_id == $bp->loggedin_user->id ) || ( $wire_post->item_id != $bp->displayed_user->id && $wire_post->user_id == $bp->displayed_user->id ) ) {
-                        
-                                $from_user_link = bp_core_get_userlink($wire_post->user_id);
-                                $to_user_link = bp_core_get_userlink( $wire_post->item_id, false, false, true, true );
-                                
-                                $content = sprintf( __('%s wrote on %s wire', 'buddypress'), $from_user_link, $to_user_link ) . ': <span class="time-since">%s</span>';                        
-                                $return_values['primary_link'] = bp_core_get_userlink( $wire_post->item_id, false, true );
-                        
-                        }
-                        
-                        if ( $content != '' ) {
-                                $post_excerpt = bp_create_excerpt($wire_post->content);
-                                
-                                $content .= '<blockquote>' . $post_excerpt . '</blockquote>';
-                                $return_values['content'] = $content;
-                                
-                                $return_values['content'] = apply_filters( 'xprofile_new_wire_post_activity', $content, $from_user_link, $to_user_link, $post_excerpt );
-                                
-                                return $return_values;
-                        }
-                        
-                        return false;
-                break;
-                case 'updated_profile':
-                        $profile_group = new BP_XProfile_Group( $item_id );
-                        
-                        if ( !$profile_group )
-                                return false;
-                        
-                        $user_link = bp_core_get_userlink($user_id);
-                        
-                        return array(
-                                'primary_link' => bp_core_get_userlink( $user_id, false, true ),
-                                'content' => apply_filters( 'xprofile_updated_profile_activity', sprintf( __('%s updated the "%s" information on their profile', 'buddypress'), $user_link, '<a href="' . $bp->displayed_user->domain . $bp->profile->slug . '">' . $profile_group->name . '</a>' ) . ' <span class="time-since">%s</span>', $user_link, $profile_group->name )
-                        );
-                break;
-        }
-        
-        do_action( 'xprofile_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user );
-        
-        return false;
-}
-
-/**
</del><span class="cx"> * xprofile_format_notifications()
</span><span class="cx"> *
</span><span class="cx"> * Format notifications into something that can be read and displayed
</span></span></pre>
</div>
</div>
</body>
</html>