Skip to:
Content

BuddyPress.org

Ticket #2005: 2005.001.diff

File 2005.001.diff, 17.0 KB (added by boonebgorges, 14 years ago)
  • bp-core/admin/bp-core-schema.php

    function bp_core_install_groups() { 
    110110                                slug varchar(200) NOT NULL,
    111111                                description longtext NOT NULL,
    112112                                status varchar(10) NOT NULL DEFAULT 'public',
     113                                invite_status varchar(10) NOT NULL DEFAULT 'members',
    113114                                enable_forum tinyint(1) NOT NULL DEFAULT '1',
    114115                                date_created datetime NOT NULL,
    115116                            KEY creator_id (creator_id),
  • bp-groups/bp-groups-actions.php

    function groups_action_create_group() { 
    9696                                $group_status = 'private';
    9797                        else if ( 'hidden' == $_POST['group-status'] )
    9898                                $group_status = 'hidden';
     99                       
     100                        $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
     101                        $group_invite_status   = in_array( $_POST['group-invite-status'], (array)$allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
    99102
    100                         if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
     103                        if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'invite_status' => $group_invite_status, 'enable_forum' => $group_enable_forum ) ) ) {
    101104                                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
    102105                                bp_core_redirect( bp_get_root_domain() . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' );
    103106                        }
  • bp-groups/bp-groups-classes.php

    Class BP_Groups_Group { 
    77        var $slug;
    88        var $description;
    99        var $status;
     10        var $invite_status;
    1011        var $enable_forum;
    1112        var $date_created;
    1213
    Class BP_Groups_Group { 
    3536                        $this->slug               = $group->slug;
    3637                        $this->description        = stripslashes($group->description);
    3738                        $this->status             = $group->status;
     39                        $this->invite_status      = $group->invite_status;
    3840                        $this->enable_forum       = $group->enable_forum;
    3941                        $this->date_created       = $group->date_created;
    4042                        $this->last_activity      = $group->last_activity;
    Class BP_Groups_Group { 
    5557        function save() {
    5658                global $wpdb, $bp;
    5759
    58                 $this->creator_id   = apply_filters( 'groups_group_creator_id_before_save',   $this->creator_id,   $this->id );
    59                 $this->name         = apply_filters( 'groups_group_name_before_save',         $this->name,         $this->id );
    60                 $this->slug         = apply_filters( 'groups_group_slug_before_save',         $this->slug,         $this->id );
    61                 $this->description  = apply_filters( 'groups_group_description_before_save',  $this->description,  $this->id );
    62                 $this->status       = apply_filters( 'groups_group_status_before_save',       $this->status,       $this->id );
    63                 $this->enable_forum = apply_filters( 'groups_group_enable_forum_before_save', $this->enable_forum, $this->id );
    64                 $this->date_created = apply_filters( 'groups_group_date_created_before_save', $this->date_created, $this->id );
     60                $this->creator_id    = apply_filters( 'groups_group_creator_id_before_save',   $this->creator_id,    $this->id );
     61                $this->name          = apply_filters( 'groups_group_name_before_save',         $this->name,          $this->id );
     62                $this->slug          = apply_filters( 'groups_group_slug_before_save',         $this->slug,          $this->id );
     63                $this->description   = apply_filters( 'groups_group_description_before_save',  $this->description,   $this->id );
     64                $this->status        = apply_filters( 'groups_group_status_before_save',       $this->status,        $this->id );
     65                $this->invite_status = apply_filters( 'groups_group_invite_status_before_save', $this->invite_status, $this->id );
     66                $this->enable_forum  = apply_filters( 'groups_group_enable_forum_before_save', $this->enable_forum,  $this->id );
     67                $this->date_created  = apply_filters( 'groups_group_date_created_before_save', $this->date_created,  $this->id );
    6568
    6669                do_action_ref_array( 'groups_group_before_save', array( &$this ) );
    6770
    Class BP_Groups_Group { 
    7376                                        slug = %s,
    7477                                        description = %s,
    7578                                        status = %s,
     79                                        invite_status = %s,
    7680                                        enable_forum = %d,
    7781                                        date_created = %s
    7882                                WHERE
    Class BP_Groups_Group { 
    8387                                        $this->slug,
    8488                                        $this->description,
    8589                                        $this->status,
     90                                        $this->invite_status,
    8691                                        $this->enable_forum,
    8792                                        $this->date_created,
    8893                                        $this->id
    Class BP_Groups_Group { 
    95100                                        slug,
    96101                                        description,
    97102                                        status,
     103                                        invite_status,
    98104                                        enable_forum,
    99105                                        date_created
    100106                                ) VALUES (
    101                                         %d, %s, %s, %s, %s, %d, %s
     107                                        %d, %s, %s, %s, %s, %s, %d, %s
    102108                                )",
    103109                                        $this->creator_id,
    104110                                        $this->name,
    105111                                        $this->slug,
    106112                                        $this->description,
    107113                                        $this->status,
     114                                        $this->invite_status,
    108115                                        $this->enable_forum,
    109116                                        $this->date_created
    110117                        );
  • bp-groups/bp-groups-functions.php

    function groups_create_group( $args = '' ) { 
    3434         *      'description'
    3535         *      'slug'
    3636         *      'status'
     37         *      'invite_status'
    3738         *      'enable_forum'
    3839         *      'date_created'
    3940         */
    function groups_create_group( $args = '' ) { 
    6162                if ( groups_is_valid_status( $status ) )
    6263                        $group->status = $status;
    6364        }
    64 
     65       
     66        if ( isset( $invite_status ) ) {
     67                if ( groups_is_valid_invite_status( $invite_status ) )
     68                        $group->invite_status = $invite_status;
     69        }
     70       
    6571        if ( isset( $enable_forum ) )
    6672                $group->enable_forum = $enable_forum;
    6773        else if ( !$group_id && !isset( $enable_forum ) )
    function groups_edit_base_group_details( $group_id, $group_name, $group_desc, $n 
    118124        return true;
    119125}
    120126
    121 function groups_edit_group_settings( $group_id, $enable_forum, $status ) {
     127function groups_edit_group_settings( $group_id, $enable_forum, $status, $invite_status ) {
    122128        global $bp;
    123129
    124130        $group = new BP_Groups_Group( $group_id );
    function groups_edit_group_settings( $group_id, $enable_forum, $status ) { 
    132138                groups_accept_all_pending_membership_requests( $group->id );
    133139
    134140        // Now update the status
    135         $group->status = $status;
     141        $group->status          = $status;
     142        $group->invite_status   = $invite_status;
    136143
    137144        if ( !$group->save() )
    138145                return false;
    function groups_is_valid_status( $status ) { 
    198205        return in_array( $status, (array)$bp->groups->valid_status );
    199206}
    200207
     208function groups_is_valid_invite_status( $status ) {
     209        global $bp;
     210
     211        return in_array( $status, (array)$bp->groups->valid_invite_status );
     212}
     213
    201214function groups_check_slug( $slug ) {
    202215        global $bp;
    203216
  • bp-groups/bp-groups-loader.php

    class BP_Groups_Component extends BP_Component { 
    184184                        'private',
    185185                        'hidden'
    186186                ) );
     187               
     188                // Groups invite statuses
     189                $this->valid_invite_status = apply_filters( 'groups_valid_invite_status', array(
     190                        'members',
     191                        'mods',
     192                        'admin'
     193                ) );
    187194
    188195                // Auto join group when non group member performs group activity
    189196                $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' );
    class BP_Groups_Component extends BP_Component { 
    316323                                'item_css_id'     => 'members'
    317324                        );
    318325
    319                         if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $this->current_group->id ) ) {
    320                                 if ( bp_is_active( 'friends' ) ) {
    321                                         $sub_nav[] = array(
    322                                                 'name'            => __( 'Send Invites', 'buddypress' ),
    323                                                 'slug'            => 'send-invites',
    324                                                 'parent_url'      => $group_link,
    325                                                 'parent_slug'     => $this->current_group->slug,
    326                                                 'screen_function' => 'groups_screen_group_invite',
    327                                                 'item_css_id'     => 'invite',
    328                                                 'position'        => 70,
    329                                                 'user_has_access' => $this->current_group->user_has_access
    330                                         );
    331                                 }
     326                        if ( bp_groups_user_can_send_invites() && bp_is_active( 'friends' ) ) {
     327                                $sub_nav[] = array(
     328                                        'name'            => __( 'Send Invites', 'buddypress' ),
     329                                        'slug'            => 'send-invites',
     330                                        'parent_url'      => $group_link,
     331                                        'parent_slug'     => $this->current_group->slug,
     332                                        'screen_function' => 'groups_screen_group_invite',
     333                                        'item_css_id'     => 'invite',
     334                                        'position'        => 70,
     335                                        'user_has_access' => $this->current_group->user_has_access
     336                                );
    332337                        }
    333338
    334339                        parent::_setup_nav( $main_nav, $sub_nav );
  • bp-groups/bp-groups-screens.php

    function groups_screen_group_admin_settings() { 
    495495
    496496                // If the edit form has been submitted, save the edited details
    497497                if ( isset( $_POST['save'] ) ) {
     498               
    498499                        $enable_forum   = ( isset($_POST['group-show-forum'] ) ) ? 1 : 0;
     500
    499501                        $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) );
    500502                        $status         = ( in_array( $_POST['group-status'], (array)$allowed_status ) ) ? $_POST['group-status'] : 'public';
    501503
     504                        $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
     505                        $invite_status         = in_array( $_POST['group-invite-status'], (array)$allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
     506
    502507                        // Check the nonce
    503508                        if ( !check_admin_referer( 'groups_edit_group_settings' ) )
    504509                                return false;
    505510
    506                         if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status ) ) {
     511                        if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) {
    507512                                bp_core_add_message( __( 'There was an error updating group settings, please try again.', 'buddypress' ), 'error' );
    508513                        } else {
    509514                                bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) );
  • bp-groups/bp-groups-template.php

    function bp_group_show_status_setting( $setting, $group = false ) { 
    798798                echo ' checked="checked"';
    799799}
    800800
     801function bp_group_show_invite_status_setting( $setting, $group = false ) {
     802        global $groups_template;
     803
     804        if ( !$group )
     805                $group =& $groups_template->group;
     806
     807        if ( $setting == $group->invite_status )
     808                echo ' checked="checked"';
     809}
     810
    801811function bp_group_admin_memberlist( $admin_list = false, $group = false ) {
    802812        global $groups_template;
    803813
    function bp_new_group_status() { 
    19291939                return apply_filters( 'bp_get_new_group_status', $bp->groups->current_group->status );
    19301940        }
    19311941
     1942function bp_new_group_invite_status() {
     1943        echo bp_get_new_group_invite_status();
     1944}
     1945        function bp_get_new_group_invite_status() {
     1946                global $bp;
     1947                return apply_filters( 'bp_get_new_group_invite_status', $bp->groups->current_group->invite_status );
     1948        }
     1949
    19321950function bp_new_group_avatar( $args = '' ) {
    19331951        echo bp_get_new_group_avatar( $args );
    19341952}
    function bp_group_invite_user_remove_invite_url() { 
    24922510                return wp_nonce_url( site_url( BP_GROUPS_SLUG . '/' . $invites_template->invite->group_id . '/invites/remove/' . $invites_template->invite->user->id ), 'groups_invite_uninvite_user' );
    24932511        }
    24942512
     2513function bp_groups_user_can_send_invites( $group_id = false ) {
     2514        global $bp;
     2515       
     2516        $can_send_invites = false;
     2517        $invite_status    = false;
     2518       
     2519        if ( is_user_logged_in() ) {
     2520                if ( is_super_admin() ) {
     2521                        // Super admins can always send invitations
     2522                        $can_send_invites = true;
     2523                } else {
     2524                        if ( $group_id ) {
     2525                                $group = new BP_Groups_Group( $group_id );
     2526                                $invite_status = $group->invite_status;
     2527                        } else if ( !empty( $bp->groups->current_group ) ) {
     2528                                $group = $bp->groups->current_group;
     2529                        } else {
     2530                                return false;
     2531                        }
     2532                       
     2533                        // This provides adjustable fallback support to pre-1.3 installations,
     2534                        // which had no invite_status
     2535                        $invite_status = !empty( $group->invite_status ) ? $group->invite_status : apply_filters( 'bp_groups_fallback_invite_status', 'members' );
     2536                       
     2537                        switch ( $invite_status ) {
     2538                                case 'admins' :
     2539                                        if ( groups_is_user_admin( bp_loggedin_user_id(), $group->id ) )
     2540                                                $can_send_invites = true;
     2541                                        break;
     2542                               
     2543                                case 'mods' :
     2544                                        if ( groups_is_user_mod( bp_loggedin_user_id(), $group->id ) )
     2545                                                $can_send_invites = true;
     2546                                        break;
     2547                               
     2548                                case 'members' :
     2549                                        if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) )
     2550                                                $can_send_invites = true;
     2551                                        break;
     2552                        }
     2553                }
     2554        }
     2555       
     2556        return apply_filters( 'bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status );
     2557}
     2558
    24952559/***
    24962560 * Groups RSS Feed Template Tags
    24972561 */
  • bp-loader.php

    if ( !defined( 'BP_VERSION' ) ) 
    1818
    1919// Define the database version
    2020if ( !defined( 'BP_DB_VERSION' ) )
    21         define( 'BP_DB_VERSION', 3706 );
     21        define( 'BP_DB_VERSION', 3707 );
    2222
    2323// Place your custom code (actions/filters) in a file called
    2424// '/plugins/bp-custom.php' and it will be loaded before anything else.
  • bp-themes/bp-default/_inc/ajax.php

    function bp_dtheme_ajax_invite_user() { 
    356356        if ( !$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id'] )
    357357                return false;
    358358
    359         if ( !groups_is_user_admin( $bp->loggedin_user->id, $_POST['group_id'] ) )
    360                 return false;
    361 
    362359        if ( !friends_check_friendship( $bp->loggedin_user->id, $_POST['friend_id'] ) )
    363360                return false;
    364361
  • bp-themes/bp-default/groups/create.php

     
    105105                                                        </ul>
    106106                                                </label>
    107107                                        </div>
     108                                       
     109                                        <hr />
     110
     111                                        <h4><?php _e( 'Group Invitations', 'buddypress' ); ?></h4>
     112                               
     113                                        <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ) ?></p>
     114                               
     115                                        <div class="radio">
     116                                                <label>
     117                                                        <input type="radio" name="group-invite-status" value="members"<?php if ( 'members' == bp_get_new_group_invite_status() || !bp_get_new_group_invite_status() ) { ?> checked="checked"<?php } ?>/>
     118                                                        <strong><?php _e( 'All group members', 'buddypress' ) ?></strong>
     119                                                </label>
     120                               
     121                                                <label>
     122                                                        <input type="radio" name="group-invite-status" value="mods"<?php if ( 'mods' == bp_get_new_group_invite_status() ) { ?> checked="checked"<?php } ?>/>
     123                                                        <strong><?php _e( 'Group admins and mods only', 'buddypress' ) ?></strong>
     124                                                </label>
     125                               
     126                                                <label>
     127                                                        <input type="radio" name="group-invite-status" value="admins"<?php if ( 'mods' == bp_get_new_group_invite_status() ) { ?> checked="checked"<?php } ?>/>
     128                                                        <strong><?php _e( 'Group admins only', 'buddypress' ) ?></strong>
     129                                                </label>
     130                                        </div>
    108131
    109132                                        <?php do_action( 'bp_after_group_settings_creation_step' ); ?>
    110133
  • bp-themes/bp-default/groups/single/admin.php

     
    8787                </label>
    8888        </div>
    8989
     90        <hr />
     91
     92        <h4><?php _e( 'Group Invitations', 'buddypress' ); ?></h4>
     93
     94        <p><?php _e( 'Which members of this group are allowed to invite others?', 'buddypress' ) ?></p>
     95
     96        <div class="radio">
     97                <label>
     98                        <input type="radio" name="group-invite-status" value="members"<?php bp_group_show_invite_status_setting( 'members' ) ?> />
     99                        <strong><?php _e( 'All group members', 'buddypress' ) ?></strong>
     100                </label>
     101
     102                <label>
     103                        <input type="radio" name="group-invite-status" value="mods"<?php bp_group_show_invite_status_setting( 'mods' ) ?> />
     104                        <strong><?php _e( 'Group admins and mods only', 'buddypress' ) ?></strong>
     105                </label>
     106
     107                <label>
     108                        <input type="radio" name="group-invite-status" value="admins"<?php bp_group_show_invite_status_setting( 'admins' ) ?> />
     109                        <strong><?php _e( 'Group admins only', 'buddypress' ) ?></strong>
     110                </label>
     111        </div>
     112
     113        <hr />
     114
    90115        <?php do_action( 'bp_after_group_settings_admin' ); ?>
    91116
    92117        <p><input type="submit" value="<?php _e( 'Save Changes', 'buddypress' ) ?> &rarr;" id="save" name="save" /></p>