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