Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest you try the <a href="http://www.phpclasses.org/browse/package/4227.html" rel="nofollow noreferrer">php gravatar class</a> by Lucas Araújo. </p> <pre><code>/** * Class Gravatar * * From Gravatar Help: * "A gravatar is a dynamic image resource that is requested from our server. The request * URL is presented here, broken into its segments." * Source: * http://site.gravatar.com/site/implement * * Usage: * &lt;code&gt; * $email = "youremail@yourhost.com"; * $default = "http://www.yourhost.com/default_image.jpg"; // Optional * $gravatar = new Gravatar($email, $default); * $gravatar-&gt;size = 80; * $gravatar-&gt;rating = "G"; * $gravatar-&gt;border = "FF0000"; * * echo $gravatar; // Or echo $gravatar-&gt;toHTML(); * &lt;/code&gt; * * Class Page: http://www.phpclasses.org/browse/package/4227.html * * @author Lucas Araújo &lt;araujo.lucas@gmail.com&gt; * @version 1.0 * @package Gravatar */ class Gravatar { /** * Gravatar's url */ const GRAVATAR_URL = "http://www.gravatar.com/avatar.php"; /** * Ratings available */ private $GRAVATAR_RATING = array("G", "PG", "R", "X"); /** * Query string. key/value */ protected $properties = array( "gravatar_id" =&gt; NULL, "default" =&gt; NULL, "size" =&gt; 80, // The default value "rating" =&gt; NULL, "border" =&gt; NULL, ); /** * E-mail. This will be converted to md5($email) */ protected $email = ""; /** * Extra attributes to the IMG tag like ALT, CLASS, STYLE... */ protected $extra = ""; /** * */ public function __construct($email=NULL, $default=NULL) { $this-&gt;setEmail($email); $this-&gt;setDefault($default); } /** * */ public function setEmail($email) { if ($this-&gt;isValidEmail($email)) { $this-&gt;email = $email; $this-&gt;properties['gravatar_id'] = md5(strtolower($this-&gt;email)); return true; } return false; } /** * */ public function setDefault($default) { $this-&gt;properties['default'] = $default; } /** * */ public function setRating($rating) { if (in_array($rating, $this-&gt;GRAVATAR_RATING)) { $this-&gt;properties['rating'] = $rating; return true; } return false; } /** * */ public function setSize($size) { $size = (int) $size; if ($size &lt;= 0) $size = NULL; // Use the default size $this-&gt;properties['size'] = $size; } /** * */ public function setExtra($extra) { $this-&gt;extra = $extra; } /** * */ public function isValidEmail($email) { // Source: http://www.zend.com/zend/spotlight/ev12apr.php return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); } /** * Object property overloading */ public function __get($var) { return @$this-&gt;properties[$var]; } /** * Object property overloading */ public function __set($var, $value) { switch($var) { case "email": return $this-&gt;setEmail($value); case "rating": return $this-&gt;setRating($value); case "default": return $this-&gt;setDefault($value); case "size": return $this-&gt;setSize($value); // Cannot set gravatar_id case "gravatar_id": return; } return @$this-&gt;properties[$var] = $value; } /** * Object property overloading */ public function __isset($var) { return isset($this-&gt;properties[$var]); } /** * Object property overloading */ public function __unset($var) { return @$this-&gt;properties[$var] == NULL; } /** * Get source */ public function getSrc() { $url = self::GRAVATAR_URL ."?"; $first = true; foreach($this-&gt;properties as $key =&gt; $value) { if (isset($value)) { if (!$first) $url .= "&amp;"; $url .= $key."=".urlencode($value); $first = false; } } return $url; } /** * toHTML */ public function toHTML() { return '&lt;img src="'. $this-&gt;getSrc() .'"' .(!isset($this-&gt;size) ? "" : ' width="'.$this-&gt;size.'" height="'.$this-&gt;size.'"') .$this-&gt;extra .' /&gt;'; } /** * toString */ public function __toString() { return $this-&gt;toHTML(); } } </code></pre> <p>and this is how you'd use it:</p> <pre><code>include 'gravatar.php'; $eMail = 'name@email.net'; $defImg = 'http://www.example.com/images/myphoto.jpg'; $avatar = new Gravatar($eMail, $defImg); $avatar-&gt;setSize(90); $avatar-&gt;setRating('G'); $avatar-&gt;setExtra('alt="my gravatar"'); &lt;p&gt; &lt;?php echo $avatar-&gt;toHTML(); ?&gt; &lt;/p&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload