晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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\APIInterface;
use CF\Integration;
use Psr\Log\LoggerInterface;
class Hooks
{
protected $api;
protected $config;
protected $dataStore;
protected $integrationContext;
protected $integrationAPI;
protected $logger;
protected $proxy;
const CLOUDFLARE_JSON = 'CLOUDFLARE_JSON';
const WP_AJAX_ACTION = 'cloudflare_proxy';
public function __construct()
{
$this->config = new Integration\DefaultConfig(file_get_contents(CLOUDFLARE_PLUGIN_DIR.'config.json', true));
$this->logger = new Integration\DefaultLogger($this->config->getValue('debug'));
$this->dataStore = new DataStore($this->logger);
$this->integrationAPI = new WordPressAPI($this->dataStore);
$this->integrationContext = new Integration\DefaultIntegration($this->config, $this->integrationAPI, $this->dataStore, $this->logger);
$this->api = new WordPressClientAPI($this->integrationContext);
$this->proxy = new Proxy($this->integrationContext);
}
/**
* @param \CF\API\APIInterface $api
*/
public function setAPI(APIInterface $api)
{
$this->api = $api;
}
public function setConfig(Integration\ConfigInterface $config)
{
$this->config = $config;
}
public function setDataStore(Integration\DataStoreInterface $dataStore)
{
$this->dataStore = $dataStore;
}
public function setIntegrationContext(Integration\IntegrationInterface $integrationContext)
{
$this->integrationContext = $integrationContext;
}
public function setIntegrationAPI(Integration\IntegrationAPIInterface $integrationAPI)
{
$this->integrationAPI = $integrationAPI;
}
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function setProxy(Proxy $proxy)
{
$this->proxy = $proxy;
}
public function cloudflareConfigPage()
{
if (function_exists('add_options_page')) {
add_options_page(__('Cloudflare Configuration'), __('Cloudflare'), 'manage_options', 'cloudflare', array($this, 'cloudflareIndexPage'));
}
}
public function cloudflareIndexPage()
{
include CLOUDFLARE_PLUGIN_DIR.'index.php';
}
public function pluginActionLinks($links)
{
$links[] = '<a href="'.get_admin_url(null, 'options-general.php?page=cloudflare').'">Settings</a>';
return $links;
}
public function initProxy()
{
$this->proxy->run();
}
public function activate()
{
if (version_compare($GLOBALS['wp_version'], CLOUDFLARE_MIN_WP_VERSION, '<')) {
deactivate_plugins(basename(CLOUDFLARE_PLUGIN_DIR));
wp_die('<p><strong>Cloudflare</strong> plugin requires WordPress version '.CLOUDFLARE_MIN_WP_VERSION.' or greater.</p>', 'Plugin Activation Error', array('response' => 200, 'back_link' => true));
}
return true;
}
public function deactivate()
{
$this->dataStore->clearDataStore();
}
public function purgeCacheEverything()
{
if ($this->isPluginSpecificCacheEnabled() || $this->isAutomaticPlatformOptimizationEnabled()) {
$wpDomainList = $this->integrationAPI->getDomainList();
if (count($wpDomainList) > 0) {
$wpDomain = $wpDomainList[0];
$zoneTag = $this->api->getZoneTag($wpDomain);
if (isset($zoneTag)) {
$isOK = $this->api->zonePurgeCache($zoneTag);
$isOK = ($isOK) ? 'succeeded' : 'failed';
$this->logger->debug("purgeCacheEverything " . $isOK);
}
}
}
}
public function purgeCacheByRelevantURLs($postId)
{
if ($this->isPluginSpecificCacheEnabled() || $this->isAutomaticPlatformOptimizationEnabled()) {
$wpDomainList = $this->integrationAPI->getDomainList();
if (!count($wpDomainList)) {
return;
}
$wpDomain = $wpDomainList[0];
$validPostStatus = array('publish', 'trash');
$thisPostStatus = get_post_status($postId);
if (get_permalink($postId) != true || !in_array($thisPostStatus, $validPostStatus)) {
return;
}
if (is_int(wp_is_post_autosave($postId)) || is_int(wp_is_post_revision($postId))) {
return;
}
$savedPost = get_post($postId);
if (is_a($savedPost, 'WP_Post') == false) {
return;
}
$urls = $this->getPostRelatedLinks($postId);
$urls = apply_filters('cloudflare_purge_by_url', $urls, $postId);
$zoneTag = $this->api->getZoneTag($wpDomain);
if (isset($zoneTag) && !empty($urls)) {
$chunks = array_chunk($urls, 30);
foreach ($chunks as $chunk) {
$isOK = $this->api->zonePurgeFiles($zoneTag, $chunk);
$isOK = ($isOK) ? 'succeeded' : 'failed';
$this->logger->debug("List of URLs purged are: " . print_r($chunk, true));
$this->logger->debug("purgeCacheByRelevantURLs " . $isOK);
}
}
}
}
public function getPostRelatedLinks($postId)
{
$listofurls = array();
$postType = get_post_type($postId);
//Purge taxonomies terms URLs
$postTypeTaxonomies = get_object_taxonomies($postType);
foreach ($postTypeTaxonomies as $taxonomy) {
$terms = get_the_terms($postId, $taxonomy);
if (empty($terms) || is_wp_error($terms)) {
continue;
}
foreach ($terms as $term) {
$termLink = get_term_link($term);
if (!is_wp_error($termLink)) {
array_push($listofurls, $termLink);
}
}
}
// Author URL
array_push(
$listofurls,
get_author_posts_url(get_post_field('post_author', $postId)),
get_author_feed_link(get_post_field('post_author', $postId))
);
// Archives and their feeds
if (get_post_type_archive_link($postType) == true) {
array_push(
$listofurls,
get_post_type_archive_link($postType),
get_post_type_archive_feed_link($postType)
);
}
// Post URL
array_push($listofurls, get_permalink($postId));
// Also clean URL for trashed post.
if (get_post_status($postId) == 'trash') {
$trashPost = get_permalink($postId);
$trashPost = str_replace('__trashed', '', $trashPost);
array_push($listofurls, $trashPost, $trashPost.'feed/');
}
// Feeds
array_push(
$listofurls,
get_bloginfo_rss('rdf_url'),
get_bloginfo_rss('rss_url'),
get_bloginfo_rss('rss2_url'),
get_bloginfo_rss('atom_url'),
get_bloginfo_rss('comments_rss2_url'),
get_post_comments_feed_link($postId)
);
// Home Page and (if used) posts page
array_push($listofurls, home_url('/'));
$pageLink = get_permalink(get_option('page_for_posts'));
if (is_string($pageLink) && !empty($pageLink) && get_option('show_on_front') == 'page') {
array_push($listofurls, $pageLink);
}
// Attachments
if ('attachment' == $postType) {
$attachmentUrls = array();
foreach (get_intermediate_image_sizes() as $size) {
$attachmentSrc = wp_get_attachment_image_src($postId, $size);
$attachmentUrls[] = $attachmentSrc[0];
}
$listofurls = array_merge(
$listofurls,
array_unique(array_filter($attachmentUrls))
);
}
// Purge https and http URLs
if (function_exists('force_ssl_admin') && force_ssl_admin()) {
$listofurls = array_merge($listofurls, str_replace('https://', 'http://', $listofurls));
} elseif (!is_ssl() && function_exists('force_ssl_content') && force_ssl_content()) {
$listofurls = array_merge($listofurls, str_replace('http://', 'https://', $listofurls));
}
return $listofurls;
}
protected function isPluginSpecificCacheEnabled()
{
$cacheSettingObject = $this->dataStore->getPluginSetting(\CF\API\Plugin::SETTING_PLUGIN_SPECIFIC_CACHE);
if (! $cacheSettingObject) {
return false;
}
$cacheSettingValue = $cacheSettingObject[\CF\API\Plugin::SETTING_VALUE_KEY];
return $cacheSettingValue !== false
&& $cacheSettingValue !== 'off';
}
protected function isAutomaticPlatformOptimizationEnabled()
{
$cacheSettingObject = $this->dataStore->getPluginSetting(\CF\API\Plugin::SETTING_AUTOMATIC_PLATFORM_OPTIMIZATION);
if (! $cacheSettingObject) {
return false;
}
$cacheSettingValue = $cacheSettingObject[\CF\API\Plugin::SETTING_VALUE_KEY];
return $cacheSettingValue !== false
&& $cacheSettingValue !== 'off';
}
public function http2ServerPushInit()
{
HTTP2ServerPush::init();
}
/*
* php://input can only be read once before PHP 5.6, try to grab it ONLY if the request
* is coming from the cloudflare proxy. We store it in a global so \CF\WordPress\Proxy
* can act on the request body later on in the script execution.
*/
public function getCloudflareRequestJSON()
{
if (isset($_GET['action']) && $_GET['action'] === self::WP_AJAX_ACTION) {
$GLOBALS[self::CLOUDFLARE_JSON] = file_get_contents('php://input');
}
}
public function initAutomaticPlatformOptimization()
{
// it could be too late to set the headers,
// return early without triggering a warning in logs
if (headers_sent()) {
return;
}
// add header unconditionally so we can detect plugin is activated
if (!is_user_logged_in() ) {
header( 'cf-edge-cache: cache,platform=wordpress' );
} else {
header( 'cf-edge-cache: no-cache' );
}
}
}