getLanguages() public static method

Get languages from the XML files.
public static getLanguages ( string $dir = null ) : array
$dir string
return array
Example #1
0
 /**
  * Install command
  *
  * @return void
  */
 protected function install()
 {
     if (!is_writable(PH_CLI_ROOT . '/config.php')) {
         echo '  The configuration file is not writable. Please make it writable before continuing.' . PHP_EOL . PHP_EOL;
     } else {
         // Install config file and database
         $input = array('language' => null, 'db_adapter' => null, 'db_name' => null, 'db_username' => null, 'db_password' => null, 'db_host' => defined('DB_HOST') && DB_HOST != '' ? DB_HOST : 'localhost', 'db_prefix' => defined('DB_PREFIX') && DB_HOST != '' ? DB_PREFIX : 'ph_', 'app_uri' => defined('APP_URI') ? APP_URI : '/phire', 'content_path' => defined('CONTENT_PATH') ? CONTENT_PATH : '/phire-content', 'password_encryption' => 4);
         $langs = \Pop\I18n\I18n::getLanguages();
         $langKeys = array_keys($langs);
         $langsList = null;
         $i = 1;
         foreach ($langs as $key => $value) {
             $num = $i < 10 ? ' ' . $i : $i;
             $langsList .= '  ' . $num . ' : [' . $key . '] ' . $value . PHP_EOL;
             $i++;
         }
         $db = array('Mysqli', 'Pdo\\Mysql', 'Pdo\\Pgsql', 'Pdo\\Sqlite', 'Pgsql', 'Sqlite');
         echo 'Installation' . PHP_EOL;
         echo '------------' . PHP_EOL;
         echo PHP_EOL;
         echo '  Select Language:' . PHP_EOL . PHP_EOL;
         echo $langsList . PHP_EOL;
         echo PHP_EOL;
         $inputLang = -1;
         while (!isset($langKeys[$inputLang])) {
             $inputLang = self::cliInput('  Enter Language # (Enter for English): ');
             if (empty($inputLang)) {
                 $inputLang = 3;
             } else {
                 $inputLang--;
             }
         }
         $input['language'] = $langKeys[$inputLang];
         echo PHP_EOL . '  Select DB Adapter:' . PHP_EOL . PHP_EOL;
         foreach ($db as $key => $value) {
             echo '  ' . ($key + 1) . ' : ' . $value . PHP_EOL;
         }
         echo PHP_EOL;
         $inputDb = -1;
         while (!isset($db[$inputDb])) {
             $inputDb = self::cliInput('  Enter DB Adapter #: ');
             $inputDb--;
         }
         $input['db_adapter'] = $db[$inputDb];
         if (stripos($input['db_adapter'], 'sqlite') === false) {
             $input['db_name'] = self::cliInput('  DB Name: ');
             $input['db_username'] = self::cliInput('  DB Username: '******'db_password'] = self::cliInput('  DB Password: '******'  DB Host (Enter for \'' . $input['db_host'] . '\'): ');
             $input['db_host'] = empty($inputHost) ? 'localhost' : $inputHost;
         }
         $inputPrefix = self::cliInput('  DB Prefix (Enter for \'' . $input['db_prefix'] . '\'): ');
         $input['db_prefix'] = empty($inputPrefix) ? $input['db_prefix'] : $inputPrefix;
         $inputAppUri = self::cliInput('  Application URI (Enter for \'' . $input['app_uri'] . '\'): ');
         $input['app_uri'] = empty($inputAppUri) ? $input['app_uri'] : $inputAppUri;
         $inputContentPath = self::cliInput('  Content Path (Enter for \'' . $input['content_path'] . '\'): ');
         $input['content_path'] = empty($inputContentPath) ? $input['content_path'] : $inputContentPath;
         // Check the content directory
         if (!file_exists(PH_CLI_ROOT . $input['content_path'])) {
             echo PHP_EOL . '  The content directory does not exist.' . PHP_EOL . PHP_EOL;
             exit;
         } else {
             $checkDirs = Project::checkDirs(PH_CLI_ROOT . $input['content_path'], true);
             if (count($checkDirs) > 0) {
                 echo PHP_EOL . '  The content directory (or subdirectories) are not writable.' . PHP_EOL . PHP_EOL;
                 exit;
             }
         }
         echo PHP_EOL . '  ...Checking Database...';
         if (stripos($input['db_adapter'], 'sqlite') === false) {
             $oldError = ini_get('error_reporting');
             error_reporting(E_ERROR);
             $dbCheck = \Pop\Project\Install\Dbs::check(array('database' => $input['db_name'], 'username' => $input['db_username'], 'password' => $input['db_password'], 'host' => $input['db_host'], 'type' => str_replace('\\', '_', $input['db_adapter'])));
             error_reporting($oldError);
             if (null != $dbCheck) {
                 echo PHP_EOL . PHP_EOL . '  ' . wordwrap($dbCheck, 70, PHP_EOL . '  ') . PHP_EOL . PHP_EOL;
                 echo '  Please try again.' . PHP_EOL . PHP_EOL;
                 exit;
             }
         }
         echo '..OK!' . PHP_EOL . '  ...Installing Database...';
         $install = $install = new Model\Install();
         $install->config(new \ArrayObject($input, \ArrayObject::ARRAY_AS_PROPS), realpath(PH_CLI_ROOT));
         // Install initial user
         echo 'OK!' . PHP_EOL . PHP_EOL . '  Initial User Setup:' . PHP_EOL . PHP_EOL;
         $user = array('email' => null, 'username' => null, 'password' => null);
         $email = '';
         $username = '';
         $password = '';
         $emailValidator = new \Pop\Validator\Email();
         $usernameValidator = new \Pop\Validator\AlphaNumeric();
         while (!$emailValidator->evaluate($email)) {
             $email = self::cliInput('  Enter User Email: ');
         }
         while (strlen($username) < 4 || !$usernameValidator->evaluate($username)) {
             $username = self::cliInput('  Enter Username (> 4 characters): ');
         }
         while (strlen($password) < 6) {
             $password = self::cliInput('  Enter Password (> 6 characters): ');
         }
         $user['email'] = $email;
         $user['username'] = $username;
         $user['password'] = $password;
         echo PHP_EOL . '  ...Saving Initial User...' . PHP_EOL . PHP_EOL;
         if (stripos($input['db_adapter'], 'Pdo') !== false) {
             $dbInterface = 'Pdo';
             $dbType = substr($input['db_adapter'], strpos($input['db_adapter'], '\\') + 1);
         } else {
             $dbInterface = $input['db_adapter'];
             $dbType = null;
         }
         if (stripos($input['db_adapter'], 'sqlite') !== false) {
             $input['db_name'] = PH_CLI_ROOT . $input['content_path'] . '/.htphire.sqlite';
             chmod(realpath(PH_CLI_ROOT . $input['content_path'] . '/.htphire.sqlite'), 0777);
         }
         $db = \Pop\Db\Db::factory($dbInterface, array('type' => $dbType, 'database' => $input['db_name'], 'host' => $input['db_host'], 'username' => $input['db_username'], 'password' => $input['db_password']));
         $db->adapter()->query("INSERT INTO " . $input['db_prefix'] . "users (type_id, role_id, username, password, email, verified, failed_attempts, site_ids, created) VALUES (2001, 3001, '" . $user['username'] . "', '" . Model\User::encryptPassword($user['password'], 4) . "', '" . $user['email'] . "', 1, 0, '" . serialize(array(0)) . "', '" . date('Y-m-d H:i:s') . "')");
         $db->adapter()->query('UPDATE ' . $input['db_prefix'] . 'config SET value = \'' . $user['email'] . '\' WHERE setting = \'system_email\'');
     }
 }
