Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes

Robo47_Service_Gravatar Class Reference

List of all members.

Public Member Functions

 __construct (array $options=array())
 _getCacheId ($email)
 Get CacheId.
 getCache ()
 Get Cache.
 getCacheId ($email, $cachePrefix=null, $rating=null, $size=null, $default=null)
 Get CacheId.
 getCachePrefix ()
 Get CachePrefix.
 getDefault ()
 Returns the default.
 getGravatarHash ($email)
 Get Gravatar Hash.
 getRating ()
 Get Rating.
 getSize ()
 Returns the size.
 getUri ($email, $size=null, $rating=null, $default=null, $ssl=null, $separator= '&')
 Get Uri.
 gravatarExists ($email, $cached=true)
 Checks if a gravatar exists for the email using default=404.
 setCache ($cache=null)
 Set the used Cache.
 setCachePrefix ($cachePrefix)
 Set CachePrefix.
 setDefault ($default)
 Sets the default.
 setOptions (array $options=array())
 Set options.
 setRating ($rating)
 Set Rating.
 setSize ($size)
 Set Size.
 useSSL ($flag)
 Whether to use SSL or not.
 usesSSL ()
 If SSL is used.

Public Attributes

const API_SSL_URL = 'https://secure.gravatar.com/avatar/'
 GRAVATAR API SSL URL.
const API_URL = 'http://www.gravatar.com/avatar/'
 GRAVATAR API URL.
const DEFAULT_404 = '404'
 GRAVATAR Default 404.
const DEFAULT_IDENTICON = 'identicon'
 GRAVATAR Default Identicon http://en.wikipedia.org/wiki/Identicon.
const DEFAULT_MONSTERID = 'monsterid'
 GRAVATAR Default Monsterid http://www.splitbrain.org/projects/monsterid.
const DEFAULT_WAVATAR = 'wavatar'
 GRAVATAR Default Wavatar http://www.shamusyoung.com/twentysidedtale/?p=1462.
const RATING_G = 'g'
 GRAVATAR Rating G - General Audiences.
const RATING_PG = 'pg'
 GRAVATAR Rating PG - Parental Guidance Suggested.
const RATING_R = 'r'
 GRAVATAR Rating R - Restricted.
const RATING_X = 'x'
 GRAVATAR Rating X.

Protected Member Functions

 _cacheFromRegistry ($key)
 Get tidy from Registry if found.
 _filterCachePrefix ($cachePrefix)
 Filters cachePrefix.
 _filterDefault ($default)
 Filters the default.
 _filterRating ($rating)
 Filters the rating.
 _filterSize ($size)
 Filters the size.
 _filterSsl ($ssl)
 Filters ssl.
 _getUri ($email, $size, $rating, $default, $ssl, $separator)

Protected Attributes

 $_cache = null
 $_cachePrefix = 'gravatar_'
 $_default = ''
 $_rating = 'g'
 $_size = 80
 $_useSSL = false

Detailed Description

Definition at line 32 of file Gravatar.php.


Constructor & Destructor Documentation

Robo47_Service_Gravatar::__construct ( array $  options = array()  ) 
Parameters:
array $options

Definition at line 142 of file Gravatar.php.

References setOptions().

    {
        $this->setOptions($options);
    }

Here is the call graph for this function:


Member Function Documentation

Robo47_Service_Gravatar::_cacheFromRegistry ( key  )  [protected]

Get tidy from Registry if found.

Exceptions:
Robo47_Filter_Exception 
Parameters:
string $key
Returns:
mixed

Definition at line 231 of file Gravatar.php.

