Services_Libravatar
[ class tree: Services_Libravatar ] [ index: Services_Libravatar ] [ all elements ]

Class: Services_Libravatar

Source Location: /Services_Libravatar-0.2.3/Services/Libravatar.php

Class Overview


PHP support for the Libravatar.org service.


Author(s):

Version:

  • Release: 0.2.3

Copyright:

  • 2011 Services_Libravatar committers.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 75]
PHP support for the Libravatar.org service.

Using this class is easy. After including or requiring Services/Libravatar.php simply do:

  1.  $libravatar = new Services_Libravatar();
  2.  $url $libravatar->getUrl('melissa@meldraweb.com');

This would populate $url with the string:

  1.  http://cdn.libravatar.org/avatar/4db84629c121f2d443d33bdb9fd149bc

A complicated lookup using all the options is:

  1.  $libravatar = new Services_Libravatar();
  2.  $libravatar->setSize(40);
  3.  $libravatar->setAlgorithm('sha256');
  4.  $libravatar->setHttps(true);
  5.  $libravatar->setDefault(
  6.      'http://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png'
  7.  );
  8.  $url $libravatar->getUrl('melissa@meldraweb.com');



[ Top ]


Class Variables

$algorithm =  'md5'

[line 84]

Hashing algorithm to use

Type:   string


[ Top ]

$default =

[line 93]

Default image URL to use

Type:   string


[ Top ]

$https =

[line 102]

If HTTPS URLs should be used

Type:   boolean


[ Top ]

$size =

[line 111]

Image size in pixels

Type:   integer


[ Top ]



Method Detail

checkOptionsArray   [line 223]

void checkOptionsArray( array $options)

Checks the options array and verify that only allowed options are in it.
  • Throws: Exception When an invalid option is used
  • Access: protected

Parameters:

array   $options   —  Array of options for getUrl()

[ Top ]

comparePriority   [line 492]

mixed comparePriority( mixed $a, mixed $b)

Sorting function for record priorities.
  • Return: The result of the comparison
  • Since: Method available since Release 0.1.0
  • Access: protected

Parameters:

mixed   $a   —  A mixed value passed by usort()
mixed   $b   —  A mixed value passed by usort()

[ Top ]

detectHttps   [line 506]

self detectHttps( )

Automatically set the https option depending on the current connection value.

If the current connection is HTTPS, the https options is activated. If it is not HTTPS, the https option is deactivated.

  • Access: public

[ Top ]

domainGet   [line 361]

string domainGet( string $identifier)

Grab the domain from the identifier.

Extract the domain from the Email or OpenID.

  • Return: A string of the domain to use
  • Since: Method available since Release 0.1.0
  • Access: protected

Parameters:

string   $identifier   —  A string of the email address or openid URL

[ Top ]

getUrl   [line 153]

string getUrl( string $identifier, [array $options = array()])

Composes a URL for the identifier and options passed in

Compose a full URL as specified by the Libravatar API, based on the email address or openid URL passed in, and the options specified.

  • Return: A string of a full URL for an avatar image
  • Since: Method available since Release 0.2.0
  • Throws: InvalidArgumentException When an invalid option is passed
  • Access: public

Parameters:

string   $identifier   —  a string of either an email address or an openid url
array   $options   —  an array of (bool) https, (string) algorithm (string) size, (string) default. See the set* methods.

[ Top ]

identifierHash   [line 284]

string identifierHash( string $identifier, [string $hash = 'md5'])

Create a hash of the identifier.

Create a hash of the email address or openid passed in. Algorithm used for email address ONLY can be varied. Either md5 or sha256 are supported by the Libravatar API. Will be ignored for openid.

  • Return: A string hash of the identifier.
  • Since: Method available since Release 0.1.0
  • Access: protected

Parameters:

string   $identifier   —  A string of the email address or openid URL
string   $hash   —  A string of the hash algorithm type to make Uses the php implementation of hash() MD5 preferred for Gravatar fallback

[ Top ]

normalizeIdentifier   [line 259]

string normalizeIdentifier( string $identifier)

