JFIF    $         d d  7    * Z qn )ZP 0   !1 A "#a$2Qr   D8 a Ri [f  \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H  ~ , l s / 9  ć: [=/#f ; ) x { ٛE Q )~     = 𘙲r*2~  a _V = '  ku m F  D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq  1dđ #̩ ͑ 0  ; H ] u 搂 @:~ ו K L  N s h } O I R* 8 :2 ! lD JV o (  3 = M ( z Ȱ+i *N A  r6K n S l ) ! J J Ӂ* %  ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c  P A\IL Nj! J ۱+ O\ ͔ ] ޒ S߼ J ȧ c%A N ol  ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f  h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0  'G=i 2N +0 e 2 ]] 9 VT P  O׮ 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P  < 0 x <     !1AQ "Raq 02Br #S CTb  ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV׸ YT D I 6 2 '8Y2  7'\T P.6 d &˦ @V q i  |8 -O Ε  ] ʔ U=   T L 8= ;6c |  !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U# 6w +  +s &r+n ڐ   { @ 29 gL u " T Ù  M=6  (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 !  OS  r D  5 7 % | ?x> L |  / nD 6?/8 w # [ ) L 7 +6〼T A T g   !  %5  Mm Z /c  -{1_Je "| ^$ 'O  & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@  u6  BԒ  i YN * f 0 _ GhKW u  lT <nj- 0{  M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q  $ H8o Q˼EV ~ k 0 h' L  Pp M -M"  m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @񄞅~p   #   !1QAa q  ? AL0L  x LU 4 d ; x   " 16ad0 7.\ߋ 0  = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X  &Q  З non]я u ג./ ; gZ$ M QР 2M ]h ni 0  P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _  1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3  6 #Ik+ v  {ƒ v i ( ވ  ? a e)  X xy/*@Q Ǽ Ծ ) $ IWO l c G;  !i  k{ gOŀ L ('x  T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ)  X 5 c QɎMy W ?  Q *!R > 6=7)Xj 5`J ] e  8%t ! + ' ! 1Q 5   !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $  v , ,m   㵜5u bV  =sY+ @d { N ! dn O < .- B;  _w J t 6;Q  Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш  e黅X ۢ F :)[ F G X ƹ / w _c MeD   ,ʡc c .  W D  tA $ j@ : ) - # u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P  6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L !  ~ y5 g9T̅J kbM' +s :S +B) v @ M  j e C f j E 0  Y\Qn z G 1 д~ W o{T 9?`  Rm yhsy3 !HAD ] m  c1 ~ 2 L  S u7x T ;j$ `} 4-> L#  vzŏ I L S  ֭  T { r  jGK C ; b  pU= - ` Bs K. S F w4  M q] Z dH S 0 ) tLg Tiny File Manager | class-integrations.php
  • File: class-integrations.php
  • Full Path: /home/mata8712/public_html/on-me-trouve/wp-content/plugins/burst-statistics/includes/Integrations/class-integrations.php
  • File size: 9.12 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php
namespace Burst\Integrations;

defined( 'ABSPATH' ) || die( 'you do not have access to this page!' );

use Burst\Traits\Admin_Helper;

class Integrations {
	use Admin_Helper;

	public array $integrations              = [];
	public ?bool $should_load_ecommerce     = null;
	public ?bool $should_load_subscriptions = null;
	/**
	 * Constructor
	 */
	public function init(): void {
		$this->integrations = apply_filters( 'burst_integrations', $this->default_integrations() );

		add_action( 'init', [ $this, 'load_translations' ] );

		// We can load integrations here directly, because our main plugin file instantiating this on plugins_loaded hook with priority 9.
		$this->load_integrations();
		$this->register_for_consent_api();
	}

	/**
	 * Determine if ecommerce features should be loaded based on active integrations.
	 *
	 * @return bool True if any active integration requires ecommerce features.
	 */
	public function should_load_ecommerce(): bool {
		if ( $this->should_load_ecommerce !== null ) {
			return $this->should_load_ecommerce;
		}

		if ( $this->is_mainwp_request() ) {
			$this->should_load_ecommerce = true;
			return $this->should_load_ecommerce;
		}

		$this->should_load_ecommerce = false;
		foreach ( $this->integrations as $plugin => $details ) {
			if ( isset( $details['load_ecommerce_integration'] ) && $details['load_ecommerce_integration'] && $this->plugin_is_active( $plugin ) ) {
				$this->should_load_ecommerce = true;
				break;
			}
		}

		$this->should_load_ecommerce = (bool) apply_filters( 'burst_load_ecommerce_integration', $this->should_load_ecommerce );
		return $this->should_load_ecommerce;
	}

