Пример #1
0
 public function Index($Offset = 0, $Limit = NULL)
 {
     $this->AddJsFile('/js/library/jquery.gardenmorepager.js');
     $this->AddJsFile('search.js');
     $this->Title(T('Search'));
     if (!is_numeric($Limit)) {
         $Limit = Gdn::Config('Garden.Search.PerPage', 20);
     }
     $Search = $this->Form->GetFormValue('Search');
     $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
     $this->SetData('SearchResults', $ResultSet, TRUE);
     $this->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE);
     if ($ResultSet) {
         $NumResults = $ResultSet->NumRows();
     } else {
         $NumResults = 0;
     }
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Pager = $PagerFactory->GetPager('MorePager', $this);
     $Pager->MoreCode = 'More Results';
     $Pager->LessCode = 'Previous Results';
     $Pager->ClientID = 'Pager';
     $Pager->Configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::Url($Search));
     $this->SetData('Pager', $Pager, TRUE);
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'results';
     }
     $this->Render();
 }
 private function BuildPager($Sender, $Total)
 {
     $Sanitized = $this->ValidateInputs();
     //get offset
     $GETString = '?' . Gdn_Url::QueryString() . '&tar=srch';
     //use this to providea link back to search - be sure to append the '&tar=srch' to tell to load the main search page
     $GETString = str_replace('p=search&', 'search?', $GETString);
     //echo $GETString; die;
     $Limit = $this->Settings['Admin']->LimitResultsPage;
     $Offset = ($Sanitized['Offset'] - 1) * $Limit;
     //limit per page
     $Pos = strpos($GETString, '&pg=' . $_GET['pg']);
     if (!$Pos == FALSE) {
         //$Url = substr($GETString, 0, $Pos); //strip the page number if it exists
         $Url = str_replace('&pg=' . GetIncomingValue('pg'), '', $GETString);
         //strip the page number if it exists
         $Url = str_replace('&tar=srch', '', $Url);
         //don't want to load adv search page when clicking page numbers
     } else {
         $Url = str_replace('&tar=srch', '', $GETString);
     }
     //don't want to load adv search page when clicking page numbers
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
     $Sender->Pager->MoreCode = '>';
     $Sender->Pager->LessCode = '<';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $Total, $Url . '&pg=%1$s');
     //echo $Url; die;
     $Sender->SetData('GETString', $GETString);
 }
Пример #3
0
 /**
  * Show all discussions in a particular category.
  */
 public function Index($CategoryIdentifier = '', $Offset = '0')
 {
     if (!is_numeric($CategoryIdentifier)) {
         $Category = $this->CategoryModel->GetFullByUrlCode(urldecode($CategoryIdentifier));
     } else {
         $Category = $this->CategoryModel->GetFull($CategoryIdentifier);
     }
     $this->SetData('Category', $Category, TRUE);
     if ($Category === FALSE) {
         return $this->All();
     }
     $this->AddCssFile('vanilla.css');
     $this->Menu->HighlightRoute('/discussions');
     if ($this->Head) {
         $this->Head->Title($Category->Name);
         $this->AddJsFile('discussions.js');
         $this->AddJsFile('bookmark.js');
         $this->AddJsFile('js/library/jquery.menu.js');
         $this->AddJsFile('options.js');
         $this->AddJsFile('/js/library/jquery.gardenmorepager.js');
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $this->SetData('CategoryID', $this->Category->CategoryID, TRUE);
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->CategoryID);
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE);
     // 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');
     // 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 the controller
     $this->Render();
 }
