/** * Get an avatar for a BuddyPress object. * * Supports avatars for users, groups, and blogs by default, but can be * extended to support custom components as well. * * This function gives precedence to locally-uploaded avatars. When a local * avatar is not found, Gravatar is queried. To disable Gravatar fallbacks * locally: * add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' ); * * @since 2.4.0 Added 'extra_attr', 'scheme', 'rating' and 'force_default' for $args. * These are inherited from WordPress 4.2.0. See {@link get_avatar()}. * * @param array|string $args { * An array of arguments. All arguments are technically optional; some * will, if not provided, be auto-detected by bp_core_fetch_avatar(). This * auto-detection is described more below, when discussing specific * arguments. * * @type int|bool $item_id The numeric ID of the item for which you're requesting * an avatar (eg, a user ID). If no 'item_id' is present, * the function attempts to infer an ID from the 'object' + the * current context: if 'object' is 'user' and the current page is a * user page, 'item_id' will default to the displayed user ID; if * 'group' and on a group page, to the current group ID; if 'blog', * to the current blog's ID. If no 'item_id' can be determined in * this way, the function returns false. Default: false. * @type string $object The kind of object for which you're getting an * avatar. BuddyPress natively supports three options: 'user', * 'group', 'blog'; a plugin may register more. Default: 'user'. * @type string $type When a new avatar is uploaded to BP, 'thumb' and * 'full' versions are saved. This parameter specifies whether you'd * like the 'full' or smaller 'thumb' avatar. Default: 'thumb'. * @type string|bool $avatar_dir The name of the subdirectory where the * requested avatar should be found. If no value is passed, * 'avatar_dir' is inferred from 'object': 'user' becomes 'avatars', * 'group' becomes 'group-avatars', 'blog' becomes 'blog-avatars'. * Remember that this string denotes a subdirectory of BP's main * avatar directory (usually based on {@link wp_upload_dir()}); it's a * string like 'group-avatars' rather than the full directory path. * Generally, it'll only be necessary to override the default value if * storing avatars in a non-default location. Defaults to false * (auto-detected). * @type int|bool $width Requested avatar width. The unit is px. This value * is used to build the 'width' attribute for the <img> element. If * no value is passed, BP uses the global avatar width for this * avatar type. Default: false (auto-detected). * @type int|bool $height Requested avatar height. The unit is px. This * value is used to build the 'height' attribute for the <img> * element. If no value is passed, BP uses the global avatar height * for this avatar type. Default: false (auto-detected). * @type string $class The CSS class for the <img> element. Note that BP * uses the 'avatar' class fairly extensively in its default styling, * so if you plan to pass a custom value, consider appending it to * 'avatar' (eg 'avatar foo') rather than replacing it altogether. * Default: 'avatar'. * @type string|bool $css_id The CSS id for the <img> element. * Default: false. * @type string $title The title attribute for the <img> element. * Default: false. * @type string $alt The alt attribute for the <img> element. In BP, this * value is generally passed by the wrapper functions, where the data * necessary for concatenating the string is at hand; see * {@link bp_get_activity_avatar()} for an example. Default: ''. * @type string|bool $email An email to use in Gravatar queries. Unless * otherwise configured, BP uses Gravatar as a fallback for avatars * that are not provided locally. Gravatar's API requires using a hash * of the user's email address; this argument provides it. If not * provided, the function will infer it: for users, by getting the * user's email from the database, for groups/blogs, by concatenating * "{$item_id}-{$object}@{bp_get_root_domain()}". The user query adds * overhead, so it's recommended that wrapper functions provide a * value for 'email' when querying user IDs. Default: false. * @type bool $no_grav Whether to disable the default Gravatar fallback. * By default, BP will fall back on Gravatar when it cannot find a * local avatar. In some cases, this may be undesirable, in which * case 'no_grav' should be set to true. To disable Gravatar * fallbacks globally, see the 'bp_core_fetch_avatar_no_grav' filter. * Default: false. * @type bool $html Whether to return an <img> HTML element, vs a raw URL * to an avatar. If false, <img>-specific arguments (like 'css_id') * will be ignored. Default: true. * @type string $extra_attr HTML attributes to insert in the IMG element. Not sanitized. Default: ''. * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. * Default null. * @type string $rating What rating to display Gravatars for. Accepts 'G', 'PG', 'R', 'X'. * Default is the value of the 'avatar_rating' option. * @type bool $force_default Used when creating the Gravatar URL. Whether to force the default * image regardless if the Gravatar exists. Default: false. * } * * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg. */ function bp_core_fetch_avatar($args = '') { $bp = buddypress(); // If avatars are disabled for the root site, obey that request and bail if (!$bp->avatar->show_avatars) { return; } global $current_blog; // Set the default variables array and parse it against incoming $args array. $params = wp_parse_args($args, array('item_id' => false, 'object' => 'user', 'type' => 'thumb', 'avatar_dir' => false, 'width' => false, 'height' => false, 'class' => 'avatar', 'css_id' => false, 'alt' => '', 'email' => false, 'no_grav' => false, 'html' => true, 'title' => '', 'extra_attr' => '', 'scheme' => null, 'rating' => get_option('avatar_rating'), 'force_default' => false)); /** Set item_id ***********************************************************/ if (empty($params['item_id'])) { switch ($params['object']) { case 'blog': $params['item_id'] = $current_blog->id; break; case 'group': if (bp_is_active('groups')) { $params['item_id'] = $bp->groups->current_group->id; } else { $params['item_id'] = false; } break; case 'user': default: $params['item_id'] = bp_displayed_user_id(); break; } /** * Filters the ID of the item being requested. * * @since 1.1.0 * * @param string $value ID of avatar item being requested. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $params['item_id'] = apply_filters('bp_core_avatar_item_id', $params['item_id'], $params['object'], $params); if (empty($params['item_id'])) { return false; } } /** Set avatar_dir ********************************************************/ if (empty($params['avatar_dir'])) { switch ($params['object']) { case 'blog': $params['avatar_dir'] = 'blog-avatars'; break; case 'group': if (bp_is_active('groups')) { $params['avatar_dir'] = 'group-avatars'; } else { $params['avatar_dir'] = false; } break; case 'user': default: $params['avatar_dir'] = 'avatars'; break; } /** * Filters the avatar directory to use. * * @since 1.1.0 * * @param string $value Name of the subdirectory where the requested avatar should be found. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $params['avatar_dir'] = apply_filters('bp_core_avatar_dir', $params['avatar_dir'], $params['object'], $params); if (empty($params['avatar_dir'])) { return false; } } /** <img> alt *************************************************************/ if (false !== strpos($params['alt'], '%s') || false !== strpos($params['alt'], '%1$s')) { switch ($params['object']) { case 'blog': $item_name = get_blog_option($params['item_id'], 'blogname'); break; case 'group': $item_name = bp_get_group_name(groups_get_group(array('group_id' => $params['item_id']))); break; case 'user': default: $item_name = bp_core_get_user_displayname($params['item_id']); break; } /** * Filters the alt attribute value to be applied to avatar. * * @since 1.5.0 * * @param string $value alt to be applied to avatar. * @param string $value ID of avatar item being requested. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $item_name = apply_filters('bp_core_avatar_alt', $item_name, $params['item_id'], $params['object'], $params); $params['alt'] = sprintf($params['alt'], $item_name); } /** Sanity Checks *********************************************************/ // Get a fallback for the 'alt' parameter, create html output. if (empty($params['alt'])) { $params['alt'] = __('Profile Photo', 'buddypress'); } $html_alt = ' alt="' . esc_attr($params['alt']) . '"'; // Filter image title and create html string. $html_title = ''; /** * Filters the title attribute value to be applied to avatar. * * @since 1.5.0 * * @param string $value Title to be applied to avatar. * @param string $value ID of avatar item being requested. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $params['title'] = apply_filters('bp_core_avatar_title', $params['title'], $params['item_id'], $params['object'], $params); if (!empty($params['title'])) { $html_title = ' title="' . esc_attr($params['title']) . '"'; } // Extra attributes $extra_attr = !empty($args['extra_attr']) ? ' ' . $args['extra_attr'] : ''; // Set CSS ID and create html string. $html_css_id = ''; /** * Filters the ID attribute to be applied to avatar. * * @since 2.2.0 * * @param string $value ID to be applied to avatar. * @param string $value ID of avatar item being requested. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $params['css_id'] = apply_filters('bp_core_css_id', $params['css_id'], $params['item_id'], $params['object'], $params); if (!empty($params['css_id'])) { $html_css_id = ' id="' . esc_attr($params['css_id']) . '"'; } // Set image width if (false !== $params['width']) { // Width has been specified. No modification necessary. } elseif ('thumb' == $params['type']) { $params['width'] = bp_core_avatar_thumb_width(); } else { $params['width'] = bp_core_avatar_full_width(); } $html_width = ' width="' . $params['width'] . '"'; // Set image height if (false !== $params['height']) { // Height has been specified. No modification necessary. } elseif ('thumb' == $params['type']) { $params['height'] = bp_core_avatar_thumb_height(); } else { $params['height'] = bp_core_avatar_full_height(); } $html_height = ' height="' . $params['height'] . '"'; /** * Filters the classes to be applied to the avatar. * * @since 1.6.0 * * @param array|string $value Class(es) to be applied to the avatar. * @param string $value ID of the avatar item being requested. * @param string $value Avatar type being requested. * @param array $params Array of parameters for the request. */ $params['class'] = apply_filters('bp_core_avatar_class', $params['class'], $params['item_id'], $params['object'], $params); // Use an alias to leave the param unchanged $avatar_classes = $params['class']; if (!is_array($avatar_classes)) { $avatar_classes = explode(' ', $avatar_classes); } // merge classes $avatar_classes = array_merge($avatar_classes, array($params['object'] . '-' . $params['item_id'] . '-avatar', 'avatar-' . $params['width'])); // Sanitize each class $avatar_classes = array_map('sanitize_html_class', $avatar_classes); // populate the class attribute $html_class = ' class="' . join(' ', $avatar_classes) . ' photo"'; // Set img URL and DIR based on prepopulated constants $avatar_loc = new stdClass(); $avatar_loc->path = trailingslashit(bp_core_avatar_upload_path()); $avatar_loc->url = trailingslashit(bp_core_avatar_url()); $avatar_loc->dir = trailingslashit($params['avatar_dir']); /** * Filters the avatar folder directory URL. * * @since 1.1.0 * * @param string $value Path to the avatar folder URL. * @param int $value ID of the avatar item being requested. * @param string $value Avatar type being requested. * @param string $value Subdirectory where the requested avatar should be found. */ $avatar_folder_url = apply_filters('bp_core_avatar_folder_url', $avatar_loc->url . $avatar_loc->dir . $params['item_id'], $params['item_id'], $params['object'], $params['avatar_dir']); /** * Filters the avatar folder directory path. * * @since 1.1.0 * * @param string $value Path to the avatar folder directory. * @param int $value ID of the avatar item being requested. * @param string $value Avatar type being requested. * @param string $value Subdirectory where the requested avatar should be found. */ $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', $avatar_loc->path . $avatar_loc->dir . $params['item_id'], $params['item_id'], $params['object'], $params['avatar_dir']); /** * Look for uploaded avatar first. Use it if it exists. * Set the file names to search for, to select the full size * or thumbnail image. */ $avatar_size = 'full' == $params['type'] ? '-bpfull' : '-bpthumb'; $legacy_user_avatar_name = 'full' == $params['type'] ? '-avatar2' : '-avatar1'; $legacy_group_avatar_name = 'full' == $params['type'] ? '-groupavatar-full' : '-groupavatar-thumb'; // Check for directory if (file_exists($avatar_folder_dir)) { // Open directory if ($av_dir = opendir($avatar_folder_dir)) { // Stash files in an array once to check for one that matches $avatar_files = array(); while (false !== ($avatar_file = readdir($av_dir))) { // Only add files to the array (skip directories) if (2 < strlen($avatar_file)) { $avatar_files[] = $avatar_file; } } // Check for array if (0 < count($avatar_files)) { // Check for current avatar foreach ($avatar_files as $key => $value) { if (strpos($value, $avatar_size) !== false) { $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key]; } } // Legacy avatar check if (!isset($avatar_url)) { foreach ($avatar_files as $key => $value) { if (strpos($value, $legacy_user_avatar_name) !== false) { $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key]; } } // Legacy group avatar check if (!isset($avatar_url)) { foreach ($avatar_files as $key => $value) { if (strpos($value, $legacy_group_avatar_name) !== false) { $avatar_url = $avatar_folder_url . '/' . $avatar_files[$key]; } } } } } } // Close the avatar directory closedir($av_dir); // If we found a locally uploaded avatar if (isset($avatar_url)) { // Support custom scheme $avatar_url = set_url_scheme($avatar_url, $params['scheme']); // Return it wrapped in an <img> element if (true === $params['html']) { /** * Filters an avatar URL wrapped in an <img> element. * * @since 1.1.0 * * @param string $value Full <img> element for an avatar. * @param array $params Array of parameters for the request. * @param string $value ID of the item requested. * @param string $value Subdirectory where the requested avatar should be found. * @param string $html_css_id ID attribute for avatar. * @param string $html_width Width attribute for avatar. * @param string $html_height Height attribtue for avatar. * @param string $avatar_folder_url Avatar URL path. * @param string $avatar_folder_dir Avatar dir path. */ return apply_filters('bp_core_fetch_avatar', '<img src="' . $avatar_url . '"' . $html_class . $html_css_id . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir); // ...or only the URL } else { /** * Filters a locally uploaded avatar URL. * * @since 1.2.5 * * @param string $avatar_url URL for a locally uploaded avatar. * @param array $params Array of parameters for the request. */ return apply_filters('bp_core_fetch_avatar_url', $avatar_url, $params); } } } /** * Filters whether or not to skip Gravatar check. * * @since 1.5.0 * * @param bool $value Whether or not to skip Gravatar. * @param array $params Array of parameters for the avatar request. */ if (!apply_filters('bp_core_fetch_avatar_no_grav', $params['no_grav'], $params)) { // Set gravatar type if (empty($bp->grav_default->{$params['object']})) { $default_grav = 'wavatar'; } elseif ('mystery' == $bp->grav_default->{$params['object']}) { /** * Filters the Mystery person avatar src value. * * @since 1.2.0 * * @param string $value Avatar value. * @param string $value Width to display avatar at. */ $default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $params['width']); } else { $default_grav = $bp->grav_default->{$params['object']}; } // Set gravatar object if (empty($params['email'])) { if ('user' == $params['object']) { $params['email'] = bp_core_get_user_email($params['item_id']); } elseif ('group' == $params['object'] || 'blog' == $params['object']) { $params['email'] = $params['item_id'] . '-' . $params['object'] . '@' . bp_get_root_domain(); } } /** * Filters the Gravatar email to use. * * @since 1.1.0 * * @param string $value Email to use in Gravatar request. * @param string $value ID of the item being requested. * @param string $value Object type being requested. */ $params['email'] = apply_filters('bp_core_gravatar_email', $params['email'], $params['item_id'], $params['object']); /** * Filters the Gravatar URL host. * * @since 1.0.2 * * @param string $value Gravatar URL host. */ $gravatar = apply_filters('bp_gravatar_url', '//www.gravatar.com/avatar/'); // Append email hash to Gravatar $gravatar .= md5(strtolower($params['email'])); // Main Gravatar URL args $url_args = array('s' => $params['width']); // Custom Gravatar URL args if (!empty($params['force_default'])) { $url_args['f'] = 'y'; } if (!empty($params['rating'])) { $url_args['r'] = strtolower($params['rating']); } // Only set default image if 'Gravatar Logo' is not requested if ('gravatar_default' !== $default_grav) { $url_args['d'] = $default_grav; } // Set up the Gravatar URL $gravatar = esc_url(add_query_arg(rawurlencode_deep(array_filter($url_args)), $gravatar)); // No avatar was found, and we've been told not to use a gravatar. } else { /** * Filters the avatar default when Gravatar is not used. * * This is a variable filter dependent on the avatar type being requested. * * @since 1.5.0 * * @param string $value Default avatar for non-gravatar requests. * @param array $params Array of parameters for the avatar request. */ $gravatar = apply_filters('bp_core_default_avatar_' . $params['object'], bp_core_avatar_default('local'), $params); } if (true === $params['html']) { /** This filter is documented in bp-core/bp-core-avatars.php */ return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir); } else { /** This filter is documented in bp-core/bp-core-avatars.php */ return apply_filters('bp_core_fetch_avatar_url', $gravatar, $params); } }
<form action="<?php bp_activity_post_form_action(); ?> " method="post" id="whats-new-form" name="whats-new-form" role="complementary"> <?php 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('width=' . bp_core_avatar_thumb_width() . '&height=' . bp_core_avatar_thumb_height()); ?> </a> </div> <h5><?php if (bp_is_group()) { printf(__("What's new in %s, %s?", 'buddypress'), bp_get_group_name(), bp_get_user_firstname()); } else { printf(__("What's new, %s?", 'buddypress'), bp_get_user_firstname()); } ?> </h5> <div id="whats-new-content"> <div id="whats-new-textarea">
/** * 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; }
/** * 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; }
function widget($args, $instance) { global $bp; extract($args); echo $before_widget; echo $before_title . $widget_name . $after_title; ?> <?php if (bp_has_links('type=popular&per_page=' . $instance['max_links'] . '&max=' . $instance['max_links'])) { ?> <div class="item-options" id="links-list-options"> <span class="ajax-loader" id="ajax-loader-links"></span> <a href="<?php echo site_url() . '/' . bp_links_root_slug(); ?> " id="newest-links"><?php _e("Newest", 'buddypress'); ?> </a> | <?php if (bp_links_is_voting_enabled()) { ?> <a href="<?php echo site_url() . '/' . bp_links_root_slug(); ?> " id="most-votes"><?php _e("Votes", 'buddypress-links'); ?> </a> | <a href="<?php echo site_url() . '/' . bp_links_root_slug(); ?> " id="high-votes"><?php _e("Rating", 'buddypress-links'); ?> </a> | <a href="<?php echo site_url() . '/' . bp_links_root_slug(); ?> " id="popular-links" class="selected"><?php _e("Popular", 'buddypress'); ?> </a> <?php } else { ?> <a href="<?php echo site_url() . '/' . bp_links_root_slug(); ?> " id="active-links"><?php _e("Active", 'buddypress'); ?> </a> <?php } ?> </div> <ul id="links-list" class="item-list"> <?php while (bp_links()) { bp_the_link(); ?> <li> <div class="item-avatar"> <a href="<?php bp_link_permalink(); ?> "><?php bp_link_avatar(array('width' => bp_core_avatar_thumb_width(), 'height' => bp_core_avatar_thumb_height())); ?> </a> </div> <div class="item"> <div class="item-title"><a href="<?php bp_link_permalink(); ?> " title="<?php bp_link_name(); ?> "><?php bp_link_name(); ?> </a></div> <?php if (bp_links_is_voting_enabled()) { ?> <div class="item-meta"><span class="activity"><?php printf(__('%+d rating', 'buddypress-links'), bp_get_link_vote_total()); ?> </span></div> <?php } ?> </div> </li> <?php } ?> </ul> <?php wp_nonce_field('bp_links_widget_links_list', '_wpnonce-links'); ?> <input type="hidden" name="links_widget_max" id="links_widget_max" value="<?php echo attribute_escape($instance['max_links']); ?> " /> <?php } else { ?> <div class="widget-error"> <?php _e('There are no links to display.', 'buddypress-links'); ?> </div> <?php } ?> <?php echo $after_widget; ?> <?php }
/** * 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; }
<?php do_action('mpp_after_lightbox_media', $media); ?> </div> <div class="mpp-lightbox-activity-container"> <div class="mpp-lightbox-media-uploader-meta mpp-clearfix"> <div class="mpp-lightbox-media-uploader-avatar"> <a href="<?php echo bp_core_get_user_domain(mpp_get_media_creator_id()); ?> "> <?php echo bp_core_fetch_avatar(array('item_id' => mpp_get_media_creator_id(), 'object' => 'members', 'width' => bp_core_avatar_thumb_width(), 'height' => bp_core_avatar_thumb_height())); ?> </a> </div> <div class="mpp-lightbox-uploader-upload-details"> <div class="mpp-lightbox-uploader-link"> <?php echo bp_core_get_userlink(mpp_get_media_creator_id()); ?> </div> </div> </div><!--end of the top row --> <div class="mpp-item-description mpp-media-description mpp-lightbox-media-description mpp-clearfix"> <?php mpp_media_description(); ?>
<?php do_action('mpp_after_lightbox_media', $media); ?> </div> <div class="mpp-lightbox-activity-container"> <div class="mpp-lightbox-media-uploader-meta mpp-clearfix"> <div class="mpp-lightbox-media-uploader-avatar"> <a href="<?php echo bp_core_get_user_domain(mpp_get_media_creator_id()); ?> "> <?php echo bp_core_fetch_avatar(array('object' => 'members', 'width' => bp_core_avatar_thumb_width(), 'height' => bp_core_avatar_thumb_height())); ?> </a> </div> <div class="mpp-lightbox-uploader-upload-details"> <div class="mpp-lightbox-uploader-link"> <?php echo bp_core_get_userlink(mpp_get_media_creator_id()); ?> </div> </div> </div><!--end of the top row --> <div class="mpp-item-description mpp-media-description mpp-lightbox-media-description mpp-clearfix"> <?php mpp_media_description(); ?>
<div class="inner-sidebar <?php do_action('wf_class_inner_sidebar'); ?> inner-sidebar-mobile"> <a id="close-buddypress-mobile-sidebar" class="close-panel-button" href="#"> <i class="fa fa-times-circle"></i> Close menu </a> <?php if (bp_is_user()) { ?> <div id="user-sidebar-menu" class="widget"> <?php bp_displayed_user_avatar('width=' . bp_core_avatar_thumb_width() . '&height=' . bp_core_avatar_thumb_height()); ?> <?php $userLink = bp_get_displayed_user_link(); ?> <strong><?php echo bp_core_get_user_displayname(bp_displayed_user_id()); ?> </strong> <br> </div> <?php } ?> <?php