<!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" />
<title>[BuddyPress][6607] trunk: Add ability to link secondary avatars in activity streams.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/6607">6607</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-12-10 14:25:26 +0000 (Mon, 10 Dec 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add ability to link secondary avatars in activity streams. Props jag1989. Fixes <a href="http://buddypress.trac.wordpress.org/ticket/4436">#4436</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpactivitybpactivitytemplatephp">trunk/bp-activity/bp-activity-template.php</a></li>
<li><a href="#trunkbptemplatesbplegacybuddypressfunctionsphp">trunk/bp-templates/bp-legacy/buddypress-functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpactivitybpactivitytemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/bp-activity/bp-activity-template.php (6606 => 6607)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-activity/bp-activity-template.php        2012-12-10 14:04:33 UTC (rev 6606)
+++ trunk/bp-activity/bp-activity-template.php        2012-12-10 14:25:26 UTC (rev 6607)
</span><span class="lines">@@ -1048,11 +1048,13 @@
</span><span class="cx">                 global $activities_template;
</span><span class="cx"> 
</span><span class="cx">                 $defaults = array(
</span><del>-                        'type'   =&gt; 'thumb',
-                        'width'  =&gt; 20,
-                        'height' =&gt; 20,
-                        'class'  =&gt; 'avatar',
-                        'email'  =&gt; false
</del><ins>+                        'type'       =&gt; 'thumb',
+                        'width'      =&gt; 20,
+                        'height'     =&gt; 20,
+                        'class'      =&gt; 'avatar',
+                        'link_class' =&gt; '',
+                        'linked'     =&gt; true,
+                        'email'      =&gt; false
</ins><span class="cx">                 );
</span><span class="cx"> 
</span><span class="cx">                 $r = wp_parse_args( $args, $defaults );
</span><span class="lines">@@ -1063,14 +1065,16 @@
</span><span class="cx">                         case 'groups' :
</span><span class="cx">                                 $object  = 'group';
</span><span class="cx">                                 $item_id = $activities_template-&gt;activity-&gt;item_id;
</span><ins>+                                $link    = bp_get_group_permalink( groups_get_group( array( 'group_id' =&gt; $item_id ) ) );
</ins><span class="cx"> 
</span><span class="cx">                                 if ( empty( $alt ) ) {
</span><span class="cx">                                         $alt = __( 'Group logo', 'buddypress' );
</span><span class="cx"> 
</span><span class="cx">                                         if ( bp_is_active( 'groups' ) ) {
</span><span class="cx">                                                 $group = groups_get_group( $item_id );
</span><del>-                                                if ( isset( $group-&gt;name ) )
</del><ins>+                                                if ( isset( $group-&gt;name ) ) {
</ins><span class="cx">                                                         $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $group-&gt;name );
</span><ins>+                                                }
</ins><span class="cx">                                         }
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1078,8 +1082,9 @@
</span><span class="cx">                         case 'blogs' :
</span><span class="cx">                                 $object  = 'blog';
</span><span class="cx">                                 $item_id = $activities_template-&gt;activity-&gt;item_id;
</span><ins>+                                $link    = home_url();
</ins><span class="cx"> 
</span><del>-                                if ( !$alt ) {
</del><ins>+                                if ( empty( $alt ) ) {
</ins><span class="cx">                                         $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="lines">@@ -1087,6 +1092,7 @@
</span><span class="cx">                         case 'friends' :
</span><span class="cx">                                 $object  = 'user';
</span><span class="cx">                                 $item_id = $activities_template-&gt;activity-&gt;secondary_item_id;
</span><ins>+                                $link    = bp_core_get_userlink( $item_id );
</ins><span class="cx"> 
</span><span class="cx">                                 if ( empty( $alt ) ) {
</span><span class="cx">                                         $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $activities_template-&gt;activity-&gt;secondary_item_id ) );
</span><span class="lines">@@ -1097,23 +1103,48 @@
</span><span class="cx">                                 $object  = 'user';
</span><span class="cx">                                 $item_id = $activities_template-&gt;activity-&gt;user_id;
</span><span class="cx">                                 $email   = $activities_template-&gt;activity-&gt;user_email;
</span><ins>+                                $link    = bp_core_get_userlink( $item_id );
</ins><span class="cx"> 
</span><del>-                                if ( !$alt ) {
</del><ins>+                                if ( empty( $alt ) ) {
</ins><span class="cx">                                         $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template-&gt;activity-&gt;display_name );
</span><span class="cx">                                 }
</span><span class="cx"> 
</span><span class="cx">                                 break;
</span><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                // Allow object and item_id to be filtered
</del><ins>+                // Allow object, item_id, and link to be filtered
</ins><span class="cx">                 $object  = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template-&gt;activity-&gt;component, $object );
</span><span class="cx">                 $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
</span><span class="cx"> 
</span><span class="cx">                 // If we have no item_id or object, there is no avatar to display
</span><del>-                if ( empty( $item_id ) || empty( $object ) )
</del><ins>+                if ( empty( $item_id ) || empty( $object ) ) {
</ins><span class="cx">                         return false;
</span><ins>+                }
</ins><span class="cx"> 
</span><del>-                return apply_filters( 'bp_get_activity_secondary_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, 'email' =&gt; $email ) ) );
</del><ins>+                // Get the avatar
+                $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,
+                        'email'   =&gt; $email
+                ) );
+
+                if ( !empty( $linked ) ) {
+                        $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template-&gt;activity-&gt;component );
+
+                        return sprintf( '&lt;a href=&quot;%s&quot; class=&quot;%s&quot;&gt;%s&lt;/a&gt;',
+                                $link,
+                                $link_class,
+                                apply_filters( 'bp_get_activity_secondary_avatar', $avatar )
+                        );
+                }
+
+                // else
+                return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkbptemplatesbplegacybuddypressfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-templates/bp-legacy/buddypress-functions.php (6606 => 6607)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-templates/bp-legacy/buddypress-functions.php        2012-12-10 14:04:33 UTC (rev 6606)
+++ trunk/bp-templates/bp-legacy/buddypress-functions.php        2012-12-10 14:25:26 UTC (rev 6607)
</span><span class="lines">@@ -87,6 +87,9 @@
</span><span class="cx">          */
</span><span class="cx">         private function setup_actions() {
</span><span class="cx"> 
</span><ins>+                // Template Output
+                add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 );
+
</ins><span class="cx">                 /** Scripts ***********************************************************/
</span><span class="cx"> 
</span><span class="cx">                 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles'   ) ); // Enqueue theme CSS
</span><span class="lines">@@ -292,6 +295,32 @@
</span><span class="cx">         public function localize_scripts() {
</span><span class="cx"> 
</span><span class="cx">         }
</span><ins>+        
+        /**
+         * Add secondary avatar image to this activity stream's record, if supported.
+         *
+         * @since BuddyPress (1.7)
+         *
+         * @param string $action The text of this activity
+         * @param BP_Activity_Activity $activity Activity object
+         * @package BuddyPress Theme
+         * @return string
+         */
+        function secondary_avatars( $action, $activity ) {
+                switch ( $activity-&gt;component ) {
+                        case 'groups' :
+                        case 'friends' :
+                                // Only insert avatar if one exists
+                                if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
+                                        $reverse_content = strrev( $action );
+                                        $position        = strpos( $reverse_content, 'a&lt;' );
+                                        $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
+                                }
+                                break;
+                }
+
+                return $action;
+        }
</ins><span class="cx"> }
</span><span class="cx"> new BP_Legacy();
</span><span class="cx"> endif;
</span></span></pre>
</div>
</div>

</body>
</html>