factory() public static method

Get an object from the factory.
See also: Gdn_Factory::Factory()
public static factory ( string $Alias = false )
$Alias string The alias of the class.
Example #1
0
/**
 * Writes the search box to the page.
 *
 * @param array The parameters passed into the function. This currently takes no parameters.
 * @param $smarty The smarty object rendering the template.
 * @return The url.
 */
function smarty_function_searchbox($params, &$smarty)
{
    $placeholder = array_key_exists('placeholder', $params) ? val('placeholder', $params, '', true) : t('SearchBoxPlaceHolder', 'Search');
    $form = Gdn::factory('Form');
    $result = $form->open(array('action' => url('/search'), 'method' => 'get')) . $form->textBox('Search', array('placeholder' => $placeholder, 'accesskey' => '/')) . $form->button('Go', array('Name' => '')) . $form->close();
    return $result;
}
 public function base_render_before($sender)
 {
     if ($sender->MasterView == 'admin') {
         return;
     }
     //tell the browser this is a mobile style
     $sender->Head->addTag('meta', array('name' => 'viewport', 'content' => "width=device-width,minimum-scale=1.0,maximum-scale=1.0"));
     /*
             $sender->InformMessage(
                 'This message will stay here until you dismiss it!',
                 array(
                     'CssClass' => 'Dismissable',
                     'DismissCallbackUrl' => '/plugin/dismissmessage/'
                 )
             );
     */
     $sender->Head->addTag('meta', array('name' => 'theme-color', 'content' => "#C08F00"));
     // YOU CAN REMOVE FONT-AWESOME IN ONLINE-VERSION
     $sender->Head->addTag('link', array('rel' => 'stylesheet', 'href' => "https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"));
     //position of the panel
     $sender->CssClass .= c('MinusBaseline.Panel.Left', false) ? ' PanelLeft' : ' PanelRight';
     //add the hamburger menu
     $sender->addAsset('Content', anchor('n', url('#'), 'Hamburger'), 'Hamburger');
     //add the searchbox to the panel
     //copied from library/vendors/SmartyPlugins/function.searchbox.php
     $form = Gdn::factory('Form');
     $form->InputPrefix = '';
     $search = $form->open(array('action' => Url('/search'), 'method' => 'get')) . $form->textBox('Search', array('placeholder' => t('SearchBoxPlaceHolder', 'Search'))) . $form->button('Go', array('Name' => '')) . $form->close();
     $sender->addAsset('Panel', wrap($search, 'div', array('class' => 'SiteSearch')), 'SearchBox');
     //nomobile link to switch to the full site
     $sender->addAsset('Foot', Gdn_Theme::link('/', t(' '), '<div class="LogoFoot"><a href="%url" class="%class">%text</a></div>'), 'LogoFoot');
     //Add logo to button of site
     $sender->addAsset('Foot', Gdn_Theme::link('profile/nomobile', t('Full Site'), '<div class="NoMobile"><a href="%url" class="%class">%text</a></div>'), 'NoMobile');
 }
 /**
  *
  * @param Gdn_Controller $Sender
  * @throws Exception
  */
 public function __construct($Sender = null)
 {
     if (property_exists($Sender, 'Conversation')) {
         $this->Conversation = $Sender->Conversation;
     }
     // Allowed to use this module?
     $this->AddUserAllowed = $Sender->ConversationModel->addUserAllowed($this->Conversation->ConversationID);
     $this->Form = Gdn::factory('Form', 'AddPeople');
     // If the form was posted back, check for people to add to the conversation
     if ($this->Form->authenticatedPostBack()) {
         // Defer exceptions until they try to use the form so we don't fill our logs
         if (!$this->AddUserAllowed || !checkPermission('Conversations.Conversations.Add')) {
             throw permissionException();
         }
         $NewRecipientUserIDs = array();
         $NewRecipients = explode(',', $this->Form->getFormValue('AddPeople', ''));
         $UserModel = Gdn::factory("UserModel");
         foreach ($NewRecipients as $Name) {
             if (trim($Name) != '') {
                 $User = $UserModel->getByUsername(trim($Name));
                 if (is_object($User)) {
                     $NewRecipientUserIDs[] = $User->UserID;
                 }
             }
         }
         $Sender->ConversationModel->addUserToConversation($this->Conversation->ConversationID, $NewRecipientUserIDs);
         $Sender->informMessage(t('Your changes were saved.'));
         $Sender->RedirectUrl = url('/messages/' . $this->Conversation->ConversationID);
     }
     $this->_ApplicationFolder = $Sender->Application;
     $this->_ThemeFolder = $Sender->Theme;
 }
 /**
  * Allows the user to declare which values are being manipulated in the
  * $this->Name configuration array.
  *
  * @param mixed $FieldName The name of the field (or array of field names) to ensure.
  */
 public function setField($FieldName)
 {
     $Config = Gdn::factory(Gdn::AliasConfig);
     if (is_array($FieldName) === false) {
         $FieldName = array($FieldName);
     }
     foreach ($FieldName as $Index => $Value) {
         if (is_numeric($Index)) {
             $NameKey = $Value;
             $Default = '';
         } else {
             $NameKey = $Index;
             $Default = $Value;
         }
         /*
         if ($this->Name != 'Configuration')
            $Name = $NameKey;
         else
            $Name = $this->Name.'.'.$NameKey;
         */
         $this->Data[$NameKey] = $Config->get($NameKey, $Default);
     }
 }
 /**
  * Add a formatter and create a chain in the Gdn factory.
  *
  * This is a conveinience method for chaining formatters without having to deal with the object creation logic.
  *
  * @param string $Type The type of formatter.
  * @param object $Formatter The formatter to install.
  * @param int $Priority The priority of the formatter in the chain. High priorities come first.
  * @return Gdn_FormatterChain The chain object that was created.
  */
 public static function chain($Type, $Formatter, $Priority = Gdn_FormatterChain::PRIORITY_DEFAULT)
 {
     // Grab the existing formatter from the factory.
     $Formatter = Gdn::factory($Type . 'Formatter');
     if ($Formatter === null) {
         $Chain = new Gdn_FormatterChain();
         Gdn::factoryInstall($Type . 'Formatter', 'Gdn_FormatterChain', __FILE__, Gdn::FactorySingleton, $Chain);
     } elseif (is_a($Formatter, 'Gdn_FormatterChain')) {
         $Chain = $Formatter;
     } else {
         Gdn::factoryUninstall($Type . 'Formatter');
         // Look for a priority on the existing object.
         if (property_exists($Formatter, 'Priority')) {
             $Priority = $Formatter->Priority;
         } else {
             $Priority = self::PRIORITY_DEFAULT;
         }
         $Chain = new Gdn_FormatterChain();
         $Chain->add($Formatter, $Priority);
         Gdn::factoryInstall($Type . 'Formatter', 'Gdn_FormatterChain', __FILE__, Gdn::FactorySingleton, $Chain);
     }
     $Chain->add($Formatter, $Priority);
     return $Chain;
 }
