Example #1
0
 private static function getLangvarsByPrefix($prefix, $lang_code = CART_LANGUAGE)
 {
     if (class_exists('Tygh\\Languages\\Values')) {
         return LanguageValues::getLangVarsByPrefix($prefix, $lang_code);
     } else {
         return fn_get_lang_vars_by_prefix($prefix, $lang_code);
     }
 }
Example #2
0
 /**
  * Creates PO file for specified Language
  *
  * @param string $lang_code 2-letters language code (Example: "en", "ru")
  * @param string $output    Output destination
  *      screen - Output countent direct to browser page
  *      download - Force file downloading
  *      server - upload file to the config.dir.lang_packs directory
  */
 public static function export($lang_code, $output = 'download')
 {
     $mve_lang_variables = array();
     // Translation packs should not include "Not translated" language data
     $allow_overlap = $lang_code == 'en' ? true : false;
     $default_lang = Registry::get('settings.Appearance.backend_default_language');
     $langs = self::get(array('lang_code' => $lang_code));
     $lang = $langs[$lang_code];
     $pack_path = fn_get_cache_path(false) . 'lang_pack/';
     $core_pack_path = $pack_path . 'core.po';
     $mve_pack_path = $pack_path . 'editions/mve.po';
     fn_rm($pack_path);
     fn_mkdir($pack_path);
     if (fn_allowed_for('MULTIVENDOR') && is_file(Registry::get('config.dir.lang_packs') . $default_lang . '/editions/mve.po')) {
         $mve_lang_variables = Po::getValues(Registry::get('config.dir.lang_packs') . $default_lang . '/editions/mve.po');
         Po::createHeader($mve_pack_path, $lang);
     }
     Po::createHeader($core_pack_path, $lang);
     // Export Language values
     list($values) = LanguageValues::getVariables(array(), 0, $lang_code);
     foreach ($values as $_id => $value) {
         $values[$_id]['msgctxt'] = 'Languages' . \I18n_Pofile::DELIMITER . $value['name'];
     }
     $values = fn_array_value_to_key($values, 'msgctxt');
     $addons_lang_vars = array();
     list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code);
     foreach ($addons as $addon_id => $addon) {
         $addons_lang_vars = array_merge($addons_lang_vars, self::exportAddonsPo($addon_id, $pack_path . 'addons/' . $addon_id . '.po', $lang_code, $values));
     }
     $original_values = self::getOriginalValues('Languages');
     $values = array_diff_key($values, $addons_lang_vars);
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['Languages::' . $value['name']]) ? $original_values['Languages::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array(), $allow_overlap);
     list($values, $excluded) = self::excludeEditionVariables('Languages', $values, $mve_lang_variables);
     Po::putValues('Languages', $values, $core_pack_path);
     if (!empty($excluded)) {
         Po::putValues('Languages', $excluded, $mve_pack_path);
     }
     // Export Settings Sections
     $sections = Settings::instance()->getCoreSections($lang_code);
     $original_values = self::getOriginalValues('SettingsSections');
     foreach ($sections as $_id => $value) {
         $sections[$_id]['original_value'] = isset($original_values['SettingsSections::' . $value['section_id']]) ? $original_values['SettingsSections::' . $value['section_id']]['msgid'] : '';
     }
     $_sections = Po::convert($sections, array('id' => 'section_id', 'value' => 'description'), $allow_overlap);
     list($_sections, $excluded) = self::excludeEditionVariables('SettingsSections', $_sections, $mve_lang_variables);
     Po::putValues('SettingsSections', $_sections, $core_pack_path);
     if (!empty($excluded)) {
         Po::putValues('SettingsSections', $excluded, $mve_pack_path);
     }
     unset($_sections);
     $original_options = self::getOriginalValues('SettingsOptions');
     $original_variants = self::getOriginalValues('SettingsVariants');
     $original_tooltips = self::getOriginalValues('SettingsTooltips');
     foreach ($sections as $section) {
         $options = Settings::instance()->getList($section['object_id'], 0, false, null, $lang_code);
         $_options = array();
         $_tooltips = array();
         foreach ($options['main'] as $option) {
             $_options[] = array('name' => $option['name'], 'value' => $option['description'], 'original_value' => isset($original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_options['SettingsOptions' . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : '');
             if (!empty($option['variants'])) {
                 $_variants = array();
                 foreach ($option['variants'] as $variant_id => $variant) {
                     $_variants[] = array('name' => $variant_id, 'value' => $variant, 'original_value' => isset($original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]) ? $original_variants['SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'] . \I18n_Pofile::DELIMITER . $variant_id]['msgid'] : '');
                 }
                 $_variants = Po::convert($_variants, array(), $allow_overlap);
                 list($_variants, $excluded) = self::excludeEditionVariables('SettingsVariants', $_variants, $mve_lang_variables);
                 Po::putValues('SettingsVariants' . \I18n_Pofile::DELIMITER . $option['name'], $_variants, $core_pack_path);
                 if (!empty($excluded)) {
                     Po::putValues('SettingsVariants', $excluded, $mve_pack_path);
                 }
                 unset($_variants);
             }
             if (!empty($option['tooltip'])) {
                 $_tooltips[] = array('name' => $option['name'], 'value' => $option['tooltip'], 'original_value' => isset($original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $option['name']]) ? $original_tooltips['SettingsTooltips' . \I18n_Pofile::DELIMITER . $option['name']]['msgid'] : '');
             }
         }
         $_options = Po::convert($_options, array(), $allow_overlap);
         list($_options, $excluded) = self::excludeEditionVariables('SettingsOptions', $_options, $mve_lang_variables);
         Po::putValues('SettingsOptions', $_options, $core_pack_path);
         if (!empty($excluded)) {
             Po::putValues('SettingsOptions', $excluded, $mve_pack_path);
         }
         $_tooltips = Po::convert($_tooltips, array(), $allow_overlap);
         list($_tooltips, $excluded) = self::excludeEditionVariables('SettingsTooltips', $_tooltips, $mve_lang_variables);
         Po::putValues('SettingsTooltips', $_tooltips, $core_pack_path);
         if (!empty($excluded)) {
             Po::putValues('SettingsTooltips', $excluded, $mve_pack_path);
         }
     }
     // Export Profile fields
     $profile_fields = fn_get_profile_fields('ALL', array(), $lang_code);
     $original_values = self::getOriginalValues('ProfileFields');
     $values = array();
     foreach ($profile_fields as $zone => $fields) {
         foreach ($fields as $field_id => $field) {
             $values[] = array('name' => $field['field_name'], 'value' => $field['description'], 'original_value' => isset($original_values['ProfileFields::' . $field['field_name']]) ? $original_values['ProfileFields::' . $field['field_name']]['msgid'] : '');
         }
     }
     $values = Po::convert($values, array(), $allow_overlap);
     list($values, $excluded) = self::excludeEditionVariables('ProfileFields', $values, $mve_lang_variables);
     Po::putValues('ProfileFields', $values, $core_pack_path);
     if (!empty($excluded)) {
         Po::putValues('ProfileFields', $excluded, $mve_pack_path);
     }
     fn_compress_files($lang_code . '.zip', './', $pack_path);
     $filename = $pack_path . $lang_code . '.zip';
     switch ($output) {
         case 'server':
             fn_copy($filename, Registry::get('config.dir.lang_packs') . $lang_code . '.zip');
             break;
         case 'download':
             fn_get_file($filename, $lang_code . '.zip');
             break;
     }
     return true;
 }
