function get_inactive_content() { global $wpdb; $inactive = array(); $current_language = $this->get_current_language(); $res_p_prepared = $wpdb->prepare("\r\n\t\t\t\t SELECT COUNT(p.ID) AS c, p.post_type, lt.name AS language FROM {$wpdb->prefix}icl_translations t\r\n\t\t\t\t\tJOIN {$wpdb->posts} p ON t.element_id=p.ID AND t.element_type LIKE %s\r\n\t\t\t\t\tJOIN {$wpdb->prefix}icl_languages l ON t.language_code = l.code AND l.active = 0\r\n\t\t\t\t\tJOIN {$wpdb->prefix}icl_languages_translations lt ON lt.language_code = l.code AND lt.display_language_code=%s\r\n\t\t\t\t\tGROUP BY p.post_type, t.language_code\r\n\t\t\t\t", array(wpml_like_escape('post_') . '%', $current_language)); $res_p = $wpdb->get_results($res_p_prepared); if ($res_p) { foreach ($res_p as $r) { $inactive[$r->language][$r->post_type] = $r->c; } } $res_t_query = "\r\n\t\t SELECT COUNT(p.term_taxonomy_id) AS c, p.taxonomy, lt.name AS language FROM {$wpdb->prefix}icl_translations t\r\n\t\t\tJOIN {$wpdb->term_taxonomy} p ON t.element_id=p.term_taxonomy_id\r\n\t\t\tJOIN {$wpdb->prefix}icl_languages l ON t.language_code = l.code AND l.active = 0\r\n\t\t\tJOIN {$wpdb->prefix}icl_languages_translations lt ON lt.language_code = l.code AND lt.display_language_code=%s\r\n\t\t\tWHERE t.element_type LIKE %s\r\n\t\t\tGROUP BY p.taxonomy, t.language_code\r\n\t\t"; $res_t_query_prepared = $wpdb->prepare($res_t_query, $current_language, wpml_like_escape('tax_') . '%'); $res_t = $wpdb->get_results($res_t_query_prepared); if ($res_t) { foreach ($res_t as $r) { if ($r->taxonomy == 'category' && $r->c == 1) { continue; //ignore the case of just the default category that gets automatically created for a new language } $inactive[$r->language][$r->taxonomy] = $r->c; } } return $inactive; }
_e('Translatable taxonomies linking', 'sitepress'); ?> <br/> <small style="margin-left:10px;"><?php _e('Allows linking existing translations after changing custom taxonomies definition (name) ', 'sitepress'); ?> </small> <?php global $wp_post_types, $wp_taxonomies; $translatable_taxs = array(); foreach ($wp_post_types as $name => $post_type) { $translatable_taxs = array_merge($translatable_taxs, $sitepress->get_translatable_taxonomies(true, $name)); } $translatable_taxs = array_unique($translatable_taxs); $res = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT element_type FROM {$wpdb->prefix}icl_translations WHERE element_type LIKE %s", array(wpml_like_escape('tax_') . '%'))); echo '<table class="widefat" style="width:300px;">'; foreach ($res as $row) { $tax = preg_replace('#^tax_#', '', $row); if ($tax == 'link_category' || $tax == 'nav_menu') { continue; } echo '<tr>'; echo '<td>' . $tax . '</td>'; if (in_array($tax, $translatable_taxs)) { echo '<td>' . __('linked to: ', 'sitepress') . $wp_taxonomies[$tax]->labels->name . '</td>'; } else { echo '<td>'; echo '<select onchange="wpml_ts_link_taxonomy(jQuery(this), \'' . $tax . '\')">'; echo '<option value="">' . __('--select--', 'sitepress') . '</option>'; foreach ($translatable_taxs as $name) {
public function parse_config($config) { global $iclTranslationManagement, $sitepress; if (function_exists('icl_register_string')) { $requires_upgrade = !$sitepress->get_setting('admin_text_3_2_migration_complete', false); $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']; } $type = 'plugin'; $admin_text_context = ''; foreach ($admin_texts as $a) { if (isset($a['type'])) { $type = $a['type']; } if (isset($a['context'])) { $admin_text_context = $a['context']; } if (!isset($type)) { $type = 'plugin'; } if (!isset($admin_text_context)) { $admin_text_context = ''; } $keys = array(); if (!isset($a['key'])) { $arr[$a['attr']['name']] = 1; $arr_context[$a['attr']['name']] = $admin_text_context; $arr_type[$a['attr']['name']] = $type; 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']] = self::read_admin_texts_recursive($key['key'], $admin_text_context, $type, $arr_context, $arr_type); } else { $arr[$a['attr']['name']][$key['attr']['name']] = 1; } $arr_context[$a['attr']['name']] = $admin_text_context; $arr_type[$a['attr']['name']] = $type; } } if (isset($arr)) { $iclTranslationManagement->admin_texts_to_translate = array_merge($iclTranslationManagement->admin_texts_to_translate, $arr); } $_icl_admin_option_names = get_option('_icl_admin_option_names'); $arr_options = array(); if (isset($arr) && is_array($arr)) { foreach ($arr as $key => $v) { $value = $this->get_option_without_filtering($key); $value = maybe_unserialize($value); if (is_array($value) && is_array($v)) { $v = array_keys($v); // only keep the values defined. foreach ($value as $option_key => $option_value) { if (!in_array($option_key, $v)) { unset($value[$option_key]); } } // Add any additional settings that are not in the options already. foreach ($v as $option_key) { if (!isset($value[$option_key])) { $value[$option_key] = ''; } } } $admin_text_context = isset($arr_context[$key]) ? $arr_context[$key] : ''; $type = isset($arr_type[$key]) ? $arr_type[$key] : ''; if (false === $value) { // wildcard? register all matching options in wp_options global $wpdb; $src = str_replace('*', '%', wpml_like_escape($key)); $matches = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE '{$src}'"); foreach ($matches as $match) { $value = maybe_unserialize($match->option_value); if (is_array($value)) { $this->register_string_recursive($match->option_name, $value, $value, '', $match->option_name, $requires_upgrade, $type, $admin_text_context); } else { icl_register_string('admin_texts_' . $match->option_name, $match->option_name, $match->option_value); } if ($requires_upgrade) { $this->migrate_3_2($type, $admin_text_context, $match->option_name, $match->option_name); } $_icl_admin_option_names[$type][$admin_text_context][] = $match->option_name; } unset($arr[$key]); } if (is_scalar($value)) { icl_register_string('admin_texts_' . $key, $key, $value); if ($requires_upgrade) { $this->migrate_3_2($type, $admin_text_context, $key, $key); } } else { if (is_object($value)) { $value = (array) $value; } if (!empty($value)) { $this->register_string_recursive($key, $value, $arr[$key], '', $key, $requires_upgrade, $type, $admin_text_context); } } $arr_options[$key] = $v; } if (is_array($_icl_admin_option_names)) { $_icl_admin_option_names = array_replace_recursive($arr_options, $_icl_admin_option_names); } else { $_icl_admin_option_names = $arr_options; } } //$_icl_admin_option_names[ $type ][ $admin_text_context ] = __array_unique_recursive( $_icl_admin_option_names[ $type ][ $admin_text_context ] ); update_option('_icl_admin_option_names', $_icl_admin_option_names); } $sitepress->set_setting('admin_text_3_2_migration_complete', true, true); } }
function delete_language($lang_id) { global $wpdb, $sitepress; $lang = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_languages WHERE id=%d", $lang_id)); if ($lang) { if (in_array($lang->code, $this->built_in_languages)) { $error = __("Error: This is a built in language. You can't delete it.", 'sitepress'); } else { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_languages WHERE id=%d", $lang_id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_languages_translations WHERE language_code=%s", $lang->code)); $translation_ids = $wpdb->get_col($wpdb->prepare("SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE language_code=%s", $lang->code)); if ($translation_ids) { $rids = $wpdb->get_col("SELECT rid FROM {$wpdb->prefix}icl_translation_status WHERE translation_id IN (" . wpml_prepare_in($translation_ids, '%d') . ")"); if ($rids) { $job_ids = $wpdb->get_col("SELECT job_id FROM {$wpdb->prefix}icl_translate_job WHERE rid IN (" . wpml_prepare_in($rids, '%d') . ")"); if ($job_ids) { $wpdb->query("DELETE FROM {$wpdb->prefix}icl_translate WHERE job_id IN (" . wpml_prepare_in($job_ids, '%d') . ")"); } } } // delete posts $post_ids = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type LIKE %s AND language_code=%s", array(wpml_like_escape('post_') . '%', $lang->code))); remove_action('delete_post', array($sitepress, 'delete_post_actions')); foreach ($post_ids as $post_id) { wp_delete_post($post_id, true); } add_action('delete_post', array($sitepress, 'delete_post_actions')); // delete terms remove_action('delete_term', array($sitepress, 'delete_term'), 1, 3); $tax_ids = $wpdb->get_col($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type LIKE %s AND language_code=%s", array(wpml_like_escape('tax_') . '%', $lang->code))); foreach ($tax_ids as $tax_id) { $row = $wpdb->get_row($wpdb->prepare("SELECT term_id, taxonomy FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id=%d", $tax_id)); if ($row) { wp_delete_term($row->term_id, $row->taxonomy); } } add_action('delete_term', array($sitepress, 'delete_term'), 1, 3); // delete comments global $IclCommentsTranslation; remove_action('delete_comment', array($IclCommentsTranslation, 'delete_comment_actions')); foreach ($post_ids as $post_id) { wp_delete_post($post_id, true); } add_action('delete_comment', array($IclCommentsTranslation, 'delete_comment_actions')); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_translations WHERE language_code=%s", $lang->code)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_strings WHERE language=%s", $lang->code)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_string_translations WHERE language=%s", $lang->code)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_locale_map WHERE code=%s", $lang->code)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}icl_flags WHERE lang_code=%s", $lang->code)); icl_cache_clear(false); $sitepress->icl_translations_cache->clear(); $sitepress->clear_flags_cache(); $sitepress->icl_language_name_cache->clear(); $this->message(sprintf(__("The language %s was deleted.", 'sitepress'), '<strong>' . $lang->code . '</strong>')); } } else { $error = __('Error: Language not found.', 'sitepress'); } if (!empty($error)) { $this->error($error); } }
function _process_generic_text($source_text, &$alp_broken_links) { global $wpdb, $wp_rewrite, $sitepress, $sitepress_settings; $sitepress_settings = $sitepress->get_settings(); $default_language = $sitepress->get_default_language(); $current_language = $sitepress->get_current_language(); $cache_key_args = array($default_language, $current_language, md5($source_text), md5(implode('', $alp_broken_links))); $cache_key = md5(json_encode($cache_key_args)); $cache_group = '_process_generic_text'; $found = false; $text = wp_cache_get($cache_key, $cache_group, false, $found); if ($found) { return $text; } $filtered_icl_post_language = filter_input(INPUT_POST, 'icl_post_language', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $text = $source_text; if (!isset($wp_rewrite)) { require_once ABSPATH . WPINC . '/rewrite.php'; $wp_rewrite = new WP_Rewrite(); } if ($current_language == $default_language) { $rewrite = $wp_rewrite->wp_rewrite_rules(); } else { remove_filter('option_rewrite_rules', array($sitepress, 'rewrite_rules_filter')); if (class_exists('WPML_Slug_Translation')) { remove_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1); } $rewrite = $wp_rewrite->wp_rewrite_rules(); add_filter('option_rewrite_rules', array($sitepress, 'rewrite_rules_filter')); if (class_exists('WPML_Slug_Translation')) { add_filter('option_rewrite_rules', array('WPML_Slug_Translation', 'rewrite_rules_filter'), 1, 1); } } $rewrite = $this->all_rewrite_rules($rewrite); $home_url = $sitepress->language_url(empty($filtered_icl_post_language) ? false : $filtered_icl_post_language); if ($sitepress_settings['language_negotiation_type'] == 3) { $home_url = preg_replace("#\\?lang=([a-z-]+)#i", '', $home_url); } $home_url = str_replace("?", "\\?", $home_url); if ($sitepress_settings['urls']['directory_for_default_language']) { $default_language = $sitepress->get_default_language(); $home_url = str_replace($default_language . "/", "", $home_url); } $int1 = preg_match_all('@<a([^>]*)href="((' . rtrim($home_url, '/') . ')?/([^"^>^\\[^\\]]+))"([^>]*)>@i', $text, $alp_matches1); $int2 = preg_match_all('@<a([^>]*)href=\'((' . rtrim($home_url, '/') . ')?/([^\'^>^\\[^\\]]+))\'([^>]*)>@i', $text, $alp_matches2); $alp_matches = array(); for ($i = 0; $i < 6; $i++) { $alp_matches[$i] = array_merge((array) $alp_matches1[$i], (array) $alp_matches2[$i]); } if ($int1 || $int2) { $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); foreach ($alp_matches[4] as $k => $m) { if (0 === strpos($m, 'wp-content')) { continue; } $lang = false; if ($sitepress_settings['language_negotiation_type'] == 1 && $sitepress_settings['urls']['directory_for_default_language'] != 1) { $m_orig = $m; $exp = explode('/', $m, 2); $lang = $exp[0]; if ($wpdb->get_var("SELECT code FROM {$wpdb->prefix}icl_languages WHERE code='{$lang}'")) { $m = $exp[1]; } else { $m = $m_orig; unset($m_orig); $lang = false; } } $pathinfo = ''; $req_uri = '/' . $m; $req_uri_array = explode('?', $req_uri); $req_uri = $req_uri_array[0]; $req_uri_params = ''; if (isset($req_uri_array[1])) { $req_uri_params = $req_uri_array[1]; } // separate anchor $req_uri_array = explode('#', $req_uri); $req_uri = $req_uri_array[0]; $anchor = isset($req_uri_array[1]) ? $req_uri_array[1] : false; $home_path = parse_url(get_home_url()); if (isset($home_path['path'])) { $home_path = $home_path['path']; } else { $home_path = ''; } $home_path = trim($home_path, '/'); $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri)); $req_uri = trim($req_uri, '/'); $req_uri = preg_replace("|^{$home_path}|", '', $req_uri); $req_uri = trim($req_uri, '/'); $pathinfo = trim($pathinfo, '/'); $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo); $pathinfo = trim($pathinfo, '/'); if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) { $request = $pathinfo; } else { // If the request uri is the index, blank it out so that we don't try to match it against a rule. if ($req_uri == $wp_rewrite->index) { $req_uri = ''; } $request = $req_uri; } $request_match = $request; $permalink_query_vars = array(); foreach ((array) $rewrite as $match => $query) { // If the requesting file is the anchor of the match, prepend it // to the path info. if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) { $request_match = $req_uri . '/' . $request; } if (preg_match("!^{$match}!", $request_match, $matches) || preg_match("!^{$match}!", urldecode($request_match), $matches)) { // Got a match. // Trim the query of everything up to the '?'. $query = preg_replace("!^.+\\?!", '', $query); // Substitute the substring matches into the query. $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); // Parse the query. parse_str($query, $permalink_query_vars); break; } } $post_name = $category_name = $tax_name = false; if (isset($permalink_query_vars['pagename'])) { $icl_post_lang = !is_null($filtered_icl_post_language) ? $filtered_icl_post_language : $current_language; $sitepress->switch_lang($icl_post_lang); $page_by_path = get_page_by_path($permalink_query_vars['pagename']); $sitepress->switch_lang($current_language); if (!empty($page_by_path->post_type)) { $post_name = $permalink_query_vars['pagename']; $post_type = 'page'; } else { $post_name = $permalink_query_vars['pagename']; $post_type = 'post'; } } elseif (isset($permalink_query_vars['name'])) { $post_name = $permalink_query_vars['name']; $post_type = 'post'; } elseif (isset($permalink_query_vars['category_name'])) { $category_name = $permalink_query_vars['category_name']; } elseif (isset($permalink_query_vars['p'])) { // case or /archives/%post_id $post_data_prepared = $wpdb->prepare("SELECT post_type, post_name FROM {$wpdb->posts} WHERE id=%d", $permalink_query_vars['p']); list($post_type, $post_name) = $wpdb->get_row($post_data_prepared, ARRAY_N); } else { if (empty($this->custom_post_query_vars) or empty($this->taxonomies_query_vars)) { $this->init_query_vars(); } foreach ($this->custom_post_query_vars as $query_vars_key => $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $post_name = $permalink_query_vars[$query_vars_value]; $post_type = $query_vars_key; break; } } foreach ($this->taxonomies_query_vars as $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $tax_name = $permalink_query_vars[$query_vars_value]; $tax_type = $query_vars_value; break; } } } if ($post_name && isset($post_type)) { $icl_post_lang = !is_null($filtered_icl_post_language) ? $filtered_icl_post_language : $current_language; $sitepress->switch_lang($icl_post_lang); $p = get_page_by_path($post_name, OBJECT, $post_type); $sitepress->switch_lang($current_language); if (empty($p)) { // fail safe if ($post_id = url_to_postid($home_path . '/' . $post_name)) { $p = get_post($post_id); } } if ($p) { if ($post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . str_replace('?', '\\?', $m); $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } // check if this is an offsite url if ($p->post_type == 'page' && ($offsite_url = get_post_meta($p->ID, '_cms_nav_offsite_url', true))) { $regv = 'href="' . $offsite_url . $anchor . '"'; } else { $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $p->ID; if ($req_uri_params != '') { $regv .= '&' . $req_uri_params; } $regv .= $anchor . '"'; } $def_url[$regk] = $regv; } else { $alp_broken_links[$alp_matches[2][$k]] = array(); $name = wpml_like_escape($post_name); $p = $wpdb->get_results("SELECT ID, post_type FROM {$wpdb->posts} WHERE post_name LIKE '{$name}%' AND post_type IN('post','page')"); if ($p) { foreach ($p as $post_suggestion) { if ($post_suggestion->post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $post_suggestion->ID, 'perma' => '/' . ltrim(str_replace(site_url(), '', get_permalink($post_suggestion->ID)), '/')); } } } } elseif ($category_name) { if (false !== strpos($category_name, '/')) { $splits = explode('/', $category_name); $category_name = array_pop($splits); $category_parent = array_pop($splits); $category_parent_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_parent)); $c = $wpdb->get_row($wpdb->prepare("SELECT t.term_id FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id=t.term_id AND x.taxonomy='category' AND x.parent=%d AND t.slug=%s", $category_parent_id, $category_name)); } else { $c = $wpdb->get_row($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_name)); } if ($c) { /* not used ?? */ if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } /* not used ?? */ $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=[\'"](' . $perm_url . ')[\'"]@i'; $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?cat_ID=' . $c->term_id . '"'; $def_url[$regk] = $regv; } elseif (isset($name)) { $alp_broken_links[$alp_matches[2][$k]] = array(); $c_prepared = $wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug LIKE %s", array($name . '%')); $c = $wpdb->get_results($c_prepared); if ($c) { foreach ($c as $cat_suggestion) { $perma = '/' . ltrim(str_replace(get_home_url(), '', get_category_link($cat_suggestion->term_id)), '/'); $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '?cat_ID=' . $cat_suggestion->term_id, 'perma' => $perma); } } } } elseif ($tax_name && isset($tax_type)) { if ($sitepress_settings['language_negotiation_type'] == 1 && $lang) { $langprefix = '/' . $lang; } else { $langprefix = ''; } $perm_url = '(' . rtrim($home_url, '/') . ')?' . $langprefix . '/' . $m; $regk = '@href=["\'](' . $perm_url . ')["\']@i'; if ($anchor) { $anchor = "#" . $anchor; } else { $anchor = ""; } $regv = 'href="' . '/' . ltrim($url_parts['path'], '/') . '?' . $tax_type . '=' . $tax_name . $anchor . '"'; $def_url[$regk] = $regv; } } if (!empty($def_url)) { $text = preg_replace(array_keys($def_url), array_values($def_url), $text); } $tx_qvs = !empty($this->taxonomies_query_vars) && is_array($this->taxonomies_query_vars) ? '|' . join('|', $this->taxonomies_query_vars) : ''; $post_qvs = !empty($this->custom_posts_query_vars) && is_array($this->custom_posts_query_vars) ? '|' . join('|', $this->custom_posts_query_vars) : ''; $int = preg_match_all('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', $text, $matches2); if ($int) { $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); $text = preg_replace('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', 'href="' . '/' . ltrim($url_parts['path'], '/') . '?$2=$3$4"', $text); } } wp_cache_set($cache_key, $text, $cache_group); return $text; }
function icl_plugin_upgrade() { global $wpdb; $iclsettings = get_option('icl_sitepress_settings'); require_once ICL_PLUGIN_PATH . '/inc/cache.php'; icl_cache_clear('locale_cache_class'); icl_cache_clear('flags_cache_class'); icl_cache_clear('language_name_cache_class'); if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.2', '<')) { $wpdb->update($wpdb->prefix . 'icl_flags', array('flag' => 'ku.png'), array('lang_code' => 'ku')); $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'Magyar'), array('language_code' => 'hu', 'display_language_code' => 'hu')); $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'Hrvatski'), array('language_code' => 'hr', 'display_language_code' => 'hr')); $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'فارسی'), array('language_code' => 'fa', 'display_language_code' => 'fa')); } if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.3', '<')) { $wpdb->update($wpdb->prefix . 'icl_languages_translations', array('name' => 'پارسی'), array('language_code' => 'fa', 'display_language_code' => 'fa')); } if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.7', '<')) { if (!isset($iclsettings['promote_wpml'])) { $iclsettings['promote_wpml'] = 0; update_option('icl_sitepress_settings', $iclsettings); } if (!isset($iclsettings['auto_adjust_ids'])) { $iclsettings['auto_adjust_ids'] = 0; update_option('icl_sitepress_settings', $iclsettings); } $wpdb->query("UPDATE {$wpdb->prefix}icl_translations SET element_type='tax_post_tag' WHERE element_type='tag'"); // @since 3.1.5 - mysql_* function deprecated in php 5.5+ $wpdb->query("UPDATE {$wpdb->prefix}icl_translations SET element_type='tax_category' WHERE element_type='category'"); } if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '1.7.8', '<')) { $res = $wpdb->get_results("SELECT ID, post_type FROM {$wpdb->posts}"); $post_types = array(); foreach ($res as $row) { $post_types[$row->post_type][] = $row->ID; } foreach ($post_types as $type => $ids) { if (!empty($ids)) { $q = "UPDATE {$wpdb->prefix}icl_translations SET element_type=%s WHERE element_type='post' AND element_id IN(" . join(',', $ids) . ")"; $q_prepared = $wpdb->prepare($q, 'post_' . $type); $wpdb->query($q_prepared); // @since 3.1.5 - mysql_* function deprecated in php 5.5+ } } // fix categories & tags in icl_translations $res = $wpdb->get_results("SELECT term_taxonomy_id, taxonomy FROM {$wpdb->term_taxonomy}"); foreach ($res as $row) { $icltr = $wpdb->get_row($wpdb->prepare("SELECT translation_id, element_type FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type LIKE %s", array($row->term_taxonomy_id, wpml_like_escape('tax_') . '%'))); if ('tax_' . $row->taxonomy != $icltr->element_type) { $wpdb->update($wpdb->prefix . 'icl_translations', array('element_type' => 'tax_' . $row->taxonomy), array('translation_id' => $icltr->translation_id)); } } } if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '2.0.0', '<')) { include_once ICL_PLUGIN_PATH . '/inc/upgrade-functions/upgrade-2.0.0.php'; if (empty($iclsettings['migrated_2_0_0'])) { define('ICL_MULTI_STEP_UPGRADE', true); return; // GET OUT AND DO NOT SET THE NEW VERSION } } if (get_option('icl_sitepress_version') && version_compare(get_option('icl_sitepress_version'), '2.0.4', '<')) { $sql = "ALTER TABLE {$wpdb->prefix}icl_translation_status ADD COLUMN `_prevstate` longtext"; $wpdb->query($sql); } $versions = array('2.0.5', '2.2.2', '2.3.0', '2.3.1', '2.3.3', '2.4.0', '2.5.0', '2.5.2', '2.6.0', '2.7', '2.9', '2.9.3', '3.1', '3.1.5', '3.1.8', '3.1.9.5', '3.2', '3.2.3', '3.3', '3.3.7'); foreach ($versions as $version) { icl_upgrade_version($version); } //Forcing upgrade logic when ICL_SITEPRESS_DEV_VERSION is defined //This allow to run the logic between different alpha/beta/RC versions //since we are now storing only the formal version in the options if (defined('ICL_SITEPRESS_DEV_VERSION')) { icl_upgrade_version(ICL_SITEPRESS_DEV_VERSION, true); } if (version_compare(get_option('icl_sitepress_version'), ICL_SITEPRESS_VERSION, '<')) { update_option('icl_sitepress_version', ICL_SITEPRESS_VERSION); } }
private static function build_where_clause($selects, $taxonomy, $search = false, $parent = false) { global $wpdb; $where_clauses[] = $selects[$wpdb->term_taxonomy]['alias'] . '.taxonomy = ' . "'" . $taxonomy . "'"; $where_clauses[] = $selects[$wpdb->prefix . 'icl_translations']['alias'] . '.element_type = ' . "'tax_" . $taxonomy . "'"; if ($parent) { $where_clauses[] = $selects[$wpdb->term_taxonomy]['alias'] . '.parent = ' . $parent; } if ($search) { $where_clauses[] = "ts.name LIKE '%" . wpml_like_escape($search) . "%' "; } $where_clause = join(' AND ', $where_clauses); return $where_clause; }
/** * @param $config * * @return array */ protected static function parse_admin_texts($config) { global $iclTranslationManagement; 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']; } $type = 'plugin'; $admin_text_context = ''; foreach ($admin_texts as $a) { if (isset($a['type'])) { $type = $a['type']; } if (isset($a['context'])) { $admin_text_context = $a['context']; } if (!isset($type)) { $type = 'plugin'; } if (!isset($admin_text_context)) { $admin_text_context = ''; } $keys = array(); if (!isset($a['key'])) { $arr[$a['attr']['name']] = 1; $arr_context[$a['attr']['name']] = $admin_text_context; $arr_type[$a['attr']['name']] = $type; 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']] = self::read_admin_texts_recursive($key['key'], $admin_text_context, $type, $arr_context, $arr_type); } else { $arr[$a['attr']['name']][$key['attr']['name']] = 1; } $arr_context[$a['attr']['name']] = $admin_text_context; $arr_type[$a['attr']['name']] = $type; } } if (isset($arr)) { $iclTranslationManagement->admin_texts_to_translate = array_merge($iclTranslationManagement->admin_texts_to_translate, $arr); } $_icl_admin_option_names = get_option('_icl_admin_option_names'); $arr_options = array(); if (isset($arr) && is_array($arr)) { foreach ($arr as $key => $v) { 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); $admin_text_context = isset($arr_context[$key]) ? $arr_context[$key] : ''; $type = isset($arr_type[$key]) ? $arr_type[$key] : ''; if (false === $value) { // wildcard? register all matching options in wp_options global $wpdb; $src = str_replace('*', '%', wpml_like_escape($key)); $matches = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE '{$src}'"); foreach ($matches as $match) { icl_register_string('admin_texts_' . $type . '_' . $admin_text_context, $match->option_name, $match->option_value); $_icl_admin_option_names[$type][$admin_text_context][] = $match->option_name; } unset($arr[$key]); } if (is_scalar($value)) { icl_register_string('admin_texts_' . $type . '_' . $admin_text_context, $key, $value); } else { if (is_object($value)) { $value = (array) $value; } if (!empty($value)) { $iclTranslationManagement->_register_string_recursive($key, $value, $arr[$key], '', $type . '_' . $admin_text_context); } } $arr_options[$type][$admin_text_context][$key] = $v; } if (is_array($_icl_admin_option_names)) { $_icl_admin_option_names = @array_merge((array) $_icl_admin_option_names, $arr_options); } else { $_icl_admin_option_names = $arr_options; } } //$_icl_admin_option_names[ $type ][ $admin_text_context ] = __array_unique_recursive( $_icl_admin_option_names[ $type ][ $admin_text_context ] ); update_option('_icl_admin_option_names', $_icl_admin_option_names); } } }
function _process_generic_text($source_text, &$alp_broken_links) { global $wpdb, $wp_rewrite, $sitepress, $sitepress_settings; $sitepress_settings = $sitepress->get_settings(); $default_language = $sitepress->get_default_language(); $current_language = $sitepress->get_current_language(); $cache_key_args = array($default_language, $current_language, md5($source_text), md5(implode('', $alp_broken_links))); $cache_key = md5(json_encode($cache_key_args)); $cache_group = '_process_generic_text'; $found = false; $text = wp_cache_get($cache_key, $cache_group, false, $found); if ($found) { return $text; } $filtered_icl_post_language = filter_input(INPUT_POST, 'icl_post_language', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $text = $source_text; // We need to loop over each language so we create sticky links for all languages. $this->active_languages = array_keys($sitepress->get_active_languages()); $current_language = empty($filtered_icl_post_language) ? $current_language : $filtered_icl_post_language; if (!empty($current_language)) { if (($key = array_search($current_language, $this->active_languages)) !== false) { unset($this->active_languages[$key]); } array_unshift($this->active_languages, $current_language); } foreach ($this->active_languages as $test_language) { $rewrite = $this->initialize_rewrite($current_language, $default_language, $sitepress); $home_url = $sitepress->language_url($test_language); if ($sitepress_settings['language_negotiation_type'] == 3) { $home_url = preg_replace("#\\?lang=([a-z-]+)#i", '', $home_url); } $home_url = str_replace("?", "\\?", $home_url); if ($sitepress_settings['urls']['directory_for_default_language'] && $test_language == $default_language) { $home_url = str_replace($default_language . "/", "", $home_url); } $int1 = preg_match_all('@<a([^>]*)href="((' . rtrim($home_url, '/') . ')?/([^"^>^\\[^\\]]+))"([^>]*)>@i', $text, $alp_matches1); $int2 = preg_match_all('@<a([^>]*)href=\'((' . rtrim($home_url, '/') . ')?/([^\'^>^\\[^\\]]+))\'([^>]*)>@i', $text, $alp_matches2); $alp_matches = array(); for ($i = 0; $i < 6; $i++) { $alp_matches[$i] = array_merge((array) $alp_matches1[$i], (array) $alp_matches2[$i]); } if ($int1 || $int2) { $def_url = array(); $url_parts = parse_url($this->get_home_url_with_no_lang_directory()); $url_parts['path'] = isset($url_parts['path']) ? $url_parts['path'] : ''; foreach ($alp_matches[4] as $k => $dir_path) { if (0 === strpos($dir_path, 'wp-content')) { continue; } list($lang, $dir_path) = $this->extract_lang_from_path($sitepress_settings, $default_language, $dir_path); $req_uri = '/' . $dir_path; $req_uri_array = explode('?', $req_uri); $req_uri = $req_uri_array[0]; $req_uri_params = ''; if (isset($req_uri_array[1])) { $req_uri_params = $req_uri_array[1]; } // separate anchor $req_uri_array = explode('#', $req_uri); $req_uri = $req_uri_array[0]; $anchor_output = isset($req_uri_array[1]) ? "#" . $req_uri_array[1] : ''; $home_path = parse_url(get_home_url()); if (isset($home_path['path'])) { $home_path = $home_path['path']; } else { $home_path = ''; } $home_path = trim($home_path, '/'); $pathinfo = ''; $req_uri = str_replace($pathinfo, '', rawurldecode($req_uri)); $req_uri = trim($req_uri, '/'); $req_uri = preg_replace("|^{$home_path}|", '', $req_uri); $req_uri = trim($req_uri, '/'); $pathinfo = trim($pathinfo, '/'); $pathinfo = preg_replace("|^{$home_path}|", '', $pathinfo); $pathinfo = trim($pathinfo, '/'); if (!empty($pathinfo) && !preg_match('|^.*' . $wp_rewrite->index . '$|', $pathinfo)) { $request = $pathinfo; } else { // If the request uri is the index, blank it out so that we don't try to match it against a rule. if ($req_uri == $wp_rewrite->index) { $req_uri = ''; } $request = $req_uri; } if (!$request) { continue; } $request_match = $request; $permalink_query_vars = array(); foreach ((array) $rewrite as $match => $query) { // If the requesting file is the anchor of the match, prepend it // to the path info. if (!empty($req_uri) && strpos($match, $req_uri) === 0 && $req_uri != $request) { $request_match = $req_uri . '/' . $request; } if (preg_match("!^{$match}!", $request_match, $matches) || preg_match("!^{$match}!", urldecode($request_match), $matches)) { // Got a match. // Trim the query of everything up to the '?'. $query = preg_replace("!^.+\\?!", '', $query); // Substitute the substring matches into the query. $query = addslashes(WP_MatchesMapRegex::apply($query, $matches)); // Parse the query. parse_str($query, $permalink_query_vars); break; } } $post_name = $category_name = $tax_name = false; if (isset($permalink_query_vars['pagename'])) { $get_page_by_path = new WPML_Get_Page_By_Path($wpdb, $sitepress); $page_by_path = $get_page_by_path->get($permalink_query_vars['pagename'], $test_language); $post_name = $permalink_query_vars['pagename']; if (!empty($page_by_path->post_type)) { $post_type = 'page'; } else { $post_type = 'post'; } } elseif (isset($permalink_query_vars['name'])) { $post_name = $permalink_query_vars['name']; $post_type = 'post'; } elseif (isset($permalink_query_vars['category_name'])) { $category_name = $permalink_query_vars['category_name']; } elseif (isset($permalink_query_vars['p'])) { // case or /archives/%post_id $post_data_prepared = $wpdb->prepare("SELECT post_type, post_name FROM {$wpdb->posts} WHERE id=%d", $permalink_query_vars['p']); list($post_type, $post_name) = $wpdb->get_row($post_data_prepared, ARRAY_N); } else { if (empty($this->custom_post_query_vars) or empty($this->taxonomies_query_vars)) { $this->init_query_vars(); } foreach ($this->custom_post_query_vars as $query_vars_key => $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $post_name = $permalink_query_vars[$query_vars_value]; $post_type = $query_vars_key; break; } } foreach ($this->taxonomies_query_vars as $query_vars_value) { if (isset($permalink_query_vars[$query_vars_value])) { $tax_name = $permalink_query_vars[$query_vars_value]; $tax_type = $query_vars_value; break; } } } if ($post_name && isset($post_type)) { $get_page_by_path = new WPML_Get_Page_By_Path($wpdb, $sitepress); $p = $get_page_by_path->get($post_name, $test_language, OBJECT, $post_type); if (empty($p)) { // fail safe if ($post_id = url_to_postid($home_path . '/' . $post_name)) { $p = get_post($post_id); } } if ($p) { if ($p->post_type == 'page' && ($offsite_url = get_post_meta($p->ID, '_cms_nav_offsite_url', true))) { $def_url = $this->get_regex_replacement_offline($def_url, $offsite_url, $sitepress_settings['language_negotiation_type'], $lang, $dir_path, $home_url, $anchor_output); } else { $def_url = $this->get_regex_replacement($def_url, $p->post_type == 'page' ? 'page_id' : 'p', $p->ID, $sitepress_settings['language_negotiation_type'], $lang, $dir_path, $home_url, $url_parts, $req_uri_params, $anchor_output); } } else { $alp_broken_links[$alp_matches[2][$k]] = array(); $name = wpml_like_escape($post_name); $p = $this->_get_ids_and_post_types($name); if ($p) { foreach ($p as $post_suggestion) { if ($post_suggestion->post_type == 'page') { $qvid = 'page_id'; } else { $qvid = 'p'; } $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '/' . ltrim($url_parts['path'], '/') . '?' . $qvid . '=' . $post_suggestion->ID, 'perma' => '/' . ltrim(str_replace(site_url(), '', get_permalink($post_suggestion->ID)), '/')); } } } } elseif ($category_name) { if (false !== strpos($category_name, '/')) { $splits = explode('/', $category_name); $category_name = array_pop($splits); $category_parent = array_pop($splits); $category_parent_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_parent)); $c = $wpdb->get_row($wpdb->prepare("SELECT t.term_id FROM {$wpdb->terms} t JOIN {$wpdb->term_taxonomy} x ON x.term_id=t.term_id AND x.taxonomy='category' AND x.parent=%d AND t.slug=%s", $category_parent_id, $category_name)); } else { $c = $wpdb->get_row($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug=%s", $category_name)); } if ($c) { $def_url = $this->get_regex_replacement($def_url, 'cat_ID', $c->term_id, $sitepress_settings['language_negotiation_type'], $lang, $dir_path, $home_url, $url_parts, $req_uri_params, $anchor_output); } elseif (isset($name)) { $alp_broken_links[$alp_matches[2][$k]] = array(); $c_prepared = $wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug LIKE %s", array($name . '%')); $c = $wpdb->get_results($c_prepared); if ($c) { foreach ($c as $cat_suggestion) { $perma = '/' . ltrim(str_replace(get_home_url(), '', get_category_link($cat_suggestion->term_id)), '/'); $alp_broken_links[$alp_matches[2][$k]]['suggestions'][] = array('absolute' => '?cat_ID=' . $cat_suggestion->term_id, 'perma' => $perma); } } } } elseif ($tax_name && isset($tax_type)) { $def_url = $this->get_regex_replacement($def_url, $tax_type, $tax_name, $sitepress_settings['language_negotiation_type'], $lang, $dir_path, $home_url, $url_parts, $req_uri_params, $anchor_output); } } if (!empty($def_url)) { $text = preg_replace(array_keys($def_url), array_values($def_url), $text); } $tx_qvs = !empty($this->taxonomies_query_vars) && is_array($this->taxonomies_query_vars) ? '|' . join('|', $this->taxonomies_query_vars) : ''; $post_qvs = !empty($this->custom_posts_query_vars) && is_array($this->custom_posts_query_vars) ? '|' . join('|', $this->custom_posts_query_vars) : ''; $int = preg_match_all('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', $text, $matches2); if ($int) { $url_parts = parse_url(rtrim(get_home_url(), '/') . '/'); $text = preg_replace('@href=[\'"](' . rtrim(get_home_url(), '/') . '/?\\?(p|page_id' . $tx_qvs . $post_qvs . ')=([0-9a-z-]+)(#.+)?)[\'"]@i', 'href="' . '/' . ltrim($url_parts['path'], '/') . '?$2=$3$4"', $text); } } } wp_cache_set($cache_key, $text, $cache_group); return $text; }