public function indexAction()
 {
     $lang = $this->getRequest()->getParam('lang', false);
     $languages = array();
     foreach (new DirectoryIterator(APPLICATION_PATH . "/../languages/") as $entry) {
         if ($entry->isFile() && pathinfo($entry->getFilename(), PATHINFO_EXTENSION) == 'ini') {
             if (count(explode('.', $entry->getFilename())) == 2) {
                 $languages[$entry->getFilename()] = pathinfo($entry->getFilename(), PATHINFO_FILENAME);
             }
         }
     }
     if ($lang != false) {
         // cleanup from ./ and ../
         $lang = str_replace(array('.', '/'), '', $lang);
         if (file_exists(APPLICATION_PATH . "/../languages/{$lang}.ini") && array_key_exists("{$lang}.ini", $languages)) {
             $translation = new Zend_Translate('ini', APPLICATION_PATH . "/../languages/{$lang}.ini");
             X_Env::initTranslator($translation);
         } else {
             $this->_helper->flashMessenger(array('type' => 'error', 'text' => X_Env::_('installer_invalid_language')));
             $lang = false;
         }
     }
     $form = new Application_Form_Installer();
     $form->setAction($this->_helper->url('save', 'installer'));
     try {
         $form->lang->setMultiOptions($languages);
         $form->setDefault('lang', $lang !== false ? "{$lang}.ini" : 'en_GB.ini');
         $form->setDefault('auth', 0);
         $form->setDefault('threads', X_Env::completeUrl($this->_helper->url('start', 'threads')));
     } catch (Exception $e) {
         // WTF?
     }
     // try to read the manifest of plugins index
     $plugins = $this->getInstallablePlugins();
     try {
         $form->plugins->setMultiOptions($plugins);
     } catch (Exception $e) {
         // Connection kaboom?
     }
     $ns = new Zend_Session_Namespace('vlc-shares::installer');
     if (isset($ns->errors) && $ns->errors) {
         $form->isValid($ns->data);
         unset($ns->errors);
         unset($ns->data);
     }
     $threadsChecks = $this->_helper->url('check', 'threads');
     $threadsPing = $this->_helper->url('ping', 'threads');
     $basePing = $this->_helper->url('', 'threads');
     $httpPort = $_SERVER['SERVER_PORT'];
     $httpPort = $httpPort != '80' && $httpPort != '' ? ":{$httpPort}" : '';
     $threadsUrls = array("'http://localhost{$httpPort}{$basePing}'", "'http://127.0.0.1{$httpPort}{$basePing}'", "'http://127.0.1.1{$httpPort}{$basePing}'", "'http://192.168.1.1{$httpPort}{$basePing}'");
     $this->view->messages = array_merge($this->_helper->flashMessenger->getMessages(), $this->_helper->flashMessenger->getCurrentMessages());
     $this->_helper->flashMessenger->clearCurrentMessages();
     $this->view->languages = $languages;
     $this->view->threadsCheck = $threadsChecks;
     $this->view->threadsPing = $threadsPing;
     $this->view->threadsUrls = $threadsUrls;
     $this->view->form = $form;
 }
Exemplo n.º 2
0
 public function addTranslation($key)
 {
     $moduleName = $key . '.' . $this->lang;
     // i have to check $moduleName to be sure that the file is inside the languages/ directory
     if (file_exists(realpath(APPLICATION_PATH . "/../languages/{$moduleName}"))) {
         $translate = new Zend_Translate('ini', realpath(APPLICATION_PATH . "/../languages/{$moduleName}"));
     } elseif ($this->lang != 'en_GB.ini' && file_exists(realpath(APPLICATION_PATH . "/../languages/{$key}.en_GB.ini"))) {
         // fallback to english translation
         X_Debug::w("Language file not found: {$moduleName}. Falling back to english translation");
         $translate = new Zend_Translate('ini', realpath(APPLICATION_PATH . "/../languages/{$key}.en_GB.ini"));
     } else {
         X_Debug::w("Language file not found: {$moduleName}");
         return false;
     }
     // time to append translator to the global instance
     X_Env::initTranslator($translate);
     return true;
 }
Exemplo n.º 3
0
 protected function _initTranslation()
 {
     $this->bootstrap('configs');
     $this->bootstrap('debug');
     $configs = $this->getResource('configs');
     $translation = null;
     if ($configs instanceof Zend_Config) {
         try {
             $translation = new Zend_Translate('ini', APPLICATION_PATH . "/../languages/" . $configs->general->get('languageFile', "en_GB.ini"));
             X_Env::initTranslator($translation);
         } catch (Exception $e) {
             // no translation available
             X_Debug::e("Translation disabled: {$e->getMessage()}");
         }
     }
     return $translation;
 }