getInterfaceLanguages() public static method

Get all the possible interface languages
Deprecation:
public static getInterfaceLanguages ( ) : array
return array
Beispiel #1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create form
     $this->frm = new BackendForm('add');
     // get the groups
     $groups = BackendGroupsModel::getAll();
     // if there is only one group we can check it so the user isn't bothered with an error for not selecting one
     $checkedGroups = count($groups) == 1 ? $groups[0]['value'] : null;
     // create elements
     // profile
     $this->frm->addText('email', null, 255);
     $this->frm->addPassword('password', null, 75, 'inputText inputPassword passwordGenerator', 'inputTextError inputPasswordError passwordGenerator')->setAttributes(array('autocomplete' => 'off'));
     $this->frm->addPassword('confirm_password', null, 75)->setAttributes(array('autocomplete' => 'off'));
     $this->frm->addText('name', null, 255);
     $this->frm->addText('surname', null, 255);
     $this->frm->addText('nickname', null, 24);
     $this->frm->addImage('avatar');
     $this->frm->addDropdown('interface_language', BL::getInterfaceLanguages(), $this->get('fork.settings')->get('Core', 'default_interface_language'));
     $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), BackendAuthentication::getUser()->getSetting('date_format'));
     $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), BackendAuthentication::getUser()->getSetting('time_format'));
     $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), BackendAuthentication::getUser()->getSetting('number_format', 'dot_nothing'));
     $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters());
     $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings());
     // permissions
     $this->frm->addCheckbox('active', true);
     $this->frm->addCheckbox('api_access', false);
     $this->frm->addMultiCheckbox('groups', $groups, $checkedGroups);
 }
Beispiel #2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     parent::execute();
     $isGod = BackendAuthentication::getUser()->isGod();
     // get possible languages
     if ($isGod) {
         $possibleLanguages = array_unique(array_merge(BL::getWorkingLanguages(), BL::getInterfaceLanguages()));
     } else {
         $possibleLanguages = BL::getWorkingLanguages();
     }
     // get parameters
     $language = \SpoonFilter::getPostValue('language', array_keys($possibleLanguages), null, 'string');
     $module = \SpoonFilter::getPostValue('module', BackendModel::getModules(), null, 'string');
     $name = \SpoonFilter::getPostValue('name', null, null, 'string');
     $type = \SpoonFilter::getPostValue('type', BackendModel::getContainer()->get('database')->getEnumValues('locale', 'type'), null, 'string');
     $application = \SpoonFilter::getPostValue('application', array('Backend', 'Frontend'), null, 'string');
     $value = \SpoonFilter::getPostValue('value', null, null, 'string');
     // validate values
     if (trim($value) == '' || $language == '' || $module == '' || $type == '' || $application == '' || $application == 'Frontend' && $module != 'Core') {
         $error = BL::err('InvalidValue');
     }
     // in case this is a 'act' type, there are special rules concerning possible values
     if ($type == 'act' && !isset($error)) {
         if (urlencode($value) != CommonUri::getUrl($value)) {
             $error = BL::err('InvalidActionValue', $this->getModule());
         }
     }
     // no error?
     if (!isset($error)) {
         // build item
         $item['language'] = $language;
         $item['module'] = $module;
         $item['name'] = $name;
         $item['type'] = $type;
         $item['application'] = $application;
         $item['value'] = $value;
         $item['edited_on'] = BackendModel::getUTCDate();
         $item['user_id'] = BackendAuthentication::getUser()->getUserId();
         // does the translation exist?
         if (BackendLocaleModel::existsByName($name, $type, $module, $language, $application)) {
             // add the id to the item
             $item['id'] = (int) BackendLocaleModel::getByName($name, $type, $module, $language, $application);
             // update in db
             BackendLocaleModel::update($item);
         } else {
             // insert in db
             BackendLocaleModel::insert($item);
         }
         // output OK
         $this->output(self::OK);
     } else {
         $this->output(self::ERROR, null, $error);
     }
 }
Beispiel #3
0
 /**
  * Set the locale
  */
 private function setLocale()
 {
     $default = $this->get('fork.settings')->get('Core', 'default_interface_language');
     $locale = $default;
     $possibleLocale = array_keys(Language::getInterfaceLanguages());
     // is the user authenticated
     if (Authentication::getUser()->isAuthenticated()) {
         $locale = Authentication::getUser()->getSetting('interface_language', $default);
     } elseif (CommonCookie::exists('interface_language')) {
         // no authenticated user, but available from a cookie
         $locale = CommonCookie::get('interface_language');
     }
     // validate if the requested locale is possible
     if (!in_array($locale, $possibleLocale)) {
         $locale = $default;
     }
     Language::setLocale($locale);
 }
