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

Thank only possible for writer topic

jackmaessenjackmaessen ✭✭✭
edited December 2014 in Vanilla 2.0 - 2.8

I have a question about this plugin. I am trying to find a solution that only the topic writer can thank for a comment.


So in his own topic, he is the only one who can thank on comment of other comment writers.

I think there should be added something in this piece of code (class.thankfullpeople.plugin.php):

if ($AllowThank) {
                        static $LocalizedThankButtonText;
                        if ($LocalizedThankButtonText === Null) $LocalizedThankButtonText = T('ThankCommentOption', T('Thank'));
                        $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
                        $Option = '<span class="Thank">'.Anchor($LocalizedThankButtonText, $ThankUrl).'</span>';
                        echo $Option;
                        //$Sender->Options .= $Option;

I just don't know how to catch the topic writer only

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited December 2014

    I don't know the source, but you would have to
    a) not show the possibility to thank any more for all discussions
    b) show possibility to thank and allow thanking only to discussion author by checking everytime it is displayed and thanks are written to db

    $DiscussionID = $Sender['EventArguments']['Comment']->DiscussionID;
    $Discussion = DiscussionModel::GetByID($DiscussionID);
    $DiscussionUserID = $Discussion->InsertUserID;
    if ($Session->UserID != $DiscussionUserID) return
    

    (This code is not tested and simply a draft for you to find your way, young Jedi)

  • Options

    this is the complete function in which the text Thank is parsed in the meta

    public function DiscussionController_AfterCommentMeta_Handler($Sender) {
                    $EventArguments =& $Sender->EventArguments;
                    $Type = $EventArguments['Type'];
                    $Object = $EventArguments['Object'];
                    //$Session = Gdn::Session();
                    $SessionUserID = $this->Session->UserID;
                    if ($SessionUserID <= 0 || $Object->InsertUserID == $SessionUserID) return;
    
                    if (!self::IsThankable($Type)) return;
    
    
    
                    static $AllowTakeBack;
                    if (is_null($AllowTakeBack)) $AllowTakeBack = C('Plugins.ThankfulPeople.AllowTakeBack', False);
                    $AllowThank = True;
    
                    switch ($Type) {
                            case 'Discussion': {
                                    $DiscussionID = $ObjectID = $Object->DiscussionID;
                                    if (array_key_exists($SessionUserID, $this->DiscussionData)) $AllowThank = False;
                                    break;
                            }
                            case 'Comment': {
                                    $CommentID = $ObjectID = $Object->CommentID;
                                    if (array_key_exists($CommentID, $this->ThankForComment) && in_array($SessionUserID, $this->ThankForComment[$CommentID])) $AllowThank = False;
                                    break;
                            }
                    }
    
    
                    if ($AllowThank) {
                            static $LocalizedThankButtonText;
    
                            if ($LocalizedThankButtonText === Null) $LocalizedThankButtonText = T('ThankCommentOption', T('Thank'));
                            $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
                            $Option = '<span class="Thank">'.Anchor($LocalizedThankButtonText, $ThankUrl).'</span>';
                            echo $Option;
                            //$Sender->Options .= $Option;
                    } elseif ($AllowTakeBack) {
                            // Allow unthank
                            static $LocalizedUnThankButtonText;
                            if (is_null($LocalizedUnThankButtonText)) $LocalizedUnThankButtonText = T('UnThankCommentOption', T('Unthank'));
                            $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$Sender->SelfUrl;
                            $Option = '<span class="UnThank">'.Anchor($LocalizedUnThankButtonText, $UnThankUrl).'</span>';
                            echo $Option;
                            //$Sender->Options .= $Option;
                    }
            }
    
  • Options
    R_JR_J Ex-Fanboy Munich Admin

    While you are looking at changing the plugin, you could even improve your version ;)

    Look at that: https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/views/discussion/helper_functions.php#L126-128
    Replace function "AfterCommentMeta" by "CommentInfo" so that it will work with Vanilla 2.3

    Then look at what useful information is in the EventArguments: https://github.com/vanilla/vanilla/blob/2.1/applications/vanilla/views/discussion/helper_functions.php#L66-74

    $Type will now always be "Comment" and $Object is the Comment.

        public function DiscussionController_CommentInfo_Handler($Sender) {
            $Comment = $Sender->EventArguments['Comment'];
            $Type = 'Comment';
            $CommentID = $Comment->CommentID;
    
            $Discussion = DiscussionModel::GetID($CommentID);
            // maybe you must use $DiscussionModel = new DiscussionModel(); $Discussion = $DiscussionModel->GetID... instead
            $DiscussionUserID = $Discussion->InsertUserID;
            $SessionUserID = $this->Session->UserID;
            // here's what you wanted to achieve:
            if ($SessionUserID <> $DiscussionUserID || $Comment->InsertUserID == $SessionUserID) {
                return;
            }
            if (!self::IsThankable($Type)) {
                return;
            }
            static $AllowTakeBack;
            if (is_null($AllowTakeBack)) {
                $AllowTakeBack = C('Plugins.ThankfulPeople.AllowTakeBack', False);
            }
            $AllowThank = True;
    
            if (array_key_exists($CommentID, $this->ThankForComment) && in_array($SessionUserID, $this->ThankForComment[$CommentID])) {
                $AllowThank = False;
            }
            if ($AllowThank) {
                static $LocalizedThankButtonText;
                if ($LocalizedThankButtonText === Null) {
                    $LocalizedThankButtonText = T('ThankCommentOption', T('Thank'));
                }
                $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$CommentID.'?Target='.$Sender->SelfUrl;
                $Option = '<span class="Thank">'.Anchor($LocalizedThankButtonText, $ThankUrl).'</span>';
                echo $Option;
            } elseif ($AllowTakeBack) {
                // Allow unthank
                static $LocalizedUnThankButtonText;
                if (is_null($LocalizedUnThankButtonText)) {
                    $LocalizedUnThankButtonText = T('UnThankCommentOption', T('Unthank'));
                }
                $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$CommentID.'?Target='.$Sender->SelfUrl;
                $Option = '<span class="UnThank">'.Anchor($LocalizedUnThankButtonText, $UnThankUrl).'</span>';
                echo $Option;
            }
        }
    

    Line 31 and 40 tell me that there are functions PluginController_ThankFor_Create and PluginController_UnThankFor_Create exist which do the real job. You have to do the check here again, otherwise people could simply write yourforum/plugin/thankfor/comment/100 in their address bar in order to thank for any comment.

Sign In or Register to comment.