<?php

/**
 * Plugin Name: Lofty IDX
 * Description: A powerful WordPress plugin that integrates IDX/MLS property listings.
 * Author: loftylisting
 * Version: 1.7.7
 * License: GPLv2 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 */

defined('ABSPATH') || exit;

// load composer autoloader
require_once __DIR__ . '/vendor/autoload.php';

use LoftyIDX\includes\LoftyIDX;
use Dotenv\Dotenv;

// error_reporting(E_ERROR);

// load env file 
$dotenv=Dotenv::createImmutable(__DIR__);
try {
    if (file_exists(__DIR__ . '/.env')) {
        if (method_exists($dotenv, 'safeLoad')) {
            $dotenv->safeLoad();
        } else {
            $dotenv->load();
        }
    }
} catch (Exception $e) {
}

define('LOFTY_IDX_FILE', __FILE__);

// frontend cdn
define('LOFTY_API_PROXY', isset($_ENV['LOFTY_API_PROXY']) ? sanitize_url($_ENV['LOFTY_API_PROXY']) : 'https://lofty.com/wp-api/wp-plugin/');
define('LOFTY_API_REFERRER', isset($_ENV['LOFTY_API_REFERRER']) ? sanitize_url($_ENV['LOFTY_API_REFERRER']) : '');
define('LOFTY_BUILD_ID', isset($_ENV['LOFTY_BUILD_ID']) ? sanitize_text_field($_ENV['LOFTY_BUILD_ID']) : '1753075827662');
define('LOFTY_CURRENCY_SYMBOL', isset($_ENV['LOFTY_CURRENCY_SYMBOL']) ? sanitize_text_field($_ENV['LOFTY_CURRENCY_SYMBOL']) : '$');
define('LOFTY_LANGUAGE', isset($_ENV['LOFTY_LANGUAGE']) ? sanitize_text_field($_ENV['LOFTY_LANGUAGE']) : 'en');

define('LOFTY_IDX_VERSION', '1.7.7');

define('LOFTY_IDX_PATH', plugin_dir_path(__FILE__));
define('LOFTY_IDX_URL', plugin_dir_url(__FILE__));

// Development mode - read from environment, default to false if not set
define('LOFTY_IS_DEV', 
    isset($_ENV['LOFTY_IS_DEV']) 
        ? filter_var($_ENV['LOFTY_IS_DEV'], FILTER_VALIDATE_BOOLEAN) 
        : false
);

// Template cache - read from environment, default to true if not set
define('LOFTY_ENABLE_TEMPLATE_CACHE', 
    isset($_ENV['LOFTY_ENABLE_TEMPLATE_CACHE']) 
        ? filter_var($_ENV['LOFTY_ENABLE_TEMPLATE_CACHE'], FILTER_VALIDATE_BOOLEAN) 
        : true
);

// Template cache path - read from environment for developer control only
// This prevents users from setting dangerous cache paths through UI
//
// Usage in .env file:
// LOFTY_TEMPLATE_CACHE_PATH=/path/to/custom/cache/directory
// LOFTY_TEMPLATE_CACHE_PATH=wp-content/cache/my-custom-cache  (relative path)
//
// Examples:
// - For shared hosting: LOFTY_TEMPLATE_CACHE_PATH=/tmp/lofty-cache
// - For custom location: LOFTY_TEMPLATE_CACHE_PATH=wp-content/lofty-cache
// - Leave empty to use default plugin cache directory
//
// SECURITY: Paths are still validated to prevent dangerous locations
define('LOFTY_TEMPLATE_CACHE_PATH', 
    isset($_ENV['LOFTY_TEMPLATE_CACHE_PATH']) 
        ? sanitize_text_field($_ENV['LOFTY_TEMPLATE_CACHE_PATH']) 
        : ''
);

// Customization env
define('LOFTY_DISABLE_CUSTOMIZATION', filter_var('false', FILTER_VALIDATE_BOOLEAN));

$loftyIDX = LoftyIDX::get_instance();

$loftyIDX->register();
