/** * Crop an uploaded avatar * * $args has the following parameters: * object - What component the avatar is for, e.g. "user" * avatar_dir The absolute path to the avatar * item_id - Item ID * original_file - The absolute path to the original avatar file * crop_w - Crop width * crop_h - Crop height * crop_x - The horizontal starting point of the crop * crop_y - The vertical starting point of the crop * * @global object $bp BuddyPress global settings * @param mixed $args * @return bool Success/failure */ function bp_core_avatar_handle_crop($args = '') { global $bp; $defaults = array('object' => 'user', 'avatar_dir' => 'avatars', 'item_id' => false, 'original_file' => false, 'crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0); $r = nxt_parse_args($args, $defaults); /*** * You may want to hook into this filter if you want to override this function. * Make sure you return false. */ if (!apply_filters('bp_core_pre_avatar_handle_crop', true, $r)) { return true; } extract($r, EXTR_SKIP); if (!$original_file) { return false; } $original_file = bp_core_avatar_upload_path() . $original_file; if (!file_exists($original_file)) { return false; } if (!$item_id) { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', dirname($original_file), $item_id, $object, $avatar_dir); } else { $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir); } if (!file_exists($avatar_folder_dir)) { return false; } require_once ABSPATH . '/nxt-admin/includes/image.php'; require_once ABSPATH . '/nxt-admin/includes/file.php'; // Delete the existing avatar files for the object bp_core_delete_existing_avatar(array('object' => $object, 'avatar_path' => $avatar_folder_dir)); // Make sure we at least have a width and height for cropping if (!(int) $crop_w) { $crop_w = bp_core_avatar_full_width(); } if (!(int) $crop_h) { $crop_h = bp_core_avatar_full_height(); } // Set the full and thumb filenames $full_filename = nxt_hash($original_file . time()) . '-bpfull.jpg'; $thumb_filename = nxt_hash($original_file . time()) . '-bpthumb.jpg'; // Crop the image $full_cropped = nxt_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, $avatar_folder_dir . '/' . $full_filename); $thumb_cropped = nxt_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, bp_core_avatar_thumb_width(), bp_core_avatar_thumb_height(), false, $avatar_folder_dir . '/' . $thumb_filename); // Remove the original @unlink($original_file); return true; }
function jfb_debug_nonce_components() { global $opt_jfb_generated_nonce; $user = nxt_get_current_user(); $uid = (int) $user->id; $nonce_life = apply_filters('nonce_life', 86400); $time = time(); $nonce_tick = ceil(time() / ($nonce_life / 2)); $tick_verify = nxt_nonce_tick(); $hash = nxt_hash($i . $action . $uid, 'nonce'); $nonce = substr($hash, -12, 10); return "NONCE: {$nonce}, uid: {$uid}, life: {$nonce_life}, time: {$time}, tick: {$nonce_tick}, verify: {$tick_verify}, hash: {$hash}"; }
/** * Creates a random, one time use token. * * @since 2.0.3 * * @param string|int $action Scalar value to add context to the nonce. * @return string The one use form token */ function nxt_create_nonce($action = -1) { $user = nxt_get_current_user(); $uid = (int) $user->ID; $i = nxt_nonce_tick(); return substr(nxt_hash($i . $action . $uid, 'nonce'), -12, 10); }
function bp_core_signup_user($user_login, $user_password, $user_email, $usermeta) { global $bp, $nxtdb; // Multisite installs have their own install procedure if (is_multisite()) { nxtmu_signup_user($user_login, $user_email, $usermeta); // On multisite, the user id is not created until the user activates the account // but we need to cast $user_id to pass to the filters $user_id = false; } else { $errors = new nxt_Error(); $user_id = nxt_insert_user(array('user_login' => $user_login, 'user_pass' => $user_password, 'display_name' => sanitize_title($user_login), 'user_email' => $user_email)); if (is_nxt_error($user_id) || empty($user_id)) { $errors->add('registerfail', sprintf(__('<strong>ERROR</strong>: Couldn’t register you... please contact the <a href="mailto:%s">webmaster</a> !', 'buddypress'), get_option('admin_email'))); return $errors; } // Update the user status to '2' which we will use as 'not activated' (0 = active, 1 = spam, 2 = not active) $nxtdb->query($nxtdb->prepare("UPDATE {$nxtdb->users} SET user_status = 2 WHERE ID = %d", $user_id)); // Set any profile data if (bp_is_active('xprofile')) { if (!empty($usermeta['profile_field_ids'])) { $profile_field_ids = explode(',', $usermeta['profile_field_ids']); foreach ((array) $profile_field_ids as $field_id) { if (empty($usermeta["field_{$field_id}"])) { continue; } $current_field = $usermeta["field_{$field_id}"]; xprofile_set_field_data($field_id, $user_id, $current_field); } } } } $bp->signup->username = $user_login; /*** * Now generate an activation key and send an email to the user so they can activate their account * and validate their email address. Multisite installs send their own email, so this is only for single blog installs. * * To disable sending activation emails you can user the filter 'bp_core_signup_send_activation_key' and return false. */ if (apply_filters('bp_core_signup_send_activation_key', true)) { if (!is_multisite()) { $activation_key = nxt_hash($user_id); update_user_meta($user_id, 'activation_key', $activation_key); bp_core_signup_send_validation_email($user_id, $user_email, $activation_key); } } do_action('bp_core_signup_user', $user_id, $user_login, $user_password, $user_email, $usermeta); return $user_id; }