0Ph(`Xp`I P`/ %ah`I'(HP  *bxpI1;-'PQh &:cIEYN>PWSdId$` 0+P@! eIO@  `(UP[fиIpRRRSPSSSS0T@A(@isQV@hQV@qKJLALg(Ag!+/gO&y`pjKP4: o!1gp 4hk K@ 7 +g@_@`l0K!8$/gXm@K!0r2g X9PnPK < +gl%HoK3 4g\S` @p`K<>s.Security.EscapeOutput.OutputNotEscaped $this->assets->insertLazyloadScript( $script_args ); } /** * Inserts the Youtube thumbnail script in the footer * * @return void * @author Remy Perona * * @since 2.0 */ public function insertYoutubeThumbnailScript() { if ( ! $this->settings->get( 'youtube' ) ) { return; } if ( ! $this->shouldLazyload() ) { return; } /** * Filters the resolution of the YouTube thumbnail * * @param string $thumbnail_resolution The resolution of the thumbnail. Accepted values: default, mqdefault, sddefault, hqdefault, maxresdefault * * @author Arun Basil Lal * * @since 1.4.8 */ $thumbnail_resolution = apply_filters( 'rocket_lazyload_youtube_thumbnail_resolution', 'hqdefault' ); $this->assets->insertYoutubeThumbnailScript( [ 'resolution' => $thumbnail_resolution, 'lazy_image' => (bool) $this->settings->get( 'images' ), ] ); } /** * Inserts the no JS CSS compatibility in the header * * @return void * @author Remy Perona * * @since 2.0.3 */ public function insertNoJSStyle() { if ( ! $this->shouldLazyload() ) { return; } $this->assets->insertNoJSCSS(); } /** * Inserts the Youtube thumbnail CSS in the header * * @return void * @author Remy Perona * * @since 2.0 */ public function insertYoutubeThumbnailStyle() { if ( ! $this->settings->get( 'youtube' ) ) { return; } if ( ! $this->shouldLazyload() ) { return; } $this->assets->insertYoutubeThumbnailCSS( [ 'base_url' => ROCKET_LL_ASSETS_URL, 'responsive_embeds' => current_theme_supports( 'responsive-embeds' ), ] ); } /** * Checks if lazyload should be applied * * @return bool * @author Remy Perona * * @since 2.0 */ private function shouldLazyload() { if ( is_admin() || is_feed() || is_preview() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || ( defined( 'DONOTLAZYLOAD' ) && DONOTLAZYLOAD ) ) { return false; } if ( $this->isPageBuilder() ) { return false; } /** * Filters the lazyload application * * @param bool $do_rocket_lazyload True to apply lazyload, false otherwise. * * @author Remy Perona * * @since 2.0 */ if ( ! apply_filters( 'do_rocket_lazyload', true ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals return false; } return true; } /** * Checks if current page is a page builder editor. * * @return bool * @author Remy Perona * * @since 2.2.2 */ private function isPageBuilder() { // Exclude Page Builders editors. $excluded_parameters = [ 'fl_builder', 'et_fb', 'ct_builder', ]; foreach ( $excluded_parameters as $excluded ) { if ( isset( $_GET[ $excluded ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return true; } } return false; } /** * Gets the content to lazyload * * @return void * @author Remy Perona * * @since 2.0 */ public function lazyload() { if ( ! $this->shouldLazyload() ) { return; } ob_start( [ $this, 'lazyloadBuffer' ] ); } /** * Applies lazyload on the provided content * * @param string $html HTML content. * * @return string * @since 2.0 * @author Remy Perona * */ public function lazyloadBuffer( $html ) { $buffer = $this->ignoreScripts( $html ); $buffer = $this->ignoreNoscripts( $buffer ); if ( $this->settings->get( 'images' ) ) { $html = $this->image->lazyloadImages( $html, $buffer , $this->is_native_images() ); $html = $this->image->lazyloadPictures( $html, $buffer ); $html = $this->image->lazyloadBackgroundImages( $html, $buffer ); } if ( $this->settings->get( 'iframes' ) ) { $args = [ 'youtube' => $this->settings->get( 'youtube' ), ]; $html = $this->iframe->lazyloadIframes( $html, $buffer, $args ); } return $html; } /** * Applies lazyload on responsive images attributes srcset and sizes * * @param string $html Image HTML. * * @return string * @since 2.0 * @author Remy Perona * */ public function lazyloadResponsive( $html ) { return $this->image->lazyloadResponsiveAttributes( $html ); } /** * Applies lazyload on WordPress smilies * * @return void * @author Remy Perona * * @since 2.0 */ public function lazyloadSmilies() { if ( ! $this->shouldLazyload() ) { return; } if ( ! $this->settings->get( 'images' ) ) { return; } $filters = [ 'the_content' => 10, 'the_excerpt' => 10, 'comment_text' => 20, ]; foreach ( $filters as $filter => $prio ) { if ( ! has_filter( $filter ) ) { continue; } remove_filter( $filter, 'convert_smilies', $prio ); add_filter( $filter, [ $this->image, 'convertSmilies' ], $prio ); } } /** * Remove inline scripts from the HTML to parse * * @param string $html HTML content. * * @return string */ private function ignoreScripts( $html ) { return preg_replace( '/]*)>(?:.+)?<\/script>/Umsi', '', $html ); } /** * Remove noscript tags from the HTML to parse * * @param string $html HTML content. * * @return string */ private function ignoreNoscripts( $html ) { return preg_replace( '##Umsi', '', $html ); } /** * Checks if native lazyload is enabled for images ** * @return bool */ private function is_native_images(): bool { /** * Filters the use of native lazyload for images * * @param bool $use_native True to use native lazyload for images, false otherwise. */ return (bool) apply_filters( 'rocket_use_native_lazyload', false ); } }