sitepress = $sitepress; $this->screen_options = $screen_options_factory->create_pagination( 'tm_translations_queue_per_page', ICL_TM_DOCS_PER_PAGE ); $this->table_sort = $screen_options_factory->create_admin_table_sort(); } public function init_hooks() { add_action( 'current_screen', array( $this, 'load' ) ); } public function load() { if ( $this->must_open_the_editor() ) { $job_id = $this->get_job_id_from_request(); $job_object = wpml_tm_load_job_factory()->get_translation_job( $job_id, false, 0, true ); if ( $job_object->get_translator_id() <= 0 ) { $job_object->assign_to( $this->sitepress->get_wp_api() ->get_current_user_id() ); } if ( $job_object && $job_object->user_can_translate( wp_get_current_user() ) ) { $this->attempt_opening_ATE( $job_id ); global $wpdb; $this->must_render_the_editor = true; $this->translation_editor = new WPML_Translation_Editor_UI( $wpdb, $this->sitepress, wpml_load_core_tm(), $job_object, new WPML_TM_Job_Action_Factory( wpml_tm_load_job_factory() ), new WPML_TM_Job_Layout( $wpdb, $this->sitepress->get_wp_api() ) ); } } } /** * @param array $icl_translation_filter * * @throws \InvalidArgumentException */ public function display( array $icl_translation_filter = array() ) { if ( $this->must_render_the_editor ) { $this->translation_editor->render(); return; } /** * @var TranslationManagement $iclTranslationManagement * @var WPML_Translation_Job_Factory $wpml_translation_job_factory */ global $iclTranslationManagement, $wpml_translation_job_factory; $translation_jobs = array(); $job_types = array(); $langs_from = array(); $lang_from = array(); $langs_to = array(); $lang_to = array(); $job_id = null; if ( ! empty( $_GET['resigned'] ) ) { $iclTranslationManagement->add_message( array( 'type' => 'updated', 'text' => __( "You've resigned from this job.", 'wpml-translation-management' ) ) ); } if ( isset( $_SESSION['translation_ujobs_filter'] ) ) { $icl_translation_filter = $_SESSION['translation_ujobs_filter']; } $current_translator = $iclTranslationManagement->get_current_translator(); $can_translate = $current_translator && $current_translator->ID > 0 && $current_translator->language_pairs; $post_link_factory = new WPML_TM_Post_Link_Factory( $this->sitepress ); if ( $can_translate ) { $icl_translation_filter['translator_id'] = $current_translator->ID; $icl_translation_filter['include_unassigned'] = true; $element_type_prefix = isset( $_GET['element_type'] ) ? $_GET['element_type'] : 'post'; if ( isset( $_GET['updated'] ) && $_GET['updated'] ) { $tm_post_link_updated = $post_link_factory->view_link( $_GET['updated'] ); if ( $iclTranslationManagement->is_external_type( $element_type_prefix ) ) { $tm_post_link_updated = apply_filters( 'wpml_external_item_link', $tm_post_link_updated, $_GET['updated'], false ); } $user_message = __( 'Translation updated: ', 'wpml-translation-management' ) . $tm_post_link_updated; $iclTranslationManagement->add_message( array( 'type' => 'updated', 'text' => $user_message ) ); } elseif ( isset( $_GET['added'] ) && $_GET['added'] ) { $tm_post_link_added = $post_link_factory->view_link( $_GET['added'] ); if ( $iclTranslationManagement->is_external_type( $element_type_prefix ) ) { $tm_post_link_added = apply_filters( 'wpml_external_item_link', $tm_post_link_added, $_GET['added'], false ); } $user_message = __( 'Translation added: ', 'wpml-translation-management' ) . $tm_post_link_added; $iclTranslationManagement->add_message( array( 'type' => 'updated', 'text' => $user_message ) ); } elseif ( isset( $_GET['job-cancelled'] ) ) { $user_message = __( 'Translation has been removed by admin', 'wpml-translation-management' ); $iclTranslationManagement->add_message( array( 'type' => 'error', 'text' => $user_message ) ); } if ( ! empty( $current_translator->language_pairs ) ) { $_langs_to = array(); if ( 1 < count( $current_translator->language_pairs ) ) { foreach ( $current_translator->language_pairs as $lang => $to ) { $langs_from[] = $this->sitepress->get_language_details( $lang ); $_langs_to = array_merge( (array) $_langs_to, array_keys( $to ) ); } $_langs_to = array_unique( $_langs_to ); } else { $_langs_to = array_keys( current( $current_translator->language_pairs ) ); $lang_from = $this->sitepress->get_language_details( key( $current_translator->language_pairs ) ); $icl_translation_filter['from'] = $lang_from['code']; } if ( 1 < count( $_langs_to ) ) { foreach ( $_langs_to as $lang ) { $langs_to[] = $this->sitepress->get_language_details( $lang ); } } else { $lang_to = $this->sitepress->get_language_details( current( $_langs_to ) ); $icl_translation_filter['to'] = $lang_to['code']; } $job_types = $wpml_translation_job_factory->get_translation_job_types_filter( array(), array( 'translator_id' => $current_translator->ID, 'include_unassigned' => true ) ); if ( isset( $_GET['orderby'] ) ) { $icl_translation_filter['order_by'] = filter_var( $_GET['orderby'], FILTER_SANITIZE_STRING ); } if ( isset( $_GET['order'] ) ) { $icl_translation_filter['order'] = filter_var( $_GET['order'], FILTER_SANITIZE_STRING ); } $translation_jobs = $wpml_translation_job_factory->get_translation_jobs( (array) $icl_translation_filter ); $has_updated_jobs = $this->translation_jobs_require_update( $translation_jobs ); if ( $has_updated_jobs ) { $translation_jobs = $wpml_translation_job_factory->get_translation_jobs( (array) $icl_translation_filter ); } } } ?>

language_pairs ) ): ?>

