public function Advanced() { $this->Permission('Vanilla.Settings.Manage'); $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array('Vanilla.Archive.Date', 'Vanilla.Archive.Exclude')); // Set the model on the form. $this->Form->SetModel($ConfigurationModel); // If seeing the form for the first time... if ($this->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $this->Form->SetData($ConfigurationModel->Data); } else { $ConfigurationModel->Validation->ApplyRule('Vanilla.Archive.Date', 'Date'); // Grab old config values to check for an update. $ArchiveDateBak = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExcludeBak = (bool) Gdn::Config('Vanilla.Archive.Exclude'); $Saved = $this->Form->Save(); if ($Saved) { $ArchiveDate = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExclude = (bool) Gdn::Config('Vanilla.Archive.Exclude'); if ($ArchiveExclude != $ArchiveExcludeBak || $ArchiveExclude && $ArchiveDate != $ArchiveDateBak) { $DiscussionModel = new Gdn_DiscussionModel(); $DiscussionModel->UpdateDiscussionCount('All'); } $this->StatusMessage = Translate("Your changes have been saved."); } } $this->AddSideMenu('vanilla/settings/advanced'); $this->AddJsFile('settings.js'); $this->Title(Translate('Advanced Forum Settings')); $this->Render(); }
public function GetData($Limit = 10) { $Session = Gdn::Session(); if ($Session->IsValid()) { $DiscussionModel = new Gdn_DiscussionModel(); $this->_DiscussionData = $DiscussionModel->Get(0, $Limit, array('w.Bookmarked' => '1', 'w.UserID' => $Session->UserID)); } }
/** * Advanced settings. * * Allows setting configuration values via form elements. * * @since 2.0.0 * @access public */ public function Advanced() { // Check permission $this->Permission('Vanilla.Settings.Manage'); // Load up config options we'll be setting $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array('Vanilla.Discussions.PerPage', 'Vanilla.Comments.AutoRefresh', 'Vanilla.Comments.PerPage', 'Vanilla.Categories.Use', 'Vanilla.Archive.Date', 'Vanilla.Archive.Exclude', 'Garden.EditContentTimeout')); // Set the model on the form. $this->Form->SetModel($ConfigurationModel); // If seeing the form for the first time... if ($this->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $this->Form->SetData($ConfigurationModel->Data); } else { // Define some validation rules for the fields being saved $ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Required'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Discussions.PerPage', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.AutoRefresh', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Required'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Comments.PerPage', 'Integer'); $ConfigurationModel->Validation->ApplyRule('Vanilla.Archive.Date', 'Date'); $ConfigurationModel->Validation->ApplyRule('Garden.EditContentTimeout', 'Integer'); // Grab old config values to check for an update. $ArchiveDateBak = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExcludeBak = (bool) Gdn::Config('Vanilla.Archive.Exclude'); // Save new settings $Saved = $this->Form->Save(); if ($Saved) { $ArchiveDate = Gdn::Config('Vanilla.Archive.Date'); $ArchiveExclude = (bool) Gdn::Config('Vanilla.Archive.Exclude'); if ($ArchiveExclude != $ArchiveExcludeBak || $ArchiveExclude && $ArchiveDate != $ArchiveDateBak) { $DiscussionModel = new Gdn_DiscussionModel(); $DiscussionModel->UpdateDiscussionCount('All'); } $this->StatusMessage = T("Your changes have been saved."); } } $this->AddSideMenu('vanilla/settings/advanced'); $this->AddJsFile('settings.js'); $this->Title(T('Advanced Forum Settings')); // Render default view (settings/advanced.php) $this->Render(); }
public function ProfileController_Discussions_Create(&$Sender) { $UserReference = ArrayValue(0, $Sender->EventArguments, ''); $Offset = ArrayValue(1, $Sender->EventArguments, 0); // Tell the ProfileController what tab to load $Sender->SetTabView($UserReference, 'Discussions', 'Profile', 'Discussions', 'Vanilla'); // Load the data for the requested tab. if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new Gdn_DiscussionModel(); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('d.InsertUserID' => $Sender->User->UserID)); $CountDiscussions = $Offset + $Sender->DiscussionData->NumRows(); if ($Sender->DiscussionData->NumRows() == $Limit) { $CountDiscussions = $Offset + $Limit + 1; } // Build a pager $PagerFactory = new PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender); $Sender->Pager->MoreCode = 'More Discussions'; $Sender->Pager->LessCode = 'Newer Discussions'; $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'profile/discussions/' . urlencode($Sender->User->Name) . '/%1$s/'); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Set the handlertype back to normal on the profilecontroller so that it fetches it's own views $Sender->HandlerType = HANDLER_TYPE_NORMAL; // Do not show discussion options $Sender->ShowOptions = FALSE; // Render the ProfileController $Sender->Render(); }
public function Delete($CommentID) { $this->EventArguments['CommentID'] = $CommentID; // Check to see if this is the first or last comment in the discussion $Data = $this->SQL->Select('d.DiscussionID, d.FirstCommentID, d.LastCommentID, c.InsertUserID')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Where('c.CommentID', $CommentID)->Get()->FirstRow(); if ($Data) { if ($Data->FirstCommentID == $CommentID) { $DiscussionModel = new Gdn_DiscussionModel(); $DiscussionModel->Delete($Data->DiscussionID); } else { // If this is the last comment, get the one before and update the LastCommentID field if ($Data->LastCommentID == $CommentID) { $OldData = $this->SQL->Select('c.CommentID')->From('Comment c')->Where('c.DiscussionID', $Data->DiscussionID)->OrderBy('c.DateInserted', 'desc')->Limit(1, 1)->Get()->FirstRow(); if (is_object($OldData)) { $this->SQL->Update('Discussion')->Set('LastCommentID', $OldData->CommentID)->Where('DiscussionID', $Data->DiscussionID)->Put(); } } $this->FireEvent('DeleteComment'); // Delete the comment $this->SQL->Delete('Comment', array('CommentID' => $CommentID)); // Delete the search. $Search = Gdn::Factory('SearchModel'); if (!is_null($Search)) { $Search->Delete(array('TableName' => 'Comment', 'PrimaryID' => $CommentID)); } } // Update the user's comment count $this->UpdateUser($Data->InsertUserID); } return TRUE; }
/** * Show all categories, and few discussions from each. */ public function All() { $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); if ($this->Head) { $this->Head->AddScript('/applications/vanilla/js/discussions.js'); $this->Head->AddScript('/applications/vanilla/js/options.js'); $this->Head->Title(Translate('All Categories')); } $this->DiscussionsPerCategory = Gdn::Config('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new Gdn_DiscussionModel(); $this->CategoryData = $this->CategoryModel->GetFull(); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->Result() as $Category) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->Get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID)); } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); $DraftsModule = new DraftsModule($this); $DraftsModule->GetData(); $this->AddModule($DraftsModule); $this->View = 'all'; $this->Render(); }
public function Mine($Offset = '0') { $this->Permission('Garden.SignIn.Allow'); $this->AddJsFile('/js/library/jquery.resizable.js'); $this->AddJsFile('/js/library/jquery.ui.packed.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussions.js'); $this->AddJsFile('options.js'); $this->Title(Translate('My Discussions')); if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $Session = Gdn::Session(); $Wheres = array('d.InsertUserID' => $Session->UserID); $DiscussionModel = new Gdn_DiscussionModel(); $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE); $CountDiscussions = $this->SetData('CountDiscussions', $DiscussionModel->GetCount($Wheres)); // Build a pager $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Discussions'; $this->Pager->LessCode = 'Newer Discussions'; $this->Pager->Wrapper = '<li %1$s>%2$s</li>'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/mine/%1$s'); // Deliver json data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'discussions'; } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); // Render the controller $this->Render(); }
public function Delete($CommentID) { $this->EventArguments['CommentID'] = $CommentID; // Check to see if this is the first comment in the discussion $Data = $this->SQL->Select('d.DiscussionID, d.FirstCommentID, c.InsertUserID')->From('Discussion d')->Join('Comment c', 'd.DiscussionID = c.DiscussionID')->Where('c.CommentID', $CommentID)->Get()->FirstRow(); if ($Data) { if ($Data->FirstCommentID == $CommentID) { $DiscussionModel = new Gdn_DiscussionModel(); $DiscussionModel->Delete($Data->DiscussionID); } else { $this->FireEvent('DeleteComment'); // Delete the comment $this->SQL->Delete('Comment', array('CommentID' => $CommentID)); // Delete the search. $Search = Gdn::Factory('SearchModel'); if (!is_null($Search)) { $Search->Delete(array('TableName' => 'Comment', 'PrimaryID' => $CommentID)); } } // Update the user's comment count $this->UpdateUser($Data->InsertUserID); } return TRUE; }