Beispiel #1
0
 /**
  * Generates an Gravatar URL.
  *
  * Size of the image:
  * * The default size is 32px, and it can be anywhere between 1px up to 2048px.
  * * If requested any value above the allowed range, then the maximum is applied.
  * * If requested any value bellow the minimum, then the default is applied.
  *
  * Default image:
  * * It can be an URL to an image.
  * * Or one of built in options that Gravatar has. See Email::getGravatarBuiltInImages().
  * * If none is defined then a built in default is used. See Email::getGravatarBuiltInDefaultImage().
  *
  * @param string $email
  * @param int    $size
  * @param string $defaultImage
  * @return null|string
  * @link http://en.gravatar.com/site/implement/images/
  */
 public static function getGravatarUrl($email, $size = 32, $defaultImage = 'identicon')
 {
     if (empty($email) || self::_isValid($email) === false) {
         return null;
     }
     $hash = md5(strtolower(trim($email)));
     $parts = array('scheme' => 'http', 'host' => 'www.gravatar.com');
     if (Url::isHttps()) {
         $parts = array('scheme' => 'https', 'host' => 'secure.gravatar.com');
     }
     // Get size
     $size = Vars::limit(Filter::int($size), 32, 2048);
     // Prepare default images
     $defaultImage = trim($defaultImage);
     if (preg_match('/^(http|https)./', $defaultImage)) {
         $defaultImage = urldecode($defaultImage);
     } else {
         $defaultImage = strtolower($defaultImage);
         if (!Arr::in((string) $defaultImage, self::getGravatarBuiltInImages())) {
             $defaultImage = self::getGravatarBuiltInDefaultImage();
         }
     }
     // Build full url
     $parts['path'] = '/avatar/' . $hash . '/';
     $parts['query'] = array('s' => $size, 'd' => $defaultImage);
     $url = Url::create($parts);
     return $url;
 }
Beispiel #2
0
 /**
  * Check opacity value
  *
  * @param $opacity
  * @return int
  */
 public static function opacity($opacity)
 {
     if ($opacity <= 1) {
         $opacity *= 100;
     }
     $opacity = Filter::int($opacity);
     $opacity = Vars::limit($opacity, 0, 100);
     return $opacity;
 }