display_main();
}
/**
* Sets up the menu items for non-admin translators pointing at the TM
* and ST translators interfaces
*/
function menu() {
if ( $this->sitepress->setup() ) {
$wp_api = $this->sitepress->get_wp_api();
if ( $wp_api->current_user_can( 'wpml_manage_translation_management' ) ) {
$wp_api->add_submenu_page( apply_filters( 'icl_menu_main_page', ICL_PLUGIN_FOLDER . '/menu/languages.php' ),
__( 'Translations', 'wpml-translation-management' ), __( 'Translations', 'wpml-translation-management' ),
'wpml_manage_translation_management', WPML_TM_FOLDER . '/menu/translations-queue.php' );
} elseif ( (bool) $this->tm_instance->get_current_translator()->language_pairs === true ) {
$wp_api->add_menu_page( __( 'Translation interface', 'wpml-translation-management' ),
__( 'Translation interface', 'wpml-translation-management' ), 'translate',
WPML_TM_FOLDER . '/menu/translations-queue.php', null, ICL_PLUGIN_URL . '/res/img/icon16.png' );
}
}
}
function menu_fix_order(){
global $submenu;
if(!isset($submenu[WPML_TM_FOLDER . '/menu/main.php'])) return;
// Make sure 'Translations' stays at the end
$found = false;
foreach($submenu[WPML_TM_FOLDER . '/menu/main.php'] as $id => $sm){
if($sm[2] == WPML_TM_FOLDER . '/menu/translations-queue.php'){
$found = $sm;
unset($submenu[WPML_TM_FOLDER . '/menu/main.php'][$id]);
break;
}
}
if($found){
$submenu[WPML_TM_FOLDER . '/menu/main.php'][] = $found;
}
}
function _warn_editing_icl_translation(){
global $wpdb, $sitepress, $iclTranslationManagement;
$request_get_trid = filter_input(INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE);
$request_get_post = filter_input(INPUT_GET, 'post', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$request_get_lang = filter_input(INPUT_GET, 'lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$post_type = false;
if($request_get_trid){
$translation_id = $wpdb->get_var($wpdb->prepare("
SELECT t.translation_id
FROM {$wpdb->prefix}icl_translations t
JOIN {$wpdb->prefix}icl_translation_status s ON t.translation_id = s.translation_id
WHERE t.trid=%d AND t.language_code=%s"
, $request_get_trid, $request_get_lang));
}else{
$post_type = $wpdb->get_var($wpdb->prepare("SELECT post_type FROM {$wpdb->posts} WHERE ID=%d", $request_get_post));
$translation_id = $wpdb->get_var($wpdb->prepare("
SELECT translation_id FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type=%s AND language_code=%s"
, $request_get_post, 'post_' . $post_type, $request_get_lang));
}
if($translation_id){
$translation_status = $wpdb->get_var($wpdb->prepare("
SELECT status FROM {$wpdb->prefix}icl_translation_status WHERE translation_id=%d"
, $translation_id));
if(!is_null($translation_status) && $translation_status > 0 && $translation_status != ICL_TM_DUPLICATE && $translation_status < ICL_TM_COMPLETE){
echo '
'.
sprintf(__('Warning: You are trying to edit a translation that is currently in the process of being added using WPML.' , 'wpml-translation-management')) . '
'.
sprintf(__('Please refer to the Translation management dashboard for the exact status of this translation.' , 'wpml-translation-management'),
admin_url('admin.php?page='.WPML_TM_FOLDER.'/menu/main.php&')) . '
Warning: You are trying to edit a translation using the standard WordPress editor but your site is configured to use the WPML Translation Editor.' , 'wpml-translation-management')?>
Warning: You are trying to add a translation using the standard WordPress editor but your site is configured to use the WPML Translation Editor.' , 'wpml-translation-management')?>
Translation management dashboard to send the original document to translation.' , 'wpml-translation-management'), admin_url('admin.php?page='.WPML_TM_FOLDER.'/menu/main.php')); ?>
settings['doc_translation_method'] = ICL_TM_TMETHOD_MANUAL;
$iclTranslationManagement->save_settings();
exit;
}
function icl_dashboard_widget_content(){
global $wpdb;
get_currentuserinfo();
$docs_sent = 0;
$docs_completed = 0;
$docs_waiting = 0;
$docs_statuses = $wpdb->get_results($wpdb->prepare("SELECT status FROM {$wpdb->prefix}icl_translation_status WHERE status > %d", ICL_TM_NOT_TRANSLATED));
foreach ( $docs_statuses as $doc_status ) {
if ( in_array( $doc_status->status, array( ICL_TM_COMPLETE, ICL_TM_WAITING_FOR_TRANSLATOR , ICL_TM_IN_PROGRESS) ) ) {
$docs_sent += 1;
if ( $doc_status->status == ICL_TM_COMPLETE ) {
$docs_completed += 1;
} elseif ( $doc_status->status == ICL_TM_WAITING_FOR_TRANSLATOR
|| $doc_status->status == ICL_TM_IN_PROGRESS
) {
$docs_waiting += 1;
}
}
}
include WPML_TM_PATH . '/menu/_icl_dashboard_widget.php';
}
function plugin_action_links($links, $file){
$this_plugin = basename(WPML_TM_PATH) . '/plugin.php';
if($file == $this_plugin) {
$links[] = '' .
__('Configure', 'wpml-translation-management') . '';
}
return $links;
}
// Localization
function plugin_localization(){
load_plugin_textdomain( 'wpml-translation-management', false, WPML_TM_FOLDER . '/locale');
}
//
function _icl_tm_parent_filter(){
global $sitepress;
$current_language = $sitepress->get_current_language();
$request_post_type = filter_input(INPUT_POST, 'type', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$request_post_lang = filter_input(INPUT_POST, 'lang', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$request_post_parent_id = filter_input(INPUT_POST, 'parent_id', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE);
$request_post_parent_all = filter_input(INPUT_POST, 'parent_all', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE);
$sitepress->switch_lang($request_post_lang);
if($request_post_type == 'page'){
$html = wp_dropdown_pages(array('echo'=>0, 'name'=>'filter[parent_id]', 'selected'=>$request_post_parent_id));
}elseif($request_post_type == 'category'){
$html = wp_dropdown_categories(array('echo'=>0, 'orderby'=>'name', 'name'=>'filter[parent_id]', 'selected'=>$request_post_parent_id));
}else{
$html = '';
}
$sitepress->switch_lang($current_language);
$html .= " ";
if(is_null($request_post_parent_all) || $request_post_parent_all) {
$checked = ' checked="checked"';
} else {
$checked="";
}
$html .= "';
$html .= " ";
if(empty($request_post_parent_all)) {
$checked = ' checked="checked"';
} else {
$checked="";
}
$html .= "';
echo wp_json_encode(array('html'=>$html));
exit;
}
function _icl_tm_toggle_promo() {
global $sitepress;
$value = filter_input( INPUT_POST, 'value', FILTER_VALIDATE_INT );
$iclsettings[ 'dashboard' ][ 'hide_icl_promo' ] = intval( $value );
$sitepress->save_settings( $iclsettings );
exit;
}
/**
* @return array
*/
public function get_active_services() {
$cache_key = 'active_services';
$cache_group = '';
$found = false;
$result = wp_cache_get($cache_key, $cache_group, false, $found);
if($found) return $result;
$active_services = array( 'local' => array() );
$current_service = TranslationProxy::get_current_service();
if ( !is_wp_error( $current_service ) ) {
if ( $current_service ) {
$active_services[ $current_service->name ] = $current_service;
}
wp_cache_set( $cache_key, $active_services, $cache_group );
}
return $active_services;
}
public function automatic_service_selection_action() {
$this->automatic_service_selection();
}
public function handle_notices_action() {
$this->handle_notices();
}
public function basket_extra_fields_refresh() {
echo TranslationProxy_Basket::get_basket_extra_fields_inputs();
die();
}
/**
* If user display Translation Dashboard or Translators
*
* @return boolean
*/
function automatic_service_selection_pages() {
return is_admin() &&
isset($_GET['page']) &&
$_GET['page'] == WPML_TM_FOLDER . '/menu/main.php' &&
( !isset($_GET['sm']) || $_GET['sm'] == 'translators' || $_GET['sm'] == 'dashboard' );
}
public function add_com_log_link( ) {
require_once WPML_TM_PATH . '/inc/translation-proxy/translationproxy-com-log.class.php';
TranslationProxy_Com_Log::add_com_log_link( );
}
public function service_activation_incomplete() {
return $this->has_active_service() && ($this->service_requires_authentication() || $this->service_requires_translators());
}
private function has_active_service() {
return TranslationProxy::get_current_service() !== false;
}
private function service_requires_translators() {
$result = false;
$service_has_translators = TranslationProxy::translator_selection_available();
if ( $service_has_translators ) {
$result = !$this->service_has_accepted_translators();
}
return $result;
}
private function service_requires_authentication() {
$result = false;
$service_has_translators = TranslationProxy::translator_selection_available();
if ( !$service_has_translators ) {
$has_custom_fields = TranslationProxy::has_custom_fields();
$custom_fields_data = TranslationProxy::get_custom_fields_data();
$result = $has_custom_fields && !$custom_fields_data;
}
return $result;
}
private function service_has_accepted_translators() {
$result = false;
$icl_data = TranslationProxy_Translator::get_icl_translator_status();
if ( isset( $icl_data[ 'icl_lang_status' ] ) && is_array( $icl_data[ 'icl_lang_status' ] ) ) {
foreach ( $icl_data[ 'icl_lang_status' ] as $translator ) {
if ( isset( $translator[ 'contract_id' ] ) && $translator[ 'contract_id' ] != 0 ) {
$result = true;
break;
}
}
}
return $result;
}
private function service_authentication_notice() {
$message_id = 'current_service_authentication_required';
if ( $this->service_activation_incomplete() ) {
$current_service_name = TranslationProxy::get_current_service_name();
if ( $this->is_translators_tab() ) {
if ( $this->service_requires_translators() && $current_service_name == 'ICanLocalize' ) {
$message = __( 'You selected %1$s as your translation service. Next, you need to add translators from %1$s to your site. Click on the "Add translators" button. Select the source and target language and choose %1$s as the source of the translator. You can add different translators between different languages.', 'wpml-translation-management' );
$button_text = __( 'Getting started with ICanLocalize', 'wpml-translation-management' );
$button_url = 'https://wpml.org/translation-service/icanlocalize/';
$notification_message = '';
$notification_message .= '
';
$notification_message .= sprintf( __( 'Please go to %1$s and use the link %2$s.', 'wpml-translation-management' ), $services_link, $service_authentication_link );
$notification_message .= '
';
} else {
$problem_detected = false;
if ( $this->service_requires_authentication() ) {
$notification_message = __( "You have selected a translation service which requires authentication.", 'wpml-translation-management' );
} elseif ( $this->service_requires_translators() ) {
$notification_message = __( "You have selected a translation service which requires translators.", 'wpml-translation-management' );
$service_authentication_link = '' . __( 'Add Translator', 'wpml-translation-management' ) . ' »';
} else {
$problem_detected = true;
$notification_message = __( "There is a problem with your translation service.", 'wpml-translation-management' );
}
$notification_message .= '
';
$notification_message .= '
';
if ( $this->service_requires_authentication() ) {
$notification_message .= sprintf( __( "If you wish to use %s, please go to %s and use the link %s.", 'wpml-translation-management' ), ''
. $current_service_name
. '', $services_link, $service_authentication_link );
} elseif ( $this->service_requires_translators() ) {
$notification_message .= sprintf( __( "If you wish to use %s, please go to %s and use the link %s.", 'wpml-translation-management' ), ''
. $current_service_name
. '', $services_link, $service_authentication_link );
} elseif ( $problem_detected ) {
$notification_message .= sprintf( __( "Please contact your administrator.", 'wpml-translation-management' ), $services_link, $service_authentication_link );
}
$notification_message .= '
';
$notification_message .= '
';
$notification_message .= sprintf( __( "If you wish to use only local translators, please go to %s and use the link %s.", 'wpml-translation-management' ), $services_link, $service_deactivation_link );
$notification_message .= '