	/**
	 * Check if there are any subscriptions
	 *
	 * @return bool True if there are subscriptions, false otherwise.
	 */
	public function has_subscription_integrations_enabled(): bool {
		if ( $this->should_load_subscriptions !== null ) {
			return $this->should_load_subscriptions;
		}

		if ( $this->is_mainwp_request() ) {
			$this->should_load_subscriptions = true;
			return $this->should_load_subscriptions;
		}

		$this->should_load_subscriptions = (bool) apply_filters( 'burst_subscription_integrations_enabled', false );
		return $this->should_load_subscriptions;
	}

	/**
	 * Register the plugin for the consent API
	 */
	public function register_for_consent_api(): void {
		$plugin = BURST_PLUGIN;
		add_filter( "wp_consent_api_registered_{$plugin}", '__return_true' );
	}

	/**
	 * Returns the default plugin integrations supported by Burst Statistics.
	 *
	 * @return array<string, array<string, mixed>> List of integrations keyed by plugin slug.
	 */
	private function default_integrations(): array {
		return require __DIR__ . '/integrations.php';
	}

	/**
	 * Load the integrations
	 */
	public function load_integrations(): void {
		$non_dependent_integrations = array_filter(
			$this->integrations,
			function ( $details ) {
				return empty( $details['required_plugins'] );
			}
		);

		$dependent_integrations = array_filter(
			$this->integrations,
			function ( $details ) {
				return ! empty( $details['required_plugins'] );
			}
		);

		foreach ( $non_dependent_integrations as $plugin => $details ) {
			if ( ! $this->plugin_is_active( $plugin ) ) {
				continue;
			}

			if ( empty( $details['php_scripts'] ) ) {
				continue;
			}

			$php_scripts_to_load = $this->get_integrations_to_load( $details['php_scripts'], $plugin );

			if ( empty( $php_scripts_to_load ) ) {
				continue;
			}

			foreach ( $php_scripts_to_load as $php_script ) {
				require_once $php_script['file'];
			}
		}

		foreach ( $dependent_integrations as $plugin => $details ) {
			if ( ! $this->plugin_is_active( $plugin ) ) {
				continue;
			}

			if ( isset( $details['required_plugins'] ) && ! $this->are_all_required_plugins_active( $details['required_plugins'] ) ) {
				continue;
			}

			if ( empty( $details['php_scripts'] ) ) {
				continue;
			}

			$php_scripts_to_load = $this->get_integrations_to_load( $details['php_scripts'], $plugin );

			if ( empty( $php_scripts_to_load ) ) {
				continue;
			}

			foreach ( $php_scripts_to_load as $php_script ) {
				require_once $php_script['file'];
			}
		}
	}

	/**
	 * Get the integrations to load
	 *
	 * @param array $php_script_lists Integration details.
	 * @return array List of integrations to load.
	 */
	public function get_integrations_to_load( array $php_script_lists, string $plugin ): array {
		$integrations = [];

		if ( ! empty( $php_script_lists['admin_scripts'] ) && is_array( $php_script_lists['admin_scripts'] ) ) {
			foreach ( $php_script_lists['admin_scripts'] as $script ) {
				$file = apply_filters( 'burst_integration_path', BURST_PATH . "includes/Integrations/plugins/{$plugin}/{$script}", $plugin );

				if ( ! file_exists( $file ) || ! $this->has_admin_access() ) {
					continue;
				}

				$integrations[] = [
					'type' => 'admin',
					'file' => $file,
				];
			}
		}

		if ( ! empty( $php_script_lists['frontend_scripts'] ) && is_array( $php_script_lists['frontend_scripts'] ) ) {
			foreach ( $php_script_lists['frontend_scripts'] as $script ) {
				$file = apply_filters( 'burst_integration_path', BURST_PATH . "includes/Integrations/plugins/{$plugin}/{$script}", $plugin );

				if ( ! file_exists( $file ) ) {
					continue;
				}

				$integrations[] = [
					'type' => 'frontend',
					'file' => $file,
				];
			}
		}

		return $integrations;
	}

