Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/01/2009 09:35:03 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Group avatar upload adjustments. Fix empty avatar src by checking for uploaded avatar first, and show gravatar (or no_grav) if no upload exists.

File:
1 edited

Legend:

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

    r2025 r2069  
    9393    $avatar_folder_url = apply_filters( 'bp_core_avatar_folder_url', get_blog_option( BP_ROOT_BLOG, 'siteurl' ) . '/' . basename( WP_CONTENT_DIR ) . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );
    9494    $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . '/blogs.dir/' . BP_ROOT_BLOG . '/files/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir );   
    95    
     95
     96    /****
     97     * Look for uploaded avatar first. Use it if it exists.
     98     * Set the file names to search for, to select the full size
     99     * or thumbnail image.
     100     */
     101    $avatar_name = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
     102    $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
     103    $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
     104
     105    if ( file_exists( $avatar_folder_dir ) ) {
     106        if ( $av_dir = opendir( $avatar_folder_dir ) ) {
     107            while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
     108                if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_group_avatar_name}/", $avatar_file ) )
     109                    $avatar_url = $avatar_folder_url . '/' . $avatar_file;
     110            }
     111        }
     112        closedir($av_dir);
     113
     114        if ( $avatar_url )
     115            return apply_filters( 'bp_core_fetch_avatar', "<img src='{$avatar_url}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
     116    }
     117
    96118    /* If no avatars have been uploaded for this item, display a gravatar */   
    97     if ( !file_exists( $avatar_folder_dir ) && !$no_grav ) {
     119    if ( !file_exists( $avatar_url ) && !$no_grav ) {
    98120       
    99121        if ( empty( $bp->grav_default->{$object} ) )
     
    120142        return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
    121143   
    122     } else if ( !file_exists( $avatar_folder_dir ) && $no_grav )
    123         return false;
    124    
    125     /* Set the file names to search for to select the full size or thumbnail image. */
    126     $avatar_name = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';   
    127     $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';   
    128     $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';   
    129    
    130     if ( $av_dir = opendir( $avatar_folder_dir ) ) {
    131         while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    132             if ( preg_match( "/{$avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_user_avatar_name}/", $avatar_file ) || preg_match( "/{$legacy_group_avatar_name}/", $avatar_file ) )
    133                 $avatar_url = $avatar_folder_url . '/' . $avatar_file;
    134         }
    135     }
    136     closedir($av_dir);
    137 
    138     return apply_filters( 'bp_core_fetch_avatar', "<img src='{$avatar_url}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
     144    } else if ( !file_exists( $avatar_url ) && $no_grav )
     145        return false;
     146   
    139147}
    140148
Note: See TracChangeset for help on using the changeset viewer.