/**
  * Show alternate locale options in Foot.
  */
 public function Base_Render_Before($Sender)
 {
     // Not in Dashboard
     // Block guests until guest sessions are restored
     if ($Sender->MasterView == 'admin') {
         return;
     }
     // Get locales
     $LocaleModel = new LocaleModel();
     $Options = $LocaleModel->EnabledLocalePacks();
     $Locales = $LocaleModel->AvailableLocalePacks();
     // Build & add links
     $Links = '';
     foreach ($Options as $Slug => $Code) {
         $LocaleInfo = GetValue($Slug, $Locales);
         $LocaleName = str_replace(' Transifex', '', GetValue('Name', $LocaleInfo));
         // No 'Transifex' in names, pls.
         $Links .= $this->BuildLocaleLink($LocaleName, $Code);
     }
     // Hackily add English option
     $Links .= $this->BuildLocaleLink('English', 'en-CA');
     $LocaleLinks = Wrap($Links, 'div', array('class' => 'languages'));
     $Sender->AddAsset('Foot', $LocaleLinks);
     // Add a simple style
     $Sender->AddAsset('Head', '<style>.Dashboard .LocaleOptions { display: none; }</style>');
     $Sender->setData('Locale', substr(Gdn::Locale()->Current(), 0, 2));
 }
 /**
  * Set user's preferred locale.
  *
  * Moved event from AppStart to AfterAnalyzeRequest to allow Embed to set P3P header first.
  */
 public function Gdn_Dispatcher_AfterAnalyzeRequest_Handler($Sender)
 {
     // Set user preference
     if ($TempLocale = $this->GetAlternateLocale()) {
         Gdn::Locale()->Set($TempLocale, Gdn::ApplicationManager()->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders());
     }
 }
 public function UserController_TempBan_Create($Sender, $Args)
 {
     $Sender->Permission('Garden.Moderation.Manage');
     $UserID = (int) GetValue('0', $Args);
     $Unban = (bool) GetValue('1', $Args);
     $User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
     if (!$User) {
         throw NotFoundException($User);
     }
     $UserModel = Gdn::UserModel();
     if ($Sender->Form->AuthenticatedPostBack()) {
         if ($Unban) {
             $UserModel->Unban($UserID, array('RestoreContent' => $Sender->Form->GetFormValue('RestoreContent')));
         } else {
             $Minutes = $Sender->Form->GetValue('TempBanPeriodMinutes');
             $Hours = $Sender->Form->GetValue('TempBanPeriodHours');
             $Days = $Sender->Form->GetValue('TempBanPeriodDays');
             $Months = $Sender->Form->GetValue('TempBanPeriodMonths');
             $Years = $Sender->Form->GetValue('TempBanPeriodYears');
             if (!(empty($Minutes) && empty($Hours) && empty($Days) && empty($Months) && empty($Years))) {
                 $AutoExpirePeriod = Gdn_Format::ToDateTime(strtotime("+{$Years} years {$Months} months {$Days} days {$Hours} hours {$Minutes} minutes"));
             } else {
                 $Sender->Form->AddError('ValidateRequired', 'Ban Period');
             }
             if (!ValidateRequired($Sender->Form->GetFormValue('Reason'))) {
                 $Sender->Form->AddError('ValidateRequired', 'Reason');
             }
             if ($Sender->Form->GetFormValue('Reason') == 'Other' && !ValidateRequired($Sender->Form->GetFormValue('ReasonText'))) {
                 $Sender->Form->AddError('ValidateRequired', 'Reason Text');
             }
             if ($Sender->Form->ErrorCount() == 0) {
                 if ($Sender->Form->GetFormValue('Reason') == 'Other') {
                     $Reason = $Sender->Form->GetFormValue('ReasonText');
                 } else {
                     $Reason = $Sender->Form->GetFormValue('Reason');
                 }
                 Gdn::Locale()->SetTranslation('HeadlineFormat.Ban', FormatString('{RegardingUserID,You} banned {ActivityUserID,you} until {BanExpire, date}.', array('BanExpire' => $AutoExpirePeriod)));
                 $UserModel->Ban($UserID, array('Reason' => $Reason));
                 $UserModel->SetField($UserID, 'BanExpire', $AutoExpirePeriod);
             }
         }
         if ($Sender->Form->ErrorCount() == 0) {
             // Redirect after a successful save.
             if ($Sender->Request->Get('Target')) {
                 $Sender->RedirectUrl = $Sender->Request->Get('Target');
             } else {
                 $Sender->RedirectUrl = Url(UserUrl($User));
             }
         }
     }
     $Sender->SetData('User', $User);
     $Sender->AddSideMenu();
     $Sender->Title($Unban ? T('Unban User') : T('Temporary Ban User'));
     if ($Unban) {
         $Sender->View = 'Unban';
     } else {
         $Sender->View = $this->ThemeView('tempban');
     }
     $Sender->Render();
 }
 /**
  * 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';
     }
 }
Example #5
0
 public static function GetLocaleDefinitions()
 {
     $Locale = Gdn::Locale();
     unset($Locale->EventArguments['WildEventStack']);
     $Variable = var_export($Locale, True);
     $CutPoint1 = strpos($Variable, "'_Definition' =>") + 16;
     $CutPoint2 = strrpos($Variable, "'_Locale' =>", $CutPoint1);
     if ($CutPoint1 === False || $CutPoint2 === False) {
         throw new Exception('Failed to detect cutpoints.');
     }
     $Match = substr($Variable, $CutPoint1, $CutPoint2 - $CutPoint1);
     $Match = trim(trim(trim($Match), ','));
     // Kids, never use eval.
     eval("\$Result = {$Match};");
     return $Result;
 }
Example #6
0
 function SetMetaTags($Page, $Controller = Null)
 {
     if (!$Controller) {
         $Controller = Gdn::Controller();
     }
     if ($Page->MetaDescription) {
         $Controller->Head->AddTag('meta', array('name' => 'description', 'content' => $Page->MetaDescription, '_sort' => 0));
     }
     if ($Page->MetaKeywords) {
         $Controller->Head->AddTag('meta', array('name' => 'keywords', 'content' => $Page->MetaKeywords, '_sort' => 0));
     }
     if ($Page->MetaRobots) {
         $Controller->Head->AddTag('meta', array('name' => 'robots', 'content' => $Page->MetaRobots, '_sort' => 0));
     }
     if ($Page->MetaTitle) {
         $Controller->Head->Title($Page->MetaTitle);
     }
     $Controller->Head->AddTag('meta', array('http-equiv' => 'content-language', 'content' => Gdn::Locale()->Current()));
     $Controller->Head->AddTag('meta', array('http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8'));
 }
 public function DiscussionController_Render_Before($Sender)
 {
     $this->ExpireCheck($Sender->Data('Discussion'));
     $this->Expire();
     if (Gdn::Session()->CheckPermission('Vanilla.Discussions.Close', TRUE, 'Category', $Sender->Data('Discussion')->PermissionCategoryID) && $Sender->Data('Discussion')->Closed && $Sender->Data('Discussion')->AutoExpire) {
         $Sender->AddJsFile('autoexpire.js', 'plugins/AutoExpireDiscussions');
     }
     if ($Sender->Data('Discussion')->Closed && $Sender->Data('Discussion')->AutoExpire) {
         Gdn::Locale()->SetTranslation('This discussion has been closed.', 'This discussion has expired.');
     }
 }
 /**
  * Undocumented method.
  *
  * @param string $ApplicationName Undocumented variable.
  * @todo Document DisableApplication() method.
  */
 public function DisableApplication($ApplicationName)
 {
     // 1. Check to make sure that this application is allowed to be disabled
     $ApplicationInfo = ArrayValueI($ApplicationName, $this->AvailableApplications(), array());
     $ApplicationName = $ApplicationInfo['Index'];
     if (!ArrayValue('AllowDisable', $ApplicationInfo, TRUE)) {
         throw new Exception(sprintf(T('You cannot disable the %s application.'), $ApplicationName));
     }
     // 2. Check to make sure that no other enabled applications rely on this one
     foreach ($this->EnabledApplications() as $CheckingName => $CheckingInfo) {
         $RequiredApplications = ArrayValue('RequiredApplications', $CheckingInfo, FALSE);
         if (is_array($RequiredApplications) && array_key_exists($ApplicationName, $RequiredApplications) === TRUE) {
             throw new Exception(sprintf(T('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $ApplicationName, $CheckingName));
         }
     }
     // 2. Disable it
     RemoveFromConfig("EnabledApplications.{$ApplicationName}");
     // Clear the object caches.
     Gdn_Autoloader::SmartFree(Gdn_Autoloader::CONTEXT_APPLICATION, $ApplicationInfo);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $this->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
     $this->EventArguments['AddonName'] = $ApplicationName;
     Gdn::PluginManager()->CallEventHandlers($this, 'ApplicationManager', 'AddonDisabled');
 }
Example #9
0
 protected static function LocaleLanguageCode()
 {
     $T = preg_split('/[_-]/', Gdn::Locale()->Current());
     return ArrayValue(0, $T, 'en');
 }
Example #10
0
 /**
  * Enable a locale pack without installing it to the config or mappings.
  *
  * @param string $LocaleKey The key of the folder.
  */
 public function TestLocale($LocaleKey)
 {
     $Available = $this->AvailableLocalePacks();
     if (!isset($Available[$LocaleKey])) {
         throw NotFoundException('Locale');
     }
     // Grab all of the definition files from the locale.
     $Paths = SafeGlob(PATH_ROOT . "/locales/{$LocaleKey}/*.php");
     foreach ($Paths as $Path) {
         Gdn::Locale()->Load($Path);
     }
 }
 public function GetInfoArray()
 {
     $Info = C('Plugins.LocaleDeveloper');
     foreach ($Info as $Key => $Value) {
         if (!$Value) {
             unset($Info[$Key]);
         }
     }
     $InfoArray = array(GetValue('Key', $Info, 'LocaleDeveloper') => array('Locale' => GetValue('Locale', $Info, Gdn::Locale()->Current()), 'Name' => GetValue('Name', $Info, 'Locale Developer'), 'Description' => 'Automatically gernerated by the Locale Developer plugin.', 'Version' => '0.1a', 'Author' => "Your Name", 'AuthorEmail' => 'Your Email', 'AuthorUrl' => 'http://your.domain.com', 'License' => 'Your choice of license'));
     return $InfoArray;
 }
 /**
  * Allows the configuration of basic setup information in Garden. This
  * should not be functional after the application has been set up.
  *
  * @since 2.0.0
  * @access public
  * @param string $RedirectUrl Where to send user afterward.
  */
 public function Configure($RedirectUrl = '')
 {
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password', 'Garden.Registration.ConfirmEmail', 'Garden.Email.SupportName'));
     // Set the models on the forms.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     // $Locale = Gdn::Locale();
     // $AvailableLocales = $Locale->GetAvailableLocaleSources();
     // $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if (!$this->Form->IsPostback()) {
         // Force the webroot using our best guesstimates
         $ConfigurationModel->Data['Database.Host'] = 'localhost';
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Database.Name', 'Required', 'You must specify the name of the database in which you want to set up Vanilla.');
         // Let's make some user-friendly custom errors for database problems
         $DatabaseHost = $this->Form->GetFormValue('Database.Host', '~~Invalid~~');
         $DatabaseName = $this->Form->GetFormValue('Database.Name', '~~Invalid~~');
         $DatabaseUser = $this->Form->GetFormValue('Database.User', '~~Invalid~~');
         $DatabasePassword = $this->Form->GetFormValue('Database.Password', '~~Invalid~~');
         $ConnectionString = GetConnectionString($DatabaseName, $DatabaseHost);
         try {
             $Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
         } catch (PDOException $Exception) {
             switch ($Exception->getCode()) {
                 case 1044:
                     $this->Form->AddError(T('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1045:
                     $this->Form->AddError(T('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 1049:
                     $this->Form->AddError(T('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
                     break;
                 case 2005:
                     $this->Form->AddError(T("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
                     break;
                 default:
                     $this->Form->AddError(sprintf(T('ValidateConnection'), strip_tags($Exception->getMessage())));
                     break;
             }
         }
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationFormValues = $this->Form->FormValues();
         if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE || $this->Form->ErrorCount() > 0) {
             // Apply the validation results to the form(s)
             $this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
         } else {
             $Host = array_shift(explode(':', Gdn::Request()->RequestHost()));
             $Domain = Gdn::Request()->Domain();
             // Set up cookies now so that the user can be signed in.
             $ExistingSalt = C('Garden.Cookie.Salt', FALSE);
             $ConfigurationFormValues['Garden.Cookie.Salt'] = $ExistingSalt ? $ExistingSalt : RandomString(10);
             $ConfigurationFormValues['Garden.Cookie.Domain'] = '';
             // Don't set this to anything by default. # Tim - 2010-06-23
             // Additional default setup values.
             $ConfigurationFormValues['Garden.Registration.ConfirmEmail'] = TRUE;
             $ConfigurationFormValues['Garden.Email.SupportName'] = $ConfigurationFormValues['Garden.Title'];
             $ConfigurationModel->Save($ConfigurationFormValues, TRUE);
             // If changing locale, redefine locale sources:
             $NewLocale = 'en-CA';
             // $this->Form->GetFormValue('Garden.Locale', FALSE);
             if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
                 $ApplicationManager = new Gdn_ApplicationManager();
                 $Locale = Gdn::Locale();
                 $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
             }
             // Install db structure & basic data.
             $Database = Gdn::Database();
             $Database->Init();
             $Drop = FALSE;
             // Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
             $Explicit = FALSE;
             try {
                 include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
             } catch (Exception $ex) {
                 $this->Form->AddError($ex);
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Create the administrative user
             $UserModel = Gdn::UserModel();
             $UserModel->DefineSchema();
             $UsernameError = T('UsernameError', 'Username can only contain letters, numbers, underscores, and must be between 3 and 20 characters long.');
             $UserModel->Validation->ApplyRule('Name', 'Username', $UsernameError);
             $UserModel->Validation->ApplyRule('Name', 'Required', T('You must specify an admin username.'));
             $UserModel->Validation->ApplyRule('Password', 'Required', T('You must specify an admin password.'));
             $UserModel->Validation->ApplyRule('Password', 'Match');
             $UserModel->Validation->ApplyRule('Email', 'Email');
             if (!($AdminUserID = $UserModel->SaveAdminUser($ConfigurationFormValues))) {
                 $this->Form->SetValidationResults($UserModel->ValidationResults());
             } else {
                 // The user has been created successfully, so sign in now.
                 SaveToConfig('Garden.Installed', TRUE, array('Save' => FALSE));
                 Gdn::Session()->Start($AdminUserID, TRUE);
                 SaveToConfig('Garden.Installed', FALSE, array('Save' => FALSE));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Assign some extra settings to the configuration file if everything succeeded.
             $ApplicationInfo = array();
             include CombinePaths(array(PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'about.php'));
             // Detect rewrite abilities
             try {
                 $Query = ConcatSep('/', Gdn::Request()->Domain(), Gdn::Request()->WebRoot(), 'dashboard/setup');
                 $Results = ProxyHead($Query, array(), 3);
                 $CanRewrite = FALSE;
                 if (in_array(ArrayValue('StatusCode', $Results, 404), array(200, 302)) && ArrayValue('X-Garden-Version', $Results, 'None') != 'None') {
                     $CanRewrite = TRUE;
                 }
             } catch (Exception $e) {
                 // cURL and fsockopen arent supported... guess?
                 $CanRewrite = function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ? TRUE : FALSE;
             }
             SaveToConfig(array('Garden.Version' => ArrayValue('Version', GetValue('Dashboard', $ApplicationInfo, array()), 'Undefined'), 'Garden.RewriteUrls' => $CanRewrite, 'Garden.CanProcessImages' => function_exists('gd_info'), 'EnabledPlugins.GettingStarted' => 'GettingStarted', 'EnabledPlugins.HtmLawed' => 'HtmLawed'));
         }
     }
     return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
 }
 public function ThemeOptions($Style = NULL)
 {
     $this->Permission('Garden.Themes.Manage');
     try {
         $this->AddJsFile('addons.js');
         $this->AddSideMenu('dashboard/settings/themeoptions');
         $ThemeManager = new Gdn_ThemeManager();
         $this->SetData('ThemeInfo', $ThemeManager->EnabledThemeInfo());
         if ($this->Form->IsPostBack()) {
             // Save the styles to the config.
             $StyleKey = $this->Form->GetFormValue('StyleKey');
             SaveToConfig(array('Garden.ThemeOptions.Styles.Key' => $StyleKey, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$StyleKey}.Basename")));
             // Save the text to the locale.
             $Translations = array();
             foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Default) {
                 $Value = $this->Form->GetFormValue($this->Form->EscapeString('Text_' . $Key));
                 $Translations['Theme_' . $Key] = $Value;
                 //$this->Form->SetFormValue('Text_'.$Key, $Value);
             }
             if (count($Translations) > 0) {
                 try {
                     Gdn::Locale()->SaveTranslations($Translations);
                     Gdn::Locale()->Refresh();
                 } catch (Exception $Ex) {
                     $this->Form->AddError($Ex);
                 }
             }
             $this->StatusMessage = T("Your changes have been saved.");
         } elseif ($Style) {
             SaveToConfig(array('Garden.ThemeOptions.Styles.Key' => $Style, 'Garden.ThemeOptions.Styles.Value' => $this->Data("ThemeInfo.Options.Styles.{$Style}.Basename")));
         }
         $this->SetData('ThemeOptions', C('Garden.ThemeOptions'));
         $StyleKey = $this->Data('ThemeOptions.Styles.Key');
         if (!$this->Form->IsPostBack()) {
             foreach ($this->Data('ThemeInfo.Options.Text', array()) as $Key => $Options) {
                 $Default = GetValue('Default', $Options, '');
                 $Value = T('Theme_' . $Key, '#DEFAULT#');
                 if ($Value === '#DEFAULT#') {
                     $Value = $Default;
                 }
                 $this->Form->SetFormValue($this->Form->EscapeString('Text_' . $Key), $Value);
             }
         }
         $this->SetData('ThemeFolder', $ThemeManager->EnabledTheme());
         $this->Title(T('Theme Options'));
         $this->Form->AddHidden('StyleKey', $StyleKey);
     } catch (Exception $Ex) {
         $this->Form->AddError($Ex);
     }
     $this->Render();
 }
Example #14
0
 /**
  * Translates a code into the selected locale's definition.
  *
  * @param string $Code The code related to the language-specific definition.
  * @param string $Default The default value to be displayed if the translation code is not found.
  * @return string The translated string or $Code if there is no value in $Default.
  */
 public static function Translate($Code, $Default = '')
 {
     if ($Default == '') {
         $Default = $Code;
     }
     return Gdn::Locale()->Translate($Code, $Default);
 }
   /**
    * Undocumented method.
    *
    * @param string $ApplicationName Undocumented variable.
    * @todo Document DisableApplication() method.
    */
   public function DisableApplication($ApplicationName) {
      // 1. Check to make sure that this application is allowed to be disabled
      $ApplicationInfo = ArrayValueI($ApplicationName, $this->AvailableApplications(), array());
      $ApplicationName = $ApplicationInfo['Index'];
      if (!ArrayValue('AllowDisable', $ApplicationInfo, TRUE))
         throw new Exception(sprintf(T('You cannot disable the %s application.'), $ApplicationName));

      // 2. Check to make sure that no other enabled applications rely on this one
      foreach ($this->EnabledApplications() as $CheckingName => $CheckingInfo) {
         $RequiredApplications = ArrayValue('RequiredApplications', $CheckingInfo, FALSE);
         if (is_array($RequiredApplications) && array_key_exists($ApplicationName, $RequiredApplications) === TRUE) {
            throw new Exception(sprintf(T('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $ApplicationName, $CheckingName));
         }
      }

      // 2. Disable it
      RemoveFromConfig('EnabledApplications'.'.'.$ApplicationName);

      // Clear the object caches.
      @unlink(PATH_LOCAL_CACHE.'/controller_map.ini');
      @unlink(PATH_LOCAL_CACHE.'/library_map.ini');

      // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
      $Locale = Gdn::Locale();
      $Locale->Set($Locale->Current(), $this->EnabledApplicationFolders(), Gdn::PluginManager()->EnabledPluginFolders(), TRUE);
   }
 /**
  * @param Gdn_Controller $Sender
  * @param array $Args
  */
 protected function Settings_AddEdit($Sender, $Args)
 {
     $client_id = $Sender->Request->Get('client_id');
     Gdn::Locale()->SetTranslation('AuthenticationKey', 'Client ID');
     Gdn::Locale()->SetTranslation('AssociationSecret', 'Secret');
     Gdn::Locale()->SetTranslation('AuthenticateUrl', 'Authentication Url');
     $Form = new Gdn_Form();
     $Sender->Form = $Form;
     if ($Form->AuthenticatedPostBack()) {
         if ($Form->GetFormValue('Generate') || $Sender->Request->Post('Generate')) {
             $Form->SetFormValue('AuthenticationKey', mt_rand());
             $Form->SetFormValue('AssociationSecret', md5(mt_rand()));
             $Sender->SetFormSaved(FALSE);
         } else {
             $Form->ValidateRule('AuthenticationKey', 'ValidateRequired');
             //          $Form->ValidateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.'));
             $Form->ValidateRule('AssociationSecret', 'ValidateRequired');
             $Form->ValidateRule('AuthenticateUrl', 'ValidateRequired');
             $Values = $Form->FormValues();
             //        $Values = ArrayTranslate($Values, array('Name', 'AuthenticationKey', 'URL', 'AssociationSecret', 'AuthenticateUrl', 'SignInUrl', 'RegisterUrl', 'SignOutUrl', 'IsDefault'));
             $Values['AuthenticationSchemeAlias'] = 'jsconnect';
             $Values['AssociationHashMethod'] = 'md5';
             $Values['Attributes'] = serialize(array('HashType' => $Form->GetFormValue('HashType'), 'TestMode' => $Form->GetFormValue('TestMode'), 'Trusted' => $Form->GetFormValue('Trusted', 0)));
             if ($Form->ErrorCount() == 0) {
                 if ($client_id) {
                     Gdn::SQL()->Put('UserAuthenticationProvider', $Values, array('AuthenticationKey' => $client_id));
                 } else {
                     Gdn::SQL()->Options('Ignore', TRUE)->Insert('UserAuthenticationProvider', $Values);
                 }
                 $Sender->RedirectUrl = Url('/settings/jsconnect');
             }
         }
     } else {
         if ($client_id) {
             $Provider = self::GetProvider($client_id);
             TouchValue('Trusted', $Provider, 1);
         } else {
             $Provider = array();
         }
         $Form->SetData($Provider);
     }
     $Sender->SetData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection')));
     $Sender->Render('Settings_AddEdit', '', 'plugins/jsconnect');
 }
Example #17
0
 public function EnableTheme($ThemeName)
 {
     // Make sure to run the setup
     $this->TestTheme($ThemeName);
     // Set the theme.
     $ThemeInfo = $this->GetThemeInfo($ThemeName);
     $ThemeFolder = GetValue('Folder', $ThemeInfo, '');
     if ($ThemeFolder == '') {
         throw new Exception(T('The theme folder was not properly defined.'));
     } else {
         $Options = GetValueR("{$ThemeName}.Options", $this->AvailableThemes());
         if ($Options) {
             SaveToConfig(array('Garden.Theme' => $ThemeName, 'Garden.ThemeOptions.Name' => GetValueR("{$ThemeName}.Name", $this->AvailableThemes(), $ThemeFolder)));
         } else {
             SaveToConfig('Garden.Theme', $ThemeName);
             RemoveFromConfig('Garden.ThemeOptions');
         }
     }
     // Tell the locale cache to refresh itself.
     Gdn::Locale()->Refresh();
     return TRUE;
 }
Example #18
0
 /**
  * Translates a code into the selected locale's definition.
  *
  * @param string $Code The code related to the language-specific definition.
  * @param string $Default The default value to be displayed if the translation code is not found.
  * @return string The translated string or $Code if there is no value in $Default.
  */
 public static function Translate($Code, $Default = FALSE)
 {
     return Gdn::Locale()->Translate($Code, $Default);
 }
Example #19
0
 /**
  * Add buttons to reactions.
  *
  * @param $sender object GardenController.
  * @param $args mixed EventArguments.
  * @return void.
  * @package Shariff
  * @since 0.1
  */
 public function base_afterReactions_handler($sender, $args)
 {
     if (!in_array($sender->ControllerName, $this->controllers)) {
         return;
     }
     $url = 'testurl';
     // data-url 	The canonical URL of the page to check.
     // if sender = comment,  commenturl.
     // if sender = discussion, discussionurl
     // if sender = ? homepageurl
     echo '<span 
         class="shariff ReactMenu" 
         lang="', Gdn::Locale()->Locale, '" 
         data-theme="', c('Shariff.Theme'), '" 
         data-title="', c('Garden.Title'), '" 
         data-services="', c('Shariff.DataServices'), '" 
         ></span>';
     /*
             data-services="[&quot;facebook&quot;,&quot;googleplus&quot;]" Available service names: twitter, facebook, googleplus, linkedin, pinterest, xing, whatsapp, mail, info
     */
 }
 /**
  * Temporarily enable a locale pack without installing it
  *
  * @param string $LocaleKey The key of the folder.
  */
 public function TestLocale($LocaleKey)
 {
     $Available = $this->AvailableLocalePacks();
     if (!isset($Available[$LocaleKey])) {
         throw NotFoundException('Locale');
     }
     // Grab all of the definition files from the locale.
     $Paths = SafeGlob(PATH_ROOT . "/locales/{$LocaleKey}/*.php");
     // Unload the dynamic config
     Gdn::Locale()->Unload();
     // Load each locale file, checking for errors
     foreach ($Paths as $Path) {
         Gdn::Locale()->Load($Path, FALSE);
     }
 }
 /**
  * Manage list of locales.
  *
  * @since 2.0.0
  * @access public
  * @param string $Op 'enable' or 'disable'
  * @param string $LocaleKey Unique ID of locale to be modified.
  * @param string $TransientKey Security token.
  */
 public function Locales($Op = NULL, $LocaleKey = NULL, $TransientKey = NULL)
 {
     $this->Permission('Garden.Settings.Manage');
     $this->Title(T('Locales'));
     $this->AddSideMenu('dashboard/settings/locales');
     $this->AddJsFile('addons.js');
     $LocaleModel = new LocaleModel();
     // Get the available locale packs.
     $AvailableLocales = $LocaleModel->AvailableLocalePacks();
     // Get the enabled locale packs.
     $EnabledLocales = $LocaleModel->EnabledLocalePacks();
     // Check to enable/disable a locale.
     if (Gdn::Session()->ValidateTransientKey($TransientKey) || $this->Form->AuthenticatedPostBack()) {
         if ($Op) {
             $Refresh = FALSE;
             switch (strtolower($Op)) {
                 case 'enable':
                     $Locale = GetValue($LocaleKey, $AvailableLocales);
                     if (!is_array($Locale)) {
                         $this->Form->AddError('@' . sprintf(T('The %s locale pack does not exist.'), htmlspecialchars($LocaleKey)), 'LocaleKey');
                     } elseif (!isset($Locale['Locale'])) {
                         $this->Form->AddError('ValidateRequired', 'Locale');
                     } else {
                         SaveToConfig("EnabledLocales.{$LocaleKey}", $Locale['Locale']);
                         $EnabledLocales[$LocaleKey] = $Locale['Locale'];
                         $Refresh = TRUE;
                     }
                     break;
                 case 'disable':
                     RemoveFromConfig("EnabledLocales.{$LocaleKey}");
                     unset($EnabledLocales[$LocaleKey]);
                     $Refresh = TRUE;
                     break;
             }
             // Set default locale field if just doing enable/disable
             $this->Form->SetValue('Locale', C('Garden.Locale', 'en-CA'));
         } elseif ($this->Form->AuthenticatedPostBack()) {
             // Save the default locale.
             SaveToConfig('Garden.Locale', $this->Form->GetFormValue('Locale'));
             $Refresh = TRUE;
             $this->InformMessage(T("Your changes have been saved."));
         }
         if ($Refresh) {
             Gdn::Locale()->Refresh();
         }
     } elseif (!$this->Form->IsPostBack()) {
         $this->Form->SetValue('Locale', C('Garden.Locale', 'en-CA'));
     }
     // Check for the default locale warning.
     $DefaultLocale = C('Garden.Locale');
     if ($DefaultLocale != 'en-CA') {
         $LocaleFound = FALSE;
         $MatchingLocales = array();
         foreach ($AvailableLocales as $Key => $LocaleInfo) {
             $Locale = GetValue('Locale', $LocaleInfo);
             if ($Locale == $DefaultLocale) {
                 $MatchingLocales[] = GetValue('Name', $LocaleInfo, $Key);
             }
             if (GetValue($Key, $EnabledLocales) == $DefaultLocale) {
                 $LocaleFound = TRUE;
             }
         }
         $this->SetData('DefaultLocaleWarning', !$LocaleFound);
         $this->SetData('MatchingLocalePacks', htmlspecialchars(implode(', ', $MatchingLocales)));
     }
     $this->SetData('AvailableLocales', $AvailableLocales);
     $this->SetData('EnabledLocales', $EnabledLocales);
     $this->SetData('Locales', $LocaleModel->AvailableLocales());
     $this->Render();
 }
Example #22
0
 public function Base_Render_Before($Sender)
 {
     if (property_exists($Sender, 'Form') && $Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
         $Sender->AddCssFile('plugins/Morf/design/morf.css');
         $Sender->AddJsFile('plugins/Morf/js/jquery.placeheld.js');
         $Language = ArrayValue(0, explode('-', Gdn::Locale()->Current()));
         foreach (array($Language, 'en') as $Language) {
             $LanguageJsFile = 'vendors/jquery.dynDateTime/lang/calendar-' . $Language . '.js';
             if (file_exists(Gdn_Plugin::GetResource($LanguageJsFile))) {
                 $Sender->AddDefinition('CalendarLanguage', $Language);
                 break;
             }
         }
         $Session = Gdn::Session();
         if ($Session->CheckPermission('Plugins.Morf.Upload.Allow')) {
             $Sender->AddJsFile('plugins/Morf/js/jquery-fieldselection.js');
             $Sender->AddJsFile('plugins/Morf/js/jquery.uploader.js');
         }
         $Sender->AddJsFile('plugins/Morf/js/morf.js');
         $Sender->AddDefinition('SessionUserID', $Session->UserID);
     }
 }
 /**
  * Undocumented method.
  *
  * @param string $ApplicationName Undocumented variable.
  * @todo Document DisableApplication() method.
  */
 public function DisableApplication($ApplicationName)
 {
     // 1. Check to make sure that this application is allowed to be disabled
     $ApplicationInfo = ArrayValue($ApplicationName, $this->AvailableApplications(), array());
     if (!ArrayValue('AllowDisable', $ApplicationInfo, TRUE)) {
         throw new Exception(sprintf(T('You cannot disable the %s application.'), $ApplicationName));
     }
     // 2. Check to make sure that no other enabled applications rely on this one
     foreach ($this->EnabledApplications() as $CheckingName => $CheckingInfo) {
         $RequiredApplications = ArrayValue('RequiredApplications', $CheckingInfo, FALSE);
         if (is_array($RequiredApplications) && array_key_exists($ApplicationName, $RequiredApplications) === TRUE) {
             throw new Exception(sprintf(T('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $ApplicationName, $CheckingName));
         }
     }
     // 2. Disable it
     RemoveFromConfig('EnabledApplications' . '.' . $ApplicationName);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
     $PluginManager = Gdn::Factory('PluginManager');
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $this->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
 }
Example #24
0
 /**
  * Garden management screen.
  */
 public function Configure()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('garden/settings/configure');
     $this->AddJsFile('email.js');
     $this->Title(Translate('General Settings'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.Email.SupportName', 'Garden.Email.SupportAddress', 'Garden.Email.UseSmtp', 'Garden.Email.SmtpHost', 'Garden.Email.SmtpUser', 'Garden.Email.SmtpPassword', 'Garden.Email.SmtpPort'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     $Locale = Gdn::Locale();
     $AvailableLocales = $Locale->GetAvailableLocaleSources();
     $this->LocaleData = ArrayCombine($AvailableLocales, $AvailableLocales);
     // Check to see if mod_rewrit is enabled.
     if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules())) {
         $this->SetData('HasModRewrite', TRUE);
     } else {
         $this->SetData('HasModRewrite', FALSE);
     }
     // If seeing the form for the first time...
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Locale', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.RewriteUrls', 'Boolean');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportName', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportAddress', 'Required');
         $ConfigurationModel->Validation->ApplyRule('Garden.Email.SupportAddress', 'Email');
         // If changing locale, redefine locale sources:
         $NewLocale = $this->Form->GetFormValue('Garden.Locale', FALSE);
         if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
             $ApplicationManager = new Gdn_ApplicationManager();
             $PluginManager = Gdn::Factory('PluginManager');
             $Locale = Gdn::Locale();
             $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
         }
         if ($this->Form->Save() !== FALSE) {
             $this->StatusMessage = Translate("Your settings have been saved.");
         }
     }
     $this->Render();
 }
 /**
  * Request password reset.
  *
  * @access public
  * @since 2.0.0
  */
 public function PasswordRequest()
 {
     Gdn::Locale()->SetTranslation('Email', T(UserModel::SigninLabelCode()));
     if ($this->Form->IsPostBack() === TRUE) {
         $this->Form->ValidateRule('Email', 'ValidateRequired');
         if ($this->Form->ErrorCount() == 0) {
             try {
                 $Email = $this->Form->GetFormValue('Email');
                 if (!$this->UserModel->PasswordRequest($Email)) {
                     $this->Form->SetValidationResults($this->UserModel->ValidationResults());
                 }
             } catch (Exception $ex) {
                 $this->Form->AddError($ex->getMessage());
             }
             if ($this->Form->ErrorCount() == 0) {
                 $this->Form->AddError('Success!');
                 $this->View = 'passwordrequestsent';
             }
         } else {
             if ($this->Form->ErrorCount() == 0) {
                 $this->Form->AddError("Couldn't find an account associated with that email/username.");
             }
         }
     }
     $this->Render();
 }
<?php

echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php 
echo Gdn::Locale()->Locale;
?>
">
<head>
    <?php 
$this->RenderAsset('Head');
?>
    <!-- Robots should not see the dashboard, but tell them not to index it just in case. -->
    <meta name="robots" content="noindex,nofollow"/>
</head>
<body id="<?php 
echo $BodyIdentifier;
?>
" class="<?php 
echo $this->CssClass;
?>
">
<div id="Frame">
    <div id="Head">
        <h1><?php 
echo anchor(c('Garden.Title') . ' ' . Wrap(t('Visit Site')), '/');
?>
</h1>

        <div class="User">
 public function DisablePlugin($PluginName)
 {
     // Get the plugin and make sure its name is the correct case.
     $Plugin = $this->GetPluginInfo($PluginName);
     if ($Plugin) {
         $PluginName = $Plugin['Index'];
     }
     Gdn_Autoloader::SmartFree(Gdn_Autoloader::CONTEXT_PLUGIN, $Plugin);
     // 1. Check to make sure that no other enabled plugins rely on this one
     // Get all available plugins and compile their requirements
     foreach ($this->EnabledPlugins() as $CheckingName => $Trash) {
         $CheckingInfo = $this->GetPluginInfo($CheckingName);
         $RequiredPlugins = ArrayValue('RequiredPlugins', $CheckingInfo, FALSE);
         if (is_array($RequiredPlugins) && array_key_exists($PluginName, $RequiredPlugins) === TRUE) {
             throw new Exception(sprintf(T('You cannot disable the %1$s plugin because the %2$s plugin requires it in order to function.'), $PluginName, $CheckingName));
         }
     }
     // 2. Perform necessary hook action
     $this->_PluginHook($PluginName, self::ACTION_DISABLE, TRUE);
     // 3. Disable it
     RemoveFromConfig("EnabledPlugins.{$PluginName}");
     unset($this->EnabledPlugins[$PluginName]);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE);
     Gdn::Locale()->Refresh();
     return TRUE;
 }
Example #28
0
 public function EnableTheme($ThemeName, $IsMobile = FALSE)
 {
     // Make sure to run the setup
     $this->TestTheme($ThemeName);
     // Set the theme.
     $ThemeInfo = $this->GetThemeInfo($ThemeName);
     $ThemeFolder = GetValue('Folder', $ThemeInfo, '');
     $oldTheme = $IsMobile ? C('Garden.MobileTheme', 'mobile') : C('Garden.Theme', 'default');
     if ($ThemeFolder == '') {
         throw new Exception(T('The theme folder was not properly defined.'));
     } else {
         $Options = GetValueR("{$ThemeName}.Options", $this->AvailableThemes());
         if ($Options) {
             if ($IsMobile) {
                 SaveToConfig(array('Garden.MobileTheme' => $ThemeName, 'Garden.MobileThemeOptions.Name' => GetValueR("{$ThemeName}.Name", $this->AvailableThemes(), $ThemeFolder)));
             } else {
                 SaveToConfig(array('Garden.Theme' => $ThemeName, 'Garden.ThemeOptions.Name' => GetValueR("{$ThemeName}.Name", $this->AvailableThemes(), $ThemeFolder)));
             }
         } else {
             if ($IsMobile) {
                 SaveToConfig('Garden.MobileTheme', $ThemeName);
                 RemoveFromConfig('Garden.MobileThemeOptions');
             } else {
                 SaveToConfig('Garden.Theme', $ThemeName);
                 RemoveFromConfig('Garden.ThemeOptions');
             }
         }
     }
     Logger::event('theme_changed', LogLevel::NOTICE, 'The {themeType} theme changed from {oldTheme} to {newTheme}.', array('themeType' => $IsMobile ? 'mobile' : 'desktop', 'oldTheme' => $oldTheme, 'newTheme' => $ThemeName));
     // Tell the locale cache to refresh itself.
     Gdn::Locale()->Refresh();
     return TRUE;
 }
Example #29
0
<?php

if (!defined('APPLICATION')) {
    exit;
}
$Locale = Gdn::Locale();
$Definitions = $Locale->GetDeveloperDefinitions();
$CountDefinitions = count($Definitions);
?>
<h1><?php 
echo T('Customize Text');
?>
</h1>
<div class="padded">
   <?php 
echo 'Search complete. There are <strong>' . $CountDefinitions . '</strong> text definitions available for editing.';
echo Wrap(Anchor('Go edit them now!', 'settings/customizetext'), 'p');
?>
</div>
 /**
  * @param SettingsController $sender
  * @param array $Args
  */
 protected function settings_addEdit($sender, $Args)
 {
     $client_id = $sender->Request->Get('client_id');
     Gdn::Locale()->SetTranslation('AuthenticationKey', 'Client ID');
     Gdn::Locale()->SetTranslation('AssociationSecret', 'Secret');
     Gdn::Locale()->SetTranslation('AuthenticateUrl', 'Authentication Url');
     /* @var Gdn_Form $form */
     $form = $sender->Form;
     $model = new Gdn_AuthenticationProviderModel();
     $form->setModel($model);
     if ($form->authenticatedPostBack()) {
         if ($form->getFormValue('Generate') || $sender->Request->post('Generate')) {
             $form->setFormValue('AuthenticationKey', mt_rand());
             $form->setFormValue('AssociationSecret', md5(mt_rand()));
             $sender->setFormSaved(FALSE);
         } else {
             $form->validateRule('AuthenticationKey', 'ValidateRequired');
             $form->validateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.'));
             $form->validateRule('AssociationSecret', 'ValidateRequired');
             $form->validateRule('AuthenticateUrl', 'ValidateRequired');
             $form->setFormValue('AuthenticationSchemeAlias', 'jsconnect');
             if ($form->save(['ID' => $client_id])) {
                 $sender->RedirectUrl = url('/settings/jsconnect');
             }
         }
     } else {
         if ($client_id) {
             $provider = self::getProvider($client_id);
             touchValue('Trusted', $provider, 1);
         } else {
             $provider = array();
         }
         $form->setData($provider);
     }
     // Set up the form controls for editing the connection.
     $hashTypes = hash_algos();
     $hashTypes = array_combine($hashTypes, $hashTypes);
     $controls = ['AuthenticationKey' => ['LabelCode' => 'Client ID', 'Description' => T('The client ID uniquely identifies the site.', 'The client ID uniquely identifies the site. You can generate a new ID with the button at the bottom of this page.')], 'AssociationSecret' => ['LabelCode' => 'Secret', 'Description' => T('The secret secures the sign in process.', 'The secret secures the sign in process. Do <b>NOT</b> give the secret out to anyone.')], 'Name' => ['LabelCode' => 'Site Name', 'Description' => T('Enter a short name for the site.', 'Enter a short name for the site. This is displayed on the signin buttons.')], 'AuthenticateUrl' => ['LabelCode' => 'Authentication URL', 'Description' => T('The location of the JSONP formatted authentication data.'), 'Options' => ['class' => 'InputBox BigInput']], 'SignInUrl' => ['LabelCode' => 'Sign In URL', 'Description' => T('The url that users use to sign in.') . ' ' . T('Use {target} to specify a redirect.'), 'Options' => ['class' => 'InputBox BigInput']], 'RegisterUrl' => ['LabelCode' => 'Registration URL', 'Description' => T('The url that users use to register for a new account.'), 'Options' => ['class' => 'InputBox BigInput']], 'SignOutUrl' => ['LabelCode' => 'Sign Out URL', 'Description' => T('The url that users use to sign out of your site.'), 'Options' => ['class' => 'InputBox BigInput']], 'Trusted' => ['Control' => 'checkbox', 'LabelCode' => 'This is trusted connection and can sync roles & permissions.'], 'IsDefault' => ['Control' => 'checkbox', 'LabelCode' => 'Make this connection your default signin method.'], 'Advanced' => ['Control' => 'callback', 'Callback' => function ($form) {
         return '<h2>' . T('Advanced') . '</h2>';
     }], 'HashType' => ['Control' => 'dropdown', 'LabelCode' => 'Hash Algorithm', 'Items' => $hashTypes, 'Description' => T('Choose md5 if you\'re not sure what to choose.', "You can select a custom hash algorithm to sign your requests. The hash algorithm must also be used in your client library. Choose md5 if you're not sure what to choose."), 'Options' => ['Default' => 'md5']], 'TestMode' => ['Control' => 'checkbox', 'LabelCode' => 'This connection is in test-mode.']];
     $sender->setData('_Controls', $controls);
     $sender->setData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection')));
     // Throw a render event as this plugin so that handlers can call our methods.
     Gdn::pluginManager()->callEventHandlers($this, __CLASS__, 'addedit', 'render');
     $sender->render('Settings_AddEdit', '', 'plugins/jsconnect');
 }