From e420e3ad72eb8365617df61b4f8f4250168c8f7e Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Tue, 6 Nov 2012 08:32:09 -0500 Subject: [PATCH] Moved Gravatar hash function to a dedicated Gravatar class --- classes/API/Gravatar.php | 42 +++++++++++++++++++++++++++++++++++++++ classes/String.php | 4 ++-- jar.php | 43 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 classes/API/Gravatar.php diff --git a/classes/API/Gravatar.php b/classes/API/Gravatar.php new file mode 100644 index 0000000..39fcf02 --- /dev/null +++ b/classes/API/Gravatar.php @@ -0,0 +1,42 @@ + + * @copyright Copyright 2007-2012, Josh Sherman + * @license http://www.opensource.org/licenses/mit-license.html + * @package PICKLES + * @link https://github.com/joshtronic/pickles + */ + +/** + * Gravatar API Interface + * + * @link http://en.gravatar.com/site/implement/ + */ +class API_Gravatar extends API_Common +{ + /** + * Hash + * + * Generates a hash from the passed string that can then be used for + * fetching an image or profile from Gravatar.com + * + * @static + * @param string $string string to hash, should be an email address + * @return string resulting hash + */ + public static function hash($string) + { + // Trims whitespace, lowers the case then applies MD5 + return md5(strtolower(trim($string))); + } +} + +?> diff --git a/classes/String.php b/classes/String.php index e9f7821..ac1498b 100644 --- a/classes/String.php +++ b/classes/String.php @@ -53,14 +53,14 @@ class String * Generates a hash from the passed string that can then be used for * fetching an avatar from Gravatar.com * + * @deprecated * @static * @param string $string string to hash, should be an email address * @return string resulting hash */ public static function generateGravatarHash($string) { - // Trims whitespace, lowers the case then applies MD5 - return md5(strtolower(trim($string))); + return API_Gravatar::hash($string); } // }}} diff --git a/jar.php b/jar.php index 56b6155..26c4865 100755 --- a/jar.php +++ b/jar.php @@ -84,6 +84,45 @@ class API_Google_Profanity extends API_Common } } +/** + * Gravatar Class File for PICKLES + * + * PHP version 5 + * + * Licensed under The MIT License + * Redistribution of these files must retain the above copyright notice. + * + * @author Josh Sherman + * @copyright Copyright 2007-2012, Josh Sherman + * @license http://www.opensource.org/licenses/mit-license.html + * @package PICKLES + * @link https://github.com/joshtronic/pickles + */ + +/** + * Gravatar API Interface + * + * @link http://en.gravatar.com/site/implement/ + */ +class API_Gravatar extends API_Common +{ + /** + * Hash + * + * Generates a hash from the passed string that can then be used for + * fetching an image or profile from Gravatar.com + * + * @static + * @param string $string string to hash, should be an email address + * @return string resulting hash + */ + public static function hash($string) + { + // Trims whitespace, lowers the case then applies MD5 + return md5(strtolower(trim($string))); + } +} + /** * Tinychat Class File for PICKLES * @@ -6970,14 +7009,14 @@ class String * Generates a hash from the passed string that can then be used for * fetching an avatar from Gravatar.com * + * @deprecated * @static * @param string $string string to hash, should be an email address * @return string resulting hash */ public static function generateGravatarHash($string) { - // Trims whitespace, lowers the case then applies MD5 - return md5(strtolower(trim($string))); + return API_Gravatar::hash($string); } // }}}