Skip to content

Commit 94b6998

Browse files
author
Derek Jones
committed
Implementation and documentation for 1.0.0
1 parent dd6d2ee commit 94b6998

File tree

6 files changed

+362
-0
lines changed

6 files changed

+362
-0
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.{php,js,css,json,xml,json}]
10+
indent_style = tab
11+
indent_size = 4
12+
13+
[*.md]
14+
indent_style = space
15+
indent_size = 4
16+
trim_trailing_whitespace = false
17+
18+
[*.{rst,rb},package.json,yml]
19+
indent_style = space
20+
indent_size = 2

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,15 @@ install:
1313
script:
1414
- vendor/jakub-onderka/php-parallel-lint/parallel-lint --exclude vendor .
1515

16+
before_deploy: "zip -r 'Gravatar' gravatar"
1617

18+
deploy:
19+
provider: releases
20+
api_key:
21+
secure: FbsYty/+8Nh8NeHirzAzjTj5V+KqA2Yz/Q/ajrG4Uq5kjlHO3HsY+oXz634h7exG+DYZpRFwSX80x0jBMgVMu9BVCF024o6Ets66YX/URlihwWA1VuP5adPO9iwxvJpD9adjDiKeoYwII4AXSxlpGmek7F+ym1Qh8vtdcS6eUP348NfNuJQty3ZIOtxE97lI317rR04st9NMDwCptAtCVUS7NApkIu2H26EhvTx9JG+vPtdl/RrWF/OkX0eoCxYdCgcPw2fixsBzVmUxxleuCD7GotEwOrQFJvIbk9Hw0Zc6bPmZLRSjIJ3/iprBGHr4QlNueJ5pLEnCCxT4VEvhMIRtAH5Ib39tpPiD97uYKRoIFFeHDxrvmHtx2MosQWRDbRFLh+aBPfInx/B3Xfcm2Lj9IZK1tOFwna966ESYXMLnHNFynHCk58flgaY9/GVF+d8Du527HmeJ36IQl5U07XyGmtq2XUnA3WKwvYklOotXcH4pDe+eGrxiLOYBkbBDdhjDtd7vz/NvbDHyxrjtMwqU8awyjoYKi63n+1pKF+J+NVZMeTOlMUmOgOuimj9vNrYWWRsugzd+xcWckFZo8jjSp0Q46i9fmHdtIciRM8XUmPZadzN97ykIgGLRUOozgVClQ/DhtTZrVnsUjkmfsfRYMl6pbtQ+u+Tzcli0KYo=
22+
file: "Gravatar.zip"
23+
skip_cleanup: true
24+
on:
25+
php: 7.0
26+
tags: true
27+
condition: $TRAVIS_PULL_REQUEST = false

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gravatar/README.md

