Skip to content

Commit ea6df9c

Browse files
committed
Added get_gravatar function and README file
1 parent 82173ad commit ea6df9c

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Gravatar Helper Spark for CodeIgniter
3+
============================
4+
5+
[Gravatar](http://gravatar.com) Helper functions to utilize with [CodeIgniter](http://codeigniter.com) 2.x and 3.x or Standard PHP Application.
6+
7+
8+
Usage
9+
-------------------------------------
10+
11+
1. Copy `gravatar_helper.php` to your `application/helpers` folder.
12+
2. Autoload the helper in `application/config/autoload.php`: $autoload['helper'] = array('gravatar');
13+
3. Use helper functions as needed.
14+
15+
16+
Examples
17+
-------------------------------------
18+
19+
/**
20+
* Get either a Gravatar URL or complete image tag for a specified email address.
21+
*
22+
* @param string $email The email address
23+
* @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ]
24+
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
25+
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
26+
* @param bool $img True to return a complete IMG tag False for just the URL
27+
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
28+
* @return String containing either just a URL or a complete image tag
29+
*/
30+
31+
<?php echo gravatar( '[email protected]', 180 )?>
32+
33+
34+
License
35+
-------------------------------------
36+
37+
© 2016 Omkar Tapale. All Rights Reserved.
38+
39+
Released under the MIT License: [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)
40+
41+
42+

helpers/gravatar_helper.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
defined('BASEPATH') OR exit('No direct script access allowed');
3+
4+
/**
5+
* CodeIgniter Gravatar Helper
6+
*
7+
* Gravatar Helper functions to utilize with Codeigniter 2.x and 3.x
8+
* or Standard PHP Application.
9+
*
10+
* @package CodeIgniter Gravatar
11+
* @subpackage Helpers
12+
* @category Helpers
13+
* @author Omkar Tapale
14+
* @copyright 2016 Omkar Tapale
15+
* @license MIT
16+
* @license http://www.opensource.org/licenses/mit-license.php
17+
* @version v1.0.0
18+
*
19+
* The latest version of CodeIgniter Gravatar Helper can be obtained from:
20+
* https://github.com/omkartapale/CodeIgniter-Gravatar-Helper
21+
*/
22+
23+
24+
if (!function_exists('get_gravatar')) {
25+
26+
/**
27+
* Get either a Gravatar URL or complete image tag for a specified email address.
28+
*
29+
* @param string $email The email address
30+
* @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ]
31+
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
32+
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
33+
* @param bool $img True to return a complete IMG tag False for just the URL
34+
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
35+
* @return String containing either just a URL or a complete image tag
36+
* @source http://gravatar.com/site/implement/images/php/
37+
*/
38+
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
39+
$url = 'http://www.gravatar.com/avatar/';
40+
$url .= md5( strtolower( trim( $email ) ) );
41+
$url .= "?s=$s&d=$d&r=$r";
42+
if ( $img ) {
43+
$url = '<img src="' . $url . '"';
44+
foreach ( $atts as $key => $val )
45+
$url .= ' ' . $key . '="' . $val . '"';
46+
$url .= ' />';
47+
}
48+
return $url;
49+
}
50+
}

0 commit comments

Comments
 (0)