Changeset 4462
- Timestamp:
- 06/05/2011 08:26:32 PM (14 years ago)
- Location:
- trunk/bp-core
- Files:
-
- 2 edited
-
bp-core-avatars.php (modified) (6 diffs)
-
bp-core-classes.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-avatars.php
r4400 r4462 279 279 } 280 280 281 /** 282 * Delete an existing avatar 283 * 284 * Accepted values for $args are: 285 * item_id - item id which relates to the object type. 286 * object - the objetc type user, group, blog, etc. 287 * avatar_dir - The directory where the avatars to be uploaded. 288 * 289 * @global object $bp BuddyPress global settings 290 * @param mixed $args 291 * @return bool Success/failure 292 */ 281 293 function bp_core_delete_existing_avatar( $args = '' ) { 282 294 global $bp; … … 337 349 } 338 350 351 /** 352 * Handles avatar uploading. 353 * 354 * The functions starts off by checking that the file has been uploaded properly using bp_core_check_avatar_upload(). 355 * It then checks that the file size is within limits, and that it has an accepted file extension (jpg, gif, png). 356 * If everything checks out, crop the image and move it to its real location. 357 * 358 * @global object $bp BuddyPress global settings 359 * @param array $file The appropriate entry the from $_FILES superglobal. 360 * @param string $upload_dir_filter A filter to be applied to upload_dir 361 * @return bool Success/failure 362 * @see bp_core_check_avatar_upload() 363 * @see bp_core_check_avatar_type() 364 */ 339 365 function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) { 340 366 global $bp; … … 422 448 } 423 449 450 /** 451 * Crop an uploaded avatar 452 * 453 * $args has the following parameters: 454 * object - What component the avatar is for, e.g. "user" 455 * avatar_dir The absolute path to the avatar 456 * item_id - Item ID 457 * original_file - The absolute path to the original avatar file 458 * crop_w - Crop width 459 * crop_h - Crop height 460 * crop_x - The horizontal starting point of the crop 461 * crop_y - The vertical starting point of the crop 462 * 463 * @global object $bp BuddyPress global settings 464 * @param mixed $args 465 * @return bool Success/failure 466 */ 424 467 function bp_core_avatar_handle_crop( $args = '' ) { 425 468 global $bp; … … 538 581 add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 ); 539 582 540 function bp_core_check_avatar_upload($file) { 583 /** 584 * Has the current avatar upload generated an error? 585 * 586 * @param array $file 587 * @return bool 588 */ 589 function bp_core_check_avatar_upload( $file ) { 541 590 if ( isset( $file['error'] ) && $file['error'] ) 542 591 return false; … … 545 594 } 546 595 547 function bp_core_check_avatar_size($file) { 596 /** 597 * Is the file size of the current avatar upload permitted? 598 * 599 * @param array $file 600 * @return bool 601 */ 602 function bp_core_check_avatar_size( $file ) { 548 603 if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE ) 549 604 return false; … … 552 607 } 553 608 609 /** 610 * Does the current avatar upload have an allowed file type? 611 * 612 * Permitted file types are JPG, GIF and PNG. 613 * 614 * @param string $file 615 * @return bool 616 */ 554 617 function bp_core_check_avatar_type($file) { 555 618 if ( ( !empty( $file['file']['type'] ) && !preg_match('/(jpe?g|gif|png)$/i', $file['file']['type'] ) ) || !preg_match( '/(jpe?g|gif|png)$/i', $file['file']['name'] ) ) -
trunk/bp-core/bp-core-classes.php
r4444 r4462 14 14 */ 15 15 class BP_Core_User { 16 17 /** 18 * ID of the user which the object relates to. 19 * 20 * @var integer 21 */ 16 22 var $id; 23 24 /** 25 * The URL to the full size of the avatar for the user. 26 * 27 * @var string 28 */ 17 29 var $avatar; 30 31 /** 32 * The URL to the thumb size of the avatar for the user. 33 * 34 * @var string 35 */ 18 36 var $avatar_thumb; 37 38 /** 39 * The URL to the mini size of the avatar for the user. 40 * 41 * @var string 42 */ 19 43 var $avatar_mini; 44 45 /** 46 * The full name of the user 47 * 48 * @var string 49 */ 20 50 var $fullname; 51 52 /** 53 * The email for the user. 54 * 55 * @var string 56 */ 21 57 var $email; 22 58 59 /** 60 * The absolute url for the user's profile. 61 * 62 * @var string 63 */ 23 64 var $user_url; 65 66 /** 67 * The HTML for the user link, with the link text being the user's full name. 68 * 69 * @var string 70 */ 24 71 var $user_link; 25 72 73 /** 74 * Contains a formatted string when the last time the user was active. 75 * 76 * Example: "active 2 hours and 50 minutes ago" 77 * 78 * @var string 79 */ 26 80 var $last_active; 27 81 28 82 /* Extras */ 83 84 /** 85 * The total number of "Friends" the user has on site. 86 * 87 * @var integer 88 */ 29 89 var $total_friends; 90 91 /** 92 * The total number of blog posts posted by the user 93 * 94 * @var integer 95 */ 30 96 var $total_blogs; 97 98 /** 99 * The total number of groups the user is a part of. 100 * 101 * Example: "1 group", "2 groups" 102 * 103 * @var string 104 */ 31 105 var $total_groups; 32 106 107 /** 108 * PHP4 constructor. 109 * 110 * @see BP_Core_User::__construct() 111 */ 33 112 function bp_core_user( $user_id, $populate_extras = false ) { 34 113 $this->__construct( $user_id, $populate_extras ); 35 114 } 36 115 37 function __construct( $user_id, $populate_extras = false ) { 116 /** 117 * Class constructor. 118 * 119 * @param integer $user_id The ID for the user 120 * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not. 121 */ 122 function __construct( $user_id, $populate_extras = false ) { 38 123 if ( $user_id ) { 39 124 $this->id = $user_id; … … 46 131 47 132 /** 48 * populate()49 *50 133 * Populate the instantiated class with data based on the User ID provided. 51 134 * 52 * @package BuddyPress Core 53 * @global $userdata WordPress user data for the current logged in user. 135 * @global object $bp Global BuddyPress settings object 54 136 * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id 55 137 * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text … … 61 143 function populate() { 62 144 global $bp; 63 145 64 146 if ( bp_is_active( 'xprofile' ) ) 65 147 $this->profile_data = $this->get_profile_data(); … … 88 170 } 89 171 172 /** 173 * Populates extra fields such as group and friendship counts. 174 * 175 * @global object $bp Global BuddyPress settings object 176 */ 90 177 function populate_extras() { 91 178 global $bp; … … 96 183 if ( bp_is_active( 'groups' ) ) { 97 184 $this->total_groups = BP_Groups_Member::total_group_count( $this->id ); 98 99 if ( $this->total_groups ) { 100 if ( 1 == $this->total_groups ) 101 $this->total_groups .= ' ' . __( 'group', 'buddypress' ); 102 else 103 $this->total_groups .= ' ' . __( 'groups', 'buddypress' ); 104 } 185 $this->total_groups = sprintf( _n( '%d group', '%d groups', $this->total_groups ), $this->total_groups ); 105 186 } 106 187 } … … 127 208 if ( 'alphabetical' == $type ) 128 209 $sql['select_alpha'] = ", pd.value as fullname"; 129 210 130 211 if ( $meta_key ) { 131 212 $sql['select_meta'] = ", umm.meta_key"; 132 213 133 214 if ( $meta_value ) 134 215 $sql['select_meta'] .= ", umm.meta_value"; … … 139 220 if ( $search_terms && bp_is_active( 'xprofile' ) || 'alphabetical' == $type ) 140 221 $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id"; 141 222 142 223 if ( $meta_key ) 143 224 $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID"; … … 187 268 $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'"; 188 269 } 189 270 190 271 if ( $meta_key ) { 191 272 $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key ); 192 273 193 274 // If a meta value is provided, match it 194 275 if ( $meta_value ) { … … 262 343 } 263 344 264 function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = false ) { 265 global $wpdb, $bp; 345 346 /** 347 * Fetches the user details for all the users who username starts with the letter given. 348 * 349 * @global object $bp Global BuddyPress settings object 350 * @global wpdb $wpdb WordPress database object 351 * @param string $letter The letter the users names are to start with. 352 * @param integer $limit The number of users we wish to retrive. 353 * @param integer $page The page number we are currently on, used in conjunction with $limit to get the start position for the limit. 354 * @param boolean $populate_extras Populate extra user fields? 355 * @param string $exclude Comma-separated IDs of users whose results aren't to be fetched. 356 * @return mixed False on error, otherwise associative array of results. 357 * @static 358 */ 359 function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) { 360 global $bp, $wpdb; 266 361 267 362 $pag_sql = ''; … … 308 403 } 309 404 405 /** 406 * Get details of specific users from the database 407 * 408 * @global object $bp Global BuddyPress settings object 409 * @global wpdb $wpdb WordPress database object 410 * @param array $user_ids The user IDs of the users who we wish to fetch information on. 411 * @param integer $limit The limit of results we want. 412 * @param integer $page The page we are on for pagination. 413 * @param boolean $populate_extras Populate extra user fields? 414 * @return array Associative array 415 * @static 416 */ 310 417 function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) { 311 global $ wpdb, $bp;418 global $bp, $wpdb; 312 419 313 420 $pag_sql = ''; … … 336 443 } 337 444 445 /** 446 * Find users who match on the value of an xprofile data. 447 * 448 * @global object $bp Global BuddyPress settings object 449 * @global wpdb $wpdb WordPress database object 450 * @param string $search_terms The terms to search the profile table value column for. 451 * @param integer $limit The limit of results we want. 452 * @param integer $page The page we are on for pagination. 453 * @param boolean $populate_extras Populate extra user fields? 454 * @return array Associative array 455 * @static 456 */ 338 457 function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) { 339 global $ wpdb, $bp;458 global $bp, $wpdb; 340 459 341 460 if ( $limit && $page ) … … 367 486 } 368 487 488 /** 489 * Fetch extra user information, such as friend count and last profile update message. 490 * 491 * Accepts multiple user IDs to fetch data for. 492 * 493 * @global object $bp Global BuddyPress settings object 494 * @global wpdb $wpdb WordPress database object 495 * @param array $paged_users an array of stdClass containing the users 496 * @param string $user_ids the user ids to select information about 497 * @param string $type the type of fields we wish to get 498 * @return mixed False on error, otherwise associative array of results. 499 * @static 500 */ 369 501 function get_user_extras( &$paged_users, &$user_ids, $type = false ) { 370 502 global $bp, $wpdb; … … 439 571 } 440 572 573 /** 574 * Get WordPress user details for a specified user. 575 * 576 * @global wpdb $wpdb WordPress database object 577 * @param integer $user_id User ID 578 * @return array Associative array 579 * @static 580 */ 441 581 function get_core_userdata( $user_id ) { 442 582 global $wpdb; … … 458 598 459 599 class BP_Core_Notification { 600 601 /** 602 * The notification id 603 * 604 * @var integer 605 */ 460 606 var $id; 607 608 /** 609 * The ID to which the notification relates to within the component. 610 * 611 * @var integer 612 */ 461 613 var $item_id; 614 615 /** 616 * The secondary ID to which the notification relates to within the component. 617 * 618 * @var integer 619 */ 462 620 var $secondary_item_id = null; 621 622 /** 623 * The user ID for who the notification is for. 624 * 625 * @var integer 626 */ 463 627 var $user_id; 628 629 /** 630 * The name of the component that the notification is for. 631 * 632 * @var string 633 */ 464 634 var $component_name; 635 636 /** 637 * The action within the component which the notification is related to. 638 * 639 * @var string 640 */ 465 641 var $component_action; 642 643 /** 644 * The date the notification was created. 645 * 646 * @var string 647 */ 466 648 var $date_notified; 649 650 /** 651 * Is the notification new or has it already been read. 652 * 653 * @var boolean 654 */ 467 655 var $is_new; 468 656 469 function bp_core_notification( $id = false ) { 657 658 /** 659 * PHP4 constructor 660 * 661 * @param integer $id 662 */ 663 function bp_core_notification( $id = 0 ) { 470 664 $this->__construct($id); 471 665 } 472 473 function __construct( $id = false ) { 666 667 /** 668 * Constructor 669 * 670 * @param integer $id 671 */ 672 function __construct( $id = 0 ) { 474 673 if ( $id ) { 475 674 $this->id = $id; … … 478 677 } 479 678 679 /** 680 * Fetches the notification data from the database. 681 * 682 * @global object $bp Global BuddyPress settings object 683 * @global wpdb $wpdb WordPress database object 684 */ 480 685 function populate() { 481 global $ wpdb, $bp;686 global $bp, $wpdb; 482 687 483 688 if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) { … … 492 697 } 493 698 699 /** 700 * Update or insert notification details into the database. 701 * 702 * @global object $bp Global BuddyPress settings object 703 * @global wpdb $wpdb WordPress database object 704 * @return bool Success or failure 705 */ 494 706 function save() { 495 global $ wpdb, $bp;707 global $bp, $wpdb; 496 708 497 709 // Update … … 518 730 } 519 731 732 /** 733 * Fetches all the notifications in the database for a specific user. 734 * 735 * @global object $bp Global BuddyPress settings object 736 * @global wpdb $wpdb WordPress database object 737 * @param integer $user_id User ID 738 * @return array Associative array 739 * @static 740 */ 520 741 function get_all_for_user( $user_id ) { 521 global $ wpdb, $bp;742 global $bp, $wpdb; 522 743 523 744 return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) ); 524 745 } 525 746 747 /** 748 * Delete all the notifications for a user based on the component name and action. 749 * 750 * @global object $bp Global BuddyPress settings object 751 * @global wpdb $wpdb WordPress database object 752 * @param integer $user_id 753 * @param string $component_name 754 * @param string $component_action 755 * @static 756 */ 526 757 function delete_for_user_by_type( $user_id, $component_name, $component_action ) { 527 global $ wpdb, $bp;758 global $bp, $wpdb; 528 759 529 760 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 530 761 } 531 762 763 /** 764 * Delete all the notifications that have a specific item id, component name and action. 765 * 766 * @global object $bp Global BuddyPress settings object 767 * @global wpdb $wpdb WordPress database object 768 * @param integer $user_id The ID of the user who the notifications are for. 769 * @param integer $item_id The item ID of the notifications we wish to delete. 770 * @param string $component_name The name of the component that the notifications we wish to delete. 771 * @param string $component_action The action of the component that the notifications we wish to delete. 772 * @param integer $secondary_item_id (optional) The secondary item id of the notifications that we wish to use to delete. 773 * @static 774 */ 532 775 function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) { 533 global $ wpdb, $bp;776 global $bp, $wpdb; 534 777 535 778 $secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : ''; … … 538 781 } 539 782 783 /** 784 * Deletes all the notifications sent by a specific user, by component and action. 785 * 786 * @global object $bp Global BuddyPress settings object 787 * @global wpdb $wpdb WordPress database object 788 * @param integer $user_id The ID of the user whose sent notifications we wish to delete. 789 * @param string $component_name The name of the component the notification was sent from. 790 * @param string $component_action The action of the component the notification was sent from. 791 * @static 792 */ 540 793 function delete_from_user_by_type( $user_id, $component_name, $component_action ) { 541 global $ wpdb, $bp;794 global $bp, $wpdb; 542 795 543 796 return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) ); 544 797 } 545 798 799 /** 800 * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action. 801 * 802 * @global object $bp Global BuddyPress settings object 803 * @global wpdb $wpdb WordPress database object 804 * @param string $item_id The item id that they notifications are to be for. 805 * @param string $component_name The component that the notifications are to be from. 806 * @param string $component_action The action that the notificationsa are to be from. 807 * @param string $secondary_item_id Optional secondary item id that the notifications are to have. 808 * @static 809 */ 546 810 function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) { 547 global $ wpdb, $bp;811 global $bp, $wpdb; 548 812 549 813 if ( $component_action ) … … 570 834 */ 571 835 class BP_Button { 572 573 836 // Button properties 837 838 /** 839 * The button ID 840 * 841 * @var integer 842 */ 574 843 var $id; 844 845 /** 846 * The component name that button belongs to. 847 * 848 * @var string 849 */ 575 850 var $component; 851 852 /** 853 * Does the user need to be logged in to see this button? 854 * 855 * @var boolean 856 */ 576 857 var $must_be_logged_in; 858 859 /** 860 * True or false if the button should not be displayed while viewing your own profile. 861 * 862 * @var boolean 863 */ 577 864 var $block_self; 578 865 866 579 867 // Wrapper 868 869 /** 870 * What type of DOM element to use for a wrapper. 871 * 872 * 873 * @var mixed div|span|p|li, or false for no wrapper 874 */ 580 875 var $wrapper; 876 877 /** 878 * The DOM class of the button wrapper 879 * 880 * @var string 881 */ 581 882 var $wrapper_class; 883 884 /** 885 * The DOM ID of the button wrapper 886 * 887 * @var string 888 */ 582 889 var $wrapper_id; 583 890 891 584 892 // Button 893 894 /** 895 * The destination link of the button 896 * 897 * @var string 898 */ 585 899 var $link_href; 900 901 /** 902 * The DOM class of the button link 903 * 904 * @var string 905 */ 586 906 var $link_class; 907 908 /** 909 * The DOM ID of the button link 910 * 911 * @var string 912 */ 587 913 var $link_id; 914 915 /** 916 * The DOM rel value of the button link 917 * 918 * @var string 919 */ 588 920 var $link_rel; 921 922 /** 923 * Title of the button link 924 * 925 * @var string 926 */ 589 927 var $link_title; 928 929 /** 930 * The contents of the button link 931 * 932 * @var string 933 */ 590 934 var $link_text; 591 935 936 592 937 // HTML result 938 593 939 var $contents; 594 940 … … 617 963 $this->__construct($args); 618 964 } 619 965 620 966 function __construct( $args = '' ) { 621 967
Note: See TracChangeset
for help on using the changeset viewer.