/**
 * Check if the given user has an uploaded avatar
 * @return boolean
 */
function userpro_user_has_avatar($user_id = false)
{
    // $user_id = bp_loggedin_user_id();
    if (bp_core_fetch_avatar(array('item_id' => $user_id, 'no_grav' => true, 'html' => false)) != bp_core_avatar_default()) {
        return true;
    }
    return false;
}
function bp_get_group_has_avatar($group_id = false)
{
    global $bp;
    if (false === $group_id) {
        $group_id = bp_get_current_group_id();
    }
    // Todo - this looks like an overgeneral check
    if (!empty($_FILES)) {
        return false;
    }
    $group_avatar = bp_core_fetch_avatar(array('item_id' => $group_id, 'object' => 'group', 'no_grav' => true, 'html' => false));
    if (bp_core_avatar_default('local') === $group_avatar) {
        return false;
    }
    return true;
}
/**
 * Check if a given user ID has an uploaded avatar.
 *
 * @since 1.0.0
 *
 * @param int $user_id ID of the user whose avatar is being checked.
 *
 * @return bool True if the user has uploaded a local avatar. Otherwise false.
 */
function bp_get_user_has_avatar($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = bp_displayed_user_id();
    }
    $retval = false;
    if (bp_core_fetch_avatar(array('item_id' => $user_id, 'no_grav' => true, 'html' => false)) != bp_core_avatar_default('local')) {
        $retval = true;
    }
    /**
     * Filters whether or not a user has an uploaded avatar.
     *
     * @since 1.6.0
     *
     * @param bool $retval  Whether or not a user has an uploaded avatar.
     * @param int  $user_id ID of the user being checked.
     */
    return (bool) apply_filters('bp_get_user_has_avatar', $retval, $user_id);
}
/**
 * Return whether a group has an avatar.
 *
 * @since 1.1.0
 *
 * @param int|bool $group_id Group ID to check.
 * @return boolean
 */
function bp_get_group_has_avatar($group_id = false)
{
    if (false === $group_id) {
        $group_id = bp_get_current_group_id();
    }
    $group_avatar = bp_core_fetch_avatar(array('item_id' => $group_id, 'object' => 'group', 'no_grav' => true, 'html' => false));
    if (bp_core_avatar_default('local') === $group_avatar) {
        return false;
    }
    return true;
}
Beispiel #5
0
/**
 * Check if a given user ID has an uploaded avatar.
 *
 * @since BuddyPress (1.0.0)
 *
 * @param int $user_id ID of the user whose avatar is being checked.
 * @return bool True if the user has uploaded a local avatar. Otherwise false.
 */
