section() public static method

The current section the site is in. This can be one or more values. Think of it like a server-side css-class.
Since: 2.1
public static section ( string $Section, string $Method = 'add' )
$Section string The name of the section.
$Method string One of: add, remove, set, get.
Ejemplo n.º 1
0
 /**
  * Runs before every call to this controller.
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     set_time_limit(0);
     // Is this even doing anything?
 }
Ejemplo n.º 2
0
 /**
  * Set 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');
     }
 }
Ejemplo n.º 3
0
 /**
  * Runs before every call to this controller.
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
     $this->Model = new DBAModel();
     $this->Form = new Gdn_Form();
     $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();
 }
Ejemplo n.º 5
0
 /**
  * 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.form.js');
     $this->addJsFile('jquery.popup.js');
     $this->addJsFile('jquery.gardenhandleajaxform.js');
     $this->addJsFile('global.js');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     parent::initialize();
     Gdn_Theme::section('Entry');
 }
Ejemplo n.º 6
0
 /**
  * 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.form.js');
     $this->addJsFile('jquery.popup.js');
     $this->addJsFile('jquery.gardenhandleajaxform.js');
     $this->addJsFile('global.js');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     // Add Modules
     $this->addModule('GuestModule');
     $this->addModule('SignedInModule');
     parent::initialize();
     Gdn_Theme::section('ActivityList');
     $this->setData('Breadcrumbs', array(array('Name' => t('Activity'), 'Url' => '/activity')));
 }
 /**
  * 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();
 }
Ejemplo n.º 8
0
 /**
  * Settings screen placeholder
  *
  * @param mixed $Sender
  */
 public function Controller_Index($Sender)
 {
     Gdn_Theme::section('Moderation');
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title('Community Reporting');
     $Sender->AddCssFile('reporting.css', 'plugins/Reporting');
     // Check to see if the admin is toggling a feature
     $Feature = GetValue('1', $Sender->RequestArgs);
     $Command = GetValue('2', $Sender->RequestArgs);
     $TransientKey = Gdn::request()->get('TransientKey');
     if (Gdn::Session()->ValidateTransientKey($TransientKey)) {
         if (in_array($Feature, array('awesome', 'report'))) {
             SaveToConfig('Plugins.Reporting.' . ucfirst($Feature) . 'Enabled', $Command == 'disable' ? FALSE : TRUE);
             Redirect('plugin/reporting');
         }
     }
     $CategoryModel = new CategoryModel();
     $Sender->SetData('Plugins.Reporting.Data', array('ReportEnabled' => $this->ReportEnabled, 'AwesomeEnabled' => $this->AwesomeEnabled));
     $Sender->Render($this->GetView('settings.php'));
 }