Example #3
0
 public function delete($id)
 {
     $data = array();
     $status = Response::STATUS_NOT_FOUND;
     $res = LanguageValues::deleteVariables(array($id));
     if ($res) {
         $status = Response::STATUS_OK;
         $data['message'] = 'Ok';
     }
     return array('status' => $status, 'data' => $data);
 }
Example #4
0
/**
 * @deprecated
 */
function fn_get_language_variables($params, $items_per_page = 0, $lang_code = DESCR_SL)
{
    return LanguageValues::getVariables($params, $items_per_page, $lang_code);
}
Example #5
0
/**
 * @deprecated
 */
function fn_update_lang_var($lang_data, $lang_code = DESCR_SL, $params = array())
{
    return LanguageValues::updateLangVar($lang_data, $lang_code, $params);
}
Example #6
0
 /**
  * Creates PO file for specified Language
  *
  * @param string $lang_code 2-letters language code (Example: "en", "ru")
  * @param string $output    Output destination
  *      screen - Output countent direct to browser page
  *      download - Force file downloading
  *      server - upload file to the config.dir.lang_packs directory
  * @param string $output_file Default name is $lang_code . '.po'
  */
 public static function createPoFile($lang_code, $output = 'download', $output_file = '')
 {
     // Translation packs should not include "Not translated" language data
     $allow_overlap = $lang_code == 'en' ? true : false;
     $filename = fn_create_temp_file();
     if (empty($output_file)) {
         $output_file = $lang_code . '.po';
     }
     $langs = self::get(array('lang_code' => $lang_code));
     $lang = $langs[$lang_code];
     Po::createHeader($filename, $lang);
     // Export Language values
     list($values) = LanguageValues::getVariables(array(), 0, $lang_code);
     $original_values = self::getOriginalValues('Languages');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['Languages::' . $value['name']]) ? $original_values['Languages::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Languages', $values, $filename);
     // Export "SettingsVariants"
     $values = Settings::instance()->getVariants('', '', '', 'all', $lang_code);
     $original_values = self::getOriginalValues('SettingsVariants');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsVariants::' . $_id]) ? $original_values['SettingsVariants::' . $_id]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => '%key'), $allow_overlap);
     Po::putValues('SettingsVariants', $values, $filename);
     // Export Settings Sections
     $values = Settings::instance()->getCoreSections($lang_code);
     $original_values = self::getOriginalValues('SettingsSections');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsSections::' . $value['section_id']]) ? $original_values['SettingsSections::' . $value['section_id']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'section_id', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsSections', $values, $filename);
     // Export Settings Options
     $values = Settings::instance()->getList(0, 0, true, null, $lang_code);
     $original_values = self::getOriginalValues('SettingsOptions');
     foreach ($values as $_id => $value) {
         $values[$_id]['original_value'] = isset($original_values['SettingsOptions::' . $value['name']]) ? $original_values['SettingsOptions::' . $value['name']]['msgid'] : '';
     }
     $values = Po::convert($values, array('id' => 'name', 'value' => 'description'), $allow_overlap);
     Po::putValues('SettingsOptions', $values, $filename);
     // Export Addons data (name, description)
     list($addons) = fn_get_addons(array('type' => 'installed'), 0, $lang_code);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['name'], 'original_value' => $addon['originals']['name']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('Addon', $values, $filename);
     $values = array();
     foreach ($addons as $addon_id => $addon) {
         $values[] = array('name' => $addon_id, 'value' => $addon['description'], 'original_value' => $addon['originals']['description']);
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('AddonDescription', $values, $filename);
     // Export Profile fields
     $profile_fields = fn_get_profile_fields('ALL', array(), $lang_code);
     $original_values = self::getOriginalValues('ProfileFields');
     $values = array();
     foreach ($profile_fields as $zone => $fields) {
         foreach ($fields as $field_id => $field) {
             $values[] = array('name' => $field['field_name'], 'value' => $field['description'], 'original_value' => isset($original_values['ProfileFields::' . $field['field_name']]) ? $original_values['ProfileFields::' . $field['field_name']]['msgid'] : '');
         }
     }
     $values = Po::convert($values, array(), $allow_overlap);
     Po::putValues('ProfileFields', $values, $filename);
     switch ($output) {
         case 'screen':
             header("Content-type: text/plain");
             readfile($filename);
             exit;
             break;
         case 'server':
             fn_copy($filename, Registry::get('config.dir.lang_packs') . $output_file);
             break;
         case 'download':
             fn_get_file($filename, $output_file);
             break;
     }
 }
