Plugin Directory

Changeset 1726842


Ignore:
Timestamp:
09/08/2017 02:04:09 PM (9 years ago)
Author:
themespond
Message:
  • Fix bug conflicts with WordPress notice
  • Fix bug interrupted by timeout
Location:
tp-image-optimizer
Files:
79 added
11 edited

Legend:

Unmodified
Added
Removed
  • tp-image-optimizer/trunk/assets/css/style.css

    r1725996 r1726842  
    919919  height: 80px;
    920920  margin-top: -20px; }
    921   .io-top-panel .top h2 {
     921  .io-top-panel .top h3 {
    922922    display: inline;
    923923    font-size: 30px;
    924924    font-weight: lighter;
    925     position: absolute; }
     925    position: absolute;
     926    margin-top: 20px; }
    926927  .io-top-panel .top .account-info {
    927928    position: absolute;
  • tp-image-optimizer/trunk/assets/js/ajax.js

    r1725996 r1726842  
    856856                    var title = $("#tp-wrapper-panel").attr("data-title");
    857857                    var range = $("#tp-wrapper-panel").attr("data-range");
     858                    if(title==''){
     859                        title='Last 30 day';
     860                    }
     861                    if(range==''){
     862                        range='last_30';
     863                    }
    858864                    $("input#" + range).prop( "checked", true );
    859865                    if (res.success) {
  • tp-image-optimizer/trunk/assets/scss/style.scss

    r1725996 r1726842  
    10321032    height: 80px;
    10331033    margin-top: -20px;
    1034     h2 {
     1034    h3 {
    10351035      display: inline;
    10361036      font-size: 30px;
    10371037      font-weight: lighter;
    10381038      position: absolute;
     1039      margin-top: 20px;
    10391040    }
    10401041    .account-info {
  • tp-image-optimizer/trunk/includes/class-image.php

    r1725996 r1726842  
    161161                foreach ($images as $image) {
    162162                    $db_table->assign_attachment_to_io($image, "full");
    163                     wp_delete_attachment($s);
    164163                }
    165164            }
  • tp-image-optimizer/trunk/includes/class-lang.php

    r1725996 r1726842  
    1919
    2020        /**
    21          *
     21         * Get main text
    2222         * @return Array Main text
    2323         * @since 1.0.0
  • tp-image-optimizer/trunk/includes/class-metabox.php

    r1725996 r1726842  
    4545
    4646        /**
    47          * TOPBAR
     47         * TOP BAR
    4848         * Include
    4949         * + Dashboard name
     
    5454            ?>
    5555            <div class='top'>
    56                 <h2><?php echo esc_html__("Dashboard", 'tp-image-optimizer'); ?></h2>
     56                <h3><?php echo esc_html__("Dashboard", 'tp-image-optimizer'); ?></h3>
    5757                <div class = 'account-info'>
    5858                    <?php $this->account(); ?>
     
    7070            $check_cron         = get_option('tpio_cron_status');
    7171            $check_cron         = intval($check_cron);
    72             $total_image_cron   = 0;
    73             $current_cron_image = 0;
    7472            $percent_cron       = 0;
    7573            if ($check_cron) {
  • tp-image-optimizer/trunk/includes/class-notice.php

    r1725996 r1726842  
    11<?php
    22
    3 /**
    4  * Notification box
    5  * @since 1.0.7
    6  */
    7 class TP_Image_Optimizer_Notice extends TP_Image_Optimizer_Service {
     3    /**
     4     * Notification box
     5     *
     6     * @since 1.0.7
     7     */
     8    class TP_Image_Optimizer_Notice extends TP_Image_Optimizer_Service {
    89
    9     public function __construct() {
     10        public function __construct() {
    1011
    11         parent::__construct();
     12            parent::__construct();
    1213
    13         add_action( 'wp_ajax_tpio_verify_coupon', array( $this, 'ajax_verify_coupon' ) );
    14     }
    15         /**
    16          * Verify coupon
    17          *
    18          * @category Ajax
    19          * @return json
    20          * @since 1.0.7
    21          */
    22     public function ajax_verify_coupon() {
    23 
    24         if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
    25             return;
    26         }
    27        
    28         if ( empty( $_POST['action'] ) || 'tpio_verify_coupon' !== $_POST['action'] || empty( $_POST['_coupon_nonce'] ) || !wp_verify_nonce( $_POST['_coupon_nonce'], 'tpio_verify_coupon' ) ) {
    29             wp_send_json_error( esc_html__( 'Security key was not validated.', 'tp-image-optimizer' ) );
     14            add_action('wp_ajax_tpio_verify_coupon', array($this, 'ajax_verify_coupon'));
    3015        }
    3116
    32         $coupon_code = isset( $_POST['coupon_code'] ) ? sanitize_text_field( $_POST['coupon_code'] ) : '';
     17        /**
     18         * Verify coupon
     19         *
     20         * @category Ajax
     21         * @return json
     22         * @since    1.0.7
     23         */
     24        public function ajax_verify_coupon() {
    3325
    34         if ( empty( $coupon_code ) ) {
    35             wp_send_json_error( esc_html__( 'Please enter a coupon code', 'tp-image-optimizer' ) );
     26            if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
     27                return;
     28            }
     29
     30            if (empty($_POST['action']) || 'tpio_verify_coupon' !== $_POST['action'] || empty($_POST['_coupon_nonce']) || !wp_verify_nonce($_POST['_coupon_nonce'], 'tpio_verify_coupon')) {
     31                wp_send_json_error(esc_html__('Security key was not validated.', 'tp-image-optimizer'));
     32            }
     33
     34            $coupon_code = isset($_POST['coupon_code']) ? sanitize_text_field($_POST['coupon_code']) : '';
     35
     36            if (empty($coupon_code)) {
     37                wp_send_json_error(esc_html__('Please enter a coupon code', 'tp-image-optimizer'));
     38            }
     39
     40            $response = wp_remote_post($this->__get('service') . 'verify-coupon', array(
     41                'headers' => array(
     42                    'authentication' => $this->__get('token')
     43                ),
     44                'body'    => array(
     45                    'coupon' => $coupon_code,
     46                )
     47            ));
     48
     49            $status_code = wp_remote_retrieve_response_code($response);
     50
     51            if ($status_code == 404) {
     52                wp_send_json_error(esc_html__('Service cannot established.', 'tp-image-optimizer'));
     53            }
     54
     55            if (!is_wp_error($response)) {
     56
     57                $response = wp_remote_retrieve_body($response);
     58
     59                $response = json_decode($response);
     60
     61                if (!empty($response->success)) {
     62
     63                    $html = '<strong>' . esc_html__('Done! Your coupon has been applied successfully.', 'tp-image-optimizer') . '</strong> <br/>';
     64                    $html .= wp_kses_post($response->data);
     65                    delete_transient('tp_image_optimizer_statistics_service');
     66                    wp_send_json_success($html);
     67                } else {
     68                    if (!empty($response->data)) {
     69                        wp_send_json_error($response->data);
     70                    }
     71                }
     72            }
     73
     74            wp_send_json_error(esc_html__('Apply coupon has some error', 'tp-image-optimizer'));
    3675        }
    3776
    38         $response = wp_remote_post( $this->__get( 'service' ) . 'verify-coupon', array(
    39             'headers' => array(
    40                 'authentication' => $this->__get( 'token' )
    41             ),
    42             'body' => array(
    43                 'coupon' => $coupon_code,
    44             )
    45                 ) );
    46 
    47         $status_code = wp_remote_retrieve_response_code( $response );
    48 
    49         if ( $status_code == 404 ) {
    50             wp_send_json_error( esc_html__( 'Service cannot established.', 'tp-image-optimizer' ) );
    51         }
    52 
    53         if ( !is_wp_error( $response ) ) {
    54 
    55             $response = wp_remote_retrieve_body( $response );
    56 
    57             $response = json_decode( $response );
    58 
    59             if ( !empty( $response->success ) ) {
    60 
    61                 $html = '<strong>' . esc_html__( 'Done! Your coupon has been applied successfully.', 'tp-image-optimizer' ) . '</strong> <br/>';
    62                 $html .= wp_kses_post( $response->data );
    63                 delete_transient( 'tp_image_optimizer_statistics_service' );
    64                 wp_send_json_success( $html );
    65             } else if ( !empty( $response->data ) ) {
    66                 wp_send_json_error( $response->data );
    67             }
    68         }
    69 
    70         wp_send_json_error( esc_html__( 'Apply coupon has some error', 'tp-image-optimizer' ) );
    7177    }
    7278
    73 }
    74 
    75 new TP_Image_Optimizer_Notice();
     79    new TP_Image_Optimizer_Notice();
  • tp-image-optimizer/trunk/includes/class-service.php

    r1725996 r1726842  
    326326            }
    327327
    328 
    329328            /**
    330329             * Request ThemesPond compress service
     
    340339             * @since    1.0.0
    341340             */
    342             public static function request_service($attachment_id = '', $size_name = 'full', $timeout = 450) {
     341            public static function request_service($attachment_id = '', $size_name = 'full', $timeout = 4500) {
    343342                update_option('tpio_id_processing', $attachment_id); // Update image processing
    344 
     343                ini_set('max_execution_time', 0);// Fix if timeout is low
    345344                $db_table = new TP_Image_Optimizer_Table();
    346345                $service = TP_Image_Optimizer_Service::$service . 'compress';
     
    354353                    'size'     => $size_name,
    355354                    'old_size' => $file_size_old,
    356                     'new_size' => $file_size_old
     355                    'new_size' => $file_size_old,
     356                    'error_log' => esc_html__("Unexpected error!", 'tp-image-optimizer')
    357357                );
     358
    358359                $check_image_on_db = $db_table->check_image_size_on_db($attachment_id, $size_name);
    359360                if (!$check_image_on_db && $file_size_old > 0) {
    360361                    $db_table->assign_attachment_to_io($attachment_id, $size_name);
    361362                }
    362                 // Validate image mime
    363                 // Reject unsupported image type
     363                // Validate supported image mime
    364364                $image_mime = get_post_mime_type($attachment_id);
    365365                if (($image_mime != 'image/png') && ($image_mime != 'image/jpeg')) {
    366                     $data_return['success'] = false;
    367366                    $image_mime = strtoupper(str_replace('image/', '', $image_mime));
    368367                    $data_return['error_log'] = esc_html__(sprintf("%s isn't support at this time", $image_mime), 'tp-image-optimizer');
     
    375374                    $data_return['success'] = true;
    376375                    $data_return['error_log'] = esc_html__("404 error: This attachment image (original image or cropped image by WordPress) has been existing in Database, but removed.", "tp-image-optimizer");
    377                     // Attachment image has been deleted, need remove this ID from IO Database Table
    378                     //$db_table->remove_deleted_attachment_image($attachment_id);
     376                    //$db_table->remove_deleted_attachment_image($attachment_id);// Remove this ID from IO Database Table
    379377                    return $data_return;
    380378                }
     
    388386                // Validate Image Type
    389387                if (!wp_attachment_is_image($attachment_id)) {
    390                     $data_return['success'] = false;
    391388                    $data_return['error_log'] = esc_html__("This attachment isn't image type", 'tp-image-optimizer');
    392389                    // Remove this ID from IO Database Table
     
    408405                    ),
    409406                    'timeout' => $timeout,
     407                    'body'    => file_get_contents($image_file)
    410408                );
    411                 $data['body'] = file_get_contents($image_file);
    412409                // Sending to service
    413410                $response = wp_remote_post($service, $data);
     
    420417                    $error_remote = "Something went wrong: $error_message";
    421418                    update_option('tp_remote_error', $error_remote); // Log to database
    422 
    423                     return TP_Image_Optimizer_Service::request_service($attachment_id, $size_name, 900);
     419                   
     420                    $result = TP_Image_Optimizer_Service::request_service($attachment_id, $size_name, 9000);
     421
     422                    return $result;
    424423                }
    425424                /**
    426                  * Unexpected error
     425                 * Service error
    427426                 */
    428427                if ($status_code != 200) {
     
    438437
    439438                if (($response == '') || ($response == 'false')) { //Timeout or no internet connection
    440                     return TP_Image_Optimizer_Service::request_service($attachment_id, $size_name, 900);
     439                    // Check number error by timeout
     440                    $number = intval(get_option("tpio_timeout_count"));
     441                    $number = $number + 1;
     442                    update_option('tpio_timeout_count', $number);
     443                    if(number<2){
     444                        $result = TP_Image_Optimizer_Service::request_service($attachment_id, $size_name, 9000);
     445                        return $result;
     446                    } else{
     447                        $data_return['error_log'] = esc_html__('Cannot process this image because maximum execution timeout ! Please increase max_execution_time in php.ini to fix this.', 'tp-image-optimizer');
     448                        return $data_return;
     449                    }
    441450                }
    442451
     
    444453                 * VALIDATE DATA RESPONSE IS IMAGE or NOT *
    445454                 * *************************************** */
    446 
    447455                // Condition 1 : Service return error
    448                 $check = isJSON($response);
    449                 // If $check == true, it mean server return an error
    450                 // Condition 2 : Unexpected error
     456                $check = isJSON($response);// If $check == true, it mean server return an error
     457                // Condition 2 : API unexpected error
    451458                $check2 = false;
    452 
    453                 if ((strpos($response, 'something went wrong') !== false) || (strpos($response, '<html>') !== false)) {
     459                if ((strpos($response, 'something went wrong') !== false) || (strpos($response, '<html') !== false)) {
    454460                    $check2 = true;
    455461                }
     462
     463                /**
     464                 * RETURN RESULT --------------------------------------------------------------------------------------
     465                 */
    456466                if (!$check && !$check2) {
    457                     $origin_path = tp_image_optimizer_scaled_image_path($attachment_id, $size_name);
     467                    $data_return['success'] = true;
     468                    unset($data_return['error_log']); // No error
     469                    delete_option('tpio_timeout_count'); // Clear timeout statistics
    458470                    /**
    459471                     *  Replace original attachment image by optimized file
    460472                     *  Override original image by response image from PostImage Service
    461473                     */
     474                    $origin_path = tp_image_optimizer_scaled_image_path($attachment_id, $size_name);
    462475                    $img_origin_load = @fopen($origin_path, "w");
    463476                    $result_write_file = fwrite($img_origin_load, $response);
    464                     // Result
    465                     $data_return['new_size'] = $result_write_file;
    466                     $data_return['success'] = true;
     477                    // Notice for user
    467478                    $data_return['log'] = esc_html__("Success optimizer #", 'tp-image-optimizer') . $attachment_id . ' - ' . $size_name;
    468                     // Update current size after optimized
     479                    $data_return['new_size'] = $result_write_file;// Update current size after optimized
    469480                    $db_table->update_current_size_for_attachment($attachment_id, $size_name, $result_write_file);
    470 
    471                     return $data_return;
    472481                } else {
    473                     if ($check2) {
    474                         $data_return['success'] = false;
    475                         $data_return['error_log'] = esc_html__("Unexpected error!", 'tp-image-optimizer');
    476 
    477                         return $data_return;
    478                     }
    479                     /**
    480                      * SERVER RETURN JSON LOG
    481                      * Catch error
    482                      */
    483                     $error_data = json_decode($response);
    484 
    485                     if ($error_data->status == 400) {
    486                         $data_return['new_size'] = $file_size_old;
    487                         $data_return['log'] = esc_html__("Success optimizer #", 'tp-image-optimizer') . $attachment_id;
    488                         $data_return['success'] = true;
    489 
    490                         return ($data_return);
    491                     }
    492                     // Logging
    493                     $data_return['error_log'] = $error_data->error;
    494                     $data_return['success'] = false;
    495 
    496                     return ($data_return);
    497                 }
    498                 $data_return['success'] = false;
    499                 $data_return['error_log'] = esc_html__("Unexpected error!", 'tp-image-optimizer');
    500 
     482                    if (!$check2) {
     483                        /**
     484                         * SERVER RETURN JSON LOG
     485                         * Catch error
     486                         */
     487                        $error_data = json_decode($response);
     488                        $data_return['error_log'] = $error_data->error;
     489                    }
     490                }
    501491                return $data_return;
    502492            }
    503493
    504494            /**
    505              * Cancel cronjob
     495             * Cancel WordPress cronjob
    506496             *
    507497             * @since 1.0.8
     
    531521            /**
    532522             * Manual compress
    533              *
     523             * 
     524             * @category Ajax
    534525             * @since 1.0.8
    535526             */
     
    621612             * Connect service and get
    622613             *
    623              * @param type $range
     614             * @param string $range
    624615             *
    625616             */
  • tp-image-optimizer/trunk/languages/tp-image-optimizer.pot

    r1725996 r1726842  
    44"Project-Id-Version: PACKAGE VERSION\n"
    55"Report-Msgid-Bugs-To: \n"
    6 "POT-Creation-Date: 2017-09-07 01:53+0000\n"
     6"POT-Creation-Date: 2017-09-08 06:52+0000\n"
    77"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    88"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    5656msgstr ""
    5757
    58 #: includes/class-image.php:192
     58#: includes/class-image.php:191
    5959msgid "Saving "
    6060msgstr ""
    6161
    62 #: includes/class-image.php:195
     62#: includes/class-image.php:194
    6363msgid "%"
    6464msgstr ""
    6565
    66 #: includes/class-image.php:247
     66#: includes/class-image.php:246
    6767msgid "All image sizes were updated successfully."
    6868msgstr ""
    6969
    70 #: includes/class-image.php:280
     70#: includes/class-image.php:279
    7171msgid ""
    7272"This feature is only compatible with WordPress 4.3+. Update your WordPress "
     
    7474msgstr ""
    7575
    76 #: includes/class-image.php:293
     76#: includes/class-image.php:292
    7777msgid "No media files found."
    7878msgstr ""
    7979
    80 #: includes/class-image.php:295
     80#: includes/class-image.php:294
    8181msgid "Refresh"
    8282msgstr ""
     
    314314msgstr ""
    315315
     316#: includes/class-metabox.php:166
     317msgid "Last 30 day"
     318msgstr ""
     319
     320#: includes/class-metabox.php:167
     321msgid "Current month"
     322msgstr ""
     323
    316324#: includes/class-metabox.php:168
    317 msgid "Last 30 day"
    318 msgstr ""
    319 
    320 #: includes/class-metabox.php:169
    321 msgid "Current month"
    322 msgstr ""
    323 
    324 #: includes/class-metabox.php:170
    325325msgid "Last month"
    326326msgstr ""
    327327
     328#: includes/class-metabox.php:200
     329msgid "Lower"
     330msgstr ""
     331
     332#: includes/class-metabox.php:201
     333msgid "Medium"
     334msgstr ""
     335
    328336#: includes/class-metabox.php:202
    329 msgid "Lower"
     337msgid "High (Recommend)"
    330338msgstr ""
    331339
    332340#: includes/class-metabox.php:203
    333 msgid "Medium"
    334 msgstr ""
    335 
    336 #: includes/class-metabox.php:204
    337 msgid "High (Recommend)"
    338 msgstr ""
    339 
    340 #: includes/class-metabox.php:205
    341341msgid "Very high"
    342342msgstr ""
    343343
    344 #: includes/class-notice.php:29
     344#: includes/class-notice.php:31
    345345msgid "Security key was not validated."
    346346msgstr ""
    347347
    348 #: includes/class-notice.php:35
     348#: includes/class-notice.php:37
    349349msgid "Please enter a coupon code"
    350350msgstr ""
    351351
    352 #: includes/class-notice.php:50 includes/class-service.php:145
     352#: includes/class-notice.php:52 includes/class-service.php:145
    353353msgid "Service cannot established."
    354354msgstr ""
    355355
    356 #: includes/class-notice.php:61
     356#: includes/class-notice.php:63
    357357msgid "Done! Your coupon has been applied successfully."
    358358msgstr ""
    359359
    360 #: includes/class-notice.php:70
     360#: includes/class-notice.php:74
    361361msgid "Apply coupon has some error"
    362362msgstr ""
     
    370370msgstr ""
    371371
    372 #: includes/class-service.php:376
     372#: includes/class-service.php:356
     373msgid "Unexpected error!"
     374msgstr ""
     375
     376#: includes/class-service.php:375
    373377msgid ""
    374378"404 error: This attachment image (original image or cropped image by "
     
    376380msgstr ""
    377381
    378 #: includes/class-service.php:384
     382#: includes/class-service.php:382
    379383msgid "Image is too small"
    380384msgstr ""
    381385
    382 #: includes/class-service.php:391
     386#: includes/class-service.php:388
    383387msgid "This attachment isn't image type"
    384388msgstr ""
    385389
    386 #: includes/class-service.php:432
     390#: includes/class-service.php:431
    387391msgid "Cannot connect to service."
    388392msgstr ""
    389393
    390 #: includes/class-service.php:467 includes/class-service.php:487
     394#: includes/class-service.php:447
     395msgid ""
     396"Cannot process this image because maximum execution timeout ! Please "
     397"increase max_execution_time in php.ini to fix this."
     398msgstr ""
     399
     400#: includes/class-service.php:478
    391401msgid "Success optimizer #"
    392 msgstr ""
    393 
    394 #: includes/class-service.php:475 includes/class-service.php:499
    395 msgid "Unexpected error!"
    396402msgstr ""
    397403
  • tp-image-optimizer/trunk/readme.txt

    r1725996 r1726842  
    44Tags: image compressor, png compressor, image size reducer, image optimizer, compress image, optimize image, smaller image, compress jpg, jpg compressor, free image optimizer, compress, image, optimize, performance, resize, lossless, optimization 
    55Requires at least: 4.0   
    6 Tested up to: 4.8   
    7 Stable tag: 2.0.0   
     6Tested up to: 4.8.1
     7Stable tag: 2.0.1
    88License: GPLv3   
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html   
     
    6161
    62621. Install to get a free token
    63 2. Enjoin with TP Image Optimizer
     632. Settings screen
     643. Enjoin with TP Image Optimizer
    6465
    6566== Upgrade Notice ==
     
    6869
    6970== Changelog ==
     71= 2.0.1 (September 08, 2017) : =
     72* Fix bug conflicts with WordPress notice
     73* Fix bug interrupted by timeout
    7074
    7175= 2.0.0 (September 07, 2017) : =
  • tp-image-optimizer/trunk/tp-image-optimizer.php

    r1725996 r1726842  
    44 * Plugin Name: TP Image Optimizer   
    55 * Description: A WordPress plugin that allows you to reduce image file sizes and optimize all images in the media library.   
    6  * Version: 2.0.0
     6 * Version: 2.0.1
    77 * Author: ThemesPond   
    88 * Author URI: https://themespond.com/   
     
    1111 *
    1212 * Requires at least: 4.0   
    13  * Tested up to: 4.8   
     13 * Tested up to: 4.8.1
    1414 * Text Domain: tp-image-optimizer   
    1515 * Domain Path: /languages/   
Note: See TracChangeset for help on using the changeset viewer.