first commit
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
class WPML_Dashboard_Ajax {
|
||||
|
||||
/** @var WPML_Super_Globals_Validation $super_globals*/
|
||||
private $super_globals;
|
||||
|
||||
public function __construct( WPML_Super_Globals_Validation $super_globals ) {
|
||||
$this->super_globals = $super_globals;
|
||||
}
|
||||
|
||||
public function init_ajax_actions() {
|
||||
add_action( 'wp_ajax_wpml_duplicate_dashboard', array( $this, 'wpml_duplicate_dashboard' ) );
|
||||
add_action( 'wp_ajax_wpml_need_sync_message', array( $this, 'wpml_need_sync_message' ) );
|
||||
}
|
||||
|
||||
public function enqueue_js() {
|
||||
wp_register_script(
|
||||
'wpml-tm-dashboard-scripts',
|
||||
WPML_TM_URL . '/res/js/tm-dashboard/wpml-tm-dashboard.js',
|
||||
array( 'jquery', 'backbone', 'wpml-tm-progressbar' ),
|
||||
WPML_TM_VERSION
|
||||
);
|
||||
$wpml_tm_strings = $this->get_wpml_tm_script_js_strings();
|
||||
wp_localize_script( 'wpml-tm-dashboard-scripts', 'wpml_tm_strings', $wpml_tm_strings );
|
||||
wp_enqueue_script( 'wpml-tm-dashboard-scripts' );
|
||||
|
||||
wp_enqueue_script( OTGS_Assets_Handles::POPOVER_TOOLTIP );
|
||||
wp_enqueue_style( OTGS_Assets_Handles::POPOVER_TOOLTIP );
|
||||
}
|
||||
|
||||
private function get_wpml_tm_script_js_strings() {
|
||||
$wpml_tm_strings = array(
|
||||
'BB_default' => __( 'Add selected content to translation basket', 'wpml-translation-management' ),
|
||||
'BB_mixed_actions' => __(
|
||||
'Add selected content to translation basket / Duplicate',
|
||||
'wpml-translation-management'
|
||||
),
|
||||
'BB_duplicate_all' => __( 'Duplicate', 'wpml-translation-management' ),
|
||||
'BB_no_actions' => __(
|
||||
'Choose at least one translation action',
|
||||
'wpml-translation-management'
|
||||
),
|
||||
'duplication_complete' => __(
|
||||
'Finished Post Duplication',
|
||||
'wpml-translation-management'
|
||||
),
|
||||
'wpml_duplicate_dashboard_nonce' => wp_create_nonce( 'wpml_duplicate_dashboard_nonce' ),
|
||||
'wpml_need_sync_message_nonce' => wp_create_nonce( 'wpml_need_sync_message_nonce' ),
|
||||
'duplicating' => __( 'Duplicating', 'wpml-translation-management' ),
|
||||
'post_parent' => __( 'Post parent', 'wpml-translation-management' ),
|
||||
'any' => __( 'Any', 'wpml-translation-management' ),
|
||||
);
|
||||
|
||||
return $wpml_tm_strings;
|
||||
}
|
||||
|
||||
public function wpml_duplicate_dashboard() {
|
||||
if ( ! wpml_is_action_authenticated( 'wpml_duplicate_dashboard' ) ) {
|
||||
wp_send_json_error( 'Wrong Nonce' );
|
||||
}
|
||||
|
||||
global $sitepress;
|
||||
|
||||
$post_ids = filter_var( $_POST['duplicate_post_ids'], FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
$languages = filter_var( $_POST['duplicate_target_languages'], FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
||||
$res = array();
|
||||
foreach ( $post_ids as $pid ) {
|
||||
foreach ( $languages as $lang_code ) {
|
||||
if ( $sitepress->make_duplicate( $pid, $lang_code ) !== false ) {
|
||||
$res[ $lang_code ] = $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json_success( $res );
|
||||
}
|
||||
|
||||
public function wpml_need_sync_message() {
|
||||
if ( ! wpml_is_action_authenticated( 'wpml_need_sync_message' ) ) {
|
||||
wp_send_json_error( 'Wrong Nonce' );
|
||||
return;
|
||||
}
|
||||
|
||||
$post_ids = $this->super_globals->post( 'duplicated_post_ids' );
|
||||
$post_ids = array_values( array_filter( explode( ',', $post_ids ) ) );
|
||||
do_action( 'wpml_new_duplicated_terms', $post_ids );
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,492 @@
|
||||
<?php
|
||||
|
||||
use WPML\FP\Lst;
|
||||
|
||||
/**
|
||||
* Class WPML_TM_Dashboard
|
||||
*/
|
||||
class WPML_TM_Dashboard {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $translatable_post_types = null;
|
||||
|
||||
/**
|
||||
* @var wpdb
|
||||
*/
|
||||
private $wpdb;
|
||||
|
||||
/**
|
||||
* @var SitePress
|
||||
*/
|
||||
private $sitepress;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $found_documents = 0;
|
||||
|
||||
/**
|
||||
* WPML_TM_Dashboard constructor.
|
||||
*
|
||||
* @param wpdb $wpdb
|
||||
* @param SitePress $sitepress
|
||||
*/
|
||||
public function __construct( wpdb $wpdb, SitePress $sitepress ) {
|
||||
$this->wpdb = $wpdb;
|
||||
$this->sitepress = $sitepress;
|
||||
add_filter( 'posts_where', array( $this, 'add_dashboard_filter_conditions' ), 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_documents( $args = array() ) {
|
||||
$results = array();
|
||||
$documents = array();
|
||||
|
||||
$defaults = array(
|
||||
'from_lang' => 'en',
|
||||
'to_lang' => '',
|
||||
'tstatus' => -1,
|
||||
'sort_by' => 'date',
|
||||
'sort_order' => 'DESC',
|
||||
'limit_no' => ICL_TM_DOCS_PER_PAGE,
|
||||
'parent_type' => 'any',
|
||||
'parent_id' => false,
|
||||
'type' => '',
|
||||
'title' => '',
|
||||
'status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit' ),
|
||||
'page' => 0,
|
||||
);
|
||||
|
||||
$args = $this->remove_empty_arguments( $args );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
$documents = $this->add_string_packages( $documents, $args );
|
||||
$documents = $this->add_translatable_posts( $documents, $args );
|
||||
$filtered_documents = apply_filters( 'wpml_tm_dashboard_documents', $documents );
|
||||
$filtered_documents = array_slice( $filtered_documents, 0, $args['limit_no'] );
|
||||
$results['documents'] = $filtered_documents;
|
||||
$results['found_documents'] = $this->found_documents - ( count( $documents ) - count( $filtered_documents ) );
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function remove_empty_arguments( $args ) {
|
||||
$output = array();
|
||||
foreach ( $args as $argument_name => $argument_value ) {
|
||||
if ( '' !== $argument_value && null !== $argument_value ) {
|
||||
$output[ $argument_name ] = $argument_value;
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add list of translatable post types to dashboard.
|
||||
*
|
||||
* @param array $results
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function add_translatable_posts( $results, $args ) {
|
||||
$post_types = $this->get_translatable_post_types();
|
||||
$offset = 0;
|
||||
if ( $this->is_cpt_type( $args ) ) {
|
||||
$post_types = array( $args['type'] );
|
||||
$offset = $args['page'] * $args['limit_no'];
|
||||
} elseif ( ! empty( $args['type'] ) ) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
$query_args = [
|
||||
'post_type' => $post_types,
|
||||
'orderby' => $args['sort_by'],
|
||||
'order' => $args['sort_order'],
|
||||
'posts_per_page' => $args['limit_no'] + 1,
|
||||
'post_status' => $args['status'],
|
||||
'post_language' => $args['from_lang'],
|
||||
'post_language_to' => $args['to_lang'],
|
||||
'post_translation_status' => $args['tstatus'],
|
||||
'suppress_filters' => false,
|
||||
'update_post_meta_cache' => false,
|
||||
'update_post_term_cache' => false,
|
||||
'no_found_rows' => true,
|
||||
'offset' => $offset,
|
||||
];
|
||||
|
||||
if ( 'any' !== $args['parent_type'] ) {
|
||||
switch ( $args['parent_type'] ) {
|
||||
case 'page':
|
||||
$query_args['post_parent'] = (int) $args['parent_id'];
|
||||
break;
|
||||
default:
|
||||
$query_args['tax_query'] = array(
|
||||
array(
|
||||
'taxonomy' => $args['parent_type'],
|
||||
'field' => 'term_id',
|
||||
'terms' => (int) $args['parent_id'],
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $args['translation_priority'] ) ) {
|
||||
|
||||
$translation_priorities = new WPML_TM_Translation_Priorities();
|
||||
|
||||
if ( $translation_priorities->get_default_value_id() === (int) $args['translation_priority'] ) {
|
||||
$tax_query = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'taxonomy' => 'translation_priority',
|
||||
'operator' => 'NOT EXISTS',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$tax_query[] = array(
|
||||
'taxonomy' => 'translation_priority',
|
||||
'field' => 'term_id',
|
||||
'terms' => $args['translation_priority'],
|
||||
);
|
||||
|
||||
$query_args['tax_query'] = $tax_query;
|
||||
|
||||
}
|
||||
|
||||
if ( ! empty( $args['title'] ) ) {
|
||||
$query_args['post_title_like'] = $args['title'];
|
||||
}
|
||||
|
||||
$lang = $this->sitepress->get_admin_language();
|
||||
$this->sitepress->switch_lang( $args['from_lang'] );
|
||||
$query_args = apply_filters( 'wpml_tm_dashboard_post_query_args', $query_args, $args );
|
||||
$query = new WPML_TM_WP_Query( $query_args );
|
||||
$this->sitepress->switch_lang( $lang );
|
||||
if ( ! empty( $query->posts ) ) {
|
||||
foreach ( $query->posts as $post ) {
|
||||
$language_details = $this->sitepress->get_element_language_details( $post->ID, 'post_' . $post->post_type );
|
||||
$post_obj = new stdClass();
|
||||
$post_obj->ID = $post->ID;
|
||||
$post_obj->translation_element_type = 'post_' . $post->post_type;
|
||||
$post_obj->title = $post->post_title;
|
||||
$post_obj->is_translation = ( null === $language_details->source_language_code ) ? '0' : '1';
|
||||
$post_obj->language_code = $language_details->language_code;
|
||||
$post_obj->trid = $language_details->trid;
|
||||
$results[] = $post_obj;
|
||||
}
|
||||
}
|
||||
$this->found_documents += $query->get_found_count();
|
||||
wp_reset_query();
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add additional where conditions to support the following query arguments:
|
||||
* - post_title_like - Allow query posts with SQL LIKE in post title.
|
||||
* - post_language_to - Allow query posts with language they are translated to.
|
||||
* - post_translation_status - Allow to query posts by their translation status.
|
||||
*
|
||||
* @param string $where
|
||||
* @param object $wp_query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function add_dashboard_filter_conditions( $where, $wp_query ) {
|
||||
$post_title_like = $wp_query->get( 'post_title_like' );
|
||||
$post_language = $wp_query->get( 'post_language_to' );
|
||||
$post_translation_status = (int) $wp_query->get( 'post_translation_status' );
|
||||
|
||||
if ( $post_title_like ) {
|
||||
$where .= $this->wpdb->prepare( " AND {$this->wpdb->posts}.post_title LIKE '%s'", '%' . $this->wpdb->esc_like( $post_title_like ) . '%' );
|
||||
}
|
||||
|
||||
$post_type = $wp_query->get( 'post_type' );
|
||||
if ( Lst::includes( $post_type[0], $this->get_translatable_post_types() ) ) {
|
||||
$where .= $this->build_translation_status_where( $post_translation_status, $post_language );
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add string packages to translation dashboard.
|
||||
*
|
||||
* @param array $results
|
||||
* @param array $args
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function add_string_packages( $results, $args ) {
|
||||
$string_packages_table = $this->wpdb->prefix . 'icl_string_packages';
|
||||
$translations_table = $this->wpdb->prefix . 'icl_translations';
|
||||
$offset = 0;
|
||||
|
||||
if ( $this->is_cpt_type( $args ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$sql_calc_found_rows = '';
|
||||
$must_count_rows = array_key_exists( 'type', $args ) && ! empty( $args['type'] );
|
||||
if ( $must_count_rows ) {
|
||||
$offset = $args['page'] * $args['limit_no'];
|
||||
$sql_calc_found_rows = 'SQL_CALC_FOUND_ROWS';
|
||||
}
|
||||
|
||||
if ( ! is_plugin_active( 'wpml-string-translation/plugin.php' ) ) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
// Exit if *icl_string_packages table doesn't exist.
|
||||
if ( $this->wpdb->get_var( "SHOW TABLES LIKE '$string_packages_table'" ) !== $string_packages_table ) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
$where = $this->create_string_packages_where( $args );
|
||||
|
||||
$sql = "SELECT DISTINCT {$sql_calc_found_rows}
|
||||
st_table.ID,
|
||||
st_table.kind_slug,
|
||||
st_table.title,
|
||||
wpml_translations.element_type,
|
||||
wpml_translations.language_code,
|
||||
wpml_translations.source_language_code,
|
||||
wpml_translations.trid
|
||||
FROM {$string_packages_table} AS st_table
|
||||
LEFT JOIN {$translations_table} AS wpml_translations
|
||||
ON wpml_translations.element_id=st_table.ID OR wpml_translations.element_id = null
|
||||
WHERE 1 = 1 {$where}
|
||||
GROUP BY st_table.ID
|
||||
ORDER BY st_table.ID ASC
|
||||
LIMIT {$args['limit_no']}
|
||||
OFFSET {$offset}";
|
||||
$sql = apply_filters( 'wpml_tm_dashboard_external_type_sql_query', $sql, $args );
|
||||
$packages = $this->wpdb->get_results( $sql );
|
||||
|
||||
if ( $must_count_rows ) {
|
||||
$this->found_documents += $this->wpdb->get_var( 'SELECT FOUND_ROWS()' );
|
||||
}
|
||||
foreach ( $packages as $package ) {
|
||||
$package_obj = new stdClass();
|
||||
$package_obj->ID = $package->ID;
|
||||
$package_obj->translation_element_type = WPML_Package_Translation::get_package_element_type( $package->kind_slug );
|
||||
$package_obj->title = $package->title;
|
||||
$package_obj->is_translation = ( null === $package->source_language_code ) ? '0' : '1';
|
||||
$package_obj->language_code = $package->language_code;
|
||||
$package_obj->trid = $package->trid;
|
||||
$results[] = $package_obj;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create additional where clause for querying string packages based on filters.
|
||||
*
|
||||
* @param array $args
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function create_string_packages_where( $args ) {
|
||||
$where = " AND wpml_translations.element_type LIKE 'package%' AND st_table.post_id IS NULL";
|
||||
if ( ! $this->is_cpt_type( $args ) && ! empty( $args['type'] ) ) {
|
||||
$where .= $this->wpdb->prepare( " AND kind_slug='%s'", $args['type'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['title'] ) ) {
|
||||
$where .= $this->wpdb->prepare( " AND title LIKE '%s'", '%' . $this->wpdb->esc_like( $args['title'] ) . '%' );
|
||||
}
|
||||
|
||||
if ( ! empty( $args['to_lang'] ) ) {
|
||||
$where .= $this->wpdb->prepare( " AND wpml_translations.language_code='%s'", $args['to_lang'] );
|
||||
$where .= $this->wpdb->prepare( " AND wpml_translations.source_language_code='%s'", $args['from_lang'] );
|
||||
} else {
|
||||
$where .= $this->wpdb->prepare( " AND wpml_translations.language_code='%s'", $args['from_lang'] );
|
||||
}
|
||||
|
||||
if ( $args['tstatus'] >= 0 ) {
|
||||
$where .= $this->build_translation_status_where( $args['tstatus'] );
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $translation_status
|
||||
* @param string $language
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function build_translation_status_where( $translation_status, $language = null ) {
|
||||
if ( $translation_status < 0 && ! $language ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( $translation_status < 0 && $language ) {
|
||||
$subquery = $this->only_language_condition( $language );
|
||||
} else {
|
||||
switch ( $translation_status ) {
|
||||
case ICL_TM_NOT_TRANSLATED:
|
||||
$subquery = $this->not_translated_or_needs_update_condition( $language );
|
||||
break;
|
||||
case ICL_TM_NEEDS_UPDATE:
|
||||
$subquery = $this->needs_update_condition( $language );
|
||||
break;
|
||||
case ICL_TM_IN_PROGRESS:
|
||||
$subquery = $this->explicit_status_condition(
|
||||
wpml_prepare_in( [ ICL_TM_IN_PROGRESS, ICL_TM_WAITING_FOR_TRANSLATOR ], '%d' ),
|
||||
$language
|
||||
);
|
||||
break;
|
||||
case ICL_TM_COMPLETE:
|
||||
$subquery = $this->explicit_status_condition(
|
||||
wpml_prepare_in( [ ICL_TM_COMPLETE, ICL_TM_DUPLICATE ], '%d' ),
|
||||
$language
|
||||
);
|
||||
break;
|
||||
default:
|
||||
$subquery = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $subquery ) {
|
||||
return " AND wpml_translations.trid IN ({$subquery})";
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function only_language_condition( $language ) {
|
||||
$query = "
|
||||
SELECT translations.trid
|
||||
FROM {$this->wpdb->prefix}icl_translations translations
|
||||
WHERE translations.language_code = %s
|
||||
";
|
||||
|
||||
return $this->wpdb->prepare( $query, $language );
|
||||
}
|
||||
|
||||
private function explicit_status_condition( $status, $language = null ) {
|
||||
$prefix = $this->wpdb->prefix;
|
||||
|
||||
$query = "
|
||||
SELECT trid
|
||||
FROM {$prefix}icl_translations translations
|
||||
INNER JOIN {$prefix}icl_translation_status translation_status ON translation_status.translation_id = translations.translation_id
|
||||
WHERE (translation_status.status IN ({$status}) AND translation_status.needs_update = 0)
|
||||
";
|
||||
|
||||
if ( $language ) {
|
||||
$query .= $this->language_where( $language );
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function needs_update_condition( $language = null ) {
|
||||
$prefix = $this->wpdb->prefix;
|
||||
|
||||
$query = "
|
||||
SELECT trid
|
||||
FROM {$prefix}icl_translations translations
|
||||
INNER JOIN {$prefix}icl_translation_status translation_status ON translation_status.translation_id = translations.translation_id
|
||||
WHERE translation_status.needs_update = 1
|
||||
";
|
||||
|
||||
if ( $language ) {
|
||||
$query .= $this->language_where( $language );
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function not_translated_or_needs_update_condition( $language = null ) {
|
||||
$prefix = $this->wpdb->prefix;
|
||||
|
||||
$query = "
|
||||
SELECT trid
|
||||
FROM {$prefix}icl_translations translations
|
||||
INNER JOIN {$prefix}icl_translation_status translation_status ON translation_status.translation_id = translations.translation_id
|
||||
WHERE ( translation_status.needs_update = 1 OR translation_status.status = 0 )
|
||||
";
|
||||
if ( $language ) {
|
||||
$query .= $this->language_where( $language );
|
||||
}
|
||||
|
||||
$query .= ' UNION ';
|
||||
|
||||
if ( $language ) {
|
||||
$query .= "
|
||||
SELECT trid
|
||||
FROM {$prefix}icl_translations translations
|
||||
WHERE NOT EXISTS (
|
||||
SELECT inner_translations.trid
|
||||
FROM {$prefix}icl_translations inner_translations
|
||||
WHERE inner_translations.trid = translations.trid AND inner_translations.language_code = %s
|
||||
)
|
||||
";
|
||||
$query = $this->wpdb->prepare( $query, $language );
|
||||
} else {
|
||||
$query .= "
|
||||
SELECT trid
|
||||
FROM {$prefix}icl_translations translations
|
||||
WHERE (
|
||||
SELECT COUNT(inner_translations.trid)
|
||||
FROM {$prefix}icl_translations inner_translations
|
||||
WHERE inner_translations.trid = translations.trid
|
||||
) < %d
|
||||
";
|
||||
$query = $this->wpdb->prepare( $query, count( $this->sitepress->get_active_languages() ) );
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
private function language_where( $language ) {
|
||||
return $this->wpdb->prepare( ' AND translations.language_code = %s', $language );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @param string $post_type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function is_cpt_type( $args = array(), $post_type = '' ) {
|
||||
$is_cpt_type = false;
|
||||
if ( ! empty( $args ) && '' === $post_type && array_key_exists( 'type', $args ) && ! empty( $args['type'] ) ) {
|
||||
$post_type = $args['type'];
|
||||
}
|
||||
|
||||
if ( in_array( $post_type, $this->get_translatable_post_types() ) ) {
|
||||
$is_cpt_type = true;
|
||||
}
|
||||
|
||||
return $is_cpt_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function get_translatable_post_types() {
|
||||
if ( null === $this->translatable_post_types ) {
|
||||
$translatable_post_types = $this->sitepress->get_translatable_documents();
|
||||
$this->translatable_post_types = array_keys( apply_filters( 'wpml_tm_dashboard_translatable_types', $translatable_post_types ) );
|
||||
}
|
||||
|
||||
return $this->translatable_post_types;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* @package wpml-core
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'WP_List_Table' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'SitePress_Table' ) ) {
|
||||
class SitePress_Table extends WP_List_Table {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,761 @@
|
||||
<?php
|
||||
|
||||
use WPML\TM\Menu\TranslationServices\ActiveServiceRepository;
|
||||
|
||||
class WPML_TM_Menus_Settings extends WPML_TM_Menus {
|
||||
|
||||
/** @var WPML_Translate_Link_Targets_UI $translate_link_targets_ui */
|
||||
private $translate_link_targets_ui;
|
||||
|
||||
/** @var bool $end_user_feature_enabled */
|
||||
private $end_user_feature_enabled;
|
||||
|
||||
private $mcsetup_sections = array();
|
||||
|
||||
public function init() {
|
||||
$this->init_navigation_links();
|
||||
}
|
||||
|
||||
private function init_navigation_links() {
|
||||
/**
|
||||
* @var SitePress $sitepress
|
||||
* @var TranslationManagement $iclTranslationManagement
|
||||
*/
|
||||
global $sitepress, $iclTranslationManagement;
|
||||
$is_admin = current_user_can( 'manage_options' );
|
||||
|
||||
$this->mcsetup_sections['ml-content-setup-sec-1'] = esc_html__( 'How to translate posts and pages', 'wpml-translation-management' );
|
||||
|
||||
if ( $is_admin ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-2'] = esc_html__( 'Posts and pages synchronization', 'wpml-translation-management' );
|
||||
$this->mcsetup_sections['ml-content-setup-sec-3'] = esc_html__( 'Translated documents options', 'wpml-translation-management' );
|
||||
|
||||
$this->mcsetup_sections['ml-content-setup-sec-wp-login'] = esc_html__( 'Login and registration pages', 'wpml-translation-management' );
|
||||
|
||||
if ( defined( 'WPML_ST_VERSION' ) ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-4'] = esc_html__( 'Custom posts slug translation options', 'wpml-translation-management' );
|
||||
}
|
||||
|
||||
if ( TranslationProxy::is_current_service_active_and_authenticated() ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-5'] = esc_html__( 'Translation pickup mode', 'wpml-translation-management' );
|
||||
}
|
||||
}
|
||||
|
||||
$this->mcsetup_sections['ml-content-setup-sec-5-1'] = esc_html__( 'XLIFF file options', 'wpml-translation-management' );
|
||||
|
||||
if ( $is_admin ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-cf'] = esc_html__( 'Custom Fields Translation', 'wpml-translation-management' );
|
||||
$this->mcsetup_sections['ml-content-setup-sec-tcf'] = esc_html__( 'Custom Term Meta Translation', 'wpml-translation-management' );
|
||||
|
||||
$custom_posts = array();
|
||||
$this->post_types = $sitepress->get_translatable_documents( true );
|
||||
|
||||
foreach ( $this->post_types as $k => $v ) {
|
||||
$custom_posts[ $k ] = $v;
|
||||
}
|
||||
|
||||
global $wp_taxonomies;
|
||||
$custom_taxonomies = array_diff( array_keys( (array) $wp_taxonomies ), array( 'post_tag', 'category', 'nav_menu', 'link_category', 'post_format' ) );
|
||||
|
||||
if ( $custom_posts ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-7'] = esc_html__( 'Post Types Translation', 'wpml-translation-management' );
|
||||
}
|
||||
|
||||
if ( $custom_taxonomies ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-8'] = esc_html__( 'Taxonomies Translation', 'wpml-translation-management' );
|
||||
}
|
||||
|
||||
if ( ! empty( $iclTranslationManagement->admin_texts_to_translate ) && function_exists( 'icl_register_string' ) ) {
|
||||
$this->mcsetup_sections['ml-content-setup-sec-9'] = esc_html__( 'Admin Strings to Translate', 'wpml-translation-management' );
|
||||
}
|
||||
}
|
||||
|
||||
$this->get_translate_link_targets_ui()->add_hooks();
|
||||
|
||||
$this->mcsetup_sections = apply_filters( 'wpml_mcsetup_navigation_links', $this->mcsetup_sections, $sitepress, $iclTranslationManagement );
|
||||
}
|
||||
|
||||
protected function render_main() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_html__( 'Settings', 'wpml-translation-management' ); ?></h1>
|
||||
|
||||
<?php
|
||||
do_action( 'icl_tm_messages' );
|
||||
$this->build_tab_items();
|
||||
$this->render_items();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function build_tab_items() {
|
||||
$this->build_mcs_item();
|
||||
$this->build_translation_notifications_item();
|
||||
|
||||
$this->tab_items = apply_filters( 'wpml_tm_tab_items', $this->tab_items );
|
||||
}
|
||||
|
||||
private function build_mcs_item() {
|
||||
global $sitepress;
|
||||
|
||||
$this->tab_items['mcsetup']['caption'] = esc_html__( 'Multilingual Content Setup', 'wpml-translation-management' );
|
||||
$translate_link_targets = new WPML_Translate_Link_Target_Global_State( $sitepress );
|
||||
if ( $translate_link_targets->is_rescan_required() ) {
|
||||
$this->tab_items['mcsetup']['caption'] = '<i class="otgs-ico-warning"></i>' . esc_html( $this->tab_items['mcsetup']['caption'] );
|
||||
}
|
||||
$this->tab_items['mcsetup']['callback'] = array( $this, 'build_content_mcs' );
|
||||
$this->tab_items['mcsetup']['current_user_can'] = array( 'manage_options', WPML_Manage_Translations_Role::CAPABILITY );
|
||||
}
|
||||
|
||||
private function build_translation_notifications_item() {
|
||||
$this->tab_items['notifications'] = array(
|
||||
'caption' => esc_html__( 'Translation Notifications', 'wpml-translation-management' ),
|
||||
'current_user_can' => WPML_Manage_Translations_Role::CAPABILITY,
|
||||
'callback' => array( $this, 'build_content_translation_notifications' ),
|
||||
);
|
||||
}
|
||||
|
||||
public function build_content_mcs() {
|
||||
/**
|
||||
* included by menu translation-management.php
|
||||
*
|
||||
* @var TranslationManagement $iclTranslationManagement
|
||||
*/
|
||||
global $sitepress, $sitepress_settings, $iclTranslationManagement;
|
||||
|
||||
$translate_link_targets = new WPML_Translate_Link_Target_Global_State( $sitepress );
|
||||
if ( $translate_link_targets->is_rescan_required() ) {
|
||||
?>
|
||||
<div class="update-nag">
|
||||
<p>
|
||||
<i class="otgs-ico-warning"></i>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'There is new translated content on this site. You can scan posts and strings to adjust links to point to translated content.',
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p><?php echo $this->get_navigation_link( $this->get_translate_link_targets_ui()->get_id() ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
$this->render_mcsetup_navigation_links();
|
||||
?>
|
||||
|
||||
<div class="wpml-section wpml-section-notice">
|
||||
<div class="updated below-h2">
|
||||
<p>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
"WPML can read a configuration file that tells it what needs translation in themes and plugins. The file is named wpml-config.xml and it's placed in the root folder of the plugin or theme.",
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://wpml.org/?page_id=5526">
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Learn more',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-1' ) ) : ?>
|
||||
<div class="wpml-section" id="ml-content-setup-sec-1">
|
||||
<?php
|
||||
$doc_translation_method = ICL_TM_TMETHOD_MANUAL;
|
||||
if ( isset( $iclTranslationManagement->settings['doc_translation_method'] ) ) {
|
||||
$doc_translation_method = $iclTranslationManagement->settings['doc_translation_method'];
|
||||
}
|
||||
$isClassicEditor = (string) ICL_TM_TMETHOD_EDITOR === (string) $doc_translation_method;
|
||||
$isATEEditor = (string) ICL_TM_TMETHOD_ATE === (string) $doc_translation_method;
|
||||
?>
|
||||
|
||||
<div class="wpml-section-header">
|
||||
<h3>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'How to translate posts and pages',
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content">
|
||||
|
||||
<form id="icl_doc_translation_method" name="icl_doc_translation_method" action="">
|
||||
<?php wp_nonce_field( 'icl_doc_translation_method_nonce', '_icl_nonce' ); ?>
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php
|
||||
|
||||
/* translators: Heading shown for selecting the editor to use with WPML's Translation Management when creating new content */
|
||||
echo esc_html__( 'New content', 'wpml-translation-management' );
|
||||
|
||||
?>
|
||||
</h4>
|
||||
|
||||
<ul class="t_method">
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="t_method" value="<?php echo ICL_TM_TMETHOD_ATE; ?>"
|
||||
<?php
|
||||
if ( $isATEEditor ) :
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
/* translators: Editor to use with WPML's Translation Management when creating new content */
|
||||
echo esc_html__( "Use WPML's Advanced Translation Editor", 'wpml-translation-management' );
|
||||
?>
|
||||
</label>
|
||||
<?php do_action( 'wpml_tm_mcs_' . ICL_TM_TMETHOD_ATE ); ?>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="t_method" value="<?php echo ICL_TM_TMETHOD_EDITOR; ?>"
|
||||
<?php
|
||||
if ( $isClassicEditor ) :
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
/* translators: Editor to use with WPML's Translation Management when creating new content */
|
||||
echo esc_html__( "Use WPML's Classic Translation Editor", 'wpml-translation-management' );
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$default_editor_for_old_jobs = get_option( WPML_TM_Old_Jobs_Editor::OPTION_NAME, null );
|
||||
?>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php
|
||||
|
||||
/* translators: heading shown for selecting the editor to use when updating content that was created with WPML's Classic Translation Editor */
|
||||
esc_html_e( "Content that was created with WPML's Classic Translation Editor", 'wpml-translation-management' );
|
||||
|
||||
?>
|
||||
</h4>
|
||||
|
||||
<ul class="<?php echo WPML_TM_Old_Jobs_Editor::OPTION_NAME; ?>">
|
||||
<li>
|
||||
<label>
|
||||
<input
|
||||
type="radio" name="<?php echo WPML_TM_Old_Jobs_Editor::OPTION_NAME; ?>"
|
||||
value="<?php echo esc_attr( WPML_TM_Editors::ATE ); ?>"
|
||||
<?php checked( $default_editor_for_old_jobs === WPML_TM_Editors::ATE ); ?> />
|
||||
<?php
|
||||
|
||||
/* translators: Which editor to use when updating content that was created with WPML's Classic Translation Editor? */
|
||||
esc_html_e( 'Switch to using the Advanced Translation Editor (old translations may be unusable)', 'wpml-translation-management' );
|
||||
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<label>
|
||||
<input
|
||||
type="radio" name="<?php echo WPML_TM_Old_Jobs_Editor::OPTION_NAME; ?>"
|
||||
value="<?php echo esc_attr( WPML_TM_Editors::WPML ); ?>"
|
||||
<?php checked( $default_editor_for_old_jobs === WPML_TM_Editors::WPML ); ?> />
|
||||
<?php
|
||||
|
||||
/* translators: Which editor to use when updating content that was created with WPML's Classic Translation Editor? */
|
||||
esc_html_e( "Use WPML's Classic Translation Editor", 'wpml-translation-management' );
|
||||
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="https://wpml.org/documentation/translating-your-contents/translation-editor-options/?utm_source=wpmlplugin&utm_campaign=tm-settings&utm_medium=translation-editor-options&utm_term=translation-management"
|
||||
target="_blank" rel="noopener" class="wpml-external-link">Translation editor options</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php do_action( 'wpml_doc_translation_method_below' ); ?>
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php echo esc_html__( 'Taxonomies', 'wpml-translation-management' ) ?>
|
||||
</h4>
|
||||
|
||||
<p id="tm_block_retranslating_terms">
|
||||
<label>
|
||||
<input
|
||||
name="tm_block_retranslating_terms"
|
||||
value="1"
|
||||
<?php checked( icl_get_setting( 'tm_block_retranslating_terms' ), "1" ) ?>
|
||||
type="checkbox"
|
||||
/>
|
||||
<?php echo esc_html__( "Don't include already translated terms in the translation editor", 'wpml-translation-management' ) ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php echo esc_html__( 'Translators help', 'wpml-translation-management' ) ?>
|
||||
</h4>
|
||||
<p>
|
||||
<label>
|
||||
<input
|
||||
name="how_to_translate"
|
||||
value="1"
|
||||
<?php checked( icl_get_setting( 'hide_how_to_translate' ), false ) ?>
|
||||
type="checkbox"
|
||||
/>
|
||||
<?php echo esc_html__( 'Show translation instructions in the list of pages', 'wpml-translation-management' ) ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php do_action( 'wpml_how_to_translate_posts_and_pages' ); ?>
|
||||
|
||||
<?php do_action( 'wpml_how_to_translate_posts_and_pages_below' ); ?>
|
||||
|
||||
<p>
|
||||
<a
|
||||
href="https://wpml.org/?page_id=3416"
|
||||
target="_blank"
|
||||
>
|
||||
<?php echo esc_html__( 'Learn more about the different translation options', 'wpml-translation-management' ) ?>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p class="buttons-wrap">
|
||||
<span class="icl_ajx_response" id="icl_ajx_response_dtm"> </span>
|
||||
<input type="submit" class="button-primary"
|
||||
value="<?php echo esc_html__( 'Save', 'wpml-translation-management' ); ?>" />
|
||||
</p>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<!-- .wpml-section-content -->
|
||||
|
||||
</div><!-- #ml-content-setup-sec-1 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-2' ) ) : ?>
|
||||
<?php include ICL_PLUGIN_PATH . '/menu/_posts_sync_options.php'; ?>
|
||||
<?php endif; ?><!-- #ml-content-setup-sec-2 -->
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-3' ) ) : ?>
|
||||
<div class="wpml-section" id="ml-content-setup-sec-3">
|
||||
|
||||
<div class="wpml-section-header">
|
||||
<h3><?php echo esc_html__( 'Translated documents options', 'wpml-translation-management' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content">
|
||||
|
||||
<form name="icl_tdo_options" id="icl_tdo_options" action="">
|
||||
<?php
|
||||
wp_nonce_field(
|
||||
'wpml-translated-document-options-nonce',
|
||||
WPML_TM_Options_Ajax::NONCE_TRANSLATED_DOCUMENT
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php echo esc_html__( 'Document status', 'wpml-translation-management' ); ?>
|
||||
</h4>
|
||||
<ul>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="icl_translated_document_status" value="0"
|
||||
<?php
|
||||
checked(
|
||||
(bool) icl_get_setting( 'translated_document_status' ),
|
||||
false
|
||||
);
|
||||
?>
|
||||
/>
|
||||
<?php echo esc_html__( 'Draft', 'wpml-translation-management' ); ?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="icl_translated_document_status" value="1"
|
||||
<?php
|
||||
checked(
|
||||
(bool) icl_get_setting( 'translated_document_status' ),
|
||||
true
|
||||
);
|
||||
?>
|
||||
/>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Same as the original document',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="explanation-text">
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Choose if translations should be published when received. Note: If Publish is selected, the translation will only be published if the original document is published when the translation is received.',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
<h4>
|
||||
<?php echo esc_html__( 'Page URL', 'wpml-translation-management' ); ?>
|
||||
</h4>
|
||||
<ul>
|
||||
<li>
|
||||
<label><input type="radio" name="icl_translated_document_page_url" value="auto-generate"
|
||||
<?php
|
||||
if ( empty( $sitepress_settings['translated_document_page_url'] )
|
||||
|| $sitepress_settings['translated_document_page_url']
|
||||
=== 'auto-generate' ) :
|
||||
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Auto-generate from title (default)',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input type="radio" name="icl_translated_document_page_url" value="translate"
|
||||
<?php
|
||||
if ( $sitepress_settings['translated_document_page_url']
|
||||
=== 'translate' ) :
|
||||
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Translate (this will include the slug in the translation and not create it automatically from the title)',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label><input type="radio" name="icl_translated_document_page_url" value="copy-encoded"
|
||||
<?php
|
||||
if ( $sitepress_settings['translated_document_page_url']
|
||||
=== 'copy-encoded' ) :
|
||||
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Copy from original language if translation language uses encoded URLs',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
<p class="buttons-wrap">
|
||||
<span class="icl_ajx_response" id="icl_ajx_response_tdo"> </span>
|
||||
<input id="js-translated_document-options-btn" type="button" class="button-primary" value="
|
||||
<?php
|
||||
echo esc_attr__(
|
||||
'Save',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
" />
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<!-- .wpml-section-content -->
|
||||
</div><!-- #ml-content-setup-sec-3 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-wp-login' ) ) {
|
||||
include ICL_PLUGIN_PATH . '/menu/_login_translation_options.php';
|
||||
}
|
||||
?>
|
||||
<!-- #ml-content-setup-sec-wp-login -->
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-4' ) ) : ?>
|
||||
<?php include WPML_ST_PATH . '/menu/_slug-translation-options.php'; ?><!-- #ml-content-setup-sec-4 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-5' ) ) : ?>
|
||||
<div class="wpml-section" id="ml-content-setup-sec-5">
|
||||
|
||||
<div class="wpml-section-header">
|
||||
<h3><?php echo esc_html__( 'Translation pickup mode', 'wpml-translation-management' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content">
|
||||
|
||||
<form id="icl_translation_pickup_mode" name="icl_translation_pickup_mode" action="">
|
||||
<?php
|
||||
wp_nonce_field(
|
||||
'wpml_save_translation_pickup_mode',
|
||||
WPML_TM_Pickup_Mode_Ajax::NONCE_PICKUP_MODE
|
||||
)
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'How should the site receive completed translations from Translation Service?',
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
<input type="radio" name="icl_translation_pickup_method"
|
||||
value="<?php echo ICL_PRO_TRANSLATION_PICKUP_XMLRPC; ?>"
|
||||
<?php
|
||||
if ( $sitepress_settings['translation_pickup_method']
|
||||
=== ICL_PRO_TRANSLATION_PICKUP_XMLRPC ) :
|
||||
|
||||
?>
|
||||
checked="checked"<?php endif ?>/>
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Translation Service will deliver translations automatically using XML-RPC',
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
<input type="radio" name="icl_translation_pickup_method"
|
||||
value="<?php echo ICL_PRO_TRANSLATION_PICKUP_POLLING; ?>"
|
||||
<?php
|
||||
if ( $sitepress_settings['translation_pickup_method']
|
||||
=== ICL_PRO_TRANSLATION_PICKUP_POLLING ) :
|
||||
|
||||
?>
|
||||
checked="checked"<?php endif; ?> />
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'The site will fetch translations manually',
|
||||
'wpml-translation-management'
|
||||
);
|
||||
?>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
|
||||
<p class="buttons-wrap">
|
||||
<span class="icl_ajx_response" id="icl_ajx_response_tpm"> </span>
|
||||
<input
|
||||
id="translation-pickup-mode"
|
||||
class="button-primary"
|
||||
name="save"
|
||||
value="<?php echo esc_attr__( 'Save', 'wpml-translation-management' ) ?>"
|
||||
type="button"
|
||||
/>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
$this->build_content_dashboard_fetch_translations_box();
|
||||
?>
|
||||
</form>
|
||||
|
||||
<?php do_action( 'wpml_tm_mcs_translation_pickup_mode' ); ?>
|
||||
|
||||
</div>
|
||||
<!-- .wpml-section-content -->
|
||||
</div><!-- #ml-content-setup-sec-5 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-5-1' ) ) : ?>
|
||||
<?php include WPML_TM_PATH . '/menu/xliff-options.php'; ?><!-- #ml-content-setup-sec-5-1 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $this->build_content_mcs_custom_fields(); ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-7' ) ) : ?>
|
||||
<?php include ICL_PLUGIN_PATH . '/menu/_custom_types_translation.php'; ?><!-- #ml-content-setup-sec-7 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-9' ) ) : ?>
|
||||
<div class="wpml-section" id="ml-content-setup-sec-9">
|
||||
|
||||
<div class="wpml-section-header">
|
||||
<h3><?php echo esc_html__( 'Admin Strings to Translate', 'wpml-translation-management' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content">
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">
|
||||
<?php echo esc_html__( 'Admin Strings', 'wpml-translation-management' ); ?>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<?php
|
||||
foreach (
|
||||
$iclTranslationManagement->admin_texts_to_translate as $option_name =>
|
||||
$option_value
|
||||
) {
|
||||
$iclTranslationManagement->render_option_writes( $option_name, $option_value );
|
||||
}
|
||||
?>
|
||||
<br />
|
||||
|
||||
href="
|
||||
<?php
|
||||
echo admin_url(
|
||||
'admin.php?page='
|
||||
. WPML_ST_FOLDER
|
||||
. '/menu/string-translation.php'
|
||||
)
|
||||
?>
|
||||
">
|
||||
<?php
|
||||
echo esc_html__(
|
||||
'Edit translatable strings',
|
||||
'wpml-translation-management'
|
||||
)
|
||||
?>
|
||||
</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
<!-- .wpml-section-content -->
|
||||
|
||||
</div><!-- #ml-content-setup-sec-9 -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( $this->should_show_mcsetup_section( $this->get_translate_link_targets_ui()->get_id() ) ) : ?>
|
||||
<?php echo $this->get_translate_link_targets_ui()->render(); ?><!-- #ml-content-setup-sec-links-target -->
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
wp_enqueue_script( 'wpml-tm-mcs' );
|
||||
wp_enqueue_script( 'wpml-tm-mcs-translate-link-targets' );
|
||||
}
|
||||
|
||||
private function build_content_mcs_custom_fields() {
|
||||
global $wpdb;
|
||||
|
||||
$factory = new WPML_TM_MCS_Custom_Field_Settings_Menu_Factory();
|
||||
|
||||
if ( $this->should_show_mcsetup_section( 'ml-content-setup-sec-cf' ) ) {
|
||||
$menu_item_posts = $factory->create_post();
|
||||
$menu_item_posts->init_data();
|
||||
echo $menu_item_posts->render();
|
||||
}
|
||||
|
||||
if ( ! empty( $wpdb->termmeta ) && $this->should_show_mcsetup_section( 'ml-content-setup-sec-tcf' ) ) {
|
||||
$menu_item_terms = $factory->create_term();
|
||||
$menu_item_terms->init_data();
|
||||
echo $menu_item_terms->render();
|
||||
}
|
||||
}
|
||||
|
||||
public function build_content_translation_notifications() {
|
||||
?>
|
||||
<form method="post" name="translation-notifications" id="translation-notifications"
|
||||
action="admin.php?page=<?php echo WPML_TM_FOLDER . $this->get_page_slug(); ?>&sm=notifications">
|
||||
<input type="hidden" name="icl_tm_action" value="save_notification_settings"/>
|
||||
|
||||
<?php do_action( 'wpml_tm_translation_notification_setting_after' ); ?>
|
||||
|
||||
<div class="wpml-section" id="translation-notifications-sec-3">
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary"
|
||||
value="<?php echo esc_html__( 'Save', 'wpml-translation-management' ); ?>"/>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php wp_nonce_field( 'save_notification_settings_nonce', 'save_notification_settings_nonce' ); ?>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
protected function get_page_slug() {
|
||||
return WPML_Translation_Management::PAGE_SLUG_SETTINGS;
|
||||
}
|
||||
|
||||
protected function get_default_tab() {
|
||||
return 'mcsetup';
|
||||
}
|
||||
|
||||
private function render_mcsetup_navigation_links() {
|
||||
echo '<ul class="wpml-navigation-links js-wpml-navigation-links">';
|
||||
|
||||
foreach ( $this->mcsetup_sections as $anchor => $title ) {
|
||||
echo '<li>' . $this->get_navigation_link( $anchor ) . '</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
private function get_navigation_link( $anchor ) {
|
||||
if ( array_key_exists( $anchor, $this->mcsetup_sections ) ) {
|
||||
return '<a href="#' . $anchor . '">' . $this->mcsetup_sections[ $anchor ] . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
/** @return bool */
|
||||
private function should_show_mcsetup_section( $anchor ) {
|
||||
return array_key_exists( $anchor, $this->mcsetup_sections );
|
||||
}
|
||||
|
||||
/** @return WPML_Translate_Link_Targets_UI */
|
||||
private function get_translate_link_targets_ui() {
|
||||
/**
|
||||
* @var SitePress $sitepress
|
||||
* @var wpdb $wpdb
|
||||
* @var $ICL_Pro_Translation
|
||||
*/
|
||||
global $sitepress, $wpdb, $ICL_Pro_Translation;
|
||||
|
||||
if ( ! $this->translate_link_targets_ui ) {
|
||||
$this->translate_link_targets_ui = new WPML_Translate_Link_Targets_UI(
|
||||
__( 'Translate Link Targets', 'wpml-translation-management' ),
|
||||
$wpdb,
|
||||
$sitepress,
|
||||
$ICL_Pro_Translation
|
||||
);
|
||||
}
|
||||
|
||||
return $this->translate_link_targets_ui;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
if ( filter_input( INPUT_GET, 'sm', FILTER_SANITIZE_STRING ) === 'basket' ) {
|
||||
add_action( 'admin_enqueue_scripts', array( 'SitePress_Table_Basket', 'enqueue_js' ) );
|
||||
}
|
||||
|
||||
abstract class WPML_TM_Menus {
|
||||
|
||||
protected $post_types;
|
||||
protected $tab_items;
|
||||
private $base_target_url;
|
||||
protected $current_shown_item;
|
||||
|
||||
/** @var WPML_UI_Screen_Options_Pagination|null $dashboard_pagination */
|
||||
protected $dashboard_pagination;
|
||||
|
||||
function __construct() {
|
||||
$this->current_shown_item = isset( $_GET['sm'] ) ? $_GET['sm'] : $this->get_default_tab();
|
||||
$this->base_target_url = dirname( __FILE__ );
|
||||
}
|
||||
|
||||
public function display_main( WPML_UI_Screen_Options_Pagination $dashboard_pagination = null ) {
|
||||
$this->dashboard_pagination = $dashboard_pagination;
|
||||
if ( true !== apply_filters( 'wpml_tm_lock_ui', false ) ) {
|
||||
$this->render_main();
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function render_main();
|
||||
|
||||
private function build_tab_item_target_url( $target ) {
|
||||
return $this->base_target_url . $target;
|
||||
}
|
||||
|
||||
abstract protected function build_tab_items();
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function get_current_shown_item() {
|
||||
return $this->current_shown_item;
|
||||
}
|
||||
|
||||
private function build_tabs() {
|
||||
$tm_sub_menu = $this->get_current_shown_item();
|
||||
foreach ( $this->tab_items as $id => $tab_item ) {
|
||||
if ( ! isset( $tab_item['caption'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $tab_item['target'] ) && ! isset( $tab_item['callback'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$caption = $tab_item['caption'];
|
||||
if ( ! $this->current_user_can_access( $tab_item ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$classes = array(
|
||||
'nav-tab',
|
||||
'nav-tab-' . $id,
|
||||
);
|
||||
if ( $tm_sub_menu === $id ) {
|
||||
$classes[] = 'nav-tab-active';
|
||||
}
|
||||
|
||||
$class = implode( ' ', $classes );
|
||||
$href = 'admin.php?page=' . WPML_TM_FOLDER . $this->get_page_slug() . '&sm=' . $id;
|
||||
?>
|
||||
<a class="<?php echo esc_attr( $class ); ?>" href="<?php echo esc_attr( $href ); ?>">
|
||||
<?php echo $caption; ?>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
private function build_content() {
|
||||
$tm_sub_menu = $this->get_current_shown_item();
|
||||
foreach ( $this->tab_items as $id => $tab_item ) {
|
||||
if ( ! isset( $tab_item['caption'] ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $tab_item['target'] ) && ! isset( $tab_item['callback'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( $tm_sub_menu == $id ) {
|
||||
if ( $this->current_user_can_access( $tab_item ) ) {
|
||||
if ( isset( $tab_item['target'] ) ) {
|
||||
$target = $tab_item['target'];
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
include_once $this->build_tab_item_target_url( $target );
|
||||
}
|
||||
if ( isset( $tab_item['callback'] ) ) {
|
||||
$callback = $tab_item['callback'];
|
||||
call_user_func( $callback );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
do_action( 'icl_tm_menu_' . $tm_sub_menu );
|
||||
}
|
||||
|
||||
protected function render_items() {
|
||||
if ( $this->tab_items ) {
|
||||
?>
|
||||
<div class="icl-translation-management-menu wpml-tabs">
|
||||
<?php
|
||||
$this->build_tabs();
|
||||
?>
|
||||
</div>
|
||||
<div class="icl_tm_wrap wpml-wrap">
|
||||
<?php
|
||||
$this->build_content();
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
public function build_content_dashboard_fetch_translations_box() {
|
||||
if ( TranslationProxy::is_current_service_active_and_authenticated() ) {
|
||||
$tm_polling_box = new WPML_TM_Polling_Box();
|
||||
echo $tm_polling_box->render();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used only by unit tests at the moment
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_post_types() {
|
||||
return $this->post_types;
|
||||
}
|
||||
|
||||
|
||||
protected function heading( $text ) {
|
||||
?>
|
||||
<h3 class="wpml-tm-section-header"><?php echo esc_html( $text ); ?></h3>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function current_user_can_access( $tab_item ) {
|
||||
$current_user_can = isset( $tab_item['current_user_can'] ) ? $tab_item['current_user_can'] : false;
|
||||
|
||||
if ( is_array( $current_user_can ) ) {
|
||||
foreach ( $current_user_can as $capability ) {
|
||||
if ( current_user_can( $capability ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return current_user_can( $current_user_can );
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected function get_page_slug();
|
||||
|
||||
abstract protected function get_default_tab();
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
var wpml_xliff_ajxloaderimg_src = '<?php echo WPML_XLIFF_TM_URL; ?>/res/img/ajax-loader.gif';
|
||||
var wpml_xliff_ajxloaderimg = '<img src="'+wpml_xliff_ajxloaderimg_src+'" alt="loading" width="16" height="16" />';
|
||||
</script>
|
||||
|
||||
<div class="wrap">
|
||||
<h2><?php echo __( 'XLIFF translation', 'wpml-translation-management' ); ?></h2>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
global $sitepress;
|
||||
|
||||
$xliff_newlines = (int) $sitepress->get_setting( 'xliff_newlines' );
|
||||
if ( ! $xliff_newlines ) {
|
||||
$xliff_newlines = WPML_XLIFF_TM_NEWLINES_ORIGINAL;
|
||||
}
|
||||
|
||||
$new_line_labels = array(
|
||||
WPML_XLIFF_TM_NEWLINES_ORIGINAL => __(
|
||||
'Do nothing - all new line characters will stay untouched.',
|
||||
'wpml-translation-management'
|
||||
),
|
||||
WPML_XLIFF_TM_NEWLINES_REPLACE => sprintf(
|
||||
__( 'All new lines should be replaced by HTML element %s. Use this option if translation tool used by translator does not support new lines characters (for example Virtaal software)', 'wpml-translation-management' ),
|
||||
'<br class="xliff-newline" />'
|
||||
),
|
||||
);
|
||||
?>
|
||||
|
||||
<div class="wpml-section" id="ml-content-setup-sec-5-1">
|
||||
|
||||
<div class="wpml-section-header">
|
||||
<h3><?php esc_html_e( 'XLIFF file options', 'wpml-translation-management' ); ?></h3>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content">
|
||||
|
||||
<form name="icl_xliff_options_form" id="icl_xliff_options_form" action="">
|
||||
<?php wp_nonce_field( 'icl_xliff_options_form_nonce', '_icl_nonce' ); ?>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
|
||||
<h4><?php esc_html_e( 'XLIFF version', 'wpml-translation-management' ); ?></h4>
|
||||
|
||||
<p>
|
||||
<?php esc_html_e( 'Choose default format for XLIFF file:', 'wpml-translation-management' ); ?>
|
||||
|
||||
<select name="icl_xliff_version">
|
||||
<option value="false"><?php echo esc_html__( 'Please choose', 'wpml-translation-management' ); ?></option>
|
||||
<?php
|
||||
$xliff_instance = setup_xliff_frontend();
|
||||
$available_xliff_versions = $xliff_instance->get_available_xliff_versions();
|
||||
foreach ( $available_xliff_versions as $value => $version ) {
|
||||
$selected = '';
|
||||
if ( $sitepress->get_setting( 'tm_xliff_version' ) === $value ) {
|
||||
$selected = 'selected="selected"';
|
||||
}
|
||||
$version_label = sprintf( __( 'XLIFF %s', 'wpml-translation-management' ), $version );
|
||||
echo sprintf( '<option value="%1$s" %2$s >%3$s</option>', esc_attr( $value ), $selected, esc_html( $version_label ) );
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="wpml-section-content-inner">
|
||||
|
||||
<h4><?php esc_html_e( 'New lines character', 'wpml-translation-management' ); ?></h4>
|
||||
<p>
|
||||
<?php esc_html_e( 'How new lines characters in XLIFF files should be handled?', 'wpml-translation-management' ); ?>
|
||||
</p>
|
||||
|
||||
<?php foreach ( $new_line_labels as $mode => $label ) { ?>
|
||||
<p>
|
||||
<label>
|
||||
<input type="radio" name="icl_xliff_newlines"
|
||||
value="<?php echo esc_attr( $mode ); ?>"<?php checked( $xliff_newlines, $mode ); ?>/>
|
||||
<?php echo esc_html( $label ); ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
<p class="buttons-wrap">
|
||||
<span class="icl_ajx_response" id="icl_ajx_response"></span>
|
||||
<input type="submit" class="button-primary"
|
||||
value="<?php esc_attr_e( 'Save', 'wpml-translation-management' ); ?>"/>
|
||||
</p>
|
||||
</form>
|
||||
</div> <!-- .wpml-section-content -->
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user