Skip to:
Content

BuddyPress.org

Changeset 6601


Ignore:
Timestamp:
12/10/2012 01:00:26 PM (12 years ago)
Author:
johnjamesjacoby
Message:

Clean up bp_core_fetch_avatar(). Props jkudish. Fixes #4503.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-avatars.php

    r6600 r6601  
    110110
    111111    // Set the default variables array
    112     $defaults = array(
     112    $params = wp_parse_args( $args, array(
    113113        'item_id'    => false,
    114114        'object'     => $def_object, // user/group/blog/custom type (if you use filters)
     
    124124        'html'       => true,        // Wrap the return img URL in <img />
    125125        'title'      => ''           // Custom <img> title (string)
    126     );
    127 
    128     // Compare defaults to passed and extract
    129     $params = wp_parse_args( $args, $defaults );
     126    ) );
    130127    extract( $params, EXTR_SKIP );
    131128
     
    200197    if ( false !== strpos( $alt, '%s' ) || false !== strpos( $alt, '%1$s' ) ) {
    201198
    202         // Get item name for alt/title tags
    203         $item_name = '';
    204 
    205199        switch ( $object ) {
    206200
     
    229223        $alt = __( 'Avatar Image', 'buddypress' );
    230224
     225    $html_alt = ' alt="' . esc_attr( $alt ) . '"';
     226
    231227    // Set title tag, if it's been provided
    232     if ( !empty( $title ) )
     228    if ( !empty( $title ) ) {
    233229        $title = " title='" . esc_attr( apply_filters( 'bp_core_avatar_title', $title, $item_id, $object, $params ) ) . "'";
     230    }
    234231
    235232    // Set CSS ID if passed
    236     if ( !empty( $css_id ) )
    237         $css_id = ' id="' . $css_id . '"';
     233    if ( !empty( $css_id ) ) {
     234        $css_id = ' id="' . esc_attr( $css_id ) . '"';
     235    }
    238236
    239237    // Set image width
    240     if ( false !== $width )
     238    if ( false !== $width ) {
    241239        $html_width = ' width="' . $width . '"';
    242     else
    243         $html_width = ( 'thumb' == $type ) ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
     240    } elseif ( 'thumb' == $type ) {
     241        $html_width = ' width="' . bp_core_avatar_thumb_width() . '"';
     242    } else {
     243        $html_width = ' width="' . bp_core_avatar_full_width() . '"';
     244    }
    244245
    245246    // Set image height
    246     if ( false !== $height )
     247    if ( false !== $height ) {
    247248        $html_height = ' height="' . $height . '"';
    248     else
    249         $html_height = ( 'thumb' == $type ) ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
     249    } elseif ( 'thumb' == $type ) {
     250        $html_height = ' height="' . bp_core_avatar_thumb_height() . '"';
     251    } else {
     252        $html_height = ' height="' . bp_core_avatar_full_height() . '"';
     253    }
    250254
    251255    // Set img URL and DIR based on prepopulated constants
     
    259263
    260264    // Add an identifying class
    261     $class .= ' ' . $object . '-' . $item_id . '-avatar';
    262 
    263     /****
     265    $class .= ' ' . $object . '-' . $item_id . '-avatar ' . sanitize_html_class( "avatar-$width" ) . ' photo';
     266
     267    /**
    264268     * Look for uploaded avatar first. Use it if it exists.
    265269     * Set the file names to search for, to select the full size
     
    323327            // Return it wrapped in an <img> element
    324328            if ( true === $html ) {
    325                 return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    326 
     329                return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $avatar_url . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $html_alt . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     330 
    327331            // ...or only the URL
    328332            } else {
     
    365369
    366370        // Set host based on if using ssl
    367         $host = 'http://www.gravatar.com/avatar/';
     371        $host = 'http://gravatar.com/avatar/';
    368372        if ( is_ssl() ) {
    369373            $host = 'https://secure.gravatar.com/avatar/';
     
    376380        // Gravatar rating; http://bit.ly/89QxZA
    377381        $rating = get_option( 'avatar_rating' );
    378         if ( ! empty( $rating ) )
     382        if ( ! empty( $rating ) ) {
    379383            $gravatar .= "&amp;r={$rating}";
     384        }
    380385
    381386    // No avatar was found, and we've been told not to use a gravatar.
     
    384389    }
    385390
    386     if ( true === $html )
    387         return apply_filters( 'bp_core_fetch_avatar', '<img src="' . esc_attr( $gravatar ) . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
    388     else
     391    if ( true === $html ) {
     392        return apply_filters( 'bp_core_fetch_avatar', '<img src="' . $gravatar . '" class="' . esc_attr( $class ) . '"' . $css_id . $html_width . $html_height . $html_alt . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir );
     393    } else {
    389394        return apply_filters( 'bp_core_fetch_avatar_url', $gravatar );
     395    }
    390396}
    391397
Note: See TracChangeset for help on using the changeset viewer.