public function render_ui()
 {
     if (TranslationProxy::get_tp_default_suid()) {
         $clear_ts = new WPML_TM_Troubleshooting_Clear_TS_UI();
         $clear_ts->show();
     }
 }
Exemple #2
0
function icl_populate_translations_pickup_box()
{
    if (!wpml_is_action_authenticated('icl_populate_translations_pickup_box')) {
        die('Wrong Nonce');
    }
    global $sitepress;
    $last_picked_up = $sitepress->get_setting('last_picked_up');
    $translation_offset = strtotime(current_time('mysql')) - @intval($last_picked_up) - 5 * 60;
    if (WP_DEBUG == false && $translation_offset < 0) {
        $time_left = floor(abs($translation_offset) / 60);
        if ($time_left == 0) {
            $time_left = abs($translation_offset);
            $wait_text = '<p><i>' . sprintf(__('You can check again in %s seconds.', 'sitepress'), '<span id="icl_sec_tic">' . $time_left . '</span>') . '</i></p>';
        } else {
            $wait_text = sprintf(__('You can check again in %s minutes.', 'sitepress'), '<span id="icl_sec_tic">' . $time_left . '</span>') . '</i></p>';
        }
        $result = array('wait_text' => $wait_text);
    } else {
        $project = TranslationProxy::get_current_project();
        $cms_id_helper = new WPML_TM_CMS_ID();
        $polling_status = new WPML_TP_Polling_Status($project, $sitepress, $cms_id_helper);
        $result = $polling_status->get_status_array();
    }
    wp_send_json_success($result);
}
 /**
  * Returns a WPML readable string that allows to tell translation service and translator id
  * (typically used for translators dropdowns)
  *
  * @param int|bool $translation_service_id
  * @param int|bool $translator_id
  *
  * @return string
  */
 public static function get_wpml_translator_id($translation_service_id = false, $translator_id = false)
 {
     if ($translation_service_id === false) {
         $translation_service_id = TranslationProxy::get_current_service_id();
     }
     $result = 'ts-' . $translation_service_id;
     if ($translator_id !== false) {
         $result .= '-' . $translator_id;
     }
     return $result;
 }
Exemple #4
0
function icl_pickup_translations()
{
    if (!wpml_is_action_authenticated('icl_pickup_translations')) {
        die('Wrong Nonce');
    }
    global $ICL_Pro_Translation, $wpdb;
    $job_factory = wpml_tm_load_job_factory();
    $wpml_tm_records = new WPML_TM_Records($wpdb);
    $cms_id_helper = new WPML_TM_CMS_ID($wpml_tm_records, $job_factory);
    $project = TranslationProxy::get_current_project();
    $remote_sync_factory = new WPML_TP_Remote_Sync_Factory($project, $ICL_Pro_Translation, $cms_id_helper);
    $pickup = new WPML_TP_Polling_Pickup($ICL_Pro_Translation, $remote_sync_factory);
    wp_send_json_success($pickup->poll_job($_POST));
}
 /**
  * @param TranslationProxy_Service $service
  * @param string                    $delivery
  */
 public function __construct($service, $delivery = 'xmlrpc')
 {
     $this->service = $service;
     $this->errors = array();
     $icl_translation_projects = TranslationProxy::get_translation_projects();
     $project_index = self::generate_service_index($service);
     if ($project_index && $icl_translation_projects && isset($icl_translation_projects[$project_index])) {
         $project = $icl_translation_projects[$project_index];
         $this->id = $project['id'];
         $this->access_key = $project['access_key'];
         $this->ts_id = $project['ts_id'];
         $this->ts_access_key = $project['ts_access_key'];
         $this->service->delivery_method = $delivery;
     }
 }
 function refresh_language_pairs()
 {
     $project = TranslationProxy::get_current_project();
     $nonce_is_valid = false;
     if (array_key_exists('nonce', $_POST)) {
         $nonce = $_POST['nonce'];
         $nonce_is_valid = wp_verify_nonce($nonce, 'wpml-tp-refresh-language-pairs');
     }
     if ($nonce_is_valid) {
         try {
             $this->wpml_tp_api->refresh_language_pairs($project);
             wp_send_json_success(esc_attr__('Language pairs refreshed.', 'wpml-translation-management'));
         } catch (Exception $e) {
             wp_send_json_error($e);
         }
     }
 }
 public function get_model()
 {
     $translation_service_name = TranslationProxy::get_current_service_name();
     $alert_1 = 'Use this feature when you want to reset your translation process. All your existing translations will remain unchanged. Any translation work that is currently in progress will be stopped.';
     $alert_2 = '';
     if (!$translation_service_name) {
         $translation_service_name = 'PRO';
         $alert_2 = 'Only select this option if you have no pending jobs or you are sure of what you are doing.';
     } else {
         if (!TranslationProxy::has_preferred_translation_service()) {
             $alert_2 = 'If you have sent content to %1$s, you should cancel the projects in %1$s system.';
         }
         $alert_2 .= 'Any work that completes after you do this reset cannot be received by your site.';
     }
     $model = array('strings' => array('title' => __('Reset professional translation state', 'wpml-translation-management'), 'alert1' => sprintf(__($alert_1, 'wpml-translation-management'), $translation_service_name), 'alert2' => sprintf(__($alert_2, 'wpml-translation-management'), $translation_service_name), 'checkBoxLabel' => sprintf(__('I am about to stop any ongoing work done by %1$s.', 'wpml-translation-management'), $translation_service_name), 'button' => __('Reset professional translation state', 'wpml-translation-management')), 'placeHolder' => 'icl_reset_pro');
     return $model;
 }
