HEX
Server: LiteSpeed
System: Linux cde4.duelhost.dk 4.18.0-553.34.1.lve.el8.x86_64 #1 SMP Thu Jan 9 16:30:32 UTC 2025 x86_64
User: xluilhul (1144)
PHP: 8.2.30
Disabled: exec,system,passthru,shell_exec,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/xluilhul/public_html/wp-content/plugins/elementor-pro/core/editor/editor.php
<?php
namespace ElementorPro\Core\Editor;

use Elementor\Core\Base\App;
use Elementor\Core\Utils\Assets_Config_Provider;
use Elementor\Core\Utils\Assets_Translation_Loader;
use ElementorPro\License\Admin as License_Admin;
use ElementorPro\License\API as License_API;
use ElementorPro\Plugin;
use ElementorPro\Modules\DisplayConditions\Module as Display_Conditions_Module;
use Elementor\Modules\AtomicWidgets\Module as AtomicWidgetsModule;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

class Editor extends App {
	const APP_BAR_DEPS_V2 = [
		'editor-site-navigation-extended',
		'editor-documents-extended',
		'license-api',
	];
	const EDITOR_V4_PACKAGES = [
		'editor-controls-extended',
		'editor-editing-panel-extended',
		'editor-components-extended',
		'core-adapter-utils',
		'editor-templates-extended',
		'editor-canvas-extended',
	];

	/**
	 * Get app name.
	 *
	 * Retrieve the app name.
	 *
	 * @return string app name.
	 * @since  2.6.0
	 * @access public
	 *
	 */
	public function get_name() {
		return 'pro-editor';
	}

	public function __construct() {
		add_action( 'elementor/init', [ $this, 'on_elementor_init' ] );
		add_action( 'elementor/editor/init', [ $this, 'on_elementor_editor_init' ] );
		add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_editor_styles' ] );
		add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_editor_scripts' ] );
		add_filter( 'elementor/editor/localize_settings', [ $this, 'localize_settings' ] );

		add_action( 'elementor/editor/v2/scripts/enqueue', function () {
			$this->enqueue_editor_v2_scripts();
		} );
	}

	public function get_init_settings() {
		$settings = [
			'version' => ELEMENTOR_PRO_VERSION,
			'isActive' => License_API::is_license_active(),
			'urls' => [
				'modules' => ELEMENTOR_PRO_MODULES_URL,
				'connect' => License_Admin::get_url(),
			],
		];

		/**
		 * Localized editor settings.
		 *
		 * Filters the localized settings used in the editor as JavaScript variables.
		 *
		 * By default Elementor Pro passes some editor settings to be consumed as JavaScript
		 * variables. This hook allows developers to add extra settings values to be consumed
		 * using JavaScript in the editor.
		 *
		 * @since 1.0.0
		 *
		 * @param array $settings Localized editor settings.
		 */
		$settings = apply_filters( 'elementor_pro/editor/localize_settings', $settings );

		return $settings;
	}

	public function enqueue_editor_styles() {
		wp_enqueue_style(
			'elementor-pro',
			$this->get_css_assets_url( 'editor' ),
			[
				'elementor-editor',
			],
			ELEMENTOR_PRO_VERSION
		);
	}

	public function enqueue_editor_scripts() {
		wp_enqueue_script(
			'elementor-pro',
			$this->get_js_assets_url( 'editor' ),
			[
				'backbone-marionette',
				'elementor-common',
				'elementor-editor-modules',
				'elementor-editor-document',
			],
			ELEMENTOR_PRO_VERSION,
			true
		);

		wp_set_script_translations( 'elementor-pro', 'elementor-pro' );

		$this->print_config( 'elementor-pro' );
	}

