Пример #1
0
 public function disassociate()
 {
     $client = new Lingotek_API();
     $prefs = Lingotek_Model::get_prefs();
     if ($prefs['delete_document_from_tms']) {
         $client->delete_document($this->document_id);
         wp_delete_term($this->term_id, 'post_translations');
     } else {
         wp_delete_term($this->term_id, 'post_translations');
     }
 }
Пример #2
0
 public function create_translation($locale, $automatic = false)
 {
     // Removes content sanitization so YouTube videos, links, etc don't get removed when inserting translations
     remove_filter('content_save_pre', 'wp_filter_post_kses');
     remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');
     $client = new Lingotek_API();
     if (false === ($translation = $client->get_translation($this->document_id, $locale, $this->source))) {
         return;
     }
     self::$creating_translation = true;
     $prefs = Lingotek_Model::get_prefs();
     // need an array by default
     $translation = json_decode($translation, true);
     // wp_insert_post expects array
     $tr_post = $translation['post'];
     $post = get_post($this->source);
     // source post
     $tr_post['post_status'] = $prefs['download_post_status'] === self::SAME_AS_SOURCE ? $post->post_status : $prefs['download_post_status'];
     // status
     // update existing translation
     if ($tr_id = $this->pllm->get_post($this->source, $locale)) {
         $tr_post['ID'] = $tr_id;
         // copy or ignore metas
         self::copy_or_ignore_metas($post->ID, $tr_id);
         // translate metas
         if (isset($translation['metas'])) {
             self::copy_translated_metas($translation['metas'], $tr_id);
         }
         wp_update_post($tr_post);
         $this->safe_translation_status_update($locale, 'current');
     } else {
         if ($this->translations[$locale] == 'ready' || $automatic) {
             unset($post->post_name);
             // forces the creation of a new default slug if not translated by Lingotek
             $tr_post = array_merge((array) $post, $tr_post);
             // copy all untranslated fields from the original post
             $tr_post['ID'] = null;
             // will force the creation of a new post
             // translate parent
             $tr_post['post_parent'] = $post->post_parent && ($tr_parent = $this->pllm->get_translation('post', $post->post_parent, $locale)) ? $tr_parent : 0;
             if ('attachment' == $post->post_type) {
                 $tr_id = wp_insert_attachment($tr_post);
                 add_post_meta($tr_id, '_wp_attachment_metadata', get_post_meta($this->source, '_wp_attachment_metadata', true));
                 add_post_meta($tr_id, '_wp_attached_file', get_post_meta($this->source, '_wp_attached_file', true));
             } else {
                 $tr_id = wp_insert_post($tr_post);
             }
             if ($tr_id) {
                 $tr_lang = $this->pllm->get_language($locale);
                 $this->pllm->set_post_language($tr_id, $tr_lang);
                 $this->safe_translation_status_update($locale, 'current', array($tr_lang->slug => $tr_id));
                 wp_set_object_terms($tr_id, $this->term_id, 'post_translations');
                 // assign terms and metas
                 $GLOBALS['polylang']->sync->copy_post_metas($this->source, $tr_id, $tr_lang->slug);
                 // copy or ignore metas
                 self::copy_or_ignore_metas($post->ID, $tr_id);
                 // translate metas
                 if (isset($translation['metas'])) {
                     self::copy_translated_metas($translation['metas'], $tr_id);
                 }
             }
         }
     }
     self::$creating_translation = false;
     // Adds content sanitization back in after Lingotek saves the translation
     add_filter('content_save_pre', 'wp_filter_post_kses');
     add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
 }
Пример #3
0
 public function disassociate()
 {
     $client = new Lingotek_API();
     $prefs = Lingotek_Model::get_prefs();
     if ($prefs['delete_document_from_tms']) {
         $client->delete_document($this->document_id);
         unset($this->desc_array['lingotek']);
         $this->save();
     } else {
         unset($this->desc_array['lingotek']);
         $this->save();
     }
 }
