AvatarSource
in package
Manages avatar sources and provides static methods for fetching avatars.
Tags
Table of Contents
Properties
- $_active_source : AvatarSourceBase
- $_sources : array<string|int, mixed>
Methods
- getActiveSource() : AvatarSourceBase
- Get the currently active avatar source.
- getAllPerspectives() : array<string, array<string|int, string>>
- Get key value array of all registered sources and their available perspectives.
- getAllSourceNames() : array<string, string>
- Get the names and base urls of all the registered avatar sources for displaying.
- getAllSources() : array<string|int, AvatarSourceBase>
- Get all registered sources.
- getAvatarFromUserData() : string
- Get a user's avatar from their raw data object.
- getAvatarFromUUID() : string
- Main usage of this class.
- getSourceByName() : AvatarSourceBase|null
- Find an avatar source instance by it's name.
- getUrlToFormat() : string
- Get raw url of active avatar source with placeholders.
- registerSource() : void
- Register avatar source.
- setActiveSource() : void
- Set the active source to the source by name.
- getDefaultPerspective() : string
- Get default perspective to pass to the active avatar source.
- validImageUrl() : bool
- Determine if a URL is a valid image URL for avatars.
Properties
$_active_source
protected
static AvatarSourceBase
$_active_source
$_sources
protected
static array<string|int, mixed>
$_sources
= []
Methods
getActiveSource()
Get the currently active avatar source.
public
static getActiveSource() : AvatarSourceBase
Return values
AvatarSourceBase —The active source.
getAllPerspectives()
Get key value array of all registered sources and their available perspectives.
public
static getAllPerspectives() : array<string, array<string|int, string>>
Used for autoupdating dropdown selector in staffcp.
Return values
array<string, array<string|int, string>> —Array of source => [] perspectives.
getAllSourceNames()
Get the names and base urls of all the registered avatar sources for displaying.
public
static getAllSourceNames() : array<string, string>
Used for showing list of sources in staffcp.
Return values
array<string, string> —List of names.
getAllSources()
Get all registered sources.
public
static getAllSources() : array<string|int, AvatarSourceBase>
Return values
array<string|int, AvatarSourceBase>getAvatarFromUserData()
Get a user's avatar from their raw data object.
public
static getAvatarFromUserData(object $data[, bool $allow_gifs = false ][, int $size = 128 ][, bool $full = false ]) : string
Used by the API for TinyMCE mention avatars to avoid reloading the user from the database.
Parameters
- $data : object
-
User data to use
- $allow_gifs : bool = false
-
Whether to allow GIFs or not ()
- $size : int = 128
-
Size in pixels to render avatar at. Default 128
- $full : bool = false
-
Whether to return the full URL or just the path
Return values
string —Full URL of avatar image.
getAvatarFromUUID()
Main usage of this class.
public
static getAvatarFromUUID(string $uuid[, int $size = 128 ]) : string
Uses active avatar source to get the URL of their Minecraft avatar.
Parameters
- $uuid : string
-
UUID of avatar to get.
- $size : int = 128
-
Size in pixels to render avatar at. Default 128
Return values
string —Compiled URL of avatar image.
getSourceByName()
Find an avatar source instance by it's name.
public
static getSourceByName(string $name) : AvatarSourceBase|null
Parameters
- $name : string
Return values
AvatarSourceBase|null —Instance if found, null if not found.
getUrlToFormat()
Get raw url of active avatar source with placeholders.
public
static getUrlToFormat() : string
Return values
string —URL with placeholders.
registerSource()
Register avatar source.
public
static registerSource(AvatarSourceBase $source) : void
Parameters
- $source : AvatarSourceBase
-
Instance of avatar source to register.
setActiveSource()
Set the active source to the source by name.
public
static setActiveSource(string $name) : void
Fallsback to Cravatar if name was not found.
Parameters
- $name : string
-
Name of source to set as active.
getDefaultPerspective()
Get default perspective to pass to the active avatar source.
private
static getDefaultPerspective() : string
Return values
string —Perspective.
validImageUrl()
Determine if a URL is a valid image URL for avatars.
private
static validImageUrl(string $url) : bool
Parameters
- $url : string
-
URL to check
Return values
bool —Whether the URL is a valid image URL