/** * Show all categories and few discussions from each. * * @param string $Category The url code of the parent category. * @since 2.0.0 * @access public */ public function discussions($Category = '') { // Setup head $this->addJsFile('discussions.js'); $this->Menu->highlightRoute('/discussions'); if (!$this->title()) { $Title = c('Garden.HomepageTitle'); if ($Title) { $this->title($Title, ''); } else { $this->title(t('All Categories')); } } if (!$Category) { $this->Description(c('Garden.Description', null)); } Gdn_Theme::section('CategoryDiscussionList'); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories'); if ($Category) { $Subtree = CategoryModel::GetSubtree($Category, false); $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID'); $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray(); } else { $Categories = $this->CategoryModel->GetFull()->resultArray(); } $this->setData('Categories', $Categories); // Get category data and discussions $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new DiscussionModel(); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->result() as $Category) { if ($Category->CategoryID > 0) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } } // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); $this->addModule($CategoryFollowToggleModule); // Set view and render $this->View = 'discussions'; $this->canonicalUrl(url('/categories', true)); $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false); if ($Path) { include_once $Path; } // For GetOptions function $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false); if ($Path2) { include_once $Path2; } $this->render(); }
/** * Hack the Base Render in order to achieve our goal * * @since 1.0 * @version 1.7.2 */ public function Base_Render_Before(&$Sender) { // Attach the Plugin's CSS to the site $Sender->AddCssFile($this->GetResource('categories2menu.css', FALSE, FALSE)); $Cat2MenuJQuerySource = '<script type="text/javascript"> var ddmenuitem = 0; var menustyles = { "visibility":"visible", "display":"block", "z-index":"9"} function Menu_close() { if(ddmenuitem) { ddmenuitem.css("visibility", "hidden"); } } function Menu_open() { Menu_close(); ddmenuitem = $(this).find("ul").css(menustyles); } jQuery(document).ready(function() { $("ul#Menu > li").bind("mouseover", Menu_open); $("ul#Menu > li").bind("mouseout", Menu_close); }); document.onclick = Menu_close;</script> '; // Add the jQuery JavaScript to the page $Sender->Head->AddString($Cat2MenuJQuerySource); if ($Sender->Menu) { // Set this to FALSE|TRUE whether you want to display the Discussion-Counter next to each Category or not $DisplayCounter = TRUE; // Build the Categories Model & load Categories Data $CategoryModel = new CategoryModel(); $_CategoryData = $CategoryModel->GetFull(); // If there are any Categories... if ($_CategoryData != FALSE) { // Add a link to the Category overview as first menuitem $Sender->Menu->AddLink('Discussions', T('→ All Categories'), '/categories/all'); // If $DisplayCounter is set to TRUE, get Count discussions per Category separately $CountDiscussions = 0; foreach ($_CategoryData->Result() as $Category) { // (will ignore root node) if ($Category->Name != 'Root') { $CountDiscussions = $CountDiscussions + $Category->CountDiscussions; } } // Fetch every single Category... foreach ($_CategoryData->Result() as $Category) { if ($Category->Name != 'Root') { if ($DisplayCounter == TRUE) { // Build the Categories-Menu with Discussions-Counter $Sender->Menu->AddLink('Discussions', $Category->Name . ' <span>' . $Category->CountDiscussions . '</span>', '/categories/' . $Category->UrlCode, FALSE); } else { // Build the Categories-Menu $Sender->Menu->AddLink('Discussions', $Category->Name, '/categories/' . $Category->UrlCode, FALSE); } } } } } }
/** * Create a discussion. * @param int The category id to add the discussion to. */ public function Discussions() { $CategoryID = 1; $Session = Gdn::Session(); $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $this->CategoryID = isset($this->Discussion) ? $this->Discussion->CategoryID : $CategoryID; if (Gdn::Config('Vanilla.Categories.Use') === TRUE) { $CategoryModel = new CategoryModel(); // Filter to categories that this user can add to $CategoryModel->SQL->Distinct()->Join('Permission _p2', '_p2.JunctionID = c.CategoryID', 'inner')->Join('UserRole _ur2', '_p2.RoleID = _ur2.RoleID', 'inner')->BeginWhereGroup()->Where('_ur2.UserID', $Session->UserID)->Where('_p2.`Vanilla.Discussions.Add`', 1)->EndWhereGroup(); $this->CategoryData = $CategoryModel->GetFull(); } if (isset($this->Discussion)) { if ($this->Discussion->InsertUserID != $Session->UserID) { $this->Permission('Vanilla.Discussions.Edit', $this->Discussion->CategoryID); } } else { $this->Permission('Vanilla.Discussions.Add'); } // Set the model on the form. $this->Form->SetModel($this->DiscussionModel); if ($this->Form->AuthenticatedPostBack() === TRUE) { $FormValues = $this->Form->FormValues(); // Check category permissions if ($this->Form->GetFormValue('Announce', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Announce', $this->CategoryID)) { $this->Form->AddError('You do not have permission to announce in this category', 'Announce'); } if ($this->Form->GetFormValue('Close', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Close', $this->CategoryID)) { $this->Form->AddError('You do not have permission to close in this category', 'Close'); } if ($this->Form->GetFormValue('Sink', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Sink', $this->CategoryID)) { $this->Form->AddError('You do not have permission to sink in this category', 'Sink'); } if (!$Session->CheckPermission('Vanilla.Discussions.Add', $this->CategoryID)) { $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID'); } if ($this->Form->ErrorCount() == 0) { $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel); $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults()); } } if ($this->Form->ErrorCount() > 0) { // Return the form errors $this->SetJSON("errors", $this->Form->Errors()); } $this->Render(); }
/** * Show all categories and few discussions from each. * * @since 2.0.0 * @access public */ public function Discussions() { // Setup head $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); $this->AddJsFile('discussions.js'); $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('All Categories')); } $this->Description(C('Garden.Description', NULL)); Gdn_Theme::Section('CategoryDiscussionList'); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); // Get category data and discussions $this->DiscussionsPerCategory = C('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new DiscussionModel(); $this->CategoryModel->Watching = !Gdn::Session()->GetPreference('ShowAllCategories'); $this->CategoryData = $this->CategoryModel->GetFull(); $this->SetData('Categories', $this->CategoryData); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->Result() as $Category) { if ($Category->CategoryID > 0) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->Get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } } // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); $this->AddModule($CategoryFollowToggleModule); // Set view and render $this->View = 'discussions'; $this->CanonicalUrl(Url('/categories', TRUE)); $Path = $this->FetchViewLocation('helper_functions', 'discussions', FALSE, FALSE); if ($Path) { include_once $Path; } $this->Render(); }
public function PostController_Render_Before($Sender) { if (Gdn::Session()->CheckPermission('Vanilla.Discussions.Close')) { $CategoryModel = new CategoryModel(); $CategoryFull = $CategoryModel->GetFull(); $CatsExpire = array(); foreach ($CategoryFull as $Category) { $CatsExpire[$Category->CategoryID] = Gdn::Session()->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Category->PermissionCategoryID) && $Category->AutoExpirePeriod; } $Sender->AddDefinition('CatsExpire', json_encode($CatsExpire)); $Sender->AddJsFile('autoexpirecheck.js', 'plugins/AutoExpireDiscussions'); } }
/** * Create a discussion. * * @param int The CategoryID to add the discussion to. */ public function Discussion($CategoryID = '') { $UseCategories = C('Vanilla.Categories.Use'); if (!$UseCategories) { $CategoryID = 0; } $Session = Gdn::Session(); $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0; $this->CategoryID = isset($this->Discussion) ? $this->Discussion->CategoryID : $CategoryID; if ($UseCategories) { $CategoryModel = new CategoryModel(); $this->CategoryData = $CategoryModel->GetFull('', 'Vanilla.Discussions.Add'); } $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('post.js'); $this->AddJsFile('autosave.js'); $this->Title(T('Start a New Discussion')); if (isset($this->Discussion)) { if ($this->Discussion->InsertUserID != $Session->UserID) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Discussion->CategoryID); } // Make sure that content can (still) be edited. $EditContentTimeout = C('Garden.EditContentTimeout', -1); $CanEdit = $EditContentTimeout == -1 || strtotime($this->Discussion->DateInserted) + $EditContentTimeout > time(); if (!$CanEdit) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Discussion->CategoryID); } } else { $this->Permission('Vanilla.Discussions.Add'); } // Set the model on the form. $this->Form->SetModel($this->DiscussionModel); if ($this->Form->AuthenticatedPostBack() === FALSE) { if (isset($this->Discussion)) { $this->Form->SetData($this->Discussion); } else { if (isset($this->Draft)) { $this->Form->SetData($this->Draft); } else { $this->Form->SetData(array('CategoryID' => $CategoryID)); } } } else { // Save as a draft? $FormValues = $this->Form->FormValues(); if ($DraftID == 0) { $DraftID = $this->Form->GetFormValue('DraftID', 0); } $Draft = $this->Form->ButtonExists('Save Draft') ? TRUE : FALSE; $Preview = $this->Form->ButtonExists('Preview') ? TRUE : FALSE; if (!$Preview) { // Check category permissions if ($this->Form->GetFormValue('Announce', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $this->CategoryID)) { $this->Form->AddError('You do not have permission to announce in this category', 'Announce'); } if ($this->Form->GetFormValue('Close', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $this->CategoryID)) { $this->Form->AddError('You do not have permission to close in this category', 'Close'); } if ($this->Form->GetFormValue('Sink', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $this->CategoryID)) { $this->Form->AddError('You do not have permission to sink in this category', 'Sink'); } if (!$Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', $this->CategoryID)) { $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID'); } // Make sure that the title will not be invisible after rendering $Name = $this->Form->GetFormValue('Name', ''); if ($Name != '' && Gdn_Format::Text($Name) == '') { $this->Form->AddError(T('You have entered an invalid discussion title'), 'Name'); } if ($this->Form->ErrorCount() == 0) { if ($Draft) { $DraftID = $this->DraftModel->Save($FormValues); $this->Form->SetValidationResults($this->DraftModel->ValidationResults()); } else { $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel); $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults()); if ($DiscussionID > 0 && $DraftID > 0) { $this->DraftModel->Delete($DraftID); } } } } else { // If this was a preview click, create a discussion/comment shell with the values for this comment $this->Discussion = new stdClass(); $this->Discussion->Name = $this->Form->GetValue('Name', ''); $this->Comment = new stdClass(); $this->Comment->InsertUserID = $Session->User->UserID; $this->Comment->InsertName = $Session->User->Name; $this->Comment->InsertPhoto = $Session->User->Photo; $this->Comment->DateInserted = Gdn_Format::Date(); $this->Comment->Body = ArrayValue('Body', $FormValues, ''); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { $this->AddAsset('Content', $this->FetchView('preview')); } else { $this->View = 'preview'; } } if ($this->Form->ErrorCount() > 0) { // Return the form errors $this->StatusMessage = $this->Form->Errors(); } else { if ($DiscussionID > 0 || $DraftID > 0) { // Make sure that the ajax request form knows about the newly created discussion or draft id $this->SetJson('DiscussionID', $DiscussionID); $this->SetJson('DraftID', $DraftID); if (!$Preview) { // If the discussion was not a draft if (!$Draft) { // Redirect to the new discussion $Discussion = $this->DiscussionModel->GetID($DiscussionID); $this->EventArguments['Discussion'] = $Discussion; $this->FireEvent('AfterDiscussionSave'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { Redirect('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name)); } else { $this->RedirectUrl = Url('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name)); } } else { // If this was a draft save, notify the user about the save $this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date()); } } } } } $this->Form->AddHidden('DiscussionID', $DiscussionID); $this->Form->AddHidden('DraftID', $DraftID, TRUE); $this->Render(); }
/** * Add a method to the ModerationController to handle splitting comments out to a new discussion. */ public function ModerationController_SplitComments_Create($Sender) { $Session = Gdn::Session(); $Sender->Form = new Gdn_Form(); $Sender->Title(T('Split Comments')); $Sender->Category = FALSE; $DiscussionID = GetValue('0', $Sender->RequestArgs, ''); if (!is_numeric($DiscussionID)) return; $DiscussionModel = new DiscussionModel(); $Discussion = $DiscussionModel->GetID($DiscussionID); if (!$Discussion) return; // Verify that the user has permission to perform the split $Sender->Permission('Vanilla.Discussion.Edit', TRUE, 'Category', $Discussion->CategoryID); $CheckedComments = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedComments', array()); if (!is_array($CheckedComments)) $CheckedComments = array(); $CommentIDs = array(); foreach ($CheckedComments as $DiscID => $Comments) { foreach ($Comments as $Comment) { if (substr($Comment, 0, 8) == 'Comment_' && $DiscID == $DiscussionID) $CommentIDs[] = str_replace('Comment_', '', $Comment); } } // Load category data $Sender->ShowCategorySelector = (bool)C('Vanilla.Categories.Use'); if ($Sender->ShowCategorySelector) { $CategoryModel = new CategoryModel(); $CategoryData = $CategoryModel->GetFull('', 'Vanilla.Discussions.Add'); $aCategoryData = array(); foreach ($CategoryData->Result() as $Category) { if ($Category->CategoryID <= 0) continue; if ($Discussion->CategoryID == $Category->CategoryID) $Sender->Category = $Category; $CategoryName = $Category->Name; if ($Category->Depth > 1) { $CategoryName = '↳ '.$CategoryName; $CategoryName = str_pad($CategoryName, strlen($CategoryName) + $Category->Depth - 2, ' ', STR_PAD_LEFT); $CategoryName = str_replace(' ', ' ', $CategoryName); } $aCategoryData[$Category->CategoryID] = $CategoryName; $Sender->EventArguments['aCategoryData'] = &$aCategoryData; $Sender->EventArguments['Category'] = &$Category; $Sender->FireEvent('AfterCategoryItem'); } $Sender->CategoryData = $aCategoryData; } $CountCheckedComments = count($CommentIDs); $Sender->SetData('CountCheckedComments', $CountCheckedComments); // Perform the split if ($Sender->Form->AuthenticatedPostBack()) { // Create a new discussion record $Data = $Sender->Form->FormValues(); $Data['Body'] = sprintf(T('This discussion was created from comments split from: %s.'), Anchor(Gdn_Format::Text($Discussion->Name), 'discussion/'.$Discussion->DiscussionID.'/'.Gdn_Format::Url($Discussion->Name).'/')); $NewDiscussionID = $DiscussionModel->Save($Data); $Sender->Form->SetValidationResults($DiscussionModel->ValidationResults()); if ($Sender->Form->ErrorCount() == 0 && $NewDiscussionID > 0) { // Re-assign the comments to the new discussion record $DiscussionModel->SQL ->Update('Comment') ->Set('DiscussionID', $NewDiscussionID) ->WhereIn('CommentID', $CommentIDs) ->Put(); // Update counts on both discussions $CommentModel = new CommentModel(); $CommentModel->UpdateCommentCount($DiscussionID); $CommentModel->UpdateUserCommentCounts($DiscussionID); $CommentModel->UpdateCommentCount($NewDiscussionID); // Clear selections unset($CheckedComments[$DiscussionID]); Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedComments', $CheckedComments); ModerationController::InformCheckedComments($Sender); $Sender->RedirectUrl = Url('discussion/'.$NewDiscussionID.'/'.Gdn_Format::Url($Data['Name'])); } } $Sender->Render($this->GetView('splitcomments.php')); }
/** * Create or update a discussion. * * @since 2.0.0 * @access public * * @param int $CategoryID Unique ID of the category to add the discussion to. */ public function Discussion($CategoryID = '') { // Override CategoryID if categories are disabled $UseCategories = $this->ShowCategorySelector = (bool)C('Vanilla.Categories.Use'); if (!$UseCategories) $CategoryID = 0; // Setup head $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('post.js'); $this->AddJsFile('autosave.js'); $Session = Gdn::Session(); // Set discussion, draft, and category data $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0; $this->CategoryID = isset($this->Discussion) ? $this->Discussion->CategoryID : $CategoryID; $this->Category = FALSE; if ($UseCategories) { $CategoryModel = new CategoryModel(); $CategoryData = $CategoryModel->GetFull('', 'Vanilla.Discussions.Add'); $aCategoryData = array(); foreach ($CategoryData->Result() as $Category) { if ($Category->CategoryID <= 0) continue; if ($this->CategoryID == $Category->CategoryID) $this->Category = $Category; $CategoryName = $Category->Name; if ($Category->Depth > 1) { $CategoryName = '↳ '.$CategoryName; $CategoryName = str_pad($CategoryName, strlen($CategoryName) + $Category->Depth - 2, ' ', STR_PAD_LEFT); $CategoryName = str_replace(' ', ' ', $CategoryName); } $aCategoryData[$Category->CategoryID] = $CategoryName; $this->EventArguments['aCategoryData'] = &$aCategoryData; $this->EventArguments['Category'] = &$Category; $this->FireEvent('AfterCategoryItem'); } $this->CategoryData = $aCategoryData; } // Check permission if (isset($this->Discussion)) { // Permission to edit if ($this->Discussion->InsertUserID != $Session->UserID) $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); // Make sure that content can (still) be edited. $EditContentTimeout = C('Garden.EditContentTimeout', -1); $CanEdit = $EditContentTimeout == -1 || strtotime($this->Discussion->DateInserted) + $EditContentTimeout > time(); if (!$CanEdit) $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); $this->Title(T('Edit Discussion')); } else { // Permission to add $this->Permission('Vanilla.Discussions.Add'); $this->Title(T('Start a New Discussion')); } // Set the model on the form $this->Form->SetModel($this->DiscussionModel); if ($this->Form->AuthenticatedPostBack() === FALSE) { // Prep form with current data for editing if (isset($this->Discussion)) { $this->Form->SetData($this->Discussion); } else if (isset($this->Draft)) $this->Form->SetData($this->Draft); else $this->Form->SetData(array('CategoryID' => $CategoryID)); } else { // Form was submitted // Save as a draft? $FormValues = $this->Form->FormValues(); $this->DeliveryType(GetIncomingValue('DeliveryType', $this->_DeliveryType)); if ($DraftID == 0) $DraftID = $this->Form->GetFormValue('DraftID', 0); $Draft = $this->Form->ButtonExists('Save Draft') ? TRUE : FALSE; $Preview = $this->Form->ButtonExists('Preview') ? TRUE : FALSE; if (!$Preview) { if (!is_object($this->Category) && isset($FormValues['CategoryID'])) $this->Category = $aCategoryData[$FormValues['CategoryID']]; if (is_object($this->Category)) { // Check category permissions. if ($this->Form->GetFormValue('Announce', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $this->Category->PermissionCategoryID)) $this->Form->AddError('You do not have permission to announce in this category', 'Announce'); if ($this->Form->GetFormValue('Close', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $this->Category->PermissionCategoryID)) $this->Form->AddError('You do not have permission to close in this category', 'Close'); if ($this->Form->GetFormValue('Sink', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $this->Category->PermissionCategoryID)) $this->Form->AddError('You do not have permission to sink in this category', 'Sink'); if (!$Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', $this->Category->PermissionCategoryID)) $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID'); } // Make sure that the title will not be invisible after rendering $Name = trim($this->Form->GetFormValue('Name', '')); if ($Name != '' && Gdn_Format::Text($Name) == '') $this->Form->AddError(T('You have entered an invalid discussion title'), 'Name'); else { // Trim the name. $FormValues['Name'] = $Name; $this->Form->SetFormValue('Name', $Name); } if ($this->Form->ErrorCount() == 0) { if ($Draft) { $DraftID = $this->DraftModel->Save($FormValues); $this->Form->SetValidationResults($this->DraftModel->ValidationResults()); } else { $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel); $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults()); if ($DiscussionID > 0 && $DraftID > 0) $this->DraftModel->Delete($DraftID); if ($DiscussionID == SPAM) { $this->StatusMessage = T('Your post has been flagged for moderation.'); $this->Render('Spam'); return; } } } } else { // If this was a preview click, create a discussion/comment shell with the values for this comment $this->Discussion = new stdClass(); $this->Discussion->Name = $this->Form->GetValue('Name', ''); $this->Comment = new stdClass(); $this->Comment->InsertUserID = $Session->User->UserID; $this->Comment->InsertName = $Session->User->Name; $this->Comment->InsertPhoto = $Session->User->Photo; $this->Comment->DateInserted = Gdn_Format::Date(); $this->Comment->Body = ArrayValue('Body', $FormValues, ''); $this->EventArguments['Discussion'] = &$this->Discussion; $this->EventArguments['Comment'] = &$this->Comment; $this->FireEvent('BeforeDiscussionPreview'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { $this->AddAsset('Content', $this->FetchView('preview')); } else { $this->View = 'preview'; } } if ($this->Form->ErrorCount() > 0) { // Return the form errors $this->ErrorMessage($this->Form->Errors()); } else if ($DiscussionID > 0 || $DraftID > 0) { // Make sure that the ajax request form knows about the newly created discussion or draft id $this->SetJson('DiscussionID', $DiscussionID); $this->SetJson('DraftID', $DraftID); if (!$Preview) { // If the discussion was not a draft if (!$Draft) { // Redirect to the new discussion $Discussion = $this->DiscussionModel->GetID($DiscussionID); $this->EventArguments['Discussion'] = $Discussion; $this->FireEvent('AfterDiscussionSave'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { Redirect('/discussion/'.$DiscussionID.'/'.Gdn_Format::Url($Discussion->Name)); } else { $this->RedirectUrl = Url('/discussion/'.$DiscussionID.'/'.Gdn_Format::Url($Discussion->Name)); } } else { // If this was a draft save, notify the user about the save $this->InformMessage(sprintf(T('Draft saved at %s'), Gdn_Format::Date())); } } } } // Add hidden fields for editing $this->Form->AddHidden('DiscussionID', $DiscussionID); $this->Form->AddHidden('DraftID', $DraftID, TRUE); $this->FireEvent('BeforeDiscussionRender'); // Render view (posts/discussion.php or post/preview.php) $this->Render(); }
/** * Create a discussion. * * @param int The CategoryID to add the discussion to. */ public function Discussion($CategoryID = '') { $Session = Gdn::Session(); $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0; $this->CategoryID = isset($this->Discussion) ? $this->Discussion->CategoryID : $CategoryID; if (Gdn::Config('Vanilla.Categories.Use') === TRUE) { $CategoryModel = new CategoryModel(); // Filter to categories that this user can add to $CategoryModel->SQL->Distinct()->Join('Permission _p2', '_p2.JunctionID = c.CategoryID', 'inner')->Join('UserRole _ur2', '_p2.RoleID = _ur2.RoleID', 'inner')->BeginWhereGroup()->Where('_ur2.UserID', $Session->UserID)->Where('_p2.`Vanilla.Discussions.Add`', 1)->EndWhereGroup(); $this->CategoryData = $CategoryModel->GetFull(); } $this->AddJsFile('js/library/jquery.autogrow.js'); $this->AddJsFile('post.js'); $this->AddJsFile('autosave.js'); $this->Title(T('Start a New Discussion')); if (isset($this->Discussion)) { if ($this->Discussion->InsertUserID != $Session->UserID) { $this->Permission('Vanilla.Discussions.Edit', $this->Discussion->CategoryID); } } else { $this->Permission('Vanilla.Discussions.Add'); } // Set the model on the form. $this->Form->SetModel($this->DiscussionModel); if ($this->Form->AuthenticatedPostBack() === FALSE) { if (isset($this->Discussion)) { $this->Form->SetData($this->Discussion); } else { if (isset($this->Draft)) { $this->Form->SetData($this->Draft); } else { $this->Form->SetData(array('CategoryID' => $CategoryID)); } } } else { // Save as a draft? $FormValues = $this->Form->FormValues(); if ($DraftID == 0) { $DraftID = $this->Form->GetFormValue('DraftID', 0); } $Draft = $this->Form->ButtonExists('Save Draft') ? TRUE : FALSE; $Preview = $this->Form->ButtonExists('Preview') ? TRUE : FALSE; if (!$Preview) { // Check category permissions if ($this->Form->GetFormValue('Announce', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Announce', $this->CategoryID)) { $this->Form->AddError('You do not have permission to announce in this category', 'Announce'); } if ($this->Form->GetFormValue('Close', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Close', $this->CategoryID)) { $this->Form->AddError('You do not have permission to close in this category', 'Close'); } if ($this->Form->GetFormValue('Sink', '') != '' && !$Session->CheckPermission('Vanilla.Discussions.Sink', $this->CategoryID)) { $this->Form->AddError('You do not have permission to sink in this category', 'Sink'); } if (!$Session->CheckPermission('Vanilla.Discussions.Add', $this->CategoryID)) { $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID'); } if ($this->Form->ErrorCount() == 0) { if ($Draft) { $DraftID = $this->DraftModel->Save($FormValues); $this->Form->SetValidationResults($this->DraftModel->ValidationResults()); } else { $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel); $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults()); if ($DiscussionID > 0 && $DraftID > 0) { $this->DraftModel->Delete($DraftID); } } } } else { // If this was a preview click, create a discussion/comment shell with the values for this comment $this->Discussion = new stdClass(); $this->Discussion->Name = $this->Form->GetValue('Name', ''); $this->Comment = new stdClass(); $this->Comment->InsertUserID = $Session->User->UserID; $this->Comment->InsertName = $Session->User->Name; $this->Comment->InsertPhoto = $Session->User->Photo; $this->Comment->DateInserted = Gdn_Format::Date(); $this->Comment->Body = ArrayValue('Body', $FormValues, ''); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { $this->AddAsset('Content', $this->FetchView('preview')); } else { $this->View = 'preview'; } } if ($this->Form->ErrorCount() > 0) { // Return the form errors $this->StatusMessage = $this->Form->Errors(); } else { if ($DiscussionID > 0 || $DraftID > 0) { // Make sure that the ajax request form knows about the newly created discussion or draft id $this->SetJson('DiscussionID', $DiscussionID); $this->SetJson('DraftID', $DraftID); if (!$Preview) { // If the discussion was not a draft if (!$Draft) { // Redirect to the new discussion $Discussion = $this->DiscussionModel->GetID($DiscussionID); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { Redirect('/vanilla/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name)); } else { $this->RedirectUrl = Url('/vanilla/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($Discussion->Name)); } } else { // If this was a draft save, notify the user about the save $this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date()); } } } } } $this->Form->AddHidden('DiscussionID', $DiscussionID); $this->Form->AddHidden('DraftID', $DraftID, TRUE); $this->Render(); }
/** * Get flagged content & show settings. * * Default method of virtual Flagging controller. */ public function Controller_Index($Sender) { $Sender->AddCssFile('admin.css'); $Sender->AddCssFile($this->GetResource('design/flagging.css', FALSE, FALSE)); $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $ConfigurationModel->SetField(array( 'Plugins.Flagging.UseDiscussions', 'Plugins.Flagging.CategoryID' )); // Set the model on the form. $Sender->Form->SetModel($ConfigurationModel); $CategoryModel = new CategoryModel(); $Sender->CategoryData = $CategoryModel->GetFull('', 'Vanilla.Discussions.Add'); // If seeing the form for the first time... if ($Sender->Form->AuthenticatedPostBack() === FALSE) { // Apply the config settings to the form. $Sender->Form->SetData($ConfigurationModel->Data); } else { $Saved = $Sender->Form->Save(); if($Saved) { $Sender->InformMessage(T("Your changes have been saved.")); } } $FlaggedItems = Gdn::SQL()->Select('*') ->From('Flag fl') ->OrderBy('DateInserted', 'DESC') ->Get(); $Sender->FlaggedItems = array(); while ($Flagged = $FlaggedItems->NextRow(DATASET_TYPE_ARRAY)) { $URL = $Flagged['ForeignURL']; $Index = $Flagged['DateInserted'].'-'.$Flagged['InsertUserID']; $Flagged['EncodedURL'] = str_replace('=','-',base64_encode($Flagged['ForeignURL'])); $Sender->FlaggedItems[$URL][$Index] = $Flagged; } unset($FlaggedItems); $Sender->Render($this->GetView('flagging.php')); }