- Timestamp:
- 11/15/2015 07:13:42 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment-cover-image.php
r10194 r10355 7 7 */ 8 8 9 // Exit if accessed directly 9 // Exit if accessed directly. 10 10 defined( 'ABSPATH' ) || exit; 11 11 … … 19 19 class BP_Attachment_Cover_Image extends BP_Attachment { 20 20 /** 21 * The constuctor 21 * The constuctor. 22 22 * 23 23 * @since 2.4.0 24 24 */ 25 25 public function __construct() { 26 // Allowed cover image types & upload size 26 // Allowed cover image types & upload size. 27 27 $allowed_types = bp_attachments_get_allowed_types( 'cover_image' ); 28 28 $max_upload_file_size = bp_attachments_get_max_upload_file_size( 'cover_image' ); … … 35 35 'required_wp_files' => array( 'file', 'image' ), 36 36 37 // Specific errors for cover images 37 // Specific errors for cover images. 38 38 'upload_error_strings' => array( 39 39 11 => sprintf( __( 'That image is too big. Please upload one smaller than %s', 'buddypress' ), size_format( $max_upload_file_size ) ), … … 49 49 * 50 50 * @param array $allowed_types Array of allowed cover image types. 51 * 52 * @return string comma separated list of allowed cover image types. 51 * @return string $value Comma-separated list of allowed cover image types. 53 52 */ 54 53 public static function get_cover_image_types( $allowed_types = array() ) { … … 66 65 * @since 2.4.0 67 66 * 68 * @param array $file the temporary file attributes (before it has been moved). 69 * 70 * @return array the file with extra errors if needed. 67 * @param array $file The temporary file attributes (before it has been moved). 68 * @return array $file The file with extra errors if needed. 71 69 */ 72 70 public function validate_upload( $file = array() ) { 73 // Bail if already an error 71 // Bail if already an error. 74 72 if ( ! empty( $file['error'] ) ) { 75 73 return $file; 76 74 } 77 75 78 // File size is too big 76 // File size is too big. 79 77 if ( $file['size'] > $this->original_max_filesize ) { 80 78 $file['error'] = 11; 81 79 82 // File is of invalid type 80 // File is of invalid type. 83 81 } elseif ( ! bp_attachments_check_filetype( $file['tmp_name'], $file['name'], bp_attachments_get_allowed_mimes( 'cover_image' ) ) ) { 84 82 $file['error'] = 12; 85 83 } 86 84 87 // Return with error code attached 85 // Return with error code attached. 88 86 return $file; 89 87 } 90 88 91 89 /** 92 * Set the directory when uploading a file 93 * 94 * @since 2.4.0 95 * 96 * @param array $upload_dir The original Uploads dir.97 * @return array upload data (path, url, basedir...)90 * Set the directory when uploading a file. 91 * 92 * @since 2.4.0 93 * 94 * @param array $upload_dir The original Uploads dir. 95 * @return array $value Upload data (path, url, basedir...). 98 96 */ 99 97 public function upload_dir_filter( $upload_dir = array() ) { 100 // Default values are for profiles 98 // Default values are for profiles. 101 99 $object_id = bp_displayed_user_id(); 102 100 … … 107 105 $object_directory = 'members'; 108 106 109 // We're in a group, edit default values 107 // We're in a group, edit default values. 110 108 if ( bp_is_group() || bp_is_group_create() ) { 111 109 $object_id = bp_get_current_group_id(); … … 113 111 } 114 112 115 // Set the subdir 113 // Set the subdir. 116 114 $subdir = '/' . $object_directory . '/' . $object_id . '/cover-image'; 117 115 … … 121 119 * @since 2.4.0 122 120 * 123 * @param array $value Array containing the path, URL, and other helpful settings.121 * @param array $value Array containing the path, URL, and other helpful settings. 124 122 * @param array $upload_dir The original Uploads dir. 125 123 */ … … 139 137 * @since 2.4.0 140 138 * 141 * @param string $file the absolute path to the file. 139 * @param string $file The absolute path to the file. 140 * @param array $dimensions Array of dimensions for the cover image. 142 141 * @return mixed 143 142 */ … … 147 146 } 148 147 149 // Get image size 148 // Get image size. 150 149 $cover_data = parent::get_image_data( $file ); 151 150 152 // Init the edit args 151 // Init the edit args. 153 152 $edit_args = array(); 154 153 155 // Do we need to resize the image ?154 // Do we need to resize the image? 156 155 if ( ( isset( $cover_data['width'] ) && $cover_data['width'] > $dimensions['width'] ) || 157 156 ( isset( $cover_data['height'] ) && $cover_data['height'] > $dimensions['height'] ) ) { … … 163 162 } 164 163 165 // Do we need to rotate the image ?164 // Do we need to rotate the image? 166 165 $angles = array( 167 166 3 => 180, … … 174 173 } 175 174 176 // No need to edit the avatar, original file will be used 175 // No need to edit the avatar, original file will be used. 177 176 if ( empty( $edit_args ) ) { 178 177 return false; 179 178 180 // Add the file to the edit arguments 179 // Add the file to the edit arguments. 181 180 } else { 182 181 $edit_args = array_merge( $edit_args, array( 'file' => $file, 'save' => false ) ); 183 182 } 184 183 185 // Get the editor so that we can use a specific save method 184 // Get the editor so that we can use a specific save method. 186 185 $editor = parent::edit_image( 'cover_image', $edit_args ); 187 186 … … 192 191 } 193 192 194 // Save the new image file 193 // Save the new image file. 195 194 return $editor->save( $this->generate_filename( $file ) ); 196 195 } 197 196 198 197 /** 199 * Generate a filename for the cover image 200 * 201 * @since 2.4.0 202 * 203 * @param string $file the absolute path to the file.204 * @return string the absolute path to the new file name198 * Generate a filename for the cover image. 199 * 200 * @since 2.4.0 201 * 202 * @param string $file The absolute path to the file. 203 * @return string $value The absolute path to the new file name. 205 204 */ 206 205 public function generate_filename( $file = '' ) { … … 218 217 219 218 /** 220 * Build script datas for the Uploader UI 221 * 222 * @since 2.4.0 223 * 224 * @return array the javascript localization data219 * Build script datas for the Uploader UI. 220 * 221 * @since 2.4.0 222 * 223 * @return array The javascript localization data 225 224 */ 226 225 public function script_data() { 227 // Get default script data 226 // Get default script data. 228 227 $script_data = parent::script_data(); 229 228 … … 240 239 ); 241 240 242 // Set feedback messages 241 // Set feedback messages. 243 242 $script_data['feedback_messages'] = array( 244 243 1 => __( 'Your new cover image was uploaded successfully.', 'buddypress' ), … … 258 257 ); 259 258 260 // Set feedback messages 259 // Set feedback messages. 261 260 $script_data['feedback_messages'] = array( 262 261 1 => __( 'The group cover image was uploaded successfully.', 'buddypress' ), … … 265 264 ); 266 265 } else { 266 267 267 /** 268 * Use this filterto include specific BuddyPress params for your object.268 * Filters the cover image params to include specific BuddyPress params for your object. 269 269 * e.g. Cover image for blogs single item. 270 270 * … … 276 276 } 277 277 278 // Include our specific js & css 278 // Include our specific js & css. 279 279 $script_data['extra_js'] = array( 'bp-cover-image' ); 280 280 $script_data['extra_css'] = array( 'bp-avatar' ); 281 281 282 /** 283 * Filters the cover image script data. 284 * 285 * @since 2.4.0 286 * 287 * @param array $script_data Array of data for the cover image. 288 */ 282 289 return apply_filters( 'bp_attachments_cover_image_script_data', $script_data ); 283 290 }
Note: See TracChangeset
for help on using the changeset viewer.