function _icl_translation_send_strings_icanlocalize($string_ids, $target) { global $wpdb, $sitepress, $sitepress_settings; if (!$sitepress_settings['st']['strings_language']) { $sitepress_settings['st']['strings_language'] = $sitepress->get_default_language(); } $target_details = $sitepress->get_language_details($target); // get all the untranslated strings $untranslated = array(); foreach ($string_ids as $st_id) { $status = $wpdb->get_var($wpdb->prepare("SELECT status FROM {$wpdb->prefix}icl_string_translations WHERE string_id=%d and language=%s", $st_id, $target)); if ($status != ICL_STRING_TRANSLATION_COMPLETE) { $untranslated[] = $st_id; } } if (sizeof($untranslated) > 0) { // Something to translate. $target_for_server = array(ICL_Pro_Translation::server_languages_map($target_details['english_name'])); //filter some language names to match the names on the server $data = array('url' => '', 'target_languages' => $target_for_server); $string_values = array(); foreach ($untranslated as $st_id) { $string = $wpdb->get_row($wpdb->prepare("SELECT context, name, value FROM {$wpdb->prefix}icl_strings WHERE id=%d", $st_id)); $string_values[$st_id] = $string->value; $data['contents']['string-' . $st_id . '-context'] = array('translate' => 0, 'data' => base64_encode(htmlspecialchars($string->context)), 'format' => 'base64'); $data['contents']['string-' . $st_id . '-name'] = array('translate' => 0, 'data' => base64_encode(htmlspecialchars($string->name)), 'format' => 'base64'); $data['contents']['string-' . $st_id . '-value'] = array('translate' => 1, 'data' => base64_encode(htmlspecialchars($string->value)), 'format' => 'base64'); } $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']); $orig_lang = $sitepress->get_language_details($sitepress_settings['st']['strings_language']); $orig_lang_for_server = ICL_Pro_Translation::server_languages_map($orig_lang['english_name']); $timestamp = date('Y-m-d H:i:s'); $xml = $iclq->build_cms_request_xml($data, $orig_lang_for_server); $args = array('xml' => $xml, 'title' => "String translations", 'to_languages' => $target_for_server, 'orig_language' => $orig_lang_for_server); $res = $iclq->send_request($args); if ($res > 0) { foreach ($string_values as $st_id => $value) { $wpdb->insert($wpdb->prefix . 'icl_string_status', array('rid' => $res, 'string_translation_id' => $st_id, 'timestamp' => $timestamp, 'md5' => md5($value))); //insert rid } $wpdb->insert($wpdb->prefix . 'icl_core_status', array('rid' => $res, 'origin' => $orig_lang['code'], 'target' => $target, 'status' => CMS_REQUEST_WAITING_FOR_PROJECT_CREATION)); return $res; } else { return 0; } } }
function process_forms() { global $wpdb; require_once ICL_PLUGIN_PATH . '/lib/Snoopy.class.php'; require_once ICL_PLUGIN_PATH . '/lib/xml2array.php'; require_once ICL_PLUGIN_PATH . '/lib/icl_api.php'; if (isset($_POST['icl_post_action'])) { switch ($_POST['icl_post_action']) { case 'save_theme_localization': $locales = array(); foreach ($_POST as $k => $v) { if (0 !== strpos($k, 'locale_file_name_') || !trim($v)) { continue; } $locales[str_replace('locale_file_name_', '', $k)] = $v; } if (!empty($locales)) { $this->set_locale_file_names($locales); } break; } return; } $create_account = isset($_POST['icl_create_account_nonce']) && $_POST['icl_create_account_nonce'] == wp_create_nonce('icl_create_account'); $create_account_and_transfer = isset($_POST['icl_create_account_and_transfer_nonce']) && $_POST['icl_create_account_and_transfer_nonce'] == wp_create_nonce('icl_create_account_and_transfer'); $config_account = isset($_POST['icl_configure_account_nonce']) && $_POST['icl_configure_account_nonce'] == wp_create_nonce('icl_configure_account'); $create_support_account = isset($_POST['icl_create_support_account_nonce']) && $_POST['icl_create_support_account_nonce'] == wp_create_nonce('icl_create_support_account'); $config_support_account = isset($_POST['icl_configure_support_account_nonce']) && $_POST['icl_configure_support_account_nonce'] == wp_create_nonce('icl_configure_support_account'); $use_existing_account = isset($_POST['icl_use_account_nonce']) && $_POST['icl_use_account_nonce'] == wp_create_nonce('icl_use_account'); $transfer_to_account = isset($_POST['icl_transfer_account_nonce']) && $_POST['icl_transfer_account_nonce'] == wp_create_nonce('icl_transfer_account'); if ($create_account || $config_account || $create_support_account || $config_support_account) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button in wizard mode. $this->settings['content_translation_setup_wizard_step'] = 2; $this->save_settings(); } else { $user = $_POST['user']; $user['create_account'] = isset($_POST['icl_create_account_nonce']) || isset($_POST['icl_create_support_account_nonce']) ? 1 : 0; $user['platform_kind'] = 2; $user['cms_kind'] = 1; $user['blogid'] = $wpdb->blogid ? $wpdb->blogid : 1; $user['url'] = get_home_url(); $user['title'] = get_option('blogname'); $user['description'] = $this->settings['icl_site_description']; $user['is_verified'] = 1; if ($user['create_account'] && defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')) { $user['affiliate_id'] = ICL_AFFILIATE_ID; $user['affiliate_key'] = ICL_AFFILIATE_KEY; } $user['interview_translators'] = $this->settings['interview_translators']; $user['project_kind'] = $this->settings['website_kind']; /* if(is_null($user['project_kind']) || $user['project_kind']==''){ $_POST['icl_form_errors'] = __('Please select the kind of website','sitepress'); return; } */ $user['pickup_type'] = intval($this->settings['translation_pickup_method']); $notifications = 0; if ($this->settings['icl_notify_complete']) { $notifications += 1; } if ($this->settings['alert_delay']) { $notifications += 2; } $user['notifications'] = $notifications; // prepare language pairs $pay_per_use = $this->settings['translator_choice'] == 1; $language_pairs = $this->settings['language_pairs']; $lang_pairs = array(); if (isset($language_pairs)) { foreach ($language_pairs as $k => $v) { $english_fr = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); $pay_per_use_increment = 0; foreach ($v as $k => $v) { $pay_per_use_increment++; $english_to = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); $lang_pairs['from_language' . $pay_per_use_increment] = ICL_Pro_Translation::server_languages_map($english_fr); $lang_pairs['to_language' . $pay_per_use_increment] = ICL_Pro_Translation::server_languages_map($english_to); if ($pay_per_use) { $lang_pairs['pay_per_use' . $pay_per_use_increment] = 1; } } } } $icl_query = new ICanLocalizeQuery(); list($site_id, $access_key) = $icl_query->createAccount(array_merge($user, $lang_pairs)); if (!$site_id) { $user['pickup_type'] = ICL_PRO_TRANSLATION_PICKUP_POLLING; list($site_id, $access_key) = $icl_query->createAccount(array_merge($user, $lang_pairs)); } if (!$site_id) { if ($access_key) { $_POST['icl_form_errors'] = $access_key; } else { $_POST['icl_form_errors'] = __('An unknown error has occurred when communicating with the ICanLocalize server. Please try again.', 'sitepress'); // We will force the next try to be http. update_option('_force_mp_post_http', 1); } } else { if ($create_account || $config_account) { $iclsettings['site_id'] = $site_id; $iclsettings['access_key'] = $access_key; $iclsettings['icl_account_email'] = $user['email']; // set the support data the same. $iclsettings['support_site_id'] = $site_id; $iclsettings['support_access_key'] = $access_key; $iclsettings['support_icl_account_email'] = $user['email']; } else { $iclsettings['support_site_id'] = $site_id; $iclsettings['support_access_key'] = $access_key; $iclsettings['support_icl_account_email'] = $user['email']; } if (isset($user['pickup_type']) && $user['pickup_type'] == ICL_PRO_TRANSLATION_PICKUP_POLLING) { $iclsettings['translation_pickup_method'] = ICL_PRO_TRANSLATION_PICKUP_POLLING; } $this->save_settings($iclsettings); if ($user['create_account'] == 1) { $_POST['icl_form_success'] = __('A project on ICanLocalize has been created.', 'sitepress') . '<br />'; } else { $_POST['icl_form_success'] = __('Project added', 'sitepress'); } $this->get_icl_translator_status($iclsettings); $this->save_settings($iclsettings); } if (!$create_support_account && !$config_support_account && intval($site_id) > 0 && $access_key && $this->settings['content_translation_setup_complete'] == 0 && $this->settings['content_translation_setup_wizard_step'] == 3 && !isset($_POST['icl_form_errors'])) { // we are running the wizard, so we can finish it now. $this->settings['content_translation_setup_complete'] = 1; $this->settings['content_translation_setup_wizard_step'] = 0; $this->save_settings(); } } } elseif ($use_existing_account || $transfer_to_account || $create_account_and_transfer) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button in wizard mode. $this->settings['content_translation_setup_wizard_step'] = 2; $this->save_settings(); } else { if ($transfer_to_account) { $_POST['user']['email'] = $_POST['user']['email2']; } // we will be using the support account for the icl_account $this->settings['site_id'] = $this->settings['support_site_id']; $this->settings['access_key'] = $this->settings['support_access_key']; $this->settings['icl_account_email'] = $this->settings['support_icl_account_email']; $this->save_settings(); if ($transfer_to_account || $create_account_and_transfer) { if (!$this->transfer_icl_account($create_account_and_transfer)) { return; } } // we are running the wizard, so we can finish it now. $this->settings['content_translation_setup_complete'] = 1; $this->settings['content_translation_setup_wizard_step'] = 0; $this->save_settings(); $iclsettings['site_id'] = $this->settings['site_id']; $iclsettings['access_key'] = $this->settings['access_key']; $this->get_icl_translator_status($iclsettings); $this->save_settings($iclsettings); } } elseif (isset($_POST['icl_initial_languagenonce']) && $_POST['icl_initial_languagenonce'] == wp_create_nonce('icl_initial_language')) { $this->prepopulate_translations($_POST['icl_initial_language_code']); $wpdb->update($wpdb->prefix . 'icl_languages', array('active' => '1'), array('code' => $_POST['icl_initial_language_code'])); $blog_default_cat = get_option('default_category'); $blog_default_cat_tax_id = $wpdb->get_var("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id='{$blog_default_cat}' AND taxonomy='category'"); if (isset($_POST['save_one_language'])) { $this->settings['setup_wizard_step'] = 0; $this->settings['setup_complete'] = 1; } else { $this->settings['setup_wizard_step'] = 2; } $this->settings['default_categories'] = array($_POST['icl_initial_language_code'] => $blog_default_cat_tax_id); $this->settings['existing_content_language_verified'] = 1; $this->settings['default_language'] = $_POST['icl_initial_language_code']; $this->settings['admin_default_language'] = $this->admin_language = $_POST['icl_initial_language_code']; // set the locale in the icl_locale_map (if it's not set) $q = "SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE code=%s"; $q_prepared = $wpdb->prepare($q, $_POST['icl_initial_language_code']); if (!$wpdb->get_var($q_prepared)) { $q = "SELECT default_locale FROM {$wpdb->prefix}icl_languages WHERE code=%s"; $q_prepared = $wpdb->prepare($q, $_POST['icl_initial_language_code']); $default_locale = $wpdb->get_var($q_prepared); if ($default_locale) { $wpdb->insert($wpdb->prefix . 'icl_locale_map', array('code' => $_POST['icl_initial_language_code'], 'locale' => $default_locale)); } } $this->save_settings(); global $sitepress_settings; $sitepress_settings = $this->settings; $this->get_active_languages(true); //refresh active languages list do_action('icl_initial_language_set'); } elseif (isset($_POST['icl_language_pairs_formnounce']) && $_POST['icl_language_pairs_formnounce'] == wp_create_nonce('icl_language_pairs_form')) { $this->save_language_pairs(); $this->settings['content_translation_languages_setup'] = 1; // Move onto the site description page $this->settings['content_translation_setup_wizard_step'] = 2; $this->settings['website_kind'] = 2; $this->settings['interview_translators'] = 1; $this->save_settings(); } elseif (isset($_POST['icl_site_description_wizardnounce']) && $_POST['icl_site_description_wizardnounce'] == wp_create_nonce('icl_site_description_wizard')) { if (isset($_POST['icl_content_trans_setup_back_2'])) { // back button. $this->settings['content_translation_languages_setup'] = 0; $this->settings['content_translation_setup_wizard_step'] = 1; $this->save_settings(); } elseif (isset($_POST['icl_content_trans_setup_next_2']) || isset($_POST['icl_content_trans_setup_next_2_enter'])) { // next button. $description = $_POST['icl_description']; if ($description == "") { $_POST['icl_form_errors'] = __('Please provide a short description of the website so that translators know what background is required from them.', 'sitepress'); } else { $this->settings['icl_site_description'] = $description; $this->settings['content_translation_setup_wizard_step'] = 3; $this->save_settings(); } } } }
function send_comment_to_translation($comment_id, $to_language) { global $wpdb, $sitepress_settings, $sitepress; $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']); $from_lang = $sitepress->get_language_details($this->user_language); $to_lang = $sitepress->get_language_details($to_language); $from_lang_server = ICL_Pro_Translation::server_languages_map($from_lang['english_name']); $to_lang_server = ICL_Pro_Translation::server_languages_map($to_lang['english_name']); $body = $wpdb->get_var("SELECT comment_content FROM {$wpdb->comments} WHERE comment_ID={$comment_id}"); $rid = $iclq->cms_create_message($body, $from_lang_server, $to_lang_server); if ($rid > 0) { // does this comment already exist in the messages status queue? $msid = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}icl_message_status WHERE object_type='comment' AND object_id={$comment_id}"); if ($msid) { $wpdb->update($wpdb->prefix . 'icl_message_status', array('rid' => $rid, 'md5' => md5($body), 'status' => MESSAGE_TRANSLATION_IN_PROGRESS), array('id' => $msid)); } else { $wpdb->insert($wpdb->prefix . 'icl_message_status', array('rid' => $rid, 'object_id' => $comment_id, 'from_language' => $this->user_language, 'to_language' => $to_language, 'md5' => md5($body), 'object_type' => 'comment', 'status' => MESSAGE_TRANSLATION_IN_PROGRESS)); } } }
//break; //break; case 'icl_cms_id_fix': $iclq = new ICanLocalizeQuery($sitepress_settings['site_id'], $sitepress_settings['access_key']); $p = $wpdb->get_row("SELECT t.* FROM {$wpdb->prefix}icl_translations t JOIN {$wpdb->prefix}icl_translation_status s ON t.translation_id=s.translation_id\n WHERE t.element_type LIKE 'post\\_%' AND t.source_language_code IS NOT NULL AND s.translation_service='icanlocalize' LIMIT {$_REQUEST['offset']}, 1"); if (!empty($p)) { $original_id = $wpdb->get_var($wpdb->prepare("SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE trid=%d AND source_language_code IS NULL", $p->trid)); if ($p->element_type == 'post_page') { $permalink = get_option('home') . '?page_id=' . $original_id; } else { $permalink = get_option('home') . '?p=' . $original_id; } $_lang_details = $sitepress->get_language_details($p->source_language_code); $from_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']); $_lang_details = $sitepress->get_language_details($p->language_code); $to_language = ICL_Pro_Translation::server_languages_map($_lang_details['english_name']); $cms_id = sprintf('%s_%d_%s_%s', preg_replace('#^post_#', '', $p->element_type), $original_id, $p->source_language_code, $p->language_code); $ret = $iclq->update_cms_id(compact('permalink', 'from_language', 'to_language', 'cms_id')); if ($ret != $cms_id && $iclq->error()) { echo json_encode(array('errors' => 1, 'message' => $iclq->error(), 'cont' => 0)); } else { echo json_encode(array('errors' => 0, 'message' => 'OK', 'cont' => 1)); } } else { echo json_encode(array('errors' => 0, 'message' => __('Done', 'sitepress'), 'cont' => 0)); } exit; //break; //break; case 'icl_cleanup': global $sitepress, $wpdb, $wp_post_types;
// included from Sitepress::reminder_popups // // NOTE: this is also used for other popup links to ICanLocalize global $wpdb; $target = $_GET['target']; $auto_resize = isset($_GET['auto_resize']) && $_GET['auto_resize']; $unload_cb = isset($_GET['unload_cb']) ? $_GET['unload_cb'] : false; if (preg_match('|^@select-translators;([^;]+);([^;]+)@|', $target, $matches)) { $from_lang = $matches[1]; $to_lang = $matches[2]; require_once ICL_PLUGIN_PATH . '/lib/Snoopy.class.php'; require_once ICL_PLUGIN_PATH . '/lib/xml2array.php'; require_once ICL_PLUGIN_PATH . '/lib/icl_api.php'; $icl_query = new ICanLocalizeQuery(); foreach ($this->get_active_languages() as $lang) { $lang_server[$lang['code']] = ICL_Pro_Translation::server_languages_map($lang['english_name']); } if (!$this->icl_account_configured()) { $user['create_account'] = 1; $user['anon'] = 1; $user['platform_kind'] = 2; $user['cms_kind'] = 1; $user['blogid'] = $wpdb->blogid ? $wpdb->blogid : 1; $user['url'] = get_option('siteurl'); $user['title'] = get_option('blogname'); $user['description'] = @strval($this->settings['icl_site_description']); $user['is_verified'] = 1; if (defined('ICL_AFFILIATE_ID') && defined('ICL_AFFILIATE_KEY')) { $user['affiliate_id'] = ICL_AFFILIATE_ID; $user['affiliate_key'] = ICL_AFFILIATE_KEY; }
/** * Creates and sends translation snapshots. * * Called by the scheduled cron event. */ function send_translation_snapshots() { if (!defined('ICL_PLUGIN_PATH')) { return; } require_once ICL_PLUGIN_PATH . '/inc/translation-management/pro-translation.class.php'; global $sitepress, $sitepress_settings; if (isset($sitepress_settings['site_id'])) { $jobs = $this->get_translation_jobs(); $total_word_count = $this->get_translation_word_count($jobs); // Do not send snapshots when nothing changed $icl_settings = $sitepress->get_settings(); if (isset($icl_settings['snapshot_word_count']) and $icl_settings['snapshot_word_count'] == $total_word_count) { return; } else { $icl_settings['snapshot_word_count'] = $total_word_count; $sitepress->save_settings($icl_settings); } $datetime = new DateTime(); if (!empty($total_word_count['total'])) { foreach ($total_word_count['total'] as $from => $to_list) { foreach ($to_list as $to => $value) { // Convert language names to icanlocalize format $from_language_name = ICL_Pro_Translation::server_languages_map($from); $to_language_name = ICL_Pro_Translation::server_languages_map($to); $params = array('date' => $datetime->format("Y-m-d\\TH:i:s-P"), 'from_language_name' => $from_language_name, 'to_language_name' => $to_language_name, 'words_to_translate' => $value, 'translated_words' => $total_word_count['finished'][$from][$to]); $this->send_translation_snapshot_to_icl($params); } } } } }
$sitepress->save_settings(array('quote-get' => $saved)); echo __('An unknown error has occurred when communicating with the ICanLocalize server. Please try again.', 'sitepress') . '<br /><br />'; require_once ICL_PLUGIN_PATH . '/inc/quote/quote-get.php'; exit; } } /** * Set URL query */ $language_pairs = array($saved['from'] => $saved['to']); $lang_pairs = array(); $incr = 1; $query = ''; if (isset($language_pairs)) { foreach ($language_pairs as $k => $v) { $english_from = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); $query .= '&to_lang_num=' . count($v); $query .= '&from_language_name=' . $english_from; foreach ($v as $k => $v) { $english_to = $wpdb->get_var("SELECT english_name FROM {$wpdb->prefix}icl_languages WHERE code='{$k}' "); $query .= '&to_language_name_' . $incr . '=' . ICL_Pro_Translation::server_languages_map($english_to); $incr++; } } } $url = ICL_API_ENDPOINT . '/websites/' . $site_id . '/quote?accesskey=' . $access_key . '&locale=' . $sitepress->get_default_language() . $query . '&compact=1'; // Call reopen JS echo '<script type="text/javascript">icl_thickbox_reopen(\'' . $url . '\');</script>'; exit; } }