Changeset 1901135
- Timestamp:
- 06/29/2018 11:50:49 AM (8 years ago)
- Location:
- octify/trunk
- Files:
-
- 7 edited
-
Controller/Compress.php (modified) (5 diffs)
-
Libs/OctifyApi.php (modified) (2 diffs)
-
Octify.php (modified) (5 diffs)
-
View/dashboard.php (modified) (1 diff)
-
View/dashboard2.php (modified) (2 diffs)
-
assets/script.js (modified) (2 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
octify/trunk/Controller/Compress.php
r1868268 r1901135 33 33 } 34 34 35 if ( get_option( self::IN_COMPRESS ) == false ) { 35 // if ( get_option( self::IN_COMPRESS ) == false ) { 36 // return; 37 // } 38 39 if ( self::isLocked() ) { 36 40 return; 37 }38 39 if ( self::isLocked() ) {40 //return;41 41 } 42 42 … … 75 75 $meta = get_post_meta( $id, OctifyApi::META_NAME, true ); 76 76 $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 } 77 84 if ( strtotime( '+60 seconds', $time ) < time() ) { 78 85 //we should retry it … … 87 94 $res = OctifyApi::sendEnvelope( array( $id ) ); 88 95 update_post_meta( $id, OctifyApi::META_NAME, array( 89 'started' => time(),90 'retry' => $retry96 'started' => time(), 97 'retry' => $retry 91 98 ) ); 92 99 self::processResponse( $res, $retry ); … … 94 101 } 95 102 } 103 self::releaseLock(); 96 104 wp_send_json_success( array( 97 105 'percent' => self::calPercent(), … … 194 202 update_option( self::LOCK, time() ); 195 203 } 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 } 196 213 } -
octify/trunk/Libs/OctifyApi.php
r1868268 r1901135 223 223 $imagePath = $uploadDirs['basedir'] . '/' . $imageMeta['file']; 224 224 $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 ) 234 237 ); 235 238 } … … 254 257 } 255 258 $body = wp_remote_retrieve_body( $request ); 259 //var_dump($body);die; 256 260 $body = json_decode( $body, true ); 257 261 if ( ! is_array( $body ) ) { 258 259 262 return new \WP_Error( 'invalid_response', 'Please try again' ); 260 263 } -
octify/trunk/Octify.php
r1868268 r1901135 4 4 * Plugin URI: https://octify.io 5 5 * Description: Octify Image Compression for WordPress. 6 * Version: 1. 26 * Version: 1.3 7 7 * Author: Octify 8 8 * Author URI: https://octify.io … … 60 60 // 61 61 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' ) ); 62 63 add_action( 'wp_ajax_get_bulk_octify_status', array( '\Octify\Controller\Compress', 'getOctifyStatus' ) ); 63 64 // … … 70 71 if ( $revertAll ) { 71 72 add_action( 'wp_loaded', array( &$this, 'revertAll' ) ); 72 }73 74 //75 }76 77 public function maybeResetStatus() {78 //find all the pending images79 $pending = \Octify\Libs\OctifyApi::findImages( 'pending' );80 if ( count( $pending ) == 0 ) {81 return;82 }83 84 //check time85 $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' => $data94 )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' => $percent130 ) );131 }132 133 public function startBulkOctify() {134 if ( ! current_user_can( 'manage_options' ) ) {135 return;136 }137 138 //get all uncompress images139 $uncompressed = \Octify\Libs\OctifyApi::findImages( 'uncompressed' );140 $error = \Octify\Libs\OctifyApi::findImages( 'error' );141 $uncompressed = array_merge( $uncompressed, $error );142 //prepare the data143 $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 status155 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 it178 set_site_transient( 'octifyUncompressCached', $ids );179 180 if ( count( $res['fail'] ) ) {181 //we have error182 wp_send_json_error( array(183 'error' => implode( '<br/>', $errorMessages )184 ) );185 update_option( 'octifyErrorFlash', $errorMessages );186 } else {187 wp_send_json_success();188 73 } 189 74 } … … 213 98 $backupPath = $meta['backup']; 214 99 $file = get_attached_file( $id ); 215 unlink( $file );216 100 copy( $backupPath, $file ); 217 101 if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) { … … 597 481 'backup_original' => true, 598 482 'resize' => false, 599 'resize_width' => false, 483 'resize_width' => 1280, 484 'resize_height' => 0, 600 485 'keep_exif' => false, 601 486 'optimise_different_size' => true -
octify/trunk/View/dashboard.php
r1834004 r1901135 218 218 </div> 219 219 </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> 220 234 <?php wp_nonce_field( 'octify_settings', '_octifyNonce' ) ?> 221 235 <br/> -
octify/trunk/View/dashboard2.php
r1868268 r1901135 87 87 </progress> 88 88 <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> 89 93 </div> 90 94 <?php … … 267 271 </div> 268 272 </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>--> 269 304 <?php wp_nonce_field( 'octify_settings', '_octifyNonce' ) ?> 270 305 <br/> -
octify/trunk/assets/script.js
r1868268 r1901135 46 46 } 47 47 } else { 48 location.reload();48 //location.reload(); 49 49 } 50 50 } … … 101 101 } 102 102 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 103 119 $('body').on('click', '.octify-revert', function () { 104 120 var that = $(this); -
octify/trunk/readme.txt
r1868268 r1901135 1 1 === WordPress Image Compression Plugin - Octify === 2 2 Plugin Name: Octify 3 Version: 1. 23 Version: 1.3 4 4 Author: Octify 5 5 Author URI: https://octify.io/ … … 7 7 Tags: Image Compression, Image Optimisation, resize, optimise, performance, optimize, compress images, optimize images, optimise images, image optimization. 8 8 Tested up to: 4.9.5 9 Stable tag: 1. 29 Stable tag: 1.3 10 10 Requires PHP: 5.3 11 11 License: GPLv2 … … 141 141 == Changelog == 142 142 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 143 150 = 1.1.4 = 144 151 -Prevent images from being re-compressed.
Note: See TracChangeset
for help on using the changeset viewer.