Пример #4
0
 /**
  * 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, $Limit = NULL) {
		$this->AddJsFile('jquery.gardenmorepager.js');
		$this->AddJsFile('search.js');
		$this->Title(T('Search'));

		if(!is_numeric($Limit))
			$Limit = Gdn::Config('Garden.Search.PerPage', 20);
		
		$Search = $this->Form->GetFormValue('Search');
      $Mode = $this->Form->GetFormValue('Mode');
      if ($Mode)
         $this->SearchModel->ForceSearchMode = $Mode;
      try {
         $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
      } catch (Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
         $ResultSet = array();
      } catch (Exception $Ex) {
         $ResultSet = array();
      }
		$this->SetData('SearchResults', $ResultSet, TRUE);
		$this->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE);
		if($ResultSet)
			$NumResults = count($ResultSet);
		else
			$NumResults = 0;
		if ($NumResults == $Offset + $Limit)
			$NumResults++;
		
		// Build a pager
		$PagerFactory = new Gdn_PagerFactory();
		$this->Pager = $PagerFactory->GetPager('MorePager', $this);
		$this->Pager->MoreCode = 'More Results';
		$this->Pager->LessCode = 'Previous Results';
		$this->Pager->ClientID = 'Pager';
		$this->Pager->Configure(
			$Offset,
			$Limit,
			$NumResults,
			'dashboard/search/%1$s/%2$s/?Search='.Gdn_Format::Url($Search)
		);
		
		if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'results';
      }
		
      $this->CanonicalUrl(Url('search', TRUE));

		$this->Render();
	}
 public function Index($Offset = FALSE, $Keywords = '')
 {
     $this->Permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', FALSE);
     $this->AddJsFile('jquery.gardenmorepager.js');
     $this->AddJsFile('user.js');
     $this->Title(T('Users'));
     $this->AddSideMenu('dashboard/user');
     $this->Form->Method = 'get';
     // Input Validation
     $Offset = is_numeric($Offset) ? $Offset : 0;
     if (!$Keywords) {
         $Keywords = $this->Form->GetFormValue('Keywords');
         if ($Keywords) {
             $Offset = 0;
         }
     }
     // Put the Keyword back in the form
     if ($Keywords) {
         $this->Form->SetFormValue('Keywords', $Keywords);
     }
     $UserModel = new UserModel();
     //$Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords, 'u.Email' => $Keywords);
     $Limit = 30;
     $TotalRecords = $UserModel->SearchCount($Keywords);
     $this->UserData = $UserModel->Search($Keywords, 'u.Name', 'asc', $Limit, $Offset);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More';
     $this->Pager->LessCode = 'Previous';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Wrapper = '<tr %1$s><td colspan="5">%2$s</td></tr>';
     $this->Pager->Configure($Offset, $Limit, $TotalRecords, 'user/browse/%1$s/' . urlencode($Keywords));
     // 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 = 'users';
     }
     $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();
 }
Пример #8
0
 /**
  * Creates virtual 'Discussions' method in ProfileController.
  * 
  * @since 2.0.0
  * @package Vanilla
  *
  * @param object $Sender ProfileController.
  */
 public function ProfileController_Discussions_Create(&$Sender)
 {
     $UserReference = ArrayValue(0, $Sender->RequestArgs, '');
     $Username = ArrayValue(1, $Sender->RequestArgs, '');
     $Offset = ArrayValue(2, $Sender->RequestArgs, 0);
     // Tell the ProfileController what tab to load
     $Sender->GetUserInfo($UserReference, $Username);
     $Sender->SetTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
     // Load the data for the requested tab.
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $DiscussionModel = new DiscussionModel();
     $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('d.InsertUserID' => $Sender->User->UserID));
     $CountDiscussions = $Offset + $Sender->DiscussionData->NumRows();
     if ($Sender->DiscussionData->NumRows() == $Limit) {
         $CountDiscussions = $Offset + $Limit + 1;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
     $Sender->Pager->MoreCode = 'More Discussions';
     $Sender->Pager->LessCode = 'Newer Discussions';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'profile/discussions/' . $Sender->User->UserID . '/' . Gdn_Format::Url($Sender->User->Name) . '/%1$s/');
     // Deliver JSON data if necessary
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
         $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
         $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
         $Sender->View = 'discussions';
     }
     // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
     $Sender->HandlerType = HANDLER_TYPE_NORMAL;
     // Do not show discussion options
     $Sender->ShowOptions = FALSE;
     // Render the ProfileController
     $Sender->Render();
 }
 /**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function index($Page = '')
 {
     $this->addJsFile('search.js');
     $this->title(t('Search'));
     saveToConfig('Garden.Format.EmbedSize', '160x90', false);
     Gdn_Theme::section('SearchResults');
     list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
     $this->setData('_Limit', $Limit);
     $Search = $this->Form->getFormValue('Search');
     $Mode = $this->Form->getFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->addError($Ex);
         $ResultSet = array();
     }
     Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
     // Fix up the summaries.
     $SearchTerms = explode(' ', Gdn_Format::text($Search));
     foreach ($ResultSet as &$Row) {
         $Row['Summary'] = SearchExcerpt(Gdn_Format::plainText($Row['Summary'], $Row['Format']), $SearchTerms);
         $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
         $Row['Format'] = 'Html';
     }
     $this->setData('SearchResults', $ResultSet, true);
     $this->setData('SearchTerm', Gdn_Format::text($Search), true);
     if ($ResultSet) {
         $NumResults = count($ResultSet);
     } else {
         $NumResults = 0;
     }
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More Results';
     $this->Pager->LessCode = 'Previous Results';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search));
     //		if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
     //         $this->setJson('LessRow', $this->Pager->toString('less'));
     //         $this->setJson('MoreRow', $this->Pager->toString('more'));
     //         $this->View = 'results';
     //      }
     $this->canonicalUrl(url('search', true));
     $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();
                 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();
     }
 }
Пример #11
0
 /**
  * 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();
 }
   public function Notifications($Offset = '0') {
      $this->Permission('Garden.SignIn.Allow');
		
		$Limit = 50;
		$Offset = is_numeric($Offset) ? $Offset : 0;
      if ($Offset < 0)
         $Offset = 0;

      $this->GetUserInfo(); 
      $this->SetTabView('Notifications');
      $Session = Gdn::Session();
      // Drop notification count back to zero.
      $SQL = Gdn::SQL();
      $SQL
         ->Update('User')
         ->Set('CountNotifications', '0')
         ->Where('UserID', $Session->UserID)
         ->Put();
      
      $this->ActivityModel = new ActivityModel();
      $this->ActivityData = $this->ActivityModel->GetNotifications($Session->UserID, $Offset, $Limit);
		$TotalRecords = $this->ActivityModel->GetCountNotifications($Session->UserID);
		
		// Build a pager
		$PagerFactory = new Gdn_PagerFactory();
		$this->Pager = $PagerFactory->GetPager('MorePager', $this);
		$this->Pager->MoreCode = 'More';
		$this->Pager->LessCode = 'Newer Notifications';
		$this->Pager->ClientID = 'Pager';
		$this->Pager->Configure(
			$Offset,
			$Limit,
			$TotalRecords,
			'profile/notifications/%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'));
			if ($Offset > 0) {
				$this->View = 'activities';
				$this->ControllerName = 'Activity';
			}
		}
		
      $this->Render();
   }   
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     Gdn_Theme::Section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     // Check permissions on the recipients.
     $InConversation = $this->ConversationModel->InConversation($ConversationID, Gdn::Session()->UserID);
     if (!$InConversation) {
         // Conversation moderation must be enabled and they must have permission
         if (!C('Conversations.Moderation.Allow', FALSE)) {
             throw PermissionException();
         }
         $this->Permission('Conversations.Moderation.Manage');
     }
     $this->Conversation = $this->ConversationModel->GetID($ConversationID);
     $this->Conversation->Participants = $this->ConversationModel->GetRecipients($ConversationID);
     $this->SetData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === FALSE) {
         throw NotFoundException('Conversation');
     }
     // Get limit
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     // Calculate counts
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
         // Send the hash link in.
         if ($CountReadMessages > 1) {
             $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages);
         }
     }
     // Fetch message data
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     // Figure out who's participating.
     $ParticipantTitle = ConversationModel::ParticipantTitle($this->Conversation, TRUE);
     $this->Participants = $ParticipantTitle;
     $this->Title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // 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 = 'messages';
     }
     // Add modules.
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->Conversation->Participants);
     $this->AddModule($InThisConversationModule);
     // Doesn't make sense for people who can't even start conversations to be adding people
     if (CheckPermission('Conversations.Conversations.Add')) {
         $this->AddModule('AddPeopleModule');
     }
     $Subject = $this->Data('Conversation.Subject');
     if (!$Subject) {
         $Subject = T('Message');
     }
     $this->Data['Breadcrumbs'][] = array('Name' => $Subject, Url('', '//'));
     // Render view
     $this->Render();
 }
Пример #14
0
 /**
  * Load discussions for a specific tag.
  * @param DiscussionsController $Sender
  */
 public function DiscussionsController_Tagged_Create($Sender)
 {
     Gdn_Theme::Section('DiscussionList');
     $Args = $Sender->RequestArgs;
     $Get = array_change_key_case($Sender->Request->Get());
     if ($UseCategories = C('Plugins.Tagging.UseCategories')) {
         // The url is in the form /category/tag/p1
         $CategoryCode = GetValue(0, $Args);
         $Tag = GetValue(1, $Args);
         $Page = GetValue(2, $Args);
     } else {
         // The url is in the form /tag/p1
         $CategoryCode = '';
         $Tag = GetValue(0, $Args);
         $Page = GetValue(1, $Args);
     }
     // Look for explcit values.
     $CategoryCode = GetValue('category', $Get, $CategoryCode);
     $Tag = GetValue('tag', $Get, $Tag);
     $Page = GetValue('page', $Get, $Page);
     $Category = CategoryModel::Categories($CategoryCode);
     $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
     list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     $MultipleTags = strpos($Tag, ',') !== FALSE;
     $Sender->SetData('Tag', $Tag, TRUE);
     $TagModel = TagModel::instance();
     $RecordCount = FALSE;
     if (!$MultipleTags) {
         $Tags = $TagModel->GetWhere(array('Name' => $Tag))->ResultArray();
         if (count($Tags) == 0) {
             throw NotFoundException('Page');
         }
         if (count($Tags) > 1) {
             foreach ($Tags as $TagRow) {
                 if ($TagRow['CategoryID'] == GetValue('CategoryID', $Category)) {
                     break;
                 }
             }
         } else {
             $TagRow = array_pop($Tags);
         }
         $Tags = $TagModel->getRelatedTags($TagRow);
         $RecordCount = $TagRow['CountDiscussions'];
         $Sender->SetData('CountDiscussions', $RecordCount);
         $Sender->SetData('Tags', $Tags);
         $Sender->SetData('Tag', $TagRow);
         $ChildTags = $TagModel->getChildTags($TagRow['TagID']);
         $Sender->SetData('ChildTags', $ChildTags);
     }
     $Sender->Title(htmlspecialchars($TagRow['FullName']));
     $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');
     $Sender->AddModule('BookmarkedModule');
     $Sender->SetData('Category', FALSE, TRUE);
     $Sender->AnnounceData = FALSE;
     $Sender->SetData('Announcements', array(), TRUE);
     $DiscussionModel = new DiscussionModel();
     $TagModel->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';
     $Sender->Pager->Configure($Offset, $Limit, $RecordCount, '');
     $Sender->View = C('Vanilla.Discussions.Layout');
     /*
           // If these don't equal, then there is a category that should be inserted.
           if ($UseCategories && $Category && $TagRow['FullName'] != GetValue('Name', $Category)) {
              $Sender->Data['Breadcrumbs'][] = array('Name' => $Category['Name'], 'Url' => TagUrl($TagRow));
           }
           $Sender->Data['Breadcrumbs'][] = array('Name' => $TagRow['FullName'], 'Url' => '');
     */
     // Render the controller.
     $this->View = C('Vanilla.Discussions.Layout') == 'table' ? 'table' : 'index';
     $Sender->Render($this->View, 'discussions', 'vanilla');
 }
 /**
  * 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')
 {
     if ($CategoryIdentifier == '') {
         // Figure out which category layout to choose (Defined on "Homepage" settings page).
         $Layout = C('Vanilla.Categories.Layout');
         switch ($Layout) {
             case 'mixed':
                 $this->View = 'discussions';
                 $this->Discussions();
                 break;
             case 'table':
                 $this->Table();
                 break;
             default:
                 $this->View = 'all';
                 $this->All();
                 break;
         }
         return;
     } else {
         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;
         }
         $Category = CategoryModel::Categories($CategoryIdentifier);
         if (empty($Category)) {
             if ($CategoryIdentifier) {
                 throw NotFoundException();
             }
         }
         $Category = (object) $Category;
         Gdn_Theme::Section($Category->CssClass);
         // Load the breadcrumbs.
         $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
         $this->SetData('Category', $Category, TRUE);
         // Load the subtree.
         if (C('Vanilla.ExpandCategories')) {
             $Categories = CategoryModel::GetSubtree($CategoryIdentifier);
         } else {
             $Categories = array($Category);
         }
         $this->SetData('Categories', $Categories);
         // Setup head
         $this->AddCssFile('vanilla.css');
         $this->Menu->HighlightRoute('/discussions');
         if ($this->Head) {
             $this->AddJsFile('discussions.js');
             $this->AddJsFile('bookmark.js');
             $this->AddJsFile('options.js');
             $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
         }
         $this->Title(GetValue('Name', $Category, ''));
         $this->Description(GetValue('Description', $Category), TRUE);
         // Set CategoryID
         $CategoryID = GetValue('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 = ConsolidateArrayValuesByKey($this->Data('Categories'), 'CategoryID');
         $Wheres = array('d.CategoryID' => $CategoryIDs);
         $this->SetData('_ShowCategoryLink', count($CategoryIDs) > 1);
         // 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);
         // 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->Pager = $PagerFactory->GetPager('Pager', $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);
         // 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';
         // 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();
     }
 }
Пример #16
0
 /**
  * Unanswered discussions list.
  */
 public function DiscussionsController_Unanswered_Create($Sender, $Args)
 {
     $Sender->Permission('Garden.Moderation.Manage');
     $Page = ArrayValue(0, $Args, 0);
     // Determine offset from $Page
     list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     // Validate $Page
     if (!is_numeric($Page) || $Page < 0) {
         $Page = 0;
     }
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.Answered' => '0');
     $Sender->DiscussionData = $DiscussionModel->Get($Page, $Limit, $Wheres);
     $Sender->SetData('Discussions', $Sender->DiscussionData);
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $Sender->SetData('CountDiscussions', $CountDiscussions);
     $Sender->Category = FALSE;
     $Sender->SetJson('Loading', $Page . ' to ' . $Limit);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->EventArguments['PagerType'] = 'Pager';
     $Sender->FireEvent('BeforeBuildBookmarkedPager');
     $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Page, $Limit, $CountDiscussions, 'discussions/unanswered/%1$s');
     if (!$Sender->Data('_PagerUrl')) {
         $Sender->SetData('_PagerUrl', 'discussions/unanswered/{Page}');
     }
     $Sender->SetData('_Page', $Page);
     $Sender->SetData('_Limit', $Limit);
     $Sender->FireEvent('AfterBuildBookmarkedPager');
     // 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('DiscussionFilterModule');
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('CategoriesModule');
     // Render default view (discussions/bookmarked.php)
     $Sender->SetData('Title', T('Unanswered'));
     $Sender->SetData('Breadcrumbs', array(array('Name' => T('Unanswered'), 'Url' => '/discussions/unanswered')));
     $Sender->Render('index');
 }
