public function DiscussionsController_Participated_Create(&$Sender, $Args)
 {
     $Sender->Permission('Garden.SignIn.Allow');
     $Page = GetValue(0, $Args);
     $Limit = GetValue(1, $Args);
     list($Offset, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     // Get Discussions
     $DiscussionModel = new DiscussionModel();
     $Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit);
     $Sender->SetData('Discussions', $Sender->DiscussionData);
     $CountDiscussions = $DiscussionModel->GetCountParticipated(Gdn::Session()->UserID);
     $Sender->SetData('CountDiscussions', $CountDiscussions);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->EventArguments['PagerType'] = 'Pager';
     $Sender->FireEvent('BeforeBuildPager');
     $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/participated/%1$s');
     $Sender->FireEvent('AfterBuildPager');
     // Deliver JSON data if necessary
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
         $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
         $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
         $Sender->View = 'discussions';
     }
     // Add modules
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($Sender);
     $BookmarkedModule->GetData();
     $Sender->AddModule($BookmarkedModule);
     $Sender->Render($this->GetView('participated.php'));
 }
Example #2
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');
 }
 /**
  * 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();
 }
 /**
  * Default all discussions view: chronological by most recent comment.
  * 
  * @since 2.0.0
  * @access public
  * 
  * @param int $Page Multiplied by PerPage option to determine offset.
  */
 public function Index($Page = '0')
 {
     // Determine offset from $Page
     list($Page, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Page, $Limit, TRUE)), TRUE));
     // Validate $Page
     if (!is_numeric($Page) || $Page < 0) {
         $Page = 0;
     }
     // Setup head
     $this->Title(T('All Discussions'));
     if ($this->Head) {
         $this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
     }
     // Add modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     // Set criteria & get discussions data
     $this->SetData('Category', FALSE, TRUE);
     $DiscussionModel = new DiscussionModel();
     $CountDiscussions = $DiscussionModel->GetCount();
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->AnnounceData = $Page == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
     $this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
     $this->DiscussionData = $DiscussionModel->Get($Page, $Limit);
     $this->SetData('Discussions', $this->DiscussionData, TRUE);
     $this->SetJson('Loading', $Page . ' to ' . $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($Page, $Limit, $CountDiscussions, 'discussions/%1$s');
     $this->FireEvent('AfterBuildPager');
     // 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';
     }
     // 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());
         $this->AddDefinition('SetClientHour', $ClientHour);
     }
     // Render default view (discussions/index.php)
     $this->Render();
 }
 /**
  * User management list.
  *
  * @since 2.0.0
  * @access public
  * @param mixed $Keywords Term or array of terms to filter list of users.
  * @param int $Page Page number.
  * @param string $Order Sort order for list.
  */
 public function Index($Keywords = '', $Page = '', $Order = '')
 {
     $this->Permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', FALSE);
     // Page setup
     $this->AddJsFile('jquery.gardenmorepager.js');
     $this->AddJsFile('user.js');
     $this->Title(T('Users'));
     $this->AddSideMenu('dashboard/user');
     // Form setup
     $this->Form->Method = 'get';
     // Input Validation.
     list($Offset, $Limit) = OffsetLimit($Page, PagerModule::$DefaultPageSize);
     if (!$Keywords) {
         $Keywords = $this->Form->GetFormValue('Keywords');
         if ($Keywords) {
             $Offset = 0;
         }
     }
     if (!is_string($Keywords)) {
         $Keywords = '';
     }
     // 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);
     list($Offset, $Limit) = OffsetLimit($Page, 30);
     $Filter = $this->_GetFilter();
     if ($Filter) {
         $Filter['Keywords'] = $Keywords;
     } else {
         $Filter = $Keywords;
     }
     $this->SetData('RecordCount', $UserModel->SearchCount($Filter));
     // Sorting
     if (in_array($Order, array('DateInserted', 'DateFirstVisit', 'DateLastActive'))) {
         $Order = 'u.' . $Order;
         $OrderDir = 'desc';
     } else {
         $Order = 'u.Name';
         $OrderDir = 'asc';
     }
     // Get user list
     $this->UserData = $UserModel->Search($Filter, $Order, $OrderDir, $Limit, $Offset);
     $this->SetData('Users', $this->UserData);
     RoleModel::SetUserRoles($this->UserData->Result());
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'users';
     }
     $this->Render();
 }
 /**
  * Manage the current badges and add new ones
  *
  * @param int $Page
  */
 public function Settings($Page = '')
 {
     $this->Permission('Yaga.Badges.Manage');
     $this->AddSideMenu('badge/settings');
     $this->Title(T('Yaga.Badges.Manage'));
     // Get list of badges from the model and pass to the view
     list($Offset, $Limit) = OffsetLimit($Page, PagerModule::$DefaultPageSize);
     $this->SetData('Badges', $this->BadgeModel->GetLimit($Limit, $Offset));
     $this->SetData('Rules', RulesController::GetRules());
     $this->Render();
 }
   public function Index($Keywords = '', $Page = '') {
      $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.
      list($Offset, $Limit) = OffsetLimit($Page, PagerModule::$DefaultPageSize);
      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);
      list($Offset, $Limit) = OffsetLimit($Page, 30);

      $Filter = $this->_GetFilter();
      if ($Filter)
         $Filter['Keywords'] = $Keywords;
      else
         $Filter = $Keywords;

      $this->SetData('RecordCount', $UserModel->SearchCount($Filter));
      $this->UserData = $UserModel->Search($Filter, 'u.Name', 'asc', $Limit, $Offset);
      RoleModel::SetUserRoles($this->UserData->Result());
      
      // 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();
   }
