晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/stando/public_html/wp-content/plugins/wpseo-news/classes/ |
Upload File : |
<?php
/**
* Yoast SEO: News plugin file.
*
* @package WPSEO_News\XML_Sitemaps
*/
/**
* Handle images used in News.
*/
class WPSEO_News_Sitemap_Images {
/**
* The current item.
*
* @var object
*/
private $item;
/**
* The output that will be returned.
*
* @var string
*/
private $output = '';
/**
* The options.
*
* @var array
*/
private $options;
/**
* Storage for the images.
*
* @var array
*/
private $images;
/**
* Setting properties and build the item.
*
* @param object $item News post object.
* @param array $options The options.
*/
public function __construct( $item, $options ) {
$this->item = $item;
$this->options = $options;
$this->parse_item_images();
}
/**
* Return the output, because the object is converted to a string.
*
* @return string
*/
public function __toString() {
return $this->output;
}
/**
* Parsing the images from the item.
*/
private function parse_item_images() {
$this->get_item_images();
if ( ! empty( $this->images ) ) {
foreach ( $this->images as $src => $img ) {
$this->parse_item_image( $src, $img );
}
}
}
/**
* Getting the images for the given $item.
*/
private function get_item_images() {
$restrict_sitemap_featured_img = isset( $this->options['restrict_sitemap_featured_img'] ) ? $this->options['restrict_sitemap_featured_img'] : false;
if ( ! $restrict_sitemap_featured_img && preg_match_all( '/<img [^>]+>/', $this->item->post_content, $matches ) ) {
$this->get_images_from_content( $matches );
}
// Also check if the featured image value is set.
$post_thumbnail_id = get_post_thumbnail_id( $this->item->ID );
if ( '' !== $post_thumbnail_id ) {
$this->get_item_featured_image( $post_thumbnail_id );
}
}
/**
* Getting the images from the content.
*
* @param array $matches Images found in the content.
*/
private function get_images_from_content( $matches ) {
foreach ( $matches[0] as $img ) {
if ( ! preg_match( '/src=("|\')([^"|\']+)("|\')/', $img, $match ) ) {
continue;
}
$src = $this->parse_image_source( $match[2] );
if ( ! empty( $src ) && ! isset( $this->images[ $src ] ) ) {
$this->images[ $src ] = $this->parse_image( $img );
}
}
}
/**
* Parsing the image source.
*
* @param string $src Image Source.
*
* @return string|void
*/
private function parse_image_source( $src ) {
static $home_url;
if ( is_null( $home_url ) ) {
$home_url = home_url();
}
if ( strpos( $src, 'http' ) !== 0 && strpos( $src, '//' ) !== 0 ) {
if ( $src[0] !== '/' ) {
return null;
}
$src = $home_url . $src;
}
if ( $src !== esc_url( $src ) ) {
return null;
}
return $src;
}
/**
* Setting title and alt for image and returns them in an array.
*
* @param string $img Image HTML.
*
* @return array
*/
private function parse_image( $img ) {
$image = array();
if ( preg_match( '/title=("|\')([^"\']+)("|\')/', $img, $match ) ) {
$image['title'] = str_replace( array( '-', '_' ), ' ', $match[2] );
}
if ( preg_match( '/alt=("|\')([^"\']+)("|\')/', $img, $match ) ) {
$image['alt'] = str_replace( array( '-', '_' ), ' ', $match[2] );
}
return $image;
}
/**
* Parse the XML for given image.
*
* @param string $src Image source.
* @param array $img Image array.
*
* @return void
*/
private function parse_item_image( $src, $img ) {
/**
* Filter: 'wpseo_xml_sitemap_img_src' - Allow changing of sitemap image src.
*
* @api string $src The image source.
*
* @param object $item The post item.
*/
$src = apply_filters( 'wpseo_xml_sitemap_img_src', $src, $this->item );
$this->output .= "\t<image:image>\n";
$this->output .= "\t\t<image:loc>" . htmlspecialchars( $src ) . "</image:loc>\n";
if ( ! empty( $img['title'] ) ) {
$this->output .= "\t\t<image:title>" . htmlspecialchars( $img['title'] ) . "</image:title>\n";
}
if ( ! empty( $img['alt'] ) ) {
$this->output .= "\t\t<image:caption>" . htmlspecialchars( $img['alt'] ) . "</image:caption>\n";
}
$this->output .= "\t</image:image>\n";
}
/**
* Getting the featured image.
*
* @param integer $post_thumbnail_id Thumbnail ID.
*
* @return void
*/
private function get_item_featured_image( $post_thumbnail_id ) {
$attachment = $this->get_attachment( $post_thumbnail_id );
if ( empty( $attachment ) ) {
return;
}
$image = array();
if ( ! empty( $attachment['title'] ) ) {
$image['title'] = $attachment['title'];
}
if ( ! empty( $attachment['alt'] ) ) {
$image['alt'] = $attachment['alt'];
}
if ( ! empty( $attachment['href'] ) ) {
$this->images[ $attachment['href'] ] = $image;
}
elseif ( ! empty( $attachment['src'] ) ) {
$this->images[ $attachment['src'] ] = $image;
}
}
/**
* Get attachment.
*
* @param int $attachment_id Attachment ID.
*
* @return array
*/
private function get_attachment( $attachment_id ) {
// Get attachment.
$attachment = get_post( $attachment_id );
// Check if we've found an attachment.
if ( is_null( $attachment ) ) {
return array();
}
// Return properties.
return array(
'title' => $attachment->post_title,
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'href' => wp_get_attachment_url( $attachment->ID ),
'src' => $attachment->guid,
);
}
}