function bp_get_user_has_avatar($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = bp_displayed_user_id();
    }
    $retval = false;
    if (bp_core_fetch_avatar(array('item_id' => $user_id, 'no_grav' => true, 'html' => false)) != bp_core_avatar_default('local')) {
        $retval = true;
    }
    return (bool) apply_filters('bp_get_user_has_avatar', $retval, $user_id);
}
function rtmedia_author_profile_pic($show_link = true, $echo = true, $author_id = false)
{
    global $rtmedia_backbone;
    if ($rtmedia_backbone['backbone']) {
        echo '';
    } else {
        if (!$author_id || $author_id == "") {
            global $rtmedia_media;
            $author_id = $rtmedia_media->media_author;
        }
        $show_link = apply_filters("rtmedia_single_media_show_profile_picture_link", $show_link);
        $profile_pic = "";
        if ($show_link) {
            $profile_pic .= "<a href='" . get_rtmedia_user_link($author_id) . "' title='" . rtmedia_get_author_name($author_id) . "'>";
        }
        $size = apply_filters("rtmedia_single_media_profile_picture_size", 90);
        if (function_exists("bp_get_user_has_avatar")) {
            if (bp_core_fetch_avatar(array('item_id' => $author_id, 'object' => 'user', 'no_grav' => false, 'html' => false)) != bp_core_avatar_default()) {
                $profile_pic .= bp_core_fetch_avatar(array('item_id' => $author_id, 'object' => 'user', 'no_grav' => false, 'html' => true, 'width' => $size, 'height' => $size));
            } else {
                $profile_pic .= "<img src='" . bp_core_avatar_default() . "' width='" . $size . "'  height='" . $size . "'/>";
            }
        } else {
            $profile_pic .= get_avatar($author_id, $size);
        }
        if ($show_link) {
            $profile_pic .= "</a>";
        }
        if ($echo) {
            echo $profile_pic;
        } else {
            return $profile_pic;
        }
    }
}
 /**
  * Filters a locally uploaded avatar URL.
  *
  * @since BuddyPress (1.2.5)
  *
  * @param string $avatar_url URL for a locally uploaded avatar.
  * @param array $params Array of parameters for the request.
  *
  * @return string|void
  */
 public function bp_core_fetch_avatar_url($avatar_url, $params)
 {
     $bp = buddypress();
     // If avatars are disabled for the root site, obey that request and bail
     if (!$bp->avatar->show_avatars) {
         return;
     }
     // only for users
     if ($params['object'] != 'user') {
         return;
     }
     $fb_id = get_user_meta($params['item_id'], '_fb_user_id', true);
     if (empty($fb_id)) {
         return $avatar_url;
     }
     // If is not gravatar it's local. And if it's local but the not the default one it means it's one uploaded by user
     // so we show that one.
     if (!empty($avatar_url)) {
         $gravatar = apply_filters('bp_gravatar_url', '//www.gravatar.com/avatar/');
         if (strpos($avatar_url, $gravatar) === false && $avatar_url != bp_core_avatar_default('local')) {
             return $avatar_url;
         }
     }
     return 'https://graph.facebook.com/' . $fb_id . '/picture?width=' . $params['width'] . '&height=' . $params['height'];
 }
Beispiel #8
0
 public function bp_core_fetch_avatar_filter_check($html, $params)
 {
     // Check that the passed parameters match the original custom parameters.
     $this->assertEmpty(array_merge(array_diff($params, $this->params), array_diff($this->params, $params)));
     // Check the returned html to see that it matches an expected value.
     // Get the correct default avatar, based on whether gravatars are allowed.
     if ($params['no_grav']) {
         $avatar_url = bp_core_avatar_default('local');
     } else {
         // This test has the slight odor of hokum since it recreates so much code that could be changed at any time.
         $bp = buddypress();
         $host = '//www.gravatar.com/avatar/';
         // Set expected gravatar type
         if (empty($bp->grav_default->{$this->params['object']})) {
             $default_grav = 'wavatar';
         } elseif ('mystery' == $bp->grav_default->{$this->params['object']}) {
             $default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $this->params['width']);
         } else {
             $default_grav = $bp->grav_default->{$this->params['object']};
         }
         $avatar_url = $host . md5(strtolower($this->params['email'])) . '?d=' . $default_grav . '&amp;s=' . $this->params['width'];
         // Gravatar rating; http://bit.ly/89QxZA
         $rating = get_option('avatar_rating');
         if (!empty($rating)) {
             $avatar_url .= "&amp;r={$rating}";
         }
     }
     $expected_html = '<img src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" />';
     $this->assertEquals($html, $expected_html);
 }
Beispiel #9
0
/**
 * bp_core_fetch_avatar()
 *
 * Fetches an avatar from a BuddyPress object. Supports user/group/blog as
 * default, but can be extended to include your own custom components too.
 *
 * @global object $bp Global BuddyPress settings object
 * @global $current_blog NXTClass global containing information and settings for the current blog being viewed.
 * @param array $args Determine the output of this function
 * @return string Formatted HTML <img> element, or raw avatar URL based on $html arg
 */
