<?php

/**
 * The file that defines the core plugin class
 *
 * A class definition that includes attributes and functions used across both the
 * public-facing side of the site and the admin area.
 *
 * @link       www.redefiningtheweb.com
 * @since      1.0.0
 *
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/includes
 */

/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      1.0.0
 * @package    Rtwwpcp_Woocommerce_Pdf_Catalog_Pro
 * @subpackage Rtwwpcp_Woocommerce_Pdf_Catalog_Pro/includes
 * @author     RedefiningTheWeb <developer@redefiningtheweb.com>
 */
class Rtwwpcp_Woocommerce_Pdf_Catalog_Pro {

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

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

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

	/**
	 * Define the core functionality of the plugin.
	 *
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
	 * the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function __construct() {
		if ( defined( 'RTWWPCP_WOOCOMMERCE_PDF_CATALOG_PRO_VERSION' ) ) {
			$this->rtwwpcp_version = RTWWPCP_WOOCOMMERCE_PDF_CATALOG_PRO_VERSION;
		} else {
			$this->rtwwpcp_version = '1.0.0';
		}
		$this->rtwwpcp_plugin_name = 'woocommerce-pdf-catalog-pro';

		$this->rtwwpcp_load_dependencies();
		$this->rtwwpcp_set_locale();
		$this->rtwwpcp_define_admin_hooks();
		$this->rtwwpcp_define_public_hooks();

	}

	/**
	 * Load the required dependencies for this plugin.
	 *
	 * Include the following files that make up the plugin:
	 *
	 * - Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Loader. Orchestrates the hooks of the plugin.
	 * - Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_i18n. Defines internationalization functionality.
	 * - Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Admin. Defines all hooks for the admin area.
	 * - Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Public. Defines all hooks for the public side of the site.
	 *
	 * Create an instance of the loader which will be used to register the hooks
	 * with WordPress.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function rtwwpcp_load_dependencies() {

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

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

		/**
		 * The class responsible for defining all actions that occur in the admin area.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/rtwwpcp-class-woocommerce-pdf-catalog-pro-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/rtwwpcp-class-woocommerce-pdf-catalog-pro-public.php';

		/**
		 * The class responsible for defining general function
		 * of the plugin.
		 */
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/rtwwpcp-general-functions.php';

