/** * Default single discussion display. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique discussion ID * @param string $DiscussionStub URL-safe title slug * @param int $Page The current page of comments */ public function Index($DiscussionID = '', $DiscussionStub = '', $Page = '') { // Setup head $Session = Gdn::Session(); $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('discussion.js'); $this->AddJsFile('autosave.js'); Gdn_Theme::Section('Discussion'); // Load the discussion record $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0; if (!array_key_exists('Discussion', $this->Data)) { $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE); } if (!is_object($this->Discussion)) { throw new Exception(sprintf(T('%s Not Found'), T('Discussion')), 404); } // Define the query offset & limit. $Limit = C('Vanilla.Comments.PerPage', 30); $OffsetProvided = $Page != ''; list($Offset, $Limit) = OffsetLimit($Page, $Limit); // Check permissions $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->PermissionCategoryID); $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE); $this->SetData('Breadcrumbs', CategoryModel::GetAncestors($this->CategoryID)); $Category = CategoryModel::Categories($this->Discussion->CategoryID); if ($CategoryCssClass = GetValue('CssClass', $Category)) { Gdn_Theme::Section($CategoryCssClass); } // Setup $this->Title($this->Discussion->Name); // Actual number of comments, excluding the discussion itself. $ActualResponses = $this->Discussion->CountComments; $this->Offset = $Offset; if (C('Vanilla.Comments.AutoOffset')) { // if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '') // $this->AddDefinition('ScrollTo', 'a[name=Item_'.$this->Discussion->CountCommentWatch.']'); if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) { // Round down to the appropriate offset based on the user's read comments & comments per page $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0; if ($CountCommentWatch > $ActualResponses) { $CountCommentWatch = $ActualResponses; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountCommentWatch / $Limit) * $Limit; } if ($ActualResponses <= $Limit) { $this->Offset = 0; } if ($this->Offset == $ActualResponses) { $this->Offset -= $Limit; } } else { if ($this->Offset == '') { $this->Offset = 0; } } if ($this->Offset < 0) { $this->Offset = 0; } $LatestItem = $this->Discussion->CountCommentWatch; if ($LatestItem === NULL) { $LatestItem = 0; } elseif ($LatestItem < $this->Discussion->CountComments) { $LatestItem += 1; } $this->SetData('_LatestItem', $LatestItem); // Set the canonical url to have the proper page title. $this->CanonicalUrl(DiscussionUrl($this->Discussion, PageNumber($this->Offset, $Limit, 0, FALSE))); // Url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE, Gdn::Session()->UserID != 0)), TRUE), Gdn::Session()->UserID == 0); // Load the comments $this->SetData('Comments', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset)); $PageNumber = PageNumber($this->Offset, $Limit); $this->SetData('Page', $PageNumber); $this->_SetOpenGraph(); include_once PATH_LIBRARY . '/vendors/simplehtmldom/simple_html_dom.php'; if ($PageNumber == 1) { $this->Description(SliceParagraph(Gdn_Format::PlainText($this->Discussion->Body, $this->Discussion->Format), 160)); // Add images to head for open graph $Dom = str_get_html(Gdn_Format::To($this->Discussion->Body, $this->Discussion->Format)); } else { $this->Data['Title'] .= sprintf(T(' - Page %s'), PageNumber($this->Offset, $Limit)); $FirstComment = $this->Data('Comments')->FirstRow(); $FirstBody = GetValue('Body', $FirstComment); $FirstFormat = GetValue('Format', $FirstComment); $this->Description(SliceParagraph(Gdn_Format::PlainText($FirstBody, $FirstFormat), 160)); // Add images to head for open graph $Dom = str_get_html(Gdn_Format::To($FirstBody, $FirstFormat)); } if ($Dom) { foreach ($Dom->find('img') as $img) { if (isset($img->src)) { $this->Image($img->src); } } } // Make sure to set the user's discussion watch records $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->EventArguments['PagerType'] = 'Pager'; $this->FireEvent('BeforeBuildPager'); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, array('DiscussionUrl')); $this->Pager->Record = $this->Discussion; PagerModule::Current($this->Pager); $this->FireEvent('AfterBuildPager'); // Define the form for the comment input $this->Form = Gdn::Factory('Form', 'Comment'); $this->Form->Action = Url('/vanilla/post/comment/'); $this->DiscussionID = $this->Discussion->DiscussionID; $this->Form->AddHidden('DiscussionID', $this->DiscussionID); $this->Form->AddHidden('CommentID', ''); // Look in the session stash for a comment $StashComment = $Session->Stash('CommentForDiscussionID_' . $this->Discussion->DiscussionID, '', FALSE); if ($StashComment) { $this->Form->SetFormValue('Body', $StashComment); } // Retrieve & apply the draft if there is one: if (Gdn::Session()->UserID) { $DraftModel = new DraftModel(); $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow(); $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : ''); if ($Draft && !$this->Form->IsPostBack()) { $this->Form->SetValue('Body', $Draft->Body); $this->Form->SetValue('Format', $Draft->Format); } } // 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 = 'comments'; } // Inform moderator of checked comments in this discussion $CheckedComments = $Session->GetAttribute('CheckedComments', array()); if (count($CheckedComments) > 0) { ModerationController::InformCheckedComments($this); } // Add modules $this->AddModule('DiscussionFilterModule'); $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); $this->CanEditComments = Gdn::Session()->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', 'any') && C('Vanilla.AdminCheckboxes.Use'); // Report the discussion id so js can use it. $this->AddDefinition('DiscussionID', $DiscussionID); $this->FireEvent('BeforeDiscussionRender'); $this->Render(); }
/** * 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($CategoryUrlCode = '') { // Override CategoryID if categories are disabled $UseCategories = $this->ShowCategorySelector = (bool) C('Vanilla.Categories.Use'); if (!$UseCategories) { $CategoryUrlCode = ''; } // Setup head $this->AddJsFile('jquery.autosize.min.js'); $this->AddJsFile('post.js'); $this->AddJsFile('autosave.js'); $Session = Gdn::Session(); Gdn_Theme::Section('PostDiscussion'); // Set discussion, draft, and category data $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0; $Category = FALSE; if (isset($this->Discussion)) { $this->CategoryID = $this->Discussion->CategoryID; $Category = CategoryModel::Categories($this->CategoryID); } else { if ($CategoryUrlCode != '') { $CategoryModel = new CategoryModel(); $Category = $CategoryModel->GetByCode($CategoryUrlCode); $this->CategoryID = $Category->CategoryID; } } if ($Category) { $this->Category = (object) $Category; $this->SetData('Category', $Category); } else { $this->CategoryID = 0; $this->Category = NULL; } $CategoryData = $UseCategories ? CategoryModel::Categories() : FALSE; // 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); } // Make sure only moderators can edit closed things if ($this->Discussion->Closed) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); } $this->Form->SetFormValue('DiscussionID', $this->Discussion->DiscussionID); $this->Title(T('Edit Discussion')); if ($this->Discussion->Type) { $this->SetData('Type', $this->Discussion->Type); } else { $this->SetData('Type', 'Discussion'); } } else { // Permission to add $this->Permission('Vanilla.Discussions.Add'); $this->Title(T('New Discussion')); } TouchValue('Type', $this->Data, 'Discussion'); // See if we should hide the category dropdown. $AllowedCategories = CategoryModel::GetByPermission('Discussions.Add', $this->Form->GetValue('CategoryID', $this->CategoryID), array('Archived' => 0, 'AllowDiscussions' => 1), array('AllowedDiscussionTypes' => $this->Data['Type'])); if (count($AllowedCategories) == 1) { $AllowedCategory = array_pop($AllowedCategories); $this->ShowCategorySelector = FALSE; $this->Form->AddHidden('CategoryID', $AllowedCategory['CategoryID']); if ($this->Form->IsPostBack() && !$this->Form->GetFormValue('CategoryID')) { $this->Form->SetFormValue('CategoryID', $AllowedCategory['CategoryID']); } } // Set the model on the form $this->Form->SetModel($this->DiscussionModel); if ($this->Form->IsPostBack() == FALSE) { // Prep form with current data for editing if (isset($this->Discussion)) { $this->Form->SetData($this->Discussion); } elseif (isset($this->Draft)) { $this->Form->SetData($this->Draft); } else { if ($this->Category !== NULL) { $this->Form->SetData(array('CategoryID' => $this->Category->CategoryID)); } $this->PopulateForm($this->Form); } } else { // Form was submitted // Save as a draft? $FormValues = $this->Form->FormValues(); $FormValues = $this->DiscussionModel->FilterForm($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) && is_array($CategoryData) && isset($FormValues['CategoryID'])) { $this->Category = GetValue($FormValues['CategoryID'], $CategoryData); } 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 (!isset($this->Discussion) && (!$Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', $this->Category->PermissionCategoryID) || !$this->Category->AllowDiscussions)) { $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) { if ($DraftID > 0) { $this->DraftModel->Delete($DraftID); } } if ($DiscussionID == SPAM || $DiscussionID == UNAPPROVED) { $this->StatusMessage = T('DiscussionRequiresApprovalStatus', 'Your discussion will appear after it is approved.'); $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->Comment->Format = GetValue('Format', $FormValues, C('Garden.InputFormatter')); $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, DATASET_TYPE_OBJECT, array('Slave' => FALSE)); $this->SetData('Discussion', $Discussion); $this->EventArguments['Discussion'] = $Discussion; $this->FireEvent('AfterDiscussionSave'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { Redirect(DiscussionUrl($Discussion)) . '?new=1'; } else { $this->RedirectUrl = DiscussionUrl($Discussion, '', TRUE) . '?new=1'; } } 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'); if ($this->CategoryID) { $Breadcrumbs = CategoryModel::GetAncestors($this->CategoryID); } else { $Breadcrumbs = array(); } $Breadcrumbs[] = array('Name' => $this->Data('Title'), 'Url' => '/post/discussion'); $this->SetData('Breadcrumbs', $Breadcrumbs); $this->SetData('_AnnounceOptions', $this->AnnounceOptions()); // Render view (posts/discussion.php or post/preview.php) $this->Render(); }
/** * Show all (nested) categories. * * @since 2.0.17 * @access public */ public function All() { // Setup head. $this->Menu->HighlightRoute('/discussions'); $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('All Categories')); } Gdn_Theme::Section('CategoryList'); $this->Description(C('Garden.Description', NULL)); $this->SetData('Breadcrumbs', array(array('Name' => T('Categories'), 'Url' => '/categories')), CategoryModel::GetAncestors(GetValue('CategoryID', $Category))); // 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 $CategoryModel = new CategoryModel(); $this->CategoryModel->Watching = !Gdn::Session()->GetPreference('ShowAllCategories'); $Categories = $this->CategoryModel->GetFull()->ResultArray(); $this->SetData('Categories', $Categories); // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('BookmarkedModule'); $this->AddModule($CategoryFollowToggleModule); $this->CanonicalUrl(Url('/categories', TRUE)); // Set a definition of the user's current timezone from the db. jQuery // will pick this up, compare to the browser, and update the user's // timezone if necessary. $CurrentUser = Gdn::Session()->User; if (is_object($CurrentUser)) { $ClientHour = $CurrentUser->HourOffset + date('G', time()); $this->AddDefinition('SetClientHour', $ClientHour); } include_once $this->FetchViewLocation('helper_functions', 'categories'); $this->Render(); }
/** * Show all (nested) categories. * * @param string $Category The url code of the parent category. * @since 2.0.17 * @access public */ public function all($Category = '') { // Setup head. $this->Menu->highlightRoute('/discussions'); if (!$this->title()) { $Title = c('Garden.HomepageTitle'); if ($Title) { $this->title($Title, ''); } else { $this->title(t('All Categories')); } } Gdn_Theme::section('CategoryList'); if (!$Category) { $this->Description(c('Garden.Description', null)); } $this->setData('Breadcrumbs', CategoryModel::GetAncestors(val('CategoryID', $this->data('Category')))); // 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 $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); // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('BookmarkedModule'); $this->addModule($CategoryFollowToggleModule); $this->canonicalUrl(url('/categories', true)); $Location = $this->fetchViewLocation('helper_functions', 'categories', false, false); if ($Location) { include_once $Location; } $this->render(); }
/** * Default single discussion display. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique discussion ID * @param string $DiscussionStub URL-safe title slug * @param int $Page The current page of comments */ public function Index($DiscussionID = '', $DiscussionStub = '', $Page = '') { // Setup head $Session = Gdn::Session(); $this->AddJsFile('jquery.ui.packed.js'); $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('options.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussion.js'); $this->AddJsFile('autosave.js'); // Load the discussion record $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0; if (!array_key_exists('Discussion', $this->Data)) { $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE); } if (!is_object($this->Discussion)) { throw new Exception(sprintf(T('%s Not Found'), T('Discussion')), 404); } // Define the query offset & limit. $Limit = C('Vanilla.Comments.PerPage', 30); $OffsetProvided = $Page != ''; list($Offset, $Limit) = OffsetLimit($Page, $Limit); // Set the canonical url to have the proper page title. $this->CanonicalUrl(Url(ConcatSep('/', 'discussion/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name), PageNumber($Offset, $Limit, TRUE, Gdn::Session()->UserID != 0)), TRUE), Gdn::Session()->UserID == 0); // Check permissions $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->PermissionCategoryID); $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE); $this->SetData('Breadcrumbs', CategoryModel::GetAncestors($this->CategoryID)); // Setup $this->Title($this->Discussion->Name); // Actual number of comments, excluding the discussion itself $ActualResponses = $this->Discussion->CountComments - 1; // If $Offset isn't defined, assume that the user has not clicked to // view a next or previous page, and this is a "view" to be counted. // NOTE: This has been moved to an event fired from analyticstick. // if ($Offset == '') // $this->DiscussionModel->AddView($DiscussionID, $this->Discussion->CountViews); $this->Offset = $Offset; if (C('Vanilla.Comments.AutoOffset')) { if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '') { $this->AddDefinition('ScrollTo', 'a[name=Item_' . $this->Discussion->CountCommentWatch . ']'); } if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) { // Round down to the appropriate offset based on the user's read comments & comments per page $CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0; if ($CountCommentWatch > $ActualResponses) { $CountCommentWatch = $ActualResponses; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountCommentWatch / $Limit) * $Limit; } if ($ActualResponses <= $Limit) { $this->Offset = 0; } if ($this->Offset == $ActualResponses) { $this->Offset -= $Limit; } } else { if ($this->Offset == '') { $this->Offset = 0; } } if ($this->Offset < 0) { $this->Offset = 0; } // Load the comments $this->SetData('CommentData', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE); $this->SetData('Comments', $this->CommentData); // Make sure to set the user's discussion watch records $this->CommentModel->SetWatch($this->Discussion, $this->CommentData->NumRows(), $this->Offset, $this->Discussion->CountComments); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->EventArguments['PagerType'] = 'Pager'; $this->FireEvent('BeforeBuildPager'); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s'); $this->FireEvent('AfterBuildPager'); // Define the form for the comment input $this->Form = Gdn::Factory('Form', 'Comment'); $this->Form->Action = Url('/vanilla/post/comment/'); $this->DiscussionID = $this->Discussion->DiscussionID; $this->Form->AddHidden('DiscussionID', $this->DiscussionID); $this->Form->AddHidden('CommentID', ''); // Retrieve & apply the draft if there is one: if (Gdn::Session()->UserID) { $DraftModel = new DraftModel(); $Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow(); $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : ''); if ($Draft) { $this->Form->SetFormValue('Body', $Draft->Body); } } // 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 = 'comments'; } // Inform moderator of checked comments in this discussion $CheckedComments = $Session->GetAttribute('CheckedComments', array()); if (count($CheckedComments) > 0) { ModerationController::InformCheckedComments($this); } // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); // Report the discussion id so js can use it. $this->AddDefinition('DiscussionID', $DiscussionID); $this->FireEvent('BeforeDiscussionRender'); $this->Render(); }
/** * Show all (nested) categories. * * @since 2.0.17 * @access public */ public function All() { // Setup head. $this->Menu->HighlightRoute('/discussions'); if (!$this->Title()) { $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('All Categories')); } } Gdn_Theme::Section('CategoryList'); $this->Description(C('Garden.Description', NULL)); $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $this->Data('Category')))); // 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 $this->CategoryModel->Watching = !Gdn::Session()->GetPreference('ShowAllCategories'); $Categories = $this->CategoryModel->GetFull()->ResultArray(); $this->SetData('Categories', $Categories); // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('BookmarkedModule'); $this->AddModule($CategoryFollowToggleModule); $this->CanonicalUrl(Url('/categories', TRUE)); $Location = $this->FetchViewLocation('helper_functions', 'categories', FALSE, FALSE); if ($Location) { include_once $Location; } $this->Render(); }
/** * Show all discussions in a particular category. * * @since 2.0.0 * @access public * * @param string $CategoryIdentifier Unique category slug or ID. * @param int $Offset Number of discussions to skip. */ public function Index($CategoryIdentifier = '', $Page = '0') { $Category = CategoryModel::Categories($CategoryIdentifier); if (empty($Category)) { if ($CategoryIdentifier) { throw NotFoundException(); } } $Category = (object) $Category; // Load the breadcrumbs. $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category))); $this->SetData('Category', $Category, TRUE); // Setup head $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); if ($this->Head) { $this->Head->Title(GetValue('Name', $Category, '')); $this->AddJsFile('discussions.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('options.js'); $this->AddJsFile('jquery.gardenmorepager.js'); $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title()); } // Set CategoryID $this->SetData('CategoryID', GetValue('CategoryID', $Category), TRUE); // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); // Get a DiscussionModel $DiscussionModel = new DiscussionModel(); $Wheres = array('d.CategoryID' => $this->CategoryID); // Check permission $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category)); // Set discussion meta data. $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30); $this->FireEvent('BeforeGetDiscussions'); list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']); if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $CountDiscussions = $DiscussionModel->GetCount($Wheres); $this->SetData('CountDiscussions', $CountDiscussions); $this->SetData('_Limit', $Limit); $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet(); $this->SetData('AnnounceData', $AnnounceData, TRUE); $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->Get($Offset, $Limit, $Wheres)); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('Pager', $this); $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s'); $this->SetData('_PagerUrl', 'categories/' . rawurlencode($CategoryIdentifier) . '/{Page}'); $this->SetData('_Page', $Page); // Set the canonical Url. $this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE)); // Change the controller name so that it knows to grab the discussion views $this->ControllerName = 'DiscussionsController'; // Pick up the discussions class $this->CssClass = 'Discussions'; // 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'; } // Render default view $this->Render(); }
/** * Show all (nested) categories. * * @param string $Category The url code of the parent category. * @param string $displayAs * @since 2.0.17 * @access public */ public function all($Category = '', $displayAs = '') { // Setup head. $this->Menu->highlightRoute('/discussions'); if (!$this->title()) { $Title = c('Garden.HomepageTitle'); if ($Title) { $this->title($Title, ''); } else { $this->title(t('All Categories')); } } Gdn_Theme::section('CategoryList'); if (!$Category) { $this->Description(c('Garden.Description', null)); } $this->setData('Breadcrumbs', CategoryModel::GetAncestors(val('CategoryID', $this->data('Category')))); // 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 $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories'); if ($Category) { $this->setData('Category', CategoryModel::categories($Category)); $this->categoriesCompatibilityCallback = function () use($Category) { $Subtree = CategoryModel::GetSubtree($Category, false); $CategoryIDs = array_column($Subtree, 'CategoryID'); return $this->CategoryModel->GetFull($CategoryIDs)->resultArray(); }; } else { $this->categoriesCompatibilityCallback = function () { return $this->CategoryModel->GetFull()->resultArray(); }; } $this->setData('CategoryTree', $this->getCategoryTree($Category ?: -1, $Category ? null : CategoryModel::getRootDisplayAs(), true, true)); // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('BookmarkedModule'); $this->addModule($CategoryFollowToggleModule); $this->canonicalUrl(url('/categories', true)); if ($this->View === 'all' && $displayAs === 'Flat') { $this->View = 'flat_all'; } $Location = $this->fetchViewLocation('helper_functions', 'categories', false, false); if ($Location) { include_once $Location; } $this->render(); }