gravatar/README.md

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Gravatar
2+
3+
Outputs a Globally Recognized Avatar ([Gravatar](http://gravatar.com)), with a plethora of customization options, including [Adorable Avatars](http://avatars.adorable.io).
4+
5+
## Requirements
6+
7+
- ExpressionEngine 3
8+
- PHP 5.4+
9+
- Uses [Gravatar lib from @forxer](https://github.com/forxer/gravatar), included.
10+
11+
## Installation
12+
13+
1. Download the [latest release](https://github.com/EllisLab/Gravatar/releases/latest).
14+
2. Copy the `gravatar` folder to your `system/user/addons` folder (you can ignore the rest of this repository's files).
15+
3. In your ExpressionEngine control panel, visit the Add-On Manager and click Install next to "Gravatar".
16+
17+
## Usage
18+
19+
### `{exp:gravatar}`
20+
21+
#### Example Usage
22+
23+
The Gravatar is a single tag plugin that is most commonly used in an `img` tag:
24+
25+
```
26+
<img src="{exp:gravatar email='[email protected]'}" alt="username's avatar">
27+
```
28+
29+
#### Parameters
30+
31+
##### email= (*required*)
32+
33+
Email address for the gravatar user. This will typically come from a variable, e.g.:
34+
35+
```
36+
{exp:gravatar email='{email}'}
37+
```
38+
39+
##### size=
40+
41+
The size of the resulting image, in pixels.
42+
43+
##### default=
44+
45+
The default image to use as a fallback when the provided email address has no Gravatar profile. Valid options are:
46+
47+
- `adorable` - an adorable avatar unique for the email identifier from [Adorable Avatars](http://avatars.adorable.io)
48+
- `blank` - a transparent PNG image (border added to HTML below for demonstration purposes)
49+
- `identicon` - a geometric pattern based on an email hash
50+
- `mm` (default) - (mystery-man) a simple, cartoon-style silhouetted outline of a person (does not vary by email hash)
51+
- `monsterid` - a generated 'monster' with different colors, faces, etc
52+
- `retro` - awesome generated, 8-bit arcade-style pixelated faces
53+
- `wavatar` - generated faces with differing features and backgrounds
54+
- URL, e.g.: `https://example.com/avatar.png` - any full URL to a publicly available image
55+
56+
Note: Gravatar's `404` response default image type is not supported.
57+
58+
##### rating=
59+
60+
The maximum self-rated threshold for image content. Valid options are:
61+
62+
- `g` - suitable for display on all websites with any audience type.
63+
- `pg` (default) - may contain rude gestures, provocatively dressed individuals, the lesser swear words, or mild violence.
64+
- `r` - may contain such things as harsh profanity, intense violence, nudity, or hard drug use.
65+
- `x` - may contain hardcore sexual imagery or extremely disturbing violence.
66+
67+
##### extension=
68+
69+
The desired image type, by file extension. Valid options are:
70+
71+
- `gif`
72+
- `jpeg`
73+
- `jpg`
74+
- `png` (default)
75+
76+
##### https=
77+
78+
Whether or not the image should be served securely. If an unsecure request is made from a secure (SSL) page, the browser will issue security warnings. You should be able to leave this setting at its default value, because you're already using SSL everywhere, right? Right??
79+
80+
- `yes` (default) - URL will use `https://`
81+
- `no` - URL will use `http://`
82+
83+
##### force_default=
84+
85+
Whether or not you'd like to force the use of default avatar images instead of using images from Gravatar profiles. This is useful during development with mock data, or for sites that want public avatars to all have the same look and feel, either by using one of Gravatar's default generators, the Adorable Avatar generator, or any similar service.
86+
87+
- `yes` - Returned image will always return your default image preference
88+
- `no` (default) - Returned image will be the user's Gravatar profile image, or the default image if one is not available
89+
90+
Example: all monsters, all the time:
91+
92+
```
93+
{exp:gravatar email='{email}' default='monsterid' force_default='yes'}
94+
```
95+
96+
## Change Log
97+
98+
### 1.0.0
99+
100+
- Initial release. Boom!
101+
102+
## Additional Files
103+
104+
You may be wondering what the rest of the files in this package are for. They are solely for development, so if you are forking the GitHub repo, they can be helpful. If you are just using the add-on in your ExpressionEngine installation, you can ignore all of these files.
105+
106+
- **.editorconfig**: [EditorConfig](http://editorconfig.org) helps developers maintain consistent coding styles across files and text editors.
107+
- **.gitignore:** [.gitignore](https://git-scm.com/docs/gitignore) lets you specify files in your working environment that you do not want under source control.
108+
- **.travis.yml:** A [Travis CI](https://travis-ci.org) configuration file for continuous integration (automated testing, releases, etc.).
109+
- **.composer.json:** A [Composer project setup file](https://getcomposer.org/doc/01-basic-usage.md) that manages development dependencies.
110+
- **.composer.lock:** A [list of dependency versions](https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file) that Composer has locked to this project.
111+
112+
## License
113+
114+
Copyright (C) 2016 EllisLab, Inc.
115+
116+
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:
117+
118+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
119+
120+
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 ELLISLAB, INC. 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.
121+
122+
Except as contained in this notice, the name of EllisLab, Inc. shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from EllisLab, Inc.

gravatar/addon.setup.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
return array(
4+
'author' => 'EllisLab',
5+
'author_url' => 'https://ellislab.com/',
6+
'name' => 'Gravatar',
7+
'description' => 'Outputs Globally Recognized Avatars (Gravatars) for a given email address',
8+
'version' => '1.0.0',
9+
'namespace' => 'User\Addons\Gravatar',
10+
'settings_exist' => FALSE
11+
);

gravatar/pi.gravatar.php

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2+
3+
require 'vendor/autoload.php';
4+
5+
use forxer\Gravatar\Gravatar as FGravatar;
6+
7+
/*
8+
Copyright (C) 2004 - 2016 EllisLab, Inc.
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in
18+
all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
ELLISLAB, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
Except as contained in this notice, the name of EllisLab, Inc. shall not be
28+
used in advertising or otherwise to promote the sale, use or other dealings
29+
in this Software without prior written authorization from EllisLab, Inc.
30+
*/
31+
32+
/**
33+
* Gravatar Class
34+
*
35+
* @package ExpressionEngine
36+
* @category Plugin
37+
* @author EllisLab
38+
* @copyright Copyright (c) 2016, EllisLab, Inc.
39+
* @link https://github.com/EllisLab/Gravatar
40+
*/
41+
class Gravatar {
42+
43+
/*
44+
* @var string The plugin return data, since we use the constructor for our lifting
45+
*/
46+
public $return_data;
47+
48+
/*
49+
* @var string Email address identifier
50+
*/
51+
private $email;
52+
53+
/*
54+
* @var int Default image size in pixels
55+
*/
56+
private $size = 80;
57+
58+
/*
59+
* @var string Default image URL
60+
*/
61+
private $default = 'mm';
62+
63+
/*
64+
* @var string Maximum allowed rating
65+
*/
66+
private $rating = 'pg';
67+
68+
/*
69+
* @var string File type extension
70+
*/
71+
private $extension = 'png';
72+
73+
/*
74+
* @var bool https
75+
*/
76+
private $https = TRUE;
77+
78+
/*
79+
* @var bool Force Default Image
80+
*/
81+
private $force_default = FALSE;
82+
83+
/*
84+
* @var string Base URL for Adorable Avatars, http://avatars.adorable.io/
85+
*/
86+
private $adorable_base_url = 'https://api.adorable.io/avatars/';
87+
88+
/**
89+
* Constructor
90+
*
91+
* @access public
92+
* @return void
93+
*/
94+
public function __construct($str = '')
95+
{
96+
if ( ! $this->setOptionsFromParameters())
97+
{
98+
ee()->TMPL->log_item('<b>Gravatar:</b> Aborted!');
99+
return FALSE;
100+
}
101+
102+
$gravatar = FGravatar::image(
103+
$this->email,
104+
$this->size,
105+
$this->default,
106+
$this->rating,
107+
$this->extension,
108+
$this->https,
109+
$this->force_default
110+
);
111+
112+
// bug in current forxer\Gravatar
113+
// Full URLs given as the default image are double encoded
114+
if (strncasecmp($this->default, 'http', 4) === 0)
115+
{
116+
$url = parse_url($gravatar);
117+
parse_str(html_entity_decode($url['query']), $default_url);
118+
$default_url['d'] = rawurldecode($default_url['d']);
119+
$gravatar = $url['scheme'].'://'.$url['host'].$url['path'].'?'.http_build_query($default_url);
120+
}
121+
122+
$this->return_data = $gravatar;
123+
}
124+
125+
// ------------------------------------------------------------------------
126+
127+
/**
128+
* Set Options from Parameters
129+
*
130+
* @return bool FALSE when required parameters are not present
131+
*/
132+
private function setOptionsFromParameters()
133+
{
134+
// order here is imporant!
135+
136+
// Email
137+
if ( ! $this->email = ee()->TMPL->fetch_param('email'))
138+
{
139+
ee()->TMPL->log_item('<b>Gravatar:</b> Email required, nothing to do');
140+
return FALSE;
141+
}
142+
143+
// Size
144+
$this->size = (ee()->TMPL->fetch_param('size')) ?: $this->size;
145+
146+
// Default Image
147+
$default = ee()->TMPL->fetch_param('default');
148+
switch ($default)
149+
{
150+
case FALSE:
151+
$this->default = $this->default;
152+
break;
153+
case 'adorable':
154+
$this->default = $this->adorable_base_url.$this->size.'/'.$this->email;
155+
break;
156+
case 'mm':
157+
case 'identicon':
158+
case 'monsterid':
159+
case 'wavatar':
160+
case 'retro':
161+
case 'blank':
162+
default:
163+
$this->default = $default;
164+
}
165+
166+
// Max Rating
167+
if (in_array(strtolower(ee()->TMPL->fetch_param('rating')), ['g', 'pg', 'r', 'x']))
168+
{
169+
$this->rating = ee()->TMPL->fetch_param('rating');
170+
}
171+
172+
// Image Extension
173+
if (in_array(strtolower(ee()->TMPL->fetch_param('extension')), ['jpg', 'jpeg', 'gif', 'png']))
174+
{
175+
$this->rating = ee()->TMPL->fetch_param('extension');
176+
}
177+
178+
// HTTPS
179+
if (ee()->TMPL->fetch_param('https'))
180+
{
181+
$this->https = get_bool_from_string(ee()->TMPL->fetch_param('https'));
182+
}
183+
184+
// Force Default Image
185+
if (ee()->TMPL->fetch_param('force_default'))
186+
{
187+
$this->force_default = get_bool_from_string(ee()->TMPL->fetch_param('force_default'));
188+
}
189+
190+
return TRUE;
191+
}
192+
193+
// ------------------------------------------------------------------------
194+
}
195+
// END CLASS
196+
197+
// EOF

0 commit comments

Comments
 (0)