Exemple #8
0
function translation_service_details($service, $show_project = false)
{
    $service_details = '';
    if (defined('OTG_SANDBOX_DEBUG') && OTG_SANDBOX_DEBUG) {
        $service_details .= '<h3>Service details:</h3>' . PHP_EOL;
        $service_details .= '<pre>' . PHP_EOL;
        $service_details .= print_r($service, true);
        $service_details .= '</pre>' . PHP_EOL;
        if ($show_project) {
            $project = TranslationProxy::get_current_project();
            echo '<pre>$project' . PHP_EOL;
            echo print_r($project, true);
            echo '</pre>';
        }
    }
    return $service_details;
}
    static function menu()
    {
        global $wpdb, $sitepress;
        if (!class_exists('TranslationManagement')) {
            return;
        }
        $site_id = $sitepress->get_setting('site_id');
        $access_key = $sitepress->get_setting('access_key');
        ?>
		<h4><?php 
        _e('Translation Management', 'sitepress');
        ?>
</h4>
		<?php 
        $current_service_name = TranslationProxy::get_current_service_name();
        if ($site_id && $access_key) {
            ?>
			<p>
				<input id="icl_sync_jobs" type="button" class="button-secondary"
					   value="<?php 
            echo sprintf(__('Synchronize translation jobs with %s', 'sitepress'), $current_service_name);
            ?>
"/><br/>
				<small
					style="margin-left:10px;"><?php 
            echo sprintf(__('Fixes links between translation entries in the database and %s.', 'sitepress'), $current_service_name);
            ?>
</small>
			</p>
			<p>
				<input id="icl_cms_id_fix" type="button" class="button-secondary"
					   value="<?php 
            _e('CMS ID fix', 'sitepress');
            ?>
"/>
					<span id="icl_cms_id_fix_prgs" style="display: none;"><?php 
            $fixing_count_sql = "\n\t\t\t\t\t\tSELECT COUNT(*)\n\t\t\t\t\t\tFROM {$wpdb->prefix}icl_translations t\n\t\t\t\t\t\tJOIN {$wpdb->prefix}icl_translation_status s\n\t\t\t\t\t\t\tON t.translation_id=s.translation_id\n\t\t\t\t\t\tWHERE t.element_type LIKE 'post\\_%'\n\t\t\t\t\t\t\tAND t.source_language_code IS NOT NULL\n\t\t\t\t\t\t\tAND s.translation_service=%s\n\t\t\t\t\t\t";
            $fixing_count_prepared = $wpdb->prepare($fixing_count_sql, array($current_service_name));
            $fixing_count = $wpdb->get_var($fixing_count_prepared);
            printf(__('fixing %s/%d', 'sitepress'), '<span id="icl_cms_id_fix_prgs_cnt">0</span>', $fixing_count);
            ?>
</span><br/>
				<small
					style="margin-left:10px;"><?php 
            _e("Updates translation in progress with new style identifiers for documents. The new identifiers depend on the document being translated and the languages so it's not possible to get out of sync when translations are being deleted locally.", 'sitepress');
            ?>
</small>
			</p>
			<p>
				<input id="icl_sync_cancelled" type="button" class="button-secondary"
					   value="<?php 
            echo sprintf(__('Check cancelled jobs on %s', 'sitepress'), $current_service_name);
            ?>
"/><br/>
				<small
					style="margin-left:10px;"><?php 
            echo sprintf(__('When using the translation pickup mode cancelled jobs on %s need to be synced manually.', 'sitepress'), $current_service_name);
            ?>
</small>
			</p>
			<div id="icl_sync_cancelled_resp" class="clear"></div>
			<input type="hidden" id="icl_ts_t2c" value=""/>
			<?php 
        }
        ?>
		<br clear="all"/>
		<?php 
        if (SitePress_Setup::setup_complete()) {
            $translation_service_name = $current_service_name;
            //Todo: [WPML 3.3] Move JS to an external resource
            $translation_service_checkbox_js_code = "if(jQuery(this).attr('checked')) ";
            $translation_service_checkbox_js_code .= "jQuery('#icl_reset_pro_but').removeClass('button-primary-disabled'); ";
            $translation_service_checkbox_js_code .= "else jQuery('#icl_reset_pro_but').addClass('button-primary-disabled');";
            $translation_service_button_js_code = "if(!jQuery('#icl_reset_pro_check').attr('checked') || !confirm('";
            $translation_service_button_js_code .= esc_js(__('Are you sure you want to reset the PRO translation configuration?', 'sitepress'));
            $translation_service_button_js_code .= "')) return false;";
            ?>
			<br/>
			<div class="icl_cyan_box">
				<h3><?php 
            _e('Reset PRO translation configuration', 'sitepress');
            ?>
</h3>

				<div class="icl_form_errors">
					<?php 
            echo sprintf(__("Resetting your %s account will interrupt any translation jobs that you have in progress.", 'wpml-translation-management'), $translation_service_name);
            ?>
					<br/>
					<?php 
            echo sprintf(__("Only use this function if your current %s account doesn't include any jobs, or if the account was deleted.", 'wpml-translation-management'), $translation_service_name);
            ?>
				</div>
				<p style="padding:6px;">
					<label>
						<input onchange="<?php 
            echo $translation_service_checkbox_js_code;
            ?>
" id="icl_reset_pro_check"
							   type="checkbox" value="1"/>
						&nbsp;<?php 
            echo sprintf(__('I am about to reset the %s project settings.', 'sitepress'), $translation_service_name);
            ?>
					</label>
				</p>

				<a id="icl_reset_pro_but"
				   onclick="<?php 
            echo $translation_service_button_js_code;
            ?>
"
				   href="admin.php?page=<?php 
            echo basename(ICL_PLUGIN_PATH);
            ?>
/menu/troubleshooting.php&amp;debug_action=reset_pro_translation_configuration&amp;nonce=<?php 
            echo wp_create_nonce('reset_pro_translation_configuration');
            ?>
"
				   class="button-primary button-primary-disabled">
					<?php 
            _e('Reset PRO translation configuration', 'sitepress');
            ?>
				</a>

			</div>

			<br clear="all"/>
			<?php 
        }
        //Todo: [WPML 3.2.1] implement this
        if (1 == 2 && !icl_do_not_promote()) {
            ?>
			<div class="icl_cyan_box">
				<a name="icl-connection-test"></a>

				<h3><?php 
            _e('Translation Proxy connection test', 'sitepress');
            ?>
</h3>
				<?php 
            if (isset($_GET['icl_action']) && $_GET['icl_action'] == 'icl-connection-test') {
                ?>
					<?php 
                //TODO: [WPML 3.2.1] Handle with TP
                ?>

				<?php 
            }
            ?>
				<a class="button"
				   href="admin.php?page=<?php 
            echo ICL_PLUGIN_FOLDER;
            ?>
/menu/troubleshooting.php&ts=<?php 
            echo time();
            ?>
&icl_action=icl-connection-test#icl-connection-test"><?php 
            _e('Connect', 'sitepress');
            ?>
</a>
			</div>
			<br clear="all"/>
			<?php 
        }
    }
 private function process_translated_string($translation_proxy_job_id, $language)
 {
     $project = TranslationProxy::get_current_project();
     $translation = $project->fetch_translation($translation_proxy_job_id);
     $translation = apply_filters('icl_data_from_pro_translation', $translation);
     $ret = false;
     $translation = $this->xliff_reader_factory->string_xliff_reader()->get_data($translation);
     if ($translation) {
         $ret = icl_translation_add_string_translation($translation_proxy_job_id, $translation, $language);
         if ($ret) {
             $project->update_job($translation_proxy_job_id);
         }
     }
     return $ret;
 }
 public static function get_translator_name($translator_id)
 {
     if (TranslationProxy::translator_selection_available()) {
         $lang_status = self::get_language_pairs();
         if ($lang_status) {
             foreach ($lang_status as $lp) {
                 $lp_trans = !empty($lp['translators']) ? $lp['translators'] : array();
                 foreach ($lp_trans as $tr) {
                     $translators[$tr['id']] = $tr['nickname'];
                 }
             }
         }
     }
     return isset($translators[$translator_id]) ? $translators[$translator_id] : false;
 }
 /**
  * @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;
     }
 }
    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 
        }
    }
<?php

define('ICL_LANGUAGE_NOT_SUPPORTED', 3);
global $wpdb, $sitepress;
$target = filter_input(INPUT_GET, 'target', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$auto_resize = filter_input(INPUT_GET, 'auto_resize', FILTER_VALIDATE_BOOLEAN | FILTER_NULL_ON_FAILURE);
$unload_cb = filter_input(INPUT_GET, 'unload_cb', FILTER_SANITIZE_FULL_SPECIAL_CHARS | FILTER_NULL_ON_FAILURE);
// Adding a translator
if (preg_match('|^@select-translators;([^;]+);([^;]+)@|', $target, $matches)) {
    $source_language = $matches[1];
    $target_language = $matches[2];
    $project = TranslationProxy::get_current_project();
    try {
        $lp_setting_index = 'language_pairs';
        $language_pairs = $sitepress->get_setting($lp_setting_index, array());
        if (!isset($language_pairs[$source_language][$target_language]) || $language_pairs[$source_language][$target_language] == 0) {
            $language_pairs[$source_language][$target_language] = 1;
            TranslationProxy_Translator::update_language_pairs($project, $language_pairs);
            $sitepress->set_setting($lp_setting_index, $language_pairs, true);
        }
        $target = $project->select_translator_iframe_url($source_language, $target_language);
    } catch (Exception $e) {
        if ($e->getCode() == ICL_LANGUAGE_NOT_SUPPORTED) {
            printf(__('<p>Requested languages are not supported by the translation service (%s). Please <a%s>contact us</a> for support. </p>', 'sitepress'), $e->getMessage(), ' target="_blank" href="http://wpml.org/?page_id=5255"');
        } else {
            printf(__('<p>Could not add the requested languages. Please <a%s>contact us</a> for support. </p><p>Show <a%s>debug information</a>.</p>', 'sitepress'), ' target="_blank" href="http://wpml.org/?page_id=5255"', ' a href="admin.php?page=' . ICL_PLUGIN_FOLDER . '/menu/troubleshooting.php&icl_action=icl-connection-test' . '#icl-connection-test"');
        }
        exit;
    }
}
$target .= strpos($target, '?') === false ? '?' : '&';
 public function has_preferred_translation_service()
 {
     return TranslationProxy::has_preferred_translation_service();
 }
    private function display_advanced_filters()
    {
        ?>
        <tr id="icl_dashboard_advanced_filters" valign="top">
            <td>
                <strong><?php 
        echo __('Filters:', 'wpml-translation-management');
        ?>
</strong><br/>
                <fieldset>
                    <div class="fieldset_row">
                        <?php 
        $this->display_post_statuses_select();
        ?>
                    </div>
                    <div class="fieldset_row">
                        <?php 
        $this->display_post_type_select();
        ?>
                    </div>
                    <div class="fieldset_row">
                        <?php 
        $this->filter_title_textbox();
        ?>
                    </div>
                    <div class="fieldset_row">
                        <?php 
        $this->display_parent_filter_select();
        ?>
                    </div>
                    <div class="fieldset_row" id="icl_parent_filter">
                        <label for="icl_parent_filter_drop" id="icl_parent_filter_label"></label>
                        <select name="filter[parent_id]" id="icl_parent_filter_drop"></select>
                    </div>
                    <div class="fieldset_row">
                        <input id="translation_dashboard_filter" name="translation_dashboard_filter"
                               class="button-primary" type="submit"
                               value="<?php 
        echo __('Display', 'wpml-translation-management');
        ?>
"/>
                    </div>
                </fieldset>
                <?php 
        // filters end */
        ?>

            </td>
            <td align="right">
                <?php 
        echo TranslationProxy::get_service_promo();
        ?>
            </td>
        </tr>
    <?php 
    }
 public static function string_status_text_filter($text, $string_id)
 {
     if (TranslationProxy_Basket::is_string_in_basket_anywhere($string_id)) {
         $text = __('In the translation basket', 'wpml-translation-management');
     } else {
         global $wpdb;
         $translation_service = $wpdb->get_var($wpdb->prepare("\tSELECT translation_service\n\t\t\t\t\t\tFROM {$wpdb->prefix}icl_string_translations\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t    string_id = %d\n\t\t\t\t\t\t\tAND translation_service > 0\n\t\t\t\t\t\t\tAND status IN (%d, %d)\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t", $string_id, ICL_TM_WAITING_FOR_TRANSLATOR, ICL_TM_IN_PROGRESS));
         if ($translation_service) {
             $text = $text . " : " . sprintf(__('One or more strings sent to %s', 'wpml-translation-management'), TranslationProxy::get_service_name($translation_service));
         }
     }
     return $text;
 }
 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');
 }
 function get_current_project()
 {
     return TranslationProxy::get_current_project();
 }
 public static function get_basket_extra_fields_array($force_refresh = false)
 {
     if ($force_refresh) {
         $networking = wpml_tm_load_tp_networking();
         $project = TranslationProxy::get_current_project();
         $extra_fields = $networking->get_extra_fields_remote($project);
     } else {
         $extra_fields = TranslationProxy::get_extra_fields_local();
     }
     return TranslationProxy::maybe_convert_extra_fields($extra_fields);
 }
 protected function get_translator_html($job)
 {
     $job = (object) $job;
     $current_service_name = TranslationProxy::get_current_service_name();
     $translation_services = array('local', TranslationProxy::get_current_service_id());
     $translator = '';
     if ($job->translation_service && $job->translation_service !== 'local') {
         try {
             $project = TranslationProxy::get_current_project();
             if ($project) {
                 if ($project->service->has_translator_selection) {
                     $translator_contact_iframe_url = $project->translator_contact_iframe_url($job->translator_id);
                     $iframe_args = array('title' => __('Contact the translator', 'wpml-translation-management'), 'unload_cb' => 'icl_thickbox_refresh');
                     $translator .= TranslationProxy_Popup::get_link($translator_contact_iframe_url, $iframe_args);
                     $translator .= esc_html($job->translator_name);
                     $translator .= "</a> (" . $current_service_name . ")";
                 } else {
                     $translator .= $current_service_name;
                 }
             } else {
                 $translator .= esc_html($job->translator_name);
             }
         } catch (Exception $e) {
             // Just doesn't create the output
         }
     } elseif ($job->status == ICL_TM_COMPLETE) {
         $translator_data = get_userdata($job->translator_id);
         $translator_name = $translator_data ? $translator_data->display_name : "";
         $translator = '<span class="icl-finished-local-name">' . $translator_name . '</span>';
     } else {
         $translator .= '<span class="icl_tj_select_translator">';
         $selected_translator = isset($job->translator_id) ? $job->translator_id : false;
         $disabled = false;
         if ($job->translation_service && $job->translation_service !== 'local' && is_numeric($job->translation_service)) {
             $selected_translator = TranslationProxy_Service::get_wpml_translator_id($job->translation_service, $job->translator_id);
             $disabled = true;
         }
         $job_id = isset($job->job_id) ? $job->job_id : $job->id;
         $local_only = isset($job->local_only) ? $job->local_only : true;
         $args = array('id' => 'icl_tj_translator_for_' . $job_id, 'name' => 'icl_tj_translator_for_' . $job_id, 'from' => $job->source_language_code, 'to' => $job->language_code, 'selected' => $selected_translator, 'services' => $translation_services, 'disabled' => $disabled, 'echo' => false, 'local_only' => $local_only);
         $translator .= TranslationManagement::translators_dropdown($args);
         $translator .= '<input type="hidden" id="icl_tj_ov_' . $job_id . '" value="' . (int) $job->translator_id . '" />';
         $translator .= '<input type="hidden" id="icl_tj_ty_' . $job_id . '" value="' . strtolower($this->get_type()) . '" />';
         $translator .= '<span class="icl_tj_select_translator_controls" id="icl_tj_tc_' . $job_id . '">';
         $translator .= '<input type="button" class="button-secondary icl_tj_ok" value="' . __('Send', 'wpml-translation-management') . '" />&nbsp;';
         $translator .= '<input type="button" class="button-secondary icl_tj_cancel" value="' . __('Cancel', 'wpml-translation-management') . '" />';
         $translator .= '</span>';
     }
     return $translator;
 }
 public static function get_translator_name($translator_id)
 {
     static $translators;
     if (TranslationProxy::translator_selection_available()) {
         $lang_status = self::get_language_pairs();
         if (is_null($translators) && $lang_status) {
             foreach ($lang_status as $lp) {
                 if (!empty($lp['translators'])) {
                     foreach ($lp['translators'] as $tr) {
                         $translators[$tr['id']] = $tr['nickname'];
                     }
                 }
             }
         }
     }
     if (isset($translators[$translator_id])) {
         return $translators[$translator_id];
     } else {
         return false;
     }
 }
 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');
 }
 function process_translated_string($translation_proxy_job_id, $language)
 {
     $project = TranslationProxy::get_current_project();
     $translation = $project->fetch_translation($translation_proxy_job_id);
     $translation = apply_filters('icl_data_from_pro_translation', $translation);
     $ret = false;
     $xliff = new WPML_TM_xliff();
     $translation = $xliff->get_strings_xliff_translation($translation);
     if ($translation) {
         $ret = icl_translation_add_string_translation($translation_proxy_job_id, $translation, $language);
         if ($ret) {
             $project->update_job($translation_proxy_job_id);
         }
     }
     return $ret;
 }
    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 
    }
