/** * Load discussions for a specific tag. */ public function DiscussionsController_Tagged_Create($Sender) { $Offset = GetValue('1', $Sender->RequestArgs, 'p1'); list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30)); $Sender->Tag = GetValue('0', $Sender->RequestArgs, ''); $Sender->Title(T('Tagged with ') . $Sender->Tag); $Sender->Head->Title($Sender->Head->Title()); $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . $Sender->Tag, PageNumber($Offset, $Limit, TRUE)), TRUE)); if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->AddJsFile('bookmark.js'); $Sender->AddJsFile('js/library/jquery.menu.js'); $Sender->AddJsFile('options.js'); $Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $DiscussionModel = new DiscussionModel(); $Tag = $DiscussionModel->SQL->Select()->From('Tag')->Where('Name', $Sender->Tag)->Get()->FirstRow(); $TagID = $Tag ? $Tag->TagID : 0; $CountDiscussions = $Tag ? $Tag->CountDiscussions : 0; $Sender->SetData('CountDiscussions', $CountDiscussions); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel->FilterToTagID = $TagID; $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/tagged/' . $Sender->Tag . '/%1$s'); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // 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()); $Sender->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $Sender->Render(PATH_PLUGINS . '/Tagging/views/taggeddiscussions.php'); }
public function Index($Offset = '0') { $this->Permission('Garden.SignIn.Allow'); $this->AddCssFile('vanilla.css'); $this->AddCssFile('form.css'); $Session = Gdn::Session(); if ($this->Head) { $this->Head->AddScript('/applications/vanilla/js/discussions.js'); $this->Head->AddScript('/applications/vanilla/js/options.js'); $this->Head->Title(Translate('My Drafts')); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $Session = Gdn::Session(); $Wheres = array('d.InsertUserID' => $Session->UserID); $this->DraftData = $this->DraftModel->Get($Session->UserID, $Offset, $Limit); $CountDrafts = $this->DraftModel->GetCount($Session->UserID); // Build a pager $PagerFactory = new PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More drafts'; $this->Pager->LessCode = 'Newer drafts'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDrafts, 'drafts/%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 = 'drafts'; } // Add Modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); // Render the controller $this->Render(); }
/** * Default all drafts view: chronological by time saved. * * @since 2.0.0 * @access public * * @param int $Offset Number of drafts to skip. */ public function Index($Offset = '0') { // Setup head $this->Permission('Garden.SignIn.Allow'); $this->AddCssFile('vanilla.css'); $this->AddJsFile('jquery.gardenmorepager.js'); $this->AddJsFile('discussions.js'); $this->AddJsFile('options.js'); $this->Title(T('My Drafts')); // Validate $Offset if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Set criteria & get drafts data $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $Session = Gdn::Session(); $Wheres = array('d.InsertUserID' => $Session->UserID); $this->DraftData = $this->DraftModel->Get($Session->UserID, $Offset, $Limit); $CountDrafts = $this->DraftModel->GetCount($Session->UserID); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More drafts'; $this->Pager->LessCode = 'Newer drafts'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDrafts, 'drafts/%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 = 'drafts'; } // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($this); $BookmarkedModule->GetData(); $this->AddModule($BookmarkedModule); // Render default view (drafts/index.php) $this->Render(); }
/** * Allows you to bookmark or unbookmark a discussion (depending on it's current state). */ public function Bookmark($DiscussionID = '', $TransientKey = '') { $Session = Gdn::Session(); $State = FALSE; if (is_numeric($DiscussionID) && $DiscussionID > 0 && $Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey)) { $Discussion = NULL; } $State = $this->DiscussionModel->BookmarkDiscussion($DiscussionID, $Session->UserID, $Discussion); // Update the user's bookmark count $CountBookmarks = $this->DiscussionModel->SetUserBookmarkCount($Session->UserID); // Redirect back where the user came from if necessary if ($this->_DeliveryType != DELIVERY_TYPE_BOOL) { $Target = GetIncomingValue('Target', 'discussions/bookmarked'); Redirect($Target); } $this->SetJson('State', $State); $this->SetJson('CountBookmarks', $CountBookmarks); $this->SetJson('ButtonLink', T($State ? 'Unbookmark this Discussion' : 'Bookmark this Discussion')); $this->SetJson('AnchorTitle', T($State ? 'Unbookmark' : 'Bookmark')); $this->SetJson('MenuText', T('My Bookmarks')); $Targets = array(); if ($State) { // Grab the individual bookmark and send it to the client. $Bookmarks = new BookmarkedModule($this); if ($CountBookmarks == 1) { // When there is only one bookmark we have to get the whole module. $Target = '#Panel'; $Type = 'Append'; $Bookmarks->GetData(); $Data = $Bookmarks->ToString(); } else { $Target = '#Bookmark_List'; $Type = 'Prepend'; $Loc = $Bookmarks->FetchViewLocation('discussion'); ob_start(); include $Loc; $Data = ob_get_clean(); } $Targets[] = array('Target' => $Target, 'Type' => $Type, 'Data' => $Data); } else { // Send command to remove bookmark html. if ($CountBookmarks == 0) { $Targets[] = array('Target' => '#Bookmarks', 'Type' => 'Remove'); } else { $Targets[] = array('Target' => '#Bookmark_' . $DiscussionID, 'Type' => 'Remove'); } } $this->SetJson('Targets', $Targets); $this->Render(); }
/** * Show all categories, and few discussions from each. */ public function All() { $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); $this->AddJsFile('discussions.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('js/library/jquery.menu.js'); $this->AddJsFile('options.js'); $this->Title(T('All Categories')); $this->DiscussionsPerCategory = Gdn::Config('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new 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); $this->View = 'all'; $this->Render(); }
/** * Allows user to bookmark or unbookmark a discussion. * * If the discussion isn't bookmarked by the user, this bookmarks it. * If it is already bookmarked, this unbookmarks it. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique discussion ID. */ public function bookmark($DiscussionID = null) { // Make sure we are posting back. if (!$this->Request->isAuthenticatedPostBack()) { throw permissionException('Javascript'); } $Session = Gdn::session(); if (!$Session->UserID) { throw permissionException('SignedIn'); } // Check the form to see if the data was posted. $Form = new Gdn_Form(); $DiscussionID = $Form->getFormValue('DiscussionID', $DiscussionID); $Bookmark = $Form->getFormValue('Bookmark', null); $UserID = $Form->getFormValue('UserID', $Session->UserID); // Check the permission on the user. if ($UserID != $Session->UserID) { $this->permission('Garden.Moderation.Manage'); } $Discussion = $this->DiscussionModel->getID($DiscussionID); if (!$Discussion) { throw notFoundException('Discussion'); } $Bookmark = $this->DiscussionModel->bookmark($DiscussionID, $UserID, $Bookmark); // Set the new value for api calls and json targets. $this->setData(array('UserID' => $UserID, 'DiscussionID' => $DiscussionID, 'Bookmarked' => (bool) $Bookmark)); setValue('Bookmarked', $Discussion, (int) $Bookmark); // Update the user's bookmark count $CountBookmarks = $this->DiscussionModel->setUserBookmarkCount($UserID); $this->jsonTarget('.User-CountBookmarks', (string) $CountBookmarks); // Short circuit if this is an api call. if ($this->deliveryType() === DELIVERY_TYPE_DATA) { $this->render('Blank', 'Utility', 'Dashboard'); return; } // Return the appropriate bookmark. require_once $this->fetchViewLocation('helper_functions', 'Discussions'); $Html = bookmarkButton($Discussion); // $this->jsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Bookmark,.Section-Discussion .PageTitle .Bookmark", $Html, 'ReplaceWith'); $this->jsonTarget("!element", $Html, 'ReplaceWith'); // Add the bookmark to the bookmarks module. if ($Bookmark) { // Grab the individual bookmark and send it to the client. $Bookmarks = new BookmarkedModule($this); if ($CountBookmarks == 1) { // When there is only one bookmark we have to get the whole module. $Target = '#Panel'; $Type = 'Append'; $Bookmarks->getData(); $Data = $Bookmarks->toString(); } else { $Target = '#Bookmark_List'; $Type = 'Prepend'; $Loc = $Bookmarks->fetchViewLocation('discussion'); ob_start(); include $Loc; $Data = ob_get_clean(); } $this->jsonTarget($Target, $Data, $Type); } else { // Send command to remove bookmark html. if ($CountBookmarks == 0) { $this->jsonTarget('#Bookmarks', null, 'Remove'); } else { $this->jsonTarget('#Bookmark_' . $DiscussionID, null, 'Remove'); } } $this->render('Blank', 'Utility', 'Dashboard'); }
public function Mine($Offset = '0') { $this->Permission('Garden.SignIn.Allow'); if ($this->Head) { $this->Head->AddScript('/js/library/jquery.resizable.js'); $this->Head->AddScript('/js/library/jquery.ui.packed.js'); $this->Head->AddScript('/applications/vanilla/js/bookmark.js'); $this->Head->AddScript('/applications/vanilla/js/discussions.js'); $this->Head->AddScript('/applications/vanilla/js/options.js'); } 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 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); $DraftsModule = new DraftsModule($this); $DraftsModule->GetData(); $this->AddModule($DraftsModule); // Render the controller $this->Render(); }
/** * Allows user to bookmark or unbookmark a discussion. * * If the discussion isn't bookmarked by the user, this bookmarks it. * If it is already bookmarked, this unbookmarks it. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique discussion ID. */ public function Bookmark($DiscussionID) { // Make sure we are posting back. if (!$this->Request->IsAuthenticatedPostBack()) { throw PermissionException('Javascript'); } $Session = Gdn::Session(); if ($Session->UserID == 0) { throw PermissionException('SignedIn'); } $Discussion = $this->DiscussionModel->GetID($DiscussionID); if (!$Discussion) { throw NotFoundException('Discussion'); } $State = $this->DiscussionModel->BookmarkDiscussion($DiscussionID, $Session->UserID, $Discussion); // Update the user's bookmark count $CountBookmarks = $this->DiscussionModel->SetUserBookmarkCount($Session->UserID); $this->JsonTarget('.User-CountBookmarks', (string) $CountBookmarks); // Return the appropriate bookmark. require_once $this->FetchViewLocation('helper_functions', 'Discussions'); $Html = BookmarkButton($Discussion); // $this->JsonTarget(".Section-DiscussionList #Discussion_$DiscussionID .Bookmark,.Section-Discussion .PageTitle .Bookmark", $Html, 'ReplaceWith'); $this->JsonTarget("!element", $Html, 'ReplaceWith'); // Add the bookmark to the bookmarks module. if ($State) { // Grab the individual bookmark and send it to the client. $Bookmarks = new BookmarkedModule($this); if ($CountBookmarks == 1) { // When there is only one bookmark we have to get the whole module. $Target = '#Panel'; $Type = 'Append'; $Bookmarks->GetData(); $Data = $Bookmarks->ToString(); } else { $Target = '#Bookmark_List'; $Type = 'Prepend'; $Loc = $Bookmarks->FetchViewLocation('discussion'); ob_start(); include $Loc; $Data = ob_get_clean(); } $this->JsonTarget($Target, $Data, $Type); } else { // Send command to remove bookmark html. if ($CountBookmarks == 0) { $this->JsonTarget('#Bookmarks', NULL, 'Remove'); } else { $this->JsonTarget('#Bookmark_' . $DiscussionID, NULL, 'Remove'); } } $this->Render('Blank', 'Utility', 'Dashboard'); }
/** * Load popular discussions. */ public function DiscussionsController_Popular_Create($Sender) { // if (!C('Plugins.Voting.Enabled')) // return; $Sender->AddModule('DiscussionFilterModule'); $Sender->Title(T('Popular')); $Sender->Head->Title($Sender->Head->Title()); $Offset = GetValue('0', $Sender->RequestArgs, '0'); // Get rid of announcements from this view if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $Limit = C('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new DiscussionModel(); $CountDiscussions = $DiscussionModel->GetCount(); $Sender->SetData('CountDiscussions', $CountDiscussions); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel->SQL->OrderBy('d.CountViews', 'desc'); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/popular/%1$s'); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Render the controller $Sender->View = 'index'; $Sender->Render(); }
/** * Load discussions for a specific tag. */ public function DiscussionsController_Tagged_Create($Sender) { if ($Sender->Request->Get('Tag')) { $Tag = $Sender->Request->Get('Tag'); $Page = GetValue('0', $Sender->RequestArgs, 'p1'); } else { $Tag = urldecode(GetValue('0', $Sender->RequestArgs, '')); $Page = GetValue('1', $Sender->RequestArgs, 'p1'); } if ($Sender->Request->Get('Page')) { $Page = $Sender->Request->Get('Page'); } $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE); list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30)); $Sender->SetData('Tag', $Tag, TRUE); $Sender->Title(T('Tagged with ') . htmlspecialchars($Tag)); $Sender->Head->Title($Sender->Head->Title()); if (urlencode($Tag) == $Tag) { $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . urlencode($Tag), PageNumber($Offset, $Limit, TRUE)), TRUE)); } else { $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . urlencode($Tag), TRUE)); } if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->AddJsFile('bookmark.js'); $Sender->AddJsFile('js/library/jquery.menu.js'); $Sender->AddJsFile('options.js'); $Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $Sender->SetData('CountDiscussions', FALSE); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel = new DiscussionModel(); $this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or')); $Sender->DiscussionData = $DiscussionModel->Get(FALSE); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; if (urlencode($Sender->Tag) == $Sender->Tag) { $PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}"; } else { $PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag); } $Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat); // Deliver json data if necessary. if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // 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()); $Sender->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $Sender->Render('TaggedDiscussions', '', 'plugins/Tagging'); }
public function Mine($Offset = '0') { $this->Permission('Garden.SignIn.Allow'); 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 DiscussionModel(); $this->DiscussionData = $DiscussionModel->Get($Offset, $Limit, $Wheres); $this->SetData('Discussions', $this->DiscussionData); $CountDiscussions = $this->SetData('CountDiscussions', $DiscussionModel->GetCount($Wheres)); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $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'); // 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(); }
/** * 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(); }
/** * Load popular discussions. */ public function DiscussionsController_Popular_Create($Sender) { if (!C('Plugins.Voting.Enabled')) return; $Sender->Title(T('Popular')); $Sender->Head->Title($Sender->Head->Title()); $Offset = GetValue('0', $Sender->RequestArgs, '0'); // Get rid of announcements from this view if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->AddJsFile('bookmark.js'); $Sender->AddJsFile('options.js'); $Sender->Head->AddRss($Sender->SelfUrl.'/feed.rss', $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) $Offset = 0; // Add Modules $Sender->AddModule('NewDiscussionModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $Limit = C('Vanilla.Discussions.PerPage', 30); $DiscussionModel = new DiscussionModel(); $CountDiscussions = $DiscussionModel->GetCount(); $Sender->SetData('CountDiscussions', $CountDiscussions); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel->SQL->OrderBy('d.CountViews', 'desc'); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure( $Offset, $Limit, $CountDiscussions, 'discussions/popular/%1$s' ); // Deliver json data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // 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()); $Sender->AddDefinition('SetClientHour', $ClientHour); } // Render the controller $Sender->View = 'index'; $Sender->Render(); }
public function DiscussionsController_Participated_Create(&$Sender, $Args) { $Sender->Permission('Garden.SignIn.Allow'); $Page = GetValue(0, $Args); $Limit = GetValue(1, $Args); list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30)); // Get Discussions $DiscussionModel = new DiscussionModel(); $Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit); $Sender->SetData('Discussions', $Sender->DiscussionData); $CountDiscussions = $DiscussionModel->GetCountParticipated(Gdn::Session()->UserID); $Sender->SetData('CountDiscussions', $CountDiscussions); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $Sender->EventArguments['PagerType'] = 'Pager'; $Sender->FireEvent('BeforeBuildPager'); $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/participated/%1$s'); $Sender->FireEvent('AfterBuildPager'); // Deliver JSON data if necessary if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Add modules $Sender->AddModule('NewDiscussionModule'); $Sender->AddModule('CategoriesModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->Render($this->GetView('participated.php')); }
/** * Load discussions for a specific tag. */ public function DiscussionsController_Tagged_Create($Sender) { Gdn_Theme::Section('DiscussionList'); if ($Sender->Request->Get('Tag')) { $Tag = $Sender->Request->Get('Tag'); $Page = GetValue('0', $Sender->RequestArgs, 'p1'); } else { $Tag = urldecode(GetValue('0', $Sender->RequestArgs, '')); $Page = GetValue('1', $Sender->RequestArgs, 'p1'); } if ($Sender->Request->Get('Page')) { $Page = $Sender->Request->Get('Page'); } $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE); list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30)); $Sender->SetData('Tag', $Tag, TRUE); $Sender->Title(T('Tagged with ') . htmlspecialchars($Tag)); $Sender->Head->Title($Sender->Head->Title()); $UrlTag = rawurlencode($Tag); if (urlencode($Tag) == $Tag) { $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE)); $FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//'); } else { $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE)); $FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//'); } if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->Head->AddRss($FeedUrl, $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $Sender->AddModule('DiscussionFilterModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $Sender->SetData('CountDiscussions', FALSE); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel = new DiscussionModel(); $this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or')); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all')); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; if (urlencode($Sender->Tag) == $Sender->Tag) { $PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}"; } else { $PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag); } $Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat); // Deliver json data if necessary. if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Render the controller $Sender->Render('TaggedDiscussions', '', 'plugins/Tagging'); }