Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

Thank only possible for writer topic

This discussion is related to the Thankful People 2 addon.
jackmaessenjackmaessen ✭✭✭
edited December 2014 in Vanilla 2.0 - 2.2

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

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator
    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)

    jackmaessen
  • 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;
                    }
            }
    
  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    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.

    jackmaessenperegrinehgtonight
Sign In or Register to comment.