/**
 * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_change_avatar()
{
    global $bp;
    if (!bp_is_my_profile() && !is_super_admin()) {
        return false;
    }
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    $bp->avatar_admin->step = 'upload-image';
    if (!empty($_FILES)) {
        // Check the nonce
        check_admin_referer('bp_avatar_upload');
        // Pass the file to the avatar upload handler
        if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
            $bp->avatar_admin->step = 'crop-image';
            // Make sure we include the jQuery jCrop file for image cropping
            add_action('nxt_print_scripts', 'bp_core_add_jquery_cropper');
        }
    }
    // If the image cropping is done, crop the image and save a full/thumb version
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_cropstore');
        if (!bp_core_avatar_handle_crop(array('item_id' => $bp->displayed_user->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
            bp_core_add_message(__('There was a problem cropping your avatar, please try uploading it again', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Your new avatar was uploaded successfully!', 'buddypress'));
            do_action('xprofile_avatar_uploaded');
        }
    }
    do_action('xprofile_screen_change_avatar');
    bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
Ejemplo n.º 2
0
/**
 * Ajax upload an avatar.
 *
 * @since 2.3.0
 *
 * @return  string|null A json object containing success data if the upload succeeded
 *                      error message otherwise.
 */
function bp_avatar_ajax_upload()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        wp_die();
    }
    /**
     * Sending the json response will be different if
     * the current Plupload runtime is html4
     */
    $is_html4 = false;
    if (!empty($_POST['html4'])) {
        $is_html4 = true;
    }
    // Check the nonce
    check_admin_referer('bp-uploader');
    // Init the BuddyPress parameters
    $bp_params = array();
    // We need it to carry on
    if (!empty($_POST['bp_params'])) {
        $bp_params = $_POST['bp_params'];
    } else {
        bp_attachments_json_response(false, $is_html4);
    }
    // We need the object to set the uploads dir filter
    if (empty($bp_params['object'])) {
        bp_attachments_json_response(false, $is_html4);
    }
    // Capability check
    if (!bp_attachments_current_user_can('edit_avatar', $bp_params)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $bp = buddypress();
    $bp_params['upload_dir_filter'] = '';
    $needs_reset = array();
    if ('user' === $bp_params['object'] && bp_is_active('xprofile')) {
        $bp_params['upload_dir_filter'] = 'xprofile_avatar_upload_dir';
        if (!bp_displayed_user_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('key' => 'displayed_user', 'value' => $bp->displayed_user);
            $bp->displayed_user->id = $bp_params['item_id'];
        }
    } elseif ('group' === $bp_params['object'] && bp_is_active('groups')) {
        $bp_params['upload_dir_filter'] = 'groups_avatar_upload_dir';
        if (!bp_get_current_group_id() && !empty($bp_params['item_id'])) {
            $needs_reset = array('component' => 'groups', 'key' => 'current_group', 'value' => $bp->groups->current_group);
            $bp->groups->current_group = groups_get_group(array('group_id' => $bp_params['item_id'], 'populate_extras' => false));
        }
    } else {
        /**
         * Filter here to deal with other components.
         *
         * @since 2.3.0
         *
         * @var array $bp_params the BuddyPress Ajax parameters.
         */
        $bp_params = apply_filters('bp_core_avatar_ajax_upload_params', $bp_params);
    }
    if (!isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    /**
     * The BuddyPress upload parameters is including the Avatar UI Available width,
     * add it to the avatar_admin global for a later use.
     */
    if (isset($bp_params['ui_available_width'])) {
        $bp->avatar_admin->ui_available_width = (int) $bp_params['ui_available_width'];
    }
    // Upload the avatar
    $avatar = bp_core_avatar_handle_upload($_FILES, $bp_params['upload_dir_filter']);
    // Reset objects
    if (!empty($needs_reset)) {
        if (!empty($needs_reset['component'])) {
            $bp->{$needs_reset['component']}->{$needs_reset['key']} = $needs_reset['value'];
        } else {
            $bp->{$needs_reset['key']} = $needs_reset['value'];
        }
    }
    // Init the feedback message
    $feedback_message = false;
    if (!empty($bp->template_message)) {
        $feedback_message = $bp->template_message;
        // Remove template message.
        $bp->template_message = false;
        $bp->template_message_type = false;
        @setcookie('bp-message', false, time() - 1000, COOKIEPATH);
        @setcookie('bp-message-type', false, time() - 1000, COOKIEPATH);
    }
    if (empty($avatar)) {
        // Default upload error
        $message = __('Upload failed.', 'buddypress');
        // Use the template message if set
        if (!empty($feedback_message)) {
            $message = $feedback_message;
        }
        // Upload error reply
        bp_attachments_json_response(false, $is_html4, array('type' => 'upload_error', 'message' => $message));
    }
    if (empty($bp->avatar_admin->image->file)) {
        bp_attachments_json_response(false, $is_html4);
    }
    $uploaded_image = @getimagesize($bp->avatar_admin->image->file);
    // Set the name of the file
    $name = $_FILES['file']['name'];
    $name_parts = pathinfo($name);
    $name = trim(substr($name, 0, -(1 + strlen($name_parts['extension']))));
    // Finally return the avatar to the editor
    bp_attachments_json_response(true, $is_html4, array('name' => $name, 'url' => $bp->avatar_admin->image->url, 'width' => $uploaded_image[0], 'height' => $uploaded_image[1], 'feedback' => $feedback_message));
}
Ejemplo n.º 3
0
/**
 * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_change_avatar()
{
    // Bail if not the correct screen
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    // Bail if there are action variables
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    $bp = buddypress();
    if (!isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    $bp->avatar_admin->step = 'upload-image';
    if (!empty($_FILES)) {
        // Check the nonce
        check_admin_referer('bp_avatar_upload');
        // Pass the file to the avatar upload handler
        if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
            $bp->avatar_admin->step = 'crop-image';
            // Make sure we include the jQuery jCrop file for image cropping
            add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
        }
    }
    // If the image cropping is done, crop the image and save a full/thumb version
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_cropstore');
        $args = array('item_id' => bp_displayed_user_id(), 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
        if (!bp_core_avatar_handle_crop($args)) {
            bp_core_add_message(__('There was a problem cropping your profile photo.', 'buddypress'), 'error');
        } else {
            /**
             * Fires right before the redirect, after processing a new avatar.
             *
             * @since 1.1.0
             * @since 2.3.4 Add two new parameters to inform about the user id and
             *              about the way the avatar was set (eg: 'crop' or 'camera')
             *
             * @param string $item_id Inform about the user id the avatar was set for
             * @param string $value Inform about the way the avatar was set ('crop')
             */
            do_action('xprofile_avatar_uploaded', (int) $args['item_id'], 'crop');
            bp_core_add_message(__('Your new profile photo was uploaded successfully.', 'buddypress'));
            bp_core_redirect(bp_displayed_user_domain());
        }
    }
    /**
     * Fires right before the loading of the XProfile change avatar screen template file.
     *
     * @since BuddyPress (1.0.0)
     */
    do_action('xprofile_screen_change_avatar');
    /**
     * Filters the template to load for the XProfile change avatar screen.
     *
     * @since BuddyPress (1.0.0)
     *
     * @param string $template Path to the XProfile change avatar template to load.
     */
    bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
