晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/home/salvufkx/www/wp-contentmmm/plugins/hello-plus/includes/ |
| Current File : //home/salvufkx/www/wp-contentmmm/plugins/hello-plus/includes/utils.php |
<?php
namespace HelloPlus\Includes;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
/**
* class Utils
**/
class Utils {
public static function elementor(): ?\Elementor\Plugin {
return class_exists( '\Elementor\Plugin' ) ? \Elementor\Plugin::instance() : null;
}
public static function has_pro(): bool {
return defined( 'ELEMENTOR_PRO_VERSION' );
}
public static function are_we_on_elementor_domains(): bool {
$current_domain = filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL );
$allowed_domains = [
'elementor.com',
'elementor.red',
];
$is_elementor_domain = false;
foreach ( $allowed_domains as $domain ) {
if ( str_ends_with( $current_domain, $domain ) ) {
$is_elementor_domain = true;
break;
}
}
return $is_elementor_domain;
}
public static function has_hello_biz(): bool {
if ( defined( 'WP_TESTS_DOMAIN' ) ) {
return true;
}
if ( self::are_we_on_elementor_domains() ) {
return true;
}
return defined( 'EHP_THEME_SLUG' );
}
public static function has_hello_elementor_theme(): bool {
return defined( 'EHP_THEME_SLUG' ) && ( 'hello-elementor' === EHP_THEME_SLUG );
}
public static function is_elementor_active(): bool {
static $elementor_active = null;
if ( is_null( $elementor_active ) ) {
$elementor_active = defined( 'ELEMENTOR_VERSION' );
}
return $elementor_active;
}
public static function is_elementor_installed(): bool {
static $elementor_installed = null;
if ( is_null( $elementor_installed ) ) {
$elementor_installed = file_exists( WP_PLUGIN_DIR . '/elementor/elementor.php' );
}
return $elementor_installed;
}
public static function get_current_post_id(): int {
if ( self::elementor() && isset( self::elementor()->documents ) && self::elementor()->documents->get_current() ) {
return self::elementor()->documents->get_current()->get_main_id();
}
return get_the_ID();
}
public static function get_update_elementor_message(): string {
return sprintf(
/* translators: %s: Elementor version number. */
__( 'Elementor plugin version needs to be at least %s for Hello Plus to Work. Please update.', 'hello-plus' ),
HELLOPLUS_MIN_ELEMENTOR_VERSION,
);
}
public static function get_client_ip(): string {
$server_ip_keys = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR',
];
foreach ( $server_ip_keys as $key ) {
$value = filter_input( INPUT_SERVER, $key, FILTER_VALIDATE_IP );
if ( $value ) {
return $value;
}
}
return '127.0.0.1';
}
public static function ends_with( $full_string, $end_string ): bool {
$len = strlen( $end_string );
if ( 0 === $len ) {
return true;
}
return ( substr( $full_string, -$len ) === $end_string );
}
public static function get_theme_slug(): string {
if ( defined( 'EHP_THEME_SLUG' ) ) {
return EHP_THEME_SLUG;
}
return 'hello-plus';
}
public static function get_theme_admin_home(): string {
if ( defined( 'EHP_THEME_SLUG' ) ) {
return add_query_arg( [ 'page' => EHP_THEME_SLUG ], self_admin_url( 'edit.php' ) );
}
return self_admin_url();
}
public static function is_preview_for_document( $post_id ): bool {
$preview_id = filter_input( INPUT_GET, 'preview_id', FILTER_VALIDATE_INT );
$preview = filter_input( INPUT_GET, 'preview', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
return 'true' === $preview && (int) $post_id === (int) $preview_id;
}
public static function is_installed_elementor_version_supported(): bool {
$plugin_file = WP_PLUGIN_DIR . '/elementor/elementor.php';
if ( ! file_exists( $plugin_file ) ) {
return true;
}
require_once ABSPATH . 'wp-admin/includes/plugin.php';
$plugin_data = get_plugin_data( $plugin_file );
$plugin_version = $plugin_data['Version'];
return self::is_elementor_version_supported( $plugin_version );
}
public static function is_active_elementor_version_supported(): bool {
return self::is_elementor_version_supported( ELEMENTOR_VERSION );
}
public static function is_elementor_version_supported( string $version ): bool {
return version_compare( $version, HELLOPLUS_MIN_ELEMENTOR_VERSION, 'ge' );
}
public static function plugin_title(): string {
return __( 'Hello+', 'hello-plus' );
}
public static function are_submissions_enabled(): bool {
return static::has_pro() &&
class_exists( '\ElementorPro\Modules\Forms\Submissions\Actions\Save_To_Database' ) &&
class_exists( '\ElementorPro\License\API' ) &&
class_exists( '\ElementorPro\Modules\Forms\Submissions\Component' ) &&
self::is_licence_has_feature_compatible(
\ElementorPro\Modules\Forms\Submissions\Component::NAME
);
}
private static function is_licence_has_feature_compatible( $feature ) {
$method = new \ReflectionMethod(
\ElementorPro\License\API::class, 'is_licence_has_feature'
);
$num_params = $method->getNumberOfParameters();
if ( $num_params > 1 ) {
return \ElementorPro\License\API::is_licence_has_feature(
$feature,
\ElementorPro\License\API::BC_VALIDATION_CALLBACK
);
} else {
return \ElementorPro\License\API::is_licence_has_feature(
$feature
);
}
}
public static function get_widgets_depends(): array {
return [ 'helloplus-button', 'helloplus-image', 'helloplus-shapes', 'helloplus-column-structure' ];
}
public static function maybe_has_pro_location_docs( string $location = '' ): array {
if ( ! self::has_pro() ) {
return [];
}
$theme_builder_module = \ElementorPro\Modules\ThemeBuilder\Module::instance();
$conditions_manager = $theme_builder_module->get_conditions_manager();
return $conditions_manager->get_documents_for_location( $location );
}
public static function get_pro_part( string $part = '' ) {
if ( ! self::has_pro() ) {
return false;
}
$pro_part = self::maybe_has_pro_location_docs( $part );
$first_pro_part_id = array_key_first( $pro_part );
return ! empty( $first_pro_part_id ) ? $first_pro_part_id : false;
}
public static function is_test_environment(): bool {
if ( defined( 'WP_TESTS_DOMAIN' ) ) {
return true;
}
if ( getenv( 'TEST_PARALLEL_INDEX' ) !== false ) {
return true;
}
$wp_env = getenv( 'WP_ENV' );
if ( $wp_env && in_array( strtolower( $wp_env ), [ 'test', 'testing', 'playwright' ], true ) ) {
return true;
}
if ( defined( 'WP_TESTS_CONFIG_FILE_PATH' ) || defined( 'WP_PHPUNIT__TESTS_CONFIG' ) ) {
return true;
}
if (
defined( 'WP_DEBUG' ) &&
defined( 'WP_DEBUG_LOG' ) &&
filter_input( INPUT_SERVER, 'HTTP_HOST', FILTER_SANITIZE_URL ) === 'localhost:8888'
) {
return true;
}
return false;
}
}
|