Add a method to the ModerationController to handle merging discussions.
@param Gdn_Controller $Sender
488715
public function ModerationController_MergeDiscussions_Create($Sender) {
      $Session = Gdn::Session();
      $Sender->Form = new Gdn_Form();
      $Sender->Title(T('Merge Discussions'));

      $DiscussionModel = new DiscussionModel();
      $CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
      if (!is_array($CheckedDiscussions))
         $CheckedDiscussions = array();
       
      $DiscussionIDs = $CheckedDiscussions;
      $Sender->SetData('DiscussionIDs', $DiscussionIDs);
      $CountCheckedDiscussions = count($DiscussionIDs);
      $Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
      $Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
      $Sender->SetData('Discussions', $Discussions);
      
      // Perform the merge
      if ($Sender->Form->AuthenticatedPostBack()) {
         // Create a new discussion record
         $MergeDiscussion = FALSE;
         $MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
         foreach ($Discussions as $Discussion) {
            if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
               $MergeDiscussion = $Discussion;
               break;
            }
         }
         if ($MergeDiscussion) {
            $ErrorCount = 0;
            
            // Verify that the user has permission to perform the merge.
            $Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
            if ($Category && !$Category['PermsDiscussionsEdit'])
               throw PermissionException('Vanilla.Discussions.Edit');
            
            // Assign the comments to the new discussion record
            $DiscussionModel->SQL
               ->Update('Comment')
               ->Set('DiscussionID', $MergeDiscussionID)
               ->WhereIn('DiscussionID', $DiscussionIDs)
               ->Put();
               
            $CommentModel = new CommentModel();
            foreach ($Discussions as $Discussion) {
               if ($Discussion['DiscussionID'] == $MergeDiscussionID)
                  continue;
               
               // Create a comment out of the discussion.
               $Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
               $Comment['DiscussionID'] = $MergeDiscussionID;
               
               $CommentModel->Validation->Results(TRUE);
               $CommentID = $CommentModel->Save($Comment);
               if ($CommentID) {
                  // Move any attachments (FileUpload plugin awareness)
                  if (class_exists('MediaModel')) {
                     $MediaModel = new MediaModel();
                     $MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
                  }
                  
                  // Delete discussion that was merged
                  $DiscussionModel->Delete($Discussion['DiscussionID']);                  
               } else {
                  $Sender->InformMessage($CommentModel->Validation->ResultsText());
                  $ErrorCount++;
               }
            }
            // Update counts on all affected discussions.
            $CommentModel->UpdateCommentCount($MergeDiscussionID);
            $CommentModel->RemovePageCache($MergeDiscussionID);
   
            // Clear selections
            Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
            ModerationController::InformCheckedDiscussions($Sender);
            if ($ErrorCount == 0)
               $Sender->RedirectUrl = Url("/discussion/$MergeDiscussionID/".Gdn_Format::Url($MergeDiscussion['Name']));
         }
      }
      
      $Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
   }
876164
public function setSenderName($senderName)
    {
        if ($this->sender == null) {
            $this->sender = new PagSeguroSender();
        }
        $this->sender->setName($senderName);
    }
934473
protected function AttachButtonBar($Sender, $Wrap = FALSE) {
      $Formatter = C('Garden.InputFormatter','Html');
      if (!in_array($Formatter, $this->Formats)) return;
      
      $View = Gdn::Controller()->FetchView('buttonbar','','plugins/ButtonBar');
      
      if ($Wrap)
         echo Wrap($View, 'div', array('class' => 'P'));
      else
         echo $View;
   }
428120
public function sendPartnerRequestToManager(array $mailVars, $sendFrom, $sendTo)
    {

        $mailTemplate = $this->createMailTemplate('partner-request-manager', $mailVars);

        if (!empty($mailTemplate)) {
            $subject = $mailTemplate->getSubject();
            $bodyParams = ['bodyContent' => $mailTemplate->getBody()];

            $this->sendMessage($sendFrom, $sendTo, $subject, $bodyParams);
        }


    }