Пример #4
0
 public static function lingotek_edit_meta_box_html()
 {
     wp_enqueue_script('lingotek_defaults', LINGOTEK_URL . '/js/defaults.js');
     global $post;
     $post_type = get_post_type($post->ID);
     $lgtm = new Lingotek_Model();
     $group = $lgtm->get_group('post', $post->ID);
     $profiles = Lingotek::get_profiles();
     $content_profiles = get_option('lingotek_content_type');
     $language_profiles = self::retrieve_lang_Profiles($post_type, $profiles, $content_profiles);
     $default_name = empty($content_profiles) == false ? $profiles[$content_profiles[$post->post_type]['profile']]['name'] : ($post_type == 'page' ? __('Manual', 'wp-lingotek') : __('Automatic', 'wp-lingotek'));
     $content_default_profile = array('default' => array('name' => __('Content Default', 'wp-lingotek') . ' (' . $default_name . ')'));
     $language_profiles['defaults'] = array('content_default' => $default_name, 'title' => __('Content Default', 'wp-lingotek'));
     $profiles = array_merge($content_default_profile, $profiles);
     $post_profile = self::get_post_profile($post->ID);
     if (isset($post_profile)) {
         $selected[$post_profile->description] = $profiles[$post_profile->description];
         unset($profiles[$post_profile->description]);
         $profiles = array_merge($selected, $profiles);
     }
     if (isset($group->source)) {
         // Disables selection of a different profile if content has been uploaded to Lingotek
         $args = array('document_id' => $group->document_id, 'action' => 'lingotek-delete', 'noheader' => true);
         if ($post_type == 'page') {
             $args['lingotek_redirect'] = true;
         }
         $site_id = get_current_blog_id();
         $url = $post_type == 'page' ? get_site_url($site_id, '/wp-admin/edit.php?post_type=page') : get_site_url($site_id, '/wp-admin/edit.php');
         $disassociate_url = wp_nonce_url(add_query_arg($args, $url), 'lingotek-delete');
         $remove_post = 'post=' . $post->ID;
         $disassociate_url = str_replace($remove_post, '', $disassociate_url);
         $prefs = Lingotek_Model::get_prefs();
         $confirm_message = isset($prefs['delete_document_from_tms']) === false ? __('Are you sure you want to do this?', 'wp-lingotek') : __('Are you sure you want to do this? The document will be deleted from Lingotek TMS.', 'wp-lingotek');
         $confirm_message = sprintf(' onclick = "return confirm(\'%s\');"', $confirm_message);
         printf('<strong>%s</strong><br><br>', __('Translation Profile', 'wp-lingotek'));
         printf('<em>%s</em><br>', __('Disassociate this content to change the Translation Profile', 'wp-lingotek'));
         printf('<a class="button button-small" href="%s" %s>%s</a><br><br>', esc_url($disassociate_url), $confirm_message, __('Disassociate', 'wp-lingotek'));
         printf('<select disabled class="lingotek-profile-setting" name="%1$s" id="%1$s">', 'lingotek_profile_meta');
     } else {
         printf('<strong>%s</strong><br><br>', __('Translation Profile', 'wp-lingotek'));
         printf('<select class="lingotek-profile-setting" name="%1$s" id="%1$s">', 'lingotek_profile_meta');
     }
     foreach ($profiles as $key => $profile) {
         echo "\n\t<option value=" . esc_attr($key) . ">" . esc_attr($profile['name']) . '</option>';
     }
     echo '</select>';
     echo '<div id="lingotek-language-profiles" style="display: none;">' . json_encode($language_profiles) . '</div>';
 }
Пример #5
0
         //Creates a new project based on the name of the selected site
         if (isset($_POST['new_project'])) {
             $options = get_blog_option($destination, 'lingotek_defaults');
             $client = new Lingotek_API();
             $title = htmlspecialchars_decode(get_blog_details($destination)->blogname, ENT_QUOTES);
             if ($new_id = $client->create_project($title, $community_id = get_blog_option($destination, 'lingotek_community'))) {
                 $options['project_id'] = $new_id;
                 // Adds correct callback URL for new project
                 $args = array('callback_url' => add_query_arg('lingotek', 1, get_blog_details($destination)->siteurl));
                 $response = $client->patch($client->get_api_url() . '/project/' . $new_id, $args);
                 update_blog_option($destination, 'lingotek_defaults', $options);
             }
         }
         if (isset($_POST['preferences'])) {
             switch_to_blog($source_site);
             $preferences = Lingotek_Model::get_prefs();
             update_blog_option($destination, 'lingotek_prefs', $preferences);
             restore_current_blog();
         }
         if (isset($_POST['utility_set_default_language'])) {
             switch_to_blog($destination);
             $GLOBALS['wp_lingotek']->utilities->run_utility('utility_set_default_language');
             restore_current_blog();
         }
     }
     if (isset($_POST['utility_set_default_language'])) {
         add_settings_error('network', 'utilities', __('The language utility ran successfully.', 'wp-lingotek'), 'updated');
     }
     add_settings_error('network', 'destination', __('Your chosen settings have updated successfully for all selected sites.', 'wp-lingotek'), 'updated');
 } else {
     add_settings_error('network', 'destination', __('Please choose at least one destination site.', 'wp-lingotek'), 'error');
Пример #6
0
$page_key = $this->plugin_slug . '_settings&sm=preferences';
if (!empty($_POST)) {
    check_admin_referer($page_key, '_wpnonce_' . $page_key);
    $options = array();
    foreach ($setting_details as $key => $setting) {
        if (isset($_POST[$key])) {
            $options[$key] = $_POST[$key];
        } else {
            $options[$key] = null;
        }
    }
    update_option('lingotek_prefs', $options);
    add_settings_error('lingotek_prefs', 'prefs', __('Your preferences were successfully updated.', 'wp-lingotek'), 'updated');
    settings_errors();
}
$selected_options = Lingotek_Model::get_prefs();
?>

<h3><?php 
_e('Preferences', 'wp-lingotek');
?>
</h3>
<p class="description"><?php 
_e('These are your preferred settings.', 'wp-lingotek');
?>
</p>


<form id="lingotek-settings" method="post" action="admin.php?page=<?php 
echo $page_key;
?>