function bp_core_fetch_avatar($args = '')
{
    global $bp, $current_blog;
    // Set a few default variables
    $def_object = 'user';
    $def_type = 'thumb';
    $def_class = 'avatar';
    $def_alt = __('Avatar Image', 'buddypress');
    // Set the default variables array
    $defaults = array('item_id' => false, 'object' => $def_object, 'type' => $def_type, 'avatar_dir' => false, 'width' => false, 'height' => false, 'class' => $def_class, 'css_id' => false, 'alt' => $def_alt, 'email' => false, 'no_grav' => false, 'html' => true, 'title' => '');
    // Compare defaults to passed and extract
    $params = nxt_parse_args($args, $defaults);
    extract($params, EXTR_SKIP);
    // Set item_id if not passed
    if (!$item_id) {
        if ('user' == $object) {
            $item_id = $bp->displayed_user->id;
        } else {
            if (bp_is_active('groups') && 'group' == $object) {
                $item_id = $bp->groups->current_group->id;
            } else {
                if ('blog' == $object) {
                    $item_id = $current_blog->id;
                }
            }
        }
        $item_id = apply_filters('bp_core_avatar_item_id', $item_id, $object);
        if (!$item_id) {
            return false;
        }
    }
    // Set avatar_dir if not passed (uses $object)
    if (!$avatar_dir) {
        if ('user' == $object) {
            $avatar_dir = 'avatars';
        } else {
            if (bp_is_active('groups') && 'group' == $object) {
                $avatar_dir = 'group-avatars';
            } else {
                if ('blog' == $object) {
                    $avatar_dir = 'blog-avatars';
                }
            }
        }
        $avatar_dir = apply_filters('bp_core_avatar_dir', $avatar_dir, $object);
        if (!$avatar_dir) {
            return false;
        }
    }
    // Add an identifying class to each item
    $class .= ' ' . $object . '-' . $item_id . '-avatar';
    // Get item name for alt/title tags
    $item_name = '';
    if ('user' == $object) {
        $item_name = bp_core_get_user_displayname($item_id);
    } elseif ('group' == $object) {
        $item_name = bp_get_group_name(new BP_Groups_Group($item_id));
    } elseif ('blog' == $object) {
        $item_name = get_blog_option($item_id, 'blogname');
    }
    $alt = sprintf($alt, apply_filters('bp_core_avatar_alt', $item_name, $item_id, $object));
    // Set title tag
    if ($title) {
        $title = " title='" . esc_attr(apply_filters('bp_core_avatar_title', $title, $item_id, $object)) . "'";
    } elseif ($item_name) {
        $title = " title='" . esc_attr(apply_filters('bp_core_avatar_title', $item_name, $item_id, $object)) . "'";
    }
    // Set CSS ID if passed
    if (!empty($css_id)) {
        $css_id = " id='{$css_id}'";
    }
    // Set avatar width
    if ($width) {
        $html_width = " width='{$width}'";
    } else {
        $html_width = 'thumb' == $type ? ' width="' . bp_core_avatar_thumb_width() . '"' : ' width="' . bp_core_avatar_full_width() . '"';
    }
    // Set avatar height
    if ($height) {
        $html_height = " height='{$height}'";
    } else {
        $html_height = 'thumb' == $type ? ' height="' . bp_core_avatar_thumb_height() . '"' : ' height="' . bp_core_avatar_full_height() . '"';
    }
    // Set avatar URL and DIR based on prepopulated constants
    $avatar_folder_url = apply_filters('bp_core_avatar_folder_url', bp_core_avatar_url() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $avatar_dir);
    $avatar_folder_dir = apply_filters('bp_core_avatar_folder_dir', bp_core_avatar_upload_path() . '/' . $avatar_dir . '/' . $item_id, $item_id, $object, $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' == $type ? '-bpfull' : '-bpthumb';
    $legacy_user_avatar_name = 'full' == $type ? '-avatar2' : '-avatar1';
    $legacy_group_avatar_name = 'full' == $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)) {
            // Return it wrapped in an <img> element
            if (true === $html) {
                return apply_filters('bp_core_fetch_avatar', '<img src="' . $avatar_url . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
                // ...or only the URL
            } else {
                return apply_filters('bp_core_fetch_avatar_url', $avatar_url);
            }
        }
    }
    // If no avatars could be found, try to display a gravatar
    // Skips gravatar check if $no_grav is passed
    if (!apply_filters('bp_core_fetch_avatar_no_grav', $no_grav)) {
        // Set gravatar size
        if ($width) {
            $grav_size = $width;
        } else {
            if ('full' == $type) {
                $grav_size = bp_core_avatar_full_width();
            } else {
                if ('thumb' == $type) {
                    $grav_size = bp_core_avatar_thumb_width();
                }
            }
        }
        // Set gravatar type
        if (empty($bp->grav_default->{$object})) {
            $default_grav = 'wavatar';
        } else {
            if ('mystery' == $bp->grav_default->{$object}) {
                $default_grav = apply_filters('bp_core_mysteryman_src', bp_core_avatar_default(), $grav_size);
            } else {
                $default_grav = $bp->grav_default->{$object};
            }
        }
        // Set gravatar object
        if (empty($email)) {
            if ('user' == $object) {
                $email = bp_core_get_user_email($item_id);
            } else {
                if ('group' == $object || 'blog' == $object) {
                    $email = "{$item_id}-{$object}@{bp_get_root_domain()}";
                }
            }
        }
        // Set host based on if using ssl
        if (is_ssl()) {
            $host = 'https://secure.gravatar.com/avatar/';
        } else {
            $host = 'http://www.gravatar.com/avatar/';
        }
        // Filter gravatar vars
        $email = apply_filters('bp_core_gravatar_email', $email, $item_id, $object);
        $gravatar = apply_filters('bp_gravatar_url', $host) . md5(strtolower($email)) . '?d=' . $default_grav . '&amp;s=' . $grav_size;
    } else {
        // No avatar was found, and we've been told not to use a gravatar.
        $gravatar = apply_filters("bp_core_default_avatar_{$object}", BP_PLUGIN_URL . '/bp-core/images/mystery-man.jpg', $params);
    }
    if (true === $html) {
        return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '" alt="' . esc_attr($alt) . '" class="' . esc_attr($class) . '"' . $css_id . $html_width . $html_height . $title . ' />', $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
    } else {
        return apply_filters('bp_core_fetch_avatar_url', $gravatar);
    }
}
 public function bp_core_fetch_avatar_filter_check($html, $params)
 {
     // Check that the passed parameters match the original custom parameters.
     $this->assertEmpty(array_merge(array_diff($params, $this->params), array_diff($this->params, $params)));
     // Check the returned html to see that it matches an expected value.
     // Get the correct default avatar, based on whether gravatars are allowed.
     if ($params['no_grav']) {
         $avatar_url = bp_core_avatar_default('local', $params);
     } else {
         // This test has the slight odor of hokum since it recreates so much code that could be changed at any time.
         $bp = buddypress();
         $host = '//www.gravatar.com/avatar/';
         // Set expected gravatar type
         if (empty($bp->grav_default->{$this->params['object']})) {
             $default_grav = 'wavatar';
         } elseif ('mystery' == $bp->grav_default->{$this->params['object']}) {
             $default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $this->params['width']);
         } else {
             $default_grav = $bp->grav_default->{$this->params['object']};
         }
         $avatar_url = $host . md5(strtolower($this->params['email']));
         // Main Gravatar URL args.
         $url_args = array('s' => $this->params['width']);
         // Force default.
         if (!empty($this->params['force_default'])) {
             $url_args['f'] = 'y';
         }
         // Gravatar rating; http://bit.ly/89QxZA
         $rating = strtolower(get_option('avatar_rating'));
         if (!empty($rating)) {
             $url_args['r'] = $rating;
         }
         // Default avatar.
         if ('gravatar_default' !== $default_grav) {
             $url_args['d'] = $default_grav;
         }
         // Set up the Gravatar URL.
         $avatar_url = esc_url(add_query_arg(rawurlencode_deep(array_filter($url_args)), $avatar_url));
     }
     $expected_html = '<img src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" ' . $this->params['extra_attr'] . ' />';
     $this->assertEquals($html, $expected_html);
 }