1150258
public function UserInfoModule_OnBasicInfo_Handler($Sender) {
      try {
         // Get the custom fields
         $ProfileFields = Gdn::UserModel()->GetMeta($Sender->User->UserID, 'Profile.%', 'Profile.');

         // Import from CustomProfileFields if available
         if (!count($ProfileFields) && is_object($Sender->User) && C('Plugins.CustomProfileFields.SuggestedFields', FALSE)) {
            $ProfileFields = Gdn::UserModel()->GetAttribute($Sender->User->UserID, 'CustomProfileFields', FALSE);
			   if ($ProfileFields) {
			      // Migrate to UserMeta & delete original
			      Gdn::UserModel()->SetMeta($Sender->User->UserID, $ProfileFields, 'Profile.');
			      Gdn::UserModel()->SaveAttribute($Sender->User->UserID, 'CustomProfileFields', FALSE);
			   }
         }
         
         // Send them off for magic formatting
         $ProfileFields = $this->ParseSpecialFields($ProfileFields);
         
         // Get all field data, error check
         $AllFields = $this->GetProfileFields();
         if (!is_array($AllFields) || !is_array($ProfileFields))
            return;

         // Display all non-hidden fields
         $ProfileFields = array_reverse($ProfileFields);
         foreach ($ProfileFields as $Name => $Value) {
            if (!$Value)
               continue;
            if (!GetValue('OnProfile', $AllFields[$Name]))
               continue;
            if (!in_array($Name, $this->MagicLabels))
               $Value = Gdn_Format::Links(htmlspecialchars($Value));
            echo ' <dt class="ProfileExtend Profile'.Gdn_Format::AlphaNumeric($Name).'">'.Gdn_Format::Text($AllFields[$Name]['Label']).'</dt> ';
            echo ' <dd class="ProfileExtend Profile'.Gdn_Format::AlphaNumeric($Name).'">'.$Value.'</dd> ';
         }
      } catch (Exception $ex) {
         // No errors
      }
   }
196977
public function DiscussionController_AfterDiscussionMeta_Handler($Sender, $Args) {      
      // Signed in users only. No guest reporting!
      if (Gdn::Session()->UserID)
         $this->AddFlagButton($Sender, $Args, 'discussion');
   }
134122
public function UserModel_BeforeDeleteUser_Handler($Sender) {
      $UserID = GetValue('UserID', $Sender->EventArguments);
      $Options = GetValue('Options', $Sender->EventArguments, array());
      $Options = is_array($Options) ? $Options : array();
      $Content =& $Sender->EventArguments['Content'];
      
      $this->DeleteUserData($UserID, $Options, $Content);
   }
1046522
public function setSender(ContactInterface $sender = null)
    {
        if ($sender !== null && !($sender instanceof Contact)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s expects an instance of %s.',
                    __FUNCTION__, Contact::class
                )
            );
        }
        $this->sender = $sender;

        return $this;
    }
934704
public function Base_Render_Before($Sender) {
      // Add "Mark All Viewed" to main menu
      if ($Sender->Menu && Gdn::Session()->IsValid()) {
         if (C('Plugins.AllViewed.ShowInMenu', TRUE))
            $Sender->Menu->AddLink('AllViewed', T('Mark All Viewed'), '/discussions/markallviewed');
      }
   }
773869
public function ProfileController_AddProfileTabs_Handler($Sender) {
      if (Gdn::Session()->IsValid()) {
         $Inbox = T('Inbox');
         $InboxHtml = Sprite('SpInbox').' '.$Inbox;
         $InboxLink = '/messages/all';
         
         if (Gdn::Session()->UserID != $Sender->User->UserID) {
            // Accomodate admin access
            if (C('Conversations.Moderation.Allow', FALSE) && Gdn::Session()->CheckPermission('Conversations.Moderation.Manage')) {
               $CountUnread = $Sender->User->CountUnreadConversations;
               $InboxLink .= "?userid={$Sender->User->UserID}";
            } else {
               return;
            }
         } else {
            // Current user
            $CountUnread = Gdn::Session()->User->CountUnreadConversations;
         }
         
         if (is_numeric($CountUnread) && $CountUnread > 0)
            $InboxHtml .= ' <span class="Aside"><span class="Count">'.$CountUnread.'</span></span>';
         $Sender->AddProfileTab($Inbox, $InboxLink, 'Inbox', $InboxHtml);
      }
   }
