Skip to content

Commit

Permalink
Introduce a new UI for BuddyDrive
Browse files Browse the repository at this point in the history
- This UI uses Backbone, Underscore and jQuery: see #19
- It improves the groups integration, making it possible to directly upload files or create folders from a group. It also makes it possible to attach files to multiple groups and real shared folders between members of a group: see #10
- It is now possible to share folders between friends and between specific members: see #6
- It allowes admin to post new files or folders into other users BuddyDrive using the BuddyDrive Items admin screen: see #11
- Users can upload multiple files at a time: see #42
- A new search field has been added to let users easily find specific files or folders.
  • Loading branch information
imath committed Apr 19, 2016
1 parent f8459c7 commit 1d957d2
Show file tree
Hide file tree
Showing 30 changed files with 7,356 additions and 2,775 deletions.
7 changes: 3 additions & 4 deletions buddydrive.php
Expand Up @@ -11,8 +11,8 @@
Domain Path: /languages/
*/

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;


if ( ! class_exists( 'BuddyDrive' ) ) :
Expand All @@ -35,7 +35,7 @@ class BuddyDrive {
*
* @var string
*/
public static $required_bp_version = '2.4.0';
public static $required_bp_version = '2.5.0';

/**
* BuddyPress config.
Expand Down Expand Up @@ -139,7 +139,6 @@ private function setup_globals() {
$this->domain = 'buddydrive';
$this->errors = new WP_Error(); // Feedback
$this->users_file_count = array();

}

/**
Expand Down
124 changes: 96 additions & 28 deletions includes/admin/buddydrive-admin.php
Expand Up @@ -88,14 +88,33 @@ public function __construct() {
*/
private function setup_globals() {
$buddydrive = buddydrive();
$this->admin_dir = trailingslashit( $buddydrive->includes_dir . 'admin' ); // Admin path
$this->admin_url = trailingslashit( $buddydrive->includes_url . 'admin' ); // Admin url
$this->styles_url = trailingslashit( $this->admin_url . 'css' ); // Admin styles URL*/
$this->js_url = trailingslashit( $this->admin_url . 'js' );
$this->settings_page = bp_core_do_network_admin() ? 'settings.php' : 'options-general.php';
$this->notice_hook = bp_core_do_network_admin() ? 'network_admin_notices' : 'admin_notices' ;
$this->user_columns_filter = bp_core_do_network_admin() ? 'wpmu_users_columns' : 'manage_users_columns';
$this->requires_db_upgrade = buddydrive_get_db_number_version() < buddydrive_get_number_version();
$this->admin_dir = trailingslashit( $buddydrive->includes_dir . 'admin' ); // Admin path
$this->admin_url = trailingslashit( $buddydrive->includes_url . 'admin' ); // Admin url
$this->styles_url = trailingslashit( $this->admin_url . 'css' ); // Admin styles URL*/
$this->js_url = trailingslashit( $this->admin_url . 'js' );
$this->settings_page = 'options-general.php';
$this->notice_hook = 'admin_notices' ;
$this->user_columns_filter = 'manage_users_columns';
$this->requires_db_upgrade = buddydrive_get_db_number_version() < buddydrive_get_number_version();

if ( bp_core_do_network_admin() ) {
$this->settings_page = 'settings.php';
$this->notice_hook = 'network_admin_notices';
$this->user_columns_filter = 'wpmu_users_columns';
$this->buddydrive_page = esc_url( add_query_arg( 'page','buddydrive-files', network_admin_url( 'admin.php' ) ) );
} else {
$this->buddydrive_page = esc_url( add_query_arg( 'page','buddydrive-files', admin_url( 'admin.php' ) ) );
}

// We are now using a BackBone UI
$this->items_admin_callback = array( $this, 'items_admin_screen' );

/**
* Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI
*/
if ( true === buddydrive_use_deprecated_ui() ) {
$this->items_admin_callback = 'buddydrive_files_admin';
}
}

/**
Expand All @@ -106,7 +125,13 @@ private function setup_globals() {
*/
private function includes() {
require( $this->admin_dir . 'buddydrive-settings.php' );
require( $this->admin_dir . 'buddydrive-items.php' );

/**
* Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI
*/
if ( true === buddydrive_use_deprecated_ui() ) {
require( $this->admin_dir . 'buddydrive-items.php' );
}
}

/**
Expand All @@ -131,17 +156,17 @@ private function setup_actions() {
add_action( $this->notice_hook, array( $this, 'activation_notice' ), 9 ); // Checks for BuddyDrive Upload directory once activated
add_action( 'buddydrive_admin_register_settings', array( $this, 'register_admin_settings' ) ); // Add settings
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 1 ); // Add enqueued JS and CSS
add_action( 'wp_ajax_buddydrive_upgrader', array( $this, 'do_upgrade' ) );

/** Filters ***********************************************************/

// Modify BuddyDrive's admin links
add_filter( 'plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );
add_filter( 'network_admin_plugin_action_links', array( $this, 'modify_plugin_action_links' ), 10, 2 );

// Filters the user space left output to strip html tags
add_filter( 'buddydrive_get_user_space_left', 'buddydrive_filter_user_space_left' , 10, 2 );

add_action( 'wp_ajax_buddydrive_upgrader', array( $this, 'do_upgrade' ) );
if ( ! buddydrive_use_deprecated_ui() ) {
add_filter( 'bp_admin_menu_order', array( $this, 'items_admin_menu_order' ), 10, 1 );
}

// Allow plugins to modify these actions
do_action_ref_array( 'buddydrive_admin_loaded', array( &$this ) );
Expand Down Expand Up @@ -176,7 +201,7 @@ public function admin_menus() {
_x( 'BuddyDrive', 'BuddyDrive User Files Admin menu title', 'buddydrive' ),
'manage_options',
'buddydrive-files',
'buddydrive_files_admin',
$this->items_admin_callback,
'div'
);

Expand All @@ -203,8 +228,13 @@ public function admin_menus() {
}


// Hook into early actions to load custom CSS and our init handler.
add_action( "load-$hook", 'buddydrive_files_admin_load' );
/**
* Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI
*/
if ( true === buddydrive_use_deprecated_ui() ) {
// Hook into early actions to load custom CSS and our init handler.
add_action( "load-$hook", 'buddydrive_files_admin_load' );
}

// Putting user edit hooks there, this way we're sure they will load at the right place
add_action( 'edit_user_profile', array( $this, 'edit_user_quota' ), 10, 1 );
Expand Down Expand Up @@ -390,18 +420,25 @@ public static function register_admin_settings() {
* @uses wp_enqueue_script() to enqueue the script
*/
public function enqueue_scripts( $hook = false ) {
if ( in_array( $hook, $this->hook_suffixes ) ) {
$min = '.min';
if ( defined( 'SCRIPT_DEBUG' ) && true == SCRIPT_DEBUG ) {
$min = '';
}
if ( ! in_array( $hook, $this->hook_suffixes ) ) {
return;
}

wp_enqueue_style( 'buddydrive-admin-css', $this->styles_url .'buddydrive-admin.css' );
$min = '.min';
if ( defined( 'SCRIPT_DEBUG' ) && true == SCRIPT_DEBUG ) {
$min = '';
}

if ( !empty( $this->hook_suffixes[1] ) && $hook == $this->hook_suffixes[1] && !empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
wp_enqueue_script ( 'buddydrive-admin-js', $this->js_url .'buddydrive-admin.js' );
wp_localize_script( 'buddydrive-admin-js', 'buddydrive_admin', buddydrive_get_js_l10n() );
wp_enqueue_style( 'buddydrive-admin-css', $this->styles_url .'buddydrive-admin.css', array(), buddydrive_get_version() );

if ( ! empty( $this->hook_suffixes[1] ) && $hook == $this->hook_suffixes[1] && ! empty( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) {
/**
* Use add_filter( 'buddydrive_use_deprecated_ui', '__return_true' ); to use the deprecated UI
*/
if ( true === buddydrive_use_deprecated_ui() ) {
wp_enqueue_script ( 'buddydrive-admin-js', $this->js_url .'buddydrive-admin.js' );
wp_localize_script( 'buddydrive-admin-js', 'buddydrive_admin', buddydrive_get_js_l10n() );
}
}

if ( isset( $this->hook_suffixes['upgrade'] ) && $hook === $this->hook_suffixes['upgrade'] ) {
Expand Down Expand Up @@ -749,11 +786,23 @@ public static function user_quota_column( $columns = array() ) {
*/
public static function user_quota_row( $retval = '', $column_name = '', $user_id = 0 ) {

if ( 'user_quota' === $column_name && ! empty( $user_id ) )
$retval = buddydrive_get_user_space_left( false, $user_id ) .'%';
if ( 'user_quota' === $column_name && ! empty( $user_id ) ) {
$quota = buddydrive_get_user_space_data( $user_id );

if ( ! empty( $quota['percent'] ) && 0 < (float) $quota['percent'] ) {
$output = sprintf(
'<a href="%1$s" title="%2$s">%3$s<a>',
buddydrive()->admin->buddydrive_page . '#user/' . $user_id,
esc_attr__( 'View all items for this user', 'buddydrive' ),
$quota['percent'] . '%'
);
} else {
$output = $quota['percent'] . '%';
}
}

// Pass retval through
return $retval;
return $output;
}

public function upgrade_screen() {
Expand Down Expand Up @@ -855,6 +904,25 @@ public function do_upgrade() {

wp_send_json_success( array( 'done' => $did, 'action_id' => $_POST['id'] ) );
}

public function items_admin_menu_order( $custom_menus = array() ) {
array_push( $custom_menus, 'buddydrive-files' );
return $custom_menus;
}

public function items_admin_screen() {
?>
<div class="wrap">
<h1><?php esc_html_e( 'BuddyDrive Items', 'buddydrive' ); ?></h1>

<?php
/**
* Load The BuddyDrive UI
*/
buddydrive_ui(); ?>
</div>
<?php
}
}

endif;
Expand Down
10 changes: 8 additions & 2 deletions includes/admin/buddydrive-items.php
@@ -1,4 +1,10 @@
<?php
/**
* Functions & classes to manage BuddyDrive items
*
* @since 1.0
* @deprecated 2.0.0
*/

// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
Expand Down Expand Up @@ -67,9 +73,9 @@ function buddydrive_files_admin_load() {

$item_ids = wp_parse_id_list( $_GET['bid'] );

$count = buddydrive_delete_item( array( 'ids' => $item_ids, 'user_id' => false ) );
$deleted = buddydrive_delete_item( array( 'ids' => $item_ids, 'user_id' => false ) );

$redirect_to = add_query_arg( 'deleted', $count, $redirect_to );
$redirect_to = add_query_arg( 'deleted', count( $deleted ), $redirect_to );

bp_core_redirect( $redirect_to );

Expand Down
7 changes: 5 additions & 2 deletions includes/buddydrive-actions.php
@@ -1,7 +1,10 @@
<?php
/**
* BuddyDrive Actions
*/

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;


// BuddyPress / WordPress actions to BuddyDrive ones
Expand Down
38 changes: 33 additions & 5 deletions includes/buddydrive-component.php
@@ -1,6 +1,10 @@
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* BuddyDrive Component
*/

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

/**
* Main BuddyDrive Component Class
Expand Down Expand Up @@ -74,9 +78,13 @@ public function includes( $includes = array() ) {
'buddydrive-item-ajax.php',
);

if ( bp_is_active( 'groups' ) )
if ( bp_is_active( 'groups' ) ) {
$includes[] = 'buddydrive-group-class.php';
}

if ( buddydrive_use_deprecated_ui() ) {
$includes[] = 'buddydrive-item-deprecated.php';
}

parent::includes( $includes );
}
Expand Down Expand Up @@ -126,7 +134,9 @@ public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
$bp = buddypress();

$nav = buddydrive_get_name();
if ( bp_is_my_profile() ) {

// Only show count on older UI
if ( bp_is_my_profile() && buddydrive_use_deprecated_ui() ) {
$nav = sprintf( __( '%s <span class="count">%d</span>', 'buddydrive' ), buddydrive_get_name(), buddydrive_count_user_files() );
}

Expand Down Expand Up @@ -164,6 +174,17 @@ public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
);
}

if ( ! buddydrive_use_deprecated_ui() && bp_is_my_profile() ) {
$sub_nav[] = array(
'name' => __( 'Between Members', 'buddydrive' ),
'slug' => 'members',
'parent_url' => $buddydrive_link,
'parent_slug' => $this->slug,
'screen_function' => array( 'BuddyDrive_Screens', 'user_files' ),
'position' => 30,
);
}

parent::setup_nav( $main_nav, $sub_nav );
}

Expand Down Expand Up @@ -217,6 +238,14 @@ public function setup_admin_bar( $wp_admin_nav = array() ) {
);
}

if ( ! buddydrive_use_deprecated_ui() ) {
$wp_admin_nav[] = array(
'parent' => 'my-account-' . $buddydrive_slug,
'id' => 'my-account-' . $buddydrive_slug .'-members',
'title' => __( 'Between Members', 'buddydrive' ),
'href' => trailingslashit( $buddydrive_link . 'members' )
);
}
}

parent::setup_admin_bar( $wp_admin_nav );
Expand Down Expand Up @@ -261,7 +290,6 @@ public function register_post_types() {
// Register the post type for files.
register_post_type( buddydrive_get_file_post_type(), $args_file );


$labels_folder = array(
'name' => __( 'BuddyFolders', 'buddydrive' ),
'singular' => __( 'BuddyFolder', 'buddydrive' ),
Expand Down

0 comments on commit 1d957d2

Please sign in to comment.