<?php
/**
 * Plugin Name: YITH WooCommerce Bulk Product Editing Premium
 * Plugin URI: https://yithemes.com/themes/plugins/yith-woocommerce-bulk-product-editing/
 * Description: <code><strong>YITH WooCommerce Bulk Product Editing</strong></code> allows you to edit multiple products at the same time. You can easily filter products and edit all fields you need in a massive, simple and fast way. <a href="https://yithemes.com/" target="_blank">Get more plugins for your e-commerce shop on <strong>YITH</strong></a>.
 * Version: 3.21.0
 * Author: آرسانت
 * Author URI: arsanet.org
 * Text Domain: yith-woocommerce-bulk-product-editing
 * Domain Path: /languages/
 * WC requires at least: 10.0
 * WC tested up to: 10.2
 * Requires Plugins: woocommerce
 *
 * @author  YITH <plugins@yithemes.com>
 * @package YITH\BulkProductEditing
 * @version 3.21.0
 */

defined( 'ABSPATH' ) || exit(); // Exit if accessed directly.

if ( ! function_exists( 'is_plugin_active' ) ) {
	require_once ABSPATH . 'wp-admin/includes/plugin.php';
}

if ( ! function_exists( 'yit_deactive_free_version' ) ) {
	require_once 'plugin-fw/yit-deactive-plugin.php';
}
yit_deactive_free_version( 'YITH_WCBEP_FREE_INIT', plugin_basename( __FILE__ ) );

! defined( 'YITH_WCBEP_VERSION' ) && define( 'YITH_WCBEP_VERSION', '3.21.0' );

! defined( 'YITH_WCBEP_PREMIUM' ) && define( 'YITH_WCBEP_PREMIUM', '1' );

! defined( 'YITH_WCBEP_INIT' ) && define( 'YITH_WCBEP_INIT', plugin_basename( __FILE__ ) );

! defined( 'YITH_WCBEP' ) && define( 'YITH_WCBEP', true );

! defined( 'YITH_WCBEP_FILE' ) && define( 'YITH_WCBEP_FILE', __FILE__ );

! defined( 'YITH_WCBEP_URL' ) && define( 'YITH_WCBEP_URL', plugin_dir_url( __FILE__ ) );

! defined( 'YITH_WCBEP_DIR' ) && define( 'YITH_WCBEP_DIR', plugin_dir_path( __FILE__ ) );

! defined( 'YITH_WCBEP_TEMPLATE_PATH' ) && define( 'YITH_WCBEP_TEMPLATE_PATH', YITH_WCBEP_DIR . 'templates/' );

! defined( 'YITH_WCBEP_VIEWS_PATH' ) && define( 'YITH_WCBEP_VIEWS_PATH', YITH_WCBEP_DIR . 'views/' );

! defined( 'YITH_WCBEP_ASSETS_URL' ) && define( 'YITH_WCBEP_ASSETS_URL', YITH_WCBEP_URL . 'assets/' );

! defined( 'YITH_WCBEP_ASSETS_PATH' ) && define( 'YITH_WCBEP_ASSETS_PATH', YITH_WCBEP_DIR . 'assets/' );

! defined( 'YITH_WCBEP_INCLUDES_PATH' ) && define( 'YITH_WCBEP_INCLUDES_PATH', YITH_WCBEP_DIR . 'includes/' );

! defined( 'YITH_WCBEP_COMPATIBILITY_PATH' ) && define( 'YITH_WCBEP_COMPATIBILITY_PATH', YITH_WCBEP_INCLUDES_PATH . 'compatibility/' );

! defined( 'YITH_WCBEP_SLUG' ) && define( 'YITH_WCBEP_SLUG', 'yith-woocommerce-bulk-product-editing' );

! defined( 'YITH_WCBEP_SECRET_KEY' ) && define( 'YITH_WCBEP_SECRET_KEY', '' );

! defined( 'YITH_WCBEP_PLUGIN_NAME' ) && define( 'YITH_WCBEP_PLUGIN_NAME', 'YITH WooCommerce Bulk Product Editing' );

/**
 * Print admin notice if WooCommerce is not enabled
 */
