晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/www/wp-content/plugins/cloudflare/src/WordPress/ |
Upload File : |
<?php
namespace CF\WordPress;
use CF\API\Client;
use CF\API\Request;
class WordPressClientAPI extends Client
{
/**
* @param $zone_name
*
* @return mixed
*/
public function getZoneTag($zone_name)
{
$zone_tag = wp_cache_get('cloudflare/client-api/zone-tag/'.$zone_name);
if (false !== $zone_tag) {
return $zone_tag;
}
$request = new Request('GET', 'zones/', array('name' => $zone_name), array());
$response = $this->callAPI($request);
$zone_tag = null;
if ($this->responseOk($response)) {
foreach ($response['result'] as $zone) {
if ($zone['name'] === $zone_name) {
$zone_tag = $zone['id'];
break;
}
}
}
wp_cache_set('cloudflare/client-api/zone-tag/'.$zone_name, $zone_tag);
return $zone_tag;
}
/**
* @param $zoneId
*
* @return bool
*/
public function zonePurgeCache($zoneId)
{
$request = new Request('DELETE', 'zones/'.$zoneId.'/purge_cache', array(), array('purge_everything' => true));
$response = $this->callAPI($request);
return $this->responseOk($response);
}
/**
* @param $zoneId
* @param $files
*
* @return bool
*/
public function zonePurgeFiles($zoneId, $files)
{
$request = new Request('DELETE', 'zones/'.$zoneId.'/purge_cache', array(), array('files' => $files));
$response = $this->callAPI($request);
return $this->responseOk($response);
}
/**
* @param $zoneId
* @param $settingName
* @param $params
*
* @return bool
*/
public function changeZoneSettings($zoneId, $settingName, $params)
{
$request = new Request('PATCH', 'zones/'.$zoneId.'/settings/'.$settingName, array(), $params);
$response = $this->callAPI($request);
return $this->responseOk($response);
}
/**
* @param $urlPattern
*
* @return array
*/
public function createPageRule($zoneId, $body)
{
$request = new Request('POST', 'zones/'.$zoneId.'/pagerules/', array(), $body);
$response = $this->callAPI($request);
return $this->responseOk($response);
}
/**
* @param Request $request
*
* @return array|mixed
*/
public function callAPI(Request $request)
{
$request = $this->beforeSend($request);
$response = $this->sendRequest($request);
$response = $this->getPaginatedResults($request, $response);
return $response;
}
/**
* @param Request $request
* @return [Array] $response
*/
public function sendRequest(Request $request)
{
$requestParams = array(
'timeout' => 30,
'method' => $request->getMethod(),
'headers' => $request->getHeaders(),
);
if ($requestParams['method'] !== 'GET') {
$requestParams['body'] = json_encode($request->getBody());
$requestParams['headers']['Content-Type'] = 'application/json';
}
// Construct URL
$url = add_query_arg($request->getParameters(), $this->getEndpoint().$request->getUrl());
// Send Request
$requestResponse = wp_remote_request($url, $requestParams);
// Check for connection error
if (is_wp_error($requestResponse)) {
$errorMessage = $requestResponse->get_error_message();
$this->logAPICall($this->getAPIClientName(), array_merge(array('type' => 'request', 'path' => $url), $requestParams), true);
$this->logAPICall($this->getAPIClientName(), array('type' => 'response', 'reason' => $requestResponse->get_error_message(), 'code' => $requestResponse->get_error_code(), 'body' => $errorMessage), true);
return $this->createAPIError($errorMessage);
}
// Check for response error != 2XX
if (wp_remote_retrieve_response_code($requestResponse) > 299) {
$errorMessage = wp_remote_retrieve_response_message($requestResponse);
$this->logAPICall($this->getAPIClientName(), array_merge(array('type' => 'request', 'path' => $url), $requestParams), true);
$this->logAPICall($this->getAPIClientName(), array('type' => 'response', 'reason' => $errorMessage, 'code' => wp_remote_retrieve_response_code($requestResponse)), true);
return $this->createAPIError($errorMessage);
}
// Decode request to JSON
$response = json_decode(wp_remote_retrieve_body($requestResponse), true);
if (json_last_error() !== JSON_ERROR_NONE) {
$errorMessage = 'Error decoding client API JSON';
$this->logAPICall($errorMessage, array('error' => json_last_error()), true);
return $this->createAPIError($errorMessage);
}
if (!$this->responseOk($response)) {
$this->logAPICall($this->getAPIClientName(), array('type' => 'response', 'body' => $response), true);
}
return $response;
}
/**
* @param Request $request
* @param [Array] $response
* @return [Array] $paginatedResponse
*/
public function getPaginatedResults(Request $request, $response)
{
if (strtoupper($request->getMethod()) !== 'GET' || !isset($response['result_info']['total_pages'])) {
return $response;
}
$mergedResponse = $response;
$currentPage = 2; // $response already contains page 1
$totalPages = $response['result_info']['total_pages'];
while ($totalPages >= $currentPage) {
$parameters = $request->getParameters();
$parameters['page'] = $currentPage;
$request->setParameters($parameters);
$pagedResponse = $this->sendRequest($request);
$mergedResponse['result'] = array_merge($mergedResponse['result'], $pagedResponse['result']);
// Notify the frontend that pagination is taken care.
$mergedResponse['result_info']['notify'] = 'Backend has taken care of pagination. Output is merged in results.';
$mergedResponse['result_info']['page'] = -1;
$mergedResponse['result_info']['count'] = -1;
$currentPage++;
}
return $mergedResponse;
}
}