/**
 * Builds an array for BuddyDrive upload data
 *
 * @uses BuddyDrive_Attachment() to get BuddyDrive basedir and baseurl
 * @return array
 */
function buddydrive_get_upload_data()
{
    if (!class_exists('BuddyDrive_Attachment')) {
        return false;
    }
    $buddydrive_attachment = new BuddyDrive_Attachment();
    return (array) $buddydrive_attachment->get_upload_data();
}
/**
 * Upload a file
 *
 * @since  1.3.0
 *
 * @param  array   $file    the $_FILES var
 * @param  int     $user_id the ID of the user submitting the file
 * @return array            the upload result
 */
function buddydrive_upload_item($file = array(), $user_id = 0)
{
    if (empty($file) || empty($user_id)) {
        return false;
    }
    // In multisite, we need to remove some filters
    if (is_multisite()) {
        remove_filter('upload_mimes', 'check_upload_mimes');
        remove_filter('upload_size_limit', 'upload_size_limit_filter');
    }
    // Accents can be problematic.
    add_filter('sanitize_file_name', 'remove_accents', 10, 1);
    $buddydrive_attachment = new BuddyDrive_Attachment();
    $upload = $buddydrive_attachment->upload($file);
    // Restore/remove filters
    if (is_multisite()) {
        add_filter('upload_mimes', 'check_upload_mimes');
        add_filter('upload_size_limit', 'upload_size_limit_filter');
    }
    // Others can deal with Accents in filename the way they want.
    remove_filter('sanitize_file_name', 'remove_accents', 10, 1);
    $action_suffix = '_failed';
    /**
     * file was uploaded !!
     * Now we can update the user's space
     */
    if (isset($upload['file']) && empty($upload['error'])) {
        $action_suffix = '_succeeded';
        buddydrive_update_user_space($user_id, $file['buddyfile-upload']['size']);
    }
    /**
     * Allow actions once the file is processed
     *
     * Use buddydrive_upload_item_failed to do actions in case the file was not uploaded
     * Use buddydrive_upload_item_succeeded to do actions in case the file was uploaded
     *
     * @since 1.3
     *
     * @param array $upload upload results
     * @param array $file the file before being moved to upload dir
     * @param int   $user_id the ID of the user who uploaded the file.
     */
    do_action("buddydrive_upload_item{$action_suffix}", $upload, $file, $user_id);
    return $upload;
}