Example #8
0
 public function Browse($Page = '')
 {
     $this->Permission('Candy.Settings.View');
     list($Offset, $Limit) = OffsetLimit($Page, 30);
     $this->Chunks = $this->ChunkModel->Get('', $Offset, $Limit, 'DateUpdated');
     $this->RecordCount = $this->ChunkModel->GetCount();
     $this->Url = '/candy/chunk/browse/%s';
     $this->Pager = new PagerModule($this);
     $this->Pager->Configure($Offset, $Limit, $this->RecordCount, $this->Url);
     $this->Title(T('Chunks'));
     $this->Render();
 }
Example #9
0
 public function Browse($Page = '')
 {
     $this->Permission('Candy.Settings.View');
     list($Offset, $Limit) = OffsetLimit($Page, 100);
     $this->Pages = $this->PageModel->Get(array('WithSection' => False), $Offset, $Limit, 'p.DateUpdated');
     $this->RecordCount = $this->PageModel->GetCount();
     $this->Url = '/candy/page/browse/%s';
     $this->Pager = new PagerModule($this);
     $this->Pager->Configure($Offset, $Limit, $this->RecordCount, $this->Url);
     $this->Title(T('Pages'));
     $this->Render();
 }
 public function Index($Offset = '0')
 {
     list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30));
     $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE)), TRUE));
     $this->Title(T('All Discussions'));
     if ($this->Head) {
         $this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
     }
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     // Add Modules
     $this->AddModule('NewDiscussionModule');
     $this->AddModule('CategoriesModule');
     $BookmarkedModule = new BookmarkedModule($this);
     $BookmarkedModule->GetData();
     $this->AddModule($BookmarkedModule);
     $this->SetData('Category', FALSE, TRUE);
     $DiscussionModel = new DiscussionModel();
     $CountDiscussions = $DiscussionModel->GetCount();
     $this->SetData('CountDiscussions', $CountDiscussions);
     $this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
     $this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
     $this->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
     $this->SetData('Discussions', $this->DiscussionData, TRUE);
     $this->SetJson('Loading', $Offset . ' to ' . $Limit);
     // Build a pager.
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('Pager', $this);
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%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';
     }
     // 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());
         $this->AddDefinition('SetClientHour', $ClientHour);
     }
     // Render the controller
     $this->Render();
 }
 /**
  * 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'));
     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) {
         $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();
 }
 /**
  * List all tags and allow searching
  *
  * @param SettingsController $Sender
  */
 public function SettingsController_Tagging_Create($Sender, $Search = NULL, $Type = NULL, $Page = NULL)
 {
     $Sender->Title('Tagging');
     $Sender->AddSideMenu('settings/tagging');
     $Sender->AddCSSFile('plugins/Tagging/design/tagadmin.css');
     $Sender->AddJSFile('plugins/Tagging/js/admin.js');
     $SQL = Gdn::SQL();
     // Get all tag types
     $TagModel = TagModel::instance();
     $TagTypes = $TagModel->getTagTypes();
     $Sender->Form->Method = 'get';
     $Sender->Form->InputPrefix = '';
     list($Offset, $Limit) = OffsetLimit($Page, 100);
     $Sender->SetData('_Limit', $Limit);
     if ($Search) {
         $SQL->Like('FullName', $Search, 'right');
     }
     // This type doesn't actually exist, but it will represent the
     // blank types in the column.
     if (strtolower($Type) == 'tags') {
         $Type = '';
     }
     if (!$Search) {
         if ($Type !== NULL) {
             if ($Type === 'null') {
                 $Type = NULL;
             }
             $SQL->Where('Type', $Type);
         } else {
             if ($Type == '') {
                 $SQL->Where('Type', '');
             }
         }
     } else {
         $Type = 'Search Results';
         // This is made up, and exists so search results can be placed in
         // their own tab.
         $TagTypes[$Type] = array('key' => $Type);
     }
     $TagTypes = array_change_key_case($TagTypes, CASE_LOWER);
     // Store type for view
     $TagType = !empty($Type) ? $Type : 'Tags';
     $Sender->SetData('_TagType', $TagType);
     // Store tag types
     $Sender->SetData('_TagTypes', $TagTypes);
     // Determine if new tags can be added for the current type.
     $CanAddTags = !empty($TagTypes[$Type]['addtag']) && $TagTypes[$Type]['addtag'] ? 1 : 0;
     $Sender->SetData('_CanAddTags', $CanAddTags);
     $Data = $SQL->Select('t.*')->From('Tag t')->OrderBy('t.FullName', 'asc')->OrderBy('t.CountDiscussions', 'desc')->Limit($Limit, $Offset)->Get()->ResultArray();
     $Sender->SetData('Tags', $Data);
     if ($Search) {
         $SQL->Like('Name', $Search, 'right');
     }
     // Make sure search uses its own search type, so results appear
     // in their own tab.
     $Sender->Form->Action = Url('/settings/tagging/?type=' . $TagType);
     // Search results pagination will mess up a bit, so don't provide a type
     // in the count.
     $RecordCountWhere = array('Type' => $Type);
     if ($Type == '') {
         $RecordCountWhere = array('Type' => '');
     }
     if ($Search) {
         $RecordCountWhere = array();
     }
     $Sender->SetData('RecordCount', $SQL->GetCount('Tag', $RecordCountWhere));
     $Sender->Render('tagging', '', 'plugins/Tagging');
 }
    /**
     * 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();
    }
 /**
  * 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();
     }
 }
 /**
  * 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();
 }
   /**
    * Show all conversations for the currently authenticated user.
    *
    * @since 2.0.0
    * @access public
    * 
    * @param string $Page
    */
   public function All($Page = '') {
      $Session = Gdn::Session();
      $this->Title(T('Conversations'));

      list($Offset, $Limit) = OffsetLimit($Page, C('Conversations.Conversations.PerPage', 50));
      
      // Calculate offset
      $this->Offset = $Offset;
      
      // Limit to bookmarks?   
      $Wheres = array();
      if ($this->Request->Get('Bookmarked'))
         $Wheres['Bookmarked'] = '1';

      $UserID = $this->Request->Get('userid', Gdn::Session()->UserID);
      if ($UserID != Gdn::Session()->UserID)
         $this->Permission('Conversations.Moderation.Manage');
      
      // Fetch from model  
      $ConversationData = $this->ConversationModel->Get(
         $UserID,
         $this->Offset,
         $Limit,
         $Wheres
      );
      
      // Join in the participants.
      $Result = $ConversationData->Result();
      $this->ConversationModel->JoinParticipants($Result);
      
      $this->ConversationData =& $ConversationData;
      $this->SetData('Conversations', $Result);
      
      $CountConversations = $this->ConversationModel->GetCount($Session->UserID, $Wheres);
      
      // Build a pager
      $PagerFactory = new Gdn_PagerFactory();
      $this->Pager = $PagerFactory->GetPager('MorePager', $this);
      $this->Pager->MoreCode = 'Older Conversations';
      $this->Pager->LessCode = 'Newer Conversations';
      $this->Pager->ClientID = 'Pager';
      $this->Pager->Configure(
         $this->Offset,
         $Limit,
         $CountConversations,
         'messages/all/{Page}' //'messages/all/%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 = 'conversations';
      }
      
      // Build and display page.
      $this->AddModule('SignedInModule');
      $this->AddModule('NewConversationModule');
      $this->Render();
   }
 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();
 }