Example #6
0
 /**
  * Get list of defined view handlers
  *
  * @staticvar array $handlers
  * @param boolean $fresh
  * @return array
  */
 public static function viewHandlers($fresh = false)
 {
     static $handlers = null;
     if (is_null($handlers) || $fresh) {
         $factories = Gdn::factory()->search('viewhandler.*');
         $handlers = array_change_key_case($factories);
     }
     return $handlers;
 }
Example #7
0
 /**
  * Get the database structure class for this database.
  *
  * @return Gdn_DatabaseStructure The database structure class for this database.
  */
 public function structure()
 {
     if (is_null($this->_Structure)) {
         $Name = $this->Engine . 'Structure';
         $this->_Structure = Gdn::factory($Name, $this);
     }
     return $this->_Structure;
 }
Example #8
0
 /**
  *
  *
  * @param $Mixed
  * @return mixed|string
  */
 public static function wysiwyg($Mixed)
 {
     static $CustomFormatter;
     if (!isset($CustomFormatter)) {
         $CustomFormatter = c('Garden.Format.WysiwygFunction', false);
     }
     if (!is_string($Mixed)) {
         return self::to($Mixed, 'Wysiwyg');
     } elseif (is_callable($CustomFormatter)) {
         return $CustomFormatter($Mixed);
     } else {
         // The text contains html and must be purified.
         $Formatter = Gdn::factory('HtmlFormatter');
         if (is_null($Formatter)) {
             // If there is no HtmlFormatter then make sure that script injections won't work.
             return self::display($Mixed);
         }
         // HTML filter first
         $Mixed = $Formatter->format($Mixed);
         // Links
         $Mixed = Gdn_Format::links($Mixed);
         // Mentions & Hashes
         $Mixed = Gdn_Format::mentions($Mixed);
         $Mixed = Emoji::instance()->translateToHtml($Mixed);
         return $Mixed;
     }
 }
Example #9
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'));
     }
 }
