<?php //phpcs:ignore
/**
 * Plugin Name:       FlexMeeting
 * Plugin URI:        https://jitsi-meet-wp.wppool.dev/
 * Description:       Host live webinars, conferences, online classes, video calls directly on your WordPress website with gutenberg block
 * Version:           2.9.2
 * Author:            WPPOOL
 * Author URI:        https://wppool.dev
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       webinar-and-video-conference-with-jitsi-meet
 * Requires at least: 5.2
 * Tested up to:      7.0
 *
 *  @package JITSI_MEET_WP
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit(); // phpcs:ignore
}

define( 'JITSI_MEET_WP_VERSION', '2.9.2' );
define( 'JITSI_MEET_WP__FILE__', __FILE__ );
define( 'JITSI_MEET_WP_DIR_PATH', plugin_dir_path( JITSI_MEET_WP__FILE__ ) );
define( 'JITSI_MEET_WP_FILE_PATH', plugin_dir_path( __FILE__ ) );
define( 'JITSI_MEET_WP_URL', plugins_url( '', __FILE__ ) );
define( 'JITSI_MEET_WP_TEMPLATES', JITSI_MEET_WP_DIR_PATH . '/templates' );
define( 'JITSI_MEET_WP_ASSETS', JITSI_MEET_WP_URL . '/assets' );


/**
 * [jitsi_meet_wp_begin]
 *
 * @return  void
 */
function jitsi_meet_wp_begin() {
	$plugin_list    = (array) get_option( 'active_plugins', array() );
	$jitsi_pro      = 'webinar-and-video-conference-jitsi-meet-pro/jitsi-meet-wp.php';
	$jitsi_ultimate = 'webinar-and-video-conference-with-jitsi-meet-ultimate/jitsi-meet-wp.php';
	$jitsi_premium  = 'webinar-and-video-conference-with-jitsi-meet-premium/jitsi-meet-wp.php';

	if ( ! in_array( $jitsi_pro, $plugin_list, true ) && ! in_array( $jitsi_ultimate, $plugin_list, true ) && ! in_array( $jitsi_premium, $plugin_list, true ) ) {
		/**
		 * Check for Gutenberg existence
		 * And prevent further execution if doesn't exist.
		 */
		if ( ! function_exists( 'register_block_type' ) ) {
			include_once JITSI_MEET_WP_DIR_PATH . 'init.php';
		} else {
			include_once JITSI_MEET_WP_DIR_PATH . 'init.php';
			include_once JITSI_MEET_WP_DIR_PATH . 'gutenberg-init.php';
			Jitsi_Meet_WP_Gutenberg::instance();
		}
	}

	if ( ! get_user_meta( get_current_user_id(), 'jitsi_hosted_topbar_dismissed', true ) ) {
		include_once JITSI_MEET_WP_FILE_PATH . 'inc/jitsi-topbar.php';
	}
}


function jitsi_meet_wp_is_any_premium_active() {
	$active_plugins  = (array) get_option( 'active_plugins', [] );
	$network_plugins = (array) get_site_option( 'active_sitewide_plugins', [] );

	$pro_plugins = [
		'webinar-and-video-conference-with-jitsi-meet-pro/jitsi-meet-wp.php',
		'webinar-and-video-conference-with-jitsi-meet-ultimate/jitsi-meet-wp.php',
		'webinar-and-video-conference-with-jitsi-meet-premium/jitsi-meet-wp.php',
	];

	foreach ( $pro_plugins as $plugin ) {
		if ( in_array( $plugin, $active_plugins, true ) || isset( $network_plugins[ $plugin ] ) ) {
			return true;
		}
	}

	return false;
}


/**
 * Jitsi meet plugin activate.
 *
 * @return  void
 */
function jitsi_meet_plugin_activate() {
	// update_option( 'jitsi_meet_wp_version', JITSI_MEET_WP_VERSION );
	// set_transient( 'jitsi_meet_wp_review_notice_interval', 'off', 7 * DAY_IN_SECONDS );
	// set_transient( 'jitsi_meet_wp_affiliate_notice_interval', 'off', 14 * DAY_IN_SECONDS );.

	$install_date = get_option( 'jitsi_meet_wp_install_time' );

	if ( empty( $install_date ) ) {
		update_option( 'jitsi_meet_wp_install_time', time() );
	}

	if ( get_option( 'jitsi_meet_welcome_redirect' ) !== 'occured' ) {
		add_option( 'jitsi_meet_welcome_redirect', true );
	}
}

register_activation_hook( __FILE__, 'jitsi_meet_plugin_activate' );

// WordPress 4.6+ auto-loads translations from wordpress.org — no manual call needed.

add_action( 'init', 'jitsi_meet_wp_begin', 20 );


/**
 * Initialize the plugin tracker
 *
 * @return mixed
 */
function jitsi_meet_wp_appsero_init_tracker() {
	if ( ! class_exists( 'Appsero\Client' ) ) {
		require_once __DIR__ . '/inc/appsero/src/Client.php';
	}

	$client = new Appsero\Client( '00788961-f5f7-4117-8a26-a99508aa506b', 'FlexMeeting', JITSI_MEET_WP__FILE__ );

	// Active insights.
	$client->insights()->init();
}

/**
 * Initialize the wppool sdk
 *
 * @return void
 */
function jitsi_meet_wppool_sdk_init() {
	// Require WPPOOL SDK files.

	if ( file_exists( JITSI_MEET_WP_FILE_PATH . 'inc/wppool/class-plugin.php' ) ) {
		require_once JITSI_MEET_WP_FILE_PATH . 'inc/wppool/class-plugin.php';
	}

	if ( function_exists( 'wppool_plugin_init' ) ) {
		wppool_plugin_init( 'webinar_and_video_conference_with_jitsi_meet', plugin_dir_url( JITSI_MEET_WP__FILE__ ) . '/inc/wppool/background-image.png' );
	}
}

/**
 * Set up wppool sdk campaign
 *
 * @return void
 */
function jitsi_meet_wppool_sdk_campaign() {
	if ( function_exists( 'wppool_plugin_init' ) ) {
		$jitsi_meet_plugin = wppool_plugin_init( 'webinar_and_video_conference_with_jitsi_meet', plugin_dir_url( JITSI_MEET_WP__FILE__ ) . '/inc/wppool/background-image.png' );

		if ( $jitsi_meet_plugin && is_object( $jitsi_meet_plugin ) && method_exists( $jitsi_meet_plugin, 'set_campaign' ) ) {
			$to       = '2025-12-04 16:00:00';
			$from     = '2025-11-17 16:00:00';
			$cta_text = esc_html__( 'Grab Your Deals', 'webinar-and-video-conference-with-jitsi-meet' );

			$campain_image = plugin_dir_url( JITSI_MEET_WP__FILE__ ) . '/inc/wppool/bfcm.png';
			$jitsi_meet_plugin->set_campaign( $campain_image, $to, $from, $cta_text );

			$button_link = 'https://lnk.wppool.dev/kHhV59A';
			$jitsi_meet_plugin->set_campaign( $campain_image, $to, $from, $cta_text, $button_link );
		}
	}
}

jitsi_meet_wppool_sdk_init();
add_action( 'init', 'jitsi_meet_wppool_sdk_campaign' );
add_action( 'init', 'jitsi_meet_wp_appsero_init_tracker' );