	public function enqueue_editor_v2_scripts() {
		$assets_config = ( new Assets_Config_Provider() )
			->set_path_resolver( function ( $name ) {
				return ELEMENTOR_PRO_ASSETS_PATH . "js/packages/{$name}/{$name}.asset.php";
			} );

		$packages_to_load = array_merge( self::APP_BAR_DEPS_V2 );

		if ( Plugin::elementor()->experiments->is_feature_active( AtomicWidgetsModule::EXPERIMENT_NAME ) ) {
			$packages_to_load = array_merge( $packages_to_load, self::EDITOR_V4_PACKAGES );
		}

		$packages = apply_filters( 'elementor-pro/editor/v2/packages', $packages_to_load );

		foreach ( $packages as $package ) {
			$assets_config->load( $package );
		}

		foreach ( $assets_config->all() as $package => $config ) {
			$deps = $this->filter_version_gated_dependencies( $config['deps'] );

			wp_enqueue_script(
				$config['handle'],
				$this->get_js_assets_url( "packages/{$package}/{$package}" ),
				$deps,
				ELEMENTOR_PRO_VERSION,
				true
			);

			wp_set_script_translations( $config['handle'], 'elementor-pro' );
		}

		if ( class_exists( Assets_Translation_Loader::class ) ) {
			$packages_handles = $assets_config->pluck( 'handle' )->all();

			Assets_Translation_Loader::for_handles( $packages_handles );
		}
	}

	public function localize_settings( array $settings ) {
		$settings['elementPromotionURL'] = Plugin::instance()->license_admin->get_connect_url([
			'utm_source' => '%s', // Will be replaced in the frontend to the widget name
			'utm_medium' => 'wp-dash',
			'utm_campaign' => 'connect-and-activate-license',
			'utm_content' => 'editor-widget-promotion',
		]);

		$settings['dynamicPromotionURL'] = Plugin::instance()->license_admin->get_connect_url( [
			'utm_source' => '%s', // Will be replaced in the frontend to the control name
			'utm_medium' => 'wp-dash',
			'utm_campaign' => 'connect-and-activate-license',
			'utm_content' => 'editor-dynamic-promotion',
		] );

		if ( ! isset( $settings['promotionWidgets'] ) ) {
			$settings['promotionWidgets'] = License_API::get_promotion_widgets();
		}

		if ( Display_Conditions_Module::can_use_display_conditions() ) {
			$settings['displayConditions'] = Display_Conditions_Module::instance()
				->get_conditions_manager()
				->get_conditions_config();
		}

		return $settings;
	}

	public function on_elementor_init() {
		Plugin::elementor()->editor->notice_bar = new Notice_Bar();

		if ( isset( Plugin::elementor()->editor->promotion ) ) {
			Plugin::elementor()->editor->promotion = new Promotion();
		}
	}

	public function on_elementor_editor_init() {
		Plugin::elementor()->common->add_template( __DIR__ . '/template.php' );
	}

	protected function get_assets_base_url() {
		return ELEMENTOR_PRO_URL;
	}

	/**
	 * Map of `@elementor/*` package names to the minimum Elementor Core version
	 * in which the corresponding script handle is registered.
	 *
	 * Keys use the original npm package name (`@elementor/<name>`) so it stays
	 * grep-able against actual `import` statements in the Pro packages. They are
	 * converted to script handles (`elementor-v2-<name>`) at filter time
	 *
	 * NOTE: When adding an entry here, make sure every usage of the package in Pro
	 * source code is guarded by a runtime version check (see e.g.
	 * `isCoreWithEmbeddedDocumentsManager()` in `editor-templates-extended`).
	 */
	const VERSION_GATED_CORE_PACKAGES = [
		'@elementor/editor-embedded-documents-manager' => '4.2.0',
	];

	/**
	 * Filter out gated dependencies that are not available in the current Elementor version.
	 *
	 * @return array The filtered dependencies array.
	 */
	private function filter_version_gated_dependencies( array $deps ): array {
		$gated_handles = [];

		foreach ( self::VERSION_GATED_CORE_PACKAGES as $package => $min_version ) {
			$gated_handles[ self::package_name_to_script_handle( $package ) ] = $min_version;
		}

		return array_filter( $deps, function ( $dep ) use ( $gated_handles ) {
			if ( ! isset( $gated_handles[ $dep ] ) ) {
				return true;
			}

			return version_compare( ELEMENTOR_VERSION, $gated_handles[ $dep ], '>=' );
		} );
	}

	private static function package_name_to_script_handle( string $package_name ): string {
		$prefix = '@elementor/';

		if ( 0 !== strpos( $package_name, $prefix ) ) {
			return $package_name;
		}

		return 'elementor-v2-' . substr( $package_name, strlen( $prefix ) );
	}
}