From 8454fbfb27a6ad6a789a6b44afac1531b7925353 Mon Sep 17 00:00:00 2001 From: Jonathan Reeve Date: Fri, 31 Oct 2014 09:40:41 -0400 Subject: [PATCH] experimental access control --- includes/functions.php | 77 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 9 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 29f55741..3654901e 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -438,14 +438,73 @@ function bp_docs_get_doc_settings( $doc_id = 0 ) { $saved_settings = array(); } - $default_settings = array( - 'read' => 'anyone', - 'edit' => 'loggedin', - 'read_comments' => 'anyone', - 'post_comments' => 'anyone', - 'view_history' => 'anyone', - 'manage' => 'creator', - ); + // First, try to set the preselected group by looking at the URL params + $selected_group_slug = isset( $_GET['group'] ) ? $_GET['group'] : ''; + + // Support for BP Group Hierarchy + if ( false !== $slash = strrpos( $selected_group_slug, '/' ) ) { + $selected_group_slug = substr( $selected_group_slug, $slash + 1 ); + } + + $selected_group = BP_Groups_Group::get_id_from_slug( $selected_group_slug ); + if ( $selected_group && ! BP_Docs_Groups_Integration::user_can_associate_doc_with_group( bp_loggedin_user_id(), $selected_group ) ) { + $selected_group = 0; + } + + // If the selected group is still 0, see if there's something in the db + if ( ! $selected_group && is_singular() ) { + $selected_group = bp_docs_get_associated_group_id( get_the_ID() ); + } + + // @todo: get the type (public, private, hidden) of the group + + _log( 'selected group is:' ); + _log( $selected_group ); + _log( 'group meta:' ); + $group = groups_get_group( array( 'group_id' => $selected_group ) ); + _log( $group ); + _log( 'group status:' ); + _log( $group->status ); + switch ( $group->status ) { + case 'public': + $default_settings = array( + 'read' => 'anyone', + 'edit' => 'loggedin', + 'read_comments' => 'anyone', + 'post_comments' => 'loggedin', + 'view_history' => 'anyone', + 'manage' => 'creator', + ); + case 'private': + $default_settings = array( + 'read' => 'anyone', + 'edit' => 'group-members', + 'read_comments' => 'anyone', + 'post_comments' => 'group-members', + 'view_history' => 'anyone', + 'manage' => 'creator', + ); + case 'hidden': + _log( 'hidden group!' ); + $default_settings = array( + 'read' => 'group-members', + 'edit' => 'group-members', + 'read_comments' => 'group-members', + 'post_comments' => 'group-members', + 'view_history' => 'group-members', + 'manage' => 'group-members', + ); + default: + $default_settings = array( + 'read' => 'anyone', + 'edit' => 'loggedin', + 'read_comments' => 'anyone', + 'post_comments' => 'loggedin', + 'view_history' => 'anyone', + 'manage' => 'creator', + ); + } + $doc_settings = wp_parse_args( $saved_settings, $default_settings ); @@ -521,7 +580,7 @@ function bp_docs_get_access_options( $settings_field, $doc_id = 0, $group_id = 0 ), 90 => array( 'name' => 'creator', - 'label' => __( 'The Doc author only', 'bp-docs' ) + 'label' => __( 'The doc author only', 'bp-docs' ) ), );