Ejemplo n.º 4
0
/**
 * Handle the display of a group's Change Avatar page.
 */
function groups_screen_group_admin_avatar()
{
    if ('group-avatar' != bp_get_group_current_admin_tab()) {
        return false;
    }
    // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here.
    if (!bp_is_item_admin() || bp_disable_group_avatar_uploads() || !buddypress()->avatar->show_avatars) {
        return false;
    }
    $bp = buddypress();
    // If the group admin has deleted the admin avatar.
    if (bp_is_action_variable('delete', 1)) {
        // Check the nonce.
        check_admin_referer('bp_group_avatar_delete');
        if (bp_core_delete_existing_avatar(array('item_id' => $bp->groups->current_group->id, 'object' => 'group'))) {
            bp_core_add_message(__('The group profile photo was deleted successfully!', 'buddypress'));
        } else {
            bp_core_add_message(__('There was a problem deleting the group profile photo. Please try again.', 'buddypress'), 'error');
        }
    }
    if (!isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    $bp->avatar_admin->step = 'upload-image';
    if (!empty($_FILES)) {
        // Check the nonce.
        check_admin_referer('bp_avatar_upload');
        // Pass the file to the avatar upload handler.
        if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
            $bp->avatar_admin->step = 'crop-image';
            // Make sure we include the jQuery jCrop file for image cropping.
            add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
        }
    }
    // If the image cropping is done, crop the image and save a full/thumb version.
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce.
        check_admin_referer('bp_avatar_cropstore');
        $args = array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
        if (!bp_core_avatar_handle_crop($args)) {
            bp_core_add_message(__('There was a problem cropping the group profile photo.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('The new group profile photo was uploaded successfully.', 'buddypress'));
        }
    }
    /**
     * Fires before the loading of the group Change Avatar page template.
     *
     * @since 1.0.0
     *
     * @param int $id ID of the group that is being displayed.
     */
    do_action('groups_screen_group_admin_avatar', $bp->groups->current_group->id);
    /**
     * Filters the template to load for a group's Change Avatar page.
     *
     * @since 1.0.0
     *
     * @param string $value Path to a group's Change Avatar template.
     */
    bp_core_load_template(apply_filters('groups_template_group_admin_avatar', 'groups/single/home'));
}
Ejemplo n.º 5
0
/**
 * Catch and process group creation form submissions.
 */
function groups_action_create_group()
{
    global $bp;
    // If we're not at domain.org/groups/create/ then return false
    if (!bp_is_groups_component() || !bp_is_current_action('create')) {
        return false;
    }
    if (!is_user_logged_in()) {
        return false;
    }
    if (!bp_user_can_create_groups()) {
        bp_core_add_message(__('Sorry, you are not allowed to create groups.', 'buddypress'), 'error');
        bp_core_redirect(trailingslashit(bp_get_root_domain() . '/' . bp_get_groups_root_slug()));
    }
    // Make sure creation steps are in the right order
    groups_action_sort_creation_steps();
    // If no current step is set, reset everything so we can start a fresh group creation
    $bp->groups->current_create_step = bp_action_variable(1);
    if (!bp_get_groups_current_create_step()) {
        unset($bp->groups->current_create_step);
        unset($bp->groups->completed_create_steps);
        setcookie('bp_new_group_id', false, time() - 1000, COOKIEPATH);
        setcookie('bp_completed_create_steps', false, time() - 1000, COOKIEPATH);
        $reset_steps = true;
        $keys = array_keys($bp->groups->group_creation_steps);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . array_shift($keys) . '/');
    }
    // If this is a creation step that is not recognized, just redirect them back to the first screen
    if (bp_get_groups_current_create_step() && empty($bp->groups->group_creation_steps[bp_get_groups_current_create_step()])) {
        bp_core_add_message(__('There was an error saving group details. Please try again.', 'buddypress'), 'error');
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
    }
    // Fetch the currently completed steps variable
    if (isset($_COOKIE['bp_completed_create_steps']) && !isset($reset_steps)) {
        $bp->groups->completed_create_steps = json_decode(base64_decode(stripslashes($_COOKIE['bp_completed_create_steps'])));
    }
    // Set the ID of the new group, if it has already been created in a previous step
    if (isset($_COOKIE['bp_new_group_id'])) {
        $bp->groups->new_group_id = (int) $_COOKIE['bp_new_group_id'];
        $bp->groups->current_group = groups_get_group(array('group_id' => $bp->groups->new_group_id));
        // Only allow the group creator to continue to edit the new group
        if (!bp_is_group_creator($bp->groups->current_group, bp_loggedin_user_id())) {
            bp_core_add_message(__('Only the group creator may continue editing this group.', 'buddypress'), 'error');
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/');
        }
    }
    // If the save, upload or skip button is hit, lets calculate what we need to save
    if (isset($_POST['save'])) {
        // Check the nonce
        check_admin_referer('groups_create_save_' . bp_get_groups_current_create_step());
        if ('group-details' == bp_get_groups_current_create_step()) {
            if (empty($_POST['group-name']) || empty($_POST['group-desc']) || !strlen(trim($_POST['group-name'])) || !strlen(trim($_POST['group-desc']))) {
                bp_core_add_message(__('Please fill in all of the required fields', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            $new_group_id = isset($bp->groups->new_group_id) ? $bp->groups->new_group_id : 0;
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug(sanitize_title(esc_attr($_POST['group-name']))), 'date_created' => bp_core_current_time(), 'status' => 'public')))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
        }
        if ('group-settings' == bp_get_groups_current_create_step()) {
            $group_status = 'public';
            $group_enable_forum = 1;
            if (!isset($_POST['group-show-forum'])) {
                $group_enable_forum = 0;
            } else {
                // Create the forum if enable_forum = 1
                if (bp_is_active('forums') && !groups_get_groupmeta($bp->groups->new_group_id, 'forum_id')) {
                    groups_new_group_forum();
                }
            }
            if ('private' == $_POST['group-status']) {
                $group_status = 'private';
            } else {
                if ('hidden' == $_POST['group-status']) {
                    $group_status = 'hidden';
                }
            }
            if (!($bp->groups->new_group_id = groups_create_group(array('group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum)))) {
                bp_core_add_message(__('There was an error saving group details, please try again.', 'buddypress'), 'error');
                bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/');
            }
            // Set the invite status
            // Checked against a whitelist for security
            $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
            $invite_status = !empty($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
            groups_update_groupmeta($bp->groups->new_group_id, 'invite_status', $invite_status);
        }
        if ('group-invites' === bp_get_groups_current_create_step()) {
            if (!empty($_POST['friends'])) {
                foreach ((array) $_POST['friends'] as $friend) {
                    groups_invite_user(array('user_id' => $friend, 'group_id' => $bp->groups->new_group_id));
                }
            }
            groups_send_invites(bp_loggedin_user_id(), $bp->groups->new_group_id);
        }
        do_action('groups_create_group_step_save_' . bp_get_groups_current_create_step());
        do_action('groups_create_group_step_complete');
        // Mostly for clearing cache on a generic action name
        /**
         * Once we have successfully saved the details for this step of the creation process
         * we need to add the current step to the array of completed steps, then update the cookies
         * holding the information
         */
        $completed_create_steps = isset($bp->groups->completed_create_steps) ? $bp->groups->completed_create_steps : array();
        if (!in_array(bp_get_groups_current_create_step(), $completed_create_steps)) {
            $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step();
        }
        // Reset cookie info
        setcookie('bp_new_group_id', $bp->groups->new_group_id, time() + 60 * 60 * 24, COOKIEPATH);
        setcookie('bp_completed_create_steps', base64_encode(json_encode($bp->groups->completed_create_steps)), time() + 60 * 60 * 24, COOKIEPATH);
        // If we have completed all steps and hit done on the final step we
        // can redirect to the completed group
        $keys = array_keys($bp->groups->group_creation_steps);
        if (count($bp->groups->completed_create_steps) == count($keys) && bp_get_groups_current_create_step() == array_pop($keys)) {
            unset($bp->groups->current_create_step);
            unset($bp->groups->completed_create_steps);
            // Once we compelete all steps, record the group creation in the activity stream.
            groups_record_activity(array('type' => 'created_group', 'item_id' => $bp->groups->new_group_id));
            do_action('groups_group_create_complete', $bp->groups->new_group_id);
            bp_core_redirect(bp_get_group_permalink($bp->groups->current_group));
        } else {
            /**
             * Since we don't know what the next step is going to be (any plugin can insert steps)
             * we need to loop the step array and fetch the next step that way.
             */
            foreach ($keys as $key) {
                if ($key == bp_get_groups_current_create_step()) {
                    $next = 1;
                    continue;
                }
                if (isset($next)) {
                    $next_step = $key;
                    break;
                }
            }
            bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . $next_step . '/');
        }
    }
    // Remove invitations
    if ('group-invites' === bp_get_groups_current_create_step() && !empty($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id'])) {
        if (!check_admin_referer('groups_invite_uninvite_user')) {
            return false;
        }
        $message = __('Invite successfully removed', 'buddypress');
        $error = false;
        if (!groups_uninvite_user((int) $_REQUEST['user_id'], $bp->groups->new_group_id)) {
            $message = __('There was an error removing the invite', 'buddypress');
            $error = 'error';
        }
        bp_core_add_message($message, $error);
        bp_core_redirect(bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/');
    }
    // Group avatar is handled separately
    if ('group-avatar' == bp_get_groups_current_create_step() && isset($_POST['upload'])) {
        if (!isset($bp->avatar_admin)) {
            $bp->avatar_admin = new stdClass();
        }
        if (!empty($_FILES) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            // Pass the file to the avatar upload handler
            if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
                $bp->avatar_admin->step = 'crop-image';
                // Make sure we include the jQuery jCrop file for image cropping
                add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
            }
        }
        // If the image cropping is done, crop the image and save a full/thumb version
        if (isset($_POST['avatar-crop-submit']) && isset($_POST['upload'])) {
            // Normally we would check a nonce here, but the group save nonce is used instead
            if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
                bp_core_add_message(__('There was an error saving the group profile photo, please try uploading again.', 'buddypress'), 'error');
            } else {
                bp_core_add_message(__('The group profile photo was uploaded successfully!', 'buddypress'));
            }
        }
    }
    bp_core_load_template(apply_filters('groups_template_create_group', 'groups/create'));
}
Ejemplo n.º 6
0
/**
 * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
 *
 * @package BuddyPress XProfile
 * @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
 * @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
 */
function xprofile_screen_change_avatar()
{
    // Bail if not the correct screen
    if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
        return false;
    }
    // Bail if there are action variables
    if (bp_action_variables()) {
        bp_do_404();
        return;
    }
    $bp = buddypress();
    if (!isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    $bp->avatar_admin->step = 'upload-image';
    if (!empty($_FILES)) {
        // Check the nonce
        check_admin_referer('bp_avatar_upload');
        // Pass the file to the avatar upload handler
        if (bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir')) {
            $bp->avatar_admin->step = 'crop-image';
            // Make sure we include the jQuery jCrop file for image cropping
            add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
        }
    }
    // If the image cropping is done, crop the image and save a full/thumb version
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_cropstore');
        $args = array('item_id' => bp_displayed_user_id(), 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
        if (!bp_core_avatar_handle_crop($args)) {
            bp_core_add_message(__('There was a problem cropping your profile photo.', 'buddypress'), 'error');
        } else {
            do_action('xprofile_avatar_uploaded');
            bp_core_add_message(__('Your new profile photo was uploaded successfully.', 'buddypress'));
            bp_core_redirect(bp_displayed_user_domain());
        }
    }
    do_action('xprofile_screen_change_avatar');
    bp_core_load_template(apply_filters('xprofile_template_change_avatar', 'members/single/home'));
}
Ejemplo n.º 7
0
 function rtmedia_api_process_update_avatar_request()
 {
     $this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
     $ec_no_file = 130001;
     $msg_no_file = __('no file', 'rtmedia');
     $ec_invalid_image = 130002;
     $msg_invalid_image = __('upload failed, check size and file type', 'rtmedia');
     $ec_avatar_updated = 130003;
     $msg_avatar_updated = __('avatar updated', 'rtmedia');
     extract($_POST);
     if (empty($_FILES['file'])) {
         echo $this->rtmedia_api_response_object('FALSE', $ec_no_file, $msg_no_file);
         exit;
     }
     $uploaded = bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir');
     if (!$uploaded) {
         echo $this->rtmedia_api_response_object('FALSE', $ec_invalid_image, $msg_invalid_image);
         exit;
     } else {
         echo $this->rtmedia_api_response_object('TRUE', $ec_avatar_updated, $msg_avatar_updated);
         exit;
     }
 }
Ejemplo n.º 8
0
function groups_screen_group_admin_avatar()
{
    global $bp;
    if (bp_is_groups_component() && bp_is_action_variable('group-avatar', 0)) {
        // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here
        if (!$bp->is_item_admin || (int) bp_get_option('bp-disable-avatar-uploads')) {
            return false;
        }
        // If the group admin has deleted the admin avatar
        if (bp_is_action_variable('delete', 1)) {
            // Check the nonce
            check_admin_referer('bp_group_avatar_delete');
            if (bp_core_delete_existing_avatar(array('item_id' => $bp->groups->current_group->id, 'object' => 'group'))) {
                bp_core_add_message(__('Your avatar was deleted successfully!', 'buddypress'));
            } else {
                bp_core_add_message(__('There was a problem deleting that avatar, please try again.', 'buddypress'), 'error');
            }
        }
        $bp->avatar_admin->step = 'upload-image';
        if (!empty($_FILES)) {
            // Check the nonce
            check_admin_referer('bp_avatar_upload');
            // Pass the file to the avatar upload handler
            if (bp_core_avatar_handle_upload($_FILES, 'groups_avatar_upload_dir')) {
                $bp->avatar_admin->step = 'crop-image';
                // Make sure we include the jQuery jCrop file for image cropping
                add_action('wp_print_scripts', 'bp_core_add_jquery_cropper');
            }
        }
        // If the image cropping is done, crop the image and save a full/thumb version
        if (isset($_POST['avatar-crop-submit'])) {
            // Check the nonce
            check_admin_referer('bp_avatar_cropstore');
            if (!bp_core_avatar_handle_crop(array('object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
                bp_core_add_message(__('There was a problem cropping the avatar, please try uploading it again', 'buddypress'));
            } else {
                bp_core_add_message(__('The new group avatar was uploaded successfully!', 'buddypress'));
            }
        }
        do_action('groups_screen_group_admin_avatar', $bp->groups->current_group->id);
        bp_core_load_template(apply_filters('groups_template_group_admin_avatar', 'groups/single/home'));
    }
}
Ejemplo n.º 9
0
function groups_action_create_group() {
	global $bp;

	/* If we're not at domain.org/groups/create/ then return false */
	if ( $bp->current_component != $bp->groups->slug || 'create' != $bp->current_action )
		return false;

	if ( !is_user_logged_in() )
		return false;

	/* Make sure creation steps are in the right order */
	groups_action_sort_creation_steps();

	/* If no current step is set, reset everything so we can start a fresh group creation */
	if ( !$bp->groups->current_create_step = $bp->action_variables[1] ) {

		unset( $bp->groups->current_create_step );
		unset( $bp->groups->completed_create_steps );

		setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH );
		setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH );

		$reset_steps = true;
		bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );
	}

	/* If this is a creation step that is not recognized, just redirect them back to the first screen */
	if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) {
		bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
		bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/' );
	}

	/* Fetch the currently completed steps variable */
	if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !$reset_steps )
		$bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) );

	/* Set the ID of the new group, if it has already been created in a previous step */
	if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
		$bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
		$bp->groups->current_group = new BP_Groups_Group( $bp->groups->new_group_id );
	}

	/* If the save, upload or skip button is hit, lets calculate what we need to save */
	if ( isset( $_POST['save'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );

		if ( 'group-details' == $bp->groups->current_create_step ) {
			if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
				bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}

			if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => gmdate( "Y-m-d H:i:s" ), 'status' => 'public' ) ) ) {
				bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}

			groups_update_groupmeta( $bp->groups->new_group_id, 'total_member_count', 1 );
			groups_update_groupmeta( $bp->groups->new_group_id, 'last_activity', gmdate( "Y-m-d H:i:s" ) );
		}

		if ( 'group-settings' == $bp->groups->current_create_step ) {
			$group_status = 'public';
			$group_enable_forum = 1;

			if ( !isset($_POST['group-show-forum']) ) {
				$group_enable_forum = 0;
			} else {
				/* Create the forum if enable_forum = 1 */
				if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
					groups_new_group_forum();
				}
			}

			if ( 'private' == $_POST['group-status'] )
				$group_status = 'private';
			else if ( 'hidden' == $_POST['group-status'] )
				$group_status = 'hidden';

			if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
				bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
				bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
			}
		}

		if ( 'group-invites' == $bp->groups->current_create_step ) {
			groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id );
		}

		do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
		do_action( 'groups_create_group_step_complete' ); // Mostly for clearing cache on a generic action name

		/**
		 * Once we have successfully saved the details for this step of the creation process
		 * we need to add the current step to the array of completed steps, then update the cookies
		 * holding the information
		 */
		if ( !in_array( $bp->groups->current_create_step, (array)$bp->groups->completed_create_steps ) )
			$bp->groups->completed_create_steps[] = $bp->groups->current_create_step;

		/* Reset cookie info */
		setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
		setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );

		/* If we have completed all steps and hit done on the final step we can redirect to the completed group */
		if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
			unset( $bp->groups->current_create_step );
			unset( $bp->groups->completed_create_steps );

			/* Once we compelete all steps, record the group creation in the activity stream. */
			groups_record_activity( array(
				'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%s created the group %s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
				'type' => 'created_group',
				'item_id' => $bp->groups->new_group_id
			) );

			do_action( 'groups_group_create_complete', $bp->groups->new_group_id );

			bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
		} else {
			/**
			 * Since we don't know what the next step is going to be (any plugin can insert steps)
			 * we need to loop the step array and fetch the next step that way.
			 */
			foreach ( (array)$bp->groups->group_creation_steps as $key => $value ) {
				if ( $key == $bp->groups->current_create_step ) {
					$next = 1;
					continue;
				}

				if ( $next ) {
					$next_step = $key;
					break;
				}
			}

			bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $next_step . '/' );
		}
	}

	/* Group avatar is handled separately */
	if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
		if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
			/* Normally we would check a nonce here, but the group save nonce is used instead */

			/* Pass the file to the avatar upload handler */
			if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
				$bp->avatar_admin->step = 'crop-image';

				/* Make sure we include the jQuery jCrop file for image cropping */
				add_action( 'wp', 'bp_core_add_jquery_cropper' );
			}
		}

		/* If the image cropping is done, crop the image and save a full/thumb version */
		if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
			/* Normally we would check a nonce here, but the group save nonce is used instead */

			if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
				bp_core_add_message( __( 'There was an error saving the group avatar, please try uploading again.', 'buddypress' ), 'error' );
			else
				bp_core_add_message( __( 'The group avatar was uploaded successfully!', 'buddypress' ) );
		}
	}

 	bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) );
}
Ejemplo n.º 10
0
function bp_core_screen_signup() {
	global $bp, $wpdb;

	if ( $bp->current_component != BP_REGISTER_SLUG )
		return false;

	/* If the user is logged in, redirect away from here */
	if ( is_user_logged_in() )
		bp_core_redirect( $bp->root_domain );

	/* If signups are disabled, just re-direct */
	if ( !bp_get_signup_allowed() )
		bp_core_redirect( $bp->root_domain );

	$bp->signup->step = 'request-details';

	/* If the signup page is submitted, validate and save */
	if ( isset( $_POST['signup_submit'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_new_signup' );

		require_once( ABSPATH . WPINC . '/registration.php' );

		/* Check the base account details for problems */
		$account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );

		/* If there are errors with account details, set them for display */
		if ( !empty( $account_details['errors']->errors['user_name'] ) )
			$bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];

		if ( !empty( $account_details['errors']->errors['user_email'] ) )
			$bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];

		/* Check that both password fields are filled in */
		if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
			$bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );

		/* Check that the passwords match */
		if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
			$bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );

		$bp->signup->username = $_POST['signup_username'];
		$bp->signup->email = $_POST['signup_email'];

		/* Now we've checked account details, we can check profile information */
		if ( function_exists( 'xprofile_check_is_required_field' ) ) {

			/* Make sure hidden field is passed and populated */
			if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {

				/* Let's compact any profile field info into an array */
				$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );

				/* Loop through the posted fields formatting any datebox values then validate the field */
				foreach ( (array) $profile_field_ids as $field_id ) {
					if ( !isset( $_POST['field_' . $field_id] ) ) {
						if ( isset( $_POST['field_' . $field_id . '_day'] ) )
							$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
					}

					/* Create errors for required fields without values */
					if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) )
						$bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
				}

			/* This situation doesn't naturally occur so bounce to website root */
			} else {
				bp_core_redirect( $bp->root_domain );
			}
		}

		/* Finally, let's check the blog details, if the user wants a blog and blog creation is enabled */
		if ( isset( $_POST['signup_with_blog'] ) ) {
			$active_signup = $bp->site_options['registration'];

			if ( 'blog' == $active_signup || 'all' == $active_signup ) {
				$blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );

				/* If there are errors with blog details, set them for display */
				if ( !empty( $blog_details['errors']->errors['blogname'] ) )
					$bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];

				if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
					$bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
			}
		}

		do_action( 'bp_signup_validate' );

		/* Add any errors to the action for the field in the template for display. */
		if ( !empty( $bp->signup->errors ) ) {
			foreach ( (array)$bp->signup->errors as $fieldname => $error_message )
				add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo "<div class=\"error\">' . $error_message . '</div>";' ) );
		} else {
			$bp->signup->step = 'save-details';

			/* No errors! Let's register those deets. */
			$active_signup = $bp->site_options['registration'];

			if ( 'none' != $active_signup ) {

				/* Let's compact any profile field info into usermeta */
				$profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );

				/* Loop through the posted fields formatting any datebox values then add to usermeta */
				foreach ( (array) $profile_field_ids as $field_id ) {
					if ( !isset( $_POST['field_' . $field_id] ) ) {
						if ( isset( $_POST['field_' . $field_id . '_day'] ) )
							$_POST['field_' . $field_id] = strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] );
					}

					if ( !empty( $_POST['field_' . $field_id] ) )
						$usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
				}

				/* Store the profile field ID's in usermeta */
				$usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];

				/* Hash and store the password */
				$usermeta['password'] = wp_hash_password( $_POST['signup_password'] );

				/* If the user decided to create a blog, save those details to usermeta */
				if ( 'blog' == $active_signup || 'all' == $active_signup ) {
					$usermeta['public'] = ( 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
				}

				$usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );

				/* Finally, sign up the user and/or blog */
				if ( isset( $_POST['signup_with_blog'] ) && bp_core_is_multisite() )
					bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
				else {
					bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
				}

				$bp->signup->step = 'completed-confirmation';
			}

			do_action( 'bp_complete_signup' );
		}

	}

	$bp->avatar_admin->step = 'upload-image';

	/* If user has uploaded a new avatar */
	if ( !empty( $_FILES ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_avatar_upload' );

		$bp->signup->step = 'completed-confirmation';

		if ( bp_core_is_multisite() ) {
			/* Get the activation key */
			if ( !$bp->signup->key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $_POST[ 'signup_username' ], $_POST[ 'signup_email' ] ) ) ) {
				bp_core_add_message( __( 'There was a problem uploading your avatar, please try uploading it again', 'buddypress' ) );
			} else {
				/* Hash the key to create the upload folder (added security so people don't sniff the activation key) */
				$bp->signup->avatar_dir = wp_hash( $bp->signup->key );
			}
		} else {
			$user_id = bp_core_get_userid( $_POST['signup_username'] );
			$bp->signup->avatar_dir = wp_hash( $user_id );
		}

		/* Pass the file to the avatar upload handler */
		if ( bp_core_avatar_handle_upload( $_FILES, 'bp_core_signup_avatar_upload_dir' ) ) {
			$bp->avatar_admin->step = 'crop-image';

			/* Make sure we include the jQuery jCrop file for image cropping */
			add_action( 'wp', 'bp_core_add_jquery_cropper' );
		}
	}

	/* If the image cropping is done, crop the image and save a full/thumb version */
	if ( isset( $_POST['avatar-crop-submit'] ) ) {

		/* Check the nonce */
		check_admin_referer( 'bp_avatar_cropstore' );

		/* Reset the avatar step so we can show the upload form again if needed */
		$bp->signup->step = 'completed-confirmation';
		$bp->avatar_admin->step = 'upload-image';

		if ( !bp_core_avatar_handle_crop( array( 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
			bp_core_add_message( __( 'There was a problem cropping your avatar, please try uploading it again', 'buddypress' ), 'error' );
		else
			bp_core_add_message( __( 'Your new avatar was uploaded successfully', 'buddypress' ) );
	}
	bp_core_load_template( 'registration/register' );
}
Ejemplo n.º 11
0
/**
 * cover photo subnav callback function. renders the title content and the template
 * files that are needed to process the upload and cropping of the photo
 * 
 * @author dunhakdis<*****@*****.**>
 * @package bp-cover-photo
 * @since 1.0
 * @return void
 */
function bcp_cover_photo_screen()
{
    // store buddypress object to $bp
    // same as global $bp;
    $bp = buddypress();
    // template directory
    $template = 'members';
    // filter function for uploading images
    $upload_filter = 'xprofile_avatar_upload_dir';
    // the id of the user
    $item_id = bp_displayed_user_id();
    if (bp_is_group_single()) {
        $template = 'groups';
        $upload_filter = 'groups_avatar_upload_dir';
        $item_id = $bp->groups->current_group->id;
    }
    // load jcrop
    add_action('wp_enqueue_scripts', 'bp_cover_photo_scripts');
    //add title and content here - last is to call the members plugin.php template
    add_action('bp_template_title', 'bp_cover_photo_screen_title');
    add_action('bp_template_content', 'bp_cover_photo_screen_content');
    // handle uploading of cover photo
    if (!empty($_FILES)) {
        // Check the nonce
        check_admin_referer('bp_avatar_upload');
        // create avatar_admin object to prevent notices
        // from empty variables and objects
        if (!isset($bp->avatar_admin)) {
            $bp->avatar_admin = new stdClass();
        }
        // Pass the file to the avatar upload handler
        $bp = buddypress();
        if (bp_core_avatar_handle_upload($_FILES, $upload_filter)) {
            // adjust current step
            $bp->avatar_admin->step = 'crop-image';
        }
    }
    // If the image cropping is done, crop the image and save a full/thumb version
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_cropstore');
        $groups_slug = bcp_get_groups_slug();
        $args = array('item_id' => $item_id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']);
        // change avatar path for groups
        if (bp_is_group_single()) {
            $args['avatar_dir'] = 'group-avatars';
        }
        if (!bcp_core_avatar_handle_crop($args)) {
            bp_core_add_message(__('There was a problem cropping your cover photo.', 'buddypress'), 'error');
        } else {
            // update the default cover photo image for groups
            if (isset($_POST['global-coverphoto'])) {
                $type = wp_kses($_POST['global-coverphoto'], array());
                $args = array('object_id' => $item_id, 'type' => $type);
                $new_cover_photo = bcp_fetch_cover_photo($args);
                update_option('__bcp_default_' . $type . '_cover_photo', $new_cover_photo['full']);
            }
            if (bp_is_group_single()) {
                // if its a single group
                // redirect to group home page
                $current_displayed_group_url = trailingslashit(get_bloginfo('url') . '/' . $groups_slug . '/' . $bp->groups->current_group->slug . '/');
                groups_update_groupmeta($item_id, 'cover-photo-timestamp', md5(time()));
                bp_core_redirect($current_displayed_group_url);
            } else {
                //otherwise, redirect to members profile
                update_user_meta($item_id, 'cover-photo-timestamp', md5(time()));
                bp_core_redirect(bp_displayed_user_domain());
            }
            bp_core_add_message(__('Your new cover photo was uploaded successfully.', 'buddypress'));
        }
    }
    bp_core_load_template(apply_filters('bp_core_template_plugin', $template . '/single/plugins'));
    return;
}
Ejemplo n.º 12
0
function bfox_bp_plans_update_plan_avatar(BfoxReadingPlan $plan, $is_create = false)
{
    global $bp;
    bfox_bp_plans_must_own($plan);
    if (!$is_create) {
        /* If the group admin has deleted the admin avatar */
        if ('delete' == $bp->action_variables[0]) {
            /* Check the nonce */
            check_admin_referer('bfox_bp_plan_avatar_delete');
            if (bp_core_delete_existing_avatar(array('item_id' => $plan->id, 'object' => 'plan'))) {
                bp_core_add_message(__('Your avatar was deleted successfully!', 'buddypress'));
            } else {
                bp_core_add_message(__('There was a problem deleting that avatar, please try again.', 'buddypress'), 'error');
            }
            bp_core_redirect($plan->url() . 'avatar/');
        }
    }
    $bp->avatar_admin->step = 'upload-image';
    if (!empty($_FILES) && isset($_POST['upload'])) {
        if ($is_create) {
            check_admin_referer('plans_create_save_plan-avatar');
        } else {
            check_admin_referer('bp_avatar_upload');
        }
        /* Pass the file to the avatar upload handler */
        if (bp_core_avatar_handle_upload($_FILES, 'bfox_bp_plans_avatar_upload_dir')) {
            $bp->avatar_admin->step = 'crop-image';
            /* Make sure we include the jQuery jCrop file for image cropping */
            add_action('wp', 'bp_core_add_jquery_cropper');
        }
    }
    /* If the image cropping is done, crop the image and save a full/thumb version */
    if (isset($_POST['avatar-crop-submit'])) {
        if ($is_create) {
            check_admin_referer('plans_create_save_plan-avatar');
        } else {
            check_admin_referer('bp_avatar_cropstore');
        }
        if (!bp_core_avatar_handle_crop(array('object' => 'plan', 'avatar_dir' => 'plan-avatars', 'item_id' => $plan->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
            bp_core_add_message(__('There was a problem cropping the avatar, please try uploading it again', 'buddypress'));
        } else {
            bp_core_add_message(__('The new reading plan avatar was uploaded successfully!', 'buddypress'));
        }
    }
}
Ejemplo n.º 13
0
/**
 * Load Link home page edit avatar template, handle form if submitted
 */
function bp_links_screen_link_admin_avatar()
{
    global $bp;
    if (!$bp->is_item_admin || 'link-avatar' != bp_links_admin_current_action_variable()) {
        return false;
    }
    // handle empty avatar admin property
    if (false === isset($bp->avatar_admin)) {
        $bp->avatar_admin = new stdClass();
    }
    // If the link admin has deleted the admin avatar
    if ('delete' == $bp->action_variables[1]) {
        /* Check the nonce */
        check_admin_referer('bp_link_avatar_delete');
        if (bp_core_delete_existing_avatar(array('item_id' => $bp->links->current_link->id, 'object' => 'link', 'avatar_dir' => 'link-avatars'))) {
            bp_core_add_message(__('Your avatar was deleted successfully!', 'buddypress-links'));
        } else {
            bp_core_add_message(sprintf('%s %s', __('There was a problem deleting that avatar', 'buddypress-links'), __('Please try again.', 'buddypress-links')), 'error');
        }
    }
    $bp->avatar_admin->step = 'upload-image';
    if (isset($_POST['avatar-crop-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_cropstore');
        // received crop coords, crop the image and save a full/thumb version
        if (bp_core_avatar_handle_crop(array('object' => 'link', 'avatar_dir' => 'link-avatars', 'item_id' => $bp->links->current_link->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h']))) {
            bp_links_embed_handle_crop($bp->links->current_link);
            bp_core_add_message(__('The link avatar was uploaded successfully!', 'buddypress-links'));
        } else {
            bp_core_add_message(sprintf('%s %s', __('There was an error saving link avatar.', 'buddypress-links'), __('Please try again.', 'buddypress-links')), 'error');
        }
    } elseif (isset($_POST['upload']) || isset($_POST['embed-submit'])) {
        // Check the nonce
        check_admin_referer('bp_avatar_upload');
        // handle image uploading
        if (!empty($_POST['embed-submit']) && bp_links_embed_handle_upload($bp->links->current_link, $_POST['embed-html'])) {
            // we are good to crop
            $bp->avatar_admin->step = 'crop-image';
            // Make sure we include the jQuery jCrop file for image cropping
            add_action('wp_enqueue_scripts', 'bp_core_add_jquery_cropper');
        } elseif (isset($_POST['upload']) && !empty($_FILES)) {
            // Pass the file to the avatar upload handler
            if (bp_core_avatar_handle_upload($_FILES, 'bp_links_avatar_upload_dir')) {
                // we are good to crop
                $bp->avatar_admin->step = 'crop-image';
                // Make sure we include the jQuery jCrop file for image cropping
                add_action('wp_enqueue_scripts', 'bp_core_add_jquery_cropper');
            }
        }
    }
    do_action('bp_links_screen_link_admin_avatar', $bp->links->current_link->id);
    bp_links_load_template('single/home');
}