晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/public_html/oldTZh/wp-content/plugins/wp-rocket/inc/Engine/Optimization/ |
Upload File : |
<?php
declare(strict_types=1);
namespace WP_Rocket\Engine\Optimization;
trait RegexTrait {
/**
* Array of replaced xmp tags
*
* @var array
*/
private $xmp_replace = [];
/**
* Array of replaced html tags.
*
* @var array
*/
private $html_replace = [];
/**
* Array of replaced svg tags
*
* @var array
*/
private $svg_replace = [];
/**
* Finds nodes matching the pattern in the HTML.
*
* @param string $pattern Pattern to match.
* @param string $html HTML content.
* @param string $modifiers Regex modifiers.
*
* @return array
*/
protected function find( string $pattern, string $html, string $modifiers = 'Umsi' ) {
preg_match_all( '/' . $pattern . '/' . $modifiers, $html, $matches, PREG_SET_ORDER );
if ( empty( $matches ) ) {
return [];
}
return $matches;
}
/**
* Hides unwanted blocks from the HTML to be parsed for optimization
*
* @since 3.1.4
*
* @param string $html HTML content.
* @return string
*/
protected function hide_comments( $html ) {
$replace = preg_replace( '#<!--\s*noptimize\s*-->.*?<!--\s*/\s*noptimize\s*-->#is', '', $html );
if ( null === $replace ) {
return $html;
}
$replace = preg_replace( '/<!--(.*)-->/Uis', '', $replace );
if ( null === $replace ) {
return $html;
}
return $replace;
}
/**
* Hides scripts from the HTML to be parsed when removing CSS from it
*
* @since 3.10.2
*
* @param string $html HTML content.
*
* @return string
*/
protected function hide_scripts( $html ) {
$replace = preg_replace( '#<script[^>]*>.*?<\/script\s*>#mis', '', $html );
if ( null === $replace ) {
return $html;
}
return $replace;
}
/**
* Hides <noscript> blocks from the HTML to be parsed.
*
* @param string $html HTML content.
*
* @return string
*/
protected function hide_noscripts( $html ) {
$replace = preg_replace( '#<noscript[^>]*>.*?<\/noscript\s*>#mis', '', $html );
if ( null === $replace ) {
return $html;
}
return $replace;
}
/**
* Replace HTML comments.
*
* @param string $html HTML content.
*
* @return string
*/
protected function replace_html_comments( string $html ): string {
$this->html_replace = [];
$regex = '#<!--.*-->#iUs';
$replaced_html = preg_replace_callback( $regex, [ $this, 'replace_html_comment' ], $html );
if ( empty( $replaced_html ) ) {
return $html;
}
return $replaced_html;
}
/**
* Replace html with comment
*
* @param array $match HTML comment.
* @return string
*/
protected function replace_html_comment( $match ) {
$key = sprintf( '<!-- %s -->', uniqid( 'WPR_HTML_COMMENT_' ) );
$this->html_replace[ $key ] = $match[0];
return $key;
}
/**
* Restore html with comment
*
* @param string $html HTML content.
* @return string
*/
protected function restore_html_comments( $html ) {
if ( empty( $this->html_replace ) ) {
return $html;
}
return str_replace( array_keys( $this->html_replace ), array_values( $this->html_replace ), $html );
}
/**
* Replace <xmp> tags in the HTML with comment
*
* @since 3.12.3
*
* @param string $html HTML content.
* @return string
*/
protected function replace_xmp_tags( $html ) {
$this->xmp_replace = [];
$regex = '#<xmp.*>.*</xmp>#Uis';
$replaced_html = preg_replace_callback( $regex, [ $this, 'replace_xmp' ], $html );
if ( empty( $replaced_html ) ) {
return $html;
}
return $replaced_html;
}
/**
* Replace <svg> tags in the HTML with comment
*
* @since 3.12.5.3
*
* @param string $html HTML content.
* @return string
*/
protected function replace_svg_tags( $html ) {
$this->svg_replace = [];
$regex = '#<\s*svg.*>.*<\s*\\\\?/\s*svg\s*>#Uis';
$replaced_html = preg_replace_callback( $regex, [ $this, 'replace_svg' ], $html );
if ( empty( $replaced_html ) ) {
return $html;
}
return $replaced_html;
}
/**
* Replace svg with comment
*
* @since 3.12.3
*
* @param array $match svg tag.
* @return string
*/
protected function replace_svg( $match ) {
$key = sprintf( '<!-- %s -->', uniqid( 'WPR_SVG_' ) );
$this->svg_replace[ $key ] = $match[0];
return $key;
}
/**
* Replace xmp with comment
*
* @since 3.12.3
*
* @param array $match xmp tag.
* @return string
*/
protected function replace_xmp( $match ) {
$key = sprintf( '<!-- %s -->', uniqid( 'WPR_XMP_' ) );
$this->xmp_replace[ $key ] = $match[0];
return $key;
}
/**
* Restore <svg> tags
*
* @since 3.12.5.3
*
* @param string $html HTML content.
* @return string
*/
protected function restore_svg_tags( $html ) {
if ( empty( $this->svg_replace ) ) {
return $html;
}
return str_replace( array_keys( $this->svg_replace ), array_values( $this->svg_replace ), $html );
}
/**
* Restore <xmp> tags
*
* @since 3.12.3
*
* @param string $html HTML content.
* @return string
*/
protected function restore_xmp_tags( $html ) {
if ( empty( $this->xmp_replace ) ) {
return $html;
}
return str_replace( array_keys( $this->xmp_replace ), array_values( $this->xmp_replace ), $html );
}
/**
* Checks if the page HTML is valid or not.
* Valid here means that it has a closing title tag.
*
* @param string $html Page HTML.
*
* @return bool
*/
private function html_has_title_tag( string $html ) {
return (bool) preg_match( '#</title>#iU', $html );
}
}