update for version 1.0.1
This commit is contained in:
3
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/.gitignore
vendored
Normal file
3
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
vendor
|
||||
composer.lock
|
||||
*.komodoproject
|
||||
300
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/Gravatar.php
vendored
Normal file
300
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/Gravatar.php
vendored
Normal file
@@ -0,0 +1,300 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
19
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/LICENSE
vendored
Normal file
19
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/LICENSE
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
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.
|
||||
122
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/README.markdown
vendored
Normal file
122
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/README.markdown
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
# 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.
|
||||
32
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/composer.json
vendored
Normal file
32
code/vendor/thomaswelton/gravatarlib/thomaswelton/GravatarLib/composer.json
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
4
code/vendor/thomaswelton/laravel-gravatar/.gitignore
vendored
Normal file
4
code/vendor/thomaswelton/laravel-gravatar/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
.DS_Store
|
||||
11
code/vendor/thomaswelton/laravel-gravatar/.travis.yml
vendored
Normal file
11
code/vendor/thomaswelton/laravel-gravatar/.travis.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev
|
||||
|
||||
script: phpunit
|
||||
20
code/vendor/thomaswelton/laravel-gravatar/LICENSE
vendored
Normal file
20
code/vendor/thomaswelton/laravel-gravatar/LICENSE
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Thomas Welton
|
||||
|
||||
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.
|
||||
93
code/vendor/thomaswelton/laravel-gravatar/README.md
vendored
Normal file
93
code/vendor/thomaswelton/laravel-gravatar/README.md
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
[](https://travis-ci.org/thomaswelton/laravel-gravatar)
|
||||
[](https://packagist.org/packages/thomaswelton/laravel-gravatar)
|
||||
[](https://packagist.org/packages/thomaswelton/laravel-gravatar)
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
Update your `composer.json` file to include this package as a dependency
|
||||
```json
|
||||
"thomaswelton/laravel-gravatar": "~1.0"
|
||||
```
|
||||
|
||||
Register the Gravatar service provider by adding it to the providers array in the `config/app.php` file.
|
||||
```
|
||||
Thomaswelton\LaravelGravatar\LaravelGravatarServiceProvider
|
||||
```
|
||||
|
||||
Alias the Gravatar facade by adding it to the aliases array in the `config/app.php` file.
|
||||
```php
|
||||
'aliases' => array(
|
||||
'Gravatar' => 'Thomaswelton\LaravelGravatar\Facades\Gravatar'
|
||||
)
|
||||
```
|
||||
|
||||
## Configuration - Optional
|
||||
|
||||
Copy the config file into your project by running
|
||||
```
|
||||
php artisan vendor:publish
|
||||
```
|
||||
|
||||
### Default Image
|
||||
|
||||
Update the config file to specify the default avatar size to use and a default image to be return if no Gravatar is found.
|
||||
|
||||
Allowed defaults:
|
||||
- (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.
|
||||
|
||||
Example images can be viewed on [the Gravatar website](https://gravatar.com/site/implement/images/).
|
||||
|
||||
### Content Ratings
|
||||
|
||||
By default only "G" rated images will be shown. You can change this system wide in the config file by editing `'maxRating' => 'g'` allowed values are
|
||||
- `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.
|
||||
|
||||
The content rating can be changed by changing the `$rating` argument when calling `Gravatar::src` or `Gravatar::image`.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Gravatar::exists($email)
|
||||
Returns a boolean telling if the given `$email` has got a Gravatar.
|
||||
|
||||
### Gravatar::src($email, $size = null, $rating = null)
|
||||
|
||||
Returns the https URL for the Gravatar of the email address specified.
|
||||
Can optionally pass in the size required as an integer. The size will be contained within a range between 1 - 512 as gravatar will no return sizes greater than 512 of less than 1
|
||||
|
||||
```html
|
||||
<!-- Show image with default dimensions -->
|
||||
<img src="{{ Gravatar::src('thomaswelton@me.com') }}">
|
||||
|
||||
<!-- Show image at 200px -->
|
||||
<img src="{{ Gravatar::src('thomaswelton@me.com', 200) }}">
|
||||
|
||||
<!-- Show image at 512px scaled in HTML to 1024px -->
|
||||
<img src="{{ Gravatar::src('thomaswelton@me.com', 1024) }}" width=1024>
|
||||
```
|
||||
|
||||
### Gravatar::image($email, $alt = null, $attributes = array(), $rating = null)
|
||||
|
||||
Returns the HTML for an `<img>` tag
|
||||
|
||||
```php
|
||||
// Show image with default dimensions
|
||||
echo Gravatar::image('thomaswelton@me.com');
|
||||
|
||||
// Show image at 200px
|
||||
echo Gravatar::image('thomaswelton@me.com', 'Some picture', array('width' => 200, 'height' => 200));
|
||||
|
||||
// Show image at 512px scaled in HTML to 1024px
|
||||
echo Gravatar::image('thomaswelton@me.com', 'Some picture', array('width' => 1024, 'height' => 1024));
|
||||
```
|
||||
34
code/vendor/thomaswelton/laravel-gravatar/composer.json
vendored
Normal file
34
code/vendor/thomaswelton/laravel-gravatar/composer.json
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"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",
|
||||
"thomaswelton/gravatarlib":"0.1.x"
|
||||
},
|
||||
"autoload":{
|
||||
"psr-0":{
|
||||
"Thomaswelton\\LaravelGravatar":"src/"
|
||||
}
|
||||
},
|
||||
"minimum-stability":"stable"
|
||||
}
|
||||
23
code/vendor/thomaswelton/laravel-gravatar/config/gravatar.php
vendored
Normal file
23
code/vendor/thomaswelton/laravel-gravatar/config/gravatar.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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'
|
||||
);
|
||||
18
code/vendor/thomaswelton/laravel-gravatar/phpunit.xml
vendored
Normal file
18
code/vendor/thomaswelton/laravel-gravatar/phpunit.xml
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Package Test Suite">
|
||||
<directory suffix=".php">./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
||||
14
code/vendor/thomaswelton/laravel-gravatar/src/Thomaswelton/LaravelGravatar/Facades/Gravatar.php
vendored
Normal file
14
code/vendor/thomaswelton/laravel-gravatar/src/Thomaswelton/LaravelGravatar/Facades/Gravatar.php
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
<?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'; }
|
||||
|
||||
}
|
||||
75
code/vendor/thomaswelton/laravel-gravatar/src/Thomaswelton/LaravelGravatar/Gravatar.php
vendored
Normal file
75
code/vendor/thomaswelton/laravel-gravatar/src/Thomaswelton/LaravelGravatar/Gravatar.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php namespace Thomaswelton\LaravelGravatar;
|
||||
|
||||
use Illuminate\Contracts\Config\Repository as Config;
|
||||
use Illuminate\Support\Facades\HTML;
|
||||
use thomaswelton\GravatarLib\Gravatar as GravatarLib;
|
||||
|
||||
class Gravatar extends GravatarLib
|
||||
{
|
||||
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'));
|
||||
|
||||
// Enable secure images by default
|
||||
$this->enableSecureImages();
|
||||
}
|
||||
|
||||
public function src($email, $size = null, $rating = null)
|
||||
{
|
||||
if (is_null($size))
|
||||
{
|
||||
$size = $this->defaultSize;
|
||||
}
|
||||
|
||||
$size = max(1, min(512, $size));
|
||||
|
||||
$this->setAvatarSize($size);
|
||||
|
||||
if ( ! is_null($rating))
|
||||
{
|
||||
$this->setMaxRating($rating);
|
||||
}
|
||||
|
||||
return htmlentities($this->buildGravatarURL($email));
|
||||
}
|
||||
|
||||
public function image($email, $alt = null, $attributes = array(), $rating = null)
|
||||
{
|
||||
$dimensions = array();
|
||||
|
||||
if (array_key_exists('width', $attributes)) $dimensions[] = $attributes['width'];
|
||||
if (array_key_exists('height', $attributes)) $dimensions[] = $attributes['height'];
|
||||
|
||||
$max_dimension = (count($dimensions)) ? min(512, max($dimensions)) : $this->defaultSize;
|
||||
|
||||
$src = $this->src($email, $max_dimension, $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);
|
||||
}
|
||||
|
||||
public function exists($email)
|
||||
{
|
||||
$this->setDefaultImage('404');
|
||||
|
||||
$url = $this->buildGravatarURL($email);
|
||||
$headers = get_headers($url, 1);
|
||||
|
||||
return strpos($headers[0], '200') ? true : false;
|
||||
}
|
||||
|
||||
private function formatImage($src, $alt, $attributes)
|
||||
{
|
||||
return '<img src="'.$src.'" alt="'.$alt.'" height="'.$attributes['height'].'" width="'.$attributes['width'].'">';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php namespace Thomaswelton\LaravelGravatar;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LaravelGravatarServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Boot the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->setupConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setupConfig()
|
||||
{
|
||||
$source = realpath(__DIR__.'/../../../config/gravatar.php');
|
||||
$this->publishes([$source => config_path('gravatar.php')]);
|
||||
$this->mergeConfigFrom($source, 'gravatar');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->app['gravatar'] = $this->app->share(function($app)
|
||||
{
|
||||
return new Gravatar($this->app['config']);
|
||||
});
|
||||
}
|
||||
}
|
||||
0
code/vendor/thomaswelton/laravel-gravatar/tests/.gitkeep
vendored
Normal file
0
code/vendor/thomaswelton/laravel-gravatar/tests/.gitkeep
vendored
Normal file
Reference in New Issue
Block a user