Changeset 13901 for trunk/src/bp-core/classes/class-bp-attachment.php
- Timestamp:
- 06/02/2024 07:14:55 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment.php
r13718 r13901 53 53 * 54 54 * @param array|string $args { 55 * Array of upload parameters. 56 * 55 57 * @type int $original_max_filesize Maximum file size in kilobytes. Defaults to php.ini settings. 56 58 * @type array $allowed_mime_types List of allowed file extensions (eg: array( 'jpg', 'gif', 'png' ) ). … … 69 71 // Upload action and the file input name are required parameters. 70 72 if ( empty( $args['action'] ) || empty( $args['file_input'] ) ) { 71 return false;73 return; 72 74 } 73 75 … … 92 94 $this->{$key} = $this->set_upload_error_strings( $param ); 93 95 94 // Sanitize the base dir.96 // Sanitize the base dir. 95 97 } elseif ( 'base_dir' === $key ) { 96 98 $this->{$key} = sanitize_title( $param ); 97 99 98 // Sanitize the upload dir filter arg to pass.100 // Sanitize the upload dir filter arg to pass. 99 101 } elseif ( 'upload_dir_filter_args' === $key ) { 100 102 $this->{$key} = (int) $param; 101 103 102 // Action & File input are already set and sanitized.104 // Action & File input are already set and sanitized. 103 105 } elseif ( 'action' !== $key && 'file_input' !== $key ) { 104 106 $this->{$key} = $param; … … 114 116 * 115 117 * @since 2.3.0 116 *117 118 */ 118 119 public function set_upload_dir() { 119 120 // Set the directory, path, & url variables. 120 $this->upload_dir = bp_upload_dir();121 $this->upload_dir = bp_upload_dir(); 121 122 122 123 if ( empty( $this->upload_dir ) ) { 123 return false;124 return; 124 125 } 125 126 … … 139 140 if ( ! empty( $this->base_dir ) ) { 140 141 $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; 142 143 143 144 // Finally create the base dir. … … 195 196 } 196 197 197 require_once ( ABSPATH . "/wp-admin/includes/{$wp_file}.php" );198 require_once ABSPATH . "/wp-admin/includes/{$wp_file}.php"; 198 199 } 199 200 } … … 207 208 * @param string $upload_dir_filter A specific filter to be applied to 'upload_dir' (optional). 208 209 * @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. 210 211 * On failure, returns an array containing the error message 211 212 * (eg: array( 'error' => $message ) ) … … 257 258 * and no specific filter has been requested, use a default 258 259 * filter to create the specific $base dir 260 * 259 261 * @see BP_Attachment->upload_dir_filter() 260 262 */ … … 290 292 * @since 2.9.0 291 293 * 292 * @param string $retval Filename.294 * @param string $retval Filename. 293 295 * @return string 294 296 */ 295 297 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+ . 297 299 if ( function_exists( 'transliterator_transliterate' ) && seems_utf8( $retval ) ) { 298 300 $retval = transliterator_transliterate( 'Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove', $retval ); 299 301 300 // Older.302 // Older. 301 303 } else { 302 304 // Use WP's built-in function to convert accents to their ASCII equivalent. … … 318 320 * the 'upload_filetypes' setting. BuddyPress will respect this setting. 319 321 * 322 * @since 2.3.0 323 * 320 324 * @see check_upload_mimes() 321 325 * 322 * @since 2.3.0 323 * 326 * @return array Valid mime types. 324 327 */ 325 328 protected function validate_mime_types() { 326 $wp_mimes = get_allowed_mime_types();329 $wp_mimes = get_allowed_mime_types(); 327 330 $valid_mimes = array(); 328 331 … … 331 334 foreach ( $wp_mimes as $ext_pattern => $mime ) { 332 335 if ( $ext !== '' && strpos( $ext_pattern, $ext ) !== false ) { 333 $valid_mimes[ $ext_pattern] = $mime;336 $valid_mimes[ $ext_pattern ] = $mime; 334 337 } 335 338 } … … 388 391 * @param array $upload_dir The original Uploads dir. 389 392 */ 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 ); 398 405 } 399 406 … … 406 413 * @since 2.3.0 407 414 * 415 * @return bool 408 416 */ 409 417 public function create_dir() { … … 432 440 * 433 441 * @param array $args { 442 * Array of arguments for the crop method. 443 * 434 444 * @type string $original_file The source file (absolute path) for the Attachment. 435 445 * @type int $crop_x The start x position to crop from. … … 489 499 490 500 // 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 ); 492 507 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 ); 494 512 } 495 513 … … 498 516 499 517 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']; 502 520 503 521 if ( empty( $ext ) || empty( $supported_image_types[ $ext ] ) ) { … … 538 556 */ 539 557 public function script_data() { 540 $script_data =array(558 return array( 541 559 'action' => $this->action, 542 560 'file_data_name' => $this->file_input, … … 547 565 ), 548 566 ); 549 550 return $script_data;551 567 } 552 568 … … 557 573 * 558 574 * @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 * 560 578 * @type string $file_abspath The source file (absolute path) for the attachment. 561 579 * @type string $file_id Optional. The file ID to use as a suffix for the revision directory. … … 599 617 // Avatars and Cover Images are specific attachments. 600 618 if ( 'avatar' === $attachment_type || 'cover_image' === $attachment_type ) { 601 $revision_dir = $dirname . 'history';619 $revision_dir = $dirname . 'history'; 602 620 } 603 621 … … 631 649 public static function get_image_data( $file ) { 632 650 // Try to get image basic data. 633 list( $width, $height, $source ImageType ) = @getimagesize( $file );651 list( $width, $height, $source_image_type ) = @getimagesize( $file ); 634 652 635 653 // No need to carry on if we couldn't get image's basic data. 636 if ( is_null( $width ) || is_null( $height ) || is_null( $source ImageType ) ) {654 if ( is_null( $width ) || is_null( $height ) || is_null( $source_image_type ) ) { 637 655 return false; 638 656 } … … 646 664 // Make sure the wp_read_image_metadata function is reachable. 647 665 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'; 649 667 } 650 668 … … 672 690 * @param string $attachment_type The attachment type (eg: avatar or cover_image). Required. 673 691 * @param array $args { 692 * Optional. Array of arguments for the edit_image method. 693 * 674 694 * @type string $file Absolute path to the image file (required). 675 695 * @type int $max_w Max width attribute for the editor's resize method (optional). … … 738 758 return $editor->save( $editor->generate_filename() ); 739 759 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. 741 761 } else { 742 762 return $editor;
Note: See TracChangeset
for help on using the changeset viewer.