<!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] [1819] trunk:
Activity stream updates to support non-numeric item_ids and allow for avatars other than user avatars to be shown as the bullet for activity stream items
.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>1819</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2009-09-08 05:06:09 +0000 (Tue, 08 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Activity stream updates to support non-numeric item_ids and allow for avatars other than user avatars to be shown as the bullet for activity stream items.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivityclassesphp">trunk/bp-activity/bp-activity-classes.php</a></li>
<li><a href="#trunkbpactivitybpactivitytemplatetagsphp">trunk/bp-activity/bp-activity-templatetags.php</a></li>
<li><a href="#trunkbpactivitybpactivitywidgetsphp">trunk/bp-activity/bp-activity-widgets.php</a></li>
<li><a href="#trunkbpactivityphp">trunk/bp-activity.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivityclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-classes.php (1818 => 1819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-classes.php        2009-09-08 05:02:00 UTC (rev 1818)
+++ trunk/bp-activity/bp-activity-classes.php        2009-09-08 05:06:09 UTC (rev 1819)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">                 
</span><span class="cx">                 do_action( 'bp_activity_before_save', $this );
</span><span class="cx">
</span><del>-                if ( !$this->user_id || !$this->component_name || !$this->component_action )
</del><ins>+                if ( !$this->component_name || !$this->component_action )
</ins><span class="cx">                         return false;
</span><span class="cx">                 
</span><span class="cx">                 /***
</span><span class="lines">@@ -67,12 +67,12 @@
</span><span class="cx">                 
</span><span class="cx">                 /* If we have an existing ID, update the activity item, otherwise insert it. */
</span><span class="cx">                 if ( $this->id ) {
</span><del>-                        if ( $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component_name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %d, secondary_item_id = %d, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id ) ) ) {
</del><ins>+                        if ( $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET user_id = %d, component_name = %s, component_action = %s, content = %s, primary_link = %s, date_recorded = FROM_UNIXTIME(%d), item_id = %s, secondary_item_id = %s, hide_sitewide = %d WHERE id = %d", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide, $this->id ) ) ) {
</ins><span class="cx">                                 do_action( 'bp_activity_after_save', $this );
</span><span class="cx">                                 return true;
</span><span class="cx">                         }
</span><span class="cx">                 } else {
</span><del>-                        if ( $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component_name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %d, %d, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide ) ) ) {
</del><ins>+                        if ( $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->activity->table_name} ( user_id, component_name, component_action, content, primary_link, date_recorded, item_id, secondary_item_id, hide_sitewide ) VALUES ( %d, %s, %s, %s, %s, FROM_UNIXTIME(%d), %s, %s, %d )", $this->user_id, $this->component_name, $this->component_action, $this->content, $this->primary_link, $this->date_recorded, $this->item_id, $this->secondary_item_id, $this->hide_sitewide ) ) ) {
</ins><span class="cx">                                 do_action( 'bp_activity_after_save', $this );
</span><span class="cx">                                 return true;
</span><span class="cx">                         }
</span><span class="lines">@@ -90,9 +90,9 @@
</span><span class="cx">                 /* If we have an item id, try and match on that, if not do a content match */
</span><span class="cx">                 if ( $this->item_id ) {
</span><span class="cx">                         if ( $this->secondary_item_id )
</span><del>-                                $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
</del><ins>+                                $secondary_sql = $wpdb->prepare( " AND secondary_item_id = %s", $secondary_item_id );
</ins><span class="cx">                                 
</span><del>-                        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );                
</del><ins>+                        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s", $this->user_id, $this->item_id, $this->component_name, $this->component_action ) );                
</ins><span class="cx">                 } else {
</span><span class="cx">                         return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s", $this->user_id, $this->content, $this->component_name, $this->component_action ) );                                
</span><span class="cx">                 }
</span><span class="lines">@@ -104,15 +104,15 @@
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">
</span><span class="cx">                 if ( $secondary_item_id )
</span><del>-                        $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %d", $secondary_item_id );
</del><ins>+                        $secondary_sql = $wpdb->prepare( "AND secondary_item_id = %s", $secondary_item_id );
</ins><span class="cx">                 
</span><span class="cx">                 if ( $component_action )
</span><span class="cx">                         $component_action_sql = $wpdb->prepare( "AND component_action = %s", $component_action );
</span><span class="cx">                 
</span><span class="cx">                 if ( $user_id )
</span><span class="cx">                         $user_sql = $wpdb->prepare( "AND user_id = %d", $user_id );
</span><del>-
-                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
</del><ins>+                
+                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->activity->table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}", $item_id, $component_name ) );
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         function delete_by_item_id( $item_id, $component_name, $component_action, $user_id = false, $secondary_item_id = false ) {
</span><span class="lines">@@ -163,18 +163,8 @@
</span><span class="cx">                         $activities = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->activity->table_name} WHERE user_id = %d AND date_recorded >= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql", $user_id, $since ) );
</span><span class="cx">                 
</span><span class="cx">                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE user_id = %d AND date_recorded >= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $max_sql", $user_id, $since ) );
</span><del>-
-                for ( $i = 0; $i < count( $activities ); $i++ ) {
-                        $activities_formatted[$i]['id'] = $activities[$i]->id;
-                        $activities_formatted[$i]['user_id'] = $activities[$i]->user_id;
-                        $activities_formatted[$i]['content'] = $activities[$i]->content;
-                        $activities_formatted[$i]['primary_link'] = $activities[$i]->primary_link;
-                        $activities_formatted[$i]['date_recorded'] = $activities[$i]->date_recorded;
-                        $activities_formatted[$i]['component_name'] = $activities[$i]->component_name;
-                        $activities_formatted[$i]['component_action'] = $activities[$i]->component_action;
-                }
</del><span class="cx">                 
</span><del>-                return array( 'activities' => $activities_formatted, 'total' => (int)$total_activities );
</del><ins>+                return array( 'activities' => $activities, 'total' => (int)$total_activities );
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         function get_activity_for_friends( $user_id, $max_items, $since, $max_items_per_friend, $limit, $page, $filter ) {
</span><span class="lines">@@ -232,17 +222,7 @@
</span><span class="cx">
</span><span class="cx">                 $total_activities = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM {$bp->activity->table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $max_sql" ) );
</span><span class="cx">
</span><del>-                for ( $i = 0; $i < count( $activities ); $i++ ) {
-                        $activities_formatted[$i]['id'] = $activities[$i]->id;
-                        $activities_formatted[$i]['user_id'] = $activities[$i]->user_id;
-                        $activities_formatted[$i]['content'] = $activities[$i]->content;
-                        $activities_formatted[$i]['primary_link'] = $activities[$i]->primary_link;
-                        $activities_formatted[$i]['date_recorded'] = $activities[$i]->date_recorded;
-                        $activities_formatted[$i]['component_name'] = $activities[$i]->component_name;
-                        $activities_formatted[$i]['component_action'] = $activities[$i]->component_action;
-                }
-
-                return array( 'activities' => $activities_formatted, 'total' => (int)$total_activities );
</del><ins>+                return array( 'activities' => $activities, 'total' => (int)$total_activities );
</ins><span class="cx">         }
</span><span class="cx">         
</span><span class="cx">         function get_recorded_component_names() {
</span><span class="lines">@@ -272,6 +252,12 @@
</span><span class="cx">                 
</span><span class="cx">                 return $wpdb->get_var( $wpdb->prepare( "SELECT date_recorded FROM {$bp->activity->table_name} ORDER BY date_recorded ASC LIMIT 1" ) );
</span><span class="cx">         }
</span><ins>+        
+        function check_exists_by_content( $content ) {
+                global $wpdb, $bp;
+
+                return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->activity->table_name} WHERE content = %s", $content ) );
+        }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ?>
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkbpactivitybpactivitytemplatetagsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-templatetags.php (1818 => 1819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-templatetags.php        2009-09-08 05:02:00 UTC (rev 1818)
+++ trunk/bp-activity/bp-activity-templatetags.php        2009-09-08 05:06:09 UTC (rev 1819)
</span><span class="lines">@@ -226,11 +226,11 @@
</span><span class="cx">                 return apply_filters( 'bp_get_activity_user_id', $activities_template->activity->user_id );
</span><span class="cx">         }
</span><span class="cx">
</span><del>-function bp_activity_user_avatar( $args = '' ) {
-        echo bp_get_activity_user_avatar( $args );
</del><ins>+function bp_activity_avatar( $args = '' ) {
+        echo bp_get_activity_avatar( $args );
</ins><span class="cx"> }
</span><del>-        function bp_get_activity_user_avatar( $args = '' ) {
-                global $activities_template;
</del><ins>+        function bp_get_activity_avatar( $args = '' ) {
+                global $bp, $activities_template;
</ins><span class="cx">
</span><span class="cx">                 $defaults = array(
</span><span class="cx">                         'type' => 'thumb',
</span><span class="lines">@@ -242,8 +242,22 @@
</span><span class="cx">
</span><span class="cx">                 $r = wp_parse_args( $args, $defaults );
</span><span class="cx">                 extract( $r, EXTR_SKIP );
</span><del>-        
-                return apply_filters( 'bp_get_group_avatar', bp_core_fetch_avatar( array( 'item_id' => $activities_template->activity->user_id, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height ) ) );
</del><ins>+                
+                $item_id = false;
+                if ( (int)$activities_template->activity->user_id )
+                        $item_id = $activities_template->activity->user_id;
+                else if ( $activities_template->activity->item_id )
+                        $item_id = $activities_template->activity->item_id;
+
+                $object = 'user';
+                if ( $bp->groups->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id )
+                        $object = 'group';
+                if ( $bp->blogs->id == $activities_template->activity->component_name && !(int) $activities_template->activity->user_id )
+                        $object = 'blog';
+                
+                $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template->activity->component_name, $object );
+                
+                return apply_filters( 'bp_get_group_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height ) ) );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> function bp_activity_content() {
</span></span></pre></div>
<a id="trunkbpactivitybpactivitywidgetsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-widgets.php (1818 => 1819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-widgets.php        2009-09-08 05:02:00 UTC (rev 1818)
+++ trunk/bp-activity/bp-activity-widgets.php        2009-09-08 05:06:09 UTC (rev 1819)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">                 <?php while ( bp_activities() ) : bp_the_activity(); ?>
</span><span class="cx">                         <li class="<?php bp_activity_css_class() ?>">
</span><span class="cx">                                 <div class="activity-avatar">
</span><del>-                                        <?php bp_activity_user_avatar() ?>
</del><ins>+                                        <?php bp_activity_avatar() ?>
</ins><span class="cx">                                 </div>
</span><span class="cx">                                 
</span><span class="cx">                                 <?php bp_activity_content() ?>
</span></span></pre></div>
<a id="trunkbpactivityphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity.php (1818 => 1819)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity.php        2009-09-08 05:02:00 UTC (rev 1818)
+++ trunk/bp-activity.php        2009-09-08 05:06:09 UTC (rev 1819)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> <?php
</span><span class="cx">
</span><del>-define ( 'BP_ACTIVITY_DB_VERSION', '1721' );
</del><ins>+define ( 'BP_ACTIVITY_DB_VERSION', '1750' );
</ins><span class="cx">
</span><span class="cx"> /* Define the slug for the component */
</span><span class="cx"> if ( !defined( 'BP_ACTIVITY_SLUG' ) )
</span><span class="lines">@@ -28,8 +28,8 @@
</span><span class="cx">                                 component_action varchar(75) NOT NULL,
</span><span class="cx">                                 content longtext NOT NULL,
</span><span class="cx">                                 primary_link varchar(150) NOT NULL,
</span><del>-                                item_id bigint(20) NOT NULL,
-                                secondary_item_id bigint(20) NOT NULL,
</del><ins>+                                item_id varchar(75) NOT NULL,
+                                secondary_item_id varchar(75) NOT NULL,
</ins><span class="cx">                                 date_recorded datetime NOT NULL,
</span><span class="cx">                                 hide_sitewide bool DEFAULT 0,
</span><span class="cx">                                 KEY date_recorded (date_recorded),
</span><span class="lines">@@ -336,35 +336,13 @@
</span><span class="cx">         return $content;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+function bp_activity_check_exists_by_content( $content ) {
+        /* Insert the "time-since" placeholder to match the existing content in the DB */
+        $content = bp_activity_add_timesince_placeholder( $content );
</ins><span class="cx">
</span><del>-function bp_activity_set_action( $component_id, $key, $value ) {
-        global $bp;
-        
-        if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
-                return false;
-        
-        $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
-                'key' => $key,
-                'value' => $value
-        ), $component_id, $key, $value );
</del><ins>+        return BP_Activity_Activity::check_exists_by_content( $content );
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-function bp_activity_get_action( $component_id, $key ) {
-        global $bp;
-        
-        if ( empty( $component_id ) || empty( $key ) )
-                return false;
-        
-        return apply_filters( 'bp_activity_get_action', $bp->activity->actions->{$component_id}->{$key}, $component_id, $key );
-}
-
-function groups_get_activity_action( $key ) {
-        if ( !function_exists( 'bp_activity_get_action' ) )
-                return false;
-        
-        return apply_filters( 'groups_get_activity_action', bp_activity_get_action( $key ), $key );
-}
-
</del><span class="cx"> function bp_activity_get_last_updated() {
</span><span class="cx">         return BP_Activity_Activity::get_last_updated();
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>