		$this->rtwwpcp_loader = new Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Loader();

	}

	/**
	 * Define the locale for this plugin for internationalization.
	 *
	 * Uses the Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_i18n class in order to set the domain and to register the hook
	 * with WordPress.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function rtwwpcp_set_locale() {

		$rtwwpcp_plugin_i18n = new Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_i18n();

		$this->rtwwpcp_loader->rtwwpcp_add_action( 'plugins_loaded', $rtwwpcp_plugin_i18n, 'rtwwpcp_load_plugin_textdomain' );

	}

	/**
	 * Register all of the hooks related to the admin area functionality
	 * of the plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function rtwwpcp_define_admin_hooks() {

		$rtwwpcp_plugin_admin = new Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Admin( $this->rtwwpcp_get_plugin_name(), $this->rtwwpcp_get_version() );

		$this->rtwwpcp_loader->rtwwpcp_add_action( 'admin_enqueue_scripts', $rtwwpcp_plugin_admin, 'rtwwpcp_enqueue_styles' );
		$this->rtwwpcp_loader->rtwwpcp_add_action( 'admin_enqueue_scripts', $rtwwpcp_plugin_admin, 'rtwwpcp_enqueue_scripts' );
		$this->rtwwpcp_loader->rtwwpcp_add_action('admin_menu', $rtwwpcp_plugin_admin, 'rtwwpcp_add_menu_page');
		$this->rtwwpcp_loader->rtwwpcp_add_action('admin_init', $rtwwpcp_plugin_admin, 'rtwwpcp_save_admin_setting');
		$this->rtwwpcp_loader->rtwwpcp_add_action('bulk_actions-edit-product', $rtwwpcp_plugin_admin, 'rtwwpcp_custom_action_product_table');
		$this->rtwwpcp_loader->rtwwpcp_add_action('handle_bulk_actions-edit-product', $rtwwpcp_plugin_admin, 'rtwwpcp_handel_custom_action_product_table', '', 3);
		$this->rtwwpcp_loader->rtwwpcp_add_action('save_post', $rtwwpcp_plugin_admin, 'rtwwpcp_pdf_delete');
		$this->rtwwpcp_loader->rtwwpcp_add_action('add_meta_boxes', $rtwwpcp_plugin_admin, 'rtwwpcp_add_meta_box',10,2);
		$this->rtwwpcp_loader->rtwwpcp_add_action('wp_ajax_rtwwpcp_create_single_product_pdf', $rtwwpcp_plugin_admin, 'rtwwpcp_make_single_product_pdf');
		if ( isset($_GET['rtwwpcp_product_id']) && $_GET['rtwwpcp_product_id'] != '' ) {
			$this->rtwwpcp_loader->rtwwpcp_add_action('init', $rtwwpcp_plugin_admin, 'rtwwpcp_make_single_product_pdf');
		}
	}

	/**
	 * Register all of the hooks related to the public-facing functionality
	 * of the plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function rtwwpcp_define_public_hooks() {

		$rtwwpcp_plugin_public = new Rtwwpcp_Woocommerce_Pdf_Catalog_Pro_Public( $this->rtwwpcp_get_plugin_name(), $this->rtwwpcp_get_version() );

		$this->rtwwpcp_loader->rtwwpcp_add_action( 'wp_enqueue_scripts', $rtwwpcp_plugin_public, 'rtwwpcp_enqueue_styles' );
		$this->rtwwpcp_loader->rtwwpcp_add_action( 'wp_enqueue_scripts', $rtwwpcp_plugin_public, 'rtwwpcp_enqueue_scripts' );
		$this->rtwwpcp_loader->rtwwpcp_add_action('wp', $rtwwpcp_plugin_public, 'rtwwpcp_genrate_shrtcode_function');

		if ( isset($_GET['rtwwpcp_generate_catalog']) || isset($_GET['rtwwpcp_generate_cat_catalog']) ) 
		{
			$this->rtwwpcp_loader->rtwwpcp_add_action('wp', $rtwwpcp_plugin_public, 'rtwwpcp_generate_pdf_catalog' );
		}

		if ( isset($_GET['rtwwpcp_generate_sngl_pdf']) && !empty($_GET['rtwwpcp_generate_sngl_pdf']) ) 
		{
			$this->rtwwpcp_loader->rtwwpcp_add_action('wp', $rtwwpcp_plugin_public, 'rtwwpcp_prnt_sngl_prdct_pdf' );
		}

		$rtwwpcp_opt = get_option( 'rtwwpcp_basic_setting_opt' );
		if ( isset($rtwwpcp_opt['sngl_prod_btn']) && $rtwwpcp_opt['sngl_prod_btn'] != '' ) 
		{
			$this->rtwwpcp_loader->rtwwpcp_add_action($rtwwpcp_opt['sngl_prod_btn'], $rtwwpcp_plugin_public, 'rtwwpcp_show_prodct_btn' );
		}else{
			$this->rtwwpcp_loader->rtwwpcp_add_action('woocommerce_after_single_product_summary', $rtwwpcp_plugin_public, 'rtwwpcp_show_prodct_btn' );
		}
		$this->rtwwpcp_loader->rtwwpcp_add_action('woocommerce_archive_description', $rtwwpcp_plugin_public, 'rtwwpcp_show_btn_on_categry_page' );
		$this->rtwwpcp_loader->rtwwpcp_add_action('save_post', $rtwwpcp_plugin_public, 'rtwwpcp_delete_pdf');
	}

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

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

	/**
	 * The reference to the class that orchestrates the hooks with the plugin.
	 *
	 * @since     1.0.0
	 * @return    Woocommerce_Pdf_Catalog_Pro_Loader    Orchestrates the hooks of the plugin.
	 */
	public function rtwwpcp_get_loader() {
		return $this->rtwwpcp_loader;
	}

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

}
