first commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_TS_Instructions_Hooks_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader {
|
||||
/**
|
||||
* @return WPML_TM_TS_Instructions_Hooks
|
||||
*/
|
||||
public function create() {
|
||||
return new WPML_TM_TS_Instructions_Hooks( $this->create_notice() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WPML_TM_TS_Instructions_Notice
|
||||
*/
|
||||
private function create_notice() {
|
||||
$template_service = new WPML_Twig_Template_Loader( array( WPML_TM_PATH . '/templates/notices/translation-service-instruction/' ) );
|
||||
|
||||
return new WPML_TM_TS_Instructions_Notice( wpml_get_admin_notices(), $template_service->get_template() );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_TS_Instructions_Hooks implements IWPML_Action {
|
||||
/** @var WPML_TM_TS_Instructions_Notice */
|
||||
private $notice;
|
||||
|
||||
/**
|
||||
* WPML_TM_TS_Instructions_Hooks constructor.
|
||||
*
|
||||
* @param WPML_TM_TS_Instructions_Notice $notice
|
||||
*/
|
||||
public function __construct( WPML_TM_TS_Instructions_Notice $notice ) {
|
||||
$this->notice = $notice;
|
||||
}
|
||||
|
||||
|
||||
public function add_hooks() {
|
||||
add_action( 'wpml_tp_project_created', array( $this, 'display_message' ), 10, 3 );
|
||||
add_action( 'init', array( $this, 'add_hooks_on_init' ), 10, 0 );
|
||||
|
||||
add_action( 'wpml_tp_service_de_authorized', array( $this, 'dismiss' ), 10, 0 );
|
||||
add_action( 'wpml_tp_service_dectivated', array( $this, 'dismiss' ), 10, 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $service
|
||||
* @param stdClass $project
|
||||
* @param array $icl_translation_projects
|
||||
*/
|
||||
public function display_message( $service, $project, array $icl_translation_projects ) {
|
||||
$is_first_project_ever = empty( $icl_translation_projects );
|
||||
|
||||
if ( $is_first_project_ever || ! $this->has_completed_remote_jobs() ) {
|
||||
$this->notice->add_notice( $service );
|
||||
}
|
||||
}
|
||||
|
||||
public function add_hooks_on_init() {
|
||||
if ( $this->notice->exists() ) {
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 10, 0 );
|
||||
add_action( 'wp_ajax_translation_service_instruction_dismiss', array( $this, 'dismiss' ), 10, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
public function enqueue_scripts() {
|
||||
$handle = 'wpml-tm-translation-service-instruction';
|
||||
|
||||
wp_register_script(
|
||||
$handle,
|
||||
WPML_TM_URL . '/dist/js/translationServiceInstruction/app.js',
|
||||
array(),
|
||||
WPML_TM_VERSION
|
||||
);
|
||||
|
||||
$data = array(
|
||||
'restUrl' => untrailingslashit( rest_url() ),
|
||||
'restNonce' => wp_create_nonce( 'wp_rest' ),
|
||||
'ate' => null,
|
||||
'currentUser' => wp_get_current_user(),
|
||||
);
|
||||
|
||||
wp_localize_script( $handle, 'WPML_TM_SETTINGS', $data );
|
||||
|
||||
wp_enqueue_script( $handle );
|
||||
}
|
||||
|
||||
public function dismiss() {
|
||||
$this->notice->remove_notice();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function has_completed_remote_jobs() {
|
||||
$search_params = new WPML_TM_Jobs_Search_Params();
|
||||
$search_params->set_status( array( ICL_TM_COMPLETE ) );
|
||||
$search_params->set_scope( WPML_TM_Jobs_Search_Params::SCOPE_REMOTE );
|
||||
|
||||
return wpml_tm_get_jobs_repository()->get_count( $search_params ) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_TS_Instructions_Notice {
|
||||
const NOTICE_ID = 'translation-service-instructions';
|
||||
const NOTICE_GROUP_ID = 'translation-service-instructions';
|
||||
const TEMPLATE = 'translation-service-instructions.twig';
|
||||
|
||||
/** @var WPML_Notices */
|
||||
private $admin_notices;
|
||||
|
||||
/** @var IWPML_Template_Service */
|
||||
private $template_service;
|
||||
|
||||
public function __construct( WPML_Notices $admin_notices, IWPML_Template_Service $template_service ) {
|
||||
$this->admin_notices = $admin_notices;
|
||||
$this->template_service = $template_service;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $service
|
||||
*/
|
||||
public function add_notice( $service ) {
|
||||
$notice = $this->admin_notices->create_notice(
|
||||
self::NOTICE_ID,
|
||||
$this->get_notice_content( $service ),
|
||||
self::NOTICE_GROUP_ID
|
||||
);
|
||||
$notice->add_display_callback( array( 'WPML_TM_Page', 'is_tm_dashboard' ) );
|
||||
$notice->set_text_only( true );
|
||||
$this->admin_notices->add_notice( $notice );
|
||||
}
|
||||
|
||||
public function remove_notice() {
|
||||
$this->admin_notices->remove_notice( self::NOTICE_GROUP_ID, self::NOTICE_ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function exists() {
|
||||
return ( WPML_TM_Page::is_dashboard() || wpml_is_ajax() ) &&
|
||||
(bool) $this->admin_notices->get_notice( self::NOTICE_ID, self::NOTICE_GROUP_ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $service
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_notice_content( $service ) {
|
||||
$model = $this->get_model( $service );
|
||||
|
||||
return $this->template_service->show( $model, self::TEMPLATE );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param stdClass $service
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function get_model( $service ) {
|
||||
return array(
|
||||
'strings' => array(
|
||||
'title' => sprintf(
|
||||
__( 'How to work correctly with %s', 'wpml-translation-management' ),
|
||||
$service->name
|
||||
),
|
||||
'description' => sprintf(
|
||||
__(
|
||||
"Congratulations for choosing %s to translate your site's content. To avoid high costs and wasted time, please watch our short video.",
|
||||
'wpml-translation-management'
|
||||
),
|
||||
$service->name
|
||||
),
|
||||
'need_help' => __( 'Need help? See ', 'wpml-translation-management' ),
|
||||
'help_caption' => __(
|
||||
'how to translate different parts of the site.',
|
||||
'wpml-translation-management'
|
||||
),
|
||||
'this_stuff_is_important' => __( 'This stuff is actually important. Please follow the video to send a test translation. Then, you can dismiss this message. Thank you!', 'wpml-translation-management' ),
|
||||
'my_test_translation_went_fine' => __( 'My test translation went fine.', 'wpml-translation-management' ),
|
||||
'dismiss' => __( 'Dismiss this message.', 'wpml-translation-management' ),
|
||||
),
|
||||
'image_url' => WPML_TM_URL . '/res/img/ts-instruction-video.png',
|
||||
'help_link' => 'https://wpml.org/documentation/translating-your-contents/professional-translation-via-wpml/doing-test-translation/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmltm',
|
||||
'video_link' => 'https://wpml.org/documentation/translating-your-contents/professional-translation-via-wpml/doing-test-translation/?utm_source=plugin&utm_medium=gui&utm_campaign=wpmltm',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user