Пример #17
0
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     Gdn_Theme::Section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     // Get conversation data
     $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
     $this->SetData('Recipients', $this->RecipientData);
     // Check permissions on the recipients.
     $InConversation = FALSE;
     foreach ($this->RecipientData->Result() as $Recipient) {
         if ($Recipient->UserID == Gdn::Session()->UserID) {
             $InConversation = TRUE;
             break;
         }
     }
     if (!$InConversation) {
         // Conversation moderation must be enabled and they must have permission
         if (!C('Conversations.Moderation.Allow', FALSE)) {
             throw PermissionException();
         }
         $this->Permission('Conversations.Moderation.Manage');
     }
     $this->Conversation = $this->ConversationModel->GetID($ConversationID);
     $this->SetData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === FALSE) {
         throw NotFoundException('Conversation');
     }
     // Get limit
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     // Calculate counts
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
         // Send the hash link in.
         if ($CountReadMessages > 1) {
             $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages);
         }
     }
     // Fetch message data
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     // Figure out who's participating.
     $this->Participants = '';
     $Count = 0;
     $Users = array();
     $InConversation = FALSE;
     foreach ($this->RecipientData->Result() as $User) {
         $Count++;
         if ($User->UserID == $Session->UserID) {
             $InConversation = TRUE;
             continue;
         }
         if ($User->Deleted) {
             $Users[] = Wrap(UserAnchor($User), 'del', array('title' => sprintf(T('%s has left this conversation.'), htmlspecialchars($User->Name))));
             $this->SetData('_HasDeletedUsers', TRUE);
         } else {
             $Users[] = UserAnchor($User);
         }
     }
     if ($InConversation) {
         if (count($Users) == 0) {
             $this->Participants = T('Just you!');
         } else {
             $this->Participants = sprintf(T('%s and you'), implode(', ', $Users));
         }
     } else {
         $this->Participants = implode(', ', $Users);
     }
     $this->Title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // 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 = 'messages';
     }
     // Add modules.
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->RecipientData);
     $this->AddModule($InThisConversationModule);
     $this->AddModule('AddPeopleModule');
     // Render view
     $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 = '', $Offset = '0')
 {
     list($Offset, $Limit) = OffsetLimit($Offset, C('Vanilla.Discussions.PerPage', 30));
     if (!is_numeric($CategoryIdentifier)) {
         $Category = $this->CategoryModel->GetFullByUrlCode(urlencode($CategoryIdentifier));
     } else {
         $Category = $this->CategoryModel->GetFull($CategoryIdentifier);
     }
     if ($Category === FALSE) {
         return $this->All();
     }
     $this->SetData('Category', $Category, TRUE);
     // Setup head
     $this->AddCssFile('vanilla.css');
     $this->Menu->HighlightRoute('/discussions');
     if ($this->Head) {
         $this->Head->Title($Category->Name);
         $this->AddJsFile('discussions.js');
         $this->AddJsFile('bookmark.js');
         $this->AddJsFile('jquery.menu.js');
         $this->AddJsFile('options.js');
         $this->AddJsFile('jquery.gardenmorepager.js');
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Set CategoryID
     $this->SetData('CategoryID', $this->Category->CategoryID, TRUE);
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     // Get a DiscussionModel
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     // Check permission
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->CategoryID);
     // Set discussion meta data
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
     $this->SetData('AnnounceData', $AnnounceData, TRUE);
     $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE);
     // 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');
     // Set the canonical Url.
     $this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE)), 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();
 }
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
     $this->Conversation = $this->ConversationModel->GetID($ConversationID, $Session->UserID);
     if ($this->Conversation === FALSE) {
         Redirect('dashboard/home/filenotfound');
     }
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
     }
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     $this->Participants = '';
     $Count = 0;
     $Users = array();
     foreach ($this->RecipientData->Result() as $User) {
         if ($User->Deleted) {
             continue;
         }
         $Count++;
         if ($User->UserID == $Session->UserID) {
             continue;
         }
         $Users[] = UserAnchor($User);
     }
     if (count($Users) == 0) {
         $this->Participants = T('Just you!');
     } else {
         $this->Participants = sprintf(T('%s and you'), implode(', ', $Users));
     }
     $this->Title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // 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 = 'messages';
     }
     $this->AddModule('SignedInModule');
     $this->AddModule('NewConversationModule');
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->RecipientData);
     $this->AddModule($InThisConversationModule);
     $this->AddModule('AddPeopleModule');
     $this->Render();
 }