Beispiel #4
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     // create user objects
     $this->user = new BackendUser($this->id);
     $this->allowUserRights = BackendAuthentication::isAllowedAction('Add') || $this->authenticatedUser->getUserId() != $this->id || $this->authenticatedUser->isGod();
     // redirect to error page when not allowed to edit other profiles
     if (!$this->authenticatedUser->isGod() && ($this->authenticatedUser->getUserId() != $this->id && !BackendAuthentication::isAllowedAction('Add'))) {
         $this->redirect(BackendModel::createURLForAction('Error') . '&type=not-allowed');
     }
     // create form
     $this->frm = new BackendForm('edit');
     // get active groups
     $groups = BackendGroupsModel::getGroupsByUser($this->id);
     // loop through groups and set checked
     foreach ($groups as $group) {
         $checkedGroups[] = $group['id'];
     }
     // create elements
     // profile
     $this->frm->addText('email', $this->record['email'], 255);
     if ($this->user->isGod()) {
         $this->frm->getField('email')->setAttributes(array('disabled' => 'disabled'));
     }
     $this->frm->addText('name', $this->record['settings']['name'], 255);
     $this->frm->addText('surname', $this->record['settings']['surname'], 255);
     $this->frm->addText('nickname', $this->record['settings']['nickname'], 24);
     $this->frm->addImage('avatar');
     // password
     // check if we're god or same user
     if ($this->authenticatedUser->getUserId() == $this->id || $this->authenticatedUser->isGod()) {
         // allow to set new password
         $this->frm->addPassword('new_password', null, 75);
         $this->frm->addPassword('confirm_password', null, 75);
         // disable autocomplete
         $this->frm->getField('new_password')->setAttributes(array('autocomplete' => 'off'));
         $this->frm->getField('confirm_password')->setAttributes(array('autocomplete' => 'off'));
     }
     // settings
     $this->frm->addDropdown('interface_language', BL::getInterfaceLanguages(), $this->record['settings']['interface_language']);
     $this->frm->addDropdown('date_format', BackendUsersModel::getDateFormats(), $this->user->getSetting('date_format'));
     $this->frm->addDropdown('time_format', BackendUsersModel::getTimeFormats(), $this->user->getSetting('time_format'));
     $this->frm->addDropdown('number_format', BackendUsersModel::getNumberFormats(), $this->user->getSetting('number_format', 'dot_nothing'));
     $this->frm->addDropDown('csv_split_character', BackendUsersModel::getCSVSplitCharacters(), $this->user->getSetting('csv_split_character'));
     $this->frm->addDropDown('csv_line_ending', BackendUsersModel::getCSVLineEndings(), $this->user->getSetting('csv_line_ending'));
     // permissions
     $this->frm->addCheckbox('active', $this->record['active'] == 'Y');
     // only when GOD or when you can edit other users
     if ($this->allowUserRights) {
         // disable active field for current users
         if ($this->authenticatedUser->getUserId() == $this->record['id']) {
             $this->frm->getField('active')->setAttribute('disabled', 'disabled');
         }
         $this->frm->addCheckbox('api_access', isset($this->record['settings']['api_access']) && $this->record['settings']['api_access'] == 'Y');
         $this->frm->addMultiCheckbox('groups', BackendGroupsModel::getAll(), $checkedGroups);
     }
 }