Example #10
0
 /**
  * Removes a Template file from the collection.
  *
  * @param string $fileName The Template file to search for.
  */
 public static function removeTemplateFile($fileName)
 {
     $tpls = Gdn::factory('Mustache')->templates;
     foreach ($tpls as $key => $fileInfo) {
         if ($fileInfo['Template'] == $fileName) {
             unset(Gdn::factory('Mustache')->templates[$key]);
             return;
         }
     }
 }
 /**
  * Allows the setting of data into one of two serialized data columns on the
  * user table: Preferences and Attributes.
  *
  * The method expects "Name" & "Value" to be in the $_POST collection. This method always
  * saves to the row of the user id performing this action (ie. $Session->UserID). The
  * type of property column being saved should be specified in the url:
  * i.e. /dashboard/utility/set/preference/name/value/transientKey
  * or /dashboard/utility/set/attribute/name/value/transientKey
  *
  * @since 2.0.0
  * @access public
  * @param string $UserPropertyColumn The type of value being saved: preference or attribute.
  * @param string $Name The name of the property being saved.
  * @param string $Value The value of the property being saved.
  * @param string $TransientKey A unique transient key to authenticate that the user intended to perform this action.
  */
 public function set($UserPropertyColumn = '', $Name = '', $Value = '', $TransientKey = '')
 {
     $this->_DeliveryType = DELIVERY_TYPE_BOOL;
     $Session = Gdn::session();
     $Success = false;
     if (in_array($UserPropertyColumn, array('preference', 'attribute')) && $Name != '' && $Value != '' && $Session->UserID > 0 && $Session->validateTransientKey($TransientKey)) {
         $UserModel = Gdn::factory("UserModel");
         $Method = $UserPropertyColumn == 'preference' ? 'SavePreference' : 'SaveAttribute';
         $Success = $UserModel->{$Method}($Session->UserID, $Name, $Value) ? 'TRUE' : 'FALSE';
     }
     if (!$Success) {
         $this->Form->addError('ErrorBool');
     }
     // Redirect back where the user came from if necessary
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->render();
     }
 }