	/**
	 * Are all required plugins active for a given integration
	 *
	 * @param array $required_plugins List of required plugins.
	 * @return bool True if all required plugins are active, false otherwise.
	 */
	public function are_all_required_plugins_active( array $required_plugins ): bool {
		foreach ( $required_plugins as $plugin ) {
			if ( ! $this->plugin_is_active( $plugin ) ) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Check if a plugin file (as passed by the activated_plugin / deactivated_plugin hooks,
	 * e.g. "woocommerce/woocommerce.php") is one of the ecommerce integrations.
	 */
	public function is_ecommerce_integration_plugin( string $plugin_file ): bool {
		$slug = dirname( $plugin_file );
		if ( $slug === '.' ) {
			$slug = basename( $plugin_file, '.php' );
		}
		return ! empty( $this->integrations[ $slug ]['load_ecommerce_integration'] );
	}

	/**
	 * Check if a specific integration is enabled by the user.
	 *
	 * Returns false when the integration itself is toggled off OR when any of its
	 * required parent integrations are disabled — so disabling WooCommerce
	 * automatically disables WooCommerce Payments, Subscriptions, and Subscriben
	 * without a separate cascade-write.
	 *
	 * @param string $slug The integration slug.
	 * @return bool True if enabled (default), false if explicitly disabled.
	 */
	public function is_integration_enabled( string $slug ): bool {
		if ( ! isset( $this->integrations[ $slug ] ) ) {
			return false;
		}

		$options = get_option( 'burst_options_settings', [] );
		$key     = 'enable_integration_' . sanitize_key( $slug );

		// Default is enabled; only treat as disabled when explicitly set to 0/false.
		$own_enabled = ! isset( $options[ $key ] ) || (bool) $options[ $key ];

		if ( ! $own_enabled ) {
			return false;
		}

		// If any required parent is disabled, this integration is also disabled.
		$required = $this->integrations[ $slug ]['required_plugins'] ?? [];
		foreach ( $required as $parent_slug ) {
			if ( ! $this->is_integration_enabled( $parent_slug ) ) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Check if the plugin is active (installed + detected + user-enabled).
	 *
	 * @param string $plugin The plugin slug.
	 * @return bool True if the plugin is active, false otherwise.
	 */
	public function plugin_is_active( string $plugin ): bool {
		if ( ! isset( $this->integrations[ $plugin ] ) ) {
			return false;
		}

		if ( ! $this->plugin_is_detected( $this->integrations[ $plugin ] ) ) {
			return false;
		}

		return $this->is_integration_enabled( $plugin );
	}

	/**
	 * Check whether an integration's plugin is installed: its constant, function,
	 * class or theme name is detected, regardless of the user-facing enabled toggle.
	 *
	 * @param array<string, mixed> $details Integration definition.
	 * @return bool True if the plugin is installed.
	 */
	public function plugin_is_detected( array $details ): bool {
		$constant = $details['constant_or_function'] ?? '';
		$theme    = wp_get_theme();

		return defined( $constant )
			|| function_exists( $constant )
			|| class_exists( $constant )
			|| ( isset( $theme->name ) && $theme->name === $constant );
	}

	/**
	 * Load translations for integrations in the react dashboard
	 */
	public function load_translations(): void {
		if ( ! $this->is_logged_in_rest() && ! $this->is_mainwp_request() ) {
			return;
		}

		$translations = require __DIR__ . '/translations.php';

		foreach ( $this->integrations as $plugin => &$details ) {
			if ( ! empty( $translations[ $plugin ] ) && ! empty( $details['goals'] ) ) {
				foreach ( $details['goals'] as $key => &$goal ) {
					$translation = $translations[ $plugin ]['goals'][ $key ] ?? null;
					if ( $translation ) {
						$goal['title']       = $translation['title'] ?? $goal['title'] ?? '';
						$goal['description'] = $translation['description'] ?? $goal['description'] ?? '';
					}
				}
			}
		}
	}
}