Example #2
0
 /**
  * Get configuration values
  *
  * @return void
  */
 public function getAll()
 {
     $cfg = Table\Config::getConfig();
     $config = array();
     $formattedConfig = array();
     foreach ($cfg->rows as $c) {
         $config[$c->setting] = $c->setting == 'media_allowed_types' || $c->setting == 'media_actions' ? $value = unserialize($c->value) : $c->value;
     }
     $sysVersion = $config['system_version'];
     $latest = '';
     $handle = fopen('http://update.phirecms.org/system/version', 'r');
     if ($handle !== false) {
         $latest = trim(stream_get_contents($handle));
         fclose($handle);
     }
     if (version_compare(\Phire\Project::VERSION, $latest) < 0 && $this->data['acl']->isAuth('Phire\\Controller\\Phire\\Config\\IndexController', 'update')) {
         $sysVersion .= ' (<a href="' . BASE_PATH . APP_URI . '/config/update">' . $this->i18n->__('Update to') . ' ' . $latest . '</a>?)';
     }
     // Set server config settings
     $formattedConfig['server'] = array('system_version' => $sysVersion, 'system_domain' => $config['system_domain'], 'system_document_root' => $config['system_document_root'], 'system_base_path' => BASE_PATH, 'system_application_path' => APP_PATH, 'system_content_path' => CONTENT_PATH, 'server_operating_system' => $config['server_operating_system'], 'server_software' => $config['server_software'], 'database_version' => $config['database_version'], 'php_version' => $config['php_version'], 'installed_on' => date($this->config->datetime_format, strtotime($config['installed_on'])), 'updated_on' => $config['updated_on'] != '0000-00-00 00:00:00' ? date($this->config->datetime_format, strtotime($config['updated_on'])) : '(' . $this->i18n->__('Never') . ')');
     // Set site title form element
     $siteTitle = new Element('text', 'site_title', $config['site_title']);
     $siteTitle->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;');
     // Set system title form element
     $systemTitle = new Element('text', 'system_title', $config['system_title']);
     $systemTitle->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;');
     // Set system email form element
     $systemEmail = new Element('text', 'system_email', $config['system_email']);
     $systemEmail->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;');
     // Set system email form element
     $replyEmail = new Element('text', 'reply_email', $config['reply_email']);
     $replyEmail->setAttributes('size', 85)->setAttributes('style', 'padding: 5px;');
     // Set separator form element
     $separator = new Element('text', 'separator', $config['separator']);
     $separator->setAttributes('size', 3)->setAttributes('style', 'padding: 5px;');
     // Set default language form element
     $langs = I18n::getLanguages();
     foreach ($langs as $key => $value) {
         $langs[$key] = substr($value, 0, strpos($value, ' ('));
     }
     $lang = new Element\Select('default_language', $langs, $config['default_language'], '                    ');
     // Set date and time format form element
     $datetime = $this->getDateTimeFormat($config['datetime_format']);
     // Set max media size form element
     $maxSize = new Element('text', 'media_max_filesize', $this->getMaxSize($config['media_max_filesize']));
     $maxSize->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;');
     // Set page limit form element
     $pageLimit = new Element('text', 'pagination_limit', $config['pagination_limit']);
     $pageLimit->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;');
     // Set page range form element
     $pageRange = new Element('text', 'pagination_range', $config['pagination_range']);
     $pageRange->setAttributes('size', 10)->setAttributes('style', 'padding: 3px;');
     // Set media actions and media types form elements
     $mediaConfig = $this->getMediaConfig($config['media_actions']);
     $mediaTypes = $this->getMediaAllowedTypes($config['media_allowed_types']);
     $imageAdapters = array('Gd' => 'Gd');
     if (\Pop\Image\Imagick::isInstalled()) {
         $imageAdapters['Imagick'] = 'Imagick';
     }
     $phpLimits = array('post_max_size' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('post_max_size'))), 'upload_max_filesize' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('upload_max_filesize'))), 'max_file_uploads' => str_replace(array('M', 'K'), array(' MB', ' KB'), strtoupper(ini_get('max_file_uploads'))));
     $phpLimitsString = '';
     foreach ($phpLimits as $limit => $limitValue) {
         $phpLimitsString .= '<span style="padding: 0 5px 0 5px;">' . $this->i18n->__(ucwords(str_replace('_', ' ', $limit))) . ': ' . '<strong>' . $limitValue . '</strong></span>';
     }
     $formattedConfig['settings'] = array('site_title' => $siteTitle, 'system_title' => $systemTitle, 'system_email' => $systemEmail, 'reply_email' => $replyEmail, 'separator' => $separator, 'default_language' => $lang, 'datetime_format' => $datetime, 'media_allowed_types' => $mediaTypes, 'media_max_filesize' => '                    ' . $maxSize . ' &nbsp;&nbsp;&nbsp; [<strong style="color: #f00; padding: 0 0 0 5px;">PHP ' . $this->i18n->__('Limits') . ':</strong> ' . $phpLimitsString . ']', 'media_actions' => $mediaConfig, 'media_image_adapter' => new Element\Select('media_image_adapter', $imageAdapters, $config['media_image_adapter'], '                    '), 'pagination_limit' => '                    ' . $pageLimit, 'pagination_range' => '                    ' . $pageRange, 'force_ssl' => new Element\Radio('force_ssl', array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), $config['force_ssl'], '                    '), 'live' => new Element\Radio('live', array('1' => $this->i18n->__('Yes'), '0' => $this->i18n->__('No')), $config['live'], '                    '));
     $this->data['config'] = new \ArrayObject($formattedConfig, \ArrayObject::ARRAY_AS_PROPS);
 }
