Plugin Directory

Changeset 3070210


Ignore:
Timestamp:
04/14/2024 12:40:41 PM (21 months ago)
Author:
FlorianBrinkmann
Message:

Update to version 8.2.0 from GitHub

Location:
lazy-loading-responsive-images
Files:
38 edited
1 copied

Legend:

Unmodified
Added
Removed
  • lazy-loading-responsive-images/tags/8.2.0/lazy-load-responsive-images.php

    r2843576 r3070210  
    1010 * Plugin URI:  https://florianbrinkmann.com/en/3350/responsive-images-and-lazy-loading-in-wordpress/
    1111 * Description: Lazy loading plugin that supports images, iFrames, video and audio elements and uses lazysizes.js. With manual modification of the markup it is also possible to lazy load background images, scripts, and styles.
    12  * Version:     8.1.1
     12 * Version:     8.2.0
    1313 * Author:      Florian Brinkmann
    1414 * Author URI:  https://florianbrinkmann.com/en/
     
    1919namespace FlorianBrinkmann\LazyLoadResponsiveImages;
    2020
    21 // Load Composer autoloader. From https://github.com/brightnucleus/jasper-client/blob/master/tests/bootstrap.php#L55-L59
    2221$autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
    2322if ( is_readable( $autoloader ) ) {
     
    2928}
    3029
    31 // Create object.
    3230$lazy_loader = new Plugin();
    3331
    34 // Set plugin basename.
     32
    3533$lazy_loader->set_basename( plugin_basename( __FILE__ ) );
    3634$lazy_loader->set_js_asset_url( plugins_url( 'js/build/functions.js', __FILE__ ) );
    3735
    38 // Init the plugin.
    3936$lazy_loader->init();
  • lazy-loading-responsive-images/tags/8.2.0/readme.txt

    r2843576 r3070210  
    44Tags: lazysizes, lazy loading, performance, images
    55Requires at least: 4.9.8
    6 Tested up to: 6.1
    7 Stable tag: 8.1.1
     6Tested up to: 6.5
     7Stable tag: 8.2.0
    88Requires PHP: 7.0
    99
     
    4545* Styles.
    4646
    47 The plugin adds a `noscript` element as fallback for disabled JavaScript.
     47The plugin adds a `noscript` element as fallback for disabled JavaScript (can be disabled with the `lazy_loader_generate_noscript` filter).
    4848
    4949You can disable lazy loading for elements with specific CSS classes by defining them via the plugin settings (*Settings* › *Media* › *Lazy Loader options*). Or use the `skip-lazy` class or the `data-skip-lazy` attribute. `skip-lazy` and `data-skip-lazy` also work on wrapper elements to exclude the wrapper and its children from being processed.
     
    105105== Changelog ==
    106106
     107= 8.2.0 – 14.04.2024 =
     108
     109Tested with WordPress 6.5.
     110
     111**Added**
     112
     113* `lazy_loader_generate_noscript` filter to allow disabling of `noscript` element generation.
     114
     115**Fixed**
     116
     117- Updated `mastermind/html5` dependency to latest version, which fixes a PHP deprecation notice.
     118
    107119= 8.1.1 – 20.12.2022 =
    108120
  • lazy-loading-responsive-images/tags/8.2.0/src/Helpers.php

    r2843576 r3070210  
    11<?php
    22/**
    3  * Helper methods.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    108use FlorianBrinkmann\LazyLoadResponsiveImages\Settings as Settings;
    119
    12 /**
    13  * Class Helpers
    14  *
    15  * Class with helper methods.
    16  *
    17  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    18  */
    1910class Helpers {
    2011
    2112    /**
    22      * Hint if the plugin is disabled for this post.
    23      *
    2413     * @var null|int
    2514     */
     
    2716
    2817    /**
    29      * Checks if this is a request at the backend.
    30      *
    3118     * @return bool true if is admin request, otherwise false.
    3219     */
     
    4633
    4734        /*
    48          * Get admin URL and referrer.
    49          *
    5035         * @link https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/pluggable.php#L1076
    5136         */
     
    5338        $referrer  = strtolower( wp_get_referer() );
    5439
    55         // Check if this is a admin request. If true, it
    56         // could also be a AJAX request.
    5740        if ( 0 === strpos( $current_url, $admin_url ) ) {
    58             // Check if the user comes from a admin page.
    5941            if ( 0 === strpos( $referrer, $admin_url ) ) {
    6042                return true;
    6143            } else {
    62                 /*
    63                  * Check for AJAX requests.
    64                  *
    65                  * @link https://gist.github.com/zitrusblau/58124d4b2c56d06b070573a99f33b9ed#file-lazy-load-responsive-images-php-L193
    66                  */
    6744                if ( function_exists( 'wp_doing_ajax' ) ) {
    6845                    return ! wp_doing_ajax();
     
    8057
    8158    /**
    82      * Checks if we are on an AMP page generated from the Automattic plugin.
    83      *
    8459     * @return bool true if is amp page, false otherwise.
    8560     */
    8661    public function is_amp_page() {
    87         // Check if Automattic’s AMP plugin is active and we are on an AMP endpoint.
    8862        if ( function_exists( 'is_amp_endpoint' ) && true === is_amp_endpoint() ) {
    8963            return true;
     
    9468
    9569    /**
    96      * Check if plugin is disabled for current post.
    97      *
    9870     * @return bool true if disabled, false otherwise.
    9971     */
    10072    public function is_disabled_for_post() {
    101         // Check if the plugin is disabled.
    10273        if ( null === $this->disabled_for_current_post ) {
    10374            $this->disabled_for_current_post = absint( get_post_meta( get_the_ID(), 'lazy_load_responsive_images_disabled', true ) );
     
    11788
    11889    /**
    119      * Check if the displayed content is something that the plugin should process.
    120      *
    12190     * @return bool
    12291     */
     
    12695        }
    12796
    128         // Check if we are on a feed page.
    12997        if ( is_feed() ) {
    13098            return false;
    13199        }
    132100
    133         // Check if this content is embedded.
    134101        if ( is_embed() ) {
    135102            return false;
    136103        }
    137104
    138         // Check if this is a request in the backend.
    139105        if ( $this->is_admin_request() ) {
    140106            return false;
    141107        }
    142108
    143         // Check for AMP page.
    144109        if ( $this->is_amp_page() ) {
    145110            return false;
    146111        }
    147112
    148         // Check for Oxygen Builder mode.
    149113        if ( defined( 'SHOW_CT_BUILDER' ) ) {
    150114            return false;
    151115        }
    152116
    153         // Check for TranslatePress editor.
    154117        if ( isset( $_REQUEST['trp-edit-translation'] ) ) {
    155118            return false;
     
    160123
    161124    /**
    162      * Sanitize comma separated list of class names.
    163      *
    164125     * @param string $class_names Comma separated list of HTML class names.
    165126     *
     
    167128     */
    168129    public function sanitize_class_name_list( $class_names ) {
    169         // Get array of the class names.
    170130        $class_names_array = explode( ',', $class_names );
    171131
     
    174134        }
    175135
    176         // Loop through the class names.
    177136        foreach ( $class_names_array as $i => $class_name ) {
    178             // Save the sanitized class name.
    179137            $class_names_array[ $i ] = sanitize_html_class( $class_name );
    180138        }
    181139
    182         // Implode the class names.
    183140        $class_names = implode( ',', $class_names_array );
    184141
     
    187144
    188145    /**
    189      * Sanitize list of filter names.
    190      *
    191146     * @param string $filters One or more WordPress filters, one per line.
    192147     *
     
    194149     */
    195150    public function sanitize_filter_name_list( $filters ) {
    196         // Get array of the filter names.
    197151        $filters_array = explode( "\n", $filters );
    198152
     
    201155        }
    202156
    203         // Loop through the filter names.
    204157        foreach ( $filters_array as $i => $filter ) {
    205158            $function_name_regex = '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/';
     
    207160            $filters_array[$i] = trim( $filters_array[$i] );
    208161           
    209             // Check if the filter is a valid PHP function name.
    210162            if ( preg_match( $function_name_regex, $filters_array[$i] ) !== 1 ) {
    211163                unset( $filters_array[$i] );
     
    214166        }
    215167
    216         // Implode the filter names.
    217168        $filters = implode( "\n", $filters_array );
    218169
     
    221172
    222173    /**
    223      * Sanitize checkbox.
    224      *
    225174     * @link https://github.com/WPTRT/code-examples/blob/master/customizer/sanitization-callbacks.php
    226175     *
     
    234183
    235184    /**
    236      * Sanitize textarea input.
    237      *
    238185     * @param bool $checked Whether the checkbox is checked.
    239186     *
     
    245192
    246193    /**
    247      * Sanitize hex color value.
    248      *
    249194     * @param string $value The input from the color input.
    250195     *
     
    252197     */
    253198    public function sanitize_hex_color( $value ) {
    254         // Sanitize the input.
    255199        $sanitized = sanitize_hex_color( $value );
    256200        if ( null !== $sanitized && '' !== $sanitized ) {
     
    259203            $settings = new Settings();
    260204            return $settings->get_loading_spinner_color_default();
    261         } // End if().
     205        }
    262206    }
    263207
  • lazy-loading-responsive-images/tags/8.2.0/src/Plugin.php

    r2505151 r3070210  
    11<?php
    22/**
    3  * Main plugin code.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    1412use Masterminds\HTML5;
    1513
    16 /**
    17  * Class Plugin
    18  *
    19  * Class for adding lazy loading to responsive images.
    20  *
    21  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    22  */
    2314class Plugin {
    2415
    2516    /**
    26      * Helpers object.
    27      *
    2817     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Helpers
    2918     */
     
    3120
    3221    /**
    33      * Settings object.
    34      *
    3522     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Settings
    3623     */
     
    3825
    3926    /**
    40      * Array of classes which should not be lazy loaded.
    41      *
    4227     * @var array
    4328     */
     
    4530
    4631    /**
    47      * Basename of the plugin.
    48      *
    4932     * @var string
    5033     */
     
    5235
    5336    /**
    54      * URL to editor JS file.
    55      *
    5637     * @var string
    5738     */
     
    5940
    6041    /**
    61      * Placeholder data uri for img src attributes.
    62      *
    6342     * @link https://stackoverflow.com/a/13139830
    6443     *
     
    6847
    6948    /**
    70      * Counter for background image classes.
     49     * @var int
    7150     */
    7251    private $background_image_number = 1;
    7352
    7453    /**
    75      * Plugin constructor.
    76      */
    77     public function __construct() {
    78 
    79     }
    80 
    81     /**
    82      * Runs the filters and actions.
    83      */
     54     * @var bool
     55     */
     56    private $generate_noscript;
     57
    8458    public function init() {
    85         // Init settings.
    8659        $this->settings = new Settings();
    8760
    88         // Set helpers.
    8961        $this->helpers = new Helpers();
    9062
    91         // Get the disabled classes and save in property.
    9263        $this->disabled_classes = $this->settings->get_disabled_classes();
    9364
    94         // Disable core lazy loading.
     65        add_action( 'init', function() {
     66            /**
     67             * Filter to disable the generation of a noscript element.
     68             *
     69             * @param bool $generate_noscript Whether to generate a noscript element or not.
     70             */
     71            $this->generate_noscript = (bool) apply_filters( 'lazy_loader_generate_noscript', true );
     72        }, 5 );
     73
    9574        add_filter( 'wp_lazy_loading_enabled', '__return_false' );
    9675
    97         // Add link to settings in the plugin list.
    9876        add_filter( 'plugin_action_links', array(
    9977            $this,
     
    10381        add_action( 'init', array( $this, 'init_content_processing' ) );
    10482       
    105         // Enqueues scripts and styles.
    10683        add_action( 'wp_enqueue_scripts', array(
    10784            $this,
     
    10986        ), 20 );
    11087
    111         // Adds inline style.
    11288        add_action( 'wp_head', array( $this, 'add_inline_style' ) );
    11389
    114         // Enqueue Gutenberg script.
    11590        add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
    11691
    117         // Load the language files.
    11892        add_action( 'plugins_loaded', array( $this, 'load_translation' ) );
    11993
    120         // Action on uninstall.
    12194        register_uninstall_hook( $this->basename, 'FlorianBrinkmann\LazyLoadResponsiveImages\Plugin::uninstall' );
    12295    }
    123 
    124     /**
    125      * Run actions and filters to start content processing.
    126      */
     96   
    12797    public function init_content_processing() {
    128         // Check if the complete markup should be processed.
    12998        if ( '1' === $this->settings->get_process_complete_markup() ) {
    13099            add_action( 'template_redirect', array( $this, 'process_complete_markup' ) );
    131100        } else {
    132             // Filter markup of the_content() calls to modify media markup for lazy loading.
    133101            add_filter( 'the_content', array( $this, 'filter_markup' ), 10001 );
    134102
    135             // Filter allowed html for posts to allow <noscript> tag.
    136103            add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
    137104
    138             // Filter markup of Text widget to modify media markup for lazy loading.
    139105            add_filter( 'widget_text', array( $this, 'filter_markup' ) );
    140106
    141             // Filter markup of gravatars to modify markup for lazy loading.
    142107            add_filter( 'get_avatar', array( $this, 'filter_markup' ) );
    143108
    144             // Adds lazyload markup and noscript element to post thumbnail.
    145109            add_filter( 'post_thumbnail_html', array(
    146110                $this,
     
    157121        }
    158122    }
    159 
    160     /**
    161      * Run output buffering, to process the complete markup.
    162      */
     123   
    163124    public function process_complete_markup() {
    164         // If this is no content we should process, exit as early as possible.
    165125        if ( ! $this->helpers->is_post_to_process() ) {
    166126            return;
     
    171131
    172132    /**
    173      * Add settings link to the plugin entry in the plugin list.
    174      *
    175133     * @param array  $links Array of action links.
    176134     * @param string $file  Basename of the plugin.
     
    191149
    192150    /**
    193      * Modifies elements to automatically enable lazy loading.
    194      *
    195151     * @param string $content HTML.
    196152     *
     
    198154     */
    199155    public function filter_markup( $content = '' ) {
    200         // If this is no content we should process, exit as early as possible.
    201156        if ( ! $this->helpers->is_post_to_process() ) {
    202157            return $content;
    203158        }
    204159
    205         // Check if we have no content.
    206160        if ( empty( $content ) ) {
    207161            return $content;
    208162        }
    209163
    210         // Check if content contains caption shortcode.
    211164        if ( has_shortcode( $content, 'caption' ) ) {
    212165            return $content;
    213166        }
    214167
    215         // Disable libxml errors.
    216168        libxml_use_internal_errors( true );
    217169
    218         // Create new HTML5 object.
    219170        $html5 = new HTML5( array(
    220171            'disable_html_ns' => true,
     
    228179        $content = str_replace( '<![endif]-->', '<!--<![endif]-->', $content );
    229180
    230         // Load the HTML.
    231181        $dom = $html5->loadHTML( $content );
    232182
    233183        $xpath = new \DOMXPath( $dom );
    234184
    235         // Get all nodes except the ones that live inside a noscript element.
    236         // @link https://stackoverflow.com/a/19348287/7774451.
    237185        $nodes = $xpath->query( "//*[not(ancestor-or-self::noscript)][not(ancestor-or-self::*[contains(@class, 'disable-lazyload') or contains(@class, 'skip-lazy') or @data-skip-lazy])]" );
    238186
     
    240188
    241189        foreach ( $nodes as $node ) {
    242             // Check if it is an element that should not be lazy loaded.
    243             // Get the classes as an array.
    244190            $node_classes = explode( ' ', $node->getAttribute( 'class' ) );
    245191
    246             // Check for intersection with array of classes, which should
    247             // not be lazy loaded.
    248192            $result = array_intersect( $this->disabled_classes, $node_classes );
    249193
    250             // Filter empty values.
    251194            $result = array_filter( $result );
    252 
    253             /*
    254              * Check if:
    255              * - we have no result from the array intersection.
    256              * - the node does not have the data-no-lazyload attr.
    257              * - the node does not already have the lazyload class.
    258              */
     195           
    259196            if ( ! empty( $result ) || $node->hasAttribute( 'data-no-lazyload' ) || in_array( 'lazyload', $node_classes, true ) ) {
    260197                continue;
    261198            }
    262199
    263             // Check if the element has a style attribute with a background image.
    264200            if (
    265201                '1' === $this->settings->get_enable_for_background_images()
     
    277213            }
    278214
    279             // Check if it is one of the supported elements and support for it is enabled.
    280215            if ( 'img' === $node->tagName && 'source' !== $node->parentNode->tagName && 'picture' !== $node->parentNode->tagName ) {
    281216                $dom = $this->modify_img_markup( $node, $dom );
     
    349284
    350285    /**
    351      * Modifies element markup for lazy loading inline background image.
    352      *
    353286     * @param \DOMNode     $node    The node with the inline background image.
    354287     * @param \DOMDocument $dom     \DOMDocument() object of the HTML.
     
    359292        $original_css = $node->getAttribute( 'style' );
    360293        $classes = $node->getAttribute( 'class' );
    361         // It is possible that there are multiple background rules for a inline element (including ones for size, position, et cetera).
    362         // We will insert all of them to the inline style element, to not mess up their order.
     294
    363295        if ( 0 !== preg_match_all( '/background(-[a-z]+)?:([^;])*;?/', $node->getAttribute( 'style' ), $matches ) ) {
    364             // $matches[0] contains the full CSS background rules.
    365             // We remove the rules from the inline style.
    366296            $modified_css = str_replace( $matches[0], '', $original_css );
    367297            $node->setAttribute( 'style', $modified_css );
    368298
    369             // Build string of background rules.
    370299            $background_rules_string = implode( ' ', $matches[0] );
    371300
    372             // Add unique class and lazyload class to element.
    373301            $unique_class = "lazy-loader-background-element-$this->background_image_number";
    374302            $classes .= " lazyload $unique_class ";
     
    376304            $this->background_image_number++;
    377305
    378             // Create style element with the background rule.
    379306            $background_style_elem = $dom->createElement( 'style', ".$unique_class.lazyloaded{ $background_rules_string }" );
    380307            $node->parentNode->insertBefore( $background_style_elem, $node );
    381308
    382             // Add the noscript element.
     309            if ( ! $this->generate_noscript ) {
     310                return $dom;
     311            }
     312
    383313            $noscript = $dom->createElement( 'noscript' );
    384 
    385             // Insert it before the img node.
    386314            $noscript_node = $node->parentNode->insertBefore( $noscript, $node );
    387 
    388             // Create element.
    389315            $background_style_elem_noscript = $dom->createElement( 'style', ".$unique_class.lazyload{ $background_rules_string }" );
    390 
    391             // Add media node to noscript node.
    392316            $noscript_node->appendChild( $background_style_elem_noscript );
    393317        }
     318
    394319        return $dom;
    395320    }
    396321
    397322    /**
    398      * Modifies img markup to enable lazy loading.
    399      *
    400323     * @param \DOMNode     $img             The img dom node.
    401324     * @param \DOMDocument $dom             \DOMDocument() object of the HTML.
     
    405328     */
    406329    public function modify_img_markup( $img, $dom, $create_noscript = true ) {
    407         // Check if the element already has a data-src attribute (might be the case for
    408         // plugins that bring their own lazy load functionality) and skip it to prevent conflicts.
    409330        if ( $img->hasAttribute( 'data-src' ) ) {
    410331            return $dom;
    411332        }
    412333
    413         // Add noscript element.
    414334        if ( true === $create_noscript ) {
    415335            $dom = $this->add_noscript_element( $dom, $img );
    416336        }
    417337
    418         // Check if the image has sizes and srcset attribute.
    419338        $sizes_attr = '';
    420339        if ( $img->hasAttribute( 'sizes' ) ) {
    421             // Get sizes value.
    422340            $sizes_attr = $img->getAttribute( 'sizes' );
    423341
    424             // Check if the value is auto. If so, we modify it to data-sizes.
    425342            if ( 'auto' === $sizes_attr ) {
    426                 // Set data-sizes attribute.
    427343                $img->setAttribute( 'data-sizes', $sizes_attr );
    428344
    429                 // Remove sizes attribute.
    430345                $img->removeAttribute( 'sizes' );
    431346            }
     
    433348
    434349        if ( $img->hasAttribute( 'srcset' ) ) {
    435             // Get srcset value.
    436350            $srcset = $img->getAttribute( 'srcset' );
    437351
    438             // Set data-srcset attribute.
    439352            $img->setAttribute( 'data-srcset', $srcset );
    440353
    441             // Set srcset attribute with src placeholder to produce valid markup.
    442354            $img_width  = $img->getAttribute( 'width' );
    443355            if ( '' !== $img_width ) {
     
    451363                }
    452364            } else {
    453                 // Remove srcset attribute.
    454365                $img->removeAttribute( 'srcset' );
    455366            }
    456367        }
    457368
    458         // Get src value.
    459369        $src = $img->getAttribute( 'src' );
    460370
    461         // Set data-src value.
    462371        $img->setAttribute( 'data-src', $src );
    463372
     
    466375        }
    467376
    468         // Get the classes.
    469377        $classes = $img->getAttribute( 'class' );
    470378
    471         // Add lazyload class.
    472379        $classes .= ' lazyload';
    473380
    474         // Set the class string.
    475381        $img->setAttribute( 'class', $classes );
    476382
    477         // Get width and height.
    478383        $img_width  = $img->getAttribute( 'width' );
    479384        $img_height = $img->getAttribute( 'height' );
    480385
    481         // Set data URI for src attribute.
    482386        if ( '' !== $img_width && '' !== $img_height ) {
    483             // We have image width and height, we can set a inline SVG to prevent content jumps.
    484387            $svg_placeholder = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20{$img_width}%20{$img_height}%22%3E%3C%2Fsvg%3E";
    485388            $img->setAttribute( 'src', $svg_placeholder );
     
    496399
    497400    /**
    498      * Modifies input[type="image"] markup to enable lazy loading.
    499      *
    500401     * @param \DOMNode     $node            The input dom node.
    501402     * @param \DOMDocument $dom             \DOMDocument() object of the HTML.
     
    505406     */
    506407    public function modify_input_markup( $node, $dom, $create_noscript = true ) {
    507         // Check if the element already has a data-src attribute (might be the case for
    508         // plugins that bring their own lazy load functionality) and skip it to prevent conflicts.
    509408        if ( $node->hasAttribute( 'data-src' ) ) {
    510409            return $dom;
    511410        }
    512411
    513         // Add noscript element.
    514412        if ( true === $create_noscript ) {
    515413            $dom = $this->add_noscript_element( $dom, $node );
    516414        }
    517415
    518         // Get src value.
    519416        $src = $node->getAttribute( 'src' );
    520417
    521         // Set data-src value.
    522418        $node->setAttribute( 'data-src', $src );
    523419
    524         // Get the classes.
    525420        $classes = $node->getAttribute( 'class' );
    526421
    527         // Add lazyload class.
    528422        $classes .= ' lazyload';
    529423
    530         // Set the class string.
    531424        $node->setAttribute( 'class', $classes );
    532425
    533         // Get width and height.
    534426        $node_width  = $node->getAttribute( 'width' );
    535427        $node_height = $node->getAttribute( 'height' );
    536428
    537         // Set data URI for src attribute.
    538429        if ( '' !== $node_width && '' !== $node_height ) {
    539             // We have image width and height, we can set a inline SVG to prevent content jumps.
    540430            $svg_placeholder = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20{$node_width}%20{$node_height}%22%3E%3C%2Fsvg%3E";
    541431            $node->setAttribute( 'src', $svg_placeholder );
     
    552442
    553443    /**
    554      * Modifies picture element markup to enable lazy loading.
    555      *
    556444     * @param \DOMNode     $picture The source dom node.
    557445     * @param \DOMDocument $dom     \DOMDocument() object of the HTML.
     
    560448     */
    561449    public function modify_picture_markup( $picture, $dom ) {
    562         // Check if img element already has `layzload` class.
    563450        $img_element = $picture->getElementsByTagName( 'img' );
    564451
     
    569456        }
    570457       
    571         // Add noscript element.
    572458        $dom = $this->add_noscript_element( $dom, $picture );
    573459
    574         // Get source elements from picture.
    575460        $source_elements = $picture->getElementsByTagName( 'source' );
    576461
    577         // Loop the source elements if there are some.
    578462        if ( 0 !== $source_elements->length ) {
    579463            foreach ( $source_elements as $source_element ) {
    580                 // Check if we have a sizes attribute.
    581464                $sizes_attr = '';
    582465                if ( $source_element->hasAttribute( 'sizes' ) ) {
    583                     // Get sizes value.
    584466                    $sizes_attr = $source_element->getAttribute( 'sizes' );
    585467
    586                     // Check if the value is auto. If so, we modify it to data-sizes.
    587468                    if ( 'auto' === $sizes_attr ) {
    588                         // Set data-sizes attribute.
    589469                        $source_element->setAttribute( 'data-sizes', $sizes_attr );
    590470
    591                         // Remove sizes attribute.
    592471                        $source_element->removeAttribute( 'sizes' );
    593472                    }
    594473                }
    595474
    596                 // Check for srcset.
    597475                if ( $source_element->hasAttribute( 'srcset' ) ) {
    598                     // Get srcset value.
    599476                    $srcset = $source_element->getAttribute( 'srcset' );
    600477
    601                     // Set data-srcset attribute.
    602478                    $source_element->setAttribute( 'data-srcset', $srcset );
    603479
    604                     // Set srcset attribute with src placeholder to produce valid markup.
    605480                    if ( '' !== $sizes_attr ) {
    606481                        $width = preg_replace( '/.+ (\d+)px$/', '$1', $sizes_attr );
     
    611486                        }
    612487                    } else {
    613                         // Remove srcset attribute.
    614488                        $source_element->removeAttribute( 'srcset' );
    615489                    }
     
    617491
    618492                if ( $source_element->hasAttribute( 'src' ) ) {
    619                     // Get src value.
    620493                    $src = $source_element->getAttribute( 'src' );
    621494
    622                     // Set data-src value.
    623495                    $source_element->setAttribute( 'data-src', $src );
    624496
    625                     // Set data URI for src attribute.
    626497                    $source_element->setAttribute( 'src', $this->src_placeholder );
    627498                }
     
    629500        }
    630501
    631         // Loop the img element.
    632502        foreach ( $img_element as $img ) {
    633503            $this->modify_img_markup( $img, $dom, false );
     
    638508
    639509    /**
    640      * Modifies iframe markup to enable lazy loading.
    641      *
    642510     * @param \DOMNode     $iframe The iframe dom node.
    643511     * @param \DOMDocument $dom    \DOMDocument() object of the HTML.
     
    646514     */
    647515    public function modify_iframe_markup( $iframe, $dom ) {
    648         // Add noscript element.
    649516        $dom = $this->add_noscript_element( $dom, $iframe );
    650517
    651         // Check if the iframe has a src attribute.
    652518        if ( $iframe->hasAttribute( 'src' ) ) {
    653             // Get src attribute.
    654519            $src = $iframe->getAttribute( 'src' );
    655520
    656             // Set data-src value.
    657521            $iframe->setAttribute( 'data-src', $src );
    658522        } else {
     
    664528        }
    665529
    666         // Get the classes.
    667530        $classes = $iframe->getAttribute( 'class' );
    668531
    669         // Add lazyload class.
    670532        $classes .= ' lazyload';
    671533
    672         // Set the class string.
    673534        $iframe->setAttribute( 'class', $classes );
    674535
    675         // Remove the src attribute.
    676536        $iframe->removeAttribute( 'src' );
    677537
     
    680540
    681541    /**
    682      * Modifies video markup to enable lazy loading.
    683      *
    684542     * @param \DOMNode     $video The video dom node.
    685543     * @param \DOMDocument $dom   \DOMDocument() object of the HTML.
     
    688546     */
    689547    public function modify_video_markup( $video, $dom ) {
    690         // Add noscript element.
    691548        $dom = $this->add_noscript_element( $dom, $video );
    692549
    693         // Check if the video has a poster attribute.
    694550        if ( $video->hasAttribute( 'poster' ) ) {
    695             // Get poster attribute.
    696551            $poster = $video->getAttribute( 'poster' );
    697552
    698             // Remove the poster attribute.
    699553            $video->removeAttribute( 'poster' );
    700554
    701             // Set data-poster value.
    702555            $video->setAttribute( 'data-poster', $poster );
    703556        }
    704557
    705         // Set preload to none.
    706558        $video->setAttribute( 'preload', 'none' );
    707559
    708         // Check for autoplay attribute and change it for lazy loading.
    709560        if ( $video->hasAttribute( 'autoplay' ) ) {
    710561            $video->removeAttribute( 'autoplay' );
     
    712563        }
    713564
    714         // Get the classes.
    715565        $classes = $video->getAttribute( 'class' );
    716566
    717         // Add lazyload class.
    718567        $classes .= ' lazyload';
    719568
    720         // Set the class string.
    721569        $video->setAttribute( 'class', $classes );
    722570
     
    725573
    726574    /**
    727      * Modifies audio markup to enable lazy loading.
    728      *
    729575     * @param \DOMNode     $audio The audio dom node.
    730576     * @param \DOMDocument $dom   \DOMDocument() object of the HTML.
     
    733579     */
    734580    public function modify_audio_markup( $audio, $dom ) {
    735         // Add noscript element.
    736581        $dom = $this->add_noscript_element( $dom, $audio );
    737582
    738         // Set preload to none.
    739583        $audio->setAttribute( 'preload', 'none' );
    740584
    741         // Get the classes.
    742585        $classes = $audio->getAttribute( 'class' );
    743586
    744         // Add lazyload class.
    745587        $classes .= ' lazyload';
    746588
    747         // Set the class string.
    748589        $audio->setAttribute( 'class', $classes );
    749590
     
    752593
    753594    /**
    754      * Adds noscript element before DOM node.
    755      *
    756595     * @param \DOMDocument     $dom            \DOMDocument() object of the
    757596     *                                         HTML.
     
    761600     */
    762601    public function add_noscript_element( $dom, $elem ) {
    763         // Create noscript element and add it before the element that gets lazy loading.
     602        if ( ! $this->generate_noscript ) {
     603            return $dom;
     604        }
     605
    764606        $noscript = $dom->createElement( 'noscript' );
    765607        $noscript_node = $elem->parentNode->insertBefore( $noscript, $elem );
    766608
    767         // Create copy of media element.
    768609        $noscript_media_fallback_elem = $elem->cloneNode( true );
    769610
     
    779620        }
    780621
    781         // Add a copy of the media element to the noscript.
    782622        $noscript_node->appendChild( $noscript_media_fallback_elem );
    783623
     
    786626
    787627    /**
    788      * Filter allowed html for posts.
    789      *
    790628     * @param array  $allowedposttags Allowed post tags.
    791629     * @param string $context         Context.
     
    802640        return $allowedposttags;
    803641    }
    804 
    805     /**
    806      * Enqueues scripts and styles.
    807      */
     642   
    808643    public function enqueue_script() {
    809644        if ( $this->helpers->is_disabled_for_post() ) {
     
    818653        }
    819654
    820         // Enqueue lazysizes.
    821655        wp_enqueue_script( 'lazysizes', plugins_url( '/lazy-loading-responsive-images/js/lazysizes.min.js' ), array(), filemtime( plugin_dir_path( __FILE__ ) . '../js/lazysizes.min.js' ), true );
    822656
    823         // Check if unveilhooks plugin should be loaded.
    824657        if ( '1' === $this->settings->get_load_unveilhooks_plugin() || '1' === $this->settings->get_enable_for_audios() || '1' === $this->settings->get_enable_for_videos() || '1' === $this->settings->get_enable_for_background_images() ) {
    825             // Enqueue unveilhooks plugin.
    826658            wp_enqueue_script( 'lazysizes-unveilhooks', plugins_url( '/lazy-loading-responsive-images/js/ls.unveilhooks.min.js' ), array( 'lazysizes' ), filemtime( plugin_dir_path( __FILE__ ) . '../js/ls.unveilhooks.min.js' ), true );
    827659        }
    828660
    829         // Check if native loading plugin should be loaded.
    830661        if ( '1' === $this->settings->get_load_native_loading_plugin() ) {
    831662            wp_enqueue_script( 'lazysizes-native-loading', plugins_url( '/lazy-loading-responsive-images/js/ls.native-loading.min.js' ), array( 'lazysizes' ), filemtime( plugin_dir_path( __FILE__ ) . '../js/ls.native-loading.min.js' ), true );
    832663        }
    833664
    834         // Include custom lazysizes config if not empty.
    835665        if ( '' !== $this->settings->get_lazysizes_config() ) {
    836666            wp_add_inline_script( 'lazysizes', $this->settings->get_lazysizes_config(), 'before' );
    837667        }
    838668    }
    839 
    840     /**
    841      * Adds inline style.
    842      *
    843      * We do not enqueue a new CSS file for two rules, but cannot use
    844      * wp_add_inline_style() because we have no handle. So we need to
    845      * echo it.
    846      */
     669   
    847670    public function add_inline_style() {
    848671        if ( $this->helpers->is_disabled_for_post() ) {
     
    850673        }
    851674
    852         // Create loading spinner style if needed.
    853675        $spinner_styles = '';
    854676        $spinner_color  = $this->settings->get_loading_spinner_color();
     
    889711        }
    890712
    891         // Display the default styles.
    892713        $default_styles = "<style>:root {
    893714            --lazy-loader-animation-duration: 300ms;
     
    917738        echo apply_filters( 'lazy_load_responsive_images_inline_styles', $default_styles );
    918739
    919         // Hide images if no JS.
    920740        echo '<noscript><style>.lazyload { display: none; } .lazyload[class*="lazy-loader-background-element-"] { display: block; opacity: 1; }</style></noscript>';
    921741    }
    922 
    923     /**
    924      * Enqueue script to Gutenberg editor view.
    925      */
     742   
    926743    public function enqueue_block_editor_assets() {
    927744        if ( isset( $_REQUEST['post'] ) && in_array( get_post_type( $_REQUEST['post'] ), $this->settings->get_disable_option_object_types() ) && post_type_supports( get_post_type( $_REQUEST['post'] ), 'custom-fields' ) ) {
     
    935752        }
    936753    }
    937 
    938     /**
    939      * Loads the plugin translation.
    940      */
     754   
    941755    public function load_translation() {
    942756        load_plugin_textdomain( 'lazy-loading-responsive-images' );
     
    944758
    945759    /**
    946      * Sets plugin basename.
    947      *
    948760     * @param string $basename The plugin basename.
    949761     */
     
    953765
    954766    /**
    955      * Sets plugin basename.
    956      *
    957767     * @param string $basename The plugin basename.
    958768     */
     
    960770        $this->js_asset_url = $js_asset_url;
    961771    }
    962 
    963     /**
    964      * Action on plugin uninstall.
    965      */
     772   
    966773    public static function uninstall() {
    967774        $options_array = array(
     
    982789        );
    983790
    984         // Delete options.
    985791        foreach ( $options_array as $option ) {
    986792            delete_option( $option );
  • lazy-loading-responsive-images/tags/8.2.0/src/Settings.php

    r2505151 r3070210  
    11<?php
    22/**
    3  * Class for adding customizer settings.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    86namespace FlorianBrinkmann\LazyLoadResponsiveImages;
    97
    10 /**
    11  * Class Settings
    12  *
    13  * Adds options to the customizer.
    14  *
    15  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    16  */
    178class Settings {
    189
    1910    /**
    20      * Helpers object.
    21      *
    2211     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Helpers
    2312     */
     
    2514
    2615    /**
    27      * Array of options data.
    28      *
    2916     * @var array
    3017     */
     
    3219
    3320    /**
    34      * Classes which should not be lazy loaded.
    35      *
    3621     * @var array
    3722     */
     
    3924
    4025    /**
    41      * Value of settings for enabling lazy loading for iFrames.
    42      *
    4326     * @var string
    4427     */
     
    4629
    4730    /**
    48      * Value of setting for loading the unveilhooks plugin.
    49      *
    5031     * @var string
    5132     */
     
    5334
    5435    /**
    55      * Value of setting for loading the unveilhooks plugin.
    56      *
    5736     * @var string
    5837     */
     
    6039
    6140    /**
    62      * Value of settings for enabling lazy loading for background images.
    63      *
    6441     * @var string
    6542     */
     
    6744
    6845    /**
    69      * Value of settings for enabling lazy loading for videos.
    70      *
    7146     * @var string
    7247     */
     
    7449
    7550    /**
    76      * Value of settings for enabling lazy loading for audios.
    77      *
    7851     * @var string
    7952     */
     
    8154
    8255    /**
    83      * Value of setting for displaying a loading spinner.
    84      *
    8556     * @var string
    8657     */
     
    8859
    8960    /**
    90      * Default loading spinner color.
    91      *
    9261     * @var string
    9362     */
     
    9564
    9665    /**
    97      * Value of setting for loading spinner color.
    98      *
    9966     * @var string
    10067     */
     
    10269
    10370    /**
    104      * Value of setting for displaying the option to disable the plugin per page/post.
    105      *
    10671     * @var string
    10772     */
     
    10974
    11075    /**
    111      * Array of object types that should show the checkbox to disable lazy loading.
    112      *
    11376     * @var array
    11477     */
     
    11679
    11780    /**
    118      * String to modify lazysizes config.
    119      *
    12081     * @var string
    12182     */
     
    12384
    12485    /**
    125      * Value of setting for processing the complete website markup.
    126      *
    12786     * @var string
    12887     */
     
    13089
    13190    /**
    132      * Value of setting for additional filters to process.
    133      *
    13491     * @var array
    13592     */
     
    13794
    13895    /**
    139      * Allowed HTML tags in descriptions.
    140      *
    14196     * @var array
    14297     */
     
    148103    );
    149104
    150     /**
    151      * Settings constructor.
    152      */
    153105    public function __construct() {
    154         // Set helpers.
    155106        $this->helpers = new Helpers();
    156107
     
    295246        );
    296247
    297         // Fill properties with setting values.
    298248        $this->disabled_classes        = explode( ',', $this->options['lazy_load_responsive_images_disabled_classes']['value'] );
    299249        $this->enable_for_iframes      = $this->options['lazy_load_responsive_images_enable_for_iframes']['value'];
     
    310260        $this->enable_for_background_images = $this->options['lazy_load_responsive_images_enable_for_background_images']['value'];
    311261
    312         // Register settings on media options page.
    313262        add_action( 'admin_init', array( $this, 'settings_init' ), 12 );
    314263
    315         // Include color picker JS.
    316264        add_action( 'admin_enqueue_scripts', array(
    317265            $this,
     
    322270            add_action( 'init', array( $this, 'disable_option_object_types_filter' ), 11 );
    323271
    324             // Register meta for disabling per page.
    325272            add_action( 'init', array( $this, 'register_post_meta' ), 11 );
    326273
    327             // Publish post actions.
    328274            add_action( 'post_submitbox_misc_actions', array( $this, 'add_checkbox' ), 9 );
    329275            add_action( 'save_post', array( $this, 'save_checkbox' ) );
     
    331277    }
    332278
    333     /**
    334      * Init settings on media options page.
    335      */
    336279    public function settings_init() {
    337         // Add section.
    338280        add_settings_section(
    339281            "lazy-load-responsive-images-section",
     
    346288        );
    347289
    348         // Loop the options.
    349290        foreach ( $this->options as $option_id => $option ) {
    350             // Register setting.
    351291            register_setting( 'media', $option_id, array(
    352292                'sanitize_callback' => $option['sanitize_callback'],
    353293            ) );
    354294
    355             // Create field.
    356295            add_settings_field(
    357296                $option_id,
     
    366305                )
    367306            );
    368         } // End foreach().
    369     }
    370 
    371     /**
    372      * Section callback.
    373      *
     307        }
     308    }
     309
     310    /**
    374311     * @param array $args
    375312     */
     
    378315
    379316    /**
    380      * Checkbox callback.
    381      *
    382317     * @param array $args               {
    383318     *                                  Argument array.
     
    389324     */
    390325    public function checkbox_field_cb( $args ) {
    391         // Get option value.
    392326        $option_value = $args['value'];
    393327
    394         // Get label for.
    395328        ?>
    396329        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
    397330               type="checkbox" <?php echo ( $option_value == '1' || $option_value == 'on' ) ? 'checked="checked"' : ''; ?>>
    398331        <?php
    399         // Check for description.
    400332        if ( '' !== $args['description'] ) { ?>
    401333            <p class="description">
     
    407339
    408340    /**
    409      * Text field callback.
    410      *
    411341     * @param array $args               {
    412342     *                                  Argument array.
     
    418348     */
    419349    public function text_field_cb( $args ) {
    420         // Get option value.
    421350        $option_value = $args['value'];
    422351
    423         // Get label for.
    424352        ?>
    425353        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
    426354               type="text" value="<?php echo esc_attr( $option_value ); ?>">
    427355        <?php
    428         // Check for description.
    429356        if ( '' !== $args['description'] ) { ?>
    430357            <p class="description">
     
    436363
    437364    /**
    438      * Textarea field callback.
    439      *
    440365     * @param array $args               {
    441366     *                                  Argument array.
     
    447372     */
    448373    public function textarea_field_cb( $args ) {
    449         // Get option value.
    450374        $option_value = $args['value'];
    451375
     
    453377        <textarea id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>" style="width: 100%;"><?php echo esc_textarea( $option_value ); ?></textarea>
    454378        <?php
    455         // Check for description.
    456379        if ( '' !== $args['description'] ) { ?>
    457380            <p class="description">
     
    463386
    464387    /**
    465      * Color field callback.
    466      *
    467388     * @param array $args               {
    468389     *                                  Argument array.
     
    475396     */
    476397    public function color_field_cb( $args ) {
    477         // Get option value.
    478398        $option_value = $args['value'];
    479399
    480         // Get label for.
    481400        ?>
    482401        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
     
    485404               class="lazy-load-responsive-images-color-field">
    486405        <?php
    487         // Check for description.
    488406        if ( '' !== $args['description'] ) { ?>
    489407            <p class="description">
     
    495413
    496414    /**
    497      * Add color picker to media settings page and init it.
    498      *
    499415     * @param string $hook_suffix PHP file of the admin screen.
    500416     */
    501417    public function add_color_picker( $hook_suffix ) {
    502         // Check if we are not on the media backend screen.
    503418        if ( 'options-media.php' !== $hook_suffix ) {
    504419            return;
    505         } // End if().
    506 
    507         // Add color picker script and style and init it.
     420        }
     421
    508422        wp_enqueue_style( 'wp-color-picker' );
    509423        wp_enqueue_script( 'wp-color-picker' );
     
    513427    }
    514428
    515     /**
    516      * Set array of post types that support granular disabling of Lazy Loader features.
    517      */
    518429    public function disable_option_object_types_filter() {
    519430        $public_post_types = get_post_types( array(
     
    521432        ), 'names' );
    522433
    523         // Remove attachment post type.
    524434        if ( is_array( $public_post_types ) && isset( $public_post_types['attachment'] ) ) {
    525435            unset( $public_post_types['attachment'] );
     
    537447    }
    538448
    539     /**
    540      * Register post meta for disabling plugin per
    541      */
    542449    public function register_post_meta() {
    543450        if ( ! is_array( $this->disable_option_object_types ) ) {
     
    560467
    561468    /**
    562      * Add checkbox to Publish Post meta box.
    563      *
    564469     * @link https://github.com/deworg/dewp-planet-feed/
    565470     */
     
    571476        }
    572477
    573         // Check user capability. Not bailing, though, on purpose.
    574478        $maybe_enabled = current_user_can( 'publish_posts' );
    575         // This actually defines whether post will be listed in our feed.
    576479        $value = absint( get_post_meta( $post->ID, 'lazy_load_responsive_images_disabled', true ) );
    577480        printf(
     
    589492
    590493    /**
    591      * Save option value to post meta.
    592      *
    593494     * @link https://github.com/deworg/dewp-planet-feed/
    594495     *
     
    622523
    623524    /**
    624      * Return disabled classes setting value.
    625      *
    626525     * @return array
    627526     */
     
    631530
    632531    /**
    633      * Return load_unveilhooks_plugin value.
    634      *
    635532     * @return string
    636533     */
     
    640537
    641538    /**
    642      * Return enable_for_audios value.
    643      *
    644539     * @return string
    645540     */
     
    649544
    650545    /**
    651      * Return enable_for_videos value.
    652      *
    653546     * @return string
    654547     */
     
    658551
    659552    /**
    660      * Return enable_for_iframes value.
    661      *
    662553     * @return string
    663554     */
     
    667558
    668559    /**
    669      * Return enable_for_background_images value.
    670      *
    671560     * @return string
    672561     */
     
    676565
    677566    /**
    678      * Return load_native_loading_plugin value.
    679      *
    680567     * @return string
    681568     */
     
    685572
    686573    /**
    687      * Return lazysizes_config value.
    688      *
    689574     * @return string
    690575     */
     
    694579
    695580    /**
    696      * Return loading_spinner_color value.
    697      *
    698581     * @return string
    699582     */
     
    703586
    704587    /**
    705      * Return loading_spinner_color_default value.
    706      *
    707588     * @return string
    708589     */
     
    712593
    713594    /**
    714      * Return loading_spinner value.
    715      *
    716595     * @return string
    717596     */
     
    721600
    722601    /**
    723      * Return disable_option_object_types value.
    724      *
    725602     * @return array
    726603     */
     
    730607
    731608    /**
    732      * Return process_complete_markup value.
    733      *
    734609     * @return string
    735610     */
     
    739614
    740615    /**
    741      * Return additional_filters value.
    742      *
    743616     * @return array
    744617     */
  • lazy-loading-responsive-images/tags/8.2.0/vendor/autoload.php

    r2843576 r3070210  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3::getLoader();
     25return ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d::getLoader();
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/ClassLoader.php

    r2843576 r3070210  
    4646    private static $includeFile;
    4747
    48     /** @var ?string */
     48    /** @var string|null */
    4949    private $vendorDir;
    5050
    5151    // PSR-4
    5252    /**
    53      * @var array[]
    54      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5554     */
    5655    private $prefixLengthsPsr4 = array();
    5756    /**
    58      * @var array[]
    59      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    6058     */
    6159    private $prefixDirsPsr4 = array();
    6260    /**
    63      * @var array[]
    64      * @psalm-var array<string, string>
     61     * @var list<string>
    6562     */
    6663    private $fallbackDirsPsr4 = array();
     
    6865    // PSR-0
    6966    /**
    70      * @var array[]
    71      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    7272     */
    7373    private $prefixesPsr0 = array();
    7474    /**
    75      * @var array[]
    76      * @psalm-var array<string, string>
     75     * @var list<string>
    7776     */
    7877    private $fallbackDirsPsr0 = array();
     
    8281
    8382    /**
    84      * @var string[]
    85      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8684     */
    8785    private $classMap = array();
     
    9189
    9290    /**
    93      * @var bool[]
    94      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9592     */
    9693    private $missingClasses = array();
    9794
    98     /** @var ?string */
     95    /** @var string|null */
    9996    private $apcuPrefix;
    10097
    10198    /**
    102      * @var self[]
     99     * @var array<string, self>
    103100     */
    104101    private static $registeredLoaders = array();
    105102
    106103    /**
    107      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    108105     */
    109106    public function __construct($vendorDir = null)
     
    114111
    115112    /**
    116      * @return string[]
     113     * @return array<string, list<string>>
    117114     */
    118115    public function getPrefixes()
     
    126123
    127124    /**
    128      * @return array[]
    129      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    130126     */
    131127    public function getPrefixesPsr4()
     
    135131
    136132    /**
    137      * @return array[]
    138      * @psalm-return array<string, string>
     133     * @return list<string>
    139134     */
    140135    public function getFallbackDirs()
     
    144139
    145140    /**
    146      * @return array[]
    147      * @psalm-return array<string, string>
     141     * @return list<string>
    148142     */
    149143    public function getFallbackDirsPsr4()
     
    153147
    154148    /**
    155      * @return string[] Array of classname => path
    156      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    157150     */
    158151    public function getClassMap()
     
    162155
    163156    /**
    164      * @param string[] $classMap Class to filename map
    165      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    166158     *
    167159     * @return void
     
    180172     * appending or prepending to the ones previously set for this prefix.
    181173     *
    182      * @param string          $prefix  The prefix
    183      * @param string[]|string $paths   The PSR-0 root directories
    184      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    185177     *
    186178     * @return void
     
    188180    public function add($prefix, $paths, $prepend = false)
    189181    {
     182        $paths = (array) $paths;
    190183        if (!$prefix) {
    191184            if ($prepend) {
    192185                $this->fallbackDirsPsr0 = array_merge(
    193                     (array) $paths,
     186                    $paths,
    194187                    $this->fallbackDirsPsr0
    195188                );
     
    197190                $this->fallbackDirsPsr0 = array_merge(
    198191                    $this->fallbackDirsPsr0,
    199                     (array) $paths
     192                    $paths
    200193                );
    201194            }
     
    206199        $first = $prefix[0];
    207200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    208             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    209202
    210203            return;
     
    212205        if ($prepend) {
    213206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    214                 (array) $paths,
     207                $paths,
    215208                $this->prefixesPsr0[$first][$prefix]
    216209            );
     
    218211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    219212                $this->prefixesPsr0[$first][$prefix],
    220                 (array) $paths
     213                $paths
    221214            );
    222215        }
     
    227220     * appending or prepending to the ones previously set for this namespace.
    228221     *
    229      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    230      * @param string[]|string $paths   The PSR-4 base directories
    231      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    232225     *
    233226     * @throws \InvalidArgumentException
     
    237230    public function addPsr4($prefix, $paths, $prepend = false)
    238231    {
     232        $paths = (array) $paths;
    239233        if (!$prefix) {
    240234            // Register directories for the root namespace.
    241235            if ($prepend) {
    242236                $this->fallbackDirsPsr4 = array_merge(
    243                     (array) $paths,
     237                    $paths,
    244238                    $this->fallbackDirsPsr4
    245239                );
     
    247241                $this->fallbackDirsPsr4 = array_merge(
    248242                    $this->fallbackDirsPsr4,
    249                     (array) $paths
     243                    $paths
    250244                );
    251245            }
     
    257251            }
    258252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    259             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    260254        } elseif ($prepend) {
    261255            // Prepend directories for an already registered namespace.
    262256            $this->prefixDirsPsr4[$prefix] = array_merge(
    263                 (array) $paths,
     257                $paths,
    264258                $this->prefixDirsPsr4[$prefix]
    265259            );
     
    268262            $this->prefixDirsPsr4[$prefix] = array_merge(
    269263                $this->prefixDirsPsr4[$prefix],
    270                 (array) $paths
     264                $paths
    271265            );
    272266        }
     
    277271     * replacing any others previously set for this prefix.
    278272     *
    279      * @param string          $prefix The prefix
    280      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    281275     *
    282276     * @return void
     
    295289     * replacing any others previously set for this namespace.
    296290     *
    297      * @param string          $prefix The prefix/namespace, with trailing '\\'
    298      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    299293     *
    300294     * @throws \InvalidArgumentException
     
    430424    {
    431425        if ($file = $this->findFile($class)) {
    432             (self::$includeFile)($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    433428
    434429            return true;
     
    481476
    482477    /**
    483      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    484      *
    485      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    486481     */
    487482    public static function getRegisteredLoaders()
     
    561556    }
    562557
    563     private static function initializeIncludeClosure(): void
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
    564562    {
    565563        if (self::$includeFile !== null) {
     
    575573         * @return void
    576574         */
    577         self::$includeFile = static function($file) {
     575        self::$includeFile = \Closure::bind(static function($file) {
    578576            include $file;
    579         };
     577        }, null, null);
    580578    }
    581579}
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/InstalledVersions.php

    r2843576 r3070210  
    9999        foreach (self::getInstalled() as $installed) {
    100100            if (isset($installed['versions'][$packageName])) {
    101                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     101                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    102102            }
    103103        }
     
    120120    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    121121    {
    122         $constraint = $parser->parseConstraints($constraint);
     122        $constraint = $parser->parseConstraints((string) $constraint);
    123123        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    124124
     
    329329                    $installed[] = self::$installedByVendor[$vendorDir];
    330330                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    331                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
     331                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     332                    $required = require $vendorDir.'/composer/installed.php';
     333                    $installed[] = self::$installedByVendor[$vendorDir] = $required;
    332334                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    333335                        self::$installed = $installed[count($installed) - 1];
     
    341343            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    342344            if (substr(__DIR__, -8, 1) !== 'C') {
    343                 self::$installed = require __DIR__ . '/installed.php';
     345                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     346                $required = require __DIR__ . '/installed.php';
     347                self::$installed = $required;
    344348            } else {
    345349                self::$installed = array();
    346350            }
    347351        }
    348         $installed[] = self::$installed;
     352
     353        if (self::$installed !== array()) {
     354            $installed[] = self::$installed;
     355        }
    349356
    350357        return $installed;
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/autoload_real.php

    r2843576 r3070210  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3
     5class ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d', 'loadClassLoader'));
    3030
    3131        require __DIR__ . '/autoload_static.php';
    32         call_user_func(\Composer\Autoload\ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInita21d1f93de4e18f6084492a2be69518d::getInitializer($loader));
    3333
    3434        $loader->register(true);
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/autoload_static.php

    r2843576 r3070210  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit992eca56574b9f1c8fe962b958c076b3
     7class ComposerStaticInita21d1f93de4e18f6084492a2be69518d
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    5959    {
    6060        return \Closure::bind(function () use ($loader) {
    61             $loader->prefixLengthsPsr4 = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$prefixLengthsPsr4;
    62             $loader->prefixDirsPsr4 = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$prefixDirsPsr4;
    63             $loader->classMap = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$classMap;
     61            $loader->prefixLengthsPsr4 = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$prefixLengthsPsr4;
     62            $loader->prefixDirsPsr4 = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$prefixDirsPsr4;
     63            $loader->classMap = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$classMap;
    6464
    6565        }, null, ClassLoader::class);
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/installed.json

    r2489768 r3070210  
    33        {
    44            "name": "masterminds/html5",
    5             "version": "2.7.4",
    6             "version_normalized": "2.7.4.0",
     5            "version": "2.9.0",
     6            "version_normalized": "2.9.0.0",
    77            "source": {
    88                "type": "git",
    99                "url": "https://github.com/Masterminds/html5-php.git",
    10                 "reference": "9227822783c75406cfe400984b2f095cdf03d417"
     10                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6"
    1111            },
    1212            "dist": {
    1313                "type": "zip",
    14                 "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/9227822783c75406cfe400984b2f095cdf03d417",
    15                 "reference": "9227822783c75406cfe400984b2f095cdf03d417",
     14                "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
     15                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
    1616                "shasum": ""
    1717            },
    1818            "require": {
    19                 "ext-ctype": "*",
    2019                "ext-dom": "*",
    21                 "ext-libxml": "*",
    2220                "php": ">=5.3.0"
    2321            },
    2422            "require-dev": {
    25                 "phpunit/phpunit": "^4.8.35"
     23                "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9"
    2624            },
    27             "time": "2020-10-01T13:52:52+00:00",
     25            "time": "2024-03-31T07:05:07+00:00",
    2826            "type": "library",
    2927            "extra": {
     
    6967            "support": {
    7068                "issues": "https://github.com/Masterminds/html5-php/issues",
    71                 "source": "https://github.com/Masterminds/html5-php/tree/2.7.4"
     69                "source": "https://github.com/Masterminds/html5-php/tree/2.9.0"
    7270            },
    7371            "install-path": "../masterminds/html5"
  • lazy-loading-responsive-images/tags/8.2.0/vendor/composer/installed.php

    r2843576 r3070210  
    22    'root' => array(
    33        'name' => 'florianbrinkmann/lazy-loading-responsive-images',
    4         'pretty_version' => 'v8.1.1',
    5         'version' => '8.1.1.0',
    6         'reference' => '35f8dc96cbf8528f0d89478d3fd5377af01c3692',
     4        'pretty_version' => '8.2.0',
     5        'version' => '8.2.0.0',
     6        'reference' => 'a48ef29925d97c95258d264e05491a76848f01b3',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'florianbrinkmann/lazy-loading-responsive-images' => array(
    14             'pretty_version' => 'v8.1.1',
    15             'version' => '8.1.1.0',
    16             'reference' => '35f8dc96cbf8528f0d89478d3fd5377af01c3692',
     14            'pretty_version' => '8.2.0',
     15            'version' => '8.2.0.0',
     16            'reference' => 'a48ef29925d97c95258d264e05491a76848f01b3',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
     
    2121        ),
    2222        'masterminds/html5' => array(
    23             'pretty_version' => '2.7.4',
    24             'version' => '2.7.4.0',
    25             'reference' => '9227822783c75406cfe400984b2f095cdf03d417',
     23            'pretty_version' => '2.9.0',
     24            'version' => '2.9.0.0',
     25            'reference' => 'f5ac2c0b0a2eefca70b2ce32a5809992227e75a6',
    2626            'type' => 'library',
    2727            'install_path' => __DIR__ . '/../masterminds/html5',
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/RELEASE.md

    r2412362 r3070210  
    11# Release Notes
     2
     32.7.6  (2021-08-18)
     4
     5- #218: Address comment handling issues
     6
     72.7.5  (2021-07-01)
     8
     9- #204: Travis: Enable tests on PHP 8.0
     10- #207: Fix PHP 8.1 deprecations
    211
    3122.7.4  (2020-10-01)
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Elements.php

    r2236239 r3070210  
    7171     */
    7272    const BLOCK_ONLY_INLINE = 128;
     73
     74    /**
     75     * Elements with optional end tags that cause auto-closing of previous and parent tags,
     76     * as example most of the table related tags, see https://www.w3.org/TR/html401/struct/tables.html
     77     * Structure is as follows:
     78     * TAG-NAME => [PARENT-TAG-NAME-TO-CLOSE1, PARENT-TAG-NAME-TO-CLOSE2, ...].
     79     *
     80     * Order is important, after auto-closing one parent with might have to close also their parent.
     81     *
     82     * @var array<string, string[]>
     83     */
     84    public static $optionalEndElementsParentsToClose = array(
     85        'tr' => array('td', 'tr'),
     86        'td' => array('td', 'th'),
     87        'th' => array('td', 'th'),
     88        'tfoot' => array('td', 'th', 'tr', 'tbody', 'thead'),
     89        'tbody' => array('td', 'th', 'tr', 'thead'),
     90    );
    7391
    7492    /**
     
    186204        'ul' => 81, // NORMAL | AUTOCLOSE_P | BLOCK_TAG
    187205        'var' => 1,
    188         'video' => 65, // NORMAL | BLOCK_TAG
     206        'video' => 1,
    189207        'wbr' => 9, // NORMAL | VOID_TAG
    190208
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php

    r2412362 r3070210  
    176176            $dt = $impl->createDocumentType('html');
    177177            // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
    178             $this->doc = $impl->createDocument(null, null, $dt);
     178            $this->doc = $impl->createDocument(null, '', $dt);
    179179            $this->doc->encoding = !empty($options['encoding']) ? $options['encoding'] : 'UTF-8';
    180180        }
     
    360360        }
    361361
     362        // some elements as table related tags might have optional end tags that force us to auto close multiple tags
     363        // https://www.w3.org/TR/html401/struct/tables.html
     364        if ($this->current instanceof \DOMElement && isset(Elements::$optionalEndElementsParentsToClose[$lname])) {
     365            foreach (Elements::$optionalEndElementsParentsToClose[$lname] as $parentElName) {
     366                if ($this->current instanceof \DOMElement && $this->current->tagName === $parentElName) {
     367                    $this->autoclose($parentElName);
     368                }
     369            }
     370        }
     371
    362372        try {
    363373            $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';
     
    406416                $aName = Elements::normalizeMathMlAttribute($aName);
    407417            }
     418
     419            $aVal = (string) $aVal;
    408420
    409421            try {
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Parser/Scanner.php

    r2236239 r3070210  
    105105    public function peek()
    106106    {
    107         if (($this->char + 1) <= $this->EOF) {
     107        if (($this->char + 1) < $this->EOF) {
    108108            return $this->data[$this->char + 1];
    109109        }
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php

    r2236239 r3070210  
    184184     * @return string The current character.
    185185     */
     186    #[\ReturnTypeWillChange]
    186187    public function current()
    187188    {
     
    193194     * This is part of the Iterator interface.
    194195     */
     196    #[\ReturnTypeWillChange]
    195197    public function next()
    196198    {
     
    201203     * Rewind to the start of the string.
    202204     */
     205    #[\ReturnTypeWillChange]
    203206    public function rewind()
    204207    {
     
    211214     * @return bool Whether the current pointer location is valid.
    212215     */
     216    #[\ReturnTypeWillChange]
    213217    public function valid()
    214218    {
     
    325329    }
    326330
     331    #[\ReturnTypeWillChange]
    327332    public function key()
    328333    {
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php

    r2412362 r3070210  
    132132            $tok = $this->scanner->next();
    133133
    134             if ('!' === $tok) {
     134            if (false === $tok) {
     135                // end of string
     136                $this->parseError('Illegal tag opening');
     137            } elseif ('!' === $tok) {
    135138                $this->markupDeclaration();
    136139            } elseif ('/' === $tok) {
     
    138141            } elseif ('?' === $tok) {
    139142                $this->processingInstruction();
    140             } elseif (ctype_alpha($tok)) {
     143            } elseif ($this->is_alpha($tok)) {
    141144                $this->tagName();
    142145            } else {
     
    348351        // EOF -> parse error
    349352        // -> parse error
    350         if (!ctype_alpha($tok)) {
     353        if (!$this->is_alpha($tok)) {
    351354            $this->parseError("Expected tag name, got '%s'", $tok);
    352355            if ("\0" == $tok || false === $tok) {
     
    713716        }
    714717
    715         // If it doesn't start with -, not the end.
    716         if ('-' != $tok) {
     718        // If next two tokens are not '--', not the end.
     719        if ('-' != $tok || '-' != $this->scanner->peek()) {
    717720            return false;
    718721        }
    719722
    720         // Advance one, and test for '->'
    721         if ('-' == $this->scanner->next() && '>' == $this->scanner->peek()) {
     723        $this->scanner->consume(2); // Consume '-' and one of '!' or '>'
     724
     725        // Test for '>'
     726        if ('>' == $this->scanner->current()) {
     727            return true;
     728        }
     729        // Test for '!>'
     730        if ('!' == $this->scanner->current() && '>' == $this->scanner->peek()) {
    722731            $this->scanner->consume(); // Consume the last '>'
    723732            return true;
    724733        }
    725         // Unread '-';
    726         $this->scanner->unconsume(1);
     734        // Unread '-' and one of '!' or '>';
     735        $this->scanner->unconsume(2);
    727736
    728737        return false;
     
    11891198        return '&';
    11901199    }
     1200
     1201    /**
     1202     * Checks whether a (single-byte) character is an ASCII letter or not.
     1203     *
     1204     * @param string $input A single-byte string
     1205     *
     1206     * @return bool True if it is a letter, False otherwise
     1207     */
     1208    protected function is_alpha($input)
     1209    {
     1210        $code = ord($input);
     1211
     1212        return ($code >= 97 && $code <= 122) || ($code >= 65 && $code <= 90);
     1213    }
    11911214}
  • lazy-loading-responsive-images/tags/8.2.0/vendor/masterminds/html5/src/HTML5/Parser/UTF8Utils.php

    r2236239 r3070210  
    3939    /**
    4040     * Count the number of characters in a string.
    41      * UTF-8 aware. This will try (in order) iconv, MB, libxml, and finally a custom counter.
     41     * UTF-8 aware. This will try (in order) iconv, MB, and finally a custom counter.
    4242     *
    4343     * @param string $string
     
    5454        if (function_exists('iconv_strlen')) {
    5555            return iconv_strlen($string, 'utf-8');
    56         }
    57 
    58         if (function_exists('utf8_decode')) {
    59             // MPB: Will this work? Won't certain decodes lead to two chars
    60             // extrapolated out of 2-byte chars?
    61             return strlen(utf8_decode($string));
    6256        }
    6357
  • lazy-loading-responsive-images/trunk/lazy-load-responsive-images.php

    r2843576 r3070210  
    1010 * Plugin URI:  https://florianbrinkmann.com/en/3350/responsive-images-and-lazy-loading-in-wordpress/
    1111 * Description: Lazy loading plugin that supports images, iFrames, video and audio elements and uses lazysizes.js. With manual modification of the markup it is also possible to lazy load background images, scripts, and styles.
    12  * Version:     8.1.1
     12 * Version:     8.2.0
    1313 * Author:      Florian Brinkmann
    1414 * Author URI:  https://florianbrinkmann.com/en/
     
    1919namespace FlorianBrinkmann\LazyLoadResponsiveImages;
    2020
    21 // Load Composer autoloader. From https://github.com/brightnucleus/jasper-client/blob/master/tests/bootstrap.php#L55-L59
    2221$autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
    2322if ( is_readable( $autoloader ) ) {
     
    2928}
    3029
    31 // Create object.
    3230$lazy_loader = new Plugin();
    3331
    34 // Set plugin basename.
     32
    3533$lazy_loader->set_basename( plugin_basename( __FILE__ ) );
    3634$lazy_loader->set_js_asset_url( plugins_url( 'js/build/functions.js', __FILE__ ) );
    3735
    38 // Init the plugin.
    3936$lazy_loader->init();
  • lazy-loading-responsive-images/trunk/readme.txt

    r2843576 r3070210  
    44Tags: lazysizes, lazy loading, performance, images
    55Requires at least: 4.9.8
    6 Tested up to: 6.1
    7 Stable tag: 8.1.1
     6Tested up to: 6.5
     7Stable tag: 8.2.0
    88Requires PHP: 7.0
    99
     
    4545* Styles.
    4646
    47 The plugin adds a `noscript` element as fallback for disabled JavaScript.
     47The plugin adds a `noscript` element as fallback for disabled JavaScript (can be disabled with the `lazy_loader_generate_noscript` filter).
    4848
    4949You can disable lazy loading for elements with specific CSS classes by defining them via the plugin settings (*Settings* › *Media* › *Lazy Loader options*). Or use the `skip-lazy` class or the `data-skip-lazy` attribute. `skip-lazy` and `data-skip-lazy` also work on wrapper elements to exclude the wrapper and its children from being processed.
     
    105105== Changelog ==
    106106
     107= 8.2.0 – 14.04.2024 =
     108
     109Tested with WordPress 6.5.
     110
     111**Added**
     112
     113* `lazy_loader_generate_noscript` filter to allow disabling of `noscript` element generation.
     114
     115**Fixed**
     116
     117- Updated `mastermind/html5` dependency to latest version, which fixes a PHP deprecation notice.
     118
    107119= 8.1.1 – 20.12.2022 =
    108120
  • lazy-loading-responsive-images/trunk/src/Helpers.php

    r2843576 r3070210  
    11<?php
    22/**
    3  * Helper methods.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    108use FlorianBrinkmann\LazyLoadResponsiveImages\Settings as Settings;
    119
    12 /**
    13  * Class Helpers
    14  *
    15  * Class with helper methods.
    16  *
    17  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    18  */
    1910class Helpers {
    2011
    2112    /**
    22      * Hint if the plugin is disabled for this post.
    23      *
    2413     * @var null|int
    2514     */
     
    2716
    2817    /**
    29      * Checks if this is a request at the backend.
    30      *
    3118     * @return bool true if is admin request, otherwise false.
    3219     */
     
    4633
    4734        /*
    48          * Get admin URL and referrer.
    49          *
    5035         * @link https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/pluggable.php#L1076
    5136         */
     
    5338        $referrer  = strtolower( wp_get_referer() );
    5439
    55         // Check if this is a admin request. If true, it
    56         // could also be a AJAX request.
    5740        if ( 0 === strpos( $current_url, $admin_url ) ) {
    58             // Check if the user comes from a admin page.
    5941            if ( 0 === strpos( $referrer, $admin_url ) ) {
    6042                return true;
    6143            } else {
    62                 /*
    63                  * Check for AJAX requests.
    64                  *
    65                  * @link https://gist.github.com/zitrusblau/58124d4b2c56d06b070573a99f33b9ed#file-lazy-load-responsive-images-php-L193
    66                  */
    6744                if ( function_exists( 'wp_doing_ajax' ) ) {
    6845                    return ! wp_doing_ajax();
     
    8057
    8158    /**
    82      * Checks if we are on an AMP page generated from the Automattic plugin.
    83      *
    8459     * @return bool true if is amp page, false otherwise.
    8560     */
    8661    public function is_amp_page() {
    87         // Check if Automattic’s AMP plugin is active and we are on an AMP endpoint.
    8862        if ( function_exists( 'is_amp_endpoint' ) && true === is_amp_endpoint() ) {
    8963            return true;
     
    9468
    9569    /**
    96      * Check if plugin is disabled for current post.
    97      *
    9870     * @return bool true if disabled, false otherwise.
    9971     */
    10072    public function is_disabled_for_post() {
    101         // Check if the plugin is disabled.
    10273        if ( null === $this->disabled_for_current_post ) {
    10374            $this->disabled_for_current_post = absint( get_post_meta( get_the_ID(), 'lazy_load_responsive_images_disabled', true ) );
     
    11788
    11889    /**
    119      * Check if the displayed content is something that the plugin should process.
    120      *
    12190     * @return bool
    12291     */
     
    12695        }
    12796
    128         // Check if we are on a feed page.
    12997        if ( is_feed() ) {
    13098            return false;
    13199        }
    132100
    133         // Check if this content is embedded.
    134101        if ( is_embed() ) {
    135102            return false;
    136103        }
    137104
    138         // Check if this is a request in the backend.
    139105        if ( $this->is_admin_request() ) {
    140106            return false;
    141107        }
    142108
    143         // Check for AMP page.
    144109        if ( $this->is_amp_page() ) {
    145110            return false;
    146111        }
    147112
    148         // Check for Oxygen Builder mode.
    149113        if ( defined( 'SHOW_CT_BUILDER' ) ) {
    150114            return false;
    151115        }
    152116
    153         // Check for TranslatePress editor.
    154117        if ( isset( $_REQUEST['trp-edit-translation'] ) ) {
    155118            return false;
     
    160123
    161124    /**
    162      * Sanitize comma separated list of class names.
    163      *
    164125     * @param string $class_names Comma separated list of HTML class names.
    165126     *
     
    167128     */
    168129    public function sanitize_class_name_list( $class_names ) {
    169         // Get array of the class names.
    170130        $class_names_array = explode( ',', $class_names );
    171131
     
    174134        }
    175135
    176         // Loop through the class names.
    177136        foreach ( $class_names_array as $i => $class_name ) {
    178             // Save the sanitized class name.
    179137            $class_names_array[ $i ] = sanitize_html_class( $class_name );
    180138        }
    181139
    182         // Implode the class names.
    183140        $class_names = implode( ',', $class_names_array );
    184141
     
    187144
    188145    /**
    189      * Sanitize list of filter names.
    190      *
    191146     * @param string $filters One or more WordPress filters, one per line.
    192147     *
     
    194149     */
    195150    public function sanitize_filter_name_list( $filters ) {
    196         // Get array of the filter names.
    197151        $filters_array = explode( "\n", $filters );
    198152
     
    201155        }
    202156
    203         // Loop through the filter names.
    204157        foreach ( $filters_array as $i => $filter ) {
    205158            $function_name_regex = '/^[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*$/';
     
    207160            $filters_array[$i] = trim( $filters_array[$i] );
    208161           
    209             // Check if the filter is a valid PHP function name.
    210162            if ( preg_match( $function_name_regex, $filters_array[$i] ) !== 1 ) {
    211163                unset( $filters_array[$i] );
     
    214166        }
    215167
    216         // Implode the filter names.
    217168        $filters = implode( "\n", $filters_array );
    218169
     
    221172
    222173    /**
    223      * Sanitize checkbox.
    224      *
    225174     * @link https://github.com/WPTRT/code-examples/blob/master/customizer/sanitization-callbacks.php
    226175     *
     
    234183
    235184    /**
    236      * Sanitize textarea input.
    237      *
    238185     * @param bool $checked Whether the checkbox is checked.
    239186     *
     
    245192
    246193    /**
    247      * Sanitize hex color value.
    248      *
    249194     * @param string $value The input from the color input.
    250195     *
     
    252197     */
    253198    public function sanitize_hex_color( $value ) {
    254         // Sanitize the input.
    255199        $sanitized = sanitize_hex_color( $value );
    256200        if ( null !== $sanitized && '' !== $sanitized ) {
     
    259203            $settings = new Settings();
    260204            return $settings->get_loading_spinner_color_default();
    261         } // End if().
     205        }
    262206    }
    263207
  • lazy-loading-responsive-images/trunk/src/Plugin.php

    r2505151 r3070210  
    11<?php
    22/**
    3  * Main plugin code.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    1412use Masterminds\HTML5;
    1513
    16 /**
    17  * Class Plugin
    18  *
    19  * Class for adding lazy loading to responsive images.
    20  *
    21  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    22  */
    2314class Plugin {
    2415
    2516    /**
    26      * Helpers object.
    27      *
    2817     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Helpers
    2918     */
     
    3120
    3221    /**
    33      * Settings object.
    34      *
    3522     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Settings
    3623     */
     
    3825
    3926    /**
    40      * Array of classes which should not be lazy loaded.
    41      *
    4227     * @var array
    4328     */
     
    4530
    4631    /**
    47      * Basename of the plugin.
    48      *
    4932     * @var string
    5033     */
     
    5235
    5336    /**
    54      * URL to editor JS file.
    55      *
    5637     * @var string
    5738     */
     
    5940
    6041    /**
    61      * Placeholder data uri for img src attributes.
    62      *
    6342     * @link https://stackoverflow.com/a/13139830
    6443     *
     
    6847
    6948    /**
    70      * Counter for background image classes.
     49     * @var int
    7150     */
    7251    private $background_image_number = 1;
    7352
    7453    /**
    75      * Plugin constructor.
    76      */
    77     public function __construct() {
    78 
    79     }
    80 
    81     /**
    82      * Runs the filters and actions.
    83      */
     54     * @var bool
     55     */
     56    private $generate_noscript;
     57
    8458    public function init() {
    85         // Init settings.
    8659        $this->settings = new Settings();
    8760
    88         // Set helpers.
    8961        $this->helpers = new Helpers();
    9062
    91         // Get the disabled classes and save in property.
    9263        $this->disabled_classes = $this->settings->get_disabled_classes();
    9364
    94         // Disable core lazy loading.
     65        add_action( 'init', function() {
     66            /**
     67             * Filter to disable the generation of a noscript element.
     68             *
     69             * @param bool $generate_noscript Whether to generate a noscript element or not.
     70             */
     71            $this->generate_noscript = (bool) apply_filters( 'lazy_loader_generate_noscript', true );
     72        }, 5 );
     73
    9574        add_filter( 'wp_lazy_loading_enabled', '__return_false' );
    9675
    97         // Add link to settings in the plugin list.
    9876        add_filter( 'plugin_action_links', array(
    9977            $this,
     
    10381        add_action( 'init', array( $this, 'init_content_processing' ) );
    10482       
    105         // Enqueues scripts and styles.
    10683        add_action( 'wp_enqueue_scripts', array(
    10784            $this,
     
    10986        ), 20 );
    11087
    111         // Adds inline style.
    11288        add_action( 'wp_head', array( $this, 'add_inline_style' ) );
    11389
    114         // Enqueue Gutenberg script.
    11590        add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
    11691
    117         // Load the language files.
    11892        add_action( 'plugins_loaded', array( $this, 'load_translation' ) );
    11993
    120         // Action on uninstall.
    12194        register_uninstall_hook( $this->basename, 'FlorianBrinkmann\LazyLoadResponsiveImages\Plugin::uninstall' );
    12295    }
    123 
    124     /**
    125      * Run actions and filters to start content processing.
    126      */
     96   
    12797    public function init_content_processing() {
    128         // Check if the complete markup should be processed.
    12998        if ( '1' === $this->settings->get_process_complete_markup() ) {
    13099            add_action( 'template_redirect', array( $this, 'process_complete_markup' ) );
    131100        } else {
    132             // Filter markup of the_content() calls to modify media markup for lazy loading.
    133101            add_filter( 'the_content', array( $this, 'filter_markup' ), 10001 );
    134102
    135             // Filter allowed html for posts to allow <noscript> tag.
    136103            add_filter( 'wp_kses_allowed_html', array( $this, 'wp_kses_allowed_html' ), 10, 2 );
    137104
    138             // Filter markup of Text widget to modify media markup for lazy loading.
    139105            add_filter( 'widget_text', array( $this, 'filter_markup' ) );
    140106
    141             // Filter markup of gravatars to modify markup for lazy loading.
    142107            add_filter( 'get_avatar', array( $this, 'filter_markup' ) );
    143108
    144             // Adds lazyload markup and noscript element to post thumbnail.
    145109            add_filter( 'post_thumbnail_html', array(
    146110                $this,
     
    157121        }
    158122    }
    159 
    160     /**
    161      * Run output buffering, to process the complete markup.
    162      */
     123   
    163124    public function process_complete_markup() {
    164         // If this is no content we should process, exit as early as possible.
    165125        if ( ! $this->helpers->is_post_to_process() ) {
    166126            return;
     
    171131
    172132    /**
    173      * Add settings link to the plugin entry in the plugin list.
    174      *
    175133     * @param array  $links Array of action links.
    176134     * @param string $file  Basename of the plugin.
     
    191149
    192150    /**
    193      * Modifies elements to automatically enable lazy loading.
    194      *
    195151     * @param string $content HTML.
    196152     *
     
    198154     */
    199155    public function filter_markup( $content = '' ) {
    200         // If this is no content we should process, exit as early as possible.
    201156        if ( ! $this->helpers->is_post_to_process() ) {
    202157            return $content;
    203158        }
    204159
    205         // Check if we have no content.
    206160        if ( empty( $content ) ) {
    207161            return $content;
    208162        }
    209163
    210         // Check if content contains caption shortcode.
    211164        if ( has_shortcode( $content, 'caption' ) ) {
    212165            return $content;
    213166        }
    214167
    215         // Disable libxml errors.
    216168        libxml_use_internal_errors( true );
    217169
    218         // Create new HTML5 object.
    219170        $html5 = new HTML5( array(
    220171            'disable_html_ns' => true,
     
    228179        $content = str_replace( '<![endif]-->', '<!--<![endif]-->', $content );
    229180
    230         // Load the HTML.
    231181        $dom = $html5->loadHTML( $content );
    232182
    233183        $xpath = new \DOMXPath( $dom );
    234184
    235         // Get all nodes except the ones that live inside a noscript element.
    236         // @link https://stackoverflow.com/a/19348287/7774451.
    237185        $nodes = $xpath->query( "//*[not(ancestor-or-self::noscript)][not(ancestor-or-self::*[contains(@class, 'disable-lazyload') or contains(@class, 'skip-lazy') or @data-skip-lazy])]" );
    238186
     
    240188
    241189        foreach ( $nodes as $node ) {
    242             // Check if it is an element that should not be lazy loaded.
    243             // Get the classes as an array.
    244190            $node_classes = explode( ' ', $node->getAttribute( 'class' ) );
    245191
    246             // Check for intersection with array of classes, which should
    247             // not be lazy loaded.
    248192            $result = array_intersect( $this->disabled_classes, $node_classes );
    249193
    250             // Filter empty values.
    251194            $result = array_filter( $result );
    252 
    253             /*
    254              * Check if:
    255              * - we have no result from the array intersection.
    256              * - the node does not have the data-no-lazyload attr.
    257              * - the node does not already have the lazyload class.
    258              */
     195           
    259196            if ( ! empty( $result ) || $node->hasAttribute( 'data-no-lazyload' ) || in_array( 'lazyload', $node_classes, true ) ) {
    260197                continue;
    261198            }
    262199
    263             // Check if the element has a style attribute with a background image.
    264200            if (
    265201                '1' === $this->settings->get_enable_for_background_images()
     
    277213            }
    278214
    279             // Check if it is one of the supported elements and support for it is enabled.
    280215            if ( 'img' === $node->tagName && 'source' !== $node->parentNode->tagName && 'picture' !== $node->parentNode->tagName ) {
    281216                $dom = $this->modify_img_markup( $node, $dom );
     
    349284
    350285    /**
    351      * Modifies element markup for lazy loading inline background image.
    352      *
    353286     * @param \DOMNode     $node    The node with the inline background image.
    354287     * @param \DOMDocument $dom     \DOMDocument() object of the HTML.
     
    359292        $original_css = $node->getAttribute( 'style' );
    360293        $classes = $node->getAttribute( 'class' );
    361         // It is possible that there are multiple background rules for a inline element (including ones for size, position, et cetera).
    362         // We will insert all of them to the inline style element, to not mess up their order.
     294
    363295        if ( 0 !== preg_match_all( '/background(-[a-z]+)?:([^;])*;?/', $node->getAttribute( 'style' ), $matches ) ) {
    364             // $matches[0] contains the full CSS background rules.
    365             // We remove the rules from the inline style.
    366296            $modified_css = str_replace( $matches[0], '', $original_css );
    367297            $node->setAttribute( 'style', $modified_css );
    368298
    369             // Build string of background rules.
    370299            $background_rules_string = implode( ' ', $matches[0] );
    371300
    372             // Add unique class and lazyload class to element.
    373301            $unique_class = "lazy-loader-background-element-$this->background_image_number";
    374302            $classes .= " lazyload $unique_class ";
     
    376304            $this->background_image_number++;
    377305
    378             // Create style element with the background rule.
    379306            $background_style_elem = $dom->createElement( 'style', ".$unique_class.lazyloaded{ $background_rules_string }" );
    380307            $node->parentNode->insertBefore( $background_style_elem, $node );
    381308
    382             // Add the noscript element.
     309            if ( ! $this->generate_noscript ) {
     310                return $dom;
     311            }
     312
    383313            $noscript = $dom->createElement( 'noscript' );
    384 
    385             // Insert it before the img node.
    386314            $noscript_node = $node->parentNode->insertBefore( $noscript, $node );
    387 
    388             // Create element.
    389315            $background_style_elem_noscript = $dom->createElement( 'style', ".$unique_class.lazyload{ $background_rules_string }" );
    390 
    391             // Add media node to noscript node.
    392316            $noscript_node->appendChild( $background_style_elem_noscript );
    393317        }
     318
    394319        return $dom;
    395320    }
    396321
    397322    /**
    398      * Modifies img markup to enable lazy loading.
    399      *
    400323     * @param \DOMNode     $img             The img dom node.
    401324     * @param \DOMDocument $dom             \DOMDocument() object of the HTML.
     
    405328     */
    406329    public function modify_img_markup( $img, $dom, $create_noscript = true ) {
    407         // Check if the element already has a data-src attribute (might be the case for
    408         // plugins that bring their own lazy load functionality) and skip it to prevent conflicts.
    409330        if ( $img->hasAttribute( 'data-src' ) ) {
    410331            return $dom;
    411332        }
    412333
    413         // Add noscript element.
    414334        if ( true === $create_noscript ) {
    415335            $dom = $this->add_noscript_element( $dom, $img );
    416336        }
    417337
    418         // Check if the image has sizes and srcset attribute.
    419338        $sizes_attr = '';
    420339        if ( $img->hasAttribute( 'sizes' ) ) {
    421             // Get sizes value.
    422340            $sizes_attr = $img->getAttribute( 'sizes' );
    423341
    424             // Check if the value is auto. If so, we modify it to data-sizes.
    425342            if ( 'auto' === $sizes_attr ) {
    426                 // Set data-sizes attribute.
    427343                $img->setAttribute( 'data-sizes', $sizes_attr );
    428344
    429                 // Remove sizes attribute.
    430345                $img->removeAttribute( 'sizes' );
    431346            }
     
    433348
    434349        if ( $img->hasAttribute( 'srcset' ) ) {
    435             // Get srcset value.
    436350            $srcset = $img->getAttribute( 'srcset' );
    437351
    438             // Set data-srcset attribute.
    439352            $img->setAttribute( 'data-srcset', $srcset );
    440353
    441             // Set srcset attribute with src placeholder to produce valid markup.
    442354            $img_width  = $img->getAttribute( 'width' );
    443355            if ( '' !== $img_width ) {
     
    451363                }
    452364            } else {
    453                 // Remove srcset attribute.
    454365                $img->removeAttribute( 'srcset' );
    455366            }
    456367        }
    457368
    458         // Get src value.
    459369        $src = $img->getAttribute( 'src' );
    460370
    461         // Set data-src value.
    462371        $img->setAttribute( 'data-src', $src );
    463372
     
    466375        }
    467376
    468         // Get the classes.
    469377        $classes = $img->getAttribute( 'class' );
    470378
    471         // Add lazyload class.
    472379        $classes .= ' lazyload';
    473380
    474         // Set the class string.
    475381        $img->setAttribute( 'class', $classes );
    476382
    477         // Get width and height.
    478383        $img_width  = $img->getAttribute( 'width' );
    479384        $img_height = $img->getAttribute( 'height' );
    480385
    481         // Set data URI for src attribute.
    482386        if ( '' !== $img_width && '' !== $img_height ) {
    483             // We have image width and height, we can set a inline SVG to prevent content jumps.
    484387            $svg_placeholder = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20{$img_width}%20{$img_height}%22%3E%3C%2Fsvg%3E";
    485388            $img->setAttribute( 'src', $svg_placeholder );
     
    496399
    497400    /**
    498      * Modifies input[type="image"] markup to enable lazy loading.
    499      *
    500401     * @param \DOMNode     $node            The input dom node.
    501402     * @param \DOMDocument $dom             \DOMDocument() object of the HTML.
     
    505406     */
    506407    public function modify_input_markup( $node, $dom, $create_noscript = true ) {
    507         // Check if the element already has a data-src attribute (might be the case for
    508         // plugins that bring their own lazy load functionality) and skip it to prevent conflicts.
    509408        if ( $node->hasAttribute( 'data-src' ) ) {
    510409            return $dom;
    511410        }
    512411
    513         // Add noscript element.
    514412        if ( true === $create_noscript ) {
    515413            $dom = $this->add_noscript_element( $dom, $node );
    516414        }
    517415
    518         // Get src value.
    519416        $src = $node->getAttribute( 'src' );
    520417
    521         // Set data-src value.
    522418        $node->setAttribute( 'data-src', $src );
    523419
    524         // Get the classes.
    525420        $classes = $node->getAttribute( 'class' );
    526421
    527         // Add lazyload class.
    528422        $classes .= ' lazyload';
    529423
    530         // Set the class string.
    531424        $node->setAttribute( 'class', $classes );
    532425
    533         // Get width and height.
    534426        $node_width  = $node->getAttribute( 'width' );
    535427        $node_height = $node->getAttribute( 'height' );
    536428
    537         // Set data URI for src attribute.
    538429        if ( '' !== $node_width && '' !== $node_height ) {
    539             // We have image width and height, we can set a inline SVG to prevent content jumps.
    540430            $svg_placeholder = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20{$node_width}%20{$node_height}%22%3E%3C%2Fsvg%3E";
    541431            $node->setAttribute( 'src', $svg_placeholder );
     
    552442
    553443    /**
    554      * Modifies picture element markup to enable lazy loading.
    555      *
    556444     * @param \DOMNode     $picture The source dom node.
    557445     * @param \DOMDocument $dom     \DOMDocument() object of the HTML.
     
    560448     */
    561449    public function modify_picture_markup( $picture, $dom ) {
    562         // Check if img element already has `layzload` class.
    563450        $img_element = $picture->getElementsByTagName( 'img' );
    564451
     
    569456        }
    570457       
    571         // Add noscript element.
    572458        $dom = $this->add_noscript_element( $dom, $picture );
    573459
    574         // Get source elements from picture.
    575460        $source_elements = $picture->getElementsByTagName( 'source' );
    576461
    577         // Loop the source elements if there are some.
    578462        if ( 0 !== $source_elements->length ) {
    579463            foreach ( $source_elements as $source_element ) {
    580                 // Check if we have a sizes attribute.
    581464                $sizes_attr = '';
    582465                if ( $source_element->hasAttribute( 'sizes' ) ) {
    583                     // Get sizes value.
    584466                    $sizes_attr = $source_element->getAttribute( 'sizes' );
    585467
    586                     // Check if the value is auto. If so, we modify it to data-sizes.
    587468                    if ( 'auto' === $sizes_attr ) {
    588                         // Set data-sizes attribute.
    589469                        $source_element->setAttribute( 'data-sizes', $sizes_attr );
    590470
    591                         // Remove sizes attribute.
    592471                        $source_element->removeAttribute( 'sizes' );
    593472                    }
    594473                }
    595474
    596                 // Check for srcset.
    597475                if ( $source_element->hasAttribute( 'srcset' ) ) {
    598                     // Get srcset value.
    599476                    $srcset = $source_element->getAttribute( 'srcset' );
    600477
    601                     // Set data-srcset attribute.
    602478                    $source_element->setAttribute( 'data-srcset', $srcset );
    603479
    604                     // Set srcset attribute with src placeholder to produce valid markup.
    605480                    if ( '' !== $sizes_attr ) {
    606481                        $width = preg_replace( '/.+ (\d+)px$/', '$1', $sizes_attr );
     
    611486                        }
    612487                    } else {
    613                         // Remove srcset attribute.
    614488                        $source_element->removeAttribute( 'srcset' );
    615489                    }
     
    617491
    618492                if ( $source_element->hasAttribute( 'src' ) ) {
    619                     // Get src value.
    620493                    $src = $source_element->getAttribute( 'src' );
    621494
    622                     // Set data-src value.
    623495                    $source_element->setAttribute( 'data-src', $src );
    624496
    625                     // Set data URI for src attribute.
    626497                    $source_element->setAttribute( 'src', $this->src_placeholder );
    627498                }
     
    629500        }
    630501
    631         // Loop the img element.
    632502        foreach ( $img_element as $img ) {
    633503            $this->modify_img_markup( $img, $dom, false );
     
    638508
    639509    /**
    640      * Modifies iframe markup to enable lazy loading.
    641      *
    642510     * @param \DOMNode     $iframe The iframe dom node.
    643511     * @param \DOMDocument $dom    \DOMDocument() object of the HTML.
     
    646514     */
    647515    public function modify_iframe_markup( $iframe, $dom ) {
    648         // Add noscript element.
    649516        $dom = $this->add_noscript_element( $dom, $iframe );
    650517
    651         // Check if the iframe has a src attribute.
    652518        if ( $iframe->hasAttribute( 'src' ) ) {
    653             // Get src attribute.
    654519            $src = $iframe->getAttribute( 'src' );
    655520
    656             // Set data-src value.
    657521            $iframe->setAttribute( 'data-src', $src );
    658522        } else {
     
    664528        }
    665529
    666         // Get the classes.
    667530        $classes = $iframe->getAttribute( 'class' );
    668531
    669         // Add lazyload class.
    670532        $classes .= ' lazyload';
    671533
    672         // Set the class string.
    673534        $iframe->setAttribute( 'class', $classes );
    674535
    675         // Remove the src attribute.
    676536        $iframe->removeAttribute( 'src' );
    677537
     
    680540
    681541    /**
    682      * Modifies video markup to enable lazy loading.
    683      *
    684542     * @param \DOMNode     $video The video dom node.
    685543     * @param \DOMDocument $dom   \DOMDocument() object of the HTML.
     
    688546     */
    689547    public function modify_video_markup( $video, $dom ) {
    690         // Add noscript element.
    691548        $dom = $this->add_noscript_element( $dom, $video );
    692549
    693         // Check if the video has a poster attribute.
    694550        if ( $video->hasAttribute( 'poster' ) ) {
    695             // Get poster attribute.
    696551            $poster = $video->getAttribute( 'poster' );
    697552
    698             // Remove the poster attribute.
    699553            $video->removeAttribute( 'poster' );
    700554
    701             // Set data-poster value.
    702555            $video->setAttribute( 'data-poster', $poster );
    703556        }
    704557
    705         // Set preload to none.
    706558        $video->setAttribute( 'preload', 'none' );
    707559
    708         // Check for autoplay attribute and change it for lazy loading.
    709560        if ( $video->hasAttribute( 'autoplay' ) ) {
    710561            $video->removeAttribute( 'autoplay' );
     
    712563        }
    713564
    714         // Get the classes.
    715565        $classes = $video->getAttribute( 'class' );
    716566
    717         // Add lazyload class.
    718567        $classes .= ' lazyload';
    719568
    720         // Set the class string.
    721569        $video->setAttribute( 'class', $classes );
    722570
     
    725573
    726574    /**
    727      * Modifies audio markup to enable lazy loading.
    728      *
    729575     * @param \DOMNode     $audio The audio dom node.
    730576     * @param \DOMDocument $dom   \DOMDocument() object of the HTML.
     
    733579     */
    734580    public function modify_audio_markup( $audio, $dom ) {
    735         // Add noscript element.
    736581        $dom = $this->add_noscript_element( $dom, $audio );
    737582
    738         // Set preload to none.
    739583        $audio->setAttribute( 'preload', 'none' );
    740584
    741         // Get the classes.
    742585        $classes = $audio->getAttribute( 'class' );
    743586
    744         // Add lazyload class.
    745587        $classes .= ' lazyload';
    746588
    747         // Set the class string.
    748589        $audio->setAttribute( 'class', $classes );
    749590
     
    752593
    753594    /**
    754      * Adds noscript element before DOM node.
    755      *
    756595     * @param \DOMDocument     $dom            \DOMDocument() object of the
    757596     *                                         HTML.
     
    761600     */
    762601    public function add_noscript_element( $dom, $elem ) {
    763         // Create noscript element and add it before the element that gets lazy loading.
     602        if ( ! $this->generate_noscript ) {
     603            return $dom;
     604        }
     605
    764606        $noscript = $dom->createElement( 'noscript' );
    765607        $noscript_node = $elem->parentNode->insertBefore( $noscript, $elem );
    766608
    767         // Create copy of media element.
    768609        $noscript_media_fallback_elem = $elem->cloneNode( true );
    769610
     
    779620        }
    780621
    781         // Add a copy of the media element to the noscript.
    782622        $noscript_node->appendChild( $noscript_media_fallback_elem );
    783623
     
    786626
    787627    /**
    788      * Filter allowed html for posts.
    789      *
    790628     * @param array  $allowedposttags Allowed post tags.
    791629     * @param string $context         Context.
     
    802640        return $allowedposttags;
    803641    }
    804 
    805     /**
    806      * Enqueues scripts and styles.
    807      */
     642   
    808643    public function enqueue_script() {
    809644        if ( $this->helpers->is_disabled_for_post() ) {
     
    818653        }
    819654
    820         // Enqueue lazysizes.
    821655        wp_enqueue_script( 'lazysizes', plugins_url( '/lazy-loading-responsive-images/js/lazysizes.min.js' ), array(), filemtime( plugin_dir_path( __FILE__ ) . '../js/lazysizes.min.js' ), true );
    822656
    823         // Check if unveilhooks plugin should be loaded.
    824657        if ( '1' === $this->settings->get_load_unveilhooks_plugin() || '1' === $this->settings->get_enable_for_audios() || '1' === $this->settings->get_enable_for_videos() || '1' === $this->settings->get_enable_for_background_images() ) {
    825             // Enqueue unveilhooks plugin.
    826658            wp_enqueue_script( 'lazysizes-unveilhooks', plugins_url( '/lazy-loading-responsive-images/js/ls.unveilhooks.min.js' ), array( 'lazysizes' ), filemtime( plugin_dir_path( __FILE__ ) . '../js/ls.unveilhooks.min.js' ), true );
    827659        }
    828660
    829         // Check if native loading plugin should be loaded.
    830661        if ( '1' === $this->settings->get_load_native_loading_plugin() ) {
    831662            wp_enqueue_script( 'lazysizes-native-loading', plugins_url( '/lazy-loading-responsive-images/js/ls.native-loading.min.js' ), array( 'lazysizes' ), filemtime( plugin_dir_path( __FILE__ ) . '../js/ls.native-loading.min.js' ), true );
    832663        }
    833664
    834         // Include custom lazysizes config if not empty.
    835665        if ( '' !== $this->settings->get_lazysizes_config() ) {
    836666            wp_add_inline_script( 'lazysizes', $this->settings->get_lazysizes_config(), 'before' );
    837667        }
    838668    }
    839 
    840     /**
    841      * Adds inline style.
    842      *
    843      * We do not enqueue a new CSS file for two rules, but cannot use
    844      * wp_add_inline_style() because we have no handle. So we need to
    845      * echo it.
    846      */
     669   
    847670    public function add_inline_style() {
    848671        if ( $this->helpers->is_disabled_for_post() ) {
     
    850673        }
    851674
    852         // Create loading spinner style if needed.
    853675        $spinner_styles = '';
    854676        $spinner_color  = $this->settings->get_loading_spinner_color();
     
    889711        }
    890712
    891         // Display the default styles.
    892713        $default_styles = "<style>:root {
    893714            --lazy-loader-animation-duration: 300ms;
     
    917738        echo apply_filters( 'lazy_load_responsive_images_inline_styles', $default_styles );
    918739
    919         // Hide images if no JS.
    920740        echo '<noscript><style>.lazyload { display: none; } .lazyload[class*="lazy-loader-background-element-"] { display: block; opacity: 1; }</style></noscript>';
    921741    }
    922 
    923     /**
    924      * Enqueue script to Gutenberg editor view.
    925      */
     742   
    926743    public function enqueue_block_editor_assets() {
    927744        if ( isset( $_REQUEST['post'] ) && in_array( get_post_type( $_REQUEST['post'] ), $this->settings->get_disable_option_object_types() ) && post_type_supports( get_post_type( $_REQUEST['post'] ), 'custom-fields' ) ) {
     
    935752        }
    936753    }
    937 
    938     /**
    939      * Loads the plugin translation.
    940      */
     754   
    941755    public function load_translation() {
    942756        load_plugin_textdomain( 'lazy-loading-responsive-images' );
     
    944758
    945759    /**
    946      * Sets plugin basename.
    947      *
    948760     * @param string $basename The plugin basename.
    949761     */
     
    953765
    954766    /**
    955      * Sets plugin basename.
    956      *
    957767     * @param string $basename The plugin basename.
    958768     */
     
    960770        $this->js_asset_url = $js_asset_url;
    961771    }
    962 
    963     /**
    964      * Action on plugin uninstall.
    965      */
     772   
    966773    public static function uninstall() {
    967774        $options_array = array(
     
    982789        );
    983790
    984         // Delete options.
    985791        foreach ( $options_array as $option ) {
    986792            delete_option( $option );
  • lazy-loading-responsive-images/trunk/src/Settings.php

    r2505151 r3070210  
    11<?php
    22/**
    3  * Class for adding customizer settings.
    4  *
    53 * @package FlorianBrinkmann\LazyLoadResponsiveImages
    64 */
     
    86namespace FlorianBrinkmann\LazyLoadResponsiveImages;
    97
    10 /**
    11  * Class Settings
    12  *
    13  * Adds options to the customizer.
    14  *
    15  * @package FlorianBrinkmann\LazyLoadResponsiveImages
    16  */
    178class Settings {
    189
    1910    /**
    20      * Helpers object.
    21      *
    2211     * @var \FlorianBrinkmann\LazyLoadResponsiveImages\Helpers
    2312     */
     
    2514
    2615    /**
    27      * Array of options data.
    28      *
    2916     * @var array
    3017     */
     
    3219
    3320    /**
    34      * Classes which should not be lazy loaded.
    35      *
    3621     * @var array
    3722     */
     
    3924
    4025    /**
    41      * Value of settings for enabling lazy loading for iFrames.
    42      *
    4326     * @var string
    4427     */
     
    4629
    4730    /**
    48      * Value of setting for loading the unveilhooks plugin.
    49      *
    5031     * @var string
    5132     */
     
    5334
    5435    /**
    55      * Value of setting for loading the unveilhooks plugin.
    56      *
    5736     * @var string
    5837     */
     
    6039
    6140    /**
    62      * Value of settings for enabling lazy loading for background images.
    63      *
    6441     * @var string
    6542     */
     
    6744
    6845    /**
    69      * Value of settings for enabling lazy loading for videos.
    70      *
    7146     * @var string
    7247     */
     
    7449
    7550    /**
    76      * Value of settings for enabling lazy loading for audios.
    77      *
    7851     * @var string
    7952     */
     
    8154
    8255    /**
    83      * Value of setting for displaying a loading spinner.
    84      *
    8556     * @var string
    8657     */
     
    8859
    8960    /**
    90      * Default loading spinner color.
    91      *
    9261     * @var string
    9362     */
     
    9564
    9665    /**
    97      * Value of setting for loading spinner color.
    98      *
    9966     * @var string
    10067     */
     
    10269
    10370    /**
    104      * Value of setting for displaying the option to disable the plugin per page/post.
    105      *
    10671     * @var string
    10772     */
     
    10974
    11075    /**
    111      * Array of object types that should show the checkbox to disable lazy loading.
    112      *
    11376     * @var array
    11477     */
     
    11679
    11780    /**
    118      * String to modify lazysizes config.
    119      *
    12081     * @var string
    12182     */
     
    12384
    12485    /**
    125      * Value of setting for processing the complete website markup.
    126      *
    12786     * @var string
    12887     */
     
    13089
    13190    /**
    132      * Value of setting for additional filters to process.
    133      *
    13491     * @var array
    13592     */
     
    13794
    13895    /**
    139      * Allowed HTML tags in descriptions.
    140      *
    14196     * @var array
    14297     */
     
    148103    );
    149104
    150     /**
    151      * Settings constructor.
    152      */
    153105    public function __construct() {
    154         // Set helpers.
    155106        $this->helpers = new Helpers();
    156107
     
    295246        );
    296247
    297         // Fill properties with setting values.
    298248        $this->disabled_classes        = explode( ',', $this->options['lazy_load_responsive_images_disabled_classes']['value'] );
    299249        $this->enable_for_iframes      = $this->options['lazy_load_responsive_images_enable_for_iframes']['value'];
     
    310260        $this->enable_for_background_images = $this->options['lazy_load_responsive_images_enable_for_background_images']['value'];
    311261
    312         // Register settings on media options page.
    313262        add_action( 'admin_init', array( $this, 'settings_init' ), 12 );
    314263
    315         // Include color picker JS.
    316264        add_action( 'admin_enqueue_scripts', array(
    317265            $this,
     
    322270            add_action( 'init', array( $this, 'disable_option_object_types_filter' ), 11 );
    323271
    324             // Register meta for disabling per page.
    325272            add_action( 'init', array( $this, 'register_post_meta' ), 11 );
    326273
    327             // Publish post actions.
    328274            add_action( 'post_submitbox_misc_actions', array( $this, 'add_checkbox' ), 9 );
    329275            add_action( 'save_post', array( $this, 'save_checkbox' ) );
     
    331277    }
    332278
    333     /**
    334      * Init settings on media options page.
    335      */
    336279    public function settings_init() {
    337         // Add section.
    338280        add_settings_section(
    339281            "lazy-load-responsive-images-section",
     
    346288        );
    347289
    348         // Loop the options.
    349290        foreach ( $this->options as $option_id => $option ) {
    350             // Register setting.
    351291            register_setting( 'media', $option_id, array(
    352292                'sanitize_callback' => $option['sanitize_callback'],
    353293            ) );
    354294
    355             // Create field.
    356295            add_settings_field(
    357296                $option_id,
     
    366305                )
    367306            );
    368         } // End foreach().
    369     }
    370 
    371     /**
    372      * Section callback.
    373      *
     307        }
     308    }
     309
     310    /**
    374311     * @param array $args
    375312     */
     
    378315
    379316    /**
    380      * Checkbox callback.
    381      *
    382317     * @param array $args               {
    383318     *                                  Argument array.
     
    389324     */
    390325    public function checkbox_field_cb( $args ) {
    391         // Get option value.
    392326        $option_value = $args['value'];
    393327
    394         // Get label for.
    395328        ?>
    396329        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
    397330               type="checkbox" <?php echo ( $option_value == '1' || $option_value == 'on' ) ? 'checked="checked"' : ''; ?>>
    398331        <?php
    399         // Check for description.
    400332        if ( '' !== $args['description'] ) { ?>
    401333            <p class="description">
     
    407339
    408340    /**
    409      * Text field callback.
    410      *
    411341     * @param array $args               {
    412342     *                                  Argument array.
     
    418348     */
    419349    public function text_field_cb( $args ) {
    420         // Get option value.
    421350        $option_value = $args['value'];
    422351
    423         // Get label for.
    424352        ?>
    425353        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
    426354               type="text" value="<?php echo esc_attr( $option_value ); ?>">
    427355        <?php
    428         // Check for description.
    429356        if ( '' !== $args['description'] ) { ?>
    430357            <p class="description">
     
    436363
    437364    /**
    438      * Textarea field callback.
    439      *
    440365     * @param array $args               {
    441366     *                                  Argument array.
     
    447372     */
    448373    public function textarea_field_cb( $args ) {
    449         // Get option value.
    450374        $option_value = $args['value'];
    451375
     
    453377        <textarea id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>" style="width: 100%;"><?php echo esc_textarea( $option_value ); ?></textarea>
    454378        <?php
    455         // Check for description.
    456379        if ( '' !== $args['description'] ) { ?>
    457380            <p class="description">
     
    463386
    464387    /**
    465      * Color field callback.
    466      *
    467388     * @param array $args               {
    468389     *                                  Argument array.
     
    475396     */
    476397    public function color_field_cb( $args ) {
    477         // Get option value.
    478398        $option_value = $args['value'];
    479399
    480         // Get label for.
    481400        ?>
    482401        <input id="<?php echo esc_attr( $args['label_for'] ); ?>" name="<?php echo esc_attr( $args['label_for'] ); ?>"
     
    485404               class="lazy-load-responsive-images-color-field">
    486405        <?php
    487         // Check for description.
    488406        if ( '' !== $args['description'] ) { ?>
    489407            <p class="description">
     
    495413
    496414    /**
    497      * Add color picker to media settings page and init it.
    498      *
    499415     * @param string $hook_suffix PHP file of the admin screen.
    500416     */
    501417    public function add_color_picker( $hook_suffix ) {
    502         // Check if we are not on the media backend screen.
    503418        if ( 'options-media.php' !== $hook_suffix ) {
    504419            return;
    505         } // End if().
    506 
    507         // Add color picker script and style and init it.
     420        }
     421
    508422        wp_enqueue_style( 'wp-color-picker' );
    509423        wp_enqueue_script( 'wp-color-picker' );
     
    513427    }
    514428
    515     /**
    516      * Set array of post types that support granular disabling of Lazy Loader features.
    517      */
    518429    public function disable_option_object_types_filter() {
    519430        $public_post_types = get_post_types( array(
     
    521432        ), 'names' );
    522433
    523         // Remove attachment post type.
    524434        if ( is_array( $public_post_types ) && isset( $public_post_types['attachment'] ) ) {
    525435            unset( $public_post_types['attachment'] );
     
    537447    }
    538448
    539     /**
    540      * Register post meta for disabling plugin per
    541      */
    542449    public function register_post_meta() {
    543450        if ( ! is_array( $this->disable_option_object_types ) ) {
     
    560467
    561468    /**
    562      * Add checkbox to Publish Post meta box.
    563      *
    564469     * @link https://github.com/deworg/dewp-planet-feed/
    565470     */
     
    571476        }
    572477
    573         // Check user capability. Not bailing, though, on purpose.
    574478        $maybe_enabled = current_user_can( 'publish_posts' );
    575         // This actually defines whether post will be listed in our feed.
    576479        $value = absint( get_post_meta( $post->ID, 'lazy_load_responsive_images_disabled', true ) );
    577480        printf(
     
    589492
    590493    /**
    591      * Save option value to post meta.
    592      *
    593494     * @link https://github.com/deworg/dewp-planet-feed/
    594495     *
     
    622523
    623524    /**
    624      * Return disabled classes setting value.
    625      *
    626525     * @return array
    627526     */
     
    631530
    632531    /**
    633      * Return load_unveilhooks_plugin value.
    634      *
    635532     * @return string
    636533     */
     
    640537
    641538    /**
    642      * Return enable_for_audios value.
    643      *
    644539     * @return string
    645540     */
     
    649544
    650545    /**
    651      * Return enable_for_videos value.
    652      *
    653546     * @return string
    654547     */
     
    658551
    659552    /**
    660      * Return enable_for_iframes value.
    661      *
    662553     * @return string
    663554     */
     
    667558
    668559    /**
    669      * Return enable_for_background_images value.
    670      *
    671560     * @return string
    672561     */
     
    676565
    677566    /**
    678      * Return load_native_loading_plugin value.
    679      *
    680567     * @return string
    681568     */
     
    685572
    686573    /**
    687      * Return lazysizes_config value.
    688      *
    689574     * @return string
    690575     */
     
    694579
    695580    /**
    696      * Return loading_spinner_color value.
    697      *
    698581     * @return string
    699582     */
     
    703586
    704587    /**
    705      * Return loading_spinner_color_default value.
    706      *
    707588     * @return string
    708589     */
     
    712593
    713594    /**
    714      * Return loading_spinner value.
    715      *
    716595     * @return string
    717596     */
     
    721600
    722601    /**
    723      * Return disable_option_object_types value.
    724      *
    725602     * @return array
    726603     */
     
    730607
    731608    /**
    732      * Return process_complete_markup value.
    733      *
    734609     * @return string
    735610     */
     
    739614
    740615    /**
    741      * Return additional_filters value.
    742      *
    743616     * @return array
    744617     */
  • lazy-loading-responsive-images/trunk/vendor/autoload.php

    r2843576 r3070210  
    2323require_once __DIR__ . '/composer/autoload_real.php';
    2424
    25 return ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3::getLoader();
     25return ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d::getLoader();
  • lazy-loading-responsive-images/trunk/vendor/composer/ClassLoader.php

    r2843576 r3070210  
    4646    private static $includeFile;
    4747
    48     /** @var ?string */
     48    /** @var string|null */
    4949    private $vendorDir;
    5050
    5151    // PSR-4
    5252    /**
    53      * @var array[]
    54      * @psalm-var array<string, array<string, int>>
     53     * @var array<string, array<string, int>>
    5554     */
    5655    private $prefixLengthsPsr4 = array();
    5756    /**
    58      * @var array[]
    59      * @psalm-var array<string, array<int, string>>
     57     * @var array<string, list<string>>
    6058     */
    6159    private $prefixDirsPsr4 = array();
    6260    /**
    63      * @var array[]
    64      * @psalm-var array<string, string>
     61     * @var list<string>
    6562     */
    6663    private $fallbackDirsPsr4 = array();
     
    6865    // PSR-0
    6966    /**
    70      * @var array[]
    71      * @psalm-var array<string, array<string, string[]>>
     67     * List of PSR-0 prefixes
     68     *
     69     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     70     *
     71     * @var array<string, array<string, list<string>>>
    7272     */
    7373    private $prefixesPsr0 = array();
    7474    /**
    75      * @var array[]
    76      * @psalm-var array<string, string>
     75     * @var list<string>
    7776     */
    7877    private $fallbackDirsPsr0 = array();
     
    8281
    8382    /**
    84      * @var string[]
    85      * @psalm-var array<string, string>
     83     * @var array<string, string>
    8684     */
    8785    private $classMap = array();
     
    9189
    9290    /**
    93      * @var bool[]
    94      * @psalm-var array<string, bool>
     91     * @var array<string, bool>
    9592     */
    9693    private $missingClasses = array();
    9794
    98     /** @var ?string */
     95    /** @var string|null */
    9996    private $apcuPrefix;
    10097
    10198    /**
    102      * @var self[]
     99     * @var array<string, self>
    103100     */
    104101    private static $registeredLoaders = array();
    105102
    106103    /**
    107      * @param ?string $vendorDir
     104     * @param string|null $vendorDir
    108105     */
    109106    public function __construct($vendorDir = null)
     
    114111
    115112    /**
    116      * @return string[]
     113     * @return array<string, list<string>>
    117114     */
    118115    public function getPrefixes()
     
    126123
    127124    /**
    128      * @return array[]
    129      * @psalm-return array<string, array<int, string>>
     125     * @return array<string, list<string>>
    130126     */
    131127    public function getPrefixesPsr4()
     
    135131
    136132    /**
    137      * @return array[]
    138      * @psalm-return array<string, string>
     133     * @return list<string>
    139134     */
    140135    public function getFallbackDirs()
     
    144139
    145140    /**
    146      * @return array[]
    147      * @psalm-return array<string, string>
     141     * @return list<string>
    148142     */
    149143    public function getFallbackDirsPsr4()
     
    153147
    154148    /**
    155      * @return string[] Array of classname => path
    156      * @psalm-return array<string, string>
     149     * @return array<string, string> Array of classname => path
    157150     */
    158151    public function getClassMap()
     
    162155
    163156    /**
    164      * @param string[] $classMap Class to filename map
    165      * @psalm-param array<string, string> $classMap
     157     * @param array<string, string> $classMap Class to filename map
    166158     *
    167159     * @return void
     
    180172     * appending or prepending to the ones previously set for this prefix.
    181173     *
    182      * @param string          $prefix  The prefix
    183      * @param string[]|string $paths   The PSR-0 root directories
    184      * @param bool            $prepend Whether to prepend the directories
     174     * @param string              $prefix  The prefix
     175     * @param list<string>|string $paths   The PSR-0 root directories
     176     * @param bool                $prepend Whether to prepend the directories
    185177     *
    186178     * @return void
     
    188180    public function add($prefix, $paths, $prepend = false)
    189181    {
     182        $paths = (array) $paths;
    190183        if (!$prefix) {
    191184            if ($prepend) {
    192185                $this->fallbackDirsPsr0 = array_merge(
    193                     (array) $paths,
     186                    $paths,
    194187                    $this->fallbackDirsPsr0
    195188                );
     
    197190                $this->fallbackDirsPsr0 = array_merge(
    198191                    $this->fallbackDirsPsr0,
    199                     (array) $paths
     192                    $paths
    200193                );
    201194            }
     
    206199        $first = $prefix[0];
    207200        if (!isset($this->prefixesPsr0[$first][$prefix])) {
    208             $this->prefixesPsr0[$first][$prefix] = (array) $paths;
     201            $this->prefixesPsr0[$first][$prefix] = $paths;
    209202
    210203            return;
     
    212205        if ($prepend) {
    213206            $this->prefixesPsr0[$first][$prefix] = array_merge(
    214                 (array) $paths,
     207                $paths,
    215208                $this->prefixesPsr0[$first][$prefix]
    216209            );
     
    218211            $this->prefixesPsr0[$first][$prefix] = array_merge(
    219212                $this->prefixesPsr0[$first][$prefix],
    220                 (array) $paths
     213                $paths
    221214            );
    222215        }
     
    227220     * appending or prepending to the ones previously set for this namespace.
    228221     *
    229      * @param string          $prefix  The prefix/namespace, with trailing '\\'
    230      * @param string[]|string $paths   The PSR-4 base directories
    231      * @param bool            $prepend Whether to prepend the directories
     222     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     223     * @param list<string>|string $paths   The PSR-4 base directories
     224     * @param bool                $prepend Whether to prepend the directories
    232225     *
    233226     * @throws \InvalidArgumentException
     
    237230    public function addPsr4($prefix, $paths, $prepend = false)
    238231    {
     232        $paths = (array) $paths;
    239233        if (!$prefix) {
    240234            // Register directories for the root namespace.
    241235            if ($prepend) {
    242236                $this->fallbackDirsPsr4 = array_merge(
    243                     (array) $paths,
     237                    $paths,
    244238                    $this->fallbackDirsPsr4
    245239                );
     
    247241                $this->fallbackDirsPsr4 = array_merge(
    248242                    $this->fallbackDirsPsr4,
    249                     (array) $paths
     243                    $paths
    250244                );
    251245            }
     
    257251            }
    258252            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
    259             $this->prefixDirsPsr4[$prefix] = (array) $paths;
     253            $this->prefixDirsPsr4[$prefix] = $paths;
    260254        } elseif ($prepend) {
    261255            // Prepend directories for an already registered namespace.
    262256            $this->prefixDirsPsr4[$prefix] = array_merge(
    263                 (array) $paths,
     257                $paths,
    264258                $this->prefixDirsPsr4[$prefix]
    265259            );
     
    268262            $this->prefixDirsPsr4[$prefix] = array_merge(
    269263                $this->prefixDirsPsr4[$prefix],
    270                 (array) $paths
     264                $paths
    271265            );
    272266        }
     
    277271     * replacing any others previously set for this prefix.
    278272     *
    279      * @param string          $prefix The prefix
    280      * @param string[]|string $paths  The PSR-0 base directories
     273     * @param string              $prefix The prefix
     274     * @param list<string>|string $paths  The PSR-0 base directories
    281275     *
    282276     * @return void
     
    295289     * replacing any others previously set for this namespace.
    296290     *
    297      * @param string          $prefix The prefix/namespace, with trailing '\\'
    298      * @param string[]|string $paths  The PSR-4 base directories
     291     * @param string              $prefix The prefix/namespace, with trailing '\\'
     292     * @param list<string>|string $paths  The PSR-4 base directories
    299293     *
    300294     * @throws \InvalidArgumentException
     
    430424    {
    431425        if ($file = $this->findFile($class)) {
    432             (self::$includeFile)($file);
     426            $includeFile = self::$includeFile;
     427            $includeFile($file);
    433428
    434429            return true;
     
    481476
    482477    /**
    483      * Returns the currently registered loaders indexed by their corresponding vendor directories.
    484      *
    485      * @return self[]
     478     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     479     *
     480     * @return array<string, self>
    486481     */
    487482    public static function getRegisteredLoaders()
     
    561556    }
    562557
    563     private static function initializeIncludeClosure(): void
     558    /**
     559     * @return void
     560     */
     561    private static function initializeIncludeClosure()
    564562    {
    565563        if (self::$includeFile !== null) {
     
    575573         * @return void
    576574         */
    577         self::$includeFile = static function($file) {
     575        self::$includeFile = \Closure::bind(static function($file) {
    578576            include $file;
    579         };
     577        }, null, null);
    580578    }
    581579}
  • lazy-loading-responsive-images/trunk/vendor/composer/InstalledVersions.php

    r2843576 r3070210  
    9999        foreach (self::getInstalled() as $installed) {
    100100            if (isset($installed['versions'][$packageName])) {
    101                 return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
     101                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
    102102            }
    103103        }
     
    120120    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    121121    {
    122         $constraint = $parser->parseConstraints($constraint);
     122        $constraint = $parser->parseConstraints((string) $constraint);
    123123        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));
    124124
     
    329329                    $installed[] = self::$installedByVendor[$vendorDir];
    330330                } elseif (is_file($vendorDir.'/composer/installed.php')) {
    331                     $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
     331                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     332                    $required = require $vendorDir.'/composer/installed.php';
     333                    $installed[] = self::$installedByVendor[$vendorDir] = $required;
    332334                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
    333335                        self::$installed = $installed[count($installed) - 1];
     
    341343            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
    342344            if (substr(__DIR__, -8, 1) !== 'C') {
    343                 self::$installed = require __DIR__ . '/installed.php';
     345                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
     346                $required = require __DIR__ . '/installed.php';
     347                self::$installed = $required;
    344348            } else {
    345349                self::$installed = array();
    346350            }
    347351        }
    348         $installed[] = self::$installed;
     352
     353        if (self::$installed !== array()) {
     354            $installed[] = self::$installed;
     355        }
    349356
    350357        return $installed;
  • lazy-loading-responsive-images/trunk/vendor/composer/autoload_real.php

    r2843576 r3070210  
    33// autoload_real.php @generated by Composer
    44
    5 class ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3
     5class ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d
    66{
    77    private static $loader;
     
    2525        require __DIR__ . '/platform_check.php';
    2626
    27         spl_autoload_register(array('ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3', 'loadClassLoader'), true, true);
     27        spl_autoload_register(array('ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d', 'loadClassLoader'), true, true);
    2828        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
    29         spl_autoload_unregister(array('ComposerAutoloaderInit992eca56574b9f1c8fe962b958c076b3', 'loadClassLoader'));
     29        spl_autoload_unregister(array('ComposerAutoloaderInita21d1f93de4e18f6084492a2be69518d', 'loadClassLoader'));
    3030
    3131        require __DIR__ . '/autoload_static.php';
    32         call_user_func(\Composer\Autoload\ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::getInitializer($loader));
     32        call_user_func(\Composer\Autoload\ComposerStaticInita21d1f93de4e18f6084492a2be69518d::getInitializer($loader));
    3333
    3434        $loader->register(true);
  • lazy-loading-responsive-images/trunk/vendor/composer/autoload_static.php

    r2843576 r3070210  
    55namespace Composer\Autoload;
    66
    7 class ComposerStaticInit992eca56574b9f1c8fe962b958c076b3
     7class ComposerStaticInita21d1f93de4e18f6084492a2be69518d
    88{
    99    public static $prefixLengthsPsr4 = array (
     
    5959    {
    6060        return \Closure::bind(function () use ($loader) {
    61             $loader->prefixLengthsPsr4 = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$prefixLengthsPsr4;
    62             $loader->prefixDirsPsr4 = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$prefixDirsPsr4;
    63             $loader->classMap = ComposerStaticInit992eca56574b9f1c8fe962b958c076b3::$classMap;
     61            $loader->prefixLengthsPsr4 = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$prefixLengthsPsr4;
     62            $loader->prefixDirsPsr4 = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$prefixDirsPsr4;
     63            $loader->classMap = ComposerStaticInita21d1f93de4e18f6084492a2be69518d::$classMap;
    6464
    6565        }, null, ClassLoader::class);
  • lazy-loading-responsive-images/trunk/vendor/composer/installed.json

    r2489768 r3070210  
    33        {
    44            "name": "masterminds/html5",
    5             "version": "2.7.4",
    6             "version_normalized": "2.7.4.0",
     5            "version": "2.9.0",
     6            "version_normalized": "2.9.0.0",
    77            "source": {
    88                "type": "git",
    99                "url": "https://github.com/Masterminds/html5-php.git",
    10                 "reference": "9227822783c75406cfe400984b2f095cdf03d417"
     10                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6"
    1111            },
    1212            "dist": {
    1313                "type": "zip",
    14                 "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/9227822783c75406cfe400984b2f095cdf03d417",
    15                 "reference": "9227822783c75406cfe400984b2f095cdf03d417",
     14                "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
     15                "reference": "f5ac2c0b0a2eefca70b2ce32a5809992227e75a6",
    1616                "shasum": ""
    1717            },
    1818            "require": {
    19                 "ext-ctype": "*",
    2019                "ext-dom": "*",
    21                 "ext-libxml": "*",
    2220                "php": ">=5.3.0"
    2321            },
    2422            "require-dev": {
    25                 "phpunit/phpunit": "^4.8.35"
     23                "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7 || ^8 || ^9"
    2624            },
    27             "time": "2020-10-01T13:52:52+00:00",
     25            "time": "2024-03-31T07:05:07+00:00",
    2826            "type": "library",
    2927            "extra": {
     
    6967            "support": {
    7068                "issues": "https://github.com/Masterminds/html5-php/issues",
    71                 "source": "https://github.com/Masterminds/html5-php/tree/2.7.4"
     69                "source": "https://github.com/Masterminds/html5-php/tree/2.9.0"
    7270            },
    7371            "install-path": "../masterminds/html5"
  • lazy-loading-responsive-images/trunk/vendor/composer/installed.php

    r2843576 r3070210  
    22    'root' => array(
    33        'name' => 'florianbrinkmann/lazy-loading-responsive-images',
    4         'pretty_version' => 'v8.1.1',
    5         'version' => '8.1.1.0',
    6         'reference' => '35f8dc96cbf8528f0d89478d3fd5377af01c3692',
     4        'pretty_version' => '8.2.0',
     5        'version' => '8.2.0.0',
     6        'reference' => 'a48ef29925d97c95258d264e05491a76848f01b3',
    77        'type' => 'wordpress-plugin',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'florianbrinkmann/lazy-loading-responsive-images' => array(
    14             'pretty_version' => 'v8.1.1',
    15             'version' => '8.1.1.0',
    16             'reference' => '35f8dc96cbf8528f0d89478d3fd5377af01c3692',
     14            'pretty_version' => '8.2.0',
     15            'version' => '8.2.0.0',
     16            'reference' => 'a48ef29925d97c95258d264e05491a76848f01b3',
    1717            'type' => 'wordpress-plugin',
    1818            'install_path' => __DIR__ . '/../../',
     
    2121        ),
    2222        'masterminds/html5' => array(
    23             'pretty_version' => '2.7.4',
    24             'version' => '2.7.4.0',
    25             'reference' => '9227822783c75406cfe400984b2f095cdf03d417',
     23            'pretty_version' => '2.9.0',
     24            'version' => '2.9.0.0',
     25            'reference' => 'f5ac2c0b0a2eefca70b2ce32a5809992227e75a6',
    2626            'type' => 'library',
    2727            'install_path' => __DIR__ . '/../masterminds/html5',
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/RELEASE.md

    r2412362 r3070210  
    11# Release Notes
     2
     32.7.6  (2021-08-18)
     4
     5- #218: Address comment handling issues
     6
     72.7.5  (2021-07-01)
     8
     9- #204: Travis: Enable tests on PHP 8.0
     10- #207: Fix PHP 8.1 deprecations
    211
    3122.7.4  (2020-10-01)
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Elements.php

    r2236239 r3070210  
    7171     */
    7272    const BLOCK_ONLY_INLINE = 128;
     73
     74    /**
     75     * Elements with optional end tags that cause auto-closing of previous and parent tags,
     76     * as example most of the table related tags, see https://www.w3.org/TR/html401/struct/tables.html
     77     * Structure is as follows:
     78     * TAG-NAME => [PARENT-TAG-NAME-TO-CLOSE1, PARENT-TAG-NAME-TO-CLOSE2, ...].
     79     *
     80     * Order is important, after auto-closing one parent with might have to close also their parent.
     81     *
     82     * @var array<string, string[]>
     83     */
     84    public static $optionalEndElementsParentsToClose = array(
     85        'tr' => array('td', 'tr'),
     86        'td' => array('td', 'th'),
     87        'th' => array('td', 'th'),
     88        'tfoot' => array('td', 'th', 'tr', 'tbody', 'thead'),
     89        'tbody' => array('td', 'th', 'tr', 'thead'),
     90    );
    7391
    7492    /**
     
    186204        'ul' => 81, // NORMAL | AUTOCLOSE_P | BLOCK_TAG
    187205        'var' => 1,
    188         'video' => 65, // NORMAL | BLOCK_TAG
     206        'video' => 1,
    189207        'wbr' => 9, // NORMAL | VOID_TAG
    190208
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Parser/DOMTreeBuilder.php

    r2412362 r3070210  
    176176            $dt = $impl->createDocumentType('html');
    177177            // $this->doc = \DOMImplementation::createDocument(NULL, 'html', $dt);
    178             $this->doc = $impl->createDocument(null, null, $dt);
     178            $this->doc = $impl->createDocument(null, '', $dt);
    179179            $this->doc->encoding = !empty($options['encoding']) ? $options['encoding'] : 'UTF-8';
    180180        }
     
    360360        }
    361361
     362        // some elements as table related tags might have optional end tags that force us to auto close multiple tags
     363        // https://www.w3.org/TR/html401/struct/tables.html
     364        if ($this->current instanceof \DOMElement && isset(Elements::$optionalEndElementsParentsToClose[$lname])) {
     365            foreach (Elements::$optionalEndElementsParentsToClose[$lname] as $parentElName) {
     366                if ($this->current instanceof \DOMElement && $this->current->tagName === $parentElName) {
     367                    $this->autoclose($parentElName);
     368                }
     369            }
     370        }
     371
    362372        try {
    363373            $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';
     
    406416                $aName = Elements::normalizeMathMlAttribute($aName);
    407417            }
     418
     419            $aVal = (string) $aVal;
    408420
    409421            try {
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Parser/Scanner.php

    r2236239 r3070210  
    105105    public function peek()
    106106    {
    107         if (($this->char + 1) <= $this->EOF) {
     107        if (($this->char + 1) < $this->EOF) {
    108108            return $this->data[$this->char + 1];
    109109        }
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php

    r2236239 r3070210  
    184184     * @return string The current character.
    185185     */
     186    #[\ReturnTypeWillChange]
    186187    public function current()
    187188    {
     
    193194     * This is part of the Iterator interface.
    194195     */
     196    #[\ReturnTypeWillChange]
    195197    public function next()
    196198    {
     
    201203     * Rewind to the start of the string.
    202204     */
     205    #[\ReturnTypeWillChange]
    203206    public function rewind()
    204207    {
     
    211214     * @return bool Whether the current pointer location is valid.
    212215     */
     216    #[\ReturnTypeWillChange]
    213217    public function valid()
    214218    {
     
    325329    }
    326330
     331    #[\ReturnTypeWillChange]
    327332    public function key()
    328333    {
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Parser/Tokenizer.php

    r2412362 r3070210  
    132132            $tok = $this->scanner->next();
    133133
    134             if ('!' === $tok) {
     134            if (false === $tok) {
     135                // end of string
     136                $this->parseError('Illegal tag opening');
     137            } elseif ('!' === $tok) {
    135138                $this->markupDeclaration();
    136139            } elseif ('/' === $tok) {
     
    138141            } elseif ('?' === $tok) {
    139142                $this->processingInstruction();
    140             } elseif (ctype_alpha($tok)) {
     143            } elseif ($this->is_alpha($tok)) {
    141144                $this->tagName();
    142145            } else {
     
    348351        // EOF -> parse error
    349352        // -> parse error
    350         if (!ctype_alpha($tok)) {
     353        if (!$this->is_alpha($tok)) {
    351354            $this->parseError("Expected tag name, got '%s'", $tok);
    352355            if ("\0" == $tok || false === $tok) {
     
    713716        }
    714717
    715         // If it doesn't start with -, not the end.
    716         if ('-' != $tok) {
     718        // If next two tokens are not '--', not the end.
     719        if ('-' != $tok || '-' != $this->scanner->peek()) {
    717720            return false;
    718721        }
    719722
    720         // Advance one, and test for '->'
    721         if ('-' == $this->scanner->next() && '>' == $this->scanner->peek()) {
     723        $this->scanner->consume(2); // Consume '-' and one of '!' or '>'
     724
     725        // Test for '>'
     726        if ('>' == $this->scanner->current()) {
     727            return true;
     728        }
     729        // Test for '!>'
     730        if ('!' == $this->scanner->current() && '>' == $this->scanner->peek()) {
    722731            $this->scanner->consume(); // Consume the last '>'
    723732            return true;
    724733        }
    725         // Unread '-';
    726         $this->scanner->unconsume(1);
     734        // Unread '-' and one of '!' or '>';
     735        $this->scanner->unconsume(2);
    727736
    728737        return false;
     
    11891198        return '&';
    11901199    }
     1200
     1201    /**
     1202     * Checks whether a (single-byte) character is an ASCII letter or not.
     1203     *
     1204     * @param string $input A single-byte string
     1205     *
     1206     * @return bool True if it is a letter, False otherwise
     1207     */
     1208    protected function is_alpha($input)
     1209    {
     1210        $code = ord($input);
     1211
     1212        return ($code >= 97 && $code <= 122) || ($code >= 65 && $code <= 90);
     1213    }
    11911214}
  • lazy-loading-responsive-images/trunk/vendor/masterminds/html5/src/HTML5/Parser/UTF8Utils.php

    r2236239 r3070210  
    3939    /**
    4040     * Count the number of characters in a string.
    41      * UTF-8 aware. This will try (in order) iconv, MB, libxml, and finally a custom counter.
     41     * UTF-8 aware. This will try (in order) iconv, MB, and finally a custom counter.
    4242     *
    4343     * @param string $string
     
    5454        if (function_exists('iconv_strlen')) {
    5555            return iconv_strlen($string, 'utf-8');
    56         }
    57 
    58         if (function_exists('utf8_decode')) {
    59             // MPB: Will this work? Won't certain decodes lead to two chars
    60             // extrapolated out of 2-byte chars?
    61             return strlen(utf8_decode($string));
    6256        }
    6357
Note: See TracChangeset for help on using the changeset viewer.