402461
public function Controller_Add($Sender) {
      $Sender->AddSideMenu('settings/tagging');
      $Sender->Title('Add Tag');
      
      // Set the model on the form.
      $TagModel = new TagModel;
      $Sender->Form->SetModel($TagModel);
      
      if ($Sender->Form->AuthenticatedPostBack()) {
         // Make sure the tag is valid
         $TagName = $Sender->Form->GetFormValue('Name');
         if (!TagModel::ValidateTag($TagName))
            $Sender->Form->AddError('@'.T('ValidateTag', 'Tags cannot contain commas.'));
         
         // Make sure that the tag name is not already in use.
         if ($TagModel->GetWhere(array('Name' => $TagName))->NumRows() > 0) {
            $Sender->Form->AddError('The specified tag name is already in use.');
         }
         
         $Saved = $Sender->Form->Save();
         if ($Saved)
            $Sender->InformMessage(T('Your changes have been saved.'));
      }
      
      $Sender->Render('addedit', '', 'plugins/Tagging');
   }
149905
public function sendGroupsParticipantsAdd($groupId, $participant)
    {
        $msgId = $this->createMsgId();
        $this->sendGroupsChangeParticipants($groupId, $participant, 'add', $msgId);
    }
333044
public function setSender($sender)
    {
        if (!is_null($sender) && (strlen($sender) > 11)) {
            throw new \InvalidArgumentException('invalid length for $sender when calling UpdateSmsCampaign., must be smaller than or equal to 11.');
        }

        $this->container['sender'] = $sender;

        return $this;
    }
1279986
public function addResolver(EmailPartResolver $resolver, $part): self
    {
        $this->resolvers[$part] = $resolver;

        return $this;
    }
540884
public function DiscussionController_InsideCommentMeta_Handler($Sender, $Args) {      
      // Signed in users only. No guest reporting!
      if (Gdn::Session()->UserID)
         $this->AddFlagButton($Sender, $Args);
   }
167163
public function Controller_Index($Sender) {
      $Sender->Title('Tagging');
      $Sender->AddSideMenu('settings/tagging');
      $Sender->AddCSSFile('plugins/Tagging/design/tagadmin.css');
      $Sender->AddJSFile('plugins/Tagging/js/admin.js');
      $SQL = Gdn::SQL();
      
      $Sender->Form->Method = 'get';
      $Sender->Form->InputPrefix = '';
      //$Sender->Form->Action = '/settings/tagging';

      list($Offset, $Limit) = OffsetLimit($Sender->Request->Get('Page'), 100);
      $Sender->SetData('_Limit', $Limit);
      
      if ($Search = $Sender->Request->Get('Search')) {
         $SQL->Like('Name', $Search , 'right');
      }
      
      $Data = $SQL
         ->Select('t.*')
         ->From('Tag t')
         ->OrderBy('t.Name', 'asc')
         ->OrderBy('t.CountDiscussions', 'desc')
         ->Limit($Limit, $Offset)
         ->Get()->ResultArray();

      $Sender->SetData('Tags', $Data);

      if ($Search = $Sender->Request->Get('Search')) {
         $SQL->Like('Name', $Search , 'right');
      }
      $Sender->SetData('RecordCount', $SQL->GetCount('Tag'));
         
      $Sender->Render('tagging', '', 'plugins/Tagging');
   }
1342746
public function mixin($ruleName, $validator, $message = '')
	{
        if ( ! empty($message))
        {
            $this->messages[$ruleName] = $message;
        }
        Validator::extend($ruleName, $validator);

		return $this;
	}