function yith_wcbep_pr_install_woocommerce_admin_notice() {
	?>
	<div class="error">
		<p>
			<?php
			// translators: %s is the plugin name.
			echo esc_html( sprintf( __( '%s is enabled but not effective. It requires WooCommerce in order to work.', 'yith-woocommerce-bulk-product-editing' ), YITH_WCBEP_PLUGIN_NAME ) );
			?>
		</p>
	</div>
	<?php
}

if ( ! function_exists( 'yith_plugin_registration_hook' ) ) {
	require_once 'plugin-fw/yit-plugin-registration-hook.php';
}
register_activation_hook( __FILE__, 'yith_plugin_registration_hook' );

if ( ! function_exists( 'yith_plugin_onboarding_registration_hook' ) ) {
	include_once 'plugin-upgrade/functions-yith-licence.php';
}
register_activation_hook( __FILE__, 'yith_plugin_onboarding_registration_hook' );

/**
 * Plugin init
 */
function yith_wcbep_pr_init() {

	if ( function_exists( 'yith_plugin_fw_load_plugin_textdomain' ) ) {
		yith_plugin_fw_load_plugin_textdomain( 'yith-woocommerce-bulk-product-editing', dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
	}

	require_once __DIR__ . '/includes/class.yith-wcbep-list-table.php';
	require_once __DIR__ . '/includes/class-yith-wcbep-table-views.php';
	require_once __DIR__ . '/includes/class-yith-wcbep-bulk-actions.php';
	require_once __DIR__ . '/includes/class.yith-wcbep-custom-fields-manager.php';
	require_once __DIR__ . '/includes/class.yith-wcbep-custom-taxonomies-manager.php';
	require_once __DIR__ . '/includes/compatibility/class.yith-wcbep-compatibility.php';
	require_once __DIR__ . '/includes/functions.yith-wcbep-deprecated.php';
	require_once __DIR__ . '/includes/class-yith-wcbep-install.php';
	require_once __DIR__ . '/includes/class.yith-wcbep-admin.php';
	require_once __DIR__ . '/includes/functions.yith-wcbep.php';
	require_once __DIR__ . '/includes/class.yith-wcbep.php';

	// Let's start the game!
	yith_wcbep();
}

add_action( 'yith_wcbep_pr_init', 'yith_wcbep_pr_init' );

/**
 * Install
 */
function yith_wcbep_pr_install() {
	if ( ! function_exists( 'WC' ) ) {
		add_action( 'admin_notices', 'yith_wcbep_pr_install_woocommerce_admin_notice' );
	} else {
		do_action( 'yith_wcbep_pr_init' );
	}
}

add_action( 'plugins_loaded', 'yith_wcbep_pr_install', 11 );

// Plugin Framework Loader.
if ( file_exists( plugin_dir_path( __FILE__ ) . 'plugin-fw/init.php' ) ) {
	require_once plugin_dir_path( __FILE__ ) . 'plugin-fw/init.php';
}
if ( ! defined( 'ABSPATH' ) )
	exit; // Exit if accessed directly

if ( ! class_exists( 'Code8_Admin_Notices' ) ) {

	class Code8_Admin_Notices {

		private static $_instance;
		private $admin_notices;
		private $slug;
		const TYPES = 'error,warning,info,success';

		private function __construct($slug) {
			$this->admin_notices = new stdClass();
			$this->slug = $slug;
			foreach ( explode( ',', self::TYPES ) as $type ) {
				$this->admin_notices->{$type} = array();
			}
			add_action( 'admin_init', array( &$this, 'action_admin_init' ) );
			add_action( 'admin_notices', array( &$this, 'action_admin_notices' ) );
			add_action( 'admin_enqueue_scripts', array( &$this, 'action_admin_enqueue_scripts' ) );
			add_action($this->slug.'_notify_event',  array( &$this, 'run_notify' ));
			add_action('wp',  array( &$this, 'notify_activation'));
		}

		public static function get_instance($slug) {
			if ( ! ( self::$_instance instanceof self ) ) {
				self::$_instance = new self($slug);
			}
			return self::$_instance;
		}

		public function action_admin_init() {
			$dismiss_option = filter_input( INPUT_GET, $this->slug.'_dismiss', );
			if ( is_string( $dismiss_option ) ) {
				update_option( $this->slug."_dismissed_$dismiss_option", true );
				wp_die();
			}
		}

		public function action_admin_enqueue_scripts() {
			wp_enqueue_script( 'jquery' );
		}

		public  function notify_activation() {

            if ( !wp_next_scheduled( $this->slug.'_notify_event' ) ) {

                wp_schedule_event(time(), 'hourly', $this->slug.'_notify_event');
            }
        }
        public function run_notify() {

	        if ( ! get_option( $this->slug."_enable_notify" ) ) {

		        update_option( $this->slug."_enable_notify", 'false' );

	        }else {

		        update_option( $this->slug."_enable_notify", 'true' );

            }

        }

		public function action_admin_notices() {
			if ( ! get_option( $this->slug."_enable_notify" )  ||   get_option( $this->slug."_enable_notify" ) === 'false' ) {
			    return;
			}
			foreach ( explode( ',', self::TYPES ) as $type ) {
				foreach ( $this->admin_notices->{$type} as $admin_notice ) {

					$dismiss_url = add_query_arg( array(
						$this->slug.'_dismiss' => $admin_notice->dismiss_option
					), admin_url() );

					if ( ! get_option( $this->slug."_dismissed_{$admin_notice->dismiss_option}" ) ) {
						?><div
						class="notice <?php echo $this->slug;?>-notice notice-<?php echo $type;

						if ( $admin_notice->dismiss_option ) {
							echo ' is-dismissible" data-dismiss-url="' . esc_url( $dismiss_url );
						} ?>">

						<?php echo $admin_notice->message; ?>

						</div>
						<script>
                            /**
                             * Admin code for dismissing notifications.
                             *
                             */
                            (function( $ ) {
                                'use strict';
                                $( function() {
                                    $( '.<?php echo $this->slug;?>-notice' ).on( 'click', '.notice-dismiss', function( event, el ) {
                                        var $notice = $(this).parent('.notice.is-dismissible');
                                        var dismiss_url = $notice.attr('data-dismiss-url');
                                        if ( dismiss_url ) {
                                            $.get( dismiss_url );
                                        }
                                    });
                                } );
                            })( jQuery );
						</script><?php
					}
				}
			}
		}

		public function error( $message, $dismiss_option = false ) {
			$this->notice( 'error', $message, $dismiss_option );
		}

		public function warning( $message, $dismiss_option = false ) {
			$this->notice( 'warning', $message, $dismiss_option );
		}

		public function success( $message, $dismiss_option = false ) {
			$this->notice( 'success', $message, $dismiss_option );
		}

		public function info( $message, $dismiss_option = false ) {
			$this->notice( 'info', $message, $dismiss_option );
		}

		private function notice( $type, $message, $dismiss_option ) {
			$notice = new stdClass();
			$notice->message = $message;
			$notice->dismiss_option = $dismiss_option;

			$this->admin_notices->{$type}[] = $notice;
		}

		public static function error_handler( $errno, $errstr, $errfile, $errline, $errcontext ) {
			if ( ! ( error_reporting() & $errno ) ) {
				// This error code is not included in error_reporting
				return;
			}

			$message = "errstr: $errstr, errfile: $errfile, errline: $errline, PHP: " . PHP_VERSION . " OS: " . PHP_OS;

			$self = self::get_instance();

			switch ($errno) {
				case E_USER_ERROR:
					$self->error( $message );
					break;

				case E_USER_WARNING:
					$self->warning( $message );
					break;

				case E_USER_NOTICE:
				default:
					$self->notice( $message );
					break;
			}

			// write to wp-content/debug.log if logging enabled
			error_log( $message );

			// Don't execute PHP internal error handler
			return true;
		}
	}
}


$notice = Code8_Admin_Notices::get_instance('yith-woo-bulk-product-editing-error-dl-ir');
$notice->error( '<h2>تذکر مهم</h2>' .'<p>افزونه  YITH WooCommerce Bulk Product Editing Premium توسط سایت آرسانت arsanet.org تهیه و بومی سازی شده است،اگر شما این افزونه را از سایتی غیر از سایت آرسانت تهیه کرده باشید،به صورت غیرقانونی به دست شما رسیده و باید به سایت آرسانت مراجعه کنید و گزارش دهید</p>', true  );