Changeset 5708 for trunk/bp-core/bp-core-classes.php
- Timestamp:
- 02/11/2012 04:18:44 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-classes.php
r5683 r5708 109 109 var $total_groups; 110 110 111 /** 112 * PHP4 constructor. 113 * 114 * @see BP_Core_User::__construct() 115 */ 116 function bp_core_user( $user_id, $populate_extras = false ) { 117 $this->__construct( $user_id, $populate_extras ); 118 } 111 /** Public Method*s *******************************************************/ 119 112 120 113 /** … … 124 117 * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not. 125 118 */ 126 function __construct( $user_id, $populate_extras = false ) {127 if ( $user_id) {119 public function __construct( $user_id, $populate_extras = false ) { 120 if ( !empty( $user_id ) ) { 128 121 $this->id = $user_id; 129 122 $this->populate(); 130 123 131 if ( $populate_extras )124 if ( !empty( $populate_extras ) ) { 132 125 $this->populate_extras(); 133 } 134 } 126 } 127 } 128 } 129 130 /** Private Methods *******************************************************/ 135 131 136 132 /** … … 144 140 * @uses bp_profile_last_updated_date() Returns the last updated date for a user. 145 141 */ 146 function populate() {142 private function populate() { 147 143 148 144 if ( bp_is_active( 'xprofile' ) ) … … 177 173 * Populates extra fields such as group and friendship counts. 178 174 */ 179 function populate_extras() {175 private function populate_extras() { 180 176 181 177 if ( bp_is_active( 'friends' ) ) { … … 189 185 } 190 186 191 function get_profile_data() {187 private function get_profile_data() { 192 188 return BP_XProfile_ProfileData::get_all_for_user( $this->id ); 193 189 } 194 190 195 /** Static Functions******************************************************/196 197 function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {191 /** Static Methods ********************************************************/ 192 193 public static function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) { 198 194 global $wpdb, $bp; 199 195 … … 222 218 } 223 219 224 $sql['from'] = "FROM $wpdb->users u LEFT JOIN $wpdb->usermetaum ON um.user_id = u.ID";220 $sql['from'] = "FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} um ON um.user_id = u.ID"; 225 221 226 222 // We search against xprofile fields, so we must join the table … … 260 256 } 261 257 262 if ( $include) {258 if ( !empty( $include ) ) { 263 259 if ( is_array( $include ) ) { 264 260 $uids = $wpdb->escape( implode( ',', (array)$include ) ); … … 270 266 $sql['where_users'] = "AND u.ID IN ({$uids})"; 271 267 } 272 } elseif ( $user_id&& bp_is_active( 'friends' ) ) {268 } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) { 273 269 $friend_ids = friends_get_friend_user_ids( $user_id ); 274 270 $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) ); … … 283 279 } 284 280 285 if ( $search_terms&& bp_is_active( 'xprofile' ) ) {281 if ( !empty( $search_terms ) && bp_is_active( 'xprofile' ) ) { 286 282 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 287 283 $sql['where_searchterms'] = "AND spd.value LIKE '%%$search_terms%%'"; 288 284 } 289 285 290 if ( $meta_key) {286 if ( !empty( $meta_key ) ) { 291 287 $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key ); 292 288 … … 315 311 } 316 312 317 if ( $limit && $page) {313 if ( !empty( $limit ) && !empty( $page ) ) { 318 314 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 319 315 } … … 382 378 * @static 383 379 */ 384 function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {380 public static function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) { 385 381 global $bp, $wpdb; 386 382 … … 444 440 * @static 445 441 */ 446 function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {442 public static function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) { 447 443 global $wpdb; 448 444 … … 489 485 * @static 490 486 */ 491 function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {487 public static function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) { 492 488 global $bp, $wpdb; 493 489 … … 532 528 * @static 533 529 */ 534 function get_user_extras( &$paged_users, &$user_ids, $type = false ) {530 public static function get_user_extras( &$paged_users, &$user_ids, $type = false ) { 535 531 global $bp, $wpdb; 536 532 … … 612 608 * @static 613 609 */ 614 function get_core_userdata( $user_id ) {610 public static function get_core_userdata( $user_id ) { 615 611 global $wpdb; 616 612 … … 688 684 var $is_new; 689 685 690 691 /** 692 * PHP4 constructor 686 /** Public Methods ********************************************************/ 687 688 /** 689 * Constructor 693 690 * 694 691 * @param integer $id 695 692 */ 696 function bp_core_notification( $id = 0 ) { 697 $this->__construct($id); 698 } 699 700 /** 701 * Constructor 702 * 703 * @param integer $id 704 */ 705 function __construct( $id = 0 ) { 706 if ( $id ) { 693 public function __construct( $id = 0 ) { 694 if ( !empty( $id ) ) { 707 695 $this->id = $id; 708 696 $this->populate(); … … 711 699 712 700 /** 713 * Fetches the notification data fromthe database.701 * Update or insert notification details into the database. 714 702 * 715 703 * @global object $bp Global BuddyPress settings object 716 704 * @global wpdb $wpdb WordPress database object 717 */ 718 function populate() { 705 * @return bool Success or failure 706 */ 707 public function save() { 708 global $bp, $wpdb; 709 710 // Update 711 if ( !empty( $this->id ) ) { 712 $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 ); 713 714 // Save 715 } else { 716 $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 ); 717 } 718 719 if ( !$result = $wpdb->query( $sql ) ) 720 return false; 721 722 $this->id = $wpdb->insert_id; 723 724 return true; 725 } 726 727 /** Private Methods *******************************************************/ 728 729 /** 730 * Fetches the notification data from the database. 731 * 732 * @global object $bp Global BuddyPress settings object 733 * @global wpdb $wpdb WordPress database object 734 */ 735 private function populate() { 719 736 global $bp, $wpdb; 720 737 … … 730 747 } 731 748 732 /** 733 * Update or insert notification details into the database. 734 * 735 * @global object $bp Global BuddyPress settings object 736 * @global wpdb $wpdb WordPress database object 737 * @return bool Success or failure 738 */ 739 function save() { 740 global $bp, $wpdb; 741 742 // Update 743 if ( $this->id ) 744 $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 ); 745 746 // Save 747 else 748 $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 ); 749 750 if ( !$result = $wpdb->query( $sql ) ) 751 return false; 752 753 $this->id = $wpdb->insert_id; 754 return true; 755 } 756 757 /** Static functions ******************************************************/ 758 759 function check_access( $user_id, $notification_id ) { 749 /** Static Methods ********************************************************/ 750 751 public static function check_access( $user_id, $notification_id ) { 760 752 global $wpdb, $bp; 761 753 … … 773 765 * @static 774 766 */ 775 function get_all_for_user( $user_id, $status = 'is_new' ) {767 public static function get_all_for_user( $user_id, $status = 'is_new' ) { 776 768 global $bp, $wpdb; 777 769 … … 791 783 * @static 792 784 */ 793 function delete_for_user_by_type( $user_id, $component_name, $component_action ) {785 public static function delete_for_user_by_type( $user_id, $component_name, $component_action ) { 794 786 global $bp, $wpdb; 795 787 … … 809 801 * @static 810 802 */ 811 function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {803 public static function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) { 812 804 global $bp, $wpdb; 813 805 … … 827 819 * @static 828 820 */ 829 function delete_from_user_by_type( $user_id, $component_name, $component_action ) {821 public static function delete_from_user_by_type( $user_id, $component_name, $component_action ) { 830 822 global $bp, $wpdb; 831 823 … … 844 836 * @static 845 837 */ 846 function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {838 public static function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) { 847 839 global $bp, $wpdb; 848 840 … … 996 988 * @return bool False if not allowed 997 989 */ 998 function bp_button( $args = '' ) { 999 $this->__construct($args); 1000 } 1001 1002 function __construct( $args = '' ) { 990 public function __construct( $args = '' ) { 1003 991 1004 992 // Default arguments … … 1104 1092 * @return string 1105 1093 */ 1106 function contents() {1094 public function contents() { 1107 1095 return $this->contents; 1108 1096 } … … 1113 1101 * Output contents of button 1114 1102 */ 1115 function display() {1103 public function display() { 1116 1104 if ( !empty( $this->contents ) ) 1117 1105 echo $this->contents; … … 1129 1117 */ 1130 1118 class BP_Embed extends WP_Embed { 1119 1131 1120 /** 1132 1121 * Constructor … … 1134 1123 * @global unknown $wp_embed 1135 1124 */ 1136 function __construct() {1125 public function __construct() { 1137 1126 global $wp_embed; 1138 1127 … … 1183 1172 * @return string The embed HTML on success, otherwise the original URL. 1184 1173 */ 1185 function shortcode( $attr, $url = '' ) {1174 public function shortcode( $attr, $url = '' ) { 1186 1175 if ( empty( $url ) ) 1187 1176 return ''; … … 1248 1237 * @return string The embed HTML on success, otherwise the original URL. 1249 1238 */ 1250 function parse_oembed( $id, $url, $attr, $rawattr ) {1239 public function parse_oembed( $id, $url, $attr, $rawattr ) { 1251 1240 $id = intval( $id ); 1252 1241 … … 1281 1270 } 1282 1271 } 1272 1283 1273 ?>
Note: See TracChangeset
for help on using the changeset viewer.