/ Published in: PHP
Gravatar link generator class
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Gravatar link generator class * * @author xuanyan <[email protected]> * @link http://www.kukufun.com */ // example1: // $gravatar = new Gravatar('[email protected]'); // $gravatar->setDefault('monsterid')->setSize(100); // echo $gravatar; // // example2: // $url = Gravatar::creat('[email protected]') // ->setDefault('http://www.kukufun.com/images/logo.png') // ->setRating('x') // ->__toString(); class Gravatar { private $size = 80; private $rating = 'g'; private $default = ''; private $email = ''; const URL = 'http://www.gravatar.com/avatar/'; public function __construct($email = '') { } public static function creat($email = '') { return new self($email); } public function setRating($rating = 'g') { { $this->rating = $rating; } return $this; } public function setDefault($default = '') { { } { $this->default = $default; } return $this; } public function setSize($size = 80) { $size < 1 && $size = 1; $size > 512 && $size = 512; $this->size = $size; return $this; } public function __toString() { $result = self::URL . $this->email . '?s=' . $this->size . '&r=' .$this->rating; $this->default && $result .= '&d=' . $this->default; return $result; } } ?>