Пример #20
0
 /**
  * Default search functionality.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Page number.
  */
 public function Index($Page = '')
 {
     $this->AddJsFile('jquery.gardenmorepager.js');
     $this->AddJsFile('search.js');
     $this->Title(T('Search'));
     SaveToConfig('Garden.Format.EmbedSize', '160x90', FALSE);
     list($Offset, $Limit) = OffsetLimit($Page, C('Garden.Search.PerPage', 20));
     $this->SetData('_Limit', $Limit);
     $Search = $this->Form->GetFormValue('Search');
     $Mode = $this->Form->GetFormValue('Mode');
     if ($Mode) {
         $this->SearchModel->ForceSearchMode = $Mode;
     }
     try {
         $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
     } catch (Gdn_UserException $Ex) {
         $this->Form->AddError($Ex);
         $ResultSet = array();
     } catch (Exception $Ex) {
         LogException($Ex);
         $this->Form->AddError($Ex);
         $ResultSet = array();
     }
     Gdn::UserModel()->JoinUsers($ResultSet, array('UserID'));
     $this->SetData('SearchResults', $ResultSet, TRUE);
     $this->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE);
     if ($ResultSet) {
         $NumResults = count($ResultSet);
     } else {
         $NumResults = 0;
     }
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More Results';
     $this->Pager->LessCode = 'Previous Results';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::Url($Search));
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'results';
     }
     $this->CanonicalUrl(Url('search', TRUE));
     $this->Render();
 }
 /**
  * Show notifications for current user.
  *
  * @since 2.0.0
  * @access public
  * @param int $Page Number to skip (paging).
  */
 public function Notifications($Page = FALSE)
 {
     $this->Permission('Garden.SignIn.Allow');
     $this->EditMode(FALSE);
     list($Offset, $Limit) = OffsetLimit($Page, 30);
     $this->GetUserInfo();
     $this->_SetBreadcrumbs(T('Notifications'), '/profile/notifications');
     $this->SetTabView('Notifications');
     $Session = Gdn::Session();
     $this->ActivityModel = new ActivityModel();
     // Drop notification count back to zero.
     $this->ActivityModel->MarkRead($Session->UserID);
     // Get notifications data.
     $Activities = $this->ActivityModel->GetNotifications($Session->UserID, $Offset, $Limit)->ResultArray();
     $this->ActivityModel->JoinComments($Activities);
     $this->SetData('Activities', $Activities);
     unset($Activities);
     //$TotalRecords = $this->ActivityModel->GetCountNotifications($Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More';
     $this->Pager->LessCode = 'Newer Notifications';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, FALSE, 'profile/notifications/%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'));
         if ($Offset > 0) {
             $this->View = 'activities';
             $this->ControllerName = 'Activity';
         }
     }
     $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();
   }
    /**
     * Alternate version of Index that uses the embed master view.
     *
     * @param int $DiscussionID Unique identifier, if discussion has been created.
     * @param string $DiscussionStub Deprecated.
     * @param int $Offset
     * @param int $Limit
     */
    public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
    {
        $this->Title(T('Comments'));
        // Add theme data
        $this->Theme = C('Garden.CommentsTheme', $this->Theme);
        Gdn_Theme::Section('Comments');
        // Force view options
        $this->MasterView = 'empty';
        $this->CanEditComments = FALSE;
        // Don't show the comment checkboxes on the embed comments page
        // Add some css to help with the transparent bg on embedded comments
        if ($this->Head) {
            $this->Head->AddString('<style type="text/css">
body { background: transparent !important; }
</style>');
        }
        // Javascript files & options
        $this->AddJsFile('jquery.gardenmorepager.js');
        $this->AddJsFile('jquery.autogrow.js');
        $this->RemoveJsFile('autosave.js');
        $this->AddJsFile('discussion.js');
        $this->AddDefinition('DoInform', '0');
        // Suppress inform messages on embedded page.
        $this->AddDefinition('SelfUrl', Gdn::Request()->PathAndQuery());
        $this->AddDefinition('Embedded', TRUE);
        // Define incoming variables (prefer querystring parameters over method parameters)
        $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
        $DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID);
        $Offset = GetIncomingValue('Offset', $Offset);
        $Limit = GetIncomingValue('Limit', $Limit);
        $vanilla_identifier = GetIncomingValue('vanilla_identifier', '');
        // Only allow vanilla identifiers of 32 chars or less - md5 if larger
        if (strlen($vanilla_identifier) > 32) {
            $vanilla_identifier = md5($vanilla_identifier);
        }
        $vanilla_type = GetIncomingValue('vanilla_type', 'page');
        $vanilla_url = GetIncomingValue('vanilla_url', '');
        $vanilla_category_id = GetIncomingValue('vanilla_category_id', '');
        $ForeignSource = array('vanilla_identifier' => $vanilla_identifier, 'vanilla_type' => $vanilla_type, 'vanilla_url' => $vanilla_url, 'vanilla_category_id' => $vanilla_category_id);
        $this->SetData('ForeignSource', $ForeignSource);
        // Set comment sorting
        $SortComments = C('Garden.Embed.SortComments') == 'desc' ? 'desc' : 'asc';
        $this->SetData('SortComments', $SortComments);
        // Retrieve the discussion record
        $Discussion = FALSE;
        if ($DiscussionID > 0) {
            $Discussion = $this->DiscussionModel->GetID($DiscussionID);
        } else {
            if ($vanilla_identifier != '' && $vanilla_type != '') {
                $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
            }
        }
        // Set discussion data if we have one for this page
        if ($Discussion) {
            $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $Discussion->PermissionCategoryID);
            $this->SetData('Discussion', $Discussion, TRUE);
            $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
            $this->Title($Discussion->Name);
            // Actual number of comments, excluding the discussion itself
            $ActualResponses = $Discussion->CountComments;
            // Define the query offset & limit
            if (!is_numeric($Limit) || $Limit < 0) {
                $Limit = C('Garden.Embed.CommentsPerPage', 30);
            }
            $OffsetProvided = $Offset != '';
            list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
            $this->Offset = $Offset;
            if (C('Vanilla.Comments.AutoOffset')) {
                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;
            }
            // Set the canonical url to have the proper page title.
            $this->CanonicalUrl(DiscussionUrl($Discussion, PageNumber($this->Offset, $Limit)));
            // Load the comments.
            $CurrentOrderBy = $this->CommentModel->OrderBy();
            if (StringBeginsWith(GetValueR('0.0', $CurrentOrderBy), 'c.DateInserted')) {
                $this->CommentModel->OrderBy('c.DateInserted ' . $SortComments);
            }
            // allow custom sort
            $this->SetData('Comments', $this->CommentModel->Get($Discussion->DiscussionID, $Limit, $this->Offset), TRUE);
            if (count($this->CommentModel->Where()) > 0) {
                $ActualResponses = FALSE;
            }
            $this->SetData('_Count', $ActualResponses);
            // Build a pager
            $PagerFactory = new Gdn_PagerFactory();
            $this->EventArguments['PagerType'] = 'MorePager';
            $this->FireEvent('BeforeBuildPager');
            $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
            $this->Pager->ClientID = 'Pager';
            $this->Pager->MoreCode = 'More Comments';
            $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/embed/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name) . '/%1$s');
            $this->Pager->CurrentRecords = $this->Comments->NumRows();
            $this->FireEvent('AfterBuildPager');
        }
        // Define the form for the comment input
        $this->Form = Gdn::Factory('Form', 'Comment');
        $this->Form->Action = Url('/vanilla/post/comment/');
        $this->Form->AddHidden('CommentID', '');
        $this->Form->AddHidden('Embedded', 'true');
        // Tell the post controller that this is an embedded page (in case there are custom views it needs to pick up from a theme).
        $this->Form->AddHidden('DisplayNewCommentOnly', 'true');
        // Only load/display the new comment after posting (don't load all new comments since the page last loaded).
        // Grab the page title
        if ($this->Request->Get('title')) {
            $this->Form->SetValue('Name', $this->Request->Get('title'));
        }
        // Set existing DiscussionID for comment form
        if ($Discussion) {
            $this->Form->AddHidden('DiscussionID', $Discussion->DiscussionID);
        }
        foreach ($ForeignSource as $Key => $Val) {
            // Drop the foreign source information into the form so it can be used if creating a discussion
            $this->Form->AddHidden($Key, $Val);
            // Also drop it into the definitions so it can be picked up for stashing comments
            $this->AddDefinition($Key, $Val);
        }
        // Retrieve & apply the draft if there is one:
        $Draft = FALSE;
        if (Gdn::Session()->UserID && $Discussion) {
            $DraftModel = new DraftModel();
            $Draft = $DraftModel->Get(Gdn::Session()->UserID, 0, 1, $Discussion->DiscussionID)->FirstRow();
            $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
        }
        if ($Draft) {
            $this->Form->SetFormValue('Body', $Draft->Body);
        } else {
            // Look in the session stash for a comment
            $StashComment = Gdn::Session()->Stash('CommentForForeignID_' . $ForeignSource['vanilla_identifier'], '', FALSE);
            if ($StashComment) {
                $this->Form->SetValue('Body', $StashComment);
                $this->Form->SetFormValue('Body', $StashComment);
            }
        }
        // Deliver JSON data if necessary
        if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
            if ($this->Discussion) {
                $this->SetJson('LessRow', $this->Pager->ToString('less'));
                $this->SetJson('MoreRow', $this->Pager->ToString('more'));
            }
            $this->View = 'comments';
        }
        // Ordering note for JS
        if ($SortComments == 'desc') {
            $this->AddDefinition('PrependNewComments', '1');
        }
        // Report the discussion id so js can use it.
        if ($Discussion) {
            $this->AddDefinition('DiscussionID', $Discussion->DiscussionID);
        }
        $this->FireEvent('BeforeDiscussionRender');
        $this->Render();
    }