language_pairs ) ): ?>
       
0 ): ?>
screen_options->get_items_per_page() ); $translation_jobs = $translation_queue_pagination->get_paged_jobs(); ?> sitepress, $iclTranslationManagement, $tm_api, $post_link_factory, $translation_jobs ); $translation_jobs = $translation_queue_jobs_model->get(); $this->show_table( $translation_jobs, count( $actions ) > 0, $job_id ); ?>
show() ?>
0 ): ?>
<> > $job ) { ?> get_row_css_class_attribute( $job ); ?>>
   
job_id; ?> post_title ); ?>
tm_post_link; ?>
post_type ); ?> lang_text_with_flags ?> status_text ); ?> deadline_date ) { echo date( 'Y-m-d', strtotime( $job->deadline_date ) ); } ?> original_doc_id ) { $ate_job_id = null; $ate_job_progress = array(); if ( array_key_exists( $job->job_id, $ate_jobs ) ) { if ( array_key_exists( 'ate_job_id', $ate_jobs[ $job->job_id ] ) ) { $ate_job_id = $ate_jobs[ $job->job_id ]['ate_job_id']; } if ( array_key_exists( 'progress', $ate_jobs[ $job->job_id ] ) ) { $ate_job_progress = $ate_jobs[ $job->job_id ]['progress']; } } ?> button_text; ?> is_doing_job ) { ?> resign_text ?>  
get_job_data_for_restore( $job_id ); $source_language_code = filter_var( isset( $_GET['source_language_code'] ) ? $_GET['source_language_code'] : '', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( $trid && $language_code ) { if ( ! $job_id ) { $job_id = $iclTranslationManagement->get_translation_job_id( $trid, $language_code ); if ( ! $job_id ) { if ( ! $source_language_code ) { $post_id = SitePress::get_original_element_id_by_trid( $trid ); } else { $posts_in_trid = $wpml_post_translations->get_element_translations( false, $trid ); $post_id = isset( $posts_in_trid[ $source_language_code ] ) ? $posts_in_trid[ $source_language_code ] : false; } $blog_translators = wpml_tm_load_blog_translators(); $args = array( 'lang_from' => $source_language_code, 'lang_to' => $language_code, 'job_id' => $job_id ); if ( $post_id && $blog_translators->is_translator( $sitepress->get_current_user()->ID, $args ) ) { $job_id = $wpml_translation_job_factory->create_local_post_job( $post_id, $language_code ); } } } else if ( $update_needed ) { $element_id = SitePress::get_original_element_id_by_trid( $trid ); $job_id = $wpml_translation_job_factory->create_local_job( $element_id, $language_code, null, $element_type ); } } return $job_id; } /** * @param $job_id * * @return array ( trid, updated_needed, language_code ) */ private function get_job_data_for_restore( $job_id ) { $fields = array( 'trid', 'update_needed', 'language_code', 'element_type' ); $result = array_fill_keys( $fields, false ); if ( isset( $_GET['trid'] ) ) { $result['trid'] = filter_var( $_GET['trid'], FILTER_SANITIZE_NUMBER_INT ); } if ( isset( $_GET['update_needed'] ) ) { $result['update_needed'] = filter_var( $_GET['update_needed'], FILTER_SANITIZE_NUMBER_INT ); } if ( isset( $_GET['language_code'] ) ) { $result['language_code'] = filter_var( $_GET['language_code'], FILTER_SANITIZE_FULL_SPECIAL_CHARS ); } $wpdb = $this->sitepress->get_wpdb(); if ( isset( $result['trid'] ) ) { $element_type_query = $wpdb->prepare( "SELECT element_type FROM {$wpdb->prefix}icl_translations WHERE trid = %d LIMIT 1", $result['trid'] ); $result['element_type'] = $wpdb->get_var( $element_type_query ); } if ( ! $job_id || isset( $_GET['trid'], $_GET['update_needed'], $_GET['language_code'], $result['element_type'] ) ) { return array( $result['trid'], $result['update_needed'], $result['language_code'], $result['element_type'] ); } $sql = " SELECT t.trid, ts.needs_update as update_needed, t.language_code, t.element_type FROM {$wpdb->prefix}icl_translations t INNER JOIN {$wpdb->prefix}icl_translation_status ts on ts.translation_id = t.translation_id INNER JOIN {$wpdb->prefix}icl_translate_job j ON j.rid = ts.rid WHERE j.job_id = %d; "; $db_result = $wpdb->get_row( $wpdb->prepare( $sql, $job_id ), ARRAY_A ); foreach ( $fields as $field ) { if ( ! isset( $_GET[ $field ] ) ) { $result[ $field ] = $db_result[ $field ]; } } return array( $result['trid'], $result['update_needed'], $result['language_code'], $result['element_type'] ); } /** * @param stdClass $job * * @return string */ private function get_row_css_class_attribute( $job ) { $classes = array(); if ( isset( $job->deadline_date ) && ICL_TM_COMPLETE !== (int) $job->status ) { $deadline_day = date( 'Y-m-d', strtotime( $job->deadline_date ) ); $today = date( 'Y-m-d' ); if ( $deadline_day < $today ) { $classes[] = 'overdue'; } } if ( $classes ) { return ' class="' . esc_attr( implode( ' ', $classes ) ) . '"'; } return ''; } /** * @return bool */ private function must_open_the_editor() { return ( isset( $_GET['job_id'] ) && $_GET['job_id'] > 0 ) || ( isset( $_GET['trid'] ) && $_GET['trid'] > 0 ); } /** * @param $job_id */ private function attempt_opening_ATE( $job_id ) { $editor_url = apply_filters( 'wpml_tm_ate_jobs_editor_url', null, $job_id, $this->get_return_url() ); if ( $editor_url ) { wp_safe_redirect( $editor_url ); die(); } } /** * @return mixed|null|string */ private function get_return_url() { $return_url = null; if ( array_key_exists( 'return_url', $_GET ) ) { $return_url = filter_var( $_GET['return_url'], FILTER_SANITIZE_URL ); $return_url_parts = wp_parse_url( $return_url ); $admin_url = get_admin_url(); $admin_url_parts = wp_parse_url( $admin_url ); if ( strpos( $return_url_parts['path'], $admin_url_parts['path'] ) === 0 ) { $admin_url_parts['path'] = $return_url_parts['path']; } else { $admin_url_parts = $return_url_parts; } if ( array_key_exists( 'query', $return_url_parts ) ) { $admin_url_parts['query'] = $return_url_parts['query']; } $return_url = http_build_url( $admin_url_parts ); } return $return_url; } }