private function init_metabox_data() { $this->metabox_data = array(); $this->active_languages = $this->sitepress->get_active_languages(); $this->default_language = $this->sitepress->get_default_language(); $this->metabox_data['title'] = __('WPML Translation', 'wpml-string-translation'); $this->metabox_data['package_language_title'] = sprintf(__('Language of this %s is %s', 'wpml-string-translation'), $this->package->kind, $this->active_languages[$this->default_language]['display_name']); $this->metabox_data['translate_title'] = sprintf(__('Send %s to translation', 'wpml-string-translation'), $this->package->kind); if ($this->got_package()) { $this->metabox_data['statuses_title'] = __('Translation status:', 'wpml-string-translation'); $this->init_translation_statuses(); } else { $this->metabox_data['statuses_title'] = __('There is nothing to translate.', 'wpml-string-translation'); } }
/** * @param string $link * * @return bool|string */ private function get_url_in_default_language_if_rel_canonical($link) { if ($this->is_permalink_filter_from_rel_canonical()) { $default_language = $this->sitepress->get_default_language(); $link = (string) $this->sitepress->convert_url($link, $default_language); } return $link; }
/** * get current language */ public static function get_current_lang() { self::validate_wpml_exists(); $wpml = new SitePress(); if (is_admin()) { $lang = $wpml->get_default_language(); } else { $lang = self::get_current_lang_code(); } return $lang; }
/** * Uses the data retrieved from the database and saves information about, * in need of fixing terms to this object. * * @return array */ private function prepare_missing_terms_data() { $default_lang = $this->sitepress->get_default_language(); $data = $this->data; $missing = array(); foreach ($data as $ttid => $data_item) { if (empty($data_item['plangs']) && empty($data_item['tlang'])) { $missing[$ttid][$default_lang] = -1; } else { $affected_languages = array_diff($data_item['plangs'], $data_item['tlang']); if (!empty($affected_languages)) { foreach ($data_item['plangs'] as $post_id => $lang) { if (!isset($missing[$ttid][$lang])) { $missing[$ttid][$lang] = array($post_id); } else { $missing[$ttid][$lang][] = $post_id; } } } } } $this->missing_terms = $missing; }
public static function wpml_get_table_taxonomies(SitePress $sitepress) { $taxonomies = $sitepress->get_wp_api()->get_taxonomies(array(), 'objects'); $result = array("taxonomies" => array(), "activeLanguages" => array(), "allLanguages" => array()); $sitepress->set_admin_language(); $active_langs = $sitepress->get_active_languages(); $default_lang = $sitepress->get_default_language(); $result["activeLanguages"][$default_lang] = array("label" => $active_langs[$default_lang]['display_name'], "flag" => $sitepress->get_flag_url($default_lang)); foreach ($active_langs as $code => $lang) { if ($code !== $default_lang) { $result["activeLanguages"][$code] = array("label" => $lang['display_name'], "flag" => $sitepress->get_flag_url($code)); } } $all_languages = $sitepress->get_languages(); foreach ($all_languages as $code => $lang) { $result["allLanguages"][$code] = array("label" => $lang['display_name'], "flag" => $sitepress->get_flag_url($code)); } foreach ($taxonomies as $key => $tax) { if ($sitepress->is_translated_taxonomy($key)) { $result["taxonomies"][$key] = array("label" => $tax->label, "singularLabel" => $tax->labels->singular_name, "hierarchical" => $tax->hierarchical, "name" => $key); } } return $result; }
/** * * get current language */ public static function getCurrentLang() { self::validateWpmlExists(); $wpml = new SitePress(); if (is_admin()) { $lang = $wpml->get_default_language(); } else { $lang = RevSliderFunctionsWP::getCurrentLangCode(); } /* NEW: if ( is_admin() ) { return apply_filters( 'wpml_default_language', null ); } return apply_filters( 'wpml_current_language', null ); */ return $lang; }
if (get_option('_wpml_inactive', false) && isset($wpmu_sitewide_plugins[ICL_PLUGIN_FOLDER . '/sitepress.php'])) { wpml_set_plugin_as_inactive(); return; } } if (!wp_next_scheduled('update_wpml_config_index')) { //Set cron job to update WPML config index file from CDN wp_schedule_event(time(), 'daily', 'update_wpml_config_index'); } /** @var WPML_Post_Translation $wpml_post_translations */ global $sitepress, $wpdb, $wpml_url_filters, $wpml_post_translations, $wpml_term_translations, $wpml_url_converter, $wpml_language_resolution, $wpml_slug_filter; $sitepress = new SitePress(); new WPML_Global_AJAX($sitepress); wpml_load_query_filter(icl_get_setting('setup_complete')); $wpml_url_filters = new WPML_URL_Filters($wpml_post_translations, $wpml_url_converter, $sitepress); wpml_load_request_handler(is_admin(), $wpml_language_resolution->get_active_language_codes(), $sitepress->get_default_language()); require ICL_PLUGIN_PATH . '/inc/url-handling/wpml-slug-filter.class.php'; $wpml_slug_filter = new WPML_Slug_Filter($wpdb, $sitepress, $wpml_post_translations); /** @var array $sitepress_settings */ $sitepress_settings = $sitepress->get_settings(); wpml_load_term_filters(); wpml_maybe_setup_post_edit(); require ICL_PLUGIN_PATH . '/modules/cache-plugins-integration/cache-plugins-integration.php'; require ICL_PLUGIN_PATH . '/inc/wp-login-filters.php'; require ICL_PLUGIN_PATH . '/inc/plugins-integration.php'; if (is_admin()) { activate_installer($sitepress); if ($sitepress->get_setting('setup_complete')) { setup_admin_menus(); } }
function icl_upgrade_2_0_0_steps($step, $stepper) { global $wpdb, $sitepress, $wp_post_types, $sitepress_settings; if (!isset($sitepress)) { $sitepress = new SitePress(); } $TranslationManagement = new TranslationManagement(); $default_language = $sitepress->get_default_language(); define('ICL_TM_DISABLE_ALL_NOTIFICATIONS', true); // make sure no notifications are being sent //if(defined('icl_upgrade_2_0_0_runonce')){ // return; //} //define('icl_upgrade_2_0_0_runonce', true); // fix source_language_code // assume that the lowest element_id is the source language ini_set('max_execution_time', 300); $post_types = array_keys($wp_post_types); foreach ($post_types as $pt) { $types[] = 'post_' . $pt; } $temp_upgrade_data = get_option('icl_temp_upgrade_data', array('step' => 0, 'offset' => 0)); switch ($step) { case 1: // if the tables are missing, call the plugin activation routine $table_name = $wpdb->prefix . 'icl_translation_status'; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") != $table_name) { icl_sitepress_activate(); } $wpdb->query("ALTER TABLE `{$wpdb->prefix}icl_translations` CHANGE `element_type` `element_type` VARCHAR( 32 ) NOT NULL DEFAULT 'post_post'"); $wpdb->query("ALTER TABLE `{$wpdb->prefix}icl_translations` CHANGE `element_id` `element_id` BIGINT( 20 ) NULL DEFAULT NULL "); // fix source_language_code // all source documents must have null if (isset($types)) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translations SET source_language_code = NULL\n\t\t\t\t\tWHERE element_type IN('" . join("','", $types) . "') AND source_language_code = '' AND language_code=%s", $default_language)); // get translated documents with missing source language $res = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\tSELECT translation_id, trid, language_code\n\t\t\t\t\tFROM {$wpdb->prefix}icl_translations\n\t\t\t\t\tWHERE (source_language_code = '' OR source_language_code IS NULL)\n\t\t\t\t\t\tAND element_type IN('" . join("','", $types) . "')\n\t\t\t\t\t\tAND language_code <> %s\n\t\t\t\t\t\t", $default_language)); foreach ($res as $row) { $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}icl_translations SET source_language_code = %s WHERE translation_id=%d", $default_language, $row->translation_id)); } } $temp_upgrade_data['step'] = 2; update_option('icl_temp_upgrade_data', $temp_upgrade_data); return array('message' => __('Processing translations...', 'sitepress')); break; case 2: $limit = 100; $offset = $temp_upgrade_data['offset']; $processing = FALSE; //loop existing translations if (isset($types)) { $res = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations\n WHERE element_type IN(" . wpml_prepare_in($types) . " )\n AND source_language_code IS NULL LIMIT %d OFFSET %d", array($limit, $offset))); foreach ($res as $row) { $processing = TRUE; // grab translations $translations = $sitepress->get_element_translations($row->trid, $row->element_type); $md5 = 0; $table_name = $wpdb->prefix . 'icl_node'; if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) { list($md5, $links_fixed) = $wpdb->get_row($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT md5, links_fixed FROM {$wpdb->prefix}icl_node\n\t\t\t\t\t\t\tWHERE nid = %d\n\t\t\t\t\t\t", $row->element_id), ARRAY_N); } if (!$md5) { $md5 = $TranslationManagement->post_md5($row->element_id); } $translation_package = $TranslationManagement->create_translation_package($row->element_id); foreach ($translations as $lang => $t) { if (!$t->original) { // determine service and status $service = 'local'; $needs_update = 0; list($rid, $status, $current_md5) = $wpdb->get_row($wpdb->prepare("\n\t\t\t\t\t\t\t\tSELECT c.rid, n.status , c.md5\n\t\t\t\t\t\t\t\tFROM {$wpdb->prefix}icl_content_status c\n\t\t\t\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_core_status n ON c.rid = n.rid\n\t\t\t\t\t\t\t\tWHERE c.nid = %d AND target = %s\n\t\t\t\t\t\t\t\tORDER BY rid DESC\n\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t", $row->element_id, $lang), ARRAY_N); $translator_id = false; if ($rid) { if ($current_md5 != $md5) { $needs_update = 1; } if ($status == 3) { $status = 10; } else { $status = 2; } $service = 'icanlocalize'; foreach ($sitepress_settings['icl_lang_status'] as $lpair) { if ($lpair['from'] == $row->language_code && $lpair['to'] == $lang && isset($lpair['translators'][0]['id'])) { $translator_id = $lpair['translators'][0]['id']; break; } } } else { $status = 10; $translator_id = $wpdb->get_var($wpdb->prepare("SELECT post_author FROM {$wpdb->posts} WHERE ID=%d", $t->element_id)); $tlp = get_user_meta($translator_id, $wpdb->prefix . 'language_pairs', true); $tlp[$row->language_code][$lang] = 1; $TranslationManagement->edit_translator($translator_id, $tlp); } // add translation_status record list($newrid) = $TranslationManagement->update_translation_status(array('translation_id' => $t->translation_id, 'status' => $status, 'translator_id' => $translator_id, 'needs_update' => $needs_update, 'md5' => $md5, 'translation_service' => $service, 'translation_package' => serialize($translation_package), 'links_fixed' => intval(isset($links_fixed) ? $links_fixed : 0))); $job_id = $TranslationManagement->add_translation_job($newrid, $translator_id, $translation_package); if ($job_id && $status == 10) { $post = get_post($t->element_id); $TranslationManagement->save_job_fields_from_post($job_id, $post); } } } } } if ($processing) { update_option('icl_temp_upgrade_data', array('step' => 2, 'offset' => intval($offset + 100))); $stepper->setNextStep(2); } else { update_option('icl_temp_upgrade_data', array('step' => 3, 'offset' => 1.0E+20)); } $message = $processing ? __('Processing translations...', 'sitepress') : __('Finalizing upgrade...', 'sitepress'); return array('message' => $message); break; case 3: // removing the plugins text table; importing data into a Sitepress setting $results = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}icl_plugins_texts"); if (!empty($results)) { foreach ($results as $row) { $cft[$row->attribute_name] = $row->translate + 1; } if (isset($cft)) { $iclsettings['translation-management']['custom_fields_translation'] = $cft; $sitepress->save_settings($iclsettings); } $wpdb->query("DROP TABLE {$wpdb->prefix}icl_plugins_texts"); } $iclsettings['language_selector_initialized'] = 1; if (get_option('_force_mp_post_http')) { $iclsettings['troubleshooting_options']['http_communication'] = intval(get_option('_force_mp_post_http')); delete_option('_force_mp_post_http'); } // set default translators if (isset($sitepress_settings['icl_lang_status'])) { foreach ($sitepress_settings['icl_lang_status'] as $lpair) { if (!empty($lpair['translators'])) { $iclsettings['default_translators'][$lpair['from']][$lpair['to']] = array('id' => $lpair['translators'][0]['id'], 'type' => 'icanlocalize'); } } } $sitepress->save_settings($iclsettings); $iclsettings['migrated_2_0_0'] = 1; $sitepress->save_settings($iclsettings); delete_option('icl_temp_upgrade_data'); return array('message' => __('Done', 'sitepress'), 'completed' => 1); break; default: return array('error' => __('Missing step', 'sitepress'), 'stop' => 1); } }
/** * * get current language */ public static function getCurrentLang() { self::validateWpmlExists(); $wpml = new SitePress(); if (is_admin()) { $lang = $wpml->get_default_language(); } else { $lang = UniteFunctionsWPRev::getCurrentLangCode(); } return $lang; }
/** * @param integer $post_id * @param SitePress $sitepress * @return bool|mixed|null|string|void */ protected function get_save_post_lang($post_id, $sitepress) { $language_code = $this->get_element_lang_code($post_id); $language_code = $language_code ? $language_code : $sitepress->get_current_language(); $language_code = $sitepress->is_active_language($language_code) ? $language_code : $sitepress->get_default_language(); return apply_filters('wpml_save_post_lang', $language_code); }