Plugin Directory

Changeset 2771692


Ignore:
Timestamp:
08/17/2022 02:43:12 PM (4 years ago)
Author:
frpet
Message:

Increase timeout for duplicate post

Location:
easytranslate/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • easytranslate/trunk/README.txt

    r2770454 r2771692  
    55Requires at least: 4.7
    66Tested up to: 6.0
    7 Stable tag: 4.4
     7Stable tag: 4.5
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • easytranslate/trunk/admin/class-easy-translate-post-translation-list.php

    r2768836 r2771692  
    307307
    308308        // check for table bulk actions
    309         if (isset($_REQUEST['action']) && isset($_REQUEST['posts']) && isset($_REQUEST['target_languages'])) {
    310 
    311             $nonce = wp_unslash($_REQUEST['_wpnonce']);
    312             // verify the nonce.
    313             /*
    314              * Note: the nonce field is set by the parent class
    315              * wp_nonce_field( 'bulk-' . $this->_args['plural'] );
    316              *
    317              */
     309        if (isset($_REQUEST['action']) && isset($_REQUEST['posts']) && !empty($_REQUEST['posts']) && isset($_REQUEST['target_languages'])) {
     310            $nonce = wp_unslash($_POST['_wpnonce']);
    318311            if (!wp_verify_nonce($nonce, 'bulk-translations')) {
    319312                $this->invalid_nonce_redirect();
    320             } else {
    321                 $a_string_id = [];
    322                 $content = [];
    323 
    324                 foreach ($_REQUEST['posts'] as $post_id) {
    325                     $content[] = $this->get_post_content($post_id, $a_string_id);
    326                 }
    327 
    328                 $urlParts = parse_url(home_url());
    329                 $hostName = $urlParts['host'] ?? get_site_url();
    330                 $name = '[' . date('Y-m-d') . '] ' . $hostName . ' page translations';
    331 
    332                 $workflow = 'translation';
    333                 if ($_REQUEST['workflow'] === 'self+machine_translation') {
    334                     $workflow = 'self+machine_translation';
    335                 }
    336 
    337                 if ($content[0]) {
    338                     $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION);
    339                     $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options));
    340                     $response = $service->translate(
    341                         $this->source_language,
    342                         array_keys($_REQUEST['target_languages']),
    343                         $content,
    344                         $workflow,
    345                         $name
    346                     );
    347                     if ($response['error'] ?? false) {
    348                         add_settings_error(
    349                             '',
    350                             'translate-error',
    351                             $response['error'] ?? '',
    352                             'error'
    353                         );
    354 
    355                         return null;
    356                     }
    357                     add_settings_error(
    358                         '',
    359                         'translate-success',
    360                         __('Sent successfully!', EASY_TRANSLATE),
    361                         'success'
    362                     );
    363                     $this->update_string_status($a_string_id, self::STATUS_WAITING);
    364                     $this->update_duplicate_status(
    365                         $_REQUEST['posts'],
    366                         array_keys($_REQUEST['target_languages']),
    367                         self::STATUS_WAITING
    368                     );
    369                 } else {
    370                     add_settings_error(
    371                         '',
    372                         'translate-error',
    373                         __('Unable to get content for translation', EASY_TRANSLATE),
    374                         'error'
    375                     );
    376                 }
    377             }
     313
     314                return null;
     315            }
     316
     317            $a_string_id = [];
     318            $content = [];
     319
     320            foreach ($_REQUEST['posts'] as $post_id) {
     321                $content[] = $this->get_post_content($post_id, $a_string_id);
     322            }
     323
     324            $urlParts = parse_url(home_url());
     325            $hostName = $urlParts['host'] ?? get_site_url();
     326            $name = '[' . date('Y-m-d') . '] ' . $hostName . ' page translations';
     327
     328            $workflow = 'translation';
     329            if ($_REQUEST['workflow'] === 'self+machine_translation') {
     330                $workflow = 'self+machine_translation';
     331            }
     332            if (!isset($content[0])) {
     333                add_settings_error(
     334                    '',
     335                    'translate-error',
     336                    __('Unable to get content for translation', EASY_TRANSLATE),
     337                    'error'
     338                );
     339
     340                return null;
     341            }
     342
     343            $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION);
     344            $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options));
     345            $response = $service->translate(
     346                $this->source_language,
     347                array_keys($_REQUEST['target_languages']),
     348                $content,
     349                $workflow,
     350                $name
     351            );
     352            if ($response['error'] ?? false) {
     353                add_settings_error(
     354                    '',
     355                    'translate-error',
     356                    $response['error'] ?? '',
     357                    'error'
     358                );
     359
     360                return null;
     361            }
     362            add_settings_error(
     363                '',
     364                'translate-success',
     365                __('Sent successfully!', EASY_TRANSLATE),
     366                'success'
     367            );
     368            $this->update_string_status($a_string_id, self::STATUS_WAITING);
     369            $this->update_duplicate_status(
     370                $_REQUEST['posts'],
     371                array_keys($_REQUEST['target_languages']),
     372                self::STATUS_WAITING
     373            );
    378374        }
    379375    }
     
    462458    protected function get_per_page_option()
    463459    {
    464 
    465460        return self::PER_PAGE_OPTION;
    466 
     461    }
     462
     463    protected function pagination($which)
     464    {
     465        if (empty($this->_pagination_args)) {
     466            return;
     467        }
     468
     469        $total_items = $this->_pagination_args['total_items'];
     470        $total_pages = $this->_pagination_args['total_pages'];
     471        $infinite_scroll = false;
     472        if (isset($this->_pagination_args['infinite_scroll'])) {
     473            $infinite_scroll = $this->_pagination_args['infinite_scroll'];
     474        }
     475
     476        if ('top' === $which && $total_pages > 1) {
     477            $this->screen->render_screen_reader_content('heading_pagination');
     478        }
     479
     480        $output = '<span class="displaying-num">' . sprintf(
     481            /* translators: %s: Number of items. */
     482                _n('%s item', '%s items', $total_items),
     483                number_format_i18n($total_items)
     484            ) . '</span>';
     485
     486        $current = $this->get_pagenum();
     487        $removable_query_args = wp_removable_query_args();
     488
     489        $current_url = set_url_scheme('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
     490        $current_url = remove_query_arg($removable_query_args, $current_url);
     491        $current_url = add_query_arg('s', esc_attr(wp_unslash($_REQUEST['s'] ?? '')), $current_url);
     492
     493        $page_links = [];
     494
     495        $total_pages_before = '<span class="paging-input">';
     496        $total_pages_after = '</span></span>';
     497
     498        $disable_first = false;
     499        $disable_last = false;
     500        $disable_prev = false;
     501        $disable_next = false;
     502
     503        if (1 == $current) {
     504            $disable_first = true;
     505            $disable_prev = true;
     506        }
     507        if ($total_pages == $current) {
     508            $disable_last = true;
     509            $disable_next = true;
     510        }
     511
     512        if ($disable_first) {
     513            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
     514        } else {
     515            $page_links[] = sprintf(
     516                "<a class='first-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     517                esc_url(remove_query_arg('paged', $current_url)),
     518                __('First page'),
     519                '&laquo;'
     520            );
     521        }
     522
     523        if ($disable_prev) {
     524            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
     525        } else {
     526            $page_links[] = sprintf(
     527                "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     528                esc_url(add_query_arg('paged', max(1, $current - 1), $current_url)),
     529                __('Previous page'),
     530                '&lsaquo;'
     531            );
     532        }
     533
     534        if ('bottom' === $which) {
     535            $html_current_page = $current;
     536            $total_pages_before = '<span class="screen-reader-text">' . __('Current Page') . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
     537        } else {
     538            $html_current_page = sprintf(
     539                "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
     540                '<label for="current-page-selector" class="screen-reader-text">' . __('Current Page') . '</label>',
     541                $current,
     542                strlen($total_pages)
     543            );
     544        }
     545        $html_total_pages = sprintf("<span class='total-pages'>%s</span>", number_format_i18n($total_pages));
     546        $page_links[] = $total_pages_before . sprintf(
     547            /* translators: 1: Current page, 2: Total pages. */
     548                _x('%1$s of %2$s', 'paging'),
     549                $html_current_page,
     550                $html_total_pages
     551            ) . $total_pages_after;
     552
     553        if ($disable_next) {
     554            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
     555        } else {
     556            $page_links[] = sprintf(
     557                "<a class='next-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     558                esc_url(add_query_arg('paged', min($total_pages, $current + 1), $current_url)),
     559                __('Next page'),
     560                '&rsaquo;'
     561            );
     562        }
     563
     564        if ($disable_last) {
     565            $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
     566        } else {
     567            $page_links[] = sprintf(
     568                "<a class='last-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
     569                esc_url(add_query_arg('paged', $total_pages, $current_url)),
     570                __('Last page'),
     571                '&raquo;'
     572            );
     573        }
     574
     575        $pagination_links_class = 'pagination-links';
     576        if (!empty($infinite_scroll)) {
     577            $pagination_links_class .= ' hide-if-js';
     578        }
     579        $output .= "\n<span class='$pagination_links_class'>" . implode("\n", $page_links) . '</span>';
     580
     581        if ($total_pages) {
     582            $page_class = $total_pages < 2 ? ' one-page' : '';
     583        } else {
     584            $page_class = ' no-pages';
     585        }
     586        $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
     587
     588        echo $this->_pagination;
    467589    }
    468590
  • easytranslate/trunk/admin/class-easy-translate-string-translation-list.php

    r2742144 r2771692  
    281281        // check for table bulk actions
    282282        if ('translate_strings' === ($_POST['action'] ?? null) && isset($_POST['strings']) && isset($_POST['target_languages'])) {
    283 
    284283            $nonce = wp_unslash($_POST['_wpnonce']);
    285             // verify the nonce.
    286             /*
    287              * Note: the nonce field is set by the parent class
    288              * wp_nonce_field( 'bulk-' . $this->_args['plural'] );
    289              *
    290              */
    291284            if (!wp_verify_nonce($nonce, 'bulk-translations')) {
    292285                $this->invalid_nonce_redirect();
    293             } else {
    294                 $content = $this->get_strings_content($_POST['strings']);
    295 
    296                 $workflow = 'translation';
    297                 if ($_POST['workflow'] === 'self+machine_translation') {
    298                     $workflow = 'self+machine_translation';
    299                 }
    300 
    301                 $urlParts = parse_url(home_url());
    302                 $hostName = $urlParts['host'] ?? get_site_url();
    303                 $name = '[' . date('Y-m-d') . '] ' . $hostName . ' string translations';
    304 
    305                 $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION);
    306                 $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options));
    307                 $response = $service->translate(
    308                     $this->source_language,
    309                     array_keys($_POST['target_languages']),
    310                     [$content],
    311                     $workflow,
    312                     $name
     286
     287                return null;
     288            }
     289
     290            $content = $this->get_strings_content($_POST['strings']);
     291
     292            $workflow = 'translation';
     293            if ($_POST['workflow'] === 'self+machine_translation') {
     294                $workflow = 'self+machine_translation';
     295            }
     296
     297            $urlParts = parse_url(home_url());
     298            $hostName = $urlParts['host'] ?? get_site_url();
     299            $name = '[' . date('Y-m-d') . '] ' . $hostName . ' string translations';
     300
     301            $options = get_option(EASY_TRANSLATE_INTEGRATION_OPTION);
     302            $service = new Easy_Translate_API_Laas(Easy_Translate_API_Integration::map_fields($options));
     303            $response = $service->translate(
     304                $this->source_language,
     305                array_keys($_POST['target_languages']),
     306                [$content],
     307                $workflow,
     308                $name
     309            );
     310
     311            if ($response['error'] ?? false) {
     312                add_settings_error(
     313                    '',
     314                    'translate-error',
     315                    $response['error'] ?? '',
     316                    'error'
    313317                );
    314318
    315                 if ($response['error'] ?? false) {
    316                     add_settings_error(
    317                         '',
    318                         'translate-error',
    319                         $response['error'] ?? '',
    320                         'error'
    321                     );
    322 
    323                     return null;
    324                 }
    325 
    326                 if ($this->update_string_status($_POST['strings'], self::STATUS_WAITING) !== false) {
    327                     add_settings_error(
    328                         '',
    329                         'translate-success',
    330                         __('Sent successfully!', EASY_TRANSLATE),
    331                         'success'
    332                     );
    333                 }
     319                return null;
     320            }
     321
     322            if ($this->update_string_status($_POST['strings'], self::STATUS_WAITING) !== false) {
     323                add_settings_error(
     324                    '',
     325                    'translate-success',
     326                    __('Sent successfully!', EASY_TRANSLATE),
     327                    'success'
     328                );
    334329            }
    335330        }
  • easytranslate/trunk/admin/class-easy-translate-translation-list.php

    r2768836 r2771692  
    6868        if ($this->is_ready) {
    6969            $this->translation_languages = self::get_target_languages();
    70         }
    71         if (isset($_POST['s']) && !empty($_POST['s'])
    72             && in_array(
    73                 $_REQUEST['page'],
    74                 [Easy_Translate_Admin::MENU_PARTIAL_TRANSLATIONS, Easy_Translate_Admin::MENU_MAIN]
    75             )
    76         ) {
    77             $_SERVER['REQUEST_URI'] .= '&s=' . esc_attr(wp_unslash($_POST['s']));
    78             wp_redirect($_SERVER['REQUEST_URI']);
    7970        }
    8071
     
    307298     *
    308299     * @param array $ids
     300     * @param array $langs
    309301     * @param int   $status
    310302     */
    311     public static function update_duplicate_status($ids, $langs, $status)
     303    public static function update_duplicate_status(array $ids, array $langs, int $status)
    312304    {
    313305        foreach ($ids as $post_id) {
     
    350342            ],
    351343            'cookies' => $_COOKIE,
     344            'timeout' => 300,
    352345        ];
    353346        wp_remote_post($url, $args);
     
    531524    public static function update_translations_status($translation_id, $status)
    532525    {
    533 
    534         global $wpdb;
    535         $wpdb->update("{$wpdb->prefix}icl_translation_status", ['status' => $status],
    536             ['translation_id' => $translation_id], ['%d'], ['%d']);
    537 
     526        global $wpdb;
     527        $wpdb->update("{$wpdb->prefix}icl_translation_status",
     528            ['status' => $status],
     529            ['translation_id' => $translation_id],
     530            ['%d'],
     531            ['%d']
     532        );
    538533    }
    539534
  • easytranslate/trunk/easy-translate.php

    r2770454 r2771692  
    1515 * Plugin URI:        https://www.easytranslate.com/en/integrations/cms/wordpress-plugin/
    1616 * Description:       This is a short description of what the plugin does. It's displayed in the WordPress admin area.
    17  * Version:           1.7.1
     17 * Version:           1.7.2
    1818 * Author:            EasyTranslate
    1919 * Author URI:        https://easytranslate.com
     
    3434 * Rename this for your plugin and update it as you release new versions.
    3535 */
    36 define('EASY_TRANSLATE_VERSION', '1.7.1');
     36define('EASY_TRANSLATE_VERSION', '1.7.2');
    3737
    3838/**
Note: See TracChangeset for help on using the changeset viewer.