Пример #24
0
 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();
 }
 /**
  * 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();
 }
 /**
  * Default activity stream.
  * 
  * @since 2.0.0
  * @access public
  * @todo Validate comment length rather than truncating.
  * 
  * @param int $RoleID Unique ID of role to limit activity to.
  * @param int $Offset Number of activity items to skip.
  */
 public function Index($RoleID = '', $Offset = FALSE) {
    $this->Permission('Garden.Activity.View');
    
    // Limit to specific RoleIDs?
    if ($RoleID == 0)
       $RoleID = '';
       
    if ($RoleID != '')
       $RoleID = explode(',', $RoleID);
       
    // Which page to load
    $Offset = is_numeric($Offset) ? $Offset : 0;
    if ($Offset < 0)
       $Offset = 0;
    
    // Page meta
    $this->AddJsFile('jquery.gardenmorepager.js');
    $this->AddJsFile('activity.js');
    $this->Title(T('Recent Activity'));
    
    // Comment submission 
    $Session = Gdn::Session();
    $Comment = $this->Form->GetFormValue('Comment');
    $this->CommentData = FALSE;
    if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
       $Comment = substr($Comment, 0, 1000); // Limit to 1000 characters...
       
       // Update About if necessary
       $ActivityType = 'WallComment';
       $NewActivityID = $this->ActivityModel->Add(
          $Session->UserID,
          $ActivityType,
          $Comment);
       
       if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
          Redirect('activity');
       } else {
          // Load just the single new comment
          $this->HideActivity = TRUE;
          $this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
          $this->View = 'activities';
       }
    } else {
       $Limit = 50;
       $this->ActivityData = is_array($RoleID) ? $this->ActivityModel->GetForRole($RoleID, $Offset, $Limit) : $this->ActivityModel->Get('', $Offset, $Limit);
       $TotalRecords = is_array($RoleID) ? $this->ActivityModel->GetCountForRole($RoleID) : $this->ActivityModel->GetCount();
       if ($this->ActivityData->NumRows() > 0) {
          $ActivityData = $this->ActivityData->ResultArray();
          $ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
          $this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
       }
       $this->View = 'all';
       
       // Build a pager
       $PagerFactory = new Gdn_PagerFactory();
       $this->Pager = $PagerFactory->GetPager('MorePager', $this);
       $this->Pager->MoreCode = 'More';
       $this->Pager->LessCode = 'Newer Activity';
       $this->Pager->ClientID = 'Pager';
       $this->Pager->Configure(
          $Offset,
          $Limit,
          $TotalRecords,
          'activity/'.(is_array($RoleID) ? implode(',', $RoleID) : '0').'/%1$s/%2$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 = 'activities';
       }
    }
    
    // Add RecentUser module
    $RecentUserModule = new RecentUserModule($this);
    $RecentUserModule->GetData();
    $this->AddModule($RecentUserModule);
    
    $this->SetData('ActivityData', $this->ActivityData);
    
    $this->Render();
 }
