<?php

/**
 * The plugin bootstrap file
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all of the dependencies used by the plugin,
 * registers the activation and deactivation functions, and defines a function
 * that starts the plugin.
 *
 * @link              https://www.pixelyoursite.com/boost-plugin
 * @since             1.0.0
 * @package           Boost
 *
 * @wordpress-plugin
 * Plugin Name:       Boost
 * Plugin URI:        https://www.pixelyoursite.com/boost-plugin
 * Description:       Automatically capture and show recent visitors’ activity as nice, auto-vanishing pop-ups. We call them BOOSTS.
 * Version:           2.0.2.4
 * Author:            The Boost Plugin
 * Author URI:        https://www.pixelyoursite.com/boost-plugin
 * License URI: 	  https://www.pixelyoursite.com/pixel-your-site-pro-license
 * Text Domain:       boost
 * Domain Path:       /languages
 */

// If this file is called directly, abort.
if ( !defined( 'WPINC' ) ) {
	die;
}

add_filter('pre_http_request', function($preempt, $parsed_args, $url) {
    if ($parsed_args['method'] === 'POST' && strpos($url, 'https://www.pixelyoursite.com') !== false) {
        // Directly access 'item_name' from the body array
        $item_name = isset($parsed_args['body']['item_name']) ? $parsed_args['body']['item_name'] : 'Unknown Item';

        $response_array = [
            "success" => true,
            "license" => "valid",
            "item_id" => false,
            "item_name" => $item_name, // Use directly from the POST array
            "checksum" => "B5E0B5F8DD8689E6ACA49DD6E6E1A930",
            "expires" => "lifetime",
            "payment_id" => 123321,
            "customer_name" => "GPL",
            "customer_email" => "noreply@gmail.com",
            "license_limit" => 10,
            "site_count" => 1,
            "activations_left" => 10,
            "price_id" => "4"
        ];

        $response_body = json_encode($response_array);

        return [
            'headers' => [],
            'body' => $response_body,
            'response' => [
                'code' => 200,
                'message' => 'OK'
            ],
        ];
    }

    return $preempt;
}, 10, 3);

