Changeset 5713 for trunk/bp-groups/bp-groups-classes.php
- Timestamp:
- 02/11/2012 04:57:20 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-classes.php
r5697 r5713 17 17 var $total_member_count; 18 18 19 function bp_groups_group( $id = null ) { 20 $this->__construct($id); 21 } 22 23 function __construct( $id = null ) { 24 if ( $id ) { 19 public function __construct( $id = null ) { 20 if ( !empty( $id ) ) { 25 21 $this->id = $id; 26 22 $this->populate(); … … 28 24 } 29 25 30 function populate() {26 private function populate() { 31 27 global $wpdb, $bp; 32 28 … … 67 63 } 68 64 69 function save() {65 public function save() { 70 66 global $wpdb, $bp; 71 67 … … 138 134 } 139 135 140 function delete() {136 public function delete() { 141 137 global $wpdb, $bp; 142 138 … … 165 161 } 166 162 167 /* Static Functions*/168 169 function group_exists( $slug, $table_name = false ) {170 global $wpdb, $bp; 171 172 if ( !$table_name)163 /** Static Methods ********************************************************/ 164 165 public static function group_exists( $slug, $table_name = false ) { 166 global $wpdb, $bp; 167 168 if ( empty( $table_name ) ) 173 169 $table_name = $bp->groups->table_name; 174 170 175 if ( !$slug)171 if ( empty( $slug ) ) 176 172 return false; 177 173 … … 179 175 } 180 176 181 function get_id_from_slug( $slug ) {177 public static function get_id_from_slug( $slug ) { 182 178 return BP_Groups_Group::group_exists( $slug ); 183 179 } … … 188 184 } 189 185 190 function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) {186 public static function filter_user_groups( $filter, $user_id = 0, $order = false, $limit = null, $page = null ) { 191 187 global $wpdb, $bp; 192 188 … … 196 192 $filter = like_escape( $wpdb->escape( $filter ) ); 197 193 198 if ( $limit && $page)194 if ( !empty( $limit ) && !empty( $page ) ) 199 195 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 200 196 … … 202 198 $gids = BP_Groups_Member::get_group_ids( $user_id ); 203 199 204 if ( !$gids['groups'])200 if ( empty( $gids['groups'] ) ) 205 201 return false; 206 202 … … 213 209 } 214 210 215 function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) {211 public static function search_groups( $filter, $limit = null, $page = null, $sort_by = false, $order = false ) { 216 212 global $wpdb, $bp; 217 213 218 214 $filter = like_escape( $wpdb->escape( $filter ) ); 219 215 220 if ( $limit && $page)216 if ( !empty( $limit ) && !empty( $page ) ) 221 217 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 222 218 223 if ( $sort_by && $order) {224 $sort_by = $wpdb->escape( $sort_by );225 $order = $wpdb->escape( $order );219 if ( !empty( $sort_by ) && !empty( $order ) ) { 220 $sort_by = $wpdb->escape( $sort_by ); 221 $order = $wpdb->escape( $order ); 226 222 $order_sql = "ORDER BY $sort_by $order"; 227 223 } … … 236 232 } 237 233 238 function check_slug( $slug ) {234 public static function check_slug( $slug ) { 239 235 global $wpdb, $bp; 240 236 … … 242 238 } 243 239 244 function get_slug( $group_id ) {240 public static function get_slug( $group_id ) { 245 241 global $wpdb, $bp; 246 242 … … 248 244 } 249 245 250 function has_members( $group_id ) {246 public static function has_members( $group_id ) { 251 247 global $wpdb, $bp; 252 248 253 249 $members = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) ); 254 250 255 if ( !$members)251 if ( empty( $members ) ) 256 252 return false; 257 253 … … 259 255 } 260 256 261 function has_membership_requests( $group_id ) {257 public static function has_membership_requests( $group_id ) { 262 258 global $wpdb, $bp; 263 259 … … 265 261 } 266 262 267 function get_membership_requests( $group_id, $limit = null, $page = null ) {268 global $wpdb, $bp; 269 270 if ( $limit && $page) {263 public static function get_membership_requests( $group_id, $limit = null, $page = null ) { 264 global $wpdb, $bp; 265 266 if ( !empty( $limit ) && !empty( $page ) ) { 271 267 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 272 268 } … … 278 274 } 279 275 280 function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) { 281 global $wpdb, $bp; 282 283 $sql = array(); 276 public static function get( $type = 'newest', $per_page = null, $page = null, $user_id = 0, $search_terms = false, $include = false, $populate_extras = true, $exclude = false, $show_hidden = false ) { 277 global $wpdb, $bp; 278 279 $sql = array(); 280 $total_sql = array(); 284 281 285 282 $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity"; … … 341 338 } 342 339 343 if ( $per_page && $page)340 if ( !empty( $per_page ) && !empty( $page ) ) 344 341 $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) ); 345 342 … … 379 376 $t_sql .= " WHERE " . join( ' AND ', (array)$total_sql['where'] ); 380 377 381 / * Get total group results */378 // Get total group results 382 379 $total_groups_sql = apply_filters( 'bp_groups_get_total_groups_sql', join( ' ', (array)$t_sql ), $t_sql ); 383 380 $total_groups = $wpdb->get_var( $total_groups_sql ); … … 388 385 } 389 386 390 / * Populate some extra information instead of querying each time in the loop */387 // Populate some extra information instead of querying each time in the loop 391 388 if ( !empty( $populate_extras ) ) { 392 389 $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) ); … … 402 399 } 403 400 404 function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {401 public static function get_by_most_forum_topics( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) { 405 402 global $wpdb, $bp, $bbdb; 406 403 407 if ( !$bbdb)404 if ( empty( $bbdb ) ) 408 405 do_action( 'bbpress_init' ); 409 406 410 if ( $limit && $page) {407 if ( !empty( $limit ) && !empty( $page ) ) { 411 408 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 412 409 } … … 425 422 } 426 423 427 if ( $user_id) {424 if ( !empty( $user_id ) ) { 428 425 $user_id = $wpdb->escape( $user_id ); 429 426 $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) AND f.topics > 0 {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.topics DESC {$pag_sql}" ); … … 443 440 } 444 441 445 function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) {442 public static function get_by_most_forum_posts( $limit = null, $page = null, $search_terms = false, $populate_extras = true, $exclude = false ) { 446 443 global $wpdb, $bp, $bbdb; 447 444 448 if ( !$bbdb)445 if ( empty( $bbdb ) ) 449 446 do_action( 'bbpress_init' ); 450 447 451 if ( $limit && $page) {448 if ( !empty( $limit ) && !empty( $page ) ) { 452 449 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 453 450 } … … 456 453 $hidden_sql = " AND g.status != 'hidden'"; 457 454 458 if ( $search_terms) {455 if ( !empty( $search_terms ) ) { 459 456 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 460 457 $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; … … 466 463 } 467 464 468 if ( $user_id) {465 if ( !empty( $user_id ) ) { 469 466 $user_id = $wpdb->escape( $user_id ); 470 467 $paged_groups = $wpdb->get_results( "SELECT DISTINCT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name_members} m, {$bbdb->forums} f, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND (gm3.meta_key = 'forum_id' AND gm3.meta_value = f.forum_id) {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY f.posts ASC {$pag_sql}" ); … … 484 481 } 485 482 486 function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) {483 public static function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true, $exclude = false ) { 487 484 global $wpdb, $bp; 488 485 … … 508 505 $letter = like_escape( $wpdb->escape( $letter ) ); 509 506 510 if ( $limit && $page) {507 if ( !empty( $limit ) && !empty( $page ) ) { 511 508 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 512 509 $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} {$exclude_sql}" ) ); … … 524 521 } 525 522 526 function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) {527 global $wpdb, $bp; 528 529 if ( $limit && $page)523 public static function get_random( $limit = null, $page = null, $user_id = 0, $search_terms = false, $populate_extras = true, $exclude = false ) { 524 global $wpdb, $bp; 525 526 if ( !empty( $limit ) && !empty( $page ) ) 530 527 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 531 528 … … 533 530 $hidden_sql = "AND g.status != 'hidden'"; 534 531 535 if ( $search_terms) {532 if ( !empty( $search_terms ) ) { 536 533 $search_terms = like_escape( $wpdb->escape( $search_terms ) ); 537 534 $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; … … 543 540 } 544 541 545 if ( $user_id) {542 if ( !empty( $user_id ) ) { 546 543 $user_id = $wpdb->escape( $user_id ); 547 544 $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 {$exclude_sql} ORDER BY rand() {$pag_sql}" ); … … 561 558 } 562 559 563 function get_group_extras( &$paged_groups, &$group_ids, $type = false ) {560 public static function get_group_extras( &$paged_groups, &$group_ids, $type = false ) { 564 561 global $bp, $wpdb; 565 562 … … 567 564 return $paged_groups; 568 565 569 / * Fetch the logged in users status within each group */566 // Fetch the logged in users status within each group 570 567 $user_status = $wpdb->get_col( $wpdb->prepare( "SELECT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id IN ( {$group_ids} ) AND is_confirmed = 1 AND is_banned = 0", bp_loggedin_user_id() ) ); 571 568 for ( $i = 0, $count = count( $paged_groups ); $i < $count; ++$i ) { … … 573 570 574 571 foreach ( (array)$user_status as $group_id ) { 575 if ( $group_id == $paged_groups[$i]->id ) 572 if ( $group_id == $paged_groups[$i]->id ) { 576 573 $paged_groups[$i]->is_member = true; 574 } 577 575 } 578 576 } … … 583 581 584 582 foreach ( (array)$user_banned as $group_id ) { 585 if ( $group_id == $paged_groups[$i]->id ) 583 if ( $group_id == $paged_groups[$i]->id ) { 586 584 $paged_groups[$i]->is_banned = true; 585 } 587 586 } 588 587 } … … 591 590 } 592 591 593 function delete_all_invites( $group_id ) {592 public static function delete_all_invites( $group_id ) { 594 593 global $wpdb, $bp; 595 594 … … 597 596 } 598 597 599 function get_total_group_count() {598 public static function get_total_group_count() { 600 599 global $wpdb, $bp; 601 600 … … 607 606 } 608 607 609 function get_global_forum_topic_count( $type ) {608 public static function get_global_forum_topic_count( $type ) { 610 609 global $bbdb, $wpdb, $bp; 611 610 … … 618 617 } 619 618 620 function get_total_member_count( $group_id ) {619 public static function get_total_member_count( $group_id ) { 621 620 global $wpdb, $bp; 622 621 623 622 return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) ); 624 623 } 625 626 624 627 625 /** … … 634 632 * @return int The topic count 635 633 */ 636 function get_global_topic_count( $status = 'public', $search_terms = false ) {634 public static function get_global_topic_count( $status = 'public', $search_terms = false ) { 637 635 global $bbdb, $wpdb, $bp; 638 636 … … 686 684 var $comments; 687 685 var $invite_sent; 688 689 686 var $user; 690 687 691 function bp_groups_member( $user_id = 0, $group_id = 0, $id = false, $populate = true ) { 692 $this->__construct($user_id,$group_id,$id,$populate); 693 } 694 695 function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) { 696 if ( $user_id && $group_id && !$id ) { 697 $this->user_id = $user_id; 688 public function __construct( $user_id = 0, $group_id = 0, $id = false, $populate = true ) { 689 690 // User and group are not empty, and ID is 691 if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) { 692 $this->user_id = $user_id; 698 693 $this->group_id = $group_id; 699 694 700 if ( $populate )695 if ( !empty( $populate ) ) { 701 696 $this->populate(); 702 } 703 704 if ( $id ) { 697 } 698 } 699 700 // ID is not empty 701 if ( !empty( $id ) ) { 705 702 $this->id = $id; 706 703 707 if ( $populate )704 if ( !empty( $populate ) ) { 708 705 $this->populate(); 709 } 710 } 711 712 function populate() { 706 } 707 } 708 } 709 710 private function populate() { 713 711 global $wpdb, $bp; 714 712 … … 716 714 $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id ); 717 715 718 if ( $this->id)716 if ( !empty( $this->id ) ) 719 717 $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id ); 720 718 721 719 $member = $wpdb->get_row($sql); 722 720 723 if ( $member) {721 if ( !empty( $member ) ) { 724 722 $this->id = $member->id; 725 723 $this->group_id = $member->group_id; … … 739 737 } 740 738 741 function save() {739 public function save() { 742 740 global $wpdb, $bp; 743 741 … … 756 754 do_action_ref_array( 'groups_member_before_save', array( &$this ) ); 757 755 758 if ( $this->id)756 if ( !empty( $this->id ) ) 759 757 $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id ); 760 758 else 761 759 $sql = $wpdb->prepare( "INSERT INTO {$bp->groups->table_name_members} ( user_id, group_id, inviter_id, is_admin, is_mod, is_banned, user_title, date_modified, is_confirmed, comments, invite_sent ) VALUES ( %d, %d, %d, %d, %d, %d, %s, %s, %d, %s, %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent ); 762 760 763 if ( !$wpdb->query( $sql) )761 if ( !$wpdb->query( $sql ) ) 764 762 return false; 765 763 … … 771 769 } 772 770 773 function promote( $status = 'mod' ) {771 public function promote( $status = 'mod' ) { 774 772 if ( 'mod' == $status ) { 775 $this->is_admin = 0;776 $this->is_mod = 1;773 $this->is_admin = 0; 774 $this->is_mod = 1; 777 775 $this->user_title = __( 'Group Mod', 'buddypress' ); 778 776 } 779 777 780 778 if ( 'admin' == $status ) { 781 $this->is_admin = 1;782 $this->is_mod = 0;779 $this->is_admin = 1; 780 $this->is_mod = 0; 783 781 $this->user_title = __( 'Group Admin', 'buddypress' ); 784 782 } … … 787 785 } 788 786 789 function demote() {790 $this->is_mod = 0;791 $this->is_admin = 0;787 public function demote() { 788 $this->is_mod = 0; 789 $this->is_admin = 0; 792 790 $this->user_title = false; 793 791 … … 795 793 } 796 794 797 function ban() {798 799 if ( $this->is_admin)795 public function ban() { 796 797 if ( !empty( $this->is_admin ) ) 800 798 return false; 801 799 … … 812 810 } 813 811 814 function unban() {815 816 if ( $this->is_admin)812 public function unban() { 813 814 if ( !empty( $this->is_admin ) ) 817 815 return false; 818 816 … … 825 823 } 826 824 827 function accept_invite() {825 public function accept_invite() { 828 826 829 827 $this->inviter_id = 0; … … 834 832 } 835 833 836 function accept_request() {834 public function accept_request() { 837 835 838 836 $this->is_confirmed = 1; … … 842 840 } 843 841 844 function remove() {842 public function remove() { 845 843 global $wpdb, $bp; 846 844 … … 859 857 } 860 858 861 /* Static Functions*/862 863 function delete( $user_id, $group_id ) {859 /** Static Methods ********************************************************/ 860 861 public static function delete( $user_id, $group_id ) { 864 862 global $wpdb, $bp; 865 863 … … 867 865 } 868 866 869 function get_group_ids( $user_id, $limit = false, $page = false ) {867 public static function get_group_ids( $user_id, $limit = false, $page = false ) { 870 868 global $wpdb, $bp; 871 869 872 870 $pag_sql = ''; 873 if ( $limit && $page)871 if ( !empty( $limit ) && !empty( $page ) ) 874 872 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 875 873 … … 888 886 } 889 887 890 function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) {888 public static function get_recently_joined( $user_id, $limit = false, $page = false, $filter = false ) { 891 889 global $wpdb, $bp; 892 890 893 891 $pag_sql = $hidden_sql = $filter_sql = ''; 894 892 895 if ( $limit && $page)893 if ( !empty( $limit ) && !empty( $page ) ) 896 894 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 897 895 898 if ( $filter) {896 if ( !empty( $filter ) ) { 899 897 $filter = like_escape( $wpdb->escape( $filter ) ); 900 898 $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )"; … … 910 908 } 911 909 912 function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) {910 public static function get_is_admin_of( $user_id, $limit = false, $page = false, $filter = false ) { 913 911 global $wpdb, $bp; 914 912 915 913 $pag_sql = $hidden_sql = $filter_sql = ''; 916 914 917 if ( $limit && $page)915 if ( !empty( $limit ) && !empty( $page ) ) 918 916 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 919 917 920 if ( $filter) {918 if ( !empty( $filter ) ) { 921 919 $filter = like_escape( $wpdb->escape( $filter ) ); 922 920 $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )"; … … 932 930 } 933 931 934 function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) {932 public static function get_is_mod_of( $user_id, $limit = false, $page = false, $filter = false ) { 935 933 global $wpdb, $bp; 936 934 937 935 $pag_sql = $hidden_sql = $filter_sql = ''; 938 936 939 if ( $limit && $page)937 if ( !empty( $limit ) && !empty( $page ) ) 940 938 $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 941 939 942 if ( $filter) {940 if ( !empty( $filter ) ) { 943 941 $filter = like_escape( $wpdb->escape( $filter ) ); 944 942 $filter_sql = " AND ( g.name LIKE '%%{$filter}%%' OR g.description LIKE '%%{$filter}%%' )"; … … 954 952 } 955 953 956 function total_group_count( $user_id = 0 ) {954 public static function total_group_count( $user_id = 0 ) { 957 955 global $bp, $wpdb; 958 956 … … 967 965 } 968 966 969 function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) {967 public static function get_invites( $user_id, $limit = false, $page = false, $exclude = false ) { 970 968 global $wpdb, $bp; 971 969 … … 980 978 } 981 979 982 function check_has_invite( $user_id, $group_id, $type = 'sent' ) {980 public static function check_has_invite( $user_id, $group_id, $type = 'sent' ) { 983 981 global $wpdb, $bp; 984 982 … … 994 992 } 995 993 996 function delete_invite( $user_id, $group_id ) {994 public static function delete_invite( $user_id, $group_id ) { 997 995 global $wpdb, $bp; 998 996 … … 1003 1001 } 1004 1002 1005 function delete_request( $user_id, $group_id ) {1003 public static function delete_request( $user_id, $group_id ) { 1006 1004 global $wpdb, $bp; 1007 1005 … … 1012 1010 } 1013 1011 1014 function check_is_admin( $user_id, $group_id ) {1012 public static function check_is_admin( $user_id, $group_id ) { 1015 1013 global $wpdb, $bp; 1016 1014 … … 1021 1019 } 1022 1020 1023 function check_is_mod( $user_id, $group_id ) {1021 public static function check_is_mod( $user_id, $group_id ) { 1024 1022 global $wpdb, $bp; 1025 1023 … … 1030 1028 } 1031 1029 1032 function check_is_member( $user_id, $group_id ) {1030 public static function check_is_member( $user_id, $group_id ) { 1033 1031 global $wpdb, $bp; 1034 1032 … … 1039 1037 } 1040 1038 1041 function check_is_banned( $user_id, $group_id ) {1039 public static function check_is_banned( $user_id, $group_id ) { 1042 1040 global $wpdb, $bp; 1043 1041 … … 1057 1055 * @since 1.2.6 1058 1056 */ 1059 function check_is_creator( $user_id, $group_id ) {1057 public static function check_is_creator( $user_id, $group_id ) { 1060 1058 global $bp, $wpdb; 1061 1059 … … 1066 1064 } 1067 1065 1068 function check_for_membership_request( $user_id, $group_id ) {1066 public static function check_for_membership_request( $user_id, $group_id ) { 1069 1067 global $wpdb, $bp; 1070 1068 … … 1075 1073 } 1076 1074 1077 function get_random_groups( $user_id, $total_groups = 5 ) {1075 public static function get_random_groups( $user_id, $total_groups = 5 ) { 1078 1076 global $wpdb, $bp; 1079 1077 … … 1086 1084 } 1087 1085 1088 function get_group_member_ids( $group_id ) {1086 public static function get_group_member_ids( $group_id ) { 1089 1087 global $bp, $wpdb; 1090 1088 … … 1092 1090 } 1093 1091 1094 function get_group_administrator_ids( $group_id ) {1092 public static function get_group_administrator_ids( $group_id ) { 1095 1093 global $bp, $wpdb; 1096 1094 … … 1098 1096 } 1099 1097 1100 function get_group_moderator_ids( $group_id ) {1098 public static function get_group_moderator_ids( $group_id ) { 1101 1099 global $bp, $wpdb; 1102 1100 … … 1104 1102 } 1105 1103 1106 function get_all_membership_request_user_ids( $group_id ) {1104 public static function get_all_membership_request_user_ids( $group_id ) { 1107 1105 global $bp, $wpdb; 1108 1106 … … 1110 1108 } 1111 1109 1112 function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false ) {1110 public static function get_all_for_group( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false ) { 1113 1111 global $bp, $wpdb; 1114 1112 1115 1113 $pag_sql = ''; 1116 if ( $limit && $page)1114 if ( !empty( $limit ) && !empty( $page ) ) 1117 1115 $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); 1118 1116 1119 1117 $exclude_admins_sql = ''; 1120 if ( $exclude_admins_mods)1118 if ( !empty( $exclude_admins_mods ) ) 1121 1119 $exclude_admins_sql = $wpdb->prepare( "AND is_admin = 0 AND is_mod = 0" ); 1122 1120 1123 1121 $banned_sql = ''; 1124 if ( $exclude_banned)1122 if ( !empty( $exclude_banned ) ) 1125 1123 $banned_sql = $wpdb->prepare( " AND is_banned = 0" ); 1126 1124 1127 1125 $exclude_sql = ''; 1128 if ( $exclude)1126 if ( !empty( $exclude ) ) 1129 1127 $exclude_sql = $wpdb->prepare( " AND m.user_id NOT IN ({$exclude})" ); 1130 1128 … … 1134 1132 $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) ); 1135 1133 1136 if ( !$members)1134 if ( empty( $members ) ) 1137 1135 return false; 1138 1136 … … 1142 1140 $total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_admins_sql} {$exclude_sql}", $group_id ) ) ); 1143 1141 1144 /* Fetch whether or not the user is a friend */ 1145 foreach ( (array)$members as $user ) $user_ids[] = $user->user_id; 1146 $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) ); 1142 // Fetch whether or not the user is a friend 1143 foreach ( (array)$members as $user ) 1144 $user_ids[] = $user->user_id; 1145 1146 $user_ids = $wpdb->escape( join( ',', (array) $user_ids ) ); 1147 1147 1148 1148 if ( bp_is_active( 'friends' ) ) { … … 1150 1150 for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) { 1151 1151 foreach ( (array)$friend_status as $status ) { 1152 if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id ) 1152 if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id ) { 1153 1153 $members[$i]->is_friend = $status->is_confirmed; 1154 } 1154 1155 } 1155 1156 } … … 1159 1160 } 1160 1161 1161 function delete_all( $group_id ) {1162 public static function delete_all( $group_id ) { 1162 1163 global $wpdb, $bp; 1163 1164 … … 1174 1175 * @uses BP_Groups_Member 1175 1176 */ 1176 function delete_all_for_user( $user_id ) {1177 public static function delete_all_for_user( $user_id ) { 1177 1178 global $bp, $wpdb; 1178 1179 … … 1209 1210 var $slug = false; 1210 1211 1211 / * The name/slug of the Group Admin tab for this extension */1212 // The name/slug of the Group Admin tab for this extension 1212 1213 var $admin_name = ''; 1213 1214 var $admin_slug = ''; 1214 1215 1215 / * The name/slug of the Group Creation tab for this extension */1216 // The name/slug of the Group Creation tab for this extension 1216 1217 var $create_name = ''; 1217 1218 var $create_slug = ''; 1218 1219 1219 / * Will this extension be visible to non-members of a group? Options: public/private */1220 // Will this extension be visible to non-members of a group? Options: public/private 1220 1221 var $visibility = 'public'; 1221 1222
Note: See TracChangeset
for help on using the changeset viewer.