sitepress = $sitepress;
$this->editor = $editor;
}
public function init_hooks() {
add_action( 'current_screen', array( $this, 'load' ) );
}
public function load() {
if ( $this->must_open_the_editor() ) {
$response = $this->editor->open( $_GET );
if ( Relation::propEq( 'editor', WPML_TM_Editors::ATE, $response ) ) {
wp_safe_redirect( Obj::prop('url', $response), 302, 'WPML' );
return;
} elseif (Relation::propEq( 'editor', WPML_TM_Editors::WPML, $response )) {
$this->openClassicTranslationEditor( Obj::prop('jobObject', $response) );
}
}
}
private function openClassicTranslationEditor( $job_object ) {
global $wpdb;
$this->must_render_the_editor = true;
$this->translation_editor = new WPML_Translation_Editor_UI(
$wpdb,
$this->sitepress,
wpml_load_core_tm(),
$job_object,
new WPML_TM_Job_Action_Factory( wpml_tm_load_job_factory() ),
new WPML_TM_Job_Layout( $wpdb, $this->sitepress->get_wp_api() )
);
}
public function display() {
if ( $this->must_render_the_editor ) {
$this->translation_editor->render();
return;
}
?>
0 || Obj::prop( 'trid', $_GET ) > 0;
}
/**
* @todo this method should be removed but we have to check firts the logic in NextTranslationLink
* @return array
*/
public static function get_cookie_filters() {
$filters = [];
if ( isset( $_COOKIE['wp-translation_ujobs_filter'] ) ) {
parse_str( $_COOKIE['wp-translation_ujobs_filter'], $filters );
$filters = filter_var_array(
$filters,
[
'type' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'from' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'to' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,
'status' => FILTER_SANITIZE_NUMBER_INT,
]
);
$isTypeValid = Logic::anyPass(
[
Str::startsWith( 'package_' ),
Str::includes( 'st-batch_strings' ),
pipe( Str::replace( 'post_', '' ), Lst::includes( Fns::__, PostTypes::getTranslatable() ) ),
]
);
$activeLanguageCodes = Obj::keys( Languages::getActive() );
if (
$filters['from'] && ! Lst::includes( $filters['from'], $activeLanguageCodes ) ||
$filters['to'] && ! Lst::includes( $filters['to'], $activeLanguageCodes ) ||
( $filters['type'] && ! $isTypeValid( $filters['type'] ) )
) {
$filters = [];
}
}
return $filters;
}
}