本文整理汇总了PHP中bp_core_avatar_full_height函数的典型用法代码示例。如果您正苦于以下问题:PHP bp_core_avatar_full_height函数的具体用法?PHP bp_core_avatar_full_height怎么用?PHP bp_core_avatar_full_height使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bp_core_avatar_full_height函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bp_core_add_cropper_inline_css
/**
* Output the inline CSS for the BP image cropper.
*
* @since 1.1.0
*/
function bp_core_add_cropper_inline_css()
{
?>
<style type="text/css">
.jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
#avatar-crop-pane { width: <?php
echo bp_core_avatar_full_width();
?>
px; height: <?php
echo bp_core_avatar_full_height();
?>
px; overflow: hidden; }
#avatar-crop-submit { margin: 20px 0; }
.jcrop-holder img,
#avatar-crop-pane img,
#avatar-upload-form img,
#create-group-form img,
#group-settings-form img { border: none !important; max-width: none !important; }
</style>
<?php
}
示例2: bp_avatar_ajax_set
/**
* Ajax set an avatar for a given object and item id.
*
* @since 2.3.0
*
* @return string|null A json object containing success data if the crop/capture succeeded
* error message otherwise.
*/
function bp_avatar_ajax_set()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
wp_send_json_error();
}
// Check the nonce
check_admin_referer('bp_avatar_cropstore', 'nonce');
$avatar_data = wp_parse_args($_POST, array('crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0));
if (empty($avatar_data['object']) || empty($avatar_data['item_id']) || empty($avatar_data['original_file'])) {
wp_send_json_error();
}
// Capability check
if (!bp_attachments_current_user_can('edit_avatar', $avatar_data)) {
wp_send_json_error();
}
if (!empty($avatar_data['type']) && 'camera' === $avatar_data['type'] && 'user' === $avatar_data['object']) {
$webcam_avatar = false;
if (!empty($avatar_data['original_file'])) {
$webcam_avatar = str_replace(array('data:image/png;base64,', ' '), array('', '+'), $avatar_data['original_file']);
$webcam_avatar = base64_decode($webcam_avatar);
}
if (!bp_avatar_handle_capture($webcam_avatar, $avatar_data['item_id'])) {
wp_send_json_error(array('feedback_code' => 1));
} else {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
/**
* Fires if the new avatar was successfully captured.
*
* @since 1.1.0 Used to inform the avatar was successfully cropped
* @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')
* Move the action at the right place, once the avatar is set
*
* @param string $item_id Inform about the user id the avatar was set for
* @param string $type Inform about the way the avatar was set ('camera')
*/
do_action('xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type']);
wp_send_json_success($return);
}
return;
}
$original_file = str_replace(bp_core_avatar_url(), '', $avatar_data['original_file']);
// Set avatars dir & feedback part
if ('user' === $avatar_data['object']) {
$avatar_dir = 'avatars';
// Defaults to object-avatars dir
} else {
$avatar_dir = sanitize_key($avatar_data['object']) . '-avatars';
}
// Crop args
$r = array('item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'], 'avatar_dir' => $avatar_dir, 'original_file' => $original_file, 'crop_w' => $avatar_data['crop_w'], 'crop_h' => $avatar_data['crop_h'], 'crop_x' => $avatar_data['crop_x'], 'crop_y' => $avatar_data['crop_y']);
// Handle crop
if (bp_core_avatar_handle_crop($r)) {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
if ('user' === $avatar_data['object']) {
/**
* Fires if the new avatar was successfully cropped.
*
* @since 1.1.0 Used to inform the avatar was successfully cropped
* @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')
* Move the action at the right place, once the avatar is set
*
* @param string $item_id Inform about the user id the avatar was set for
* @param string $type Inform about the way the avatar was set ('crop')
*/
do_action('xprofile_avatar_uploaded', (int) $avatar_data['item_id'], $avatar_data['type']);
}
wp_send_json_success($return);
} else {
wp_send_json_error(array('feedback_code' => 1));
}
}
示例3: bp_core_add_cropper_inline_css
/**
* bp_core_add_cropper_inline_css()
*
* Adds the inline CSS needed for the cropper to work on a per-page basis.
*
* @package BuddyPress Core
*/
function bp_core_add_cropper_inline_css()
{
global $bp;
?>
<style type="text/css">
.jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
.jcrop-vline, .jcrop-hline { font-size: 0; position: absolute; background: white top left repeat url( <?php
echo BP_PLUGIN_URL;
?>
/bp-core/images/Jcrop.gif ); }
.jcrop-vline { height: 100%; width: 1px !important; }
.jcrop-hline { width: 100%; height: 1px !important; }
.jcrop-handle { font-size: 1px; width: 7px !important; height: 7px !important; border: 1px #eee solid; background-color: #333; *width: 9px; *height: 9px; }
.jcrop-tracker { width: 100%; height: 100%; }
.custom .jcrop-vline, .custom .jcrop-hline { background: yellow; }
.custom .jcrop-handle { border-color: black; background-color: #C7BB00; -moz-border-radius: 3px; -webkit-border-radius: 3px; }
#avatar-crop-pane { width: <?php
echo bp_core_avatar_full_width();
?>
px; height: <?php
echo bp_core_avatar_full_height();
?>
px; overflow: hidden; }
#avatar-crop-submit { margin: 20px 0; }
#avatar-upload-form img, #create-group-form img, #group-settings-form img { border: none !important; }
</style>
<?php
}
示例4: bp_core_avatar_handle_crop
/**
* 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
*
* @param array $args {
* Array of function parameters.
* @type string $object Object type of the item whose avatar you're
* handling. 'user', 'group', 'blog', or custom. Default: 'user'.
* @type string $avatar_dir Subdirectory where avatar should be stored.
* Default: 'avatars'.
* @type bool|int $item_id ID of the item that the avatar belongs to.
* @type bool|string $original_file Absolute papth to the original avatar
* file.
* @type int $crop_w Crop width. Default: the global 'full' avatar width,
* as retrieved by bp_core_avatar_full_width().
* @type int $crop_h Crop height. Default: the global 'full' avatar height,
* as retrieved by bp_core_avatar_full_height().
* @type int $crop_x The horizontal starting point of the crop. Default: 0.
* @type int $crop_y The vertical starting point of the crop. Default: 0.
* }
* @return bool True on success, false on failure.
*/
function bp_core_avatar_handle_crop($args = '')
{
$r = wp_parse_args($args, 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));
/***
* 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 (empty($original_file)) {
return false;
}
$original_file = bp_core_avatar_upload_path() . $original_file;
if (!file_exists($original_file)) {
return false;
}
if (empty($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 . '/wp-admin/includes/image.php';
require_once ABSPATH . '/wp-admin/includes/file.php';
// Delete the existing avatar files for the object
$existing_avatar = bp_core_fetch_avatar(array('object' => $object, 'item_id' => $item_id, 'html' => false));
if (!empty($existing_avatar)) {
// Check that the new avatar doesn't have the same name as the
// old one before deleting
$upload_dir = wp_upload_dir();
$existing_avatar_path = str_replace($upload_dir['baseurl'], '', $existing_avatar);
$new_avatar_path = str_replace($upload_dir['basedir'], '', $original_file);
if ($existing_avatar_path !== $new_avatar_path) {
bp_core_delete_existing_avatar(array('object' => $object, 'item_id' => $item_id, 'avatar_path' => $avatar_folder_dir));
}
}
// Make sure we at least have a width and height for cropping
if (empty($crop_w)) {
$crop_w = bp_core_avatar_full_width();
}
if (empty($crop_h)) {
$crop_h = bp_core_avatar_full_height();
}
// Get the file extension
$data = @getimagesize($original_file);
$ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';
// Set the full and thumb filenames
$full_filename = wp_hash($original_file . time()) . '-bpfull.' . $ext;
$thumb_filename = wp_hash($original_file . time()) . '-bpthumb.' . $ext;
// Crop the image
$full_cropped = wp_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 = wp_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);
// Check for errors
if (empty($full_cropped) || empty($thumb_cropped) || is_wp_error($full_cropped) || is_wp_error($thumb_cropped)) {
return false;
}
// Remove the original
@unlink($original_file);
return true;
}
示例5: crop
/**
* Crop the avatar.
*
* @since 2.3.0
*
* @see BP_Attachment::crop for the list of parameters
* @uses bp_core_fetch_avatar()
* @uses bp_core_delete_existing_avatar()
* @uses bp_core_avatar_full_width()
* @uses bp_core_avatar_full_height()
* @uses bp_core_avatar_dimension()
* @uses BP_Attachment::crop
*
* @param array $args Array of arguments for the cropping.
* @return array The cropped avatars (full and thumb).
*/
public function crop($args = array())
{
// Bail if the original file is missing.
if (empty($args['original_file'])) {
return false;
}
/**
* Original file is a relative path to the image
* eg: /avatars/1/avatar.jpg
*/
$relative_path = $args['original_file'];
$absolute_path = $this->upload_path . $relative_path;
// Bail if the avatar is not available.
if (!file_exists($absolute_path)) {
return false;
}
if (empty($args['item_id'])) {
/** This filter is documented in bp-core/bp-core-avatars.php */
$avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', dirname($absolute_path), $args['item_id'], $args['object'], $args['avatar_dir']);
} else {
/** This filter is documented in bp-core/bp-core-avatars.php */
$avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $this->upload_path . '/' . $args['avatar_dir'] . '/' . $args['item_id'], $args['item_id'], $args['object'], $args['avatar_dir']);
}
// Bail if the avatar folder is missing for this item_id.
if (!file_exists($avatar_folder_dir)) {
return false;
}
// Delete the existing avatar files for the object.
$existing_avatar = bp_core_fetch_avatar(array('object' => $args['object'], 'item_id' => $args['item_id'], 'html' => false));
/**
* Check that the new avatar doesn't have the same name as the
* old one before deleting
*/
if (!empty($existing_avatar) && $existing_avatar !== $this->url . $relative_path) {
bp_core_delete_existing_avatar(array('object' => $args['object'], 'item_id' => $args['item_id'], 'avatar_path' => $avatar_folder_dir));
}
// Make sure we at least have minimal data for cropping.
if (empty($args['crop_w'])) {
$args['crop_w'] = bp_core_avatar_full_width();
}
if (empty($args['crop_h'])) {
$args['crop_h'] = bp_core_avatar_full_height();
}
// Get the file extension.
$data = @getimagesize($absolute_path);
$ext = $data['mime'] == 'image/png' ? 'png' : 'jpg';
$args['original_file'] = $absolute_path;
$args['src_abs'] = false;
$avatar_types = array('full' => '', 'thumb' => '');
foreach ($avatar_types as $key_type => $type) {
if ('thumb' === $key_type) {
$args['dst_w'] = bp_core_avatar_thumb_width();
$args['dst_h'] = bp_core_avatar_thumb_height();
} else {
$args['dst_w'] = bp_core_avatar_full_width();
$args['dst_h'] = bp_core_avatar_full_height();
}
$args['dst_file'] = $avatar_folder_dir . '/' . wp_hash($absolute_path . time()) . '-bp' . $key_type . '.' . $ext;
$avatar_types[$key_type] = parent::crop($args);
}
// Remove the original.
@unlink($absolute_path);
// Return the full and thumb cropped avatars.
return $avatar_types;
}
示例6: do_action
<?php
/**
* Fires before the activity post form.
*
* @since 1.2.0
*/
do_action('bp_before_activity_post_form');
?>
<div id="whats-new-avatar">
<a href="<?php
echo bp_loggedin_user_domain();
?>
">
<?php
bp_loggedin_user_avatar('type=full&width=' . bp_core_avatar_full_width() . '&height=' . bp_core_avatar_full_height());
?>
</a>
</div>
<p class="activity-greeting">
<?php
printf(__("Welcome back, %s", 'buddypress'), bp_get_user_firstname(bp_get_loggedin_user_fullname()));
?>
</p>
<?php
wp_nonce_field('post_update', '_wpnonce_post_update');
?>
<?php
示例7: bp_attachments_enqueue_scripts
/**
* Enqueues the script needed for the Uploader UI.
*
* @see BP_Attachment::script_data() && BP_Attachment_Avatar::script_data() for examples showing how
* to set specific script data.
*
* @since 2.3.0
*
* @param string $class name of the class extending BP_Attachment (eg: BP_Attachment_Avatar).
*
* @return null|WP_Error
*/
function bp_attachments_enqueue_scripts($class = '')
{
// Enqueue me just once per page, please.
if (did_action('bp_attachments_enqueue_scripts')) {
return;
}
if (!$class || !class_exists($class)) {
return new WP_Error('missing_parameter');
}
// Get an instance of the class and get the script data
$attachment = new $class();
$script_data = $attachment->script_data();
$args = bp_parse_args($script_data, array('action' => '', 'file_data_name' => '', 'max_file_size' => 0, 'browse_button' => 'bp-browse-button', 'container' => 'bp-upload-ui', 'drop_element' => 'drag-drop-area', 'bp_params' => array(), 'extra_css' => array(), 'extra_js' => array(), 'feedback_messages' => array()), 'attachments_enqueue_scripts');
if (empty($args['action']) || empty($args['file_data_name'])) {
return new WP_Error('missing_parameter');
}
// Get the BuddyPress uploader strings
$strings = bp_attachments_get_plupload_l10n();
// Get the BuddyPress uploader settings
$settings = bp_attachments_get_plupload_default_settings();
// Set feedback messages
if (!empty($args['feedback_messages'])) {
$strings['feedback_messages'] = $args['feedback_messages'];
}
// Use a temporary var to ease manipulation
$defaults = $settings['defaults'];
// Set the upload action
$defaults['multipart_params']['action'] = $args['action'];
// Set BuddyPress upload parameters if provided
if (!empty($args['bp_params'])) {
$defaults['multipart_params']['bp_params'] = $args['bp_params'];
}
// Merge other arguments
$ui_args = array_intersect_key($args, array('file_data_name' => true, 'browse_button' => true, 'container' => true, 'drop_element' => true));
$defaults = array_merge($defaults, $ui_args);
if (!empty($args['max_file_size'])) {
$defaults['filters']['max_file_size'] = $args['max_file_size'] . 'b';
}
// Specific to BuddyPress Avatars
if ('bp_avatar_upload' === $defaults['multipart_params']['action']) {
// Include the cropping informations for avatars
$settings['crop'] = array('full_h' => bp_core_avatar_full_height(), 'full_w' => bp_core_avatar_full_width());
// Avatar only need 1 file and 1 only!
$defaults['multi_selection'] = false;
// Does the object already has an avatar set
$has_avatar = $defaults['multipart_params']['bp_params']['has_avatar'];
// What is the object the avatar belongs to
$object = $defaults['multipart_params']['bp_params']['object'];
// Init the Avatar nav
$avatar_nav = array('upload' => array('id' => 'upload', 'caption' => __('Upload', 'buddypress'), 'order' => 0), 'delete' => array('id' => 'delete', 'caption' => __('Delete', 'buddypress'), 'order' => 100, 'hide' => (int) (!$has_avatar)));
// Create the Camera Nav if the WebCam capture feature is enabled
if (bp_avatar_use_webcam() && 'user' === $object) {
$avatar_nav['camera'] = array('id' => 'camera', 'caption' => __('Take Photo', 'buddypress'), 'order' => 10);
// Set warning messages
$strings['camera_warnings'] = array('requesting' => __('Please allow us to access to your camera.', 'buddypress'), 'loading' => __('Please wait as we access your camera.', 'buddypress'), 'loaded' => __('Camera loaded. Click on the "Capture" button to take your photo.', 'buddypress'), 'noaccess' => __('It looks like you do not have a webcam or we were unable to get permission to use your webcam. Please upload a photo instead.', 'buddypress'), 'errormsg' => __('Your browser is not supported. Please upload a photo instead.', 'buddypress'), 'videoerror' => __('Video error. Please upload a photo instead.', 'buddypress'), 'ready' => __('Your profile photo is ready. Click on the "Save" button to use this photo.', 'buddypress'), 'nocapture' => __('No photo was captured. Click on the "Capture" button to take your photo.', 'buddypress'));
}
/**
* Use this filter to add a navigation to a custom tool to set the object's avatar.
*
* @since 2.3.0
*
* @param array $avatar_nav An associative array of available nav items where each item is an array organized this way:
* $avatar_nav[ $nav_item_id ] {
* @type string $nav_item_id The nav item id in lower case without special characters or space.
* @type string $caption The name of the item nav that will be displayed in the nav.
* @type int $order An integer to specify the priority of the item nav, choose one.
* between 1 and 99 to be after the uploader nav item and before the delete nav item.
* @type int $hide If set to 1 the item nav will be hidden
* (only used for the delete nav item).
* }
* @param string $object the object the avatar belongs to (eg: user or group)
*/
$settings['nav'] = bp_sort_by_key(apply_filters('bp_attachments_avatar_nav', $avatar_nav, $object), 'order', 'num');
// Specific to BuddyPress cover images
} elseif ('bp_cover_image_upload' === $defaults['multipart_params']['action']) {
// Cover images only need 1 file and 1 only!
$defaults['multi_selection'] = false;
// Default cover component is xprofile
$cover_component = 'xprofile';
// Get the object we're editing the cover image of
$object = $defaults['multipart_params']['bp_params']['object'];
// Set the cover component according to the object
if ('group' === $object) {
$cover_component = 'groups';
} elseif ('user' !== $object) {
$cover_component = apply_filters('bp_attachments_cover_image_ui_component', $cover_component);
}
// Get cover image advised dimensions
//.........这里部分代码省略.........
示例8: set_fb_image_as_bp_avatar
/**
* Gets FB profile image and sets it as BuddyPress avatar.
*/
function set_fb_image_as_bp_avatar($user_id, $me)
{
if (!defined('BP_VERSION')) {
return true;
}
if (!function_exists('bp_core_avatar_upload_path')) {
return true;
}
if (!$me || !@$me['id']) {
return false;
}
$fb_uid = $me['id'];
if (function_exists('xprofile_avatar_upload_dir')) {
$xpath = xprofile_avatar_upload_dir(false, $user_id);
$path = $xpath['path'];
}
if (!function_exists('xprofile_avatar_upload_dir') || empty($path)) {
$object = 'user';
$avatar_dir = apply_filters('bp_core_avatar_dir', 'avatars', $object);
$path = bp_core_avatar_upload_path() . "/{$avatar_dir}/" . $user_id;
$path = apply_filters('bp_core_avatar_folder_dir', $path, $user_id, $object, $avatar_dir);
if (!realpath($path)) {
@wp_mkdir_p($path);
}
}
// Get FB picture
//$fb_img = file_get_contents("http://graph.facebook.com/{$fb_uid}/picture?type=large");
$page = wp_remote_get("http://graph.facebook.com/{$fb_uid}/picture?type=large", array('method' => 'GET', 'timeout' => '5', 'redirection' => '5', 'user-agent' => 'wdfb', 'blocking' => true, 'compress' => false, 'decompress' => true, 'sslverify' => false));
if (is_wp_error($page)) {
return false;
}
// Request fail
if ((int) $page['response']['code'] != 200) {
return false;
}
// Request fail
$fb_img = $page['body'];
$filename = md5($fb_uid);
$filepath = "{$path}/{$filename}";
file_put_contents($filepath, $fb_img);
// Determine the right extension
$info = getimagesize($filepath);
$extension = false;
if (function_exists('image_type_to_extension')) {
$extension = image_type_to_extension($info[2], false);
} else {
switch ($info[2]) {
case IMAGETYPE_GIF:
$extension = 'gif';
break;
case IMAGETYPE_JPEG:
$extension = 'jpg';
break;
case IMAGETYPE_PNG:
$extension = 'png';
break;
}
}
// Unknown file type, clean up
if (!$extension) {
@unlink($filepath);
return false;
}
$extension = 'jpeg' == strtolower($extension) ? 'jpg' : $extension;
// Forcing .jpg extension for JPEGs
// Clear old avatars
$imgs = glob($path . '/*.{gif,png,jpg}', GLOB_BRACE);
if (is_array($imgs)) {
foreach ($imgs as $old) {
@unlink($old);
}
}
// Create and set new avatar
if (defined('WDFB_BP_AVATAR_AUTO_CROP') && WDFB_BP_AVATAR_AUTO_CROP) {
// Explicitly requested thumbnail processing
// First, determine the centering position for cropping
if ($info && isset($info[0]) && $info[0] && isset($info[1]) && $info[1]) {
$full = apply_filters('wdfb-avatar-auto_crop', array('x' => (int) (($info[0] - bp_core_avatar_full_width()) / 2), 'y' => (int) (($info[1] - bp_core_avatar_full_height()) / 2), 'width' => bp_core_avatar_full_width(), 'height' => bp_core_avatar_full_height()), $filepath, $info);
}
$crop = $full ? wp_crop_image($filepath, $full['x'], $full['y'], $full['width'], $full['height'], bp_core_avatar_full_width(), bp_core_avatar_full_height(), false, "{$filepath}-bpfull.{$extension}") : false;
if (!$crop) {
@unlink($filepath);
return false;
}
// Now, the thumbnail. First, try to resize the full avatar
$thumb_file = wp_create_thumbnail("{$filepath}-bpfull.{$extension}", bp_core_avatar_thumb_width());
if (!is_wp_error($thumb_file)) {
// All good! We're done - clean up
copy($thumb_file, "{$filepath}-bpthumb.{$extension}");
@unlink($thumb_file);
} else {
// Sigh. Let's just fake it by using the original file then.
copy("{$filepath}-bpfull.{$extension}", "{$filepath}-bpthumb.{$extension}");
}
@unlink($filepath);
return true;
} else {
//.........这里部分代码省略.........
示例9: bp_core_avatar_handle_crop
/**
* 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;
}
示例10: bp_legacy_theme_cover_image
/**
* BP Legacy's callback for the cover image feature.
*
* @since 2.4.0
*
* @param array $params the current component's feature parameters.
* @return array an array to inform about the css handle to attach the css rules to
*/
function bp_legacy_theme_cover_image($params = array())
{
if (empty($params)) {
return;
}
// Avatar height - padding - 1/2 avatar height.
$avatar_offset = $params['height'] - 5 - round((int) bp_core_avatar_full_height() / 2);
// Header content offset + spacing.
$top_offset = bp_core_avatar_full_height() - 10;
$left_offset = bp_core_avatar_full_width() + 20;
$cover_image = isset($params['cover_image']) ? 'background-image: url(' . $params['cover_image'] . ');' : '';
$hide_avatar_style = '';
// Adjust the cover image header, in case avatars are completely disabled.
if (!buddypress()->avatar->show_avatars) {
$hide_avatar_style = '
#buddypress #item-header-cover-image #item-header-avatar {
display: none;
}
';
if (bp_is_user()) {
$hide_avatar_style = '
#buddypress #item-header-cover-image #item-header-avatar a {
display: block;
height: ' . $top_offset . 'px;
margin: 0 15px 19px 0;
}
#buddypress div#item-header #item-header-cover-image #item-header-content {
margin-left:auto;
}
';
}
}
return '
/* Cover image */
#buddypress #header-cover-image {
height: ' . $params["height"] . 'px;
' . $cover_image . '
}
#buddypress #create-group-form #header-cover-image {
position: relative;
margin: 1em 0;
}
.bp-user #buddypress #item-header {
padding-top: 0;
}
#buddypress #item-header-cover-image #item-header-avatar {
margin-top: ' . $avatar_offset . 'px;
float: left;
overflow: visible;
width:auto;
}
#buddypress div#item-header #item-header-cover-image #item-header-content {
clear: both;
float: left;
margin-left: ' . $left_offset . 'px;
margin-top: -' . $top_offset . 'px;
width:auto;
}
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
margin-top: ' . $params["height"] . 'px;
margin-left: 0;
clear: none;
max-width: 50%;
}
body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
padding-top: 20px;
max-width: 20%;
}
' . $hide_avatar_style . '
#buddypress div#item-header-cover-image h2 a,
#buddypress div#item-header-cover-image h2 {
color: #FFF;
text-rendering: optimizelegibility;
text-shadow: 0px 0px 3px rgba( 0, 0, 0, 0.8 );
margin: 0 0 .6em;
font-size:200%;
}
#buddypress #item-header-cover-image #item-header-avatar img.avatar {
border: solid 2px #FFF;
background: rgba( 255, 255, 255, 0.8 );
}
//.........这里部分代码省略.........
示例11: wsl_get_bp_user_custom_avatar
function wsl_get_bp_user_custom_avatar($html, $args)
{
//Buddypress component should be enabled
if (!wsl_is_component_enabled('buddypress')) {
return $html;
}
//Check if avatars display is enabled
if (!get_option('wsl_settings_users_avatars')) {
return $html;
}
//Check arguments
if (is_array($args)) {
//User Object
if (!empty($args['object']) and strtolower($args['object']) == 'user') {
//User Identifier
if (!empty($args['item_id']) and is_numeric($args['item_id'])) {
$user_id = $args['item_id'];
//Only Overwrite gravatars
# https://wordpress.org/support/topic/buddypress-avatar-overwriting-problem?replies=1
if (bp_get_user_has_avatar($user_id)) {
return $html;
}
$wsl_avatar = wsl_get_user_custom_avatar($user_id);
//Retrieve Avatar
if ($wsl_avatar) {
$img_class = 'class="' . (!empty($args['class']) ? $args['class'] . ' ' : '') . 'avatar-wordpress-social-login" ';
$img_width = !empty($args['width']) ? 'width="' . $args['width'] . '" ' : 'width="' . bp_core_avatar_full_width() . '" ';
$img_height = !empty($args['height']) ? 'height="' . $args['height'] . '" ' : 'height="' . bp_core_avatar_full_height() . '" ';
$img_alt = !empty($args['alt']) ? 'alt="' . esc_attr($args['alt']) . '" ' : '';
//Replace
$wsl_html = preg_replace('#<img[^>]+>#i', '<img src="' . $wsl_avatar . '" ' . $img_alt . $img_class . $img_height . $img_width . '/>', $html);
// HOOKABLE:
return apply_filters('wsl_hook_alter_get_bp_user_custom_avatar', $wsl_html, $user_id, $wsl_avatar, $html, $args);
}
}
}
}
return $html;
}
示例12: tv_upload_file
function tv_upload_file()
{
global $bp, $wpdb;
if (!isset($bp->signup->step)) {
$bp->signup = new stdClass();
}
if (!isset($bp->avatar_admin)) {
$bp->avatar_admin = new stdClass();
}
$bp->signup->step = 'completed-confirmation';
$next_user_id = get_last_id_auto_increment($wpdb->prefix . 'users');
$bp->signup->avatar_dir = wp_hash($next_user_id);
$bp->displayed_user->id = $next_user_id;
//$bp->avatar_admin->image->url = $_FILES['file']['name'];
$avatar = tv_bp_core_avatar_handle_upload($_FILES, 'xprofile_avatar_upload_dir');
if ($avatar) {
$bp->avatar_admin->step = 'crop-image';
ob_start();
//tv_add_jquery_cropper();
// Bail if no image was uploaded
$image = apply_filters('bp_inline_cropper_image', getimagesize(bp_core_avatar_upload_path() . buddypress()->avatar_admin->image->dir));
if (empty($image)) {
//
$full_height = bp_core_avatar_full_height();
}
$full_width = bp_core_avatar_full_width();
// Calculate Aspect Ratio
if (!empty($full_height) && $full_width != $full_height) {
$aspect_ratio = $full_width / $full_height;
} else {
$aspect_ratio = 1;
}
// Default cropper coordinates
$crop_left = round($image[0] / 4);
$crop_top = round($image[1] / 4);
$crop_right = $image[0] - $crop_left;
$crop_bottom = $image[1] - $crop_top;
$html = '<li class="image-wrap thumbnail" style="width: 100%">';
//$html .= '<h5>'. _e( 'Crop Your New Avatar', 'buddypress' ).'</h5>';
$html = '<img src="' . bp_get_avatar_to_crop() . '" id="avatar-to-crop" class="avatar" alt="Image to crop" />';
$html .= ' <div id="avatar-crop-pane">';
$html .= ' <img src="' . bp_get_avatar_to_crop() . '" id="avatar-crop-preview" class="avatar" alt="Crop Preview" />';
$html .= ' </div>';
$html .= ' <input type="button" name="avatar_crop_submit" id="avatar_crop_submit" value="Crop image" />';
$html .= ' <img class="waiting" src="' . esc_url(admin_url('images/wpspin_light.gif')) . '" alt="" style="display:none" />';
$html .= '<input type="hidden" name="image_src" id="image_src" value="' . bp_get_avatar_to_crop_src() . '" />';
$html .= '<input type="hidden" name="id_user" id="id_user" value="' . $next_user_id . '" />';
$html .= '<input type="hidden" id="x" name="x" />';
$html .= '<input type="hidden" id="y" name="y" />';
$html .= '<input type="hidden" id="w" name="w" />';
$html .= '<input type="hidden" id="h" name="h" />';
$html .= '<script type="text/javascript">';
$html .= '
jQuery("#avatar-to-crop").Jcrop({
onChange: showPreview,
onSelect: showPreview,
onSelect: updateCoords,
keySupport:false,
aspectRatio: ' . $aspect_ratio . ',
setSelect: [' . $crop_left . ', ' . $crop_top . ', ' . $crop_right . ', ' . $crop_bottom . ' ]
});
updateCoords({x:' . $crop_left . ', y: ' . $crop_top . ', w: ' . $crop_right . ', h: ' . $crop_bottom . '});
function updateCoords(c) {
jQuery("#x").val(c.x);
jQuery("#y").val(c.y);
jQuery("#w").val(c.w);
jQuery("#h").val(c.h);
}
function showPreview(coords) {
if ( parseInt(coords.w) > 0 ) {
var fw = 150;
var fh = 150;
var rx = fw / coords.w;
var ry = fh / coords.h;
jQuery( "#avatar-crop-preview" ).css({
width: Math.round(rx * ' . $image[0] . ') + "px",
height: Math.round(ry * ' . $image[1] . ') + "px",
marginLeft: "-" + Math.round(rx * coords.x) + "px",
marginTop: "-" + Math.round(ry * coords.y) + "px"
});
}
}
';
$html .= '</script>';
$html .= '
<style type="text/css">
.jcrop-holder { float: left; margin: 0 20px 20px 0; text-align: left; }
#avatar-crop-pane { width: 150px; height: 150px; overflow: hidden; }
#avatar-crop-submit { margin: 20px 0; }
.jcrop-holder img,
#avatar-crop-pane img,
#avatar-upload-form img,
#create-group-form img,
#group-settings-form img { border: none !important; max-width: none !important; }
</style> ';
//.........这里部分代码省略.........
示例13: bp_avatar_ajax_set
/**
* Ajax set an avatar for a given object and item id
*
* @since BuddyPress (2.3.0)
*
* @return string a json object containing success data if the crop/capture succeeded
* error message otherwise
*/
function bp_avatar_ajax_set()
{
// Bail if not a POST action
if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
wp_send_json_error();
}
// Check the nonce
check_admin_referer('bp_avatar_cropstore', 'nonce');
$avatar_data = wp_parse_args($_POST, array('crop_w' => bp_core_avatar_full_width(), 'crop_h' => bp_core_avatar_full_height(), 'crop_x' => 0, 'crop_y' => 0));
if (empty($avatar_data['object']) || empty($avatar_data['item_id']) || empty($avatar_data['original_file'])) {
wp_send_json_error();
}
// Capability check
if (!bp_attachments_current_user_can('edit_avatar', $avatar_data)) {
wp_send_json_error();
}
if (!empty($avatar_data['type']) && 'camera' === $avatar_data['type'] && 'user' === $avatar_data['object']) {
$webcam_avatar = false;
if (!empty($avatar_data['original_file'])) {
$webcam_avatar = str_replace(array('data:image/png;base64,', ' '), array('', '+'), $avatar_data['original_file']);
$webcam_avatar = base64_decode($webcam_avatar);
}
if (!bp_avatar_handle_capture($webcam_avatar, $avatar_data['item_id'])) {
wp_send_json_error(array('feedback_code' => 1));
} else {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
do_action('xprofile_screen_change_avatar');
wp_send_json_success($return);
}
return;
}
$original_file = str_replace(bp_core_avatar_url(), '', $avatar_data['original_file']);
// Set avatars dir & feedback part
if ('user' === $avatar_data['object']) {
$avatar_dir = 'avatars';
// Defaults to object-avatars dir
} else {
$avatar_dir = sanitize_key($avatar_data['object']) . '-avatars';
}
// Crop args
$r = array('item_id' => $avatar_data['item_id'], 'object' => $avatar_data['object'], 'avatar_dir' => $avatar_dir, 'original_file' => $original_file, 'crop_w' => $avatar_data['crop_w'], 'crop_h' => $avatar_data['crop_h'], 'crop_x' => $avatar_data['crop_x'], 'crop_y' => $avatar_data['crop_y']);
// Handle crop
if (bp_core_avatar_handle_crop($r)) {
$return = array('avatar' => html_entity_decode(bp_core_fetch_avatar(array('object' => $avatar_data['object'], 'item_id' => $avatar_data['item_id'], 'html' => false, 'type' => 'full'))), 'feedback_code' => 2, 'item_id' => $avatar_data['item_id']);
if ('user' === $avatar_data['object']) {
do_action('xprofile_screen_change_avatar');
}
wp_send_json_success($return);
} else {
wp_send_json_error(array('feedback_code' => 1));
}
}
示例14: bcp_core_avatar_handle_crop
/**
* Crop an uploaded avatar.
*
* originally from bp file <>. It was copied since naming it does not have any filters
* for renaming and changing the cropped avatae
*
* $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
*
* @param array $args {
* Array of function parameters.
* @type string $object Object type of the item whose avatar you're
* handling. 'user', 'group', 'blog', or custom. Default: 'user'.
* @type string $avatar_dir Subdirectory where avatar should be stored.
* Default: 'avatars'.
* @type bool|int $item_id ID of the item that the avatar belongs to.
* @type bool|string $original_file Absolute papth to the original avatar
* file.
* @type int $crop_w Crop width. Default: the global 'full' avatar width,
* as retrieved by bp_core_avatar_full_width().
* @type int $crop_h Crop height. Default: the global 'full' avatar height,
* as retrieved by bp_core_avatar_full_height().
* @type int $crop_x The horizontal starting point of the crop. Default: 0.
* @type int $crop_y The vertical starting point of the crop. Default: 0.
* }
* @return bool True on success, false on failure.
*/
function bcp_core_avatar_handle_crop($args = '')
{
$existing_avatar = '';
$coverphoto_full_width = BCP_MAX_WIDTH;
$coverphoto_full_height = BCP_MAX_HEIGHT;
$coverphoto_thumb_full_width = BCP_THUMB_MAX_WIDTH;
$coverphoto_thumb_full_height = BCP_THUMB_MAX_HEIGHT;
$r = wp_parse_args($args, 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));
/***
* 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 (empty($original_file)) {
return false;
}
$original_file = bp_core_avatar_upload_path() . $original_file;
if (!file_exists($original_file)) {
return false;
}
if (empty($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 . '/wp-admin/includes/image.php';
require_once ABSPATH . '/wp-admin/includes/file.php';
// Delete the existing avatar files for the object
$args = array('object_id' => $item_id, 'type' => 'user');
//change object type to groups for groups
if ('group-avatars' == $avatar_dir) {
$args['type'] = 'groups';
}
$existing_covers = bcp_fetch_cover_photo($args);
if (!empty($existing_covers)) {
// Check that the new avatar doesn't have the same name as the
// old one before deleting
$upload_dir = wp_upload_dir();
$existing_avatar_path = str_replace($upload_dir['baseurl'], '', $existing_avatar);
$new_avatar_path = str_replace($upload_dir['basedir'], '', $original_file);
if ($existing_avatar_path !== $new_avatar_path) {
if ($handle = opendir($avatar_folder_dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$file_info = pathinfo($entry);
$file_name = $file_info['filename'];
$file_ext = $file_info['extension'];
$cover_photos = array('coverphoto-full', 'coverphoto-thumb');
if (in_array($file_name, $cover_photos)) {
// cover photo exists
$file = $avatar_folder_dir . '/' . $file_name . '.' . $file_ext;
@unlink($file);
}
}
}
// close the directory
closedir($handle);
}
}
}
//.........这里部分代码省略.........
示例15: record_cover_image
function record_cover_image($params = array())
{
if (empty($params)) {
return;
}
// avatar height - padding - 1/2 avatar height
$avatar_offset = $params['height'] - 5 - round((int) bp_core_avatar_full_height() / 2);
// header content offset + spacing
$top_offset = bp_core_avatar_full_height() - 10;
$left_offset = bp_core_avatar_full_width() + 20;
$this->cover_image = $params['cover_image'];
}