Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/15/2015 07:13:42 PM (11 years ago)
Author:
tw2113
Message:

More documentation cleanup for part of BP-Core component.

See #6398.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-attachment-avatar.php

    r10206 r10355  
    2929     */
    3030    public function __construct() {
    31         // Allowed avatar types
     31        // Allowed avatar types.
    3232        $allowed_types = bp_core_get_allowed_avatar_types();
    3333
     
    3737            'original_max_filesize' => bp_core_avatar_original_max_filesize(),
    3838
    39             // Specific errors for avatars
     39            // Specific errors for avatars.
    4040            'upload_error_strings'  => array(
    4141                9  => sprintf( __( 'That photo is too big. Please upload one smaller than %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ),
     
    5151     *
    5252     * @param array $allowed_types Array of allowed avatar types.
    53      *
    5453     * @return string comma separated list of allowed avatar types.
    5554     */
     
    9291     *
    9392     * @param  array $file the temporary file attributes (before it has been moved).
    94      *
    9593     * @return array the file with extra errors if needed.
    9694     */
    9795    public function validate_upload( $file = array() ) {
    98         // Bail if already an error
     96        // Bail if already an error.
    9997        if ( ! empty( $file['error'] ) ) {
    10098            return $file;
    10199        }
    102100
    103         // File size is too big
     101        // File size is too big.
    104102        if ( ! bp_core_check_avatar_size( array( 'file' => $file ) ) ) {
    105103            $file['error'] = 9;
    106104
    107         // File is of invalid type
     105        // File is of invalid type.
    108106        } elseif ( ! bp_core_check_avatar_type( array( 'file' => $file ) ) ) {
    109107            $file['error'] = 10;
    110108        }
    111109
    112         // Return with error code attached
     110        // Return with error code attached.
    113111        return $file;
    114112    }
     
    122120     * @uses  bp_core_avatar_original_max_width()
    123121     *
    124      * @param string $file the absolute path to the file.
    125      *
     122     * @param string $file               The absolute path to the file.
     123     * @param int    $ui_available_width Available width for the UI.
    126124     * @return mixed
    127125     */
    128126    public static function shrink( $file = '', $ui_available_width = 0 ) {
    129         // Get image size
     127        // Get image size.
    130128        $avatar_data = parent::get_image_data( $file );
    131129
    132         // Init the edit args
     130        // Init the edit args.
    133131        $edit_args = array();
    134132
     
    136134        $original_max_width = bp_core_avatar_original_max_width();
    137135
    138         // The ui_available_width is defined and it's smaller than the Avatar original max width
     136        // The ui_available_width is defined and it's smaller than the Avatar original max width.
    139137        if ( ! empty( $ui_available_width ) && $ui_available_width < $original_max_width ) {
    140138            /**
     
    150148        }
    151149
    152         // Do we need to resize the image ?
     150        // Do we need to resize the image?
    153151        if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > $original_max_width ) {
    154152            $edit_args = array(
     
    158156        }
    159157
    160         // Do we need to rotate the image ?
     158        // Do we need to rotate the image?
    161159        $angles = array(
    162160            3 => 180,
     
    169167        }
    170168
    171         // No need to edit the avatar, original file will be used
     169        // No need to edit the avatar, original file will be used.
    172170        if ( empty( $edit_args ) ) {
    173171            return false;
    174172
    175         // Add the file to the edit arguments
     173        // Add the file to the edit arguments.
    176174        } else {
    177175            $edit_args['file'] = $file;
     
    190188     *
    191189     * @param string $file the absolute path to the file.
    192      *
    193      * @return boolean
     190     * @return bool
    194191     */
    195192    public static function is_too_small( $file = '' ) {
     
    218215     * @uses BP_Attachment::crop
    219216     *
    220      * @param array $args
    221      *
     217     * @param array $args Array of arguments for the cropping.
    222218     * @return array The cropped avatars (full and thumb).
    223219     */
    224220    public function crop( $args = array() ) {
    225         // Bail if the original file is missing
     221        // Bail if the original file is missing.
    226222        if ( empty( $args['original_file'] ) ) {
    227223            return false;
     
    235231        $absolute_path = $this->upload_path . $relative_path;
    236232
    237         // Bail if the avatar is not available
     233        // Bail if the avatar is not available.
    238234        if ( ! file_exists( $absolute_path ) )  {
    239235            return false;
     
    250246        }
    251247
    252         // Bail if the avatar folder is missing for this item_id
     248        // Bail if the avatar folder is missing for this item_id.
    253249        if ( ! file_exists( $avatar_folder_dir ) ) {
    254250            return false;
    255251        }
    256252
    257         // Delete the existing avatar files for the object
     253        // Delete the existing avatar files for the object.
    258254        $existing_avatar = bp_core_fetch_avatar( array(
    259255            'object'  => $args['object'],
     
    270266        }
    271267
    272         // Make sure we at least have minimal data for cropping
     268        // Make sure we at least have minimal data for cropping.
    273269        if ( empty( $args['crop_w'] ) ) {
    274270            $args['crop_w'] = bp_core_avatar_full_width();
     
    279275        }
    280276
    281         // Get the file extension
     277        // Get the file extension.
    282278        $data = @getimagesize( $absolute_path );
    283279        $ext  = $data['mime'] == 'image/png' ? 'png' : 'jpg';
     
    301297        }
    302298
    303         // Remove the original
     299        // Remove the original.
    304300        @unlink( $absolute_path );
    305301
    306         // Return the full and thumb cropped avatars
     302        // Return the full and thumb cropped avatars.
    307303        return $avatar_types;
    308304    }
     
    355351     */
    356352    public function script_data() {
    357         // Get default script data
     353        // Get default script data.
    358354        $script_data = parent::script_data();
    359355
    360         // Defaults to Avatar Backbone script
     356        // Defaults to Avatar Backbone script.
    361357        $js_scripts = array( 'bp-avatar' );
    362358
    363         // Default object
     359        // Default object.
    364360        $object = '';
    365361
    366         // Get the possible item ids
     362        // Get the possible item ids.
    367363        $user_id  = $this->get_user_id();
    368364        $group_id = $this->get_group_id();
    369365
    370366        if ( ! empty( $user_id ) ) {
    371             // Should we load the the Webcam Avatar javascript file
     367            // Should we load the the Webcam Avatar javascript file.
    372368            if ( bp_avatar_use_webcam() ) {
    373369                $js_scripts = array( 'bp-webcam' );
     
    384380            );
    385381
    386             // Set feedback messages
     382            // Set feedback messages.
    387383            $script_data['feedback_messages'] = array(
    388384                1 => __( 'There was a problem cropping your profile photo.', 'buddypress' ),
     
    402398            );
    403399
    404             // Set feedback messages
     400            // Set feedback messages.
    405401            $script_data['feedback_messages'] = array(
    406402                1 => __( 'There was a problem cropping the group profile photo.', 'buddypress' ),
     
    422418        }
    423419
    424         // Include the specific css
     420        // Include the specific css.
    425421        $script_data['extra_css'] = array( 'bp-avatar' );
    426422
    427         // Include the specific css
     423        // Include the specific css.
    428424        $script_data['extra_js']  = $js_scripts;
    429425
    430         // Set the object to contextualize the filter
     426        // Set the object to contextualize the filter.
    431427        if ( isset( $script_data['bp_params']['object'] ) ) {
    432428            $object = $script_data['bp_params']['object'];
Note: See TracChangeset for help on using the changeset viewer.