<?php

/**
 * The core plugin class.
 *
 * @since      0.1.0
 * @package    PinnerPress
 */

if (!class_exists('PinnerPress')) {
class PinnerPress {

    /**
     * The loader that's responsible for maintaining and registering all hooks that power
     * the plugin.
     *
     * @since    0.1.0
     * @access   protected
     * @var      PinnerPress_Loader    $loader    Maintains and registers all hooks for the plugin.
     */
    protected $loader;

    /**
     * The unique identifier of this plugin.
     *
     * @since    0.1.0
     * @access   protected
     * @var      string    $plugin_name    The string used to uniquely identify this plugin.
     */
    protected $plugin_name;

    /**
     * The current version of the plugin.
     *
     * @since    0.1.0
     * @access   protected
     * @var      string    $version    The current version of the plugin.
     */
    protected $version;

    /**
     * Define the core functionality of the plugin.
     *
     * @since    0.1.0
     */
    public function __construct() {
        if (defined('PINNERPRESS_VERSION')) {
            $this->version = PINNERPRESS_VERSION;
        } else {
            $this->version = '0.1.0';
        }
        $this->plugin_name = 'pinnerpress';

        $this->load_dependencies();
        $this->set_locale();
        $this->define_admin_hooks();
        $this->define_public_hooks();
    }

    /**
     * Load the required dependencies for this plugin.
     *
     * @since    0.1.0
     * @access   private
     */
    private function load_dependencies() {

        /**
         * The class responsible for orchestrating the actions and filters of the
         * core plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-loader.php';

        /**
         * The class responsible for defining internationalization functionality
         * of the plugin.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-i18n.php';

        /**
         * The class responsible for defining all actions that occur in the admin area.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'admin/class-pinnerpress-admin.php';

        /**
         * The class responsible for defining all actions that occur in the public-facing
         * side of the site.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'public/class-pinnerpress-public.php';

        /**
         * The class responsible for analytics functionality.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-analytics.php';

        /**
         * The class responsible for image analytics overlay functionality.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-image-analytics-overlay.php';

        /**
         * The class responsible for Hubbub migration functionality.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-hubbub-migration.php';

        /**
         * The class responsible for Tasty Pins migration functionality.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-tasty-pins-migration.php';

        /**
         * The class responsible for ESSB migration functionality.
         */
        require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-pinnerpress-essb-migration.php';

        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-pin-button.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-block-extensions.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-follow-block.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-callout-block.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-follow-shortcode.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-follow-widget.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-hidden-images.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/pinnerpress-hidden-pins-button.php';

        $this->loader = new PinnerPress_Loader();
    }

    /**
     * Define the locale for this plugin for internationalization.
     *
     * @since    0.1.0
     * @access   private
     */
    private function set_locale() {
        $plugin_i18n = new PinnerPress_i18n();
        $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain');
    }

    /**
     * Register all of the hooks related to the admin area functionality
     * of the plugin.
     *
     * @since    0.1.0
     * @access   private
     */
    private function define_admin_hooks() {
        $plugin_admin = new PinnerPress_Admin($this->get_plugin_name(), $this->get_version());

        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts');
        
        // Add admin menu items
        $this->loader->add_action('admin_menu', $plugin_admin, 'add_plugin_admin_menu');

        // Register settings
        $this->loader->add_action('admin_init', $plugin_admin, 'register_plugin_settings');
        
        // Initialize analytics
        $plugin_analytics = new PinnerPress_Analytics();
        
        // Initialize image analytics overlay
        $plugin_analytics_overlay = new PinnerPress_Image_Analytics_Overlay($this->get_plugin_name(), $this->get_version());
        
        // Initialize Hubbub migration functionality
        $hubbub_migration = new PinnerPress_Hubbub_Migration();
        
        // Initialize Tasty Pins migration functionality
        $tasty_pins_migration = new PinnerPress_Tasty_Pins_Migration();
        
        // Initialize ESSB migration functionality
        $essb_migration = new PinnerPress_ESSB_Migration();
    }

    /**
     * Register all of the hooks related to the public-facing functionality
     * of the plugin.
     *
     * @since    0.1.0
     * @access   private
     */
    private function define_public_hooks() {
        $plugin_public = new PinnerPress_Public($this->get_plugin_name(), $this->get_version());

        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles');
        $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts');
        
        // Initialize image analytics overlay for public hooks
        $plugin_analytics_overlay = new PinnerPress_Image_Analytics_Overlay($this->get_plugin_name(), $this->get_version());
    }

    /**
     * Run the loader to execute all of the hooks with WordPress.
     *
     * @since    0.1.0
     */
    public function run() {
        $this->loader->run();
    }

    /**
     * The name of the plugin used to uniquely identify it within the context of
     * WordPress and to define internationalization functionality.
     *
     * @since     0.1.0
     * @return    string    The name of the plugin.
     */
    public function get_plugin_name() {
        return $this->plugin_name;
    }

    /**
     * The reference to the class that orchestrates the hooks with the plugin.
     *
     * @since     0.1.0
     * @return    PinnerPress_Loader    Orchestrates the hooks of the plugin.
     */
    public function get_loader() {
        return $this->loader;
    }

    /**
     * Retrieve the version number of the plugin.
     *
     * @since     0.1.0
     * @return    string    The version number of the plugin.
     */
    public function get_version() {
        return $this->version;
    }
}
} 