Пример #27
0
 /**
  * Creates virtual 'Discussions' method in ProfileController.
  * 
  * @since 2.0.0
  * @package Vanilla
  *
  * @param ProfileController $Sender ProfileController.
  */
 public function ProfileController_Discussions_Create($Sender, $UserReference = '', $Username = '', $Page = '', $UserID = '')
 {
     $Sender->EditMode(FALSE);
     // Tell the ProfileController what tab to load
     $Sender->GetUserInfo($UserReference, $Username, $UserID);
     $Sender->_SetBreadcrumbs(T('Discussions'), '/profile/discussions');
     $Sender->SetTabView('Discussions', 'Profile', 'Discussions', 'Vanilla');
     $Sender->CountCommentsPerPage = C('Vanilla.Comments.PerPage', 30);
     list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $DiscussionModel = new DiscussionModel();
     $Discussions = $DiscussionModel->GetByUser($Sender->User->UserID, $Limit, $Offset, FALSE, Gdn::Session()->UserID);
     $CountDiscussions = $Offset + $DiscussionModel->LastDiscussionCount + 1;
     $Sender->DiscussionData = $Sender->SetData('Discussions', $Discussions);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
     $Sender->Pager->MoreCode = 'More Discussions';
     $Sender->Pager->LessCode = 'Newer Discussions';
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, UserUrl($Sender->User, '', 'discussions') . '/{Page}');
     // Deliver JSON data if necessary
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL && $Offset > 0) {
         $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
         $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
         $Sender->View = 'discussions';
     }
     // Set the HandlerType back to normal on the profilecontroller so that it fetches it's own views
     $Sender->HandlerType = HANDLER_TYPE_NORMAL;
     // Do not show discussion options
     $Sender->ShowOptions = FALSE;
     if ($Sender->Head) {
         // These pages offer only duplicate content to search engines and are a bit slow.
         $Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
     }
     // Render the ProfileController
     $Sender->Render();
 }
