示例#1
0
 function column_default($item, $column_name)
 {
     // generic case (count)
     if (false === strpos($column_name, 'language_')) {
         return $item[$column_name];
     }
     // language column
     $language = $this->pllm->get_language(substr($column_name, 9));
     $document = $this->lgtm->get_group('string', $item['context']);
     // FIXME
     // post ready for upload
     if ($this->lgtm->can_upload('string', $item['context']) && $language->slug == $this->pllm->options['default_lang']) {
         echo $this->string_actions->upload_icon($item['context']);
     } elseif (isset($document->source) && $document->is_disabled_target($language)) {
         echo '<div class="lingotek-color dashicons dashicons-no"></div>';
     } elseif (isset($document->source) && $document->source == $language->mo_id) {
         echo 'importing' == $document->status ? Lingotek_Actions::importing_icon($document) : Lingotek_String_actions::uploaded_icon($item['context']);
     } elseif (isset($document->translations[$language->locale]) || isset($document->source) && 'current' == $document->status) {
         echo Lingotek_Actions::translation_icon($document, $language);
     } else {
         echo '<div class="lingotek-color dashicons dashicons-no"></div>';
     }
     $language_only = 'language_' . $language->slug;
     $errors = get_option('lingotek_log_errors');
     if ($language_only == $this->get_first_language_column()) {
         if (isset($errors[$item['context']])) {
             $api_error = Lingotek_Actions::retrieve_api_error($errors[$item['context']]);
             echo Lingotek_Actions::display_error_icon('error', $api_error);
         }
     }
 }
示例#2
0
 public function __construct()
 {
     parent::__construct('term');
     foreach ($this->pllm->get_translated_taxonomies() as $taxonomy) {
         add_filter($taxonomy . '_row_actions', array(&$this, 'term_row_actions'), 10, 2);
     }
     add_action('admin_footer-edit-tags.php', array(&$this, 'add_bulk_actions'));
     // FIXME admin_print_footer_scripts instead?
     add_action('load-edit-tags.php', array(&$this, 'manage_actions'));
 }
示例#3
0
 public function __construct($type)
 {
     // confirm message
     self::$confirm_message = sprintf(' onclick = "return confirm(\'%s\');"', __('You are about to overwrite existing translations. Are you sure?', 'wp-lingotek'));
     // row actions
     self::$actions = array('upload' => array('action' => __('Upload to Lingotek', 'wp-lingotek'), 'progress' => __('Uploading...', 'wp-lingotek'), 'description' => __('Upload this item to Lingotek TMS', 'wp-lingotek')), 'request' => array('action' => __('Request translations', 'wp-lingotek'), 'progress' => __('Requesting translations...', 'wp-lingotek'), 'description' => __('Request translations of this item to Lingotek TMS', 'wp-lingotek')), 'status' => array('action' => __('Update translations status', 'wp-lingotek'), 'progress' => __('Updating translations status...', 'wp-lingotek'), 'description' => __('Update translations status of this item in Lingotek TMS', 'wp-lingotek')), 'download' => array('action' => __('Download translations', 'wp-lingotek'), 'progress' => __('Downloading translations...', 'wp-lingotek'), 'description' => __('Download translations of this item from Lingotek TMS', 'wp-lingotek')), 'delete' => array('action' => __('Disassociate translations', 'wp-lingotek'), 'progress' => __('Disassociating translations...', 'wp-lingotek'), 'description' => __('Disassociate the translations of this item from Lingotek TMS', 'wp-lingotek')));
     // action icons
     self::$icons = array('upload' => array('title' => __('Upload Now', 'wp-lingotek'), 'icon' => 'upload'), 'importing' => array('title' => __('Importing source', 'wp-lingotek'), 'icon' => 'clock'), 'uploaded' => array('title' => __('Source uploaded', 'wp-lingotek'), 'icon' => 'yes'), 'request' => array('title' => __('Request a translation', 'wp-lingotek'), 'icon' => 'plus'), 'pending' => array('title' => __('In Progress', 'wp-lingotek'), 'icon' => 'clock'), 'ready' => array('title' => __('Ready to download', 'wp-lingotek'), 'icon' => 'download'), 'current' => array('title' => __('Current', 'wp-lingotek'), 'icon' => 'edit'), 'not-current' => array('title' => __('The target translation is no longer current as the source content has been updated', 'wp-lingotek'), 'icon' => 'edit'), 'error' => array('title' => __('There was an error contacting Lingotek', 'wp-lingotek'), 'icon' => 'warning'));
     $this->type = $type;
     $this->pllm = $GLOBALS['polylang']->model;
     $this->lgtm = $GLOBALS['wp_lingotek']->model;
     add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
     foreach (array_keys(self::$actions) as $action) {
         add_action('wp_ajax_lingotek_progress_' . $this->type . '_' . $action, array(&$this, 'ajax_' . $action));
     }
 }
示例#4
0
 public function __construct()
 {
     parent::__construct('post');
     // row actions
     add_filter('post_row_actions', array(&$this, 'post_row_actions'), 10, 2);
     add_filter('page_row_actions', array(&$this, 'post_row_actions'), 10, 2);
     // hierarchical post types
     add_filter('media_row_actions', array(&$this, 'post_row_actions'), 10, 2);
     // add bulk actions
     add_action('admin_footer-edit.php', array(&$this, 'add_bulk_actions'));
     // FIXME admin_print_footer_scripts instead?
     add_action('admin_footer-upload.php', array(&$this, 'add_bulk_actions'));
     // manage bulk actions, row actions and icon actions
     add_action('load-edit.php', array(&$this, 'manage_actions'));
     add_action('load-upload.php', array(&$this, 'manage_actions'));
     // add meta box on post and page edit pages, and hook on save
     add_action('add_meta_boxes', array(&$this, 'lingotek_add_meta_boxes'));
     add_action('save_post', array(&$this, 'lingotek_save_meta_boxes'));
 }
示例#5
0
 protected function error_icon_html($column, $object_id, $source_locale = null)
 {
     // checking for api errors
     $source_column = substr($column, 9);
     $column_language_only = substr($column, 0, 11);
     $errors = get_option('lingotek_log_errors');
     if ($source_column == $source_locale) {
         if (isset($errors[$object_id])) {
             $api_error = Lingotek_Actions::retrieve_api_error($errors[$object_id]);
             echo Lingotek_Actions::display_error_icon('error', $api_error);
         }
     }
 }
示例#6
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);
 }
示例#7
0
 protected function get_action_link($args, $warning = false)
 {
     $args['page'] = 'wp-lingotek_manage';
     $args['noheader'] = true;
     return parent::get_action_link($args, $warning);
 }
 public function post_column($column, $post_id)
 {
     $this->content_type = get_post_type($post_id);
     echo $this->_column('post', $column, $post_id);
     // checking for api errors
     $column_language_only = substr($column, 0, 11);
     $group = $this->lgtm->get_group('post', $post_id);
     if ($group) {
         $source = $group->desc_array['lingotek']['source'];
         // remove the remnants of previous API errors if there aren't any current errors
         if (isset($group->desc_array['lingotek']['api_errors'])) {
             $api_errors = $group->desc_array['lingotek']['api_errors'];
             if (empty($api_errors)) {
                 unset($group->desc_array['lingotek']['api_errors']);
             }
         }
         if ($column_language_only == $this->get_first_language_column() && $post_id === $source && isset($group->desc_array['lingotek']['api_errors'])) {
             $error = $this->retrieve_api_error($group);
             echo Lingotek_Actions::display_error_icon('error', $error);
         }
     }
 }