A base class that all controllers can inherit for common properties and methods.
Inheritance: extends Gdn_Pluggable
 /**
  * Grabs all new notifications and adds them to the sender's inform queue.
  *
  * This method gets called by dashboard's hooks file to display new
  * notifications on every pageload.
  *
  * @since 2.0.18
  * @access public
  *
  * @param Gdn_Controller $Sender The object calling this method.
  */
 public static function informNotifications($Sender)
 {
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         return;
     }
     $ActivityModel = new ActivityModel();
     // Get five pending notifications.
     $Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
     // If we're in the middle of a visit only get very recent notifications.
     $Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
     $Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray();
     $ActivityIDs = array_column($Activities, 'ActivityID');
     $ActivityModel->setNotified($ActivityIDs);
     $Sender->EventArguments['Activities'] =& $Activities;
     $Sender->fireEvent('InformNotifications');
     foreach ($Activities as $Activity) {
         if ($Activity['Photo']) {
             $UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
         } else {
             $UserPhoto = '';
         }
         $Excerpt = Gdn_Format::plainText($Activity['Story']);
         $ActivityClass = ' Activity-' . $Activity['ActivityType'];
         $Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
     }
 }
 /**
  * Add Timeago to all controllers
  *
  * @since  2.0.0
  * @access public
  * @param  Gdn_Controller $sender
  */
 public function base_render_before($sender)
 {
     // Plugin definitions for use in Javascript
     $definitions = array('locale' => array('prefixAgo' => t('timeago.prefixAgo', null), 'prefixFromNow' => t('timeago.prefixFromNow', null), 'suffixAgo' => t('timeago.suffixAgo', 'ago'), 'suffixFromNow' => t('timeago.suffixFromNow', 'from now'), 'seconds' => t('timeago.seconds', 'less than a minute'), 'minute' => t('timeago.minute', 'about a minute'), 'minutes' => t('timeago.minutes', '%d minutes'), 'hour' => t('timeago.hour', 'about an hour'), 'hours' => t('timeago.hours', 'about %d hours'), 'day' => t('timeago.day', 'a day'), 'days' => t('timeago.days', '%d days'), 'month' => t('timeago.month', 'about a month'), 'months' => t('timeago.months', '%d months'), 'year' => t('timeago.year', 'about a year'), 'years' => t('timeago.years', '%d years'), 'wordSeparator' => t('timeago.wordSeparator', ' '), 'numbers' => array()));
     $sender->addDefinition('Timeago', json_encode($definitions));
     // Add required assets
     $sender->addJsFile('timeago.min.js', 'plugins/timeago');
 }
 /**
  * Attach button bar in place
  * 
  * This method is abstracted because it is called from multiple places, due
  * to the way that the comment.php view is invoked both by the DiscussionController
  * and the PostController.
  * 
  * @param Gdn_Controller $Sender 
  */
 protected function AttachButtonBar($Sender, $Wrap = FALSE)
 {
     $View = $Sender->FetchView('buttonbar', '', 'plugins/ButtonBar');
     if ($Wrap) {
         echo Wrap($View, 'div', array('class' => 'P'));
     } else {
         echo $View;
     }
 }
