Skip to:
Content

BuddyPress.org

Ticket #7265: 7265.02.patch

File 7265.02.patch, 4.8 KB (added by imath, 7 years ago)
  • src/bp-core/bp-core-attachments.php

    diff --git src/bp-core/bp-core-attachments.php src/bp-core/bp-core-attachments.php
    index 78bb6cfef..b4ec1b18e 100644
    function bp_attachments_uploads_dir_get( $data = '' ) { 
    8383        return apply_filters( 'bp_attachments_uploads_dir_get', $retval, $data );
    8484}
    8585
     86/**
     87 * Gets the upload dir array for cover images.
     88 *
     89 * @since 3.0.0
     90 *
     91 * @param  array $args Array containing the cover image path, URL, and other helpful settings.
     92 * @return array See wp_upload_dir().
     93 */
     94function bp_attachments_cover_image_upload_dir( $args = array() ) {
     95        // Default values are for profiles.
     96        $object_id = bp_displayed_user_id();
     97
     98        if ( empty( $object_id ) ) {
     99                $object_id = bp_loggedin_user_id();
     100        }
     101
     102        $object_directory = 'members';
     103
     104        // We're in a group, edit default values.
     105        if ( bp_is_group() || bp_is_group_create() ) {
     106                $object_id        = bp_get_current_group_id();
     107                $object_directory = 'groups';
     108        }
     109
     110        //
     111        $r = bp_parse_args( $args, array_merge( array(
     112                'object_id' => $object_id,
     113                'object_directory' => $object_directory,
     114        ), bp_upload_dir() ), 'cover_image_upload_dir' );
     115
     116
     117        // Set the subdir.
     118        $subdir  = '/' . $r['object_directory'] . '/' . $r['object_id'] . '/cover-image';
     119
     120        /**
     121         * Filters the cover image upload directory.
     122         *
     123         * @since 2.4.0
     124         *
     125         * @param array $value Array containing the path, URL, and other helpful settings.
     126         * @param array $args  The original Uploads dir.
     127         */
     128        return apply_filters( 'bp_attachments_cover_image_upload_dir', array(
     129                'path'    => $r['basedir'] . $subdir,
     130                'url'     => set_url_scheme( $r['baseurl'] ) . $subdir,
     131                'subdir'  => $subdir,
     132                'basedir' => $r['basedir'],
     133                'baseurl' => set_url_scheme( $r['baseurl'] ),
     134                'error'   => false
     135        ), $args );
     136}
     137
    86138/**
    87139 * Get the max upload file size for any attachment.
    88140 *
    function bp_attachments_create_item_type( $type = 'avatar', $args = array() ) { 
    312364                        $attachment_data = call_user_func_array( $r['component'] . '_avatar_upload_dir', $dir_args );
    313365                }
    314366        } elseif ( 'cover_image' === $type ) {
    315                 $attachment_data = bp_attachments_uploads_dir_get();
     367                $cover_image_class = new BP_Attachment_Cover_Image();
     368                $attachment_data   = $cover_image_class->upload_dir_filter();
    316369
    317370                // The BP Attachments Uploads Dir is not set, stop.
    318371                if ( ! $attachment_data ) {
    function bp_attachments_cover_image_generate_file( $args = array(), $cover_image 
    11301183                $cover_image_class = new BP_Attachment_Cover_Image();
    11311184        }
    11321185
     1186        $upload_dir = $cover_image_class->upload_dir_filter();
     1187
    11331188        // Make sure the file is inside the Cover Image Upload path.
    1134         if ( false === strpos( $args['file'], $cover_image_class->upload_path ) ) {
     1189        if ( false === strpos( $args['file'], $upload_dir['basedir'] ) ) {
    11351190                return false;
    11361191        }
    11371192
    function bp_attachments_cover_image_ajax_upload() { 
    12901345
    12911346        $error_message = __( 'There was a problem uploading the cover image.', 'buddypress' );
    12921347
    1293         $bp_attachments_uploads_dir = bp_attachments_uploads_dir_get();
     1348        $bp_attachments_uploads_dir = $cover_image_attachment->upload_dir_filter();
    12941349
    12951350        // The BP Attachments Uploads Dir is not set, stop.
    12961351        if ( ! $bp_attachments_uploads_dir ) {
  • src/bp-core/classes/class-bp-attachment-cover-image.php

    diff --git src/bp-core/classes/class-bp-attachment-cover-image.php src/bp-core/classes/class-bp-attachment-cover-image.php
    index 8c6c60b10..3ad0d8b88 100644
    class BP_Attachment_Cover_Image extends BP_Attachment { 
    9696         * @return array $value Upload data (path, url, basedir...).
    9797         */
    9898        public function upload_dir_filter( $upload_dir = array() ) {
    99                 // Default values are for profiles.
    100                 $object_id = bp_displayed_user_id();
    101 
    102                 if ( empty( $object_id ) ) {
    103                         $object_id = bp_loggedin_user_id();
    104                 }
    105 
    106                 $object_directory = 'members';
    107 
    108                 // We're in a group, edit default values.
    109                 if ( bp_is_group() || bp_is_group_create() ) {
    110                         $object_id        = bp_get_current_group_id();
    111                         $object_directory = 'groups';
    112                 }
    113 
    114                 // Set the subdir.
    115                 $subdir  = '/' . $object_directory . '/' . $object_id . '/cover-image';
    116 
    117                 /**
    118                  * Filters the cover image upload directory.
    119                  *
    120                  * @since 2.4.0
    121                  *
    122                  * @param array $value      Array containing the path, URL, and other helpful settings.
    123                  * @param array $upload_dir The original Uploads dir.
    124                  */
    125                 return apply_filters( 'bp_attachments_cover_image_upload_dir', array(
    126                         'path'    => $this->upload_path . $subdir,
    127                         'url'     => $this->url . $subdir,
    128                         'subdir'  => $subdir,
    129                         'basedir' => $this->upload_path,
    130                         'baseurl' => $this->url,
    131                         'error'   => false
    132                 ), $upload_dir );
     99                return bp_attachments_cover_image_upload_dir( parent::upload_dir_filter() );
    133100        }
    134101
    135102        /**