tm_instance = $iclTranslationManagement;
$this->current_element_index = 0;
$this->job_instance = $job_instance;
$this->job = $job_instance->get_basic_data();
if ( $job_instance->get_translator_id() <= 0 ) {
$job_instance->assign_to( $sitepress->get_wp_api()->get_current_user_id(), 'local' );
}
}
function render() {
list( $this->rtl_original, $this->rtl_translation ) = $this->init_rtl_settings();
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
?>
init_original_post();
$this->init_editor_object();
$this->render_editor_header();
$this->render_translator_note();
?>
tm_instance->is_external_type( $this->job->element_type_prefix );
}
private function init_original_post() {
// we do not need the original document of the job here
// but the document with the same trid and in the $this->job->source_language_code
$this->all_translations = $this->sitepress->get_element_translations( $this->job->trid,
$this->job->original_post_type );
$this->original_post = false;
foreach ( $this->all_translations as $t ) {
if ( $t->language_code === $this->job->source_language_code ) {
$this->original_post = $this->tm_instance->get_post( $t->element_id, $this->job->element_type_prefix );
//if this fails for some reason use the original doc from which the trid originated
break;
}
}
$this->original_post = $this->original_post
? $this->original_post
: $this->tm_instance->get_post( $this->job_instance->get_original_element_id(),
$this->job->element_type_prefix );
return $this->original_post;
}
private function init_editor_object() {
global $wpdb;
$this->editor_object = new WPML_Translation_Editor( $this->sitepress,
$wpdb,
$this->job_instance->get_language_code( true ),
$this->job_instance->get_source_language_code( true ),
$this->rtl_original_attribute_object,
$this->rtl_translation_attribute );
}
/**
* @return array
*/
private function init_rtl_settings() {
$this->rtl_original = $this->sitepress->is_rtl( $this->job->source_language_code );
$this->rtl_translation = $this->sitepress->is_rtl( $this->job->language_code );
$this->rtl_original_attribute_object = $this->rtl_original ? ' dir="rtl"' : ' dir="ltr"';
$this->rtl_translation_attribute = $this->rtl_translation ? ' dir="rtl"' : ' dir="ltr"';
return array( $this->rtl_original, $this->rtl_translation );
}
private function render_editor_header() {
?>
job_instance->get_title() );
$tm_post_link = '' . $post_title . ' ';
printf( __( 'You are translating %s from %s to %s.', 'wpml-translation-management' ),
$tm_post_link,
$this->job_instance->get_source_language_code( true ),
$this->job_instance->get_language_code( true ) );
echo '' . $this->editor_object->render_copy_from_original_link() . ' ';
?>
job_instance->get_original_element_id(),
'_icl_translator_note',
true )
) {
?>
current_element->field_type );
}
/**
* @param $current_element
*
* @return mixed
*/
private function set_current_element( $current_element ) {
$this->current_element_index = ( ! isset( $this->current_element_index ) || $this->current_element_index < 1 ) ? 1 : $this->current_element_index + 1;
return $this->current_element = $current_element;
}
/**
* @return bool
*/
private function is_current_element_a_custom_field() {
return ( 0 === strpos( $this->current_element->field_type, 'field-' ) );
}
/**
*
*/
private function render_translation_element() {
?>
is_external_element() ) {
// Get human readable string Title and editor style from the WPML string package.
$this->current_element_field_type = apply_filters( 'wpml_tm_editor_string_name', $this->current_element->field_type, $this->original_post );
$this->current_element_field_style = $this->current_element->field_type;
$this->current_element_field_style = apply_filters( 'wpml_tm_editor_string_style', $this->current_element_field_style, $this->current_element->field_type, $this->original_post );
} else if ( $this->is_current_element_a_custom_field() ) {
$custom_field_data = $this->editor_object->custom_field_data( $this->current_element, $this->job );
$this->current_element_field_type = $custom_field_data[ 0 ];
$this->current_element_field_style = $custom_field_data[ 1 ];
$this->current_element = $custom_field_data[ 2 ];
} else {
$this->current_element_field_type = $this->current_element->field_type;
$this->current_element_field_style = false;
}
}
private function render_current_field_description() {
if ( $this->is_current_element_a_custom_field() ) {
$icl_editor_cf_description = apply_filters( 'icl_editor_cf_description', '', $this->current_element->field_type );
if ( $icl_editor_cf_description !== null ) {
echo '' . $icl_editor_cf_description . '
';
}
}
}
private function init_current_element_content() {
$this->current_element_content_original = $this->tm_instance->decode_field_data( $this->current_element->field_data, $this->current_element->field_format );
$this->current_element_content_translated = $this->tm_instance->decode_field_data( $this->current_element->field_data_translated, $this->current_element->field_format );
if(!$this->current_element_content_translated) {
$post_fields = isset($_POST[ 'fields' ]) ? $_POST[ 'fields' ] : null;
$current_element_in_post_fields = $post_fields ? $post_fields[ $this->current_element->field_type ] : null;
if ( $current_element_in_post_fields && $current_element_in_post_fields[ 'tid' ] == $this->current_element->tid ) {
$this->current_element_content_translated = $current_element_in_post_fields[ 'data' ];
}
}
}
private function render_current_element_field_body() {
?>
false,
'textarea_name' => 'fields[' . strtolower( $this->current_element->field_type ) . '][data]',
'textarea_rows' => 20,
'editor_css' => $this->rtl_translation ? ' ' : ''
);
$this->render_wp_editor( $settings );
?>
current_element_content_original as $k => $c ) {
?>
rtl_translation_attribute; ?> />
false,
'textarea_name' => 'fields[' . strtolower( $this->current_element->field_type ) . '][data]',
'textarea_rows' => 4
);
$this->render_wp_editor( $settings );
}
private function render_current_element_field_single_line() {
?>
rtl_translation_attribute; ?> />
current_element_content_translated, $this->current_element->field_type, $settings );
}
private function render_current_element_field_original_body() {
?>
rtl_original_attribute_object; ?>>
false,
'textarea_name' => 'fields[' . strtolower( $this->current_element->field_type ) . '][original]',
'textarea_rows' => 20,
'editor_css' => $this->rtl_translation ? ' ' : ''
);
wp_editor( $this->current_element_content_original, 'original_' . strtolower( $this->current_element->field_type ), $settings );
?>
current_element_content_original as $c ) {
?>
rtl_original_attribute_object; ?>>
10 ) );
} ?>
rtl_original ) {
echo ' dir="rtl" style="text-align:right;"';
} else {
echo ' dir="ltr" style="text-align:left;"';
} ?>>current_element_content_original ) ?>
current_element->field_type === 'body' || $this->current_element_field_style == 2 ) {
$this->render_current_element_field_original_body();
} elseif ( $this->current_element->field_format === 'csv_base64' ) {
$this->render_current_element_field_original_csv_base64();
} else {
$this->render_current_element_field_original_single_line();
}
}
private function render_current_element_field() {
if ( $this->current_element->field_type == 'body' ) {
$this->render_current_element_field_body();
} elseif ( $this->current_element->field_format == 'csv_base64' ) {
$this->render_current_element_field_csv_base64();
// CASE 3 - multiple lines ***********************
} elseif ( ( $this->is_current_element_a_custom_field() || $this->original_post ) && $this->current_element_field_style == 1 ) {
$this->render_current_element_field_textarea();
// CASE 4 - wysiwyg ***********************
} elseif ( ( $this->is_current_element_a_custom_field() || $this->original_post ) && $this->current_element_field_style == 2 ) {
$this->render_current_element_field_wysiwyg();
} else {
$this->render_current_element_field_single_line();
}
}
private function render_current_element_field_original_content() {
?>
render_current_element_field_original();
?>
current_element->field_finished && ! empty( $this->job->prev_version ) ) {
$prev_value = '';
foreach ( $this->job->prev_version->elements as $pel ) {
if ( $this->current_element->field_type == $pel->field_type ) {
$prev_value = $this->tm_instance->decode_field_data( $pel->field_data, $pel->field_format );
}
}
if ( $this->current_element->field_format != 'csv_base64' ) {
$diff = wp_text_diff( $prev_value, $this->tm_instance->decode_field_data( $this->current_element->field_data, $this->current_element->field_format ) );
}
if ( ! empty( $diff ) ) {
?>
set_current_element( $current_element );
if ( $this->current_element->field_data ) {
if ( $this->is_current_element_a_term() ) {
$this->editor_object->add_term( $this->current_element );
} else {
if ( ! $this->current_element->field_finished ) {
$this->all_translations_finished = false;
}
$this->render_translation_element();
}
}
}
private function render_elements() {
$elements = isset( $this->job->elements ) ? $this->job->elements : array();
$ordered_elements = array();
foreach ( array( 'title', 'body' ) as $type ) {
foreach ( $elements as $key => $element ) {
if ( $element->field_type === $type ) {
$ordered_elements[] = $element;
unset( $elements[ $key ] );
}
}
}
$ordered_elements = array_merge( $ordered_elements, $elements );
foreach ( $ordered_elements as $current_element ) {
$this->render_element( $current_element );
}
}
private function render_elements_content() {
?>
all_translations_finished = true;
$this->render_elements();
echo $this->editor_object->render_term_metaboxes();
?>