/**
 * Hook to display custom avatars
 */
function oa_social_login_custom_avatar($avatar, $mixed, $size, $default, $alt = '')
{
    //The social login settings
    static $oa_social_login_avatars = null;
    if (is_null($oa_social_login_avatars)) {
        $oa_social_login_settings = get_option('oa_social_login_settings');
        $oa_social_login_avatars = isset($oa_social_login_settings['plugin_show_avatars_in_comments']) ? $oa_social_login_settings['plugin_show_avatars_in_comments'] : 0;
    }
    //Check if social avatars are enabled
    if (!empty($oa_social_login_avatars)) {
        //Check if we have an user identifier
        if (is_numeric($mixed) and $mixed > 0) {
            $user_id = $mixed;
        } elseif (is_string($mixed) and $user = get_user_by('email', $mixed)) {
            $user_id = $user->ID;
        } elseif (is_object($mixed) and property_exists($mixed, 'user_id') and is_numeric($mixed->user_id)) {
            $user_id = $mixed->user_id;
        } else {
            $user_id = null;
        }
        //User found?
        if (!empty($user_id)) {
            //Override current avatar ?
            $override_avatar = true;
            //BuddyPress (Thumbnails in the default WordPress toolbar)
            if (function_exists('bp_core_fetch_avatar') and function_exists('bp_core_avatar_default')) {
                //Fetch the BuddyPress user avatar
                $bp_user_avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'no_grav' => true, 'html' => false));
                //Do not override if it's not the default avatar
                if (!empty($bp_user_avatar) and $bp_user_avatar != bp_core_avatar_default()) {
                    //User has probably upladed an avatar
                    $override_avatar = false;
                }
            }
            //Show avatar?
            if ($override_avatar) {
                //Read the avatar
                $user_meta_thumbnail = get_user_meta($user_id, 'oa_social_login_user_thumbnail', true);
                $user_meta_picture = get_user_meta($user_id, 'oa_social_login_user_picture', true);
                //Use the picture if possible
                if ($oa_social_login_avatars == 2) {
                    $user_picture = !empty($user_meta_picture) ? $user_meta_picture : $user_meta_thumbnail;
                } else {
                    $user_picture = !empty($user_meta_thumbnail) ? $user_meta_thumbnail : $user_meta_picture;
                }
                //Avatar found?
                if ($user_picture !== false and strlen(trim($user_picture)) > 0) {
                    return '<img alt="' . oa_social_login_esc_attr($alt) . '" src="' . $user_picture . '" class="avatar avatar-social-login avatar-' . $size . ' photo" height="' . $size . '" width="' . $size . '" />';
                }
            }
        }
    }
    //Default
    return $avatar;
}
Beispiel #12
0
/**
 * Media author's profile pic
 *
 * @global      array       $rtmedia_backbone
 * @global      object      $rtmedia_media
 *
 * @param       bool        $show_link
 * @param       bool        $echo
 * @param       bool        $author_id
 *
 * @return      string
 */