Example #3
0
 /**
  * Get the init field values
  *
  * @return array
  */
 protected function getInitFields()
 {
     $check = Version::check(Version::DATA);
     foreach ($check as $key => $value) {
         if (strpos($key, 'db') !== false) {
             if ($value == 'Yes' && stripos($key, 'sqlsrv') === false && stripos($key, 'oracle') === false) {
                 $db = str_replace('db', '', $key);
                 if (strpos($db, 'Pdo') !== false && $db != 'Pdo') {
                     $db = 'Pdo\\' . ucfirst(strtolower(str_replace('Pdo', '', $db)));
                     $this->dbAdapters[$db] = $db;
                 } else {
                     if ($db != 'Pdo') {
                         $db = ucfirst(strtolower($db));
                         if ($db != 'Mysql') {
                             $this->dbAdapters[$db] = $db;
                         }
                     }
                 }
             }
         }
     }
     $langs = I18n::getLanguages(__DIR__ . '/../../../data/assets/i18n');
     foreach ($langs as $key => $value) {
         $langs[$key] = substr($value, 0, strpos($value, ' ('));
     }
     $fields = array('language' => array('type' => 'select', 'label' => $this->i18n->__('Language'), 'value' => $langs, 'marked' => POP_LANG, 'attributes' => array('onchange' => "changeLanguage(this);", 'style' => 'width: 260px;')), 'db_adapter' => array('type' => 'select', 'label' => $this->i18n->__('DB Adapter'), 'required' => true, 'value' => $this->dbAdapters, 'attributes' => array('style' => 'width: 260px;')), 'db_name' => array('type' => 'text', 'label' => $this->i18n->__('DB Name'), 'attributes' => array('size' => 30)), 'db_username' => array('type' => 'text', 'label' => $this->i18n->__('DB Username'), 'attributes' => array('size' => 30)), 'db_password' => array('type' => 'text', 'label' => $this->i18n->__('DB Password'), 'attributes' => array('size' => 30)), 'db_host' => array('type' => 'text', 'label' => $this->i18n->__('DB Host'), 'attributes' => array('size' => 30), 'value' => 'localhost'), 'db_prefix' => array('type' => 'text', 'name' => 'db_prefix', 'label' => $this->i18n->__('DB Table Prefix'), 'attributes' => array('size' => 30), 'value' => 'ph_'), 'app_uri' => array('type' => 'text', 'label' => $this->i18n->__('Application URI') . '<br /><em style="font-size: 0.9em; color: #666; font-weight: normal;">(' . $this->i18n->__('How you will access the system') . ')</em>', 'attributes' => array('size' => 30), 'value' => APP_URI), 'content_path' => array('type' => 'text', 'label' => $this->i18n->__('Content Path') . '<br /><em style="font-size: 0.9em; color: #666; font-weight: normal;">(' . $this->i18n->__('Where assets will be located') . ')</em>', 'required' => true, 'attributes' => array('size' => 30), 'value' => CONTENT_PATH), 'password_encryption' => array('type' => 'hidden', 'value' => 4), 'submit' => array('type' => 'submit', 'label' => '&nbsp;', 'value' => $this->i18n->__('NEXT'), 'attributes' => array('class' => 'install-btn')));
     return $fields;
 }
