Skip to:
Content

BuddyPress.org

Changeset 6607


Ignore:
Timestamp:
12/10/2012 02:25:26 PM (14 years ago)
Author:
johnjamesjacoby
Message:

Add ability to link secondary avatars in activity streams. Props jag1989. Fixes #4436.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-template.php

    r6524 r6607  
    10491049
    10501050                $defaults = array(
    1051                         'type'   => 'thumb',
    1052                         'width'  => 20,
    1053                         'height' => 20,
    1054                         'class'  => 'avatar',
    1055                         'email'  => false
     1051                        'type'       => 'thumb',
     1052                        'width'      => 20,
     1053                        'height'     => 20,
     1054                        'class'      => 'avatar',
     1055                        'link_class' => '',
     1056                        'linked'     => true,
     1057                        'email'      => false
    10561058                );
    10571059
     
    10641066                                $object  = 'group';
    10651067                                $item_id = $activities_template->activity->item_id;
     1068                                $link    = bp_get_group_permalink( groups_get_group( array( 'group_id' => $item_id ) ) );
    10661069
    10671070                                if ( empty( $alt ) ) {
     
    10701073                                        if ( bp_is_active( 'groups' ) ) {
    10711074                                                $group = groups_get_group( $item_id );
    1072                                                 if ( isset( $group->name ) )
     1075                                                if ( isset( $group->name ) ) {
    10731076                                                        $alt = sprintf( __( 'Group logo of %s', 'buddypress' ), $group->name );
     1077                                                }
    10741078                                        }
    10751079                                }
     
    10791083                                $object  = 'blog';
    10801084                                $item_id = $activities_template->activity->item_id;
    1081 
    1082                                 if ( !$alt ) {
     1085                                $link    = home_url();
     1086
     1087                                if ( empty( $alt ) ) {
    10831088                                        $alt = sprintf( __( 'Profile picture of the author of the site %s', 'buddypress' ), get_blog_option( $item_id, 'blogname' ) );
    10841089                                }
     
    10881093                                $object  = 'user';
    10891094                                $item_id = $activities_template->activity->secondary_item_id;
     1095                                $link    = bp_core_get_userlink( $item_id );
    10901096
    10911097                                if ( empty( $alt ) ) {
     
    10981104                                $item_id = $activities_template->activity->user_id;
    10991105                                $email   = $activities_template->activity->user_email;
    1100 
    1101                                 if ( !$alt ) {
     1106                                $link    = bp_core_get_userlink( $item_id );
     1107
     1108                                if ( empty( $alt ) ) {
    11021109                                        $alt = sprintf( __( 'Profile picture of %s', 'buddypress' ), $activities_template->activity->display_name );
    11031110                                }
     
    11061113                }
    11071114
    1108                 // Allow object and item_id to be filtered
     1115                // Allow object, item_id, and link to be filtered
    11091116                $object  = apply_filters( 'bp_get_activity_secondary_avatar_object_' . $activities_template->activity->component, $object );
    11101117                $item_id = apply_filters( 'bp_get_activity_secondary_avatar_item_id', $item_id );
    11111118
    11121119                // If we have no item_id or object, there is no avatar to display
    1113                 if ( empty( $item_id ) || empty( $object ) )
     1120                if ( empty( $item_id ) || empty( $object ) ) {
    11141121                        return false;
    1115 
    1116                 return apply_filters( 'bp_get_activity_secondary_avatar', bp_core_fetch_avatar( array( 'item_id' => $item_id, 'object' => $object, 'type' => $type, 'alt' => $alt, 'class' => $class, 'width' => $width, 'height' => $height, 'email' => $email ) ) );
     1122                }
     1123
     1124                // Get the avatar
     1125                $avatar = bp_core_fetch_avatar( array(
     1126                        'item_id' => $item_id,
     1127                        'object'  => $object,
     1128                        'type'    => $type,
     1129                        'alt'     => $alt,
     1130                        'class'   => $class,
     1131                        'width'   => $width,
     1132                        'height'  => $height,
     1133                        'email'   => $email
     1134                ) );
     1135
     1136                if ( !empty( $linked ) ) {
     1137                        $link = apply_filters( 'bp_get_activity_secondary_avatar_link', $link, $activities_template->activity->component );
     1138
     1139                        return sprintf( '<a href="%s" class="%s">%s</a>',
     1140                                $link,
     1141                                $link_class,
     1142                                apply_filters( 'bp_get_activity_secondary_avatar', $avatar )
     1143                        );
     1144                }
     1145
     1146                // else
     1147                return apply_filters( 'bp_get_activity_secondary_avatar', $avatar );
    11171148        }
    11181149
  • trunk/bp-templates/bp-legacy/buddypress-functions.php

    r6605 r6607  
    8787         */
    8888        private function setup_actions() {
     89
     90                // Template Output
     91                add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 );
    8992
    9093                /** Scripts ***********************************************************/
     
    292295        public function localize_scripts() {
    293296
     297        }
     298       
     299        /**
     300         * Add secondary avatar image to this activity stream's record, if supported.
     301         *
     302         * @since BuddyPress (1.7)
     303         *
     304         * @param string $action The text of this activity
     305         * @param BP_Activity_Activity $activity Activity object
     306         * @package BuddyPress Theme
     307         * @return string
     308         */
     309        function secondary_avatars( $action, $activity ) {
     310                switch ( $activity->component ) {
     311                        case 'groups' :
     312                        case 'friends' :
     313                                // Only insert avatar if one exists
     314                                if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
     315                                        $reverse_content = strrev( $action );
     316                                        $position        = strpos( $reverse_content, 'a<' );
     317                                        $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
     318                                }
     319                                break;
     320                }
     321
     322                return $action;
    294323        }
    295324}
Note: See TracChangeset for help on using the changeset viewer.