MyBB Community Forums

Full Version: gravatar plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I made a few modifications to the gravatar plugin to support requesting a gravatar through SSL. Essentially, it adds a toggle in the gravatar config settings to enable/disable using SSL. This is useful for all of you running a forum with SSL support so that IE users don't get that security warning.

If you know how I can get ahold of the original author, that'd be great, so that I could submit this to him directly.

A patch for the current version of the gravatar plugin follows (sorry, it won't let me just attach it):

gravatar.php.patch
--- inc/plugins/gravatar.php    2008-10-20 21:16:38.000000000 -0700
+++ inc/plugins/gravatar.php.ssl        2008-12-18 13:51:30.000000000 -0800
@@ -35,6 +35,7 @@
 //Run when the plugin is activated.
 function gravatar_activate(){
        newSettingGroup('gravatar','Gravatar Settings','Gravatar Plugin Settings',11);
+       newSetting('gravatar_ssl', 'SSL Gravatars', 'Use SSL for requesting Gravatars?','yesno',0,4);
        newSetting('gravatar_rating', 'Maximum Gravatar Rating', 'What is the highest rating for Gravatars allowed on your forum - G, PG, R or X?','text','r
',1);
        newSetting('gravatar_size','Gravatar Size','The width/height of Gravatars?','text','60',2);
        newSetting('gravatar_default','Default Gravatar', 'If the user does not have a Gravatar, what should the default be?<br/>Leave as "http://" for no d
efault.','text','http://',3);
@@ -42,6 +43,7 @@
 
 //Run when the plugin is deactivated.
 function gravatar_deactivate(){
+       removeSetting('gravatar_ssl');
        removeSetting('gravatar_rating');
        removeSetting('gravatar_size');
        removeSetting('gravatar_default');
@@ -58,22 +60,27 @@
 
 //Build the Gravatar url.
 function gravatar_urlDetails(){
-global $gravURL, $mybb;
+global $gravURL, $gravBaseURL, $mybb;
        $gravDef = '?d='.urlencode($mybb->settings['gravatar_default']);
        $gravSiz = '&s='.$mybb->settings['gravatar_size'];
        $gravRat = '&r='.$mybb->settings['gravatar_rating'];
        $gravURL = $gravDef.$gravSiz.$gravRat;
+       if($mybb->settings['gravatar_ssl'] == 1){
+               $gravBaseURL = 'https://secure.gravatar.com/avatar/';
+       } else {
+               $gravBaseURL = 'http://gravatar.com/avatar/';
+       }
 }
 
 //This function does what it says in the name.
 function gravatar_createForPost($post){
-       global $templates, $gravURL;
+       global $templates, $gravURL, $gravBaseURL;
        
        gravatar_urlDetails();
        
        //If the user does not already have an avatar.
        if($post['avatar']==''){
-               $post['avatar'] = htmlspecialchars_uni('http://gravatar.com/avatar/'.md5($post['email']));
+               $post['avatar'] = htmlspecialchars_uni($gravBaseURL.md5($post['email']));
                $post['avatar'] .= $gravURL;
                eval('$post["useravatar"] = "'.$templates->get('postbit_avatar').'";');
        }
@@ -81,26 +88,26 @@
 
 //This function does what it says in the name.
 function gravatar_createForMemberlist(){
-       global $templates, $user, $gravURL;
+       global $templates, $user, $gravURL, $gravBaseURL;
 
        gravatar_urlDetails();
        
        //If the user does not already have an avatar.
        if($user['avatar']==''){
-               $user['avatar'] = htmlspecialchars_uni('http://gravatar.com/avatar/'.md5($user['email']));
+               $user['avatar'] = htmlspecialchars_uni($gravBaseURL.md5($user['email']));
                $user['avatar'] .= $gravURL;
        }
 }
 
 //This function does what it says in the name.
 function gravatar_createForProfile(){
-       global $memprofile, $avatar, $avatar_width_height, $gravURL;
+       global $memprofile, $avatar, $avatar_width_height, $gravURL, $gravBaseURL;
        
        gravatar_urlDetails();
        
        //If the user does not already have an avatar.
        if($memprofile['avatar']==''){
-               $avatar = htmlspecialchars_uni('http://gravatar.com/avatar/'.md5($memprofile['email']));
+               $avatar = htmlspecialchars_uni($gravBaseURL.md5($memprofile['email']));
                $avatar .= $gravURL;
                $avatar = '<img src="'.$avatar.'" alt="" '.$avatar_width_height.' />';
        }
@@ -108,15 +115,15 @@
 
 //This function does what it says in the name.
 function gravatar_createForUCP(){
-       global $mybb, $templates, $gravURL;
+       global $mybb, $templates, $gravURL, $gravBaseURL;
        
        gravatar_urlDetails();
        
        //If the user does not already have an avatar.
        if($mybb->user['avatar']==''){
-               $mybb->user['avatar'] = htmlspecialchars_uni('http://gravatar.com/avatar/'.md5($mybb->user['email']));
+               $mybb->user['avatar'] = htmlspecialchars_uni($gravBaseURL.md5($mybb->user['email']));
                $mybb->user['avatar'] .= $gravURL;
                eval('$avatar = "'.$templates->get('usercp_currentavatar').'";');
        }
Ahh go nuts with mods, though I did actually make a signifigant update to the plugin that MyBB Mods never validated, so which I then removed. Though its done in a completely different way, so you may prefer my original one. Its been a long time since I've touched it though:
http://dredgy.com/misc/mybb/Gravatar.zip
I know this is an old thread, but I've thought of a better integration. MyBB has an avatartype field in the users table. Currently MyBB uses gallery to mean it's a standard avatar from the gallery, upload for uploaded avatars, and remote for remote URLs. Nothing prevents us from using a custom value (gravatar) to indicate that that user should use their gravatar.