Example #7
0
 public static function restoreSettingsAndCSS($upgrade_dirs)
 {
     // Restore langvars - for all languages except EN and RU
     $languages = Lang::getLanguages();
     $except_langs = array('en', 'ru');
     foreach ($languages as $language) {
         $backup_file = $upgrade_dirs['backup_settings'] . 'lang_' . $language['lang_code'] . '.bak';
         if (!in_array($language['lang_code'], $except_langs) and file_exists($backup_file)) {
             LanguageValues::updateLangVar(unserialize(fn_get_contents($backup_file)), $language['lang_code']);
         }
     }
     // Restore blocks
     $old_company_id = Registry::get('runtime.company_id');
     foreach ($upgrade_dirs['backup_company_settings'] as $company_id => $dir) {
         Registry::set('runtime.company_id', $company_id);
         $backup_file = $dir . 'blocks.xml';
         if (file_exists($backup_file)) {
             if (version_compare(PRODUCT_VERSION, '4.1.1', '>=')) {
                 Registry::set('runtime.layout', Layout::instance()->getDefault());
             }
             Exim::instance($company_id, fn_twg_get_default_layout_id())->importFromFile($backup_file);
         }
     }
     Registry::set('runtime.company_id', $old_company_id);
     // Restore settings if addon was connected
     $restored_settings = array('my_private_key', 'my_public_key', 'his_public_key', 'email', 'customer_connections', 'admin_connection');
     $settings = array();
     foreach ($_SESSION['twigmo_backup_settings'] as $setting => $value) {
         if (in_array($setting, $restored_settings)) {
             $settings[$setting] = $value;
         }
     }
     $settings['version'] = TWIGMO_VERSION;
     unset($_SESSION['twigmo_backup_settings']);
     TwigmoSettings::set($settings);
     $connector = new TwigmoConnector();
     if (!$connector->updateConnections(true)) {
         $connector->disconnect(array(), true);
     }
     // Restore images
     self::copyFiles($upgrade_dirs['backup_files']['media_frontend'], $upgrade_dirs['installed']['media_frontend']);
     return true;
 }