| @@ -1,20 +1,25 @@ | ||
| 1 | 1 | <?php |
| 2 | + | |
| 3 | +use Imagify\Imagifybeat\Actions; | |
| 4 | +use Imagify\Imagifybeat\Core; | |
| 5 | +use Imagify\Stats\OptimizedMediaWithoutNextGen; | |
| 6 | + | |
| 2 | 7 | defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 3 | 8 | |
| 4 | 9 | /** |
| 5 | 10 | * Get all translations we can use with wp_localize_script(). |
| 6 | 11 | * |
| 7 | - * @since 1.5 | |
| 8 | - * @author Jonathan Buttigieg | |
| 12 | + * @since 1.5 | |
| 9 | 13 | * |
| 10 | - * @param string $context The translation context. | |
| 11 | - * @return array $translations The translations. | |
| 14 | + * @param string $context The translation context. | |
| 15 | + * | |
| 16 | + * @return array $translations The translations. | |
| 12 | 17 | */ |
| 13 | 18 | function get_imagify_localize_script_translations( $context ) { |
| 14 | 19 | global $post_id; |
| 15 | 20 | |
| 16 | - $imagifybeat_actions = \Imagify\Imagifybeat\Actions::get_instance(); | |
| 21 | + $imagifybeat_actions = Actions::get_instance(); | |
| 17 | 22 | |
| 18 | 23 | switch ( $context ) { |
| 19 | 24 | case 'admin-bar': |
| 20 | 25 | if ( is_admin() ) { |
| @@ -39,9 +44,9 @@ | ||
| 39 | 44 | /* translators: Don't use escaped HTML entities here (like ). */ |
| 40 | 45 | 'saveApiKeyTitle' => __( 'Connect to Imagify!', 'imagify' ), |
| 41 | 46 | 'saveApiKeyText' => __( 'Paste your API key below:', 'imagify' ), |
| 42 | 47 | 'saveApiKeyConfirmButtonText' => __( 'Connect me', 'imagify' ), |
| 43 | - 'ApiKeyErrorEmpty' => __( 'You need to specify your api key!', 'imagify' ), | |
| 48 | + 'ApiKeyErrorEmpty' => __( 'You need to specify your API key!', 'imagify' ), | |
| 44 | 49 | 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ), |
| 45 | 50 | 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ), |
| 46 | 51 | ], |
| 47 | 52 | ]; |
| @@ -54,10 +59,16 @@ | ||
| 54 | 59 | ]; |
| 55 | 60 | |
| 56 | 61 | case 'options': |
| 57 | 62 | $translations = [ |
| 58 | - 'getFilesTree' => imagify_can_optimize_custom_folders() ? get_imagify_admin_url( 'get-files-tree' ) : false, | |
| 59 | - 'labels' => [ | |
| 63 | + 'getFilesTree' => imagify_can_optimize_custom_folders() ? get_imagify_admin_url( 'get-files-tree' ) : false, | |
| 64 | + 'resetInternalState' => [ | |
| 65 | + 'action' => 'imagify_reset_internal_state', | |
| 66 | + 'confirm' => __( 'Are you sure you want to reset the Imagify internal state? This will clear optimization locks and cancel any pending jobs.', 'imagify' ), | |
| 67 | + 'success' => __( 'Imagify internal state has been reset successfully.', 'imagify' ), | |
| 68 | + 'error' => __( 'An error occurred while resetting the internal state. Please try again.', 'imagify' ), | |
| 69 | + ], | |
| 70 | + 'labels' => [ | |
| 60 | 71 | 'ValidApiKeyText' => __( 'Your API key is valid.', 'imagify' ), |
| 61 | 72 | 'waitApiKeyCheckText' => __( 'Check in progress...', 'imagify' ), |
| 62 | 73 | 'ApiKeyCheckSuccessTitle' => __( 'Congratulations!', 'imagify' ), |
| 63 | 74 | 'ApiKeyCheckSuccessText' => __( 'Your API key is valid. You can now configure the Imagify settings to optimize your images.', 'imagify' ), |
| @@ -73,31 +84,34 @@ | ||
| 73 | 84 | 'themesAdded' => __( 'Added! All Good!', 'imagify' ), |
| 74 | 85 | ], |
| 75 | 86 | ]; |
| 76 | 87 | |
| 77 | - if ( \Imagify\Stats\OptimizedMediaWithoutWebp::get_instance()->get_cached_stat() ) { | |
| 88 | + if ( OptimizedMediaWithoutNextGen::get_instance()->get_cached_stat() ) { | |
| 78 | 89 | $contexts = imagify_get_context_names(); |
| 79 | 90 | $translations['bulk'] = [ |
| 80 | - 'curlMissing' => ! Imagify_Requirements::supports_curl(), | |
| 81 | - 'editorMissing' => ! Imagify_Requirements::supports_image_editor(), | |
| 82 | - 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(), | |
| 83 | - 'apiDown' => ! Imagify_Requirements::is_api_up(), | |
| 84 | - 'keyIsValid' => Imagify_Requirements::is_api_key_valid(), | |
| 85 | - 'isOverQuota' => Imagify_Requirements::is_over_quota(), | |
| 86 | - 'imagifybeatIDs' => [ | |
| 87 | - 'queue' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_status' ), | |
| 91 | + 'curlMissing' => ! Imagify_Requirements::supports_curl(), | |
| 92 | + 'editorMissing' => ! Imagify_Requirements::supports_image_editor(), | |
| 93 | + 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(), | |
| 94 | + 'apiDown' => ! Imagify_Requirements::is_api_up(), | |
| 95 | + 'keyIsValid' => Imagify_Requirements::is_api_key_valid(), | |
| 96 | + 'isOverQuota' => Imagify_Requirements::is_over_quota(), | |
| 97 | + 'imagifybeatIDs' => [ | |
| 98 | + 'progress' => $imagifybeat_actions->get_imagifybeat_id( 'options_optimization_status' ), | |
| 88 | 99 | 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ), |
| 89 | 100 | ], |
| 90 | - 'ajaxActions' => [ | |
| 91 | - 'getMediaIds' => 'imagify_get_media_ids', | |
| 92 | - 'bulkProcess' => 'imagify_bulk_optimize', | |
| 101 | + 'ajaxActions' => [ | |
| 102 | + 'MissingNextGen' => 'imagify_missing_nextgen_generation', | |
| 93 | 103 | ], |
| 94 | - 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ), | |
| 95 | - 'contexts' => $contexts, | |
| 96 | - 'labels' => [ | |
| 104 | + 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ), | |
| 105 | + 'contexts' => $contexts, | |
| 106 | + 'progress_next_gen' => [ | |
| 107 | + 'remaining' => OptimizedMediaWithoutNextGen::get_instance()->get_stat(), | |
| 108 | + 'total' => get_transient( 'imagify_missing_next_gen_total' ), | |
| 109 | + ], | |
| 110 | + 'labels' => [ | |
| 97 | 111 | 'curlMissing' => __( 'cURL is not available on the server.', 'imagify' ), |
| 98 | 112 | 'editorMissing' => sprintf( |
| 99 | - /* translators: %s is a "More info?" link. */ | |
| 113 | + // translators: %s is a "More info?" link. | |
| 100 | 114 | __( 'No php extensions are available to edit images on the server. ImageMagick or GD is required. %s', 'imagify' ), |
| 101 | 115 | '<a href="' . esc_url( imagify_get_external_url( 'documentation-imagick-gd' ) ) . '" target="_blank">' . __( 'More info?', 'imagify' ) . '</a>' |
| 102 | 116 | ), |
| 103 | 117 | 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ), |
| @@ -103,12 +117,11 @@ | ||
| 103 | 117 | 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ), |
| 104 | 118 | 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ), |
| 105 | 119 | 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ), |
| 106 | 120 | 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ), |
| 107 | - 'processing' => __( 'Imagify is still processing. Are you sure you want to leave this page?', 'imagify' ), | |
| 108 | 121 | 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ), |
| 109 | - 'nothingToDoText' => __( 'All your optimized images already have a WebP version. Congratulations!', 'imagify' ), | |
| 110 | - 'nothingToDoNoBackupText' => __( 'Because the selected images did not have a backup copy, Imagify was unable to create WebP versions.', 'imagify' ), | |
| 122 | + 'nothingToDoText' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ), | |
| 123 | + 'nothingToDoNoBackupText' => __( 'Because the selected images did not have a backup copy, Imagify was unable to create next-gen versions.', 'imagify' ), | |
| 111 | 124 | 'error' => __( 'Error', 'imagify' ), |
| 112 | 125 | 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ), |
| 113 | 126 | 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ), |
| 114 | 127 | 'getUnoptimizedImagesErrorText' => __( 'An unknown error occurred when we tried to get all your unoptimized media files. Try again and if the issue still persists, please contact us!', 'imagify' ), |
| @@ -130,15 +143,19 @@ | ||
| 130 | 143 | return $translations; |
| 131 | 144 | |
| 132 | 145 | case 'pricing-modal': |
| 133 | 146 | $translations = [ |
| 134 | - 'imagify_app_domain' => IMAGIFY_APP_DOMAIN, | |
| 135 | - 'labels' => [ | |
| 136 | - 'errorCouponAPI' => __( 'Error with checking this coupon.', 'imagify' ), | |
| 137 | - /* translators: 1 is a percentage, 2 is a coupon code. */ | |
| 138 | - 'successCouponAPI' => sprintf( _x( '%1$s off with %2$s', 'coupon validated', 'imagify' ), '<span class="imagify-coupon-offer"></span>', '<strong class="imagify-coupon-word"></strong>' ), | |
| 139 | - 'errorPriceAPI' => __( 'Something went wrong with getting our updated offers. Please retry later.', 'imagify' ), | |
| 140 | - 'defaultCouponLabel' => __( 'If you have a <strong>coupon code</strong><br> use it here:', 'imagify' ), | |
| 147 | + 'imagify_app_domain' => IMAGIFY_APP_DOMAIN, | |
| 148 | + 'labels' => [ | |
| 149 | + 'errorCouponAPI' => __( 'Error with checking this coupon.', 'imagify' ), | |
| 150 | + 'successCouponAPI' => sprintf( | |
| 151 | + /* translators: 1 is a percentage, 2 is a coupon code. */ | |
| 152 | + _x( '%1$s off with %2$s', 'coupon validated', 'imagify' ), | |
| 153 | + '<span class="imagify-coupon-offer"></span>', | |
| 154 | + '<strong class="imagify-coupon-word"></strong>' | |
| 155 | + ), | |
| 156 | + 'errorPriceAPI' => __( 'Something went wrong with getting our updated offers. Please retry later.', 'imagify' ), | |
| 157 | + 'defaultCouponLabel' => __( 'If you have a <strong>coupon code</strong><br> use it here:', 'imagify' ), | |
| 141 | 158 | 'errorCouponPlan' => __( 'This coupon is not valid with this plan.', 'imagify' ), |
| 142 | 159 | ], |
| 143 | 160 | ]; |
| 144 | 161 | |
| @@ -165,9 +182,9 @@ | ||
| 165 | 182 | $media = $process->get_media(); |
| 166 | 183 | |
| 167 | 184 | if ( $media->is_image() ) { |
| 168 | 185 | $dimensions = $media->get_dimensions(); |
| 169 | - $image = [ | |
| 186 | + $image = [ | |
| 170 | 187 | 'src' => $media->get_fullsize_url(), |
| 171 | 188 | 'width' => $dimensions['width'], |
| 172 | 189 | 'height' => $dimensions['height'], |
| 173 | 190 | ]; |
| @@ -191,9 +208,9 @@ | ||
| 191 | 208 | ], |
| 192 | 209 | ]; |
| 193 | 210 | |
| 194 | 211 | case 'beat': |
| 195 | - return \Imagify\Imagifybeat\Core::get_instance()->get_settings(); | |
| 212 | + return Core::get_instance()->get_settings(); | |
| 196 | 213 | |
| 197 | 214 | case 'media-modal': |
| 198 | 215 | return [ |
| 199 | 216 | 'imagifybeatID' => $imagifybeat_actions->get_imagifybeat_id( 'library_optimization_status' ), |
| @@ -210,32 +227,33 @@ | ||
| 210 | 227 | ]; |
| 211 | 228 | |
| 212 | 229 | case 'bulk': |
| 213 | 230 | $translations = [ |
| 214 | - 'curlMissing' => ! Imagify_Requirements::supports_curl(), | |
| 215 | - 'editorMissing' => ! Imagify_Requirements::supports_image_editor(), | |
| 216 | - 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(), | |
| 217 | - 'apiDown' => Imagify_Requirements::is_imagify_blocked() || ! Imagify_Requirements::is_api_up(), | |
| 218 | - 'keyIsValid' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid(), | |
| 219 | - 'isOverQuota' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid() && Imagify_Requirements::is_over_quota(), | |
| 220 | - 'imagifybeatIDs' => [ | |
| 231 | + 'curlMissing' => ! Imagify_Requirements::supports_curl(), | |
| 232 | + 'editorMissing' => ! Imagify_Requirements::supports_image_editor(), | |
| 233 | + 'extHttpBlocked' => Imagify_Requirements::is_imagify_blocked(), | |
| 234 | + 'apiDown' => Imagify_Requirements::is_imagify_blocked() || ! Imagify_Requirements::is_api_up(), | |
| 235 | + 'keyIsValid' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid(), | |
| 236 | + 'isOverQuota' => ! Imagify_Requirements::is_imagify_blocked() && Imagify_Requirements::is_api_up() && Imagify_Requirements::is_api_key_valid() && Imagify_Requirements::is_over_quota(), | |
| 237 | + 'imagifybeatIDs' => [ | |
| 221 | 238 | 'stats' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_stats' ), |
| 222 | 239 | 'queue' => $imagifybeat_actions->get_imagifybeat_id( 'bulk_optimization_status' ), |
| 223 | 240 | 'requirements' => $imagifybeat_actions->get_imagifybeat_id( 'requirements' ), |
| 224 | 241 | ], |
| 225 | - 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg', | |
| 226 | - 'ajaxActions' => [ | |
| 227 | - 'getMediaIds' => 'imagify_get_media_ids', | |
| 242 | + 'waitImageUrl' => IMAGIFY_ASSETS_IMG_URL . 'popin-loader.svg', | |
| 243 | + 'ajaxActions' => [ | |
| 228 | 244 | 'bulkProcess' => 'imagify_bulk_optimize', |
| 245 | + 'bulkStop' => 'imagify_bulk_stop', | |
| 229 | 246 | 'getFolderData' => 'imagify_get_folder_type_data', |
| 230 | 247 | 'bulkInfoSeen' => 'imagify_bulk_info_seen', |
| 231 | 248 | ], |
| 232 | - 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ), | |
| 233 | - 'bufferSizes' => [ | |
| 249 | + 'ajaxNonce' => wp_create_nonce( 'imagify-bulk-optimize' ), | |
| 250 | + 'bufferSizes' => [ | |
| 234 | 251 | 'wp' => 4, |
| 235 | 252 | 'custom-folders' => 4, |
| 236 | 253 | ], |
| 237 | - 'labels' => [ | |
| 254 | + 'optimizing' => get_transient( 'imagify_custom-folders_optimize_running' ) || get_transient( 'imagify_wp_optimize_running' ), | |
| 255 | + 'labels' => [ | |
| 238 | 256 | 'overviewChartLabels' => [ |
| 239 | 257 | 'unoptimized' => __( 'Unoptimized', 'imagify' ), |
| 240 | 258 | 'optimized' => __( 'Optimized', 'imagify' ), |
| 241 | 259 | 'error' => __( 'Error', 'imagify' ), |
| @@ -249,15 +267,14 @@ | ||
| 249 | 267 | 'extHttpBlocked' => __( 'External HTTP requests are blocked.', 'imagify' ), |
| 250 | 268 | 'apiDown' => __( 'Sorry, our servers are temporarily unavailable. Please, try again in a couple of minutes.', 'imagify' ), |
| 251 | 269 | 'invalidAPIKeyTitle' => __( 'Your API key is not valid!', 'imagify' ), |
| 252 | 270 | 'overQuotaTitle' => __( 'You have used all your credits!', 'imagify' ), |
| 253 | - 'processing' => __( 'Imagify is still processing. Are you sure you want to leave this page?', 'imagify' ), | |
| 254 | 271 | 'waitTitle' => __( 'Please wait...', 'imagify' ), |
| 255 | 272 | 'waitText' => __( 'We are trying to get your unoptimized media files, it may take time depending on the number of files.', 'imagify' ), |
| 256 | 273 | 'nothingToDoTitle' => __( 'Hold on!', 'imagify' ), |
| 257 | 274 | 'nothingToDoText' => [ |
| 258 | 275 | 'optimize' => __( 'All your media files have been optimized by Imagify. Congratulations!', 'imagify' ), |
| 259 | - 'generate_webp' => __( 'All your optimized images already have a WebP version. Congratulations!', 'imagify' ), | |
| 276 | + 'generate_webp' => __( 'All your optimized images already have a next-gen version. Congratulations!', 'imagify' ), | |
| 260 | 277 | ], |
| 261 | 278 | 'optimizing' => __( 'Optimizing', 'imagify' ), |
| 262 | 279 | 'error' => __( 'Error', 'imagify' ), |
| 263 | 280 | 'ajaxErrorText' => __( 'The operation failed.', 'imagify' ), |
| @@ -267,11 +284,8 @@ | ||
| 267 | 284 | 'nbrFiles' => __( '%s file(s)', 'imagify' ), |
| 268 | 285 | 'notice' => _x( 'Notice', 'noun', 'imagify' ), |
| 269 | 286 | /* translators: %s is a number. Don't use %d. */ |
| 270 | 287 | 'nbrErrors' => __( '%s error(s)', 'imagify' ), |
| 271 | - /* translators: 1 and 2 are file sizes. Don't use HTML entities here (like ). */ | |
| 272 | - 'textToShare' => __( 'Discover @imagify, the new compression tool to optimize your images for free. I saved %1$s out of %2$s!', 'imagify' ), | |
| 273 | - 'twitterShareURL' => imagify_get_external_url( 'share-twitter' ), | |
| 274 | 288 | 'getUnoptimizedImagesErrorTitle' => __( 'Oops, There is something wrong!', 'imagify' ), |
| 275 | 289 | 'getUnoptimizedImagesErrorText' => __( 'An unknown error occurred when we tried to get all your unoptimized media files. Try again and if the issue still persists, please contact us!', 'imagify' ), |
| 276 | 290 | 'waitingOtimizationsText' => __( 'Waiting other optimizations to finish.', 'imagify' ), |
| 277 | 291 | /* translators: %s is a formatted number, dont use %d. */ |
| @@ -279,8 +293,17 @@ | ||
| 279 | 293 | /* translators: %s is a formatted number, dont use %d. */ |
| 280 | 294 | 'imagesErrorText' => __( '%s Error(s)', 'imagify' ), |
| 281 | 295 | 'bulkInfoTitle' => __( 'Information', 'imagify' ), |
| 282 | 296 | 'confirmBulk' => __( 'Start the optimization', 'imagify' ), |
| 297 | + 'stopTitle' => __( 'Stop the optimization?', 'imagify' ), | |
| 298 | + 'stopText' => __( 'Media files still waiting in the queue will not be optimized. The media file currently being processed cannot be interrupted. You can restart the optimization at any time.', 'imagify' ), | |
| 299 | + 'confirmStop' => __( 'Stop the optimization', 'imagify' ), | |
| 300 | + 'cancelStop' => __( 'Continue the optimization', 'imagify' ), | |
| 301 | + 'stoppedTitle' => __( 'Optimization stopped', 'imagify' ), | |
| 302 | + /* translators: %s is a number. Don't use %d. */ | |
| 303 | + 'stoppedText' => __( '%s media file(s) were removed from the queue.', 'imagify' ), | |
| 304 | + 'stoppedNothingQueuedText' => __( 'The optimization was stopped. No media file was left in the queue.', 'imagify' ), | |
| 305 | + 'stopErrorText' => __( 'The optimization could not be stopped. Please reload the page and try again.', 'imagify' ), | |
| 283 | 306 | ], |
| 284 | 307 | ]; |
| 285 | 308 | |
| 286 | 309 | if ( get_transient( 'imagify_large_library' ) ) { |
| @@ -325,6 +348,6 @@ | ||
| 325 | 348 | ]; |
| 326 | 349 | |
| 327 | 350 | default: |
| 328 | 351 | return []; |
| 329 | - } // End switch(). | |
| 352 | + } | |
| 330 | 353 | } |