Normalizes the identifier (E-mail address or OpenID)
  • Return: Normalized identifier
  • Access: protected

Parameters:

string   $identifier   —  E-Mail address or OpenID

[ Top ]

normalizeOpenId   [line 306]

string normalizeOpenId( mixed $identifier)

Normalizes an identifier (URI or XRI)
  • Return: Normalized Identifier. Empty string when the OpenID is invalid.
  • Access: public

Parameters:

mixed   $identifier   —  URI or XRI to be normalized

[ Top ]

processAlgorithm   [line 524]

string processAlgorithm( string $algorithm)

Verify and cast the email address hashing algorithm to use.
  • Return: Algorithm
  • Throws: InvalidArgumentException When an unsupported algorithm is given
  • Access: protected

Parameters:

string   $algorithm   —  Algorithm to use, "sha256" or "md5".

[ Top ]

processDefault   [line 552]

string processDefault( string $url)

Verify and cast the default URL to use when no avatar image can be found.

If none is set, the libravatar logo is returned.

  • Return: Default URL
  • Throws: InvalidArgumentException When an invalid URL is given
  • Access: protected

Parameters:

string   $url   —  Full URL to use OR one of the following:
  • "404" - give a "404 File not found" instead of an image
  • "mm"
  • "identicon"
  • "monsterid"
  • "wavatar"
  • "retro"

[ Top ]

processSize   [line 589]

integer processSize( integer $size)

Verify and cast the required size of the images.
  • Return: Size
  • Throws: InvalidArgumentException When a size <= 0 is given
  • Access: protected

Parameters:

integer   $size   —  Size (width and height in pixels) of the image. NULL for the default width.

[ Top ]

setAlgorithm   [line 613]

self setAlgorithm( string $algorithm)

Set the email address hashing algorithm to use.

To keep gravatar compatibility, use "md5".

  • Throws: InvalidArgumentException When an unsupported algorithm is given
  • Access: public

Parameters:

string   $algorithm   —  Algorithm to use, "sha256" or "md5".

[ Top ]

setDefault   [line 635]

self setDefault( string $url)

Set the default URL to use when no avatar image can be found.

If none is set, the gravatar logo is returned.

  • Throws: InvalidArgumentException When an invalid URL is given
  • Access: public

Parameters:

string   $url   —  Full URL to use OR one of the following:
  • "404" - give a "404 File not found" instead of an image
  • "mm"
  • "identicon"
  • "monsterid"
  • "wavatar"
  • "retro"

[ Top ]

setHttps   [line 651]

self setHttps( boolean $useHttps)

Set if HTTPS URLs shall be returned.

Parameters:

boolean   $useHttps   —  If HTTPS url shall be returned

[ Top ]

setSize   [line 667]

self setSize( integer $size)

Set the required size of the images.

Every avatar image is square sized, which means you need to set only number.

  • Throws: InvalidArgumentException When a size <= 0 is given
  • Access: public

Parameters:

integer   $size   —  Size (width and height) of the image

[ Top ]

srvGet   [line 407]

string srvGet( string $domain, [boolean $https = false])

Get the target to use.

Get the SRV record, filtered by priority and weight. If our domain has no SRV records, fall back to Libravatar.org

  • Return: The target URL.
  • Since: Method available since Release 0.1.0
  • Access: protected

Parameters:

string   $domain   —  A string of the domain we extracted from the provided identifier with domainGet()
boolean   $https   —  Whether or not to look for https records

[ Top ]

url   [line 131]

string url( string $identifier, [array $options = array()])

Composes a URL for the identifier and options passed in

Compose a full URL as specified by the Libravatar API, based on the email address or openid URL passed in, and the options specified.

  • Return: A string of a full URL for an avatar image
  • Deprecated: Use getUrl() instead
  • Since: Method available since Release 0.2.0
  • Access: public

Parameters:

string   $identifier   —  a string of either an email address or an openid url
array   $options   —  an array of (bool) https, (string) algorithm (string) size, (string) default. See the set* methods.

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:54:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.