first commit
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\TM\Editor;
|
||||
|
||||
class ClassicEditorActions {
|
||||
|
||||
public function addHooks() {
|
||||
add_action( 'wp_ajax_wpml_save_job_ajax', [ $this, 'saveJob' ] );
|
||||
}
|
||||
|
||||
public function saveJob() {
|
||||
if ( ! wpml_is_action_authenticated( 'wpml_save_job' ) ) {
|
||||
wp_send_json_error( 'Permission denied.' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
$post_data = \WPML_TM_Post_Data::strip_slashes_for_single_quote( $_POST['data'] );
|
||||
parse_str( $post_data, $data );
|
||||
|
||||
/**
|
||||
* It filters job data
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
$data = apply_filters( 'wpml_translation_editor_save_job_data', $data );
|
||||
|
||||
$job = \WPML\Container\make( \WPML_TM_Editor_Job_Save::class );
|
||||
|
||||
$job_details = [
|
||||
'job_type' => $data['job_post_type'],
|
||||
'job_id' => $data['job_post_id'],
|
||||
'target' => $data['target_lang'],
|
||||
'translation_complete' => isset( $data['complete'] ) ? true : false,
|
||||
];
|
||||
$job = apply_filters( 'wpml-translation-editor-fetch-job', $job, $job_details );
|
||||
|
||||
$ajax_response = $job->save( $data );
|
||||
$ajax_response->send_json();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_Editors {
|
||||
const ATE = 'ate';
|
||||
const WPML = 'wpml';
|
||||
const WP = 'wp';
|
||||
const NONE = 'none';
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class WPML_TM_Old_Jobs_Editor {
|
||||
|
||||
const OPTION_NAME = 'wpml-old-jobs-editor';
|
||||
|
||||
/** @var wpdb */
|
||||
private $wpdb;
|
||||
|
||||
/** @var WPML_Translation_Job_Factory */
|
||||
private $job_factory;
|
||||
|
||||
public function __construct( WPML_Translation_Job_Factory $job_factory ) {
|
||||
global $wpdb;
|
||||
$this->wpdb = $wpdb;
|
||||
|
||||
$this->job_factory = $job_factory;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $job_id
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function get( $job_id ) {
|
||||
$current_editor = $this->get_current_editor( $job_id );
|
||||
|
||||
if ( WPML_TM_Editors::NONE === $current_editor || WPML_TM_Editors::ATE === $current_editor ) {
|
||||
return $current_editor;
|
||||
} else {
|
||||
return get_option( self::OPTION_NAME, null );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $job_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldStickToWPMLEditor( $job_id ) {
|
||||
$sql = "
|
||||
SELECT job.editor
|
||||
FROM {$this->wpdb->prefix}icl_translate_job job
|
||||
WHERE job.job_id < %d AND job.rid = (
|
||||
SELECT rid FROM {$this->wpdb->prefix}icl_translate_job WHERE job_id = %s
|
||||
)
|
||||
ORDER BY job.job_id DESC
|
||||
";
|
||||
|
||||
$previousJobEditor = $this->wpdb->get_var( $this->wpdb->prepare( $sql, $job_id, $job_id ) );
|
||||
|
||||
return $previousJobEditor === WPML_TM_Editors::WPML && get_option( self::OPTION_NAME, null ) === WPML_TM_Editors::WPML;
|
||||
}
|
||||
|
||||
public function set( $job_id, $editor ) {
|
||||
$this->job_factory->update_job_data( $job_id, array( 'editor' => $editor ) );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $job_id
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
private function get_current_editor( $job_id ) {
|
||||
$sql = "SELECT editor FROM {$this->wpdb->prefix}icl_translate_job WHERE job_id = %d";
|
||||
|
||||
return $this->wpdb->get_var( $this->wpdb->prepare( $sql, $job_id ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user