$item_ids, 'user_id' => false ) ); $redirect_to = add_query_arg( 'deleted', count( $deleted ), $redirect_to ); bp_core_redirect( $redirect_to ); } elseif ( 'edit' == $doaction && ! empty( $_GET['bid'] ) ) { // columns screen option add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) ); get_current_screen()->add_help_tab( array( 'id' => 'buddydrive-edit-overview', 'title' => __( 'Overview', 'buddydrive' ), 'content' => '

' . __( 'This page is a convenient way to edit the details associated with one of your file or folder.', 'buddydrive' ) . '

' . '

' . __( 'The Name and Description box is fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to hide or unhide, or to choose a 1- or 2-column layout for this screen.', 'buddydrive' ) . '

' ) ); // Register metaboxes for the edit screen. add_meta_box( 'submitdiv', _x( 'Save', 'buddydrive-item admin edit screen', 'buddydrive' ), 'buddydrive_admin_edit_metabox_status', get_current_screen()->id, 'side', 'high' ); add_meta_box( 'buddydrive_item_privacy', _x( 'Privacy', 'buddydrive-item admin edit screen', 'buddydrive' ), 'buddydrive_admin_edit_metabox_privacy', get_current_screen()->id, 'side', 'core' ); add_meta_box( 'buddydrive_item_children', _x( 'Files', 'buddydrive-item admin edit screen', 'buddydrive' ), 'buddydrive_admin_edit_metabox_list_files', get_current_screen()->id, 'normal', 'core' ); do_action( 'buddydrive_files_admin_meta_boxes' ); // Enqueue javascripts wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'dashboard' ); wp_enqueue_script( 'comment' ); // Index screen } else { $buddydrive_list_table = new BuddyDrive_List_Table(); } if ( $doaction && 'save' == $doaction ) { // Get item ID $item_id = isset( $_REQUEST['bid'] ) ? (int) $_REQUEST['bid'] : ''; $redirect_to = add_query_arg( array( 'bid' => (int) $item_id, 'action' => 'edit' ), $redirect_to ); // Check this is a valid form submission check_admin_referer( 'edit-buddydrive-item_' . $item_id ); $item = buddydrive_get_buddyfile( $item_id, array( buddydrive_get_folder_post_type(), buddydrive_get_file_post_type() ) ); if ( empty( $item->title ) ) { wp_redirect( $redirect_to ); exit; } $args = array(); if( !empty( $_POST['buddydrive-edit']['item-title'] ) ) $args['title'] = wp_kses( $_POST['buddydrive-edit']['item-title'], array() ); if( !empty( $_POST['buddydrive-edit']['item-content'] ) ) $args['content'] = wp_kses( $_POST['buddydrive-edit']['item-content'], array() ); if( !empty( $_POST['buddydrive-edit']['sharing'] ) ) $args['privacy'] = $_POST['buddydrive-edit']['sharing']; if( !empty( $_POST['buddydrive-edit']['password'] ) ) $args['password'] = wp_kses( $_POST['buddydrive-edit']['password'], array() ); if( !empty( $_POST['buddydrive-edit']['buddygroup'] ) ) $args['group'] = $_POST['buddydrive-edit']['buddygroup']; $args['parent_folder_id'] = !empty( $_POST['buddydrive-edit']['folder'] ) ? intval( $_POST['buddydrive-edit']['folder'] ) : 0 ; $updated = buddydrive_update_item( $args, $item ); if( !empty( $updated ) ) $redirect_to = add_query_arg( 'updated', 1, $redirect_to ); else $redirect_to = add_query_arg( 'error', 1, $redirect_to ); wp_redirect( apply_filters( 'buddydrive_item_admin_edit_redirect', $redirect_to ) ); exit; } } /** * Choose the right section to display * * @uses buddydrive_files_admin_edit() to load the edit page of a single item * @uses buddydrive_files_admin_delete() to request for a confirmation * @uses buddydrive_files_admin_index() to load the list of BuddyDrive items */ function buddydrive_files_admin() { // Decide whether to load the index or edit screen $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; if ( ! empty( $_REQUEST['action2'] ) && $_REQUEST['action2'] != "-1" ) { $doaction = $_REQUEST['action2']; } // Display the single item edit screen if ( 'edit' == $doaction && ! empty( $_GET['bid'] ) ) { buddydrive_files_admin_edit(); // Display the item deletion confirmation screen } else if ( 'delete' == $doaction && ! empty( $_GET['bid'] ) ) { buddydrive_files_admin_delete(); // Otherwise, display the items index screen } else { buddydrive_files_admin_index(); } } /** * The list of BuddyDrive items * * @global object $buddydrive_list_table * @global string $plugin_page * @uses BuddyDrive_List_Table::prepare_items() to prepare the BuddyDrive items for display * @uses screen_icon() to display BuddyDrive icon * @uses wp_html_excerpt truncate the string provided * @uses esc_html sanitize the string * @uses BuddyDrive_List_Table::views() to display the available views * @uses BuddyDrive_List_Table::search_box() to display the search box * @uses BuddyDrive_List_Table::display() to display each item on its own row */ function buddydrive_files_admin_index() { global $buddydrive_list_table, $plugin_page; $messages = array(); // If the user has just made a change to an item, build status messages if ( ! empty( $_REQUEST['deleted'] ) ) { $deleted = ! empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; if ( $deleted > 0 ) { $messages[] = sprintf( _n( '%s item has been permanently deleted.', '%s items have been permanently deleted.', $deleted, 'buddydrive' ), number_format_i18n( $deleted ) ); } } // Prepare the BuddyDrive items for display $buddydrive_list_table->prepare_items(); // Call an action for plugins to modify the messages before we display the edit form do_action( 'buddydrive_files_admin_index', $messages ); ?>

\n", $messages ); ?>

views(); ?>
search_box( __( 'Search all Items', 'buddydrive' ), 'buddydrive-files' ); ?> display(); ?>
title ) ? apply_filters( 'buddydrive_get_item_title', $item->title ) : ''; if( $item->post_type == buddydrive_get_file_post_type() ) remove_meta_box( 'buddydrive_item_children', get_current_screen()->id, 'normal' ); // Construct URL for form $form_url = remove_query_arg( array( 'action', 'action2', 'deleted', 'error' ), $_SERVER['REQUEST_URI'] ); $form_url = add_query_arg( 'action', 'save', $form_url ); // Call an action for plugins to modify the BuddyDrive item before we display the edit form do_action_ref_array( 'buddydrive_files_admin_edit', array( &$item ) ); ?>

