This commit is contained in:
2020-10-06 14:27:47 +07:00
commit 586be80cf6
16613 changed files with 3274099 additions and 0 deletions

View File

@@ -0,0 +1 @@
/vendor/

View File

@@ -0,0 +1,136 @@
<?php
namespace cebe\gravatar;
use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\helpers\Html;
/**
* Displays a gravatar image tag.
*
* To use this widget, you may insert the following code in a view:
*
* ```
* echo \cebe\gravatar\Gravatar::widget([
* 'email' => 'mail@cebe.cc',
* 'size' => 128,
* 'defaultImage' => 'monsterid',
* // 'secure' => false, // will be autodetected
* 'rating' => 'r',
* 'options'=>[
* 'alt'=>'Gravatar image',
* 'title'=>'Gravatar image',
* ]
* ]);
* </pre>
*
* @author Carsten Brandt <mail@cebe.cc>
*/
class Gravatar extends Widget
{
public $gravatarUrl = 'http://www.gravatar.com/avatar/';
public $gravatarUrlSecure = 'https://secure.gravatar.com/avatar/';
/**
* @var boolean whether to use [[gravatarUrl]] or [[gravatarUrlSecure]] as base url.
* If not set it will be detected by current request.
*/
public $secure;
/**
* @var int image size in pixel
* @link http://en.gravatar.com/site/implement/images/#size
*/
public $size = 128;
/**
* @var string the email to use
*/
public $email;
/**
* Can be one of '404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro' or a url to default image.
* @var string default image to use if no gravatar available
* @link http://en.gravatar.com/site/implement/images/#default-image
*/
public $defaultImage;
/**
* Can be one of 'g', 'pg', 'r', 'x'
* @var string gravatar image rating
* @link http://en.gravatar.com/site/implement/images/#rating
*/
public $rating = 'g';
/**
* @var string can be 'png' or 'jpg'
* @link http://en.gravatar.com/site/implement/images/#base-request
*/
public $fileType;
/**
* @var array html options for the image tag
*/
public $options = [];
public function run()
{
if (!isset($this->options['alt'])) {
$this->options['alt'] = 'Gravatar image';
}
echo Html::img($this->getImageUrl(), $this->options);
}
/**
* @return string generates the gravatar image url
*/
public function getImageUrl()
{
if ($this->secure === null) {
$this->secure = \Yii::$app->request->isSecureConnection;
}
$url = $this->secure ? $this->gravatarUrlSecure : $this->gravatarUrl;
$url .= $this->getEmailHash() . (($this->fileType !== null) ? '.' . $this->fileType : '');
$params = [
'r' => $this->rating,
's' => $this->size,
];
if ($this->defaultImage !== null) {
$params['d'] = $this->defaultImage;
}
$url .= '?' . http_build_query($params);
return $url;
}
private $_emailHash;
/**
* Generates email hash for gravatar url
*
* @link http://en.gravatar.com/site/implement/hash/
* @return string md5 hash of the trimmed lowercase [[email]]
* @throws \yii\base\InvalidConfigException if no email has been specified.
*/
public function getEmailHash()
{
if ($this->_emailHash !== null) {
return $this->_emailHash;
} elseif ($this->email === null) {
throw new InvalidConfigException('No email specified for Gravatar image Widget.');
}
return $this->_emailHash = md5(strtolower(trim($this->email)));
}
/**
* Sets the email hash to use for gravatar url
* @param $hash
*/
public function setEmailHash($hash)
{
$this->_emailHash = $hash;
}
}

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2013 Carsten Brandt
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.

View File

@@ -0,0 +1,32 @@
yii2-gravatar
=============
Gravatar Widget for Yii Framework 2
How to install?
---------------
Get it via [composer](http://getcomposer.org/) by adding the package to your `composer.json`:
```json
{
"require": {
"cebe/yii2-gravatar": "1.0"
}
}
```
You may also check the package information on [packagist](https://packagist.org/packages/cebe/yii2-gravatar).
Usage
-----
```php
<?php echo \cebe\gravatar\Gravatar::widget([
'email' => 'mail@cebe.cc',
'options' => [
'alt' => 'Carsten Brandt'
],
'size' => 32
]); ?>
```

View File

@@ -0,0 +1,26 @@
{
"name": "cebe/yii2-gravatar",
"description": "Gravatar Widget for Yii 2",
"keywords": ["yii", "gravatar"],
"type": "yii2-extension",
"license": "MIT",
"authors": [
{
"name": "Carsten Brandt",
"email": "mail@cebe.cc"
}
],
"support": {
"issues": "https://github.com/cebe/yii2-gravatar/issues",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/cebe/yii2-gravatar"
},
"require": {
"yiisoft/yii2": "*"
},
"autoload": {
"psr-0": { "cebe\\gravatar\\": "" }
},
"target-dir": "cebe/gravatar"
}