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/' ) ); $wp_roles = wp_roles(); $manager_records = new WPML_Translation_Manager_Records( $wpdb, new WPML_WP_User_Query_Factory(), $wp_roles ); $translator_records = new WPML_Translator_Records( $wpdb, new WPML_WP_User_Query_Factory(), $wp_roles ); $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 ) ); } public 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' ) ); if ( $this->notices_added_because_wpml_is_inactive_or_incomplete() ) { return false; } $this->handle_get_requests(); $this->tm_loader->load_pro_translation( $wpml_wp_api ); if ( $wpml_wp_api->is_admin() ) { $this->add_pre_tm_init_admin_hooks(); do_action( 'wpml_tm_init' ); $this->add_post_tm_init_admin_hooks( $pagenow ); } $this->add_page_builders_hooks( $wpml_wp_api ); $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 ); } /** * @return bool `true` if notices were added */ private function notices_added_because_wpml_is_inactive_or_incomplete() { $wpml_wp_api = $this->sitepress->get_wp_api(); if ( ! $wpml_wp_api->constant( 'ICL_SITEPRESS_VERSION' ) || $wpml_wp_api->constant( 'ICL_PLUGIN_INACTIVE' ) ) { if ( ! function_exists( 'is_multisite' ) || ! is_multisite() ) { add_action( 'admin_notices', array( $this, '_no_wpml_warning' ) ); } return true; } elseif ( ! $this->sitepress->get_setting( 'setup_complete' ) ) { $this->maybe_show_wpml_not_installed_warning(); return true; } return false; } 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' ) ); } } 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', '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 ); if ( $this->sitepress->get_wp_api()->is_translation_queue_page() ) { 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 . '/dist/js/translation-managers/app.js', array( 'jquery-ui-dialog' ), 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( 'underscore' ), 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 ); if ( $this->sitepress->get_wp_api()->is_translation_queue_page() ) { 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 ); wp_enqueue_style( OTGS_Assets_Handles::POPOVER_TOOLTIP ); wp_enqueue_script( OTGS_Assets_Handles::POPOVER_TOOLTIP ); } // TODO Load only in translation editor && taxonomy transaltion wp_enqueue_style( 'wpml-dialog' ); wp_enqueue_style( OTGS_Assets_Handles::SWITCHER ); } } function translation_service_js_data( $data ) { $data['nonce']['translation_service_authentication'] = wp_create_nonce( 'translation_service_authentication' ); $data['nonce']['translation_service_toggle'] = wp_create_nonce( 'translation_service_toggle' ); return $data; } function _no_wpml_warning() { ?>

WPML in order to work.', 'wpml-translation-management' ), 'https://wpml.org/' ); ?>

WPML versions prior 2.0.5.', 'wpml-translation-management' ), 'https://wpml.org/' ); ?>

