Skip to content

Commit

Permalink
Added get_gravatar function and README file
Browse files Browse the repository at this point in the history
  • Loading branch information
omkartapale committed Feb 1, 2016
1 parent 82173ad commit ea6df9c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

Gravatar Helper Spark for CodeIgniter
============================

[Gravatar](http://gravatar.com) Helper functions to utilize with [CodeIgniter](http://codeigniter.com) 2.x and 3.x or Standard PHP Application.


Usage
-------------------------------------

1. Copy `gravatar_helper.php` to your `application/helpers` folder.
2. Autoload the helper in `application/config/autoload.php`: $autoload['helper'] = array('gravatar');
3. Use helper functions as needed.


Examples
-------------------------------------

/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param bool $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
*/

<?php echo gravatar( '[email protected]', 180 )?>


License
-------------------------------------

© 2016 Omkar Tapale. All Rights Reserved.

Released under the MIT License: [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php)



50 changes: 50 additions & 0 deletions helpers/gravatar_helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
* CodeIgniter Gravatar Helper
*
* Gravatar Helper functions to utilize with Codeigniter 2.x and 3.x
* or Standard PHP Application.
*
* @package CodeIgniter Gravatar
* @subpackage Helpers
* @category Helpers
* @author Omkar Tapale
* @copyright 2016 Omkar Tapale
* @license MIT
* @license http://www.opensource.org/licenses/mit-license.php
* @version v1.0.0
*
* The latest version of CodeIgniter Gravatar Helper can be obtained from:
* https://github.com/omkartapale/CodeIgniter-Gravatar-Helper
*/


if (!function_exists('get_gravatar')) {

/**
* Get either a Gravatar URL or complete image tag for a specified email address.
*
* @param string $email The email address
* @param int $s Size in pixels, defaults to 80px [ 1 - 2048 ]
* @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
* @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
* @param bool $img True to return a complete IMG tag False for just the URL
* @param array $atts Optional, additional key/value attributes to include in the IMG tag
* @return String containing either just a URL or a complete image tag
* @source http://gravatar.com/site/implement/images/php/
*/
function get_gravatar( $email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array() ) {
$url = 'http://www.gravatar.com/avatar/';
$url .= md5( strtolower( trim( $email ) ) );
$url .= "?s=$s&d=$d&r=$r";
if ( $img ) {
$url = '<img src="' . $url . '"';
foreach ( $atts as $key => $val )
$url .= ' ' . $key . '="' . $val . '"';
$url .= ' />';
}
return $url;
}
}

0 comments on commit ea6df9c

Please sign in to comment.