Example #18
0
 /**
  * View spam logs.
  *
  * @since 2.0.?
  * @access public
  *
  * @param int $Page Page number.
  */
 public function Spam($Page = '')
 {
     $this->Permission('Garden.Moderation.Manage');
     list($Offset, $Limit) = OffsetLimit($Page, 10);
     $this->SetData('Title', T('Spam Queue'));
     $Where = array('Operation' => array('Spam'));
     $RecordCount = $this->LogModel->GetCountWhere($Where);
     $this->SetData('RecordCount', $RecordCount);
     if ($Offset >= $RecordCount) {
         $Offset = $RecordCount - $Limit;
     }
     $Log = $this->LogModel->GetWhere($Where, 'LogID', 'Desc', $Offset, $Limit);
     $this->SetData('Log', $Log);
     if ($this->DeliveryType() == DELIVERY_TYPE_VIEW) {
         $this->View = 'Table';
     }
     $this->AddSideMenu('dashboard/log/spam');
     $this->Render();
 }
 /**
  * Create paginated list of discussions user has participated in.
  */
 public function DiscussionsController_Participated_Create($Sender, $Args = array())
 {
     $Sender->Permission('Garden.SignIn.Allow');
     Gdn_Theme::Section('DiscussionList');
     $Page = GetValue(0, $Args);
     $Limit = GetValue(1, $Args);
     // Set criteria & get discussions data
     list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
     $DiscussionModel = new DiscussionModel();
     $Sender->DiscussionData = $DiscussionModel->GetParticipated(Gdn::Session()->UserID, $Offset, $Limit);
     $Sender->SetData('Discussions', $Sender->DiscussionData);
     //Set view
     $Sender->View = 'index';
     if (C('Vanilla.Discussions.Layout') === 'table') {
         $Sender->View = 'table';
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->EventArguments['PagerType'] = 'Pager';
     $Sender->FireEvent('BeforeBuildParticipatedPager');
     $Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, FALSE, 'discussions/participated/{Page}');
     $Sender->SetData('CountDiscussions', false);
     // force prev/next pager
     $Sender->FireEvent('AfterBuildParticipatedPager');
     // 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';
     }
     $Sender->SetData('_PagerUrl', 'discussions/participated/{Page}');
     $Sender->SetData('_Page', $Page);
     $Sender->SetData('_Limit', $Limit);
     // Add modules
     $Sender->AddModule('NewDiscussionModule');
     $Sender->AddModule('DiscussionFilterModule');
     $Sender->AddModule('CategoriesModule');
     $Sender->AddModule('BookmarkedModule');
     $Sender->Title(T('Participated Discussions'));
     $Sender->SetData('Breadcrumbs', array(array('Name' => T('Participated Discussions'), 'Url' => '/discussions/participated')));
     $Sender->Render();
 }
 /**
  * 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 conversations for the currently authenticated user.
  *
  * @since 2.0.0
  * @access public
  * 
  * @param string $Page
  */
 public function All($Page = '')
 {
     $Session = Gdn::Session();
     $this->Title(T('Inbox'));
     Gdn_Theme::Section('ConversationList');
     list($Offset, $Limit) = OffsetLimit($Page, C('Conversations.Conversations.PerPage', 50));
     // Calculate offset
     $this->Offset = $Offset;
     $UserID = $this->Request->Get('userid', Gdn::Session()->UserID);
     if ($UserID != Gdn::Session()->UserID) {
         if (!C('Conversations.Moderation.Allow', FALSE)) {
             throw PermissionException();
         }
         $this->Permission('Conversations.Moderation.Manage');
     }
     $Conversations = $this->ConversationModel->Get2($UserID, $Offset, $Limit);
     $this->SetData('Conversations', $Conversations->ResultArray());
     // Get Conversations Count
     //$CountConversations = $this->ConversationModel->GetCount($UserID);
     //$this->SetData('CountConversations', $CountConversations);
     // Build the pager
     if (!$this->Data('_PagerUrl')) {
         $this->SetData('_PagerUrl', 'messages/all/{Page}');
     }
     $this->SetData('_Page', $Page);
     $this->SetData('_Limit', $Limit);
     $this->SetData('_CurrentRecords', count($Conversations->ResultArray()));
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'conversations';
     }
     // Build and display page.
     $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();
 }
 /**
  * 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();
 }
   public static function Write($Options = array()) {
      static $WriteCount = 0;

      if (!self::$_CurrentPager) {
         if (is_a($Options, 'Gdn_Controller')) {
            self::$_CurrentPager = new PagerModule($Options);
            $Options = array();
         } else {
            self::$_CurrentPager = new PagerModule(GetValue('Sender', $Options, Gdn::Controller()));
         }
      }
      $Pager = self::$_CurrentPager;

		$Pager->MoreCode = GetValue('MoreCode', $Options, $Pager->MoreCode);
		$Pager->LessCode = GetValue('LessCode', $Options, $Pager->LessCode);
		
      $Pager->ClientID = GetValue('ClientID', $Options, $Pager->ClientID);

      $Pager->Limit = GetValue('Limit', $Options, $Pager->Controller()->Data('_Limit', $Pager->Limit));
      $Pager->HtmlBefore = GetValue('HtmlBefore', $Options, GetValue('HtmlBefore', $Pager, ''));

      // Try and figure out the offset based on the parameters coming in to the controller.
      if (!$Pager->Offset) {
         $Page = $Pager->Controller()->Request->Get('Page', FALSE);
         if (!$Page) {
            $Page = 'p1';
            foreach($Pager->Controller()->RequestArgs as $Arg) {
               if (preg_match('`p\d+`', $Arg)) {
                  $Page = $Arg;
                  break;
               }
            }
         }
         list($Offset, $Limit) = OffsetLimit($Page, $Pager->Limit);
         $TotalRecords = GetValue('RecordCount', $Options, $Pager->Controller()->Data('RecordCount', 0));

         $Get = $Pager->Controller()->Request->Get();
         unset($Get['Page']);
         $Url = GetValue('Url', $Options, $Pager->Controller()->SelfUrl.'?Page={Page}&'.http_build_query($Get));

         $Pager->Configure($Offset, $Limit, $TotalRecords, $Url);
      }

      echo $Pager->ToString($WriteCount > 0 ? 'more' : 'less');
      $WriteCount++;

//      list($Offset, $Limit) = OffsetLimit(GetValue, 20);
//		$Pager->Configure(
//			$Offset,
//			$Limit,
//			$TotalAddons,
//			"/settings/addons/$Section?Page={Page}"
//		);
//		$Sender->SetData('_Pager', $Pager);
   }
 /**
  * Manage user bans (add, edit, delete, list).
  *
  * @since 2.0.18
  * @access public
  * @param string $Action Add, edit, delete, or none.
  * @param string $Search Term to filter ban list by.
  * @param int $Page Page number.
  * @param int $ID Ban ID we're editing or deleting.
  */
 public function Bans($Action = '', $Search = '', $Page = '', $ID = '')
 {
     $this->Permission('Garden.Moderation.Manage');
     // Page setup
     $this->AddSideMenu();
     $this->Title(T('Banning Options'));
     $this->AddJsFile('bans.js');
     list($Offset, $Limit) = OffsetLimit($Page, 20);
     $BanModel = new BanModel();
     $this->_BanModel = $BanModel;
     switch (strtolower($Action)) {
         case 'add':
         case 'edit':
             $this->Form->SetModel($BanModel);
             if ($this->Form->AuthenticatedPostBack()) {
                 if ($ID) {
                     $this->Form->SetFormValue('BanID', $ID);
                 }
                 try {
                     // Save the ban.
                     $this->Form->Save();
                 } catch (Exception $Ex) {
                     $this->Form->AddError($Ex);
                 }
             } else {
                 if ($ID) {
                     $this->Form->SetData($BanModel->GetID($ID));
                 }
             }
             $this->SetData('_BanTypes', array('IPAddress' => T('IP Address'), 'Email' => T('Email'), 'Name' => T('Name')));
             $this->View = 'Ban';
             break;
         case 'delete':
             $BanModel->Delete(array('BanID' => $ID));
             $this->View = 'BanDelete';
             break;
         default:
             $Bans = $BanModel->GetWhere(array(), 'BanType, BanValue', 'asc', $Limit, $Offset)->ResultArray();
             $this->SetData('Bans', $Bans);
             break;
     }
     $this->Render();
 }
