<!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] [2439] trunk:
  Making sure all blog comments under a BuddyPress enabled install have proper BuddyPress full names and profile links for registered users
 .</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd>2439</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-01-25 00:33:37 +0000 (Mon, 25 Jan 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Making sure all blog comments under a BuddyPress enabled install have proper BuddyPress full names and profile links for registered users. Also improved the efficiency of this.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpcorephp">trunk/bp-core.php</a></li>
<li><a href="#trunkbpthemesbpdefault_inccssdefaultcss">trunk/bp-themes/bp-default/_inc/css/default.css</a></li>
<li><a href="#trunkbpxprofilebpxprofileclassesphp">trunk/bp-xprofile/bp-xprofile-classes.php</a></li>
<li><a href="#trunkbpxprofilebpxprofilefiltersphp">trunk/bp-xprofile/bp-xprofile-filters.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpcorephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-core.php (2438 => 2439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-core.php        2010-01-24 23:19:12 UTC (rev 2438)
+++ trunk/bp-core.php        2010-01-25 00:33:37 UTC (rev 2439)
</span><span class="lines">@@ -2000,6 +2000,46 @@
</span><span class="cx"> add_action( 'admin_notices', 'bp_core_activation_notice' );
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * bp_core_filter_comments()
+ *
+ * Filter the blog post comments array and insert BuddyPress URLs for users.
+ *
+ * @package BuddyPress Core
+ */
+function bp_core_filter_comments( $comments, $post_id ) {
+        global $wpdb;
+
+        if ( !is_site_admin() )
+                return $comments;
+
+        foreach( $comments as $comment ) {
+                if ( $comment-&gt;user_id )
+                        $user_ids[] = $comment-&gt;user_id;
+        }
+
+        if ( empty( $user_ids ) )
+                return $comments;
+
+        $user_ids = implode( ',', $user_ids );
+
+        if ( !$userdata = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT ID as user_id, user_login, user_nicename FROM {$wpdb-&gt;users} WHERE ID IN ({$user_ids})&quot; ) ) )
+                return $comments;
+
+        foreach( $userdata as $user )
+                $users[$user-&gt;user_id] = bp_core_get_user_domain( $user-&gt;user_id, $user-&gt;user_nicename, $user-&gt;user_login );
+
+        foreach( $comments as $i =&gt; $comment ) {
+                if ( !empty( $comment-&gt;user_id ) ) {
+                        if ( !empty( $users[$comment-&gt;user_id] ) )
+                                $comments[$i]-&gt;comment_author_url = $users[$comment-&gt;user_id];
+                }
+        }
+
+        return $comments;
+}
+add_filter( 'comments_array', 'bp_core_filter_comments', 10, 2 );
+
+/**
</ins><span class="cx">  * bp_core_clear_user_object_cache()
</span><span class="cx">  *
</span><span class="cx">  * Clears all cached objects for a user, or a user is part of.
</span></span></pre></div>
<a id="trunkbpthemesbpdefault_inccssdefaultcss"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/css/default.css (2438 => 2439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/css/default.css        2010-01-24 23:19:12 UTC (rev 2438)
+++ trunk/bp-themes/bp-default/_inc/css/default.css        2010-01-25 00:33:37 UTC (rev 2439)
</span><span class="lines">@@ -1504,7 +1504,7 @@
</span><span class="cx">                         text-decoration: none;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-        .navigation {
</del><ins>+        .navigation, .paged-navigation, .comment-navigation {
</ins><span class="cx">                 overflow: hidden;
</span><span class="cx">                 font-family: georgia, times, serif;
</span><span class="cx">                 font-style: italic;
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofileclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-classes.php (2438 => 2439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-classes.php        2010-01-24 23:19:12 UTC (rev 2438)
+++ trunk/bp-xprofile/bp-xprofile-classes.php        2010-01-25 00:33:37 UTC (rev 2439)
</span><span class="lines">@@ -787,22 +787,22 @@
</span><span class="cx">                 return $profile_data;
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        function get_value_byid( $field_id, $user_id = null ) {
</del><ins>+        function get_value_byid( $field_id, $user_ids = null ) {
</ins><span class="cx">                 global $wpdb, $bp;
</span><span class="cx"> 
</span><del>-                if ( !$user_id )
-                        $user_id = $bp-&gt;displayed_user-&gt;id;
</del><ins>+                if ( !$user_ids )
+                        $user_ids = $bp-&gt;displayed_user-&gt;id;
</ins><span class="cx"> 
</span><span class="cx">                 if ( !$bp-&gt;profile )
</span><span class="cx">                         xprofile_setup_globals();
</span><span class="cx"> 
</span><del>-                $sql = $wpdb-&gt;prepare( &quot;SELECT * FROM {$bp-&gt;profile-&gt;table_name_data} WHERE field_id = %d AND user_id = %d&quot;, $field_id, $user_id );
</del><ins>+                if ( is_array( $user_ids ) ) {
+                        $user_ids = implode( ',', (array)$user_ids );
+                        $data = $wpdb-&gt;get_results( $wpdb-&gt;prepare( &quot;SELECT user_id, value FROM {$bp-&gt;profile-&gt;table_name_data} WHERE field_id = %d AND user_id IN ({$user_ids})&quot;, $field_id ) );
+                } else
+                        $data = $wpdb-&gt;get_var( $wpdb-&gt;prepare( &quot;SELECT value FROM {$bp-&gt;profile-&gt;table_name_data} WHERE field_id = %d AND user_id = %d&quot;, $field_id, $user_ids ) );
</ins><span class="cx"> 
</span><del>-                if ( $profile_data = $wpdb-&gt;get_row($sql) ) {
-                        return $profile_data-&gt;value;
-                } else {
-                        return false;
-                }
</del><ins>+                return $data;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function get_value_byfieldname( $fields, $user_id = null ) {
</span></span></pre></div>
<a id="trunkbpxprofilebpxprofilefiltersphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-xprofile/bp-xprofile-filters.php (2438 => 2439)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-xprofile/bp-xprofile-filters.php        2010-01-24 23:19:12 UTC (rev 2438)
+++ trunk/bp-xprofile/bp-xprofile-filters.php        2010-01-25 00:33:37 UTC (rev 2439)
</span><span class="lines">@@ -84,5 +84,30 @@
</span><span class="cx">         return $values;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+function xprofile_filter_comments( $comments, $post_id ) {
+        foreach( $comments as $comment ) {
+                if ( $comment-&gt;user_id )
+                        $user_ids[] = $comment-&gt;user_id;
+        }
</ins><span class="cx"> 
</span><ins>+        if ( empty( $user_ids ) )
+                return $comments;
+
+        if ( $fullnames = BP_XProfile_ProfileData::get_value_byid( 1, $user_ids ) ) {
+                foreach( $fullnames as $user ) {
+                        $users[$user-&gt;user_id] = trim($user-&gt;value);
+                }
+        }
+
+        foreach( $comments as $i =&gt; $comment ) {
+                if ( !empty( $comment-&gt;user_id ) ) {
+                        if ( !empty( $users[$comment-&gt;user_id] ) )
+                                $comments[$i]-&gt;comment_author = $users[$comment-&gt;user_id];
+                }
+        }
+
+        return $comments;
+}
+add_filter( 'comments_array', 'xprofile_filter_comments', 10, 2 );
+
</ins><span class="cx"> ?&gt;
</span><span class="cx">\ No newline at end of file
</span></span></pre>
</div>
</div>

</body>
</html>