first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
/**
* Class WPML_TF_Translation_Queue_Hooks
*
* @author OnTheGoSystems
*/
class WPML_TF_Translation_Queue_Hooks implements IWPML_Action {
/** @var WPML_TF_Data_Object_Storage $feedback_storage */
private $feedback_storage;
public function __construct( WPML_TF_Data_Object_Storage $feedback_storage ) {
$this->feedback_storage = $feedback_storage;
}
public function add_hooks() {
add_filter( 'wpml_tm_allowed_translators_for_job', array( $this, 'add_reviewer_to_allowed_translators' ), 10, 2 );
}
public function add_reviewer_to_allowed_translators(
array $allowed_translators,
WPML_Translation_Job $translation_job
) {
$current_user_id = get_current_user_id();
if ( $translation_job->get_translator_id() !== $current_user_id ) {
$filter_args = array(
'reviewer_id' => $current_user_id,
);
$collection_filter = new WPML_TF_Feedback_Collection_Filter( $filter_args );
$feedback_collection = $this->feedback_storage->get_collection( $collection_filter );
foreach ( $feedback_collection as $feedback ) {
/** @var WPML_TF_Feedback $feedback */
if ( $feedback->get_job_id() === (int) $translation_job->get_id()
&& 'fixed' !== $feedback->get_status()
) {
$allowed_translators[] = $current_user_id;
break;
}
}
}
return $allowed_translators;
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Class WPML_TF_Translation_Service_Change_Hooks
*
* @author OnTheGoSystems
*/
class WPML_TF_Translation_Service_Change_Hooks implements IWPML_Action {
/** @var WPML_TF_Settings_Read $settings_read */
private $settings_read;
/** @var WPML_TF_Settings_Write $settings_write */
private $settings_write;
/** @var WPML_TF_TP_Ratings_Synchronize_Factory $tp_ratings_synchronize_factory */
private $tp_ratings_synchronize_factory;
public function __construct(
WPML_TF_Settings_Read $settings_read,
WPML_TF_Settings_Write $settings_write,
WPML_TF_TP_Ratings_Synchronize_Factory $tp_ratings_synchronize_factory
) {
$this->settings_read = $settings_read;
$this->settings_write = $settings_write;
$this->tp_ratings_synchronize_factory = $tp_ratings_synchronize_factory;
}
public function add_hooks() {
add_action(
'wpml_tm_before_set_translation_service',
array( $this, 'before_set_translation_service_callback' )
);
}
public function before_set_translation_service_callback( stdClass $service ) {
$this->cleanup_pending_ratings_queue();
$this->disable_tf_if_not_allowed_by_ts( $service );
}
private function cleanup_pending_ratings_queue() {
$tp_ratings_sync = $this->tp_ratings_synchronize_factory->create();
$tp_ratings_sync->run( true );
}
private function disable_tf_if_not_allowed_by_ts( stdClass $service ) {
if ( isset( $service->translation_feedback ) && ! $service->translation_feedback ) {
/** @var WPML_TF_Settings $settings */
$settings = $this->settings_read->get( 'WPML_TF_Settings' );
$settings->set_enabled( false );
$this->settings_write->save( $settings );
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Class WPML_TF_XML_RPC_Hooks
*
* @author OnTheGoSystems
*/
class WPML_TF_XML_RPC_Hooks implements IWPML_Action {
/** @var WPML_TF_XML_RPC_Feedback_Update_Factory $xml_rpc_feedback_update_factory */
private $xml_rpc_feedback_update_factory;
/** @var WPML_WP_API $wp_api */
private $wp_api;
public function __construct(
WPML_TF_XML_RPC_Feedback_Update_Factory $xml_rpc_feedback_update_factory,
WPML_WP_API $wp_api
) {
$this->xml_rpc_feedback_update_factory = $xml_rpc_feedback_update_factory;
$this->wp_api = $wp_api;
}
public function add_hooks() {
if ( $this->wp_api->constant( 'XMLRPC_REQUEST' ) ) {
add_filter( 'xmlrpc_methods', array( $this, 'add_tf_xmlrpc_methods' ) );
}
}
/**
* @param array $methods
*
* @return array
*/
public function add_tf_xmlrpc_methods( $methods ) {
$methods['translationproxy.update_feedback_status'] = array( $this, 'update_feedback_status' );
return $methods;
}
/** @param array $args */
public function update_feedback_status( array $args ) {
$xml_rpc_feedback_update = $this->xml_rpc_feedback_update_factory->create();
$xml_rpc_feedback_update->set_status( $args );
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Class WPML_TM_TF_Feedback_List_Hooks
*
* @author OnTheGoSystems
*/
class WPML_TM_TF_Feedback_List_Hooks implements IWPML_Action {
public function add_hooks() {
add_filter( 'wpml_use_tm_editor', array( $this, 'maybe_force_to_use_translation_editor' ) );
}
/**
* @param int|bool $use_translation_editor
*
* @return int|bool
*/
public function maybe_force_to_use_translation_editor( $use_translation_editor ) {
if ( ! current_user_can( 'edit_others_posts' ) ) {
$use_translation_editor = true;
}
return $use_translation_editor;
}
}