예제 #1
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();
 }
예제 #2
0
 public function SettingsController_DashboardData_Handler(&$Sender)
 {
     $DiscussionModel = new DiscussionModel();
     // Number of Discussions
     $CountDiscussions = $DiscussionModel->GetCount();
     $Sender->AddDefinition('CountDiscussions', $CountDiscussions);
     $Sender->BuzzData[T('Discussions')] = number_format($CountDiscussions);
     // Number of New Discussions in the last day
     $Sender->BuzzData[T('New discussions in the last day')] = number_format($DiscussionModel->GetCount(array('d.DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 day')))));
     // Number of New Discussions in the last week
     $Sender->BuzzData[T('New discussions in the last week')] = number_format($DiscussionModel->GetCount(array('d.DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 week')))));
     $CommentModel = new CommentModel();
     // Number of Comments
     $CountComments = $CommentModel->GetCountWhere();
     $Sender->AddDefinition('CountComments', $CountComments);
     $Sender->BuzzData[T('Comments')] = number_format($CountComments);
     // Number of New Comments in the last day
     $Sender->BuzzData[T('New comments in the last day')] = number_format($CommentModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 day')))));
     // Number of New Comments in the last week
     $Sender->BuzzData[T('New comments in the last week')] = number_format($CommentModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 week')))));
 }
 /**
  * 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();
 }
예제 #4
0
 public function Mine($Offset = '0')
 {
     $this->Permission('Garden.SignIn.Allow');
     if ($this->Head) {
         $this->Head->AddScript('/js/library/jquery.resizable.js');
         $this->Head->AddScript('/js/library/jquery.ui.packed.js');
         $this->Head->AddScript('/applications/vanilla/js/bookmark.js');
         $this->Head->AddScript('/applications/vanilla/js/discussions.js');
         $this->Head->AddScript('/applications/vanilla/js/options.js');
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $Session = Gdn::Session();
     $Wheres = array('d.InsertUserID' => $Session->UserID);
     $DiscussionModel = new DiscussionModel();
     $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $Limit, $Wheres), TRUE);
     $CountDiscussions = $this->SetData('CountDiscussions', $DiscussionModel->GetCount($Wheres));
     // Build a pager
     $PagerFactory = new PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More Discussions';
     $this->Pager->LessCode = 'Newer Discussions';
     $this->Pager->Wrapper = '<li %1$s>%2$s</li>';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/mine/%1$s');
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $DraftsModule = new DraftsModule($this);
     $DraftsModule->GetData();
     $this->AddModule($DraftsModule);
     // Render the controller
     $this->Render();
 }
예제 #5
0
 /**
  * Discussions filter: Unresolved.
  *
  * @return void
  */
 public function discussionsController_unresolved_create($sender, $args)
 {
     $sender->permission('Plugins.Resolved.Manage');
     $page = val(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.Resolved' => '0');
     // Hack in our wheregroup.
     Gdn::sql()->beginWhereGroup()->whereNotIn('d.Type', array('page', 'Report', 'poll', 'SimplePage'))->orWhere('d.Type is null')->endWhereGroup();
     $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/unresolved/%1$s');
     if (!$sender->data('_PagerUrl')) {
         $sender->setData('_PagerUrl', 'discussions/unresolved/{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
     $sender->setData('Title', T('Unresolved'));
     $sender->setData('Breadcrumbs', array(array('Name' => T('Unresolved'), 'Url' => '/discussions/unresolved')));
     $sender->render('index');
 }
 /**
  * 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();
     }
 }
예제 #7
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();
 }
예제 #8
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();
 }
예제 #9
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');
 }
 /**
  * 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();
 }
   /**
    * 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();
   }
예제 #12
0
파일: stub.php 프로젝트: bishopb/vanilla
<?php

if (!defined('APPLICATION')) {
    exit;
}
/**
 * Vanilla stub content for a new forum.
 *
 * Called by VanillaHooks::Setup() to insert stub content upon enabling app.
 * @package Vanilla
 */
// Only do this once, ever.
$DiscussionModel = new DiscussionModel();
if ($DiscussionModel->GetCount()) {
    return;
}
$SQL = Gdn::Database()->SQL();
$DiscussionModel = new DiscussionModel();
// Prep default content
$DiscussionTitle = "BAM! You&rsquo;ve got a sweet forum";
$DiscussionBody = "There&rsquo;s nothing sweeter than a fresh new forum, ready to welcome your community. A Vanilla Forum has all the bits and pieces you need to build an awesome discussion platform customized to your needs. Here&rsquo;s a few tips:\n<ul>\n   <li>Use the <a href=\"/dashboard/settings/gettingstarted\">Getting Started</a> list in the Dashboard to configure your site.</li>\n   <li>Don&rsquo;t use too many categories. We recommend 3-8. Keep it simple!</li>\n   <li>&ldquo;Announce&rdquo; a discussion (click the gear) to stick to the top of the list, and &ldquo;Close&rdquo; it to stop further comments.</li>\n   <li>Use &ldquo;Sink&rdquo; to take attention away from a discussion. New comments will no longer bring it back to the top of the list.</li>\n   <li>Bookmark a discussion (click the star) to get notifications for new comments. You can edit notification settings from your profile.</li>\n</ul>\nGo ahead and edit or delete this discussion, then spread the word to get this place cooking. Cheers!";
$CommentBody = "This is the first comment on your site and it&rsquo;s an important one. \n\nDon&rsquo;t see your must-have feature? We keep Vanilla nice and simple by default. Use <b>addons</b> to get the special sauce your community needs.\n\nNot sure which addons to enable? Our favorites are Button Bar and Tagging. They&rsquo;re almost always a great start.";
$WallBody = "Ping! An activity post is a public way to talk at someone. When you update your status here, it posts it on your activity feed.";
// Prep content meta data
$SystemUserID = Gdn::UserModel()->GetSystemUserID();
$TargetUserID = Gdn::Session()->UserID;
$Now = Gdn_Format::ToDateTime();
$CategoryID = GetValue('CategoryID', CategoryModel::DefaultCategory());
// Get wall post type ID
$WallCommentTypeID = $SQL->GetWhere('ActivityType', array('Name' => 'WallPost'))->Value('ActivityTypeID');
// Insert first discussion & comment
 /**
  * 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(GetValue('CategoryID', $Category)));
         $this->SetData('Category', $Category, TRUE);
         $this->Title(htmlspecialchars(GetValue('Name', $Category, '')));
         $this->Description(GetValue('Description', $Category), TRUE);
         if ($Category->DisplayAs == 'Categories') {
             if (GetValue('Depth', $Category) > 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();
                         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.
         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->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
         }
         // 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;
         }
         $Page = PageNumber($Offset, $Limit);
         // 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->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 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();
     }
 }
예제 #14
0
 /**
  * Show all discussions in a particular category.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param string $CategoryIdentifier Unique category slug or ID.
  * @param int $Offset Number of discussions to skip.
  */
 public function Index($CategoryIdentifier = '', $Page = '0')
 {
     $Category = CategoryModel::Categories($CategoryIdentifier);
     if (empty($Category)) {
         if ($CategoryIdentifier) {
             throw NotFoundException();
         }
     }
     $Category = (object) $Category;
     // Load the breadcrumbs.
     $this->SetData('Breadcrumbs', CategoryModel::GetAncestors(GetValue('CategoryID', $Category)));
     $this->SetData('Category', $Category, TRUE);
     // Setup head
     $this->AddCssFile('vanilla.css');
     $this->Menu->HighlightRoute('/discussions');
     if ($this->Head) {
         $this->Head->Title(GetValue('Name', $Category, ''));
         $this->AddJsFile('discussions.js');
         $this->AddJsFile('bookmark.js');
         $this->AddJsFile('options.js');
         $this->AddJsFile('jquery.gardenmorepager.js');
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     // Set CategoryID
     $this->SetData('CategoryID', GetValue('CategoryID', $Category), TRUE);
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $this->AddModule('BookmarkedModule');
     // Get a DiscussionModel
     $DiscussionModel = new DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     // Check permission
     $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', GetValue('PermissionCategoryID', $Category));
     // Set discussion meta data.
     $this->EventArguments['PerPage'] = C('Vanilla.Discussions.PerPage', 30);
     $this->FireEvent('BeforeGetDiscussions');
     list($Offset, $Limit) = OffsetLimit($Page, $this->EventArguments['PerPage']);
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->SetData('_Limit', $Limit);
     $AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
     $this->SetData('AnnounceData', $AnnounceData, TRUE);
     $this->DiscussionData = $this->SetData('Discussions', $DiscussionModel->Get($Offset, $Limit, $Wheres));
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'categories/' . $CategoryIdentifier . '/%1$s');
     $this->SetData('_PagerUrl', 'categories/' . rawurlencode($CategoryIdentifier) . '/{Page}');
     $this->SetData('_Page', $Page);
     // Set the canonical Url.
     $this->CanonicalUrl(Url(ConcatSep('/', 'categories/' . GetValue('UrlCode', $Category, $CategoryIdentifier), PageNumber($Offset, $Limit, TRUE, FALSE)), TRUE));
     // Change the controller name so that it knows to grab the discussion views
     $this->ControllerName = 'DiscussionsController';
     // Pick up the discussions class
     $this->CssClass = 'Discussions';
     // Deliver JSON data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'discussions';
     }
     // Render default view
     $this->Render();
 }
   /**
    * Display discussions started by the user.
    * 
    * @since 2.0.0
    * @access public
    *
    * @param int $Offset Number of discussions to skip.
    */
   public function Mine($Offset = '0') {
      $this->Permission('Garden.SignIn.Allow');
      
      // Validate $Offset
      if (!is_numeric($Offset) || $Offset < 0)
         $Offset = 0;
      
      // Set criteria & get discussions data
      $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->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->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('NewDiscussionModule');
      $this->AddModule('CategoriesModule');
      $this->AddModule('BookmarkedModule');
      
      // Render default view (discussions/mine.php)
      $this->SetData('Title', T('My Discussions'));
      $this->Render('Index');
   }