PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /home/trave494/polo-family.com/wp-content/plugins/wwcAliAff/modules/stats_prod/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //home/trave494/polo-family.com/wp-content/plugins/wwcAliAff/modules/stats_prod/init.php

<?php
/*
* Define class wwcAliAffStatsProd
* Make sure you skip down to the end of this file, as there are a few
* lines of code that are very important.
*/
!defined('ABSPATH') and exit;
      
if (class_exists('wwcAliAffStatsProd') != true) {
    class wwcAliAffStatsProd
    {
        /*
        * Some required plugin information
        */
        const VERSION = '1.0';

        /*
        * Store some helpers config
        */
		public $the_plugin = null;

		private $module_folder = '';
		private $module = '';

		static protected $_instance;

        /*
        * Required __construct() function that initalizes the AA-Team Framework
        */
        public function __construct()
        {
        	global $wwcAliAff;

        	$this->the_plugin = $wwcAliAff;
			$this->module_folder = $this->the_plugin->cfg['paths']['plugin_dir_url'] . 'modules/stats_prod/';
			$this->module = $this->the_plugin->cfg['modules']['stats_prod'];
   
			if (is_admin()) {
	            add_action('admin_menu', array( &$this, 'adminMenu' ));
			}

			if ( $this->the_plugin->is_admin !== true ) {
				$this->addFrontFilters();
			}
        }

		/**
	    * Singleton pattern
	    *
	    * @return wwcAliAffStatsProd Singleton instance
	    */
	    static public function getInstance()
	    {
	        if (!self::$_instance) {
	            self::$_instance = new self;
	        }

	        return self::$_instance;
	    }

		/**
	    * Hooks
	    */
	    static public function adminMenu()
	    {
	       self::getInstance()
	    		->_registerAdminPages();
	    }

	    /**
	    * Register plug-in module admin pages and menus
	    */
		protected function _registerAdminPages()
    	{
    		add_submenu_page(
    			$this->the_plugin->alias,
    			$this->the_plugin->alias . " " . __('Products Stats', $this->the_plugin->localizationName),
	            __('Products Stats', $this->the_plugin->localizationName),
	            'manage_options',
	            $this->the_plugin->alias . "_stats_prod",
	            array($this, 'display_index_page')
	        );

			return $this;
		}

		public function display_index_page()
		{
			$this->printBaseInterface();
		}
		
		/**
		 * frontend methods: update hits & add to cart for alibaba product!
		 *
		 */
		public function addFrontFilters() {
			add_action('wp', array( $this, 'frontend' ), 0);
			
			add_action('woocommerce_add_to_cart', array($this, 'add_to_cart'), 1, 6); // add item to cart
			add_action('wp_ajax_woocommerce_add_to_cart', array($this, 'add_to_cart_ajax'), 0);
			add_action('wp_ajax_nopriv_woocommerce_add_to_cart', array($this, 'add_to_cart_ajax'), 0);
		}

		public function frontend() {
			global $wpdb, $wp;

			// $currentUri = home_url(add_query_arg(array(), $wp->request));

			if ( !is_admin() /*&& is_singular()*/ ) {
				global $post;
				$post_id = (int)$post->ID;
  
				// verify if it's an woocommerce alibaba product!
				if ( $post_id <= 0 || !$this->the_plugin->verify_product_isalibaba($post_id) )
					return false;
 	
				// update hits
				$hits = (int) get_post_meta($post_id, '_wwcaliaff_hits', true);
				update_post_meta($post_id, '_wwcaliaff_hits', (int)($hits+1));
			}
		}

		public function add_to_cart_validation( $passed, $product_id, $quantity, $variation_id='', $variations='' ) {
			if ( !is_admin() ) {
				$post_id = $product_id;

				// verify if it's an woocommerce alibaba product!
				if ( $post_id <= 0 || !$this->the_plugin->verify_product_isalibaba($post_id) )
					return false;
				
				$addtocart = (int) get_post_meta($post_id, '_wwcaliaff_addtocart', true);
				update_post_meta($post_id, '_wwcaliaff_addtocart', (int)($addtocart+1));
				
				return true;
			}
		}
		
		public function add_to_cart_ajax() {
			global $woocommerce;
  
			check_ajax_referer( 'add-to-cart', 'security' );
			
			$product_id = (int) apply_filters('woocommerce_add_to_cart_product_id', $_POST['product_id']);
			
			$passed_validation = apply_filters('woocommerce_add_to_cart_validation', true, $product_id, 1);
			
			if ($passed_validation && $woocommerce->cart->add_to_cart($product_id, 1)) :
				// Return html fragments
				$data = apply_filters('add_to_cart_fragments', array());
				
				$post_id = $product_id;

				// verify if it's an woocommerce alibaba product!
				if ( $post_id <= 0 || !$this->the_plugin->verify_product_isalibaba($post_id) )
					return false;
				
				$addtocart = (int) get_post_meta($post_id, '_wwcaliaff_addtocart', true);
				update_post_meta($post_id, '_wwcaliaff_addtocart', (int)($addtocart+1));
			else :
				// If there was an error adding to the cart, redirect to the product page to show any errors
				$data = array(
					'error' => true,
					'product_url' => get_permalink( $product_id )
				);
				$woocommerce->set_messages();
			endif;
			
			echo json_encode( $data );
			
			die();
		}
		
		public function add_to_cart( $cart_item_key='', $product_id='', $quantity='', $variation_id='', $variation='', $cart_item_data='' ) {
  
			if ( !is_admin() ) {
				$post_id = $product_id;

				// verify if it's an woocommerce alibaba product!
				if ( $post_id <= 0 || !$this->the_plugin->verify_product_isalibaba($post_id) )
					return false;
				
				$addtocart = (int) get_post_meta($post_id, '_wwcaliaff_addtocart', true);
				update_post_meta($post_id, '_wwcaliaff_addtocart', (int)($addtocart+1));

				return true;
			}
		}
		

		/*
		* printBaseInterface, method
		* --------------------------
		*
		* this will add the base DOM code for you options interface
		*/
		private function printBaseInterface()
		{
			global $wpdb;
?>
		<script type="text/javascript" src="<?php echo $this->module_folder;?>app.class.js" ></script>
		<div id="wwcAliAff-wrapper" class="fluid wrapper-wwcAliAff">
			
			<?php
			// show the top menu
			wwcAliAffAdminMenu::getInstance()->make_active('info|stats_prod')->show_menu(); 
			?>

			<!-- Content -->
			<div id="wwcAliAff-content">
				
				<h1 class="wwcAliAff-section-headline">
					<?php 
					if( isset($this->module['stats_prod']['in_dashboard']['icon']) ){
						echo '<img src="' . ( $this->module_folder . $this->module['stats_prod']['in_dashboard']['icon'] ) . '" class="wwcAliAff-headline-icon">';
					}
					?>
					<?php echo $this->module['stats_prod']['menu']['title'];?>
					<span class="wwcAliAff-section-info"><?php echo $this->module['stats_prod']['description'];?></span>
					<?php
					$has_help = isset($this->module['stats_prod']['help']) ? true : false;
					if( $has_help === true ){
						
						$help_type = isset($this->module['stats_prod']['help']['type']) && $this->module['stats_prod']['help']['type'] ? 'remote' : 'local';
						if( $help_type == 'remote' ){
							echo '<a href="#load_docs" class="wwcAliAff-show-docs" data-helptype="' . ( $help_type ) . '" data-url="' . ( $this->module['stats_prod']['help']['url'] ) . '">HELP</a>';
						} 
					}
					echo '<a href="#load_docs" class="wwcAliAff-show-feedback" data-helptype="' . ( 'remote' ) . '" data-url="' . ( $this->the_plugin->feedback_url ) . '" data-operation="feedback">Feedback</a>';
					?>
				</h1>
				
				<!-- Main loading box -->
				<div id="wwcAliAff-main-loading">
					<div id="wwcAliAff-loading-overlay"></div>
					<div id="wwcAliAff-loading-box">
						<div class="wwcAliAff-loading-text"><?php _e('Loading', $this->the_plugin->localizationName);?></div>
						<div class="wwcAliAff-meter wwcAliAff-animate" style="width:86%; margin: 34px 0px 0px 7%;"><span style="width:100%"></span></div>
					</div>
				</div>

				<!-- Container -->
				<div class="wwcAliAff-container clearfix">

					<!-- Main Content Wrapper -->
					<div id="wwcAliAff-content-wrap" class="clearfix">

						<!-- Content Area -->
						<div id="wwcAliAff-content-area">
							<div class="wwcAliAff-grid_4">
	                        	<div class="wwcAliAff-panel">
	                        		<!--div class="wwcAliAff-panel-header">
										<span class="wwcAliAff-panel-title">
											<?php _e('Synchronization logs', $this->the_plugin->localizationName);?>
										</span>
									</div-->
									<div class="wwcAliAff-panel-content">
										<form class="wwcAliAff-form" action="#save_with_ajax">
											<div class="wwcAliAff-form-row wwcAliAff-table-ajax-list" id="wwcAliAff-table-ajax-response">
											<?php
											wwcAliAffAjaxListTable::getInstance( $this->the_plugin )
												->setup(array(
													'id' 				=> 'wwcAliAffPriceUpdateMonitor',
													'show_header' 		=> true,
													'search_box' 		=> false,
													'items_per_page' 	=> '15',
													'post_statuses' 	=> array(
														'publish'   => __('Published', $this->the_plugin->localizationName)
													),
													'list_post_types'	=> array('product'),
													'columns'			=> array(

														'id'		=> array(
															'th'	=> __('ID', $this->the_plugin->localizationName),
															'td'	=> '%ID%',
															'width' => '40'
														),
														
														'thumb'		=> array(
															'th'	=> __('Thumb', $this->the_plugin->localizationName),
															'td'	=> '%thumb%',
															'align' => 'center',
															'width' => '50'
														),
														
														'wwcaliaff_sku'		=> array(
															'th'	=> __('Alibaba SKU', $this->the_plugin->localizationName),
															'td'	=> '%wwcaliaff_sku%',
															'align' => 'center',
															'width' => '70'
														),

														'title'		=> array(
															'th'	=> __('Title', $this->the_plugin->localizationName),
															'td'	=> '%title%',
															'align' => 'left'
														),
														/*
														'price'		=> array(
															'th'	=> __('Price', $this->the_plugin->localizationName),
															'td'	=> '%price%',
															'align' => 'left',
															'width' => '160'
														),*/
														
														'hits'		=> array(
															'th'	=> __('Hits', $this->the_plugin->localizationName),
															'td'	=> '%hits%',
															'align' => 'center',
															'width' => '70'
														),
														
														/*'added_to_cart'		=> array(
															'th'	=> __('Added to cart', $this->the_plugin->localizationName),
															'td'	=> '%added_to_cart%',
															'align' => 'center',
															'width' => '90'
														),*/
														
														'redirected_to_alibaba'	=> array(
															'th'	=> __('Redirected to Alibaba', $this->the_plugin->localizationName),
															'td'	=> '%redirected_to_alibaba%',
															'align' => 'center',
															'width' => '140'
														),
														
														'date'		=> array(
															'th'	=> __('Date Added', $this->the_plugin->localizationName),
															'td'	=> '%date%',
															'width' => '120'
														),

														/*'optimize_btn' => array(
															'th'	=> __('Action', $this->the_plugin->localizationName),
															'td'	=> '%button%',
															'option' => array(
																'value' => __('Update product now', $this->the_plugin->localizationName),
																'action' => 'sync_now',
																'color' => 'blue'
															),
															'width' => '120'
														),*/
													)
												))
												->print_html();
								            ?>
								            </div>
							            </form>
				            		</div>
								</div>
							</div>
							<div class="clear"></div>
						</div>
					</div>
				</div>
			</div>
		</div>

<?php
		}
    }
}
 
// Initialize the wwcAliAffStatsProd class
$wwcAliAffStatsProd = wwcAliAffStatsProd::getInstance();