晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/wordpress-seo/inc/ |
Upload File : |
<?php
/**
* WPSEO plugin file.
*
* @package WPSEO\Inc
*/
/**
* Handles requests to MyYoast.
*/
class WPSEO_MyYoast_Api_Request {
/**
* The Request URL.
*
* @var string
*/
protected $url;
/**
* The request parameters.
*
* @var array
*/
protected $args = [
'method' => 'GET',
'timeout' => 5,
'headers' => [
'Accept-Encoding' => '*',
'Expect' => '',
],
];
/**
* Contains the fetched response.
*
* @var stdClass
*/
protected $response;
/**
* Contains the error message when request went wrong.
*
* @var string
*/
protected $error_message = '';
/**
* Constructor.
*
* @codeCoverageIgnore
*
* @param string $url The request url.
* @param array $args The request arguments.
*/
public function __construct( $url, array $args = [] ) {
$this->url = 'https://my.yoast.com/api/' . $url;
$this->args = wp_parse_args( $args, $this->args );
}
/**
* Fires the request.
*
* @return bool True when request is successful.
*/
public function fire() {
try {
$response = $this->do_request( $this->url, $this->args );
$response = $this->decode_response( $response );
$this->response = $this->validate_response( $response );
return true;
} catch ( WPSEO_MyYoast_Bad_Request_Exception $bad_request_exception ) {
$this->error_message = $bad_request_exception->getMessage();
return false;
}
}
/**
* Retrieves the error message.
*
* @return string The set error message.
*/
public function get_error_message() {
return $this->error_message;
}
/**
* Retrieves the response.
*
* @return stdClass The response object.
*/
public function get_response() {
return $this->response;
}
/**
* Performs the request using WordPress internals.
*
* @codeCoverageIgnore
*
* @param string $url The request URL.
* @param array $request_arguments The request arguments.
*
* @return string The retrieved body.
* @throws WPSEO_MyYoast_Bad_Request_Exception When request is invalid.
*/
protected function do_request( $url, $request_arguments ) {
$request_arguments = $this->enrich_request_arguments( $request_arguments );
$response = wp_remote_request( $url, $request_arguments );
if ( is_wp_error( $response ) ) {
throw new WPSEO_MyYoast_Bad_Request_Exception( $response->get_error_message() );
}
$response_code = wp_remote_retrieve_response_code( $response );
$response_message = wp_remote_retrieve_response_message( $response );
// Do nothing, response code is okay.
if ( $response_code === 200 ) {
return wp_remote_retrieve_body( $response );
}
throw new WPSEO_MyYoast_Bad_Request_Exception( esc_html( $response_message ), (int) $response_code );
}
/**
* Decodes the JSON encoded response.
*
* @param string $response The response to decode.
*
* @return stdClass The json decoded response.
* @throws WPSEO_MyYoast_Invalid_JSON_Exception When decoded string is not a JSON object.
*/
protected function decode_response( $response ) {
$response = json_decode( $response );
if ( ! is_object( $response ) ) {
throw new WPSEO_MyYoast_Invalid_JSON_Exception(
esc_html__( 'No JSON object was returned.', 'wordpress-seo' )
);
}
return $response;
}
/**
* Validates that all the needed fields are in de decoded response.
*
* @param stdClass $response The response to validate.
*
* @return stdClass The json decoded response.
* @throws WPSEO_MyYoast_Invalid_JSON_Exception When not all needed fields are found.
*/
private function validate_response( $response ) {
if ( isset( $response->url, $response->subscriptions ) && is_array( $response->subscriptions ) ) {
return $response;
}
throw new WPSEO_MyYoast_Invalid_JSON_Exception(
esc_html__( 'Not all needed fields are present.', 'wordpress-seo' )
);
}
/**
* Checks if MyYoast tokens are allowed and adds the token to the request body.
*
* When tokens are disallowed it will add the url to the request body.
*
* @param array $request_arguments The arguments to enrich.
*
* @return array The enriched arguments.
*/
protected function enrich_request_arguments( array $request_arguments ) {
$request_arguments = wp_parse_args( $request_arguments, [ 'headers' => [] ] );
$addon_version_headers = $this->get_installed_addon_versions();
foreach ( $addon_version_headers as $addon => $version ) {
$request_arguments['headers'][ $addon . '-version' ] = $version;
}
$request_body = $this->get_request_body();
if ( $request_body !== [] ) {
$request_arguments['body'] = $request_body;
}
return $request_arguments;
}
/**
* Retrieves the request body based on URL or access token support.
*
* @codeCoverageIgnore
*
* @return array The request body.
*/
public function get_request_body() {
return [ 'url' => WPSEO_Utils::get_home_url() ];
}
/**
* Wraps the get current user id function.
*
* @codeCoverageIgnore
*
* @return int The user id.
*/
protected function get_current_user_id() {
return get_current_user_id();
}
/**
* Retrieves the installed addons as http headers.
*
* @codeCoverageIgnore
*
* @return array The installed addon versions.
*/
protected function get_installed_addon_versions() {
$addon_manager = new WPSEO_Addon_Manager();
return $addon_manager->get_installed_addons_versions();
}
}