Referenced by setCache().

    {
        if (Zend_Registry::isRegistered($key)) {
            return Zend_Registry::get($key);
        } else {
            $message = 'Registry key "' . $key .
                '" for Cache is not registered.';
            throw new Robo47_Service_Gravatar_Exception($message);
        }
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::_filterCachePrefix ( cachePrefix  )  [protected]

Filters cachePrefix.

With Fallback for null to internal value

Parameters:
string|null $cachePrefix
Returns:
string

Definition at line 447 of file Gravatar.php.

References getCachePrefix().

Referenced by getCacheId().

    {
        if (null === $cachePrefix) {
            return $this->getCachePrefix();
        } else {
            return (string) $cachePrefix;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_filterDefault ( default  )  [protected]

Filters the default.

With Fallback for null to internal value

Parameters:
string|null $default
Returns:
string

Definition at line 413 of file Gravatar.php.

References getDefault().

Referenced by getCacheId(), and getUri().

    {
        if (null === $default) {
            return $this->getDefault();
        } else {
            return (string) $default;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_filterRating ( rating  )  [protected]

Filters the rating.

With Fallback for null to internal value

Parameters:
string|null $rating
Returns:
string

Definition at line 390 of file Gravatar.php.

References getRating().

Referenced by getCacheId(), and getUri().

    {
        $rating = strtolower($rating);
        switch ($rating) {
            case self::RATING_G:
            case self::RATING_PG:
            case self::RATING_R:
            case self::RATING_X:
                return $rating;
                break;
            default:
                return $this->getRating();
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_filterSize ( size  )  [protected]

Filters the size.

With Fallback for null to internal value

Parameters:
integer|null $size
Returns:
integer

Definition at line 373 of file Gravatar.php.

References getSize().

Referenced by getCacheId(), and getUri().

    {
        if (null === $size) {
            return $this->getSize();
        } else {
            return (int) $size;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_filterSsl ( ssl  )  [protected]

Filters ssl.

With Fallback for null to internal value

Parameters:
bool|null $ssl
Returns:
bool

Definition at line 430 of file Gravatar.php.

References usesSSL().

Referenced by getUri().

    {
        if (null === $ssl) {
            return $this->usesSSL();
        } else {
            return (bool) $ssl;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_getCacheId ( email  ) 

Get CacheId.

Parameters:
string $email
Returns:
string

Definition at line 557 of file Gravatar.php.

References getCacheId(), getCachePrefix(), getDefault(), getRating(), and getSize().

Referenced by gravatarExists().

    {
        return $this->getCacheId(
            $email,
            $this->getCachePrefix(),
            $this->getRating(),
            $this->getSize(),
            $this->getDefault()
        );
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::_getUri ( email,
size,
rating,
default,
ssl,
separator 
) [protected]
Parameters:
string $email
integer $size
string $rating
string $default
bool $ssl
string $separator
Returns:
string

Definition at line 495 of file Gravatar.php.

References API_SSL_URL, API_URL, and getGravatarHash().

Referenced by getUri().

    {
        if ($ssl) {
            $url = Robo47_Service_Gravatar::API_SSL_URL;
        } else {
            $url = Robo47_Service_Gravatar::API_URL;
        }

        $url .= $this->getGravatarHash($email);

        $params = array(
            's' => $size,
            'r' => $rating,
            'd' => $default,
        );
        return $url . '?' . http_build_query($params, '', $separator);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::getCache (  ) 

Get Cache.

Returns:
Zend_Cache_Core

Definition at line 247 of file Gravatar.php.

    {
        return $this->_cache;
    }

Robo47_Service_Gravatar::getCacheId ( email,
cachePrefix = null,
rating = null,
size = null,
default = null 
)

Get CacheId.

Parameters:
string $email
string $prefix
string $rating
integer $size
string $default
Returns:
string

Definition at line 535 of file Gravatar.php.

References _filterCachePrefix(), _filterDefault(), _filterRating(), _filterSize(), and getGravatarHash().

Referenced by _getCacheId().

    {
        $cachePrefix = $this->_filterCachePrefix($cachePrefix);
        $size = $this->_filterSize($size);
        $rating = $this->_filterRating($rating);
        $default = $this->_filterDefault($default);

        $id = $cachePrefix;
        $id .= $this->getGravatarHash($email);
        $id .= '_' . $rating;
        $id .= '_' . $size;
        $id .= '_' . md5($default);
        return $id;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::getCachePrefix (  ) 

Get CachePrefix.

Returns:
string

Definition at line 269 of file Gravatar.php.

Referenced by _filterCachePrefix(), and _getCacheId().

    {
        return $this->_cachePrefix;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::getDefault (  ) 

Returns the default.

Returns:
string

Definition at line 360 of file Gravatar.php.

Referenced by _filterDefault(), and _getCacheId().

    {
        return $this->_default;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::getGravatarHash ( email  ) 

Get Gravatar Hash.

Parameters:
string $email
Returns:
string

Definition at line 520 of file Gravatar.php.

Referenced by _getUri(), and getCacheId().

    {
        return md5(strtolower(trim($email)));
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::getRating (  ) 

Get Rating.

Returns:
string

Definition at line 302 of file Gravatar.php.

Referenced by _filterRating(), and _getCacheId().

    {
        return $this->_rating;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::getSize (  ) 

Returns the size.

Returns:
integer

Definition at line 333 of file Gravatar.php.

Referenced by _filterSize(), and _getCacheId().

    {
        return $this->_size;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::getUri ( email,
size = null,
rating = null,
default = null,
ssl = null,
separator = '&' 
)

Get Uri.

Parameters:
string $email
integer $size
string $rating
string $default
bool $ssl
string $separator
Returns:
string

Definition at line 467 of file Gravatar.php.

References _filterDefault(), _filterRating(), _filterSize(), _filterSsl(), and _getUri().

Referenced by gravatarExists().

    {
        $size = $this->_filterSize($size);
        $rating = $this->_filterRating($rating);
        $default = $this->_filterDefault($default);
        $ssl = $this->_filterSsl($ssl);

        return $this->_getUri(
            $email,
            $size,
            $rating,
            $default,
            $ssl,
            $separator
        );
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::gravatarExists ( email,
cached = true 
)

Checks if a gravatar exists for the email using default=404.

Parameters:
string $email
bool $cached whether to use cache or not
Returns:
boolean

Definition at line 575 of file Gravatar.php.

References _getCacheId(), and getUri().

    {
        $cacheId = $this->_getCacheId($email);
        if (null !== $this->_cache && $cached) {
            $successful = $this->_cache->load($cacheId);
            if ('true' === $successful) {
                return true;
            } elseif ('false' === $successful) {
                return false;
            }
        }
        $httpClient = self::getHttpClient();

        $uri = $this->getUri($email, null, null, null, null, '&');
        $httpClient->setUri($uri);

        $response = $httpClient->request(Zend_Http_Client::GET);
        $success = false;
        if (200 == $response->getStatus()) {
            $success = true;
        }
        if (null !== $this->_cache) {
            if ($success) {
                $this->_cache->save('true', $cacheId);
            } else {
                $this->_cache->save('false', $cacheId);
            }
        }
        return $success;
    }

Here is the call graph for this function:

Robo47_Service_Gravatar::setCache ( cache = null  ) 

Set the used Cache.

Parameters:
Zend_Cache_Core|string|null $cache
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 210 of file Gravatar.php.

References _cacheFromRegistry().

Referenced by setOptions().

    {
        if (is_string($cache)) {
            $cache = $this->_cacheFromRegistry($cache);
        }
        if (!$cache instanceof Zend_Cache_Core &&
            null !== $cache) {
            $message = 'cache is not instance of Zend_Cache_Core';
            throw new Robo47_Service_Gravatar_Exception($message);
        }
        $this->_cache = $cache;
        return $this;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::setCachePrefix ( cachePrefix  ) 

Set CachePrefix.

Parameters:
string $cachePrefix
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 258 of file Gravatar.php.

Referenced by setOptions().

    {
        $this->_cachePrefix = $cachePrefix;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::setDefault ( default  ) 

Sets the default.

Default can be an url of a image which is used if no gravatar found or one of the Robo47_Service_Gravatar::DEFAULT_*-Constants for alternate generated images (identicon, monsterid, wavatar) or a 404-header as answeder

Parameters:
string $default
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 349 of file Gravatar.php.

Referenced by setOptions().

    {
        $this->_default = $default;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::setOptions ( array $  options = array()  ) 

Set options.

Parameters:
array $options
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 153 of file Gravatar.php.

References setCache(), setCachePrefix(), setDefault(), setRating(), setSize(), and useSSL().

Referenced by __construct().

    {
        foreach ($options as $key => $value) {
            switch ($key) {
                case 'rating':
                    $this->setRating($value);
                    break;
                case 'default':
                    $this->setDefault($value);
                    break;
                case 'cache':
                    $this->setCache($value);
                    break;
                case 'cachePrefix':
                    $this->setCachePrefix($value);
                    break;
                case 'size':
                    $this->setSize($value);
                    break;
                case 'useSSL':
                    $this->useSSL($value);
                    break;
                default:
                    break;
            }
        }
        return $this;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Robo47_Service_Gravatar::setRating ( rating  ) 

Set Rating.

Parameters:
string $rating
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 280 of file Gravatar.php.

Referenced by setOptions().

    {
        $rating = strtolower($rating);
        switch ($rating) {
            case self::RATING_G:
            case self::RATING_PG:
            case self::RATING_R:
            case self::RATING_X:
                $this->_rating = $rating;
                break;
            default:
                $message = 'Invalid rating: ' . $rating;
                throw new Robo47_Service_Gravatar_Exception($message);
        }
        return $this;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::setSize ( size  ) 

Set Size.

Parameters:
integer $size
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 313 of file Gravatar.php.

Referenced by setOptions().

    {
        $size = (int) $size;
        if ($size < 1) {
            $message = 'size is smaller than 1';
            throw new Robo47_Service_Gravatar_Exception($message);
        }
        if ($size > 512) {
            $message = 'size is greater than 512';
            throw new Robo47_Service_Gravatar_Exception($message);
        }
        $this->_size = $size;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::useSSL ( flag  ) 

Whether to use SSL or not.

Parameters:
bool $flag
Returns:
Robo47_Service_Gravatar *Provides Fluent Interface*

Definition at line 188 of file Gravatar.php.

Referenced by setOptions().

    {
        $this->_useSSL = (bool) $flag;
        return $this;
    }

Here is the caller graph for this function:

Robo47_Service_Gravatar::usesSSL (  ) 

If SSL is used.

Returns:
bool

Definition at line 199 of file Gravatar.php.

Referenced by _filterSsl().

    {
        return $this->_useSSL;
    }

Here is the caller graph for this function:


Member Data Documentation

Robo47_Service_Gravatar::$_cache = null [protected]

Definition at line 124 of file Gravatar.php.

Robo47_Service_Gravatar::$_cachePrefix = 'gravatar_' [protected]

Definition at line 130 of file Gravatar.php.

Robo47_Service_Gravatar::$_default = '' [protected]

Definition at line 118 of file Gravatar.php.

Robo47_Service_Gravatar::$_rating = 'g' [protected]

Definition at line 98 of file Gravatar.php.

Robo47_Service_Gravatar::$_size = 80 [protected]

Definition at line 104 of file Gravatar.php.

Robo47_Service_Gravatar::$_useSSL = false [protected]

Definition at line 136 of file Gravatar.php.

const Robo47_Service_Gravatar::API_SSL_URL = 'https://secure.gravatar.com/avatar/'

GRAVATAR API SSL URL.

Definition at line 42 of file Gravatar.php.

Referenced by _getUri().

const Robo47_Service_Gravatar::API_URL = 'http://www.gravatar.com/avatar/'

GRAVATAR API URL.

Definition at line 37 of file Gravatar.php.

Referenced by _getUri().

GRAVATAR Default 404.

Definition at line 85 of file Gravatar.php.

GRAVATAR Default Identicon http://en.wikipedia.org/wiki/Identicon.

Definition at line 68 of file Gravatar.php.

GRAVATAR Default Monsterid http://www.splitbrain.org/projects/monsterid.

Definition at line 74 of file Gravatar.php.

GRAVATAR Default Wavatar http://www.shamusyoung.com/twentysidedtale/?p=1462.

Definition at line 80 of file Gravatar.php.

GRAVATAR Rating G - General Audiences.

Definition at line 47 of file Gravatar.php.

GRAVATAR Rating PG - Parental Guidance Suggested.

Definition at line 52 of file Gravatar.php.

GRAVATAR Rating R - Restricted.

Definition at line 57 of file Gravatar.php.

GRAVATAR Rating X.

Definition at line 62 of file Gravatar.php.


The documentation for this class was generated from the following file: