getWorkingLanguages() public static method

Get all possible working languages
public static getWorkingLanguages ( ) : array
return array
Ejemplo n.º 1
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     if ($this->getParameter('id') != null) {
         // get the translation
         $translation = BackendLocaleModel::get($this->getParameter('id', 'int'));
         // if not empty, set the filter
         if (!empty($translation)) {
             // we are copying the given translation
             $isCopy = true;
         } else {
             $this->redirect(BackendModel::createURLForAction('Index') . '&error=non-existing' . $this->filterQuery);
         }
     } else {
         $isCopy = false;
     }
     // create form
     $this->frm = new BackendForm('add', BackendModel::createURLForAction() . $this->filterQuery);
     // create and add elements
     $this->frm->addDropdown('application', array('Backend' => 'Backend', 'Frontend' => 'Frontend'), $isCopy ? $translation['application'] : $this->filter['application']);
     $this->frm->addDropdown('module', BackendModel::getModulesForDropDown(), $isCopy ? $translation['module'] : $this->filter['module']);
     $this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $isCopy ? $translation['type'] : $this->filter['type'][0]);
     $this->frm->addText('name', $isCopy ? $translation['name'] : $this->filter['name']);
     $this->frm->addTextarea('value', $isCopy ? $translation['value'] : $this->filter['value'], null, null, true);
     $this->frm->addDropdown('language', BL::getWorkingLanguages(), $isCopy ? $translation['language'] : $this->filter['language'][0]);
 }
Ejemplo n.º 2
0
 /**
  * Execute the action
  * We will build the classname, require the class and call the execute method.
  */
 public function execute()
 {
     $this->loadConfig();
     // is the requested action available? If not we redirect to the error page.
     if (!$this->config->isActionAvailable($this->action)) {
         // build the url
         $errorUrl = '/' . NAMED_APPLICATION . '/' . $this->get('request')->getLocale() . '/error?type=action-not-allowed';
         // redirect to the error page
         return $this->redirect($errorUrl, 307);
     }
     // build action-class
     $actionClass = 'Backend\\Modules\\' . $this->getModule() . '\\Actions\\' . $this->getAction();
     if ($this->getModule() == 'Core') {
         $actionClass = 'Backend\\Core\\Actions\\' . $this->getAction();
     }
     if (!class_exists($actionClass)) {
         throw new Exception('The class ' . $actionClass . ' could not be found.');
     }
     // get working languages
     $languages = BackendLanguage::getWorkingLanguages();
     $workingLanguages = array();
     // loop languages and build an array that we can assign
     foreach ($languages as $abbreviation => $label) {
         $workingLanguages[] = array('abbr' => $abbreviation, 'label' => $label, 'selected' => $abbreviation == BackendLanguage::getWorkingLanguage());
     }
     // assign the languages
     $this->tpl->assign('workingLanguages', $workingLanguages);
     // create action-object
     /** @var $object BackendBaseAction */
     $object = new $actionClass($this->getKernel());
     $this->getContainer()->get('logger')->info("Executing backend action '{$object->getAction()}' for module '{$object->getModule()}'.");
     $object->execute();
     return $object->getContent();
 }
Ejemplo n.º 3
0
 /**
  * Load the form
  */
 private function loadForm()
 {
     $this->frm = new BackendForm('edit', BackendModel::createURLForAction(null, null, null, array('id' => $this->id)) . $this->filterQuery);
     $this->frm->addDropdown('application', array('Backend' => 'Backend', 'Frontend' => 'Frontend'), $this->record['application']);
     $this->frm->addDropdown('module', BackendModel::getModulesForDropDown(), $this->record['module']);
     $this->frm->addDropdown('type', BackendLocaleModel::getTypesForDropDown(), $this->record['type']);
     $this->frm->addText('name', $this->record['name']);
     $this->frm->addTextarea('value', $this->record['value'], null, null, true);
     $this->frm->addDropdown('language', BL::getWorkingLanguages(), $this->record['language']);
 }
Ejemplo n.º 4
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 (rawurlencode($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);
     }
 }
Ejemplo n.º 5
0
 /**
  * @param string $language
  *
  * @throws Exception If the provided language is not valid
  */
 public function setLanguage($language)
 {
     // get the possible languages
     $possibleLanguages = BackendLanguage::getWorkingLanguages();
     // validate
     if (!array_key_exists($language, $possibleLanguages)) {
         throw new Exception('Language invalid.');
     }
     // set working language
     BackendLanguage::setWorkingLanguage($language);
 }
Ejemplo n.º 6
0
 /**
  * Get all possible working languages
  *
  * @deprecated
  *
  * @return array
  */
 public static function getWorkingLanguages()
 {
     trigger_error('Backend\\Core\\Engine\\Language is deprecated.
          It has been moved to Backend\\Core\\Language\\Language', E_USER_DEPRECATED);
     return parent::getWorkingLanguages();
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 protected function getPossibleLanguages()
 {
     return Language::getWorkingLanguages();
 }
Ejemplo n.º 8
0
 /**
  * Process the querystring
  */
 private function processQueryString()
 {
     // store the querystring local, so we don't alter it.
     $queryString = $this->getQueryString();
     // find the position of ? (which separates real URL and GET-parameters)
     $positionQuestionMark = mb_strpos($queryString, '?');
     // separate the GET-chunk from the parameters
     $getParameters = '';
     if ($positionQuestionMark === false) {
         $processedQueryString = $queryString;
     } else {
         $processedQueryString = mb_substr($queryString, 0, $positionQuestionMark);
         $getParameters = mb_substr($queryString, $positionQuestionMark);
     }
     // split into chunks, a Backend URL will always look like /<lang>/<module>/<action>(?GET)
     $chunks = (array) explode('/', trim($processedQueryString, '/'));
     // check if this is a request for a AJAX-file
     $isAJAX = isset($chunks[1]) && $chunks[1] == 'ajax';
     // get the language, this will always be in front
     $language = '';
     if (isset($chunks[1]) && $chunks[1] != '') {
         $language = \SpoonFilter::getValue($chunks[1], array_keys(BackendLanguage::getWorkingLanguages()), '');
     }
     // no language provided?
     if ($language == '' && !$isAJAX) {
         // remove first element
         array_shift($chunks);
         // redirect to login
         $this->redirect('/' . NAMED_APPLICATION . '/' . SITE_DEFAULT_LANGUAGE . (empty($chunks) ? '' : '/') . implode('/', $chunks) . $getParameters);
     }
     // get the module, null will be the default
     $module = isset($chunks[2]) && $chunks[2] != '' ? $chunks[2] : 'Dashboard';
     $module = \SpoonFilter::toCamelCase($module);
     // get the requested action, if it is passed
     if (isset($chunks[3]) && $chunks[3] != '') {
         $action = \SpoonFilter::toCamelCase($chunks[3]);
     } elseif (!$isAJAX) {
         // Check if we can load the config file
         $configClass = 'Backend\\Modules\\' . $module . '\\Config';
         if ($module == 'Core') {
             $configClass = 'Backend\\Core\\Config';
         }
         try {
             // when loading a backend url for a module that doesn't exist, without
             // providing an action, a FatalErrorException occurs, because the config
             // class we're trying to load doesn't exist. Let's just throw instead,
             // and catch it immediately.
             if (!class_exists($configClass)) {
                 throw new Exception('The config class does not exist');
             }
             /** @var BackendBaseConfig $config */
             $config = new $configClass($this->getKernel(), $module);
             // set action
             $action = $config->getDefaultAction() !== null ? $config->getDefaultAction() : 'Index';
         } catch (Exception $ex) {
             if (BackendModel::getContainer()->getParameter('kernel.debug')) {
                 throw new Exception('The config file for the module (' . $module . ') can\'t be found.');
             } else {
                 // @todo    don't use redirects for error, we should have something like an invoke method.
                 // build the url
                 $errorUrl = '/' . NAMED_APPLICATION . '/' . $language . '/error?type=action-not-allowed';
                 // add the querystring, it will be processed by the error-handler
                 $errorUrl .= '&querystring=' . rawurlencode('/' . $this->getQueryString());
                 // redirect to the error page
                 $this->redirect($errorUrl, 307);
             }
         }
     }
     // AJAX parameters are passed via GET or POST
     if ($isAJAX) {
         $module = isset($_GET['fork']['module']) ? $_GET['fork']['module'] : '';
         $action = isset($_GET['fork']['action']) ? $_GET['fork']['action'] : '';
         $language = isset($_GET['fork']['language']) ? $_GET['fork']['language'] : SITE_DEFAULT_LANGUAGE;
         $module = isset($_POST['fork']['module']) ? $_POST['fork']['module'] : $module;
         $action = isset($_POST['fork']['action']) ? $_POST['fork']['action'] : $action;
         $language = isset($_POST['fork']['language']) ? $_POST['fork']['language'] : $language;
         $this->setModule($module);
         $this->setAction($action);
         BackendLanguage::setWorkingLanguage($language);
     } else {
         $this->processRegularRequest($module, $action, $language);
     }
 }
Ejemplo n.º 9
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 = ucfirst(\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;
 }
Ejemplo n.º 10
0
 /**
  * Set language
  *
  * @param string $value The language to load.
  *
  * @throws Exception
  */
 public function setLanguage($value)
 {
     // get the possible languages
     $possibleLanguages = BackendLanguage::getWorkingLanguages();
     // validate
     if (!array_key_exists($value, $possibleLanguages)) {
         throw new Exception('Invalid language.');
     }
     // set property
     $this->language = $value;
     // set the locale (we need this for the labels)
     BackendLanguage::setLocale($this->language);
     // set working language
     BackendLanguage::setWorkingLanguage($this->language);
 }