<?php
/**
 * Plugin Name: Seazonify
 * Plugin URI: https://seazonify.com
 * Description: Empower your site with high-performance seasonal effects designed to boost engagement and delight visitors year-round.
 * Version: 1.0.5
 * Author: imimofficial
 * Author URI: https://mdmimakhtar.com
 * License: GPL-2.0+
 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain: seazonify
 */

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

define('SEAZONIFY_VERSION', '1.0.5');
define('SEAZONIFY_PLUGIN_DIR', plugin_dir_path(__FILE__));
$seazonify_plugin_url = plugin_dir_url(__FILE__);
// Ensure absolute URL especially for environments with proxies or custom directory structures
if (strpos($seazonify_plugin_url, 'http') === false) {
    // If protocol-relative (//), prepend current scheme
    if (strpos($seazonify_plugin_url, '//') === 0) {
        $seazonify_plugin_url = is_ssl() ? 'https:' . $seazonify_plugin_url : 'http:' . $seazonify_plugin_url;
    } 
    // If root-relative (/), prepend home_url
    elseif (strpos($seazonify_plugin_url, '/') === 0) {
        $seazonify_plugin_url = home_url($seazonify_plugin_url);
    } 
    // Otherwise, it might be relative to the current script, which shouldn't happen with plugin_dir_url
}
define('SEAZONIFY_PLUGIN_URL', trailingslashit($seazonify_plugin_url));

// Seazonify App settings
define('SEAZONIFY_APP_URL', 'https://api.seazonify.com');

define('SEAZONIFY_LOGO_URL', SEAZONIFY_PLUGIN_URL . 'admin/images/logo.png');
define('SEAZONIFY_GITHUB_REPO', 'itsmimakhtar/Seazonify');
define('SEAZONIFY_GITHUB_BRANCH', 'main');
define('SEAZONIFY_CDN_BASE', SEAZONIFY_PLUGIN_URL . 'assets');
define('SEAZONIFY_EFFECTS_URL', SEAZONIFY_PLUGIN_URL . 'assets/effects/');
define('SEAZONIFY_CONTROLLER_URL', SEAZONIFY_PLUGIN_URL . 'admin/js/controller.js');

/**
 * Activation hook
 */
function seazonify_activate()
{
    $default_options = array(
        'enabled' => false,
        'visual_effect' => '',
        'audio_effect' => '',
        'combo_effect' => '',
        'show_controller' => true,
        'cache_duration' => 3600,
        'display_on' => 'all', // all, homepage, pages, posts, custom
        'include_pages' => array(),
        'exclude_pages' => array(),
        'include_posts' => array(),
        'exclude_posts' => array(),
    );
    add_option('seazonify_settings', $default_options);
    delete_transient('seazonify_effects_cache');
}
register_activation_hook(__FILE__, 'seazonify_activate');

/**
 * Deactivation hook
 */
function seazonify_deactivate()
{
    delete_transient('seazonify_effects_cache');
}
register_deactivation_hook(__FILE__, 'seazonify_deactivate');


/**
 * Include core files
 */
require_once SEAZONIFY_PLUGIN_DIR . 'includes/class-seazonify-effects.php';
require_once SEAZONIFY_PLUGIN_DIR . 'includes/class-seazonify-admin.php';
require_once SEAZONIFY_PLUGIN_DIR . 'includes/class-seazonify-customizer.php';
require_once SEAZONIFY_PLUGIN_DIR . 'includes/class-seazonify-rate-limiter.php';
require_once SEAZONIFY_PLUGIN_DIR . 'includes/class-seazonify-frontend.php';

/**
 * Initialize plugin
 */
function seazonify_run()
{
    if (is_admin()) {
        new Seazonify_Admin();
    }
    new Seazonify_Customizer();
    // Always load frontend class for shared hooks (like script attributes)
    new Seazonify_Frontend();
}
add_action('plugins_loaded', 'seazonify_run');
