晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
|
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/public_html/wp-content/plugins/wp-analytify/inc/ |
Upload File : |
<?php
/**
* Class for logging events and errors
*
* @package Analytify
* @subpackage Logging
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.2.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* Analytify_Logging Class
*
* A general use class for logging events and errors.
*
* @since 1.2.4
*/
class Analytify_Logging {
/**
* Set up the Analytify Logging Class
*
* @since 1.2.4
*/
public function __construct() {
// Create the log post type
add_action( 'init', array( $this, 'register_post_type' ), 1 );
// Create types taxonomy and default types
add_action( 'init', array( $this, 'register_taxonomy' ), 1 );
}
/**
* Registers the analytify_log Post Type
*
* @access public
* @since 1.2.4
* @return void
*/
public function register_post_type() {
/* Logs post type */
$log_args = array(
'labels' => array( 'name' => __( 'Logs', 'wp-analytify' ) ),
'public' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'show_ui' => false,
'query_var' => false,
'rewrite' => false,
'capability_type' => 'post',
'supports' => array( 'title', 'editor' ),
'can_export' => true,
);
register_post_type( 'analytify_log', $log_args );
}
/**
* Registers the Type Taxonomy
*
* The "Type" taxonomy is used to determine the type of log entry
*
* @access public
* @since 1.2.4
* @return void
*/
public function register_taxonomy() {
register_taxonomy( 'analytify_log_type', 'analytify_log', array( 'public' => false ) );
}
/**
* Log types
*
* Sets up the default log types and allows for new ones to be created
*
* @access public
* @since 1.2.4
* @return array $terms
*/
public function log_types() {
$terms = array(
'errors',
'messages',
);
return apply_filters( 'analytify_log_types', $terms );
}
/**
* Check if a log type is valid
*
* Checks to see if the specified type is in the registered list of types
*
* @access public
* @since 1.2.4
* @uses Analytify_Logging::log_types()
* @param string $type Log type
* @return bool Whether log type is valid
*/
function valid_type( $type ) {
return in_array( $type, $this->log_types() );
}
/**
* Create new log entry
*
* This is just a simple and fast way to log something. Use $this->insert_log()
* if you need to store custom meta data
*
* @access public
* @since 1.2.4
* @uses _Logging::insert_log()
* @param string $title Log entry title
* @param string $message Log entry message
* @param int $parent Log entry parent
* @param string $type Log type (default: null)
* @return int Log ID
*/
public function add( $title = '', $message = '', $parent = 0, $type = null ) {
$log_data = array(
'post_title' => $title,
'post_content' => $message,
'post_parent' => $parent,
'log_type' => $type,
);
return $this->insert_log( $log_data );
}
/**
* Easily retrieves log items for a particular object ID
*
* @access public
* @since 1.2.4
* @uses Analytify_Logging::get_connected_logs()
* @param int $object_id (default: 0)
* @param string $type Log type (default: null)
* @param int $paged Page number (default: null)
* @return array Array of the connected logs
*/
public function get_logs( $object_id = 0, $type = null, $paged = null ) {
return $this->get_connected_logs( array( 'post_parent' => $object_id, 'paged' => $paged, 'log_type' => $type ) );
}
/**
* Stores a log entry
*
* @access public
* @since 1.2.4
* @uses Analytify_Logging::valid_type()
* @param array $log_data Log entry data
* @param array $log_meta Log entry meta
* @return int The ID of the newly created log item
*/
function insert_log( $log_data = array(), $log_meta = array() ) {
$defaults = array(
'post_type' => 'analytify_log',
'post_status' => 'publish',
'post_parent' => 0,
'post_content' => '',
'log_type' => false,
);
$args = wp_parse_args( $log_data, $defaults );
// print_r($args);
do_action( 'analytify_pre_insert_log', $log_data, $log_meta );
// Store the log entry
$log_id = wp_insert_post( $args );
// Set the log type, if any
if ( $log_data['log_type'] && $this->valid_type( $log_data['log_type'] ) ) {
wp_set_object_terms( $log_id, $log_data['log_type'], 'analytify_log_type', false );
}
// Set log meta, if any
if ( $log_id && ! empty( $log_meta ) ) {
foreach ( (array) $log_meta as $key => $meta ) {
update_post_meta( $log_id, '_analytify_log_' . sanitize_key( $key ), $meta );
}
}
do_action( 'analytify_post_insert_log', $log_id, $log_data, $log_meta );
// print_r($log_id);
return $log_id;
}
/**
* Update and existing log item
*
* @access public
* @since 1.2.4
* @param array $log_data Log entry data
* @param array $log_meta Log entry meta
* @return bool True if successful, false otherwise
*/
public function update_log( $log_data = array(), $log_meta = array() ) {
do_action( 'analytify_pre_update_log', $log_data, $log_meta );
$defaults = array(
'post_type' => 'analytify_log',
'post_status' => 'publish',
'post_parent' => 0,
);
$args = wp_parse_args( $log_data, $defaults );
// Store the log entry
$log_id = wp_update_post( $args );
if ( $log_id && ! empty( $log_meta ) ) {
foreach ( (array) $log_meta as $key => $meta ) {
if ( ! empty( $meta ) ) {
update_post_meta( $log_id, '_analytify_log_' . sanitize_key( $key ), $meta ); }
}
}
do_action( 'analytify_post_update_log', $log_id, $log_data, $log_meta );
}
/**
* Retrieve all connected logs
*
* Used for retrieving logs related to particular items, such as a specific purchase.
*
* @access private
* @since 1.2.4
* @param array $args Query arguments
* @return mixed array if logs were found, false otherwise
*/
public function get_connected_logs( $args = array() ) {
$defaults = array(
'post_type' => 'analytify_log',
'posts_per_page' => 20,
'post_status' => 'publish',
'paged' => get_query_var( 'paged' ),
'log_type' => false,
);
$query_args = wp_parse_args( $args, $defaults );
if ( $query_args['log_type'] && $this->valid_type( $query_args['log_type'] ) ) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'analytify_log_type',
'field' => 'slug',
'terms' => $query_args['log_type'],
),
);
}
$logs = get_posts( $query_args );
if ( $logs ) {
return $logs; }
// No logs found
return false;
}
/**
* Retrieves number of log entries connected to particular object ID
*
* @access public
* @since 1.2.4
* @param int $object_id (default: 0)
* @param string $type Log type (default: null)
* @param array $meta_query Log meta query (default: null)
* @param array $date_query Log data query (default: null) (since 1.9)
* @return int Log count
*/
public function get_log_count( $object_id = 0, $type = null, $meta_query = null, $date_query = null ) {
global $pagenow, $typenow;
$query_args = array(
'post_parent' => $object_id,
'post_type' => 'analytify_log',
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids',
);
if ( ! empty( $type ) && $this->valid_type( $type ) ) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'analytify_log_type',
'field' => 'slug',
'terms' => $type,
),
);
}
if ( ! empty( $meta_query ) ) {
$query_args['meta_query'] = $meta_query;
}
if ( ! empty( $date_query ) ) {
$query_args['date_query'] = $date_query;
}
$logs = new WP_Query( $query_args );
return (int) $logs->post_count;
}
/**
* Delete a log
*
* @access public
* @since 1.2.4
* @uses Analytify_Logging::valid_type
* @param int $object_id (default: 0)
* @param string $type Log type (default: null)
* @param array $meta_query Log meta query (default: null)
* @return void
*/
public function delete_logs( $object_id = 0, $type = null, $meta_query = null ) {
$query_args = array(
'post_parent' => $object_id,
'post_type' => 'analytify_log',
'posts_per_page' => -1,
'post_status' => 'publish',
'fields' => 'ids',
);
if ( ! empty( $type ) && $this->valid_type( $type ) ) {
$query_args['tax_query'] = array(
array(
'taxonomy' => 'analytify_log_type',
'field' => 'slug',
'terms' => $type,
),
);
}
if ( ! empty( $meta_query ) ) {
$query_args['meta_query'] = $meta_query;
}
$logs = get_posts( $query_args );
if ( $logs ) {
foreach ( $logs as $log ) {
wp_delete_post( $log, true );
}
}
}
}
// Initiate the logging system
$GLOBALS['analytify_logs'] = new Analytify_Logging();
/**
* Record a log entry
*
* This is just a simple wrapper function for the log class add() function
*
* @since 1.3.3
*
* @param string $title
* @param string $message
* @param int $parent
* @param null $type
*
* @global $analytify_logs Analytify Logs Object
*
* @uses Analytify_Logging::add()
*
* @return mixed ID of the new log entry
*/
function analytify_record_log( $title = '', $message = '', $parent = 0, $type = null ) {
global $analytify_logs;
$log = $analytify_logs->add( $title, $message, $parent, $type );
return $log;
}