Changeset 1747601
- Timestamp:
- 10/17/2017 02:33:30 AM (8 years ago)
- Location:
- easy-lazy-loader/trunk
- Files:
-
- 4 edited
-
easy-lazy-loader.php (modified) (14 diffs)
-
js/easy-lazy-loader.js (modified) (1 diff)
-
js/easy-lazy-loader.min.js (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easy-lazy-loader/trunk/easy-lazy-loader.php
r1747565 r1747601 2 2 /* 3 3 Plugin Name: Easy Lazy Loader 4 Version: 1. 0.04 Version: 1.1.0 5 5 Plugin URI: https://www.iprodev.com/go/easy-lazy-loader/ 6 6 Author: iProDev … … 16 16 17 17 class EasyLazyLoader { 18 const version = '1. 0.0';18 const version = '1.1.0'; 19 19 20 20 public $MAIN; … … 497 497 498 498 public function enqueue_scripts() { 499 wp_enqueue_script( 'jquery-sonar', self::get_url( $this->OPTIONS['debug_mode'] ? 'js/jquery.sonar.js' : 'js/jquery.sonar.min.js' ), array( 'jquery' ), self::version, true );499 wp_enqueue_script( 'jquery-sonar', self::get_url( $this->OPTIONS['debug_mode'] ? 'js/jquery.sonar.js' : 'js/jquery.sonar.min.js' ), array( 'jquery' ), '3.0.0', true ); 500 500 wp_enqueue_script( $this->SLUG, self::get_url( $this->OPTIONS['debug_mode'] ? 'js/easy-lazy-loader.js' : 'js/easy-lazy-loader.min.js' ), array( 'jquery', 'jquery-sonar' ), self::version, true ); 501 501 … … 614 614 preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $imgHTML, $width_match ); 615 615 preg_match( '/height=["|\']([^("|\')]+)["|\']/i', $imgHTML, $height_match ); 616 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : 1;617 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : 1;616 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : '2'; 617 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : '1'; 618 618 619 619 // don't to the replacement if the image is a data-uri … … 621 621 622 622 $placeholder_url_used = $placeholder_url; 623 if ( in_array( $placeholder_type, array( 'lowres', 'color' ) ) ) {623 if ( in_array( $placeholder_type, array( 'lowres', 'color', 'default' ) ) ) { 624 624 $img_id = false; 625 625 if( preg_match( '/class=["\'].*?wp-image-([0-9]*)/is', $imgHTML, $id_matches ) ) 626 626 $img_id = intval( $id_matches[1] ); 627 else if ( preg_match( '/src=(["\'])(.*?)["\']/is', $imgHTML, $src_matches ) ) 628 $img_id = $this->get_attachment_id_from_src( $src_matches[2] ); 627 629 628 630 // use low res preview image as placeholder if applicable … … 644 646 } 645 647 646 $placeholder_url_used = self::create_placeholder( $placeholder_color, $width, $height, 'Image loading...' ); 648 $placeholder_url_used = self::create_placeholder( $placeholder_color, (int) $width, (int) $height, 'Image loading...' ); 649 } 650 // use transparent as placeholder if applicable 651 else if ( 'default' === $placeholder_type && !is_string( $width ) && !is_string( $height ) ) { 652 $placeholder_url_used = self::create_placeholder( $placeholder_color, (int) $width, (int) $height ); 647 653 } 648 654 } … … 692 698 693 699 if ( ! strlen( $placeholder_url ) ) { 694 $placeholder_url = 'data:image/gif;base64,R0lGOD dhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';700 $placeholder_url = 'data:image/gif;base64,R0lGODlhAgABAIAAAP///wAAACH5BAEAAAAALAAAAAACAAEAAAICBAoAOw=='; 695 701 } 696 702 … … 710 716 preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $iframeHTML, $width_match ); 711 717 preg_match( '/height=["|\']([^("|\')]+)["|\']/i', $iframeHTML, $height_match ); 712 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : 720;713 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : 405;718 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : '720'; 719 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : '405'; 714 720 715 721 if ( 'color' === $placeholder_type && class_exists( 'WordPress_Gallery_Extra' ) ) { 716 $placeholder_url = self::create_placeholder( $this->OPTIONS['default_iframe_placeholder_color'], $width, $height, "iframe loading..." ); 722 $placeholder_url = self::create_placeholder( $this->OPTIONS['default_iframe_placeholder_color'], (int) $width, (int) $height, "iframe loading..." ); 723 } else if ( 'default' === $placeholder_type && !is_string( $width ) && !is_string( $height ) ) { 724 $placeholder_url = self::create_placeholder( null, (int) $width, (int) $height ); 717 725 } 718 726 … … 749 757 750 758 if ( ! strlen( $placeholder_url ) ) { 751 $placeholder_url = 'data:image/gif;base64,R0lGOD dhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';759 $placeholder_url = 'data:image/gif;base64,R0lGODlhAgABAIAAAP///wAAACH5BAEAAAAALAAAAAACAAEAAAICBAoAOw=='; 752 760 } 753 761 … … 761 769 preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $videoHTML, $width_match ); 762 770 preg_match( '/height=["|\']([^("|\')]+)["|\']/i', $videoHTML, $height_match ); 763 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : 720;764 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : 405;771 $width = !empty( $width_match ) && isset( $width_match[1] ) ? intval( $width_match[1] ) : '720'; 772 $height = !empty( $height_match ) && isset( $height_match[1] ) ? intval( $height_match[1] ) : '405'; 765 773 766 774 if ( 'color' === $placeholder_type && class_exists( 'WordPress_Gallery_Extra' ) ) { 767 $placeholder_url = self::create_placeholder( $this->OPTIONS['default_video_placeholder_color'], $width, $height, "Video loading..." ); 775 $placeholder_url = self::create_placeholder( $this->OPTIONS['default_video_placeholder_color'], (int) $width, (int) $height, "Video loading..." ); 776 } else if ( 'default' === $placeholder_type && !is_string( $width ) && !is_string( $height ) ) { 777 $placeholder_url = self::create_placeholder( null, (int) $width, (int) $height ); 768 778 } 769 779 … … 802 812 803 813 if ( ! strlen( $placeholder_url ) ) { 804 $placeholder_url = 'data:image/gif;base64,R0lGOD dhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';814 $placeholder_url = 'data:image/gif;base64,R0lGODlhGAABAIAAAP///wAAACH5BAEAAAAALAAAAAAYAAEAAAIEhI+pVwA7'; 805 815 } 806 816 … … 930 940 */ 931 941 public static function create_placeholder( $background = '#FFF', $width = 1, $height = 1, $text = "" ) { 942 if ( !$text ) { 943 $factor = min( 1 / $width, 1 / $height ); 944 $width_new = round( $width * $factor ); 945 $height_new = round( $height * $factor ); 946 947 if ( $width_new <= 0 ) { 948 $factor = 1 / $width; 949 } else if ( $height_new <= 0 ) { 950 $factor = 1 / $height; 951 } 952 953 $width = round( $width * $factor ); 954 $height = round( $height * $factor ); 955 } 956 932 957 // Create a new image instance 933 $image = imagecreate( $width, $height ); 934 935 // Parse color and fill bg 936 $color = self::hex2rgb( $background ); 937 $back = imagecolorallocate( $image, $color['r'], $color['g'], $color['b'] ); 938 939 // Make the background 940 imagefilledrectangle( $image, 0, 0, $width, $height, $back ); 941 942 if ( $text ) { 958 $image = imagecreatetruecolor( $width, $height ); 959 960 if ( $background ) { 961 // Parse color and fill bg 962 $color = self::hex2rgb( $background ); 963 $back = imagecolorallocate( $image, $color['r'], $color['g'], $color['b'] ); 964 965 // Make the background 966 imagefilledrectangle( $image, 0, 0, $width, $height, $back ); 967 } else { 968 $black = imagecolorallocate( $image, 0, 0, 0 ); 969 imagecolortransparent( $image, $black ); 970 } 971 972 /*if ( $text ) { 943 973 $font_size = 15; 944 974 $text_width = imagefontwidth( $font_size ) * strlen( $text ); … … 952 982 imagestring( $image, $font_size, ( $width / 2 ) - ( $text_width / 2 ), ( $height / 2 ) - ( $text_height / 2 ), $text, $textcolor ); 953 983 } 954 } 984 }*/ 955 985 956 986 ob_start(); … … 984 1014 985 1015 return $rgb; // returns an array with the rgb values 1016 } 1017 1018 public function get_attachment_id_from_src( $image_src ) { 1019 global $wpdb; 1020 1021 $reg = "/-[0-9]+x[0-9]+?.(jpg|jpeg|png|gif)$/i"; 1022 $src = preg_replace( $reg, '', $image_src ); 1023 if ( $src != $image_src ) { 1024 $ext = pathinfo( $image_src, PATHINFO_EXTENSION ); 1025 $image_src = $src . '.' .$ext; 1026 } 1027 1028 $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'"; 1029 $id = $wpdb->get_var( $query ); 1030 1031 return $id; 986 1032 } 987 1033 -
easy-lazy-loader/trunk/js/easy-lazy-loader.js
r1747565 r1747601 3 3 * http://www.iprodev.com/ 4 4 * 5 * @version: 1. 0.0 - October 13, 20175 * @version: 1.1.0 - October 17, 2017 6 6 * 7 7 * @author: iProDev (Hemn Chawroka) -
easy-lazy-loader/trunk/js/easy-lazy-loader.min.js
r1747565 r1747601 3 3 * https://www.iprodev.com/ 4 4 * 5 * @version: 1. 0.0 - October 13, 20175 * @version: 1.1.0 - October 17, 2017 6 6 * 7 7 * @author: iProDev (Hemn Chawroka) -
easy-lazy-loader/trunk/readme.txt
r1747565 r1747601 2 2 Contributors: iprodev 3 3 Donate link: https://iprodev.com/easy-lazy-loader 4 Tags: lazy load, images, front-end optimization4 Tags: lazy load, images, videos, audios, iframes, front-end optimization 5 5 Requires at least: 3.2 6 6 Tested up to: 4.9 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv3 9 9 License URI: https://www.gnu.org/licenses/gpl.html … … 102 102 == Changelog == 103 103 104 = 1.1.0 = 105 106 * **Optimized:** attachment identifier, now identify images from their URL. 107 * **Optimized:** placeholders to preserve their ratio as possible. 108 * **Fixed:** some bugs and stability improvements. 109 104 110 = 1.0.0 = 105 111
Note: See TracChangeset
for help on using the changeset viewer.