晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/tabatabaei/.trash/wp-content.1/plugins/demo-import-kit/inc/ |
Upload File : |
<?php
/**
* Class for the customizer importer used in the Demo Import Kit plugin.
*
* Code is mostly from the Customizer Export/Import plugin.
*
* @see https://wordpress.org/plugins/customizer-export-import/
* @package demo-import-kit
*/
// Block direct access to the main plugin file.
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class DIK_Customizer_Importer {
/**
* Imports uploaded mods and calls WordPress core customize_save actions so
* themes that hook into them can act before mods are saved to the database.
*
* Update: WP core customize_save actions were removed, because of some errors.
*
* @since 1.0.1
* @param string $import_file_path Path to the import file.
* @return void|WP_Error
*/
public static function import_customizer_options( $import_file_path ) {
// Setup global vars.
global $wp_customize;
// Setup internal vars.
$template = get_template();
// Make sure we have an import file.
if ( ! file_exists( $import_file_path ) ) {
return new WP_Error(
'missing_cutomizer_import_file',
sprintf(
esc_html__( 'The customizer import file is missing! File path: %s', 'demo-import-kit' ),
$import_file_path
)
);
}
// Get the upload data.
$raw = Demo_Import_Kit_Base_Class::data_from_file( $import_file_path );
// Make sure we got the data.
if ( is_wp_error( $raw ) ) {
return $raw;
}
$data = unserialize( $raw );
// Data checks.
if ( ! is_array( $data ) && ( ! isset( $data['template'] ) || ! isset( $data['mods'] ) ) ) {
return new WP_Error(
'customizer_import_data_error',
esc_html__( 'No correct file format. Please make sure to use the correct customizer import file.', 'demo-import-kit' )
);
}
if ( $data['template'] !== $template ) {
return new WP_Error(
'customizer_import_wrong_theme',
esc_html__( 'The customizer import file is not suitable for current theme. You can only import customizer settings for the same theme or a child theme.', 'demo-import-kit' )
);
}
// Import images.
if ( apply_filters( 'dik/customizer_import_images', true ) ) {
$data['mods'] = self::import_customizer_images( $data['mods'] );
}
// Import custom options.
if ( isset( $data['options'] ) ) {
// Require modified customizer options class.
if ( ! class_exists( 'WP_Customize_Setting' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-customize-setting.php';
}
require DIK_PATH . 'inc/customizer-option.php';
foreach ( $data['options'] as $option_key => $option_value ) {
$option = new DIK_Customizer_Option( $wp_customize, $option_key, array(
'default' => '',
'type' => 'option',
'capability' => 'edit_theme_options',
) );
$option->import( $option_value );
}
}
// Loop through the mods.
foreach ( $data['mods'] as $key => $val ) {
// Save the mod.
set_theme_mod( $key, $val );
}
}
/**
* Helper function: Customizer import - imports images for settings saved as mods.
*
* @since 1.0.1
* @param array $mods An array of customizer mods.
* @return array The mods array with any new import data.
*/
private static function import_customizer_images( $mods ) {
foreach ( $mods as $key => $val ) {
if ( self::customizer_is_image_url( $val ) ) {
$data = self::customizer_sideload_image( $val );
if ( ! is_wp_error( $data ) ) {
$mods[ $key ] = $data->url;
// Handle header image controls.
if ( isset( $mods[ $key . '_data' ] ) ) {
$mods[ $key . '_data' ] = $data;
update_post_meta( $data->attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
}
}
}
}
return $mods;
}
/**
* Helper function: Customizer import
* Taken from the core media_sideload_image function and
* modified to return an array of data instead of html.
*
* @since 1.0.1.
* @param string $file The image file path.
* @return array An array of image data.
*/
private static function customizer_sideload_image( $file ) {
$data = new stdClass();
if ( ! function_exists( 'media_handle_sideload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/media.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
}
if ( ! empty( $file ) ) {
// Set variables for storage, fix file filename for query strings.
preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
$file_array = array();
$file_array['name'] = basename( $matches[0] );
// Download file to temp location.
$file_array['tmp_name'] = download_url( $file );
// If error storing temporarily, return the error.
if ( is_wp_error( $file_array['tmp_name'] ) ) {
return $file_array['tmp_name'];
}
// Do the validation and storage stuff.
$id = media_handle_sideload( $file_array, 0 );
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) {
unlink( $file_array['tmp_name'] );
return $id;
}
// Build the object to return.
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
$data->height = $meta['height'];
$data->width = $meta['width'];
}
return $data;
}
/**
* Checks to see whether a string is an image url or not.
*
* @since 1.0.1
* @param string $string The string to check.
* @return bool Whether the string is an image url or not.
*/
private static function customizer_is_image_url( $string = '' ) {
if ( is_string( $string ) ) {
if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
return true;
}
}
return false;
}
}