How to get Gravatar working in AheadWorks blog extension for Magento
29 Aug, 2011 / 3 MIN readFor those of you who don’t know Gravatar, it’s a globally recognized avatar. A service that provides a unique and global avatar from a central database; regardless of where you are when you post comments.
To be able to take advantage of this functionality you need to first register on http://es.gravatar.com/. Once registered you can configure your individual email accounts, together with an image that will be displayed when the account is in use.
Once you have completed the introduction, the next step is to adapt your own blog so that it only uses one unique global avatar.
One of the best blog solutions in the market for Magento (and which is free) is the AheadWorks extension. This extension provides everything you will need to set up your blog in Magento, including: Multi Store View, comments and intros. What it doesn’t include is the option to include an Avatar within your blog comments. Hence the reason to write this blog.
The first step is to locate the template that is used to display completed comments in the blog entry. Searching in the AheadWorks extension, you will find it in app/design/frontend/mipaquete/miskin/template/aw_blog/post.phtml
Once past the Magento comments, you add the following function, which has been taken from the Gravatar website:
* Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address * @param string $s Size in pixels, defaults to 80px [ 1 − 512 ] * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ] * @param string $r Maximum rating (inclusive) [ g | pg | r | x ] * @param boole $img True to return a complete IMG tag False for just the URL * @param array $atts Optional, additional key/value attributes to include in the IMG tag * @return String containing either just a URL or a complete image tag * @source http://gravatar.com/site/implement/images/php/ */ function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) { $url = 'http://www.gravatar.com/avatar/'; $url .= md5( strtolower( trim( $email ) ) ); $url .= "?s=$s&d=$d&r=$r"; if ( $img ) { $url = '=>$val ) $url .= ' ' . $key . '="' . $val . '"'; $url .= ' />'; } return $url; } ?>
The next step is to actually test the function on-site. Then you will you to go to the loop where your comments are situated and replace it with the following:
getEmail(); //contiene el email de la persona que ha comentado. //$default = Mage::getBaseUrl(); $size=40;//tamaño que va a tener la imagen del avatar $grav_url = "http://www.gravatar.com/avatar/" . md5( strtolower( trim( $email ) ) ) . "?d=" . urlencode( Mage::getBaseUrl() ) . "&s=" . $size; //echo Mage::getBaseUrl(); //echo $grav_url; echo get_gravatar( $email,$size,'mm','g', true, array() );//Utilizamos la función definida anteriormente para mostrar dicho gravatar. ?>
Here are the results:
You can find more information about the modifications carried out in the following link:
http://es.gravatar.com/site/implement/images/php/
By: @davidselo