Esempio n. 4
0
 /**
  * Wrapper for captcha rendering.
  *
  * Allows conditional ignoring of captcha rendering if skipped in the config.
  *
  * @param Gdn_Controller $controller
  * @return null;
  */
 public static function render($controller)
 {
     if (!Captcha::enabled()) {
         return null;
     }
     // Hook to allow rendering of captcha form
     $controller->fireAs('captcha')->fireEvent('render');
     return null;
 }
 /**
  * The settings page for vanillicon.
  *
  * @param Gdn_Controller $sender
  */
 public function settingsController_vanillicon_create($sender)
 {
     $sender->permission('Garden.Settings.Manage');
     $cf = new ConfigurationModule($sender);
     $items = array('v1' => 'Vanillicon 1', 'v2' => 'Vanillicon 2');
     $cf->initialize(array('Plugins.Vanillicon.Type' => array('LabelCode' => 'Vanillicon Set', 'Control' => 'radiolist', 'Description' => 'Which vanillicon set do you want to use?', 'Items' => $items, 'Options' => array('display' => 'after'), 'Default' => 'v1')));
     $sender->setData('Title', sprintf(t('%s Settings'), 'Vanillicon'));
     $cf->renderAll();
 }
 /**
  *
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function SettingsController_Render_Before($Sender, $Args)
 {
     if (strcasecmp($Sender->RequestMethod, 'locales') != 0) {
         return;
     }
     // Add a little pointer to the settings.
     $Text = '<div class="Info">' . sprintf(T('Locale Developer Settings %s.'), Anchor(T('here'), '/dashboard/settings/localedeveloper')) . '</div>';
     $Sender->AddAsset('Content', $Text, 'LocaleDeveloperLink');
 }
 /**
  * Add the rtl stylesheets to the page.
  *
  * The rtl stylesheets should always be added separately so that they aren't combined with other stylesheets when
  * a non-rtl language is still being displayed.
  *
  * @param Gdn_Controller $Sender
  */
 public function Base_Render_Before(&$Sender)
 {
     $currentLocale = substr(Gdn::Locale()->Current(), 0, 2);
     if (in_array($currentLocale, $this->rtlLocales)) {
         if (InSection('Dashboard')) {
             $Sender->AddCssFile('admin_rtl.css', 'plugins/RightToLeft');
         } else {
             $Sender->AddCssFile('style_rtl.css', 'plugins/RightToLeft');
         }
         $Sender->CssClass .= ' rtl';
     }
 }
 /**
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 public function EntryController_Render_Before($Sender, $Args)
 {
     if ($Sender->RequestMethod != 'passwordreset') {
         return;
     }
     if (isset($Sender->Data['User'])) {
         // Get all of the users with the same email.
         $Email = $Sender->Data('User.Email');
         $Users = Gdn::SQL()->Select('Name')->From('User')->Where('Email', $Email)->Get()->ResultArray();
         $Names = array_column($Users, 'Name');
         SetValue('Name', $Sender->Data['User'], implode(', ', $Names));
     }
 }
 public function FetchViewLocation($View = '', $ControllerName = FALSE, $ApplicationFolder = FALSE, $ThrowError = TRUE)
 {
     if (!$ControllerName) {
         $ControllerName = '';
     }
     return parent::FetchViewLocation($View, $ControllerName, $ApplicationFolder, $ThrowError);
 }
Esempio n. 10
0
 /**
  * Get the file location of a view.
  *
  * @param string $view
  * @param bool $controllerName
  * @param bool $applicationFolder
  * @param bool $throwError
  * @param bool $useController
  * @return bool|mixed
  * @throws Exception
  */
 public function fetchViewLocation($view = '', $controllerName = false, $applicationFolder = false, $throwError = true, $useController = true)
 {
     if (!$controllerName) {
         $controllerName = '';
     }
     return parent::fetchViewLocation($view, $controllerName, $applicationFolder, $throwError, $useController);
 }
Esempio n. 11
0
 public function Initialize()
 {
     if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
         $this->Head = new HeadModule($this);
     }
     parent::Initialize();
 }
Esempio n. 12
0
 /**
  * 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.form.js');
     $this->addJsFile('jquery.popup.js');
     $this->addJsFile('jquery.gardenhandleajaxform.js');
     $this->addJsFile('jquery.autosize.min.js');
     $this->addJsFile('global.js');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     $this->addModule('GuestModule');
     parent::initialize();
     Gdn_Theme::section('Profile');
     if ($this->EditMode) {
         $this->CssClass .= 'EditMode';
     }
     /**
      * The default Cache-Control header does not include no-store, which can cause issues with outdated session
      * information (e.g. message button missing). The same check is performed here as in Gdn_Controller before the
      * Cache-Control header is added, but this value includes the no-store specifier.
      */
     if (Gdn::session()->isValid()) {
         $this->setHeader('Cache-Control', 'private, no-cache, no-store, max-age=0, must-revalidate');
     }
     $this->setData('Breadcrumbs', array());
     $this->CanEditPhotos = Gdn::session()->checkRankedPermission(c('Garden.Profile.EditPhotos', true)) || Gdn::session()->checkPermission('Garden.Users.Edit');
 }
Esempio n. 13
0
 /**
  * Get the file location of a view.
  *
  * @param string $View
  * @param bool $ControllerName
  * @param bool $ApplicationFolder
  * @param bool $ThrowError
  * @return bool|mixed
  * @throws Exception
  */
 public function fetchViewLocation($View = '', $ControllerName = false, $ApplicationFolder = false, $ThrowError = true)
 {
     if (!$ControllerName) {
         $ControllerName = '';
     }
     return parent::fetchViewLocation($View, $ControllerName, $ApplicationFolder, $ThrowError);
 }
 public function Initialize()
 {
     parent::Initialize();
     $this->_DeliveryMethod = DELIVERY_METHOD_JSON;
     //$this->SetHeader("Content-Type", "application/json; charset=utf-8");
     $this->SetHeader("Content-Type", "text/plain; charset=utf-8");
     $this->MasterView = 'json';
 }
 /**
  * All requests to this controller must be made via JS.
  *
  * @throws PermissionException
  */
 public function Initialize()
 {
     parent::Initialize();
     $this->Application = 'Yaga';
     if (!$this->Request->IsPostBack()) {
         throw PermissionException('Javascript');
     }
 }
