/**
  * 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));
 }
 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 locales.
     $AvailableLocales = $LocaleModel->AvailableLocalePacks();
     // Get the enabled locales.
     $EnabledLocales = $LocaleModel->EnabledLocalePacks();
     // Check to enable/disable a plugin.
     if ($Op && Gdn::Session()->ValidateTransientKey($TransientKey)) {
         $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;
         }
         if ($Refresh) {
             Gdn::Locale()->Refresh();
         }
     }
     $this->SetData('AvailableLocales', $AvailableLocales);
     $this->SetData('EnabledLocales', $EnabledLocales);
     $this->Render();
 }
Example #3
0
 /**
  *
  *
  * @param bool $Enabled
  * @return array
  */
 public function getAddons($Enabled = false)
 {
     $Addons = array();
     // Get the core.
     self::_AddAddon(array('AddonKey' => 'vanilla', 'AddonType' => 'core', 'Version' => APPLICATION_VERSION, 'Folder' => '/'), $Addons);
     // Get a list of all of the applications.
     $ApplicationManager = new Gdn_ApplicationManager();
     if ($Enabled) {
         $Applications = $ApplicationManager->AvailableApplications();
     } else {
         $Applications = $ApplicationManager->EnabledApplications();
     }
     foreach ($Applications as $Key => $Info) {
         // Exclude core applications.
         if (in_array(strtolower($Key), array('conversations', 'dashboard', 'skeleton', 'vanilla'))) {
             continue;
         }
         $Addon = array('AddonKey' => $Key, 'AddonType' => 'application', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, strtolower($Key)));
         self::_AddAddon($Addon, $Addons);
     }
     // Get a list of all of the plugins.
     $PluginManager = Gdn::pluginManager();
     if ($Enabled) {
         $Plugins = $PluginManager->EnabledPlugins();
     } else {
         $Plugins = $PluginManager->AvailablePlugins();
     }
     foreach ($Plugins as $Key => $Info) {
         // Exclude core plugins.
         if (in_array(strtolower($Key), array())) {
             continue;
         }
         $Addon = array('AddonKey' => $Key, 'AddonType' => 'plugin', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/applications/' . GetValue('Folder', $Info, $Key));
         self::_AddAddon($Addon, $Addons);
     }
     // Get a list of all the themes.
     $ThemeManager = new Gdn_ThemeManager();
     if ($Enabled) {
         $Themes = $ThemeManager->EnabledThemeInfo(true);
     } else {
         $Themes = $ThemeManager->AvailableThemes();
     }
     foreach ($Themes as $Key => $Info) {
         // Exclude core themes.
         if (in_array(strtolower($Key), array('default'))) {
             continue;
         }
         $Addon = array('AddonKey' => $Key, 'AddonType' => 'theme', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/themes/' . GetValue('Folder', $Info, $Key));
         self::_AddAddon($Addon, $Addons);
     }
     // Get a list of all locales.
     $LocaleModel = new LocaleModel();
     if ($Enabled) {
         $Locales = $LocaleModel->EnabledLocalePacks(true);
     } else {
         $Locales = $LocaleModel->AvailableLocalePacks();
     }
     foreach ($Locales as $Key => $Info) {
         // Exclude core themes.
         if (in_array(strtolower($Key), array('skeleton'))) {
             continue;
         }
         $Addon = array('AddonKey' => $Key, 'AddonType' => 'locale', 'Version' => val('Version', $Info, '0.0'), 'Folder' => '/locales/' . GetValue('Folder', $Info, $Key));
         self::_AddAddon($Addon, $Addons);
     }
     return $Addons;
 }
 /**
  * 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();
 }
 public function _Settings($Sender, $Args)
 {
     $Sender->Form = $this->Form;
     // Grab the existing locale packs.
     $LocaleModel = new LocaleModel();
     $LocalePacks = $LocaleModel->AvailableLocalePacks();
     $LocalArray = array();
     foreach ($LocalePacks as $Key => $Info) {
         $LocaleArray[$Key] = GetValue('Name', $Info, $Key);
     }
     $Sender->SetData('LocalePacks', $LocaleArray);
     if ($this->Form->IsPostBack()) {
         if ($this->Form->GetFormValue('Save')) {
             $Values = ArrayTranslate($this->Form->FormValues(), array('Key', 'Name', 'Locale', 'CaptureDefinitions'));
             $SaveValues = array();
             foreach ($Values as $Key => $Value) {
                 $SaveValues['Plugins.LocaleDeveloper.' . $Key] = $Value;
             }
             // Save the settings.
             SaveToConfig($SaveValues, '', array('RemoveEmpty' => TRUE));
             $Sender->StatusMessage = T('Your changes have been saved.');
         } elseif ($this->Form->GetFormValue('GenerateChanges')) {
             $Key = $this->Form->GetFormValue('LocalePackForChanges');
             if (!$Key) {
                 $this->Form->AddError('ValidateRequired', 'Locale Pack');
             }
             $Path = PATH_ROOT . '/locales/' . $Key;
             if (!file_exists($Path)) {
                 $this->Form->AddError('Could not find the selected locale pack.');
             }
             if ($this->Form->ErrorCount() == 0) {
                 try {
                     $LocaleModel->GenerateChanges($Path, $this->LocalePath);
                     $Sender->StatusMessage = T('Your changes have been saved.');
                 } catch (Exception $Ex) {
                     $this->Form->AddError($Ex);
                 }
             }
         } elseif ($this->Form->GetFormValue('Copy')) {
             $Key = $this->Form->GetFormValue('LocalePackForCopy');
             if (!$Key) {
                 $this->Form->AddError('ValidateRequired', 'Locale Pack');
             }
             $Path = PATH_ROOT . '/locales/' . $Key;
             if (!file_exists($Path)) {
                 $this->Form->AddError('Could not find the selected locale pack.');
             }
             if ($this->Form->ErrorCount() == 0) {
                 try {
                     $LocaleModel->CopyDefinitions($Path, $this->LocalePath . '/copied.php');
                     $Sender->StatusMessage = T('Your changes have been saved.');
                 } catch (Exception $Ex) {
                     $this->Form->AddError($Ex);
                 }
             }
         } elseif ($this->Form->GetFormValue('Remove')) {
             $Files = SafeGlob($this->LocalePath . '/*');
             foreach ($Files as $File) {
                 $Result = unlink($File);
                 if (!$Result) {
                     $this->Form->AddError('@' . sprintf(T('Could not remove %s.'), $File));
                 }
             }
             if ($this->Form->ErrorCount() == 0) {
                 $Sender->StatusMessage = T('Your changes have been saved.');
             }
         }
     } else {
         $Values = C('Plugins.LocaleDeveloper');
         foreach ($Values as $Key => $Value) {
             $this->Form->SetFormValue($Key, $Value);
         }
     }
     $Sender->SetData('LocalePath', $this->LocalePath);
     $Sender->Render('', '', 'plugins/LocaleDeveloper');
 }