Plugin Directory

Changeset 1868268


Ignore:
Timestamp:
05/03/2018 04:54:57 PM (8 years ago)
Author:
octify
Message:

Implement new compression checks, ensure compression status is correctly updated.

Location:
octify/trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • octify/trunk/Libs/OctifyApi.php

    r1860529 r1868268  
    341341//              return;
    342342//          }
    343 
    344             $currentStatus = get_post_meta( $attachmentId, self::META_STATUS, true );
    345             if ( $currentStatus == 'compressed' ) {
    346                 //wont compress which already compressed
    347                 return;
    348             }
    349 
    350343            $file = get_attached_file( $attachmentId );
    351344            if ( ! function_exists( 'download_url' ) ) {
  • octify/trunk/Octify.php

    r1860529 r1868268  
    44 * Plugin URI: https://octify.io
    55 * Description: Octify Image Compression for WordPress.
    6  * Version: 1.1.4
     6 * Version: 1.2
    77 * Author: Octify
    88 * Author URI: https://octify.io
     
    4343        add_action( 'admin_enqueue_scripts', array( &$this, 'adminScripts' ) );
    4444        add_action( 'admin_menu', array( &$this, 'adminMenu' ) );
    45         add_action( 'wp_loaded', array( &$this, 'saveSettings' ) );
    46         add_action( 'wp_loaded', array( &$this, 'activate' ) );
    47         add_action( 'wp_loaded', array( &$this, 'extend' ) );
    48         add_action( 'wp_loaded', array( &$this, 'getFreeKey' ) );
     45        add_action( 'wp_loaded', array( '\Octify\Controller\Settings', 'saveSettings' ) );
     46        add_action( 'wp_loaded', array( '\Octify\Controller\Payment', 'activate' ) );
     47        add_action( 'wp_loaded', array( '\Octify\Controller\Payment', 'getFreeKey' ) );
    4948        //inject octify to media page
    5049        add_filter( 'manage_media_columns', array( &$this, 'columns' ) );
     
    6059        add_action( 'wp_ajax_octify_revert', array( &$this, 'revert' ) );
    6160        //
    62         add_action( 'wp_ajax_start_bulk_octify', array( &$this, 'startBulkOctify' ) );
    63         add_action( 'wp_ajax_get_bulk_octify_status', array( &$this, 'getOctifyStatus' ) );
     61        add_action( 'wp_ajax_start_bulk_octify', array( '\Octify\Controller\Compress', 'bulkOctify' ) );
     62        add_action( 'wp_ajax_get_bulk_octify_status', array( '\Octify\Controller\Compress', 'getOctifyStatus' ) );
    6463        //
    6564        add_action( 'wp_shutdown', function () {
     
    7271            add_action( 'wp_loaded', array( &$this, 'revertAll' ) );
    7372        }
     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;
    74116    }
    75117
     
    145187            wp_send_json_success();
    146188        }
    147     }
    148 
    149     public function getFreeKey() {
    150         if ( ! current_user_can( 'manage_options' ) ) {
    151             return;
    152         }
    153         $nonce = isset( $_POST['_octifyNonce'] ) ? $_POST['_octifyNonce'] : null;
    154         if ( ! wp_verify_nonce( $nonce, 'octify_getFreeKey' ) ) {
    155             return;
    156         }
    157 
    158         $email = isset( $_POST['email'] ) ? $_POST['email'] : null;
    159         if ( ! $email ) {
    160             //show error
    161             update_option( 'octifyErrorFlash', __( "Email can't be blank", octify()->domain ) );
    162         }
    163 
    164         $code = \Octify\Libs\OctifyApi::getAPIKey( $email );
    165         $res  = \Octify\Libs\OctifyApi::activateCheck( $email, $code['code'] );
    166         if ( is_wp_error( $res ) ) {
    167             update_option( 'octifyErrorFlash', $res->get_error_message() );
    168         } else {
    169             update_option( 'octifyFlash', __( "Welcome to Octify!", octify()->domain ) );
    170         }
    171 
    172         wp_redirect( admin_url( 'upload.php?page=octify#' ) );
    173189    }
    174190
     
    235251        }
    236252        $file = get_attached_file( $id );
    237         unlink( $file );
     253        //unlink( $file );
    238254        copy( $backupPath, $file );
    239255        if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
    240256            include( ABSPATH . 'wp-admin/includes/image.php' );
    241257        }
    242         wp_generate_attachment_metadata( $id, $file );
    243258        delete_post_meta( $id, \Octify\Libs\OctifyApi::META_NAME );
    244259        delete_post_meta( $id, \Octify\Libs\OctifyApi::META_STATUS );
     260        //wp_generate_attachment_metadata( $id, $file );
    245261        wp_send_json( array(
    246262            'status' => 1,
     
    480496    }
    481497
    482     /**
    483      * Save settings
    484      */
    485     public function saveSettings() {
    486         $wpNonce = isset( $_POST['_octifyNonce'] ) ? $_POST['_octifyNonce'] : null;
    487         if ( is_null( $wpNonce ) ) {
    488             return;
    489         }
    490         if ( ! wp_verify_nonce( $wpNonce, 'octify_settings' ) ) {
    491             return;
    492         }
    493 
    494         $settings = octify()->getSettings();
    495         foreach ( $settings as $key => $val ) {
    496             if ( isset( $_POST[ $key ] ) ) {
    497                 $settings[ $key ] = $_POST[ $key ];
    498             }
    499         }
    500         update_option( 'octify', $settings );
    501         update_option( 'octifyFlash', __( "Settings saved successfully", $this->domain ) );
    502         wp_redirect( admin_url( 'upload.php?page=octify' ) );
    503         exit;
    504     }
    505 
    506     public function activate() {
    507         $wpNonce = isset( $_POST['_octifyNonce'] ) ? $_POST['_octifyNonce'] : null;
    508         if ( is_null( $wpNonce ) ) {
    509             return;
    510         }
    511         if ( ! wp_verify_nonce( $wpNonce, 'octifyActivator' ) ) {
    512             return;
    513         }
    514 
    515         $email = sanitize_email( $_POST['email'] );
    516         $code  = sanitize_key( $_POST['code'] );
    517 
    518         $res = \Octify\Libs\OctifyApi::activateCheck( $email, $code );
    519         if ( is_wp_error( $res ) ) {
    520             update_option( 'octifyErrorFlash', $res->get_error_message() );
    521         } else {
    522             update_option( 'octifyFlash', __( "WooHoo! You've just made an awesome decision
    523 thanks for choosing Octify!", octify()->domain ) );
    524         }
    525 
    526         wp_redirect( admin_url( 'upload.php?page=octify' ) );
    527         exit;
    528     }
    529 
    530     public function extend() {
    531         $wpNonce = isset( $_POST['_octifyNonce'] ) ? $_POST['_octifyNonce'] : null;
    532         if ( is_null( $wpNonce ) ) {
    533             return;
    534         }
    535         if ( ! wp_verify_nonce( $wpNonce, 'extendLicense' ) ) {
    536             return;
    537         }
    538 
    539         $email = sanitize_email( $_POST['email'] );
    540         $code  = sanitize_key( $_POST['code'] );
    541 
    542         $res = \Octify\Libs\OctifyApi::activateCheck( $email, $code );
    543         if ( is_wp_error( $res ) ) {
    544             update_option( 'octifyErrorFlash', $res->get_error_message() );
    545         } else {
    546             update_option( 'octifyFlash', __( "WooHoo! You've just made an awesome decision
    547 thanks for choosing Octify!", octify()->domain ) );
    548         }
    549 
    550         wp_redirect( admin_url( 'upload.php?page=octify' ) );
    551         exit;
    552     }
    553 
    554498    public function adminMenu() {
    555499        $svg = file_get_contents( $this->plugin_path . 'assets/octify-character-dashicon.svg' );
     
    569513
    570514        if ( is_plugin_active( 'ocean-extra/ocean-extra.php' ) ) {
     515            global $submenu;
     516            $permalink = 'https://octify.io/?ref=nicolaslecocq';
    571517            add_submenu_page( 'octify', __( "Go Pro", octify()->domain ), __( "Go Pro", octify()->domain ), 'manage_options', 'octify-pro', array(
    572518                &$this,
    573519                'goPro'
    574520            ) );
     521            $submenu['octify'][] = array( 'Go Pro', 'manage_options', $permalink );
     522            unset( $submenu['octify'][1] );
    575523        }
    576524
     
    612560            return;
    613561        }
    614 
    615562        unset( $parts[0] );
    616563        $className = implode( '\\', $parts );
  • octify/trunk/View/dashboard2.php

    r1859158 r1868268  
    7575                        $pendingImages = count( \Octify\Libs\OctifyApi::findImages( 'pending' ) );
    7676                        if ( $pendingImages > 0 ) {
    77                             $process = \Octify\Libs\OctifyApi::calculateProgress();
     77                            $process = \Octify\Controller\Compress::calPercent();
    7878                            ?>
    7979                            <p>
     
    8686                                          value="<?php echo $process ?>" max="100"><?php echo $process ?>%
    8787                                </progress>
     88                                <span class="octify-log"></span>
    8889                            </div>
    8990                            <?php
     
    304305                            </div>
    305306                            <br/>
    306                             <?php wp_nonce_field( 'extendLicense', '_octifyNonce' ) ?>
     307                            <?php wp_nonce_field( 'octifyActivator', '_octifyNonce' ) ?>
    307308                            <button class="button is-primary" type="submit">Submit</button>
    308309                        </form>
  • octify/trunk/assets/script.js

    r1846576 r1868268  
    3737            },
    3838            success: function (data) {
    39                 $('.octify-progress').attr('value', data.data.percent).text(data.data.percent + '%');
    40                 if (data.data.percent == 100) {
     39                if (data.success == 1) {
     40                    $('.octify-progress').attr('value', data.data.percent).text(data.data.percent + '%');
     41                    $('.octify-log').html(data.data.log);
     42                    if (data.data.is_done === true) {
     43                        location.reload();
     44                    } else {
     45                        setTimeout(listen_bulk_status, 1000);
     46                    }
     47                } else {
    4148                    location.reload();
    42                 } else {
    43                     setTimeout(listen_bulk_status, 3000);
    4449                }
    4550            }
  • octify/trunk/readme.txt

    r1860529 r1868268  
    11=== WordPress Image Compression Plugin - Octify ===
    22Plugin Name: Octify
    3 Version: 1.1.4
     3Version: 1.2
    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.1.4
     9Stable tag: 1.2
    1010Requires PHP: 5.3
    1111License: GPLv2
Note: See TracChangeset for help on using the changeset viewer.