Lazy Load - Version 0.6.1

Version Description

  • Security: XSS fix (reported by Jouko Pynnne
Download this release

Release Info

Developer philipjohn
Plugin Icon wp plugin Lazy Load
Version 0.6.1
Comparing to
See all releases

Code changes from version 0.6 to 0.6.1

Files changed (2) hide show
  1. lazy-load.php +37 -5
  2. readme.txt +6 -2
lazy-load.php CHANGED
@@ -2,7 +2,7 @@
2
  /**
3
  * Plugin Name: Lazy Load
4
  * Description: Lazy load images to improve page load times. Uses jQuery.sonar to only load an image when it's visible in the viewport.
5
- * Version: 0.6
6
  * Text Domain: lazy-load
7
  *
8
  * Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
@@ -15,7 +15,7 @@ if ( ! class_exists( 'LazyLoad_Images' ) ) :
15
 
16
  class LazyLoad_Images {
17
 
18
- const version = '0.6';
19
  protected static $enabled = true;
20
 
21
  static function init() {
@@ -54,13 +54,45 @@ class LazyLoad_Images {
54
  if ( false !== strpos( $content, 'data-lazy-src' ) )
55
  return $content;
56
 
 
 
 
 
 
 
 
57
  // In case you want to change the placeholder image
58
  $placeholder_image = apply_filters( 'lazyload_images_placeholder_image', self::get_url( 'images/1x1.trans.gif' ) );
59
 
60
- // This is a pretty simple regex, but it works
61
- $content = preg_replace( '#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf( '<img${1}src="%s" data-lazy-src="${2}"${3}><noscript><img${1}src="${2}"${3}></noscript>', $placeholder_image ), $content );
62
 
63
- return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  }
65
 
66
  static function is_enabled() {
2
  /**
3
  * Plugin Name: Lazy Load
4
  * Description: Lazy load images to improve page load times. Uses jQuery.sonar to only load an image when it's visible in the viewport.
5
+ * Version: 0.6.1
6
  * Text Domain: lazy-load
7
  *
8
  * Code by the WordPress.com VIP team, TechCrunch 2011 Redesign team, and Jake Goldman (10up LLC).
15
 
16
  class LazyLoad_Images {
17
 
18
+ const version = '0.6.1';
19
  protected static $enabled = true;
20
 
21
  static function init() {
54
  if ( false !== strpos( $content, 'data-lazy-src' ) )
55
  return $content;
56
 
57
+ // This is a pretty simple regex, but it works
58
+ $content = preg_replace_callback( '#<(img)([^>]+?)(>(.*?)</\\1>|[\/]?>)#si', array( __CLASS__, 'process_image' ), $content );
59
+
60
+ return $content;
61
+ }
62
+
63
+ static function process_image( $matches ) {
64
  // In case you want to change the placeholder image
65
  $placeholder_image = apply_filters( 'lazyload_images_placeholder_image', self::get_url( 'images/1x1.trans.gif' ) );
66
 
67
+ $old_attributes_str = $matches[2];
68
+ $old_attributes = wp_kses_hair( $old_attributes_str, wp_allowed_protocols() );
69
 
70
+ if ( empty( $old_attributes['src'] ) ) {
71
+ return $matches[0];
72
+ }
73
+
74
+ $image_src = $old_attributes['src']['value'];
75
+
76
+ // Remove src and lazy-src since we manually add them
77
+ $new_attributes = $old_attributes;
78
+ unset( $new_attributes['src'], $new_attributes['data-lazy-src'] );
79
+
80
+ $new_attributes_str = self::build_attributes_string( $new_attributes );
81
+
82
+ return sprintf( '<img src="%1$s" data-lazy-src="%2$s" %3$s><noscript>%4$s</noscript>', esc_url( $placeholder_image ), esc_url( $image_src ), $new_attributes_str, $matches[0] );
83
+ }
84
+
85
+ private static function build_attributes_string( $attributes ) {
86
+ $string = array();
87
+ foreach ( $attributes as $name => $attribute ) {
88
+ $value = $attribute['value'];
89
+ if ( '' === $value ) {
90
+ $string[] = sprintf( '%s', $name );
91
+ } else {
92
+ $string[] = sprintf( '%s="%s"', $name, esc_attr( $value ) );
93
+ }
94
+ }
95
+ return implode( ' ', $string );
96
  }
97
 
98
  static function is_enabled() {
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: batmoo, automattic, jakemgold, 10up
3
  Tags: lazy load, images, front-end optimization
4
  Requires at least: 3.2
5
- Tested up to: 4.5
6
- Stable tag: 0.6
7
 
8
  Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
9
 
@@ -58,6 +58,10 @@ This will lazy load <em>all</em> your images.
58
 
59
  == Changelog ==
60
 
 
 
 
 
61
  = 0.6 =
62
 
63
  * Filter to control when lazy loading is enabled
2
  Contributors: batmoo, automattic, jakemgold, 10up
3
  Tags: lazy load, images, front-end optimization
4
  Requires at least: 3.2
5
+ Tested up to: 4.6
6
+ Stable tag: 0.6.1
7
 
8
  Lazy load images to improve page load times and server bandwidth. Images are loaded only when visible to the user.
9
 
58
 
59
  == Changelog ==
60
 
61
+ = 0.6.1 =
62
+
63
+ * Security: XSS fix (reported by <a href="https://klikki.fi/">Jouko Pynnöne</a>
64
+
65
  = 0.6 =
66
 
67
  * Filter to control when lazy loading is enabled