/** * @param string|object $file */ function __construct($file = "") { if (is_object($file)) { $config = $file->config; $type = $file->type; $admin_text_context = $file->admin_text_context; } elseif (is_string($file) && $file !== "" && file_exists($file)) { $config = icl_xml2array(file_get_contents($file)); $type = dirname($file) == get_template_directory() || dirname($file) == get_stylesheet_directory() ? 'theme' : 'plugin'; $admin_text_context = basename(dirname($file)); } $admin_text_config = isset($config['wpml-config']['admin-texts']) ? $config['wpml-config']['admin-texts'] : array(); $wpml_config_all = array(); if (isset($type) && isset($admin_text_context) && isset($admin_text_config['key'])) { if (isset($admin_text_config['key']['attr'])) { //single $admin_text_config['key']['type'] = $type; $admin_text_config['key']['context'] = $admin_text_context; $wpml_config_all[] = $admin_text_config['key']; } else { foreach ((array) $admin_text_config['key'] as $cf) { $cf['type'] = $type; $cf['context'] = $admin_text_context; $wpml_config_all[] = $cf; } } } $this->config = $this->fill_wildcards($wpml_config_all); }
function init() { global $sitepress_settings; $ap = get_option('active_plugins'); $i = array_intersect($ap, array_keys(self::$wpml_cpi_plugins)); if (!empty($i)) { $this->plugin_cp_class = self::$wpml_cpi_plugins[array_pop($i)]; if (class_exists($this->plugin_cp_class) && method_exists($this->plugin_cp_class, 'clear_cache')) { $this->settings = $sitepress_settings['modules']['caching-plugins-integration']; $this->validate_settings(); add_action('icl_page_overview_top', array($this, 'menu')); wp_enqueue_script('wpml-cpi-scripts', ICL_PLUGIN_URL . '/modules/cache-plugins-integration/scripts.js', array(), ICL_SITEPRESS_VERSION); add_action('icl_ajx_custom_call', array($this, 'ajx_calls'), 1, 2); add_action('icl_st_add_string_translation', array($this, 'call_cache_clear')); add_action('icl_st_unregister_string_multi', array($this, 'call_cache_clear')); add_action('icl_st_unregister_string', array($this, 'call_cache_clear')); $ajx_request_exceptions = array('ajx_health_checked', 'save_language_pairs', 'toggle_content_translation', 'icl_admin_language_options', 'icl_page_sync_options', 'validate_language_domain', 'icl_save_theme_localization_type', 'dismiss_help', 'dismiss_page_estimate_hint', 'dismiss_upgrade_notice', 'dismiss_upgrade_notice', 'dismiss_translate_help', 'setup_got_to_step1', 'setup_got_to_step2', 'toggle_show_translations', 'icl_show_sidebar'); if (!isset($_REQUEST['icl_ajx_action']) || !in_array($_REQUEST['icl_ajx_action'], $ajx_request_exceptions)) { add_action('icl_save_settings', array($this, 'icl_save_settings_cb'), 10, 1); } // when a post is sent from the translation server global $HTTP_RAW_POST_DATA; $hrow = icl_xml2array($HTTP_RAW_POST_DATA); if (isset($hrow['methodCall']['methodName']['value']) && $hrow['methodCall']['methodName']['value'] == 'icanlocalize.set_translation_status') { add_action('save_post', array($this, 'call_cache_clear')); } } } }
function request($request_url) { $results = false; $request_url = $this->get_adjusted_request_url($request_url); $this->adjust_post_data(); $this->disable_error_reporting(); $icanSnoopy = new IcanSnoopy(); if (!is_readable($icanSnoopy->curl_path) || !is_executable($icanSnoopy->curl_path)) { $icanSnoopy->curl_path = '/usr/bin/curl'; } $this->reset_error_reporting(); $icanSnoopy->_fp_timeout = 3; $icanSnoopy->read_timeout = 5; if ('GET' === $this->method) { $icanSnoopy->fetch($request_url); } else { $icanSnoopy->set_submit_multipart(); $icanSnoopy->submit($request_url, $this->post_data, $this->post_files); } if ($icanSnoopy->error || $icanSnoopy->timed_out) { $this->error = $icanSnoopy->error; } else { if ($this->gzipped) { $icanSnoopy->results = $this->gzdecode($icanSnoopy->results); } $results = icl_xml2array($icanSnoopy->results, 1); if (array_key_exists('info', $results) && '-1' === $results['info']['status']['attr']['err_code']) { $this->error = $results['info']['status']['value']; $results = false; } } return $results; }
function xmlrpc_call_actions($action) { global $HTTP_RAW_POST_DATA, $wpdb; $params = icl_xml2array($HTTP_RAW_POST_DATA); add_filter('is_protected_meta', array($this, 'xml_unprotect_wpml_meta'), 10, 3); switch ($action) { case 'wp.getPage': case 'blogger.getPost': // yet this doesn't return custom fields if (isset($params['methodCall']['params']['param'][1]['value']['int']['value'])) { $page_id = $params['methodCall']['params']['param'][1]['value']['int']['value']; $lang_details = $this->get_element_language_details($page_id, 'post_' . get_post_type($page_id)); $this->this_lang = $lang_details->language_code; // set the current language to the posts language update_post_meta($page_id, '_wpml_language', $lang_details->language_code); update_post_meta($page_id, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if ($page_id != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($page_id, '_wpml_translations', json_encode($translations)); } break; case 'metaWeblog.getPost': if (isset($params['methodCall']['params']['param'][0]['value']['int']['value'])) { $page_id = $params['methodCall']['params']['param'][0]['value']['int']['value']; $lang_details = $this->get_element_language_details($page_id, 'post_' . get_post_type($page_id)); $this->this_lang = $lang_details->language_code; // set the current language to the posts language update_post_meta($page_id, '_wpml_language', $lang_details->language_code); update_post_meta($page_id, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if (isset($res[$k]) && $page_id != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($page_id, '_wpml_translations', json_encode($translations)); } break; case 'metaWeblog.getRecentPosts': if (isset($params['methodCall']['params']['param'][3]['value']['int']['value'])) { $num_posts = intval($params['methodCall']['params']['param'][3]['value']['int']['value']); if ($num_posts) { $posts = get_posts('suppress_filters=false&numberposts=' . $num_posts); foreach ($posts as $p) { $lang_details = $this->get_element_language_details($p->ID, 'post_post'); update_post_meta($p->ID, '_wpml_language', $lang_details->language_code); update_post_meta($p->ID, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if ($p->ID != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($p->ID, '_wpml_translations', json_encode($translations)); } } } break; case 'metaWeblog.newPost': $custom_fields = false; if (is_array($params['methodCall']['params']['param'][3]['value']['struct']['member'])) { foreach ($params['methodCall']['params']['param'][3]['value']['struct']['member'] as $m) { if ($m['name']['value'] == 'custom_fields') { $custom_fields_raw = $m['value']['array']['data']['value']; break; } } } if (!empty($custom_fields_raw)) { foreach ($custom_fields_raw as $cf) { $key = $value = null; foreach ($cf['struct']['member'] as $m) { if ($m['name']['value'] == 'key') { $key = $m['value']['string']['value']; } elseif ($m['name']['value'] == 'value') { $value = $m['value']['string']['value']; } } if ($key !== null && $value !== null) { $custom_fields[$key] = $value; } } } if (is_array($custom_fields) && isset($custom_fields['_wpml_language']) && isset($custom_fields['_wpml_trid'])) { $icl_post_language = $custom_fields['_wpml_language']; $icl_trid = $custom_fields['_wpml_trid']; $post_type = $params['methodCall']['params']['param'][3]['value']['struct']['member'][2]['value']['string']['value']; if (!$wpdb->get_var("SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE element_type='post_{$post_type}' AND trid={$icl_trid} AND language_code='{$icl_post_language}'")) { $_POST['icl_post_language'] = $icl_post_language; $_POST['icl_trid'] = $icl_trid; } else { $IXR_Error = new IXR_Error(401, __('A translation for this post already exists', 'sitepress')); echo $IXR_Error->getXml(); exit(1); } } break; case 'metaWeblog.editPost': $post_id = $params['methodCall']['params']['param'][0]['value']['int']['value']; if (!$post_id) { break; } $custom_fields = $params['methodCall']['params']['param'][3]['value']['struct']['member'][3]['value']['array']['data']['value']; if (is_array($custom_fields)) { $icl_trid = false; $icl_post_language = false; foreach ($custom_fields as $cf) { if ($cf['struct']['member'][0]['value']['string']['value'] == '_wpml_language') { $icl_post_language = $cf['struct']['member'][1]['value']['string']['value']; } elseif ($cf['struct']['member'][0]['value']['string']['value'] == '_wpml_trid') { $icl_trid = $cf['struct']['member'][1]['value']['string']['value']; } } $epost_id = $wpdb->get_var("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type='post_post'\r\n\t\t\t\t\t\tAND trid={$icl_trid} AND language_code='{$icl_post_language}'"); if ($icl_trid && $icl_post_language && (!$epost_id || $epost_id == $post_id)) { $_POST['icl_post_language'] = $icl_post_language; $_POST['icl_trid'] = $icl_trid; } else { $IXR_Error = new IXR_Error(401, __('A translation in this language already exists', 'sitepress')); echo $IXR_Error->getXml(); exit(1); } } break; } }
function check_wpml_config() { global $sitepress_settings; if (empty($sitepress_settings)) { return; } $file = realpath(WCML_PLUGIN_PATH . '/wpml-config.xml'); if (!file_exists($file)) { $this->xml_config_errors[] = __('wpml-config.xml file missing from WooCommerce Multilingual folder.', 'wpml-wcml'); } else { $config = icl_xml2array(file_get_contents($file)); if (isset($config['wpml-config'])) { //custom-fields if (isset($config['wpml-config']['custom-fields'])) { if (isset($config['wpml-config']['custom-fields']['custom-field']['value'])) { //single $cfs[] = $config['wpml-config']['custom-fields']['custom-field']; } else { foreach ($config['wpml-config']['custom-fields']['custom-field'] as $cf) { $cfs[] = $cf; } } if ($cfs) { foreach ($cfs as $cf) { if (!isset($sitepress_settings['translation-management']['custom_fields_translation'][$cf['value']])) { continue; } $effective_config_value = $sitepress_settings['translation-management']['custom_fields_translation'][$cf['value']]; $correct_config_value = $cf['attr']['action'] == 'copy' ? 1 : ($cf['attr']['action'] == 'translate' ? 2 : 0); if ($effective_config_value != $correct_config_value) { $this->xml_config_errors[] = sprintf(__('Custom field %s configuration from wpml-config.xml file was altered!', 'wpml-wcml'), '<i>' . $cf['value'] . '</i>'); } } } } //custom-types if (isset($config['wpml-config']['custom-types'])) { if (isset($config['wpml-config']['custom-types']['custom-type']['value'])) { //single $cts[] = $config['wpml-config']['custom-types']['custom-type']; } else { foreach ($config['wpml-config']['custom-types']['custom-type'] as $cf) { $cts[] = $cf; } } if ($cts) { foreach ($cts as $ct) { if (!isset($sitepress_settings['custom_posts_sync_option'][$ct['value']])) { continue; } $effective_config_value = $sitepress_settings['custom_posts_sync_option'][$ct['value']]; $correct_config_value = $ct['attr']['translate']; if ($effective_config_value != $correct_config_value) { $this->xml_config_errors[] = sprintf(__('Custom type %s configuration from wpml-config.xml file was altered!', 'wpml-wcml'), '<i>' . $ct['value'] . '</i>'); } } } } //taxonomies if (isset($config['wpml-config']['taxonomies'])) { if (isset($config['wpml-config']['taxonomies']['taxonomy']['value'])) { //single $txs[] = $config['wpml-config']['taxonomies']['taxonomy']; } else { foreach ($config['wpml-config']['taxonomies']['taxonomy'] as $cf) { $txs[] = $cf; } } if ($txs) { foreach ($txs as $tx) { if (!isset($sitepress_settings['taxonomies_sync_option'][$tx['value']])) { continue; } $effective_config_value = $sitepress_settings['taxonomies_sync_option'][$tx['value']]; $correct_config_value = $tx['attr']['translate']; if ($effective_config_value != $correct_config_value) { $this->xml_config_errors[] = sprintf(__('Custom taxonomy %s configuration from wpml-config.xml file was altered!', 'wpml-wcml'), '<i>' . $tx['value'] . '</i>'); } } } } } } }
static function parse_wpml_config_files() { $config_all['wpml-config'] = array('custom-fields' => array(), 'custom-types' => array(), 'taxonomies' => array(), 'admin-texts' => array(), 'language-switcher-settings' => array()); if (!empty(self::$wpml_config_files)) { foreach (self::$wpml_config_files as $file) { $config = is_object($file) ? $file->config : icl_xml2array(file_get_contents($file)); do_action('wpml_parse_config_file', $file); if (isset($config['wpml-config'])) { $wpml_config = $config['wpml-config']; $wpml_config_all = $config_all['wpml-config']; $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'custom-field', 'custom-fields'); $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'custom-type', 'custom-types'); $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'taxonomy', 'taxonomies'); //language-switcher-settings if (isset($wpml_config['language-switcher-settings']['key'])) { if (!is_numeric(key($wpml_config['language-switcher-settings']['key']))) { //single $wpml_config_all['language-switcher-settings']['key'][] = $wpml_config['language-switcher-settings']['key']; } else { foreach ($wpml_config['language-switcher-settings']['key'] as $cf) { $wpml_config_all['language-switcher-settings']['key'][] = $cf; } } } $config_all['wpml-config'] = $wpml_config_all; } } $config_all = apply_filters('icl_wpml_config_array', $config_all); $config_all = apply_filters('wpml_config_array', $config_all); } self::parse_wpml_config($config_all); }
function _request($request, $method='GET', $formvars=null, $formfiles=null, $gzipped = false){ global $sitepress_settings, $sitepress; $request = str_replace(" ", "%20", $request); $c = new IcanSnoopy(); $debugvars = array( 'debug_cms' => 'WordPress', 'debug_module' => 'WPML ' . ICL_SITEPRESS_VERSION, 'debug_url' => get_bloginfo('siteurl') ); if($method == 'GET'){ $request .= '&' . http_build_query($debugvars); }else{ $formvars += $debugvars; } // disable error reporting // needed for open_basedir restrictions (is_readable) $_display_errors = ini_get('display_errors'); $_error_reporting = ini_get('error_reporting'); ini_set('display_errors', '0'); ini_set('error_reporting', E_NONE); if (!@is_readable($c->curl_path) || !@is_executable($c->curl_path)){ $c->curl_path = '/usr/bin/curl'; } // restore error reporting // needed for open_basedir restrictions ini_set('display_errors', $_display_errors); ini_set('error_reporting', $_error_reporting); $c->_fp_timeout = 3; $c->read_timeout = 5; $url_parts = parse_url($request); if($sitepress_settings['troubleshooting_options']['http_communication']){ $request = str_replace('https://','http://',$request); } if($method=='GET'){ $c->fetch($request); if($c->timed_out){die(__('Error:','sitepress').$c->error);} }else{ $c->set_submit_multipart(); $c->submit($request, $formvars, $formfiles); if($c->timed_out){die(__('Error:','sitepress').$c->error);} } if($c->error){ $this->error = $c->error; return false; } if($gzipped){ $c->results = $this->_gzdecode($c->results); } $results = icl_xml2array($c->results,1); if(isset($results['info']) && $results['info']['status']['attr']['err_code']=='-1'){ $this->error = $results['info']['status']['value']; return false; } return $results; }
function request($url) { $result = $this->request->request($url); if (!is_object($result)) { return icl_xml2array($result['body'], 1); } else { return array(); } }
static function parse_wpml_config_files() { if (!empty(self::$wpml_config_files)) { $config_all['wpml-config'] = array('custom-fields' => array(), 'custom-types' => array(), 'taxonomies' => array(), 'admin-texts' => array(), 'language-switcher-settings' => array()); foreach (self::$wpml_config_files as $file) { if (is_object($file)) { $config = $file->config; $type = $file->type; $admin_text_context = $file->admin_text_context; } else { $config = icl_xml2array(file_get_contents($file)); $type = dirname($file) == get_template_directory() || dirname($file) == get_stylesheet_directory() ? 'theme' : 'plugin'; $admin_text_context = basename(dirname($file)); } if (isset($config['wpml-config'])) { $wpml_config = $config['wpml-config']; $wpml_config_all = $config_all['wpml-config']; $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'custom-field', 'custom-fields'); $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'custom-type', 'custom-types'); $wpml_config_all = self::parse_config_index($wpml_config_all, $wpml_config, 'taxonomy', 'taxonomies'); //admin-texts if (isset($wpml_config['admin-texts']['key'])) { if (!is_numeric(key(@current($wpml_config['admin-texts'])))) { //single $wpml_config['admin-texts']['key']['type'] = $type; $wpml_config['admin-texts']['key']['context'] = $admin_text_context; $wpml_config_all['admin-texts']['key'][] = $wpml_config['admin-texts']['key']; } else { foreach ((array) $wpml_config['admin-texts']['key'] as $cf) { $cf['type'] = $type; $cf['context'] = $admin_text_context; $wpml_config_all['admin-texts']['key'][] = $cf; } } } //language-switcher-settings if (isset($wpml_config['language-switcher-settings']['key'])) { if (!is_numeric(key($wpml_config['language-switcher-settings']['key']))) { //single $wpml_config_all['language-switcher-settings']['key'][] = $wpml_config['language-switcher-settings']['key']; } else { foreach ($wpml_config['language-switcher-settings']['key'] as $cf) { $wpml_config_all['language-switcher-settings']['key'][] = $cf; } } } $config_all['wpml-config'] = $wpml_config_all; } } $config_all = apply_filters('icl_wpml_config_array', $config_all); $config_all = apply_filters('wpml_config_array', $config_all); self::parse_wpml_config($config_all); } }
function parse_wpml_config_files() { if (!empty($this->wpml_config_files)) { $config_all['wpml-config'] = array('custom-fields' => array(), 'custom-types' => array(), 'taxonomies' => array(), 'admin-texts' => array(), 'language-switcher-settings' => array()); foreach ($this->wpml_config_files as $file) { $config = icl_xml2array(file_get_contents($file)); if (isset($config['wpml-config'])) { //custom-fields if (isset($config['wpml-config']['custom-fields'])) { if (isset($config['wpml-config']['custom-fields']['custom-field']['value'])) { //single $config_all['wpml-config']['custom-fields']['custom-field'][] = $config['wpml-config']['custom-fields']['custom-field']; } else { foreach ($config['wpml-config']['custom-fields']['custom-field'] as $cf) { $config_all['wpml-config']['custom-fields']['custom-field'][] = $cf; } } } //custom-types if (isset($config['wpml-config']['custom-types'])) { if (isset($config['wpml-config']['custom-types']['custom-type']['value'])) { //single $config_all['wpml-config']['custom-types']['custom-type'][] = $config['wpml-config']['custom-types']['custom-type']; } else { foreach ($config['wpml-config']['custom-types']['custom-type'] as $cf) { $config_all['wpml-config']['custom-types']['custom-type'][] = $cf; } } } //taxonomies if (isset($config['wpml-config']['taxonomies'])) { if (isset($config['wpml-config']['taxonomies']['taxonomy']['value'])) { //single $config_all['wpml-config']['taxonomies']['taxonomy'][] = $config['wpml-config']['taxonomies']['taxonomy']; } else { foreach ($config['wpml-config']['taxonomies']['taxonomy'] as $cf) { $config_all['wpml-config']['taxonomies']['taxonomy'][] = $cf; } } } //admin-texts if (isset($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'])))) { //single $config['wpml-config']['admin-texts']['key']['type'] = $type; $config['wpml-config']['admin-texts']['key']['atid'] = $atid; $config_all['wpml-config']['admin-texts']['key'][] = $config['wpml-config']['admin-texts']['key']; } else { foreach ($config['wpml-config']['admin-texts']['key'] as $cf) { $cf['type'] = $type; $cf['atid'] = $atid; $config_all['wpml-config']['admin-texts']['key'][] = $cf; } } } //language-switcher-settings if (isset($config['wpml-config']['language-switcher-settings'])) { if (!is_numeric(key($config['wpml-config']['language-switcher-settings']['key']))) { //single $config_all['wpml-config']['language-switcher-settings']['key'][] = $config['wpml-config']['language-switcher-settings']['key']; } else { foreach ($config['wpml-config']['language-switcher-settings']['key'] as $cf) { $config_all['wpml-config']['language-switcher-settings']['key'][] = $cf; } } } } } $config_all = apply_filters('icl_wpml_config_array', $config_all); $this->_parse_wpml_config($config_all); } }
/** * Get config from file */ public function get_config() { $config_files = array(); /** * First look for WPGlobus config */ $config_files[] = $this->wpglobus_config_file; /** * and then look for a WPML config */ $config_files[] = $this->wpml_config_file; $config_file = ''; foreach ($config_files as $config_file) { $this->config_dir_file = ''; /** * First priority: look for a config file in WP_LANG_DIR folder. * For example, for the theme slug `my-theme`, the file path is: * wp-content/languages/themes/my-theme-wpglobus-config.json * * * We'll check for both child and parent theme slugs */ foreach (array(get_stylesheet(), get_template()) as $theme_slug) { $config_in_wp_lang_dir = WP_LANG_DIR . '/themes/' . $theme_slug . '-' . $config_file; if (is_file($config_in_wp_lang_dir) && is_readable($config_in_wp_lang_dir)) { $this->config_dir_file = $config_in_wp_lang_dir; break 2; } } /** * Then, check for the config file provided by the theme author: * * @example wp-content/themes/my-theme/wpglobus-config.json */ if ($this->theme_dir['parent'] === $this->theme_dir['child']) { $file = $this->theme_dir['parent'] . '/' . $config_file; if (file_exists($file)) { $this->config_dir_file = $file; } } else { foreach ($this->theme_dir as $relation => $dir) { $file = $dir . '/' . $config_file; if ('child' === $relation && file_exists($file)) { /** * Now config in child theme has highest priority */ $this->config_dir_file = $file; break; } if ('parent' === $relation && file_exists($file)) { $this->config_dir_file = $file; } } } if (!empty($this->config_dir_file)) { break; } } if (empty($this->config_dir_file)) { $config_file = ''; } /** * If a configuration file has been found in the previous loop, * we have `$this->config_dir_file` containing the file path, * and the loop iterator, `$config_file`, pointing to the file type. */ switch ($config_file) { case $this->wpglobus_config_file: $this->config = $this->json2array(file_get_contents($this->config_dir_file)); $this->config_from = $this->wpglobus_config_file; break; case $this->wpml_config_file: /** * Compatibility with WPML configuration file: * their XML is parsed using their function, `icl_xml2array`, * which we copied as-is to the `lib` folder. * * @link https://wpml.org/documentation/support/language-configuration-files/ */ /** @noinspection PhpIncludeInspection */ require_once WPGlobus::$PLUGIN_DIR_PATH . 'lib/xml2array.php'; /** @noinspection PhpUndefinedFunctionInspection */ $this->config = icl_xml2array(file_get_contents($this->config_dir_file)); $this->config_from = $this->wpml_config_file; break; } if (!empty($this->config) && empty($this->config['version'])) { $this->config['version'] = '1'; } }
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')); } } } }
function xmlrpc_call_actions($action) { $params = icl_xml2array(print_r(file_get_contents('php://input'), true)); add_filter('is_protected_meta', array($this, 'xml_unprotect_wpml_meta'), 10, 3); switch ($action) { case 'wp.getPage': case 'blogger.getPost': // yet this doesn't return custom fields if (isset($params['methodCall']['params']['param'][1]['value']['int']['value'])) { $page_id = $params['methodCall']['params']['param'][1]['value']['int']['value']; $lang_details = $this->get_element_language_details($page_id, 'post_' . get_post_type($page_id)); $this->this_lang = $lang_details->language_code; // set the current language to the posts language update_post_meta($page_id, '_wpml_language', $lang_details->language_code); update_post_meta($page_id, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if ($page_id != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($page_id, '_wpml_translations', wp_json_encode($translations)); } break; case 'metaWeblog.getPost': if (isset($params['methodCall']['params']['param'][0]['value']['int']['value'])) { $page_id = $params['methodCall']['params']['param'][0]['value']['int']['value']; $lang_details = $this->get_element_language_details($page_id, 'post_' . get_post_type($page_id)); $this->this_lang = $lang_details->language_code; // set the current language to the posts language update_post_meta($page_id, '_wpml_language', $lang_details->language_code); update_post_meta($page_id, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if (isset($res[$k]) && $page_id != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($page_id, '_wpml_translations', wp_json_encode($translations)); } break; case 'metaWeblog.getRecentPosts': if (isset($params['methodCall']['params']['param'][3]['value']['int']['value'])) { $num_posts = (int) $params['methodCall']['params']['param'][3]['value']['int']['value']; if ($num_posts) { $posts = get_posts('suppress_filters=false&numberposts=' . $num_posts); foreach ($posts as $p) { $lang_details = $this->get_element_language_details($p->ID, 'post_post'); update_post_meta($p->ID, '_wpml_language', $lang_details->language_code); update_post_meta($p->ID, '_wpml_trid', $lang_details->trid); $active_languages = $this->get_active_languages(); $res = $this->get_element_translations($lang_details->trid); $translations = array(); foreach ($active_languages as $k => $v) { if ($p->ID != $res[$k]->element_id) { $translations[$k] = isset($res[$k]->element_id) ? $res[$k]->element_id : 0; } } update_post_meta($p->ID, '_wpml_translations', wp_json_encode($translations)); } } } break; } }