/** * Comment on an activity item. * * @since 2.0.0 * @access public */ public function Comment() { $this->Permission('Garden.Profiles.Edit'); $Session = Gdn::Session(); $this->Form->SetModel($this->ActivityModel); $NewActivityID = 0; // Form submitted if ($this->Form->IsPostBack()) { $Body = $this->Form->GetValue('Body', ''); $ActivityID = $this->Form->GetValue('ActivityID', ''); if (is_numeric($ActivityID) && $ActivityID > 0) { $ActivityComment = array('ActivityID' => $ActivityID, 'Body' => $Body, 'Format' => 'Text'); $ID = $this->ActivityModel->Comment($ActivityComment); if ($ID == SPAM) { $this->StatusMessage = T('Your post has been flagged for moderation.'); $this->Render('Blank', 'Utility'); return; } $this->Form->SetValidationResults($this->ActivityModel->ValidationResults()); if ($this->Form->ErrorCount() > 0) { throw new Exception($this->ActivityModel->Validation->ResultsText()); $this->ErrorMessage($this->Form->Errors()); } } } // Redirect back to the sending location if this isn't an ajax request if ($this->_DeliveryType === DELIVERY_TYPE_ALL) { $Target = $this->Form->GetValue('Return'); if (!$Target) { $Target = '/activity'; } Redirect($Target); } else { // Load the newly added comment. $this->SetData('Comment', $this->ActivityModel->GetComment($ID)); // Set it in the appropriate view. $this->View = 'comment'; } // And render $this->Render(); }
public function Post($Notify = FALSE, $UserID = FALSE) { if (is_numeric($Notify)) { $UserID = $Notify; $Notify = FALSE; } if (!$UserID) { $UserID = Gdn::Session()->UserID; } switch ($Notify) { case 'mods': $this->Permission('Garden.Moderation.Manage'); $NotifyUserID = ActivityModel::NOTIFY_MODS; break; case 'admins': $this->Permission('Garden.Settings.Manage'); $NotifyUserID = ActivityModel::NOTIFY_ADMINS; break; default: $this->Permission('Garden.Profiles.Edit'); $NotifyUserID = ActivityModel::NOTIFY_PUBLIC; break; } $Activities = array(); if ($this->Form->IsPostBack()) { $Data = $this->Form->FormValues(); $Data = $this->ActivityModel->FilterForm($Data); if (!isset($Data['Format']) || strcasecmp($Data['Format'], 'Raw') == 0) { $Data['Format'] = C('Garden.InputFormatter'); } if ($UserID != Gdn::Session()->UserID) { // This is a wall post. $Activity = array('ActivityType' => 'WallPost', 'ActivityUserID' => $UserID, 'RegardingUserID' => Gdn::Session()->UserID, 'HeadlineFormat' => T('HeadlineFormat.WallPost', '{RegardingUserID,you} → {ActivityUserID,you}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format']); } else { // This is a status update. $Activity = array('ActivityType' => 'Status', 'HeadlineFormat' => T('HeadlineFormat.Status', '{ActivityUserID,user}'), 'Story' => $Data['Comment'], 'Format' => $Data['Format'], 'NotifyUserID' => $NotifyUserID); $this->SetJson('StatusMessage', Gdn_Format::PlainText($Activity['Story'], $Activity['Format'])); } $Activity = $this->ActivityModel->Save($Activity, FALSE, array('CheckSpam' => TRUE)); if ($Activity == SPAM || $Activity == UNAPPROVED) { $this->StatusMessage = T('ActivityRequiresApproval', 'Your post will appear after it is approved.'); $this->Render('Blank', 'Utility'); return; } if ($Activity) { if ($UserID == Gdn::Session()->UserID && $NotifyUserID == ActivityModel::NOTIFY_PUBLIC) { Gdn::UserModel()->SetField(Gdn::Session()->UserID, 'About', Gdn_Format::PlainText($Activity['Story'], $Activity['Format'])); } $Activities = array($Activity); ActivityModel::JoinUsers($Activities); $this->ActivityModel->CalculateData($Activities); } else { $this->Form->SetValidationResults($this->ActivityModel->ValidationResults()); $this->StatusMessage = $this->ActivityModel->Validation->ResultsText(); // $this->Render('Blank', 'Utility'); } } if ($this->DeliveryType() == DELIVERY_TYPE_ALL) { Redirect($this->Request->Get('Target', '/activity')); } $this->SetData('Activities', $Activities); $this->Render('Activities'); }