Overview

Namespaces

  • None
  • Wei
    • Validator

Classes

  • Wei\Validator\All
  • Wei\Validator\AllOf
  • Wei\Validator\Alnum
  • Wei\Validator\Alpha
  • Wei\Validator\BaseValidator
  • Wei\Validator\Between
  • Wei\Validator\Blank
  • Wei\Validator\Callback
  • Wei\Validator\CharLength
  • Wei\Validator\Chinese
  • Wei\Validator\Color
  • Wei\Validator\Contains
  • Wei\Validator\CreditCard
  • Wei\Validator\Date
  • Wei\Validator\DateTime
  • Wei\Validator\Decimal
  • Wei\Validator\Digit
  • Wei\Validator\Dir
  • Wei\Validator\DivisibleBy
  • Wei\Validator\DoubleByte
  • Wei\Validator\Email
  • Wei\Validator\EndsWith
  • Wei\Validator\EqualTo
  • Wei\Validator\Exists
  • Wei\Validator\FieldExists
  • Wei\Validator\File
  • Wei\Validator\GreaterThan
  • Wei\Validator\GreaterThanOrEqual
  • Wei\Validator\IdCardCn
  • Wei\Validator\IdCardHk
  • Wei\Validator\IdCardMo
  • Wei\Validator\IdCardTw
  • Wei\Validator\IdenticalTo
  • Wei\Validator\Image
  • Wei\Validator\In
  • Wei\Validator\Ip
  • Wei\Validator\Length
  • Wei\Validator\LessThan
  • Wei\Validator\LessThanOrEqual
  • Wei\Validator\Lowercase
  • Wei\Validator\Luhn
  • Wei\Validator\MaxLength
  • Wei\Validator\MinLength
  • Wei\Validator\MobileCn
  • Wei\Validator\NaturalNumber
  • Wei\Validator\NoneOf
  • Wei\Validator\Null
  • Wei\Validator\Number
  • Wei\Validator\OneOf
  • Wei\Validator\Password
  • Wei\Validator\Phone
  • Wei\Validator\PhoneCn
  • Wei\Validator\PlateNumberCn
  • Wei\Validator\PositiveInteger
  • Wei\Validator\PostcodeCn
  • Wei\Validator\Present
  • Wei\Validator\QQ
  • Wei\Validator\RecordExists
  • Wei\Validator\Regex
  • Wei\Validator\Required
  • Wei\Validator\SomeOf
  • Wei\Validator\StartsWith
  • Wei\Validator\Time
  • Wei\Validator\Tld
  • Wei\Validator\Type
  • Wei\Validator\Uppercase
  • Wei\Validator\Url
  • Wei\Validator\Uuid
  • Overview
  • Namespace
  • Function
  1: <?php
  2: /**
  3:  * Wei Framework
  4:  *
  5:  * @copyright   Copyright (c) 2008-2015 Twin Huang
  6:  * @license     http://opensource.org/licenses/mit-license.php MIT License
  7:  */
  8: 
  9: namespace Wei;
 10: 
 11: /**
 12:  * A service that generates a Gravatar URL for a specified email address
 13:  *
 14:  * @author      Twin Huang <twinhuang@qq.com>
 15:  * @link        https://gravatar.com/site/implement/images/
 16:  */
 17: class Gravatar extends Base
 18: {
 19:     /**
 20:      * The default image type or URL when email do not have a Gravatar image
 21:      *
 22:      * The image type could be 404, mm, identicon, monsterid or wavatar
 23:      *
 24:      * @var string
 25:      */
 26:     protected $default = 'mm';
 27: 
 28:     /**
 29:      * Whether display Gravatar in HTTPS request
 30:      *
 31:      * @var bool
 32:      */
 33:     protected $secure = false;
 34: 
 35:     /**
 36:      * The default size of image, from 1px up to 2048px
 37:      *
 38:      * @var int
 39:      */
 40:     protected $size = 80;
 41: 
 42:     /**
 43:      * The image size for `small` method
 44:      *
 45:      * @var int
 46:      */
 47:     protected $smallSize = 48;
 48: 
 49:     /**
 50:      * The image size for large
 51:      *
 52:      * @var int
 53:      */
 54:     protected $largeSize = 200;
 55: 
 56:     /**
 57:      * Generate a Gravatar URL for a specified email address
 58:      *
 59:      * @param string $email The email address
 60:      * @param int $size The image size in pixels
 61:      * @param string $default The image type or URL when email do not have a Gravatar image
 62:      * @param string $rating The image rating
 63:      * @return string A image URL
 64:      * @link http://gravatar.com/site/implement/images/php/
 65:      */
 66:     public function __invoke($email, $size = null, $default = null, $rating = null)
 67:     {
 68:         if ($this->secure) {
 69:             $url = 'https://secure.gravatar.com/avatar/';
 70:         } else {
 71:             $url = 'http://www.gravatar.com/avatar/';
 72:         }
 73: 
 74:         $url .= md5(strtolower(trim($email)));
 75:         $url .= '?s=' . ($size ?: $this->size);
 76:         $url .= '&d=' . ($default ?: $this->default);
 77: 
 78:         if ($rating) {
 79:             $url .= '&r=' . $rating;
 80:         }
 81: 
 82:         return $url;
 83:     }
 84: 
 85:     /**
 86:      * Generate a large size Gravatar URL for a specified email address
 87:      *
 88:      * @param string $email The email address
 89:      * @param string $default The image type or URL when email do not have a Gravatar image
 90:      * @param string $rating The image rating
 91:      * @return string
 92:      */
 93:     public function large($email, $default = null, $rating = null)
 94:     {
 95:         return $this->__invoke($email, $this->largeSize, $default, $rating);
 96:     }
 97: 
 98:     /**
 99:      * Generate a small size Gravatar URL for a specified email address
100:      *
101:      * @param string $email The email address
102:      * @param string $default The image type or URL when email do not have a Gravatar image
103:      * @param string $rating The image rating
104:      * @return string
105:      */
106:     public function small($email, $default = null, $rating = null)
107:     {
108:         return $this->__invoke($email, $this->smallSize, $default, $rating);
109:     }
110: 
111:     /**
112:      * Sets the default image type or URL
113:      *
114:      * @param string $default
115:      * @return $this
116:      */
117:     public function setDefault($default)
118:     {
119:         $this->default = urlencode($default);
120:         return $this;
121:     }
122: }
123: 
Wei Framework API documentation generated by ApiGen