Example #4
0
 public function testGetLanguages()
 {
     $this->assertEquals(12, count(I18n::getLanguages()));
 }
Example #5
0
     echo 'Help' . PHP_EOL;
     echo '----' . PHP_EOL;
     Install::cliHelp();
     // Else, show instructions
 } else {
     if ($argv[1] == '-s' || $argv[1] == '--show') {
         echo 'Project Install Instructions' . PHP_EOL;
         echo '----------------------------' . PHP_EOL;
         Install::instructions();
         // Else, set default project language
     } else {
         if ($argv[1] == '-l' || $argv[1] == '--lang') {
             echo 'Set Default Project Language' . PHP_EOL;
             echo '----------------------------' . PHP_EOL;
             // Create list of available languages
             $langs = I18n::getLanguages();
             $langsList = null;
             $i = 0;
             foreach ($langs as $key => $value) {
                 $num = $i < 10 ? ' ' . $i : $i;
                 $langsList .= '  ' . $num . ' : [' . $key . '] ' . $value . PHP_EOL;
                 $i++;
             }
             // Prompt user to select language
             if (isset($argv[2])) {
                 if (!array_key_exists($argv[2], $langs)) {
                     echo $langsList . PHP_EOL;
                     $lang = Install::getLanguage($langs);
                 } else {
                     $lang = $argv[2];
                 }