Example #26
0
 /**
  * Tag management (let admins rename tags, remove tags, etc).
  * TODO: manage the Plugins.Tagging.Required boolean setting that makes tagging required or not.
  * @param SettingsController $Sender
  */
 public function SettingsController_Tagging_Create($Sender, $Args)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title('Tagging');
     $Sender->AddSideMenu('settings/tagging');
     $Sender->AddCSSFile('plugins/Tagging/design/tagadmin.css');
     $Sender->AddJSFile('plugins/Tagging/admin.js');
     $SQL = Gdn::SQL();
     $Sender->Form->Method = 'get';
     $Sender->Form->InputPrefix = '';
     $Sender->Form->Action = '/settings/tagging';
     list($Offset, $Limit) = OffsetLimit($Sender->Request->Get('Page'), 100);
     $Sender->SetData('_Limit', $Limit);
     if ($Search = $Sender->Request->Get('Search')) {
         $SQL->Like('Name', $Search, 'right');
     }
     $Data = $SQL->Select('t.*')->From('Tag t')->OrderBy('t.Name', 'asc')->OrderBy('t.CountDiscussions', 'desc')->Limit($Limit, $Offset)->Get()->ResultArray();
     $Sender->SetData('Tags', $Data);
     if ($Search = $Sender->Request->Get('Search')) {
         $SQL->Like('Name', $Search, 'right');
     }
     $Sender->SetData('RecordCount', $SQL->GetCount('Tag'));
     $Sender->Render('Tagging', '', 'plugins/Tagging');
 }
