Plugin Directory

Changeset 1901135


Ignore:
Timestamp:
06/29/2018 11:50:49 AM (8 years ago)
Author:
octify
Message:

Octify 1.3!

Location:
octify/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • octify/trunk/Controller/Compress.php

    r1868268 r1901135  
    3333        }
    3434
    35         if ( get_option( self::IN_COMPRESS ) == false ) {
     35//      if ( get_option( self::IN_COMPRESS ) == false ) {
     36//          return;
     37//      }
     38
     39        if ( self::isLocked() ) {
    3640            return;
    37         }
    38 
    39         if ( self::isLocked() ) {
    40             //return;
    4141        }
    4242
     
    7575                $meta = get_post_meta( $id, OctifyApi::META_NAME, true );
    7676                $time = $meta['started'];
     77                if ( $meta['started'] == false ) {
     78                    $meta = array(
     79                        'started' => time(),
     80                        'retry'   => 1
     81                    );
     82                    update_post_meta( $id, OctifyApi::META_NAME, $meta );
     83                }
    7784                if ( strtotime( '+60 seconds', $time ) < time() ) {
    7885                    //we should retry it
     
    8794                        $res = OctifyApi::sendEnvelope( array( $id ) );
    8895                        update_post_meta( $id, OctifyApi::META_NAME, array(
    89                             'started'  => time(),
    90                             'retry' => $retry
     96                            'started' => time(),
     97                            'retry'   => $retry
    9198                        ) );
    9299                        self::processResponse( $res, $retry );
     
    94101                }
    95102            }
     103            self::releaseLock();
    96104            wp_send_json_success( array(
    97105                'percent' => self::calPercent(),
     
    194202        update_option( self::LOCK, time() );
    195203    }
     204
     205    public function cancelBulkOctify() {
     206        $pending = OctifyApi::findImages( 'pending' );
     207        foreach ( $pending as $image ) {
     208            delete_post_meta( $image->ID, OctifyApi::META_STATUS );
     209            delete_post_meta( $image->ID, OctifyApi::META_NAME );
     210        }
     211        wp_send_json_success();
     212    }
    196213}
  • octify/trunk/Libs/OctifyApi.php

    r1868268 r1901135  
    223223            $imagePath             = $uploadDirs['basedir'] . '/' . $imageMeta['file'];
    224224            $imageToProcess[ $id ] = array(
    225                 'site_url'  => site_url(),
    226                 'meta'      => $id,
    227                 'image_url' => $imageUrl,
    228                 'method'    => $settings['mode'],
    229                 'keep_exif' => $settings['keep_exif'],
    230                 'postback'  => '/wp-admin/admin-ajax.php?action=octify_postback',
    231                 'secret'    => self::getLicense(),
    232                 'api_key'   => self::getLicense(),
    233                 'filesize'  => filesize( $imagePath )
     225                'site_url'      => site_url(),
     226                'meta'          => $id,
     227                'image_url'     => $imageUrl,
     228                'method'        => $settings['mode'],
     229                'keep_exif'     => $settings['keep_exif'],
     230                'resize'        => $settings['resize'],
     231                'resize_width'  => $settings['resize_width'],
     232                'resize_height' => $settings['resize_height'],
     233                'postback'      => '/wp-admin/admin-ajax.php?action=octify_postback',
     234                'secret'        => self::getLicense(),
     235                'api_key'       => self::getLicense(),
     236                'filesize'      => filesize( $imagePath )
    234237            );
    235238        }
     
    254257                }
    255258                $body = wp_remote_retrieve_body( $request );
     259                //var_dump($body);die;
    256260                $body = json_decode( $body, true );
    257261                if ( ! is_array( $body ) ) {
    258 
    259262                    return new \WP_Error( 'invalid_response', 'Please try again' );
    260263                }
  • octify/trunk/Octify.php

    r1868268 r1901135  
    44 * Plugin URI: https://octify.io
    55 * Description: Octify Image Compression for WordPress.
    6  * Version: 1.2
     6 * Version: 1.3
    77 * Author: Octify
    88 * Author URI: https://octify.io
     
    6060        //
    6161        add_action( 'wp_ajax_start_bulk_octify', array( '\Octify\Controller\Compress', 'bulkOctify' ) );
     62        add_action( 'wp_ajax_cancel_octify_compress', array( '\Octify\Controller\Compress', 'cancelBulkOctify' ) );
    6263        add_action( 'wp_ajax_get_bulk_octify_status', array( '\Octify\Controller\Compress', 'getOctifyStatus' ) );
    6364        //
     
    7071        if ( $revertAll ) {
    7172            add_action( 'wp_loaded', array( &$this, 'revertAll' ) );
    72         }
    73 
    74 //
    75     }
    76 
    77     public function maybeResetStatus() {
    78         //find all the pending images
    79         $pending = \Octify\Libs\OctifyApi::findImages( 'pending' );
    80         if ( count( $pending ) == 0 ) {
    81             return;
    82         }
    83 
    84         //check time
    85         $data = array();
    86         foreach ( $pending as $image ) {
    87             $data[] = wp_get_attachment_image_url( $image->ID, 'full' );
    88         }
    89 
    90         $request = wp_remote_post( \Octify\Libs\OctifyApi::API_ENDPOINT . 'v1/compress/check_images_status', array(
    91             'body' => array(
    92                 'site_url' => network_site_url(),
    93                 'images'   => $data
    94             )
    95         ) );
    96 
    97         $body = wp_remote_retrieve_body( $request );
    98         $data = json_decode( $body, true );
    99         foreach ( $data as $datum ) {
    100             update_post_meta( $datum['meta'], \Octify\Libs\OctifyApi::META_STATUS, 'error' );
    101             update_post_meta( $datum['meta'], \Octify\Libs\OctifyApi::META_NAME, array(
    102                 'error' => __( "Oops! Your image timed out, try again or contact your host to raise your timeout limit", octify()->domain )
    103             ) );
    104         }
    105     }
    106 
    107     public function cronSchedule( $schedules ) {
    108         if ( ! isset( $schedules["5min"] ) ) {
    109             $schedules["5min"] = array(
    110                 'interval' => 5 * 60,
    111                 'display'  => __( 'Once every 5 minutes' )
    112             );
    113         }
    114 
    115         return $schedules;
    116     }
    117 
    118     public function getOctifyStatus() {
    119         if ( ! current_user_can( 'manage_options' ) ) {
    120             return;
    121         }
    122 
    123         $percent = \Octify\Libs\OctifyApi::calculateProgress();
    124         if ( $percent == 100 ) {
    125             delete_site_transient( 'octifyUncompressCached' );
    126         }
    127 
    128         wp_send_json_success( array(
    129             'percent' => $percent
    130         ) );
    131     }
    132 
    133     public function startBulkOctify() {
    134         if ( ! current_user_can( 'manage_options' ) ) {
    135             return;
    136         }
    137 
    138         //get all uncompress images
    139         $uncompressed = \Octify\Libs\OctifyApi::findImages( 'uncompressed' );
    140         $error        = \Octify\Libs\OctifyApi::findImages( 'error' );
    141         $uncompressed = array_merge( $uncompressed, $error );
    142         //prepare the data
    143         $ids = array();
    144         foreach ( $uncompressed as $image ) {
    145             $ids[] = $image->ID;
    146         }
    147 
    148         $res = \Octify\Libs\OctifyApi::sendEnvelope( $ids );
    149         if ( is_wp_error( $res ) ) {
    150             wp_send_json_error( array(
    151                 'error' => $res->get_error_message()
    152             ) );
    153         }
    154         //generic update the status
    155         foreach ( $res['success'] as $id ) {
    156             update_post_meta( $id, \Octify\Libs\OctifyApi::META_STATUS, 'pending' );
    157         }
    158         $errorMessages[] = __( 'Following images having issues and can not be compressed', octify()->domain );
    159         $isExpired       = false;
    160         foreach ( $res['fail'] as $id ) {
    161             update_post_meta( $id['id'], \Octify\Libs\OctifyApi::META_STATUS, 'error' );
    162             update_post_meta( $id['id'], \Octify\Libs\OctifyApi::META_NAME, array(
    163                 'error' => $id['error']
    164             ) );
    165             if ( $id['code'] == 'expired' ) {
    166                 $isExpired = true;
    167             } else {
    168                 $errorMessages[] = sprintf( __( "Image with ID %s - %s", octify()->domain ), $id['id'], $id['error'] );
    169             }
    170             unset( $uncompressed[ array_search( $id['id'], $uncompressed ) ] );
    171         }
    172         if ( $isExpired ) {
    173             $errorMessages = array(
    174                 sprintf( __( "Whoops! Sorry you've used up your compression Quota. Want more? <a href='%s' target='_blank'>Buy Now</a>", octify()->domain ), 'https://octify.io/' )
    175             );
    176         }
    177         //cache it
    178         set_site_transient( 'octifyUncompressCached', $ids );
    179 
    180         if ( count( $res['fail'] ) ) {
    181             //we have error
    182             wp_send_json_error( array(
    183                 'error' => implode( '<br/>', $errorMessages )
    184             ) );
    185             update_option( 'octifyErrorFlash', $errorMessages );
    186         } else {
    187             wp_send_json_success();
    18873        }
    18974    }
     
    21398                    $backupPath = $meta['backup'];
    21499                    $file       = get_attached_file( $id );
    215                     unlink( $file );
    216100                    copy( $backupPath, $file );
    217101                    if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
     
    597481            'backup_original'         => true,
    598482            'resize'                  => false,
    599             'resize_width'            => false,
     483            'resize_width'            => 1280,
     484            'resize_height'           => 0,
    600485            'keep_exif'               => false,
    601486            'optimise_different_size' => true
  • octify/trunk/View/dashboard.php

    r1834004 r1901135  
    218218                    </div>
    219219                </div>
     220                <div class="control is-horizontal">
     221                    <div class="control-label">
     222                        <label><?php _e( "Resize", octify()->domain ) ?></label>
     223                    </div>
     224                    <div class="control">
     225                        <label for="resize " class="radio">
     226                            <input type="hidden" name="resize" value="0">
     227                            <input id="resize " type="checkbox" value="1"
     228                                <?php checked( 1, $settings['resize'] ) ?>
     229                                   name="resize">
     230                            <?php _e( "Resize", octify()->domain ) ?>
     231                        </label>
     232                    </div>
     233                </div>
    220234                <?php wp_nonce_field( 'octify_settings', '_octifyNonce' ) ?>
    221235                <br/>
  • octify/trunk/View/dashboard2.php

    r1868268 r1901135  
    8787                                </progress>
    8888                                <span class="octify-log"></span>
     89                                <form method="post" id="cancel-frm">
     90                                    <input type="hidden" name="action" value="cancel_octify_compress"/>
     91                                    <button type="submit" class="button"><?php _e( "Cancel", octify()->domain ) ?></button>
     92                                </form>
    8993                            </div>
    9094                            <?php
     
    267271                                </div>
    268272                            </div>
     273<!--                            <div class="control is-horizontal">-->
     274<!--                                <div class="control-label">-->
     275<!--                                    <label>--><?php //_e( "Resize", octify()->domain ) ?><!--</label>-->
     276<!--                                    <span class="sub">-->
     277<!--                                --><?php //_e( "Optimise image sizes created by WordPress", octify()->domain ) ?>
     278<!--                            </span>-->
     279<!--                                </div>-->
     280<!--                                <div class="control">-->
     281<!--                                    <label for="resize" class="radio">-->
     282<!--                                        <input type="hidden" name="resize" value="0">-->
     283<!--                                        <input class="tgl tgl-light"-->
     284<!--                                               name="resize" --><?php //checked( 1, $settings['resize'] ) ?>
     285<!--                                               value="1" id="resize" type="checkbox"/>-->
     286<!--                                        <label class="tgl-btn" for="resize"></label>-->
     287<!--                                    </label>-->
     288<!--                                </div>-->
     289<!--                            </div>-->
     290<!--                            <div class="control is-horizontal">-->
     291<!--                                <div class="control-label">-->
     292<!--                                    <label>--><?php //_e( "Resize Size", octify()->domain ) ?><!--</label>-->
     293<!--                                    <span class="sub">-->
     294<!--                                --><?php //_e( "Optimise image sizes created by WordPress", octify()->domain ) ?>
     295<!--                            </span>-->
     296<!--                                </div>-->
     297<!--                                <div class="control">-->
     298<!--                                    <input type="text" name="resize_width" placeholder="Width"-->
     299<!--                                           value="--><?php //echo $settings['resize_width'] ?><!--"/>-->
     300<!--                                    <input type="text" name="resize_height" placeholder="Height"-->
     301<!--                                           value="--><?php //echo $settings['resize_height'] ?><!--"/>-->
     302<!--                                </div>-->
     303<!--                            </div>-->
    269304                            <?php wp_nonce_field( 'octify_settings', '_octifyNonce' ) ?>
    270305                            <br/>
  • octify/trunk/assets/script.js

    r1868268 r1901135  
    4646                    }
    4747                } else {
    48                     location.reload();
     48                    //location.reload();
    4949                }
    5050            }
     
    101101    }
    102102
     103    $('#cancel-frm').submit(function () {
     104        var that = $(this);
     105        $.ajax({
     106            type: 'POST',
     107            data: that.serialize(),
     108            url: ajaxurl,
     109            beforeSend: function () {
     110                that.find('button').attr('disabled', 'disabled')
     111            },
     112            success: function () {
     113                location.reload();
     114            }
     115        })
     116        return false;
     117    })
     118
    103119    $('body').on('click', '.octify-revert', function () {
    104120        var that = $(this);
  • octify/trunk/readme.txt

    r1868268 r1901135  
    11=== WordPress Image Compression Plugin - Octify ===
    22Plugin Name: Octify
    3 Version: 1.2
     3Version: 1.3
    44Author: Octify
    55Author URI: https://octify.io/
     
    77Tags: Image Compression, Image Optimisation, resize, optimise, performance, optimize, compress images, optimize images, optimise images, image optimization.
    88Tested up to: 4.9.5
    9 Stable tag: 1.2
     9Stable tag: 1.3
    1010Requires PHP: 5.3
    1111License: GPLv2
     
    141141== Changelog ==
    142142
     143= 1.3 =
     144-Fix issue with some domains incorrectly identifying as localhost
     145-Fix issue where compressing wouldn't skip a broken image.
     146
     147= 1.2 =
     148-Fix some bugs
     149
    143150= 1.1.4 =
    144151-Prevent images from being re-compressed.
Note: See TracChangeset for help on using the changeset viewer.