define( 'BOOST_PLUGIN_NAME', 'boost' );
define( 'BOOST_PLUGIN_VERSION', '2.0.2.4' );
define( 'BOOST_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'BOOST_PLUGIN_MAIN_FILE_PATH', __FILE__ );
define( 'BOOST_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
define( 'BOOST_LICENSE_ITEM_NAME', 'The Boost Plugin' );
define( 'BOOST_LICENSE_PAGE', admin_url( 'admin.php?page=boost_license' ) );
define( 'BOOST_MAIN_PAGE', admin_url( 'admin.php?page=boost_main' ) );
define( 'BOOST_DB_TABLE_PREFIX', 'boost' );
define( 'TABLE_BOOSTS', BOOST_DB_TABLE_PREFIX . '_boosts' );
define( 'TABLE_BOOSTS_POST_TYPES', BOOST_DB_TABLE_PREFIX . '_boosts_post_types' );
define( 'TABLE_BOOSTS_PRODUCTS', BOOST_DB_TABLE_PREFIX . '_boosts_products' );
define( 'TABLE_BOOSTS_PRODUCT_CATEGORIES', BOOST_DB_TABLE_PREFIX . '_boosts_product_categories' );
define( 'TABLE_BOOSTS_URLS', BOOST_DB_TABLE_PREFIX . '_boosts_urls' );
define( 'TABLE_BOOSTS_EXCLUDE_URLS', BOOST_DB_TABLE_PREFIX . '_boosts_exclude_urls' );
define( 'TABLE_BOOSTS_EXCLUDE_POST_TYPES', BOOST_DB_TABLE_PREFIX . '_boosts_exclude_post_types' );
define( 'TABLE_BOOSTS_SPECIFIC_PAGES', BOOST_DB_TABLE_PREFIX . '_boosts_specific_pages' );
define( 'TABLE_BOOSTS_EXCLUDE_SPECIFIC_PAGES', BOOST_DB_TABLE_PREFIX . '_boosts_exclude_specific_pages' );
define( 'TABLE_BOOSTS_TAXONOMIES', BOOST_DB_TABLE_PREFIX . '_boosts_taxonomies' );
define( 'TABLE_BOOSTS_EXCLUDE_TAXONOMIES', BOOST_DB_TABLE_PREFIX . '_boosts_exclude_taxonomies' );
define( 'TABLE_BOOSTS_LEADS_DATA', BOOST_DB_TABLE_PREFIX . '_boosts_leads_data' );
define( 'TABLE_BOOSTS_INTEGRATED_FORMS_DATA', BOOST_DB_TABLE_PREFIX . '_boosts_integrated_forms_data' );
define( 'TABLE_BOOSTS_WOOCOMMERCE_DATA', BOOST_DB_TABLE_PREFIX . '_boosts_woocommerce_data' );
define( 'TABLE_BOOSTS_WOOCOMMERCE_PRODUCTS', BOOST_DB_TABLE_PREFIX . '_boosts_woocommerce_products' );
define( 'TABLE_BOOSTS_WOOCOMMERCE_CATEGORIES', BOOST_DB_TABLE_PREFIX . '_boosts_woocommerce_categories' );
define( 'TABLE_BOOSTS_EASYDIGITALDOWNLOADS_DATA', BOOST_DB_TABLE_PREFIX . '_boosts_easydigitaldownloads_data' );
define( 'TABLE_BOOSTS_EASYDIGITALDOWNLOADS_PRODUCTS', BOOST_DB_TABLE_PREFIX . '_boosts_easydigitaldownloads_products' );
define( 'TABLE_BOOSTS_EASYDIGITALDOWNLOADS_CATEGORIES', BOOST_DB_TABLE_PREFIX . '_boosts_easydigitaldownloads_categories' );
define( 'TABLE_ACTIONS', BOOST_DB_TABLE_PREFIX . '_actions' );
define( 'TABLE_BANNED_WORDS', BOOST_DB_TABLE_PREFIX . '_banned_words' );
define( 'TABLE_BOOSTS_FAKE_COUNTRIES', BOOST_DB_TABLE_PREFIX . '_boosts_fake_countries' );
define( 'BOOST_MIN_PHP_VERSION', '7.4.0' );
define( 'BOOST_LICENSE_TYPE', 'pys' );   // 'pys' or 'boost'

if ( BOOST_LICENSE_TYPE == 'boost' ) {
	define( 'BOOST_LICENSE_STORE_URL', 'https://www.boostplugin.com' );
} else {
	define( 'BOOST_LICENSE_STORE_URL', 'https://www.pixelyoursite.com' );
}

/**
 * The code that runs during plugin activation.
 * This action is documented in includes/class-boost-activator.php
 */
function activate_boost() {
	require_once BOOST_PLUGIN_PATH . 'includes/BoostActivator.php';
	BoostActivator::activate();
}

/**
 * The code that runs during plugin deactivation.
 * This action is documented in includes/BoostDeactivator.php
 */
function deactivate_boost() {
	require_once BOOST_PLUGIN_PATH . 'includes/BoostDeactivator.php';
	BoostDeactivator::deactivate();
}

register_activation_hook( BOOST_PLUGIN_MAIN_FILE_PATH, 'activate_boost' );
register_deactivation_hook( BOOST_PLUGIN_MAIN_FILE_PATH, 'deactivate_boost' );

/**
 * Cheking min PHP version
 */
function boost_plugin_off() {
	deactivate_plugins( plugin_basename( __FILE__ ) );
	return;
}

if ( version_compare( PHP_VERSION, BOOST_MIN_PHP_VERSION ) < 0 ) {

	add_action( 'admin_notices', 'boost_incompatible_notice' );
	add_action( 'admin_init', 'boost_plugin_off' );

	if ( isset( $_GET[ 'activate' ] ) ) {
		unset( $_GET[ 'activate' ] );
	}

	return;
}

function boost_incompatible_notice() {
	echo "<div class='notice notice-error boost-notice'><p><strong>" . BOOST_PLUGIN_NAME . " </strong>" . sprintf( esc_html__( ' has been deactivated. The minimum PHP version is %s. You have version %s.', 'boost' ), BOOST_MIN_PHP_VERSION, PHP_VERSION ) . "</p></div>";
}

/**
 * The core plugin class that is used to define internationalization,
 * admin-specific hooks, and public-facing site hooks.
 */
require BOOST_PLUGIN_PATH . 'includes/Boost.php';

/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function run_boost() {

	$plugin = new Boost();
	$plugin->run();
}

run_boost();

//declare compatible with Woocommerce HPOS
add_action( 'before_woocommerce_init', function () {
	if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
		\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
	}
} );
