HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/wpforms-user-journey/src/Loader.php
<?php

namespace WPFormsUserJourney;

use WPForms_Updater;
use WPFormsUserJourney\Integrations\Zapier;

/**
 * WPForms User Journey loader class.
 *
 * @since 1.0.0
 */
final class Loader {
	/**
	 * Storage name.
	 *
	 * @since 1.6.0
	 */
	public const STORAGE_NAME = '_wpfuj';

	/**
	 * Cleanup cookie name.
	 *
	 * @since 1.6.0
	 */
	public const CLEANUP_COOKIE_NAME = '_wpfuj_cleanup';

	/**
	 * Max local storage size.
	 *
	 * @since 1.6.0
	 */
	public const MAX_LOCAL_STORAGE_SIZE = 5 * MB_IN_BYTES;

	/**
	 * Approximate max data items to fit in local storage, assuming that the average item size is 100 bytes.
	 *
	 * @since 1.6.0
	 */
	public const MAX_LOCAL_STORAGE_ITEMS = self::MAX_LOCAL_STORAGE_SIZE / 100;

	/**
	 * Database class.
	 *
	 * @since 1.0.0
	 *
	 * @var DB
	 */
	public $db;

	/**
	 * View class.
	 *
	 * @since 1.0.3
	 *
	 * @var View
	 */
	public $view;

	/**
	 * URL to a plugin directory. Used for assets.
	 *
	 * @since 1.0.0
	 *
	 * @var string
	 */
	public $url = '';

	/**
	 * Initiate the main plugin instance.
	 *
	 * @since 1.0.0
	 *
	 * @return Loader
	 */
	public static function get_instance(): Loader {

		static $instance;

		if ( ! $instance ) {
			$instance = new self();

			$instance->init();
		}

		return $instance;
	}

	/**
	 * Init the Loader.
	 *
	 * @since 1.0.0
	 *
	 * @return Loader
	 */
	public function init(): Loader {

		$this->url = plugin_dir_url( __DIR__ );

		$this->setup();
		$this->hooks();

		return $this;
	}

	/**
	 * Plugin hooks.
	 *
	 * @since 1.0.0
	 */
	private function hooks(): void {

		add_filter( 'wpforms_helpers_templates_get_theme_template_paths', [ $this, 'register_template_path' ], 100 );
	}

	/**
	 * All the actual plugin loading is done here.
	 *
	 * @since 1.0.0
	 */
	private function setup(): void {

		$this->load_database();
		$this->load_admin_entries();
		$this->load_admin_export();
		$this->load_admin_form();
		$this->load_frontend();
		$this->load_view();
		$this->load_smart_tags();
		$this->load_processing();
		$this->load_integrations();
	}

	/**
	 * Add a template path for working of the wpforms_render function.
	 *
	 * @since 1.0.0
	 *
	 * @param array|mixed $paths List of paths.
	 *
	 * @return array
	 */
	public function register_template_path( $paths ): array {

		$paths = (array) $paths;

		$paths[] = WPFORMS_USER_JOURNEY_PATH . 'templates';

		return $paths;
	}

	/**
	 * Load database functionality.
	 *
	 * @since 1.0.0
	 */
	private function load_database(): void {

		$this->db = new DB();
	}

	/**
	 * Load admin entries functionality.
	 *
	 * @since 1.0.0
	 */
	private function load_admin_entries(): void {

		if ( wpforms_is_admin_page( 'entries' ) ) {
			( new Admin\Entries() )->init();
		}
	}

	/**
	 * Load admin export functionality.
	 *
	 * @since 1.4.0
	 */
	private function load_admin_export(): void {

		if (
			wpforms_is_admin_page( 'tools', 'export' ) ||
			wpforms_is_ajax( 'wpforms_tools_entries_export_step' )
		) {
			( new Admin\Export() )->init();
		}
	}

	/**
	 * Load admin form functionality.
	 *
	 * @since 1.0.0
	 */
	private function load_admin_form(): void {

		if ( wpforms_is_admin_page() ) {
			( new Admin\Form() )->init();
		}
	}

	/**
	 * Load frontend functionality.
	 *
	 * @since 1.0.0
	 */
	private function load_frontend(): void {

		if ( ! is_admin() ) {
			( new Frontend() )->init();
		}
	}

	/**
	 * Load view.
	 *
	 * @since 1.0.3
	 */
	private function load_view(): void {

		$this->view = new View();
	}

	/**
	 * Load smart tags.
	 *
	 * @since 1.0.3
	 */
	private function load_smart_tags(): void {

		( new SmartTags() )->init();
	}

	/**
	 * Load form processing.
	 *
	 * @since 1.0.0
	 */
	private function load_processing(): void {

		if ( ! is_admin() || wpforms_is_frontend_ajax() ) {
			( new Process() )->init();
		}
	}

	/**
	 * Load integrations.
	 *
	 * @since 1.5.0
	 */
	private function load_integrations(): void {

		$this->load_zapier();
	}

	/**
	 * Load Zapier integration.
	 *
	 * @since 1.5.0
	 */
	private function load_zapier(): void {

		// Check if Zapier is active.
		if ( ! function_exists( 'wpforms_zapier_load' ) ) {
			return;
		}

		( new Zapier() )->init( $this->view, $this->db );
	}

	/**
	 * Load the plugin updater.
	 *
	 * @since .0.0
	 * @deprecated 1.4.0
	 *
	 * @todo Remove with core 1.9.2
	 *
	 * @param string $key License key.
	 *
	 * @noinspection ReturnTypeCanBeDeclaredInspection
	 * @noinspection PhpMissingParamTypeInspection
	 */
	public function updater( $key ) {

		_deprecated_function( __METHOD__, '1.4.0 of the WPForms User Journey plugin' );

		new WPForms_Updater(
			[
				'plugin_name' => 'WPForms User Journey',
				'plugin_slug' => 'wpforms-user-journey',
				'plugin_path' => plugin_basename( WPFORMS_USER_JOURNEY_FILE ),
				'plugin_url'  => trailingslashit( $this->url ),
				'remote_url'  => WPFORMS_UPDATER_API,
				'version'     => WPFORMS_USER_JOURNEY_VERSION,
				'key'         => $key,
			]
		);
	}

	/**
	 * Get max data size for user journey tracking.
	 *
	 * @since 1.6.0
	 *
	 * @return int
	 */
	public function get_max_data_size(): int {
		/**
		 * Filter the max data size for user journey tracking.
		 *
		 * @since 1.6.0
		 *
		 * @param int $max_data_size Max data size.
		 */
		$max_data_size = (int) apply_filters( 'wpforms_user_journey_loader_max_data_size', 10 * KB_IN_BYTES );
		$max_data_size = max( 0, $max_data_size );

		return min( $max_data_size, self::MAX_LOCAL_STORAGE_SIZE );
	}

	/**
	 * Get max data items for user journey tracking.
	 *
	 * @since 1.6.0
	 *
	 * @return int
	 */
	public function get_max_data_items(): int {
		/**
		 * Filter the max data items for user journey tracking.
		 *
		 * @since 1.6.0
		 *
		 * @param int $max_data_items Max data items.
		 */
		$max_data_items = (int) apply_filters( 'wpforms_user_journey_loader_max_data_items', 100 );
		$max_data_items = max( 0, $max_data_items );

		return min( $max_data_items, self::MAX_LOCAL_STORAGE_ITEMS );
	}
}