/** * 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') { // Figure out which category layout to choose (Defined on "Homepage" settings page). $Layout = c('Vanilla.Categories.Layout'); if ($CategoryIdentifier == '') { switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->Discussions(); break; case 'table': $this->table(); break; default: $this->View = 'all'; $this->All(); break; } return; } else { $Category = CategoryModel::categories($CategoryIdentifier); if (empty($Category)) { // Try lowercasing before outright failing $LowerCategoryIdentifier = strtolower($CategoryIdentifier); if ($LowerCategoryIdentifier != $CategoryIdentifier) { $Category = CategoryModel::categories($LowerCategoryIdentifier); if ($Category) { redirect("/categories/{$LowerCategoryIdentifier}", 301); } } throw notFoundException(); } $Category = (object) $Category; Gdn_Theme::section($Category->CssClass); // Load the breadcrumbs. $this->setData('Breadcrumbs', CategoryModel::GetAncestors(val('CategoryID', $Category))); $this->setData('Category', $Category, true); $this->title(htmlspecialchars(val('Name', $Category, ''))); $this->Description(val('Description', $Category), true); if ($Category->DisplayAs == 'Categories') { if (val('Depth', $Category) > c('Vanilla.Categories.NavDepth', 0)) { // Headings don't make sense if we've cascaded down one level. saveToConfig('Vanilla.Categories.DoHeadings', false, false); } trace($this->deliveryMethod(), 'delivery method'); trace($this->deliveryType(), 'delivery type'); trace($this->SyndicationMethod, 'syndication'); if ($this->SyndicationMethod != SYNDICATION_NONE) { // RSS can't show a category list so just tell it to expand all categories. saveToConfig('Vanilla.ExpandCategories', true, false); } else { // This category is an overview style category and displays as a category list. switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->Discussions($CategoryIdentifier); break; case 'table': $this->table($CategoryIdentifier); break; default: $this->View = 'all'; $this->All($CategoryIdentifier); break; } return; } } Gdn_Theme::section('DiscussionList'); // Figure out which discussions layout to choose (Defined on "Homepage" settings page). $Layout = c('Vanilla.Discussions.Layout'); switch ($Layout) { case 'table': if ($this->SyndicationMethod == SYNDICATION_NONE) { $this->View = 'table'; } break; default: // $this->View = 'index'; break; } // Load the subtree. $Categories = CategoryModel::GetSubtree($CategoryIdentifier, false); $this->setData('Categories', $Categories); // Setup head $this->Menu->highlightRoute('/discussions'); if ($this->Head) { $this->addJsFile('discussions.js'); $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->title()); } // Set CategoryID $CategoryID = val('CategoryID', $Category); $this->setData('CategoryID', $CategoryID, true); // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); // Get a DiscussionModel $DiscussionModel = new DiscussionModel(); $CategoryIDs = array($CategoryID); if (c('Vanilla.ExpandCategories')) { $CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID')); } $Wheres = array('d.CategoryID' => $CategoryIDs); $this->setData('_ShowCategoryLink', count($CategoryIDs) > 1); // Check permission $this->permission('Vanilla.Discussions.View', true, 'Category', val('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; } $Page = PageNumber($Offset, $Limit); // Allow page manipulation $this->EventArguments['Page'] =& $Page; $this->EventArguments['Offset'] =& $Offset; $this->EventArguments['Limit'] =& $Limit; $this->fireEvent('AfterPageCalculation'); // We want to limit the number of pages on large databases because requesting a super-high page can kill the db. $MaxPages = c('Vanilla.Categories.MaxPages'); if ($MaxPages && $Page > $MaxPages) { throw notFoundException(); } $CountDiscussions = $DiscussionModel->getCount($Wheres); if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) { $CountDiscussions = $MaxPages * $Limit; } $this->setData('CountDiscussions', $CountDiscussions); $this->setData('_Limit', $Limit); // We don't wan't child categories in announcements. $Wheres['d.CategoryID'] = $CategoryID; $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet(); $this->setData('AnnounceData', $AnnounceData, true); $Wheres['d.CategoryID'] = $CategoryIDs; $this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhere($Wheres, $Offset, $Limit)); // 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($Offset, $Limit, $CountDiscussions, array('CategoryUrl')); $this->Pager->Record = $Category; PagerModule::Current($this->Pager); $this->setData('_Page', $Page); $this->setData('_Limit', $Limit); $this->fireEvent('AfterBuildPager'); // Set the canonical Url. $this->canonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit))); // Change the controller name so that it knows to grab the discussion views $this->ControllerName = 'DiscussionsController'; // Pick up the discussions class $this->CssClass = 'Discussions Category-' . GetValue('UrlCode', $Category); // 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->fireEvent('BeforeCategoriesRender'); $this->render(); } }
/** * Display discussions started by the user. * * @since 2.0.0 * @access public * * @param int $Offset Number of discussions to skip. */ public function mine($Page = 'p1') { $this->permission('Garden.SignIn.Allow'); Gdn_Theme::section('DiscussionList'); // Set criteria & get discussions data list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30)); $Session = Gdn::session(); $Wheres = array('d.InsertUserID' => $Session->UserID); $DiscussionModel = new DiscussionModel(); $this->DiscussionData = $DiscussionModel->get($Offset, $Limit, $Wheres); $this->setData('Discussions', $this->DiscussionData); $CountDiscussions = $this->setData('CountDiscussions', $DiscussionModel->getCount($Wheres)); $this->View = 'index'; if (c('Vanilla.Discussions.Layout') === 'table') { $this->View = 'table'; } // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->EventArguments['PagerType'] = 'MorePager'; $this->fireEvent('BeforeBuildMinePager'); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->MoreCode = 'More Discussions'; $this->Pager->LessCode = 'Newer Discussions'; $this->Pager->ClientID = 'Pager'; $this->Pager->configure($Offset, $Limit, $CountDiscussions, 'discussions/mine/%1$s'); $this->setData('_PagerUrl', 'discussions/mine/{Page}'); $this->setData('_Page', $Page); $this->setData('_Limit', $Limit); $this->fireEvent('AfterBuildMinePager'); // 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('DiscussionFilterModule'); $this->addModule('NewDiscussionModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); // Render view $this->setData('Title', t('My Discussions')); $this->setData('Breadcrumbs', array(array('Name' => t('My Discussions'), 'Url' => '/discussions/mine'))); $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') { // Figure out which category layout to choose (Defined on "Homepage" settings page). $Layout = c('Vanilla.Categories.Layout'); if ($CategoryIdentifier == '') { switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->discussions(); break; case 'table': $this->table(); break; default: $this->View = 'all'; $this->all('', CategoryModel::getRootDisplayAs()); break; } return; } else { $Category = CategoryModel::categories($CategoryIdentifier); if (empty($Category)) { throw notFoundException(); } $Category = (object) $Category; Gdn_Theme::section($Category->CssClass); // Load the breadcrumbs. $this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $Category))); $this->setData('Category', $Category, true); $this->title(htmlspecialchars(val('Name', $Category, ''))); $this->description(val('Description', $Category), true); switch ($Category->DisplayAs) { case 'Flat': case 'Heading': case 'Categories': $stopHeadings = val('Depth', $Category) > CategoryModel::instance()->getNavDepth(); CategoryModel::instance()->setStopHeadingsCalculation($stopHeadings); if ($this->SyndicationMethod != SYNDICATION_NONE) { // RSS can't show a category list so just tell it to expand all categories. saveToConfig('Vanilla.ExpandCategories', true, false); } else { // This category is an overview style category and displays as a category list. switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->discussions($CategoryIdentifier); break; case 'table': $this->table($CategoryIdentifier, $Category->DisplayAs); break; default: $this->View = 'all'; $this->All($CategoryIdentifier, $Category->DisplayAs); break; } return; } break; } Gdn_Theme::section('DiscussionList'); // Figure out which discussions layout to choose (Defined on "Homepage" settings page). $Layout = c('Vanilla.Discussions.Layout'); switch ($Layout) { case 'table': if ($this->SyndicationMethod == SYNDICATION_NONE) { $this->View = 'table'; } break; default: // $this->View = 'index'; break; } $this->setData('CategoryTree', $this->getCategoryTree($CategoryIdentifier, val('DisplayAs', $Category))); // Add a backwards-compatibility shim for the old categories. $this->categoriesCompatibilityCallback = function () use($CategoryIdentifier) { $categories = CategoryModel::getSubtree($CategoryIdentifier, false); return $categories; }; // Setup head $this->Menu->highlightRoute('/discussions'); if ($this->Head) { $this->addJsFile('discussions.js'); $this->Head->addRss(categoryUrl($Category) . '/feed.rss', $this->Head->title()); } // Set CategoryID $CategoryID = val('CategoryID', $Category); $this->setData('CategoryID', $CategoryID, true); // Add modules $this->addModule('NewDiscussionModule'); $this->addModule('DiscussionFilterModule'); $this->addModule('CategoriesModule'); $this->addModule('BookmarkedModule'); // Get a DiscussionModel $DiscussionModel = new DiscussionModel(); $DiscussionModel->setSort(Gdn::request()->get()); $DiscussionModel->setFilters(Gdn::request()->get()); $this->setData('Sort', $DiscussionModel->getSort()); $this->setData('Filters', $DiscussionModel->getFilters()); $CategoryIDs = array($CategoryID); if (c('Vanilla.ExpandCategories')) { $CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID')); } $Wheres = array('d.CategoryID' => $CategoryIDs); $this->setData('_ShowCategoryLink', count($CategoryIDs) > 1); // Check permission $this->permission('Vanilla.Discussions.View', true, 'Category', val('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; } $Page = PageNumber($Offset, $Limit); // Allow page manipulation $this->EventArguments['Page'] =& $Page; $this->EventArguments['Offset'] =& $Offset; $this->EventArguments['Limit'] =& $Limit; $this->fireEvent('AfterPageCalculation'); // We want to limit the number of pages on large databases because requesting a super-high page can kill the db. $MaxPages = c('Vanilla.Categories.MaxPages'); if ($MaxPages && $Page > $MaxPages) { throw notFoundException(); } $CountDiscussions = $DiscussionModel->getCount($Wheres); if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) { $CountDiscussions = $MaxPages * $Limit; } $this->setData('CountDiscussions', $CountDiscussions); $this->setData('_Limit', $Limit); // We don't wan't child categories in announcements. $Wheres['d.CategoryID'] = $CategoryID; $AnnounceData = $DiscussionModel->getAnnouncements($Wheres, $Offset, $Limit); $this->AnnounceData = $this->setData('Announcements', $AnnounceData); $Wheres['d.CategoryID'] = $CategoryIDs; // RSS should include announcements. if ($this->SyndicationMethod !== SYNDICATION_NONE) { $Wheres['Announce'] = 'all'; } $this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhereRecent($Wheres, $Limit, $Offset)); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $url = CategoryUrl($CategoryIdentifier); $this->EventArguments['PagerType'] = 'Pager'; $this->fireEvent('BeforeBuildPager'); if (!$this->data('_PagerUrl')) { $this->setData('_PagerUrl', $url . '/{Page}'); } $queryString = DiscussionModel::getSortFilterQueryString($DiscussionModel->getSort(), $DiscussionModel->getFilters()); $this->setData('_PagerUrl', $this->data('_PagerUrl') . $queryString); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->ClientID = 'Pager'; $this->Pager->configure($Offset, $Limit, $CountDiscussions, $this->data('_PagerUrl')); $this->Pager->Record = $Category; PagerModule::current($this->Pager); $this->setData('_Page', $Page); $this->setData('_Limit', $Limit); $this->fireEvent('AfterBuildPager'); // Set the canonical Url. $this->canonicalUrl(categoryUrl($Category, pageNumber($Offset, $Limit))); // Change the controller name so that it knows to grab the discussion views $this->ControllerName = 'DiscussionsController'; // Pick up the discussions class $this->CssClass = 'Discussions Category-' . val('UrlCode', $Category); // 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->fireEvent('BeforeCategoriesRender'); $this->render(); } }