';
$html .= $this->get_translated_content_paragraph( $taxonomy, false );
$blocked = $sitepress->get_setting( 'tm_block_retranslating_terms' );
$additional_styles = '';
$learn_more = '';
if ( $blocked ) {
$explanation = __( '
Some terms in this taxonomy have already been translated.
If your user permissions allow, you can edit the translation from the "Taxonomy Translation" admin screen.
',
'wpml-translation-management' );
$learn_more = '
';
$additional_styles = 'style="color:red;"';
} else {
$explanation = __( "Some terms have already been translated. If you want to edit their translation, please uncheck the box below their value.",
'wpml-translation-management' );
}
$html .= '
' . $explanation . $learn_more . '
';
$terms_in_taxonomy = $this->terms[ $taxonomy ];
$rows = array();
foreach ( $terms_in_taxonomy as $term ) {
$rows[ ] = $this->render_html_single_term_row( $term[ 'original' ],
$term[ 'translation' ],
$term[ 'ttid_string' ],
$term[ 'tid' ],
$blocked );
}
foreach ( $rows as $row ) {
$html .= $row[ 'translated' ];
}
$html .= $this->get_original_content_paragraph();
$html .= '
';
$html .= '
';
foreach ( $rows as $row ) {
$html .= $row[ 'original' ];
}
$html .= str_repeat( '
', 6 );
return $html;
}
/**
* @param $original_content String
* @param $existing_content String
* @param $field_type String
* @param $tid Integer
* @param $blocked Boolean
*
* An associative array holding the html for the original value row as well as the html for the row
* containing the translated value of a field.
*
* @return array
*/
private function render_html_single_term_row( $original_content, $existing_content, $field_type, $tid, $blocked ) {
$html = '
';
if ( ! ( $blocked && $existing_content ) ) {
$html .= $this->get_finished_checkbox_html( $existing_content, false, $field_type, true );
$html .= $this->hidden_field_html( $tid, $field_type, 'csv_base64' );
}
$html .= '';
return array(
'translated' => $html,
'original' => $this->render_html_single_original_term_row( $original_content )
);
}
private function render_html_single_original_term_row( $original_content ) {
$html = '
rtlo . '>';
$html .= '
' . $original_content . '
';
$html .= '
';
$html .= '
';
return $html;
}
/**
* Returns the html of a hidden field that is used by TM to correctly associate data submitted from the TM Editor
* with its job and field.
*
* The tid entry for the translated field's data in the icl_translate table.
*
* @param $tid Integer
* @param $field_type String
* The type of encoding, the field uses when saved to the database.
* @param $field_format String
*
* @return string
*/
public function hidden_field_html( $tid, $field_type, $field_format ) {
$field_start = '
';
$html .= $field_start . '[tid]" value="' . $tid . '" />';
return $html;
}
/**
* Returns the html of a 'This translation is finished.' checkbox.
*
* Sets whether or not the checkbox is checked by default.
*
* @param $finished boolean
* Sets whether or not the checkbox applies to a multivalued field.
* @param $multiple boolean
* @param $field_type string
* Sets whether or not the checkbox applies to the translated value of a taxonomy term.
* @param bool $term
*
* @return string
*/
public function get_finished_checkbox_html( $finished, $multiple, $field_type, $term = false ) {
$class = '"icl_tm_finished';
if ( $multiple ) {
$class .= ' icl_tmf_multiple';
}
if ( $term ) {
$class .= ' icl_tmf_term';
}
$class .= '"';
$html = '
';
return $html;
}
/**
* Renders and then returns the paragraph heading translated content sections.
*
* @param $field_type string
*
* Sets whether or not a 'Copy from Original' link is to be displayed for this paragraph.
* @param $show_copy_link boolean
*
* @return string
*/
public function get_translated_content_paragraph( $field_type, $show_copy_link ) {
$html = '
';
$html .= __( 'Translated content', 'wpml-translation-management' ) . ' - ' . $this->target_lang;
$html .= $show_copy_link ? $this->render_copy_from_original_link($field_type) : '';
$html .= '
';
return $html;
}
public function render_copy_from_original_link($field_type = false ){
$caption = $field_type === false ? __( 'Copy all fields from %s', 'wpml-translation-management' )
: __( 'Copy from %s', 'wpml-translation-management' );
$caption = sprintf ( $caption, $this->lang_source );
$sep = $field_type === false ? '' : '| ';
$field_type = $field_type === false ? 'icl_all_fields' : sanitize_title($field_type);
$html = '
'. $sep .'';
return $html;
}
/**
* Renders and then returns the html paragraph heading the original contents of a translated field.
*
* @return string
*/
private function render_original_content_paragraph() {
$html = '
';
$html .= __( 'Original content', 'wpml-translation-management' );
$html .= ' - ' . $this->lang_source;
$html .= '
';
return $html;
}
/**
* Returns the html paragraph heading the original contents of a translated field.
*
* @return string
*/
public function get_original_content_paragraph() {
return $this->original_content_paragraph_html;
}
/**
* Formats term data retrieved from the database.
*
* @param $data array
*
* @return array
*/
private function format_term_elements( $data ) {
global $wpdb;
$terms = array();
foreach ( $data as $element ) {
$term_translation = base64_decode( $element->field_data_translated );
if(!$term_translation) {
$post_fields = isset($_POST[ 'fields' ]) ? $_POST[ 'fields' ] : null;
$current_element_in_post_fields = $post_fields ? $post_fields[ $element->field_type ] : null;
if ( $current_element_in_post_fields && $current_element_in_post_fields[ 'tid' ] == $element->tid ) {
$term_translation = $current_element_in_post_fields[ 'data' ];
}
}
$terms [ substr( $element->field_type, 2 ) ] = array(
'original' => base64_decode( $element->field_data ),
'translation' => $term_translation,
'tid' => $element->tid,
'ttid_string' => $element->field_type
);
}
$return = array();
$ttids = array_keys( $terms );
if ( ! empty( $ttids ) ) {
$ttid_in_query_fragment = "term_taxonomy_id IN (" . wpml_prepare_in( $ttids, '%d' ) . ")";
$query = "SELECT taxonomy, term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE " . $ttid_in_query_fragment;
$res = $wpdb->get_results( $query );
foreach ( $res as $term ) {
if ( ! isset( $return[ $term->taxonomy ] ) ) {
$return[ $term->taxonomy ] = array();
}
$return[ $term->taxonomy ][ ] = $terms[ $term->term_taxonomy_id ];
}
}
return $return;
}
/**
* Applies filters to a custom field job element.
* Custom fields that were named with numeric suffixes are stripped of these suffixes.
*
* @param object $element
* @param object $job
*
* @return array
*/
public function custom_field_data( $element, $job ) {
$element_field_type_parts = explode( '-', $element->field_type );
$last_part = array_pop( $element_field_type_parts );
$unfiltered_type = empty( $element_field_type_parts )
? $last_part
: ( implode( '-', $element_field_type_parts )
. ( is_numeric( $last_part ) ? '' : '-' . $last_part ) );
$element_field_type = $unfiltered_type;
/**
* @deprecated Use `wpml_editor_custom_field_name` filter instead
* @since 3.2
*/
$element_field_type = apply_filters( 'icl_editor_cf_name', $element_field_type );
$element_field_type = apply_filters( 'wpml_editor_custom_field_name', $element_field_type );
$element_field_style = 1;
/**
* @deprecated Use `wpml_editor_custom_field_style` filter instead
* @since 3.2
*/
$element_field_style = apply_filters( 'icl_editor_cf_style',
$element_field_style,
$unfiltered_type );
$element_field_style = apply_filters( 'wpml_editor_custom_field_style',
$element_field_style,
$unfiltered_type );
$element = apply_filters( 'wpml_editor_cf_to_display', $element, $job );
return array( $element_field_type, $element_field_style, $element );
}
}