Ejemplo n.º 9
0
 /**
  * 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->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->getByUser($Session->UserID, $Offset, $Limit);
     $CountDrafts = $this->DraftModel->getCountByUser($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();
 }
Ejemplo n.º 10
0
 /**
  * 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(htmlspecialchars(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);
     $this->setData('_CurrentRecords', count($ResultSet));
     $this->canonicalUrl(url('search', true));
     $this->render();
 }
Ejemplo n.º 11
0
 /**
  * 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('autosave.js');
     $this->addJsFile('post.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;
     $CategoryModel = new CategoryModel();
     if (isset($this->Discussion)) {
         $this->CategoryID = $this->Discussion->CategoryID;
         $Category = CategoryModel::categories($this->CategoryID);
     } elseif ($CategoryUrlCode != '') {
         $Category = CategoryModel::categories($CategoryUrlCode);
         if ($Category) {
             $this->CategoryID = val('CategoryID', $Category);
         }
     }
     if ($Category) {
         $this->Category = (object) $Category;
         $this->setData('Category', $Category);
         $this->Form->addHidden('CategoryID', $this->Category->CategoryID);
         if (val('DisplayAs', $this->Category) == 'Discussions' && !$DraftID) {
             $this->ShowCategorySelector = false;
         } else {
             // Get all our subcategories to add to the category if we are in a Header or Categories category.
             $this->Context = CategoryModel::getSubtree($this->CategoryID);
         }
     } else {
         $this->CategoryID = 0;
         $this->Category = null;
     }
     $CategoryData = $this->ShowCategorySelector ? CategoryModel::categories() : false;
     // Check permission
     if (isset($this->Discussion)) {
         // Make sure that content can (still) be edited.
         $CanEdit = DiscussionModel::canEdit($this->Discussion);
         if (!$CanEdit) {
             throw permissionException('Vanilla.Discussions.Edit');
         }
         // 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.
         if ($this->Category) {
             $this->permission('Vanilla.Discussions.Add', true, 'Category', $this->Category->PermissionCategoryID);
         } else {
             $this->permission('Vanilla.Discussions.Add');
         }
         $this->title(t('New Discussion'));
     }
     touchValue('Type', $this->Data, 'Discussion');
     // See if we should hide the category dropdown.
     if ($this->ShowCategorySelector) {
         $AllowedCategories = CategoryModel::getByPermission('Discussions.Add', $this->Form->getValue('CategoryID', $this->CategoryID), ['Archived' => 0, 'AllowDiscussions' => 1], ['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()) {
         // 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);
         }
     } elseif ($this->Form->authenticatedPostBack()) {
         // Form was submitted
         // Save as a draft?
         $FormValues = $this->Form->formValues();
         $FormValues = $this->DiscussionModel->filterForm($FormValues);
         $this->deliveryType(Gdn::request()->getValue('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 = val($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');
                 }
             }
             $isTitleValid = true;
             $Name = trim($this->Form->getFormValue('Name', ''));
             if (!$Draft) {
                 // Let's be super aggressive and disallow titles with no word characters in them!
                 $hasWordCharacter = preg_match('/\\w/u', $Name) === 1;
                 if (!$hasWordCharacter || $Name != '' && Gdn_Format::text($Name) == '') {
                     $this->Form->addError(t('You have entered an invalid discussion title'), 'Name');
                     $isTitleValid = false;
                 }
             }
             if ($isTitleValid) {
                 // 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->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.');
                         // Clear out the form so that a draft won't save.
                         $this->Form->formValues(array());
                         $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 = val('Body', $FormValues, '');
             $this->Comment->Format = val('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());
         } elseif ($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, 1)) . '?new=1';
                     } else {
                         $this->RedirectUrl = discussionUrl($Discussion, 1, 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' => val('AddUrl', val($this->data('Type'), DiscussionModel::discussionTypes()), '/post/discussion'));
     $this->setData('Breadcrumbs', $Breadcrumbs);
     $this->setData('_AnnounceOptions', $this->announceOptions());
     // Render view (posts/discussion.php or post/preview.php)
     $this->render();
 }
Ejemplo n.º 12
0
 /**
  * Show applicants queue.
  *
  * @since 2.0.0
  * @access public
  */
 public function applicants()
 {
     $this->permission('Garden.Users.Approve');
     $this->setHighlightRoute('dashboard/user/applicants');
     $this->addJsFile('applicants.js');
     $this->title(t('Applicants'));
     $this->fireEvent('BeforeApplicants');
     $UserModel = Gdn::userModel();
     $this->UserData = $UserModel->getApplicants();
     Gdn_Theme::section('Moderation');
     $this->render();
 }
Ejemplo n.º 13
0
 /**
  * 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->Form->InputPrefix = '';
 }
Ejemplo n.º 14
0
 /**
  *
  *
  * @param PluginController $Sender
  * @throws Exception
  */
 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);
 }
