function xprofile_catch_activate_crop() { if (isset($_GET['cropped'])) { // The user has cropped their avatar after activating account // Confirm that the nonce is valid if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'slick_avatars')) { bp_core_redirect(get_option('home')); } $user_id = xprofile_get_user_by_key($_GET['key']); if ($user_id && isset($_POST['orig']) && isset($_POST['canvas'])) { bp_core_check_crop($_POST['orig'], $_POST['canvas']); $result = bp_core_avatar_cropstore($_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h']); bp_core_avatar_save($result, $user_id); } $ud = get_userdata($user_id); $url = site_url(BP_MEMBERS_SLUG . '/' . $ud->user_login); bp_core_redirect($url); } }
function bp_core_avatar_admin($message = null, $action, $delete_action) { global $wp_upload_error; ?> <?php if (!isset($_POST['slick_avatars_action']) && !isset($_GET['slick_avatars_action'])) { ?> <?php if ($message) { ?> <br /> <div id="message" class="updated fade"> <p><?php echo $message; ?> </p> </div> <?php } ?> <p><?php _e('Your avatar will be used on your profile and throughout the site.', 'buddypress'); ?> </p> <p><?php _e('Click below to select a JPG, GIF or PNG format photo from your computer and then click \'Upload Photo\' to proceed.', 'buddypress'); ?> </p> <?php bp_core_render_avatar_upload_form($action); $str = bp_core_get_avatar(get_current_user_id(), 1); if (strlen($str)) { echo '<h3>' . __('This is your current avatar', 'buddypress') . '</h3>'; echo '<span class="crop-img avatar">' . bp_core_get_avatar(get_current_user_id(), 1) . '</span>'; echo '<span class="crop-img avatar">' . bp_core_get_avatar(get_current_user_id(), 2) . '</span>'; echo '<a href="' . wp_nonce_url($delete_action, 'bp_delete_avatar_link') . '">' . __('Delete', 'buddypress') . '</a>'; } } else { if (isset($_POST['slick_avatars_action']) && 'upload' == $_POST['slick_avatars_action']) { // Confirm that the nonce is valid if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'slick_avatars')) { bp_core_ap_die('Security error.'); } // Set friendly error feedback. $uploadErrors = array(0 => __("There is no error, the file uploaded with success", 'buddypress'), 1 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 2 => __("Your image was bigger than the maximum allowed file size of: ", 'buddypress') . size_format(CORE_MAX_FILE_SIZE), 3 => __("The uploaded file was only partially uploaded", 'buddypress'), 4 => __("No file was uploaded", 'buddypress'), 6 => __("Missing a temporary folder", 'buddypress')); if (!bp_core_check_avatar_upload($_FILES)) { bp_core_ap_die(sprintf(__('Your upload failed, please try again. Error was: %s', 'buddypress'), $uploadErrors[$_FILES['file']['error']])); } if (!bp_core_check_avatar_size($_FILES)) { bp_core_ap_die(sprintf(__('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), size_format(CORE_MAX_FILE_SIZE))); } if (!bp_core_check_avatar_type($_FILES)) { bp_core_ap_die(__('Please upload only JPG, GIF or PNG photos.', 'buddypress')); } // "Handle" upload into temporary location if (!($original = bp_core_handle_avatar_upload($_FILES))) { bp_core_ap_die(sprintf(__('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error)); } // Resize down to something we can display on the page or use original if its small enough already. if (!($canvas = bp_core_resize_avatar($original))) { $canvas = $original; } // Render the cropper UI bp_core_render_avatar_cropper($original, $canvas, $action); } else { if (isset($_POST['slick_avatars_action']) && 'crop' == $_POST['slick_avatars_action']) { // Crop, save, store // Confirm that the nonce is valid if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'slick_avatars')) { bp_core_ap_die(__('Security error.', 'buddypress')); } if (!bp_core_check_crop($_POST['orig'], $_POST['canvas'])) { bp_core_ap_die(__('Error when cropping, please go back and try again', 'buddypress')); } if (!($result = bp_core_avatar_cropstore(stripslashes($_POST['orig']), $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h']))) { bp_core_ap_die(__('Error when saving avatars, please go back and try again.', 'buddypress')); } // Store details to the DB and we're done echo '<p>' . __('Your new avatar was successfully created!', 'buddypress') . '</p>'; bp_core_avatar_save($result); echo '<span class="crop-img">' . bp_core_get_avatar(get_current_user_id(), 1) . '</span>'; if (CORE_AVATAR_V2_W && CORE_AVATAR_V2_H) { echo '<span class="crop-img">' . bp_core_get_avatar(get_current_user_id(), 2) . '</span>'; } } else { if (isset($_GET['slick_avatars_action']) && 'delete' == $_GET['slick_avatars_action']) { // Delete an avatar bp_core_delete_avatar(); unset($_GET['slick_avatars_action']); $message = __('Avatar successfully removed.', 'buddypress'); bp_core_avatar_admin($message); } } } } ?> <?php }
function groups_create_group($step, $group_id) { global $bp, $create_group_step, $group_obj, $bbpress_live; if (is_numeric($step) && (1 == (int) $step || 2 == (int) $step || 3 == (int) $step || 4 == (int) $step)) { if (!$group_obj) { $group_obj = new BP_Groups_Group($group_id); } switch ($step) { case '1': if (!check_admin_referer('groups_step1_save')) { return false; } if ($_POST['group-name'] != '' && $_POST['group-desc'] != '') { $group_obj->creator_id = $bp->loggedin_user->id; $group_obj->name = stripslashes($_POST['group-name']); $group_obj->description = stripslashes($_POST['group-desc']); $group_obj->news = stripslashes($_POST['group-news']); $slug = groups_check_slug(sanitize_title($_POST['group-name'])); $group_obj->slug = $slug; $group_obj->status = 'public'; $group_obj->is_invitation_only = 0; $group_obj->enable_wire = 1; $group_obj->enable_forum = 1; $group_obj->enable_photos = 1; $group_obj->photos_admin_only = 0; $group_obj->date_created = time(); if (!$group_obj->save()) { return false; } // Save the creator as the group administrator $admin = new BP_Groups_Member($bp->loggedin_user->id, $group_obj->id); $admin->is_admin = 1; $admin->user_title = __('Group Admin', 'buddypress'); $admin->date_modified = time(); $admin->inviter_id = 0; $admin->is_confirmed = 1; if (!$admin->save()) { return false; } do_action('groups_create_group_step1_save'); /* Set groupmeta */ groups_update_groupmeta($group_obj->id, 'total_member_count', 1); groups_update_groupmeta($group_obj->id, 'last_activity', time()); groups_update_groupmeta($group_obj->id, 'theme', 'buddypress'); groups_update_groupmeta($group_obj->id, 'stylesheet', 'buddypress'); return $group_obj->id; } return false; break; case '2': if (!check_admin_referer('groups_step2_save')) { return false; } $group_obj->status = 'public'; $group_obj->is_invitation_only = 0; $group_obj->enable_wire = 1; $group_obj->enable_forum = 1; $group_obj->enable_photos = 1; $group_obj->photos_admin_only = 0; if (!isset($_POST['group-show-wire'])) { $group_obj->enable_wire = 0; } if (!isset($_POST['group-show-forum'])) { $group_obj->enable_forum = 0; } else { /* Create the forum if enable_forum = 1 */ if (function_exists('bp_forums_setup') && '' == groups_get_groupmeta($group_obj->id, 'forum_id')) { groups_new_group_forum(); } } if (!isset($_POST['group-show-photos'])) { $group_obj->enable_photos = 0; } if ($_POST['group-photos-status'] != 'all') { $group_obj->photos_admin_only = 1; } if ('private' == $_POST['group-status']) { $group_obj->status = 'private'; } else { if ('hidden' == $_POST['group-status']) { $group_obj->status = 'hidden'; } } if (!$group_obj->save()) { return false; } /* Record in activity streams */ groups_record_activity(array('item_id' => $group_obj->id, 'component_name' => $bp->groups->slug, 'component_action' => 'created_group', 'is_private' => 0)); do_action('groups_create_group_step2_save'); return $group_obj->id; break; case '3': if (!check_admin_referer('groups_step3_save')) { return false; } if (isset($_POST['skip'])) { return $group_obj->id; } // Image already cropped and uploaded, lets store a reference in the DB. if (!wp_verify_nonce($_POST['nonce'], 'slick_avatars') || !($result = bp_core_avatar_cropstore($_POST['orig'], $_POST['canvas'], $_POST['v1_x1'], $_POST['v1_y1'], $_POST['v1_w'], $_POST['v1_h'], $_POST['v2_x1'], $_POST['v2_y1'], $_POST['v2_w'], $_POST['v2_h'], false, 'groupavatar', $group_obj->id))) { return false; } // Success on group avatar cropping, now save the results. $avatar_hrefs = groups_get_avatar_hrefs($result); $group_obj->avatar_thumb = stripslashes($avatar_hrefs['thumb_href']); $group_obj->avatar_full = stripslashes($avatar_hrefs['full_href']); if (!$group_obj->save()) { return false; } do_action('groups_create_group_step3_save'); return $group_obj->id; break; case '4': if (!check_admin_referer('groups_step4_save')) { return false; } groups_send_invites($group_obj, true); do_action('groups_created_group', $group_obj->id); return $group_obj->id; break; } } return false; }