function rtmedia_author_profile_pic($show_link = true, $echo = true, $author_id = false)
{
    global $rtmedia_backbone;
    if ($rtmedia_backbone['backbone']) {
        echo '';
    } else {
        if (empty($author_id)) {
            global $rtmedia_media;
            $author_id = $rtmedia_media->media_author;
        }
        $show_link = apply_filters('rtmedia_single_media_show_profile_picture_link', $show_link);
        $profile_pic = '';
        if ($show_link) {
            $profile_pic .= "<a href='" . esc_url(get_rtmedia_user_link($author_id)) . "' title='" . esc_attr(rtmedia_get_author_name($author_id)) . "'>";
        }
        $size = apply_filters('rtmedia_single_media_profile_picture_size', 90);
        if (function_exists('bp_get_user_has_avatar')) {
            if (bp_core_fetch_avatar(array('item_id' => $author_id, 'object' => 'user', 'no_grav' => false, 'html' => false)) !== bp_core_avatar_default()) {
                $profile_pic .= bp_core_fetch_avatar(array('item_id' => $author_id, 'object' => 'user', 'no_grav' => false, 'html' => true, 'width' => $size, 'height' => $size));
            } else {
                $profile_pic .= "<img src='" . esc_url(bp_core_avatar_default()) . "' width='" . esc_attr($size) . "'  height='" . esc_attr($size) . "' />";
            }
        } else {
            $profile_pic .= get_avatar($author_id, $size);
        }
        if ($show_link) {
            $profile_pic .= '</a>';
        }
        if ($echo) {
            echo $profile_pic;
            // @codingStandardsIgnoreLine
        } else {
            return $profile_pic;
        }
    }
    // End if().
}