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.

ThankfulPeople2 refreshes user to top of page after 2.3 update [RESOLVED]

old_manold_man New
edited March 2017 in Vanilla 2.0 - 2.8

This started with our 2.3 update. I posted a comment with a less descriptive title a couple of days back (look for my awful avatar), and we never got a solution. We cleared INI files, and removed ThankfulPeople2 and reinstalled it. No luck. Previoiusly, when a user hit the button the page refreshed to the post the user had just "thanked."

Is anyone else having this problem?

Thanks.

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Technically that is not a problem but the expected behavior. I wonder how it could be different. I see those lines in the text which are responsible:

        Line 159:                         $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
        Line 167:                         $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
        Line 205:                         $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
        Line 213:                         $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
        Line 251:                         $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
        Line 259:                         $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
    

    Do you see the $Sender->SelfUrl part? that will always be the discussion and never an individual comment.

    There is pretty much deprecated code in that plugin. I can describe you how to get it up and running "fast" (based on your skills) and I could guide you how to make that beautifully polished. What do you prefer?

  • I am easily distracted by shiny objects.

    Also, as you can probably deduce from the "Hell Yeah" and "Damn Straight" edits we made to the plugin, our members are not exactly "polished." What's the expression? "You can't polish a . . . ."

    So, with these disclaimers, I will let you choose. "Beggars can't be . . . ." I sense you prefer to impart "beautifully polished," which is fine. Our only requirement is that users refresh back to the message they just "thanked." I do understand that our prior experience of refreshing to the individual message seems anomalous--the intended behavior is to refresh to the top of the page, if I understand. So, we seek an edit that would allow us to tweak ThankfulPeople2, to refresh to the specific comment.

    So, when I finish my real job at 5:00 (USA, eastern), I will return here to see your instructions.

    Thank you.

  • R_JR_J Ex-Fanboy Munich Admin

    The choice in here would be between learning some more of how Vanilla works or simply try to understand only what is needed to fix that. I understand your first sentence as a hint that the quick & (not really) dirty solution is more yours ;)

    Let's start!

    But before you begin be warned: during the development it might be that there are errors in the file. A PHP error in one of the files can make your forum stop working until that error is fixed. Best thing would be to work on a local installation. It doesn't need to be a copy of your forum, a simple installation will do.
    If you are brave enough and don't care about your visitors, you can work on your live system.
    Please make a backup of the plugin file before you begin. If you render your forum unusable because of some error in the changed file, you could revert back by restoring the plugin file.


    I've shown you above the lines in which there is something that you would have to change. All those $Sender->SelfUrl are wrong and you would have to change that. Look at the code. There is some sort of pattern here which will help us. The lines above are "pairs" and before each pair there is a code block which looks exactly the same at all three places. This is just a lucky coincidence which helps us a lot, since I would have to explain only one time which must be done three times and you only have to understand one explanation that you have to execute three times.

    The code I am speaking a bout looks like that:

    switch ($Type) {
            case 'Discussion': {
                (...)
            }
            case 'Comment': {
                (...)
            }
    }
    
    
    if ($AllowThank) {
        (...)
    } elseif ($AllowTakeBack) {
        (...)
    

    Instead of passing the discussion link to as the target, we want to pass the link to the discussion or the link to the comment, based on what that string is built for. Even if you have no experience with programming at all, it is obvious that we have a code block here which handles some commands for comments and a code block which is dealing with discussions.

    Vanilla has 2 handy functions to built a proper url to a discussion or to a comment: commentUrl and discussionUrl. We will use this commands in the appropriate code block to fill a variable we call $target. Afterwards you only have to replace that $Sender->SelfUrl with $target. That's the theory. Here's some code.

    Find that first

    switch ($Type) {
            case 'Discussion': {
    

    in line 142. Below that write the following code:
    $target = discussionUrl($Object);

    Then do (nearly) the same below

    case 'Comment': {
    

    Originally in line 148.

    Add $target = commentUrl($Object); below this line.

    After you have done that, you can replace the $Sender->SelfUrl in line 159 and 167 with $target.


    Basically that is all that is to do. I spoke of three blocks with the same pattern and we only took care of the first by now, but the other two occurances of the SelfUrl have to be treated exactly the same: add one line each below the case discussion/comment and replace $Sender->SelfUrl with $target

    After you have done so, you're finished! Yes, it has been that easy =)


    But there is room for improvement. Every discussionUrl($Object) call costs time, while the link to the discussion always was available as $Sender->SelfUrl. So let's tweak your solution only a little bit. Replace every $target = discussionUrl($Object); that you have inserted by $target = $Sender->SelfUrl;.
    The behavior stays the same but the speed increases by one or two micro seconds B)

  • I'm back from the rockpile, and reading.

    Thanks.

  • Works just dandy.

    I am indebted to you, sir.

    Munich?

    My son is applying to some kind of graduate college in Berlin. May I PM you?

  • How do I mark this as solved?

  • R_JR_J Ex-Fanboy Munich Admin

    Marking discussions as solved is not needed, since you as the discussion author do not have the possibility to do so. Therefore a moderator would always have to take action.

    Simply ask a question instead of starting a discussion next time. You'll be able to mark comments to questions as answers.

  • I just wanted to post a 2019 update to this, in version 3.x the instructions above no longer work and will cause your forum to fail.

    if you come across this post and wonder what to do next you can just comment out the ThankFullpeople2 line under // EnabledPlugins in /conf/config.php

Sign In or Register to comment.