Plugin Directory

Changeset 1200571


Ignore:
Timestamp:
07/16/2015 10:46:16 PM (11 years ago)
Author:
smithworx
Message:

added real-time translation status updates to pages, posts, tags, and categories

Location:
lingotek-translation/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • lingotek-translation/trunk/admin/actions.php

    r1193542 r1200571  
    8787
    8888            'current' => array(
    89                 'title' => __('current', 'wp-lingotek'),
     89                'title' => __('Current', 'wp-lingotek'),
    9090                'icon'  => 'edit'
    9191            ),
  • lingotek-translation/trunk/admin/admin.php

    r1193542 r1200571  
    99     */
    1010    public function __construct() {
    11 
    1211        $plugin = Lingotek::get_instance();
    1312        $this->plugin_slug = $plugin->get_plugin_slug();
     
    2726        add_filter('set-screen-option', array($this, 'set_screen_option'), 10, 3);
    2827
    29         add_action('wp_ajax_'.$this->ajax_dashboard_language_endpoint, array(&$this->dashboard, 'ajax_language_dashboard'));
    30 
     28    add_action('wp_ajax_'.$this->ajax_dashboard_language_endpoint, array(&$this->dashboard, 'ajax_language_dashboard'));
     29    add_action('wp_ajax_get_current_status', array($this,'ajax_get_current_status'));
    3130        //Network admin menu
    3231        add_action('network_admin_menu', array($this, 'add_network_admin_menu'));
    3332    }
     33  public function ajax_get_current_status(){
     34    global $wpdb;
     35    $languages = pll_languages_list(array('fields' => 'locale'));
     36    $object_ids = $_POST['check_ids'];
     37    if($object_ids === null){
     38      return;
     39    }
     40    $terms = isset($_POST['terms_translations']);
     41    $taxonomy = $terms ? 'term_translations'
     42        : 'post_translations';
     43    //this function allows for sanitization of a variable amount of sql IN values
     44    $relationship_placeholders = $this->lingotek_get_placeholders($object_ids);
     45
     46    $terms_query = $wpdb->prepare("SELECT term_tax.*, terms.name AS doc_id, wp_tr.object_id FROM wp_term_taxonomy term_tax "
     47        . "INNER JOIN wp_terms terms ON term_tax.term_id = terms.term_id "
     48        . "INNER JOIN wp_term_relationships wp_tr ON term_tax.term_taxonomy_id = wp_tr.term_taxonomy_id "
     49        . "WHERE taxonomy = '$taxonomy' "
     50        . "AND wp_tr.object_id in ($relationship_placeholders)", $object_ids);
     51    $results = $wpdb->get_results($terms_query);
     52
     53    //package up the db results into an associative array. The main array consists of
     54    //ids and nonces. Each id has a source language, languages with statuses, and a workbench link
     55    $content_metadata = [];
     56    foreach($results as $group => $result){
     57      $id = $result->object_id;
     58      $post_data = unserialize($result->description)['lingotek'];
     59
     60      $source_language = $terms ? pll_get_term_language($post_data['source'], 'locale')
     61        : pll_get_post_language($post_data['source'], 'locale');
     62
     63      $content_metadata[$id]['source'] = $source_language;
     64      $content_metadata[$id]['doc_id'] = $result->doc_id;
     65      $content_metadata[$id][$source_language]['status'] = $post_data['status'];
     66      foreach($post_data['translations']as $locale => $translation_status){
     67        $content_metadata[$id][$locale]['status'] = $translation_status;
     68        $workbench_link = Lingotek_Actions::workbench_link($result->doc_id, $locale);
     69        $content_metadata[$id][$locale]['workbench_link'] = $workbench_link;
     70      }
     71    }
     72
     73    //fills in missing languages to be able to update all the ones listed on Wordpress
     74    foreach($languages as $language){
     75      foreach($content_metadata as $group => $status){
     76        if(!isset($status[$language])){
     77          $content_metadata[$group][$language]['status'] = "none";
     78        }
     79      }
     80    }
     81    //get the nonces associated with the different actions
     82    $content_metadata['request_nonce'] = $this->lingotek_get_matching_nonce('lingotek-request');
     83    $content_metadata['download_nonce'] = $this->lingotek_get_matching_nonce('lingotek-download');
     84    $content_metadata['upload_nonce'] = $this->lingotek_get_matching_nonce('lingotek-upload');
     85    $content_metadata['status_nonce'] = $this->lingotek_get_matching_nonce('lingotek-status');
     86
     87    wp_send_json($content_metadata);
     88  }
     89
     90  public function lingotek_get_matching_nonce($action){
     91    $upload_link = wp_nonce_url(add_query_arg(array(
     92              'action' => $action)),
     93              $action);
     94    $nonce_begin = strpos($upload_link, 'wpnonce=') + 8;
     95    $nonce = substr($upload_link,$nonce_begin);
     96    return $nonce;
     97  }
     98
     99  public function lingotek_get_placeholders($items){
     100    foreach($items as $item){
     101      $placeholders .= '%s,';
     102    }
     103    $placeholders = rtrim($placeholders, ',');
     104    return $placeholders;
     105  }
    34106
    35107    public function get_dashboard_endpoint(){
     
    56128        $scripts = array(
    57129            'progress'  => array(array('edit', 'upload', 'edit-tags', 'translation_page_wp-lingotek_manage', 'translation_page_wp-lingotek_settings'), array('jquery-ui-progressbar', 'jquery-ui-dialog', 'wp-ajax-response'), 1),
     130            'updater'   => array(array('edit', 'upload', 'edit-tags'), array('jquery-ui-progressbar', 'jquery-ui-dialog', 'wp-ajax-response'), 1),
    58131        );
    59132
     
    410483     */
    411484    public function set_screen_option($status, $option, $value) {
    412         if ('lingotek_strings_per_page' == $option)
     485        if ('lingotek_strings_per_page' == $option) {
    413486            return $value;
     487    }
    414488        return $status;
    415489    }
  • lingotek-translation/trunk/admin/filters-columns.php

    r1193542 r1200571  
    4444
    4545        foreach ($this->model->get_languages_list() as $language) {
    46             $columns['language_'.$language->slug] = $language->flag ? $language->flag :
     46            $columns['language_'.$language->locale] = $language->flag ? $language->flag :
    4747                sprintf('<a href="" title="%s">%s</a>',
    4848                    esc_html("$language->name ($language->locale)"),
     
    7171            call_user_func(array($this->model, 'get_' . $type . '_language'), $object_id);
    7272
    73         if (false === strpos($column, 'language_') || !$lang)
     73        if (false === strpos($column, 'language_') || !$lang) {
    7474            return '';
     75    }
    7576
    7677        $language = $this->model->get_language(substr($column, 9));
     
    7980        // yes for uploaded posts, but I will need js as the field is built for all posts
    8081        // /!\ also take care not add this field two times when translations are managed by Polylang
    81 
    8282        // hidden field containing the post language for quick edit (used to filter categories since Polylang 1.7)
    83         if ($column == $this->get_first_language_column() /*&& !$this->model->get_translation_id('post', $post_id)*/)
     83        if ($column == $this->get_first_language_column()  /*&& !$this->model->get_translation_id('post', $post_id)*/) {
    8484            printf('<div class="hidden" id="lang_%d">%s</div>', esc_attr($object_id), esc_html($lang->slug));
     85    }
    8586
    8687        $id = ($inline && $lang->slug != $this->model->get_language($_POST['old_lang'])->slug) ?
     
    9798
    9899        // post ready for upload
    99         if ($this->lgtm->can_upload($type, $object_id) && $object_id == $id)
     100        if ($this->lgtm->can_upload($type, $object_id) && $object_id == $id) {
    100101            return $disabled ?
    101                 ('post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id)) :
    102                 $actions->upload_icon($object_id);
     102                ('post' == $type ? parent::post_column($column, $object_id)
     103          : parent::term_column('', $column, $object_id))
     104          : $actions->upload_icon($object_id);
     105    }
    103106
    104107        // translation disabled
    105         elseif (isset($document->source) && $document->is_disabled_target($language))
     108        elseif (isset($document->source) && $document->is_disabled_target($language)) {
    106109            return 'post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id);
     110    }
    107111
    108112        // source post is uploaded
    109113        elseif (isset($document->source) && $document->source == $id) {
    110114            // source ready for upload
    111             if ($this->lgtm->can_upload($type, $id))
     115            if ($this->lgtm->can_upload($type, $id)) {
    112116                return $actions->upload_icon($id);
     117      }
    113118
    114119            // importing source
    115             if ($id == $object_id && 'importing' == $document->status)
     120            if ($id == $object_id && 'importing' == $document->status) {
    116121                return Lingotek_Actions::importing_icon($document);
     122      }
    117123
    118124            // uploaded
     
    121127
    122128        // translations
    123         elseif (isset($document->translations[$language->locale]) || (isset($document->source) && 'current' == $document->status))
     129        elseif (isset($document->translations[$language->locale]) || (isset($document->source) && 'current' == $document->status)){
    124130            return Lingotek_Actions::translation_icon($document, $language);
     131    }
    125132
    126133        // translations exist but are not managed by Lingotek TMS
    127         elseif (empty($document->source))
    128             return $object_id == $id && !$disabled ?
    129                 $actions->upload_icon($object_id, true) :
    130                 ('post' == $type ? parent::post_column($column, $object_id) : parent::term_column('', $column, $object_id));
     134        elseif (empty($document->source)) {
     135            return $object_id == $id && !$disabled ? $actions->upload_icon($object_id, true)
     136          : ('post' == $type ? parent::post_column($column, $object_id)
     137          : parent::term_column('', $column, $object_id));
     138    }
    131139
    132140        // no translation
    133         else
     141        else {
    134142            return  '<div class="lingotek-color dashicons dashicons-no"></div>';
     143    }
    135144    }
    136145
  • lingotek-translation/trunk/admin/manage/view-string-groups.php

    r1193542 r1200571  
    1717    $table = new Lingotek_Strings_Table($string_actions);
    1818    $action = $table->current_action();
    19     if (!empty($action))
     19    if (!empty($action)) {
    2020        $string_actions->manage_actions($action);
     21  }
    2122
    2223    $data = Lingotek_Model::get_strings();
    23     foreach ($data as $key => $row)
     24    foreach ($data as $key => $row) {
    2425        $data[$key]['row'] = $key; // store the row number for convenience
     26  }
    2527
    2628    $table->prepare_items($data); ?>
     
    3133
    3234    foreach (Lingotek_String_actions::$actions as $action => $strings) {
    33         if (!empty($_GET['bulk-lingotek-' . $action]))
     35        if (!empty($_GET['bulk-lingotek-' . $action])) {
    3436            printf('<div id="lingotek-progressdialog" title="%s"><div id="lingotek-progressbar"></div></div>', $strings['progress']);
     37    }
    3538    }
    3639}
  • lingotek-translation/trunk/admin/post-actions.php

    r1193542 r1200571  
    9595    public function manage_actions() {
    9696        global $typenow;
     97    printf('<div id="auto-update" class="hidden"></div>');
    9798        $post_type = 'load-upload.php' == current_filter() ? 'attachment' : $typenow;
    9899
  • lingotek-translation/trunk/js/progress.js

    r1193542 r1200571  
    11jQuery(document).ready(function($) {
    2 
    32    function lingotek_progress(i) {
    43        if (i < lingotek_data.ids.length) {
  • lingotek-translation/trunk/readme.txt

    r1199446 r1200571  
    55Requires at least: 3.8
    66Tested up to: 4.2
    7 Stable tag: 1.0.1
     7Stable tag: 1.0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    116116== Changelog ==
    117117
     118= 1.0.2 (2015-07-16) =
     119
     120* Real-time translation status updates!
     121
    118122= 1.0.1 (2015-07-14) =
    119123
Note: See TracChangeset for help on using the changeset viewer.