Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/02/2009 07:54:21 PM (17 years ago)
Author:
apeatling
Message:

Merging 1.1 branch changes and syncing.

File:
1 edited

Legend:

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

    r2069 r2077  
    3232if ( !defined( 'BP_AVATAR_DEFAULT_THUMB' ) )
    3333        define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-xprofile/images/none-thumbnail.gif' );
    34        
     34
    3535function bp_core_fetch_avatar( $args = '' ) {
    3636        global $bp, $current_blog;
    37        
     37
    3838        $defaults = array(
    3939                'item_id' => false,
    … …  
    4141                'type' => 'thumb',
    4242                'avatar_dir' => false,
    43                 'width' => false, 
     43                'width' => false,
    4444                'height' => false,
    4545                'class' => 'avatar',
    … …  
    5050
    5151        $params = wp_parse_args( $args, $defaults );
    52         extract( $params, EXTR_SKIP ); 
     52        extract( $params, EXTR_SKIP );
    5353
    5454        if ( !$item_id ) {
    … …  
    5959                else if ( 'blog' == $object )
    6060                        $item_id = $current_blog->id;
    61                        
     61
    6262                $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
    63        
     63
    6464                if ( !$item_id ) return false;
    6565        }
    66                
     66
    6767        if ( !$avatar_dir ) {
    6868                if ( 'user' == $object )
    … …  
    7272                else if ( 'blog' == $object )
    7373                        $avatar_dir = 'blog-avatars';
    74                        
     74
    7575                $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
    76                
    77                 if ( !$avatar_dir ) return false;               
    78         }
    79        
     76
     77                if ( !$avatar_dir ) return false;
     78        }
     79
    8080        if ( !$css_id )
    81                 $css_id = $object . '-' . $item_id . '-avatar'; 
    82        
     81                $css_id = $object . '-' . $item_id . '-avatar';
     82
    8383        if ( $width )
    8484                $html_width = " width='{$width}'";
    8585        else
    8686                $html_width = ( 'thumb' == $type ) ? ' width="' . BP_AVATAR_THUMB_WIDTH . '"' : ' width="' . BP_AVATAR_FULL_WIDTH . '"';
    87                
     87
    8888        if ( $height )
    8989                $html_height = " height='{$height}'";
    9090        else
    9191                $html_height = ( 'thumb' == $type ) ? ' height="' . BP_AVATAR_THUMB_HEIGHT . '"' : ' height="' . BP_AVATAR_FULL_HEIGHT . '"';
    92        
    93         $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 );     
    94         $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 );   
     92
     93        $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 );
     94        $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 );
    9595
    9696        /****
    … …  
    116116        }
    117117
    118         /* If no avatars have been uploaded for this item, display a gravatar */       
     118        /* If no avatars have been uploaded for this item, display a gravatar */
    119119        if ( !file_exists( $avatar_url ) && !$no_grav ) {
    120                
    121120                if ( empty( $bp->grav_default->{$object} ) )
    122121                        $default_grav = 'wavatar';
    … …  
    129128                else if ( 'full' == $type ) $grav_size = BP_AVATAR_FULL_WIDTH;
    130129                else if ( 'thumb' == $type ) $grav_size = BP_AVATAR_THUMB_WIDTH;
    131                
     130
    132131                if ( 'user' == $object ) {
    133132                        $ud = get_userdata( $item_id );
    … …  
    136135                        $grav_email = "{$item_id}-{$object}@{$bp->root_domain}";
    137136                }
    138        
    139                 $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );       
     137
     138                $grav_email = apply_filters( 'bp_core_gravatar_email', $grav_email, $item_id, $object );
    140139                $gravatar = apply_filters( 'bp_gravatar_url', 'http://www.gravatar.com/avatar/' ) . md5( $grav_email ) . '?d=' . $default_grav . '&s=' . $grav_size;
    141                
     140
    142141                return apply_filters( 'bp_core_fetch_avatar', "<img src='{$gravatar}' alt='{$alt}' id='{$css_id}' class='{$class}'{$html_width}{$html_height} />", $params );
    143        
    144142        } else if ( !file_exists( $avatar_url ) && $no_grav )
    145143                return false;
    146        
    147144}
    148145
    149146function bp_core_delete_existing_avatar( $args = '' ) {
    150147        global $bp;
    151        
     148
    152149        $defaults = array(
    153150                'item_id' => false,
    … …  
    157154
    158155        $args = wp_parse_args( $args, $defaults );
    159         extract( $args, EXTR_SKIP );   
    160        
     156        extract( $args, EXTR_SKIP );
     157
    161158        if ( !$item_id ) {
    162159                if ( 'user' == $object )
    … …  
    166163                else if ( 'blog' == $object )
    167164                        $item_id = $current_blog->id;
    168                        
     165
    169166                $item_id = apply_filters( 'bp_core_avatar_item_id', $item_id, $object );
    170        
     167
    171168                if ( !$item_id ) return false;
    172169        }
    173                
     170
    174171        if ( !$avatar_dir ) {
    175172                if ( 'user' == $object )
    … …  
    179176                else if ( 'blog' == $object )
    180177                        $avatar_dir = 'blog-avatars';
    181                        
     178
    182179                $avatar_dir = apply_filters( 'bp_core_avatar_dir', $avatar_dir, $object );
    183                
    184                 if ( !$avatar_dir ) return false;               
     180
     181                if ( !$avatar_dir ) return false;
    185182        }
    186183
    … …  
    193190        }
    194191
    195         $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 );   
     192        $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 );
    196193
    197194        if ( !file_exists( $avatar_folder_dir ) )
    … …  
    201198            while ( false !== ( $avatar_file = readdir($av_dir) ) ) {
    202199                        if ( ( preg_match( "/-bpfull/", $avatar_file ) || preg_match( "/-bpthumb/", $avatar_file ) ) && '.' != $avatar_file && '..' != $avatar_file )
    203                                 @unlink( $avatar_folder_dir . '/' . $avatar_file );                             
     200                                @unlink( $avatar_folder_dir . '/' . $avatar_file );
    204201                }
    205202        }
    … …  
    215212function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
    216213        global $bp;
    217        
     214
    218215        require_once( ABSPATH . '/wp-admin/includes/image.php' );
    219216        require_once( ABSPATH . '/wp-admin/includes/file.php' );
    220        
     217
    221218        $uploadErrors = array(
    222         0 => __("There is no error, the file uploaded with success", 'buddypress'), 
    223         1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE), 
     219        0 => __("There is no error, the file uploaded with success", 'buddypress'),
     220        1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
    224221        2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE),
    225222        3 => __("The uploaded file was only partially uploaded", 'buddypress'),
    … …  
    232229                return false;
    233230        }
    234        
     231
    235232        if ( !bp_core_check_avatar_size( $file ) ) {
    236233                bp_core_add_message( sprintf( __( 'The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(BP_AVATAR_ORIGINAL_MAX_FILESIZE) ), 'error' );
    237234                return false;
    238235        }
    239        
     236
    240237        if ( !bp_core_check_avatar_type( $file ) ) {
    241238                bp_core_add_message( __( 'Please upload only JPG, GIF or PNG photos.', 'buddypress' ), 'error' );
    242239                return false;
    243240        }
    244        
     241
    245242        // Filter the upload location
    246243        add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
    247        
     244
    248245        $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
    249246
    … …  
    253250                return false;
    254251        }
    255                
     252
    256253        // Resize the image down to something manageable and then delete the original
    257254        if ( getimagesize( $bp->avatar_admin->original['file'] ) > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
    258255                $bp->avatar_admin->resized = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
    259256        }
    260        
     257
    261258        $bp->avatar_admin->image = new stdClass;
    262        
    263         // We only want to handle one image after resize. 
     259
     260        // We only want to handle one image after resize.
    264261        if ( empty( $bp->avatar_admin->resized ) )
    265262                $bp->avatar_admin->image->dir = $bp->avatar_admin->original['file'];
    … …  
    268265                @unlink( $bp->avatar_admin->original['file'] );
    269266        }
    270        
     267
    271268        /* Set the url value for the image */
    272269        $bp->avatar_admin->image->url = str_replace( WP_CONTENT_DIR, WP_CONTENT_URL, $bp->avatar_admin->image->dir );
    … …  
    277274function bp_core_avatar_handle_crop( $args = '' ) {
    278275        global $bp;
    279        
     276
    280277        $defaults = array(
    281278                'object' => 'user',
    … …  
    297294        if ( !file_exists( WP_CONTENT_DIR . '/' . $original_file ) )
    298295                return false;
    299                        
     296
    300297        if ( !$item_id )
    301                 $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir ); 
     298                $avatar_folder_dir = apply_filters( 'bp_core_avatar_folder_dir', WP_CONTENT_DIR . dirname( $original_file ), $item_id, $object, $avatar_dir );
    302299        else
    303300                $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 );
    … …  
    305302        if ( !file_exists( $avatar_folder_dir ) )
    306303                return false;
    307        
     304
    308305        require_once( ABSPATH . '/wp-admin/includes/image.php' );
    309306        require_once( ABSPATH . '/wp-admin/includes/file.php' );
    … …  
    311308        /* Delete the existing avatar files for the object */
    312309        bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
    313        
     310
    314311        /* Make sure we at least have a width and height for cropping */
    315312        if ( !(int)$crop_w )
    316313                $crop_w = BP_AVATAR_FULL_WIDTH;
    317        
     314
    318315        if ( !(int)$crop_h )
    319316                $crop_h = BP_AVATAR_FULL_HEIGHT;
    … …  
    322319        $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
    323320        $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
    324                        
     321
    325322        /* Crop the image */
    326323        $full_cropped = wp_crop_image( WP_CONTENT_DIR . $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_FULL_WIDTH, BP_AVATAR_FULL_HEIGHT, false, $avatar_folder_dir . '/' . $full_filename );
    … …  
    337334        if ( is_object ( $id_or_email ) )
    338335                $id_or_email = $id_or_email->user_id;
    339        
     336
    340337        $bp_avatar = bp_core_fetch_avatar( array( 'no_grav' => true, 'item_id' => $id_or_email, 'width' => $size, 'height' => $size, 'alt' => $alt ) );
    341338
    … …  
    347344        if ( $file['error'] )
    348345                return false;
    349        
     346
    350347        return true;
    351348}
    … …  
    354351        if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
    355352                return false;
    356        
     353
    357354        return true;
    358355}
    … …  
    361358        if ( ( strlen($file['file']['type']) && !preg_match('/(jpe?g|gif|png)$/', $file['file']['type'] ) ) && !preg_match( '/(jpe?g|gif|png)$/', $file['file']['name'] ) )
    362359                return false;
    363        
     360
    364361        return true;
    365362}
Note: See TracChangeset for help on using the changeset viewer.