Example #1
0
function revert_to_default_wp_avatar($img, $params, $item_id)
{
    // we are concerned only with users
    if ($params['object'] != 'user') {
        return $img;
    }
    //check if user has uploaded an avatar
    //if not then revert back to wordpress core get_avatar method
    //remove the filter first, or else it will go in infinite loop
    remove_filter('bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3);
    if (!userpro_user_has_avatar($item_id)) {
        $width = $params['width'];
        // Set image width
        if (false !== $width) {
            $img_width = $width;
        } elseif ('thumb' == $type) {
            $img_width = bp_core_avatar_thumb_width();
        } else {
            $img_width = bp_core_avatar_full_width();
        }
        $img = get_avatar($item_id, $img_width);
    }
    //add the filter back again
    add_filter('bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3);
    return $img;
}
Example #2
0
function revert_to_default_wp_avatar($img, $params, $item_id)
{
    if ($params['object'] != 'user') {
        return $img;
    }
    remove_filter('bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3);
    if (!userpro_user_has_avatar($item_id)) {
        $width = $params['width'];
        if (false !== $width) {
            $img_width = $width;
        } elseif ('thumb' == $params['type']) {
            $img_width = bp_core_avatar_thumb_width();
        } else {
            $img_width = bp_core_avatar_full_width();
        }
        $img = get_avatar($item_id, $img_width);
    }
    add_filter('bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3);
    return $img;
}
/**
 * Get the user avatar during signup.
 *
 * @see bp_core_fetch_avatar() for description of arguments.
 *
 * @param array|string $args {
 *     Array of optional arguments.
 *     @type int    $size  Height/weight in pixels. Default: value of
 *                         bp_core_avatar_full_width().
 *     @type string $class CSS class. Default: 'avatar'.
 *     @type string $alt   HTML 'alt' attribute. Default: 'Your Avatar'.
 * }
 * @return string
 */
function bp_get_signup_avatar($args = '')
{
    $bp = buddypress();
    $defaults = array('size' => bp_core_avatar_full_width(), 'class' => 'avatar', 'alt' => __('Your Profile Photo', 'buddypress'));
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Avatar DIR is found.
    if ($signup_avatar_dir = bp_get_signup_avatar_dir_value()) {
        $gravatar_img = bp_core_fetch_avatar(array('item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class));
        // No avatar DIR was found.
    } else {
        // Set default gravatar type.
        if (empty($bp->grav_default->user)) {
            $default_grav = 'wavatar';
        } elseif ('mystery' == $bp->grav_default->user) {
            $default_grav = $bp->plugin_url . 'bp-core/images/mystery-man.jpg';
        } else {
            $default_grav = $bp->grav_default->user;
        }
        /**
         * Filters the base Gravatar url used for signup avatars when no avatar dir found.
         *
         * @since 1.0.2
         *
         * @param string $value Gravatar url to use.
         */
        $gravatar_url = apply_filters('bp_gravatar_url', '//www.gravatar.com/avatar/');
        $md5_lcase_email = md5(strtolower(bp_get_signup_email_value()));
        $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    }
    /**
     * Filters the user avatar during signup.
     *
     * @since 1.1.0
     *
     * @param string $gravatar_img Avatar HTML image tag.
     * @param array  $args         Array of parsed args for avatar query.
     */
    return apply_filters('bp_get_signup_avatar', $gravatar_img, $args);
}
function bp_get_signup_avatar($args = '')
{
    global $bp;
    $defaults = array('size' => bp_core_avatar_full_width(), 'class' => 'avatar', 'alt' => __('Your Avatar', 'buddypress'));
    $r = nxt_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Avatar DIR is found
    if ($signup_avatar_dir = bp_get_signup_avatar_dir_value()) {
        $gravatar_img = bp_core_fetch_avatar(array('item_id' => $signup_avatar_dir, 'object' => 'signup', 'avatar_dir' => 'avatars/signups', 'type' => 'full', 'width' => $size, 'height' => $size, 'alt' => $alt, 'class' => $class));
        // No avatar DIR was found
    } else {
        // Set default gravatar type
        if (empty($bp->grav_default->user)) {
            $default_grav = 'wavatar';
        } else {
            if ('mystery' == $bp->grav_default->user) {
                $default_grav = BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg';
            } else {
                $default_grav = $bp->grav_default->user;
            }
        }
        // Create
        $gravatar_url = apply_filters('bp_gravatar_url', 'http://www.gravatar.com/avatar/');
        $md5_lcase_email = md5(strtolower(bp_get_signup_email_value()));
        $gravatar_img = '<img src="' . $gravatar_url . $md5_lcase_email . '?d=' . $default_grav . '&amp;s=' . $size . '" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" class="' . $class . '" />';
    }
    return apply_filters('bp_get_signup_avatar', $gravatar_img, $args);
}
Example #5
0
/**
 * 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;
}
/**
 * Syncs site icon URLs to blogmeta.
 *
 * @since 2.7.0
 *
 * @param int|string $old_value Old value
 * @param int|string $new_value New value
 */
function bp_blogs_update_option_site_icon($old_value, $new_value)
{
    if (0 === $new_value) {
        bp_blogs_update_blogmeta(get_current_blog_id(), 'site_icon_url_thumb', 0);
        bp_blogs_update_blogmeta(get_current_blog_id(), 'site_icon_url_full', 0);
    } else {
        // Save site icon URL as blogmeta.
        bp_blogs_update_blogmeta(get_current_blog_id(), 'site_icon_url_thumb', get_site_icon_url(bp_core_avatar_thumb_width()));
        bp_blogs_update_blogmeta(get_current_blog_id(), 'site_icon_url_full', get_site_icon_url(bp_core_avatar_full_width()));
    }
}
/**
 * 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 
}
 /**
  * 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;
 }
/**
 * Get the URL of the 'full' default avatar.
 *
 * @since 1.5.0
 * @since 2.6.0 Introduced `$params` and `$object_type` parameters.
 *
 * @param string $type   'local' if the fallback should be the locally-hosted version
 *                       of the mystery person, 'gravatar' if the fallback should be
 *                       Gravatar's version. Default: 'gravatar'.
 * @param array  $params Parameters passed to bp_core_fetch_avatar().
 * @return string The URL of the default avatar.
 */
function bp_core_avatar_default($type = 'gravatar', $params = array())
{
    // Local override.
    if (defined('BP_AVATAR_DEFAULT')) {
        $avatar = BP_AVATAR_DEFAULT;
        // Use the local default image.
    } elseif ('local' === $type) {
        $size = '';
        if (isset($params['type']) && 'thumb' === $params['type'] && bp_core_avatar_thumb_width() <= 50 || isset($params['width']) && $params['width'] <= 50) {
            $size = '-50';
        }
        $avatar = buddypress()->plugin_url . "bp-core/images/mystery-man{$size}.jpg";
        // Use Gravatar's mystery person as fallback.
    } else {
        $size = '';
        if (isset($params['type']) && 'thumb' === $params['type']) {
            $size = bp_core_avatar_thumb_width();
        } else {
            $size = bp_core_avatar_full_width();
        }
        $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=' . $size;
    }
    /**
     * Filters the URL of the 'full' default avatar.
     *
     * @since 1.5.0
     * @since 2.6.0 Added `$params`.
     *
     * @param string $avatar URL of the default avatar.
     * @param array  $params Params provided to bp_core_fetch_avatar().
     */
    return apply_filters('bp_core_avatar_default', $avatar, $params);
}
/**
 * Get a blog's avatar.
 *
 * At the moment, blog avatars are simply the user avatars of the blog
 * admin. Filter 'bp_get_blog_avatar_' . $blog_id to customize.
 *
 * @since 2.4.0 Introduced `$title` argument.
 *
 * @see bp_core_fetch_avatar() For a description of arguments and
 *      return values.
 *
 * @param array|string $args  {
 *     Arguments are listed here with an explanation of their defaults.
 *     For more information about the arguments, see
 *     {@link bp_core_fetch_avatar()}.
 *     @type string   $alt     Default: 'Profile picture of site author [user name]'.
 *     @type string   $class   Default: 'avatar'.
 *     @type string   $title   Default: 'Profile picture of site author [user name]'.
 *     @type string   $type    Default: 'full'.
 *     @type int|bool $width   Default: false.
 *     @type int|bool $height  Default: false.
 *     @type bool     $id      Currently unused.
 *     @type bool     $no_grav Default: true.
 * }
 * @return string User avatar string.
 */
function bp_get_blog_avatar($args = '')
{
    global $blogs_template;
    // Bail if avatars are turned off
    // @todo Should we maybe still filter this?
    if (!buddypress()->avatar->show_avatars) {
        return false;
    }
    $author_displayname = bp_core_get_user_displayname($blogs_template->blog->admin_user_id);
    // Parse the arguments.
    $r = bp_parse_args($args, array('type' => 'full', 'width' => false, 'height' => false, 'class' => 'avatar', 'title' => sprintf(__('Profile picture of site author %s', 'buddypress'), esc_attr($author_displayname)), 'id' => false, 'alt' => sprintf(__('Profile picture of site author %s', 'buddypress'), esc_attr($author_displayname)), 'no_grav' => true));
    // Use site icon if available.
    $avatar = '';
    if (bp_is_active('blogs', 'site-icon') && function_exists('has_site_icon')) {
        $site_icon = bp_blogs_get_blogmeta(bp_get_blog_id(), "site_icon_url_{$r['type']}");
        // Never attempted to fetch site icon before; do it now!
        if ('' === $site_icon) {
            switch_to_blog(bp_get_blog_id());
            // Fetch the other size first.
            if ('full' === $r['type']) {
                $size = bp_core_avatar_thumb_width();
                $save_size = 'thumb';
            } else {
                $size = bp_core_avatar_full_width();
                $save_size = 'full';
            }
            $site_icon = get_site_icon_url($size);
            // Empty site icons get saved as integer 0.
            if (empty($site_icon)) {
                $site_icon = 0;
            }
            // Sync site icon for other size to blogmeta.
            bp_blogs_update_blogmeta(bp_get_blog_id(), "site_icon_url_{$save_size}", $site_icon);
            // Now, fetch the size we want.
            if (0 !== $site_icon) {
                $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width();
                $site_icon = get_site_icon_url($size);
            }
            // Sync site icon to blogmeta.
            bp_blogs_update_blogmeta(bp_get_blog_id(), "site_icon_url_{$r['type']}", $site_icon);
            restore_current_blog();
        }
        // We have a site icon.
        if (!is_numeric($site_icon)) {
            if (empty($r['width']) && !isset($size)) {
                $size = 'full' === $r['type'] ? bp_core_avatar_full_width() : bp_core_avatar_thumb_width();
            } else {
                $size = (int) $r['width'];
            }
            $avatar = sprintf('<img src="%1$s" class="%2$s" width="%3$s" height="%3$s" alt="%4$s" title="%4$s" />', esc_url($site_icon), esc_attr("{$r['class']} avatar-{$size}"), esc_attr($size), sprintf(esc_attr__('Site icon for %s', 'buddypress'), bp_get_blog_name()));
        }
    }
    // Fallback to user ID avatar.
    if ('' === $avatar) {
        $avatar = bp_core_fetch_avatar(array('item_id' => $blogs_template->blog->admin_user_id, 'title' => $r['title'], 'type' => $r['type'], 'alt' => $r['alt'], 'css_id' => $r['id'], 'class' => $r['class'], 'width' => $r['width'], 'height' => $r['height']));
    }
    /**
     * In future BuddyPress versions you will be able to set the avatar for a blog.
     * Right now you can use a filter with the ID of the blog to change it if you wish.
     * By default it will return the avatar for the primary blog admin.
     *
     * This filter is deprecated as of BuddyPress 1.5 and may be removed in a future version.
     * Use the 'bp_get_blog_avatar' filter instead.
     */
    $avatar = apply_filters('bp_get_blog_avatar_' . $blogs_template->blog->blog_id, $avatar);
    /**
     * Filters a blog's avatar.
     *
     * @since 1.5.0
     *
     * @param string $avatar  Formatted HTML <img> element, or raw avatar
     *                        URL based on $html arg.
     * @param int    $blog_id ID of the blog whose avatar is being displayed.
     * @param array  $r       Array of arguments used when fetching avatar.
     */
    return apply_filters('bp_get_blog_avatar', $avatar, $blogs_template->blog->blog_id, $r);
}
/**
 * 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 mixed $args
 * @return bool Success/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
    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 (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;
}
Example #12
0
/**
 * 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);
            }
        }
    }
    // 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 = 'coverphoto-full.' . $ext;
    $thumb_filename = 'coverphoto-thumb.' . $ext;
    // Crop the image
    $full_cropped = wp_crop_image($original_file, (int) $crop_x, (int) $crop_y, (int) $crop_w, (int) $crop_h, $coverphoto_thumb_width, $coverphoto_thumb_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, $coverphoto_thumb_full_width, $coverphoto_thumb_full_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;
}
Example #13
0
 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'];
 }
Example #14
0
			<?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 
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>    ';
        echo $html;
    } else {
        echo 'Error upload';
    }
    exit;
}
/**
 * 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
        $cover_dimensions = bp_attachments_get_cover_image_dimensions($cover_component);
        // Set warning messages
        $strings['cover_image_warnings'] = apply_filters('bp_attachments_cover_image_ui_warnings', array('dimensions' => sprintf(__('For better results, make sure to upload an image that is larger than %1$spx wide, and %2$spx tall.', 'buddypress'), (int) $cover_dimensions['width'], (int) $cover_dimensions['height'])));
    }
    // Set Plupload settings
    $settings['defaults'] = $defaults;
    /**
     * Enqueue some extra styles if required
     *
     * Extra styles need to be registered.
     */
    if (!empty($args['extra_css'])) {
        foreach ((array) $args['extra_css'] as $css) {
            if (empty($css)) {
                continue;
            }
            wp_enqueue_style($css);
        }
    }
    wp_enqueue_script('bp-plupload');
    wp_localize_script('bp-plupload', 'BP_Uploader', array('strings' => $strings, 'settings' => $settings));
    /**
     * Enqueue some extra scripts if required
     *
     * Extra scripts need to be registered.
     */
    if (!empty($args['extra_js'])) {
        foreach ((array) $args['extra_js'] as $js) {
            if (empty($js)) {
                continue;
            }
            wp_enqueue_script($js);
        }
    }
    /**
     * Fires at the conclusion of bp_attachments_enqueue_scripts()
     * to avoid the scripts to be loaded more than once.
     *
     * @since 2.3.0
     */
    do_action('bp_attachments_enqueue_scripts');
}
/**
 * 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 );
		}

		#buddypress #item-header-cover-image #item-header-avatar a {
			border: none;
			text-decoration: none;
		}

		#buddypress #item-header-cover-image #item-buttons {
			margin: 0 0 10px;
			padding: 0 0 5px;
		}

		#buddypress #item-header-cover-image #item-buttons:after {
			clear: both;
			content: "";
			display: table;
		}

		@media screen and (max-width: 782px) {
			#buddypress #item-header-cover-image #item-header-avatar,
			.bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
			#buddypress div#item-header #item-header-cover-image #item-header-content {
				width:100%;
				text-align:center;
			}

			#buddypress #item-header-cover-image #item-header-avatar a {
				display:inline-block;
			}

			#buddypress #item-header-cover-image #item-header-avatar img {
				margin:0;
			}

			#buddypress div#item-header #item-header-cover-image #item-header-content,
			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:0;
			}

			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 {
				max-width: 100%;
			}

			#buddypress div#item-header-cover-image h2 a,
			#buddypress div#item-header-cover-image h2 {
				color: inherit;
				text-shadow: none;
				margin:25px 0 0;
				font-size:200%;
			}

			#buddypress #item-header-cover-image #item-buttons div {
				float:none;
				display:inline-block;
			}

			#buddypress #item-header-cover-image #item-buttons:before {
				content:"";
			}

			#buddypress #item-header-cover-image #item-buttons {
				margin: 5px 0;
			}
		}
	';
}
Example #18
0
/**
 * Get the URL of the 'full' default avatar.
 *
 * @since BuddyPress (1.5.0)
 *
 * @param string $type 'local' if the fallback should be the locally-hosted
 *        version of the mystery-man, 'gravatar' if the fallback should be
 *        Gravatar's version. Default: 'gravatar'.
 * @return string The URL of the default avatar.
 */
function bp_core_avatar_default($type = 'gravatar')
{
    // Local override
    if (defined('BP_AVATAR_DEFAULT')) {
        $avatar = BP_AVATAR_DEFAULT;
        // Use the local default image
    } else {
        if ('local' === $type) {
            $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man.jpg';
            // Use Gravatar's mystery man as fallback
        } else {
            if (is_ssl()) {
                $host = 'https://secure.gravatar.com';
            } else {
                $host = 'http://www.gravatar.com';
            }
            $avatar = $host . '/avatar/00000000000000000000000000000000?d=mm&amp;s=' . bp_core_avatar_full_width();
        }
    }
    return apply_filters('bp_core_avatar_default', $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;
 }
Example #20
0
/**
 * Get the URL of the 'full' default avatar.
 *
 * @since 1.5.0
 *
 * @param string $type 'local' if the fallback should be the locally-hosted version
 *                     of the mystery-person, 'gravatar' if the fallback should be
 *                     Gravatar's version. Default: 'gravatar'.
 *
 * @return string The URL of the default avatar.
 */
function bp_core_avatar_default($type = 'gravatar')
{
    // Local override
    if (defined('BP_AVATAR_DEFAULT')) {
        $avatar = BP_AVATAR_DEFAULT;
        // Use the local default image
    } elseif ('local' === $type) {
        $avatar = buddypress()->plugin_url . 'bp-core/images/mystery-man.jpg';
        // Use Gravatar's mystery person as fallback
    } else {
        $avatar = '//www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&amp;s=' . bp_core_avatar_full_width();
    }
    /**
     * Filters the URL of the 'full' default avatar.
     *
     * @since 1.5.0
     *
     * @param string $avatar URL of the default avatar.
     */
    return apply_filters('bp_core_avatar_default', $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 {
         // No auto-crop, move on
         copy($filepath, "{$filepath}-bpfull.{$extension}");
         copy($filepath, "{$filepath}-bpthumb.{$extension}");
         @unlink($filepath);
         return true;
     }
     return false;
 }
/**
 * 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 
}
Example #23
0
						 
						  <ul id="members-list" class="item-list" role="main">
						 
						  <?php 
    while (bp_members()) {
        bp_the_member();
        ?>
						 
						    <li>
						      <div class="item-avatar">
						         <a href="<?php 
        bp_member_permalink();
        ?>
">
						         		<?php 
        bp_member_avatar('type=full&width=' . bp_core_avatar_full_width() . '&height=' . bp_core_avatar_full_height());
        ?>
						         </a>
						      </div>
						 
						      <div class="item">
						        <div class="item-title">
						           <a href="<?php 
        bp_member_permalink();
        ?>
"><?php 
        bp_member_name();
        ?>
</a>
						 
						       </div>