<?php

/**
 * Plugin Name: Structure Viewer
 * Description: Browse, inspect, and export any plugin or theme file structure — right from WordPress admin. For developers who build smarter with AI.
 * Version:     2.2.0
 * Author:      Blincks
 * Author URI:  https://www.blincks.com
 * Plugin URI:  https://wordpress.org/plugins/structure-viewer
 * License:     GPL-2.0-or-later
 * Text Domain: structure-viewer
 * Domain Path: /languages
 */
// Prevent direct access
if ( !defined( 'ABSPATH' ) ) {
    exit( 'Direct access denied.' );
}
/**
 * When the premium version is activated, Freemius uses this check to
 * auto-deactivate the free version. DO NOT remove the outer if block —
 * it is required for the `function_exists` call above to work correctly.
 */
if ( function_exists( 'structureviewer_fs' ) ) {
    structureviewer_fs()->set_basename( false, __FILE__ );
} else {
    /**
     * Freemius SDK initialisation.
     * Creates the structureviewer_fs() helper and fires the structureviewer_fs_loaded action.
     */
    function structureviewer_fs() {
        global $structureviewer_fs;
        if ( !isset( $structureviewer_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
            $structureviewer_fs = fs_dynamic_init( array(
                'id'               => '23348',
                'slug'             => 'structure-viewer',
                'premium_slug'     => 'structure-viewer-pro',
                'type'             => 'plugin',
                'public_key'       => 'pk_2e88b146143e9c3ce7314cdc46242',
                'is_premium'       => false,
                'premium_suffix'   => 'Structure Viewer Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'menu'             => array(
                    'slug'    => 'structure-viewer',
                    'support' => false,
                    'parent'  => array(
                        'slug' => 'tools.php',
                    ),
                ),
                'is_live'          => true,
            ) );
        }
        return $structureviewer_fs;
    }

    // Init Freemius.
    structureviewer_fs();
    // Signal that SDK was initiated.
    do_action( 'structureviewer_fs_loaded' );
    // ── Constants ─────────────────────────────────────────────────────────────────
    define( 'STRUCTUREVIEWER_VERSION', '2.2.0' );
    define( 'STRUCTUREVIEWER_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
    define( 'STRUCTUREVIEWER_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    define( 'STRUCTUREVIEWER_NONCE', 'structureviewer_nonce_action' );
    // ── Core includes (always loaded) ─────────────────────────────────────────────
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Helpers/Sanitizer.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Helpers/ItemData.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Search/Filters.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Search/Search.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Explorer/Exporter.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Explorer/FileViewer.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Explorer/Scanner.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Core/Settings.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Core/Uninstall.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Admin/Dashboard.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Admin/AdminPage.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Core/Loader.php';
    require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/Core/Plugin.php';
    // ── Uninstall cleanup (Freemius action) ───────────────────────────────────────
    // We do NOT ship an uninstall.php file. Per Freemius docs, having one
    // breaks their uninstall-feedback flow and the SDK can't report what users
    // tell it during the uninstall dialog. Instead we hook into Freemius's
    // `after_uninstall` action, which fires AFTER the uninstall event has been
    // reported to the server.
    structureviewer_fs()->add_action( 'after_uninstall', ['SV_Uninstall', 'cleanup'] );
    // ── WP-CLI ────────────────────────────────────────────────────────────────────
    if ( defined( 'WP_CLI' ) && WP_CLI ) {
        require_once STRUCTUREVIEWER_PLUGIN_DIR . 'includes/CLI/CLI.php';
    }
    // ── Boot ──────────────────────────────────────────────────────────────────────
    SV_Plugin::init();
}
// end Freemius free/premium wrapper