function get_element_language_details($el_id, $el_type = 'post_post') { global $wpdb; static $pre_load_done = false; if (!$pre_load_done && !ICL_DISABLE_CACHE) { // search previous queries for a group of posts foreach ($this->queries as $query) { $pos = strstr($query, 'post_id IN ('); if ($pos !== FALSE) { $group = substr($pos, 10); $group = substr($group, 0, strpos($group, ')') + 1); $query = "SELECT element_id, trid, language_code, source_language_code\n FROM {$wpdb->prefix}icl_translations\n WHERE element_id IN {$group} AND element_type='{$el_type}'"; $ret = $wpdb->get_results($query); foreach ($ret as $details) { if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($details->element_id . $el_type, $details); } } // get the taxonomy for the posts for later use // categories first $query = "SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_category' and tt.taxonomy='category')\n "; $query .= "UNION\n "; $query .= "SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_post_tag' and tt.taxonomy='post_tag')"; global $wp_taxonomies; $custom_taxonomies = array_diff(array_keys($wp_taxonomies), array('post_tag', 'category', 'link_category')); if (!empty($custom_taxonomies)) { foreach ($custom_taxonomies as $tax) { $query .= " UNION\n SELECT DISTINCT(tr.term_taxonomy_id), tt.term_id, tt.taxonomy, icl.trid, icl.language_code, icl.source_language_code\n FROM {$wpdb->prefix}term_relationships as tr\n LEFT JOIN {$wpdb->prefix}term_taxonomy AS tt\n ON tr.term_taxonomy_id = tt.term_taxonomy_id\n LEFT JOIN {$wpdb->prefix}icl_translations as icl ON tr.term_taxonomy_id = icl.element_id\n WHERE tr.object_id IN {$group}\n AND (icl.element_type='tax_{$tax}' and tt.taxonomy='{$tax}')"; } } $ret = $wpdb->get_results($query); foreach ($ret as $details) { // save language details $lang_details = new stdClass(); $lang_details->trid = $details->trid; $lang_details->language_code = $details->language_code; $lang_details->source_language_code = $details->source_language_code; if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($details->term_taxonomy_id . 'tax_' . $details->taxonomy, $lang_details); // save the term taxonomy $this->icl_term_taxonomy_cache->set('category_' . $details->term_id, $details->term_taxonomy_id); } } break; } } $pre_load_done = true; } if (isset($this->icl_translations_cache) && $this->icl_translations_cache->has_key($el_id . $el_type)) { return $this->icl_translations_cache->get($el_id . $el_type); } $details_prepared_sql = $wpdb->prepare("\n SELECT trid, language_code, source_language_code\n FROM {$wpdb->prefix}icl_translations\n WHERE element_id=%d AND element_type=%s", array($el_id, $el_type)); $details = $wpdb->get_row($details_prepared_sql); if (isset($this->icl_translations_cache)) { $this->icl_translations_cache->set($el_id . $el_type, $details); } return $details; }
function save_user_options() { $user_id = $_POST['user_id']; if ($user_id) { update_user_meta($user_id, 'icl_admin_language', $_POST['icl_user_admin_language']); update_user_meta($user_id, 'icl_show_hidden_languages', isset($_POST['icl_show_hidden_languages']) ? intval($_POST['icl_show_hidden_languages']) : 0); update_user_meta($user_id, 'icl_admin_language_for_edit', isset($_POST['icl_admin_language_for_edit']) ? intval($_POST['icl_admin_language_for_edit']) : 0); $this->icl_locale_cache->clear(); } }
function get_flag($lang_code) { if (isset($this->icl_flag_cache)) { $flag = $this->icl_flag_cache->get($lang_code); } else { $flag = null; } if (!$flag) { $flag = $this->wpdb->get_row($this->wpdb->prepare("SELECT flag, from_template\r\n FROM {$this->wpdb->prefix}icl_flags\r\n WHERE lang_code=%s", $lang_code)); if (isset($this->icl_flag_cache)) { $this->icl_flag_cache->set($lang_code, $flag); } } return $flag; }
function get_display_language_name($lang_code, $display_code = null) { $display_code = $display_code ? $display_code : $this->get_current_language(); if (isset($this->icl_language_name_cache)) { $translated_name = $this->icl_language_name_cache->get($lang_code . $display_code); } else { $translated_name = null; } if (!$translated_name) { $display_code = $display_code == 'all' ? $this->get_admin_language() : $display_code; $translated_name = $this->wpdb->get_var($this->wpdb->prepare(" SELECT name\n FROM {$this->wpdb->prefix}icl_languages_translations\n WHERE language_code=%s\n AND display_language_code=%s", $lang_code, $display_code)); if (isset($this->icl_language_name_cache)) { $this->icl_language_name_cache->set($lang_code . $display_code, $translated_name); } } return $translated_name; }