wpdb = $wpdb;
$this->sitepress = $sitepress;
$this->tm_instance = $tm_instance;
$this->tp_client = $tp_client;
$this->active_service = TranslationProxy::get_current_service();
$this->service_name = TranslationProxy::get_current_service_name();
}
public function build_content_translators() {
global $current_user;
$selected_translator = $this->tm_instance->get_selected_translator();
$active_service = $this->active_service;
$service_name = $this->service_name;
if ( current_user_can( 'list_users' ) || current_user_can( 'manage_options' ) ) {
add_filter( 'icl_translation_services_button', array( $this, 'icl_local_add_translator_button' ) );
add_filter( 'icl_translation_services_button', array( 'TranslationProxy', 'get_current_service_info' ) );
$only_local_translators = ( $active_service && (
!TranslationProxy_Service::is_authenticated( $active_service )
|| ( $active_service && !$active_service->has_translator_selection )
) );
?>
translation_service_has_translators( $active_service ) ) {
if ( $only_local_translators ) {
$translation_dashboard_url = "admin.php?page=" . WPML_TM_FOLDER . "/menu/main.php&sm=dashboard";
$translation_dashboard_link = sprintf( '
' . __( 'Translation Dashboard',
'wpml-translation-management' ) . ' ',
$translation_dashboard_url );
$service_html = '
';
$service_html .= sprintf( __( 'This section is for selecting WPML (local) translators only. If you wish to use %s, please go to %s.' ),
'' . $service_name . ' ',
$translation_dashboard_link );
$service_html .= '
';
} else {
$service_html = TranslationProxy::get_service_translators_info();
}
ICL_AdminNotifier::display_instant_message( $service_html );
}
if ( $selected_translator && $selected_translator->ID ) {
// Edit form
echo '
' . __( 'Edit translator', 'wpml-translation-management' ) . ' ';
echo '
' . "\r\n";
} else {
// Services add translator form
// Services hook
$services_buttons = apply_filters( 'icl_translation_services_button', array() );
if ( !empty( $services_buttons ) ) {
if ( !$only_local_translators ) {
$translators = wpml_tm_load_blog_translators();
$add_translator_class = $translators->get_blog_translators() ? 'button-secondary alignright' : 'button-primary no-translators';
// Toggle button
echo '
' . "\r\n";
}
// Toggle div start
$form_classes = array( 'translator-form-wrapper' );
if ( !isset( $_GET[ 'service' ] ) && !$only_local_translators ) {
$form_classes[ ] = 'hidden';
}
echo '
' . "\r\n";
} else {
_e( 'No add translator interface available', 'wpml-translation-management' );
}
}
// Translators lists
// Local translators
$blog_users_t = TranslationManagement::get_blog_translators();
if ( TranslationProxy::translator_selection_available() ) {
$other_service_translators = TranslationProxy_Translator::translation_service_translators_list();
}
?>
translators_head_foot_row() ?>
translators_head_foot_row() ?>
ID == $bu->ID ) {
$edit_link = 'profile.php';
} else {
$edit_link = esc_url( add_query_arg( 'wp_http_referer',
urlencode( esc_url( stripslashes( $_SERVER[ 'REQUEST_URI' ] ) ) ),
"user-edit.php?user_id=$bu->ID" ) );
}
$language_pairs = get_user_meta( $bu->ID, $this->wpdb->prefix . 'language_pairs', true );
?>
user_login; ?>
get_translation_languages();
?>
$lp ): ?>
$null ) {
if ( isset( $langs[ $to ] ) ) {
$tos[ ] = $langs[ $to ][ 'display_name' ];
} elseif ( $to ) {
$_lang = $this->sitepress->get_language_details( $to );
if ( $_lang ) {
$tos[ ] = '' . $_lang[ 'display_name' ] . __( ' (inactive)',
'wpml-translation-management' ) . ' ';
}
}
}
?>
Local
>
get_translation_languages();
if ( is_array( $language_pairs ) ) {
?>
$lp ) {
$from = isset( $langs[ $from ][ 'display_name' ] )
? $langs[ $from ][ 'display_name' ] : $from;
$tos = array();
foreach ( $lp as $to ) {
$tos[ ] = isset( $langs[ $to ][ 'display_name' ] )
? $langs[ $to ][ 'display_name' ] : $to;
}
?>
icl_local_edit_translator_form();
if ( isset( $buttons[ 'local' ][ 'content' ] ) && $buttons[ 'local' ][ 'content' ] ) {
$buttons[ 'local' ][ 'content' ] = '' . $buttons[ 'local' ][ 'content' ] . '
';
}
return $buttons;
}
public function build_website_details_refresh() {
if ( $this->translation_service_has_translators() ) {
echo $this->flush_website_details_cache_button();
}
}
private function translators_head_foot_row() {
?>
' . __( 'Refresh Available Services List', 'wpml-translation-management' ) . ' » ' . "\r\n";
}
/**
* Add/edit local translator form
*
* @param string $action add|edit
* @param int|object $selected_translator
*
* @return mixed
*/
private function icl_local_edit_translator_form( $action = 'add', $selected_translator = 0 ) {
$blog_users_nt = $this->tm_instance->get_blog_not_translators();
$output = '';
$return[ 'name' ] = __( 'Local', 'wpml-translation-management' );
$return[ 'description' ] = __( 'Your own translators', 'wpml-translation-management' );
if ( $action === 'add' && empty( $blog_users_nt ) ) {
$alert_message = '';
$alert_message .= __( 'All WordPress users are already translators. To add more translators, first create accounts for them.',
'wpml-translation-management' );
$alert_message .= '
';
$return[ 'content' ] = '';
$return[ 'messages' ] = ICL_AdminNotifier::display_instant_message( $alert_message,
'information',
false,
true );
return $return;
}
$output .= '
' . __( 'Select user.', 'wpml-translation-management' ) . '
' . wp_nonce_field( $action . '_translator',
$action . '_translator_nonce',
true,
false );
if ( !$selected_translator ):
$output .= ' ';
$output .= ' ';
$output .= ' ';
$output .= ' ';
$output .= '' . __( 'To add translators, they must first have accounts in WordPress. Translators can have any editing privileges, including subscriber.' , 'wpml-translation-management' ) . '
';
else:
$output .=
''
. sprintf( __( 'Editing language pairs for %s ', 'wpml-translation-management' ),
esc_html( $selected_translator->display_name ) . ' (' . $selected_translator->user_login . ')' )
. ' ';
$output .= ' ';
endif;
if ( $selected_translator ) {
$output .= '
get_translation_languages();
foreach ( $languages as $from_lang ):
$lang_from_selected = false;
if ( $selected_translator && 0 < @count( $selected_translator->language_pairs[ $from_lang[ 'code' ] ] ) ):
$lang_from_selected = true;
endif;
$output .= '
';
$output .= '
language_pairs[ $from_lang[ 'code' ] ] ) ):
$output .= ' style="display:block"';
endif;
$output .= '>
' . __( 'to', 'wpml-translation-management' ) . '
';
endforeach;
$output .= '';
$output .= '
';
}
$return[ 'content' ] = $output;
return ( $action == 'edit' ) ? $output : $return;
}
private function get_translation_languages(){
return $languages = apply_filters( 'wpml_tm_allowed_source_languages', $this->sitepress->get_active_languages() );
}
private function flush_website_details_cache_button() {
$ts_name = TranslationProxy::get_current_service_name();
$link_text = sprintf( __( 'Refresh Translators data from %s', 'wpml-translation-management' ), $ts_name );
$nonce = wp_create_nonce( 'wpml-flush-website-details-cache' );
return '' . $link_text . ' » ' . PHP_EOL;
}
/**
* @param $active_service
*
* @return bool
* @throws \InvalidArgumentException
*/
public function translation_service_has_translators( $active_service = null ) {
if ( ! $active_service && ! $this->active_service instanceof WP_Error ) {
$active_service = $this->active_service;
}
return $active_service && TranslationProxy::translator_selection_available();
}
/**
* If the given $source is an error type, it will display an instant message
*
* @param WP_Error|WPMLTranslationProxyApiException|Exception $source
*/
private function display_error( $source ) {
$error = false;
if ( $source instanceof Exception) {
$error = array(
'message' => $source->getMessage(),
'code' => $source->getCode(),
);
} elseif ( is_wp_error( $source ) ) {
$error = array(
'message' => $source->get_error_message(),
'data' => $source->get_error_data(),
'code' => $source->get_error_code(),
);
}
if ( $error ) {
$message = '';
$message .= '';
if ( isset( $error[ 'code' ] ) && $error[ 'code' ] ) {
$message .= '#' . $error[ 'code' ] . ' ';
}
$message .= $error[ 'message' ];
$message .= ' ';
if ( isset( $error[ 'data' ] ) ) {
foreach ( $error[ 'data' ] as $data_key => $data_item ) {
if ( $data_key == 'details' ) {
$message .= ' Details: ' . $data_item;
} elseif ( $data_key == 'service_id' ) {
$message .= ' Service ID: ' . $data_item;
} else {
$message .= '' . print_r( $data_item, true ) . ' ';
}
}
}
ICL_AdminNotifier::displayInstantMessage( $message, 'error' );
}
return $error;
}
}