Changeset 13901
- Timestamp:
- 06/02/2024 07:14:55 PM (19 months ago)
- Location:
- trunk/src/bp-core/classes
- Files:
-
- 5 edited
-
class-bp-attachment-avatar.php (modified) (13 diffs)
-
class-bp-attachment-cover-image.php (modified) (8 diffs)
-
class-bp-attachment.php (modified) (24 diffs)
-
class-bp-block.php (modified) (3 diffs)
-
class-bp-button.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment-avatar.php
r13414 r13901 32 32 $allowed_types = bp_core_get_allowed_avatar_types(); 33 33 34 parent::__construct( array( 35 'action' => 'bp_avatar_upload', 36 'file_input' => 'file', 37 'original_max_filesize' => bp_core_avatar_original_max_filesize(), 38 39 // Specific errors for avatars. 40 'upload_error_strings' => array( 41 /* translators: %s: Max file size for the profile photo */ 42 9 => sprintf( _x( 'That photo is too big. Please upload one smaller than %s', 'profile photo upload error', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), 43 44 /* translators: %s: comma separated list of file types allowed for the profile photo */ 45 10 => sprintf( _nx( 'Please upload only this file type: %s.', 'Please upload only these file types: %s.', count( $allowed_types ), 'profile photo upload error', 'buddypress' ), self::get_avatar_types( $allowed_types ) ), 46 ), 47 ) ); 34 parent::__construct( 35 array( 36 'action' => 'bp_avatar_upload', 37 'file_input' => 'file', 38 'original_max_filesize' => bp_core_avatar_original_max_filesize(), 39 40 // Specific errors for avatars. 41 'upload_error_strings' => array( 42 /* translators: %s: Max file size for the profile photo */ 43 9 => sprintf( _x( 'That photo is too big. Please upload one smaller than %s', 'profile photo upload error', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), 44 45 /* translators: %s: comma separated list of file types allowed for the profile photo */ 46 10 => sprintf( _nx( 'Please upload only this file type: %s.', 'Please upload only these file types: %s.', count( $allowed_types ), 'profile photo upload error', 'buddypress' ), self::get_avatar_types( $allowed_types ) ), 47 ), 48 ) 49 ); 48 50 } 49 51 … … 98 100 $file['error'] = 9; 99 101 100 // File is of invalid type.102 // File is of invalid type. 101 103 } elseif ( ! bp_core_check_avatar_type( array( 'file' => $file ) ) ) { 102 104 $file['error'] = 10; … … 153 155 3 => 180, 154 156 6 => -90, 155 8 => 90,157 8 => 90, 156 158 ); 157 159 … … 163 165 if ( empty( $edit_args ) ) { 164 166 return false; 167 } 165 168 166 169 // Add the file to the edit arguments. 167 } else { 168 $edit_args['file'] = $file; 169 } 170 $edit_args['file'] = $file; 170 171 171 172 return parent::edit_image( 'avatar', $edit_args ); … … 176 177 * 177 178 * @since 2.3.0 178 *179 179 * 180 180 * @param string $file the absolute path to the file. … … 186 186 $full_height = bp_core_avatar_full_height(); 187 187 188 if ( isset( $uploaded_image[0] ) && $uploaded_image[0] < $full_width || $uploaded_image[1] < $full_height ) { 189 return true; 190 } 191 192 return false; 188 return ( isset( $uploaded_image[0] ) && ( $uploaded_image[0] < $full_width || $uploaded_image[1] < $full_height ) ); 193 189 } 194 190 … … 198 194 * @since 2.3.0 199 195 * 200 * @see BP_Attachment::cropfor the list of parameters196 * @see BP_Attachment::crop() for the list of parameters 201 197 * 202 198 * @param array $args Array of arguments for the cropping. … … 229 225 230 226 // Bail if the avatar is not available. 231 if ( ! file_exists( $absolute_path ) ) {227 if ( ! file_exists( $absolute_path ) ) { 232 228 return false; 233 229 } … … 281 277 } 282 278 283 $is_full = preg_match( "/-bpfull/", $avatar_file->name );284 $is_thumb = preg_match( "/-bpthumb/", $avatar_file->name );279 $is_full = preg_match( '/-bpfull/', $avatar_file->name ); 280 $is_thumb = preg_match( '/-bpthumb/', $avatar_file->name ); 285 281 286 282 if ( $is_full || $is_thumb ) { … … 322 318 'thumb' => '', 323 319 ); 324 $timestamp = bp_core_current_time( true, 'timestamp' );320 $timestamp = bp_core_current_time( true, 'timestamp' ); 325 321 326 322 foreach ( $avatar_types as $key_type => $type ) { … … 359 355 */ 360 356 private function get_user_id() { 361 $bp = buddypress();357 $bp = buddypress(); 362 358 $user_id = 0; 363 359 … … 424 420 'item_id' => $user_id, 425 421 'has_avatar' => bp_get_user_has_avatar( $user_id ), 426 'nonces' => array(422 'nonces' => array( 427 423 'set' => wp_create_nonce( 'bp_avatar_cropstore' ), 428 424 'remove' => wp_create_nonce( 'bp_delete_avatar_link' ), … … 476 472 477 473 // Include the specific css. 478 $script_data['extra_js'] = $js_scripts;474 $script_data['extra_js'] = $js_scripts; 479 475 480 476 // Set the object to contextualize the filter. -
trunk/src/bp-core/classes/class-bp-attachment-cover-image.php
r13414 r13901 30 30 $max_upload_file_size = bp_attachments_get_max_upload_file_size( 'cover_image' ); 31 31 32 parent::__construct( array( 33 'action' => 'bp_cover_image_upload', 34 'file_input' => 'file', 35 'original_max_filesize' => $max_upload_file_size, 36 'base_dir' => bp_attachments_uploads_dir_get( 'dir' ), 37 'required_wp_files' => array( 'file', 'image' ), 38 39 // Specific errors for cover images. 40 'upload_error_strings' => array( 41 /* translators: %s: Max file size for the cover image */ 42 11 => sprintf( _x( 'That image is too big. Please upload one smaller than %s', 'cover image upload error', 'buddypress' ), size_format( $max_upload_file_size ) ), 43 44 /* translators: %s: comma separated list of file types allowed for the cover image */ 45 12 => sprintf( _nx( 'Please upload only this file type: %s.', 'Please upload only these file types: %s.', count( $allowed_types ), 'cover image upload error', 'buddypress' ), self::get_cover_image_types( $allowed_types ) ), 46 ), 47 ) ); 32 parent::__construct( 33 array( 34 'action' => 'bp_cover_image_upload', 35 'file_input' => 'file', 36 'original_max_filesize' => $max_upload_file_size, 37 'base_dir' => bp_attachments_uploads_dir_get( 'dir' ), 38 'required_wp_files' => array( 'file', 'image' ), 39 40 // Specific errors for cover images. 41 'upload_error_strings' => array( 42 /* translators: %s: Max file size for the cover image */ 43 11 => sprintf( _x( 'That image is too big. Please upload one smaller than %s', 'cover image upload error', 'buddypress' ), size_format( $max_upload_file_size ) ), 44 45 /* translators: %s: comma separated list of file types allowed for the cover image */ 46 12 => sprintf( _nx( 'Please upload only this file type: %s.', 'Please upload only these file types: %s.', count( $allowed_types ), 'cover image upload error', 'buddypress' ), self::get_cover_image_types( $allowed_types ) ), 47 ), 48 ) 49 ); 48 50 } 49 51 … … 83 85 $file['error'] = 11; 84 86 85 // File is of invalid type.87 // File is of invalid type. 86 88 } elseif ( isset( $file['tmp_name'] ) && isset( $file['name'] ) && ! bp_attachments_check_filetype( $file['tmp_name'], $file['name'], bp_attachments_get_allowed_mimes( 'cover_image' ) ) ) { 87 89 $file['error'] = 12; … … 138 140 3 => 180, 139 141 6 => -90, 140 8 => 90,142 8 => 90, 141 143 ); 142 144 … … 149 151 return false; 150 152 151 // Add the file to the edit arguments.153 // Add the file to the edit arguments. 152 154 } else { 153 $edit_args = array_merge( $edit_args, array( 'file' => $file, 'save' => false ) ); 155 $edit_args = array_merge( 156 $edit_args, 157 array( 158 'file' => $file, 159 'save' => false, 160 ) 161 ); 154 162 } 155 163 … … 157 165 $editor = parent::edit_image( 'cover_image', $edit_args ); 158 166 159 if ( is_wp_error( $editor ) ) {167 if ( is_wp_error( $editor ) ) { 160 168 return $editor; 161 169 } elseif ( ! is_a( $editor, 'WP_Image_Editor' ) ) { … … 173 181 * 174 182 * @param string $file The absolute path to the file. 175 * @return false|string $value The absolute path to the new file name.183 * @return false|string 176 184 */ 177 185 public function generate_filename( $file = '' ) { … … 208 216 'item_id' => $item_id, 209 217 'has_cover_image' => bp_attachments_get_user_has_cover_image( $item_id ), 210 'nonces' => array(218 'nonces' => array( 211 219 'remove' => wp_create_nonce( 'bp_delete_cover_image' ), 212 220 ), … … 226 234 'item_id' => bp_get_current_group_id(), 227 235 'has_cover_image' => bp_attachments_get_group_has_cover_image( $item_id ), 228 'nonces' => array(236 'nonces' => array( 229 237 'remove' => wp_create_nonce( 'bp_delete_cover_image' ), 230 238 ), -
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; -
trunk/src/bp-core/classes/class-bp-block.php
r13877 r13901 17 17 */ 18 18 class BP_Block { 19 19 20 /** 20 21 * WP Block Type object. 21 22 * 22 23 * @since 6.0.0 24 * 23 25 * @var WP_Block_Type|WP_Error 24 26 */ … … 29 31 * 30 32 * @since 6.0.0 33 * 31 34 * @var array 32 35 */ … … 37 40 * 38 41 * @since 6.0.0 42 * 39 43 * @var array 40 44 */ -
trunk/src/bp-core/classes/class-bp-button.php
r13818 r13901 233 233 * @since 1.2.6 234 234 * 235 * @param array|string $args See {@BP_Button}.235 * @param array|string $args See `BP_Button`. 236 236 */ 237 237 public function __construct( $args = '' ) { … … 246 246 247 247 // Deprecated. Subject to removal in a future release. 248 248 249 $this->wrapper = $r['wrapper']; 249 if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; 250 if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; 251 if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; 252 if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; 253 if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; 254 if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; 250 251 if ( ! empty( $r['link_id'] ) ) { 252 $this->link_id = ' id="' . $r['link_id'] . '"'; 253 } 254 if ( ! empty( $r['link_href'] ) ) { 255 $this->link_href = ' href="' . $r['link_href'] . '"'; 256 } 257 if ( ! empty( $r['link_title'] ) ) { 258 $this->link_title = ' title="' . $r['link_title'] . '"'; 259 } 260 if ( ! empty( $r['link_rel'] ) ) { 261 $this->link_rel = ' rel="' . $r['link_rel'] . '"'; 262 } 263 if ( ! empty( $r['link_class'] ) ) { 264 $this->link_class = ' class="' . $r['link_class'] . '"'; 265 } 266 if ( ! empty( $r['link_text'] ) ) { 267 $this->link_text = $r['link_text']; 268 } 255 269 256 270 // Required button properties. … … 262 276 // $id and $component are required and component must be active. 263 277 if ( empty( $r['id'] ) || empty( $r['component'] ) || ! bp_is_active( $this->component ) ) { 264 return false;278 return; 265 279 } 266 280 267 281 // No button for guests if must be logged in. 268 if ( true == $this->must_be_logged_in && ! is_user_logged_in() ) {269 return false;282 if ( true === $this->must_be_logged_in && ! is_user_logged_in() ) { 283 return; 270 284 } 271 285 272 286 // The block_self property. 273 if ( true == $this->block_self ) {287 if ( true === $this->block_self ) { 274 288 /* 275 289 * No button if you are the current user in a members loop. … … 279 293 */ 280 294 if ( bp_get_member_user_id() ) { 281 if ( is_user_logged_in() && bp_loggedin_user_id() == bp_get_member_user_id() ) {282 return false;295 if ( is_user_logged_in() && bp_loggedin_user_id() === bp_get_member_user_id() ) { 296 return; 283 297 } 284 298 285 // No button if viewing your own profile (and not in a members loop).299 // No button if viewing your own profile (and not in a members loop). 286 300 } elseif ( bp_is_my_profile() ) { 287 return false;301 return; 288 302 } 289 303 } … … 311 325 312 326 // Render parent element attributes. 313 $parent_elem = new BP_Core_HTML_Element( array( 314 'element' => $r['parent_element'], 315 'attr' => $r['parent_attr'] 316 ) ); 327 $parent_elem = new BP_Core_HTML_Element( 328 array( 329 'element' => $r['parent_element'], 330 'attr' => $r['parent_attr'], 331 ) 332 ); 317 333 318 334 // Set before and after. … … 320 336 $after = $parent_elem->get( 'close_tag' ); 321 337 322 // No parent element.338 // No parent element. 323 339 } else { 324 $before = $after = ''; 340 $before = ''; 341 $after = ''; 325 342 } 326 343 … … 339 356 } 340 357 341 $button = new BP_Core_HTML_Element( array( 342 'element' => $r['button_element'], 343 'attr' => $r['button_attr'], 344 'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : '' 345 ) ); 358 $button = new BP_Core_HTML_Element( 359 array( 360 'element' => $r['button_element'], 361 'attr' => $r['button_attr'], 362 'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : '', 363 ) 364 ); 346 365 $button = $button->contents(); 347 366 } … … 374 393 * @since 2.7.0. 375 394 * 376 * @param array $r See {@ linkBP_Button} class for full documentation.395 * @param array $r See {@see BP_Button} class for full documentation. 377 396 * @return array 378 397 */ … … 380 399 // Array of deprecated arguments. 381 400 $backpat_args = array( 382 'wrapper', 'wrapper_class', 'wrapper_id', 383 'link_href', 'link_class', 'link_id', 'link_rel', 'link_title' 401 'wrapper', 402 'wrapper_class', 403 'wrapper_id', 404 'link_href', 405 'link_class', 406 'link_id', 407 'link_rel', 408 'link_title', 384 409 ); 385 410 … … 389 414 } 390 415 391 $parent = $child = false; 416 $parent = false; 417 $child = false; 392 418 $sep = strpos( $prop, '_' ); 393 419 … … 410 436 $r[ "{$parent}_element" ] = $r[ $prop ]; 411 437 412 // Set attributes.438 // Set attributes. 413 439 } elseif ( true === $child ) { 414 $new_prop = substr( $prop, strpos( $prop, '_' ) + 1 );440 $new_prop = substr( $prop, strpos( $prop, '_' ) + 1 ); 415 441 if ( empty( $r[ "{$parent}_attr" ] ) ) { 416 442 $r[ "{$parent}_attr" ] = array();
Note: See TracChangeset
for help on using the changeset viewer.