HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

possible changes to make in work in vanilla 2.1 and 2.0.18.x and does NOT require php 5.4

peregrineperegrine MVP
edited September 2013 in Feedback

FirstRow(DATASET_TYPE_ARRAY)['Gender']; // will only work in php 5.4 as far as I can guess

change from

   function DiscussionController_BeforeCommentMeta_Handler($Sender) {
      $UserID = $Sender->EventArguments['Author']->UserID;
      $Gender = Gdn::SQL()
         ->Select('Gender')
         ->From('User')
         ->Where('UserID', $UserID)
         ->Get()
         ->FirstRow(DATASET_TYPE_ARRAY)['Gender']; 
      echo "<span class=\"Gender_{$Gender}\" />";
   } 

TO:

      function DiscussionController_BeforeCommentMeta_Handler($Sender) {
       if (substr(APPLICATION_VERSION,0,3) < 2.1) {
       $this->AttachGender($Sender);
      }
      }
        function DiscussionController_AuthorInfo_Handler($Sender) {
        $this->AttachGender($Sender);
      }

      function AttachGender($Sender) {
          $UserID = $Sender->EventArguments['Author']->UserID;
          $Gender = Gdn::SQL()
             ->Select('Gender')
             ->From('User')
             ->Where('UserID', $UserID)
             ->Get()
             ->FirstRow('', DATASET_TYPE_ARRAY)
             ->Gender;

          echo "<span class=\"Gender_{$Gender}\" /></span>";
       }
    }

css additions

span.Gender_m:after {
font-size: 16px;
content:"\2642";
}

span.Gender_f:after {
font-size: 16px;
content:"\2640";
}

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

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Thanks to you, @peregrine, for working over it. I've seen a question somewhere that showed that plugin has the PHP version problem again but I've haven't had the time right now to look at it. I'll update the plugin as soon as possible.

    Great that you already made it work with Vanilla version 2.1!

  • peregrineperegrine MVP
    edited September 2013

    I think the idea is to avoid stuffing the arrays like you do - it is a php 5.4 deal.

    same issue as the other plugin [] question

    if @jeongwee tries it - you will know if it works in 2.1

    the symbol goes after the name in 2.1 with these changes.

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

  • R_JR_J Ex-Fanboy Munich Admin

    I was never fluent in PHP (and I'm far from being it now), so anything that works for me makes me happy. I have learned that there's a version issue with some array usages but I'm not aware that I'm using it :-|

    Someone stumbled upon that in the Alias plugin and I've fixed it and someone stumbled upon this issue in the ShowGender plugin and fixed it himself by updating PHP. It was on my todo list to look for that in this plugin, but I'm really thankful that you did it, because you even made it 2.1-proofed.

    I'll try to avoid that usage, but most of my programming times, I'm struggling with a lot of barebone problems caused by not yet having found a routine how to get information out of that darn $Sender or any other object I have to deal with. That always takes me more time that it feels it should. So I do not spent time on things that work although I should do to make my code better.

  • R_JR_J Ex-Fanboy Munich Admin

    I was trying to update the plugin quickly this evening, but it wasn't as easy as I thought. I can't use your code because I want it to look the same in 2.018.8 and 2.1 and this is harder than I've expected.

  • peregrineperegrine MVP
    edited September 2013

    I can't use your code because I want it to look the same in 2.018.8 and 2.1 and this is harder than I've expected.

    it puts after the name in both versions doesn't it?

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

  • R_JR_J Ex-Fanboy Munich Admin

    I know you're right, but that's some kind of perfectionism which always stands in my way and hinders me from being effective. I'll wait if someone comes up with an easy solution for my problem and if not, I'll accept two different looks

  • peregrineperegrine MVP
    edited September 2013

    I don't comprehend - the gender is after name in both cases. the layout is different.

    perfection in placement - does not equate with "perfection" all the extra need for all the extra code that gets executed. maybe your perfection is misguided.

    you have multiple options.....

    the controller needs to be the correct controller.

    if you want to use the wrong controller
    UserModel_AfterGetID_Handler instead of AuthorInfo

    UserModel_AfterGetID_Handler that fires more times than needed. you could use css and display:none for all of the places it doesn't need to show.

    or use js to prepend your span

    or use positioning with the correct controller.

    someone might have a different take on it. But your choice - a plugin that works in both versions or one that doesn't work at all in version 2.1 or in php 5.2 and 5.3 which may be more common than you think.

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

  • You can compile two versions of PHP 5.3 and 5.4 and set up different URLs for testing. This is using nginx, and php-fpm - I do this for my plugin development, I write a script to run automated tests and it runs in different environments with http://travis-ci.org so even if I forget to test it in 5.3, travis runs it in 5.3 and tests it for me.

Sign In or Register to comment.