function xprofile_handle_signup_avatar($user_id, $meta) { $resized = $meta['avatar_image_resized']; $original = $meta['avatar_image_original']; if (!empty($resized) && !empty($original)) { // Create and set up the upload dir first. $upload_dir = bp_core_avatar_upload_dir(false, $user_id); $resized_strip_path = explode('/', $resized); $original_strip_path = explode('/', $original); $resized_filename = $resized_strip_path[count($resized_strip_path) - 1]; $original_filename = $original_strip_path[count($original_strip_path) - 1]; $resized_new = $upload_dir['path'] . '/' . $resized_filename; $original_new = $upload_dir['path'] . '/' . $original_filename; @copy($resized, $resized_new); @copy($original, $original_new); @unlink($resized); @unlink($original); $resized = $resized_new; $original = $original_new; // Render the cropper UI $action = bp_activation_page(false) . '?key=' . $_GET['key'] . '&cropped=true'; bp_core_render_avatar_cropper($original, $resized, $action, $user_id); } }
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_avatar_upload($file) { // validate the group avatar upload if there is one. $avatar_error = false; // Set friendly error feedback. $uploadErrors = array(0 => __("There is no error, the file uploaded with success", 'buddypress'), 1 => __("The uploaded file exceeds the upload_max_filesize directive in php.ini", 'buddypress'), 2 => __("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", 'buddypress'), 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($file)) { $avatar_error = true; $avatar_error_msg = __('Your group avatar upload failed, please try again. Error was: ' . $uploadErrors[$file['file']['error']], 'buddypress'); } else { if (!bp_core_check_avatar_size($file)) { $avatar_error = true; $avatar_size = size_format(1024 * CORE_MAX_FILE_SIZE); $avatar_error_msg = __('The file you uploaded is too big. Please upload a file under', 'buddypress') . size_format(CORE_MAX_FILE_SIZE); } else { if (!bp_core_check_avatar_type($file)) { $avatar_error = true; $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.', 'buddypress'); } else { if (!($original = bp_core_handle_avatar_upload($file))) { $avatar_error = true; $avatar_error_msg = __('Upload Failed! Please check the permissions on the group avatar upload directory.', 'buddypress'); } } } } if (!($canvas = bp_core_resize_avatar($original))) { $canvas = $original; } if ($avatar_error) { ?> <div id="message" class="error"> <p><?php echo $avatar_error_msg; ?> </p> </div> <?php bp_core_render_avatar_upload_form('', true); } else { bp_core_render_avatar_cropper($original, $canvas, null, null, false, $bp->loggedin_user->domain); } }