package and depencies
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
vendor
|
||||
composer.lock
|
||||
*.komodoproject
|
@@ -1,300 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*===================================================================
|
||||
*
|
||||
* GravatarLib - Gravatar PHP 5.3 OOP Library
|
||||
*-------------------------------------------------------------------
|
||||
* @category gravatarlib
|
||||
* @package gravatarlib
|
||||
* @author emberlabs.org
|
||||
* @copyright (c) 2011 emberlabs.org
|
||||
* @license MIT License
|
||||
* @link https://github.com/emberlabs/gravatarlib
|
||||
*
|
||||
*===================================================================
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this package in the file LICENSE.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace thomaswelton\GravatarLib;
|
||||
use \InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* GravatarLib - A lightweight library for working with gravatars en masse,
|
||||
* used for setting a ton of options and then just passing in only the essential data needed.
|
||||
*
|
||||
*
|
||||
* @category gravatarlib
|
||||
* @package gravatarlib
|
||||
* @author emberlabs.org
|
||||
* @license MIT License
|
||||
* @link https://github.com/emberlabs/gravatarlib
|
||||
*/
|
||||
class Gravatar
|
||||
{
|
||||
/**
|
||||
* @var integer - The size to use for avatars.
|
||||
*/
|
||||
protected $size = 80;
|
||||
|
||||
/**
|
||||
* @var mixed - The default image to use - either a string of the gravatar-recognized default image "type" to use, a URL, or false if using the...default gravatar default image (hah)
|
||||
*/
|
||||
protected $default_image = false;
|
||||
|
||||
/**
|
||||
* @var string - The maximum rating to allow for the avatar.
|
||||
*/
|
||||
protected $max_rating = 'g';
|
||||
|
||||
/**
|
||||
* @var boolean - Should we use the secure (HTTPS) URL base?
|
||||
*/
|
||||
protected $use_secure_url = false;
|
||||
|
||||
/**
|
||||
* @var string - A temporary internal cache of the URL parameters to use.
|
||||
*/
|
||||
protected $param_cache = NULL;
|
||||
|
||||
/**#@+
|
||||
* @var string - URL constants for the avatar images
|
||||
*/
|
||||
const HTTP_URL = 'http://www.gravatar.com/avatar/';
|
||||
const HTTPS_URL = 'https://secure.gravatar.com/avatar/';
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Get the currently set avatar size.
|
||||
* @return integer - The current avatar size in use.
|
||||
*/
|
||||
public function getAvatarSize()
|
||||
{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the avatar size to use.
|
||||
* @param integer $size - The avatar size to use, must be less than 512 and greater than 0.
|
||||
* @return \thomaswelton\GravatarLib\Gravatar - Provides a fluent interface.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setAvatarSize($size)
|
||||
{
|
||||
// Wipe out the param cache.
|
||||
$this->param_cache = NULL;
|
||||
|
||||
if(!is_int($size) && !ctype_digit($size))
|
||||
{
|
||||
throw new InvalidArgumentException('Avatar size specified must be an integer');
|
||||
}
|
||||
|
||||
$this->size = (int) $size;
|
||||
|
||||
if($this->size > 512 || $this->size < 0)
|
||||
{
|
||||
throw new InvalidArgumentException('Avatar size must be within 0 pixels and 512 pixels');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current default image setting.
|
||||
* @return mixed - False if no default image set, string if one is set.
|
||||
*/
|
||||
public function getDefaultImage()
|
||||
{
|
||||
return $this->default_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default image to use for avatars.
|
||||
* @param mixed $image - The default image to use. Use boolean false for the gravatar default, a string containing a valid image URL, or a string specifying a recognized gravatar "default".
|
||||
* @return \thomaswelton\GravatarLib\Gravatar - Provides a fluent interface.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setDefaultImage($image)
|
||||
{
|
||||
// Quick check against boolean false.
|
||||
if($image === false)
|
||||
{
|
||||
$this->default_image = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Wipe out the param cache.
|
||||
$this->param_cache = NULL;
|
||||
|
||||
// Check $image against recognized gravatar "defaults", and if it doesn't match any of those we need to see if it is a valid URL.
|
||||
$_image = strtolower($image);
|
||||
$valid_defaults = array('404' => 1, 'mm' => 1, 'identicon' => 1, 'monsterid' => 1, 'wavatar' => 1, 'retro' => 1);
|
||||
if(!isset($valid_defaults[$_image]))
|
||||
{
|
||||
if(!filter_var($image, FILTER_VALIDATE_URL))
|
||||
{
|
||||
throw new InvalidArgumentException('The default image specified is not a recognized gravatar "default" and is not a valid URL');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->default_image = rawurlencode($image);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->default_image = $_image;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current maximum allowed rating for avatars.
|
||||
* @return string - The string representing the current maximum allowed rating ('g', 'pg', 'r', 'x').
|
||||
*/
|
||||
public function getMaxRating()
|
||||
{
|
||||
return $this->max_rating;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum allowed rating for avatars.
|
||||
* @param string $rating - The maximum rating to use for avatars ('g', 'pg', 'r', 'x').
|
||||
* @return \thomaswelton\GravatarLib\Gravatar - Provides a fluent interface.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setMaxRating($rating)
|
||||
{
|
||||
// Wipe out the param cache.
|
||||
$this->param_cache = NULL;
|
||||
|
||||
$rating = strtolower($rating);
|
||||
$valid_ratings = array('g' => 1, 'pg' => 1, 'r' => 1, 'x' => 1);
|
||||
if(!isset($valid_ratings[$rating]))
|
||||
{
|
||||
throw new InvalidArgumentException(sprintf('Invalid rating "%s" specified, only "g", "pg", "r", or "x" are allowed to be used.', $rating));
|
||||
}
|
||||
|
||||
$this->max_rating = $rating;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are using the secure protocol for the image URLs.
|
||||
* @return boolean - Are we supposed to use the secure protocol?
|
||||
*/
|
||||
public function usingSecureImages()
|
||||
{
|
||||
return $this->use_secure_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the use of the secure protocol for image URLs.
|
||||
* @return \thomaswelton\GravatarLib\Gravatar - Provides a fluent interface.
|
||||
*/
|
||||
public function enableSecureImages()
|
||||
{
|
||||
$this->use_secure_url = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the use of the secure protocol for image URLs.
|
||||
* @return \thomaswelton\GravatarLib\Gravatar - Provides a fluent interface.
|
||||
*/
|
||||
public function disableSecureImages()
|
||||
{
|
||||
$this->use_secure_url = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the avatar URL based on the provided email address.
|
||||
* @param string $email - The email to get the gravatar for.
|
||||
* @param string $hash_email - Should we hash the $email variable? (Useful if the email address has a hash stored already)
|
||||
* @return string - The XHTML-safe URL to the gravatar.
|
||||
*/
|
||||
public function buildGravatarURL($email, $hash_email = true)
|
||||
{
|
||||
// Start building the URL, and deciding if we're doing this via HTTPS or HTTP.
|
||||
if($this->usingSecureImages())
|
||||
{
|
||||
$url = static::HTTPS_URL;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = static::HTTP_URL;
|
||||
}
|
||||
|
||||
// Tack the email hash onto the end.
|
||||
if($hash_email == true && !empty($email))
|
||||
{
|
||||
$url .= $this->getEmailHash($email);
|
||||
}
|
||||
elseif(!empty($email))
|
||||
{
|
||||
$url .= $email;
|
||||
}
|
||||
else
|
||||
{
|
||||
$url .= str_repeat('0', 32);
|
||||
}
|
||||
|
||||
// Check to see if the param_cache property has been populated yet
|
||||
if($this->param_cache === NULL)
|
||||
{
|
||||
// Time to figure out our request params
|
||||
$params = array();
|
||||
$params[] = 's=' . $this->getAvatarSize();
|
||||
$params[] = 'r=' . $this->getMaxRating();
|
||||
if($this->getDefaultImage())
|
||||
{
|
||||
$params[] = 'd=' . $this->getDefaultImage();
|
||||
}
|
||||
|
||||
// Stuff the request params into the param_cache property for later reuse
|
||||
$this->params_cache = (!empty($params)) ? '?' . implode('&', $params) : '';
|
||||
}
|
||||
|
||||
// Handle "null" gravatar requests.
|
||||
$tail = '';
|
||||
if(empty($email))
|
||||
{
|
||||
$tail = !empty($this->params_cache) ? '&f=y' : '?f=y';
|
||||
}
|
||||
|
||||
// And we're done.
|
||||
return $url . $this->params_cache . $tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the email hash to use (after cleaning the string).
|
||||
* @param string $email - The email to get the hash for.
|
||||
* @return string - The hashed form of the email, post cleaning.
|
||||
*/
|
||||
public function getEmailHash($email)
|
||||
{
|
||||
// Using md5 as per gravatar docs.
|
||||
return hash('md5', strtolower(trim($email)));
|
||||
}
|
||||
|
||||
/**
|
||||
* ...Yeah, it's just an alias of buildGravatarURL. This is just to make it easier to use as a twig asset.
|
||||
* @see \thomaswelton\GravatarLib\Gravatar::buildGravatarURL()
|
||||
*/
|
||||
public function get($email, $hash_email = true)
|
||||
{
|
||||
// Just an alias. Makes it easy to use this as a twig asset.
|
||||
return $this->buildGravatarURL($email, $hash_email);
|
||||
}
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
Copyright (c) 2011 emberlabs.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is furnished
|
||||
to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
@@ -1,122 +0,0 @@
|
||||
# GravatarLib
|
||||
|
||||
GravatarLib is a small library intended to provide easy integration of gravatar-provided avatars.
|
||||
|
||||
## copyright
|
||||
|
||||
(c) 2011 emberlabs.org
|
||||
|
||||
## license
|
||||
|
||||
This library is licensed under the MIT license; you can find a full copy of the license itself in the file /LICENSE
|
||||
|
||||
## requirements
|
||||
|
||||
* PHP 5.3.0 or newer
|
||||
* hash() function must be available, along with the md5 algorithm
|
||||
|
||||
## usage
|
||||
|
||||
We'll assume you're using this git repository as a git submodule, and have it located at `includes/emberlabs/GravatarLib/` according to namespacing rules, for easy autoloading.
|
||||
|
||||
### general example
|
||||
|
||||
``` php
|
||||
<?php
|
||||
include __DIR__ . '/includes/emberlabs/GravatarLib/Gravatar.php';
|
||||
$gravatar = new \emberlabs\GravatarLib\Gravatar();
|
||||
// example: setting default image and maximum size
|
||||
$gravatar->setDefaultImage('mm')
|
||||
->setAvatarSize(150);
|
||||
// example: setting maximum allowed avatar rating
|
||||
$gravatar->setMaxRating('pg');
|
||||
$avatar = $gravatar->buildGravatarURL('someemail@domain.com');
|
||||
```
|
||||
|
||||
### setting the default image
|
||||
|
||||
Gravatar provides several pre-fabricated default images for use when the email address provided does not have a gravatar or when the gravatar specified exceeds your maximum allowed content rating.
|
||||
The provided images are 'mm', 'identicon', 'monsterid', 'retro', and 'wavatar'. To set the default iamge to use on your site, use the method `\emberlabs\GravatarLib\Gravatar->setDefaultImage()`
|
||||
In addition, you can also set your own default image to be used by providing a valid URL to the image you wish to use.
|
||||
|
||||
Here are a couple of examples...
|
||||
|
||||
``` php
|
||||
$gravatar->setDefaultImage('wavatar');
|
||||
```
|
||||
|
||||
``` php
|
||||
$gravatar->setDefaultImage('http://yoursitehere.com/path/to/image.png');
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### WARNING
|
||||
If an invalid default image is specified (both an invalid prefab default image and an invalid URL is provided), this method will throw an exception of class `\InvalidArgumentException`.
|
||||
|
||||
### setting avatar size
|
||||
|
||||
Gravatar allows avatar images ranging from 1px to 512px in size -- and you, the developer or site administrator can specify the exact size of avatar that you want.
|
||||
By default, the avatar size provided is 80px. To set the avatar size for use on your site, use the method `\emberlabs\GravatarLib\Gravatar->setAvatarSize()`, and specify the avatar size with an integer representing the size in pixels.
|
||||
|
||||
An example of setting the avatar size is provided below:
|
||||
|
||||
``` php
|
||||
$gravatar->setAvatarSize(184);
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### WARNING
|
||||
If an invalid size (less than 1, greater than 512) or a non-integer value is specified, this method will throw an exception of class `\InvalidArgumentException`.
|
||||
|
||||
### setting the maximum content rating
|
||||
|
||||
Gravatar provides four levels for rating avatars by, which are named similar to entertainment media ratings scales used in the United States. They are, by order of severity (first is safe for everyone to see, last is explicit), "g", "pg", "r", and "x".
|
||||
By default, the maximum content rating is set to "g". You can set the maximum allowable rating on avatars embedded within your site by using the method `\emberlabs\GravatarLib\Gravatar->setMaxRating()`. Please note that any avatars that do not fall under your maximum content rating will be replaced with the default image you have specified.
|
||||
|
||||
Here's an example of how to set the maximum content rating:
|
||||
|
||||
``` php
|
||||
$gravatar->setMaxRating('r');
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### WARNING
|
||||
If an invalid maximum rating is specified, this method will throw an exception of class `\InvalidArgumentException`.
|
||||
|
||||
### enabling secure images
|
||||
|
||||
If your site is served over HTTPS, you'll likely want to serve gravatars over HTTPS as well to avoid "mixed content warnings".
|
||||
To enable "secure images" mode, call the method `\emberlabs\GravatarLib\Gravatar->enableSecureImages()` before generating any gravatar URLs.
|
||||
To check to see if you are using "secure images" mode, call the method `\emberlabs\GravatarLib\Gravatar->usingSecureImages()`, which will return a boolean value regarding whether or not secure images mode is enabled.
|
||||
|
||||
### twig integration
|
||||
|
||||
It's extremely easy to hook this library up as a template asset to the [Twig template engine](http://www.twig-project.org/).
|
||||
|
||||
When you've got an instance of the Twig_Environment ready, add in your instantiated gravatar object as a twig "global" like so:
|
||||
|
||||
``` php
|
||||
<?php
|
||||
// include the lib file here, or use an autoloader if you wish
|
||||
include __DIR__ . '/includes/emberlabs/GravatarLib/Gravatar.php';
|
||||
// instantiate the gravatar library object
|
||||
$gravatar = new \emberlabs\GravatarLib\Gravatar();
|
||||
|
||||
// ... do whatever you want with your settings here
|
||||
|
||||
// here, we will assume $twig is an already-created instance of Twig_Environment
|
||||
$twig->addGlobal('gravatar', $gravatar);
|
||||
```
|
||||
|
||||
Now in your twig templates, you can get a user's gravatar with something like this snip of code:
|
||||
|
||||
(note: this template snip assumes that the "email" template variable contains the email of the user to grab the gravatar for)
|
||||
|
||||
```
|
||||
<img src="User avatar" src="{{ gravatar.get(email)|raw }}" />
|
||||
```
|
||||
|
||||
We are also using the raw filter here to preserve XHTML 1.0 Strict compliance; the generated gravatar URL contains the `&` character, and if the filter was not used it would be double-escaped.
|
@@ -1,32 +0,0 @@
|
||||
{
|
||||
"name": "thomaswelton/gravatarlib",
|
||||
"description": "A lightweight PHP 5.3 OOP library providing easy gravatar integration.",
|
||||
"keywords": ["gravatar", "templating", "twig"],
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"authors": [{
|
||||
"name" : "Sam Thompson",
|
||||
"email" : "sam@emberlabs.org"
|
||||
},
|
||||
{
|
||||
"name" : "Damian Bushong",
|
||||
"email" : "damian@emberlabs.org"
|
||||
},
|
||||
{
|
||||
"name" : "Thomas Welton",
|
||||
"email" : "thomaswelton@me.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"suggest" : {
|
||||
"twig/twig" : ">=1.4.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"thomaswelton\\GravatarLib\\": ""
|
||||
}
|
||||
},
|
||||
"target-dir" : "thomaswelton/GravatarLib"
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"name":"thomaswelton/laravel-gravatar",
|
||||
"description":"Laravel 5 Gravatar helper",
|
||||
"keywords":[
|
||||
"laravel",
|
||||
"laravel5",
|
||||
"gravatar"
|
||||
],
|
||||
"homepage":"https://github.com/thomaswelton/laravel-gravatar",
|
||||
"license":"MIT",
|
||||
"authors":[
|
||||
{
|
||||
"name":"ThomasWelton",
|
||||
"email":"thomaswelton@me.com",
|
||||
"role":"Developer"
|
||||
},
|
||||
{
|
||||
"name":"Antoine Augusti",
|
||||
"email":"antoine.augusti@gmail.com",
|
||||
"role":"Developer"
|
||||
}
|
||||
],
|
||||
"require":{
|
||||
"php":">=5.4.0",
|
||||
"illuminate/support":"~5.0|^6.0|^7.0|^8.0",
|
||||
"thomaswelton/gravatarlib":"0.1.x"
|
||||
},
|
||||
"require-dev":{
|
||||
"phpunit/phpunit":"4.8.*",
|
||||
"mockery/mockery":"0.9.*"
|
||||
},
|
||||
"autoload":{
|
||||
"psr-4":{
|
||||
"Thomaswelton\\LaravelGravatar\\":"src/",
|
||||
"Thomaswelton\\Tests\\LaravelGravatar\\":"tests/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Thomaswelton\\LaravelGravatar\\LaravelGravatarServiceProvider"
|
||||
],
|
||||
"aliases": {
|
||||
"Gravatar": "Thomaswelton\\LaravelGravatar\\Facades\\Gravatar"
|
||||
}
|
||||
}
|
||||
},
|
||||
"minimum-stability":"stable"
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
// --- The default avatar size
|
||||
'size' => 80,
|
||||
|
||||
// --- The default avatar to display if we have no results
|
||||
// (bool) false
|
||||
// (string) 404
|
||||
// (string) mm: (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash).
|
||||
// (string) identicon: a geometric pattern based on an email hash.
|
||||
// (string) monsterid: a generated 'monster' with different colors, faces, etc.
|
||||
// (string) wavatar: generated faces with differing features and backgrounds.
|
||||
// (string) retro: awesome generated, 8-bit arcade-style pixelated faces.
|
||||
'default' => 'identicon',
|
||||
|
||||
// --- Set the type of avatars we allow to show
|
||||
// - g: suitable for display on all websites with any audience type.
|
||||
// - pg: may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
|
||||
// - r: may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
|
||||
// - x: may contain hardcore sexual imagery or extremely disturbing violence.
|
||||
'maxRating' => 'g'
|
||||
);
|
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Thomaswelton\LaravelGravatar\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Gravatar extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'gravatar';
|
||||
}
|
||||
}
|
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Thomaswelton\LaravelGravatar;
|
||||
|
||||
use Illuminate\Contracts\Config\Repository as Config;
|
||||
use thomaswelton\GravatarLib\Gravatar as GravatarLib;
|
||||
|
||||
class Gravatar extends GravatarLib
|
||||
{
|
||||
/**
|
||||
* The maximum size allowed for the Gravatar.
|
||||
*/
|
||||
const MAX_SIZE = 512;
|
||||
|
||||
/**
|
||||
* The default size of the Gravatar.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $defaultSize = null;
|
||||
|
||||
public function __construct(Config $config)
|
||||
{
|
||||
// Set default configuration values
|
||||
$this->setDefaultImage($config->get('gravatar.default'));
|
||||
$this->defaultSize = $config->get('gravatar.size');
|
||||
$this->setMaxRating($config->get('gravatar.maxRating', 'g'));
|
||||
|
||||
$this->enableSecureImages();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the URL of a Gravatar. Note: it does not check for the existence of this Gravatar.
|
||||
*
|
||||
* @param string $email The email address.
|
||||
* @param int $size Override the size of the Gravatar.
|
||||
* @param null|string $rating Override the default rating if you want to.
|
||||
*
|
||||
* @return string The URL of the Gravatar.
|
||||
*/
|
||||
public function src($email, $size = null, $rating = null)
|
||||
{
|
||||
if (is_null($size)) {
|
||||
$size = $this->defaultSize;
|
||||
}
|
||||
|
||||
$size = max(1, min(self::MAX_SIZE, $size));
|
||||
|
||||
$this->setAvatarSize($size);
|
||||
|
||||
if (!is_null($rating)) {
|
||||
$this->setMaxRating($rating);
|
||||
}
|
||||
|
||||
return $this->buildGravatarURL($email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the code of HTML image for a Gravatar.
|
||||
*
|
||||
* @param string $email The email address.
|
||||
* @param string $alt The alt attribute for the image.
|
||||
* @param array $attributes Override the 'height' and the 'width' of the image if you want.
|
||||
* @param null|string $rating Override the default rating if you want to.
|
||||
*
|
||||
* @return string The code of the HTML image.
|
||||
*/
|
||||
public function image($email, $alt = null, $attributes = [], $rating = null)
|
||||
{
|
||||
$dimensions = [];
|
||||
|
||||
if (array_key_exists('width', $attributes)) {
|
||||
$dimensions[] = $attributes['width'];
|
||||
}
|
||||
if (array_key_exists('height', $attributes)) {
|
||||
$dimensions[] = $attributes['height'];
|
||||
}
|
||||
|
||||
if (count($dimensions) > 0) {
|
||||
$size = min(self::MAX_SIZE, max($dimensions));
|
||||
} else {
|
||||
$size = $this->defaultSize;
|
||||
}
|
||||
|
||||
$src = $this->src($email, $size, $rating);
|
||||
|
||||
if (!array_key_exists('width', $attributes) && !array_key_exists('height', $attributes)) {
|
||||
$attributes['width'] = $this->size;
|
||||
$attributes['height'] = $this->size;
|
||||
}
|
||||
|
||||
return $this->formatImage($src, $alt, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Gravatar image exists.
|
||||
*
|
||||
* @param string $email The email address.
|
||||
*
|
||||
* @return bool True if the Gravatar exists, false otherwise.
|
||||
*/
|
||||
public function exists($email)
|
||||
{
|
||||
$this->setDefaultImage('404');
|
||||
|
||||
$url = $this->buildGravatarURL($email);
|
||||
$headers = get_headers($url, 1);
|
||||
|
||||
return substr($headers[0], 9, 3) == '200';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the HTML image code.
|
||||
*
|
||||
* @param string $src The source attribute of the image.
|
||||
* @param string $alt The alt attribute of the image.
|
||||
* @param array $attributes Used to set the width and the height.
|
||||
*
|
||||
* @return string The HTML code.
|
||||
*/
|
||||
private function formatImage($src, $alt, $attributes)
|
||||
{
|
||||
return sprintf('<img src="%s" alt="%s" height="%s" width="%s">', $src, $alt, $attributes['height'], $attributes['width']);
|
||||
}
|
||||
}
|
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Thomaswelton\LaravelGravatar;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LaravelGravatarServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->setupConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the config.
|
||||
*/
|
||||
protected function setupConfig()
|
||||
{
|
||||
$source = realpath(__DIR__.'/../config/gravatar.php');
|
||||
$this->publishes([$source => config_path('gravatar.php')]);
|
||||
$this->mergeConfigFrom($source, 'gravatar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app->singleton('gravatar', function ($app) {
|
||||
return new Gravatar($this->app['config']);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user