Example #12
0
 /**
  * Fire before every page render.
  *
  * @param Gdn_Controller $Sender
  */
 public function base_render_before($Sender)
 {
     $Session = Gdn::session();
     // Check the statistics.
     if ($Sender->deliveryType() == DELIVERY_TYPE_ALL) {
         Gdn::statistics()->check();
     }
     // Enable theme previewing
     if ($Session->isValid()) {
         $PreviewThemeName = htmlspecialchars($Session->getPreference('PreviewThemeName', ''));
         $PreviewThemeFolder = htmlspecialchars($Session->getPreference('PreviewThemeFolder', ''));
         if ($PreviewThemeName != '') {
             $Sender->Theme = $PreviewThemeName;
             $Sender->informMessage(sprintf(t('You are previewing the %s theme.'), wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . anchor(t('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->transientKey(), 'PreviewThemeButton') . ' ' . anchor(t('Cancel'), 'settings/cancelpreview/', '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..."));
 }
Example #13
0
 /**
  * Database & config changes to be done upon enable.
  *
  * @since 2.0.0
  * @access public
  */
 public function setup()
 {
     $Database = Gdn::database();
     $Config = Gdn::factory(Gdn::AliasConfig);
     $Drop = false;
     //c('Conversations.Version') === FALSE ? TRUE : FALSE;
     $Validation = new Gdn_Validation();
     // This is going to be needed by structure.php to validate permission names
     include PATH_APPLICATIONS . DS . 'conversations' . DS . 'settings' . DS . 'structure.php';
     include PATH_APPLICATIONS . DS . 'conversations' . DS . 'settings' . DS . 'stub.php';
     $ApplicationInfo = array();
     include combinePaths(array(PATH_APPLICATIONS . DS . 'conversations' . DS . 'settings' . DS . 'about.php'));
     $Version = val('Version', val('Conversations', $ApplicationInfo, array()), 'Undefined');
     saveToConfig('Conversations.Version', $Version);
 }
Example #14
0
 /**
  * Automatically executed when application is enabled.
  *
  * @since 2.0.0
  * @package Vanilla
  */
 public function setup()
 {
     $Database = Gdn::database();
     $Config = Gdn::factory(Gdn::AliasConfig);
     $Drop = false;
     // Call structure.php to update database
     $Validation = new Gdn_Validation();
     // Needed by structure.php to validate permission names
     include PATH_APPLICATIONS . DS . 'vanilla' . DS . 'settings' . DS . 'structure.php';
     saveToConfig('Routes.DefaultController', 'discussions');
 }
 /**
  *
  *
  * @return Smarty The smarty object used for rendering.
  */
 public function smarty()
 {
     if (is_null($this->_Smarty)) {
         $Smarty = Gdn::factory('Smarty');
         $Smarty->cache_dir = PATH_CACHE . DS . 'Smarty' . DS . 'cache';
         $Smarty->compile_dir = PATH_CACHE . DS . 'Smarty' . DS . 'compile';
         $Smarty->plugins_dir[] = PATH_LIBRARY . DS . 'vendors' . DS . 'SmartyPlugins';
         //         Gdn::PluginManager()->Trace = TRUE;
         Gdn::pluginManager()->callEventHandlers($Smarty, 'Gdn_Smarty', 'Init');
         $this->_Smarty = $Smarty;
     }
     return $this->_Smarty;
 }
 /**
  * Adds information to the definition list that causes the app to "phone
  * home" and see if there are upgrades available.
  *
  * Currently added to the dashboard only. Nothing renders with this method.
  * It is public so it can be added by plugins.
  */
 public function addUpdateCheck()
 {
     if (c('Garden.NoUpdateCheck')) {
         return;
     }
     // Check to see if the application needs to phone-home for updates. Doing
     // this here because this method is always called when admin pages are
     // loaded regardless of the application loading them.
     $UpdateCheckDate = Gdn::config('Garden.UpdateCheckDate', '');
     if ($UpdateCheckDate == '' || !IsTimestamp($UpdateCheckDate) || $UpdateCheckDate < strtotime("-1 day")) {
         $UpdateData = array();
         // Grab all of the plugins & versions
         $Plugins = Gdn::pluginManager()->availablePlugins();
         foreach ($Plugins as $Plugin => $Info) {
             $Name = val('Name', $Info, $Plugin);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Plugin');
             }
         }
         // Grab all of the applications & versions
         $ApplicationManager = Gdn::factory('ApplicationManager');
         $Applications = $ApplicationManager->availableApplications();
         foreach ($Applications as $Application => $Info) {
             $Name = val('Name', $Info, $Application);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Application');
             }
         }
         // Grab all of the themes & versions
         $ThemeManager = new Gdn_ThemeManager();
         $Themes = $ThemeManager->availableThemes();
         foreach ($Themes as $Theme => $Info) {
             $Name = val('Name', $Info, $Theme);
             $Version = val('Version', $Info, '');
             if ($Version != '') {
                 $UpdateData[] = array('Name' => $Name, 'Version' => $Version, 'Type' => 'Theme');
             }
         }
         // Dump the entire set of information into the definition list (jQuery
         // will pick it up and ping the VanillaForums.org server with this info).
         $this->addDefinition('UpdateChecks', Gdn_Format::serialize($UpdateData));
     }
 }
Example #17
0
 /**
  *
  */
 public function renderMaster()
 {
     // Build the master view if necessary
     if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) {
         $this->MasterView = $this->masterView();
         // Only get css & ui components if this is NOT a syndication request
         if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) {
             $CssAnchors = AssetModel::getAnchors();
             $this->EventArguments['CssFiles'] =& $this->_CssFiles;
             $this->fireEvent('BeforeAddCss');
             $ETag = AssetModel::eTag();
             $CombineAssets = c('Garden.CombineAssets');
             $ThemeType = isMobile() ? 'mobile' : 'desktop';
             // And now search for/add all css files.
             foreach ($this->_CssFiles as $CssInfo) {
                 $CssFile = $CssInfo['FileName'];
                 if (!array_key_exists('Options', $CssInfo) || !is_array($CssInfo['Options'])) {
                     $CssInfo['Options'] = array();
                 }
                 $Options =& $CssInfo['Options'];
                 // style.css and admin.css deserve some custom processing.
                 if (in_array($CssFile, $CssAnchors)) {
                     if (!$CombineAssets) {
                         // Grab all of the css files from the asset model.
                         $AssetModel = new AssetModel();
                         $CssFiles = $AssetModel->getCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag);
                         foreach ($CssFiles as $Info) {
                             $this->Head->addCss($Info[1], 'all', true, $CssInfo);
                         }
                     } else {
                         $Basename = substr($CssFile, 0, -4);
                         $this->Head->addCss(url("/asset/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', false, $CssInfo['Options']);
                     }
                     continue;
                 }
                 $AppFolder = $CssInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::CssPath($CssFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if (isUrl($Path)) {
                     $this->Head->AddCss($Path, 'all', val('AddVersion', $Options, true), $Options);
                     continue;
                 } else {
                     // Check to see if there is a CSS cacher.
                     $CssCacher = Gdn::factory('CssCacher');
                     if (!is_null($CssCacher)) {
                         $Path = $CssCacher->get($Path, $AppFolder);
                     }
                     if ($Path !== false) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $this->Head->addCss($Path, 'all', true, $Options);
                     }
                 }
             }
             // Add a custom js file.
             if (arrayHasValue($this->_CssFiles, 'style.css')) {
                 $this->addJsFile('custom.js');
                 // only to non-admin pages.
             }
             $Cdns = array();
             if (!c('Garden.Cdns.Disable', false)) {
                 $Cdns = array('jquery.js' => "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js");
             }
             // And now search for/add all JS files.
             $this->EventArguments['Cdns'] =& $Cdns;
             $this->fireEvent('AfterJsCdns');
             $this->Head->addScript('', 'text/javascript', false, array('content' => $this->definitionList(false)));
             foreach ($this->_JsFiles as $Index => $JsInfo) {
                 $JsFile = $JsInfo['FileName'];
                 if (!is_array($JsInfo['Options'])) {
                     $JsInfo['Options'] = array();
                 }
                 $Options =& $JsInfo['Options'];
                 if (isset($Cdns[$JsFile])) {
                     $JsFile = $Cdns[$JsFile];
                 }
                 $AppFolder = $JsInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::JsPath($JsFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if ($Path !== false) {
                     $AddVersion = true;
                     if (!isUrl($Path)) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $AddVersion = val('AddVersion', $Options, true);
                     }
                     $this->Head->addScript($Path, 'text/javascript', $AddVersion, $Options);
                     continue;
                 }
             }
         }
         // Add the favicon.
         $Favicon = C('Garden.FavIcon');
         if ($Favicon) {
             $this->Head->setFavIcon(Gdn_Upload::url($Favicon));
         }
         // Make sure the head module gets passed into the assets collection.
         $this->addModule('Head');
     }
     // Master views come from one of four places:
     $MasterViewPaths = array();
     if (strpos($this->MasterView, '/') !== false) {
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*'));
     } else {
         if ($this->Theme) {
             // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
             // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*'));
         }
         // 3. Plugin default. eg. root/plugin_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 4. Application default. eg. root/app_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 5. Garden default. eg. root/dashboard/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*'));
     }
     // Find the first file that matches the path.
     $MasterViewPath = false;
     foreach ($MasterViewPaths as $Glob) {
         $Paths = safeGlob($Glob);
         if (is_array($Paths) && count($Paths) > 0) {
             $MasterViewPath = $Paths[0];
             break;
         }
     }
     $this->EventArguments['MasterViewPath'] =& $MasterViewPath;
     $this->fireEvent('BeforeFetchMaster');
     if ($MasterViewPath === false) {
         trigger_error(errorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR);
     }
     /// A unique identifier that can be used in the body tag of the master view if needed.
     $ControllerName = $this->ClassName;
     // Strip "Controller" from the body identifier.
     if (substr($ControllerName, -10) == 'Controller') {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Strip "Gdn_" from the body identifier.
     if (substr($ControllerName, 0, 4) == 'Gdn_') {
         $ControllerName = substr($ControllerName, 4);
     }
     $this->setData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, true);
     // Check to see if there is a handler for this particular extension.
     $ViewHandler = Gdn::factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.')));
     if (is_null($ViewHandler)) {
         $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($this->RequestMethod)));
         include $MasterViewPath;
     } else {
         $ViewHandler->render($MasterViewPath, $this);
     }
 }
Example #18
-1
 /**
  * Delete a single draft.
  *
  * Redirects user back to Index unless DeliveryType is set.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $DraftID Unique ID of draft to be deleted.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function delete($DraftID = '', $TransientKey = '')
 {
     $Form = Gdn::factory('Form');
     $Session = Gdn::session();
     if (is_numeric($DraftID) && $DraftID > 0) {
         $Draft = $this->DraftModel->getID($DraftID);
     }
     if ($Draft) {
         if ($Session->validateTransientKey($TransientKey) && (val('InsertUserID', $Draft) == $Session->UserID || checkPermission('Garden.Community.Manage'))) {
             // Delete the draft
             if (!$this->DraftModel->deleteID($DraftID)) {
                 $Form->addError('Failed to delete draft');
             }
         } else {
             throw permissionException('Garden.Community.Manage');
         }
     } else {
         throw notFoundException('Draft');
     }
     // Redirect
     if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
         $Target = GetIncomingValue('Target', '/drafts');
         redirect($Target);
     }
     // Return any errors
     if ($Form->errorCount() > 0) {
         $this->setJson('ErrorMessage', $Form->errors());
     }
     // Render default view
     $this->render();
 }