sitepress = $sitepress; $this->tm_loader = $tm_loader; $this->tm_instance = $tm_instance; $this->wpml_tp_translator = $wpml_tp_translator; } public function init() { global $wpdb; $template_service_loader = new WPML_Twig_Template_Loader( array( WPML_TM_PATH . '/templates/tm-menus/' ) ); $manager_records = new WPML_Translation_Manager_Records( $wpdb, new WPML_WP_User_Query_Factory() ); $translator_records = new WPML_Translator_Records( $wpdb, new WPML_WP_User_Query_Factory() ); $this->wpml_tm_menus_management = new WPML_TM_Menus_Management( $template_service_loader->get_template(), $manager_records, $translator_records ); $mcs_factory = new WPML_TM_Scripts_Factory(); $mcs_factory->init_hooks(); if ( null === $this->wpml_tp_translator ) { $this->wpml_tp_translator = new WPML_TP_Translator(); } $this->ajax_route = new WPML_Ajax_Route( new WPML_TM_Ajax_Factory( $wpdb, $this->sitepress, $_POST ) ); } function load() { global $pagenow; $this->tm_loader->tm_after_load(); $wpml_wp_api = $this->sitepress->get_wp_api(); if ( $wpml_wp_api->is_admin() ) { $this->tm_loader->load_xliff_frontend(); } $this->plugin_localization(); add_action('wp_ajax_basket_extra_fields_refresh', array($this, 'basket_extra_fields_refresh') ); // Check if WPML is active. If not display warning message and not load Sticky links if ( ! defined( 'ICL_SITEPRESS_VERSION' ) || ICL_PLUGIN_INACTIVE ) { if ( ! function_exists( 'is_multisite' ) || ! is_multisite() ) { add_action( 'admin_notices', array( $this, '_no_wpml_warning' ) ); } return false; } elseif ( ! $this->sitepress->get_setting( 'setup_complete' ) ) { $this->maybe_show_wpml_not_installed_warning(); return false; } if ( isset( $_GET['icl_action'] ) ) { if ( $_GET['icl_action'] === 'reminder_popup' && isset( $_GET['_icl_nonce'] ) && wp_verify_nonce( $_GET['_icl_nonce'], 'reminder_popup_nonce' ) === 1 ) { add_action( 'init', array( 'TranslationProxy_Popup', 'display' ) ); } elseif ( $_GET['icl_action'] === 'dismiss_help' ) { $this->sitepress->set_setting( 'dont_show_help_admin_notice', true, true ); } } if ( isset( $_GET['wpml_tm_saved'] ) ) { add_action( 'admin_notices', array( $this, 'job_saved_message' ) ); } if ( isset( $_GET['wpml_tm_cancel'] ) ) { add_action( 'admin_notices', array( $this, 'job_cancelled_message' ) ); } $this->tm_loader->load_pro_translation( $wpml_wp_api ); add_action( 'wp_ajax_wpml_check_batch_status', array($this, 'check_batch_status_ajax') ); if ( $wpml_wp_api->is_admin() ) { add_action( 'init', array( $this, 'automatic_service_selection_action' ) ); add_action( 'translation_service_authentication', array( $this, 'translation_service_authentication' ) ); add_filter( 'translation_service_js_data', array( $this, 'translation_service_js_data' ) ); add_filter( 'wpml_string_status_text', array( 'WPML_Remote_String_Translation', 'string_status_text_filter' ), 10, 3 ); add_action( 'trashed_post', array( $this, 'trashed_post_actions' ), 10, 2 ); add_action( 'wp_ajax_icl_get_jobs_table', 'icl_get_jobs_table' ); add_action( 'wp_ajax_icl_cancel_translation_jobs', 'icl_cancel_translation_jobs' ); add_action( 'wp_ajax_icl_populate_translations_pickup_box', 'icl_populate_translations_pickup_box' ); add_action( 'wp_ajax_icl_pickup_translations', 'icl_pickup_translations' ); add_action( 'wp_ajax_icl_pickup_translations_complete', 'icl_pickup_translations_complete' ); add_action( 'wp_ajax_get_translator_status', array( 'TranslationProxy_Translator', 'get_translator_status_ajax' ) ); add_action( 'wp_ajax_wpml-flush-website-details-cache', array( 'TranslationProxy_Translator', 'flush_website_details_cache_action' ) ); add_action( 'wpml_updated_translation_status', array( 'TranslationProxy_Batch', 'maybe_assign_generic_batch' ), 10, 2 ); add_action( 'init', array($this, 'handle_notices_action' ) ); do_action( 'wpml_tm_init' ); if ( $pagenow !== 'customize.php' ) { // stop TM scripts from messing up theme customizer add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'admin_print_styles', array( $this, 'admin_print_styles' ), 11 ); $this->add_custom_xml_config(); } add_action( 'wpml_admin_menu_configure', array( $this, 'management_menu' ) ); add_action( 'wpml_admin_menu_configure', array( $this, 'translators_menu' ) ); add_action( 'wpml_admin_menu_configure', array( $this, 'settings_menu' ) ); add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 ); if ( $this->sitepress->get_wp_api() ->is_translation_queue_page() ) { $translation_queue_factory = new WPML_Translations_Queue_Factory(); $this->tm_queue = $translation_queue_factory->create(); $this->tm_queue->init_hooks(); } if ( $this->sitepress->get_wp_api()->is_dashboard_tab() ) { $screen_options_factory = new WPML_UI_Screen_Options_Factory( $this->sitepress ); $this->dashboard_screen_options = $screen_options_factory->create_pagination( 'tm_dashboard_per_page', ICL_TM_DOCS_PER_PAGE ); } // Add a nice warning message if the user tries to edit a post manually and it's actually in the process of being translated if ( in_array( $pagenow, array( 'post-new.php', 'post.php', 'admin-ajax.php' ), true ) ) { $post_edit_notices_factory = new WPML_TM_Post_Edit_Notices_Factory(); $post_edit_notices_factory->create()->add_hooks(); } add_action( 'wp_ajax_dismiss_icl_side_by_site', array( $this, 'dismiss_icl_side_by_site' ) ); add_action( 'wp_ajax_icl_tm_toggle_promo', array( $this, '_icl_tm_toggle_promo' ) ); add_action ( 'wpml_support_page_after', array( $this, 'add_com_log_link' ) ); add_action ( 'wpml_translation_basket_page_after', array( $this, 'add_com_log_link' ) ); $this->translate_independently(); } if ( $wpml_wp_api->is_admin() || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ) { $page_builder_hooks = new WPML_TM_Page_Builders_Hooks( null, $this->sitepress ); $page_builder_hooks->init_hooks(); } $this->api_hooks(); add_filter( 'wpml_config_white_list_pages', array( $this, 'filter_wpml_config_white_list_pages' ) ); do_action( 'wpml_tm_loaded' ); return true; } public function api_hooks() { add_action( 'wpml_save_custom_field_translation_option', array( $this, 'wpml_save_custom_field_translation_option' ), 10, 2 ); } public function filter_wpml_config_white_list_pages( array $white_list_pages ) { $white_list_pages[] = WPML_TM_FOLDER . self::PAGE_SLUG_MANAGEMENT; $white_list_pages[] = WPML_TM_FOLDER . self::PAGE_SLUG_SETTINGS; return $white_list_pages; } public function maybe_show_wpml_not_installed_warning() { if ( ! ( isset( $_GET['page'] ) && 'sitepress-multilingual-cms/menu/languages.php' === $_GET['page'] ) ) { add_action( 'admin_notices', array( $this, '_wpml_not_installed_warning' ) ); } } private function translate_independently() { global $wpdb; if ( ( isset( $_GET['sm'] ) && 'basket' === $_GET['sm'] ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && 'icl_disconnect_posts' === $_POST['action'] ) ) { $translation_basket = new WPML_Translation_Basket( $wpdb ); $translate_independently = new WPML_TM_Translate_Independently( $this->tm_instance, $translation_basket, $this->sitepress ); $translate_independently->init(); } } function trashed_post_actions( $post_id ) { //Removes trashed post from the basket TranslationProxy_Basket::delete_item_from_basket( $post_id ); } function is_jobs_tab() { return $this->is_tm_page('jobs'); } function is_translators_tab() { return $this->is_tm_page('translators'); } function is_translation_services_tab() { return $this->is_tm_page('translation-services'); } function admin_enqueue_scripts() { if ( ! defined( 'DOING_AJAX' ) ) { wp_register_script( 'wpml-tm-progressbar', WPML_TM_URL . '/res/js/wpml-progressbar.js', array( 'jquery', 'jquery-ui-progressbar', 'backbone', ), WPML_TM_VERSION ); wp_register_script( 'wpml-tm-scripts', WPML_TM_URL . '/res/js/scripts.js', array( 'jquery', 'wpml-tm-progressbar', 'sitepress-scripts', ), WPML_TM_VERSION ); wp_enqueue_script( 'wpml-tm-scripts' ); wp_enqueue_style('wpml-tm-styles', WPML_TM_URL . '/res/css/style.css', array(), WPML_TM_VERSION); wp_enqueue_style('wpml-tm-queue', WPML_TM_URL . '/res/css/translations-queue.css', array(), WPML_TM_VERSION); if ( filter_input(INPUT_GET, 'page') === WPML_TM_FOLDER . '/menu/main.php' ) { if ( isset( $_GET[ 'sm' ] ) && ( $_GET[ 'sm' ] == 'translation-services' || $_GET[ 'sm' ] === 'translators' ) ) { wp_register_script( 'wpml-tm-translation-translators', WPML_TM_URL . '/dist/js/translators/app.js', array( 'jquery-ui-dialog' ), WPML_TM_VERSION ); wp_register_script( 'wpml-tm-translation-managers', WPML_TM_URL . '/res/js/translation-managers.js', array( 'wpml-tm-scripts', 'underscore' ), WPML_TM_VERSION ); wp_enqueue_script( 'wpml-select-2', ICL_PLUGIN_URL . '/lib/select2/select2.min.js', array( 'jquery' ), ICL_SITEPRESS_VERSION, true ); wp_enqueue_script( 'wpml-tm-translation-roles-select2', WPML_TM_URL . '/res/js/translation-roles-select2.js', array(), WPML_TM_VERSION ); wp_enqueue_script( 'wpml-tm-set-translation-roles', WPML_TM_URL . '/res/js/set-translation-role.js', array(), WPML_TM_VERSION ); $active_service = TranslationProxy::get_current_service(); $service_name = isset($active_service->name) ? $active_service->name : __('Translation Service', 'wpml-translation-management'); if (isset($active_service->url)) { $service_site_url = "{$service_name}"; } else { $service_site_url = $service_name; } $tm_ts_data = array( 'strings' => array( 'done' => __( 'Done', 'wpml-translation-management' ), 'header' => sprintf(__('%s requires additional data', 'wpml-translation-management'), $service_name), 'tip' => sprintf(__("You can find this at %s site", 'wpml-translation-management'), $service_site_url) ), ); $tm_tt_data = array( 'no_matches' => __( 'No matches', 'wpml-translation-management' ), 'found' => __( 'User found', 'wpml-translation-management' ) ); $tm_ts_data = apply_filters( 'translation_service_js_data', $tm_ts_data ); $tm_tm_data = array( 'restNonce' => wp_create_nonce( 'wp_rest' ), ); wp_localize_script( 'wpml-tm-translation-translators', 'tm_tt_data', $tm_tt_data ); wp_enqueue_script( 'wpml-tm-translation-translators' ); wp_localize_script( 'wpml-tm-translation-managers', 'tm_tm_data', $tm_tm_data ); wp_enqueue_script( 'wpml-tm-translation-managers' ); } wp_enqueue_script( 'wpml-tm-translation-proxy', WPML_TM_URL . '/res/js/translation-proxy.js', array( 'wpml-tm-scripts', 'jquery-ui-dialog' ), WPML_TM_VERSION ); } if ( WPML_TM_Page::is_settings() ) { WPML_Simple_Language_Selector::enqueue_scripts(); } wp_enqueue_style ( 'wp-jquery-ui-dialog' ); wp_enqueue_script( 'thickbox' ); do_action('wpml_tm_scripts_enqueued'); } } function admin_print_styles() { if ( ! defined( 'DOING_AJAX' ) ) { wp_enqueue_style( 'wpml-tm-styles', WPML_TM_URL . '/res/css/style.css', array( 'jquery-ui-theme', 'jquery-ui-theme' ), WPML_TM_VERSION ); wp_enqueue_style( 'wpml-tm-queue', WPML_TM_URL . '/res/css/translations-queue.css', array(), WPML_TM_VERSION ); wp_enqueue_style( 'wpml-tm-editor-css', WPML_TM_URL . '/res/css/translation-editor/translation-editor.css', array(), WPML_TM_VERSION ); //TODO Load only in translation editor && taxonomy transaltion wp_enqueue_style( 'wpml-dialog'); } } function translation_service_authentication() { $active_service = TranslationProxy::get_current_service(); $custom_fields = TranslationProxy::get_custom_fields( $active_service->id ); $auth_content[] = '
'; $auth_content[] = $authorization_message; $auth_content[] = '
'; $auth_content[] = '' . print_r( $error_data_message, true ) . ''; $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'); } /** * @param $custom_field_name * @param $translation_option */ public function wpml_save_custom_field_translation_option( $custom_field_name, $translation_option ) { $available_options = array( WPML_IGNORE_CUSTOM_FIELD, WPML_COPY_CUSTOM_FIELD, WPML_COPY_ONCE_CUSTOM_FIELD, WPML_TRANSLATE_CUSTOM_FIELD ); $translation_option = absint( $translation_option ); if ( ! in_array( $translation_option, $available_options ) ) { $translation_option = WPML_IGNORE_CUSTOM_FIELD; } $custom_field_name = sanitize_text_field( $custom_field_name ); $tm_settings = $this->sitepress->get_setting( 'translation-management', array() ); $tm_settings['custom_fields_translation'][ $custom_field_name ] = $translation_option; $this->sitepress->set_setting( 'translation-management', $tm_settings, true ); } private function add_custom_xml_config() { if ( class_exists( 'WPML_Custom_XML' ) ) { $factory = new WPML_TM_Custom_XML_Factory(); $hooks = new WPML_TM_Custom_XML_UI_Hooks( $factory->create_ui(), $factory->create_resources( $this->sitepress->get_wp_api() ), $factory->create_ajax() ); $hooks->init(); } } }