PK œqhYî¶J‚ßF ßF ) nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/
Dir : /home/trave494/polo-family.com/wp-content/plugins/aawzone-ebay/include/helpers/ |
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 |
Dir : //home/trave494/polo-family.com/wp-content/plugins/aawzone-ebay/include/helpers/template.class.php |
<?php /* * Define class WooZoneProviderEbay_Template * 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('WooZoneProviderEbay_Template') != true) { class WooZoneProviderEbay_Template { /* * Some required plugin information */ const VERSION = '1.0'; public $post_type = ''; public $cfg = array(); public $template_directory = ''; public $the_plugin = array(); /* * Required __construct() function that initalizes the WooZoneProviderEbay_Template */ public function __construct( $the_plugin=array() ) { $this->the_plugin = $the_plugin; add_action( 'woocommerce_no_products_found', array($this, 'add_html_marker') ); add_action( 'wp_enqueue_scripts', array( $this, 'add_styles' ), 10); add_action( 'wp_ajax_' . $this->the_plugin->alias . '_frontend_style', array( $this, 'frontend_style' ) ); add_action( 'wp_ajax_nopriv_' . $this->the_plugin->alias . '_frontend_style', array( $this, 'frontend_style' ) ); add_action( 'wp_ajax_' . $this->the_plugin->alias . '_save_stats', array( $this, 'save_stats' ) ); add_action( 'wp_footer', array($this, 'not_found_box') ); } public function add_styles() { wp_enqueue_style( WooZoneProviderEbay()->alias . '-Droid+Sans', 'https://fonts.googleapis.com/css?family=Droid+Sans:400,700', array(), '1.0' ); //wp_enqueue_style( WooZoneProviderEbay()->alias . '-amazon-styles', WooZoneProviderEbay()->assetUrl('frontend.css'), array(), '1.0' ); wp_enqueue_style( WooZoneProviderEbay()->alias . '-rating', WooZoneProviderEbay()->assetUrl('star-rating-svg.css'), array(), '1.0' ); wp_enqueue_script( WooZoneProviderEbay()->alias . '-amazon-rating', WooZoneProviderEbay()->assetUrl('jquery.star-rating-svg.js'), array( 'jquery' ) ); //wp_enqueue_script( WooZoneProviderEbay()->alias . '-amazon', WooZoneProviderEbay()->assetUrl('frontend.js'), array( 'jquery' ) ); wp_localize_script( WooZoneProviderEbay()->alias . '-amazon', WooZoneProviderEbay()->alias . '_custom', array( 'ajaxurl' => admin_url('admin-ajax.php') )); wp_enqueue_style( WooZoneProviderEbay()->alias . '-frontend_style', admin_url( 'admin-ajax.php?action=' . WooZoneProviderEbay()->alias . '_frontend_style' ), array(), '1.0' ); if( count($this->the_plugin->settings['setup']['template_typography']) > 0 ){ $google_fonts = array(); foreach ($this->the_plugin->settings['setup']['template_typography'] as $key => $value) { $google_fonts[] = str_replace( " ", "+", $value['family']); } $google_fonts = array_unique( $google_fonts ); wp_enqueue_style( WooZoneProviderEbay()->alias . '-googlefonts', '//fonts.googleapis.com/css?family=' . implode( "|", $google_fonts ), array(), '1.0' ); } } public function get_client_ip() { $ipaddress = ''; if ($_SERVER['REMOTE_ADDR']) $ipaddress = $_SERVER['REMOTE_ADDR']; else if ($_SERVER['HTTP_CLIENT_IP']) $ipaddress = $_SERVER['HTTP_CLIENT_IP']; else if ($_SERVER['HTTP_X_FORWARDED']) $ipaddress = $_SERVER['HTTP_X_FORWARDED']; else if ($_SERVER['HTTP_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; else if( $_SERVER['HTTP_FORWARDED']) $ipaddress = $_SERVER['HTTP_FORWARDED']; else if ($_SERVER['HTTP_X_FORWARDED_FOR']) $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; return $ipaddress; } public function ip2number( $ip ) { $long = ip2long($ip); if ($long == -1 || $long === false) { return false; } return sprintf("%u", $long); } /** * Parameters: * $key - The key to be searched for. * $list - The sorted array. * $compare_func - A user defined function for comparison. Same definition as the one in usort * $low - First index of the array to be searched (local parameters). * $high - Last index of the array to be searched (local parameters). * * Return: * index of the search key if found, otherwise return -(insert_index + 1). * insert_index is the index of greatest element that is smaller than $key or count($list) if $key * is larger than all elements in the array. * * License: Feel free to use the code if you need it. */ public function binary_search($key, array $list, $compare_func) { $low = 0; $high = count($list) - 1; while ($low <= $high) { $mid = (int) (($high - $low) / 2) + $low; // could use php ceil function $cmp = call_user_func($compare_func, $list[$mid], $key); if ($cmp < 0) { $low = $mid + 1; } else if ($cmp > 0) { $high = $mid - 1; } else { return $mid; } } return -($low - 1); } public function binary_search_cmp($a, $b) { return ($a < $b) ? -1 : (($a > $b) ? 1 : 0); } public function get_country_perip_external( $return_field='country' ) { $geo_targeting_settings = $this->the_plugin->settings['setup']['geo_targeting']; if( $geo_targeting_settings['geo_status'] == 'off' ){ return 'geo_off'; } //unset($_SESSION[ WooZoneProviderEbay()->alias . "_country" ]); // for debugging... if ( isset($_SESSION[ WooZoneProviderEbay()->alias . "_country" ]) && !empty($_SESSION[ WooZoneProviderEbay()->alias . "_country" ]) ) { if ( $return_field == 'country' ) { return unserialize($_SESSION[ WooZoneProviderEbay()->alias . "_country" ]); } } //$ip = '207.154.230.183'; $ip = $this->get_client_ip(); $config = array( 'services_used_forip' => $geo_targeting_settings['service'] ); $paths = array( 'api.hostip.info' => 'http://api.hostip.info/country.php?ip={ipaddress}', 'www.geoplugin.net' => 'http://www.geoplugin.net/json.gp?ip={ipaddress}', 'www.telize.com' => 'http://www.telize.com/geoip/{ipaddress}', 'ipinfo.io' => 'http://ipinfo.io/{ipaddress}/geo', ); $service_used = 'www.geoplugin.net'; if ( isset($config['services_used_forip']) && !empty($config['services_used_forip']) ) { $service_used = $config['services_used_forip']; } $country = ''; if ( $service_used == 'local_csv' ) { // local csv file with ip lists // read csv hash (string with ip from list) $csv_hash = $this->the_plugin->wp_filesystem->get_contents( $this->the_plugin->path( 'ASSETS_DIR', 'GeoIPCountryWhois-hash.csv' ) ); $csv_hash = explode(',', $csv_hash); // read csv full (ip from, ip to, country) $csv_full = $this->the_plugin->wp_filesystem->get_contents( $this->the_plugin->path( 'ASSETS_DIR', 'GeoIPCountryWhois-full.csv' ) ); $csv_full = explode(PHP_EOL, $csv_full); //var_dump('<pre>',count($csv_hash), count($csv_full),'</pre>'); //var_dump('<pre>',$csv_hash, $csv_full,'</pre>'); $ip2number = $this->ip2number( $ip ); //var_dump('<pre>', $ip, $ip2number, '</pre>'); $ipHashIndex = $this->binary_search($ip2number, $csv_hash, array($this, 'binary_search_cmp')); if ( $ipHashIndex < 0 ) { // verify if is between (ip_from, ip_to) of csv row $ipHashIndex = abs( $ipHashIndex ); $ipFullRow = $csv_full["$ipHashIndex"]; $csv_row = explode(',', $ipFullRow); if ( $ip2number >= $csv_row[0] && $ip2number <= $csv_row[1] ) { $country = $csv_row[2]; } } else { // exact match in the list as ip_from of csv row $ipFullRow = $csv_full["$ipHashIndex"]; $country = end( explode(',', $ipFullRow) ); } if (empty($country)) { //$main_aff_site = $this->main_aff_site(); //$country = strtoupper(str_replace(".", '', $main_aff_site)); $country = 'NOT-FOUND'; } $country = strtoupper( $country ); //echo __FILE__ . ":" . __LINE__;die . PHP_EOL; } else { // external service $service_url = $paths["$service_used"]; $service_url = str_replace('{ipaddress}', $ip, $service_url); //$get_user_location = wp_remote_get( $service_url ); $get_user_location = file_get_contents( $service_url ); //die( var_dump( "<pre>", $get_user_location, $service_url , "</pre>" ) . PHP_EOL . __FILE__ . ":" . __LINE__ ); if ( isset($get_user_location->errors) ) { //$main_aff_site = $this->main_aff_site(); //$country = strtoupper(str_replace(".", '', $main_aff_site)); $country = 'NOT-FOUND'; } else { $country = $get_user_location; switch ($service_used) { case 'api.hostip.info': break; case 'www.geoplugin.net': $country = json_decode($country); $country = strtoupper( $country->geoplugin_countryCode ); break; case 'www.telize.com': $country = json_decode($country); $country = strtoupper( $country->country_code ); break; case 'ipinfo.io': $country = json_decode($country); $country = strtoupper( $country->country ); break; default: break; } } } if ( $return_field == 'country' ) { $_SESSION[ WooZoneProviderEbay()->alias . "_country" ] = serialize($country); return $country; } } public function frontend_style() { // Set the correct MIME type, because Apache won't set it for us header("Content-type: text/css"); $settings = $this->the_plugin->settings['setup']; $css = array(); // custom cases here ... if( isset($settings['products_per_column']) ){ $css[] = " body .WooZoneProviderEbay-amazon-response { grid-template-columns: repeat(" . ( $settings['products_per_column'] ) . ", minmax(0, 1fr)); } "; } if( isset($settings['template_typography']['headline']) ){ $css[] = " body .WooZoneProviderEbay-box-title { font-family: '" . ( $settings['template_typography']['headline']['family'] ) . "'; font-size: " . ( $settings['template_typography']['headline']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['headline']['weight'] ) . "; color: " . ( $settings['template_typography']['headline']['color'] ) . "; } "; } if( isset($settings['template_typography']['product_title']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-title { font-family: '" . ( $settings['template_typography']['product_title']['family'] ) . "'; font-size: " . ( $settings['template_typography']['product_title']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['product_title']['weight'] ) . "; color: " . ( $settings['template_typography']['product_title']['color'] ) . "; } "; } if( isset($settings['template_typography']['product_sub_title']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-subtitle { font-family: '" . ( $settings['template_typography']['product_sub_title']['family'] ) . "'; font-size: " . ( $settings['template_typography']['product_sub_title']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['product_sub_title']['weight'] ) . "; color: " . ( $settings['template_typography']['product_sub_title']['color'] ) . "; } "; } if( isset($settings['template_typography']['nb_of_reviews']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-rating-totals { font-family: '" . ( $settings['template_typography']['nb_of_reviews']['family'] ) . "'; font-size: " . ( $settings['template_typography']['nb_of_reviews']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['nb_of_reviews']['weight'] ) . "; color: " . ( $settings['template_typography']['nb_of_reviews']['color'] ) . "; } "; } if( isset($settings['template_typography']['regular_price']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-price div { font-family: '" . ( $settings['template_typography']['regular_price']['family'] ) . "'; font-size: " . ( $settings['template_typography']['regular_price']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['regular_price']['weight'] ) . "; color: " . ( $settings['template_typography']['regular_price']['color'] ) . "; } "; } if( isset($settings['template_typography']['sale_price']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-price .WooZoneProviderEbay-new-price { font-family: '" . ( $settings['template_typography']['sale_price']['family'] ) . "'; font-size: " . ( $settings['template_typography']['sale_price']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['sale_price']['weight'] ) . "; color: " . ( $settings['template_typography']['sale_price']['color'] ) . "; } "; } if( isset($settings['template_typography']['buy_btn']) ){ $css[] = " body .WooZoneProviderEbay-amazon-products .WooZoneProviderEbay-product .WooZoneProviderEbay-button { font-family: '" . ( $settings['template_typography']['buy_btn']['family'] ) . "'; font-size: " . ( $settings['template_typography']['buy_btn']['size'] ) . "px; font-weight: " . ( $settings['template_typography']['buy_btn']['weight'] ) . "; color: " . ( $settings['template_typography']['buy_btn']['color'] ) . "; background-color: " . ( $settings['template_typography']['buy_btn']['background-color'] ) . "; } "; } $buffer = implode( "\n", $css ); // Remove comments $buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); // Remove space after colons $buffer = str_replace(': ', ':', $buffer); // Remove whitespace $buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' '), '', $buffer); die( $buffer ); } private function amzForUser( $userCountry='US' ) { $amz_sites = $this->the_plugin->amazon_sites(); // when geo is off if( $userCountry == 'geo_off' ){ foreach ($this->the_plugin->settings['setup']['amazon_ids'] as $key => $value) { if( trim($value) != "" ){ return array( 'country' => $key, 'aff_id' => $value, 'amz_site_name' => $amz_sites[$key]['label'], 'website' => "." . @end( explode("amazon.", $amz_sites[$key]['url'] ) ) ); } } // some debug !!! return array( 'country' => 'com', 'aff_id' => 'YOU_NEED_TO_ADD_SOME_AFFIDs', 'amz_site_name' => 'United States', 'website' => '.com' ); } // when geo is ON $aff_id = $this->the_plugin->settings['setup']['amazon_ids'][$this->the_plugin->settings['setup']['geo_targeting']['default_aff']]; $country = $this->the_plugin->settings['setup']['geo_targeting']['default_aff']; $website = '.com'; if( trim($aff_id) == "" ){ $aff_id = 'YOU_NEED_TO_SETUP_VALID_MAIN_AFF_ID'; } if( $userCountry == 'US' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['com'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['com']; $country = 'com'; } } elseif( $userCountry == 'CA' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['ca'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['ca']; $country = 'ca'; } } elseif( $userCountry == 'FR' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['fr'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['fr']; $country = 'fr'; } } elseif( $userCountry == 'CN' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['cn'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['cn']; $country = 'cn'; } } elseif( $userCountry == 'DE' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['de'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['de']; $country = 'de'; } } elseif( $userCountry == 'IN' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['in'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['in']; $country = 'in'; } } elseif( $userCountry == 'IT' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['it'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['it']; $country = 'it'; } } elseif( $userCountry == 'JP' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['jp'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['jp']; $country = 'jp'; } } elseif( $userCountry == 'ES' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['es'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['es']; $country = 'es'; } } elseif( $userCountry == 'GB' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['uk'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['uk']; $country = 'uk'; } } elseif( $userCountry == 'MX' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['mx'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['mx']; $country = 'mx'; } } elseif( $userCountry == 'BR' ){ if( trim( $this->the_plugin->settings['setup']['amazon_ids']['br'] ) ){ $aff_id = $this->the_plugin->settings['setup']['amazon_ids']['br']; $country = 'br'; } } $amz_site_name = "United States"; if( isset($amz_sites[$country]) ){ $amz_site_name = $amz_sites[$country]['label']; $website = "." . @end( explode("amazon.", $amz_sites[$country]['url'] ) ); } return array( 'aff_id' => $aff_id, 'amz_site_name' => $amz_site_name, 'website' => $website, 'country' => $country ); } public function buy_url( $user_country, $amzUser ) { $url = 'https://www.amazon' . ( $amzUser['website'] ) . '/gp/product/{ASIN}?tag=' . ( $amzUser['aff_id'] ) . ''; if( $this->the_plugin->settings['setup']['checkout_type'] == 'add_to_cart' ){ $url = 'https://www.amazon' . ( $amzUser['website'] ) . '/gp/aws/cart/add.html?AssociateTag=' . ( $amzUser['aff_id'] ) . '&ASIN.1={ASIN}&Quantity.1=1'; } return $url; } public function add_html_marker() { echo '<div class="' . ( WooZoneProviderEbay()->alias ) . '-amazon-products-wrapper"></div>'; } public function not_found_box() { global $wp_query; if( is_search() && trim(get_search_query()) != "" ){ if( isset($wp_query->found_posts) && $wp_query->found_posts == 0 ){ $user_country = $this->get_country_perip_external(); // force for testing request $user_country = isset($_GET['force_country']) && strlen($_GET['force_country']) < 5 ? $_GET['force_country'] : $user_country; $amzUser = $this->amzForUser( $user_country ); $amz_sites = $this->the_plugin->amazon_sites(); $html = array(); $html[] = '<div class="' . ( WooZoneProviderEbay()->alias ) . '-amazon-products" data-country="' . ( $user_country ) . '" data-amzsite="' . ( $amzUser['website'] ) . '" data-where="' . ( $this->the_plugin->settings['setup']['where_to_display'] ) . '" data-apiurl="' . ( $amz_sites[$amzUser['country']]['api_url'] ) . '" data-placeholder="' . ( WooZoneProviderEbay()->assetUrl('images/placeholder.png') ) . '" data-perpage="' . ( $this->the_plugin->settings['setup']['items_per_page'] + 1 ) . '" data-keyword="' . ( get_search_query() ) . '" data-btntext="' . ( $this->the_plugin->settings['setup']['button_text'] ) . '" data-buyurl="' . ( $this->buy_url( $user_country, $amzUser ) ) . '" data-searchindex="' . ( $this->the_plugin->settings['setup']['amazon_categories'][$amzUser['country']] ) . '" data-showpagination="' . ( $this->the_plugin->settings['setup']['show_pagination'] ) . '">'; $headline = $this->the_plugin->settings['setup']['headline_text']; $headline = str_replace('{amazon_site_name}', $amzUser['amz_site_name'], $headline ); $html[] = '<h2 class="' . ( WooZoneProviderEbay()->alias ) . '-box-title">' . ( $headline ) . '</h2>'; $html[] = '<div class="' . ( WooZoneProviderEbay()->alias ) . '-amazon-response"></div>'; $html[] = '<div class="' . ( WooZoneProviderEbay()->alias ) . '-amazon-pag-response"></div>'; $html[] = '</div>'; echo implode( "\n", $html ); } } } public function save_stats() { $params = isset($_REQUEST['params']) ? $_REQUEST['params'] : array(); if( $params && count($params) > 0 ){ $ip = $this->get_client_ip(); WooZoneProviderEbay()->db->insert( WooZoneProviderEbay()->db->prefix . 'WooZoneProviderEbay_stats', array( 'action' => isset($params['action']) ? $params['action'] : '', 'keyword' => isset($params['keyword']) ? $params['keyword'] : '', 'amazon_site' => isset($params['amzsite']) ? $params['amzsite'] : '', 'country' => isset($params['country']) ? $params['country'] : '', 'url' => isset($params['url']) ? $params['url'] : '', 'ip' => $ip ), array( '%s', '%s', '%s', '%s', '%s', '%s' ) ); } die("ok"); } } }