availableLocalePacks() public method

public availableLocalePacks ( ) : array | null
return array | null
Example #1
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 ($TransientKey && Gdn::session()->validateTransientKey($TransientKey) || $this->Form->authenticatedPostBack()) {
         if ($Op) {
             $Refresh = false;
             switch (strtolower($Op)) {
                 case 'enable':
                     $Locale = val($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', Gdn_Locale::canonicalize(c('Garden.Locale', 'en')));
         } 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();
             redirect('/settings/locales');
         }
     } elseif (!$this->Form->isPostBack()) {
         $this->Form->setValue('Locale', Gdn_Locale::canonicalize(c('Garden.Locale', 'en')));
     }
     // Check for the default locale warning.
     $DefaultLocale = Gdn_Locale::canonicalize(c('Garden.Locale'));
     if ($DefaultLocale !== 'en') {
         $LocaleFound = false;
         $MatchingLocales = array();
         foreach ($AvailableLocales as $Key => $LocaleInfo) {
             $Locale = val('Locale', $LocaleInfo);
             if ($Locale == $DefaultLocale) {
                 $MatchingLocales[] = val('Name', $LocaleInfo, $Key);
             }
             if (val($Key, $EnabledLocales) == $DefaultLocale) {
                 $LocaleFound = true;
             }
         }
         $this->setData('DefaultLocale', $DefaultLocale);
         $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();
 }
 /**
  * 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)
 {
     $this->permission('Garden.Settings.Manage');
     $this->title(t('Locales'));
     $this->setHighlightRoute('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 ($this->Form->authenticatedPostBack() && !$Op) {
         // Save the default locale.
         saveToConfig('Garden.Locale', $this->Form->getFormValue('Locale'));
         $this->informMessage(t("Your changes have been saved."));
         Gdn::locale()->refresh();
         redirect('/settings/locales');
     } else {
         $this->Form->setValue('Locale', Gdn_Locale::canonicalize(c('Garden.Locale', 'en')));
     }
     if ($Op) {
         switch (strtolower($Op)) {
             case 'enable':
                 $this->enableLocale($LocaleKey, val($LocaleKey, $AvailableLocales), $EnabledLocales);
                 break;
             case 'disable':
                 $this->disableLocale($LocaleKey, val($LocaleKey, $AvailableLocales), $EnabledLocales);
         }
     }
     // Check for the default locale warning.
     $DefaultLocale = Gdn_Locale::canonicalize(c('Garden.Locale'));
     if ($DefaultLocale !== 'en') {
         $LocaleFound = false;
         $MatchingLocales = array();
         foreach ($AvailableLocales as $Key => $LocaleInfo) {
             $Locale = val('Locale', $LocaleInfo);
             if ($Locale == $DefaultLocale) {
                 $MatchingLocales[] = val('Name', $LocaleInfo, $Key);
             }
             if (val($Key, $EnabledLocales) == $DefaultLocale) {
                 $LocaleFound = true;
             }
         }
         $this->setData('DefaultLocale', $DefaultLocale);
         $this->setData('DefaultLocaleWarning', !$LocaleFound);
         $this->setData('MatchingLocalePacks', htmlspecialchars(implode(', ', $MatchingLocales)));
     }
     // Remove all hidden locales, unless they are enabled.
     $AvailableLocales = array_filter($AvailableLocales, function ($locale) use($EnabledLocales) {
         return !val('Hidden', $locale) || isset($EnabledLocales[val('Index', $locale)]);
     });
     $this->setData('AvailableLocales', $AvailableLocales);
     $this->setData('EnabledLocales', $EnabledLocales);
     $this->setData('Locales', $LocaleModel->availableLocales());
     $this->render();
 }