/** * Hightlight menu path. Automatically run on every use. * * @since 2.0.0 * @access public */ public function Initialize() { parent::Initialize(); Gdn_Theme::Section('Dashboard'); if ($this->Menu) { $this->Menu->HighlightRoute('/dashboard/settings'); } }
public function PluginController_FileUpload_Create($Sender) { $Sender->Title('FileUpload'); $Sender->AddSideMenu('plugin/fileupload'); Gdn_Theme::Section('Dashboard'); $Sender->Form = new Gdn_Form(); $this->EnableSlicing($Sender); $this->Dispatch($Sender, $Sender->RequestArgs); }
public function Initialize() { parent::Initialize(); Gdn_Theme::Section('Dashboard'); $this->Model = new DBAModel(); $this->Form = new Gdn_Form(); $this->Form->InputPrefix = ''; $this->AddJsFile('dba.js'); }
/** * 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(); }
/** * Make this look like a dashboard page and add the resources * * @since 1.0 * @access public */ public function Initialize() { parent::Initialize(); $this->Application = 'Yaga'; Gdn_Theme::Section('Dashboard'); if ($this->Menu) { $this->Menu->HighlightRoute('/rank'); } $this->AddJsFile('jquery-ui-1.10.0.custom.min.js'); $this->AddJsFile('admin.ranks.js'); }
/** * Make this look like a dashboard page and add the resources * * @since 1.0 * @access public */ public function Initialize() { parent::Initialize(); $this->Application = 'Yaga'; Gdn_Theme::Section('Dashboard'); if ($this->Menu) { $this->Menu->HighlightRoute('/badge'); } $this->AddJsFile('admin.badges.js'); $this->AddCssFile('badges.css'); }
/** * Make this look like a dashboard page and add the resources * * @since 1.0 * @access public */ public function Initialize() { parent::Initialize(); $this->Application = 'Yaga'; Gdn_Theme::Section('Dashboard'); if ($this->Menu) { $this->Menu->HighlightRoute('/yaga'); } $this->AddSideMenu('yaga/settings'); $this->AddCssFile('yaga.css'); }
/** * Include JS and CSS used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function Initialize() { $this->Head = new HeadModule($this); $this->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex')); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('style.css'); parent::Initialize(); Gdn_Theme::Section('Entry'); }
/** * Include JS, CSS, and modules used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function Initialize() { $this->Head = new HeadModule($this); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('style.css'); // Add Modules $this->AddModule('GuestModule'); $this->AddModule('SignedInModule'); parent::Initialize(); Gdn_Theme::Section('ActivityList'); $this->SetData('Breadcrumbs', array(array('Name' => T('Activity'), 'Url' => '/activity'))); }
/** * Adds JS, CSS, & modules. Automatically run on every use. * * @since 2.0.0 * @access public */ public function Initialize() { $this->ModuleSortContainer = 'Profile'; $this->Head = new HeadModule($this); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('style.css'); $this->AddModule('GuestModule'); parent::Initialize(); Gdn_Theme::Section('Profile'); if ($this->EditMode) { $this->CssClass .= 'EditMode'; } $this->SetData('Breadcrumbs', array()); }
/** * Highlight route and do authenticator setup. * * Always called by dispatcher before controller's requested method. * * @since 2.0.3 * @access public */ public function Initialize() { parent::Initialize(); Gdn_Theme::Section('Dashboard'); if ($this->Menu) { $this->Menu->HighlightRoute('/dashboard/authentication'); } $this->EnableSlicing($this); $Authenticators = Gdn::Authenticator()->GetAvailable(); $this->ChooserList = array(); $this->ConfigureList = array(); foreach ($Authenticators as $AuthAlias => $AuthConfig) { $this->ChooserList[$AuthAlias] = $AuthConfig['Name']; $Authenticator = Gdn::Authenticator()->AuthenticateWith($AuthAlias); $ConfigURL = is_a($Authenticator, "Gdn_Authenticator") && method_exists($Authenticator, 'AuthenticatorConfiguration') ? $Authenticator->AuthenticatorConfiguration($this) : FALSE; $this->ConfigureList[$AuthAlias] = $ConfigURL; } $this->CurrentAuthenticationAlias = Gdn::Authenticator()->AuthenticateWith('default')->GetAuthenticationSchemeAlias(); }
/** * Default all drafts view: chronological by time saved. * * @since 2.0.0 * @access public * * @param int $Offset Number of drafts to skip. */ public function Index($Offset = '0') { Gdn_Theme::Section('DiscussionList'); // Setup head $this->Permission('Garden.SignIn.Allow'); $this->AddCssFile('vanilla.css'); $this->AddJsFile('jquery.gardenmorepager.js'); $this->AddJsFile('discussions.js'); $this->Title(T('My Drafts')); // Validate $Offset if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Set criteria & get drafts data $Limit = Gdn::Config('Vanilla.Discussions.PerPage', 30); $Session = Gdn::Session(); $Wheres = array('d.InsertUserID' => $Session->UserID); $this->DraftData = $this->DraftModel->Get($Session->UserID, $Offset, $Limit); $CountDrafts = $this->DraftModel->GetCount($Session->UserID); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More drafts'; $this->Pager->LessCode = 'Newer drafts'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $CountDrafts, 'drafts/%1$s'); // Deliver JSON data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'drafts'; } // Add modules $this->AddModule('DiscussionFilterModule'); $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); // Render default view (drafts/index.php) $this->Render(); }
/** * Always triggered first. Add Javascript files. * * @since 2.0.? * @access public */ public function Initialize() { parent::Initialize(); Gdn_Theme::Section('Dashboard'); $this->AddJsFile('log.js'); $this->AddJsFile('jquery.expander.js'); $this->AddJsFile('jquery-ui.js'); $this->Form->InputPrefix = ''; }
/** * 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(); }
/** * Load discussions for a specific tag. */ public function DiscussionsController_Tagged_Create($Sender) { Gdn_Theme::Section('DiscussionList'); if ($Sender->Request->Get('Tag')) { $Tag = $Sender->Request->Get('Tag'); $Page = GetValue('0', $Sender->RequestArgs, 'p1'); } else { $Tag = urldecode(GetValue('0', $Sender->RequestArgs, '')); $Page = GetValue('1', $Sender->RequestArgs, 'p1'); } if ($Sender->Request->Get('Page')) { $Page = $Sender->Request->Get('Page'); } $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE); list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30)); $Sender->SetData('Tag', $Tag, TRUE); $Sender->Title(T('Tagged with ') . htmlspecialchars($Tag)); $Sender->Head->Title($Sender->Head->Title()); $UrlTag = rawurlencode($Tag); if (urlencode($Tag) == $Tag) { $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE)); $FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//'); } else { $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE)); $FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//'); } if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->Head->AddRss($FeedUrl, $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $Sender->AddModule('DiscussionFilterModule'); $BookmarkedModule = new BookmarkedModule($Sender); $BookmarkedModule->GetData(); $Sender->AddModule($BookmarkedModule); $Sender->SetData('Category', FALSE, TRUE); $Sender->SetData('CountDiscussions', FALSE); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel = new DiscussionModel(); $this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or')); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all')); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; if (urlencode($Sender->Tag) == $Sender->Tag) { $PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}"; } else { $PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag); } $Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat); // Deliver json data if necessary. if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) { $Sender->SetJson('LessRow', $Sender->Pager->ToString('less')); $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more')); $Sender->View = 'discussions'; } // Render the controller $Sender->Render('TaggedDiscussions', '', 'plugins/Tagging'); }
public function Unread($Page = '0') { if (!Gdn::Session()->IsValid()) { Redirect('/discussions/index', 302); } // 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; } Gdn_Theme::Section('DiscussionList'); // Determine offset from $Page list($Page, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30)); $this->CanonicalUrl(Url(ConcatSep('/', 'discussions', 'unread', PageNumber($Page, $Limit, TRUE, FALSE)), TRUE)); // Validate $Page if (!is_numeric($Page) || $Page < 0) { $Page = 0; } // Setup head. if (!$this->Data('Title')) { $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('Unread Discussions')); } } if (!$this->Description()) { $this->Description(C('Garden.Description', NULL)); } if ($this->Head) { $this->Head->AddRss(Url('/discussions/unread/feed.rss', TRUE), $this->Head->Title()); } // Add modules $this->AddModule('DiscussionFilterModule'); $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); $this->SetData('Breadcrumbs', array(array('Name' => T('Discussions'), 'Url' => '/discussions'), array('Name' => T('Unread'), 'Url' => '/discussions/unread'))); // Set criteria & get discussions data $this->SetData('Category', FALSE, TRUE); $DiscussionModel = new DiscussionModel(); $DiscussionModel->Watching = TRUE; // Get Discussion Count $CountDiscussions = $DiscussionModel->GetUnreadCount(); $this->SetData('CountDiscussions', $CountDiscussions); // Get Discussions $this->DiscussionData = $DiscussionModel->GetUnread($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/unread/%1$s'); if (!$this->Data('_PagerUrl')) { $this->SetData('_PagerUrl', 'discussions/unread/{Page}'); } $this->SetData('_Page', $Page); $this->SetData('_Limit', $Limit); $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); } $this->Render(); }
/** * Load discussions for a specific tag. * @param DiscussionsController $Sender */ public function DiscussionsController_Tagged_Create($Sender) { Gdn_Theme::Section('DiscussionList'); $Args = $Sender->RequestArgs; $Get = array_change_key_case($Sender->Request->Get()); if ($UseCategories = C('Plugins.Tagging.UseCategories')) { // The url is in the form /category/tag/p1 $CategoryCode = GetValue(0, $Args); $Tag = GetValue(1, $Args); $Page = GetValue(2, $Args); } else { // The url is in the form /tag/p1 $CategoryCode = ''; $Tag = GetValue(0, $Args); $Page = GetValue(1, $Args); } // Look for explcit values. $CategoryCode = GetValue('category', $Get, $CategoryCode); $Tag = GetValue('tag', $Get, $Tag); $Page = GetValue('page', $Get, $Page); $Category = CategoryModel::Categories($CategoryCode); $Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE); list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30)); $MultipleTags = strpos($Tag, ',') !== FALSE; $Sender->SetData('Tag', $Tag, TRUE); $TagModel = TagModel::instance(); $RecordCount = FALSE; if (!$MultipleTags) { $Tags = $TagModel->GetWhere(array('Name' => $Tag))->ResultArray(); if (count($Tags) == 0) { throw NotFoundException('Page'); } if (count($Tags) > 1) { foreach ($Tags as $TagRow) { if ($TagRow['CategoryID'] == GetValue('CategoryID', $Category)) { break; } } } else { $TagRow = array_pop($Tags); } $Tags = $TagModel->getRelatedTags($TagRow); $RecordCount = $TagRow['CountDiscussions']; $Sender->SetData('CountDiscussions', $RecordCount); $Sender->SetData('Tags', $Tags); $Sender->SetData('Tag', $TagRow); $ChildTags = $TagModel->getChildTags($TagRow['TagID']); $Sender->SetData('ChildTags', $ChildTags); } $Sender->Title(htmlspecialchars($TagRow['FullName'])); $UrlTag = rawurlencode($Tag); if (urlencode($Tag) == $Tag) { $Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE)); $FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//'); } else { $Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE)); $FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//'); } if ($Sender->Head) { $Sender->AddJsFile('discussions.js'); $Sender->Head->AddRss($FeedUrl, $Sender->Head->Title()); } if (!is_numeric($Offset) || $Offset < 0) { $Offset = 0; } // Add Modules $Sender->AddModule('NewDiscussionModule'); $Sender->AddModule('DiscussionFilterModule'); $Sender->AddModule('BookmarkedModule'); $Sender->SetData('Category', FALSE, TRUE); $Sender->AnnounceData = FALSE; $Sender->SetData('Announcements', array(), TRUE); $DiscussionModel = new DiscussionModel(); $TagModel->SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or')); $Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all')); $Sender->SetData('Discussions', $Sender->DiscussionData, TRUE); $Sender->SetJson('Loading', $Offset . ' to ' . $Limit); // Build a pager. $PagerFactory = new Gdn_PagerFactory(); $Sender->Pager = $PagerFactory->GetPager('Pager', $Sender); $Sender->Pager->ClientID = 'Pager'; $Sender->Pager->Configure($Offset, $Limit, $RecordCount, ''); $Sender->View = C('Vanilla.Discussions.Layout'); /* // If these don't equal, then there is a category that should be inserted. if ($UseCategories && $Category && $TagRow['FullName'] != GetValue('Name', $Category)) { $Sender->Data['Breadcrumbs'][] = array('Name' => $Category['Name'], 'Url' => TagUrl($TagRow)); } $Sender->Data['Breadcrumbs'][] = array('Name' => $TagRow['FullName'], 'Url' => ''); */ // Render the controller. $this->View = C('Vanilla.Discussions.Layout') == 'table' ? 'table' : 'index'; $Sender->Render($this->View, 'discussions', 'vanilla'); }
/** * Show all categories and few discussions from each. * * @since 2.0.0 * @access public */ public function Discussions() { // Setup head $this->AddCssFile('vanilla.css'); $this->Menu->HighlightRoute('/discussions'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussions.js'); $this->AddJsFile('options.js'); $Title = C('Garden.HomepageTitle'); if ($Title) { $this->Title($Title, ''); } else { $this->Title(T('All Categories')); } $this->Description(C('Garden.Description', NULL)); Gdn_Theme::Section('CategoryDiscussionList'); // Set the category follow toggle before we load category data so that it affects the category query appropriately. $CategoryFollowToggleModule = new CategoryFollowToggleModule($this); $CategoryFollowToggleModule->SetToggle(); // Get category data and discussions $this->DiscussionsPerCategory = C('Vanilla.Discussions.PerCategory', 5); $DiscussionModel = new DiscussionModel(); $this->CategoryModel->Watching = !Gdn::Session()->GetPreference('ShowAllCategories'); $this->CategoryData = $this->CategoryModel->GetFull(); $this->SetData('Categories', $this->CategoryData); $this->CategoryDiscussionData = array(); foreach ($this->CategoryData->Result() as $Category) { if ($Category->CategoryID > 0) { $this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->Get(0, $this->DiscussionsPerCategory, array('d.CategoryID' => $Category->CategoryID, 'Announce' => 'all')); } } // Add modules $this->AddModule('NewDiscussionModule'); $this->AddModule('DiscussionFilterModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); $this->AddModule($CategoryFollowToggleModule); // Set view and render $this->View = 'discussions'; $this->CanonicalUrl(Url('/categories', TRUE)); include_once $this->FetchViewLocation('helper_functions', 'discussions'); $this->Render(); }
/** * Alternate version of Index that uses the embed master view. * * @param int $DiscussionID Unique identifier, if discussion has been created. * @param string $DiscussionStub Deprecated. * @param int $Offset * @param int $Limit */ public function Embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '') { $this->Title(T('Comments')); // Add theme data $this->Theme = C('Garden.CommentsTheme', $this->Theme); Gdn_Theme::Section('Comments'); // Force view options $this->MasterView = 'empty'; $this->CanEditComments = FALSE; // Don't show the comment checkboxes on the embed comments page // Add some css to help with the transparent bg on embedded comments if ($this->Head) { $this->Head->AddString('<style type="text/css"> body { background: transparent !important; } </style>'); } // Javascript files & options $this->AddJsFile('jquery.gardenmorepager.js'); $this->AddJsFile('jquery.autogrow.js'); $this->RemoveJsFile('autosave.js'); $this->AddJsFile('discussion.js'); $this->AddDefinition('DoInform', '0'); // Suppress inform messages on embedded page. $this->AddDefinition('SelfUrl', Gdn::Request()->PathAndQuery()); $this->AddDefinition('Embedded', TRUE); // Define incoming variables (prefer querystring parameters over method parameters) $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0; $DiscussionID = GetIncomingValue('vanilla_discussion_id', $DiscussionID); $Offset = GetIncomingValue('Offset', $Offset); $Limit = GetIncomingValue('Limit', $Limit); $vanilla_identifier = GetIncomingValue('vanilla_identifier', ''); // Only allow vanilla identifiers of 32 chars or less - md5 if larger if (strlen($vanilla_identifier) > 32) { $vanilla_identifier = md5($vanilla_identifier); } $vanilla_type = GetIncomingValue('vanilla_type', 'page'); $vanilla_url = GetIncomingValue('vanilla_url', ''); $vanilla_category_id = GetIncomingValue('vanilla_category_id', ''); $ForeignSource = array('vanilla_identifier' => $vanilla_identifier, 'vanilla_type' => $vanilla_type, 'vanilla_url' => $vanilla_url, 'vanilla_category_id' => $vanilla_category_id); $this->SetData('ForeignSource', $ForeignSource); // Set comment sorting $SortComments = C('Garden.Embed.SortComments') == 'desc' ? 'desc' : 'asc'; $this->SetData('SortComments', $SortComments); // Retrieve the discussion record $Discussion = FALSE; if ($DiscussionID > 0) { $Discussion = $this->DiscussionModel->GetID($DiscussionID); } else { if ($vanilla_identifier != '' && $vanilla_type != '') { $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type); } } // Set discussion data if we have one for this page if ($Discussion) { $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $Discussion->PermissionCategoryID); $this->SetData('Discussion', $Discussion, TRUE); $this->SetData('DiscussionID', $Discussion->DiscussionID, TRUE); $this->Title($Discussion->Name); // Actual number of comments, excluding the discussion itself $ActualResponses = $Discussion->CountComments; // Define the query offset & limit if (!is_numeric($Limit) || $Limit < 0) { $Limit = C('Garden.Embed.CommentsPerPage', 30); } $OffsetProvided = $Offset != ''; list($Offset, $Limit) = OffsetLimit($Offset, $Limit); $this->Offset = $Offset; if (C('Vanilla.Comments.AutoOffset')) { if ($ActualResponses <= $Limit) { $this->Offset = 0; } if ($this->Offset == $ActualResponses) { $this->Offset -= $Limit; } } else { if ($this->Offset == '') { $this->Offset = 0; } } if ($this->Offset < 0) { $this->Offset = 0; } // Set the canonical url to have the proper page title. $this->CanonicalUrl(DiscussionUrl($Discussion, PageNumber($this->Offset, $Limit))); // Load the comments. $CurrentOrderBy = $this->CommentModel->OrderBy(); if (StringBeginsWith(GetValueR('0.0', $CurrentOrderBy), 'c.DateInserted')) { $this->CommentModel->OrderBy('c.DateInserted ' . $SortComments); } // allow custom sort $this->SetData('Comments', $this->CommentModel->Get($Discussion->DiscussionID, $Limit, $this->Offset), TRUE); if (count($this->CommentModel->Where()) > 0) { $ActualResponses = FALSE; } $this->SetData('_Count', $ActualResponses); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->EventArguments['PagerType'] = 'MorePager'; $this->FireEvent('BeforeBuildPager'); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->ClientID = 'Pager'; $this->Pager->MoreCode = 'More Comments'; $this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/embed/' . $Discussion->DiscussionID . '/' . Gdn_Format::Url($Discussion->Name) . '/%1$s'); $this->Pager->CurrentRecords = $this->Comments->NumRows(); $this->FireEvent('AfterBuildPager'); } // Define the form for the comment input $this->Form = Gdn::Factory('Form', 'Comment'); $this->Form->Action = Url('/vanilla/post/comment/'); $this->Form->AddHidden('CommentID', ''); $this->Form->AddHidden('Embedded', 'true'); // Tell the post controller that this is an embedded page (in case there are custom views it needs to pick up from a theme). $this->Form->AddHidden('DisplayNewCommentOnly', 'true'); // Only load/display the new comment after posting (don't load all new comments since the page last loaded). // Grab the page title if ($this->Request->Get('title')) { $this->Form->SetValue('Name', $this->Request->Get('title')); } // Set existing DiscussionID for comment form if ($Discussion) { $this->Form->AddHidden('DiscussionID', $Discussion->DiscussionID); } foreach ($ForeignSource as $Key => $Val) { // Drop the foreign source information into the form so it can be used if creating a discussion $this->Form->AddHidden($Key, $Val); // Also drop it into the definitions so it can be picked up for stashing comments $this->AddDefinition($Key, $Val); } // Retrieve & apply the draft if there is one: $Draft = FALSE; if (Gdn::Session()->UserID && $Discussion) { $DraftModel = new DraftModel(); $Draft = $DraftModel->Get(Gdn::Session()->UserID, 0, 1, $Discussion->DiscussionID)->FirstRow(); $this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : ''); } if ($Draft) { $this->Form->SetFormValue('Body', $Draft->Body); } else { // Look in the session stash for a comment $StashComment = Gdn::Session()->Stash('CommentForForeignID_' . $ForeignSource['vanilla_identifier'], '', FALSE); if ($StashComment) { $this->Form->SetValue('Body', $StashComment); $this->Form->SetFormValue('Body', $StashComment); } } // Deliver JSON data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { if ($this->Discussion) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); } $this->View = 'comments'; } // Ordering note for JS if ($SortComments == 'desc') { $this->AddDefinition('PrependNewComments', '1'); } // Report the discussion id so js can use it. if ($Discussion) { $this->AddDefinition('DiscussionID', $Discussion->DiscussionID); } $this->FireEvent('BeforeDiscussionRender'); $this->Render(); }
public function EditMode($Switch) { $this->EditMode = $Switch; if (!$this->EditMode && strpos($this->CssClass, 'EditMode') !== FALSE) { $this->CssClass = str_replace('EditMode', '', $this->CssClass); } if ($Switch) { Gdn_Theme::Section('EditProfile'); } else { Gdn_Theme::Section('EditProfile', 'remove'); } }
/** * Create or update a discussion. * * @since 2.0.0 * @access public * * @param int $CategoryID Unique ID of the category to add the discussion to. */ public function Discussion($CategoryUrlCode = '') { // Override CategoryID if categories are disabled $UseCategories = $this->ShowCategorySelector = (bool) C('Vanilla.Categories.Use'); if (!$UseCategories) { $CategoryUrlCode = ''; } // Setup head $this->AddJsFile('jquery.autosize.min.js'); $this->AddJsFile('post.js'); $this->AddJsFile('autosave.js'); $Session = Gdn::Session(); Gdn_Theme::Section('PostDiscussion'); // Set discussion, draft, and category data $DiscussionID = isset($this->Discussion) ? $this->Discussion->DiscussionID : ''; $DraftID = isset($this->Draft) ? $this->Draft->DraftID : 0; $Category = FALSE; if (isset($this->Discussion)) { $this->CategoryID = $this->Discussion->CategoryID; $Category = CategoryModel::Categories($this->CategoryID); } else { if ($CategoryUrlCode != '') { $CategoryModel = new CategoryModel(); $Category = $CategoryModel->GetByCode($CategoryUrlCode); $this->CategoryID = $Category->CategoryID; } } if ($Category) { $this->Category = (object) $Category; $this->SetData('Category', $Category); } else { $this->CategoryID = 0; $this->Category = NULL; } $CategoryData = $UseCategories ? CategoryModel::Categories() : FALSE; // Check permission if (isset($this->Discussion)) { // Permission to edit if ($this->Discussion->InsertUserID != $Session->UserID) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); } // Make sure that content can (still) be edited. $EditContentTimeout = C('Garden.EditContentTimeout', -1); $CanEdit = $EditContentTimeout == -1 || strtotime($this->Discussion->DateInserted) + $EditContentTimeout > time(); if (!$CanEdit) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); } // Make sure only moderators can edit closed things if ($this->Discussion->Closed) { $this->Permission('Vanilla.Discussions.Edit', TRUE, 'Category', $this->Category->PermissionCategoryID); } $this->Form->SetFormValue('DiscussionID', $this->Discussion->DiscussionID); $this->Title(T('Edit Discussion')); if ($this->Discussion->Type) { $this->SetData('Type', $this->Discussion->Type); } else { $this->SetData('Type', 'Discussion'); } } else { // Permission to add $this->Permission('Vanilla.Discussions.Add'); $this->Title(T('New Discussion')); } TouchValue('Type', $this->Data, 'Discussion'); // See if we should hide the category dropdown. $AllowedCategories = CategoryModel::GetByPermission('Discussions.Add', $this->Form->GetValue('CategoryID', $this->CategoryID), array('Archived' => 0, 'AllowDiscussions' => 1), array('AllowedDiscussionTypes' => $this->Data['Type'])); if (count($AllowedCategories) == 1) { $AllowedCategory = array_pop($AllowedCategories); $this->ShowCategorySelector = FALSE; $this->Form->AddHidden('CategoryID', $AllowedCategory['CategoryID']); if ($this->Form->IsPostBack() && !$this->Form->GetFormValue('CategoryID')) { $this->Form->SetFormValue('CategoryID', $AllowedCategory['CategoryID']); } } // Set the model on the form $this->Form->SetModel($this->DiscussionModel); if ($this->Form->IsPostBack() == FALSE) { // Prep form with current data for editing if (isset($this->Discussion)) { $this->Form->SetData($this->Discussion); } elseif (isset($this->Draft)) { $this->Form->SetData($this->Draft); } else { if ($this->Category !== NULL) { $this->Form->SetData(array('CategoryID' => $this->Category->CategoryID)); } $this->PopulateForm($this->Form); } } else { // Form was submitted // Save as a draft? $FormValues = $this->Form->FormValues(); $FormValues = $this->DiscussionModel->FilterForm($FormValues); $this->DeliveryType(GetIncomingValue('DeliveryType', $this->_DeliveryType)); if ($DraftID == 0) { $DraftID = $this->Form->GetFormValue('DraftID', 0); } $Draft = $this->Form->ButtonExists('Save Draft') ? TRUE : FALSE; $Preview = $this->Form->ButtonExists('Preview') ? TRUE : FALSE; if (!$Preview) { if (!is_object($this->Category) && is_array($CategoryData) && isset($FormValues['CategoryID'])) { $this->Category = GetValue($FormValues['CategoryID'], $CategoryData); } if (is_object($this->Category)) { // Check category permissions. if ($this->Form->GetFormValue('Announce', '') && !$Session->CheckPermission('Vanilla.Discussions.Announce', TRUE, 'Category', $this->Category->PermissionCategoryID)) { $this->Form->AddError('You do not have permission to announce in this category', 'Announce'); } if ($this->Form->GetFormValue('Close', '') && !$Session->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $this->Category->PermissionCategoryID)) { $this->Form->AddError('You do not have permission to close in this category', 'Close'); } if ($this->Form->GetFormValue('Sink', '') && !$Session->CheckPermission('Vanilla.Discussions.Sink', TRUE, 'Category', $this->Category->PermissionCategoryID)) { $this->Form->AddError('You do not have permission to sink in this category', 'Sink'); } if (!isset($this->Discussion) && (!$Session->CheckPermission('Vanilla.Discussions.Add', TRUE, 'Category', $this->Category->PermissionCategoryID) || !$this->Category->AllowDiscussions)) { $this->Form->AddError('You do not have permission to start discussions in this category', 'CategoryID'); } } // Make sure that the title will not be invisible after rendering $Name = trim($this->Form->GetFormValue('Name', '')); if ($Name != '' && Gdn_Format::Text($Name) == '') { $this->Form->AddError(T('You have entered an invalid discussion title'), 'Name'); } else { // Trim the name. $FormValues['Name'] = $Name; $this->Form->SetFormValue('Name', $Name); } if ($this->Form->ErrorCount() == 0) { if ($Draft) { $DraftID = $this->DraftModel->Save($FormValues); $this->Form->SetValidationResults($this->DraftModel->ValidationResults()); } else { $DiscussionID = $this->DiscussionModel->Save($FormValues, $this->CommentModel); $this->Form->SetValidationResults($this->DiscussionModel->ValidationResults()); if ($DiscussionID > 0) { if ($DraftID > 0) { $this->DraftModel->Delete($DraftID); } } if ($DiscussionID == SPAM || $DiscussionID == UNAPPROVED) { $this->StatusMessage = T('DiscussionRequiresApprovalStatus', 'Your discussion will appear after it is approved.'); $this->Render('Spam'); return; } } } } else { // If this was a preview click, create a discussion/comment shell with the values for this comment $this->Discussion = new stdClass(); $this->Discussion->Name = $this->Form->GetValue('Name', ''); $this->Comment = new stdClass(); $this->Comment->InsertUserID = $Session->User->UserID; $this->Comment->InsertName = $Session->User->Name; $this->Comment->InsertPhoto = $Session->User->Photo; $this->Comment->DateInserted = Gdn_Format::Date(); $this->Comment->Body = ArrayValue('Body', $FormValues, ''); $this->Comment->Format = GetValue('Format', $FormValues, C('Garden.InputFormatter')); $this->EventArguments['Discussion'] =& $this->Discussion; $this->EventArguments['Comment'] =& $this->Comment; $this->FireEvent('BeforeDiscussionPreview'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { $this->AddAsset('Content', $this->FetchView('preview')); } else { $this->View = 'preview'; } } if ($this->Form->ErrorCount() > 0) { // Return the form errors $this->ErrorMessage($this->Form->Errors()); } else { if ($DiscussionID > 0 || $DraftID > 0) { // Make sure that the ajax request form knows about the newly created discussion or draft id $this->SetJson('DiscussionID', $DiscussionID); $this->SetJson('DraftID', $DraftID); if (!$Preview) { // If the discussion was not a draft if (!$Draft) { // Redirect to the new discussion $Discussion = $this->DiscussionModel->GetID($DiscussionID, DATASET_TYPE_OBJECT, array('Slave' => FALSE)); $this->SetData('Discussion', $Discussion); $this->EventArguments['Discussion'] = $Discussion; $this->FireEvent('AfterDiscussionSave'); if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { Redirect(DiscussionUrl($Discussion)) . '?new=1'; } else { $this->RedirectUrl = DiscussionUrl($Discussion, '', TRUE) . '?new=1'; } } else { // If this was a draft save, notify the user about the save $this->InformMessage(sprintf(T('Draft saved at %s'), Gdn_Format::Date())); } } } } } // Add hidden fields for editing $this->Form->AddHidden('DiscussionID', $DiscussionID); $this->Form->AddHidden('DraftID', $DraftID, TRUE); $this->FireEvent('BeforeDiscussionRender'); if ($this->CategoryID) { $Breadcrumbs = CategoryModel::GetAncestors($this->CategoryID); } else { $Breadcrumbs = array(); } $Breadcrumbs[] = array('Name' => $this->Data('Title'), 'Url' => '/post/discussion'); $this->SetData('Breadcrumbs', $Breadcrumbs); $this->SetData('_AnnounceOptions', $this->AnnounceOptions()); // Render view (posts/discussion.php or post/preview.php) $this->Render(); }
/** * Switch MasterView. Include JS, CSS used by all methods. * * Always called by dispatcher before controller's requested method. * * @since 2.0.0 * @access public */ public function Initialize() { // Set up head $this->Head = new HeadModule($this); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('jquery.atwho.js'); $this->AddJsFile('global.js'); if (in_array($this->ControllerName, array('profilecontroller', 'activitycontroller'))) { $this->AddCssFile('style.css'); } else { $this->AddCssFile('admin.css'); } // Change master template $this->MasterView = 'admin'; parent::Initialize(); Gdn_Theme::Section('Dashboard'); }
public function Init($Path, $Controller) { $Smarty = $this->Smarty(); // Get a friendly name for the controller. $ControllerName = get_class($Controller); if (StringEndsWith($ControllerName, 'Controller', TRUE)) { $ControllerName = substr($ControllerName, 0, -10); } // Get an ID for the body. $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($Controller->RequestMethod))); $Smarty->assign('BodyID', $BodyIdentifier); //$Smarty->assign('Config', Gdn::Config()); // Assign some information about the user. $Session = Gdn::Session(); if ($Session->IsValid()) { $User = array('Name' => $Session->User->Name, 'Photo' => '', 'CountNotifications' => (int) GetValue('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) GetValue('CountUnreadConversations', $Session->User, 0), 'SignedIn' => TRUE); $Photo = $Session->User->Photo; if ($Photo) { if (!preg_match('`^https?://`i', $Photo)) { $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s')); } } else { if (function_exists('UserPhotoDefaultUrl')) { $Photo = UserPhotoDefaultUrl($Session->User, 'ProfilePhoto'); } elseif ($ConfigPhoto = C('Garden.DefaultAvatar')) { $Photo = Gdn_Upload::Url($ConfigPhoto); } else { $Photo = Asset('/applications/dashboard/design/images/defaulticon.png', TRUE); } } $User['Photo'] = $Photo; } else { $User = FALSE; /*array( 'Name' => '', 'CountNotifications' => 0, 'SignedIn' => FALSE);*/ } $Smarty->assign('User', $User); // Make sure that any datasets use arrays instead of objects. foreach ($Controller->Data as $Key => $Value) { if ($Value instanceof Gdn_DataSet) { $Controller->Data[$Key] = $Value->ResultArray(); } elseif ($Value instanceof stdClass) { $Controller->Data[$Key] = (array) $Value; } } $BodyClass = GetValue('CssClass', $Controller->Data, '', TRUE); $Sections = Gdn_Theme::Section(NULL, 'get'); if (is_array($Sections)) { foreach ($Sections as $Section) { $BodyClass .= ' Section-' . $Section; } } $Controller->Data['BodyClass'] = $BodyClass; $Smarty->assign('Assets', (array) $Controller->Assets); $Smarty->assign('Path', Gdn::Request()->Path()); // Assigign the controller data last so the controllers override any default data. $Smarty->assign($Controller->Data); $Smarty->Controller = $Controller; // for smarty plugins $Smarty->security = TRUE; $Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('CheckPermission', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url', 'InSection', 'InCategory')); $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf')); $Smarty->secure_dir = array($Path); }
/** * Include JS, CSS, and modules used by all methods of this controller. * Called by dispatcher before controller's requested method. */ public function Initialize() { if ($this->DeliveryType() == DELIVERY_TYPE_ALL) { $this->Head = new HeadModule($this); } $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('admin.css'); $this->AddCssFile('pagessettings.css'); // Call Gdn_Controller's Initialize() as well. $this->MasterView = 'admin'; parent::Initialize(); Gdn_Theme::Section('Dashboard'); }
/** * 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(); }
/** * Shows all uncleared messages within a conversation for the viewing user * * @since 2.0.0 * @access public * * @param int $ConversationID Unique ID of conversation to view. * @param int $Offset Number to skip. * @param int $Limit Number to show. */ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') { $this->Offset = $Offset; $Session = Gdn::Session(); Gdn_Theme::Section('Conversation'); // Figure out Conversation ID if (!is_numeric($ConversationID) || $ConversationID < 0) { $ConversationID = 0; } // Form setup for adding comments $this->Form->SetModel($this->ConversationMessageModel); $this->Form->AddHidden('ConversationID', $ConversationID); // Check permissions on the recipients. $InConversation = $this->ConversationModel->InConversation($ConversationID, Gdn::Session()->UserID); if (!$InConversation) { // Conversation moderation must be enabled and they must have permission if (!C('Conversations.Moderation.Allow', FALSE)) { throw PermissionException(); } $this->Permission('Conversations.Moderation.Manage'); } $this->Conversation = $this->ConversationModel->GetID($ConversationID); $this->Conversation->Participants = $this->ConversationModel->GetRecipients($ConversationID); $this->SetData('Conversation', $this->Conversation); // Bad conversation? Redirect if ($this->Conversation === FALSE) { throw NotFoundException('Conversation'); } // Get limit if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) { $Limit = Gdn::Config('Conversations.Messages.PerPage', 50); } // Calculate counts if (!is_numeric($this->Offset) || $this->Offset < 0) { // Round down to the appropriate offset based on the user's read messages & messages per page $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages; if ($CountReadMessages < 0) { $CountReadMessages = 0; } if ($CountReadMessages > $this->Conversation->CountMessages) { $CountReadMessages = $this->Conversation->CountMessages; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountReadMessages / $Limit) * $Limit; // Send the hash link in. if ($CountReadMessages > 1) { $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages); } } // Fetch message data $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit); // Figure out who's participating. $ParticipantTitle = ConversationModel::ParticipantTitle($this->Conversation, TRUE); $this->Participants = $ParticipantTitle; $this->Title(strip_tags($this->Participants)); // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'Newer Messages'; $this->Pager->LessCode = 'Older Messages'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/'); // Mark the conversation as ready by this user. $this->ConversationModel->MarkRead($ConversationID, $Session->UserID); // Deliver json data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'messages'; } // Add modules. $ClearHistoryModule = new ClearHistoryModule($this); $ClearHistoryModule->ConversationID($ConversationID); $this->AddModule($ClearHistoryModule); $InThisConversationModule = new InThisConversationModule($this); $InThisConversationModule->SetData($this->Conversation->Participants); $this->AddModule($InThisConversationModule); // Doesn't make sense for people who can't even start conversations to be adding people if (CheckPermission('Conversations.Conversations.Add')) { $this->AddModule('AddPeopleModule'); } $Subject = $this->Data('Conversation.Subject'); if (!$Subject) { $Subject = T('Message'); } $this->Data['Breadcrumbs'][] = array('Name' => $Subject, Url('', '//')); // Render view $this->Render(); }
/** * Default single discussion display. * * @since 2.0.0 * @access public * * @param int $DiscussionID Unique discussion ID * @param string $DiscussionStub URL-safe title slug * @param int $Page The current page of comments */ public function Index($DiscussionID = '', $DiscussionStub = '', $Page = '') { // Setup head $Session = Gdn::Session(); $this->AddJsFile('jquery.autogrow.js'); $this->AddJsFile('options.js'); $this->AddJsFile('bookmark.js'); $this->AddJsFile('discussion.js'); $this->AddJsFile('autosave.js'); Gdn_Theme::Section('Discussion'); // Load the discussion record $DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0; if (!array_key_exists('Discussion', $this->Data)) { $this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE); } if (!is_object($this->Discussion)) { throw new Exception(sprintf(T('%s Not Found'), T('Discussion')), 404); } // Define the query offset & limit. $Limit = C('Vanilla.Comments.PerPage', 30); $OffsetProvided = $Page != ''; list($Offset, $Limit) = OffsetLimit($Page, $Limit); // Check permissions $this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->PermissionCategoryID); $this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE); $this->SetData('Breadcrumbs', CategoryModel::GetAncestors($this->CategoryID)); // Setup $this->Title($this->Discussion->Name); // Actual number of comments, excluding the discussion itself. $ActualResponses = $this->Discussion->CountComments; $this->Offset = $Offset; if (C('Vanilla.Comments.AutoOffset')) { // if ($this->Discussion->CountCommentWatch > 1 && $OffsetProvided == '') // $this->AddDefinition('ScrollTo', 'a[name=Item_'.$this->Discussion->CountCommentWatch.']'); 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; } $LatestItem = $this->Discussion->CountCommentWatch; if ($LatestItem === NULL) { $LatestItem = 0; } elseif ($LatestItem < $this->Discussion->CountComments) { $LatestItem += 1; } $this->SetData('_LatestItem', $LatestItem); // Set the canonical url to have the proper page title. $this->CanonicalUrl(DiscussionUrl($this->Discussion, PageNumber($this->Offset, $Limit, FALSE))); // Url(ConcatSep('/', 'discussion/'.$this->Discussion->DiscussionID.'/'. Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE, Gdn::Session()->UserID != 0)), TRUE), Gdn::Session()->UserID == 0); // Load the comments $this->SetData('Comments', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset)); $PageNumber = PageNumber($this->Offset, $Limit); $this->SetData('Page', $PageNumber); $this->_SetOpenGraph(); include_once PATH_LIBRARY . '/vendors/simplehtmldom/simple_html_dom.php'; if ($PageNumber == 1) { $this->Description(SliceParagraph(Gdn_Format::PlainText($this->Discussion->Body, $this->Discussion->Format), 160)); // Add images to head for open graph $Dom = str_get_html(Gdn_Format::To($this->Discussion->Body, $this->Discussion->Format)); } else { $this->Data['Title'] .= sprintf(T(' - Page %s'), PageNumber($this->Offset, $Limit)); $FirstComment = $this->Data('Comments')->FirstRow(); $FirstBody = GetValue('Body', $FirstComment); $FirstFormat = GetValue('Format', $FirstComment); $this->Description(SliceParagraph(Gdn_Format::PlainText($FirstBody, $FirstFormat), 160)); // Add images to head for open graph $Dom = str_get_html(Gdn_Format::To($FirstBody, $FirstFormat)); } if ($Dom) { foreach ($Dom->find('img') as $img) { if (isset($img->src)) { $this->Image($img->src); } } } // Make sure to set the user's discussion watch records $this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments); // 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($this->Offset, $Limit, $ActualResponses, array('DiscussionUrl')); $this->Pager->Record = $this->Discussion; PagerModule::Current($this->Pager); $this->FireEvent('AfterBuildPager'); // 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', ''); // Look in the session stash for a comment $StashComment = $Session->Stash('CommentForDiscussionID_' . $this->Discussion->DiscussionID, '', FALSE); if ($StashComment) { $this->Form->SetFormValue('Body', $StashComment); } // Retrieve & apply the draft if there is one: 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->IsPostBack()) { $this->Form->SetValue('Body', $Draft->Body); $this->Form->SetValue('Format', $Draft->Format); } } // 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'; } // Inform moderator of checked comments in this discussion $CheckedComments = $Session->GetAttribute('CheckedComments', array()); if (count($CheckedComments) > 0) { ModerationController::InformCheckedComments($this); } // Add modules $this->AddModule('DiscussionFilterModule'); $this->AddModule('NewDiscussionModule'); $this->AddModule('CategoriesModule'); $this->AddModule('BookmarkedModule'); $this->CanEditComments = Gdn::Session()->CheckPermission('Vanilla.Comments.Edit', TRUE, 'Category', 'any') && C('Vanilla.AdminCheckboxes.Use'); // Report the discussion id so js can use it. $this->AddDefinition('DiscussionID', $DiscussionID); $this->FireEvent('BeforeDiscussionRender'); $this->Render(); }
/** * Shows all uncleared messages within a conversation for the viewing user * * @since 2.0.0 * @access public * * @param int $ConversationID Unique ID of conversation to view. * @param int $Offset Number to skip. * @param int $Limit Number to show. */ public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '') { $this->Offset = $Offset; $Session = Gdn::Session(); Gdn_Theme::Section('Conversation'); // Figure out Conversation ID if (!is_numeric($ConversationID) || $ConversationID < 0) { $ConversationID = 0; } // Form setup for adding comments $this->Form->SetModel($this->ConversationMessageModel); $this->Form->AddHidden('ConversationID', $ConversationID); // Get conversation data $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID); $this->SetData('Recipients', $this->RecipientData); // Check permissions on the recipients. $InConversation = FALSE; foreach ($this->RecipientData->Result() as $Recipient) { if ($Recipient->UserID == Gdn::Session()->UserID) { $InConversation = TRUE; break; } } if (!$InConversation) { // Conversation moderation must be enabled and they must have permission if (!C('Conversations.Moderation.Allow', FALSE)) { throw PermissionException(); } $this->Permission('Conversations.Moderation.Manage'); } $this->Conversation = $this->ConversationModel->GetID($ConversationID); $this->SetData('Conversation', $this->Conversation); // Bad conversation? Redirect if ($this->Conversation === FALSE) { throw NotFoundException('Conversation'); } // Get limit if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) { $Limit = Gdn::Config('Conversations.Messages.PerPage', 50); } // Calculate counts if (!is_numeric($this->Offset) || $this->Offset < 0) { // Round down to the appropriate offset based on the user's read messages & messages per page $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages; if ($CountReadMessages < 0) { $CountReadMessages = 0; } if ($CountReadMessages > $this->Conversation->CountMessages) { $CountReadMessages = $this->Conversation->CountMessages; } // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60; $this->Offset = floor($CountReadMessages / $Limit) * $Limit; // Send the hash link in. if ($CountReadMessages > 1) { $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages); } } // Fetch message data $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit); // Figure out who's participating. $this->Participants = ''; $Count = 0; $Users = array(); $InConversation = FALSE; foreach ($this->RecipientData->Result() as $User) { $Count++; if ($User->UserID == $Session->UserID) { $InConversation = TRUE; continue; } if ($User->Deleted) { $Users[] = Wrap(UserAnchor($User), 'del', array('title' => sprintf(T('%s has left this conversation.'), htmlspecialchars($User->Name)))); $this->SetData('_HasDeletedUsers', TRUE); } else { $Users[] = UserAnchor($User); } } if ($InConversation) { if (count($Users) == 0) { $this->Participants = T('Just you!'); } else { $this->Participants = sprintf(T('%s and you'), implode(', ', $Users)); } } else { $this->Participants = implode(', ', $Users); } $this->Title(strip_tags($this->Participants)); // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'Newer Messages'; $this->Pager->LessCode = 'Older Messages'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/'); // Mark the conversation as ready by this user. $this->ConversationModel->MarkRead($ConversationID, $Session->UserID); // Deliver json data if necessary if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'messages'; } // Add modules. $ClearHistoryModule = new ClearHistoryModule($this); $ClearHistoryModule->ConversationID($ConversationID); $this->AddModule($ClearHistoryModule); $InThisConversationModule = new InThisConversationModule($this); $InThisConversationModule->SetData($this->RecipientData); $this->AddModule($InThisConversationModule); $this->AddModule('AddPeopleModule'); // Render view $this->Render(); }
public function Initialize() { parent::Initialize(); Gdn_Theme::Section('Dashboard'); }
/** * Display 'no permission' page. * * @since 2.0.0 * @access public */ public function Permission() { Gdn_Theme::Section('Error'); if ($this->DeliveryMethod() == DELIVERY_METHOD_XHTML) { safeHeader("HTTP/1.0 401", TRUE, 401); $this->Render(); } else { $this->RenderException(PermissionException()); } }