public function save_term($term_id, $tt_id, $taxonomy) { if (!$this->model->is_translated_taxonomy($taxonomy)) { return; } if (!isset($_REQUEST['import'])) { parent::save_term($term_id, $tt_id, $taxonomy); if ('automatic' == Lingotek_Model::get_profile_option('upload', $taxonomy, $this->model->get_term_language($term_id)) && $this->lgtm->can_upload('term', $term_id)) { $this->lgtm->upload_term($term_id, $taxonomy); } } }
protected function _column($type, $column, $object_id, $custom_data = NULL) { $action = 'post' == $type ? 'inline-save' : 'inline-save-tax'; $inline = defined('DOING_AJAX') && $_REQUEST['action'] == $action && isset($_POST['inline_lang_choice']); $lang = $inline ? $this->model->get_language($_POST['inline_lang_choice']) : call_user_func(array($this->model, 'get_' . $type . '_language'), $object_id); if (false === strpos($column, 'language_') || !$lang) { if ($custom_data) { return $custom_data; } else { return ''; } } $language = $this->model->get_language(substr($column, 9)); // FIXME should I suppress quick edit? // yes for uploaded posts, but I will need js as the field is built for all posts // /!\ also take care not add this field two times when translations are managed by Polylang // hidden field containing the post language for quick edit (used to filter categories since Polylang 1.7) if ($column == $this->get_first_language_column()) { printf('<div class="hidden" id="lang_%d">%s</div>', esc_attr($object_id), esc_html($lang->slug)); } $id = $inline && $lang->slug != $this->model->get_language($_POST['old_lang'])->slug ? $language->slug == $lang->slug ? $object_id : 0 : call_user_func(array($this->model, 'get_' . $type), $object_id, $language); $document = $this->lgtm->get_group($type, $object_id); // FIXME not very clean $actions = 'post' == $type ? $GLOBALS['wp_lingotek']->post_actions : $GLOBALS['wp_lingotek']->term_actions; $profile = Lingotek_Model::get_profile($this->content_type, $language, $object_id); $disabled = 'disabled' == $profile['profile']; // post ready for upload if ($this->lgtm->can_upload($type, $object_id) && $object_id == $id) { return $disabled ? 'post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id) : $actions->upload_icon($object_id); } elseif (isset($document->source) && $document->is_disabled_target($lang, $language) && !isset($document->translations[$language->locale])) { return 'post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id); } elseif (isset($document->source) && $document->source == $id) { // source ready for upload if ($this->lgtm->can_upload($type, $id)) { return $actions->upload_icon($id); } // importing source if ($id == $object_id && 'importing' == $document->status) { return Lingotek_Actions::importing_icon($document); } // uploaded return 'post' == $type ? Lingotek_Post_actions::uploaded_icon($id) : Lingotek_Term_actions::uploaded_icon($id); } elseif ($type == 'term' && !isset($document->translations[$language->locale]) && $document->source != $object_id) { return parent::term_column('', $column, $object_id); } elseif (isset($document->translations[$language->locale]) || isset($document->source) && 'current' == $document->status) { return Lingotek_Actions::translation_icon($document, $language); } elseif (empty($document->source)) { return $object_id == $id && !$disabled ? $actions->upload_icon($object_id, true) : ('post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id)); } else { return '<div class="lingotek-color dashicons dashicons-no"></div>'; } }
public function is_automatic_upload() { return 'automatic' == Lingotek_Model::get_profile_option('upload', get_post_type($this->source), $this->get_source_language(), false, $this->source); }
public function is_disabled_target($language, $target = null) { $profile = Lingotek_Model::get_profile($this->type, $language, $this->source); if ($target) { return isset($profile['targets'][$target->slug]) && ('disabled' == $profile['targets'][$target->slug] || 'copy' == $profile['targets'][$target->slug]); } else { return isset($profile['targets'][$language->slug]) && ('disabled' == $profile['targets'][$language->slug] || 'copy' == $profile['targets'][$language->slug]); } }
public function is_automatic_upload() { return 'automatic' == Lingotek_Model::get_profile_option('upload', 'string', $this->get_source_language()); }
public function ajax_get_current_status() { $lgtm =& $GLOBALS['wp_lingotek']->model; $pllm = $GLOBALS['polylang']->model; $languages = pll_languages_list(array('fields' => 'locale')); $object_ids = $_POST['check_ids']; if ($object_ids === null) { return; } $terms = isset($_POST['terms_translations']); //The main array consists of //ids and nonces. Each id has a source language, languages with statuses, and a workbench link $content_metadata = array(); foreach ($object_ids as $object_id) { $id = $object_id; $type = $terms ? 'term' : 'post'; if (isset($_POST['taxonomy'])) { $taxonomy = $_POST['taxonomy']; if (strpos($_POST['taxonomy'], '&')) { $taxonomy = strstr($_POST['taxonomy'], '&', true); } } else { $taxonomy = get_post_type($id); } $content_metadata[$id] = array('existing_trans' => false, 'source' => false, 'doc_id' => null, 'source_id' => null, 'source_status' => null); $document = $lgtm->get_group($type, $object_id); if ($document && !isset($document->source) && count($document->desc_array) >= 3) { $content_metadata[$id]['existing_trans'] = true; } if ($document && isset($document->source) && isset($document->document_id) && isset($document->status) && isset($document->translations)) { if ($document->source !== (int) $object_id) { $document = $lgtm->get_group($type, $document->source); } $source_id = $document->source !== null ? $document->source : $object_id; $source_language = $terms ? pll_get_term_language($document->source, 'locale') : pll_get_post_language($document->source, 'locale'); $existing_translations = $pllm->get_translations($type, $source_id); if (count($existing_translations) > 1) { $content_metadata[$id]['existing_trans'] = true; } $content_metadata[$id]['source'] = $source_language; $content_metadata[$id]['doc_id'] = $document->document_id; $content_metadata[$id]['source_id'] = $document->source; $content_metadata[$id]['source_status'] = $document->status; $target_status = $document->status == 'edited' || $document->status == null ? 'edited' : 'current'; $content_metadata[$id][$source_language]['status'] = $document->source == $object_id ? $document->status : $target_status; if (is_array($document->translations)) { foreach ($document->translations as $locale => $translation_status) { $content_metadata[$id][$locale]['status'] = $translation_status; $workbench_link = Lingotek_Actions::workbench_link($document->document_id, $locale); $content_metadata[$id][$locale]['workbench_link'] = $workbench_link; } } //fills in missing languages, makes life easier for the updater foreach ($languages as $language) { foreach ($content_metadata as $group => $status) { $language_obj = $pllm->get_language($source_language); $target_lang_obj = $pllm->get_language($language); $profile = Lingotek_Model::get_profile($taxonomy, $language_obj, $group); if ($profile['profile'] != 'disabled' && $status['source'] != false) { if (!isset($status[$language])) { $content_metadata[$group][$language]['status'] = "none"; if ($document->is_disabled_target($pllm->get_language($source_language), $pllm->get_language($language)) || isset($document->desc_array[$target_lang_obj->slug]) && !isset($document->source)) { $content_metadata[$group][$language]['status'] = 'disabled'; } } } } } } $language = $type == 'post' ? pll_get_post_language($id) : pll_get_term_language($id); $language = $pllm->get_language($language); if ($language) { $profile = Lingotek_Model::get_profile($taxonomy, $language, $id); if ($profile['profile'] == 'disabled' && $content_metadata[$id]['source'] == false) { $content_metadata[$id]['source'] = 'disabled'; } } } //get the nonces associated with the different actions $content_metadata['request_nonce'] = $this->lingotek_get_matching_nonce('lingotek-request'); $content_metadata['download_nonce'] = $this->lingotek_get_matching_nonce('lingotek-download'); $content_metadata['upload_nonce'] = $this->lingotek_get_matching_nonce('lingotek-upload'); $content_metadata['status_nonce'] = $this->lingotek_get_matching_nonce('lingotek-status'); wp_send_json($content_metadata); }
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>'; }
public function save_post($post_id, $post, $update) { if ($this->can_save_post_data($post_id, $post, true)) { $document = $this->lgtm->get_group('post', $post_id); // updated post if ($document && $post_id == $document->source && $this->post_hash_has_changed($post)) { $document->source_edited(); if ($document->is_automatic_upload() && Lingotek_Group_Post::is_valid_auto_upload_post_status($post->post_status)) { $this->lgtm->upload_post($post_id); } } } if (!$this->model->is_translated_post_type($post->post_type)) { return; } // new post if (!isset($_REQUEST['import'])) { parent::save_post($post_id, $post, $update); if (!wp_is_post_revision($post_id) && 'auto-draft' != $post->post_status && Lingotek_Group_Post::is_valid_auto_upload_post_status($post->post_status) && 'automatic' == Lingotek_Model::get_profile_option('upload', $post->post_type, $this->model->get_post_language($post_id), false, $post_id) && !(isset($_POST['action']) && 'heartbeat' == $_POST['action']) && $this->lgtm->can_upload('post', $post_id)) { $this->lgtm->upload_post($post_id); } } }
<p class="description"><?php printf(__('Manage group translation of system, widget, and plugin-specific strings. View individual strings on the <a href="%s"><b>Strings</b></a> page.', 'wp-lingotek'), 'admin.php?page=wp-lingotek_manage&sm=strings'); ?> </p> <?php $profile = Lingotek_Model::get_profile('string', $this->pllm->get_language($this->pllm->options['default_lang'])); if ('disabled' == $profile['profile']) { printf('<div class="error" style="border-left: 4px solid #ffba00;"><p>%s</p></div>', sprintf(__('The strings translation is disabled in %sContent Type Configuration%s.', 'wp-lingotek'), '<a href="' . admin_url('admin.php?page=wp-lingotek_settings&sm=content') . '">', '</a>')); } else { $string_actions = $GLOBALS['wp_lingotek']->string_actions; $table = new Lingotek_Strings_Table($string_actions); $action = $table->current_action(); if (!empty($action)) { $string_actions->manage_actions($action); } $data = Lingotek_Model::get_strings(); foreach ($data as $key => $row) { $data[$key]['row'] = $key; // store the row number for convenience } $table->prepare_items($data); ?> <form id="lingotek-strings" method="post" action="admin.php?page=wp-lingotek_manage&noheader=true&sm=string-groups"><?php $table->display(); ?> </form><?php foreach (Lingotek_String_actions::$actions as $action => $strings) { if (!empty($_GET['bulk-lingotek-' . $action])) { printf('<div id="lingotek-progressdialog" title="%s"><div id="lingotek-progressbar"></div></div>', $strings['progress']); }
//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');
public function add_attachment($post_id) { if ($this->model->is_translated_post_type('attachment') && 'automatic' == Lingotek_Model::get_profile_option('upload', 'attachment', $this->model->get_post_language($post_id)) && $this->lgtm->can_upload('post', $post_id)) { $this->lgtm->upload_post($post_id); } }
public function updated_option() { foreach (Lingotek_Model::get_strings() as $id) { if ($this->lgtm->can_upload('string', $id['context'])) { $this->lgtm->upload_strings($id['context']); } } }
public function copy_term($term, $target, $taxonomy) { self::$copying_term = true; $document = $this->get_group('term', $term->term_id); $cp_lang = $this->pllm->get_language($target); $cp_term = (array) $term; //unset($cp_term['term_id']); if (isset($cp_term['slug']) && term_exists($cp_term['slug'])) { $cp_term['slug'] .= '-' . $cp_lang->slug; } $new_term = wp_insert_term($cp_term['name'], $taxonomy, $cp_term); if (!is_wp_error($new_term)) { $this->pllm->set_term_language($new_term['term_id'], $cp_lang); wp_set_object_terms($new_term['term_id'], $document->term_id, 'term_translations'); $document->desc_array[$target] = $new_term['term_id']; $document->save(); } self::$copying_term = false; }
public function manage_actions() { global $taxnow, $post_type; if (!$this->pllm->is_translated_taxonomy($taxnow)) { return; } // get the action $wp_list_table = _get_list_table('WP_Terms_List_Table'); $action = $wp_list_table->current_action(); if (empty($action)) { return; } $redirect = remove_query_arg(array('action', 'action2', 'delete_tags'), wp_get_referer()); if (!$redirect) { $redirect = admin_url("edit-tags.php?taxonomy={$taxnow}&post_type={$post_type}"); } switch ($action) { case 'bulk-lingotek-upload': if (empty($_REQUEST['delete_tags'])) { return; } $term_ids = array(); foreach (array_map('intval', $_REQUEST['delete_tags']) as $term_id) { // safe upload if ($this->lgtm->can_upload('term', $term_id)) { $terms_ids[] = $term_id; } elseif (($document = $this->lgtm->get_group('term', $term_id)) && empty($document->source)) { // take care to upload only one post in a translation group $intersect = array_intersect($term_ids, $this->pllm->get_translations('term', $term_id)); if (empty($intersect)) { $term_ids[] = $term_id; $redirect = add_query_arg('lingotek_warning', 1, $redirect); } } } // check if translation is disabled if (!empty($term_ids)) { foreach ($term_ids as $key => $term_id) { $language = $this->pllm->get_term_language($term_id); $profile = Lingotek_Model::get_profile($taxnow, $language); if ('disabled' == $profile['profile']) { unset($term_ids[$key]); } } } case 'bulk-lingotek-request': case 'bulk-lingotek-download': case 'bulk-lingotek-status': case 'bulk-lingotek-delete': if (empty($_REQUEST['delete_tags'])) { return; } if (empty($term_ids)) { $term_ids = array_map('intval', $_REQUEST['delete_tags']); } check_admin_referer('bulk-tags'); $redirect = add_query_arg($action, 1, $redirect); $redirect = add_query_arg('ids', implode(',', $term_ids), $redirect); break; case 'lingotek-upload': check_admin_referer('lingotek-upload'); $this->lgtm->upload_term((int) $_GET['term'], $taxnow); break; default: if (!$this->_manage_actions($action)) { return; } // do not redirect if this is not one of our actions } wp_redirect($redirect); exit; }
$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; ?>
static function get_unique_source_counts_by_type() { global $polylang; $lgtm = new Lingotek_Model(); // FIXME not created by Lingotek as Polylang believes we are doing ajax on frontend foreach ($polylang->model->get_translated_post_types() as $post_type) { $count = $lgtm->count_posts($post_type); $post_type_object = get_post_type_object($post_type); $response['types'][$post_type_object->labels->name] = isset($count['total']) ? $count['total'] : 0; //only count translation sets } foreach ($polylang->model->get_translated_taxonomies() as $tax) { $count = $lgtm->count_terms($tax); $taxonomy = get_taxonomy($tax); $response['types'][$taxonomy->labels->name] = isset($count['total']) ? $count['total'] : 0; //only count translation sets } $response['total'] = array_sum($response['types']); return $response; }