\n", $messages ); ?>

post_type == buddydrive_get_file_post_type() ) :?>
id, 'side', $item ); ?>
id, 'normal', $item ); ?> id, 'advanced', $item ); ?>
ID ); ?>

Go back and try again.', 'buddydrive' ), esc_url( bp_get_admin_url( 'admin.php?page=buddydrive-files' ) ) ); ?>

'buddydrive-files', 'bid' => $item->ID ), bp_get_admin_url( 'admin.php' ) ); ?>
'4' ) ); ?>
ID ); $owner = $item->user_id; $avatar = buddydrive_get_show_owner_avatar( $owner ); ?>
: %
post_parent) ) :?>
group, 'buddydrive-edit[buddygroup]' );?>

folder", "buddydrive"), esc_url( add_query_arg( array( 'page' => 'buddydrive-files', 'bid' => $item->post_parent, 'action' => 'edit'), bp_get_admin_url( 'admin.php' ) ) ) );?>

post_type == buddydrive_get_file_post_type() ) :?>
post_parent, 'buddydrive-edit[folder]' );?>
'buddydrive-files'), bp_get_admin_url( 'admin.php' ) ); if ( buddydrive_has_items( array( 'buddydrive_parent' => $folder_id, 'paged' => $paged ) ) ) :?>  >
buddydrive_get_item_id() ), $form_url ); $edit_url = add_query_arg( array( 'action' => 'edit' ), $base_url ); $delete_url = wp_nonce_url( $base_url . "&action=delete", 'buddydrive-delete' ); ?> |
post_type == buddydrive_get_folder_post_type() ) ? true : false ; ?>
ID );?>
ID; } $base_url = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', '_wp_http_referer', 'bid' ), $_SERVER['REQUEST_URI'] ); ?>