wpml_tm_menus_management->display_main( $this->dashboard_screen_options ); } /** * Sets up the menu items for non-admin translators pointing at the TM * and ST translators interfaces * * @param string $menu_id */ public function translators_menu( $menu_id ) { if ( 'WPML' !== $menu_id ) { return; } $wp_api = $this->sitepress->get_wp_api(); $is_translation_manager = $wp_api->current_user_can( WPML_Manage_Translations_Role::CAPABILITY ); $can_manage_translation_management = $is_translation_manager || $wp_api->current_user_can( 'wpml_manage_translation_management' ); $has_language_pairs = (bool) $this->tm_instance->get_current_translator()->language_pairs === true; $menu = array(); $menu['order'] = 400; $menu['page_title'] = __( 'Translations', 'wpml-translation-management' ); $menu['menu_title'] = __( 'Translations', 'wpml-translation-management' ); $menu['menu_slug'] = WPML_TM_FOLDER . '/menu/translations-queue.php'; $menu['function'] = array( $this, 'translation_queue_page' ); $menu['icon_url'] = ICL_PLUGIN_URL . '/res/img/icon16.png'; if ( $can_manage_translation_management ) { $menu['capability'] = $is_translation_manager ? WPML_Manage_Translations_Role::CAPABILITY : 'wpml_manage_translation_management'; do_action( 'wpml_admin_menu_register_item', $menu ); } else { $menu['capability'] = $has_language_pairs ? WPML_Translator_Role::CAPABILITY : ''; $menu = apply_filters( 'wpml_menu_page', $menu ); if ( $menu['capability'] ) { add_menu_page( $menu['page_title'], $menu['menu_title'], $menu['capability'], $menu['menu_slug'], $menu['function'], $menu['icon_url'] ); } } } /** * Renders the TM queue * * @used-by \WPML_Translation_Management::menu */ function translation_queue_page() { if ( true !== apply_filters( 'wpml_tm_lock_ui', false ) && $this->is_the_main_request() && ! AteApiLock::isLocked() ) { $this->tm_queue->display(); } } /** * @param string $menu_id */ public function settings_menu( $menu_id ) { if ( 'WPML' !== $menu_id ) { return; } $menu_label = __( 'Settings', 'wpml-translation-management' ); $is_translation_manager = current_user_can( WPML_Manage_Translations_Role::CAPABILITY ); $menu = array(); $menu['order'] = 9900; // see WPML_Main_Admin_Menu::MENU_ORDER_SETTINGS $menu['page_title'] = $menu_label; $menu['menu_title'] = $menu_label; $menu['capability'] = $is_translation_manager ? WPML_Manage_Translations_Role::CAPABILITY : 'wpml_manage_translation_management'; $menu['menu_slug'] = WPML_TM_FOLDER . self::PAGE_SLUG_SETTINGS; $menu['function'] = array( $this, 'settings_page' ); do_action( 'wpml_admin_menu_register_item', $menu ); } public function settings_page() { $settings_page = new WPML_TM_Menus_Settings(); $settings_page->init(); $settings_page->display_main(); } private function is_the_main_request() { return ! isset( $_SERVER['HTTP_ACCEPT'] ) || false !== strpos( $_SERVER['HTTP_ACCEPT'], 'text/html' ); } function dismiss_icl_side_by_site() { global $iclTranslationManagement; $iclTranslationManagement->settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL; $iclTranslationManagement->save_settings(); exit; } function plugin_action_links( $links, $file ) { $this_plugin = basename( WPML_TM_PATH ) . '/plugin.php'; if ( $file == $this_plugin ) { $links[] = '' . __( 'Configure', 'wpml-translation-management' ) . ''; } return $links; } // Localization function plugin_localization() { load_plugin_textdomain( 'wpml-translation-management', false, WPML_TM_FOLDER . '/locale' ); } function _icl_tm_toggle_promo() { global $sitepress; $value = filter_input( INPUT_POST, 'value', FILTER_VALIDATE_INT ); $iclsettings['dashboard']['hide_icl_promo'] = (int) $value; $sitepress->save_settings( $iclsettings ); exit; } /** * @return array */ public function get_active_services() { $cache_key = 'active_services'; $cache_group = ''; $found = false; $result = wp_cache_get( $cache_key, $cache_group, false, $found ); if ( $found ) { return $result; } $active_services = array( 'local' => array() ); $current_service = TranslationProxy::get_current_service(); if ( ! is_wp_error( $current_service ) ) { if ( $current_service ) { $active_services[ $current_service->name ] = $current_service; } wp_cache_set( $cache_key, $active_services, $cache_group ); } return $active_services; } public function automatic_service_selection_action() { $this->automatic_service_selection(); } /** * Handles the display of notices in the TM translators tab */ public function handle_notices_action() { if ( $this->sitepress->get_wp_api()->is_back_end() && $this->sitepress->get_wp_api()->is_tm_page() ) { $lang_status = $this->wpml_tp_translator->get_icl_translator_status(); if ( $lang_status ) { $this->sitepress->save_settings( $lang_status ); } $this->service_authentication_notice(); } } public function basket_extra_fields_refresh() { echo TranslationProxy_Basket::get_basket_extra_fields_inputs(); die(); } /** * If user display Translation Dashboard or Translators * * @return boolean */ function automatic_service_selection_pages() { return is_admin() && isset( $_GET['page'] ) && $_GET['page'] == WPML_TM_FOLDER . '/menu/main.php' && ( ! isset( $_GET['sm'] ) || $_GET['sm'] == 'translation-services' || $_GET['sm'] == 'dashboard' ); } public function add_com_log_link() { WPML_TranslationProxy_Com_Log::add_com_log_link(); } public function service_activation_incomplete() { return $this->has_active_service() && ( $this->service_requires_authentication() || $this->service_requires_translators() ); } /** * If a service is active (even if not authenticated) it returns true. * * @return bool */ public function has_active_service() { return TranslationProxy::get_current_service() !== false; } private function service_requires_translators() { $result = false; $service_has_translators = TranslationProxy::translator_selection_available(); if ( $service_has_translators ) { $result = ! $this->service_has_accepted_translators(); } return $result; } private function service_requires_authentication() { $result = false; $service_has_translators = TranslationProxy::translator_selection_available(); if ( ! $service_has_translators ) { $has_custom_fields = TranslationProxy::has_custom_fields(); $custom_fields_data = TranslationProxy::get_custom_fields_data(); $result = $has_custom_fields && ! $custom_fields_data; } return $result; } private function service_has_accepted_translators() { $result = false; $icl_data = $this->wpml_tp_translator->get_icl_translator_status(); if ( isset( $icl_data['icl_lang_status'] ) && is_array( $icl_data['icl_lang_status'] ) ) { foreach ( $icl_data['icl_lang_status'] as $translator ) { if ( isset( $translator['contract_id'] ) && $translator['contract_id'] != 0 ) { $result = true; break; } } } return $result; } private function service_authentication_notice() { $message_id = 'current_service_authentication_required'; if ( current_user_can( WPML_Manage_Translations_Role::CAPABILITY ) && $this->service_activation_incomplete() ) { $current_service_name = TranslationProxy::get_current_service_name(); if ( ! $this->is_translation_services_tab() ) { $service_tab_name = esc_html__( 'Translation Services Tab', 'wpml-translation-management' ); $translator_tab_name = esc_html__( 'Translators Tab', 'wpml-translation-management' ); $link_pattern = '%2$s'; $service_pattern = '%1$s'; $services_base_url = admin_url( 'admin.php?page=' . WPML_TM_FOLDER . '/menu/main.php' ); $translation_services_url = add_query_arg( array( 'sm' => 'translation-services' ), $services_base_url ); $translators_url = add_query_arg( array( 'sm' => 'translators' ), $services_base_url ); $translation_services_link = sprintf( $link_pattern, $translation_services_url, $service_tab_name ); $translators_link = sprintf( $link_pattern, $translators_url, $translator_tab_name ); $service_authentication_link = sprintf( $service_pattern, esc_html__( 'Authenticate', 'wpml-translation-management' ) ); $service_deactivation_link = sprintf( $service_pattern, esc_html__( 'Deactivate', 'wpml-translation-management' ) ); if ( $this->service_requires_authentication() ) { $notification_message = ''; $notification_message .= sprintf( __( 'One more step before you can use %s', 'wpml-translation-management' ), $current_service_name ); $notification_message .= ''; $notification_message .= ''; } else { if ( $this->service_requires_translators() ) { $notification_message = __( 'You have selected a translation service which requires translators.', 'wpml-translation-management' ); $service_authentication_link = '' . __( 'Add a Translator', 'wpml-translation-management' ) . ' »'; $notification_message .= '