Changeset 2789870
- Timestamp:
- 09/25/2022 01:01:25 PM (4 years ago)
- Location:
- wp-performance-pack/trunk
- Files:
-
- 7 edited
-
modules/dynamic_images/class.wppp_dynamic_images.php (modified) (4 diffs)
-
modules/dynamic_images/class.wppp_rewrite.php (modified) (1 diff)
-
modules/dynamic_images/class.wppp_serve_image.php (modified) (3 diffs)
-
modules/dynamic_images/serve-dynamic-images-ut.php (modified) (1 diff)
-
modules/dynamic_images/serve-dynamic-images.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
wp-performance-pack.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-performance-pack/trunk/modules/dynamic_images/class.wppp_dynamic_images.php
r2369424 r2789870 10 10 11 11 class WPPP_Dynamic_Images extends WPPP_Module { 12 p rivate $dynimg_image_sizes = NULL;12 public static $rewrite_regex = '(.+)-([0-9]+x[0-9]+)\.((?i)jpeg|jpg|png|gif)'; 13 13 14 14 public $rw_folder = false; … … 97 97 } 98 98 $path = substr( plugins_url( $file, __FILE__ ), strlen( site_url() ) + 1 ); // cut wp-content including trailing slash 99 add_rewrite_rule( '(.*)-([0-9]+)x([0-9]+)?\.((?i)jpeg|jpg|png|gif)', $path, 'top' );99 add_rewrite_rule( WPPP_Dynamic_Images::$rewrite_regex, $path, 'top' ); 100 100 add_filter ( 'mod_rewrite_rules', array ( $this, 'mod_rewrite_rules' ) ); 101 101 } … … 114 114 // init is called prior to options update 115 115 // so add or remove rules before flushing 116 117 116 if ( $enabled ) { 118 117 $this->set_rewrite_rules(); 118 flush_rewrite_rules(); 119 119 } else { 120 global $wp_rewrite; 121 if ( $wp_rewrite && isset( $wp_rewrite->non_wp_rules['(.*)-([0-9]+)x([0-9]+)?\.((?i)jpeg|jpg|png|gif)'] ) ) { 122 unset( $wp_rewrite->non_wp_rules['(.*)-([0-9]+)x([0-9]+)?\.((?i)jpeg|jpg|png|gif)'] ); 123 } 120 WPPP_Dynamic_Images::static_disable_rewrite_rules(); 121 } 122 } 123 124 public static function static_disable_rewrite_rules() { 125 // init is called prior to options update 126 // so add or remove rules before flushing 127 global $wp_rewrite; 128 if ( $wp_rewrite && isset( $wp_rewrite->non_wp_rules[ WPPP_Dynamic_Images::$rewrite_regex ] ) ) { 129 unset( $wp_rewrite->non_wp_rules[ WPPP_Dynamic_Images::$rewrite_regex ] ); 124 130 } 125 131 flush_rewrite_rules(); … … 268 274 $intersizes = get_intermediate_image_sizes(); 269 275 foreach ( $intersizes as $s ) { 270 $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); 271 if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) { 272 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes 273 } else { 274 $sizes[$s]['width'] = intval ( get_option( "{$s}_size_w" ) ); // For default sizes set in options 275 if ( $sizes[$s]['width'] == 0 ) { 276 unset( $sizes[$s] ); 277 continue; 278 } 279 } 280 if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) { 281 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes 282 } else { 283 $sizes[$s]['height'] = intval ( get_option( "{$s}_size_h" ) ); // For default sizes set in options 284 if ( $sizes[$s]['height'] == 0 ) { 285 unset( $sizes[$s] ); 286 continue; 287 } 288 } 289 if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) { 290 $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop'] ? true : false; // For theme-added sizes 291 } else { 292 $sizes[$s]['crop'] = get_option( "{$s}_crop" ) ? true : false; // For default sizes set in options 276 $sizes[ $s ] = array( 'width' => 0, 'height' => 0, 'crop' => false ); 277 if ( in_array( $s, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) { 278 $sizes[ $s ][ 'width' ] = intval( get_option( $s . '_size_w' ) ); 279 $sizes[ $s ][ 'height' ] = intval( get_option( $s . '_size_h' ) ); 280 $sizes[ $s ][ 'crop' ] = get_option( $s . '_crop' ) ? true : false; 281 } elseif ( isset( $_wp_additional_image_sizes[ $s ] ) ) { 282 $sizes[ $s ][ 'width' ] = intval( $_wp_additional_image_sizes[ $s ][ 'width' ] ); 283 $sizes[ $s ][ 'height' ] = intval( $_wp_additional_image_sizes[ $s ][ 'height' ] ); 284 $sizes[ $s ][ 'crop' ] = $_wp_additional_image_sizes[$s]['crop'] ? true : false; 285 } 286 if ( ( $sizes[ $s ][ 'width' ] == 0 ) && ( $sizes[ $s ][ 'height' ] == 0 ) ) { 287 // unset size if both width and height are 0. This is due to special sizes like "medium_large" 288 // "medium_large" can have a fixed width but has no height limit. 289 unset( $sizes[ $s ] ); 293 290 } 294 291 } -
wp-performance-pack/trunk/modules/dynamic_images/class.wppp_rewrite.php
r2240498 r2789870 66 66 $upbase = parse_url( wp_upload_dir()[ 'baseurl' ], PHP_URL_PATH ); 67 67 $wppp .= "RewriteCond %{REQUEST_FILENAME} !-f 68 RewriteCond %{REQUEST_URI} {$upbase}(.*) $69 RewriteCond %{DOCUMENT_ROOT}{$content}/wppp/images/%1 -f70 RewriteRule .* {$content}/wppp/images/%1 [L]68 RewriteCond %{REQUEST_URI} {$upbase}(.*)\.((?i)jpeg|jpg|png|gif)$ 69 RewriteCond %{DOCUMENT_ROOT}{$content}/wppp/images/%1.%2 -f 70 RewriteRule .* {$content}/wppp/images/%1.%2 [L] 71 71 "; 72 72 } 73 74 73 $wppp .= "RewriteCond %{REQUEST_FILENAME} !-f 75 RewriteRule ^(. *)-([0-9]+)x([0-9]+)?\.((?i)jpeg|jpg|png|gif){$rewrite_base}wp-content/plugins/wp-performance-pack/modules/dynamic_images/{$wppp_file} [QSA,L]74 RewriteRule ^(.+)-([0-9]+x[0-9]+)\.((?i)jpeg|jpg|png|gif)$ {$rewrite_base}wp-content/plugins/wp-performance-pack/modules/dynamic_images/{$wppp_file} [QSA,L] 76 75 #WPPP End"; 77 76 } -
wp-performance-pack/trunk/modules/dynamic_images/class.wppp_serve_image.php
r2789717 r2789870 51 51 */ 52 52 function exit404( $message ) { 53 global $wp_query; 54 if ( isset( $wp_query ) ) { 55 $wp_query->set_404(); 56 status_header( 404 ); 57 } else { 58 header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' ); 59 header( 'Cache-Control: no-cache, must-revalidate' ); // HTTP/1.1 60 header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date 61 echo $message; 62 exit(); 63 } 53 64 } 54 65 … … 196 207 $new_size = image_resize_dimensions( $imgsize[ 'width' ], $imgsize[ 'height' ], $size_data[ 'width' ], $size_data[ 'height' ], $size_data[ 'crop' ] ); 197 208 if ( ( abs( $new_size[ 4 ] - $this->width ) <= 1 ) && ( abs( $new_size[ 5 ] - $this->height ) <= 1 ) ) { 198 // allow size to vary by one pixel to catch rounding differences in size calculation 209 // allow size to vary by one pixel to catch rounding differences in size calculation 199 210 $the_size = $size; 200 211 $crop = $size_data[ 'crop' ]; … … 208 219 } 209 220 unset( $sizes ); 210 211 /*212 if ( $crop )213 header('Location: http://192.168.3.5:8085/insecure/rs:fill:' . $this->width . ':' . $this->height . ':1/g:sm/plain/local://' . $this->filename );214 else215 header('Location: http://192.168.3.5:8085/insecure/rs:fit:' . $this->width . ':' . $this->height . ':1/g:sm/plain/local://' . $this->filename );216 exit;217 */218 221 219 222 // create intermediate file name before resizing in order to serve intermediate images from file if they are mirrored into wppp folder -
wp-performance-pack/trunk/modules/dynamic_images/serve-dynamic-images-ut.php
r2258139 r2789870 31 31 } 32 32 33 function exit404( $message ) {34 header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );35 header( 'Cache-Control: no-cache, must-revalidate' ); // HTTP/1.136 header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date37 echo $message;38 exit();39 }40 41 33 function load_wppp() { 42 34 global $wp_performance_pack; -
wp-performance-pack/trunk/modules/dynamic_images/serve-dynamic-images.php
r2325721 r2789870 2 2 /** 3 3 * Serve intermediate images on demand. Is called via mod_rewrite rule. 4 * This file is used, when ShortInit is selected as server method. 5 * 4 6 * 5 7 * @author Björn Ahrens … … 11 13 12 14 class WPPP_Serve_Image_SI extends WPPP_Serve_Image { 13 14 function exit404( $message ) {15 header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );16 header( 'Cache-Control: no-cache, must-revalidate' ); // HTTP/1.117 header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date18 echo $message;19 exit();20 }21 15 22 16 function init( $request ) { -
wp-performance-pack/trunk/readme.txt
r2789819 r2789870 3 3 Tags: performance, image resizing, gettext, disable, cdn 4 4 Requires at least: 4.7 5 Tested up to: 6. 25 Tested up to: 6.0.2 6 6 Requires PHP: 5.3 7 Stable tag: 2.5. 17 Stable tag: 2.5.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 124 124 == Changelog == 125 125 126 = 2.5.2 = 127 * [dynimg] Correct handling of special image sizes like "medium_large" (thanks @madmax4ever) 128 * [dynimg] Improved rewrite rules (thanks @madmax4ever) 129 * [dynimg] Better 404 handling (thanks @madmax4ever) 130 * Removed deprecated call when deactivating the plugin (thanks @madmax4ever) 131 126 132 = 2.5.1 = 127 133 * [wpfeatures] Fixed comment entries in admin menu not being disabled correctly -
wp-performance-pack/trunk/wp-performance-pack.php
r2789819 r2789870 4 4 Plugin URI: http://wordpress.org/plugins/wp-performance-pack 5 5 Description: Performance optimizations for WordPress. Improve localization performance and image handling, serve images through CDN. 6 Version: 2.5. 16 Version: 2.5.2 7 7 Text Domain: wp-performance-pack 8 8 Author: Björn Ahrens … … 130 130 * @const string 131 131 */ 132 const wppp_version = '2.5. 1';132 const wppp_version = '2.5.2'; 133 133 134 134 /** … … 360 360 if ( $this->options['dynamic_images'] ) { 361 361 // Delete rewrite rules from htaccess 362 WPPP_Dynamic_Images:: flush_rewrite_rules( false);362 WPPP_Dynamic_Images::static_disable_rewrite_rules(); 363 363 } 364 364
Note: See TracChangeset
for help on using the changeset viewer.