Exemple #26
0
<?php

global $wpdb;
require WPML_TM_PATH . '/menu/basket-tab/wpml-basket-tab-ajax.class.php';
$basket_ajax = new WPML_Basket_Tab_Ajax(TranslationProxy::get_current_project(), wpml_tm_load_basket_networking(), new WPML_Translation_Basket($wpdb));
add_action('init', array($basket_ajax, 'init'));
function icl_get_jobs_table()
{
    require_once WPML_TM_PATH . '/menu/wpml-translation-jobs-table.class.php';
    global $iclTranslationManagement;
    $nonce = filter_input(INPUT_POST, 'icl_get_jobs_table_data_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    if (!wp_verify_nonce($nonce, 'icl_get_jobs_table_data_nonce')) {
        die('Wrong Nonce');
    }
    $table = new WPML_Translation_Jobs_Table($iclTranslationManagement);
    $data = $table->get_paginated_jobs();
    wp_send_json_success($data);
}
function icl_get_job_original_field_content()
{
    global $iclTranslationManagement;
    if (!wpml_is_action_authenticated('icl_get_job_original_field_content')) {
        die('Wrong Nonce');
    }
    $job_id = filter_input(INPUT_POST, 'tm_editor_job_id', FILTER_SANITIZE_NUMBER_INT);
    $field = filter_input(INPUT_POST, 'tm_editor_job_field');
    $data = array();
    $job = $job_id !== null && $field !== null ? $job = $iclTranslationManagement->get_translation_job($job_id) : null;
    $elements = $job && isset($job->elements) ? $job->elements : array();
    foreach ($elements as $element) {
        $sanitized_type = sanitize_title($element->field_type);
 /**
  * Returns the batch id for a given basket or batch name
  *
  * @param string $basket_name
  *
  * @return int|bool
  */
 private function get_batch_id_from_name($basket_name)
 {
     return TranslationProxy::get_batch_id_from_name($basket_name);
 }
 public function rollback_basket_commit()
 {
     TranslationProxy_Basket::get_basket(true);
     $basket_name = TranslationProxy_Basket::get_basket_name();
     $basket_name = $basket_name ? $basket_name : filter_input(INPUT_POST, 'basket_name', FILTER_SANITIZE_STRING);
     $batch_id = TranslationProxy::get_batch_id_from_name($basket_name);
     if ($batch_id) {
         $batch = new WPML_Translation_Batch($batch_id);
         $batch->cancel_all_remote_jobs();
     }
 }
 /**
  * @param array $info
  *
  * @deprecated @since 3.2 Use TranslationProxy::get_current_service_info instead
  * @return array
  */
 public static function current_service_info($info = array())
 {
     return TranslationProxy::get_current_service_info($info);
 }
 /**
  * @return bool
  */
 private function must_show_incomplete_jobs_notice()
 {
     return $this->is_jobs_tab() && TranslationProxy::get_current_service_id() && !$this->service_activation_incomplete() && !$this->service_activation_ajax->get_ignore_local_jobs();
 }