<?php
/**
 * Plugin Name: Edocman Lite
 * Plugin URI: https://joomdonation.com/edocman-wp
 * Description: Lightweight document management system for WordPress. Organize, manage, and share documents with categories and download tracking.
 * Version: 1.0.0
 * Author: Ossolution
 * Author URI: https://joomdonation.com
 * Requires at least: 5.0
 * Tested up to: 7.0
 * Requires PHP: 7.4
 * Text Domain: edocman-lite
 * Domain Path: /languages
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

// Prevent direct access.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

// Define plugin constants
define('EDOCMAN_LITE_VERSION', '1.0.0');
define('EDOCMAN_LITE_DB_VERSION', '1.2');
define('EDOCMAN_LITE_PLUGIN_FILE', __FILE__);
define('EDOCMAN_LITE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('EDOCMAN_LITE_PLUGIN_URL', plugin_dir_url(__FILE__));
define('EDOCMAN_LITE_PLUGIN_PATH', plugin_dir_path(__FILE__));

// Include required files
require_once EDOCMAN_LITE_PLUGIN_DIR . 'includes/class-edocman-lite-autoloader.php';
Edocman_Lite_Autoloader::register();

require_once EDOCMAN_LITE_PLUGIN_DIR . 'includes/class-edocman-lite.php';

// Initialize the plugin
function edocman_lite_run() {
    $plugin = new Edocman_Lite();
    $plugin->run();
}

// Hook to initialize plugin
add_action('init', 'edocman_lite_run');

// Activation hook
register_activation_hook(__FILE__, array('Edocman_Lite', 'activate'));

// Deactivation hook
register_deactivation_hook(__FILE__, array('Edocman_Lite', 'deactivate'));

// Register widget
function edocman_lite_register_widgets() {
    register_widget('Edocman_Lite_Categories_Widget');
}
add_action('widgets_init', 'edocman_lite_register_widgets');

// Run database migrations on every load so existing sites receive new columns.
function edocman_lite_maybe_upgrade_db() {
    require_once EDOCMAN_LITE_PLUGIN_DIR . 'includes/class-edocman-lite-database.php';
    $database = new Edocman_Lite_Database();
    $database->maybe_upgrade();
}
add_action('plugins_loaded', 'edocman_lite_maybe_upgrade_db');
