Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/02/2024 07:14:55 PM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part IX: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883], [13886], [13887], [13888], [13891], [13892], [13893] and [13900]

See #9164 and #7228

File:
1 edited

Legend:

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

    r13718 r13901  
    5353         *
    5454         * @param array|string $args {
     55         *     Array of upload parameters.
     56         *
    5557         *     @type int    $original_max_filesize  Maximum file size in kilobytes. Defaults to php.ini settings.
    5658         *     @type array  $allowed_mime_types     List of allowed file extensions (eg: array( 'jpg', 'gif', 'png' ) ).
     
    6971                // Upload action and the file input name are required parameters.
    7072                if ( empty( $args['action'] ) || empty( $args['file_input'] ) ) {
    71                         return false;
     73                        return;
    7274                }
    7375
     
    9294                                $this->{$key} = $this->set_upload_error_strings( $param );
    9395
    94                         // Sanitize the base dir.
     96                                // Sanitize the base dir.
    9597                        } elseif ( 'base_dir' === $key ) {
    9698                                $this->{$key} = sanitize_title( $param );
    9799
    98                         // Sanitize the upload dir filter arg to pass.
     100                                // Sanitize the upload dir filter arg to pass.
    99101                        } elseif ( 'upload_dir_filter_args' === $key ) {
    100102                                $this->{$key} = (int) $param;
    101103
    102                         // Action & File input are already set and sanitized.
     104                                // Action & File input are already set and sanitized.
    103105                        } elseif ( 'action' !== $key && 'file_input' !== $key ) {
    104106                                $this->{$key} = $param;
     
    114116         *
    115117         * @since 2.3.0
    116          *
    117118         */
    118119        public function set_upload_dir() {
    119120                // Set the directory, path, & url variables.
    120                 $this->upload_dir  = bp_upload_dir();
     121                $this->upload_dir = bp_upload_dir();
    121122
    122123                if ( empty( $this->upload_dir ) ) {
    123                         return false;
     124                        return;
    124125                }
    125126
     
    139140                if ( ! empty( $this->base_dir ) ) {
    140141                        $this->upload_path = trailingslashit( $this->upload_path ) . $this->base_dir;
    141                         $this->url         = trailingslashit( $this->url  ) . $this->base_dir;
     142                        $this->url         = trailingslashit( $this->url ) . $this->base_dir;
    142143
    143144                        // Finally create the base dir.
     
    195196                        }
    196197
    197                         require_once( ABSPATH . "/wp-admin/includes/{$wp_file}.php" );
     198                        require_once ABSPATH . "/wp-admin/includes/{$wp_file}.php";
    198199                }
    199200        }
     
    207208         * @param string      $upload_dir_filter A specific filter to be applied to 'upload_dir' (optional).
    208209         * @param string|null $time              Optional. Time formatted in 'yyyy/mm'. Default null.
    209          * @return array On success, returns an associative array of file attributes.
     210         * @return false|array On success, returns an associative array of file attributes.
    210211         *               On failure, returns an array containing the error message
    211212         *               (eg: array( 'error' => $message ) )
     
    257258                 * and no specific filter has been requested, use a default
    258259                 * filter to create the specific $base dir
     260                 *
    259261                 * @see  BP_Attachment->upload_dir_filter()
    260262                 */
     
    290292         * @since 2.9.0
    291293         *
    292          * @param  string $retval Filename.
     294         * @param string $retval Filename.
    293295         * @return string
    294296         */
    295297        public function sanitize_utf8_filename( $retval ) {
    296                 // PHP 5.4+ or with PECL intl 2.0+
     298                // PHP 5.4+ or with PECL intl 2.0+ .
    297299                if ( function_exists( 'transliterator_transliterate' ) && seems_utf8( $retval ) ) {
    298300                        $retval = transliterator_transliterate( 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove', $retval );
    299301
    300                 // Older.
     302                        // Older.
    301303                } else {
    302304                        // Use WP's built-in function to convert accents to their ASCII equivalent.
     
    318320         * the 'upload_filetypes' setting. BuddyPress will respect this setting.
    319321         *
     322         * @since 2.3.0
     323         *
    320324         * @see check_upload_mimes()
    321325         *
    322          * @since 2.3.0
    323          *
     326         * @return array Valid mime types.
    324327         */
    325328        protected function validate_mime_types() {
    326                 $wp_mimes = get_allowed_mime_types();
     329                $wp_mimes    = get_allowed_mime_types();
    327330                $valid_mimes = array();
    328331
     
    331334                        foreach ( $wp_mimes as $ext_pattern => $mime ) {
    332335                                if ( $ext !== '' && strpos( $ext_pattern, $ext ) !== false ) {
    333                                         $valid_mimes[$ext_pattern] = $mime;
     336                                        $valid_mimes[ $ext_pattern ] = $mime;
    334337                                }
    335338                        }
     
    388391                 * @param array $upload_dir     The original Uploads dir.
    389392                 */
    390                 return apply_filters( 'bp_attachment_upload_dir', array(
    391                         'path'    => $this->upload_path,
    392                         'url'     => $this->url,
    393                         'subdir'  => false,
    394                         'basedir' => $this->upload_path,
    395                         'baseurl' => $this->url,
    396                         'error'   => false
    397                 ), $upload_dir );
     393                return apply_filters(
     394                        'bp_attachment_upload_dir',
     395                        array(
     396                                'path'    => $this->upload_path,
     397                                'url'     => $this->url,
     398                                'subdir'  => false,
     399                                'basedir' => $this->upload_path,
     400                                'baseurl' => $this->url,
     401                                'error'   => false,
     402                        ),
     403                        $upload_dir
     404                );
    398405        }
    399406
     
    406413         * @since 2.3.0
    407414         *
     415         * @return bool
    408416         */
    409417        public function create_dir() {
     
    432440         *
    433441         * @param array $args {
     442         *     Array of arguments for the crop method.
     443         *
    434444         *     @type string $original_file The source file (absolute path) for the Attachment.
    435445         *     @type int    $crop_x        The start x position to crop from.
     
    489499
    490500                // Check image file types.
    491                 $check_types = array( 'src_file' => array( 'file' => $r['original_file'], 'error' => _x( 'source file', 'Attachment source file', 'buddypress' ) ) );
     501                $check_types = array(
     502                        'src_file' => array(
     503                                'file'  => $r['original_file'],
     504                                'error' => _x( 'source file', 'Attachment source file', 'buddypress' ),
     505                        ),
     506                );
    492507                if ( ! empty( $r['dst_file'] ) ) {
    493                         $check_types['dst_file'] = array( 'file' => $r['dst_file'], 'error' => _x( 'destination file', 'Attachment destination file', 'buddypress' ) );
     508                        $check_types['dst_file'] = array(
     509                                'file'  => $r['dst_file'],
     510                                'error' => _x( 'destination file', 'Attachment destination file', 'buddypress' ),
     511                        );
    494512                }
    495513
     
    498516
    499517                foreach ( $check_types as $file ) {
    500                         $is_image      = wp_check_filetype( $file['file'] );
    501                         $ext           = $is_image['ext'];
     518                        $is_image = wp_check_filetype( $file['file'] );
     519                        $ext      = $is_image['ext'];
    502520
    503521                        if ( empty( $ext ) || empty( $supported_image_types[ $ext ] ) ) {
     
    538556         */
    539557        public function script_data() {
    540                 $script_data = array(
     558                return array(
    541559                        'action'            => $this->action,
    542560                        'file_data_name'    => $this->file_input,
     
    547565                        ),
    548566                );
    549 
    550                 return $script_data;
    551567        }
    552568
     
    557573         *
    558574         * @param string $attachment_type The attachement type (eg: avatar).
    559          * @param array $args {
     575         * @param array  $args {
     576         *     Optional. Array of arguments for the add_revision method.
     577         *
    560578         *     @type string $file_abspath The source file (absolute path) for the attachment.
    561579         *     @type string $file_id      Optional. The file ID to use as a suffix for the revision directory.
     
    599617                // Avatars and Cover Images are specific attachments.
    600618                if ( 'avatar' === $attachment_type || 'cover_image' === $attachment_type ) {
    601                         $revision_dir  = $dirname . 'history';
     619                        $revision_dir = $dirname . 'history';
    602620                }
    603621
     
    631649        public static function get_image_data( $file ) {
    632650                // Try to get image basic data.
    633                 list( $width, $height, $sourceImageType ) = @getimagesize( $file );
     651                list( $width, $height, $source_image_type ) = @getimagesize( $file );
    634652
    635653                // No need to carry on if we couldn't get image's basic data.
    636                 if ( is_null( $width ) || is_null( $height ) || is_null( $sourceImageType ) ) {
     654                if ( is_null( $width ) || is_null( $height ) || is_null( $source_image_type ) ) {
    637655                        return false;
    638656                }
     
    646664                // Make sure the wp_read_image_metadata function is reachable.
    647665                if ( ! function_exists( 'wp_read_image_metadata' ) ) {
    648                         require_once( ABSPATH . 'wp-admin/includes/image.php' );
     666                        require_once ABSPATH . 'wp-admin/includes/image.php';
    649667                }
    650668
     
    672690         * @param string $attachment_type The attachment type (eg: avatar or cover_image). Required.
    673691         * @param array  $args {
     692         *     Optional. Array of arguments for the edit_image method.
     693         *
    674694         *     @type string $file     Absolute path to the image file (required).
    675695         *     @type int    $max_w    Max width attribute for the editor's resize method (optional).
     
    738758                        return $editor->save( $editor->generate_filename() );
    739759
    740                 // Need to do some other edit actions or use a specific method to save file.
     760                        // Need to do some other edit actions or use a specific method to save file.
    741761                } else {
    742762                        return $editor;
Note: See TracChangeset for help on using the changeset viewer.