Ejemplo n.º 15
0
 /**
  * Load discussions for a specific tag.
  * @param DiscussionsController $Sender
  */
 public function discussionsController_Tagged_create($Sender)
 {
     Gdn_Theme::section('DiscussionList');
     $Args = $Sender->RequestArgs;
     $Get = array_change_key_case($Sender->Request->get());
     if ($UseCategories = c('Plugins.Tagging.UseCategories')) {
         // The url is in the form /category/tag/p1
         $CategoryCode = val(0, $Args);
         $Tag = val(1, $Args);
         $Page = val(2, $Args);
     } else {
         // The url is in the form /tag/p1
         $CategoryCode = '';
         $Tag = val(0, $Args);
         $Page = val(1, $Args);
     }
     // Look for explcit values.
     $CategoryCode = val('category', $Get, $CategoryCode);
     $Tag = val('tag', $Get, $Tag);
     $Page = val('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'] == val('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'] != val('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');
 }
Ejemplo n.º 16
0
 /**
  * Fire before every page render.
  *
  * @param Gdn_Controller $Sender
  */
 public function base_render_before($Sender)
 {
     $Session = Gdn::session();
     if ($Sender->MasterView == 'admin') {
         if (val('Form', $Sender)) {
             $Sender->Form->setStyles('bootstrap');
         }
         $Sender->CssClass = htmlspecialchars($Sender->CssClass);
         $Sections = Gdn_Theme::section(null, 'get');
         if (is_array($Sections)) {
             foreach ($Sections as $Section) {
                 $Sender->CssClass .= ' Section-' . $Section;
             }
         }
         // Get our plugin nav items.
         $navAdapter = new NestedCollectionAdapter(DashboardNavModule::getDashboardNav());
         $Sender->EventArguments['SideMenu'] = $navAdapter;
         $Sender->fireEvent('GetAppSettingsMenuItems');
         $Sender->removeJsFile('jquery.popup.js');
         $Sender->addJsFile('vendors/jquery.checkall.min.js', 'dashboard');
         $Sender->addJsFile('dashboard.js', 'dashboard');
         $Sender->addJsFile('jquery.expander.js');
         $Sender->addJsFile('settings.js', 'dashboard');
         $Sender->addJsFile('vendors/tether.min.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/util.js', 'dashboard');
         $Sender->addJsFile('vendors/drop.min.js', 'dashboard');
         $Sender->addJsFile('vendors/moment.min.js', 'dashboard');
         $Sender->addJsFile('vendors/daterangepicker.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/tooltip.js', 'dashboard');
         $Sender->addJsFile('vendors/clipboard.min.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/dropdown.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/collapse.js', 'dashboard');
         $Sender->addJsFile('vendors/bootstrap/modal.js', 'dashboard');
         $Sender->addJsFile('vendors/icheck.min.js', 'dashboard');
         $Sender->addJsFile('jquery.tablejenga.js', 'dashboard');
         $Sender->addJsFile('jquery.fluidfixed.js', 'dashboard');
         $Sender->addJsFile('vendors/prettify/prettify.js', 'dashboard');
         $Sender->addJsFile('vendors/ace/ace.js', 'dashboard');
         $Sender->addJsFile('vendors/ace/ext-searchbox.js', 'dashboard');
         $Sender->addCssFile('vendors/tomorrow.css', 'dashboard');
     }
     // Check the statistics.
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         Gdn::statistics()->check();
     }
     // Inform user of theme previewing
     if ($Session->isValid()) {
         $PreviewThemeFolder = htmlspecialchars($Session->getPreference('PreviewThemeFolder', ''));
         $PreviewMobileThemeFolder = htmlspecialchars($Session->getPreference('PreviewMobileThemeFolder', ''));
         $PreviewThemeName = htmlspecialchars($Session->getPreference('PreviewThemeName', $PreviewThemeFolder));
         $PreviewMobileThemeName = htmlspecialchars($Session->getPreference('PreviewMobileThemeName', $PreviewMobileThemeFolder));
         if ($PreviewThemeFolder != '') {
             $Sender->informMessage(sprintf(t('You are previewing the %s desktop theme.'), wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/themes/' . $PreviewThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/' . $PreviewThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
         if ($PreviewMobileThemeFolder != '') {
             $Sender->informMessage(sprintf(t('You are previewing the %s mobile theme.'), wrap($PreviewMobileThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/mobilethemes/' . $PreviewMobileThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/' . $PreviewMobileThemeFolder . '/' . $Session->transientKey(), 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
         }
     }
     if ($Session->isValid()) {
         $Confirmed = val('Confirmed', Gdn::session()->User, true);
         if (UserModel::requireConfirmEmail() && !$Confirmed) {
             $Message = formatString(t('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
             $Sender->informMessage($Message, '');
         }
     }
     // Add Message Modules (if necessary)
     $MessageCache = Gdn::config('Garden.Messages.Cache', array());
     $Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
     $Exceptions = array('[Base]');
     if (in_array($Sender->MasterView, array('', 'default'))) {
         $Exceptions[] = '[NonAdmin]';
     }
     // SignIn popup is a special case
     $SignInOnly = $Sender->deliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
     if ($SignInOnly) {
         $Exceptions = array();
     }
     if ($Sender->MasterView != 'admin' && !$Sender->data('_NoMessages') && (val('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, false) || InArrayI($Location, $MessageCache))) {
         $MessageModel = new MessageModel();
         $MessageData = $MessageModel->getMessagesForLocation($Location, $Exceptions, $Sender->data('Category.CategoryID'));
         foreach ($MessageData as $Message) {
             $MessageModule = new MessageModule($Sender, $Message);
             if ($SignInOnly) {
                 // Insert special messages even in SignIn popup
                 echo $MessageModule;
             } elseif ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
                 $Sender->addModule($MessageModule);
             }
         }
         $Sender->MessagesLoaded = '1';
         // Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
     }
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         $Gdn_Statistics = Gdn::factory('Statistics');
         $Gdn_Statistics->check($Sender);
     }
     // Allow forum embedding
     if ($Embed = c('Garden.Embed.Allow')) {
         // Record the remote url where the forum is being embedded.
         $RemoteUrl = c('Garden.Embed.RemoteUrl');
         if (!$RemoteUrl) {
             $RemoteUrl = GetIncomingValue('remote');
             if ($RemoteUrl) {
                 saveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
             }
         }
         if ($RemoteUrl) {
             $Sender->addDefinition('RemoteUrl', $RemoteUrl);
         }
         if ($remoteUrlFormat = c('Garden.Embed.RemoteUrlFormat')) {
             $Sender->addDefinition('RemoteUrlFormat', $remoteUrlFormat);
         }
         // Force embedding?
         if (!IsSearchEngine() && strtolower($Sender->ControllerName) != 'entry') {
             if (IsMobile()) {
                 $forceEmbedForum = c('Garden.Embed.ForceMobile') ? '1' : '0';
             } else {
                 $forceEmbedForum = c('Garden.Embed.ForceForum') ? '1' : '0';
             }
             $Sender->addDefinition('ForceEmbedForum', $forceEmbedForum);
             $Sender->addDefinition('ForceEmbedDashboard', c('Garden.Embed.ForceDashboard') ? '1' : '0');
         }
         $Sender->addDefinition('Path', Gdn::request()->path());
         $get = Gdn::request()->get();
         unset($get['p']);
         // kludge for old index.php?p=/path
         $Sender->addDefinition('Query', http_build_query($get));
         // $Sender->addDefinition('MasterView', $Sender->MasterView);
         $Sender->addDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
         if ($Embed === 2) {
             $Sender->addJsFile('vanilla.embed.local.js');
         } else {
             $Sender->addJsFile('embed_local.js');
         }
     } else {
         $Sender->setHeader('X-Frame-Options', 'SAMEORIGIN');
     }
     // Allow return to mobile site
     $ForceNoMobile = val('X-UA-Device-Force', $_COOKIE);
     if ($ForceNoMobile === 'desktop') {
         $Sender->addAsset('Foot', wrap(Anchor(t('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
     }
     // Allow global translation of TagHint
     $Sender->addDefinition("TagHint", t("TagHint", "Start to type..."));
     // Add symbols.
     if ($Sender->deliveryMethod() === DELIVERY_METHOD_XHTML) {
         $Sender->addAsset('Symbols', $Sender->fetchView('symbols', '', 'Dashboard'));
     }
 }
Ejemplo n.º 17
0
 /**
  * Display 'no permission' page.
  *
  * @since 2.0.0
  * @access public
  */
 public function unauthorized()
 {
     Gdn_Theme::section('Error');
     if ($this->deliveryMethod() == DELIVERY_METHOD_XHTML) {
         safeHeader("HTTP/1.0 401", true, 401);
         $this->render();
     } else {
         $this->RenderException(permissionException());
     }
 }
Ejemplo n.º 18
0
 /**
  * View spam logs.
  *
  * @since 2.0.?
  * @access public
  *
  * @param int $Page Page number.
  */
 public function spam($Page = '')
 {
     $this->permission(array('Garden.Moderation.Manage', 'Moderation.Spam.Manage'), false);
     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';
     }
     Gdn_Theme::section('Moderation');
     $this->setHighlightRoute('dashboard/log/spam');
     $this->render();
 }
 /**
  * Show all categories and few discussions from each.
  *
  * @param string $Category The url code of the parent category.
  * @since 2.0.0
  * @access public
  */
 public function discussions($Category = '')
 {
     // Setup head
     $this->addJsFile('discussions.js');
     $this->Menu->highlightRoute('/discussions');
     if (!$this->title()) {
         $Title = c('Garden.HomepageTitle');
         if ($Title) {
             $this->title($Title, '');
         } else {
             $this->title(t('All Categories'));
         }
     }
     if (!$Category) {
         $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();
     $this->CategoryModel->Watching = !Gdn::session()->GetPreference('ShowAllCategories');
     if ($Category) {
         $Subtree = CategoryModel::GetSubtree($Category, false);
         $CategoryIDs = consolidateArrayValuesByKey($Subtree, 'CategoryID');
         $Categories = $this->CategoryModel->GetFull($CategoryIDs)->resultArray();
     } else {
         $Categories = $this->CategoryModel->GetFull()->resultArray();
     }
     $this->setData('Categories', $Categories);
     // Get category data and discussions
     $this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5);
     $DiscussionModel = new DiscussionModel();
     $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));
     $Path = $this->fetchViewLocation('helper_functions', 'discussions', false, false);
     if ($Path) {
         include_once $Path;
     }
     // For GetOptions function
     $Path2 = $this->fetchViewLocation('helper_functions', 'categories', false, false);
     if ($Path2) {
         include_once $Path2;
     }
     $this->render();
 }
Ejemplo n.º 20
0
 /**
  *
  *
  * @param string $Tutorial
  */
 public function tutorials($Tutorial = '')
 {
     $this->permission('Garden.Settings.Manage');
     $this->setData('Title', t('Help &amp; Tutorials'));
     $this->setHighlightRoute('dashboard/settings/tutorials');
     $this->setData('CurrentTutorial', $Tutorial);
     Gdn_Theme::section('Tutorials');
     $this->setData('IsWidePage', true);
     $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.autosize.min.js');
        $this->addJsFile('discussion.js');
        $this->removeJsFile('autosave.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);
        } elseif ($vanilla_identifier != '' && $vanilla_type != '') {
            $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
        }
        // Set discussion data if we have one for this page
        if ($Discussion) {
            // Allow Vanilla.Comments.View to be defined to limit access to embedded comments only.
            // Otherwise, go with normal discussion view permissions. Either will do.
            $this->permission(array('Vanilla.Discussions.View', 'Vanilla.Comments.View'), false, '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;
                }
            } elseif ($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('/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()->getPublicStash('CommentForForeignID_' . $ForeignSource['vanilla_identifier']);
            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();
    }
Ejemplo n.º 22
0
 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');
     }
 }
Ejemplo n.º 23
0
 /**
  * @return bool
  * @throws Exception
  */
 public function prepare()
 {
     if (!self::$initStaticFired) {
         self::$initStaticFired = true;
         $this->fireEvent('init');
     }
     if (empty($this->currentSections)) {
         $currentSections = Gdn_Theme::section('', 'get');
         $currentSections = array_map('strtolower', $currentSections);
         $customMenuKeys = array_intersect(array_keys(self::$sectionItems), $currentSections);
         $hasCustomMenu = !empty($customMenuKeys);
         if (!$hasCustomMenu) {
             $currentSections = [self::SECTION_DEFAULT];
         }
         // Add global items
         $currentSections[] = self::SECTION_GLOBAL;
     } else {
         $currentSections = array_map('strtolower', $this->currentSections);
     }
     foreach ($currentSections as $currentSection) {
         if ($section = val(strtolower($currentSection), self::$sectionItems)) {
             $this->addSectionItems($section);
         }
     }
     return parent::prepare();
 }
Ejemplo n.º 24
0
 /**
  *
  *
  * @param $Path
  * @param $Controller
  */
 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) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!IsUrl($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 = val('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;
     // Set the current locale for themes to take advantage of.
     $Locale = Gdn::locale()->Locale;
     $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', $Locale));
     if (class_exists('Locale')) {
         $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
         $CurrentLocale['Region'] = Locale::getRegion($Locale);
         $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
         $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
         $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
     }
     $Smarty->assign('CurrentLocale', $CurrentLocale);
     $Smarty->assign('Assets', (array) $Controller->Assets);
     $Smarty->assign('Path', Gdn::request()->path());
     // Assign 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('Category', 'CheckPermission', 'InSection', 'InCategory', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url'));
     $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf'));
     $Smarty->secure_dir = array($Path);
 }
Ejemplo n.º 25
0
 /**
  * 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('jquery.autosize.min.js');
     $this->addJsFile('global.js');
     if (in_array($this->ControllerName, array('profilecontroller', 'activitycontroller'))) {
         $this->addCssFile('style.css');
         $this->addCssFile('vanillicon.css', 'static');
     } else {
         $this->addCssFile('admin.css');
     }
     // Change master template
     $this->MasterView = 'admin';
     parent::initialize();
     Gdn_Theme::section('Dashboard');
 }
Ejemplo n.º 26
0
 /**
  *
  *
  * @param string $Path
  * @param Gdn_Controller $Controller
  */
 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', htmlspecialchars($BodyIdentifier));
     //$Smarty->assign('Config', Gdn::Config());
     // Assign some information about the user.
     $Session = Gdn::session();
     if ($Session->isValid()) {
         $User = array('Name' => htmlspecialchars($Session->User->Name), 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!isUrl($Photo)) {
                 $Photo = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
             }
         } else {
             $Photo = UserModel::getDefaultAvatarUrl($Session->User);
         }
         $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 = val('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;
     // Set the current locale for themes to take advantage of.
     $Locale = Gdn::locale()->Locale;
     $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', Gdn::locale()->language(true)));
     if (class_exists('Locale')) {
         $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
         $CurrentLocale['Region'] = Locale::getRegion($Locale);
         $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
         $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
         $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
     }
     $Smarty->assign('CurrentLocale', $CurrentLocale);
     $Smarty->assign('Assets', (array) $Controller->Assets);
     // 2016-07-07 Linc: Request used to return blank for homepage.
     // Now it returns defaultcontroller. This restores BC behavior.
     $isHomepage = val('isHomepage', $Controller->Data);
     $Path = $isHomepage ? "" : Gdn::request()->path();
     $Smarty->assign('Path', $Path);
     $Smarty->assign('Homepage', $isHomepage);
     // true/false
     // Assign the controller data last so the controllers override any default data.
     $Smarty->assign($Controller->Data);
     $security = new SmartySecurityVanilla($Smarty);
     $security->php_handling = Smarty::PHP_REMOVE;
     $security->allow_constants = false;
     $security->allow_super_globals = false;
     $security->streams = null;
     $security->setPhpFunctions(array_merge($security->php_functions, ['array', 'category', 'checkPermission', 'inSection', 'inCategory', 'ismobile', 'multiCheckPermission', 'getValue', 'setValue', 'url', 'useragenttype']));
     $security->php_modifiers = array_merge($security->php_functions, array('sprintf'));
     $Smarty->enableSecurity($security);
 }
Ejemplo n.º 27
0
 /**
  * Get flagged content & show settings.
  *
  * Default method of virtual Flagging controller.
  */
 public function controller_index($Sender)
 {
     $Sender->addCssFile('admin.css');
     $Sender->addCssFile($this->getResource('design/flagging.css', false, false));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->setField(array('Plugins.Flagging.UseDiscussions', 'Plugins.Flagging.CategoryID'));
     // Set the model on the form.
     $Sender->Form->setModel($ConfigurationModel);
     // If seeing the form for the first time...
     if ($Sender->Form->authenticatedPostBack() === false) {
         // Apply the config settings to the form.
         $Sender->Form->setData($ConfigurationModel->Data);
     } else {
         $Saved = $Sender->Form->save();
         if ($Saved) {
             $Sender->informMessage(t("Your changes have been saved."));
         }
     }
     $FlaggedItems = Gdn::sql()->select('*')->from('Flag fl')->orderBy('DateInserted', 'DESC')->get();
     $Sender->FlaggedItems = array();
     while ($Flagged = $FlaggedItems->nextRow(DATASET_TYPE_ARRAY)) {
         $URL = $Flagged['ForeignURL'];
         $Index = $Flagged['DateInserted'] . '-' . $Flagged['InsertUserID'];
         $Flagged['EncodedURL'] = str_replace('=', '-', base64_encode($Flagged['ForeignURL']));
         $Sender->FlaggedItems[$URL][$Index] = $Flagged;
     }
     unset($FlaggedItems);
     Gdn_Theme::section('Moderation');
     $Sender->render($this->getView('flagging.php'));
 }
 /**
  * Endpoint for the PromotedContentModule's data.
  *
  * Parameters & values must be lowercase and via GET.
  *
  * @see PromotedContentModule
  */
 public function promoted()
 {
     // Create module & set data.
     $PromotedModule = new PromotedContentModule();
     $Status = $PromotedModule->Load(Gdn::request()->get());
     if ($Status === true) {
         // Good parameters.
         $PromotedModule->GetData();
         $this->setData('Content', $PromotedModule->data('Content'));
         $this->setData('Title', t('Promoted Content'));
         $this->setData('View', c('Vanilla.Discussions.Layout'));
         $this->setData('EmptyMessage', t('No discussions were found.'));
         // Pass display properties to the view.
         $this->Group = $PromotedModule->Group;
         $this->TitleLimit = $PromotedModule->TitleLimit;
         $this->BodyLimit = $PromotedModule->BodyLimit;
     } else {
         $this->setData('Errors', $Status);
     }
     $this->deliveryMethod();
     Gdn_Theme::section('PromotedContent');
     $this->render('promoted', 'modules', 'vanilla');
 }
Ejemplo n.º 29
0
 /**
  * Run before
  */
 public function initialize()
 {
     parent::initialize();
     Gdn_Theme::section('Dashboard');
 }
Ejemplo n.º 30
0
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function index($ConversationID = false, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::session();
     Gdn_Theme::section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->setModel($this->ConversationMessageModel);
     $this->Form->addHidden('ConversationID', $ConversationID);
     // 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);
     $this->EventArguments['MessageData'] = $this->MessageData;
     $this->fireEvent('beforeMessages');
     $this->setData('Messages', $this->MessageData);
     // 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' => url('', '//'));
     // Render view
     $this->render();
 }