false, 'plural' => 'items', 'singular' => 'item', ) ); } /** * Handle filtering of data, sorting, pagination, and any other data-manipulation required prior to rendering. * * @since BuddyDrive (1.0) * @uses get_current_screen() to get current admin screen * @uses WP_List_Table::get_pagenum to set the current page * @uses buddydrive_get_folder_post_type() to get BuddyFolder post type * @uses buddydrive_get_file_post_type() to get BuddyFile post type * @uses The BuddyDrive loop to list items * @uses WP_List_Table::set_pagination_args() to build the pagination */ function prepare_items() { global $buddydrive_template; $screen = get_current_screen(); // Option defaults $include_id = false; $search_terms = false; // Set current page $page = $this->get_pagenum(); // Set per page from the screen options $per_page = 20; // Sort order $order = 'ASC'; if ( !empty( $_REQUEST['order'] ) ) { $order = ( 'desc' == strtolower( $_REQUEST['order'] ) ) ? 'DESC' : 'ASC'; } // Order by - default to title $orderby = false; if ( !empty( $_REQUEST['orderby'] ) ) { switch ( $_REQUEST['orderby'] ) { case 'name' : $orderby = 'title'; break; case 'owner' : $orderby = 'user_id'; break; case 'last_edit' : $orderby = 'post_modified_gmt'; break; } } // Are we doing a search? if ( !empty( $_REQUEST['s'] ) ) $search_terms = $_REQUEST['s']; // Check if user has clicked on a specific item (if so, fetch only that item). if ( !empty( $_REQUEST['bid'] ) ) $include_id = (int) $_REQUEST['bid']; $type = array( buddydrive_get_folder_post_type(), buddydrive_get_file_post_type() ); /* Set the current view */ if ( isset( $_GET['buddydrive_type'] ) && in_array( $_GET['buddydrive_type'], $type ) ) { $this->view = $_GET['buddydrive_type']; $type = $_GET['buddydrive_type']; } $buddydrive_args = array( 'buddydrive_scope' => 'admin', 'per_page' => $per_page, 'paged' => $page, 'type' => $type ); if( !empty( $orderby) ) { $buddydrive_args['orderby'] = $orderby; $buddydrive_args['order'] = $order; } if( !empty( $search_terms ) ) { $buddydrive_args['search'] = $search_terms; } $buddydrive_items = array(); if ( buddydrive_has_items( $buddydrive_args ) ) { while ( buddydrive_has_items() ) { buddydrive_the_item(); $buddydrive_items[] = (array) $buddydrive_template->query->post; } } // Set raw data to display $this->items = $buddydrive_items; // Store information needed for handling table pagination $this->set_pagination_args( array( 'per_page' => $per_page, 'total_items' => $buddydrive_template->query->found_posts, 'total_pages' => ceil( $buddydrive_template->query->found_posts / $per_page ) ) ); } /** * Get an array of all the columns on the page * * @return array the column headers * @since BuddyDrive (1.0) * @uses WP_List_Table::get_columns() * @uses WP_List_Table::get_sortable_columns() */ function get_column_info() { $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_primary_column_name(), ); return $this->_column_headers; } /** * Displays a message on screen when no items are found (e.g. no search matches) * * @since BuddyDrive (1.0) */ function no_items() { _e( 'No items found.', 'buddydrive' ); } /** * Outputs the BuddyDrive Items data table * * @since BuddyDrive (1.0) * @uses WP_List_Table::display_tablenav() * @uses WP_List_Table::get_table_classes() * @uses WP_List_Table::print_column_headers() * @uses WP_List_Table::display_rows_or_placeholder() */ function display() { $this->display_tablenav( 'top' ); ?> print_column_headers(); ?> print_column_headers( false ); ?> display_rows_or_placeholder(); ?>
display_tablenav( 'bottom' ); } /** * Generates content for a single row of the table * * @param object $item The current item * @since BuddyDrive (1.0) * @uses esc_attr() to sanitize data * @uses WP_List_Table::single_row_columns() to display the row */ function single_row( $item = array() ) { static $even = false; $row_classes = array(); if ( $even ) { $row_classes = array( 'even' ); } else { $row_classes = array( 'alternate', 'odd' ); } $row_classes = apply_filters( 'buddydrive_list_table_single_row_class', $row_classes, $item['ID'] ); $row_class = ' class="' . implode( ' ', $row_classes ) . '"'; echo ''; echo $this->single_row_columns( $item ); echo ''; $even = ! $even; } /** * Get the list of views available on this table (e.g. "all", "folder"). * * @since BuddyDrive (1.0) * @uses remove_query_arg() to remove arguments to url * @uses esc_attr() to sanitize data * @uses esc_url() to sanitize url * @uses add_query_arg() to add arguments to the url */ function get_views() { $url_base = remove_query_arg( array( 's','orderby', 'order', 'buddydrive_type', '_wpnonce', '_wp_http_referer', 'action', 'action2', 'paged' ), $_SERVER['REQUEST_URI'] ); ?> __( 'Delete', 'buddydrive' ) ) ); } /** * Get the table column titles. * * @see WP_List_Table::single_row_columns() * @return array * @since BuddyDrive (1.0) */ function get_columns() { return apply_filters( 'buddydrive_list_table_columns', array( 'cb' => '', 'comment' => _x( 'Name', 'BuddyDrive admin Item Name column header', 'buddydrive' ), 'description' => _x( 'Description', 'BuddyDrive admin Item Description column header', 'buddydrive' ), 'status' => _x( 'Privacy', 'BuddyDrive admin Privacy Status column header', 'buddydrive' ), 'owner' => _x( 'Owner', 'BuddyDrive admin Owner column header', 'buddydrive' ), 'mime_type' => _x( 'Mime type', 'BuddyDrive admin Mime type column header', 'buddydrive' ), 'last_edit' => _x( 'Last Edit', 'BuddyDrive admin Last Edit column header', 'buddydrive' ) )); } /** * Get the column names for sortable columns * * @return array * @since BuddyPress (1.0) */ function get_sortable_columns() { return array( 'comment' => array( 'name', false ), 'owner' => array( 'owner', false ), 'last_edit' => array( 'last_edit', false ) ); } /** * Checkbox column * * @param array $item A singular item (one full row) * @see WP_List_Table::single_row_columns() * @since BuddyDrive (1.0) */ function column_cb( $item = array() ) { printf( '', (int) $item['ID'] ); } /** * Name column, and "quick admin" rollover actions. * * Called "comment" in the CSS so we can re-use some WP core CSS. * * @param array $item A singular item (one full row) * @uses bp_get_admin_url() to build the admin url * @uses wp_nonce_url() for security reasons * @uses buddydrive_get_root_url() to get the BuddyDrive root url * @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type * @uses esc_url() to sanitize url * @see WP_List_Table::single_row_columns() * @since BuddyDrive (1.0) */ function column_comment( $item = array() ) { // Preorder items: download | Edit | Delete $actions = array( 'download' => '', 'edit' => '', 'delete' => '', ); // Build actions URLs $base_url = bp_get_admin_url( 'admin.php?page=buddydrive-files&bid=' . $item['ID'] ); $delete_url = wp_nonce_url( $base_url . "&action=delete", 'buddydrive-delete' ); $edit_url = $base_url . '&action=edit'; $download = trailingslashit( 'file/' . $item['post_name'] ); $visit_url = buddydrive_get_root_url() .'/'. $download ; // Download if( $item['post_type'] != buddydrive_get_folder_post_type() ) $actions['download'] = sprintf( '%s', esc_url( $visit_url ), __( 'Download', 'buddydrive' ) ); // Edit $actions['edit'] = sprintf( '%s', esc_url( $edit_url ), __( 'Edit', 'buddydrive' ) ); // Delete $actions['delete'] = sprintf( '%s', esc_url( $delete_url ), __( 'Delete', 'buddydrive' ) ); // Other plugins can filter which actions are shown $actions = apply_filters( 'buddydrive_admin_comment_row_actions', array_filter( $actions ), $item ); $content = apply_filters( 'buddydrive_get_item_title', $item['post_title'] ); $icon = ( $item['post_type'] != buddydrive_get_folder_post_type() ) ? '' : ''; echo $icon . ' ' . $content . ' ' . $this->row_actions( $actions ); } /** * Description column * * @since BuddyDrive (1.0) * @param array $item A singular item (one full row) */ function column_description( $item = array() ) { echo apply_filters( 'buddydrive_get_item_description', $item['post_content'] ); } /** * Status column * * @since BuddyDrive (1.0) * @param array $item A singular item (one full row) * @uses get_post_meta() to get item's privacy * @uses buddydrive_get_group_avatar() to get the avatar of the group the BuddyItem is attached to * */ function column_status( $item = array() ) { $privacy = buddydrive_get_privacy( $item['ID'] ); $status_desc = ''; if( !empty( $privacy ) ) { switch ( $privacy ) { case 'private' : $status_desc = ' ' . __( 'Private', 'buddydrive' ); break; case 'password' : $status_desc = ' ' . __( 'Password protected', 'buddydrive' ); break; case 'public' : $status_desc = ' ' . __( 'Public', 'buddydrive' ); break; case 'friends' : $status_desc = ' ' . __( 'Friends only', 'buddydrive' ); break; case 'groups' : $avatar = buddydrive_get_group_avatar( $item['ID'] ); $status_desc = $avatar; break; } } echo apply_filters_ref_array( 'buddydrive_admin_get_item_status', array( $status_desc, $privacy ) ); } /** * Owners column * * @since BuddyDrive (1.0) * @param array $item A singular item (one full row) * @uses buddydrive_get_show_owner_avatar() to get owner's avatar */ function column_owner( $item = array() ) { echo buddydrive_get_show_owner_avatar( $item['post_author'] ); } /** * Mime type column * * @since BuddyDrive (1.0) * @param array $item A singular item (one full row) */ function column_mime_type( $item = array() ) { $mime_type = !empty( $item['post_mime_type'] ) ? $item['post_mime_type'] : 'folder'; echo apply_filters( 'buddydrive_get_item_mime_type', $mime_type ); } /** * Last Active column * * @since BuddyDrive (1.0) * @param array $item A singular item (one full row) * @uses bp_format_time() to format the date */ function column_last_edit( $item = array() ) { $date = $item['post_modified_gmt']; $date = bp_format_time( strtotime( $date ), true, false ); echo apply_filters( 'buddydrive_get_item_date', $date ); } function column_default( $item = array(), $column_name ) { return apply_filters( "buddydrive_list_table_custom_column", '', $column_name, (int) $item['ID'] ); } /** * Get name of default primary column * * @since BuddyDrive (1.3.0) * @access protected * * @return string */ protected function get_default_primary_column_name() { return 'comment'; } }