<!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-&gt;user_id || !$this-&gt;component_name || !$this-&gt;component_action )
</del><ins>+                if ( !$this-&gt;component_name || !$this-&gt;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-&gt;id ) {
</span><del>-                        if ( $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;UPDATE {$bp-&gt;activity-&gt;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&quot;, $this-&gt;user_id, $this-&gt;component_name, $this-&gt;component_action, $this-&gt;content, $this-&gt;primary_link, $this-&gt;date_recorded, $this-&gt;item_id, $this-&gt;secondary_item_id, $this-&gt;hide_sitewide, $this-&gt;id ) ) ) {
</del><ins>+                        if ( $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;UPDATE {$bp-&gt;activity-&gt;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&quot;, $this-&gt;user_id, $this-&gt;component_name, $this-&gt;component_action, $this-&gt;content, $this-&gt;primary_link, $this-&gt;date_recorded, $this-&gt;item_id, $this-&gt;secondary_item_id, $this-&gt;hide_sitewide, $this-&gt;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-&gt;query( $wpdb-&gt;prepare( &quot;INSERT INTO {$bp-&gt;activity-&gt;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 )&quot;, $this-&gt;user_id, $this-&gt;component_name, $this-&gt;component_action, $this-&gt;content, $this-&gt;primary_link, $this-&gt;date_recorded, $this-&gt;item_id, $this-&gt;secondary_item_id, $this-&gt;hide_sitewide ) ) ) {
</del><ins>+                        if ( $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;INSERT INTO {$bp-&gt;activity-&gt;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 )&quot;, $this-&gt;user_id, $this-&gt;component_name, $this-&gt;component_action, $this-&gt;content, $this-&gt;primary_link, $this-&gt;date_recorded, $this-&gt;item_id, $this-&gt;secondary_item_id, $this-&gt;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-&gt;item_id ) {
</span><span class="cx">                         if ( $this-&gt;secondary_item_id )
</span><del>-                                $secondary_sql = $wpdb-&gt;prepare( &quot; AND secondary_item_id = %d&quot;, $secondary_item_id );
</del><ins>+                                $secondary_sql = $wpdb-&gt;prepare( &quot; AND secondary_item_id = %s&quot;, $secondary_item_id );
</ins><span class="cx">                                 
</span><del>-                        return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT id FROM {$bp-&gt;activity-&gt;table_name} WHERE user_id = %d AND item_id = %d{$secondary_sql} AND component_name = %s AND component_action = %s&quot;, $this-&gt;user_id, $this-&gt;item_id, $this-&gt;component_name, $this-&gt;component_action ) );                
</del><ins>+                        return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT id FROM {$bp-&gt;activity-&gt;table_name} WHERE user_id = %d AND item_id = %s{$secondary_sql} AND component_name = %s AND component_action = %s&quot;, $this-&gt;user_id, $this-&gt;item_id, $this-&gt;component_name, $this-&gt;component_action ) );                
</ins><span class="cx">                 } else {
</span><span class="cx">                         return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT id FROM {$bp-&gt;activity-&gt;table_name} WHERE user_id = %d AND content = %s AND component_name = %s AND component_action = %s&quot;, $this-&gt;user_id, $this-&gt;content, $this-&gt;component_name, $this-&gt;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-&gt;prepare( &quot;AND secondary_item_id = %d&quot;, $secondary_item_id );
</del><ins>+                        $secondary_sql = $wpdb-&gt;prepare( &quot;AND secondary_item_id = %s&quot;, $secondary_item_id );
</ins><span class="cx">                 
</span><span class="cx">                 if ( $component_action )
</span><span class="cx">                         $component_action_sql = $wpdb-&gt;prepare( &quot;AND component_action = %s&quot;, $component_action );
</span><span class="cx">                 
</span><span class="cx">                 if ( $user_id )
</span><span class="cx">                         $user_sql = $wpdb-&gt;prepare( &quot;AND user_id = %d&quot;, $user_id );
</span><del>-
-                return $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM {$bp-&gt;activity-&gt;table_name} WHERE item_id = %d {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}&quot;, $item_id, $component_name ) );
</del><ins>+                
+                return $wpdb-&gt;query( $wpdb-&gt;prepare( &quot;DELETE FROM {$bp-&gt;activity-&gt;table_name} WHERE item_id = %s {$secondary_sql} AND component_name = %s {$component_action_sql} {$user_sql}&quot;, $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-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;activity-&gt;table_name} WHERE user_id = %d AND date_recorded &gt;= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $pag_sql $max_sql&quot;, $user_id, $since ) );
</span><span class="cx">                 
</span><span class="cx">                 $total_activities = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT count(id) FROM {$bp-&gt;activity-&gt;table_name} WHERE user_id = %d AND date_recorded &gt;= FROM_UNIXTIME(%d) $privacy_sql $filter_sql ORDER BY date_recorded DESC $max_sql&quot;, $user_id, $since ) );
</span><del>-
-                for ( $i = 0; $i &lt; count( $activities ); $i++ ) {
-                        $activities_formatted[$i]['id'] = $activities[$i]-&gt;id;
-                        $activities_formatted[$i]['user_id'] = $activities[$i]-&gt;user_id;
-                        $activities_formatted[$i]['content'] = $activities[$i]-&gt;content;
-                        $activities_formatted[$i]['primary_link'] = $activities[$i]-&gt;primary_link;
-                        $activities_formatted[$i]['date_recorded'] = $activities[$i]-&gt;date_recorded;
-                        $activities_formatted[$i]['component_name'] = $activities[$i]-&gt;component_name;
-                        $activities_formatted[$i]['component_action'] = $activities[$i]-&gt;component_action;
-                }
</del><span class="cx">                 
</span><del>-                return array( 'activities' =&gt; $activities_formatted, 'total' =&gt; (int)$total_activities );
</del><ins>+                return array( 'activities' =&gt; $activities, 'total' =&gt; (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-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT count(id) FROM {$bp-&gt;activity-&gt;table_name} WHERE hide_sitewide = 0 $filter_sql ORDER BY date_recorded DESC $max_sql&quot; ) );
</span><span class="cx"> 
</span><del>-                for ( $i = 0; $i &lt; count( $activities ); $i++ ) {
-                        $activities_formatted[$i]['id'] = $activities[$i]-&gt;id;
-                        $activities_formatted[$i]['user_id'] = $activities[$i]-&gt;user_id;
-                        $activities_formatted[$i]['content'] = $activities[$i]-&gt;content;
-                        $activities_formatted[$i]['primary_link'] = $activities[$i]-&gt;primary_link;
-                        $activities_formatted[$i]['date_recorded'] = $activities[$i]-&gt;date_recorded;
-                        $activities_formatted[$i]['component_name'] = $activities[$i]-&gt;component_name;
-                        $activities_formatted[$i]['component_action'] = $activities[$i]-&gt;component_action;
-                }
-
-                return array( 'activities' =&gt; $activities_formatted, 'total' =&gt; (int)$total_activities );
</del><ins>+                return array( 'activities' =&gt; $activities, 'total' =&gt; (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-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT date_recorded FROM {$bp-&gt;activity-&gt;table_name} ORDER BY date_recorded ASC LIMIT 1&quot; ) );
</span><span class="cx">         }
</span><ins>+        
+        function check_exists_by_content( $content ) {
+                global $wpdb, $bp;
+
+                return $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT id FROM {$bp-&gt;activity-&gt;table_name} WHERE content = %s&quot;, $content ) );
+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ?&gt;
</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-&gt;activity-&gt;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' =&gt; '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' =&gt; $activities_template-&gt;activity-&gt;user_id, 'type' =&gt; $type, 'alt' =&gt; $alt, 'class' =&gt; $class, 'width' =&gt; $width, 'height' =&gt; $height ) ) );
</del><ins>+                
+                $item_id = false;
+                if ( (int)$activities_template-&gt;activity-&gt;user_id )
+                        $item_id = $activities_template-&gt;activity-&gt;user_id;
+                else if ( $activities_template-&gt;activity-&gt;item_id )
+                        $item_id = $activities_template-&gt;activity-&gt;item_id;
+
+                $object = 'user';
+                if ( $bp-&gt;groups-&gt;id == $activities_template-&gt;activity-&gt;component_name &amp;&amp; !(int) $activities_template-&gt;activity-&gt;user_id )
+                        $object = 'group';
+                if ( $bp-&gt;blogs-&gt;id == $activities_template-&gt;activity-&gt;component_name &amp;&amp; !(int) $activities_template-&gt;activity-&gt;user_id )
+                        $object = 'blog';
+                
+                $object = apply_filters( 'bp_get_activity_avatar_object_' . $activities_template-&gt;activity-&gt;component_name, $object );
+                
+                return apply_filters( 'bp_get_group_avatar', bp_core_fetch_avatar( array( 'item_id' =&gt; $item_id, 'object' =&gt; $object, 'type' =&gt; $type, 'alt' =&gt; $alt, 'class' =&gt; $class, 'width' =&gt; $width, 'height' =&gt; $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">                 &lt;?php while ( bp_activities() ) : bp_the_activity(); ?&gt;
</span><span class="cx">                         &lt;li class=&quot;&lt;?php bp_activity_css_class() ?&gt;&quot;&gt;
</span><span class="cx">                                 &lt;div class=&quot;activity-avatar&quot;&gt;
</span><del>-                                        &lt;?php bp_activity_user_avatar() ?&gt;
</del><ins>+                                        &lt;?php bp_activity_avatar() ?&gt;
</ins><span class="cx">                                 &lt;/div&gt;
</span><span class="cx">                                 
</span><span class="cx">                                 &lt;?php bp_activity_content() ?&gt;
</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"> &lt;?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 &quot;time-since&quot; 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-&gt;activity-&gt;actions-&gt;{$component_id}-&gt;{$key} = apply_filters( 'bp_activity_set_action', array(
-                'key' =&gt; $key,
-                'value' =&gt; $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-&gt;activity-&gt;actions-&gt;{$component_id}-&gt;{$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>