Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/20/2011 10:53:49 AM (14 years ago)
Author:
johnjamesjacoby
Message:

Second pass at huge component refactor.

Move component files out of root directory and append '-loader' to the file names. Split those files up into smaller pieces.

Abstract 'settings' component out of 'core' and into its own component for future extension, including new template files in bp-default.

Append '-sa' to bbPress bridge file for 'Stand Alone' compatibility, to make room for bbPress plugin compatibility layer.

Various bug fixes through-out all components. Various code clean-up and documentation through-out all components.

Still more refactoring to do.

File:
1 edited

Legend:

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

    r3742 r3757  
    11<?php
    2 /*
    3  Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
    4  Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
    5 */
     2/**
     3 * BuddyPress Avatars
     4 *
     5 * Based on contributions from: Beau Lebens - http://www.dentedreality.com.au/
     6 * Modified for BuddyPress by: Andy Peatling - http://apeatling.wordpress.com/
     7 */
    68
    79/***
     
    3436    if ( !defined( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE' ) ) {
    3537        if ( !isset( $bp->site_options['fileupload_maxk'] ) )
    36             define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); /* 5mb */
     38            define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', 5120000 ); // 5mb
    3739        else
    3840            define( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $bp->site_options['fileupload_maxk'] * 1024 );
     
    4547        define( 'BP_AVATAR_DEFAULT_THUMB', BP_PLUGIN_URL . '/bp-core/images/mystery-man-50.jpg' );
    4648}
    47 add_action( 'bp_init', 'bp_core_set_avatar_constants', 8 );
     49add_action( 'bp_init', 'bp_core_set_avatar_constants', 3 );
    4850
    4951/**
     
    164166     * or thumbnail image.
    165167     */
    166     $avatar_size = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
    167     $legacy_user_avatar_name = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
     168    $avatar_size              = ( 'full' == $type ) ? '-bpfull' : '-bpthumb';
     169    $legacy_user_avatar_name  = ( 'full' == $type ) ? '-avatar2' : '-avatar1';
    168170    $legacy_group_avatar_name = ( 'full' == $type ) ? '-groupavatar-full' : '-groupavatar-thumb';
    169171
     
    263265
    264266        // Filter gravatar vars
    265         $email      = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
    266         $gravatar   = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
     267        $email    = apply_filters( 'bp_core_gravatar_email', $email, $item_id, $object );
     268        $gravatar = apply_filters( 'bp_gravatar_url', $host ) . md5( strtolower( $email ) ) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    267269
    268270    } else {
     
    281283
    282284    $defaults = array(
    283         'item_id' => false,
    284         'object' => 'user', // user OR group OR blog OR custom type (if you use filters)
     285        'item_id'    => false,
     286        'object'     => 'user', // user OR group OR blog OR custom type (if you use filters)
    285287        'avatar_dir' => false
    286288    );
     
    372374    }
    373375
    374     /* Filter the upload location */
     376    // Filter the upload location
    375377    add_filter( 'upload_dir', $upload_dir_filter, 10, 0 );
    376378
    377379    $bp->avatar_admin->original = wp_handle_upload( $file['file'], array( 'action'=> 'bp_avatar_upload' ) );
    378380
    379     /* Move the file to the correct upload location. */
     381    // Move the file to the correct upload location.
    380382    if ( !empty( $bp->avatar_admin->original['error'] ) ) {
    381383        bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $bp->avatar_admin->original['error'] ), 'error' );
     
    383385    }
    384386
    385     /* Get image size */
     387    // Get image size
    386388    $size = @getimagesize( $bp->avatar_admin->original['file'] );
    387389
    388     /* Check image size and shrink if too large */
     390    // Check image size and shrink if too large
    389391    if ( $size[0] > BP_AVATAR_ORIGINAL_MAX_WIDTH ) {
    390392        $thumb = wp_create_thumbnail( $bp->avatar_admin->original['file'], BP_AVATAR_ORIGINAL_MAX_WIDTH );
    391393
    392         /* Check for thumbnail creation errors */
     394        // Check for thumbnail creation errors
    393395        if ( is_wp_error( $thumb ) ) {
    394396            bp_core_add_message( sprintf( __( 'Upload Failed! Error was: %s', 'buddypress' ), $thumb->get_error_message() ), 'error' );
     
    396398        }
    397399
    398         /* Thumbnail is good so proceed */
     400        // Thumbnail is good so proceed
    399401        $bp->avatar_admin->resized = $thumb;
    400402    }
    401403
    402     /* We only want to handle one image after resize. */
     404    // We only want to handle one image after resize.
    403405    if ( empty( $bp->avatar_admin->resized ) )
    404406        $bp->avatar_admin->image->dir = str_replace( BP_AVATAR_UPLOAD_PATH, '', $bp->avatar_admin->original['file'] );
     
    414416    }
    415417
    416     /* Set the url value for the image */
     418    // Set the url value for the image
    417419    $bp->avatar_admin->image->url = BP_AVATAR_URL . $bp->avatar_admin->image->dir;
    418420
     
    424426
    425427    $defaults = array(
    426         'object' => 'user',
    427         'avatar_dir' => 'avatars',
    428         'item_id' => false,
     428        'object'        => 'user',
     429        'avatar_dir'    => 'avatars',
     430        'item_id'       => false,
    429431        'original_file' => false,
    430         'crop_w' => BP_AVATAR_FULL_WIDTH,
    431         'crop_h' => BP_AVATAR_FULL_HEIGHT,
    432         'crop_x' => 0,
    433         'crop_y' => 0
     432        'crop_w'        => BP_AVATAR_FULL_WIDTH,
     433        'crop_h'        => BP_AVATAR_FULL_HEIGHT,
     434        'crop_x'        => 0,
     435        'crop_y'        => 0
    434436    );
    435437
     
    464466    require_once( ABSPATH . '/wp-admin/includes/file.php' );
    465467
    466     /* Delete the existing avatar files for the object */
     468    // Delete the existing avatar files for the object
    467469    bp_core_delete_existing_avatar( array( 'object' => $object, 'avatar_path' => $avatar_folder_dir ) );
    468470
    469     /* Make sure we at least have a width and height for cropping */
     471    // Make sure we at least have a width and height for cropping
    470472    if ( !(int)$crop_w )
    471473        $crop_w = BP_AVATAR_FULL_WIDTH;
     
    474476        $crop_h = BP_AVATAR_FULL_HEIGHT;
    475477
    476     /* Set the full and thumb filenames */
    477     $full_filename = wp_hash( $original_file . time() ) . '-bpfull.jpg';
     478    // Set the full and thumb filenames
     479    $full_filename  = wp_hash( $original_file . time() ) . '-bpfull.jpg';
    478480    $thumb_filename = wp_hash( $original_file . time() ) . '-bpthumb.jpg';
    479481
    480     /* Crop the image */
    481     $full_cropped = wp_crop_image( $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 );
     482    // Crop the image
     483    $full_cropped  = wp_crop_image( $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 );
    482484    $thumb_cropped = wp_crop_image( $original_file, (int)$crop_x, (int)$crop_y, (int)$crop_w, (int)$crop_h, BP_AVATAR_THUMB_WIDTH, BP_AVATAR_THUMB_HEIGHT, false, $avatar_folder_dir . '/' . $thumb_filename );
    483485
    484     /* Remove the original */
     486    // Remove the original
    485487    @unlink( $original_file );
    486488
Note: See TracChangeset for help on using the changeset viewer.