Пример #28
0
 public function Index($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
 {
     $this->AddCssFile('vanilla.css');
     $Session = Gdn::Session();
     $this->AddJsFile('/js/library/jquery.resizable.js');
     $this->AddJsFile('/js/library/jquery.ui.packed.js');
     $this->AddJsFile('/js/library/jquery.autogrow.js');
     $this->AddJsFile('/js/library/jquery.gardenmorepager.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;
     $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
     if (!is_object($this->Discussion)) {
         Redirect('FileNotFound');
     }
     // Check Permissions
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->CategoryID);
     $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
     if ($this->Discussion === FALSE) {
         Redirect('dashboard/home/filenotfound');
     } else {
         // Setup
         $this->Title(Gdn_Format::Text($this->Discussion->Name));
         // Actual number of comments, excluding the discussion itself
         $ActualResponses = $this->Discussion->CountComments - 1;
         // Define the query offset & limit
         if (!is_numeric($Limit) || $Limit < 0) {
             $Limit = Gdn::Config('Vanilla.Comments.PerPage', 50);
         }
         $this->Offset = $Offset;
         if (!is_numeric($this->Offset) || $this->Offset < 0) {
             // 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 < 0) {
             $this->Offset = 0;
         }
         // Make sure to set the user's discussion watch records
         $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
         // Load the comments
         $this->SetData('CommentData', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
         $this->SetData('Comments', $this->CommentData);
         // Build a pager
         $PagerFactory = new Gdn_PagerFactory();
         $this->Pager = $PagerFactory->GetPager('MorePager', $this);
         $this->Pager->MoreCode = '%1$s more comments';
         $this->Pager->LessCode = '%1$s older comments';
         $this->Pager->ClientID = 'Pager';
         $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'vanilla/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s/%2$s/');
     }
     // 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:
     $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';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->FireEvent('BeforeDiscussionRender');
     $this->Render();
 }
Пример #29
0
 public function Index($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
 {
     $this->AddCssFile('vanilla.css');
     $Session = Gdn::Session();
     $this->AddJsFile('jquery.resizable.js');
     $this->AddJsFile('jquery.ui.packed.js');
     $this->AddJsFile('jquery.autogrow.js');
     //      $this->AddJsFile('jquery.gardenmorepager.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;
     $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
     if (!is_object($this->Discussion)) {
         return Gdn::Dispatcher()->Dispatch('Default404');
     }
     // Check Permissions
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->CategoryID);
     $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
     // Setup
     $this->Title($this->Discussion->Name);
     // Actual number of comments, excluding the discussion itself
     $ActualResponses = $this->Discussion->CountComments - 1;
     // Define the query offset & limit
     if (!is_numeric($Limit) || $Limit < 0) {
         $Limit = C('Vanilla.Comments.PerPage', 50);
     }
     $OffsetProvided = $Offset != '';
     list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
     // 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.
     if ($Offset == '') {
         $this->DiscussionModel->AddView($DiscussionID);
     }
     $this->Offset = $Offset;
     if (C('Vanilla.Comments.AutoOffset')) {
         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;
     }
     // 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($this->Offset, $Limit, TRUE)), TRUE));
     // Make sure to set the user's discussion watch records
     $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
     // Load the comments
     $this->SetData('CommentData', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
     $this->SetData('Comments', $this->CommentData);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s');
     //      $this->Pager->MoreCode = '%1$s more comments';
     //      $this->Pager->LessCode = '%1$s older comments';
     //      $this->Pager->ClientID = 'Pager';
     //      $this->Pager->Configure(
     //         $this->Offset,
     //         $Limit,
     //         $ActualResponses,
     //         'discussion/'.$DiscussionID.'/'.Gdn_Format::Url($this->Discussion->Name).'/%1$s/%2$s/'
     //      );
     // 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:
     $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';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->FireEvent('BeforeDiscussionRender');
     $this->Render();
 }
Пример #30
0
 /**
  * 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');
 }