Avatar_Suggestions_Attachment

Avatar Suggestions Attachment class.

Defined (1)

The class is defined in the following location(s).

/includes/bp-avatar-suggestions-attachment.php  
  1. class Avatar_Suggestions_Attachment extends BP_Attachment { 
  2.  
  3. /** 
  4. * Construct Upload parameters 
  5. * @since BP Avatar Suggestions (1.3.0) 
  6. */ 
  7. public function __construct() { 
  8. parent::__construct( array( 
  9. 'action' => 'avatar_suggestions_upload',  
  10. 'file_input' => 'suggestion',  
  11. 'original_max_filesize' => bp_core_avatar_original_max_filesize(),  
  12. 'required_wp_files' => array( 'file', 'image' ),  
  13. 'allowed_mime_types' => bp_core_get_allowed_avatar_types(),  
  14. 'upload_error_strings' => array( 
  15. 9 => sprintf( __( 'The width x height of the profile photo should be at least %d x %d px.', 'bp-avatar-suggestions' ), bp_core_avatar_full_width(), bp_core_avatar_full_height() ),  
  16. ),  
  17. ) ); 
  18.  
  19. /** 
  20. * Avatar Suggestions specific rule 
  21. * Adds an error if the width x height of the suggestion is < then the full 
  22. * avatar dimensions 
  23. * @since BP Avatar Suggestions (1.3.0) 
  24. * @param array $file the temporary file attributes (before it has been moved) 
  25. * @return array the file with extra errors if needed 
  26. */ 
  27. public function validate_upload( $file = array() ) { 
  28. $file = parent::validate_upload( $file ); 
  29.  
  30. // Bail if already an error 
  31. if ( ! empty( $file['error'] ) ) { 
  32. return $file; 
  33.  
  34. // Type will be handle by WordPress at a later time 
  35. if ( ! isset( $file['type'] ) || ! isset( $file['tmp_name'] ) ) { 
  36. return $file; 
  37.  
  38. if ( 0 === strpos( $file['type'], 'image/' ) && function_exists( 'getimagesize' ) ) { 
  39. $uploaded_image = @getimagesize( $file['tmp_name'] ); 
  40.  
  41. if ( ! isset( $uploaded_image[0] ) || ! isset( $uploaded_image[1] ) ) { 
  42. return $file; 
  43.  
  44. if ( ! isset( $uploaded_image[0] ) || ! isset( $uploaded_image[1] ) || $uploaded_image[0] < bp_core_avatar_full_width() || $uploaded_image[1] < bp_core_avatar_full_height() ) { 
  45. // Use our custom error 
  46. $file['error'] = 9; 
  47.  
  48. // Return with error code attached 
  49. return $file; 
  50.  
  51. /** 
  52. * Build script datas for the Uploader UI 
  53. * @since BP Avatar Suggestions (1.3.0) 
  54. * @return array the javascript localization data 
  55. */ 
  56. public function script_data() { 
  57. // Get default script data 
  58. $script_data = parent::script_data(); 
  59.  
  60. // Get the post all suggestions are attached to. 
  61. $post_id = buddypress()->extend->avatar_suggestions->avatar_post_id; 
  62.  
  63. if ( ! empty( $post_id ) ) { 
  64. $script_data['bp_params'] = array( 
  65. 'object' => 'post',  
  66. 'item_id' => $post_id,  
  67. ); 
  68.  
  69. // Include our specific css 
  70. $script_data['extra_css'] = array( 'bp-as-admin-style' ); 
  71.  
  72. // Include our specific js 
  73. $script_data['extra_js'] = array( 'bp-as-admin-js' ); 
  74.  
  75. return $script_data;