Beispiel #5
0
 /**
  * Import a locale XML file.
  *
  * @param \SimpleXMLElement $xml                The locale XML.
  * @param bool              $overwriteConflicts Should we overwrite when there is a conflict?
  * @param array             $frontendLanguages  The frontend languages to install locale for.
  * @param array             $backendLanguages   The backend languages to install locale for.
  * @param int               $userId             Id of the user these translations should be inserted for.
  * @param int               $date               The date the translation has been inserted.
  * @return array The import statistics
  */
 public static function importXML(\SimpleXMLElement $xml, $overwriteConflicts = false, $frontendLanguages = null, $backendLanguages = null, $userId = null, $date = null)
 {
     $overwriteConflicts = (bool) $overwriteConflicts;
     $statistics = array('total' => 0, 'imported' => 0);
     // set defaults if necessary
     // we can't simply use these right away, because this function is also calls by the installer,
     // which does not have Backend-functions
     if ($frontendLanguages === null) {
         $frontendLanguages = array_keys(BL::getWorkingLanguages());
     }
     if ($backendLanguages === null) {
         $backendLanguages = array_keys(BL::getInterfaceLanguages());
     }
     if ($userId === null) {
         $userId = BackendAuthentication::getUser()->getUserId();
     }
     if ($date === null) {
         $date = BackendModel::getUTCDate();
     }
     // get database instance
     $db = BackendModel::getContainer()->get('database');
     // possible values
     $possibleApplications = array('Frontend', 'Backend');
     $possibleModules = (array) $db->getColumn('SELECT m.name FROM modules AS m');
     // types
     $typesShort = (array) $db->getEnumValues('locale', 'type');
     foreach ($typesShort as $type) {
         $possibleTypes[$type] = self::getTypeName($type);
     }
     // install English translations anyhow, they're fallback
     $possibleLanguages = array('Frontend' => array_unique(array_merge(array('en'), $frontendLanguages)), 'Backend' => array_unique(array_merge(array('en'), $backendLanguages)));
     // current locale items (used to check for conflicts)
     $currentLocale = (array) $db->getColumn('SELECT CONCAT(application, module, type, language, name)
          FROM locale');
     // applications
     foreach ($xml as $application => $modules) {
         // application does not exist
         if (!in_array($application, $possibleApplications)) {
             continue;
         }
         // modules
         foreach ($modules as $module => $items) {
             // module does not exist
             if (!in_array($module, $possibleModules)) {
                 continue;
             }
             // items
             foreach ($items as $item) {
                 // attributes
                 $attributes = $item->attributes();
                 $type = \SpoonFilter::getValue($attributes['type'], $possibleTypes, '');
                 $name = \SpoonFilter::getValue($attributes['name'], null, '');
                 // missing attributes
                 if ($type == '' || $name == '') {
                     continue;
                 }
                 // real type (shortened)
                 $type = array_search($type, $possibleTypes);
                 // translations
                 foreach ($item->translation as $translation) {
                     // statistics
                     $statistics['total']++;
                     // attributes
                     $attributes = $translation->attributes();
                     $language = \SpoonFilter::getValue($attributes['language'], $possibleLanguages[$application], '');
                     // language does not exist
                     if ($language == '') {
                         continue;
                     }
                     // the actual translation
                     $translation = (string) $translation;
                     // locale item
                     $locale['user_id'] = $userId;
                     $locale['language'] = $language;
                     $locale['application'] = $application;
                     $locale['module'] = $module;
                     $locale['type'] = $type;
                     $locale['name'] = $name;
                     $locale['value'] = $translation;
                     $locale['edited_on'] = $date;
                     // check if translation does not yet exist, or if the translation can be overridden
                     if (!in_array($application . $module . $type . $language . $name, $currentLocale) || $overwriteConflicts) {
                         $db->execute('INSERT INTO locale (user_id, language, application, module, type, name, value, edited_on)
                              VALUES (?, ?, ?, ?, ?, ?, ?, ?)
                              ON DUPLICATE KEY UPDATE user_id = ?, value = ?, edited_on = ?', array($locale['user_id'], $locale['language'], $locale['application'], $locale['module'], $locale['type'], $locale['name'], $locale['value'], $locale['edited_on'], $locale['user_id'], $locale['value'], $locale['edited_on']));
                         // statistics
                         $statistics['imported']++;
                     }
                 }
             }
         }
     }
     // rebuild cache
     foreach ($possibleApplications as $application) {
         foreach ($possibleLanguages[$application] as $language) {
             self::buildCache($language, $application);
         }
     }
     return $statistics;
 }
Beispiel #6
0
 /**
  * Install a module.
  *
  * @param string $module   The name of the module to be installed.
  */
 public static function installModule($module)
 {
     $class = 'Backend\\Modules\\' . $module . '\\Installer\\Installer';
     $variables = array();
     // run installer
     $installer = new $class(BackendModel::getContainer()->get('database'), BL::getActiveLanguages(), array_keys(BL::getInterfaceLanguages()), false, $variables);
     $installer->install();
     // clear the cache so locale (and so much more) gets rebuilt
     self::clearCache();
 }