Plugin Directory

Changeset 1747601


Ignore:
Timestamp:
10/17/2017 02:33:30 AM (8 years ago)
Author:
iprodev
Message:

Version 1.1.0

Location:
easy-lazy-loader/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • easy-lazy-loader/trunk/easy-lazy-loader.php

    r1747565 r1747601  
    22/*
    33Plugin Name: Easy Lazy Loader
    4 Version: 1.0.0
     4Version: 1.1.0
    55Plugin URI: https://www.iprodev.com/go/easy-lazy-loader/
    66Author: iProDev
     
    1616
    1717    class EasyLazyLoader {
    18         const version = '1.0.0';
     18        const version = '1.1.0';
    1919
    2020        public $MAIN;
     
    497497
    498498        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 );
    500500            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 );
    501501
     
    614614                preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $imgHTML, $width_match );
    615615                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';
    618618               
    619619                // don't to the replacement if the image is a data-uri
     
    621621                   
    622622                    $placeholder_url_used = $placeholder_url;
    623                     if ( in_array( $placeholder_type, array( 'lowres', 'color' ) ) ) {
     623                    if ( in_array( $placeholder_type, array( 'lowres', 'color', 'default' ) ) ) {
    624624                        $img_id = false;
    625625                        if( preg_match( '/class=["\'].*?wp-image-([0-9]*)/is', $imgHTML, $id_matches ) )
    626626                            $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] );
    627629
    628630                        // use low res preview image as placeholder if applicable
     
    644646                            }
    645647
    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 );
    647653                        }
    648654                    }
     
    692698
    693699            if ( ! strlen( $placeholder_url ) ) {
    694                 $placeholder_url = 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';
     700                $placeholder_url = 'data:image/gif;base64,R0lGODlhAgABAIAAAP///wAAACH5BAEAAAAALAAAAAACAAEAAAICBAoAOw==';
    695701            }
    696702
     
    710716                preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $iframeHTML, $width_match );
    711717                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';
    714720
    715721                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 );
    717725                }
    718726
     
    749757
    750758            if ( ! strlen( $placeholder_url ) ) {
    751                 $placeholder_url = 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';
     759                $placeholder_url = 'data:image/gif;base64,R0lGODlhAgABAIAAAP///wAAACH5BAEAAAAALAAAAAACAAEAAAICBAoAOw==';
    752760            }
    753761
     
    761769                preg_match( '/width=["|\']([^("|\')]+)["|\']/i', $videoHTML, $width_match );
    762770                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';
    765773
    766774                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 );
    768778                }
    769779
     
    802812
    803813            if ( ! strlen( $placeholder_url ) ) {
    804                 $placeholder_url = 'data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAEACAkQBADs=';
     814                $placeholder_url = 'data:image/gif;base64,R0lGODlhGAABAIAAAP///wAAACH5BAEAAAAALAAAAAAYAAEAAAIEhI+pVwA7';
    805815            }
    806816
     
    930940         */
    931941        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
    932957            // 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 ) {
    943973                $font_size = 15;
    944974                $text_width = imagefontwidth( $font_size ) * strlen( $text );
     
    952982                    imagestring( $image, $font_size, ( $width / 2 ) - ( $text_width / 2 ), ( $height / 2 ) - ( $text_height / 2 ), $text, $textcolor );
    953983                }
    954             }
     984            }*/
    955985
    956986            ob_start();
     
    9841014
    9851015            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;
    9861032        }
    9871033
  • easy-lazy-loader/trunk/js/easy-lazy-loader.js

    r1747565 r1747601  
    33 * http://www.iprodev.com/
    44 *
    5  * @version: 1.0.0 - October 13, 2017
     5 * @version: 1.1.0 - October 17, 2017
    66 *
    77 * @author: iProDev (Hemn Chawroka)
  • easy-lazy-loader/trunk/js/easy-lazy-loader.min.js

    r1747565 r1747601  
    33 * https://www.iprodev.com/
    44 *
    5  * @version: 1.0.0 - October 13, 2017
     5 * @version: 1.1.0 - October 17, 2017
    66 *
    77 * @author: iProDev (Hemn Chawroka)
  • easy-lazy-loader/trunk/readme.txt

    r1747565 r1747601  
    22Contributors: iprodev
    33Donate link: https://iprodev.com/easy-lazy-loader
    4 Tags: lazy load, images, front-end optimization
     4Tags: lazy load, images, videos, audios, iframes, front-end optimization
    55Requires at least: 3.2
    66Tested up to: 4.9
    7 Stable tag: 1.0.0
     7Stable tag: 1.1.0
    88License: GPLv3
    99License URI: https://www.gnu.org/licenses/gpl.html
     
    102102== Changelog ==
    103103
     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
    104110= 1.0.0 =
    105111
Note: See TracChangeset for help on using the changeset viewer.