function _parse_wpml_config($config)
 {
     global $sitepress, $sitepress_settings;
     // custom fields
     if (!empty($config['wpml-config']['custom-fields'])) {
         if (!is_numeric(key(current($config['wpml-config']['custom-fields'])))) {
             $cf[0] = $config['wpml-config']['custom-fields']['custom-field'];
         } else {
             $cf = $config['wpml-config']['custom-fields']['custom-field'];
         }
         foreach ($cf as $c) {
             if ($c['attr']['action'] == 'translate') {
                 $action = 2;
             } elseif ($c['attr']['action'] == 'copy') {
                 $action = 1;
             } else {
                 $action = 0;
             }
             $this->settings['custom_fields_translation'][$c['value']] = $action;
             if (is_array($this->settings['custom_fields_readonly_config']) && !in_array($c['value'], $this->settings['custom_fields_readonly_config'])) {
                 $this->settings['custom_fields_readonly_config'][] = $c['value'];
             }
         }
     }
     // custom types
     $cf = array();
     if (!empty($config['wpml-config']['custom-types'])) {
         if (!is_numeric(key(current($config['wpml-config']['custom-types'])))) {
             $cf[0] = $config['wpml-config']['custom-types']['custom-type'];
         } else {
             $cf = $config['wpml-config']['custom-types']['custom-type'];
         }
         foreach ($cf as $c) {
             $translate = intval($c['attr']['translate']);
             if ($translate) {
                 $sitepress->verify_post_translations($c['value']);
             }
             $this->settings['custom_types_readonly_config'][$c['value']] = $translate;
             $sitepress_settings['custom_posts_sync_option'][$c['value']] = $translate;
         }
         add_filter('get_translatable_documents', array($this, '_override_get_translatable_documents'));
     }
     // taxonomies
     $cf = array();
     if (!empty($config['wpml-config']['taxonomies'])) {
         if (!is_numeric(key(current($config['wpml-config']['taxonomies'])))) {
             $cf[0] = $config['wpml-config']['taxonomies']['taxonomy'];
         } else {
             $cf = $config['wpml-config']['taxonomies']['taxonomy'];
         }
         foreach ($cf as $c) {
             // did this exist before?
             $empty_before = empty($this->settings['taxonomies_readonly_config'][$c['value']]);
             $translate = intval($c['attr']['translate']);
             $this->settings['taxonomies_readonly_config'][$c['value']] = $translate;
             $sitepress_settings['taxonomies_sync_option'][$c['value']] = $translate;
             // this has just changed. save.
             if ($translate == 1 && $empty_before) {
                 $sitepress->verify_taxonomy_translations($c['value']);
                 $this->save_settings();
             }
         }
         add_filter('get_translatable_taxonomies', array($this, '_override_get_translatable_taxonomies'));
     }
     // taxonomies - check what's been removed
     if (!empty($this->settings['taxonomies_readonly_config'])) {
         $config_values = array();
         foreach ($cf as $config_value) {
             $config_values[$config_value['value']] = $config_value['attr']['translate'];
         }
         $do_save = false;
         foreach ($this->settings['taxonomies_readonly_config'] as $tconf => $tconf_val) {
             if (empty($config_values[$tconf])) {
                 unset($this->settings['taxonomies_readonly_config'][$tconf]);
                 $do_save = true;
             }
             //else
             // {
             //    if($config_values[$tconf] != $tconf_val){
             //        $this->settings['taxonomies_readonly_config'][$tconf] = $config_values[$tconf];
             //       $do_save = true;
             //    }
             // }
         }
         if ($do_save) {
             $this->save_settings();
         }
     }
     // admin texts
     if (function_exists('icl_register_string')) {
         $admin_texts = array();
         if (!empty($config['wpml-config']['admin-texts'])) {
             if (!is_numeric(key(@current($config['wpml-config']['admin-texts'])))) {
                 $admin_texts[0] = $config['wpml-config']['admin-texts']['key'];
             } else {
                 $admin_texts = $config['wpml-config']['admin-texts']['key'];
             }
             foreach ($admin_texts as $a) {
                 if (isset($a['type'])) {
                     $type = $a['type'];
                 }
                 if (isset($a['atid'])) {
                     $atid = $a['atid'];
                 }
                 if (!isset($type)) {
                     $type = 'plugin';
                 }
                 if (!isset($atid)) {
                     $atid = '';
                 }
                 $keys = array();
                 if (!isset($a['key'])) {
                     $arr[$a['attr']['name']] = 1;
                     continue;
                 } elseif (!is_numeric(key($a['key']))) {
                     $keys[0] = $a['key'];
                 } else {
                     $keys = $a['key'];
                 }
                 foreach ($keys as $key) {
                     if (isset($key['key'])) {
                         $arr[$a['attr']['name']][$key['attr']['name']] = $this->_read_admin_texts_recursive($key['key']);
                     } else {
                         $arr[$a['attr']['name']][$key['attr']['name']] = 1;
                     }
                 }
             }
             foreach ($arr as $key => $v) {
                 // http://forum.wpml.org/topic.php?id=4888&replies=7#post-23038
                 // http://forum.wpml.org/topic.php?id=4615
                 // http://forum.wpml.org/topic.php?id=4761
                 remove_filter('option_' . $key, 'icl_st_translate_admin_string');
                 // dont try to translate this one below
                 $value = get_option($key);
                 add_filter('option_' . $key, 'icl_st_translate_admin_string');
                 // put the filter back on
                 $value = maybe_unserialize($value);
                 if (false === $value) {
                     unset($arr[$key]);
                 }
                 if (is_scalar($value)) {
                     icl_register_string('admin_texts_' . $type . '_' . $atid, $key, $value);
                 } else {
                     if (is_object($value)) {
                         $value = (array) $value;
                     }
                     if (!empty($value)) {
                         $this->_register_string_recursive($key, $value, $arr[$key], '', $type . '_' . $atid);
                     }
                 }
             }
             $this->admin_texts_to_translate = array_merge($this->admin_texts_to_translate, $arr);
             $_icl_admin_option_names = get_option('_icl_admin_option_names');
             //filter out obsolete entries
             /*
             $_as_changed = false;
             foreach($_icl_admin_option_names[$type][$atid] as $k=>$csf){
                 if(empty($arr[$csf])){
                     unset($_icl_admin_option_names[$type][$atid][$k]);    
                 }
             }
             */
             $_icl_admin_option_names[$type][$atid] = @array_merge_recursive((array) $_icl_admin_option_names[$type][$atid], $this->_array_keys_recursive($arr));
             // avoid duplicates
             /*       
             foreach($_icl_admin_option_names[$type][$atid] as $k => $v){
                 if(is_array($v)){
                     $_icl_admin_option_names[$type][$atid][$k] = array_unique($v);    
                 }
             }
             */
             $_icl_admin_option_names[$type][$atid] = __array_unique_recursive($_icl_admin_option_names[$type][$atid]);
             // __array_unique_recursive is declared in the string translation plugin inc/functions.php
             update_option('_icl_admin_option_names', $_icl_admin_option_names);
         }
     }
     // language-switcher-settings
     if (empty($sitepress_settings['language_selector_initialized']) || isset($_GET['restore_ls_settings']) && $_GET['restore_ls_settings'] == 1) {
         if (!empty($config['wpml-config']['language-switcher-settings'])) {
             if (!is_numeric(key($config['wpml-config']['language-switcher-settings']['key']))) {
                 $cfgsettings[0] = $config['wpml-config']['language-switcher-settings']['key'];
             } else {
                 $cfgsettings = $config['wpml-config']['language-switcher-settings']['key'];
             }
             $iclsettings = $this->_read_settings_recursive($cfgsettings);
             $iclsettings['language_selector_initialized'] = 1;
             $sitepress->save_settings($iclsettings);
             if (!empty($sitepress_settings['setup_complete']) && !empty($_GET['page'])) {
                 wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&icl_ls_reset=default#icl_save_language_switcher_options'));
             }
         }
     }
 }
