晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/wp-contentTZh/plugins/elementor/modules/wp-rest/classes/ |
Upload File : |
<?php
namespace Elementor\Modules\WpRest\Classes;
use Elementor\Core\Utils\Collection;
use Elementor\Modules\WpRest\Base\Query as Base;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
class Term_Query extends Base {
const ENDPOINT = 'term';
const SEARCH_FILTER_ACCEPTED_ARGS = 3;
/**
* @param array $clauses Associative array of the clauses for the query.
* @param array $taxonomies Array of taxonomy names.
* @param array $args The args passed to 'get_terms()'.
* @return array Modified clauses.
*/
public function customize_terms_query( $clauses, $taxonomies, $args ) {
if ( ! $args['custom_search'] ) {
return $clauses;
}
if ( is_numeric( $args['name__like'] ) ) {
$clauses['where'] = '(' . $clauses['where'] . ' OR t.term_id = ' . $args['name__like'] . ')';
}
if ( empty( $args['excluded_taxonomies'] ) ) {
return $clauses;
}
$excluded_taxonomies = $args['excluded_taxonomies'];
$escaped = array_map( 'esc_sql', $excluded_taxonomies );
$list = "'" . implode( "','", $escaped ) . "'";
$clauses['where'] .= " AND tt.taxonomy NOT IN ({$list})";
return $clauses;
}
/**
* @param \WP_REST_Request $request
* @return \WP_REST_Response
*/
protected function get( \WP_REST_Request $request ) {
$params = $request->get_params();
$term = trim( $params[ self::SEARCH_TERM_KEY ] ?? '' );
if ( empty( $term ) ) {
return new \WP_REST_Response( [
'success' => true,
'data' => [
'value' => [],
],
], 200 );
}
$included_taxonomies = $params[ self::INCLUDED_TYPE_KEY ];
$excluded_taxonomies = $params[ self::EXCLUDED_TYPE_KEY ];
$keys_format_map = $params[ self::KEYS_CONVERSION_MAP_KEY ];
$requested_count = $params[ self::ITEMS_COUNT_KEY ] ?? 0;
$validated_count = max( $requested_count, 1 );
$count = min( $validated_count, self::MAX_RESPONSE_COUNT );
$should_hide_empty = $params[ self::HIDE_EMPTY_KEY ] ?? false;
$query_args = [
'number' => $count,
'name__like' => $term,
'hide_empty' => $should_hide_empty,
'taxonomy' => ! empty( $included_taxonomies ) ? $included_taxonomies : null,
'excluded_taxonomies' => $excluded_taxonomies ?? [],
'suppress_filter' => false,
'custom_search' => true,
];
if ( ! empty( $params[ self::META_QUERY_KEY ] ) && is_array( $params[ self::META_QUERY_KEY ] ) ) {
$query_args['meta_query'] = $params[ self::META_QUERY_KEY ];
}
$this->add_filter_to_customize_query();
$terms = new Collection( get_terms( $query_args ) );
$this->remove_filter_to_customize_query();
$term_group_labels = $terms
->reduce( function ( $term_types, $term ) {
if ( ! isset( $term_types[ $term->taxonomy ] ) ) {
$taxonomy = get_taxonomy( $term->taxonomy );
$term_types[ $term->taxonomy ] = $taxonomy->labels->name ?? $term->labels;
}
return $term_types;
}, [] );
return new \WP_REST_Response( [
'success' => true,
'data' => [
'value' => $terms
->map( function ( $term ) use ( $keys_format_map, $term_group_labels ) {
$term_object = (array) $term;
if ( isset( $term_object['taxonomy'] ) ) {
$group_name = $term_object['taxonomy'];
if ( isset( $term_group_labels[ $group_name ] ) ) {
$term_object['taxonomy'] = $term_group_labels[ $group_name ];
}
}
return $this->translate_keys( $term_object, $keys_format_map );
} )
->all(),
],
], 200 );
}
/**
* @return void
*/
private function add_filter_to_customize_query() {
$priority = self::SEARCH_FILTER_PRIORITY;
$accepted_args = self::SEARCH_FILTER_ACCEPTED_ARGS;
add_filter( 'terms_clauses', [ $this, 'customize_terms_query' ], $priority, $accepted_args );
}
/**
* @return void
*/
private function remove_filter_to_customize_query() {
$priority = self::SEARCH_FILTER_PRIORITY;
$accepted_args = self::SEARCH_FILTER_ACCEPTED_ARGS;
remove_filter( 'terms_clauses', [ $this, 'customize_terms_query' ], $priority, $accepted_args );
}
/**
* @return array
*/
protected function get_endpoint_registration_args(): array {
return [
self::INCLUDED_TYPE_KEY => [
'description' => 'Included taxonomy containing terms (categories, tags, etc...)',
'type' => 'array',
'required' => false,
'default' => null,
'sanitize_callback' => fn ( ...$args ) => self::sanitize_string_array( ...$args ),
],
self::EXCLUDED_TYPE_KEY => [
'description' => 'Excluded taxonomy containing terms (categories, tags, etc...)',
'type' => 'array',
'required' => false,
'default' => null,
'sanitize_callback' => fn ( ...$args ) => self::sanitize_string_array( ...$args ),
],
self::SEARCH_TERM_KEY => [
'description' => 'Terms to search',
'type' => 'string',
'required' => false,
'default' => '',
'sanitize_callback' => 'sanitize_text_field',
],
self::KEYS_CONVERSION_MAP_KEY => [
'description' => 'Specify keys to extract and convert, i.e. ["key_1" => "new_key_1"].',
'type' => 'array',
'required' => false,
'default' => [
'term_id' => 'id',
'name' => 'label',
'taxonomy' => 'groupLabel',
],
'sanitize_callback' => fn ( ...$args ) => self::sanitize_string_array( ...$args ),
],
self::ITEMS_COUNT_KEY => [
'description' => 'Terms per request',
'type' => 'integer',
'required' => false,
'default' => self::MAX_RESPONSE_COUNT,
],
self::HIDE_EMPTY_KEY => [
'description' => 'Whether to include only public terms',
'type' => 'boolean',
'required' => false,
'default' => false,
],
self::META_QUERY_KEY => [
'description' => 'WP_Query meta_query array',
'type' => 'array',
'required' => false,
'default' => null,
'sanitize_callback' => fn ( ...$args ) => self::sanitize_string_array( ...$args ),
],
];
}
protected static function get_allowed_param_keys(): array {
return [
self::EXCLUDED_TYPE_KEY,
self::INCLUDED_TYPE_KEY,
self::KEYS_CONVERSION_MAP_KEY,
self::META_QUERY_KEY,
self::TAX_QUERY_KEY,
self::ITEMS_COUNT_KEY,
];
}
protected static function get_keys_to_encode(): array {
return [
self::EXCLUDED_TYPE_KEY,
self::INCLUDED_TYPE_KEY,
self::KEYS_CONVERSION_MAP_KEY,
self::META_QUERY_KEY,
self::TAX_QUERY_KEY,
];
}
}