Changeset 10355
- Timestamp:
- 11/15/2015 07:13:42 PM (9 years ago)
- Location:
- trunk/src/bp-core/classes
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-attachment-avatar.php
r10206 r10355 29 29 */ 30 30 public function __construct() { 31 // Allowed avatar types 31 // Allowed avatar types. 32 32 $allowed_types = bp_core_get_allowed_avatar_types(); 33 33 … … 37 37 'original_max_filesize' => bp_core_avatar_original_max_filesize(), 38 38 39 // Specific errors for avatars 39 // Specific errors for avatars. 40 40 'upload_error_strings' => array( 41 41 9 => sprintf( __( 'That photo is too big. Please upload one smaller than %s', 'buddypress' ), size_format( bp_core_avatar_original_max_filesize() ) ), … … 51 51 * 52 52 * @param array $allowed_types Array of allowed avatar types. 53 *54 53 * @return string comma separated list of allowed avatar types. 55 54 */ … … 92 91 * 93 92 * @param array $file the temporary file attributes (before it has been moved). 94 *95 93 * @return array the file with extra errors if needed. 96 94 */ 97 95 public function validate_upload( $file = array() ) { 98 // Bail if already an error 96 // Bail if already an error. 99 97 if ( ! empty( $file['error'] ) ) { 100 98 return $file; 101 99 } 102 100 103 // File size is too big 101 // File size is too big. 104 102 if ( ! bp_core_check_avatar_size( array( 'file' => $file ) ) ) { 105 103 $file['error'] = 9; 106 104 107 // File is of invalid type 105 // File is of invalid type. 108 106 } elseif ( ! bp_core_check_avatar_type( array( 'file' => $file ) ) ) { 109 107 $file['error'] = 10; 110 108 } 111 109 112 // Return with error code attached 110 // Return with error code attached. 113 111 return $file; 114 112 } … … 122 120 * @uses bp_core_avatar_original_max_width() 123 121 * 124 * @param string $file the absolute path to the file.125 * 122 * @param string $file The absolute path to the file. 123 * @param int $ui_available_width Available width for the UI. 126 124 * @return mixed 127 125 */ 128 126 public static function shrink( $file = '', $ui_available_width = 0 ) { 129 // Get image size 127 // Get image size. 130 128 $avatar_data = parent::get_image_data( $file ); 131 129 132 // Init the edit args 130 // Init the edit args. 133 131 $edit_args = array(); 134 132 … … 136 134 $original_max_width = bp_core_avatar_original_max_width(); 137 135 138 // The ui_available_width is defined and it's smaller than the Avatar original max width 136 // The ui_available_width is defined and it's smaller than the Avatar original max width. 139 137 if ( ! empty( $ui_available_width ) && $ui_available_width < $original_max_width ) { 140 138 /** … … 150 148 } 151 149 152 // Do we need to resize the image 150 // Do we need to resize the image? 153 151 if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > $original_max_width ) { 154 152 $edit_args = array( … … 158 156 } 159 157 160 // Do we need to rotate the image 158 // Do we need to rotate the image? 161 159 $angles = array( 162 160 3 => 180, … … 169 167 } 170 168 171 // No need to edit the avatar, original file will be used 169 // No need to edit the avatar, original file will be used. 172 170 if ( empty( $edit_args ) ) { 173 171 return false; 174 172 175 // Add the file to the edit arguments 173 // Add the file to the edit arguments. 176 174 } else { 177 175 $edit_args['file'] = $file; … … 190 188 * 191 189 * @param string $file the absolute path to the file. 192 * 193 * @return boolean 190 * @return bool 194 191 */ 195 192 public static function is_too_small( $file = '' ) { … … 218 215 * @uses BP_Attachment::crop 219 216 * 220 * @param array $args 221 * 217 * @param array $args Array of arguments for the cropping. 222 218 * @return array The cropped avatars (full and thumb). 223 219 */ 224 220 public function crop( $args = array() ) { 225 // Bail if the original file is missing 221 // Bail if the original file is missing. 226 222 if ( empty( $args['original_file'] ) ) { 227 223 return false; … … 235 231 $absolute_path = $this->upload_path . $relative_path; 236 232 237 // Bail if the avatar is not available 233 // Bail if the avatar is not available. 238 234 if ( ! file_exists( $absolute_path ) ) { 239 235 return false; … … 250 246 } 251 247 252 // Bail if the avatar folder is missing for this item_id 248 // Bail if the avatar folder is missing for this item_id. 253 249 if ( ! file_exists( $avatar_folder_dir ) ) { 254 250 return false; 255 251 } 256 252 257 // Delete the existing avatar files for the object 253 // Delete the existing avatar files for the object. 258 254 $existing_avatar = bp_core_fetch_avatar( array( 259 255 'object' => $args['object'], … … 270 266 } 271 267 272 // Make sure we at least have minimal data for cropping 268 // Make sure we at least have minimal data for cropping. 273 269 if ( empty( $args['crop_w'] ) ) { 274 270 $args['crop_w'] = bp_core_avatar_full_width(); … … 279 275 } 280 276 281 // Get the file extension 277 // Get the file extension. 282 278 $data = @getimagesize( $absolute_path ); 283 279 $ext = $data['mime'] == 'image/png' ? 'png' : 'jpg'; … … 301 297 } 302 298 303 // Remove the original 299 // Remove the original. 304 300 @unlink( $absolute_path ); 305 301 306 // Return the full and thumb cropped avatars 302 // Return the full and thumb cropped avatars. 307 303 return $avatar_types; 308 304 } … … 355 351 */ 356 352 public function script_data() { 357 // Get default script data 353 // Get default script data. 358 354 $script_data = parent::script_data(); 359 355 360 // Defaults to Avatar Backbone script 356 // Defaults to Avatar Backbone script. 361 357 $js_scripts = array( 'bp-avatar' ); 362 358 363 // Default object 359 // Default object. 364 360 $object = ''; 365 361 366 // Get the possible item ids 362 // Get the possible item ids. 367 363 $user_id = $this->get_user_id(); 368 364 $group_id = $this->get_group_id(); 369 365 370 366 if ( ! empty( $user_id ) ) { 371 // Should we load the the Webcam Avatar javascript file 367 // Should we load the the Webcam Avatar javascript file. 372 368 if ( bp_avatar_use_webcam() ) { 373 369 $js_scripts = array( 'bp-webcam' ); … … 384 380 ); 385 381 386 // Set feedback messages 382 // Set feedback messages. 387 383 $script_data['feedback_messages'] = array( 388 384 1 => __( 'There was a problem cropping your profile photo.', 'buddypress' ), … … 402 398 ); 403 399 404 // Set feedback messages 400 // Set feedback messages. 405 401 $script_data['feedback_messages'] = array( 406 402 1 => __( 'There was a problem cropping the group profile photo.', 'buddypress' ), … … 422 418 } 423 419 424 // Include the specific css 420 // Include the specific css. 425 421 $script_data['extra_css'] = array( 'bp-avatar' ); 426 422 427 // Include the specific css 423 // Include the specific css. 428 424 $script_data['extra_js'] = $js_scripts; 429 425 430 // Set the object to contextualize the filter 426 // Set the object to contextualize the filter. 431 427 if ( isset( $script_data['bp_params']['object'] ) ) { 432 428 $object = $script_data['bp_params']['object']; -
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 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 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 } -
trunk/src/bp-core/classes/class-bp-attachment.php
r10194 r10355 50 50 * @since 2.3.0 51 51 * @since 2.4.0 Add the $upload_dir_filter_args argument to the $arguments array 52 * @uses sanitize_key() 53 * @uses wp_max_upload_size() 54 * @uses bp_parse_args() 55 * @uses BP_Attachment->set_upload_error_strings() 56 * @uses BP_Attachment->set_upload_dir() 52 57 * 53 58 * @param array|string $args { … … 64 69 * Defaults to 0 (optional). 65 70 * } 66 * @uses sanitize_key()67 * @uses wp_max_upload_size()68 * @uses bp_parse_args()69 * @uses BP_Attachment->set_upload_error_strings()70 * @uses BP_Attachment->set_upload_dir()71 71 */ 72 72 public function __construct( $args = '' ) { 73 // Upload action and the file input name are required parameters 73 // Upload action and the file input name are required parameters. 74 74 if ( empty( $args['action'] ) || empty( $args['file_input'] ) ) { 75 75 return false; 76 76 } 77 77 78 // Sanitize the action ID and the file input name 78 // Sanitize the action ID and the file input name. 79 79 $this->action = sanitize_key( $args['action'] ); 80 80 $this->file_input = sanitize_key( $args['file_input'] ); … … 92 92 $this->{$key} = $this->set_upload_error_strings( $param ); 93 93 94 // Sanitize the base dir 94 // Sanitize the base dir. 95 95 } elseif ( 'base_dir' === $key ) { 96 96 $this->{$key} = sanitize_title( $param ); 97 97 98 // Sanitize the upload dir filter arg to pass 98 // Sanitize the upload dir filter arg to pass. 99 99 } elseif ( 'upload_dir_filter_args' === $key ) { 100 100 $this->{$key} = (int) $param; 101 101 102 // Action & File input are already set and sanitized 102 // Action & File input are already set and sanitized. 103 103 } elseif ( 'action' !== $key && 'file_input' !== $key ) { 104 104 $this->{$key} = $param; … … 106 106 } 107 107 108 // Set the path/url and base dir for uploads 108 // Set the path/url and base dir for uploads. 109 109 $this->set_upload_dir(); 110 110 } … … 118 118 */ 119 119 public function set_upload_dir() { 120 // Set the directory, path, & url variables 120 // Set the directory, path, & url variables. 121 121 $this->upload_dir = bp_upload_dir(); 122 122 … … 128 128 $this->url = $this->upload_dir['baseurl']; 129 129 130 // Ensure URL is https if SSL is set/forced 130 // Ensure URL is https if SSL is set/forced. 131 131 if ( is_ssl() ) { 132 132 $this->url = str_replace( 'http://', 'https://', $this->url ); … … 142 142 $this->url = trailingslashit( $this->url ) . $this->base_dir; 143 143 144 // Finally create the base dir 144 // Finally create the base dir. 145 145 $this->create_dir(); 146 146 } … … 155 155 * 156 156 * @param array $param A list of error messages to add to BuddyPress core ones. 157 * 158 * @return array the list of upload errors 157 * @return array $upload_errors The list of upload errors. 159 158 */ 160 159 public function set_upload_error_strings( $param = array() ) { … … 204 203 * @since 2.3.0 205 204 * 206 * @param array $file The appropriate entry the from $_FILES superglobal.207 * @param string $upload_dir_filter A specific filter to be applied to 'upload_dir' (optional).208 * @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null.209 *210 205 * @uses wp_handle_upload() To upload the file 211 206 * @uses add_filter() To temporarly overrides WordPress uploads data … … 213 208 * @uses apply_filters() Call 'bp_attachment_upload_overrides' to include specific upload overrides 214 209 * 215 * @return array On success, returns an associative array of file attributes. 216 * On failure, returns an array containing the error message 217 * (eg: array( 'error' => $message ) ) 210 * @param array $file The appropriate entry the from $_FILES superglobal. 211 * @param string $upload_dir_filter A specific filter to be applied to 'upload_dir' (optional). 212 * @param string|null $time Optional. Time formatted in 'yyyy/mm'. Default null. 213 * @return array On success, returns an associative array of file attributes. 214 * On failure, returns an array containing the error message 215 * (eg: array( 'error' => $message ) ) 218 216 */ 219 217 public function upload( $file, $upload_dir_filter = '', $time = null ) { … … 238 236 add_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ), 10, 1 ); 239 237 240 // Set Default overrides 238 // Set Default overrides. 241 239 $overrides = array( 242 240 'action' => $this->action, … … 275 273 } 276 274 277 // Make sure the file will be uploaded in the attachment directory 275 // Make sure the file will be uploaded in the attachment directory. 278 276 if ( ! empty( $upload_dir_filter ) ) { 279 277 add_filter( 'upload_dir', $upload_dir_filter, 10, $this->upload_dir_filter_args ); 280 278 } 281 279 282 // Upload the attachment 280 // Upload the attachment. 283 281 $this->attachment = wp_handle_upload( $file[ $this->file_input ], $overrides, $time ); 284 282 285 // Restore WordPress Uploads data 283 // Restore WordPress Uploads data. 286 284 if ( ! empty( $upload_dir_filter ) ) { 287 285 remove_filter( 'upload_dir', $upload_dir_filter, 10, $this->upload_dir_filter_args ); 288 286 } 289 287 290 // Remove the pre WordPress 4.0 static filter 288 // Remove the pre WordPress 4.0 static filter. 291 289 remove_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ), 10, 1 ); 292 290 293 // Finally return the uploaded file or the error 291 // Finally return the uploaded file or the error. 294 292 return $this->attachment; 295 293 } … … 300 298 * In case of a multisite, the mime types are already restricted by 301 299 * the 'upload_filetypes' setting. BuddyPress will respect this setting. 300 * 302 301 * @see check_upload_mimes() 303 302 * … … 310 309 $valid_mimes = array(); 311 310 312 // Set the allowed mimes for the upload 311 // Set the allowed mimes for the upload. 313 312 foreach ( (array) $this->allowed_mime_types as $ext ) { 314 313 foreach ( $wp_mimes as $ext_pattern => $mime ) { … … 333 332 * 334 333 * @param array $file The temporary file attributes (before it has been moved). 335 *336 334 * @return array The file. 337 335 */ 338 336 public function validate_upload( $file = array() ) { 339 // Bail if already an error 337 // Bail if already an error. 340 338 if ( ! empty( $file['error'] ) ) { 341 339 return $file; … … 346 344 } 347 345 348 // Return the file 346 // Return the file. 349 347 return $file; 350 348 } … … 394 392 */ 395 393 public function create_dir() { 396 // Bail if no specific base dir is set 394 // Bail if no specific base dir is set. 397 395 if ( empty( $this->base_dir ) ) { 398 396 return false; 399 397 } 400 398 401 // Check if upload path already exists 399 // Check if upload path already exists. 402 400 if ( ! is_dir( $this->upload_path ) ) { 403 401 404 // If path does not exist, attempt to create it 402 // If path does not exist, attempt to create it. 405 403 if ( ! wp_mkdir_p( $this->upload_path ) ) { 406 404 return false; … … 408 406 } 409 407 410 // Directory exists 408 // Directory exists. 411 409 return true; 412 410 } … … 452 450 } 453 451 454 // Check image file pathes 452 // Check image file pathes. 455 453 $path_error = __( 'Cropping the file failed: the file path is not allowed.', 'buddypress' ); 456 454 457 // Make sure it's coming from an uploaded file 455 // Make sure it's coming from an uploaded file. 458 456 if ( false === strpos( $r['original_file'], $this->upload_path ) ) { 459 457 $wp_error->add( 'crop_error', $path_error ); … … 464 462 * If no destination file is provided, WordPress will use a default name 465 463 * and will write the file in the source file's folder. 466 * If a destination file is provided, we need to make sure it's going into uploads 464 * If a destination file is provided, we need to make sure it's going into uploads. 467 465 */ 468 466 if ( ! empty( $r['dst_file'] ) && false === strpos( $r['dst_file'], $this->upload_path ) ) { … … 471 469 } 472 470 473 // Check image file types 471 // Check image file types. 474 472 $check_types = array( 'src_file' => array( 'file' => $r['original_file'], 'error' => _x( 'source file', 'Attachment source file', 'buddypress' ) ) ); 475 473 if ( ! empty( $r['dst_file'] ) ) { … … 478 476 479 477 /** 480 * WordPress image supported types 478 * WordPress image supported types. 481 479 * @see wp_attachment_is() 482 480 */ … … 499 497 } 500 498 501 // Add the image.php to the required WordPress files, if it's not already the case 499 // Add the image.php to the required WordPress files, if it's not already the case. 502 500 $required_files = array_flip( $this->required_wp_files ); 503 501 if ( ! isset( $required_files['image'] ) ) { … … 505 503 } 506 504 507 // Load the files 505 // Load the files. 508 506 $this->includes(); 509 507 510 // Finally crop the image 508 // Finally crop the image. 511 509 return wp_crop_image( $r['original_file'], (int) $r['crop_x'], (int) $r['crop_y'], (int) $r['crop_w'], (int) $r['crop_h'], (int) $r['dst_w'], (int) $r['dst_h'], $r['src_abs'], $r['dst_file'] ); 512 510 } … … 545 543 */ 546 544 public static function get_image_data( $file ) { 547 // Try to get image basic data 545 // Try to get image basic data. 548 546 list( $width, $height, $sourceImageType ) = @getimagesize( $file ); 549 547 … … 553 551 } 554 552 555 // Initialize the image data 553 // Initialize the image data. 556 554 $image_data = array( 557 555 'width' => $width, … … 567 565 } 568 566 569 // Now try to get image's meta data 567 // Now try to get image's meta data. 570 568 $meta = wp_read_image_metadata( $file ); 571 569 572 570 if ( ! empty( $meta ) ) { 573 // Before 4.0 the Orientation wasn't included 571 // Before 4.0 the Orientation wasn't included. 574 572 if ( ! isset( $meta['orientation'] ) && 575 573 is_callable( 'exif_read_data' ) && … … 583 581 } 584 582 585 // Now add the metas to image data 583 // Now add the metas to image data. 586 584 $image_data['meta'] = $meta; 587 585 } … … 602 600 * @since 2.4.0 603 601 * 604 * @param 605 * @param array array$args {602 * @param string $attachment_type The attachment type (eg: avatar or cover_image). Required. 603 * @param array $args { 606 604 * @type string $file Absolute path to the image file (required). 607 605 * @type int $max_w Max width attribute for the editor's resize method (optional). … … 612 610 * @type bool $save Whether to use the editor's save method or not (optional). 613 611 * } 614 *615 612 * @return string|WP_Image_Editor|WP_Error The edited image path or the WP_Image_Editor object in case of success, 616 613 * an WP_Error object otherwise. … … 636 633 } 637 634 638 // Get the image editor 635 // Get the image editor. 639 636 $editor = wp_get_image_editor( $r['file'] ); 640 637 … … 648 645 $rotated = $editor->rotate( $r['rotate'] ); 649 646 650 // Stop in case of error 647 // Stop in case of error. 651 648 if ( is_wp_error( $rotated ) ) { 652 649 return $rotated; … … 657 654 $resized = $editor->resize( $r['max_w'], $r['max_h'], $r['crop'] ); 658 655 659 // Stop in case of error 656 // Stop in case of error. 660 657 if ( is_wp_error( $resized ) ) { 661 658 return $resized; … … 663 660 } 664 661 665 // Use the editor save method to get a path to the edited image 662 // Use the editor save method to get a path to the edited image. 666 663 if ( true === $r['save'] ) { 667 664 return $editor->save( $editor->generate_filename() ); 668 665 669 // Need to do some other edit actions or use a specific method to save file 666 // Need to do some other edit actions or use a specific method to save file. 670 667 } else { 671 668 return $editor; -
trunk/src/bp-core/classes/class-bp-button.php
r10108 r10355 144 144 public $link_text = ''; 145 145 146 /** HTML result ***********************************************************/ 147 146 /** HTML result 147 * 148 * @var string 149 */ 148 150 public $contents = ''; 149 151 … … 161 163 $r = wp_parse_args( $args, get_class_vars( __CLASS__ ) ); 162 164 163 // Required button properties 165 // Required button properties. 164 166 $this->id = $r['id']; 165 167 $this->component = $r['component']; … … 172 174 return false; 173 175 174 // No button if component is not active 176 // No button if component is not active. 175 177 if ( ! bp_is_active( $this->component ) ) 176 178 return false; 177 179 178 // No button for guests if must be logged in 180 // No button for guests if must be logged in. 179 181 if ( true == $this->must_be_logged_in && ! is_user_logged_in() ) 180 182 return false; 181 183 182 // block_self184 // The block_self property. 183 185 if ( true == $this->block_self ) { 184 186 // No button if you are the current user in a members loop 185 187 // This condition takes precedence, because members loops 186 // can be found on user profiles 188 // can be found on user profiles. 187 189 if ( bp_get_member_user_id() ) { 188 190 if ( is_user_logged_in() && bp_loggedin_user_id() == bp_get_member_user_id() ) { … … 191 193 192 194 // No button if viewing your own profile (and not in 193 // a members loop) 195 // a members loop). 194 196 } elseif ( bp_is_my_profile() ) { 195 197 return false; … … 197 199 } 198 200 199 // Wrapper properties 201 // Wrapper properties. 200 202 if ( false !== $this->wrapper ) { 201 203 202 // Wrapper ID 204 // Wrapper ID. 203 205 if ( !empty( $r['wrapper_id'] ) ) { 204 206 $this->wrapper_id = ' id="' . $r['wrapper_id'] . '"'; 205 207 } 206 208 207 // Wrapper class 209 // Wrapper class. 208 210 if ( !empty( $r['wrapper_class'] ) ) { 209 211 $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"'; … … 212 214 } 213 215 214 // Set before and after 216 // Set before and after. 215 217 $before = '<' . $r['wrapper'] . $this->wrapper_class . $this->wrapper_id . '>'; 216 218 $after = '</' . $r['wrapper'] . '>'; 217 219 218 // No wrapper 220 // No wrapper. 219 221 } else { 220 222 $before = $after = ''; 221 223 } 222 224 223 // Link properties 225 // Link properties. 224 226 if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; 225 227 if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; … … 229 231 if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; 230 232 231 // Build the button 233 // Build the button. 232 234 $this->contents = $before . '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>' . $after; 233 235 -
trunk/src/bp-core/classes/class-bp-core-notification.php
r10108 r10355 15 15 * Use BP_Notifications_Notification instead. 16 16 * 17 * @package BuddyPress Core18 17 * @deprecated since 1.9.0 19 18 */ … … 81 80 * Constructor 82 81 * 83 * @param int $id 82 * @param int $id ID for the notification. 84 83 */ 85 84 public function __construct( $id = 0 ) { … … 102 101 $bp = buddypress(); 103 102 104 // Update 103 // Update. 105 104 if ( !empty( $this->id ) ) { 106 105 $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id ); 107 106 108 // Save 107 // Save. 109 108 } else { 110 109 $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new ); … … 149 148 * @param int $user_id ID to check access for. 150 149 * @param int $notification_id Notification ID to check for. 151 *152 150 * @return string 153 151 */ … … 164 162 * 165 163 * @global wpdb $wpdb WordPress database object 164 * 165 * @static 166 166 * 167 167 * @param int $user_id User ID. 168 168 * @param string $status 'is_new' or 'all'. 169 *170 169 * @return array Associative array 171 * @static172 170 */ 173 171 public static function get_all_for_user( $user_id, $status = 'is_new' ) { … … 188 186 * @global wpdb $wpdb WordPress database object. 189 187 * 190 * @param int $user_id 191 * @param string $component_name 192 * @param string $component_action 193 * 194 * @static 195 * 188 * @static 189 * 190 * @param int $user_id ID of the user to delet notification for. 191 * @param string $component_name Component name. 192 * @param string $component_action Component action. 196 193 * @return mixed 197 194 */ … … 208 205 * 209 206 * @global wpdb $wpdb WordPress database object. 207 * 208 * @static 210 209 * 211 210 * @param int $user_id The ID of the user who the notifications are for. … … 215 214 * @param int|bool $secondary_item_id (optional) The secondary item id of the notifications that we wish to 216 215 * use to delete. 217 * @static218 *219 216 * @return mixed 220 217 */ … … 236 233 * @global wpdb $wpdb WordPress database object. 237 234 * 235 * @static 236 * 238 237 * @param int $user_id The ID of the user whose sent notifications we wish to delete. 239 238 * @param string $component_name The name of the component the notification was sent from. 240 239 * @param string $component_action The action of the component the notification was sent from. 241 * @static242 *243 240 * @return mixed 244 241 */ … … 256 253 * 257 254 * @global wpdb $wpdb WordPress database object. 255 * 256 * @static 258 257 * 259 258 * @param string $item_id The item id that they notifications are to be for. … … 261 260 * @param string $component_action The action that the notifications are to be from. 262 261 * @param string $secondary_item_id Optional secondary item id that the notifications are to have. 263 * @static264 *265 262 * @return mixed 266 263 */ -
trunk/src/bp-core/classes/class-bp-core-user.php
r10108 r10355 19 19 * $user = new BP_Core_User( $user_id ); 20 20 * $user_avatar = $user->avatar; 21 * 21 * $user_email = $user->email; 22 22 * $user_status = $user->status; 23 23 * etc. … … 178 178 } 179 179 180 // Cache a few things that are fetched often 180 // Cache a few things that are fetched often. 181 181 wp_cache_set( 'bp_user_fullname_' . $this->id, $this->fullname, 'bp' ); 182 182 wp_cache_set( 'bp_user_email_' . $this->id, $this->email, 'bp' ); … … 282 282 $sql['from'] = "FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} um ON um.user_id = u.ID"; 283 283 284 // We search against xprofile fields, so we must join the table 284 // We search against xprofile fields, so we must join the table. 285 285 if ( $search_terms && bp_is_active( 'xprofile' ) ) { 286 286 $sql['join_profiledata_search'] = "LEFT JOIN {$bp->profile->table_name_data} spd ON u.ID = spd.user_id"; 287 287 } 288 288 289 // Alphabetical sorting is done by the xprofile Full Name field 289 // Alphabetical sorting is done by the xprofile Full Name field. 290 290 if ( 'alphabetical' == $type ) { 291 291 $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; … … 349 349 $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key ); 350 350 351 // If a meta value is provided, match it 351 // If a meta value is provided, match it. 352 352 if ( $meta_value ) { 353 353 $sql['where_meta'] .= $wpdb->prepare( " AND umm.meta_value = %s", $meta_value ); … … 388 388 $paged_users = $wpdb->get_results( $paged_users_sql ); 389 389 390 // Re-jig the SQL so we can get the total user count 390 // Re-jig the SQL so we can get the total user count. 391 391 unset( $sql['select_main'] ); 392 392 … … 420 420 $total_users = $wpdb->get_var( $total_users_sql ); 421 421 422 /** *422 /** 423 423 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 424 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) 424 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join). 425 425 */ 426 426 if ( !empty( $populate_extras ) ) { … … 431 431 } 432 432 433 // Add additional data to the returned results 433 // Add additional data to the returned results. 434 434 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids, $type ); 435 435 } … … 448 448 * @param int $page The page number we are currently on, used in conjunction 449 449 * with $limit to get the start position for the limit. 450 * @param bool $populate_extras Populate extra user fields?450 * @param bool $populate_extras If we should populate extra user fields. 451 451 * @param string $exclude Comma-separated IDs of users whose results 452 452 * aren't to be fetched. 453 *454 453 * @return mixed False on error, otherwise associative array of results. 455 454 */ … … 462 461 } 463 462 464 // Multibyte compliance 463 // Multibyte compliance. 465 464 if ( function_exists( 'mb_strlen' ) ) { 466 465 if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) { … … 506 505 $paged_users = $wpdb->get_results( $paged_users_sql ); 507 506 508 /** *507 /** 509 508 * Lets fetch some other useful data in a separate queries, this will be 510 509 * faster than querying the data for every user in a list. We can't add … … 517 516 $user_ids[] = (int) $user->id; 518 517 519 // Add additional data to the returned results 518 // Add additional data to the returned results. 520 519 if ( $populate_extras ) { 521 520 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 536 535 * @param int $limit The limit of results we want. 537 536 * @param int $page The page we are on for pagination. 538 * @param bool $populate_extras Populate extra user fields? 539 * 537 * @param bool $populate_extras If we should populate extra user fields. 540 538 * @return array Associative array. 541 539 */ … … 607 605 $paged_users = $wpdb->get_results( $paged_users_sql ); 608 606 609 /** *607 /** 610 608 * Lets fetch some other useful data in a separate queries, this will be 611 609 * faster than querying the data for every user in a list. We can't add … … 615 613 */ 616 614 617 // Add additional data to the returned results 615 // Add additional data to the returned results. 618 616 if ( !empty( $populate_extras ) ) { 619 617 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 632 630 * @param int $limit The limit of results we want. 633 631 * @param int $page The page we are on for pagination. 634 * @param boolean $populate_extras Populate extra user fields? 635 * 632 * @param boolean $populate_extras If we should populate extra user fields. 636 633 * @return array Associative array. 637 634 */ … … 668 665 $paged_users = $wpdb->get_results( $paged_users_sql ); 669 666 670 /** *667 /** 671 668 * Lets fetch some other useful data in a separate queries, this will be faster than querying the data for every user in a list. 672 669 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join) … … 675 672 $user_ids[] = $user->id; 676 673 677 // Add additional data to the returned results 674 // Add additional data to the returned results. 678 675 if ( $populate_extras ) 679 676 $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids ); … … 692 689 * @param string $user_ids The user ids to select information about. 693 690 * @param string|bool $type The type of fields we wish to get. 694 *695 691 * @return mixed False on error, otherwise associative array of results. 696 692 */ … … 703 699 return $paged_users; 704 700 705 // Sanitize user IDs 701 // Sanitize user IDs. 706 702 $user_ids = implode( ',', wp_parse_id_list( $user_ids ) ); 707 703 708 // Fetch the user's full name 704 // Fetch the user's full name. 709 705 if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) { 710 706 $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) ); … … 717 713 } 718 714 719 // Fetch the user's total friend count 715 // Fetch the user's total friend count. 720 716 if ( 'popular' != $type ) { 721 717 $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) ); … … 728 724 } 729 725 730 // Fetch whether or not the user is a friend 726 // Fetch whether or not the user is a friend. 731 727 if ( bp_is_active( 'friends' ) ) { 732 728 $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) ); … … 749 745 } 750 746 751 // Fetch the user's last_activity 747 // Fetch the user's last_activity. 752 748 if ( 'active' != $type ) { 753 749 $user_activity = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as last_activity FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'last_activity' ) ) ); … … 760 756 } 761 757 762 // Fetch the user's latest update 758 // Fetch the user's latest update. 763 759 $user_update = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as latest_update FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'bp_latest_update' ) ) ); 764 760 for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) { … … 778 774 * 779 775 * @param int $user_id User ID. 780 *781 776 * @return array Associative array. 782 777 */ … … 793 788 * Get last activity data for a user or set of users. 794 789 * 795 * @param int|array User IDs or multiple user IDs. 796 * 790 * @param int|array $user_id User IDs or multiple user IDs. 797 791 * @return array 798 792 */ … … 800 794 global $wpdb; 801 795 802 // Sanitize and remove empty values 796 // Sanitize and remove empty values. 803 797 $user_ids = array_filter( wp_parse_id_list( $user_id ) ); 804 798 … … 825 819 } 826 820 827 // Fetch all user data from the cache 821 // Fetch all user data from the cache. 828 822 $retval = array(); 829 823 foreach ( $user_ids as $user_id ) { … … 844 838 * @param int $user_id ID of the user whose last_activity you are updating. 845 839 * @param string $time MySQL-formatted time string. 846 *847 840 * @return bool True on success, false on failure. 848 841 */ … … 858 851 $table_name, 859 852 860 // Data to update 853 // Data to update. 861 854 array( 862 855 'date_recorded' => $time, 863 856 ), 864 857 865 // WHERE 858 // WHERE. 866 859 array( 867 860 'id' => $activity[ $user_id ]['activity_id'], 868 861 ), 869 862 870 // Data sanitization format 863 // Data sanitization format. 871 864 array( 872 865 '%s', 873 866 ), 874 867 875 // WHERE sanitization format 868 // WHERE sanitization format. 876 869 array( 877 870 '%d', … … 879 872 ); 880 873 881 // add new date to existing activity entry for caching874 // Add new date to existing activity entry for caching. 882 875 $activity[ $user_id ]['date_recorded'] = $time; 883 876 … … 886 879 $table_name, 887 880 888 // Data 881 // Data. 889 882 array( 890 883 'user_id' => $user_id, … … 898 891 ), 899 892 900 // Data sanitization format 893 // Data sanitization format. 901 894 array( 902 895 '%d', … … 911 904 ); 912 905 913 // set up activity array for caching914 // view the foreach loop in the get_last_activity() method for format906 // Set up activity array for caching. 907 // View the foreach loop in the get_last_activity() method for format. 915 908 $activity = array(); 916 909 $activity[ $user_id ] = array( … … 921 914 } 922 915 923 // set cache916 // Set cache. 924 917 wp_cache_set( $user_id, $activity[ $user_id ], 'bp_last_activity' ); 925 918 … … 932 925 * @since 2.0.0 933 926 * 934 * @param int $user_id 935 * 927 * @param int $user_id ID of the user whose activity should be deleted. 936 928 * @return bool True on success, false on failure or if no last_activity 937 929 * is found for the user. … … 949 941 buddypress()->members->table_name_last_activity, 950 942 951 // WHERE 943 // WHERE. 952 944 array( 953 945 'id' => $existing[ $user_id ]['activity_id'], 954 946 ), 955 947 956 // WHERE sanitization format 948 // WHERE sanitization format. 957 949 array( 958 950 '%s', -
trunk/src/bp-core/classes/class-bp-date-query.php
r10108 r10355 11 11 12 12 if ( class_exists( 'WP_Date_Query' ) ) : 13 13 14 /** 14 15 * BuddyPress date query class. … … 34 35 * Constructor. 35 36 * 36 * @param array $date_query 37 * @param string $column 37 * @param array $date_query Date query arguments. 38 * @param string $column THe DB column to query against. 38 39 * 39 40 * @see WP_Date_Query::__construct() … … 59 60 * 60 61 * @param array $retval Current DB columns. 61 *62 62 * @return array 63 63 */ -
trunk/src/bp-core/classes/class-bp-embed.php
r10108 r10355 32 32 // These are providers that use a regex callback on the URL in question. 33 33 // Do not confuse with oEmbed providers, which require an external ping. 34 // Used in WP_Embed::shortcode() 34 // Used in WP_Embed::shortcode(). 35 35 $this->handlers = $wp_embed->handlers; 36 36 … … 83 83 * @param array $attr Shortcode attributes. 84 84 * @param string $url The URL attempting to be embeded. 85 *86 85 * @return string The embed HTML on success, otherwise the original URL. 87 86 */ … … 93 92 $attr = wp_parse_args( $attr, wp_embed_defaults() ); 94 93 95 // kses converts& into & and we need to undo this96 // See https://core.trac.wordpress.org/ticket/11311 94 // Use kses to convert & into & and we need to undo this 95 // See https://core.trac.wordpress.org/ticket/11311. 97 96 $url = str_replace( '&', '&', $url ); 98 97 99 // Look for known internal handlers 98 // Look for known internal handlers. 100 99 ksort( $this->handlers ); 101 100 foreach ( $this->handlers as $priority => $handlers ) { … … 137 136 $attr['discover'] = ( apply_filters( 'bp_embed_oembed_discover', false ) && current_user_can( 'unfiltered_html' ) ); 138 137 139 // Set up a new WP oEmbed object to check URL with registered oEmbed providers 138 // Set up a new WP oEmbed object to check URL with registered oEmbed providers. 140 139 require_once( ABSPATH . WPINC . '/class-oembed.php' ); 141 140 $oembed_obj = _wp_oembed_get_object(); 142 141 143 // If oEmbed discovery is true, skip oEmbed provider check 142 // If oEmbed discovery is true, skip oEmbed provider check. 144 143 $is_oembed_link = false; 145 144 if ( !$attr['discover'] ) { … … 151 150 } 152 151 153 // If url doesn't match a WP oEmbed provider, stop parsing 152 // If url doesn't match a WP oEmbed provider, stop parsing. 154 153 if ( !$is_oembed_link ) 155 154 return $this->maybe_make_link( $url ); … … 176 175 * @param array $rawattr Untouched shortcode attributes from 177 176 * {@link WP_Embed::shortcode()}. 178 *179 177 * @return string The embed HTML on success, otherwise the original URL. 180 178 */ … … 183 181 184 182 if ( $id ) { 185 // Setup the cachekey 183 // Setup the cachekey. 186 184 $cachekey = '_oembed_' . md5( $url . serialize( $attr ) ); 187 185 188 // Let components / plugins grab their cache 186 // Let components / plugins grab their cache. 189 187 $cache = ''; 190 188 … … 203 201 $cache = apply_filters( 'bp_embed_get_cache', $cache, $id, $cachekey, $url, $attr, $rawattr ); 204 202 205 // Grab cache and return it if available 203 // Grab cache and return it if available. 206 204 if ( !empty( $cache ) ) { 207 205 … … 218 216 return apply_filters( 'bp_embed_oembed_html', $cache, $url, $attr, $rawattr ); 219 217 220 // If no cache, ping the oEmbed provider and cache the result 218 // If no cache, ping the oEmbed provider and cache the result. 221 219 } else { 222 220 $html = wp_oembed_get( $url, $attr ); … … 236 234 do_action( 'bp_embed_update_cache', $cache, $cachekey, $id ); 237 235 238 // If there was a result, return it 236 // If there was a result, return it. 239 237 if ( $html ) { 240 238 … … 245 243 } 246 244 247 // Still unknown 245 // Still unknown. 248 246 return $this->maybe_make_link( $url ); 249 247 } -
trunk/src/bp-core/classes/class-bp-media-extractor.php
r10160 r10355 63 63 * @param int $what_to_extract Media type to extract (optional). 64 64 * @param array $extra_args Bespoke data for a particular extractor (optional). 65 *66 65 * @return array { 67 66 * @type array $has Extracted media counts. { … … 197 196 * @param string $plaintext Sanitized version of the content. 198 197 * @param array $extra_args Bespoke data for a particular extractor (optional). 199 *200 198 * @return array { 201 199 * @type array $has Extracted media counts. { … … 212 210 $data = array( 'has' => array( 'links' => 0 ), 'links' => array() ); 213 211 214 // Matches: href="text" and href='text' 212 // Matches: href="text" and href='text'. 215 213 if ( stripos( $richtext, 'href=' ) !== false ) { 216 214 preg_match_all( '#href=(["\'])([^"\']+)\1#i', $richtext, $matches ); … … 257 255 * @param string $plaintext Sanitized version of the content. 258 256 * @param array $extra_args Bespoke data for a particular extractor. 259 *260 257 * @return array { 261 258 * @type array $has Extracted media counts. { … … 292 289 } 293 290 294 // Build results 291 // Build results. 295 292 foreach ( $mentions as $user_id => $mention_name ) { 296 293 $mention = array( 'name' => strtolower( $mention_name ) ); … … 329 326 * @param string $plaintext Sanitized version of the content. 330 327 * @param array $extra_args Bespoke data for a particular extractor (optional). 331 *332 328 * @return array { 333 329 * @type array $has Extracted media counts. { … … 354 350 // `<img src>` tags. 355 351 if ( stripos( $richtext, 'src=' ) !== false ) { 356 preg_match_all( '#src=(["\'])([^"\']+)\1#i', $richtext, $img_srcs ); // matches src="text" and src='text'352 preg_match_all( '#src=(["\'])([^"\']+)\1#i', $richtext, $img_srcs ); // Matches src="text" and src='text'. 357 353 358 354 // <img>. … … 449 445 * @param string $plaintext Sanitized version of the content. 450 446 * @param array $extra_args Bespoke data for a particular extractor (optional). 451 *452 447 * @return array { 453 448 * @type array $has Extracted media counts. { … … 477 472 478 473 $shortcode = array(); 479 $shortcode['attributes'] = $attrs; // Attributes 480 $shortcode['content'] = $matches[5][ $i ]; // Content 481 $shortcode['type'] = $shortcode_name; // Shortcode 482 $shortcode['original'] = $matches[0][ $i ]; // Entire shortcode 474 $shortcode['attributes'] = $attrs; // Attributes. 475 $shortcode['content'] = $matches[5][ $i ]; // Content. 476 $shortcode['type'] = $shortcode_name; // Shortcode. 477 $shortcode['original'] = $matches[0][ $i ]; // Entire shortcode. 483 478 484 479 $data['shortcodes'][] = $shortcode; … … 511 506 * @param string $plaintext Sanitized version of the content. 512 507 * @param array $extra_args Bespoke data for a particular extractor (optional). 513 *514 508 * @return array { 515 509 * @type array $has Extracted media counts. { … … 591 585 * @param string $plaintext Sanitized version of the content. 592 586 * @param array $extra_args Bespoke data for a particular extractor (optional). 593 *594 587 * @return array { 595 588 * @type array $has Extracted media counts. { … … 644 637 } 645 638 646 // <a href="*.mp3"> tags 639 // <a href="*.mp3"> tags. 647 640 foreach ( $audio_types as $extension ) { 648 641 $extension = '.' . $extension; … … 689 682 * @param string $plaintext Sanitized version of the content. 690 683 * @param array $extra_args Bespoke data for a particular extractor (optional). 691 *692 684 * @return array { 693 685 * @type array $has Extracted media counts. { … … 768 760 * @param string $plaintext Sanitized version of the content. 769 761 * @param array $extra_args Bespoke data for a particular extractor (optional). 770 *771 762 * @return array 772 763 */ … … 794 785 $image_size = array( $extra_args['width'], $extra_args['height'] ); 795 786 } else { 796 $image_size = $extra_args['width']; // e.g. "thumb", "medium".787 $image_size = $extra_args['width']; // E.g. "thumb", "medium". 797 788 } 798 789 … … 868 859 * @param string $plaintext Sanitized version of the content. 869 860 * @param array $extra_args Contains data that an implementation might need beyond the defaults. 870 *871 861 * @return array 872 862 */ … … 890 880 $image_size = array( $extra_args['width'], $extra_args['height'] ); 891 881 } else { 892 $image_size = $extra_args['width']; // e.g. "thumb", "medium".882 $image_size = $extra_args['width']; // E.g. "thumb", "medium". 893 883 } 894 884 } else { … … 919 909 * @since 2.3.0 920 910 * 921 * @param string $richtext 922 * 911 * @param string $richtext Content to sanitize. 923 912 * @return string 924 913 */ -
trunk/src/bp-core/classes/class-bp-members-suggestions.php
r10108 r10355 84 84 public function get_suggestions() { 85 85 $user_query = array( 86 'count_total' => '', // Prevents total count 86 'count_total' => '', // Prevents total count. 87 87 'populate_extras' => false, 88 88 'type' => 'alphabetical', -
trunk/src/bp-core/classes/class-bp-suggestions.php
r10108 r10355 57 57 * Constructor. 58 58 * 59 * @since 2.1.0 60 * 59 61 * @param array $args Optional. If set, used as the parameters for the suggestions service query. 60 * @since 2.1.061 62 */ 62 63 public function __construct( array $args = array() ) { … … 69 70 * Set the parameters for the suggestions service query. 70 71 * 72 * @since 2.1.0 73 * 71 74 * @param array $args { 72 75 * @type int $limit Maximum number of results to display. Optional, default: 16. … … 75 78 * Mandatory. 76 79 * } 77 * @since 2.1.078 80 */ 79 81 public function set_query( array $args = array() ) { -
trunk/src/bp-core/classes/class-bp-user-query.php
r10248 r10355 147 147 public function __construct( $query = null ) { 148 148 149 // Store the raw query vars for later access 149 // Store the raw query vars for later access. 150 150 $this->query_vars_raw = $query; 151 151 152 // Allow extending classes to register action/filter hooks 152 // Allow extending classes to register action/filter hooks. 153 153 $this->setup_hooks(); 154 154 … … 184 184 185 185 // Get user ids 186 // If the user_ids param is present, we skip the query 186 // If the user_ids param is present, we skip the query. 187 187 if ( false !== $this->query_vars['user_ids'] ) { 188 188 $this->user_ids = wp_parse_id_list( $this->query_vars['user_ids'] ); … … 193 193 } 194 194 195 // Bail if no user IDs were found 195 // Bail if no user IDs were found. 196 196 if ( empty( $this->user_ids ) ) { 197 197 return; 198 198 } 199 199 200 // Fetch additional data. First, using WP_User_Query 200 // Fetch additional data. First, using WP_User_Query. 201 201 $this->do_wp_user_query(); 202 202 203 // Get BuddyPress specific user data 203 // Get BuddyPress specific user data. 204 204 $this->populate_extras(); 205 205 } … … 231 231 $bp = buddypress(); 232 232 233 // Default query variables used here 233 // Default query variables used here. 234 234 $type = ''; 235 235 $per_page = 0; … … 244 244 extract( $this->query_vars ); 245 245 246 // Setup the main SQL query container 246 // Setup the main SQL query container. 247 247 $sql = array( 248 248 'select' => '', … … 253 253 ); 254 254 255 /* *TYPE **************************************************************/255 /* TYPE **************************************************************/ 256 256 257 257 // Determines the sort order, which means it also determines where the 258 // user IDs are drawn from (the SELECT and WHERE statements) 258 // user IDs are drawn from (the SELECT and WHERE statements). 259 259 switch ( $type ) { 260 260 261 261 // 'online' query happens against the last_activity usermeta key 262 262 // Filter 'bp_user_query_online_interval' to modify the 263 // number of minutes used as an interval 263 // number of minutes used as an interval. 264 264 case 'online' : 265 265 $this->uid_name = 'user_id'; … … 282 282 283 283 // 'active', 'newest', and 'random' queries 284 // all happen against the last_activity usermeta key 284 // all happen against the last_activity usermeta key. 285 285 case 'active' : 286 286 case 'newest' : … … 303 303 break; 304 304 305 // 'popular' sorts by the 'total_friend_count' usermeta 305 // 'popular' sorts by the 'total_friend_count' usermeta. 306 306 case 'popular' : 307 307 $this->uid_name = 'user_id'; … … 314 314 break; 315 315 316 // 'alphabetical' sorts depend on the xprofile setup 316 // 'alphabetical' sorts depend on the xprofile setup. 317 317 case 'alphabetical' : 318 318 … … 321 321 // can do so if xprofile sync is enabled, or if xprofile is inactive. 322 322 // 323 // @todo remove need for bp_is_active() check 323 // @todo remove need for bp_is_active() check. 324 324 if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) { 325 325 $this->uid_name = 'ID'; … … 330 330 331 331 // When profile sync is disabled, alphabetical sorts must happen against 332 // the xprofile table 332 // the xprofile table. 333 333 } else { 334 334 $this->uid_name = 'user_id'; … … 347 347 break; 348 348 349 // Any other 'type' falls through 349 // Any other 'type' falls through. 350 350 default : 351 351 $this->uid_name = 'ID'; … … 355 355 // In this case, we assume that a plugin is 356 356 // handling order, so we leave those clauses 357 // blank 358 357 // blank. 359 358 break; 360 359 } 361 360 362 /* *WHERE *************************************************************/363 364 // 'include' - User ids to include in the results 361 /* WHERE *************************************************************/ 362 363 // 'include' - User ids to include in the results. 365 364 $include = false !== $include ? wp_parse_id_list( $include ) : array(); 366 365 $include_ids = $this->get_include_ids( $include ); … … 370 369 } 371 370 372 // 'exclude' - User ids to exclude from the results 371 // 'exclude' - User ids to exclude from the results. 373 372 if ( false !== $exclude ) { 374 373 $exclude_ids = implode( ',', wp_parse_id_list( $exclude ) ); … … 377 376 378 377 // 'user_id' - When a user id is passed, limit to the friends of the user 379 // @todo remove need for bp_is_active() check 378 // @todo remove need for bp_is_active() check. 380 379 if ( ! empty( $user_id ) && bp_is_active( 'friends' ) ) { 381 380 $friend_ids = friends_get_friend_user_ids( $user_id ); … … 386 385 387 386 // If the user has no friends, the query should always 388 // return no users 387 // return no users. 389 388 } else { 390 389 $sql['where'][] = $this->no_results['where']; … … 392 391 } 393 392 394 /* *Search Terms ******************************************************/393 /* Search Terms ******************************************************/ 395 394 396 395 // 'search_terms' searches user_login and user_nicename 397 // xprofile field matches happen in bp_xprofile_bp_user_query_search() 396 // xprofile field matches happen in bp_xprofile_bp_user_query_search(). 398 397 if ( false !== $search_terms ) { 399 398 $search_terms = bp_esc_like( wp_kses_normalize_entities( $search_terms ) ); … … 438 437 439 438 // 'meta_key', 'meta_value' allow usermeta search 440 // To avoid global joins, do a separate query 439 // To avoid global joins, do a separate query. 441 440 if ( false !== $meta_key ) { 442 441 $meta_sql = $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = %s", $meta_key ); … … 455 454 } 456 455 457 // 'per_page', 'page' - handles LIMIT 456 // 'per_page', 'page' - handles LIMIT. 458 457 if ( !empty( $per_page ) && !empty( $page ) ) { 459 458 $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) ); … … 472 471 $sql = apply_filters_ref_array( 'bp_user_query_uid_clauses', array( $sql, &$this ) ); 473 472 474 // Assemble the query chunks 473 // Assemble the query chunks. 475 474 $this->uid_clauses['select'] = $sql['select']; 476 475 $this->uid_clauses['where'] = ! empty( $sql['where'] ) ? 'WHERE ' . implode( ' AND ', $sql['where'] ) : ''; … … 502 501 global $wpdb; 503 502 504 // If counting using SQL_CALC_FOUND_ROWS, set it up here 503 // If counting using SQL_CALC_FOUND_ROWS, set it up here. 505 504 if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) { 506 505 $this->uid_clauses['select'] = str_replace( 'SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $this->uid_clauses['select'] ); 507 506 } 508 507 509 // Get the specific user ids 508 // Get the specific user ids. 510 509 $this->user_ids = $wpdb->get_col( "{$this->uid_clauses['select']} {$this->uid_clauses['where']} {$this->uid_clauses['orderby']} {$this->uid_clauses['order']} {$this->uid_clauses['limit']}" ); 511 510 512 // Get the total user count 511 // Get the total user count. 513 512 if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) { 514 513 … … 557 556 $wp_user_query = new WP_User_Query( apply_filters( 'bp_wp_user_query_args', array( 558 557 559 // Relevant 558 // Relevant. 560 559 'fields' => $fields, 561 560 'include' => $this->user_ids, 562 561 563 562 // Overrides 564 'blog_id' => 0, // BP does not require blog roles 565 'count_total' => false // We already have a count 563 'blog_id' => 0, // BP does not require blog roles. 564 'count_total' => false // We already have a count. 566 565 567 566 ), $this ) ); … … 583 582 } 584 583 585 // Reindex for easier matching 584 // Reindex for easier matching. 586 585 $r = array(); 587 586 foreach ( $wp_user_query->results as $u ) { … … 589 588 } 590 589 591 // Match up to the user ids from the main query 590 // Match up to the user ids from the main query. 592 591 foreach ( $this->user_ids as $key => $uid ) { 593 592 if ( isset( $r[ $uid ] ) ) { … … 595 594 596 595 // The BP template functions expect an 'id' 597 // (as opposed to 'ID') property 596 // (as opposed to 'ID') property. 598 597 $this->results[ $uid ]->id = $uid; 599 598 600 // remove user ID from original user_ids property599 // Remove user ID from original user_ids property. 601 600 } else { 602 601 unset( $this->user_ids[ $key ] ); … … 619 618 * @param array $include Sanitized array of user IDs, as passed to the 'include' 620 619 * parameter of the class constructor. 621 *622 620 * @return array The list of users to which the main query should be 623 621 * limited. … … 640 638 global $wpdb; 641 639 642 // Bail if no users 640 // Bail if no users. 643 641 if ( empty( $this->user_ids ) || empty( $this->results ) ) { 644 642 return; … … 647 645 // Bail if the populate_extras flag is set to false 648 646 // In the case of the 'popular' sort type, we force 649 // populate_extras to true, because we need the friend counts 647 // populate_extras to true, because we need the friend counts. 650 648 if ( 'popular' == $this->query_vars['type'] ) { 651 649 $this->query_vars['populate_extras'] = 1; … … 656 654 } 657 655 658 // Turn user ID's into a query-usable, comma separated value 656 // Turn user ID's into a query-usable, comma separated value. 659 657 $user_ids_sql = implode( ',', wp_parse_id_list( $this->user_ids ) ); 660 658 … … 679 677 do_action_ref_array( 'bp_user_query_populate_extras', array( $this, $user_ids_sql ) ); 680 678 681 // Fetch last_active data from the activity table 679 // Fetch last_active data from the activity table. 682 680 $last_activities = BP_Core_User::get_last_activity( $this->user_ids ); 683 681 684 // Set a last_activity value for each user, even if it's empty 682 // Set a last_activity value for each user, even if it's empty. 685 683 foreach ( $this->results as $user_id => $user ) { 686 684 $user_last_activity = isset( $last_activities[ $user_id ] ) ? $last_activities[ $user_id ]['date_recorded'] : ''; … … 691 689 // We want the three following pieces of info from usermeta: 692 690 // - friend count 693 // - latest update 691 // - latest update. 694 692 $total_friend_count_key = bp_get_user_meta_key( 'total_friend_count' ); 695 693 $bp_latest_update_key = bp_get_user_meta_key( 'bp_latest_update' ); 696 694 697 // total_friend_count must be set for each user, even if its698 // value is 0 695 // Total_friend_count must be set for each user, even if its 696 // value is 0. 699 697 foreach ( $this->results as $uindex => $user ) { 700 698 $this->results[$uindex]->total_friend_count = 0; 701 699 } 702 700 703 // Create, prepare, and run the separate usermeta query 701 // Create, prepare, and run the separate usermeta query. 704 702 $user_metas = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", $total_friend_count_key, $bp_latest_update_key ) ); 705 703 … … 723 721 724 722 // When meta_key or meta_value have been passed to the query, 725 // fetch the resulting values for use in the template functions 723 // fetch the resulting values for use in the template functions. 726 724 if ( ! empty( $this->query_vars['meta_key'] ) ) { 727 725 $meta_sql = array( … … 758 756 * @param string|array $member_types Array or comma-separated list of member types. 759 757 * @param string $operator 'IN' or 'NOT IN'. 760 *761 758 * @return string 762 759 */ … … 805 802 $clause = ''; 806 803 807 // no_results clauses are the same between IN and NOT IN.804 // The no_results clauses are the same between IN and NOT IN. 808 805 if ( false !== strpos( $sql_clauses['where'], '0 = 1' ) ) { 809 806 $clause = $this->no_results['where']; -
trunk/src/bp-core/classes/class-bp-walker-nav-menu-checklist.php
r10108 r10355 103 103 } 104 104 105 // Menu item hidden fields 105 // Menu item hidden fields. 106 106 $output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />'; 107 107 $output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />'; -
trunk/src/bp-core/classes/class-bp-walker-nav-menu.php
r10108 r10355 52 52 * @param array $elements See {@link Walker::walk()}. 53 53 * @param int $max_depth See {@link Walker::walk()}. 54 *55 54 * @return string See {@link Walker::walk()}. 56 55 */ … … 61 60 $output = ''; 62 61 63 if ( $max_depth < -1 ) // invalid parameter62 if ( $max_depth < -1 ) // Invalid parameter. 64 63 return $output; 65 64 66 if ( empty( $elements ) ) // nothing to walk65 if ( empty( $elements ) ) // Nothing to walk. 67 66 return $output; 68 67 69 68 $parent_field = $this->db_fields['parent']; 70 69 71 // flat display70 // Flat display. 72 71 if ( -1 == $max_depth ) { 73 72 … … 119 118 120 119 /* 121 * if we are displaying all levels, and remaining children_elements is not empty,122 * then we got orphans, which should be displayed regardless 120 * If we are displaying all levels, and remaining children_elements is not empty, 121 * then we got orphans, which should be displayed regardless. 123 122 */ 124 123 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) { … … 149 148 */ 150 149 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { 151 // If we're someway down the tree, indent the HTML with the appropriate number of tabs 150 // If we're someway down the tree, indent the HTML with the appropriate number of tabs. 152 151 $indent = $depth ? str_repeat( "\t", $depth ) : ''; 153 152 … … 165 164 166 165 // Add HTML ID 167 $id = sanitize_html_class( $item->css_id . '-personal-li' ); // Backpat with BP pre-1.7 166 $id = sanitize_html_class( $item->css_id . '-personal-li' ); // Backpat with BP pre-1.7. 168 167 169 168 /** … … 182 181 $output .= $indent . '<li' . $id . $class_names . '>'; 183 182 184 // Add href attribute 183 // Add href attribute. 185 184 $attributes = ! empty( $item->link ) ? ' href="' . esc_url( $item->link ) . '"' : ''; 186 185 187 // Construct the link 186 // Construct the link. 188 187 $item_output = $args->before; 189 188 $item_output .= '<a' . $attributes . '>';
Note: See TracChangeset
for help on using the changeset viewer.