예제 #1
0
 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>';
     }
 }
예제 #2
0
 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]);
     }
 }
예제 #3
0
 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);
 }
예제 #4
0
 public function manage_actions()
 {
     global $typenow;
     $post_type = 'load-upload.php' == current_filter() ? 'attachment' : $typenow;
     if (!$this->pllm->is_translated_post_type($post_type)) {
         return;
     }
     // get the action
     // $typenow is empty for media
     $wp_list_table = _get_list_table(empty($typenow) ? 'WP_Media_List_Table' : 'WP_Posts_List_Table');
     $action = $wp_list_table->current_action();
     if (empty($action)) {
         return;
     }
     $redirect = remove_query_arg(array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status', 'post', 'bulk_edit', 'post_view'), wp_get_referer());
     if (!$redirect) {
         $redirect = admin_url("edit.php?post_type={$typenow}");
     }
     switch ($action) {
         case 'bulk-lingotek-upload':
             $type = empty($typenow) ? 'media' : 'post';
             if (empty($_REQUEST[$type])) {
                 return;
             }
             $post_ids = array();
             foreach (array_map('intval', $_REQUEST[$type]) as $post_id) {
                 // safe upload
                 if ($this->lgtm->can_upload('post', $post_id)) {
                     $post_ids[] = $post_id;
                 } elseif (($document = $this->lgtm->get_group('post', $post_id)) && empty($document->source)) {
                     // take care to upload only one post in a translation group
                     $intersect = array_intersect($post_ids, $this->pllm->get_translations('post', $post_id));
                     if (empty($intersect)) {
                         $post_ids[] = $post_id;
                         $redirect = add_query_arg('lingotek_warning', 1, $redirect);
                     }
                 }
             }
             // check if translation is disabled
             if (!empty($post_ids)) {
                 foreach ($post_ids as $key => $post_id) {
                     $language = $this->pllm->get_post_language($post_id);
                     $profile = Lingotek_Model::get_profile($post_type, $language);
                     if ('disabled' == $profile['profile']) {
                         unset($post_ids[$key]);
                     }
                 }
             }
         case 'bulk-lingotek-request':
         case 'bulk-lingotek-download':
         case 'bulk-lingotek-status':
         case 'bulk-lingotek-delete':
             if (empty($post_ids)) {
                 $type = empty($typenow) ? 'media' : 'post';
                 if (empty($_REQUEST[$type])) {
                     return;
                 }
                 $post_ids = array_map('intval', $_REQUEST[$type]);
             }
             empty($typenow) ? check_admin_referer('bulk-media') : check_admin_referer('bulk-posts');
             $redirect = add_query_arg($action, 1, $redirect);
             $redirect = add_query_arg('ids', implode(',', $post_ids), $redirect);
             break;
         case 'lingotek-upload':
             check_admin_referer('lingotek-upload');
             $this->lgtm->upload_post((int) $_GET['post']);
             break;
         default:
             if (!$this->_manage_actions($action)) {
                 return;
             }
             // do not redirect if this is not one of our actions
     }
     wp_redirect($redirect);
     exit;
 }
예제 #5
0
<h3><?php 
_e('String Groups', 'wp-lingotek');
?>
</h3>

<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&amp;noheader=true&amp;sm=string-groups"><?php 
    $table->display();
    ?>
예제 #6
0
 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;
 }