/**
  * Increment/decrement comment scores
  */
 public function DiscussionController_VoteComment_Create($Sender)
 {
     //		if (!C('Plugins.Voting.Enabled'))
     //			return;
     $CommentID = GetValue(0, $Sender->RequestArgs, 0);
     $VoteType = GetValue(1, $Sender->RequestArgs);
     $TransientKey = GetValue(2, $Sender->RequestArgs);
     $Session = Gdn::Session();
     $FinalVote = 0;
     $Total = 0;
     if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $CommentID > 0) {
         $CommentModel = new CommentModel();
         $OldUserVote = $CommentModel->GetUserScore($CommentID, $Session->UserID);
         $NewUserVote = $VoteType == 'voteup' ? 1 : -1;
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
         // Allow admins to vote unlimited.
         $AllowVote = $Session->CheckPermission('Garden.Moderation.Manage');
         // Only allow users to vote up or down by 1.
         if (!$AllowVote) {
             $AllowVote = $FinalVote > -2 && $FinalVote < 2;
         }
         if ($AllowVote) {
             $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalVote);
         }
         // Move the comment into or out of moderation.
         if (class_exists('LogModel')) {
             $Moderate = FALSE;
             if ($Total <= C('Plugins.Voting.ModThreshold1', -10)) {
                 $LogOptions = array('GroupBy' => array('RecordID'));
                 // Get the comment row.
                 $Data = $CommentModel->GetID($CommentID, DATASET_TYPE_ARRAY);
                 if ($Data) {
                     // Get the users that voted the comment down.
                     $OtherUserIDs = $CommentModel->SQL->Select('UserID')->From('UserComment')->Where('CommentID', $CommentID)->Where('Score <', 0)->Get()->ResultArray();
                     $OtherUserIDs = array_column($OtherUserIDs, 'UserID');
                     $LogOptions['OtherUserIDs'] = $OtherUserIDs;
                     // Add the comment to moderation.
                     if ($Total > C('Plugins.Voting.ModThreshold2', -20)) {
                         LogModel::Insert('Moderate', 'Comment', $Data, $LogOptions);
                     }
                 }
                 $Moderate = TRUE;
             }
             if ($Total <= C('Plugins.Voting.ModThreshold2', -20)) {
                 // Remove the comment.
                 $CommentModel->Delete($CommentID, array('Log' => 'Moderate'));
                 $Sender->InformMessage(sprintf(T('The %s has been removed for moderation.'), T('comment')));
             } elseif ($Moderate) {
                 $Sender->InformMessage(sprintf(T('The %s has been flagged for moderation.'), T('comment')));
             }
         }
     }
     $Sender->DeliveryType(DELIVERY_TYPE_BOOL);
     $Sender->SetJson('TotalScore', $Total);
     $Sender->SetJson('FinalVote', $FinalVote);
     $Sender->Render();
 }
   /**
    * Increment/decrement comment scores
    */
   public function DiscussionController_VoteComment_Create($Sender) {
		if (!C('Plugins.Voting.Enabled'))
			return;

      $CommentID = GetValue(0, $Sender->RequestArgs, 0);
      $VoteType = GetValue(1, $Sender->RequestArgs);
      $TransientKey = GetValue(2, $Sender->RequestArgs);
      $Session = Gdn::Session();
      $FinalVote = 0;
      $Total = 0;
      if ($Session->IsValid() && $Session->ValidateTransientKey($TransientKey) && $CommentID > 0) {
         $CommentModel = new CommentModel();
         $OldUserVote = $CommentModel->GetUserScore($CommentID, $Session->UserID);
         $NewUserVote = $VoteType == 'voteup' ? 1 : -1;
         $FinalVote = intval($OldUserVote) + intval($NewUserVote);
         // Allow admins to vote unlimited.
         $AllowVote = $Session->CheckPermission('Vanilla.Comments.Edit');
         // Only allow users to vote up or down by 1.
         if (!$AllowVote)
            $AllowVote = $FinalVote > -2 && $FinalVote < 2;
         
         if ($AllowVote)
            $Total = $CommentModel->SetUserScore($CommentID, $Session->UserID, $FinalVote);
      }
      $Sender->DeliveryType(DELIVERY_TYPE_BOOL);
      $Sender->SetJson('TotalScore', $Total);
      $Sender->SetJson('FinalVote', $FinalVote);
      $Sender->Render();
   }