/** * Gets the space a user is using with his files * * @param string $type html or a diff * @param int $user_id the user id * @uses bp_loggedin_user_id() to get current user id * @uses buddydrive_get_quota_by_user_id() to get quota for user * @uses get_user_meta() to get user's space used so far * @return int|string the space left or html to display it */ function buddydrive_get_user_space_left($type = false, $user_id = false) { if (empty($user_id)) { $user_id = bp_loggedin_user_id(); } $max_space = buddydrive_get_quota_by_user_id($user_id); $max_space = intval($max_space) * 1024 * 1024; $used_space = get_user_meta($user_id, '_buddydrive_total_space', true); $used_space = intval($used_space); $quota = number_format($used_space / $max_space * 100, 2); if ($type == 'diff') { return $max_space - $used_space; } else { return apply_filters('buddydrive_get_user_space_left', sprintf(__('<span id="buddy-quota">%s</span>% used', 'buddydrive'), $quota), $quota); } }
/** * Displays a field to customize the user's upload quota * * @since version 1.1 * * @param object $profileuser data about the user being edited * @global $blog_id the id of the current blog * @uses bp_get_root_blog_id() to make sure we're on the blog BuddyPress is activated on * @uses current_user_can() to check for edit user capability * @uses ve_get_quota_by_user_id() to get user's quota (default to role's default) * @uses esc_html_e() to sanitize translation before display. * @return string html output */ public static function edit_user_quota($profileuser) { global $blog_id; if ($blog_id != bp_get_root_blog_id()) { return; } // Bail if current user cannot edit users if (!current_user_can('edit_user', $profileuser->ID)) { return; } $user_quota = buddydrive_get_quota_by_user_id($profileuser->ID); ?> <h3><?php esc_html_e('User's BuddyDrive quota', 'bbpress'); ?> </h3> <table class="form-table"> <tbody> <tr> <th><label for="_buddydrive_user_quota"><?php esc_html_e('Space available', 'buddydrive'); ?> </label></th> <td> <input name="_buddydrive_user_quota" type="number" min="1" step="1" id="_buddydrive_user_quota" value="<?php echo $user_quota; ?> " class="small-text" /> <label for="_buddydrive_user_quota"><?php _e('MO', 'buddydrive'); ?> </label> </td> </tr> </tbody> </table> <?php }