晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/persian-gravity-forms/includes/ |
Upload File : |
<?php
defined( 'ABSPATH' ) || exit;
class GFPersian_Adress extends GFPersian_Core {
public function __construct() {
if ( $this->option( 'address', '1' ) != '1' ) {
return;
}
add_action( 'gform_editor_js', [ $this, 'custom_options_editor_js' ] );
add_action( 'gform_field_standard_settings', [ $this, 'custom_options' ], 10, 2 );
add_filter( 'gform_address_types', [ $this, 'iran_address_type' ] );
add_filter( 'gform_predefined_choices', [ $this, 'iran_provinces_choices' ], 1 );
add_filter( 'gform_field_content', [ $this, 'iran_cities_field_type' ], 10, 5 );
add_action( 'gform_register_init_scripts', [ $this, 'init_script' ], 10, 1 );
add_action( 'gform_enqueue_scripts', [ $this, 'external_js' ], 10, 2 );
}
/**
* Iran provinces list
*
* @return array
*/
public function iran_provinces(): array {
return [
'آذربایجان شرقی',
'آذربایجان غربی',
'اردبیل',
'اصفهان',
'البرز',
'ایلام',
'بوشهر',
'تهران',
'چهارمحال و بختیاری',
'خراسان جنوبی',
'خراسان رضوی',
'خراسان شمالی',
'خوزستان',
'زنجان',
'سمنان',
'سیستان و بلوچستان',
'فارس',
'قزوین',
'قم',
'کردستان',
'کرمان',
'کرمانشاه',
'کهگیلویه و بویراحمد',
'گلستان',
'گیلان',
'لرستان',
'مازندران',
'مرکزی',
'هرمزگان',
'همدان',
'یزد'
];
}
/**
* Add Iran address type to GForms
*
* @filter gform_address_types
*
* @param array $addressTypes Contains the details for existing address types.
*
* @return array
*/
public function iran_address_type( array $address_types ): array {
$address_types['iran'] = [
'label' => 'ایران',
'country' => 'ایران',
'zip_label' => 'کدپستی',
'state_label' => 'استان',
'states' => array_merge( [ '' ], $this->iran_provinces() )
];
return $address_types;
}
/**
* Set values for predefined province in field
*
* @filter gform_predefined_choices
*
* @param array $choices
*
* @return array
*/
public function iran_provinces_choices( array $choices ): array {
$states['استان های ایران'] = $this->iran_provinces();
return array_merge( $states, $choices );
}
/**
* Add custom options to the address fields
*
* @action gform_field_standard_settings
*
* @param int $position
* @param string $form_id
*
* @return void
*/
public function custom_options( int $position, string $form_id ): void {
if ( $position == 25 ) { ?>
<li class="iran_cities field_setting">
<input type="checkbox" id="iran_cities"
onclick="SetFieldProperty('iran_cities', jQuery(this).is(':checked') ? 1 : 0);"/>
<label class="inline gfield_value_label" for="iran_cities">فعالسازی شهرهای ایران</label>
</li>
<li class="switch_state_city_position field_setting">
<input type="checkbox" id="switch_state_city_position"
onclick="SetFieldProperty('switch_state_city_position', jQuery(this).is(':checked') ? 1 : 0);"/>
<label class="inline gfield_value_label" for="switch_state_city_position">جابجایی فیلد شهر و استان</label>
</li>
<?php
}
}
/**
* Add iran cities to form edit field logic
*
* @action gform_editor_js
*
* @return void
*/
public function custom_options_editor_js(): void { ?>
<script type='text/javascript'>
jQuery(document).ready(function ($) {
fieldSettings["address"] += ", .iran_cities, .switch_state_city_position";
const field_address_type_el = $('#field_address_type');
$(document).bind("gform_load_field_settings", function (event, field, form) {
// Iran Cities option
const iran_cities_el = $("#iran_cities");
const iran_cities_container_el = $('#iran_cities_div');
iran_cities_el.attr("checked", field["iran_cities"] == true);
if (!iran_cities_container_el.length) {
let iran_cities = $(".iran_cities");
let iran_cities_input = iran_cities.html();
iran_cities.remove();
field_address_type_el.after('<div id="iran_cities_div"><br>' + iran_cities_input + '</div>');
}
// Switch state and city field option
const switch_state_city_position_el = $("#switch_state_city_position");
const switch_state_city_position_container_el = $('#switch_state_city_position_div');
switch_state_city_position_el.attr("checked", field["switch_state_city_position"] == true);
if (!switch_state_city_position_container_el.length) {
let switch_state_city_position = $(".switch_state_city_position");
let switch_state_city_position_input = switch_state_city_position.html();
switch_state_city_position.remove();
field_address_type_el.after('<div id="switch_state_city_position_div"><br>' + switch_state_city_position_input + '</div>');
}
// Conditional logic control of custom options
if (field_address_type_el.val() === 'iran') {
iran_cities_container_el.show();
switch_state_city_position_container_el.show();
} else {
iran_cities_container_el.hide();
switch_state_city_position_container_el.hide();
}
field_address_type_el.change(function () {
if ($(this).val() === 'iran') {
iran_cities_container_el.slideDown();
switch_state_city_position_container_el.slideDown();
} else {
iran_cities_container_el.slideUp();
switch_state_city_position_container_el.slideUp();
}
});
});
});
</script>
<?php
}
/**
* Add Iran cities list to address field
*
* @filter gform_field_content
*
* @param string $content The field content
* @param GF_Field|array $field The Field Object
* @param array|string $value The field value
* @param int $lead_id The entry ID
* @param string $form_id The form ID
*
* @return string
*
*/
public function iran_cities_field_type( string $content, $field, $value, int $lead_id, string $form_id ): string {
if ( ! $this->is_iran_cities( $field ) ) {
return $content;
}
$id = rgar( $field, 'id', 0 );
$id = absint( $id );
preg_match( '/<input.*?(name=["\']input_' . $id . '.3["\'].*?)\/??>/i', $content, $match );
if ( ! empty( $match[0] ) && ! empty( $match[1] ) ) {
$city_input = trim( $match[1] );
$city_input = str_ireplace( 'value=', 'data-selected=', $city_input );
$content = str_replace( $match[0], "<select {$city_input}><option value='' selected='selected'> </option></select>", $content );
}
return $content;
}
/**
* Add Iran city assets to the GForms address field presentation
*
* @action gform_enqueue_scripts
*
* @param array $form An array representing the current Form object.
* @param bool $ajax Whether this is being requested via AJAX.
*
* @return void
*/
public function external_js( array $form, bool $ajax ): void {
$fields = GFCommon::get_fields_by_type( $form, [ 'address' ] );
foreach ( $fields as $field ) {
if ( ! $this->is_iran_cities( $field ) ) {
continue;
}
wp_dequeue_script( 'gform_iran_cities' );
wp_deregister_script( 'gform_iran_cities' );
wp_register_script( 'gform_iran_cities', GF_PERSIAN_URL . 'assets/js/iran-cities-full' . GFPersian_Core::minified() . '.js', [], GF_PERSIAN_VERSION, false );
wp_enqueue_script( 'gform_iran_cities' );
}
}
/**
* Register Iran city input frontend logic when it presents
*
* @action gform_register_init_scripts
*
* @param array $form The Form object
*
* @return void
*/
public function init_script( array $form ): void {
foreach ( $form['fields'] as $field ) {
if ( ! $this->is_iran_cities( $field ) ) {
continue;
}
$id = $form['id'] . '_' . $field['id'];
$script = 'jQuery(document).ready(function($){' . '$(".has_city #input_' . $id . '_3").html(persian_gravity_form_iran_cities(""+$(".has_city #input_' . $id . '_4").val()));' . 'if ($(".has_city #input_' . $id . '_3").attr("data-selected")) {' . '$(".has_city #input_' . $id . '_3").val($(".has_city #input_' . $id . '_3").attr("data-selected"));' . '}' . '$(document.body).on("change autocomplete", ".has_city #input_' . $id . '_4" ,function(){' . '$(".has_city #input_' . $id . '_3").html(persian_gravity_form_iran_cities(""+$(".has_city #input_' . $id . '_4").val()));' . '}).on("change", ".has_city #input_' . $id . '_3" ,function(){' . '$(this).attr("data-selected", $(this).val());' . '})' . '});';
if ( $this->switch_state_city_position( $field ) ) {
$script .= 'jQuery(document).ready(function($){var $parent=$("#input_' . $id . '"),$city=$("#input_' . $id . '_3_container"),$state=$("#input_' . $id . '_4_container");if($parent.length&&$city.length&&$state.length){$state.insertBefore($city);}});';
}
GFFormDisplay::add_init_script( $form['id'], 'iran_address_city_' . $id, GFFormDisplay::ON_PAGE_RENDER, $script );
}
}
/**
* Check Iran cities option enabled
*
* @param GF_Field|array $field
*
* @return bool
*/
private function is_iran_cities( $field ): bool {
return $field['type'] == 'address' && $field['addressType'] == 'iran' && rgar( $field, 'iran_cities', false ) && ! is_admin();
}
/**
* Check state and city position switch enabled
*
* @param GF_Field|array $field
*
* @return bool
*/
private function switch_state_city_position( $field ): bool {
return $field['type'] == 'address' && rgar( $field, 'switch_state_city_position', false ) && ! is_admin();
}
}
new GFPersian_Adress();