Skip to:
Content

BuddyPress.org

Changeset 502


Ignore:
Timestamp:
11/06/2008 05:16:28 PM (18 years ago)
Author:
apeatling
Message:

Support for private groups and group membership requests.

Location:
trunk
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r489 r502  
    200200                        if ( !$blog )
    201201                                return false;
     202                       
     203                        if ( !$user_id )
     204                                return false;
    202205                               
    203206                        return sprintf( __( '%s created a new blog: %s', 'buddypress' ), bp_core_get_userlink($user_id), '<a href="' . get_blog_option( $blog->blog_id, 'siteurl' ) . '">' . get_blog_option( $blog->blog_id, 'blogname' ) . '</a>' ) . ' <span class="time-since">%s</span>';         
  • trunk/bp-core.php

    r469 r502  
    22
    33/* Define the current version number for checking if DB tables are up to date. */
    4 define( 'BP_CORE_VERSION', '0.2.7' );
     4define( 'BP_CORE_VERSION', '0.2.8' );
    55
    66/* Define the slug for member pages and the members directory (e.g. domain.com/[members] ) */
     
    7474        global $current_userid;
    7575        global $action_variables;
    76        
     76
    7777        /* The domain for the root of the site where the main blog resides */   
    7878        $bp['root_domain'] = bp_core_get_root_domain();
     
    155155                                user_id int(11) NOT NULL,
    156156                                item_id int(11) NOT NULL,
     157                                secondary_item_id int(11),
    157158                                component_name varchar(75) NOT NULL,
    158159                                component_action varchar(75) NOT NULL,
     
    161162                        PRIMARY KEY id (id),
    162163                            KEY item_id (item_id),
     164                                KEY secondary_item_id (secondary_item_id),
    163165                                KEY user_id (user_id),
    164166                            KEY is_new (is_new),
  • trunk/bp-core/bp-core-classes.php

    r469 r502  
    190190class BP_Core_Notification {
    191191        var $id;
     192        var $item_id;
     193        var $secondary_item_id = null;
    192194        var $user_id;
    193195        var $component_name;
     
    207209               
    208210                if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp['core']['table_name_notifications'] . " WHERE id = %d", $this->id ) ) ) {
     211                        $this->item_id = $notification->item_id;
     212                        $this->secondary_item_id = $notification->secondary_item_id;
    209213                        $this->user_id = $notification->user_id;
    210214                        $this->component_name = $notification->component_name;
     
    220224                if ( $this->id ) {
    221225                        // Update
    222                         $sql = $wpdb->prepare( "UPDATE " . $bp['core']['table_name_notifications'] . " SET item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = FROM_UNIXTIME(%d), is_new = %d ) WHERE id = %d", $this->item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
     226                        $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 = FROM_UNIXTIME(%d), 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 );
    223227                } else {
    224228                        // Save
    225                         $sql = $wpdb->prepare( "INSERT INTO " . $bp['core']['table_name_notifications'] . " ( item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %s, %s, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
    226                 }
    227 
    228                 return $wpdb->query( $sql );
     229                        $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, FROM_UNIXTIME(%d), %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
     230                }
     231
     232                if ( !$result = $wpdb->query( $sql ) )
     233                        return false;
     234
     235                $this->id = $wpdb->insert_id;
     236                return true;
    229237        }
    230238
     
    259267        }
    260268       
    261         function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action ) {
    262                 global $wpdb, $bp;
    263                
    264                 return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['core']['table_name_notifications'] . " WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s", $user_id, $item_id, $component_name, $component_action ) );
     269        function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
     270                global $wpdb, $bp;
     271               
     272                if ( $secondary_item_id )
     273                        $secondary_item_sql = $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id );
     274               
     275                return $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp['core']['table_name_notifications'] . " WHERE user_id = %d AND item_id = %d AND component_name = %s AND component_action = %s{$secondary_item_sql}", $user_id, $item_id, $component_name, $component_action ) );
    265276        }
    266277       
  • trunk/bp-core/bp-core-cssjs.php

    r436 r502  
    1414        wp_enqueue_script( 'bp-general-js', site_url() . '/wp-content/mu-plugins/bp-core/js/general.js' );
    1515}
    16 add_action( 'template_redirect', 'bp_core_add_js' );
     16add_action( 'wp', 'bp_core_add_js' );
    1717
    1818/**
  • trunk/bp-core/bp-core-notifications.php

    r469 r502  
    11<?php
    22
    3 function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $date_notified = false ) {
     3function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
    44        global $bp;
    55       
     
    1414        $notification->date_notified = $date_notified;
    1515        $notification->is_new = 1;
    16 
     16       
     17        if ( $secondary_item_id )
     18                $notification->secondary_item_id = $secondary_item_id;
     19       
    1720        if ( !$notification->save() )
    1821                return false;
     
    6164                       
    6265                        $item_id = ( $action_item_count == 1 ) ? $component_action_items[0]->item_id : false;
     66                        $secondary_item_id = ( $action_item_count == 1 ) ? $component_action_items[0]->secondary_item_id : false;
    6367                       
    6468                        if ( function_exists( $component_name . '_format_notifications' ) ) {
    65                                 $renderable[] = call_user_func( $component_name . '_format_notifications', $component_action_name, $item_id, $action_item_count );
     69                                $renderable[] = call_user_func( $component_name . '_format_notifications', $component_action_name, $item_id, $secondary_item_id, $action_item_count );
    6670                        }
    6771                }
     
    7175}
    7276
    73 function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action ) {
    74         return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action );
     77function bp_core_delete_notifications_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
     78        return BP_Core_Notification::delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id );
    7579}
    7680
  • trunk/bp-core/bp-core-settings.php

    r455 r502  
    124124                <?php do_action( 'bp_notification_settings' ) ?>
    125125               
    126                 <p><input type="submit" name="submit" value="Save Changes" id="submit" class="auto" /></p>             
     126                <p class="submit"><input type="submit" name="submit" value="Save Changes" id="submit" class="auto" /></p>               
    127127               
    128128                <?php wp_nonce_field('bp_settings_notifications') ?>
  • trunk/bp-core/css/admin-bar.css

    r497 r502  
    22
    33#wp-admin-bar {
    4         position: absolute;
    5         top: 0;
    6         left: 0;
    7         width: 100%;
    8         z-index: 1001;
    9         height: 28px;
    10         color: #fff;
    11         text-align: left;
    12         background:url(../images/admin_bar_back.gif) #818181 repeat-x;
     4        position: absolute !important;
     5        top: 0 !important;
     6        left: 0 !important;
     7        width: 100% !important;
     8        z-index: 1001 !important;
     9        height: 28px !important;
     10        color: #fff !important;
     11        text-align: left !important;
     12        background:url(../images/admin_bar_back.gif) #818181 repeat-x !important;
    1313}
    14         #wp-admin-bar * { z-index: 999; }
     14        #wp-admin-bar * { z-index: 999 !important; }
    1515
    1616        #wp-admin-bar img#admin-bar-logo {
    17                 position: absolute;
     17                position: absolute !important;
    1818                top: 8px;
    1919                left: 10px;
     
    3737
    3838#wp-admin-bar ul { /* all lists */
    39         margin: 0;
    40         list-style: none;
    41         line-height: 1;
    42         cursor: pointer;
    43         height: 30px;
    44         padding: 0;
     39        margin: 0 !important;
     40        list-style: none !important;
     41        line-height: 1 !important;
     42        cursor: pointer !important;
     43        height: 30px !important;
     44        padding: 0 !important;
    4545}
    4646        #wp-admin-bar ul {
    47                 margin-left: 80px;
     47                margin-left: 80px !important;
    4848        }
    4949                #wp-admin-bar ul li { /* all list items */
    50                         padding: 0;
     50                        padding: 0 !important;
    5151                        /*height: 30px;*/
    52                         float: left;
     52                        float: left !important;
    5353                }
    5454                        #wp-admin-bar ul li a {
    55                                 display: block;
    56                                 font-size: 1.1em;
     55                                display: block !important;
     56                                font-size: 1em !important;
     57                                font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, Verdana, Arial, sans-serif !important;
    5758                                text-decoration: none !important;
    5859                                color: #fff !important;
     
    6061                       
    6162                        #wp-admin-bar ul.main-nav li a:hover, #wp-admin-bar ul.main-nav li:hover {
    62                                 background: #777;
     63                                background: #777 !important;
    6364                                color: #fff !important;
    6465                        }
     
    6768
    6869#wp-admin-bar ul li ul {
    69         position: absolute;
    70         width: 185px;
    71         left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
    72         height: auto;
    73         margin-left: 0;
     70        position: absolute !important;
     71        width: 185px !important;
     72        left: -999em !important; /* using left instead of display to hide menus because display: none isn't read by screen readers */
     73        height: auto !important;
     74        margin-left: 0 !important;
    7475}
    7576        #wp-admin-bar ul li ul li {
    76                 float: none;
    77                 margin: 0;
    78                 border: none;
    79                 border-bottom: 1px solid #f4f4f4;
     77                float: none !important;
     78                margin: 0 !important;
     79                border: none !important;
     80                border-bottom: 1px solid #f4f4f4 !important;
    8081                background: #f4f4f4 !important;
    81                 border-left: 1px solid #ccc;
    82                 border-right: 1px solid #ccc;
     82                border-left: 1px solid #ccc !important;
     83                border-right: 1px solid #ccc !important;
     84                margin-bottom: -1px !important;
    8385        }
    8486                #wp-admin-bar ul li ul li.alt {
    8587                        background: #fafafa !important;
    86                         border-bottom: 1px solid #fafafa;
     88                        border-bottom: 1px solid #fafafa !important;
    8789                }
    8890               
    8991                #wp-admin-bar ul li ul li:last-child {
    90                         border-bottom: 1px solid #ccc;
    91                         -moz-border-radius-bottomleft: 4px;
    92                         -khtml-border-bottom-left-radius: 4px;
    93                         -webkit-border-bottom-left-radius: 4px;
    94                         border-bottom-left-radius: 4px;
    95                         -moz-border-radius-bottomright: 4px;
    96                         -khtml-border-bottom-right-radius: 4px;
    97                         -webkit-border-bottom-right-radius: 4px;
    98                         border-bottom-right-radius: 4px;
     92                        border-bottom: 1px solid #ccc !important;
     93                        -moz-border-radius-bottomleft: 4px !important;
     94                        -khtml-border-bottom-left-radius: 4px !important;
     95                        -webkit-border-bottom-left-radius: 4px !important;
     96                        border-bottom-left-radius: 4px !important;
     97                        -moz-border-radius-bottomright: 4px !important;
     98                        -khtml-border-bottom-right-radius: 4px !important;
     99                        -webkit-border-bottom-right-radius: 4px !important;
     100                        border-bottom-right-radius: 4px !important;
    99101                }
    100102               
     
    104106       
    105107        #wp-admin-bar ul.main-nav li ul li a:hover {
    106                 background: #888;
     108                background: #888 !important;
    107109        }
    108110       
    109111        #wp-admin-bar ul li div.admin-bar-clear {
    110                 clear: both;
     112                clear: both !important;
    111113                background: #eee !important;
    112                 border-bottom: 3px solid #eee;
     114                border-bottom: 3px solid #eee !important;
    113115        }
    114116
     
    116118
    117119#wp-admin-bar ul li ul ul {
    118         margin: -28px 0 0 183px;
     120        margin: -28px 0 0 183px !important;
    119121}
    120122
    121123#wp-admin-bar ul li:hover ul, #wp-admin-bar ul li li:hover ul, #wp-admin-bar ul li.sfhover ul, #wp-admin-bar ul li ul li.sfhover ul { /* lists nested under hovered list items */
    122         left: auto;
     124        left: auto !important;
    123125}
    124126
    125127#wp-admin-bar ul li:hover ul ul, #wp-admin-bar li.sfhover ul li ul {
    126         left: -999em;
     128        left: -999em !important;
    127129}
    128130
    129131#wp-admin-bar ul.main-nav li ul li:hover {
    130         background: #555;
     132        background: #555 !important;
    131133}
    132134
    133135#wp-admin-bar ul li ul li ul li:first-child {
    134         border-top: 1px solid #ccc;
    135         -moz-border-radius-topright: 4px;
    136         -khtml-border-top-right-radius: 4px;
    137         -webkit-border-top-right-radius: 4px;
    138         border-top-right-radius: 4px;
     136        border-top: 1px solid #ccc !important;
     137        -moz-border-radius-topright: 4px !important;
     138        -khtml-border-top-right-radius: 4px !important;
     139        -webkit-border-top-right-radius: 4px !important;
     140        border-top-right-radius: 4px !important;
    139141}
    140142
     
    142144
    143145#wp-admin-bar img.avatar {
    144         float: left;
    145         border: 2px solid #fff !important;
    146         margin-right: 8px;
     146        float: left !important;
     147        border: 2px solid #fff !important !important;
     148        margin-right: 8px !important;
    147149}
    148150
    149151#wp-admin-bar span.activity {
    150         display: block;
    151         color: #888;
    152         margin-left: 34px;
     152        display: block !important;
     153        color: #888 !important;
     154        margin-left: 34px !important;
    153155        font-size: 10px !important;
    154156        background: none !important;
     
    158160
    159161#wp-admin-bar li a:hover span.activity {
    160         color: #ccc;
     162        color: #ccc !important;
    161163}
    162164
    163165#wp-admin-bar ul.author-list li {
    164         height: 55px;
     166        height: 55px !important;
    165167}
    166168
    167169#wp-admin-bar ul li#notifications_menu a span {
    168         background: #fff;
    169         padding: 0 6px;
    170         color: #555;
     170        background: #fff !important;
     171        padding: 0 6px !important;
     172        color: #555 !important;
    171173        font-weight: bold !important;
    172174        font-size: 0.8em !important;
    173         -moz-border-radius: 2px;
    174         -khtml-border-radius: 2px;
    175         -webkit-border-radius: 2px;
    176         margin-left: 2px;
     175        -moz-border-radius: 2px !important;
     176        -khtml-border-radius: 2px !important;
     177        -webkit-border-radius: 2px !important;
     178        margin-left: 2px !important;
    177179}
  • trunk/bp-friends.php

    r489 r502  
    230230}
    231231
    232 function friends_format_notifications( $action, $item_id, $total_items ) {
     232function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    233233        global $bp;
    234234       
  • trunk/bp-groups.php

    r489 r502  
    33
    44define ( 'BP_GROUPS_IS_INSTALLED', 1 );
    5 define ( 'BP_GROUPS_VERSION', '0.1.4' );
     5define ( 'BP_GROUPS_VERSION', '0.2.1' );
    66
    77include_once( 'bp-groups/bp-groups-classes.php' );
     
    5252                        user_title varchar(100) NOT NULL,
    5353                        date_modified datetime NOT NULL,
     54                        comments longtext NOT NULL,
    5455                        is_confirmed tinyint(1) NOT NULL DEFAULT '0',
    5556                        PRIMARY KEY  (id),
     
    115116                $bp['groups']['table_name_wire'] = $wpdb->base_prefix . 'bp_groups_wire';
    116117       
    117         $bp['groups']['forbidden_names'] = array( 'my-groups', 'group-finder', 'create', 'invites', 'delete', 'add' );
     118        $bp['groups']['forbidden_names'] = array( 'my-groups', 'group-finder', 'create', 'invites', 'delete', 'add', 'admin', 'request-membership' );
    118119
    119120        return $bp;
     
    153154               
    154155                /* Is the logged in user a member of the group? */
    155                 $is_member = ( BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) ? true : false;
     156                $is_member = ( groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) ) ? true : false;
    156157       
    157158                /* Should this group be visible to the logged in user? */
     
    201202                       
    202203                        bp_core_add_nav_default( $bp['groups']['slug'], 'groups_screen_group_home', 'home' );
    203                         bp_core_add_subnav_item( $bp['groups']['slug'], 'home', __('Home', 'buddypress'), $group_link, 'groups_screen_group_home', 'group-home', $is_visible );
     204                        bp_core_add_subnav_item( $bp['groups']['slug'], 'home', __('Home', 'buddypress'), $group_link, 'groups_screen_group_home', 'group-home' );
    204205                       
    205206                        // If the user is a group administrator, then show the group admin nav item */
     
    207208                                bp_core_add_subnav_item( $bp['groups']['slug'], 'admin', __('Admin', 'buddypress'), $group_link , 'groups_screen_group_admin', 'group-admin', $bp['is_item_admin'] );
    208209                       
     210                        // If this is a closed group, and the user is not a member, show a "Request Membership" nav item.
     211                        if ( $group_obj->status == 'private' && ( !groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) && !groups_check_for_membership_request( $bp['loggedin_userid'], $group_obj->id ) ) )
     212                                bp_core_add_subnav_item( $bp['groups']['slug'], 'request-membership', __('Request Membership', 'buddypress'), $group_link , 'groups_screen_group_request_membership', 'request-membership' );
     213                               
    209214                        bp_core_add_subnav_item( $bp['groups']['slug'], 'forum', __('Forum', 'buddypress'), $group_link , 'groups_screen_group_forum', 'group-forum', $is_visible);
    210215                       
     
    220225                       
    221226                        if ( is_user_logged_in() && groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) ) {
    222                                 bp_core_add_subnav_item( $bp['groups']['slug'], 'send-invites', __('Send Invites', 'buddypress'), $group_link, 'groups_screen_group_invite', 'group-invite', $is_member );
     227                                if ( function_exists('friends_install') )
     228                                        bp_core_add_subnav_item( $bp['groups']['slug'], 'send-invites', __('Send Invites', 'buddypress'), $group_link, 'groups_screen_group_invite', 'group-invite', $is_member );
     229                               
    223230                                bp_core_add_subnav_item( $bp['groups']['slug'], 'leave-group', __('Leave Group', 'buddypress'), $group_link, 'groups_screen_group_leave', 'group-leave', $is_member );
    224231                        }
     
    426433       
    427434        if ( $is_single_group ) {
    428                 if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'yes' ) {
     435                if ( isset($bp['action_variables']) && $bp['action_variables'][0] == 'yes' ) {
    429436                        // remove the user from the group.
    430437                        if ( !groups_leave_group( $group_obj->id ) ) {
     
    440447                        bp_catch_uri( 'groups/group-home' );
    441448               
    442                 } else if ( isset($bp['action_variables']) && $bp['action_variables'][1] == 'no' ) {
     449                } else if ( isset($bp['action_variables']) && $bp['action_variables'][0] == 'no' ) {
    443450                        bp_catch_uri( 'groups/group-home' );
    444451                } else {
     
    446453                        bp_catch_uri( 'groups/leave-group-confirm' );
    447454                }
     455        }
     456}
     457
     458function groups_screen_group_request_membership() {
     459        global $bp, $group_obj;
     460       
     461        if ( $group_obj->status == 'private' ) {
     462               
     463                // If the user has submitted a request, send it.
     464                if ( isset( $_POST['group-request-send']) ) {
     465                        if ( !groups_send_membership_request( $bp['loggedin_userid'], $group_obj->id ) ) {
     466                                $bp['message'] = __( 'There was an error sending your group membership request, please try again.', 'buddypress' );
     467                                $bp['message_type'] = 'error';
     468                        } else {
     469                                $bp['message'] = __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' );
     470                                $bp['message_type'] = 'success';
     471                        }
     472                        add_action( 'template_notices', 'bp_core_render_notice' );
     473
     474                }
     475                bp_catch_uri( 'groups/request-membership' );
    448476        }
    449477}
     
    512540}
    513541add_action( 'wp', 'groups_screen_group_admin_settings', 3 );
     542
     543
     544function groups_screen_group_admin_requests() {
     545        global $bp;
     546       
     547        if ( $bp['current_component'] == $bp['groups']['slug'] && $bp['action_variables'][0] == 'membership-requests' ) {
     548               
     549                if ( !$bp['is_item_admin'] )
     550                        return false;
     551                       
     552                // Remove any screen notifications
     553                bp_core_delete_notifications_for_user_by_type( $bp['loggedin_userid'], 'groups', 'new_membership_request' );
     554               
     555                $request_action = $bp['action_variables'][1];
     556                $membership_id = $bp['action_variables'][2];
     557
     558                if ( isset($request_action) && isset($membership_id) ) {
     559                        if ( $request_action == 'accept' && is_numeric($membership_id) ) {
     560                                // Accept the membership request
     561                                if ( !groups_accept_membership_request( $membership_id ) ) {
     562                                        $bp['message'] = __( 'There was an error accepting the membership request, please try again.', 'buddypress' );
     563                                        $bp['message_type'] = 'error';
     564                                } else {
     565                                        $bp['message'] = __( 'Group membership request accepted', 'buddypress' );
     566                                        $bp['message_type'] = 'success';
     567                                }
     568                        } else if ( $request_action == 'reject' && is_numeric($membership_id) ) {
     569                                // Reject the membership request
     570                                if ( !groups_reject_membership_request( $membership_id ) ) {
     571                                        $bp['message'] = __( 'There was an error rejecting the membership request, please try again.', 'buddypress' );
     572                                        $bp['message_type'] = 'error';
     573                                } else {
     574                                        $bp['message'] = __( 'Group membership request rejected', 'buddypress' );
     575                                        $bp['message_type'] = 'success';
     576                                }       
     577                        }
     578                        add_action( 'template_notices', 'bp_core_render_notice' );
     579                }
     580               
     581                bp_catch_uri( 'groups/admin/membership-requests' );
     582        }
     583}
     584add_action( 'wp', 'groups_screen_group_admin_requests', 3 );
    514585
    515586
     
    571642               
    572643        // user wants to join a group
    573         if ( !BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $group_obj->id ) ) {
     644        if ( !groups_is_user_member( $bp['loggedin_userid'], $group_obj->id ) ) {
    574645                if ( !groups_join_group($group_obj->id) ) {
    575646                        $bp['message'] = __('There was an error joining the group. Please try again.', 'buddypress');
     
    598669        if ( function_exists('bp_activity_record') ) {
    599670                extract($args);
    600                 bp_activity_record( $item_id, $component_name, $component_action, $is_private );
     671               
     672                if ( !isset($group_id) )
     673                        $group_id = $item_id;
     674               
     675                $group = new BP_Groups_Group( $group_id, false, false );
     676               
     677                if ( $group->status == 'public' )
     678                        bp_activity_record( $item_id, $component_name, $component_action, $is_private );
    601679        }
    602680}
     
    649727}
    650728
     729function groups_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
     730        global $bp;
     731       
     732        switch ( $action ) {
     733                case 'new_membership_request':
     734                        $group_id = $secondary_item_id;
     735                        $requesting_user_id = $item_id;
     736                       
     737                        $group = new BP_Groups_Group( $group_id, false, false );
     738                       
     739                        if ( (int)$total_items > 1 ) {
     740                                return '<a href="' . bp_group_permalink( $group, false ) . '/admin/membership-requests/" title="' . __( 'Group Membership Requests', 'buddypress' ) . '">' . sprintf( __('%d new membership requests for the group "%s"'), (int)$total_items, $group->name ) . '</a>';         
     741                        } else {
     742                                $user_fullname = bp_core_global_user_fullname( $requesting_user_id );
     743                                $user_url = bp_core_get_userurl( $requesting_user_id );
     744                                return '<a href="' . bp_group_permalink( $group, false ) . '/admin/membership-requests/" title="' . $user_fullname .' requests group membership">' . sprintf( __('%s requests membership for the group "%s"'), $user_fullname, $group->name ) . '</a>';
     745                        }       
     746                break;
     747        }
     748       
     749        return false;
     750}
     751
    651752/**************************************************************************
    652753 groups_update_last_activity()
     
    672773 **************************************************************************/
    673774
    674 function groups_get_user_groups( $pag_page, $pag_num ) {
     775function groups_get_user_groups( $pag_num, $pag_page ) {
    675776        global $bp;
    676777       
     
    760861}
    761862
     863
     864function groups_search_groups( $search_terms, $pag_num_per_page = 5, $pag_page = 1 ) {
     865        return BP_Groups_Group::search_groups( $search_terms, $pag_num_per_page, $pag_page );
     866}
     867
     868function groups_filter_user_groups( $filter, $pag_num_per_page = 5, $pag_page = 1 ) {
     869        return BP_Groups_Group::filter_user_groups( $filter, $pag_num_per_page, $pag_page );
     870}
    762871
    763872/**************************************************************************
     
    9861095}
    9871096
    988 function groups_leave_group( $group_id ) {
    989         global $bp;
    990        
     1097function groups_check_group_exists( $group_id ) {
     1098        return BP_Groups_Group::group_exists( $group_id );
     1099}
     1100
     1101function groups_leave_group( $group_id, $user_id = false ) {
     1102        global $bp;
     1103       
     1104        if ( !$user_id )
     1105                $user_id = $bp['loggedin_userid'];
     1106               
    9911107        // This is exactly the same as deleting and invite, just is_confirmed = 1 NOT 0.
    992         if ( !groups_uninvite_user( $bp['loggedin_userid'], $group_id ) )
     1108        if ( !groups_uninvite_user( $user_id, $group_id ) )
    9931109                return false;
    9941110
     
    10011117}
    10021118
    1003 function groups_join_group( $group_id ) {
    1004         global $bp;
     1119function groups_join_group( $group_id, $user_id = false ) {
     1120        global $bp;
     1121       
     1122        if ( !$user_id )
     1123                $user_id = $bp['loggedin_userid'];
    10051124       
    10061125        $new_member = new BP_Groups_Member;
    10071126        $new_member->group_id = $group_id;
    1008         $new_member->user_id = $bp['loggedin_userid'];
     1127        $new_member->user_id = $user_id;
    10091128        $new_member->inviter_id = 0;
    10101129        $new_member->is_admin = 0;
     
    10281147}
    10291148
     1149function groups_get_group_admin( $group_id ) {
     1150        return BP_Groups_Member::get_group_administrator_id( $group_id );
     1151}
     1152
    10301153function groups_new_wire_post( $group_id, $content ) {
    10311154        if ( $wire_post_id = bp_wire_new_post( $group_id, $content ) ) {
    10321155               
    10331156                /* activity stream recording action */
    1034                 do_action( 'activity_groups_new_wire_post', array( 'item_id' => $wire_post_id, 'component_name' => 'groups', 'component_action' => 'new_wire_post', 'is_private' => 0 ) );
     1157                do_action( 'activity_groups_new_wire_post', array( 'item_id' => $wire_post_id, 'group_id' => $group_id, 'component_name' => 'groups', 'component_action' => 'new_wire_post', 'is_private' => 0 ) );
    10351158               
    10361159                /* regular action */
     
    10681191        if ( $notify_members )
    10691192                groups_notification_group_updated( $group->id );
     1193
     1194        do_action( 'bp_groups_details_updated', $group->id );
    10701195       
    10711196        return true;
     
    10851210                return false;
    10861211       
     1212        do_action( 'bp_groups_settings_updated', $group->id );
     1213       
    10871214        return true;
     1215}
     1216
     1217function groups_send_membership_request( $requesting_user_id, $group_id ) {
     1218        global $bp;
     1219
     1220        $requesting_user = new BP_Groups_Member;
     1221        $requesting_user->group_id = $group_id;
     1222        $requesting_user->user_id = $requesting_user_id;
     1223        $requesting_user->inviter_id = 0;
     1224        $requesting_user->is_admin = 0;
     1225        $requesting_user->user_title = '';
     1226        $requesting_user->date_modified = time();
     1227        $requesting_user->is_confirmed = 0;
     1228        $requesting_user->comments = $_POST['group-request-membership-comments'];
     1229       
     1230        if ( $requesting_user->save() ) {
     1231                $admin = groups_get_group_admin( $group_id );
     1232               
     1233                // Saved okay, now send the email notification
     1234                groups_notification_new_membership_request( $requesting_user_id, $admin->user_id, $group_id, $requesting_user->id );
     1235               
     1236                do_action( 'bp_groups_group_membership_requested', $requesting_user_id, $admin->user_id, $group_id, $requesting_user->id );
     1237       
     1238                return true;
     1239        }
     1240       
     1241        return false;
     1242}
     1243
     1244function groups_accept_membership_request( $membership_id ) {
     1245        $membership = new BP_Groups_Member( false, false, $membership_id );
     1246        $membership->accept_request();
     1247       
     1248        if ( !$membership->save() )
     1249                return false;
     1250       
     1251        return true;
     1252}
     1253
     1254function groups_reject_membership_request( $membership_id ) {
     1255        $membership = new BP_Groups_Member( false, false, $membership_id );
     1256       
     1257        if ( !BP_Groups_Member::delete( $membership->user_id, $membership->group_id ) )
     1258                return false;
     1259       
     1260        return true;
     1261}
     1262
     1263function groups_check_for_membership_request( $user_id, $group_id ) {
     1264        return BP_Groups_Member::check_for_membership_request( $user_id, $group_id );
    10881265}
    10891266
  • trunk/bp-groups/bp-groups-ajax.php

    r463 r502  
    4040add_action( 'wp_ajax_groups_invite_user', 'groups_ajax_invite_user' );
    4141
    42 function groups_ajax_group_search() {
     42function groups_ajax_group_filter() {
    4343        global $bp;
    4444
    45         check_ajax_referer('group_search');
    46 
    47         $pag_page = isset( $_POST['fpage'] ) ? intval( $_POST['fpage'] ) : 1;
    48         $pag_num = isset( $_POST['num'] ) ? intval( $_POST['num'] ) : 5;
    49         $total_group_count = 0;
    50 
    51         if ( $_POST['group-search-box'] == "" ) {
    52                 $groups = groups_get_user_groups( $pag_page, $pag_num );
    53         } else {
    54                 $groups = BP_Groups_Group::search_user_groups( $_POST['group-search-box'], $pag_num, $pag_page );
    55         }
     45        check_ajax_referer('group-filter-box');
    5646       
    57         $total_group_count = (int)$groups['count'];
    58 
    59         if ( $total_group_count ) {
    60                 $pag_links = paginate_links( array(
    61                         'base' => $bp['current_domain'] . $bp['groups']['slug'] . add_query_arg( 'mpage', '%#%' ),
    62                         'format' => '',
    63                         'total' => ceil($total_group_count / $pag_num),
    64                         'current' => $pag_page,
    65                         'prev_text' => '&laquo;',
    66                         'next_text' => '&raquo;',
    67                         'mid_size' => 1
    68                 ));
    69         }
    70        
    71         if ( $groups['groups'] ) {
    72                 echo '0[[SPLIT]]'; // return valid result.
    73        
    74                 for ( $i = 0; $i < count($groups['groups']); $i++ ) {
    75                         $group = $groups['groups'][$i];
    76                         ?>
    77                         <li>
    78                                 <img class="avatar" alt="Group Avatar" src="<?php echo $group->avatar_thumb ?>"/>
    79                                 <h4>
    80                                         <a href="<?php bp_group_permalink( $group ) ?>"><?php echo $group->name ?></a>
    81                                         <span class="small"> - <?php echo $group->total_member_count . ' ' . __('members', 'buddypress') ?></span>
    82                                 </h4>
    83                                 <p class="desc"><?php echo bp_create_excerpt( $group->description, 20 ) ?></p>
    84                         </li>
    85                         <?php   
    86                 }
    87                 echo '[[SPLIT]]' . $pag_links;
    88         } else {
    89                 $result['message'] = '<img src="' . $bp['groups']['image_base'] . '/warning.gif" alt="Warning" /> &nbsp;' . $result['message'];
    90                 echo "-1[[SPLIT]]" . __("No groups matched your search.", 'buddypress');
    91         }
     47        load_template( get_template_directory() . '/groups/group-loop.php' );
    9248}
    93 add_action( 'wp_ajax_group_search', 'groups_ajax_group_search' );
     49add_action( 'wp_ajax_group_filter', 'groups_ajax_group_filter' );
    9450
    9551function groups_ajax_group_finder_search() {
    9652        global $bp;
    9753
    98         check_ajax_referer('groupfinder_search');
     54        check_ajax_referer('groupfinder-search-box');
    9955
    100         $pag_page = isset( $_POST['fpage'] ) ? intval( $_POST['fpage'] ) : 1;
    101         $pag_num = isset( $_POST['num'] ) ? intval( $_POST['num'] ) : 5;
    102         $total_group_count = 0;
    103 
    104         if ( $_POST['groupfinder-search-box'] != "" ) {
    105                 $groups = BP_Groups_Group::search_groups( $_POST['groupfinder-search-box'], $pag_num, $pag_page );
    106         }
    107        
    108         $total_group_count = (int)$groups['count'];
    109 
    110         if ( $total_group_count ) {
    111                 $pag_links = paginate_links( array(
    112                         'base' => $bp['current_domain'] . $bp['groups']['slug'] . add_query_arg( 'mpage', '%#%' ),
    113                         'format' => '',
    114                         'total' => ceil($total_group_count / $pag_num),
    115                         'current' => $pag_page,
    116                         'prev_text' => '&laquo;',
    117                         'next_text' => '&raquo;',
    118                         'mid_size' => 1
    119                 ));
    120         }
    121        
    122         if ( $groups['groups'] ) {
    123                 echo '0[[SPLIT]]'; // return valid result.
    124        
    125                 for ( $i = 0; $i < count($groups['groups']); $i++ ) {
    126                         $group = $groups['groups'][$i];
    127                         ?>
    128                         <li>
    129                                 <img class="avatar" alt="Group Avatar" src="<?php echo $group->avatar_thumb ?>"/>
    130                                 <h4>
    131                                         <a href="<?php bp_group_permalink( $group ) ?>"><?php echo $group->name ?></a>
    132                                         <span class="small"> - <?php echo $group->total_member_count . ' ' . __('members', 'buddypress') ?></span>
    133                                 </h4>
    134                                 <p class="desc"><?php echo bp_create_excerpt( $group->description, 20 ) ?></p>
    135                         </li>
    136                         <?php   
    137                 }
    138                 echo '[[SPLIT]]' . $pag_links;
    139         } else {
    140                 $result['message'] = '<img src="' . $bp['groups']['image_base'] . '/warning.gif" alt="Warning" /> &nbsp;' . $result['message'];
    141                 echo "-1[[SPLIT]]" . __("No groups matched your search.", 'buddypress');
    142         }
     56        load_template( get_template_directory() . '/groups/group-loop.php' );
    14357}
    14458add_action( 'wp_ajax_group_finder_search', 'groups_ajax_group_finder_search' );
  • trunk/bp-groups/bp-groups-classes.php

    r482 r502  
    4646                if ( $group ) {
    4747                        $this->creator_id = $group->creator_id;
    48                         $this->name = $group->name;
     48                        $this->name = stripslashes($group->name);
    4949                        $this->slug = $group->slug;
    50                         $this->description = $group->description;
    51                         $this->news = $group->news;
     50                        $this->description = stripslashes($group->description);
     51                        $this->news = stripslashes($group->news);
    5252                        $this->status = $group->status;
    5353                        $this->is_invitation_only = $group->is_invitation_only;
     
    165165                }
    166166               
    167                 $result = $wpdb->query($sql);
    168                
    169                 if ( $wpdb->insert_id )
    170                         $this->id = $wpdb->insert_id;
    171                
    172                 return $result;
     167                if ( !$result = $wpdb->query($sql) )
     168                        return false;
     169               
     170                $this->id = $wpdb->insert_id;
     171                return true;
    173172        }
    174173       
     
    217216               
    218217        }
     218       
     219        function is_member() {
     220                global $bp;
     221               
     222                for ( $i = 0; $i < count($this->user_dataset); $i++ ) {
     223                        if ( $this->user_dataset[$i]->user_id == $bp['loggedin_userid'] ) {
     224                                return true;
     225                        }
     226                }       
     227               
     228                return false;
     229        }
    219230
    220231        /* Static Functions */
     
    253264        }
    254265       
    255         function search_user_groups( $filter, $limit = null, $page = null ) {
     266        function filter_user_groups( $filter, $limit = null, $page = null ) {
    256267                global $wpdb, $bp;
    257268               
     
    262273               
    263274                // Get all the group ids for the current user's groups.
    264                 $gids = BP_Groups_Member::get_group_ids( $user_id );
     275                $gids = BP_Groups_Member::get_group_ids( $bp['current_userid'], false, false, false );
    265276                $gids = implode( ',', $gids['ids'] );
    266277
     
    286297                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    287298               
    288                 $sql = $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name'] . " WHERE name LIKE '$filter%%' OR description LIKE '$filter%%'$pag_sql" );
    289                 $count_sql = $wpdb->prepare( "SELECT count(id) FROM " . $bp['groups']['table_name'] . " WHERE name LIKE '$filter%%' OR description LIKE '$filter%%'" );
     299                $sql = $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name'] . " WHERE status != 'hidden' AND name LIKE '$filter%%' OR description LIKE '$filter%%'$pag_sql" );
     300                $count_sql = $wpdb->prepare( "SELECT count(id) FROM " . $bp['groups']['table_name'] . " WHERE status != 'hidden' AND name LIKE '$filter%%' OR description LIKE '$filter%%'" );
    290301               
    291302                $group_ids = $wpdb->get_col($sql);
    292303                $total_groups = $wpdb->get_var($count_sql);
    293 
     304               
    294305                for ( $i = 0; $i < count($group_ids); $i++ ) {
    295306                        $groups[] = new BP_Groups_Group( (int)$group_ids[$i] );
     
    315326               
    316327                $members = $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d", $group_id ) );                                             
    317                
    318                 if ( $members < 1 )
     328
     329                if ( !$members )
    319330                        return false;
    320331               
    321332                return true;
     333        }
     334       
     335        function has_membership_requests( $group_id ) {
     336                global $wpdb, $bp;
     337               
     338                return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 0", $group_id ) );                                             
     339        }
     340       
     341        function get_membership_requests( $group_id, $limit = null, $page = null ) {
     342                global $wpdb, $bp;
     343               
     344                if ( $limit && $page )
     345                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     346               
     347                return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_confirmed = 0{$pag_sql}", $group_id ) );                       
    322348        }
    323349       
     
    328354                        $limit = 5;
    329355
    330                 return $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM " . $bp['groups']['table_name'] . " ORDER BY date_created DESC LIMIT %d", $limit ) );
     356                return $wpdb->get_results( $wpdb->prepare( "SELECT id as group_id FROM " . $bp['groups']['table_name'] . " WHERE status != 'hidden' ORDER BY date_created DESC LIMIT %d", $limit ) );
    331357        }
    332358       
     
    337363                        $limit = 5;
    338364
    339                 return $wpdb->get_results( $wpdb->prepare( "SELECT group_id FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE meta_key = 'last_activity' ORDER BY CONVERT(meta_value, SIGNED) DESC LIMIT %d", $limit ) );
     365                return $wpdb->get_results( $wpdb->prepare( "SELECT group_id FROM " . $bp['groups']['table_name_groupmeta'] . " gm, " . $bp['groups']['table_name'] . " g WHERE g.id = gm.group_id AND g.status != 'hidden' AND meta_key = 'last_activity' ORDER BY CONVERT(meta_value, SIGNED) DESC LIMIT %d", $limit ) );
    340366        }
    341367       
     
    346372                        $limit = 5;
    347373
    348                 return $wpdb->get_results( $wpdb->prepare( "SELECT group_id FROM " . $bp['groups']['table_name_groupmeta'] . " WHERE meta_key = 'total_member_count' ORDER BY CONVERT(meta_value, SIGNED) DESC LIMIT %d", $limit ) );
     374                return $wpdb->get_results( $wpdb->prepare( "SELECT gm.group_id FROM " . $bp['groups']['table_name_groupmeta'] . " gm, " . $bp['groups']['table_name'] . " g WHERE g.id = gm.group_id AND g.status != 'hidden' AND meta_key = 'total_member_count' ORDER BY CONVERT(meta_value, SIGNED) DESC LIMIT %d", $limit ) );
    349375        }
    350376}
     
    359385        var $date_modified;
    360386        var $is_confirmed;
     387        var $comments;
    361388       
    362389        var $user;
    363390       
    364         function bp_groups_member( $user_id = null, $group_id = null, $populate = true ) {
    365                 if ( $user_id && $group_id ) {
     391        function bp_groups_member( $user_id = false, $group_id = false, $id = false, $populate = true ) {
     392                if ( $user_id && $group_id && !$id ) {
    366393                        $this->user_id = $user_id;
    367394                        $this->group_id = $group_id;
     
    370397                                $this->populate();
    371398                }
     399               
     400                if ( $id ) {
     401                        $this->id = $id;
     402                       
     403                        if ( $populate )
     404                                $this->populate();
     405                }               
    372406        }
    373407       
    374408        function populate() {
    375409                global $wpdb, $bp;
    376 
    377                 $sql = $wpdb->prepare( "SELECT * FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
     410               
     411                if ( $this->user_id && $this->group_id && !$this->id )
     412                        $sql = $wpdb->prepare( "SELECT * FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
     413               
     414                if ( $this->id )
     415                        $sql = $wpdb->prepare( "SELECT * FROM " . $bp['groups']['table_name_members'] . " WHERE id = %d", $this->id );
     416                       
    378417                $member = $wpdb->get_row($sql);
    379418               
    380419                if ( $member ) {
    381420                        $this->id = $member->id;
     421                        $this->group_id = $member->group_id;
     422                        $this->user_id = $member->user_id;
    382423                        $this->inviter_id = $member->inviter_id;
    383424                        $this->is_admin = $member->is_admin;
     
    385426                        $this->date_modified = $member->date_modified;
    386427                        $this->is_confirmed = $member->is_confirmed;
     428                        $this->comments = $member->comments;
    387429                       
    388430                        $this->user = new BP_Core_User( $this->user_id );
     
    394436               
    395437                if ( $this->id ) {
    396                         $sql = $wpdb->prepare( "UPDATE " . $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin = %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed, $this->id );
     438                        $sql = $wpdb->prepare( "UPDATE " . $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin = %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d, comments = %s WHERE id = %d", $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->id );
    397439               
    398440                } else {
    399                         $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, user_title, date_modified, is_confirmed ) VALUES ( %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed );
    400                 }
    401 
    402                 if ( !$result = $wpdb->query($sql) )
     441                        $sql = $wpdb->prepare( "INSERT INTO " . $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id, is_admin, user_title, date_modified, is_confirmed, comments ) VALUES ( %d, %d, %d, %d, %s, FROM_UNIXTIME(%d), %d, %s )", $this->user_id, $this->group_id, $this->inviter_id, $this->is_admin, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments );
     442                }
     443
     444                if ( !$wpdb->query($sql) )
    403445                        return false;
    404446               
     447                $this->id = $wpdb->insert_id;
    405448                return true;
    406449        }
     
    418461                $this->date_modified = time();
    419462        }
     463       
     464        function accept_request() {
     465                $this->is_confirmed = 1;
     466                $this->date_modified = time();         
     467        }
    420468               
    421469        /* Static Functions */
     
    434482        }
    435483       
    436         function get_group_ids( $user_id, $page = false, $limit = false ) {
     484        function get_group_ids( $user_id, $page = false, $limit = false, $get_total = true ) {
    437485                global $wpdb, $bp;
    438486               
    439487                if ( $limit && $page )
    440488                        $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    441 
    442                 $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1$pag_sql", $user_id ) );
    443                 $group_count = BP_Groups_Member::total_group_count( $user_id );
     489               
     490                // If the user is logged in and viewing their own groups, we can show hidden and closed groups
     491                if ( bp_is_home() ) {
     492                        $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d $pag_sql", $user_id ) );     
     493                } else {
     494                        $group_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d$pag_sql", $user_id ) ); 
     495                }
     496               
     497                if ( $get_total )
     498                        $group_count = BP_Groups_Member::total_group_count( $user_id );
    444499       
    445500                return array( 'ids' => $group_ids, 'count' => $group_count );
     
    452507                        $user_id = $bp['current_userid'];
    453508                       
    454                 return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(group_id) FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1", $user_id ) );
     509                if ( bp_is_home() ) {
     510                        return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(group_id) FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1", $user_id ) );                       
     511                } else {
     512                        return $wpdb->get_var( $wpdb->prepare( "SELECT DISTINCT count(m.group_id) FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1", $user_id ) );                 
     513                }
    455514        }
    456515       
     
    479538        }
    480539       
     540        function check_for_membership_request( $user_id, $group_id ) {
     541                global $wpdb, $bp;
     542               
     543                return $wpdb->query( $wpdb->prepare( "SELECT id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id = %d AND is_confirmed = 0", $user_id, $group_id ) );   
     544        }
     545       
    481546        function get_random_groups( $user_id, $total_groups = 5 ) {
    482547                global $wpdb, $bp;
    483 
    484                 return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1 ORDER BY rand() LIMIT $total_groups", $user_id ) );
     548               
     549                // If the user is logged in and viewing their random groups, we can show hidden and closed groups
     550                if ( bp_is_home() ) {
     551                        return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND is_confirmed = 1 ORDER BY rand() LIMIT $total_groups", $user_id ) );
     552                } else {
     553                        return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM " . $bp['groups']['table_name_members'] . " m, " . $bp['groups']['table_name'] . " g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 ORDER BY rand() LIMIT $total_groups", $user_id ) );                     
     554                }
     555        }
     556       
     557        function get_group_administrator_id( $group_id ) {
     558                global $bp, $wpdb;
     559               
     560                return $wpdb->get_row( $wpdb->prepare( "SELECT user_id FROM " . $bp['groups']['table_name_members'] . " WHERE group_id = %d AND is_admin = 1", $group_id ) );
    485561        }
    486562       
  • trunk/bp-groups/bp-groups-notifications.php

    r494 r502  
    8585}
    8686
     87function groups_notification_new_membership_request( $requesting_user_id, $admin_id, $group_id, $membership_id ) {
     88        global $bp, $current_user;
     89
     90        bp_core_add_notification( $requesting_user_id, $admin_id, 'groups', 'new_membership_request', $group_id );
     91
     92        if ( get_usermeta( $admin_id, 'notification_new_membership_request' ) == 'no' )
     93                return false;
     94               
     95        $requesting_user_name = bp_fetch_user_fullname( $requesting_user_id, false );
     96        $group = new BP_Groups_Group( $group_id, false, false );
     97       
     98        $ud = get_userdata($admin_id);
     99        $requesting_ud = get_userdata($requesting_user_id);
     100
     101        $group_request_accept = bp_group_permalink( $group, false ) . '/admin/membership-requests/accept/' . $membership_id;
     102        $group_request_reject = bp_group_permalink( $group, false ) . '/admin/membership-requests/reject/' . $membership_id;
     103        $profile_link = site_url() . '/' . MEMBERS_SLUG . '/' . $requesting_ud->user_login . '/profile';
     104        $settings_link = site_url() . '/' . MEMBERS_SLUG . '/' . $ud->user_login . '/settings/notifications';
     105
     106        // Set up and send the message
     107        $to = $ud->user_email;
     108        $subject = sprintf( __( 'Membership request for group: %s', 'buddypress' ), stripslashes($group->name) );
     109
     110$message = sprintf( __(
     111'%s wants to join the group "%s".
     112
     113Because you are the administrator of this group, you must either accept or reject the membership request.
     114
     115To accept the membership request: %s
     116To reject the membership request: %s
     117To view %s\'s profile: %s
     118
     119---------------------
     120', 'buddypress' ), $requesting_user_name, stripslashes($group->name), $group_request_accept, $group_request_reject, $requesting_user_name, $profile_link );
     121
     122        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     123
     124        // Send it
     125        wp_mail( $to, $subject, $message );     
     126}
     127
    87128?>
  • trunk/bp-groups/bp-groups-templatetags.php

    r484 r502  
    1616        function bp_groups_template( $user_id = null, $group_slug = null ) {
    1717                global $bp;
    18 
    19                 $this->pag_page = isset( $_GET['fpage'] ) ? intval( $_GET['fpage'] ) : 1;
    20                 $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 5;
    21 
    22                 if ( $bp['current_action'] == 'my-groups' || !$bp['current_action'] ) {
    23                
    24                         $this->groups = groups_get_user_groups( $this->pag_page, $this->pag_num );
     18               
     19                $this->pag_page = isset( $_REQUEST['fpage'] ) ? intval( $_REQUEST['fpage'] ) : 1;
     20                $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : 5;
     21               
     22                if ( ( $bp['current_action'] == 'my-groups' && $_REQUEST['group-filter-box'] == '' ) || !$bp['current_action'] ) {
     23                       
     24                        $this->groups = groups_get_user_groups( $this->pag_num, $this->pag_page );
    2525                        $this->total_group_count = (int)$this->groups['count'];
    2626                        $this->groups = $this->groups['groups'];
    2727                        $this->group_count = count($this->groups);
    2828               
     29                } else if ( $bp['current_action'] == 'my-groups' && $_REQUEST['group-filter-box'] != '' ) {
     30
     31                        $this->groups = groups_filter_user_groups( $_REQUEST['group-filter-box'], $this->pag_num, $this->pag_page );
     32                        $this->total_group_count = (int)$this->groups['count'];
     33                        $this->groups = $this->groups['groups'];
     34                        $this->group_count = count($this->groups);
     35               
     36                } else if ( $bp['current_action'] == 'group-finder' && $_REQUEST['groupfinder-search-box'] != '' ) {
     37
     38                        $this->groups = groups_search_groups( $_REQUEST['groupfinder-search-box'], $this->pag_num, $this->pag_page );
     39                        $this->total_group_count = (int)$this->groups['count'];
     40                        $this->groups = $this->groups['groups'];
     41                        $this->group_count = count($this->groups);
     42                       
    2943                } else if ( $bp['current_action'] == 'invites' ) {
    3044               
     
    121135}
    122136
     137function bp_group_is_visible() {
     138        global $bp, $groups_template;
     139       
     140        if ( $groups_template->group->status == 'public' ) {
     141                return true;
     142        } else {
     143                if ( groups_is_user_member( $bp['loggedin_userid'], $groups_template->group->id ) ) {
     144                        return true;
     145                }
     146        }
     147       
     148        return false;
     149}
     150
    123151function bp_group_id( $echo = true ) {
    124152        global $groups_template;
     
    235263        }
    236264
    237 function bp_group_invitation_status() {
    238         global $groups_template;
    239        
    240         if ( $groups_template->group->is_invitation_only ) {
    241                 _e('Invitation Only', 'buddypress');
    242         } else {
    243                 _e('Open', 'buddypress');
    244         }
    245 }
    246         function bp_group_is_invitation_only() {
    247                 global $groups_template;
    248                 return $groups_template->group->is_invitation_only;
    249         }
    250265
    251266function bp_group_date_created() {
     
    301316                $action = $bp['loggedin_domain'] . $bp['groups']['slug'] . '/my-groups/search/';
    302317                $label = __('Filter Groups', 'buddypress');
    303                 $type = 'group';
     318                $name = 'group-filter-box';
    304319        } else {
    305320                $action = $bp['loggedin_domain'] . $bp['groups']['slug'] . '/group-finder/search/';
    306321                $label = __('Find a Group', 'buddypress');
    307                 $type = 'groupfinder';
    308                 $value = $bp['action_variables'][1];
    309         }
    310 
    311         if ( !$groups_template->group_count && $bp['current_action'] != 'group-finder' ) {
    312                 $disabled = ' disabled="disabled"';
     322                $name = 'groupfinder-search-box';
     323                $value = $bp['action_variables'][0];
    313324        }
    314325?>
    315326        <form action="<?php echo $action ?>" id="group-search-form" method="post">
    316                 <label for="<?php echo $type ?>-search-box" id="<?php echo $type ?>-search-label"><?php echo $label ?> <img id="ajax-loader" src="<?php echo $bp['groups']['image_base'] ?>/ajax-loader.gif" height="7" alt="Loading" style="display: none;" /></label>
    317                 <input type="search" name="<?php echo $type ?>-search-box" id="<?php echo $type ?>-search-box" value="<?php echo $value ?>"<?php echo $disabled ?> />
     327                <label for="<?php echo $name ?>" id="<?php echo $name ?>-label"><?php echo $label ?> <img id="ajax-loader" src="<?php echo $bp['groups']['image_base'] ?>/ajax-loader.gif" height="7" alt="Loading" style="display: none;" /></label>
     328                <input type="search" name="<?php echo $name ?>" id="<?php echo $name ?>" value="<?php echo $value ?>"<?php echo $disabled ?> />
    318329                <?php if ( function_exists('wp_nonce_field') )
    319                         wp_nonce_field( $type . '_search' );
     330                        wp_nonce_field( $name );
    320331                ?>
    321332        </form>
    322333<?php
     334}
     335
     336function bp_group_show_no_groups_message() {
     337        global $bp;
     338       
     339        if ( $bp['current_action'] == 'group-finder' )
     340                return false;
     341       
     342        return true;
    323343}
    324344
     
    396416        <!--<li<?php if ( $current_tab == 'manage-members' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/manage-members"><?php _e('Manage Members', 'buddypress') ?></a></li>-->
    397417        <!--<li<?php if ( $current_tab == 'delete-group' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/delete-group"><?php _e('Delete Group', 'buddypress') ?></a></li>-->
     418        <?php if ( $groups_template->group->status == 'private' ) : ?>
     419        <li<?php if ( $current_tab == 'membership-requests' ) : ?> class="current"<?php endif; ?>><a href="<?php echo $bp['root_domain'] . '/' . $bp['groups']['slug'] ?>/<?php echo $groups_template->group->slug ?>/admin/membership-requests"><?php _e('Membership Requests', 'buddypress') ?></a></li>
     420        <?php endif; ?>
    398421<?php
    399422        do_action( 'bp_groups_admin_tabs' );
    400423}
    401424
     425function bp_group_form_action( $page ) {
     426        global $bp, $groups_template;
     427       
     428        echo bp_group_permalink( $group, false ) . '/' . $page;
     429}
     430
    402431function bp_group_admin_form_action( $page ) {
    403432        global $bp, $groups_template;
    404433       
    405434        echo bp_group_permalink( $group, false ) . '/admin/' . $page;
     435}
     436
     437function bp_group_has_requested_membership() {
     438        global $bp, $groups_template;
     439       
     440        if ( groups_check_for_membership_request( $bp['loggedin_userid'], $groups_template->group->id ) )
     441                return true;
     442       
     443        return false;
    406444}
    407445
     
    461499                <?php case '2': ?>
    462500                        <?php if ( $completed_to_step > 0 ) { ?>
     501                                <?php if ( function_exists('bp_wire_install') ) : ?>
    463502                                <div class="checkbox">
    464503                                        <label><input type="checkbox" name="group-show-wire" id="group-show-wire" value="1"<?php if ( $group_obj->enable_wire ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable comment wire', 'buddypress') ?></label>
    465504                                </div>
     505                                <?php endif; ?>
     506                               
     507                                <?php if ( function_exists('bp_forum_install') ) : ?>
    466508                                <div class="checkbox">
    467509                                        <label><input type="checkbox" name="group-show-forum" id="group-show-forum" value="1"<?php if ( $group_obj->enable_forum ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable discussion forum', 'buddypress') ?></label>
    468510                                </div>
     511                                <?php endif; ?>
     512                               
     513                                <?php if ( function_exists('bp_albums_install') ) : ?>
    469514                                <div class="checkbox with-suboptions">
    470515                                        <label><input type="checkbox" name="group-show-photos" id="group-show-photos" value="1"<?php if ( $group_obj->enable_photos ) { ?> checked="checked"<?php } ?> /> <?php _e('Enable photo gallery', 'buddypress') ?></label>
     
    474519                                        </div>
    475520                                </div>
     521                                <?php endif; ?>
    476522                       
    477523                                <h3><?php _e('Privacy Options', 'buddypress'); ?></h3>
     
    590636                        <?php echo $member->user->avatar_thumb ?>
    591637                        <p><?php echo $member->user->user_link ?> <?php if ( $member->user_title ) { ?><?php echo '<span class="small">- ' . $member->user_title . '</span>' ?><?php } ?></p>
    592                         <span class="activity">joined <?php echo bp_core_time_since( strtotime($member->date_modified) ) ?> ago</span>
     638                        <span class="activity"><?php echo sprintf( __( 'joined %s ago', 'buddypress' ), bp_core_time_since( strtotime( $member->date_modified ) ) ); ?></span>
    593639        <?php if ( bp_exists('friends') && function_exists('bp_add_friend_button') ) { ?>
    594640                        <div class="action">
     
    653699                                        <?php echo $user->avatar_thumb ?>
    654700                                        <h4><?php echo $user->user_link ?></h4>
    655                                         <span class="activity">active <?php echo $user->last_active ?> ago</span>
     701                                        <span class="activity"><?php echo $user->last_active ?></span>
    656702                                        <div class="action">
    657703                                                <a class="remove" href="<?php echo site_url() . $bp['groups']['slug'] . '/' . $group_obj->id . '/invites/remove/' . $user->id ?>" id="uid-<?php echo $user->id ?>">Remove Invite</a>
     
    676722        global $bp, $groups_template;
    677723       
    678         if ( is_user_logged_in() && !BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $groups_template->group->id ) ) {
    679                 echo '<a class="join-group" href="' . bp_group_permalink( false, false ) . '/join">' . __('Join Group', 'buddypress') . '</a>';
     724        if ( !is_user_logged_in() || BP_Groups_Member::check_is_member( $bp['loggedin_userid'], $groups_template->group->id ) )
     725                return false;
     726               
     727        switch ( $groups_template->group->status ) {
     728                case 'public':
     729                        echo '<a class="join-group" href="' . bp_group_permalink( false, false ) . '/join">' . __('Join Group', 'buddypress') . '</a>';                                 
     730                break;
     731               
     732                case 'private':
     733                        if ( !bp_group_has_requested_membership() )
     734                                echo '<a class="request-membership" href="' . bp_group_permalink( false, false ) . '/request-membership">' . __('Request Membership', 'buddypress') . '</a>';           
     735                        else
     736                                echo 'Membership Requested';
     737                break;
     738        }
     739}
     740
     741function bp_group_status_message() {
     742        global $groups_template;
     743       
     744        if ( $groups_template->group->status == 'private' ) {
     745                if ( !bp_group_has_requested_membership() )
     746                        _e( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
     747                else
     748                        _e( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );                     
     749        } else {
     750                _e( 'This is a hidden group and only invited members can join.', 'buddypress' );
    680751        }
    681752}
     
    708779}
    709780
     781/****
     782 * Membership Requests Template Tags
     783 **/
     784
     785class BP_Groups_Membership_Requests_Template {
     786        var $current_request = -1;
     787        var $request_count;
     788        var $requests;
     789        var $request;
     790       
     791        var $in_the_loop;
     792       
     793        var $pag_page;
     794        var $pag_num;
     795        var $pag_links;
     796        var $total_request_count;
     797       
     798        function bp_groups_membership_requests_template( $group_id = null ) {
     799                global $bp;
     800               
     801                $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : 1;
     802                $this->pag_num = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : 5;
     803               
     804                $this->requests = BP_Groups_Group::get_membership_requests( $group_id, $this->pag_num, $this->pag_page );
     805                $this->request_count = count($this->requests);
     806               
     807                $this->total_request_count = (int) BP_Groups_Group::has_membership_requests( $group_id );
     808
     809                $this->pag_links = paginate_links( array(
     810                        'base' => add_query_arg( 'mrpage', '%#%' ),
     811                        'format' => '',
     812                        'total' => ceil( $this->total_request_count / $this->pag_num ),
     813                        'current' => $this->pag_page,
     814                        'prev_text' => '&laquo;',
     815                        'next_text' => '&raquo;',
     816                        'mid_size' => 1
     817                ));
     818               
     819        }
     820       
     821        function has_requests() {
     822                if ( $this->request_count )
     823                        return true;
     824               
     825                return false;
     826        }
     827       
     828        function next_request() {
     829                $this->current_request++;
     830                $this->request = $this->requests[$this->current_request];
     831               
     832                return $this->request;
     833        }
     834       
     835        function rewind_requests() {
     836                $this->current_request = -1;
     837                if ( $this->request_count > 0 ) {
     838                        $this->request = $this->requests[0];
     839                }
     840        }
     841       
     842        function requests() {
     843                if ( $this->current_request + 1 < $this->request_count ) {
     844                        return true;
     845                } elseif ( $this->current_request + 1 == $this->request_count ) {
     846                        do_action('loop_end');
     847                        // Do some cleaning up after the loop
     848                        $this->rewind_requests();
     849                }
     850
     851                $this->in_the_loop = false;
     852                return false;
     853        }
     854       
     855        function the_request() {
     856                global $request;
     857
     858                $this->in_the_loop = true;
     859                $this->request = $this->next_request();
     860
     861                if ( $this->current_request == 0 ) // loop has just started
     862                        do_action('loop_start');
     863        }
     864}
     865
     866function bp_group_has_membership_requests() {
     867        global $requests_template, $groups_template;
     868       
     869        $requests_template = new BP_Groups_Membership_Requests_Template( $groups_template->group->id );
     870
     871        return $requests_template->has_requests();
     872}
     873
     874function bp_group_membership_requests() {
     875        global $requests_template;
     876       
     877        return $requests_template->requests();
     878}
     879
     880function bp_group_the_membership_request() {
     881        global $requests_template;
     882       
     883        return $requests_template->the_request();
     884}
     885
     886function bp_group_request_user_avatar_thumb() {
     887        global $requests_template;
     888       
     889        echo bp_core_get_avatar( $requests_template->request->user_id, 1 );
     890}
     891
     892function bp_group_request_reject_link() {
     893        global $requests_template, $groups_template;   
     894
     895        echo bp_group_permalink( $groups_template->group, false ) . '/admin/membership-requests/reject/' . $requests_template->request->id;
     896}
     897
     898function bp_group_request_accept_link() {
     899        global $requests_template, $groups_template;   
     900
     901        echo bp_group_permalink( $groups_template->group, false ) . '/admin/membership-requests/accept/' . $requests_template->request->id;
     902}
     903
     904function bp_group_request_time_since_requested() {
     905        global $requests_template;     
     906
     907        echo sprintf( __( 'requested %s ago', 'buddypress' ), bp_core_time_since( strtotime( $requests_template->request->date_modified ) ) );
     908}
     909
     910function bp_group_request_comment() {
     911        global $requests_template;
     912       
     913        echo strip_tags( stripslashes( $requests_template->request->comments ) );
     914}
     915
     916function bp_group_request_user_link() {
     917        global $requests_template;
     918       
     919        echo bp_core_get_userlink( $requests_template->request->user_id );
     920}
     921
    710922?>
  • trunk/bp-groups/js/general.js

    r263 r502  
    7878
    7979                        jQuery.post( ajaxurl, {
    80                                 action: 'group_search',
     80                                action: 'group_filter',
    8181                                'cookie': encodeURIComponent(document.cookie),
    8282                                '_wpnonce': jQuery("input#_wpnonce").val(),
     
    8484                                'num': 5,
    8585
    86                                 'group-search-box': jQuery("#group-search-box").val()
    87                         },
    88                         function(response)
    89                         {       
    90                                 render_group_search_response(response);
     86                                'group-filter-box': jQuery("#group-filter-box").val()
     87                        },
     88                        function(response)
     89                        {       
     90                                response = response.substr( 0, response.length - 1 );
     91                               
     92                                jQuery("div#group-loop").fadeOut(200,
     93                                        function() {
     94                                                jQuery('#ajax-loader').toggle();
     95                                                jQuery("div#group-loop").html(response);
     96                                                jQuery("div#group-loop").fadeIn(200);
     97                                        }
     98                                );
    9199                        });
    92100                       
     
    113121                        function(response)
    114122                        {       
    115                                 render_group_finder_search_response(response);
    116                         });
    117                        
    118                         return false;
    119                 }
    120         );
    121 
    122         jQuery("input#group-search-box").keyup(
     123                                response = response.substr( 0, response.length - 1 );
     124
     125                                jQuery("div#group-loop").fadeOut(200,
     126                                        function() {
     127                                                jQuery('#ajax-loader').toggle();
     128                                                jQuery("div#group-loop").html(response);
     129                                                jQuery("div#group-loop").fadeIn(200);
     130                                        }
     131                                );
     132                        });
     133                       
     134                        return false;
     135                }
     136        );
     137
     138        jQuery("input#group-filter-box").keyup(
    123139                function(e) {
    124140                        if ( e.which == 13 ) {
     
    126142                               
    127143                                jQuery.post( ajaxurl, {
    128                                         action: 'group_search',
     144                                        action: 'group_filter',
    129145                                        'cookie': encodeURIComponent(document.cookie),
    130146                                        '_wpnonce': jQuery("input#_wpnonce").val(),
    131147
    132                                         'group-search-box': jQuery("#group-search-box").val()
     148                                        'group-filter-box': jQuery("#group-filter-box").val()
    133149                                },
    134150                                function(response)
    135151                                {
    136                                         render_group_search_response(response);
     152                                        response = response.substr( 0, response.length - 1 );
     153
     154                                        jQuery("div#group-loop").fadeOut(200,
     155                                                function() {
     156                                                        jQuery('#ajax-loader').toggle();
     157                                                        jQuery("div#group-loop").html(response);
     158                                                        jQuery("div#group-loop").fadeIn(200);
     159                                                }
     160                                        );
    137161                                });
    138162
     
    145169                function(e) {
    146170                        if ( e.which == 13 ) {
    147                                 jQuery('#ajax-loader').toggle();
    148                                
     171                                if ( jQuery("#groupfinder-search-box").val() == '' )
     172                                        return false;
     173                                       
     174                                jQuery('#ajax-loader').toggle();
     175                                       
    149176                                jQuery.post( ajaxurl, {
    150177                                        action: 'group_finder_search',
     
    156183                                function(response)
    157184                                {
    158                                         render_group_finder_search_response(response);
     185                                        response = response.substr( 0, response.length - 1 );
     186
     187                                        jQuery("div#finder-message").fadeOut(200);
     188                                        jQuery("div#group-loop").fadeOut(200,
     189                                                function() {
     190                                                        jQuery('#ajax-loader').toggle();
     191                                                        jQuery("div#group-loop").html(response);
     192                                                        jQuery("div#group-loop").fadeIn(200);
     193                                                }
     194                                        );
    159195                                });
    160196
     
    164200        );
    165201});
    166 
    167 function render_group_search_response(response) {
    168         response = response.substr(0, response.length-1);
    169         response = response.split('[[SPLIT]]');
    170 
    171         if ( response[0] != "-1" ) {
    172                 jQuery("ul#group-list").fadeOut(200,
    173                         function() {
    174                                 jQuery('#ajax-loader').toggle();
    175                                 jQuery("ul#group-list").html(response[1]);
    176                                 jQuery("ul#group-list").fadeIn(200);
    177                         }
    178                 );
    179                
    180                 jQuery("div#pag").fadeOut(200,
    181                         function() {
    182                                 jQuery("div#pag").html(response[2]);
    183                                 jQuery("div#pag").fadeIn(200);
    184                         }
    185                 );
    186                
    187         } else {
    188                 jQuery("ul#group-list").fadeOut(200,
    189                         function() {
    190                                 jQuery('#ajax-loader').toggle();
    191                                 jQuery("div#pag").fadeOut(200);
    192                                 var message = '<p><div id="message" class="error"><p>' + response[1] + '</p></div></p>';
    193                                 jQuery("ul#group-list").html(message);
    194                                 jQuery("ul#group-list").fadeIn(200);
    195                         }
    196                 );
    197         }
    198                        
    199         return false;
    200 }
    201 
    202 function render_group_finder_search_response(response) {
    203         response = response.substr(0, response.length-1);
    204         response = response.split('[[SPLIT]]');
    205        
    206         console.log(response);
    207 
    208         jQuery('#finder-message').before('<ul id="friend-list"></ul>');
    209        
    210         if ( jQuery('#finder-message') ) {
    211                 jQuery('#finder-message').fadeOut(200);
    212         }
    213        
    214         if ( response[0] != "-1" ) {
    215                 jQuery("ul#friend-list").fadeOut(200,
    216                         function() {
    217                                 jQuery('#ajax-loader').toggle();
    218                                 jQuery("ul#friend-list").html(response[1]);
    219                                 jQuery("ul#friend-list").fadeIn(200);
    220                         }
    221                 );
    222 
    223                 jQuery("div#groupfinder-pag").fadeOut(200,
    224                         function() {
    225                                 jQuery("div#groupfinder-pag").html(response[2]);
    226                                 jQuery("div#groupfinder-pag").fadeIn(200);
    227                         }
    228                 );
    229 
    230         } else {                                       
    231                 jQuery("ul#friend-list").fadeOut(200,
    232                         function() {
    233                                 jQuery('#ajax-loader').toggle();
    234                                 jQuery("div#groupfinder-pag").fadeOut(200);
    235                                 var message = '<p><div id="message" class="error"><p>' + response[1] + '</p></div></p>';
    236                                 jQuery("ul#friend-list").html(message);
    237                                 jQuery("ul#friend-list").fadeIn(200);
    238                         }
    239                 );
    240         }
    241        
    242         return false;
    243 }
  • trunk/bp-xprofile.php

    r489 r502  
    425425 * @return The readable notification item
    426426 */
    427 function xprofile_format_notifications( $action, $item_id, $total_items ) {
     427function xprofile_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    428428        global $bp;
    429429
  • trunk/bp-xprofile/bp-xprofile-cssjs.php

    r373 r502  
    77add_action( 'wp_head', 'xprofile_add_signup_css' );
    88
     9function xprofile_add_signup_js() {
     10        if ( $_SERVER['SCRIPT_NAME'] == '/wp-signup.php' )
     11                wp_enqueue_script( 'jquery' );
     12}
     13add_action( 'wp', 'xprofile_add_signup_js' );
    914
    1015function xprofile_add_admin_css() {
     
    1520add_action( 'admin_head', 'xprofile_add_admin_css' );
    1621
    17 
    18 function xprofile_add_admin_js() {
    19         if ( strpos( $_GET['page'], 'xprofile' ) !== false ) {
    20                 wp_enqueue_script( 'bp-xprofile-admin-js', site_url() . "/wp-content/mu-plugins/bp-xprofile/js/admin.js" );
    21                 add_action( 'admin_head', 'bp_core_add_cropper_js' );
    22         }
    23 }
    24 add_action( 'admin_menu', 'xprofile_add_admin_js' );
    25 
    2622function xprofile_add_cropper_js() {
    2723        global $bp;
    2824
    29         if ( $_SERVER['SCRIPT_NAME'] == '/wp-activate.php' || $bp['current_action'] == 'change-avatar' || ( isset($_GET['page']) && $_GET['page'] == 'bp-xprofile.php' ) ) {
     25        if ( $_SERVER['SCRIPT_NAME'] == '/wp-activate.php' || $bp['current_action'] == 'change-avatar' ) {
    3026                wp_enqueue_script('jquery');
    3127                wp_enqueue_script('prototype');
Note: See TracChangeset for help on using the changeset viewer.