Changeset 2539116
- Timestamp:
- 05/28/2021 03:10:30 PM (5 years ago)
- Location:
- megaoptim-image-optimizer/trunk
- Files:
-
- 13 edited
-
assets/js/megaoptim-processor.js (modified) (4 diffs)
-
includes/classes/Adapters/MGO_FileLibrary.php (modified) (8 diffs)
-
includes/classes/Adapters/MGO_MediaLibrary.php (modified) (14 diffs)
-
includes/classes/Exceptions/MGO_Exception.php (modified) (2 diffs)
-
includes/classes/Jobs/MGO_MediaLibrary_Process.php (modified) (4 diffs)
-
includes/classes/MGO_Ajax.php (modified) (5 diffs)
-
includes/classes/MGO_CLI.php (modified) (2 diffs)
-
includes/classes/MGO_Profile.php (modified) (2 diffs)
-
includes/classes/MGO_ResultBag.php (modified) (2 diffs)
-
includes/compat/nextgen-gallery/classes/MGO_NGGLibrary.php (modified) (7 diffs)
-
includes/hooks/notices.php (modified) (1 diff)
-
megaoptim.php (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
megaoptim-image-optimizer/trunk/assets/js/megaoptim-processor.js
r2260564 r2539116 134 134 $spin.show(); 135 135 self.run(index, attachments.length, attachments); 136 }, 1000);136 }, 500); 137 137 138 138 }; … … 192 192 self.update_couters(response.data); 193 193 if (parseInt(response.data['tokens']) === 0) { 194 $(window).off('beforeunload'); 194 195 window.location.href = window.location.href; 195 196 } … … 197 198 self.update_row_error(data[index]['ID'], response.data.error); 198 199 self.log(response.data, 'log'); 199 if ( !(response.data['can_continue'] === 1 || response.data['can_continue'] === '1')) {200 if ( response.data.hasOwnProperty('can_continue') && !(response.data['can_continue'] === 1 || response.data['can_continue'] === '1')) { 200 201 self.stop_optimizer(); 201 202 } … … 216 217 self.unlock_optimizer(); 217 218 self.run(index, len, data); 218 }, 500);219 }, 120); 219 220 } 220 221 }); -
megaoptim-image-optimizer/trunk/includes/classes/Adapters/MGO_FileLibrary.php
r2432752 r2539116 53 53 $result = new MGO_ResultBag(); 54 54 55 //Dont go further if not connected56 $profile = MGO_Profile::_is_connected();57 if ( ! $profile OR is_null( $this->optimizer ) ) {58 throw new MGO_Exception( 'Please make sure you have set up MegaOptim.com API key' );59 }60 55 //Check if attachment is optimized 61 56 $attachment_object = new MGO_FileAttachment( $attachment->path ); … … 64 59 if ( $attachment_object->is_processed() ) { 65 60 throw new MGO_Attachment_Already_Optimized_Exception( 'The attachment is already fully optimized.' ); 66 }67 68 // Bail if no tokens left.69 $tokens = $profile->get_tokens_count();70 if ( $tokens != - 1 && $tokens <= 0 ) {71 throw new MGO_Exception( 'No tokens left. Please top up your account at https://megaoptim.com/dashboard in order to continue.' );72 61 } 73 62 … … 76 65 if ( ! empty( $params ) ) { 77 66 $request_params = array_merge( $request_params, $params ); 67 } 68 69 // Check if image exist 70 if ( ! file_exists( $attachment->path ) ) { 71 throw new MGO_Exception( __( 'Original image version does not exist on the server.', 'megaoptim-image-optimizer' ) ); 78 72 } 79 73 … … 89 83 do_action( 'megaoptim_before_optimization', $attachment_object, $request_params ); 90 84 91 //Create Backup If needed92 if ( $this->should_backup() ) {93 $backup_path = $attachment_object->backup();94 $attachment_object->set_backup_path( $backup_path );95 }96 97 // Check if image exist98 if ( ! file_exists( $attachment->path ) ) {99 throw new MGO_Exception( __( 'Original image version does not exist on the server.', 'megaoptim-image-optimizer' ) );100 }101 102 85 try { 103 86 // Grab the resource … … 106 89 $response = $this->optimizer->run( $resource, $request_params ); 107 90 $result->add( 'full', $response ); 91 108 92 if ( $response->isError() ) { 109 93 megaoptim_log( $response->getErrors() ); 110 94 } else { 111 megaoptim_log($response); 95 96 megaoptim_log( $response ); 97 98 //Create Backup If needed 99 if ( $this->should_backup() ) { 100 $backup_path = $attachment_object->backup(); 101 $attachment_object->set_backup_path( $backup_path ); 102 } 103 104 // Save optimized files 112 105 foreach ( $response->getOptimizedFiles() as $file ) { 113 106 if ( $file->getSavedBytes() > 0 && $file->isSuccessfullyOptimized() ) { … … 116 109 $result->total_full_size ++; 117 110 $result->total_saved_bytes += $file->getSavedBytes(); 118 $webp= $file->getWebP();119 if ( ! is_null( $webp ) ) {120 if ( $webp->getSavedBytes() > 0 ) {121 $webp->saveAsFile( $attachment->path . '.webp' );122 }123 }111 $webp = $file->getWebP(); 112 if ( ! is_null( $webp ) ) { 113 if ( $webp->getSavedBytes() > 0 ) { 114 $webp->saveAsFile( $attachment->path . '.webp' ); 115 } 116 } 124 117 } 125 118 $attachment_object->set_data( $response, $request_params ); 126 119 $attachment_object->set( 'directory', $attachment->directory ); 127 120 $attachment_object->save(); 121 128 122 // No need to backup attachments that are already optimized! 129 123 if ( $attachment_object->is_already_optimized() ) { … … 146 140 } 147 141 142 if ( $result->is_erroneous() ) { 143 $result->throw_last_error(); 144 } 145 148 146 $result->set_attachment( $attachment_object ); 149 147 … … 270 268 $directories = array(); 271 269 $excludes = megaoptim_get_excluded_custom_dir_paths(); 272 $files = megaoptim_find_images( $directory, true, $excludes);270 $files = megaoptim_find_images( $directory, true, $excludes ); 273 271 foreach ( $files as $file ) { 274 272 array_push( $directories, dirname( $file ) . DIRECTORY_SEPARATOR ); -
megaoptim-image-optimizer/trunk/includes/classes/Adapters/MGO_MediaLibrary.php
r2432752 r2539116 66 66 public function optimize( $attachment, $params = array() ) { 67 67 68 @set_time_limit( 0);68 @set_time_limit( 0 ); 69 69 70 70 $result = new MGO_ResultBag(); 71 72 //Don't go further if not connected73 $profile = MGO_Profile::_is_connected();74 if ( ! $profile OR is_null( $this->optimizer ) ) {75 throw new MGO_Exception( 'Please make sure you have set up MegaOptim.com API key' );76 }77 71 78 72 //Check if Attachment is image … … 98 92 if ( $attachment_object->is_processed() ) { 99 93 throw new MGO_Attachment_Already_Optimized_Exception( 'The attachment is already fully optimized.' ); 100 }101 102 // Bail if no tokens left.103 $tokens = $profile->get_tokens_count();104 if ( $tokens != - 1 && $tokens <= 0 ) {105 throw new MGO_Exception( 'No tokens left. Please top up your account at https://megaoptim.com/dashboard in order to continue.' );106 94 } 107 95 … … 124 112 125 113 //Get the file names 126 //$original_resource = $this->get_attachment( $attachment, 'full', false );127 114 $original_path = $this->get_attachment_path( $attachment, 'full', false ); 128 115 if ( ! file_exists( $original_path ) ) { … … 130 117 } 131 118 132 //Create Backup If Enabled133 if ( $this->should_backup() ) {134 $backup_path = $attachment_object->backup();135 $attachment_object->set_backup_path( $backup_path );136 }137 138 119 // Optimize the original and the thumbnails 139 120 try { 121 140 122 megaoptim_log( 'Optimizing MediaLibrary attachment with id ' . $attachment_object->get_id() ); 141 123 124 //Create Backup If Enabled 125 if ( $this->should_backup() ) { 126 $backup_path = $attachment_object->backup(); 127 $attachment_object->set_backup_path( $backup_path ); 128 } 129 // Create resources 142 130 $resources = array(); 143 131 $attachments = array(); 144 145 132 $attachment_object->maybe_set_metadata(); 146 133 $remaining_thumbnails = $attachment_object->get_remaining_thumbnails(); … … 189 176 megaoptim_log( '--- Response: ' . $response->getRawResponse() ); 190 177 foreach ( $attachments as $att ) { 191 $file = $response->getResultByFileName( basename( $att['save_path'] ) ); 178 $filename = basename( $att['save_path'] ); 179 $file = $response->getResultByFileName( $filename ); 192 180 if ( ! is_null( $file ) ) { 193 181 // Save data … … 224 212 */ 225 213 do_action( 'megaoptim_size_optimized', $attachment_object, $att['save_path'], $response, $request_params, $size ); 214 } else { 215 megaoptim_log( '--- Saving Response: Response by filename not found. File name: ' . $filename ); 226 216 } 227 217 } … … 232 222 $attachment_object->save(); 233 223 $attachment_object->refresh(); 224 225 if ( $result->is_erroneous() ) { 226 $result->throw_last_error(); 227 } 228 234 229 $result->set_attachment( $attachment_object ); 235 236 230 do_action( 'megaoptim_attachment_optimized', $attachment_object, $request_params, $result ); 237 231 … … 239 233 } catch ( Exception $e ) { 240 234 $attachment_object->unlock(); 241 megaoptim_log( '--- Optimizer Exception: ' . $e->getMessage() );242 throw new MGO_Exception( $e->getMessage() . ' in ' . $e->getFile());235 megaoptim_log( '--- Optimizer Exception: ' . sprintf( '%s in %s', $e->getMessage(), $e->getFile() ) ); 236 throw new MGO_Exception( $e->getMessage() ); 243 237 } 244 238 } … … 261 255 262 256 return; 263 }264 265 //Don't go further if not connected266 $profile = MGO_Profile::_is_connected();267 if ( ! $profile OR is_null( $this->optimizer ) ) {268 throw new MGO_Exception( 'Please make sure you have set up MegaOptim.com API key' );269 257 } 270 258 … … 286 274 if ( $attachment_object->is_locked() ) { 287 275 throw new MGO_Attachment_Locked_Exception( 'The attachment is currently being optimized. No need to re-run the optimization.' ); 288 }289 290 // Bail if no tokens left.291 $tokens = $profile->get_tokens_count();292 if ( $tokens != - 1 && $tokens <= 0 ) {293 throw new MGO_Exception( 'No tokens left. Please top up your account at https://megaoptim.com/dashboard in order to continue.' );294 276 } 295 277 … … 373 355 public function convert_webp( $args ) { 374 356 375 }357 } 376 358 377 359 /** … … 383 365 */ 384 366 public function get_images( $args = array() ) { 385 386 367 387 368 global $wpdb; … … 425 406 $query = str_replace( $tag, $tag_count, $query_str ); 426 407 $total_items = (int) $wpdb->get_var( $query ); 427 $total_pages = ( $total_items > 0 && $items_per_page > 0 ) ? ceil(( $total_items / $items_per_page )) : 1;408 $total_pages = ( $total_items > 0 && $items_per_page > 0 ) ? ceil( ( $total_items / $items_per_page ) ) : 1; 428 409 429 410 // Setup page offset … … 795 776 $largest_thumbnail_dimensions = $attachment->get_largest_thumbnail_dimensions(); 796 777 797 $max_width = 0;798 $max_height = 0;799 800 if (isset($params['max_width'])) {801 $max_width = intval($params['max_width']);802 }803 if (isset($params['max_height'])) {804 $max_height = intval($params['max_height']);805 }806 807 if ($max_width > 0) {808 if ($max_width > $largest_thumbnail_dimensions['width']) {809 $max_width = 0;810 }811 }812 813 if ($max_height > 0) {814 if ($max_height > $largest_thumbnail_dimensions['height']) {815 $max_height = 0;816 }817 }818 819 $params['max_width'] = $max_width;820 $params['max_height'] = $max_height;778 $max_width = 0; 779 $max_height = 0; 780 781 if ( isset( $params['max_width'] ) ) { 782 $max_width = intval( $params['max_width'] ); 783 } 784 if ( isset( $params['max_height'] ) ) { 785 $max_height = intval( $params['max_height'] ); 786 } 787 788 if ( $max_width > 0 ) { 789 if ( $max_width > $largest_thumbnail_dimensions['width'] ) { 790 $max_width = 0; 791 } 792 } 793 794 if ( $max_height > 0 ) { 795 if ( $max_height > $largest_thumbnail_dimensions['height'] ) { 796 $max_height = 0; 797 } 798 } 799 800 $params['max_width'] = $max_width; 801 $params['max_height'] = $max_height; 821 802 822 803 return $params; -
megaoptim-image-optimizer/trunk/includes/classes/Exceptions/MGO_Exception.php
r1952089 r2539116 23 23 } 24 24 25 /** 26 * Class MGO_Exception 27 */ 25 28 class MGO_Exception extends Exception { 26 29 27 private $errors = array(); 30 /** 31 * The errors 32 * @var array|string[] 33 */ 34 private $errors; 28 35 29 public function __construct( $message = "", $code = 0, Exception $previous = null ) { 36 /** 37 * MGO_Exception constructor. 38 * 39 * @param array $message 40 * @param int $code 41 * @param null $previous 42 */ 43 public function __construct( $message = "", $code = 0, $previous = null ) { 44 45 $this->errors = array(); 30 46 if ( is_array( $message ) ) { 31 47 $primary_error_message = $message[0]; … … 38 54 } 39 55 56 /** 57 * Return the errors 58 * @return array|string[] 59 */ 40 60 public function get_errors() { 41 61 return $this->errors; -
megaoptim-image-optimizer/trunk/includes/classes/Jobs/MGO_MediaLibrary_Process.php
r2202391 r2539116 78 78 $attachment->save(); 79 79 $attachment->unlock(); 80 80 81 return false; 81 82 } … … 93 94 $is_retina = $_itm['type'] === 'retina'; 94 95 95 $file = $response->getResultByFileName( basename( $resource ) ); 96 $filename = basename( $resource ); 97 $file = $response->getResultByFileName( $filename ); 96 98 97 99 if ( ! is_null( $file ) ) { … … 112 114 $webp->saveAsFile( $local_path . '.webp' ); 113 115 } 114 115 116 } 116 117 … … 137 138 */ 138 139 do_action( 'megaoptim_size_optimized', $attachment, $local_path, $response, $request_params, $size ); 140 } else { 141 megaoptim_log( '--- Saving Response: Response by filename not found. File name: '.$filename ); 139 142 } 140 143 } -
megaoptim-image-optimizer/trunk/includes/classes/MGO_Ajax.php
r2260564 r2539116 112 112 if ( isset( $_REQUEST['api_key'] ) && ! empty( $_REQUEST['api_key'] ) ) { 113 113 try { 114 $profile = new MGO_Profile( $_REQUEST['api_key'] );114 $profile = new MGO_Profile( $_REQUEST['api_key'], true ); 115 115 if ( $profile->is_valid_apikey() ) { 116 116 MGO_Settings::instance()->update( array( … … 140 140 141 141 if ( ! megaoptim_check_referer( MGO_Ajax::NONCE_OPTIMIZER, 'nonce' ) ) { 142 wp_send_json_error( array( 'error' => __( 'Access denied.', 'megaoptim-image-optimizer' ) ) ); 142 wp_send_json_error( array( 143 'error' => __( 'Access denied.', 'megaoptim-image-optimizer' ), 144 'can_continue' => 0, 145 ) ); 143 146 } 144 147 145 148 if ( ! is_user_logged_in() || ! current_user_can( 'upload_files' ) ) { 146 wp_send_json_error( array( 'error' => __( 'Access denied.', 'megaoptim-image-optimizer' ) ) ); 149 wp_send_json_error( array( 150 'error' => __( 'Access denied.', 'megaoptim-image-optimizer' ), 151 'can_continue' => 0, 152 ) ); 147 153 } 148 154 149 155 if ( ! isset( $_REQUEST['attachment'] ) ) { 150 wp_send_json_error( array( 'error' => __( 'No attachment provided.', 'megaoptim-image-optimizer' ) ) ); 156 wp_send_json_error( array( 157 'error' => __( 'No attachment provided.', 'megaoptim-image-optimizer' ), 158 'can_continue' => 1, 159 ) ); 151 160 } 152 161 $attachment_id = $_REQUEST['attachment']['ID']; … … 303 312 if ( isset( $_REQUEST[ MGO_Settings::API_KEY ] ) && ! empty( $_REQUEST[ MGO_Settings::API_KEY ] ) ) { 304 313 try { 305 $response = MGO_Profile::get_user_by_api_key( $_REQUEST['megaoptimpt_api_key'] ); 306 if ( $response === false ) { 307 array_push( $errors, __( 'Could not verify your API key. The API can not be reached. Please contact support.', 'megaoptim-image-optimizer' ) ); 308 } else if ( ! isset( $response['status'] ) ) { 309 array_push( $errors, __( 'We received invalid response trying to authenticate your api key. Please contact support.', 'megaoptim-image-optimizer' ) ); 310 } else if ( $response['status'] != 'ok' ) { 311 array_push( $errors, __( 'Your API key is invalid. Please make sure you use correct API issued by MegaOptim.com', 'megaoptim-image-optimizer' ) ); 314 $apikey = sanitize_text_field( $_REQUEST['megaoptimpt_api_key'] ); 315 $profile = new MGO_Profile( $apikey, true ); 316 if ( ! $profile->is_connected() ) { 317 array_push( $errors, __( 'Could not connect to the MegaOptim API. The provided API key is empty or invalid.', 'megaoptim-image-optimizer' ) ); 312 318 } 313 319 } catch ( MGO_Exception $e ) { … … 397 403 398 404 // Image sizes 399 if ( ! isset( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] ) OR! is_array( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] )400 ORcount( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] ) === 0405 if ( ! isset( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] ) or ! is_array( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] ) 406 or count( $_REQUEST[ MGO_Settings::IMAGE_SIZES ] ) === 0 401 407 ) { 402 408 array_push( $errors, __( 'No image sizes selected. Please select some!', 'megaoptim-image-optimizer' ) ); … … 511 517 switch ( $context ) { 512 518 case MEGAOPTIM_TYPE_MEDIA_ATTACHMENT: 513 $filters = array();514 foreach (array('date_from', 'date_to') as $key) {515 if (isset($_REQUEST[$key]) && ! empty($_REQUEST[$key])) {516 $filters[$key] = $_REQUEST[$key];517 }518 }519 $filters['page'] = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;520 $filters['per_page'] = isset( $_REQUEST['per_page']) ? $_REQUEST['per_page'] : 5000;521 $stats = MGO_MediaLibrary::instance()->get_stats(true, $filters);522 break;519 $filters = array(); 520 foreach ( array( 'date_from', 'date_to' ) as $key ) { 521 if ( isset( $_REQUEST[ $key ] ) && ! empty( $_REQUEST[ $key ] ) ) { 522 $filters[ $key ] = $_REQUEST[ $key ]; 523 } 524 } 525 $filters['page'] = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : null; 526 $filters['per_page'] = isset( $_REQUEST['per_page'] ) ? $_REQUEST['per_page'] : 5000; 527 $stats = MGO_MediaLibrary::instance()->get_stats( true, $filters ); 528 break; 523 529 default: 524 530 $stats = apply_filters( 'megaoptim_library_data', null, $context ); -
megaoptim-image-optimizer/trunk/includes/classes/MGO_CLI.php
r2260564 r2539116 252 252 } 253 253 \WP_CLI::success( $message ); 254 } catch ( MGO_Attachment_Already_Optimized_Exception $e ) { 255 $message = sprintf( __( 'Attachment already %s optimized. No further optimization needed.', 'megaoptim-image-optimizer' ), $image['ID'] ); 256 \WP_CLI::success( $message ); 257 } catch ( MGO_Exception $e ) { 258 $message = sprintf( __( 'Attachment %s not optimized. Reason: %s', 'megaoptim-image-optimizer' ), $image['ID'], $e->getMessage() ); 259 \WP_CLI::warning( $message ); 254 } catch ( \MGO_Exception $e ) { 255 if ( $e instanceof MGO_Attachment_Already_Optimized_Exception ) { 256 \WP_CLI::success( sprintf( __( 'Attachment %s already optimized. No further optimization needed.', 'megaoptim-image-optimizer' ), $image['ID'] ) ); 257 } else if ( $e instanceof MGO_Attachment_Locked_Exception ) { 258 \WP_CLI::warning( sprintf( __( 'Attachment %s not optimized. Reason: %s', 'megaoptim-image-optimizer' ), $image['ID'], $e->getMessage() ) ); 259 } else { 260 \WP_CLI::warning( sprintf( __( 'Attachment %s not optimized. Reason: %s', 'megaoptim-image-optimizer' ), $image['ID'], $e->getMessage() ) ); 261 break; 262 } 260 263 } 261 264 } 262 265 $time_elapsed_secs = microtime( true ) - $time_start; 263 WP_CLI::success( sprintf( __( 'Process finished in %s seconds. Total optimized %s, Totaal saved %s', 'megaoptim-image-optimizer' ), megaoptim_round( $time_elapsed_secs, 5), $total_optimized, megaoptim_human_file_size($total_saved) ) );266 WP_CLI::success( sprintf( __( 'Process finished in %s seconds. Total optimized %s, Totaal saved %s', 'megaoptim-image-optimizer' ), megaoptim_round( $time_elapsed_secs, 5 ), $total_optimized, megaoptim_human_file_size( $total_saved ) ) ); 264 267 } 265 268 } … … 353 356 megaoptim_regenerate_thumbnails( $attachment_ID, $attachment_path ); 354 357 delete_post_meta( $attachment_ID, '_megaoptim_data' ); 355 do_action( 'megaoptim_after_restore_attachment', new MGO_MediaAttachment( $attachment_ID) );358 do_action( 'megaoptim_after_restore_attachment', new MGO_MediaAttachment( $attachment_ID ) ); 356 359 WP_CLI::success( sprintf( __( 'Attachment %s successfully restored.', 'megaoptim-image-optimizer' ), $attachment_ID ) ); 357 360 $total_restored ++; -
megaoptim-image-optimizer/trunk/includes/classes/MGO_Profile.php
r2138495 r2539116 95 95 $response = wp_remote_post( WP_MEGAOPTIM_API_PROFILE, array( 96 96 'method' => 'POST', 97 'timeout' => 45,97 'timeout' => 10, 98 98 'redirection' => 5, 99 99 'httpversion' => '1.0', … … 150 150 /** 151 151 * Returns the Tokens count left. 152 * 153 * @param $refresh - Refresh if the data is not fresh. 154 * 152 155 * @return mixed|string 153 156 */ 154 public function get_tokens_count( ) {155 if ( ! $this->fresh ) {157 public function get_tokens_count( $refresh = true ) { 158 if ( ! $this->fresh && $refresh ) { 156 159 $this->refresh(); 157 160 } -
megaoptim-image-optimizer/trunk/includes/classes/MGO_ResultBag.php
r2138495 r2539116 20 20 21 21 class MGO_ResultBag { 22 23 22 24 23 public $total_full_size = 0; … … 108 107 ); 109 108 } 109 110 /** 111 * Is errorneous? 112 */ 113 public function is_erroneous() { 114 $totalE = 0; 115 $totalR = 0; 116 foreach ( $this->responses as $response ) { 117 if ( $response->isError() ) { 118 $totalE ++; 119 } 120 $totalR ++; 121 } 122 return $totalR > 0 && $totalR === $totalE; 123 } 124 125 /** 126 * Throw the last error. 127 * @throws MGO_Exception 128 */ 129 public function throw_last_error() { 130 $error = null; 131 foreach ( $this->responses as $response ) { 132 if ( method_exists( $response, 'isError' ) && $response->isError() ) { 133 $error = $response; 134 } 135 } 136 if ( ! empty( $error ) ) { 137 $messages = $error->getErrors(); 138 if ( count( $messages ) > 0 ) { 139 throw new MGO_Exception( $messages[0], $error->getErrorCode() ); 140 } 141 } 142 } 110 143 } -
megaoptim-image-optimizer/trunk/includes/compat/nextgen-gallery/classes/MGO_NGGLibrary.php
r2202391 r2539116 78 78 } 79 79 80 //Dont go further if not connected81 $profile = MGO_Profile::_is_connected();82 if ( ! $profile OR is_null( $this->optimizer ) ) {83 throw new MGO_Exception( 'Please make sure you have set up MegaOptim.com API key' );84 }85 80 //Check if attachment is optimized 86 81 $attachment_object = new MGO_NGGAttachment( $attachment->ID ); … … 94 89 if ( $attachment_object->is_processed() ) { 95 90 throw new MGO_Attachment_Already_Optimized_Exception( 'The attachment is already fully optimized.' ); 96 }97 98 // Bail if no tokens left.99 $tokens = $profile->get_tokens_count();100 if ( $tokens != -1 && $tokens <= 0 ) {101 throw new MGO_Exception( 'No tokens left. Please top up your account at https://megaoptim.com/dashboard in order to continue.' );102 91 } 103 92 … … 116 105 */ 117 106 do_action( 'megaoptim_before_optimization', $attachment_object, $request_params ); 118 119 //Create Backup If needed120 if ( $this->should_backup() ) {121 $backup_path = $attachment_object->backup();122 $attachment_object->set_backup_path( $backup_path );123 }124 107 125 108 // Check if image exist … … 140 123 megaoptim_log('--- API Errors: ' . $response->getErrors() ); 141 124 } else { 125 126 //Create Backup If needed 127 if ( $this->should_backup() ) { 128 $backup_path = $attachment_object->backup(); 129 $attachment_object->set_backup_path( $backup_path ); 130 } 131 142 132 megaoptim_log( '--- Response: ' . $response->getRawResponse() ); 143 133 foreach ( $response->getOptimizedFiles() as $file ) { … … 169 159 } 170 160 161 if ( $result->is_erroneous() ) { 162 $result->throw_last_error(); 163 } 164 171 165 $attachment_object->unlock(); 172 166 … … 204 198 } 205 199 206 //Dont go further if not connected207 $profile = MGO_Profile::_is_connected();208 if ( ! $profile OR is_null( $this->optimizer ) ) {209 throw new MGO_Exception( 'Please make sure you have set up MegaOptim.com API key' );210 }211 200 //Check if attachment is optimized 212 201 $attachment_object = new MGO_NGGAttachment( $attachment->ID ); … … 220 209 if ( $attachment_object->is_processed() ) { 221 210 throw new MGO_Attachment_Already_Optimized_Exception( 'The attachment is already fully optimized.' ); 222 }223 224 // Bail if no tokens left.225 $tokens = $profile->get_tokens_count();226 if ( $tokens != -1 && $tokens <= 0 ) {227 throw new MGO_Exception( 'No tokens left. Please top up your account at https://megaoptim.com/dashboard in order to continue.' );228 211 } 229 212 -
megaoptim-image-optimizer/trunk/includes/hooks/notices.php
r2260564 r2539116 5 5 */ 6 6 function _megaoptim_notice_user_balance() { 7 if ( ! is_admin() ) {7 if ( ! is_admin() || wp_doing_ajax() ) { 8 8 return; 9 9 } 10 10 try { 11 $profile = new MGO_Profile(); 12 $api_key = MGO_Settings::instance()->get( MGO_Settings::API_KEY ); 13 $tokens_count = $profile->get_tokens_count(); 14 if ( !empty($api_key) && intval( $tokens_count ) === 0 ) { 15 $message = sprintf( 16 '%s %s %s %s.', 17 __( 'Your MegaOptim account is out of optimization tokens. To continue using', 'megaoptim-image-optimizer' ), 18 '<strong>' . __( 'MegaOptim Image Optimizer', 'megaoptim-image-optimizer' ) . '</strong>', 19 __( 'please top up your account' ), 20 '<a target="_blank" href="' . WP_MEGAOPTIM_DASHBOARD_URL . '">' . __( 'here', 'megaoptim-image-optimizer' ) . '</a>' 21 ); 22 MGO_Admin_Notices::instance()->warning( 'insufficient_balance', $message, 1 ); 11 $api_key = MGO_Settings::instance()->get( MGO_Settings::API_KEY ); 12 if ( ! empty( $api_key ) ) { 13 $profile = new MGO_Profile( $api_key ); 14 $tokens_count = $profile->get_tokens_count( false ); // use cached results. 15 if ( intval( $tokens_count ) === 0 ) { 16 $message = sprintf( 17 '%s %s %s %s.', 18 __( 'Your MegaOptim account is out of optimization tokens. To continue using', 'megaoptim-image-optimizer' ), 19 '<strong>' . __( 'MegaOptim Image Optimizer', 'megaoptim-image-optimizer' ) . '</strong>', 20 __( 'please top up your account' ), 21 '<a target="_blank" href="' . WP_MEGAOPTIM_DASHBOARD_URL . '">' . __( 'here', 'megaoptim-image-optimizer' ) . '</a>' 22 ); 23 MGO_Admin_Notices::instance()->warning( 'insufficient_balance', $message, 1 ); 24 } 23 25 } 24 26 } catch ( \Exception $exception ) { -
megaoptim-image-optimizer/trunk/megaoptim.php
r2432757 r2539116 6 6 Author: MegaOptim 7 7 Author URI: https://megaoptim.com 8 Version: 1.4.1 18 Version: 1.4.12 9 9 Text Domain: megaoptim-image-optimizer 10 10 Domain Path: /languages … … 15 15 } 16 16 17 define( 'WP_MEGAOPTIM_VER', '1.4.1 1' );17 define( 'WP_MEGAOPTIM_VER', '1.4.12' ); 18 18 define( 'WP_MEGAOPTIM_PATH', plugin_dir_path( __FILE__ ) ); 19 19 define( 'WP_MEGAOPTIM_URL', plugin_dir_url( __FILE__ ) ); … … 21 21 define( 'WP_MEGAOPTIM_PLUGIN_FILE_PATH', __FILE__ ); 22 22 23 require_once( WP_MEGAOPTIM_PATH . 'includes' . DIRECTORY_SEPARATOR . 'loader.php' );23 require_once( WP_MEGAOPTIM_PATH . 'includes' . DIRECTORY_SEPARATOR . 'loader.php' ); -
megaoptim-image-optimizer/trunk/readme.txt
r2432757 r2539116 3 3 Tags: convert webp, webp, optimize images, optimize, images, compress 4 4 Requires at least: 3.6 5 Tested up to: 5. 65 Tested up to: 5.7 6 6 Requires PHP: 5.3 7 Stable tag: 1.4.1 17 Stable tag: 1.4.12 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 43 43 - Compatible with WP Engine, SiteGround and other providers 44 44 - Compatbile with localhost and password protected sites 45 - No credits charged if 5%or less is saved per image45 - No credits charged if %5 or less is saved per image 46 46 - Multisite Support 47 47 … … 138 138 == Changelog == 139 139 140 = 1.4.12 = 141 - Performance optimizations in /wp-admin 142 - Performance optimizations in the Bulk optimization process through the admin UI 143 - Imrpoved WP CLI Bulk optimizer. If there is an error like "No tokens left", terminate the process completely 144 - Removed confirm dialog when refreshing optimizer page for insufficient tokens 145 140 146 = 1.4.11 = 141 - Fix PHP error147 - Fix error triggered when activating the plugin 142 148 143 149 = 1.4.10 =
Note: See TracChangeset
for help on using the changeset viewer.