Exemple #2
0
function __array_unique_recursive($array)
{
    $scalars = array();
    foreach ($array as $key => $value) {
        if (is_scalar($value)) {
            if (isset($scalars[$value])) {
                unset($array[$key]);
            } else {
                $scalars[$value] = true;
            }
        } elseif (is_array($value)) {
            $array[$key] = __array_unique_recursive($value);
        }
    }
    return $array;
}
 function _parse_wpml_config($file)
 {
     global $sitepress, $sitepress_settings;
     $config = icl_xml2array(file_get_contents($file));
     // custom fields
     if (!empty($config['wpml-config']['custom-fields'])) {
         if (!is_numeric(key(current($config['wpml-config']['custom-fields'])))) {
             $cf[0] = $config['wpml-config']['custom-fields']['custom-field'];
         } else {
             $cf = $config['wpml-config']['custom-fields']['custom-field'];
         }
         foreach ($cf as $c) {
             if ($c['attr']['action'] == 'translate') {
                 $action = 2;
             } elseif ($c['attr']['action'] == 'copy') {
                 $action = 1;
             } else {
                 $action = 0;
             }
             $this->settings['custom_fields_translation'][$c['value']] = $action;
             if (is_array($this->settings['custom_fields_readonly_config']) && !in_array($c['value'], $this->settings['custom_fields_readonly_config'])) {
                 $this->settings['custom_fields_readonly_config'][] = $c['value'];
             }
         }
     }
     // custom types
     $cf = array();
     if (!empty($config['wpml-config']['custom-types'])) {
         if (!is_numeric(key(current($config['wpml-config']['custom-types'])))) {
             $cf[0] = $config['wpml-config']['custom-types']['custom-type'];
         } else {
             $cf = $config['wpml-config']['custom-types']['custom-type'];
         }
         foreach ($cf as $c) {
             $translate = intval($c['attr']['translate']);
             if ($translate) {
                 $sitepress->verify_post_translations($c['value']);
             }
             $this->settings['custom_types_readonly_config'][$c['value']] = $translate;
             $sitepress_settings['custom_posts_sync_option'][$c['value']] = $translate;
         }
         add_filter('get_translatable_documents', array($this, '_override_get_translatable_documents'));
     }
     // taxonomies
     $cf = array();
     if (!empty($config['wpml-config']['taxonomies'])) {
         if (!is_numeric(key(current($config['wpml-config']['taxonomies'])))) {
             $cf[0] = $config['wpml-config']['taxonomies']['taxonomy'];
         } else {
             $cf = $config['wpml-config']['taxonomies']['taxonomy'];
         }
         foreach ($cf as $c) {
             $translate = intval($c['attr']['translate']);
             $this->settings['taxonomies_readonly_config'][$c['value']] = $translate;
             $sitepress_settings['taxonomies_sync_option'][$c['value']] = $translate;
         }
         add_filter('get_translatable_taxonomies', array($this, '_override_get_translatable_taxonomies'));
     }
     // admin texts
     if (function_exists('icl_register_string')) {
         $admin_texts = array();
         if (!empty($config['wpml-config']['admin-texts'])) {
             $type = dirname($file) == get_template_directory() || dirname($file) == get_stylesheet_directory() ? 'theme' : 'plugin';
             $atid = basename(dirname($file));
             if (!is_numeric(key(@current($config['wpml-config']['admin-texts'])))) {
                 $admin_texts[0] = $config['wpml-config']['admin-texts']['key'];
             } else {
                 $admin_texts = $config['wpml-config']['admin-texts']['key'];
             }
             foreach ($admin_texts as $a) {
                 $keys = array();
                 if (!isset($a['key'])) {
                     $arr[$a['attr']['name']] = 1;
                     continue;
                 } elseif (!is_numeric(key($a['key']))) {
                     $keys[0] = $a['key'];
                 } else {
                     $keys = $a['key'];
                 }
                 foreach ($keys as $key) {
                     if (isset($key['key'])) {
                         $arr[$a['attr']['name']][$key['attr']['name']] = $this->_read_admin_texts_recursive($key['key']);
                     } else {
                         $arr[$a['attr']['name']][$key['attr']['name']] = 1;
                     }
                 }
             }
             foreach ($arr as $key => $v) {
                 $value = get_option($key);
                 $value = maybe_unserialize($value);
                 if (false === $value) {
                     unset($arr[$key]);
                 }
                 if (is_scalar($value)) {
                     icl_register_string('admin_texts_' . $type . '_' . $atid, $key, $value);
                 } else {
                     if (is_object($value)) {
                         $value = (array) $value;
                     }
                     if (!empty($value)) {
                         $this->_register_string_recursive($key, $value, $arr[$key], '', $type . '_' . $atid);
                     }
                 }
             }
             $this->admin_texts_to_translate = array_merge($this->admin_texts_to_translate, $arr);
             $_icl_admin_option_names = get_option('_icl_admin_option_names');
             //filter out obsolete entries
             /*
             $_as_changed = false;
             foreach($_icl_admin_option_names[$type][$atid] as $k=>$csf){
                 if(empty($arr[$csf])){
                     unset($_icl_admin_option_names[$type][$atid][$k]);    
                 }
             }
             */
             $_icl_admin_option_names[$type][$atid] = @array_merge_recursive((array) $_icl_admin_option_names[$type][$atid], $this->_array_keys_recursive($arr));
             $_icl_admin_option_names[$type][$atid] = __array_unique_recursive($_icl_admin_option_names[$type][$atid]);
             // __array_unique_recursive is declared in the string translation plugin inc/functions.php
             update_option('_icl_admin_option_names', $_icl_admin_option_names);
         }
     }
     // language-switcher-settings
     if (empty($sitepress_settings['language_selector_initialized']) || isset($_GET['restore_ls_settings']) && $_GET['restore_ls_settings'] == 1) {
         if (!empty($config['wpml-config']['language-switcher-settings'])) {
             if (!is_numeric(key($config['wpml-config']['language-switcher-settings']['key']))) {
                 $cfgsettings[0] = $config['wpml-config']['language-switcher-settings']['key'];
             } else {
                 $cfgsettings = $config['wpml-config']['language-switcher-settings']['key'];
             }
             $iclsettings = $this->_read_settings_recursive($cfgsettings);
             $iclsettings['language_selector_initialized'] = 1;
             $sitepress->save_settings($iclsettings);
             if (!empty($sitepress_settings['setup_complete']) && !empty($_GET['page'])) {
                 wp_redirect(admin_url('admin.php?page=' . $_GET['page'] . '&icl_ls_reset=default#icl_save_language_switcher_options'));
             }
         }
     }
 }