/** * @return bool|array */ public static function get_extra_fields_local() { global $sitepress; $service = TranslationProxy::get_current_service(); $icl_translation_projects = $sitepress->get_setting('icl_translation_projects'); if (isset($icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields']) && !empty($icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields'])) { return $icl_translation_projects[TranslationProxy_Project::generate_service_index($service)]['extra_fields']; } else { return false; } }
/** * * Get information about translators from current project. Works only for ICL as a Translation Service * * @global object $sitepress * * @return array */ public static function get_icl_translator_status() { /** @var WPML_Pro_Translation $ICL_Pro_Translation */ global $sitepress, $ICL_Pro_Translation; if (!TranslationProxy::translator_selection_available()) { return false; } $project = TranslationProxy::get_current_project(); if (!$project) { return false; } $cache_key = md5(serialize($project)); $cache_group = 'get_icl_translator_status'; $found = false; $result = wp_cache_get($cache_key, $cache_group, false, $found); if ($found) { return $result; } $iclsettings = array(); $website_details = self::get_website_details(new TranslationProxy_Project(TranslationProxy::get_current_service())); if ((bool) $website_details === false) { return false; } $language_pairs = array(); if (isset($website_details['translation_languages']['translation_language'])) { $translation_languages = $website_details['translation_languages']['translation_language']; if (!isset($translation_languages[0])) { $buf = $translation_languages; $translation_languages = array(0 => $buf); } foreach ($translation_languages as $lang) { $translators = $_tr = array(); $max_rate = false; if (isset($lang['translators']) && !empty($lang['translators'])) { if (!isset($lang['translators']['translator'][0])) { $_tr[0] = $lang['translators']['translator']; } else { $_tr = $lang['translators']['translator']; } foreach ($_tr as $t) { if ($max_rate === false || $t['attr']['amount'] > $max_rate) { $max_rate = $t['attr']['amount']; } $translators[] = array('id' => $t['attr']['id'], 'nickname' => $t['attr']['nickname'], 'contract_id' => $t['attr']['contract_id']); } } $language_pairs[] = array('from' => $sitepress->get_language_code($ICL_Pro_Translation->server_languages_map($lang['attr']['from_language_name'], true)), 'to' => $sitepress->get_language_code($ICL_Pro_Translation->server_languages_map($lang['attr']['to_language_name'], true)), 'have_translators' => $lang['attr']['have_translators'], 'available_translators' => $lang['attr']['available_translators'], 'applications' => $lang['attr']['applications'], 'contract_id' => $lang['attr']['contract_id'], 'id' => $lang['attr']['id'], 'translators' => $translators, 'max_rate' => $max_rate); } } $iclsettings['icl_lang_status'] = $language_pairs; if (isset($res['client']['attr'])) { $iclsettings['icl_balance'] = $res['client']['attr']['balance']; $iclsettings['icl_anonymous_user'] = $res['client']['attr']['anon']; } if (isset($res['html_status']['value'])) { $iclsettings['icl_html_status'] = html_entity_decode($res['html_status']['value']); $iclsettings['icl_html_status'] = preg_replace_callback('#<a([^>]*)href="([^"]+)"([^>]*)>#i', create_function('$matches', 'global $sitepress; return TranslationProxy_Popup::get_link($matches[2]);'), $iclsettings['icl_html_status']); } if (isset($res['translators_management_info']['value'])) { $iclsettings['translators_management_info'] = html_entity_decode($res['translators_management_info']['value']); $iclsettings['translators_management_info'] = preg_replace_callback('#<a([^>]*)href="([^"]+)"([^>]*)>#i', create_function('$matches', 'global $sitepress; return TranslationProxy_Popup::get_link($matches[2]);'), $iclsettings['translators_management_info']); } $iclsettings['icl_support_ticket_id'] = @intval($res['attr']['support_ticket_id']); wp_cache_set($cache_key, $iclsettings, $cache_group); return $iclsettings; }
private function build_content_dashboard_remote_translations_controls() { // shows only when translation polling is on and there are translations in progress $this->build_content_dashboard_fetch_translations_box(); $active_service = icl_do_not_promote() ? false : TranslationProxy::get_current_service(); $service_dashboard_info = TranslationProxy::get_service_dashboard_info(); if ($active_service && $service_dashboard_info) { ?> <div class="icl_cyan_box"> <h3><?php echo $active_service->name . ' ' . __('account status', 'wpml-translation-management'); ?> </h3> <?php echo $service_dashboard_info; ?> </div> <?php } }
public function build_content_translation_services() { $reload = filter_input(INPUT_GET, 'reload_services', FILTER_VALIDATE_BOOLEAN); $services = TranslationProxy::services($reload); icl_handle_error($services); $active_service = TranslationProxy::get_current_service(); if (is_wp_error($active_service)) { icl_handle_error($active_service); $active_service = false; } ?> <div class="js-available-services"> <?php if (!defined('WPML_TP_DEFAULT_SUID') || !WPML_TP_DEFAULT_SUID) { echo $this->wpml_refresh_translation_services_button(); } ?> <div class="icl-current-service"> <?php if ($active_service) { ?> <div class="img-wrap"> <img src="<?php echo $active_service->logo_url; ?> " alt="<?php echo $active_service->name; ?> "/> </div> <div class="desc"> <?php if (!defined('WPML_TP_DEFAULT_SUID')) { ?> <h3><?php _e('Current service', 'wpml-translation-management'); ?> </h3> <?php } ?> <h4><?php echo $active_service->name; ?> </h4> <p> <?php echo $active_service->description; ?> </p> <?php echo translation_service_details($active_service, true); do_action('translation_service_authentication'); ?> </div> <?php } ?> </div> <?php if (!defined('WPML_TP_DEFAULT_SUID') && !empty($services)) { ?> <ul class="icl-available-services"> <?php foreach ($services as $service) { $state = $active_service && $service->id == $active_service->id ? "active" : "inactive"; if ($state === 'inactive') { ?> <li> <div class="img-wrap js-activate-service" data-target-id="<?php echo $service->id; ?> "> <img src="<?php echo $service->logo_url; ?> " alt="<?php echo $service->name; ?> "/> </div> <h4><?php echo $service->name; ?> </h4> <p> <?php echo $service->description; ?> <?php echo translation_service_details($active_service, true); ?> </p> <p> <button type="submit" class="js-activate-service-id" data-id="<?php echo $service->id; ?> " data-custom-fields="<?php echo esc_attr(wp_json_encode($service->custom_fields)); ?> "> <?php _e('Activate', 'wpml-translation-management'); ?> </button> </p> </li> <?php } } ?> </ul> <?php } ?> </div> <?php }
public static function translators_dropdown($args = array()) { $dropdown = ''; /** @var $from string|false */ /** @var $to string|false */ /** @var $classes string|false */ /** @var $id string|false */ /** @var $name string|false */ /** @var $selected bool */ /** @var $echo bool */ /** @var $add_label bool */ /** @var $services array */ /** @var $show_service bool */ /** @var $disabled bool */ /** @var $default_name bool|string */ /** @var $local_only bool */ //set default value for variables $from = false; $to = false; $id = 'translator_id'; $name = 'translator_id'; $selected = 0; $echo = true; $add_label = false; $services = array('local'); $show_service = true; $disabled = false; $default_name = false; $local_only = false; extract($args, EXTR_OVERWRITE); $translators = array(); try { $translation_service = TranslationProxy::get_current_service(); $translation_service_id = TranslationProxy::get_current_service_id(); $translation_service_name = TranslationProxy::get_current_service_name(); $is_service_authenticated = TranslationProxy::is_service_authenticated(); //if translation service does not support translators choice, always shows first available if (isset($translation_service->id) && !TranslationProxy::translator_selection_available() && $is_service_authenticated) { $translators[] = (object) array('ID' => TranslationProxy_Service::get_wpml_translator_id($translation_service->id), 'display_name' => __('First available', 'sitepress'), 'service' => $translation_service_name); } elseif (in_array($translation_service_id, $services) && $is_service_authenticated) { $lang_status = TranslationProxy_Translator::get_language_pairs(); if (empty($lang_status)) { $lang_status = array(); } foreach ((array) $lang_status as $language_pair) { if ($from && $from != $language_pair['from']) { continue; } if ($to && $to != $language_pair['to']) { continue; } if (!empty($language_pair['translators'])) { if (1 < count($language_pair['translators'])) { $translators[] = (object) array('ID' => TranslationProxy_Service::get_wpml_translator_id($translation_service->id), 'display_name' => __('First available', 'sitepress'), 'service' => $translation_service_name); } foreach ($language_pair['translators'] as $tr) { if (!isset($_icl_translators[$tr['id']])) { $translators[] = $_icl_translators[$tr['id']] = (object) array('ID' => TranslationProxy_Service::get_wpml_translator_id($translation_service->id, $tr['id']), 'display_name' => $tr['nickname'], 'service' => $translation_service_name); } } } } } if (in_array('local', $services)) { $translators[] = (object) array('ID' => 0, 'display_name' => __('First available', 'sitepress')); $translators = array_merge($translators, self::get_blog_translators(array('from' => $from, 'to' => $to))); } $translators = apply_filters('wpml_tm_translators_list', $translators); $dropdown .= '<select id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" ' . ($disabled ? 'disabled="disabled"' : '') . '>'; if ($default_name) { $dropdown_selected = selected($selected, false, false); $dropdown .= '<option value="" ' . $dropdown_selected . '>'; $dropdown .= esc_html($default_name); $dropdown .= '</option>'; } foreach ($translators as $t) { if ($local_only && isset($t->service)) { continue; } $current_translator = $t->ID; $dropdown_selected = selected($selected, $current_translator, false); $dropdown .= '<option value="' . $current_translator . '" ' . $dropdown_selected . '>'; $dropdown .= esc_html($t->display_name); if ($show_service) { $dropdown .= ' ('; $dropdown .= isset($t->service) ? $t->service : __('Local', 'sitepress'); $dropdown .= ')'; } $dropdown .= '</option>'; } $dropdown .= '</select>'; } catch (TranslationProxy_Api_Error $ex) { $dropdown .= __('Translation Proxy error', 'sitepress') . ': ' . $ex->getMessage(); } catch (Exception $ex) { $dropdown .= __('Error', 'sitepress') . ': ' . $ex->getMessage(); } if ($add_label) { $dropdown = '<label for="' . esc_attr($id) . '">' . __('Translation jobs for:', 'wpml-translation-management') . '</label> ' . $dropdown; } if ($echo) { echo $dropdown; } return $dropdown; }
protected function automatic_service_selection() { if (defined('DOING_AJAX') || !$this->automatic_service_selection_pages()) { return; } $done = wp_cache_get('done', 'automatic_service_selection'); ICL_AdminNotifier::remove_message('automatic_service_selection'); if (!$done && defined('WPML_TP_DEFAULT_SUID')) { $selected_service = TranslationProxy::get_current_service(); if (isset($selected_service->suid) && $selected_service->suid == WPML_TP_DEFAULT_SUID) { return; } try { $service_by_suid = TranslationProxy_Service::get_service_by_suid(WPML_TP_DEFAULT_SUID); } catch (Exception $ex) { $service_by_suid = false; } if (isset($service_by_suid->id)) { $selected_service_id = isset($selected_service->id) ? $selected_service->id : false; if (!$selected_service_id || $selected_service_id != $service_by_suid->id) { if ($selected_service_id) { TranslationProxy::deselect_active_service(); } $result = TranslationProxy::select_service($service_by_suid->id); if (is_wp_error($result)) { $error_data = $result->get_error_data(); $error_data_string = false; foreach ($error_data as $key => $error_data_message) { $error_data_string .= $result->get_error_message() . '<br/>'; $error_data_string .= $key . ': <pre>' . print_r($error_data_message, true) . '</pre>'; $error_data_string .= $result->get_error_message() . $error_data_string; } } if (defined('WPML_TP_SERVICE_CUSTOM_FIELDS')) { TranslationProxy::authenticate_service($service_by_suid->id, WPML_TP_SERVICE_CUSTOM_FIELDS); } } } else { $error_data_string = __("WPML can't find the translation service specified in WPML_TP_DEFAULT_SUID constant. Please remove the constant or set the correct value.", 'wpml-translation-management'); } } if (isset($error_data_string)) { $automatic_service_selection_args = array('id' => 'automatic_service_selection', 'group' => 'automatic_service_selection', 'msg' => $error_data_string, 'type' => 'error', 'admin_notice' => true, 'hide' => false); ICL_AdminNotifier::add_message($automatic_service_selection_args); } wp_cache_set('done', true, 'automatic_service_selection'); }
/** * * Downloads translation from TP and updates its document * * @param $translation_proxy_job_id * @param $cms_id * * @return bool|string * */ function download_and_process_translation($translation_proxy_job_id, $cms_id) { global $wpdb; if (empty($cms_id)) { // it's a string //TODO: [WPML 3.3] this should be handled as any other element type in 3.3 $target = $wpdb->get_var($wpdb->prepare("SELECT target FROM {$wpdb->prefix}icl_core_status WHERE rid=%d", $translation_proxy_job_id)); return $this->process_translated_string($translation_proxy_job_id, $target); } else { $translation_id = $this->cms_id_helper->get_translation_id($cms_id, TranslationProxy::get_current_service()); return !empty($translation_id) && $this->add_translated_document($translation_id, $translation_proxy_job_id); } }
private function automatic_service_selection() { if (defined('DOING_AJAX') || !$this->automatic_service_selection_pages()) { return; } $done = wp_cache_get('done', 'automatic_service_selection'); ICL_AdminNotifier::remove_message('automatic_service_selection'); $tp_default_suid = TranslationProxy::get_tp_default_suid(); if (!$done && $tp_default_suid) { $selected_service = TranslationProxy::get_current_service(); if (isset($selected_service->suid) && $selected_service->suid == $tp_default_suid) { return; } try { $service_by_suid = TranslationProxy_Service::get_service_by_suid($tp_default_suid); } catch (Exception $ex) { $service_by_suid = false; } if (isset($service_by_suid->id)) { $selected_service_id = isset($selected_service->id) ? $selected_service->id : false; if (!$selected_service_id || $selected_service_id != $service_by_suid->id) { if ($selected_service_id) { TranslationProxy::deselect_active_service(); } $result = TranslationProxy::select_service($service_by_suid->id); if (is_wp_error($result)) { $error_data = $result->get_error_data(); $error_data_string = false; foreach ($error_data as $key => $error_data_message) { $error_data_string .= $result->get_error_message() . '<br/>'; $error_data_string .= $key . ': <pre>' . print_r($error_data_message, true) . '</pre>'; $error_data_string .= $result->get_error_message() . $error_data_string; } } } } else { $error_data_string = __("WPML can't find the translation service. Please contact WPML Support or your translation service provider.", 'wpml-translation-management'); } } if (isset($error_data_string)) { $automatic_service_selection_args = array('id' => 'automatic_service_selection', 'group' => 'automatic_service_selection', 'msg' => $error_data_string, 'type' => 'error', 'admin_notice' => true, 'hide' => false); ICL_AdminNotifier::add_message($automatic_service_selection_args); } wp_cache_set('done', true, 'automatic_service_selection'); }
private function has_active_service() { return TranslationProxy::get_current_service() !== false; }
private function ts_supports_notifications() { $translation_service = TranslationProxy::get_current_service(); return $supports_notifications = isset($translation_service->notification) ? $translation_service->notification : true; }
public function build_content_translation_services() { $has_errors = false; $reload = filter_input(INPUT_GET, 'reload_services', FILTER_VALIDATE_BOOLEAN); $services = TranslationProxy::services($reload); $has_errors |= icl_handle_error($services); if (TranslationProxy::$errors) { $has_errors |= true; foreach (TranslationProxy::$errors as $error) { icl_handle_error($error); } } $active_service = TranslationProxy::get_current_service(); if (is_wp_error($active_service)) { $has_errors |= icl_handle_error($active_service); $active_service = false; } $service_activation_button_class = 'button-primary'; if ($active_service) { $service_activation_button_class = 'button-secondary'; } ?> <div class="js-available-services"> <?php if (!TranslationProxy::get_tp_default_suid()) { echo $this->wpml_refresh_translation_services_button(); } if ($this->translation_service_has_translators($active_service)) { echo $this->flush_website_details_cache_button(); } if (!$has_errors) { ?> <div class="icl-current-service"> <?php if ($active_service) { ?> <div class="img-wrap"> <img src="<?php echo $active_service->logo_url; ?> " alt="<?php echo $active_service->name; ?> "/> </div> <div class="desc"> <?php if (!TranslationProxy::get_tp_default_suid()) { ?> <h3><?php _e('Current service', 'wpml-translation-management'); ?> </h3> <?php } ?> <h4><?php echo $active_service->name; ?> </h4> <p> <?php echo $active_service->description; ?> </p> <?php echo translation_service_details($active_service, true); do_action('translation_service_authentication'); ?> </div> <?php } ?> </div> <?php if (!TranslationProxy::get_tp_default_suid() && !empty($services)) { ?> <ul class="icl-available-services"> <?php foreach ($services as $service) { $state = $active_service && $service->id == $active_service->id ? "active" : "inactive"; if ($state === 'inactive') { ?> <li> <div class="img-wrap js-activate-service" data-target-id="<?php echo $service->id; ?> "> <img src="<?php echo $service->logo_url; ?> " alt="<?php echo $service->name; ?> "/> </div> <h4><?php echo $service->name; ?> </h4> <p> <?php echo $service->description; ?> <?php echo translation_service_details($active_service, true); ?> </p> <p> <button type="submit" class="js-activate-service-id <?php echo $service_activation_button_class; ?> " data-id="<?php echo $service->id; ?> " data-custom-fields="<?php echo esc_attr(wp_json_encode($service->custom_fields)); ?> "> <?php _e('Activate', 'wpml-translation-management'); ?> </button> <?php if (isset($service->doc_url) && $service->doc_url) { ?> <a href="<?php echo $service->doc_url; ?> " target="_blank"><?php echo __('Documentation', 'wpml-translation-management'); ?> </a> <?php } ?> </p> </li> <?php } } ?> </ul> <?php } } ?> </div> <?php }
/** * Renders the html for the TP polling pickup box * * @return string */ public function render() { $logger_settings = new WPML_Jobs_Fetch_Log_Settings(); ob_start(); ?> <div id="icl_tm_pickup_wrap"> <div class="icl_cyan_box"> <div id="icl_tm_pickup_wrap_errors" class="icl_tm_pickup_wrap" style="display:none"><p></p></div> <div id="icl_tm_pickup_wrap_completed" class="icl_tm_pickup_wrap" style="display:none"><p></p> </div> <div id="icl_tm_pickup_wrap_cancelled" class="icl_tm_pickup_wrap" style="display:none"><p></p> </div> <div id="icl_tm_pickup_wrap_error_submitting" class="icl_tm_pickup_wrap" style="display:none"><p></p> </div> <p id="icl_pickup_nof_jobs"></p> <p><input type="button" class="button-secondary" data-reloading-text="<?php _e('Reloading:', 'wpml-translation-management'); ?> " value="" id="icl_tm_get_translations"/></p> <p> <a href="<?php echo esc_attr('admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php&sm=' . $logger_settings->get_ui_key()); ?> " class="button-secondary"> <?php _e('Open the content updates log', 'sitepress'); ?> </a> </p> <p id="icl_pickup_last_pickup"></p> <?php $translation_service = TranslationProxy::get_current_service(); if ($translation_service && property_exists($translation_service, 'has_language_pairs') && $translation_service->has_language_pairs) { ?> <p> <a href="#" class="button-secondary js-refresh-language-pairs" data-nonce="<?php echo wp_create_nonce('wpml-tp-refresh-language-pairs'); ?> "> <?php _e('Refresh language pairs', 'wpml-translation-management'); ?> </a> </p> <?php } ?> </div> <div id="tp_polling_job" style="display:none"></div> </div> <br clear="all"/> <?php wp_nonce_field('icl_pickup_translations_nonce', '_icl_nonce_pickup_t'); wp_nonce_field('icl_populate_translations_pickup_box_nonce', '_icl_nonce_populate_t'); wp_enqueue_script('wpml-tp-polling-setup'); return ob_get_clean(); }
<?php /* included from WPML_Translation_Management::icl_dashboard_widget_content */ global $sitepress, $ICL_Pro_Translation, $sitepress_settings, $sitepress, $current_user; //Todo: handle TS URLs $service = TranslationProxy::get_current_service(); //Todo: implement custom text if ($service) { $dashboard_text_url = sprintf(__('%s offers affordable professional translation via a streamlined process.', 'wpml-translation-management'), '<a target="_blank" href="' . esc_attr($service->url) . '">' . $service->name . '</a>'); } else { $dashboard_text_url = TranslationProxy::get_service_dashboard_info(); } ?> <p> <?php if ($docs_sent) { printf(__('%d documents sent to translation.<br />%d are complete, %d waiting for translation.', 'wpml-translation-management'), $docs_sent, $docs_completed, $docs_waiting); } ?> </p> <p> <a href="admin.php?page=<?php echo WPML_TM_FOLDER; ?> /menu/main.php" class="button secondary"> <strong><?php _e('Translate content', 'wpml-translation-management'); ?> </strong> </a>