Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Gender to determine default avatar

2»

Comments

  • Options

    @peregrine‌ , Thanks so much, the plugin works exactly what I wanted!

  • Options

    @peregrine said:
    make a defaultu.png defaultm.png and a defaultf.png

    This was very smart, however it is not working on the Profile image with width 200. I couldn't see the problem there.

  • Options

    there are two areas in code you probably missed one! as well as think about what your are doing.

    the profile one calls
    plugins/Gravatar/default_250.png'

    so you would need to call it default_250

    to evaluate to default_250m.png, default_250f.png and default_250u.png

    to work with the 3 250 sized png files.

     public function ProfileController_AfterAddSideMenu_Handler($Sender, $Args) {
          if (!$Sender->User->Photo) {
             $Email = GetValue('Email', $Sender->User);
             $Protocol = Gdn::Request()->Scheme() == 'https' ? 'https://secure.' : 'http://www.';
    
             $Url = $Protocol.'gravatar.com/avatar.php?'
                .'gravatar_id='.md5(strtolower($Email))
                .'&size='.C('Garden.Profile.MaxWidth', 200);
    
             if (C('Plugins.Gravatar.UseVanillicon', TRUE)) {
                $Url .= '&default='.urlencode(Gdn::Request()->Scheme().'://vanillicon.com/'.md5($Email).'_200.png');
            } else {
           //     $Url .= '&default='.urlencode(Asset(C('Plugins.Gravatar.DefaultAvatar', 'plugins/Gravatar/default_250.png'), TRUE));
     $webroot = Gdn_Url::WebRoot();
    $webhost = $_SERVER["HTTP_HOST"];
    $Gender = GetValue('Gender', $User);
    $Url = "http://$webhost/$webroot/plugins/Gravatar/default_250.png$Gender.png";
          }
             $Sender->User->Photo = $Url;
          }
       }
    }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    gohuntergohunter
    edited April 2014

    empty

  • Options
    gohuntergohunter
    edited April 2014

    That is right.

    Thats what I did, and it is not injecting the gender to file name and pulling the right one.

    here is my code:

    class GravatarPlugin extends Gdn_Plugin {
       public function ProfileController_AfterAddSideMenu_Handler($Sender, $Args) {
          if (!$Sender->User->Photo) {
             $Email = GetValue('Email', $Sender->User);
             $Protocol =  Gdn::Request()->Scheme() == 'https' ? 'https://secure.' : 'http://www.';
    
             $Url = $Protocol.'gravatar.com/avatar.php?'
                .'gravatar_id='.md5(strtolower($Email))
                .'&size='.C('Garden.Profile.MaxWidth', 200);
    
             if (C('Plugins.Gravatar.UseVanillicon', TRUE))
                $Url .= '&default='.urlencode(Gdn::Request()->Scheme().'://vanillicon.com/'.md5($Email).'_200.png');
             else {
                $webroot = Gdn_Url::WebRoot();
                $webhost = $_SERVER["HTTP_HOST"];
                $Gender = GetValue('Gender', $User); 
                $Url = "http://localhost/uploads/Avatar/default_200$Gender.png";
            }
    
             $Sender->User->Photo = $Url;
          }
       }
    }
    
    
    
    if (!function_exists('UserPhotoDefaultUrl')) {
       function UserPhotoDefaultUrl($User) {
          $Email = GetValue('Email', $User);
          $Https = Gdn::Request()->Scheme() == 'https';
          $Protocol = $Https ? 'https://secure.' : 'http://www.';
    
          $Url = $Protocol.'gravatar.com/avatar.php?'
             .'gravatar_id='.md5(strtolower($Email))
             .'&size='.C('Garden.Thumbnail.Width', 50);
             
          if (C('Plugins.Gravatar.UseVanillicon', TRUE))
             $Url .= '&default='.urlencode(Gdn::Request()->Scheme().'://vanillicon.com/'.md5($Email).'.png');
          else  {
             $webroot = Gdn_Url::WebRoot();
             $webhost = $_SERVER["HTTP_HOST"];
             $Gender = GetValue('Gender', $User); 
             $Url = "http://$webhost/uploads/Avatar/default$Gender.png";
          }
          
          return $Url;
       }
    }
    
    
  • Options
    gohuntergohunter
    edited April 2014

    and this is what is getting getting pulled without the gender.

    
    
  • Options
    peregrineperegrine MVP
    edited April 2014

    try this

        public function ProfileController_AfterAddSideMenu_Handler($Sender, $Args) {
            if (!$Sender->User->Photo) {
                $Email = GetValue('Email', $Sender->User);
                $Protocol = Gdn::Request()->Scheme() == 'https' ? 'https://secure.' : 'http://www.';
    
                $Url = $Protocol . 'gravatar.com/avatar.php?'
                        . 'gravatar_id=' . md5(strtolower($Email))
                        . '&size=' . C('Garden.Profile.MaxWidth', 200);
    
    
    
                if (C('Plugins.Gravatar.UseVanillicon', TRUE))
                    $Url .= '&default=' . urlencode(Gdn::Request()->Scheme() . '://vanillicon.com/' . md5($Email) . '_200.png');
                else {
                    $webroot = Gdn_Url::WebRoot();
                    $webhost = $_SERVER["HTTP_HOST"];
                    $Gender = GetValue('Gender', $User);
                    if (($Gender != "m") || ($Gender != "f"))
                        $Gender = "u";
    
                    $Url = "http://$webhost/$webroot/plugins/Gravatar/default_200$Gender.png";
                }
                $Sender->User->Photo = $Url;
            }
        }
    
    }
    
    if (!function_exists('UserPhotoDefaultUrl')) {
    
        function UserPhotoDefaultUrl($User) {
            $Email = GetValue('Email', $User);
            $Https = Gdn::Request()->Scheme() == 'https';
            $Protocol = $Https ? 'https://secure.' : 'http://www.';
    
            $Url = $Protocol . 'gravatar.com/avatar.php?'
                    . 'gravatar_id=' . md5(strtolower($Email))
                    . '&size=' . C('Garden.Thumbnail.Width', 50);
    
    
    
    
            if (C('Plugins.Gravatar.UseVanillicon', TRUE)) {
                $Url .= '&default=' . urlencode(Gdn::Request()->Scheme() . '://vanillicon.com/' . md5($Email) . '.png');
            } else {
                $webroot = Gdn_Url::WebRoot();
                $webhost = $_SERVER["HTTP_HOST"];
                $Gender = GetValue('Gender', $User);
                if (($Gender != "m") || ($Gender != "f"))
                    $Gender = "u";
                $Url = "http://$webhost/$webroot/plugins/Gravatar/default$Gender.png";
            }
            return $Url;
        }
    
    }
    

    and make sure you have images for

    defaultu.png
    defaultm.png
    defaultf.png

    default_200u.png
    default_200m.png
    default_200f.png

    default_250u.png
    default_250m.png
    default_250f.png

    in the /plugins/Gravatar/ folder

    if you deviate, I can't help you much past that.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited April 2014

    on second thought use this code.
    on second thought use this code.

        public function ProfileController_AfterAddSideMenu_Handler($Sender, $Args) {
            if (!$Sender->User->Photo) {
                $Email = GetValue('Email', $Sender->User);
                $Protocol = Gdn::Request()->Scheme() == 'https' ? 'https://secure.' : 'http://www.';
                $Url = $Protocol . 'gravatar.com/avatar.php?'
                        . 'gravatar_id=' . md5(strtolower($Email))
                        . '&size=' . C('Garden.Profile.MaxWidth', 200);
    
                if (C('Plugins.Gravatar.UseVanillicon', TRUE)) {
                    $Url .= '&default=' . urlencode(Gdn::Request()->Scheme() . '://vanillicon.com/' . md5($Email) . '_200.png');
               } else {
                    $webroot = Gdn_Url::WebRoot();
                    $webhost = $_SERVER["HTTP_HOST"];
                    $Gender = $Sender->User->Gender;
             if (($Gender != "m") && ($Gender != "f"))  $Gender = "u";     
                    $Url = "http://$webhost/$webroot/plugins/Gravatar/default_200$Gender.png";
                }
                $Sender->User->Photo = $Url;
            }
        }
    
    }
    
    if (!function_exists('UserPhotoDefaultUrl')) {
    
        function UserPhotoDefaultUrl($User) {
            $Email = GetValue('Email', $User);
            $Https = Gdn::Request()->Scheme() == 'https';
            $Protocol = $Https ? 'https://secure.' : 'http://www.';
            $Url = $Protocol . 'gravatar.com/avatar.php?'
                    . 'gravatar_id=' . md5(strtolower($Email))
                    . '&size=' . C('Garden.Thumbnail.Width', 50);
    
            if (C('Plugins.Gravatar.UseVanillicon', TRUE)) {
                $Url .= '&default=' . urlencode(Gdn::Request()->Scheme() . '://vanillicon.com/' . md5($Email) . '.png');
            } else {
                $webroot = Gdn_Url::WebRoot();
                $webhost = $_SERVER["HTTP_HOST"];
                $Gender = GetValue('Gender', $User);
            if (($Gender != "m") && ($Gender != "f"))  $Gender = "u";
                $Url = "http://$webhost/$webroot/plugins/Gravatar/default$Gender.png";
            }
            return $Url;
        }
    

    and make sure you have images for

    defaultu.png
    defaultm.png
    defaultf.png

    default_200u.png
    default_200m.png
    default_200f.png

    in the /plugins/Gravatar/ folder

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    @peregrine‌ ;

    I appreciate your help, finally :'( it works.

    It was not working until I had to delete the $Gender = "u"... that took me for a while lol...

    I was like keep holding and holding to not post it until solve it by myself as if I post it again with it is being not working, I know I would discourage you. :)

    But it works now!!

    btw, eventhough the path was pointing to a different folder than plugins, it still works. Sweet aint it?

  • Options

    worked with:

    if (($Gender != "m") || ($Gender != "f"));
  • Options
    peregrineperegrine MVP
    edited April 2014

    btw, eventhough the path was pointing to a different folder than plugins, it still works. Sweet aint it?

    all you have done, is take compartmentalization away. one would think images related to plugin would be better in the plugin itself. you could make it point anywhere, doesn't mean its a good idea though.

    suit your self

    this makes absolutely no sense.

    worked with:
    
        if (($Gender != "m") || ($Gender != "f"));
    

    it does absolutely nothing except to add a test that does absolutely nothing - nonsense code.

    if you cut and paste what I posted will indeed work. http://vanillaforums.org/discussion/comment/206486/#Comment_206486 and ensure the 6 images I posted are in your plugin location. The code posted will ensure it will work when you upgrade to 2.1 as well.

    that said. I surrender. use what you want.

    I advise you run through a php tutorial.

    glad you had some success though.

    but you failed to answer hgtonights question What version number of Vanilla are you running?

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    gohuntergohunter
    edited April 2014

    :)

    Thanks @peregrine‌ for helping me.

    You're correct, I need extensive training on php development and I really appreciate for your patience.

    Currently, I'm learning almost everything in webdevelopment at the same time. Perhaps that is why I am creating some painfully stupid simple questions on coding for those who know what they are doing. Every single code, I try to dig and understand as much as possible.

    Well... officially, I graduated as a graphic designer and illustrator and have worked extensively in print, ad, motion design field. Now I'm wanting to learn more into programming side...

    I hope you all patiently understand my transformation and learning process, but it is really painful.

    Thank you!

    oh, for @hgtonight‌'s question: Version 2.1rc1 just updated to 2.1

    I thought I mentioned my current version several times right before posting this discussion. I apologize for that.

  • Options
    peregrineperegrine MVP
    edited April 2014

    I thought I mentioned my current version several times right before posting this discussion. I apologize for that.

    no problem.

    Currently, I'm learning almost everything in webdevelopment at the same time

    yes. many of us did what you are doing, learning all at the same time and. it gets easier with practice, if you find coding interesting. and probably all of us are still learning.

    each new discussion is a new discussion topic . Assume no one read other discussions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    peregrineperegrine MVP
    edited April 2014

    @gohunter

    Since you said you are using 2.1

    please add to this thread as you add new add-ons to your forum ....

    http://vanillaforums.org/discussion/26703/plugins-and-themes-that-work-in-vanilla-2-1

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options

    Sure I will

Sign In or Register to comment.