Esempio n. 16
0
 /**
  * Before every controller method call.
  */
 public function initialize()
 {
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->Head = new HeadModule($this);
     }
     $this->addCssFile('style.css');
     parent::initialize();
 }
Esempio n. 17
0
 /**
  * Insert buttonbar resources
  *
  * This method is abstracted because it is invoked by multiple controllers.
  *
  * @param Gdn_Controller $Sender
  */
 protected function attachButtonBarResources($Sender, $Formatter)
 {
     if (!in_array($Formatter, $this->Formats)) {
         return;
     }
     $Sender->addJsFile('buttonbar.js', 'plugins/ButtonBar');
     $Sender->addJsFile('jquery.hotkeys.js', 'plugins/ButtonBar');
     $Sender->addDefinition('ButtonBarLinkUrl', t('ButtonBar.LinkUrlText', 'Enter your URL:'));
     $Sender->addDefinition('ButtonBarImageUrl', t('ButtonBar.ImageUrlText', 'Enter image URL:'));
     $Sender->addDefinition('ButtonBarBBCodeHelpText', t('ButtonBar.BBCodeHelp', 'You can use <b><a href="http://en.wikipedia.org/wiki/BBCode" target="_new">BBCode</a></b> in your post.'));
     $Sender->addDefinition('ButtonBarHtmlHelpText', t('ButtonBar.HtmlHelp', 'You can use <b><a href="http://htmlguide.drgrog.com/cheatsheet.php" target="_new">Simple Html</a></b> in your post.'));
     $Sender->addDefinition('ButtonBarMarkdownHelpText', t('ButtonBar.MarkdownHelp', 'You can use <b><a href="http://en.wikipedia.org/wiki/Markdown" target="_new">Markdown</a></b> in your post.'));
     $Sender->addDefinition('InputFormat', $Formatter);
 }
 /**
  * This is a good place to include JS, CSS, and modules used by all methods of this controller.
  *
  * Always called by dispatcher before controller's requested method.
  * 
  * @since 1.0
  * @access public
  */
 public function Initialize() {
    // There are 4 delivery types used by Render().
    // DELIVERY_TYPE_ALL is the default and indicates an entire page view.
    if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
       $this->Head = new HeadModule($this);
       
    // Call Gdn_Controller's Initialize() as well.
    parent::Initialize();
 }
Esempio n. 19
0
 /**
  * Do this before anything else.
  */
 public function initialize()
 {
     parent::initialize();
     if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
         $this->Head = new HeadModule($this);
     }
     $this->addCssFile('style.css');
     $this->addCssFile('addons.css');
     $this->CountCommentsPerPage = c('Vanilla.Comments.PerPage', 30);
 }
Esempio n. 20
0
 public function Error()
 {
     $this->RemoveCssFile('admin.css');
     $this->AddCssFile('style.css');
     $this->MasterView = 'default';
     $this->CssClass = 'SplashMessage NoPanel';
     $this->SetData('_NoMessages', TRUE);
     $Code = $this->Data('Code', 400);
     header("HTTP/1.0 {$Code} " . Gdn_Controller::GetStatusMessage($Code), TRUE, $Code);
     $this->Render();
 }
 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');
    $this->AddModule('GuestModule');
    parent::Initialize();
 }   
