' : false;
}
$message->message .= "\n" . $_POST['_buddyitem_link'] . "\n" . $password ;
}
}
add_action( 'messages_message_before_save', 'buddydrive_update_message_content', 10, 1 );
/**
* Files are ajax uploaded !
*
* Adds some customization to the WordPress upload process.
*
* @since 1.0
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses is_multisite() to check for multisite
* @uses wp_handle_upload() to handle file upload
* @uses bp_loggedin_user_id() to get current user id
* @uses get_user_meta() to get some additional data about user (quota)
* @uses update_user_meta() to update this data (quota)
* @uses wp_kses() to sanitize content & pwd
* @uses get_post_meta() to get some privacy data of the parent folder
* @uses buddydrive_get_file_post_type() to get the BuddyFile post type
* @uses buddydrive_save_item() to save the BuddyFile
* @return int id of the the BuddyFile created
*/
function buddydrive_save_new_buddyfile() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
return;
}
// Check the nonce
check_admin_referer( 'buddydrive-form' );
$output = '';
$privacy = $password = $parent = $customs = false;
$groups = array();
$buddydrive_file = buddydrive_upload_item( $_FILES, bp_loggedin_user_id() );
if ( ! empty( $buddydrive_file ) && is_array( $buddydrive_file ) && empty( $buddydrive_file['error'] ) ) {
$name = $_FILES['buddyfile-upload']['name'];
$name_parts = pathinfo( $name );
$name = $name_parts['filename'];
$content = false;
if ( ! empty( $_POST['buddydesc'] ) ) {
$content = wp_kses( $_POST['buddydesc'], array() );
}
// Defaults to private
$privacy = 'private';
if ( ! empty( $_POST['buddyshared'] ) ) {
$privacy = $_POST['buddyshared'];
// Shared in a group
if ( ! empty( $_POST['buddygroup'] ) && 'groups' === $privacy ) {
$groups = $_POST['buddygroup'];
}
// Using a password
if ( ! empty( $_POST['buddypass'] ) ) {
$password = $_POST['buddypass'];
}
}
if ( ! empty( $_POST['buddyfolder'] ) ) {
$parent = (int) $_POST['buddyfolder'];
}
if ( ! empty( $_POST['customs'] ) ) {
$customs = json_decode( wp_unslash( $_POST['customs'] ) );
}
// Construct the buddydrive_file_post_type array
$args = array(
'type' => buddydrive_get_file_post_type(),
'title' => $name,
'content' => $content,
'mime_type' => $buddydrive_file['type'],
'guid' => $buddydrive_file['url'],
'privacy' => $privacy,
'groups' => $groups,
'password' => $password,
);
if ( ! empty( $parent ) ) {
$args['parent_folder_id'] = $parent;
}
if ( ! empty( $customs ) ) {
$args['customs'] = $customs;
}
$buddyfile_id = buddydrive_add_item( $args );
if ( ! empty( $buddyfile_id ) && 'public' === $privacy ) {
buddydrive_set_thumbnail( $buddyfile_id, $buddydrive_file );
}
echo $buddyfile_id;
} else {
echo '
' . __( 'Dismiss', 'buddydrive' ) . '' . sprintf( __( '“%s” has failed to upload due to an error : %s', 'buddydrive' ), esc_html( $_FILES['buddyfile-upload']['name'] ), $buddydrive_file['error'] ) . '
';
}
die();
}
/**
* Handle public file uploaded using buddydrive_editor
*
* @since 1.3.0
* @deprecated 2.0.0
*/
function buddydrive_add_public_file() {
_deprecated_function( __FUNCTION__, '2.0' );
return buddydrive_upload_file();
}
/**
* Gets the latest created file once uploaded
*
* Fixes IE shit
*
* @deprecated 2.0.0
*
* @uses the BuddyDrive loop to return the file created [description]
* @uses buddydrive_get_template() to get the template needed on BP Default or other themes
* @return string html (the table row)
*/
function buddydrive_fetch_created_file() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
$buddyfile_id = intval( $_POST['createdid'] );
if ( ! empty( $buddyfile_id ) ) {
if ( buddydrive_has_items ( 'id=' . $buddyfile_id ) ) {
while ( buddydrive_has_items() ) {
buddydrive_the_item();
bp_get_template_part( 'buddydrive-entry' );
}
}
}
die();
}
add_action( 'wp_ajax_buddydrive_fetchfile', 'buddydrive_fetch_created_file' );
/**
* Create a folder thanks to Ajax
*
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses wp_kses() to sanitize pwd and title
* @uses buddydrive_get_folder_post_type() to get folder post type
* @uses buddydrive_save_item() to save the folder
* @uses the BuddyDrive loop to retrieve the folder created
* @uses buddydrive_get_template() to get the template for bp-default or any theme
* @return string the folder created
*/
function buddydrive_save_new_buddyfolder() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
// Check the nonce
check_admin_referer( 'buddydrive_actions', '_wpnonce_buddydrive_actions' );
if( ! empty( $_POST['title'] ) ) {
$buddydrive_title = $_POST['title'];
if( ! empty( $_POST['sharing_option'] ) ) {
$meta = new stdClass();
$meta->privacy = $_POST['sharing_option'];
if ( $_POST['sharing_option'] == 'password' )
$meta->password = wp_kses( $_POST['sharing_pass'], array() );
if ( $_POST['sharing_option'] == 'groups' )
$meta->groups = $_POST['sharing_group'];
}
$args = array(
'type' => buddydrive_get_folder_post_type(),
'title' => wp_kses( $buddydrive_title, array() ),
'content' => '',
'metas' => $meta
);
$buddyfolder_id = buddydrive_save_item( $args );
if ( buddydrive_has_items ( 'id=' . $buddyfolder_id ) ) {
while ( buddydrive_has_items() ) {
buddydrive_the_item();
bp_get_template_part( 'buddydrive-entry' );
}
}
}
die();
}
add_action( 'wp_ajax_buddydrive_createfolder', 'buddydrive_save_new_buddyfolder');
/**
* Opens a folder and list the files attach to it depending on its privacy
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_buddyfile() to get the folder
* @uses buddydrive_get_folder_post_type() to get the folder post type
* @uses bp_is_active() to check if friends or groups components are actives
* @uses friends_check_friendship() to check if current user is a friend of the folder owner
* @uses groups_is_user_member() to check if the user is a member of the group the folder is attached to
* @uses buddydrive_get_template() to get the template for bp-default or any theme
* @return string the list of files
*/
function buddydrive_open_buddyfolder() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
$buddyfolder_id = $_POST['folder'];
$buddyfolder = buddydrive_get_buddyfile( $buddyfolder_id, buddydrive_get_folder_post_type() );
$result = array();
$access = false;
$buddyscope = $_POST['scope'];
if ( empty( $buddyfolder->ID ) ) {
$result[] = '
'. __( 'Sorry, this folder does not exist anymore.', 'buddydrive' ).'
'. __( 'Sorry, this folder is private', 'buddydrive' ).'
';
}
$name_required = !empty( $_POST['foldername'] ) ? 1 : 0;
if ( ! empty( $name_required ) ) {
$result[] = $buddyfolder->title;
}
}
echo json_encode( $result );
die();
}
add_action( 'wp_ajax_buddydrive_openfolder', 'buddydrive_open_buddyfolder');
add_action( 'wp_ajax_nopriv_buddydrive_openfolder', 'buddydrive_open_buddyfolder');
/**
* Loads more files or folders in the BuddyDrive "explorer"
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_template() to load the BuddyDrive loop
* @return string more items if there are some
*/
function buddydrive_load_more_items() {
ob_start();
bp_get_template_part( 'buddydrive-loop' );
$result = ob_get_contents();
ob_end_clean();
echo $result;
die();
}
add_action( 'wp_ajax_buddydrive_loadmore', 'buddydrive_load_more_items' );
add_action( 'wp_ajax_nopriv_buddydrive_loadmore', 'buddydrive_load_more_items' );
add_action( 'wp_ajax_buddydrive_filterby', 'buddydrive_load_more_items' );
add_action( 'wp_ajax_nopriv_buddydrive_filterby', 'buddydrive_load_more_items' );
/**
* Same as previous except it's for the admin part of the plugin
*
* @deprecated 2.0.0
*
* @uses buddydrive_admin_edit_files_loop() to list the files
* @return string more files if there are any
*/
function buddydrive_admin_ajax_loadmore() {
$folder_id = ! empty( $_POST['folder'] ) ? intval( $_POST['folder'] ) : -1;
$paged = ! empty( $_POST['page'] ) ? intval( $_POST['page'] ) : -1;
ob_start();
buddydrive_admin_edit_files_loop( $folder_id, $paged );
$result = ob_get_contents();
ob_end_clean();
echo $result;
die();
}
add_action( 'wp_ajax_buddydrive_adminloadmore', 'buddydrive_admin_ajax_loadmore');
/**
* Displays a list of the user's group where BuddyDrive is activated
*
* @deprecated 2.0.0
*
* @uses bp_loggedin_user_id() to get current user id
* @uses buddydrive_get_select_user_group() to build the select box
* @return string a select box
*/
function buddydrive_list_user_groups() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
if ( ! bp_is_active('groups') )
exit();
$user_id = ! empty( $_POST['userid'] ) ? intval( $_POST['userid'] ) : bp_loggedin_user_id() ;
$group_id = ! empty( $_POST['groupid'] ) ? intval( $_POST['groupid'] ) : false ;
$name = ! empty( $_POST['selectname'] ) ? $_POST['selectname'] : false ;
$output = buddydrive_get_select_user_group( $user_id, $group_id, $name );
echo $output;
die();
}
add_action( 'wp_ajax_buddydrive_getgroups', 'buddydrive_list_user_groups' );
/**
* Ajax deletes folder or files
*
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses buddydrive_delete_item() deletes the post_type (file or folder)
* @return array the result with the item ids deleted
*/
function buddydrive_delete_items() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
return;
}
// Check the nonce
check_admin_referer( 'buddydrive_actions', '_wpnonce_buddydrive_actions' );
$items = $_POST['items'];
$items = substr( $items, 0, strlen( $items ) - 1 );
$items = explode( ',', $items );
$deleted = buddydrive_delete_item( array( 'ids' => $items, 'user_id' => false ) );
if ( ! empty( $deleted ) ) {
echo json_encode( array( 'result' => count( $deleted ), 'items' => $deleted ) );
} else {
echo json_encode( array( 'result' => 0 ) );
}
die();
}
add_action( 'wp_ajax_buddydrive_deleteitems', 'buddydrive_delete_items');
/**
* Loads a form to edit a file or a folder
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_buddyfile() to get the item to edit
* @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
* @uses buddydrive_get_file_post_type() to get the BuddyFile post type
* @uses wp_kses() to sanitize data
* @uses buddydrive_select_sharing_options() to display the privacy choices
* @uses buddydrive_select_user_group() to display the groups available
* @uses buddydrive_select_folder_options() to display the available folders
* @return string the edit form
*/
function buddydrive_edit_form() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
$item_id = !empty( $_POST['buddydrive_item'] ) ? intval( $_POST['buddydrive_item'] ) : false ;
if ( ! empty( $item_id ) ) {
$item = buddydrive_get_buddyfile( $item_id, array( buddydrive_get_folder_post_type(), buddydrive_get_file_post_type() ) );
?>
title ) ) {
echo json_encode(array(0));
die();
}
$args = array();
if ( ! empty( $_POST['title'] ) )
$args['title'] = wp_kses( $_POST['title'], array() );
if ( ! empty( $_POST['content'] ) )
$args['content'] = wp_kses( $_POST['content'], array() );
if ( ! empty( $_POST['sharing'] ) )
$args['privacy'] = $_POST['sharing'];
if ( ! empty( $_POST['password'] ) )
$args['password'] = wp_kses( $_POST['password'], array() );
if ( ! empty( $_POST['group'] ) )
$args['group'] = $_POST['group'];
$args['parent_folder_id'] = !empty( $_POST['folder'] ) ? intval( $_POST['folder'] ) : 0 ;
// We need to check if the parent folder is attached to a group.
if ( ! empty( $args['parent_folder_id'] ) ) {
$maybe_in_group = get_post_meta( $args['parent_folder_id'], '_buddydrive_sharing_groups', true );
if ( ! empty( $maybe_in_group ) )
$args['group'] = intval( $maybe_in_group );
}
if ( ! empty( $_POST['customs'] ) ) {
$args['buddydrive_meta'] = json_decode( wp_unslash( $_POST['customs'] ) );
}
$updated = buddydrive_update_item( $args, $item );
$result = array();
if ( ! empty( $updated ) ) {
if ( buddydrive_has_items ( 'id=' . $updated ) ) {
ob_start();
while ( buddydrive_has_items() ) {
buddydrive_the_item();
bp_get_template_part( 'buddydrive-entry', false );
}
$result[] = ob_get_contents();
ob_end_clean();
}
$result[] = $args['parent_folder_id'];
echo json_encode($result);
}
else
echo json_encode(array(0));
die();
}
add_action( 'wp_ajax_buddydrive_updateitem', 'buddydrive_ajax_update_item' );
/**
* Post an activity to the group
*
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses bp_loggedin_user_id() to get the current user id
* @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
* @uses buddydrive_get_file_post_type() to get the BuddyFile post type
* @uses get_post_meta() to get item extra data (privacy)
* @uses buddydrive_get_buddyfile() to get item
* @uses groups_get_group() to get the group
* @uses bp_core_get_userlink() to get link to user's profile
* @uses buddydrive_get_name() so that it's possible to brand the plugin
* @uses bp_get_group_permalink() to build the group permalink
* @uses groups_record_activity() to finaly record the activity
* @return int 1 or string an error message
*/
function buddydrive_share_in_group() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
// Check the nonce
check_admin_referer( 'buddydrive_actions', '_wpnonce_buddydrive_actions' );
$buddyitem = intval( $_POST['itemid'] );
if ( empty( $buddyitem ) ) {
_e( 'this is embarassing, it did not work :(', 'buddydrive' );
die();
}
if ( ! bp_is_active( 'groups' ) ) {
_e( 'Group component is deactivated, please contact the administrator.', 'buddydrive' );
die();
}
$link = $_POST['url'] ;
$result = false;
$user_id = bp_loggedin_user_id();
$item_type = ( 'folder' == $_POST['itemtype'] ) ? buddydrive_get_folder_post_type() : buddydrive_get_file_post_type();
if ( ! empty( $buddyitem ) ) {
$group_id = get_post_meta( $buddyitem, '_buddydrive_sharing_groups', true );
if ( empty( $group_id ) ) {
$buddyfile = buddydrive_get_buddyfile( $buddyitem, $item_type );
$parent_id = $buddyfile->post_parent;
$group_id = get_post_meta( $parent_id, '_buddydrive_sharing_groups', true );
}
if ( ! empty( $group_id ) ) {
$group = groups_get_group( array( 'group_id' => $group_id ) );
$action = $activity_action = sprintf( __( '%1$s shared a %2$s Item in the group %3$s', 'buddydrive'), bp_core_get_userlink( $user_id ), esc_html( buddydrive_get_name() ), '' . esc_html( $group->name ) . '' );
$content = $link;
$args = array(
'user_id' => $user_id,
'action' => $action,
'content' => $content,
'type' => 'activity_update',
'component' => 'groups',
'item_id' => $group_id
);
$result = groups_record_activity( $args );
}
}
if ( ! empty( $result ) ) {
// Update the group's latest activity
groups_update_last_activity( $group_id );
echo 1;
} else {
_e( 'this is embarassing, it did not work :(', 'buddydrive' );
}
die();
}
add_action( 'wp_ajax_buddydrive_groupupdate', 'buddydrive_share_in_group' );
/**
* Post an activity in user's profile
*
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses bp_loggedin_user_id() to get the current user id
* @uses buddydrive_get_folder_post_type() to get the BuddyFolder post type
* @uses buddydrive_get_name() so that it's possible to brand the plugin
* @uses buddydrive_get_file_post_type() to get the BuddyFile post type
* @uses buddydrive_get_buddyfile() to get item
* @uses bp_core_get_userlink() to get link to user's profile
* @uses bp_activity_add() to finaly record the activity without updating the latest meta
* @return int 1 or string an error message
*/
function buddydrive_share_in_profile() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
// Check the nonce
check_admin_referer( 'buddydrive_actions', '_wpnonce_buddydrive_actions' );
$buddyitem = intval( $_POST['itemid'] );
if ( empty( $buddyitem ) ) {
_e( 'this is embarassing, it did not work :(', 'buddydrive' );
die();
}
$link = $_POST['url'] ;
$result = false;
$user_id = bp_loggedin_user_id();
$item_type = ( 'folder' == $_POST['itemtype'] ) ? buddydrive_get_folder_post_type() : buddydrive_get_file_post_type();
if ( ! empty( $buddyitem ) ) {
$buddyfile = buddydrive_get_buddyfile( $buddyitem, $item_type );
if ( empty( $buddyfile->ID ) || $buddyfile->check_for != 'public' ) {
// no item or not a public one ??
_e( 'We could not find your BuddyDrive item or its privacy is not set to public', 'buddydrive');
die();
}
$action = sprintf( __( '%1$s shared a %2$s Item', 'buddydrive'), bp_core_get_userlink( $user_id ), buddydrive_get_name() );
$content = $link;
$args = array(
'user_id' => $user_id,
'action' => $action,
'content' => $content,
'primary_link' => bp_core_get_userlink( $user_id, false, true ),
'component' => 'activity',
'type' => 'activity_update'
);
$result = bp_activity_add( $args );
}
if ( ! empty( $result ) )
echo 1;
else
echo _e( 'this is embarassing, it did not work :(', 'buddydrive' );
die();
}
add_action( 'wp_ajax_buddydrive_profileupdate', 'buddydrive_share_in_profile' );
/**
* Updates the display of the quota of the current user
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_user_space_left() to get the quota
* @return string the quota
*/
function buddydrive_update_quota(){
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
add_filter( 'buddydrive_get_user_space_left', 'buddydrive_filter_user_space_left', 10, 2 );
echo buddydrive_get_user_space_left();
remove_filter( 'buddydrive_get_user_space_left', 'buddydrive_filter_user_space_left', 10, 2 );
die();
}
add_action( 'wp_ajax_buddydrive_updatequota', 'buddydrive_update_quota');
/**
* Filters the querystring
*
* Ajax Scope is admin, so we need to uses this trick to have the data we're requesting
*
* @deprecated 2.0.0
*
* @param array $args the arguments of the BuddyDrive query
* @return array the merge $args with post args
*/
function buddydrive_ajax_querystring( $args = false ) {
$args = array();
$filter = ! empty( $_COOKIE['buddydrive_filter'] ) ? $_COOKIE['buddydrive_filter'] : false;
if ( ! empty( $_POST['buddydrive_filter'] ) ) {
$filter = $_POST['buddydrive_filter'];
}
if ( ! empty( $filter ) ) {
switch( $filter ) {
case 'modified' :
$args['orderby'] = 'modified';
$args['order'] = 'DESC';
break;
default:
$args['orderby'] = 'title';
$args['order'] = 'ASC';
break;
}
}
if( !empty( $_POST['page'] ) )
$args['paged'] = $_POST['page'];
if( !empty( $_POST['folder'] ) )
$args['buddydrive_parent'] = $_POST['folder'];
if( !empty( $_POST['exclude'] ) )
$args['exclude'] = $_POST['exclude'];
if( !empty( $_POST['scope'] ) ) {
$args['buddydrive_scope'] = $_POST['scope'];
if( $args['buddydrive_scope'] == 'groups' && !empty( $_POST['group'] ) )
$args['group_id'] = $_POST['group'];
}
return $args;
}
add_filter( 'buddydrive_querystring', 'buddydrive_ajax_querystring', 1, 1 );
/**
* Removes an item from the group (group admins may wish to)
*
* @deprecated 2.0.0
*
* @uses check_admin_referer() for security reasons
* @uses buddydrive_remove_item_from_group() to unattached the file or folder from the group
* @return int the result
*/
function buddydrive_remove_from_group() {
// Bail if not a POST action
if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
return;
// Check the nonce
check_admin_referer( 'buddydrive_actions', '_wpnonce_buddydrive_actions' );
$item_id = $_POST['itemid'];
$group_id = $_POST['groupid'];
if ( empty( $item_id ) || empty( $group_id ) ) {
echo 0;
} else {
$removed = buddydrive_remove_item_from_group( $item_id, $group_id );
/**
* Old UI is expecting 1 and since 2.0.0
* we now return the removed item ID.
*/
if ( $removed ) {
echo 1;
}
}
die();
}
add_action( 'wp_ajax_buddydrive_removefromgroup', 'buddydrive_remove_from_group' );
/**
* Prints the User files screen title
*
* @deprecated 2.0.0
*/
function buddydrive_user_files_title() {
buddydrive_item_nav();
}
/**
* Prints the User files screen content
*
* @deprecated 2.0.0
*/
function buddydrive_user_files_content() {
?>
$user_id,
'per_page' => false,
'paged' => false,
'type' => buddydrive_get_folder_post_type()
);
if ( buddydrive_has_items( $buddydrive_args ) ) {
$output = '';
}
return apply_filters( 'buddydrive_get_select_folder_options', $output, $buddydrive_args );
}
/**
* Displays a select box to choose the group to attach the BuddyDrive Item to
*
* @deprecated 2.0.0
*
* @param int $user_id the user id
* @param int $selected the group id in case of edit form
* @param string $name the name of the select box
* @uses buddydrive_get_select_user_group() to get the select box
*/
function buddydrive_select_user_group( $user_id = false, $selected = false, $name = false ) {
echo buddydrive_get_select_user_group( $user_id, $selected, $name );
}
/**
* Builds the select box to choose the group to attach the BuddyDrive Item to
*
* @deprecated 2.0.0
*
* @param int $user_id the user id
* @param int $selected the group id in case of edit form
* @param string $name the name of the select box
* @uses bp_loggedin_user_id() to get current user id
* @uses groups_get_groups() to list the groups of the user
* @uses groups_get_groupmeta() to check group enabled BuddyDrive
* @uses selected() to eventually activate a group
* @return string the select box
*/
function buddydrive_get_select_user_group( $user_id = false, $selected = false, $name = false ) {
if ( empty( $user_id ) ) {
$user_id = bp_loggedin_user_id();
}
if ( is_array( $selected ) ) {
$selected = reset( $selected );
}
$name = ! empty( $name ) ? ' name="'.$name.'"' : false ;
$output = __( 'No group available for BuddyDrive', 'buddydrive' );
if ( ! bp_is_active( 'groups' ) ) {
return $output;
}
$user_groups = groups_get_groups( array(
'user_id' => $user_id,
'show_hidden' => true,
'per_page' => false,
'meta_query' => array(
array(
'key' => '_buddydrive_enabled',
'value' => 1,
'compare' => '='
) )
) );
if ( empty( $user_groups['groups'] ) ) {
return $output;
}
/**
* Filter here to restrict the groups the user can publish a file into
*
* @since 1.3.4
*
* @param array $value A list of group objects the user can publish a BuddyDrive item into
* @param int $user_id The user ID
*/
$buddydrive_groups = apply_filters( 'buddydrive_filter_select_user_group', $user_groups['groups'], $user_id );
// building the select box
if ( ! empty( $buddydrive_groups ) && is_array( $buddydrive_groups ) ) {
$output = '';
}
return apply_filters( 'buddydrive_get_select_user_group', $output, $buddydrive_groups );
}
/**
* Displays the form to create a new folder
*
* @deprecated 2.0.0
*
* @uses buddydrive_select_sharing_options() to display the privacy select box
*/
function buddydrive_folder_form() {
?>
id;
$buddyscope = 'groups';
}
/**
* Set the defaults for the parameters you are accepting via the "buddydrive_has_items()"
* function call
*/
$defaults = array(
'id' => false,
'name' => false,
'group_id' => $group_id,
'user_id' => $user,
'per_page' => 10,
'paged' => 1,
'type' => $defaulttype,
'buddydrive_scope' => $buddyscope,
'search' => false,
'buddydrive_parent' => 0,
'exclude' => 0,
'orderby' => 'title',
'order' => 'ASC'
);
$r = bp_parse_args( $args, $defaults, 'buddydrive_has_items' );
if ( 'admin' === $r['buddydrive_scope'] && ! bp_current_user_can( 'bp_moderate' ) ) {
$r['buddydrive_scope'] = 'files';
}
$buddydrive_template = new BuddyDrive_Item();
if ( ! empty( $search ) ) {
$buddydrive_template->get( array( 'per_page' => $r['per_page'], 'paged' => $r['paged'], 'type' => $r['type'], 'buddydrive_scope' => $r['buddydrive_scope'], 'search' => $r['search'], 'orderby' => $r['orderby'], 'order' => $r['order'] ) );
} else {
$buddydrive_template->get( array( 'id' => $r['id'], 'name' => $r['name'], 'group_id' => $r['group_id'], 'user_id' => $r['user_id'], 'per_page' => $r['per_page'], 'paged' => $r['paged'], 'type' => $r['type'], 'buddydrive_scope' => $r['buddydrive_scope'], 'buddydrive_parent' => $r['buddydrive_parent'], 'exclude' => $r['exclude'], 'orderby' => $r['orderby'], 'order' => $r['order'] ) );
}
do_action( 'buddydrive_has_items_catch_total_count', $buddydrive_template->query->found_posts );
}
return apply_filters( 'buddydrive_has_items', $buddydrive_template->have_posts() );
}
/**
* BuddyDrive Loop : do we have more items
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return boolean true or false
*/
function buddydrive_has_more_items() {
global $buddydrive_template;
$total_items = intval( $buddydrive_template->query->found_posts );
$pag_num = intval( $buddydrive_template->query->query_vars['posts_per_page'] );
$pag_page = intval( $buddydrive_template->query->query_vars['paged'] );
$remaining_pages = floor( ( $total_items - 1 ) / ( $pag_num * $pag_page ) );
$has_more_items = (int) $remaining_pages ? true : false;
return apply_filters( 'buddydrive_has_more_items', $has_more_items );
}
/**
* BuddyDrive Loop : get the item's data
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return object the item's data
*/
function buddydrive_the_item() {
global $buddydrive_template;
return $buddydrive_template->query->the_post();
}
/**
* Displays the id of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_id() to get the item id
*/
function buddydrive_item_id() {
echo buddydrive_get_item_id();
}
/**
* Gets the item id
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return int the item id
*/
function buddydrive_get_item_id() {
global $buddydrive_template;
return $buddydrive_template->query->post->ID;
}
/**
* Displays the parent id of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_parent_item_id() to get the parent item id
*/
function buddydrive_parent_item_id() {
echo buddydrive_get_parent_item_id();
}
/**
* Gets the parent item id
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return int the parent item id
*/
function buddydrive_get_parent_item_id() {
global $buddydrive_template;
return $buddydrive_template->query->post->post_parent;
}
/**
* Displays the title of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_title() to get the title of the item
*/
function buddydrive_item_title() {
echo buddydrive_get_item_title();
}
/**
* Gets the title of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return string the title of the item
*/
function buddydrive_get_item_title() {
global $buddydrive_template;
return apply_filters('buddydrive_get_item_title', esc_html( $buddydrive_template->query->post->post_title ) );
}
/**
* Displays the description of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_description() to get the description of the item
*/
function buddydrive_item_description() {
echo buddydrive_get_item_description();
}
/**
* Gets the description of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return string the description of the item
*/
function buddydrive_get_item_description() {
global $buddydrive_template;
return apply_filters( 'buddydrive_get_item_description', $buddydrive_template->query->post->post_content );
}
/**
* Do we have a file ?
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_get_file_post_type() to get the BuddyFile post type
* @return boolean true or false
*/
function buddydrive_is_buddyfile() {
global $buddydrive_template;
$is_buddyfile = false;
if ( $buddydrive_template->query->post->post_type == buddydrive_get_file_post_type() )
$is_buddyfile = true;
return $is_buddyfile;
}
/**
* Displays the action link (download or open folder) of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_action_link() to get the action link of the item
*/
function buddydrive_action_link() {
echo buddydrive_get_action_link();
}
/**
* Gets the action link of the BuddyDrive item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_is_buddyfile() to check for a file
* @return string the action link of the item
*/
function buddydrive_get_action_link() {
global $buddydrive_template;
$buddyslug = 'folder';
if ( buddydrive_is_buddyfile() )
$buddyslug = 'file';
$slug = trailingslashit( $buddyslug.'/' . $buddydrive_template->query->post->post_name );
$link = buddydrive_get_root_url() .'/'. $slug;
return apply_filters( 'buddydrive_get_action_link', esc_url( $link ) );
}
/**
* Displays an action link class for the BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_action_link_class() to get the action link class of the item
*/
function buddydrive_action_link_class() {
echo buddydrive_get_action_link_class();
}
/**
* Gets the action link class for the BuddyDrive item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_is_buddyfile() to check for a file
* @return string the action link class for the item
*/
function buddydrive_get_action_link_class() {
$class = array();
$class[] = buddydrive_is_buddyfile() ? 'buddyfile' : 'buddyfolder';
$class = apply_filters( 'buddydrive_get_action_link_class', $class );
return sanitize_html_class( implode( ' ', $class ) );
}
/**
* Displays an attribute to identify a folder or a file
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_attribute() to get the attribute of the item
*/
function buddydrive_item_attribute() {
echo buddydrive_get_item_attribute();
}
/**
* Gets the attribute to identify a folder or a file
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_is_buddyfile() to check for a file
* @return string the attribute for the item
*/
function buddydrive_get_item_attribute() {
$data_attr = false;
if ( ! buddydrive_is_buddyfile() )
$data_attr = ' data-folder="'.buddydrive_get_item_id().'"';
else
$data_attr = ' data-file="'.buddydrive_get_item_id().'"';
return apply_filters( 'buddydrive_get_item_attribute', $data_attr );
}
/**
* Displays the user id of the owner of a BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_owner_id() to get owner's id
*/
function buddydrive_owner_id() {
echo buddydrive_get_owner_id();
}
/**
* Gets the user id of the owner of a BuddyDrive item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return int the owner's id
*/
function buddydrive_get_owner_id() {
global $buddydrive_template;
return apply_filters( 'buddydrive_get_owner_id', $buddydrive_template->query->post->post_author );
}
/**
* Displays the avatar of the owner of a BuddyDrive item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_show_owner_avatar() to get avatar of the owner
*/
function buddydrive_owner_avatar() {
echo buddydrive_get_show_owner_avatar();
}
/**
* Gets the avatar of the owner
*
* @deprecated 2.0.0
*
* @param int $user_id the user id
* @param string $width the width of the avatar
* @param string $height the height of the avatar
* @uses buddydrive_get_owner_id() to get the user id
* @uses bp_core_get_username() to get the username of the owner
* @uses bp_core_fetch_avatar() to get the avatar of the owner
* @return string avatar of the owner
*/
function buddydrive_get_show_owner_avatar( $user_id = false, $width = '32', $height = '32' ) {
if ( empty( $user_id ) )
$user_id = buddydrive_get_owner_id();
$username = bp_core_get_username( $user_id );
$avatar = bp_core_fetch_avatar( array(
'item_id' => $user_id,
'object' => 'user',
'type' => 'thumb',
'avatar_dir' => 'avatars',
'alt' => sprintf( __( 'User Avatar of %s', 'buddydrive' ), $username ),
'width' => $width,
'height' => $height,
'title' => $username
) );
return apply_filters( 'buddydrive_get_show_owner_avatar', $avatar, $user_id, $username );
}
/**
* Displays the link to the owner's home page
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_owner_link() to get the link to the owner's home page
*/
function buddydrive_owner_link() {
echo buddydrive_get_owner_link();
}
/**
* Gets the link to the owner's home page
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_owner_id() to get the owner id
* @uses bp_core_get_userlink() to get the link to owner's home page
* @return the link
*/
function buddydrive_get_owner_link() {
$user_id = buddydrive_get_owner_id();
$userlink = bp_core_get_userlink( $user_id, false, true );
return apply_filters( 'buddydrive_get_owner_link', $userlink );
}
/**
* Displays the avatar of the group the item is attached to
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_group_avatar() to get the group avatar
*/
function buddydrive_group_avatar() {
echo buddydrive_get_group_avatar();
}
/**
* Gets the group avatar the item is attached to
*
* @deprecated 2.0.0
*
* @param int $item_id the item id
* @param boolean $nolink should we wrap a link to group's page
* @param string $width the width of the avatar
* @param string $height the height of the avatar
* @uses buddydrive_get_parent_item_id() to get parent id
* @uses buddydrive_get_item_id() to default to item id
* @uses get_post_meta() to get the group id attached to the item
* @uses groups_get_group() to get the group object for the group_id
* @uses bp_get_group_permalink() to get the group link
* @uses bp_core_fetch_avatar() to get the group avatar
* @uses groups_is_user_member() to check for user's membership
* @uses bp_loggedin_user_id() to get current user id
* @return string the group avatar
*/
function buddydrive_get_group_avatar( $item_id = false, $nolink = false, $width ='32', $height = '32' ) {
$buddydrive_item_group_meta = false;
if ( empty( $item_id ) ) {
$parent_id = buddydrive_get_parent_item_id();
$item_id = ( !empty( $parent_id ) ) ? $parent_id : buddydrive_get_item_id();
}
$buddydrive_item_group_meta = get_post_meta( $item_id, '_buddydrive_sharing_groups', true );
if ( empty( $buddydrive_item_group_meta ) )
return false;
if ( ! bp_is_active( 'groups' ) )
return false;
$group = groups_get_group( array( 'group_id' => $buddydrive_item_group_meta ) );
if ( empty( $group) ) {
return false;
}
$group_link = bp_get_group_permalink( $group );
$group_name = $group->name;
$group_avatar = bp_core_fetch_avatar( array(
'item_id' => $buddydrive_item_group_meta,
'object' => 'group',
'type' => 'thumb',
'avatar_dir' => 'group-avatars',
'alt' => sprintf( __( 'Group logo of %d', 'buddydrive' ), esc_attr( $group_name ) ),
'width' => $width,
'height' => $height,
'title' => esc_attr( $group_name )
) );
if ( 'hidden' == $group->status && ! groups_is_user_member( bp_loggedin_user_id(), $buddydrive_item_group_meta ) && ! is_super_admin() ) {
$nolink = true;
}
if ( ! empty( $nolink ) ) {
return $group_avatar;
} else {
return apply_filters( 'buddydrive_get_group_avatar', '' . $group_avatar .'' );
}
}
/**
* Displays the avatar of the owner or a checkbox
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_owner_or_cb()
*/
function buddydrive_owner_or_cb() {
echo buddydrive_get_owner_or_cb();
}
/**
* Choose between the owner's avatar or a checkbox if on loggedin user's BuddyDrive
*
* @deprecated 2.0.0
*
* @uses bp_is_my_profile() to check we're on a user's profile
* @uses bp_current_action() to check for BuddyDrive scope
* @uses buddydrive_get_item_id() to get the item id
* @uses buddydrive_get_owner_link() to get the link to owner's profile
* @uses buddydrive_get_show_owner_avatar() to get owner's avatar.
* @return string the right html
*/
function buddydrive_get_owner_or_cb() {
$output = '';
if ( bp_is_my_profile() && bp_current_action() == 'files' ) {
$output = '';
} else {
$output = ''. buddydrive_get_show_owner_avatar() . '';
}
return apply_filters( 'buddydrive_get_owner_or_cb', $output );
}
/**
* Displays a checkbox or a table header
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_th_owner_or_cb()
*/
function buddydrive_th_owner_or_cb() {
echo buddydrive_get_th_owner_or_cb();
}
/**
* Gets a checkbox or a table header
*
* @deprecated 2.0.0
*
* @uses bp_is_my_profile() to check we're on a user's profile
* @uses bp_current_action() to check for BuddyDrive scope
* @return string the right html
*/
function buddydrive_get_th_owner_or_cb() {
$output = '';
if ( bp_is_my_profile() && bp_current_action() == 'files')
$output = '';
else
$output = __('Owner', 'buddydrive');
return apply_filters( 'buddydrive_get_th_owner_or_cb', $output );
}
/**
* Displays the privacy of an item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_privacy() to get the privacy option
* @uses buddydrive_get_group_avatar() to get the group avatar of the group the item is attached to
* @uses buddydrive_get_item_id() to get the id of the item
*/
function buddydrive_item_privacy() {
$status = buddydrive_get_item_privacy();
switch ( $status['privacy'] ) {
case 'private' :
echo '';
break;
case 'public' :
echo '';
break;
case 'friends' :
echo '';
break;
case 'password' :
echo '';
break;
case 'groups' :
if( !empty( $status['group'] ) )
echo buddydrive_get_group_avatar( buddydrive_get_item_id() );
else
_e( 'Group', 'buddydrive' );
break;
default:
/**
* Hook here to output the content for your custom privacy options
*
* @since 1.3.3
*
* @param array $status The privacy status.
*/
do_action( 'buddydrive_default_item_privacy', $status );
break;
}
}
/**
* Gets the item's privacy
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_get_item_id() to get the item id
* @uses get_post_meta() to get item's privacy option
* @return array the item's privacy
*/
function buddydrive_get_item_privacy() {
global $buddydrive_template;
$status = array();
$buddyfile_id = buddydrive_get_item_id();
$item_privacy_id = !( empty( $buddydrive_template->query->post->post_parent ) ) ? $buddydrive_template->query->post->post_parent : $buddyfile_id ;
$status['privacy'] = buddydrive_get_privacy( $item_privacy_id );
if ( 'groups' === $status['privacy'] ) {
$status['group'] = get_post_meta( $item_privacy_id, '_buddydrive_sharing_groups', true );
}
return apply_filters( 'buddydrive_get_item_privacy', $status );
}
/**
* Displays the mime type of an item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_mime_type() to get it !
*/
function buddydrive_item_mime_type() {
echo buddydrive_get_item_mime_type();
}
/**
* Gets the mime type of an item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_is_buddyfile() to check for a BuddyFile
* @return string the mime type
*/
function buddydrive_get_item_mime_type() {
global $buddydrive_template;
$mime_type = __( 'folder', 'buddydrive' );
if ( buddydrive_is_buddyfile() ) {
$doc = $buddydrive_template->query->post->guid;
$mime_type = __( 'file', 'buddydrive' );
if ( preg_match( '/^.*?\.(\w+)$/', $doc, $matches ) )
$mime_type = esc_html( $matches[1] ) .' '. $mime_type;
}
return apply_filters('buddydrive_get_item_mime_type', $mime_type );
}
/**
* Displays an icon before the item's title
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_icon() to get the icon
*/
function buddydrive_item_icon() {
echo buddydrive_get_item_icon();
}
/**
* Gets the item's icon
*
* @deprecated 2.0.0
*
* @uses buddydrive_is_buddyfile() to check for a BuddyFile
* @return string html of the icon
*/
function buddydrive_get_item_icon() {
$icon = '';
if ( buddydrive_is_buddyfile() )
$icon = '';
return apply_filters( 'buddydrive_get_item_icon', $icon );
}
/**
* Displays the file name of the uploaded file
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_uploaded_file_name() to get it
*/
function buddydrive_uploaded_file_name() {
echo buddydrive_get_uploaded_file_name();
}
/**
* Gets the mime type of an item
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @return string the uploaded file name
*/
function buddydrive_get_uploaded_file_name() {
global $buddydrive_template;
return basename( $buddydrive_template->query->post->guid );
}
/**
* Displays the last modified date of an item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_item_date() to get it!
*/
function buddydrive_item_date() {
echo buddydrive_get_item_date();
}
/**
* Gets the item date
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses bp_format_time() to format the date
* @return string the formatted date
*/
function buddydrive_get_item_date() {
global $buddydrive_template;
$date = $buddydrive_template->query->post->post_modified_gmt;
$date = bp_format_time( strtotime( $date ), true, false );
return apply_filters( 'buddydrive_get_item_date', $date );
}
/**
* Various checks to see if a user can remove an item from a group
*
* @deprecated 2.0.0
*
* @param int $group_id the group id
* @uses bp_get_current_group_id() to get current group id
* @uses buddydrive_is_group() to check we're on a group's BuddyDrive
* @uses buddydrive_get_parent_item_id() to get parent item
* @uses groups_is_user_admin() to check if the current user is admin of the group
* @uses bp_loggedin_user_id() to get current user id
* @uses is_super_admin() to give power to admin !
* @return boolean $can_remove
*/
function buddydrive_current_user_can_remove( $group_id = false ) {
$can_remove = false;
if ( empty( $group_id ) )
$group_id = bp_get_current_group_id();
if ( ! buddydrive_is_group() || buddydrive_get_parent_item_id() )
$can_remove = false;
else if ( groups_is_user_admin( bp_loggedin_user_id(), $group_id ) )
$can_remove = true;
else if ( is_super_admin() )
$can_remove = true;
return apply_filters( 'buddydrive_current_user_can_remove', $can_remove );
}
/**
* Checks if a user can share an item
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_owner_id() to get owner's id
* @uses bp_loggedin_user_id() to get current user id
* @return boolean true or false
*/
function buddydrive_current_user_can_share() {
$can_share = false;
if ( buddydrive_get_owner_id() == bp_loggedin_user_id() && ! buddydrive_is_group() )
$can_share = true;
return apply_filters( 'buddydrive_current_user_can_share', $can_share );
}
/**
* Checks if the user can get the link of an item
*
* @deprecated 2.0.0
*
* @param array $privacy the sharing options
* @uses buddydrive_get_owner_id() to get owner's id
* @uses bp_loggedin_user_id() to get current user id
* @uses is_user_logged_in() to check if the visitor is not logged in
* @uses bp_is_active() to check for friends and groups component
* @uses friends_check_friendship() to check the friendship between owner and current user
* @uses groups_is_user_member() to check if the current user is member of the group the BuddyDrive item is attached to
* @return boolean true or false
*/
function buddydrive_current_user_can_link( $privacy = false ) {
$can_link = false;
if ( buddydrive_get_owner_id() == bp_loggedin_user_id() )
$can_link = true;
else if ( empty( $privacy ) )
$can_link = false;
else if ( ! is_user_logged_in() )
$can_link = false;
else if ( $privacy['privacy'] == 'public' )
$can_link = true;
else if ( $privacy['privacy'] == 'friends' && bp_is_active('friends') && friends_check_friendship( buddydrive_get_owner_id(), bp_loggedin_user_id() ) )
$can_link = true;
else if ( $privacy['privacy'] == 'groups' && bp_is_active('groups') && ! empty( $privacy['group'] ) && groups_is_user_member( bp_loggedin_user_id(), intval( $privacy['group'] ) ) )
$can_link = true;
else if ( is_super_admin() )
$can_link = true;
return apply_filters( 'buddydrive_current_user_can_link', $can_link );
}
/**
* Displays the link to row actions
*
* @deprecated 2.0.0
*
* @uses buddydrive_get_row_actions()
*/
function buddydrive_row_actions() {
echo buddydrive_get_row_actions();
}
/**
* Builds the row actions
*
* @deprecated 2.0.0
*
* @global object $buddydrive_template
* @uses buddydrive_get_item_id() to get item id
* @uses buddydrive_is_buddyfile() to check for a file
* @uses buddydrive_get_item_description() to get item's description
* @uses buddydrive_get_item_privacy() to get item's privacy options
* @uses buddydrive_current_user_can_link()
* @uses buddydrive_get_action_link()
* @uses buddydrive_current_user_can_share()
* @uses bp_is_active() to check for the messages, activity and group components.
* @uses bp_loggedin_user_domain() to get user's home url
* @uses bp_get_messages_slug() to get the messages component slug
* @uses buddydrive_current_user_can_share()
* @return [type] [description]
*/
function buddydrive_get_row_actions() {
global $buddydrive_template;
$row_actions = $inside_top = $inside_bottom = false;
$buddyfile_id = buddydrive_get_item_id();
if ( buddydrive_is_buddyfile() ) {
$description = buddydrive_get_item_description();
if ( ! empty( $description ) ) {
$inside_top[]= '' . __('Description', 'buddydrive'). '';
$inside_bottom .= '