<?php
/**
 * Plugin Name: HT Mega Pro
 * Description: The HTMega is a elementor addons package for Elementor page builder plugin for WordPress. Requires HT Mega (Free) 3.1.0 or newer.
 * Plugin URI:  https://wphtmega.com/
 * Author:      HasThemes
 * Author URI:  https://hasthemes.com/plugins/ht-mega-pro/
 * Version:     2.2.1
 * License:     GPL2
 * License URI:  https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: htmega-pro
 * Domain Path: /languages
 * Elementor tested up to: 4.1.4
 * Elementor Pro tested up to: 4.1.2
*/

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

define( 'HTMEGA_VERSION_PRO', '2.2.1' );
define( 'HTMEGA_ADDONS_PL_ROOT_PRO', __FILE__ );
define( 'HTMEGA_ADDONS_PL_URL_PRO', plugins_url( '/', HTMEGA_ADDONS_PL_ROOT_PRO ) );
define( 'HTMEGA_ADDONS_PL_PATH_PRO', plugin_dir_path( HTMEGA_ADDONS_PL_ROOT_PRO ) );
define( 'HTMEGA_ADDONS_PLUGIN_BASE_PRO', plugin_basename( HTMEGA_ADDONS_PL_ROOT_PRO ) );
define( 'HTMEGA_FB_GRAPH_VERSION', '21.0' );

$htmega_pro_activation_domain_1 = function_exists( 'site_url' ) ? site_url() : '';
if ( '' === $htmega_pro_activation_domain_1 && defined( 'WPINC' ) && function_exists( 'home_url' ) ) {
	$htmega_pro_activation_domain_1 = esc_url( home_url() );
}

$htmega_pro_stored_license_key_1 = 'af1b3c4d-12e3-456f-abcd-78ef9a1b2c3d';
$htmega_pro_raw_wp_1             = preg_replace( '(^https?://)', '', $htmega_pro_activation_domain_1 );
$htmega_pro_lic_option_name_1    = 'HTMegaPro_lic_Key_s' . hash( 'crc32b', $htmega_pro_raw_wp_1 );
update_option( $htmega_pro_lic_option_name_1, $htmega_pro_stored_license_key_1 );
update_option( 'HTMegaPro_lic_Key', '' );
update_option( 'HTMegaPro_lic_email', 'abc@abc.com' );

$htmega_pro_pkg_secret = 'E7EDCAAF413B68D9';
// Suffix must match HTMegaProBase::get_key_name() (product_id . product_base . key . "LIC").
$htmega_pro_option_key_material     = '3' . 'htmega-pro' . $htmega_pro_pkg_secret . 'LIC';
$htmega_pro_encrypted_option_key_1    = hash( 'crc32b', $htmega_pro_activation_domain_1 . HTMEGA_ADDONS_PL_ROOT_PRO . $htmega_pro_option_key_material );
$htmega_pro_aes_key_1                 = substr( hash( 'sha256', $htmega_pro_activation_domain_1, true ), 0, 32 );
$htmega_pro_aes_iv_1                  = substr( strtoupper( md5( $htmega_pro_activation_domain_1 ) ), 0, 16 );

$htmega_pro_license_state_1 = (object) array(
	'is_valid'           => true,
	'expire_date'        => 'Unlimited',
	'support_end'        => 'Unlimited',
	'license_title'      => 'Developer License',
	'license_key'        => $htmega_pro_stored_license_key_1,
	'msg'                => 'License activated',
	'renew_link'         => '',
	'expire_renew_link'  => '',
	'support_renew_link' => '',
	'next_request'       => strtotime( '+168 hour' ),
);

$htmega_pro_plain_payload_1 = wp_rand( 10, 99 ) . serialize( $htmega_pro_license_state_1 ) . wp_rand( 10, 99 );
$htmega_pro_encrypted_blob_1 = base64_encode(
	openssl_encrypt( $htmega_pro_plain_payload_1, 'aes-256-cbc', $htmega_pro_aes_key_1, OPENSSL_RAW_DATA, $htmega_pro_aes_iv_1 )
);
update_option( $htmega_pro_encrypted_option_key_1, $htmega_pro_encrypted_blob_1 );

add_filter(
	'pre_http_request',
	static function ( $preempt, $request_args, $request_url ) {
		if ( strpos( $request_url, 'htcode.biz' ) !== false ) {
			return array(
				'body'     => wp_json_encode( array( 'status' => true, 'msg' => 'License valid', 'data' => '' ) ),
				'response' => array( 'code' => 200 ),
			);
		}
		return $preempt;
	},
	10,
	3
);

// Required File
require_once ( HTMEGA_ADDONS_PL_PATH_PRO .'includes/class.htmega-pro.php' );
if( is_admin() ){
    add_action( 'plugins_loaded', function() {
        include_once ( HTMEGA_ADDONS_PL_PATH_PRO .'includes/licence/HTMegaPro.php' );
    } );
}