Esempio n. 22
0
 /**
  * Before all method calls.
  */
 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('admin.css');
     $this->MasterView = 'admin';
     parent::initialize();
 }
 /**
  * Webhook for Teamwork.
  *
  * POST data looks like this:
  * [  'event' => 'TASK.COMPLETED',
  *    'objectId' => '000',
  *    'accountId' => '000',
  *    'userId' => '000',
  * ]
  *
  * @see http://developer.teamwork.com/todolistitems
  *
  * @param Gdn_Controller $sender
  * @param $secret
  * @throws Exception
  */
 public function utilityController_teamworkTaskCompleted_create($sender, $secret)
 {
     if ($secret != c('SprintNotifier.Teamwork.Secret')) {
         throw new Exception('Invalid token.');
     }
     // Get data
     $data = Gdn::request()->post();
     // Sanity check we set up webhooks right.
     if (val('event', $data) != 'TASK.COMPLETED') {
         return;
     }
     // Cheat by storing some data in the config.
     $users = c('SprintNotifier.Teamwork.Users', []);
     $projects = c('SprintNotifier.Teamwork.Projects', []);
     // Get full task data via Teamwork's *ahem* "API".
     $task = self::teamworkTask(val('objectId', $data));
     // DEBUG
     UserModel::setMeta(0, array('TaskAPI' => var_export($task, true)), 'SprintNotifier.Debug.');
     // Respect project whitelist if we're using one.
     if (count($projects) && !in_array($task['project-name'], $projects)) {
         return;
     }
     // Build data for the chat message.
     $teamworkUserID = val('userId', $data);
     $userName = val($teamworkUserID, $users, 'User ' . val('userId', $data));
     $taskUrl = sprintf('https://%1$s.teamwork.com/tasks/%2$s', c('Teamwork.Account'), val('objectId', $data));
     $message = sprintf('%1$s completed %2$s task: <a href="%3$s">%4$s</a>', $userName, strtolower($task['project-name']), $taskUrl, $task['content']);
     // Override HipChat plugin's default token & room.
     saveToConfig('HipChat.Room', c('SprintNotifier.HipChat.RoomID'), false);
     saveToConfig('HipChat.Token', c('SprintNotifier.HipChat.Token'), false);
     // DEBUG
     UserModel::setMeta(0, array('Message' => var_export($message, true)), 'SprintNotifier.Debug.');
     // Say it! Bust it!
     if (class_exists('HipChat')) {
         HipChat::say($message);
     }
     self::bustCache();
     // 200 OK
     $sender->render('blank', 'utility', 'dashboard');
 }
Esempio n. 24
0
 /**
  * Display error page.
  */
 public function error()
 {
     $this->removeCssFile('admin.css');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     $this->MasterView = 'default';
     $this->CssClass = 'SplashMessage NoPanel';
     $this->setData('_NoMessages', true);
     $Code = $this->data('Code', 400);
     safeheader("HTTP/1.0 {$Code} " . Gdn_Controller::GetStatusMessage($Code), true, $Code);
     Gdn_Theme::section('Error');
     $this->render();
 }
Esempio n. 25
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');
 }
 /**
  * Include some assets globally.
  */
 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('jquery.atwho.js');
     $this->addJsFile('global.js');
     $this->addCssFile('style.css');
     $this->addCssFile('vanillicon.css', 'static');
     $this->CssClass = 'NoPanel';
     parent::initialize();
 }
 /**
  * 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('style.css');
     parent::Initialize();
     $this->FireEvent('AfterInitialize');
 }
Esempio n. 28
0
 public function Initialize()
 {
     $this->Head = new HeadModule($this);
     $this->AddJsFile('js/library/jquery.js');
     $this->AddJsFile('js/library/jquery.livequery.js');
     $this->AddJsFile('js/library/jquery.form.js');
     $this->AddJsFile('js/library/jquery.popup.js');
     // $this->AddJsFile('js/library/jquery.menu.js');
     $this->AddJsFile('js/library/jquery.gardenhandleajaxform.js');
     $this->AddJsFile('js/global.js');
     $this->AddCssFile('style.css');
     $GuestModule = new GuestModule($this);
     $this->AddModule($GuestModule);
     parent::Initialize();
 }
Esempio n. 29
0
 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('global.js');
         $this->AddCssFile('style.css');
         $this->AddCssFile('candy.css');
         //$this->AddSideMenu();
         $this->AddJsFile('candy.js');
         // Application global js
     }
     parent::Initialize();
 }
Esempio n. 30
0
 public function Initialize()
 {
     $this->Head = new HeadModule($this);
     $this->AddJsFile('js/library/jquery.js');
     $this->AddJsFile('js/library/jquery.livequery.js');
     $this->AddJsFile('js/library/jquery.form.js');
     $this->AddJsFile('js/library/jquery.popup.js');
     $this->AddJsFile('js/library/jquery.menu.js');
     $this->AddJsFile('js/library/jquery.gardenhandleajaxform.js');
     $this->AddJsFile('js/global.js');
     $this->AddCssFile('style.css');
     $GuestModule = new GuestModule($this);
     $GuestModule->MessageCode = "It looks like you're new here. If you want to take part in the discussions, click one of these buttons!";
     $this->AddModule($GuestModule);
     parent::Initialize();
 }