public static function is_authenticated($service)
 {
     //for services that do not require authentication return true by default
     if (!TranslationProxy::service_requires_authentication($service)) {
         return true;
     }
     return isset($service->custom_fields_data) && $service->custom_fields_data ? true : false;
 }
 /**
  *
  * @return bool
  */
 public static function is_current_service_active_and_authenticated()
 {
     $active_service = self::get_current_service();
     return $active_service && (!TranslationProxy::service_requires_authentication() || TranslationProxy_Service::is_authenticated($active_service));
 }
 function translation_service_authentication()
 {
     $active_service = TranslationProxy::get_current_service();
     $custom_fields = TranslationProxy::get_custom_fields($active_service->id);
     $auth_content[] = '<div class="js-service-authentication">';
     $auth_content[] = '<ul>';
     if (TranslationProxy::service_requires_authentication($active_service)) {
         $auth_content[] = '<input type="hidden" name="service_id" id="service_id" value="' . $active_service->id . '" />';
         $custom_fields_data = TranslationProxy::get_custom_fields_data();
         if (!$custom_fields_data) {
             $auth_content[] = '<li>';
             $auth_content[] = '<p>';
             $auth_content[] = sprintf(__('%s is active, but requires authentication data.', 'wpml-translation-management'), $active_service->name);
             $auth_content[] = '</p>';
             $auth_content[] = '</li>';
             $auth_content[] = '<li>';
             $auth_content[] = '<strong>';
             $auth_content[] = '<a href="#" class="js-authenticate-service" data-id="' . $active_service->id . '" data-custom-fields="' . esc_attr(wp_json_encode($custom_fields)) . '">';
             $auth_content[] = __('Click here to authenticate.', 'wpml-translation-management');
             $auth_content[] = '</a>';
             $auth_content[] = '</strong>';
             $auth_content[] = wp_nonce_field('authenticate_service', 'authenticate_service_nonce', true, false);
             $auth_content[] = '<input type="hidden" name="custom_fields_serialized" id="custom_fields_serialized" value="" />';
             $auth_content[] = '</li>';
         } else {
             $auth_content[] = '<li>';
             $auth_content[] = '<p>';
             $auth_content[] = sprintf(__('%s is authorized.', 'wpml-translation-management'), $active_service->name) . '&nbsp;';
             $auth_content[] = '</p>';
             $auth_content[] = '</li>';
             $auth_content[] = '<li>';
             $auth_content[] = '<strong>';
             $auth_content[] = '<a href="#" class="js-invalidate-service" data-id="' . $active_service->id . '" data-custom-fields="' . esc_attr(wp_json_encode($custom_fields)) . '">';
             $auth_content[] = __('Click here to de-authorize.', 'wpml-translation-management');
             $auth_content[] = '</a>';
             $auth_content[] = '</strong>';
             $auth_content[] = wp_nonce_field('invalidate_service', 'invalidate_service_nonce', true, false);
             $auth_content[] = '</li>';
         }
     }
     if (!defined('WPML_TP_DEFAULT_SUID')) {
         $auth_content[] = '<li>';
         $auth_content[] = '<strong>';
         $auth_content[] = '<a href="#" class="js-deactivate-service" data-id="' . $active_service->id . '" data-custom-fields="' . esc_attr(wp_json_encode($custom_fields)) . '">';
         $auth_content[] = __('Click here to deactivate.', 'wpml-translation-management');
         $auth_content[] = '</a>';
         $auth_content[] = '</strong>';
         $auth_content[] = '</li>';
     }
     $auth_content[] = '</ul>';
     $auth_content[] = '</div>';
     $auth_content_full = implode("\n", $auth_content);
     ICL_AdminNotifier::display_instant_message($auth_content_full);
 }
 function translation_service_authentication()
 {
     $active_service = TranslationProxy::get_current_service();
     $custom_fields = TranslationProxy::get_custom_fields($active_service->id);
     $auth_content[] = '<div class="js-service-authentication">';
     $auth_content[] = '<ul>';
     if (TranslationProxy::service_requires_authentication($active_service)) {
         $auth_content[] = '<input type="hidden" name="service_id" id="service_id" value="' . $active_service->id . '" />';
         $custom_fields_data = TranslationProxy::get_custom_fields_data();
         if (!$custom_fields_data) {
             $authorization_message = sprintf(__('To send content to translation by %1$s, you need to have an account in %1$s and enter here your authentication details.', 'wpml-translation-management'), $active_service->name);
             $js_action = 'js-authenticate-service';
             $authorization_button = __('Authenticate', 'wpml-translation-management');
             $authorization_button_class = 'button-primary';
             $nonce_field = wp_nonce_field('authenticate_service', 'authenticate_service_nonce', true, false);
         } else {
             $authorization_message = sprintf(__('%s is authorized.', 'wpml-translation-management'), $active_service->name) . '&nbsp;';
             $js_action = 'js-invalidate-service';
             $authorization_button = __('De-authorize', 'wpml-translation-management');
             $authorization_button_class = 'button-secondary';
             $nonce_field = wp_nonce_field('invalidate_service', 'invalidate_service_nonce', true, false);
         }
         $auth_content[] = '<li>';
         $auth_content[] = '<p>';
         $auth_content[] = $authorization_message;
         $auth_content[] = '</p>';
         $auth_content[] = '</li>';
         $auth_content[] = '<li>';
         $auth_content[] = '<a href="#" class="' . $js_action . ' ' . $authorization_button_class . '" data-id="' . $active_service->id . '" data-custom-fields="' . esc_attr(wp_json_encode($custom_fields)) . '">';
         $auth_content[] = $authorization_button;
         $auth_content[] = '</a>';
         $auth_content[] = $nonce_field;
         $auth_content[] = '<input type="hidden" name="custom_fields_serialized" id="custom_fields_serialized" value="" />';
     }
     if (!TranslationProxy::get_tp_default_suid()) {
         $auth_content[] = '<a href="#" class="js-deactivate-service button-secondary" data-id="' . $active_service->id . '" data-custom-fields="' . esc_attr(wp_json_encode($custom_fields)) . '">';
         $auth_content[] = __('Deactivate', 'wpml-translation-management');
         $auth_content[] = '</a>';
     }
     if (isset($active_service->doc_url) && $active_service->doc_url) {
         $auth_content[] = '<a href="' . $active_service->doc_url . '" target="_blank">' . __('Documentation', 'wpml-translation-management') . '</a>';
     }
     $auth_content[] = '</li>';
     $auth_content[] = '</ul>';
     $auth_content[] = '</div>';
     $auth_content_full = implode("\n", $auth_content);
     ICL_AdminNotifier::display_instant_message($auth_content_full);
 }