Example #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();
 }
Example #28
0
 /**
  * This method shows the highest scoring discussions/comments a user has ever posted
  *
  * @param ProfileController $Sender
  * @param int $UserReference
  * @param string $Username
  * @param int $Page
  */
 public function ProfileController_Best_Create($Sender, $UserReference = '', $Username = '', $Page = 0)
 {
     if (!C('Yaga.Reactions.Enabled')) {
         return;
     }
     list($Offset, $Limit) = OffsetLimit($Page, C('Yaga.BestContent.PerPage', 10));
     if (!is_numeric($Offset) || $Offset < 0) {
         $Offset = 0;
     }
     $Sender->EditMode(FALSE);
     // Tell the ProfileController what tab to load
     $Sender->GetUserInfo($UserReference, $Username);
     $Sender->_SetBreadcrumbs(T('Yaga.BestContent'), UserUrl($Sender->User, '', 'best'));
     $Sender->SetTabView(T('Yaga.BestContent'), 'best', 'profile', 'Yaga');
     $Sender->AddJsFile('jquery.expander.js');
     $Sender->AddJsFile('reactions.js', 'yaga');
     $Sender->AddDefinition('ExpandText', T('(more)'));
     $Sender->AddDefinition('CollapseText', T('(less)'));
     $Model = new ActedModel();
     $Data = $Model->GetBest($Sender->User->UserID, $Limit, $Offset);
     $Sender->SetData('Content', $Data);
     // 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) {
         $Sender->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex,noarchive'));
     }
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
     $Sender->Pager->ClientID = 'Pager';
     $Sender->Pager->Configure($Offset, $Limit, FALSE, 'profile/best/' . $Sender->User->UserID . '/' . Gdn_Format::Url($Sender->User->Name) . '/%1$s/');
     // Render the ProfileController
     $Sender->Render();
 }
 /**
  * Default activity stream.
  * 
  * @since 2.0.0
  * @access public
  * @todo Validate comment length rather than truncating.
  * 
  * @param int $Offset Number of activity items to skip.
  */
 public function Index($Filter = FALSE, $Page = FALSE)
 {
     switch (strtolower($Filter)) {
         case 'mods':
             $this->Title(T('Recent Moderator Activity'));
             $this->Permission('Garden.Moderation.Manage');
             $NotifyUserID = ActivityModel::NOTIFY_MODS;
             break;
         case 'admins':
             $this->Title(T('Recent Admin Activity'));
             $this->Permission('Garden.Settings.Manage');
             $NotifyUserID = ActivityModel::NOTIFY_ADMINS;
             break;
         default:
             $Filter = 'public';
             $this->Title(T('Recent Activity'));
             $this->Permission('Garden.Activity.View');
             $NotifyUserID = ActivityModel::NOTIFY_PUBLIC;
             break;
     }
     // Which page to load
     list($Offset, $Limit) = OffsetLimit($Page, 30);
     $Offset = is_numeric($Offset) ? $Offset : 0;
     if ($Offset < 0) {
         $Offset = 0;
     }
     // Page meta.
     $this->AddJsFile('activity.js');
     // Comment submission
     $Session = Gdn::Session();
     $Comment = $this->Form->GetFormValue('Comment');
     $Activities = $this->ActivityModel->GetWhere(array('NotifyUserID' => $NotifyUserID), $Offset, $Limit)->ResultArray();
     $this->ActivityModel->JoinComments($Activities);
     $this->SetData('Filter', strtolower($Filter));
     $this->SetData('Activities', $Activities);
     $this->AddModule('ActivityFilterModule');
     $this->View = 'all';
     $this->Render();
 }
    /**
     * Alternate version of Index that uses the embed master view.
     */
    public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
    {
        $this->CanEditComments = FALSE;
        // Don't show the comment checkboxes on the embed comments page
        $this->Theme = 'default';
        // Force the default theme on embedded comments
        // 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; }
ul.MessageList li.Item { background: #fff; }
ul.MessageList li.Item.Mine { background: #E3F4FF; }
</style>');
        }
        $Session = Gdn::Session();
        $this->AddJsFile('jquery.ui.packed.js');
        $this->AddJsFile('jquery.gardenmorepager.js');
        $this->AddJsFile('jquery.autogrow.js');
        $this->AddJsFile('options.js');
        $this->AddJsFile('discussion.js');
        $this->MasterView = 'empty';
        // 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);
        $ForeignID = GetIncomingValue('vanilla_identifier', '');
        $ForeignType = GetIncomingValue('vanilla_type', '');
        $ForeignName = GetIncomingValue('vanilla_name', '');
        $ForeignUrl = GetIncomingValue('vanilla_url', '');
        $this->SetData('ForeignUrl', $ForeignUrl);
        $this->AddDefinition('ForeignUrl', $ForeignUrl);
        $ForeignBody = GetIncomingValue('vanilla_body', '');
        $CategoryID = GetIncomingValue('vanilla_category_id', '');
        // Retrieve the discussion record.
        $Discussion = FALSE;
        if ($DiscussionID > 0) {
            $Discussion = $this->DiscussionModel->GetID($DiscussionID);
        } else {
            if ($ForeignID != '' && $ForeignType != '') {
                $Discussion = $this->DiscussionModel->GetForeignID($ForeignID, $ForeignType);
            }
        }
        // If no discussion record was found, but foreign id was provided, create it now
        if (!$Discussion && $ForeignID != '' && $ForeignType != '') {
            if ($ForeignName == '' || $ForeignBody == '') {
                $PageInfo = FetchPageInfo($ForeignUrl);
                if (!$PageInfo['Exception']) {
                    $ForeignName = $PageInfo['Title'];
                    $ForeignBody = Wrap(Anchor($ForeignName, $ForeignUrl), 'strong') . "\n" . '<br />' . Wrap(Anchor($ForeignUrl, $ForeignUrl), 'small') . "\n" . Wrap($PageInfo['Description'], 'p');
                    if (count($PageInfo['Images']) > 0) {
                        $ForeignBody = Anchor(Img($PageInfo['Images'][0], array('alt' => $ForeignName, 'class' => 'Thumbnail')), $ForeignUrl) . "\n" . $ForeignBody;
                    }
                }
            }
            $Body = $ForeignBody;
            if ($Body == '' && $ForeignUrl != '') {
                $Body = $ForeignUrl;
            }
            if ($Body == '') {
                $Body = T('This discussion is related to an undefined foriegn content source.');
            }
            // Validate the CategoryID for inserting
            if (!is_numeric($CategoryID)) {
                $CategoryID = C('Vanilla.Embed.DefaultCategoryID', 0);
                if ($CategoryID <= 0) {
                    // No default category defined, so grab the first non-root category and use that.
                    try {
                        $CategoryID = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
                    } catch (Exception $ex) {
                        // No categories in the db? default to 0
                        $CategoryID = 0;
                    }
                }
            }
            $SystemUserID = Gdn::UserModel()->GetSystemUserID();
            $DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', array('InsertUserID' => $SystemUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'UpdateUserID' => $SystemUserID, 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $CategoryID == '' ? NULL : $CategoryID, 'ForeignID' => $ForeignID, 'Type' => $ForeignType, 'Name' => $ForeignName == '' ? T('Undefined foreign content') : $ForeignName, 'Body' => $Body, 'Attributes' => serialize(array('ForeignUrl' => $ForeignUrl))));
            $ValidationResults = $this->DiscussionModel->ValidationResults();
            if (count($ValidationResults) == 0 && $DiscussionID > 0) {
                $Discussion = $this->DiscussionModel->GetID($DiscussionID);
                // Update the category discussion count
                if ($CategoryID > 0) {
                    $this->DiscussionModel->UpdateDiscussionCount($CategoryID, $DiscussionID);
                }
            }
        }
        // If no discussion was found, 404
        if (!$Discussion) {
            $this->Render('FileNotFound', 'HomeController', 'Dashboard');
            return;
        }
        $this->SetData('Discussion', $Discussion, TRUE);
        $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE);
        $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', 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(Url(ConcatSep('/', 'discussion/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE)), TRUE));
        // Load the comments
        $this->CommentModel->OrderBy('c.DateInserted desc');
        // allow custom sort
        $this->SetData('CommentData', $this->CommentModel->Get($this->Discussion->DiscussionID, $Limit, $this->Offset), TRUE);
        // 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/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s');
        $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('DiscussionID', $this->Discussion->DiscussionID);
        $this->Form->AddHidden('CommentID', '');
        $this->Form->AddHidden('DisplayNewCommentOnly', 'true');
        // Only load/display the new comment after posting (don't load all new comments since the page last loaded).
        // Retrieve & apply the draft if there is one:
        $Draft = FALSE;
        if (Gdn::Session()->UserID) {
            $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);
        } else {
            // Look in the session stash for a comment
            $StashComment = $Session->Stash('CommentForDiscussionID_' . $this->Discussion->DiscussionID, '', FALSE);
            if ($StashComment) {
                $this->Form->SetFormValue('Body', $StashComment);
            }
        }
        // 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';
        }
        $this->AddDefinition('PrependNewComments', '1');
        $this->AddDefinition('DiscussionID', $Discussion->DiscussionID);
        // Report the discussion id so js can use it.
        $this->FireEvent('BeforeDiscussionRender');
        $this->Render();
    }