Beispiel #1
0
 public function Index($Offset = 0, $Limit = NULL)
 {
     $this->AddJsFile('/js/library/jquery.gardenmorepager.js');
     $this->AddJsFile('search.js');
     $this->Title(Translate('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', Format::Text($Search), TRUE);
     $NumResults = $ResultSet->NumRows();
     if ($NumResults == $Offset + $Limit) {
         $NumResults++;
     }
     // Build a pager
     $PagerFactory = new PagerFactory();
     $Pager = $PagerFactory->GetPager('MorePager', $this);
     $Pager->MoreCode = 'More Results';
     $Pager->LessCode = 'Previous Results';
     $Pager->ClientID = 'Pager';
     $Pager->Configure($Offset, $Limit, $NumResults, 'garden/search/%1$s/%2$s/?Search=' . Format::Url($Search));
     $this->SetData('Pager', $Pager, TRUE);
     $this->View = 'results';
     $this->Render();
 }
Beispiel #2
0
 public function Index($Offset = FALSE, $Keywords = '')
 {
     $this->Permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', FALSE);
     if ($this->Head) {
         $this->Head->AddScript('js/library/jquery.gardenmorepager.js');
         $this->Head->AddScript('/applications/garden/js/user.js');
         $this->Head->Title(Translate('Users'));
     }
     $this->AddSideMenu('garden/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 Gdn_UserModel();
     $Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords);
     $Limit = 30;
     $TotalRecords = $UserModel->GetCountLike($Like);
     $this->UserData = $UserModel->GetLike($Like, 'u.Name', 'asc', $Limit, $Offset);
     // Build a pager
     $PagerFactory = new 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();
 }
Beispiel #3
0
 public function Index($Offset = '0')
 {
     $this->Permission('Garden.SignIn.Allow');
     $this->AddCssFile('vanilla.css');
     $this->AddCssFile('form.css');
     $Session = Gdn::Session();
     if ($this->Head) {
         $this->Head->AddScript('/applications/vanilla/js/discussions.js');
         $this->Head->AddScript('/applications/vanilla/js/options.js');
         $this->Head->Title(Translate('My Drafts'));
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $Session = Gdn::Session();
     $Wheres = array('d.InsertUserID' => $Session->UserID);
     $this->DraftData = $this->DraftModel->Get($Session->UserID, $Offset, $Limit);
     $CountDrafts = $this->DraftModel->GetCount($Session->UserID);
     // Build a pager
     $PagerFactory = new PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'More drafts';
     $this->Pager->LessCode = 'Newer drafts';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDrafts, 'drafts/%1$s');
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'drafts';
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     // Render the controller
     $this->Render();
 }
Beispiel #4
0
 public function ProfileController_Discussions_Create(&$Sender)
 {
     $UserReference = ArrayValue(0, $Sender->EventArguments, '');
     $Offset = ArrayValue(1, $Sender->EventArguments, 0);
     // Tell the ProfileController what tab to load
     $Sender->SetTabView($UserReference, '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 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/' . urlencode($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();
 }
Beispiel #5
0
 public function Index($DiscussionID = '', $Offset = '', $Limit = '')
 {
     $this->AddCssFile('vanilla.css');
     $Session = Gdn::Session();
     if ($this->Head) {
         $this->Head->AddScript('/js/library/jquery.resizable.js');
         $this->Head->AddScript('/js/library/jquery.ui.packed.js');
         $this->Head->AddScript('/js/library/jquery.autogrow.js');
         $this->Head->AddScript('/js/library/jquery.gardenmorepager.js');
         $this->Head->AddScript('/applications/vanilla/js/options.js');
         $this->Head->AddScript('/applications/vanilla/js/bookmark.js');
         $this->Head->AddScript('/applications/vanilla/js/discussion.js');
         $this->Head->AddScript('/applications/vanilla/js/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', $this->Discussion->CategoryID);
     $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
     if ($this->Discussion === FALSE) {
         return $this->ReDispatch('garden/home/filenotfound');
     } else {
         // Setup
         if ($this->Head) {
             $this->Head->Title(Format::Text($this->Discussion->Name));
         }
         // 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 > $this->Discussion->CountComments) {
                 $CountCommentWatch = $this->Discussion->CountComments;
             }
             // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
             $this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
         }
         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->CommentData = $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
         // Build a pager
         $PagerFactory = new 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, $this->Discussion->CountComments, 'vanilla/discussion/' . $DiscussionID . '/%1$s/%2$s/' . Format::Url($this->Discussion->Name));
     }
     // Define the form for the comment input
     $this->Form = Gdn::Factory('Form', 'Comment');
     $this->DiscussionID = $this->Discussion->DiscussionID;
     $this->Form->AddHidden('DiscussionID', $this->DiscussionID);
     $this->Form->AddHidden('CommentID', '');
     $this->Form->AddHidden('DraftID', '');
     $this->Form->Action = Url('/vanilla/post/comment/');
     // 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');
     $DraftsModule = new DraftsModule($this);
     $DraftsModule->GetData(20, $DiscussionID);
     $this->AddModule($DraftsModule);
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->FireEvent('DiscussionRenderBefore');
     $this->Render();
 }
Beispiel #6
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();
 }
Beispiel #7
0
 /**
  * Show all discussions in a particular category.
  */
 public function Index($CategoryIdentifier = '', $Offset = '0')
 {
     if (!is_numeric($CategoryIdentifier)) {
         $Category = $this->CategoryModel->GetFullByName(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->Head->AddScript('/applications/vanilla/js/discussions.js');
         $this->Head->AddScript('/applications/vanilla/js/options.js');
         $this->Head->AddScript('/js/library/jquery.gardenmorepager.js');
         $this->Head->AddRss('/rss/' . $this->SelfUrl, $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);
     $DraftsModule = new DraftsModule($this);
     $DraftsModule->GetData();
     $this->AddModule($DraftsModule);
     $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30);
     $DiscussionModel = new Gdn_DiscussionModel();
     $Wheres = array('d.CategoryID' => $this->CategoryID);
     $this->Permission('Vanilla.Discussions.View', $this->CategoryID);
     $CountDiscussions = $DiscussionModel->GetCount($Wheres);
     $this->SetData('CountDiscussions', $CountDiscussions);
     $TmpLimit = $Limit;
     $AnnounceData = FALSE;
     if ($Offset == 0) {
         $AnnounceData = $DiscussionModel->GetAnnouncements($Wheres);
         $TmpLimit = $Limit - $AnnounceData->NumRows();
     }
     $this->SetData('AnnounceData', $AnnounceData, TRUE);
     $this->SetData('DiscussionData', $DiscussionModel->Get($Offset, $TmpLimit, $Wheres), TRUE);
     // Build a pager
     $PagerFactory = new 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, '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();
 }
Beispiel #8
0
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @todo ENFORCE PERMISSIONS SO THAT PEOPLE CAN'T READ OTHER PEOPLE'S MESSAGES
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     if ($this->Head) {
         $this->Head->Title(Translate('Conversations'));
     }
     $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('garden/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);
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new 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('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();
 }