晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
Server : Apache System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64 User : rainic ( 1014) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/rainic/www/oldTZh/wp-content/plugins/wp-rocket/inc/Dependencies/RocketLazyload/ |
Upload File : |
<?php
/**
* Handles lazyloading of iframes
*
* @package WP_Rocket\Dependencies\RocketLazyload
*/
namespace WP_Rocket\Dependencies\RocketLazyload;
/**
* A class to provide the methods needed to lazyload iframes in WP Rocket and Lazyload by WP Rocket
*/
class Iframe {
/**
* Finds iframes in the HTML provided and call the methods to lazyload them
*
* @param string $html Original HTML.
* @param string $buffer Content to parse.
* @param array $args Array of arguments to use.
* @return string
*/
public function lazyloadIframes( $html, $buffer, $args = [] ) {
$defaults = [
'youtube' => false,
];
$args = wp_parse_args( $args, $defaults );
if ( ! preg_match_all( '@<iframe(?<atts>\s.+)>.*</iframe>@iUs', $buffer, $iframes, PREG_SET_ORDER ) ) {
return $html;
}
$iframes = array_unique( $iframes, SORT_REGULAR );
foreach ( $iframes as $iframe ) {
if ( $this->isIframeExcluded( $iframe ) ) {
continue;
}
// Given the previous regex pattern, $iframe['atts'] starts with a whitespace character.
if ( ! preg_match( '@\ssrc\s*=\s*(\'|")(?<src>.*)\1@iUs', $iframe['atts'], $atts ) ) {
continue;
}
$iframe['src'] = trim( $atts['src'] );
if ( '' === $iframe['src'] ) {
continue;
}
if ( $args['youtube'] ) {
$iframe_lazyload = $this->replaceYoutubeThumbnail( $iframe );
}
if ( empty( $iframe_lazyload ) ) {
$iframe_lazyload = $this->replaceIframe( $iframe );
}
$html = str_replace( $iframe[0], $iframe_lazyload, $html );
unset( $iframe_lazyload );
}
return $html;
}
/**
* Checks if the provided iframe is excluded from lazyload
*
* @param array $iframe Array of matched patterns.
* @return boolean
*/
public function isIframeExcluded( $iframe ) {
foreach ( $this->getExcludedPatterns() as $excluded_pattern ) {
if ( strpos( $iframe[0], $excluded_pattern ) !== false ) {
return true;
}
}
return false;
}
/**
* Gets patterns excluded from lazyload for iframes
*
* @since 2.1.1
*
* @return array
*/
private function getExcludedPatterns() {
/**
* Filters the patterns excluded from lazyload for iframes
*
* @since 2.1.1
*
* @param array $excluded_patterns Array of excluded patterns.
*/
return apply_filters(
'rocket_lazyload_iframe_excluded_patterns',
[
'gform_ajax_frame',
'data-no-lazy=',
'recaptcha/api/fallback',
'loading="eager"',
'data-skip-lazy',
'skip-lazy',
'google_ads_iframe_',
]
);
}
/**
* Applies lazyload on the iframe provided
*
* @param array $iframe Array of matched elements.
* @return string
*/
private function replaceIframe( $iframe ) {
/**
* Filter the LazyLoad placeholder on src attribute
*
* @since 1.0
*
* @param string $placeholder placeholder that will be printed.
*/
$placeholder = apply_filters( 'rocket_lazyload_placeholder', 'about:blank' );
$placeholder_atts = str_replace( $iframe['src'], $placeholder, $iframe['atts'] );
$iframe_lazyload = str_replace( $iframe['atts'], $placeholder_atts . ' data-rocket-lazyload="fitvidscompatible" data-lazy-src="' . esc_url( $iframe['src'] ) . '"', $iframe[0] );
if ( ! preg_match( '@\sloading\s*=\s*(\'|")(?:lazy|auto)\1@i', $iframe_lazyload ) ) {
$iframe_lazyload = str_replace( '<iframe', '<iframe loading="lazy"', $iframe_lazyload );
}
/**
* Filter the LazyLoad HTML output on iframes
*
* @since 1.0
*
* @param array $html Output that will be printed.
*/
$iframe_lazyload = apply_filters( 'rocket_lazyload_iframe_html', $iframe_lazyload );
$iframe_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
return $iframe_lazyload;
}
/**
* Replaces the iframe provided by the Youtube thumbnail
*
* @param array $iframe Array of matched elements.
* @return bool|string
*/
private function replaceYoutubeThumbnail( $iframe ) {
$youtube_id = $this->getYoutubeIDFromURL( $iframe['src'] );
if ( ! $youtube_id ) {
return false;
}
$query = wp_parse_url( htmlspecialchars_decode( $iframe['src'] ), PHP_URL_QUERY );
$youtube_url = $this->changeYoutubeUrlForYoutuDotBe( $iframe['src'] );
$youtube_url = $this->cleanYoutubeUrl( $iframe['src'] );
preg_match( '@\s*title\s*=\s*(\'|")(?<title>.*)\1@iUs', $iframe['atts'], $atts );
$title = $atts['title'] ?? '';
/**
* Filter the LazyLoad HTML output on Youtube iframes
*
* @since 2.11
*
* @param array $html Output that will be printed.
*/
$youtube_lazyload = apply_filters( 'rocket_lazyload_youtube_html', '<div class="rll-youtube-player" data-src="' . esc_attr( $youtube_url ) . '" data-id="' . esc_attr( $youtube_id ) . '" data-query="' . esc_attr( $query ) . '" data-alt="' . esc_attr( $title ) . '"></div>' );
$youtube_lazyload .= '<noscript>' . $iframe[0] . '</noscript>';
return $youtube_lazyload;
}
/**
* Gets the Youtube ID from the URL provided
*
* @param string $url URL to search.
* @return bool|string
*/
public function getYoutubeIDFromURL( $url ) {
$pattern = '#^(?:https?:)?(?://)?(?:www\.)?(?:youtu\.be|youtube\.com|youtube-nocookie\.com)/(?:embed/|v/|watch/?\?v=)?([\w-]{11})#iU';
$result = preg_match( $pattern, $url, $matches );
if ( ! $result ) {
return false;
}
// exclude playlist.
if ( 'videoseries' === $matches[1] ) {
return false;
}
return $matches[1];
}
/**
* Changes URL youtu.be/ID to youtube.com/embed/ID
*
* @param string $url URL to replace.
* @return string Unchanged URL or modified URL.
*/
public function changeYoutubeUrlForYoutuDotBe( $url ) {
$pattern = '#^(?:https?:)?(?://)?(?:www\.)?(?:youtu\.be)/(?:embed/|v/|watch/?\?v=)?([\w-]{11})#iU';
$result = preg_match( $pattern, $url, $matches );
if ( ! $result ) {
return $url;
}
return 'https://www.youtube.com/embed/' . $matches[1];
}
/**
* Cleans Youtube URL. Keeps only scheme, host and path.
*
* @param string $url URL to be cleaned.
* @return string Cleaned URL
*/
public function cleanYoutubeUrl( $url ) {
$parsed_url = wp_parse_url( $url, -1 );
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '//';
$host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
$path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
return $scheme . $host . $path;
}
}