/home/fortodpl/thecutediva.com/wp-content/plugins/litespeed-cache/src/media.cls.php (45122B)
'; // Original image info. if ( $size_meta && ! empty( $size_meta['ori_saved'] ) ) { $percent = (int) ceil( ( (int) $size_meta['ori_saved'] * 100 ) / max( 1, (int) $size_meta['ori_total'] ) ); $extension = pathinfo( $short_path, PATHINFO_EXTENSION ); $bk_file = substr( $short_path, 0, -strlen( $extension ) ) . 'bk.' . $extension; $bk_optm_file = substr( $short_path, 0, -strlen( $extension ) ) . 'bk.optm.' . $extension; $link = Utility::build_url( Router::ACTION_IMG_OPTM, 'orig' . $post_id ); $desc = false; $cls = ''; if ( $this->info( $bk_file, $post_id ) ) { $curr_status = esc_html__( '(optm)', 'litespeed-cache' ); $desc = esc_attr__( 'Currently using optimized version of file.', 'litespeed-cache' ) . ' ' . esc_attr__( 'Click to switch to original (unoptimized) version.', 'litespeed-cache' ); } elseif ( $this->info( $bk_optm_file, $post_id ) ) { $cls .= ' litespeed-warning'; $curr_status = esc_html__( '(non-optm)', 'litespeed-cache' ); $desc = esc_attr__( 'Currently using original (unoptimized) version of file.', 'litespeed-cache' ) . ' ' . esc_attr__( 'Click to switch to optimized version.', 'litespeed-cache' ); } echo wp_kses( GUI::pie_tiny( $percent, 24, sprintf( esc_html__( 'Original file reduced by %1$s (%2$s)', 'litespeed-cache' ), $percent . '%', Utility::real_size( $size_meta['ori_saved'] ) ), 'left' ), GUI::allowed_svg_tags() ); printf( esc_html__( 'Orig saved %s', 'litespeed-cache' ), (int) $percent . '%' ); if ( $desc ) { printf( ' %4$s', esc_url( $link ), esc_attr( $cls ), wp_kses_post( $desc ), esc_html( $curr_status ) ); } else { printf( ' %2$s', esc_attr__( 'Using optimized version of file. ', 'litespeed-cache' ) . ' ' . esc_attr__( 'No backup of original file exists.', 'litespeed-cache' ), esc_html__( '(optm)', 'litespeed-cache' ) ); } } elseif ( $size_meta && 0 === (int) $size_meta['ori_saved'] ) { echo wp_kses( GUI::pie_tiny( 0, 24, esc_html__( 'Congratulation! Your file was already optimized', 'litespeed-cache' ), 'left' ), GUI::allowed_svg_tags() ); printf( esc_html__( 'Orig %s', 'litespeed-cache' ), '' . esc_html__( '(no savings)', 'litespeed-cache' ) . '' ); } else { echo esc_html__( 'Orig', 'litespeed-cache' ) . '—'; } echo '
'; echo ''; // WebP/AVIF info. if ( $size_meta && $this->webp_support( true ) && ! empty( $size_meta[ $this->_sys_format . '_saved' ] ) ) { $is_avif = 'avif' === $this->_sys_format; $size_meta_saved = $size_meta[ $this->_sys_format . '_saved' ]; $size_meta_total = $size_meta[ $this->_sys_format . '_total' ]; $percent = ceil( ( $size_meta_saved * 100 ) / max( 1, $size_meta_total ) ); $link = Utility::build_url( Router::ACTION_IMG_OPTM, $this->_sys_format . $post_id ); $desc = false; $cls = ''; if ( $this->info( $short_path . '.' . $this->_sys_format, $post_id ) ) { $curr_status = esc_html__( '(optm)', 'litespeed-cache' ); $desc = $is_avif ? esc_attr__( 'Currently using optimized version of AVIF file.', 'litespeed-cache' ) : esc_attr__( 'Currently using optimized version of WebP file.', 'litespeed-cache' ); $desc .= ' ' . esc_attr__( 'Click to switch to original (unoptimized) version.', 'litespeed-cache' ); } elseif ( $this->info( $short_path . '.optm.' . $this->_sys_format, $post_id ) ) { $cls .= ' litespeed-warning'; $curr_status = esc_html__( '(non-optm)', 'litespeed-cache' ); $desc = $is_avif ? esc_attr__( 'Currently using original (unoptimized) version of AVIF file.', 'litespeed-cache' ) : esc_attr__( 'Currently using original (unoptimized) version of WebP file.', 'litespeed-cache' ); $desc .= ' ' . esc_attr__( 'Click to switch to optimized version.', 'litespeed-cache' ); } echo wp_kses( GUI::pie_tiny( $percent, 24, sprintf( $is_avif ? esc_html__( 'AVIF file reduced by %1$s (%2$s)', 'litespeed-cache' ) : esc_html__( 'WebP file reduced by %1$s (%2$s)', 'litespeed-cache' ), $percent . '%', Utility::real_size( $size_meta_saved ) ), 'left' ), GUI::allowed_svg_tags() ); printf( $is_avif ? esc_html__( 'AVIF saved %s', 'litespeed-cache' ) : esc_html__( 'WebP saved %s', 'litespeed-cache' ), '' . esc_html( $percent ) . '%' ); if ( $desc ) { printf( ' %4$s', esc_url( $link ), esc_attr( $cls ), wp_kses_post( $desc ), esc_html( $curr_status ) ); } else { printf( ' %3$s', esc_attr__( 'Using optimized version of file. ', 'litespeed-cache' ), $is_avif ? esc_attr__( 'No backup of unoptimized AVIF file exists.', 'litespeed-cache' ) : esc_attr__( 'No backup of unoptimized WebP file exists.', 'litespeed-cache' ), esc_html__( '(optm)', 'litespeed-cache' ) ); } } else { echo esc_html( $this->next_gen_image_title() ) . '—'; } echo '
'; // Delete row btn. if ( $size_meta ) { printf( '', esc_url( Utility::build_url( Router::ACTION_IMG_OPTM, Img_Optm::TYPE_RESET_ROW, false, null, [ 'id' => $post_id ] ) ), esc_html__( 'Restore from backup', 'litespeed-cache' ) ); echo '', $lazy_lib . '', $this->content );
}
}
/**
* Parse img src for VPI preload only.
* Note: Didn't reuse the _parse_img() because it contains replacement logic which is not needed for preload.
*
* @since 6.2
* @since 7.6 - Added attributes fetchpriority="high" and decode="sync" for VPI images.
* @return void
*/
private function _parse_img_for_preload() {
// Load VPI setting.
$is_mobile = $this->_separate_mobile();
$vpi_files = $this->cls( 'Metabox' )->setting( $is_mobile ? VPI::POST_META_MOBILE : VPI::POST_META );
if ( $vpi_files ) {
$vpi_files = Utility::sanitize_lines( $vpi_files, 'basename' );
}
if ( ! $vpi_files ) {
return;
}
if ( ! $this->content ) {
return;
}
$content = preg_replace( [ '##sU', '##isU' ], '', $this->content );
if ( ! $content ) {
return;
}
$vpi_fp_search = [];
$vpi_fp_replace = [];
preg_match_all('#]+)/?>#isU', $content, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$attrs = Utility::parse_attr($match[1]);
if ( empty( $attrs['src'] ) ) {
continue;
}
if ( false !== strpos( $attrs['src'], 'base64' ) || 0 === strpos( $attrs['src'], 'data:' ) ) {
self::debug2( 'lazyload bypassed base64 img' );
continue;
}
if ( false !== strpos( $attrs['src'], '{' ) ) {
self::debug2( 'image src has {} ' . $attrs['src'] );
continue;
}
// If the src contains VPI filename, then preload it.
if ( ! Utility::str_hit_array( $attrs['src'], $vpi_files ) ) {
continue;
}
self::debug2( 'VPI preload found and matched: ' . $attrs['src'] );
$this->_vpi_preload_list[] = $attrs['src'];
// Add attributes fetchpriority="high" and decode="sync"
// after WP 6.3.0 use: wp_img_tag_add_loading_optimization_attrs().
$new_html = [];
$attrs[ 'fetchpriority' ] = 'high';
$attrs[ 'decoding' ] = 'sync';
// create html with new attributes.
foreach ( $attrs as $k => $attr ) {
$new_html[] = $k . '="' . $attr . '"';
}
if ( $new_html ) {
$vpi_fp_search[] = $match[1];
$vpi_fp_replace[] = implode( ' ', $new_html);
}
}
// if VPI fetchpriority changes, do the replacement
if ( $vpi_fp_search && $vpi_fp_replace ) {
$this->content = str_replace( $vpi_fp_search, $vpi_fp_replace, $this->content );
}
unset( $vpi_fp_search );
unset( $vpi_fp_replace );
}
/**
* Parse img src.
*
* @since 1.4
* @access private
* @return array{0:array,1:array,2:array} All the src & related raw html list with placeholders.
*/
private function _parse_img() {
/**
* Exclude list.
*
* @since 1.5
* @since 2.7.1 Changed to array.
*/
$excludes = apply_filters( 'litespeed_media_lazy_img_excludes', $this->conf( Base::O_MEDIA_LAZY_EXC ) );
$cls_excludes = apply_filters( 'litespeed_media_lazy_img_cls_excludes', $this->conf( Base::O_MEDIA_LAZY_CLS_EXC ) );
$cls_excludes[] = 'skip-lazy'; // https://core.trac.wordpress.org/ticket/44427
$src_list = [];
$html_list = [];
$placeholder_list = [];
$content = preg_replace(
[
'##sU',
'##isU',
'##isU', // Remove script to avoid false matches and warnings, when image size detection is turned ON.
],
'',
$this->content
);
/**
* Exclude parent classes.
*
* @since 3.0
*/
$parent_cls_exc = apply_filters( 'litespeed_media_lazy_img_parent_cls_excludes', $this->conf( Base::O_MEDIA_LAZY_PARENT_CLS_EXC ) );
if ( $parent_cls_exc ) {
self::debug2( 'Lazyload Class excludes', $parent_cls_exc );
foreach ( $parent_cls_exc as $v ) {
$content = preg_replace('#<(\w+) [^>]*class=(\'|")[^\'"]*' . preg_quote($v, '#') . '[^\'"]*\2[^>]*>.*\1>#sU', '', $content);
}
}
$add_missing_sizes = ( defined( 'LITESPEED_GUEST_OPTM' ) || $this->conf( Base::O_MEDIA_ADD_MISSING_SIZES ) )
&& apply_filters( 'litespeed_media_add_missing_sizes', true );
preg_match_all( '#
]+)/?>#isU', $content, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
$attrs = Utility::parse_attr( $match[1] );
if ( empty( $attrs['src'] ) ) {
continue;
}
/**
* Add src validation to bypass base64 img src.
*
* @since 1.6
*/
if ( false !== strpos( $attrs['src'], 'base64' ) || 0 === strpos( $attrs['src'], 'data:' ) ) {
self::debug2( 'lazyload bypassed base64 img' );
continue;
}
self::debug2( 'lazyload found: ' . $attrs['src'] );
if (
! empty( $attrs['data-no-lazy'] ) ||
! empty( $attrs['data-skip-lazy'] ) ||
! empty( $attrs['data-lazyloaded'] ) ||
! empty( $attrs['data-src'] ) ||
! empty( $attrs['data-srcset'] )
) {
self::debug2( 'bypassed' );
continue;
}
$hit = ! empty( $attrs['class'] ) ? Utility::str_hit_array( $attrs['class'], $cls_excludes ) : false;
if ( $hit ) {
self::debug2( 'lazyload image cls excludes [hit] ' . $hit );
continue;
}
/**
* Exclude from lazyload by setting.
*
* @since 1.5
*/
if ( $excludes && Utility::str_hit_array( $attrs['src'], $excludes ) ) {
self::debug2( 'lazyload image exclude ' . $attrs['src'] );
continue;
}
/**
* Excludes invalid image src from buddypress avatar crop.
*
* @see https://wordpress.org/support/topic/lazy-load-breaking-buddypress-upload-avatar-feature
* @since 3.0
*/
if ( false !== strpos( $attrs['src'], '{' ) ) {
self::debug2( 'image src has {} ' . $attrs['src'] );
continue;
}
// to avoid multiple replacement.
if ( in_array( $match[0], $html_list, true ) ) {
continue;
}
// Add missing dimensions.
if ( $add_missing_sizes ) {
if ( empty( $attrs['width'] ) || 'auto' === $attrs['width'] || empty( $attrs['height'] ) || 'auto' === $attrs['height'] ) {
self::debug( '⚠️ Missing sizes for image [src] ' . $attrs['src'] );
$dimensions = $this->_detect_dimensions( $attrs['src'] );
if ( $dimensions ) {
$ori_width = $dimensions[0];
$ori_height = $dimensions[1];
// Calculate height based on width.
if ( ! empty( $attrs['width'] ) && 'auto' !== $attrs['width'] ) {
$ori_height = (int) ( ( $ori_height * (int) $attrs['width'] ) / max( 1, $ori_width ) );
} elseif ( ! empty( $attrs['height'] ) && 'auto' !== $attrs['height'] ) {
$ori_width = (int) ( ( $ori_width * (int) $attrs['height'] ) / max( 1, $ori_height ) );
}
// Remove existing width/height, then append new values
$inner = Utility::remove_attr( $match[1], 'width' );
$inner = Utility::remove_attr( $inner, 'height' );
$new_html = '
';
self::debug( 'Add missing sizes ' . $ori_width . 'x' . $ori_height . ' to ' . $attrs['src'] );
$this->content = str_replace( $match[0], $new_html, $this->content );
$match[0] = $new_html;
$attrs['width'] = $ori_width;
$attrs['height'] = $ori_height;
}
}
}
$placeholder = false;
if ( ! empty( $attrs['width'] ) && 'auto' !== $attrs['width'] && ! empty( $attrs['height'] ) && 'auto' !== $attrs['height'] ) {
$placeholder = (int) $attrs['width'] . 'x' . (int) $attrs['height'];
}
$src_list[] = $attrs['src'];
$html_list[] = $match[0];
$placeholder_list[] = $placeholder;
}
return [ $src_list, $html_list, $placeholder_list ];
}
/**
* Detect the original sizes.
*
* @since 4.0
*
* @param string $src Source URL/path.
* @return array|false getimagesize array or false.
*/
private function _detect_dimensions( $src ) {
$pathinfo = Utility::is_internal_file( $src );
if ( $pathinfo ) {
$src = $pathinfo[0];
} elseif ( apply_filters( 'litespeed_media_ignore_remote_missing_sizes', false ) ) {
return false;
}
if ( 0 === strpos( $src, '//' ) ) {
$src = 'https:' . $src;
}
try {
$sizes = getimagesize( $src );
} catch ( \Exception $e ) {
return false;
}
if ( ! empty( $sizes[0] ) && ! empty( $sizes[1] ) ) {
return $sizes;
}
return false;
}
/**
* Parse iframe src.
*
* @since 1.4
* @access private
* @return array All the related raw html list (full