Skip to:
Content

BuddyPress.org

Ticket #7484: 7484.01.patch

File 7484.01.patch, 1.7 KB (added by r-a-y, 8 years ago)
  • src/bp-core/classes/class-bp-attachment.php

     
    268268                        add_filter( 'upload_dir', $upload_dir_filter, 10, $this->upload_dir_filter_args );
    269269                }
    270270
     271                // Helper for utf-8 filenames.
     272                add_filter( 'sanitize_file_name', array( $this, 'sanitize_utf8_filename' ) );
     273
    271274                // Upload the attachment.
    272275                $this->attachment = wp_handle_upload( $file[ $this->file_input ], $overrides, $time );
    273276
     277                remove_filter( 'sanitize_file_name', array( $this, 'sanitize_utf8_filename' ) );
     278
    274279                // Restore WordPress Uploads data.
    275280                if ( ! empty( $upload_dir_filter ) ) {
    276281                        remove_filter( 'upload_dir', $upload_dir_filter, 10 );
     
    284289        }
    285290
    286291        /**
     292         * Helper to convert utf-8 characters in filenames to their ASCII equivalent.
     293         *
     294         * @since 2.9.0
     295         *
     296         * @param  string $retval Filename.
     297         * @return string
     298         */
     299        public function sanitize_utf8_filename( $retval ) {
     300                // PHP 5.4+ or with PECL intl 2.0+
     301                if ( function_exists( 'transliterator_transliterate' ) && seems_utf8( $retval ) ) {
     302                        $retval = transliterator_transliterate( 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove', $retval );
     303
     304                // Older.
     305                } else {
     306                        // Use WP's built-in function to convert accents to their ASCII equivalent.
     307                        $retval = remove_accents( $retval );
     308
     309                        // Still here? use iconv().
     310                        if ( function_exists( 'iconv' ) && seems_utf8( $retval ) ) {
     311                                $retval = iconv( 'UTF-8', 'ASCII//TRANSLIT//IGNORE', $retval );
     312                        }
     313                }
     314
     315                return $retval;
     316        }
     317
     318        /**
    287319         * Validate the allowed mime types using WordPress allowed mime types.
    288320         *
    289321         * In case of a multisite, the mime types are already restricted by