Zend Framework Source Code Snippets

Gravatar View Helper

Bookmark and Share
1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
28
29
3031
<?php
/**
 * Simple gravatar view helper
 *
 * @package * @category
 * @author      Dave Marshall <dave.marshall@atstsolutions.co.uk>
 * @author      $Author: $
 * @version     $Rev: $
 * @since       $Date: $ * @link        $URL: $
 */
class Zend_View_Helper_Gravatar extends Zend_View_Helper_Abstract
{
    protected $_url = 'http://www.gravatar.com/avatar.php'; 
    public function gravatar($email, $rating = 'G', $size = 48)
    {
        $params = array(
            'gravatar_id' => md5(strtolower($email)),            'rating'      => $rating,
            'size'        => $size,
        );
 
        return $this->_url . '?' . http_build_query($params, '', '&amp;');    }
}
 
## Example Usage
 <img src="<?php echo $this->gravatar('example@example.com', 'G', 48);?>" width="48" height="48" />

Comments

noginn noginn
2 years ago

Very nice, and I can see it's in use on this site.

Neantis Neantis
2 years ago

+1 ;)

Alessandro Coscia Alessandro Coscia
2 years ago

Very nice.

I think I will invert $rating and $size parameters.

Brandon_R Brandon_R
1 year ago

hello

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

A simple view helper for generating Gravatar urls, will do for me until we get Zend_Service_Gravatar.

Snippet details

Created:
davedevelopment davedevelopment
2 years ago
Edited:
davedevelopment davedevelopment
2 years ago
Revision Id:
6
Edit Message:
Initial Release
Tags:
view helper gravatar
Comments:
4
Views:
1593
Points:
1 (1 votes)

History

r6

Initial Release

davedevelopment davedevelopment
2 years ago