✘✘ GRAYBYTE WORDPRESS FILE MANAGER ✘✘

​🇳​​🇦​​🇲​​🇪♯➤ server366.web-hosting.com ​🇻​♯➤ 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP 🇾​♯➤ 2025

𝗛𝗢𝗠𝗘 𝗜𝗗 ♯➤ 67.223.118.204 ♯➤ 𝗔𝗗𝗠𝗜𝗡 𝗜𝗗 216.73.216.243
𝗢𝗣𝗧𝗜𝗢𝗡𝗦 ♯ CRL ♯➤ 𝗢𝗞 ┃ WGT ♯➤ 𝗢𝗞 ┃ SDO ♯➤ 𝗢𝗙𝗙 ┃ PKEX ♯➤ 𝗢𝗙𝗙
𝗗𝗘𝗔𝗖𝗧𝗜𝗩𝗔𝗧𝗘𝗗 ♯➤ 𝗔𝗟𝗟 𝗪𝗢𝗥𝗞𝗜𝗡𝗚....

𝗛𝗢𝗠𝗘
𝗖𝗨𝗥𝗥𝗘𝗡𝗧 𝗙𝗜𝗟𝗘 : /home/builxejc/public_html/wp-content/plugins/wordpress-popup/inc//opt-in-geo.php
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
 * Geolocation utility functions
 *
 * @package Hustle
 */

/**
 * Class Opt_In_Geo
 */
class Opt_In_Geo {
	/**
	 * Site option key
	 *
	 * @var COUNTRY_IP_MAP
	 */
	const COUNTRY_IP_MAP = 'wpoi-county-id-map';

	/**
	 * Default GeoIP provider key
	 *
	 * @var DEFAULT_GEOIP_PROVIDER
	 */
	const DEFAULT_GEOIP_PROVIDER = 'ipwhois';

	/**
	 * Group name of ip list cache.
	 */
	private const IP_CACHE_GROUP = 'hustle_ip_list';

	/**
	 * Tries to get the public IP address of the current user.
	 *
	 * @return string The IP Address
	 */
	public static function get_user_ip() {
		// check for bot.
		if ( self::is_crawler() ) {
			return false;
		}

		// Check if request is from CloudFlare.
		if ( self::is_cloudflare() ) {
			$cf_ip = filter_input( INPUT_SERVER, 'HTTP_CF_CONNECTING_IP', FILTER_VALIDATE_IP );
			if ( $cf_ip ) {
				return apply_filters( 'hustle_user_ip', $cf_ip );
			}
		}

		$result = (object) array(
			'ip'       => filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_SPECIAL_CHARS ),
			'proxy'    => false,
			'proxy_ip' => '',
		);

		/*
		 * This code tries to bypass a proxy and get the actual IP address of
		 * the visitor behind the proxy.
		 * Warning: These values might be spoofed!
		 */
		$ip_fields = array(
			'HTTP_CLIENT_IP',
			'HTTP_X_FORWARDED_FOR',
			'HTTP_X_FORWARDED',
			'HTTP_X_CLUSTER_CLIENT_IP',
			'HTTP_FORWARDED_FOR',
			'HTTP_FORWARDED',
			'REMOTE_ADDR',
		);
		$forwarded = false;
		foreach ( $ip_fields as $key ) {
			if ( true === array_key_exists( $key, $_SERVER ) ) {
				$ips = filter_input( INPUT_SERVER, $key );
				if ( ! $ips ) {
					// Skip empty or invalid values.
					continue;
				}

				foreach ( explode( ',', $ips ) as $ip ) {
					$ip = trim( $ip );

					if ( false !== filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
						$forwarded = $ip;
						break 2;
					}
				}
			}
		}

		// If we found a different IP address than REMOTE_ADDR then it's a proxy!
		if ( ! empty( $forwarded ) && $forwarded !== $result->ip ) {
			$result->proxy    = true;
			$result->proxy_ip = $result->ip;
			$result->ip       = $forwarded;
		}

		if ( $result->ip ) {
			$user_ip = $result->ip;
		} else {
			$user_ip = 'UNKNOWN';
		}

		return apply_filters( 'hustle_user_ip', esc_attr( $user_ip ) );
	}

	/**
	 * Validates that the IP that made the request is from cloudflare
	 *
	 * @param String $ip - the ip to check.
	 * @return bool
	 */
	private static function validate_cloudflare_ip( $ip ) {
		$cloudflare_ips = array(
			'199.27.128.0/21',
			'173.245.48.0/20',
			'103.21.244.0/22',
			'103.22.200.0/22',
			'103.31.4.0/22',
			'141.101.64.0/18',
			'108.162.192.0/18',
			'190.93.240.0/20',
			'188.114.96.0/20',
			'197.234.240.0/22',
			'198.41.128.0/17',
			'162.158.0.0/15',
			'104.16.0.0/12',
		);
		$is_cf_ip       = false;
		foreach ( $cloudflare_ips as $cloudflare_ip ) {
			if ( self::cloudflare_ip_in_range( $ip, $cloudflare_ip ) ) {
				$is_cf_ip = true;
				break;
			}
		}

		return $is_cf_ip;
	}

	/**
	 * Check if the cloudflare IP is in range
	 *
	 * @param String $ip - the current IP.
	 * @param String $range - the allowed range of cloudflare ips.
	 * @return bool
	 */
	private static function cloudflare_ip_in_range( $ip, $range ) {
		if ( strpos( $range, '/' ) === false ) {
			$range .= '/32';
		}

		// $range is in IP/CIDR format eg 127.0.0.1/24.
		list( $range, $netmask ) = explode( '/', $range, 2 );
		$range_decimal           = ip2long( $range );
		$ip_decimal              = ip2long( $ip );
		$wildcard_decimal        = pow( 2, ( 32 - $netmask ) ) - 1;
		$netmask_decimal         = ~$wildcard_decimal;

		return ( ( $ip_decimal & $netmask_decimal ) === ( $range_decimal & $netmask_decimal ) );
	}

	/**
	 * Check if there are any cloudflare headers in the request
	 *
	 * @return bool
	 */
	private static function cloudflare_requests_check() {
		$flag = true;

		if ( ! isset( $_SERVER['HTTP_CF_CONNECTING_IP'] ) ) {
			$flag = false;
		}
		if ( ! isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) {
			$flag = false;
		}
		if ( ! isset( $_SERVER['HTTP_CF_RAY'] ) ) {
			$flag = false;
		}
		if ( ! isset( $_SERVER['HTTP_CF_VISITOR'] ) ) {
			$flag = false;
		}

		return $flag;
	}

	/**
	 * Check if the request is from cloudflare. If it is, we get the IP
	 *
	 * @return bool
	 */
	private static function is_cloudflare() {
		if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
			$ip = filter_input( INPUT_SERVER, 'HTTP_CLIENT_IP' );
		} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
			$ip = filter_input( INPUT_SERVER, 'HTTP_X_FORWARDED_FOR' );
		} else {
			$ip = filter_input( INPUT_SERVER, 'REMOTE_ADDR' );
		}
		if ( isset( $ip ) ) {
			$request_check = self::cloudflare_requests_check();
			if ( ! $request_check ) {
				return false;
			}

			$ip_check = self::validate_cloudflare_ip( $ip );

			return $ip_check;
		}

		return false;
	}

	/**
	 * Checks if the users IP address belongs to a certain country.
	 *
	 * @return bool
	 */
	public function get_user_country() {

		// check for bot.
		if ( self::is_crawler() ) {
			return false;
		}

		// Grab the users IP address.
		$ip = self::get_user_ip();

		// Deprecated.
		$country = apply_filters_deprecated( 'wpoi-get-user-country', array( '', $ip ), '4.6.0', 'hustle_get_user_country' );

		// See if an add-on provides the country for us.
		$country = apply_filters( 'hustle_get_user_country', $country, $ip );

		if ( empty( $country ) ) {
			$country = $this->get_country_from_ip( $ip );
		}

		if ( empty( $country ) ) {
			$country = 'XX';
		}

		return $country;
	}

	/**
	 * Returns a list of available ip-resolution services.
	 *
	 * @return array List of available webservices.
	 */
	private function get_geo_services() {
		static $geo_service = null;
		if ( null === $geo_service ) {
			$geo_service = array();

			$geo_service['freeip'] = (object) array(
				'label' => 'Free IP API',
				'url'   => 'https://free.freeipapi.com/api/json/%ip%',
				'type'  => 'json',
				'field' => array( 'country_code' ),
			);

			$geo_service['ipwhois'] = (object) array(
				'label' => 'IPWhois',
				'url'   => 'https://ipwho.is/%ip%',
				'type'  => 'json',
				'field' => array( 'country_code' ),
			);

			// Deprecated.
			$geo_service = apply_filters_deprecated( 'wpoi-geo-services', array( $geo_service ), '4.6.0', 'hustle_geo_services' );

			/**
			 * Allow other modules/plugins to register a geo service.
			 */
			$geo_service = apply_filters( 'hustle_geo_services', $geo_service );
		}

		return $geo_service;
	}

	/**
	 * Returns the lookup-service details
	 *
	 * @param string $type Type.
	 * @return object Service object for geo lookup
	 */
	private function get_service( $type = null ) {
		$service = false;
		if ( null === $type ) {
			// Deprecated.
			$remote_ip_url = apply_filters_deprecated( 'wpoi-remote-ip-url', array( '' ), '4.6.0', 'hustle_remote_ip_url' );
			$remote_ip_url = apply_filters( 'hustle_remote_ip_url', $remote_ip_url );
			if ( ! empty( $remote_ip_url ) ) {
				$type = '';
			} else {
				$type = self::DEFAULT_GEOIP_PROVIDER;
			}

			// Deprecated.
			$type = apply_filters_deprecated( 'wpoi-geo-type-service', array( $type ), '4.6.0', 'hustle_geo_type_service' );

			/**
			 * Allow to choose a geo service.
			 */
			$type = apply_filters( 'hustle_geo_type_service', $type );
		}

		if ( empty( $type ) ) {
			$service = (object) array(
				'url'   => $remote_ip_url,
				'label' => 'wp-config.php',
				'type'  => 'text',
			);
		} elseif ( 'geo_db' === $type ) {
			$service = (object) array(
				'url'   => 'db',
				'label' => __( 'Local IP Lookup Table', 'hustle' ),
				'type'  => 'text',
			);
		} else {
			$geo_service = $this->get_geo_services();
			if ( isset( $geo_service[ $type ] ) ) {
				$service = $geo_service[ $type ];
			} else {
				if ( WP_DEBUG ) {
					$message = sprintf(
						/* translators: %s: geoip provider name. */
						__( 'GeoIP provider %s does not exist. Switching to default.', 'hustle' ),
						$type
					);
					trigger_error( esc_html( $message ), E_USER_NOTICE ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
				}
				$service = $geo_service[ self::DEFAULT_GEOIP_PROVIDER ];
			}
		}

		return $service;
	}

	/**
	 * Queries an external geo-API to find the country of the specified IP.
	 *
	 * @param  string $ip The IP Address.
	 * @param  object $service Lookup-Service details.
	 * @return string The country code.
	 */
	private function country_from_api( $ip, $service ) {
		$country = false;

		if ( is_object( $service ) && ! empty( $service->url ) ) {
			$url      = str_replace( '%ip%', $ip, $service->url );
			$response = wp_remote_get( $url );

			if ( ! is_wp_error( $response ) ) {

				$body = isset( $response['body'] ) ? $response['body'] : '';

				if ( ! is_wp_error( $response )
					&& 200 === (int) $response['response']['code']
					&& 'XX' !== $response['body']
					|| false !== ( $body = file_get_contents( $url ) ) // phpcs:ignore
				) {
					if ( 'text' === $service->type ) {
						$country = trim( $body );
					} elseif ( 'json' === $service->type ) {
						$data = (array) json_decode( $body );
						if ( isset( $service->field ) ) {
							if ( is_array( $service->field ) ) {
								$keys  = $service->field;
								$value = $data;

								$element = array_shift( $keys );
								while ( $element ) {
									if ( is_array( $value ) ) {
										if ( isset( $value[ $element ] ) ) {
											$value = $value[ $element ];
										}
									} elseif ( is_object( $value ) ) {
										if ( isset( $value->$element ) ) {
											$value = $value->$element;
										}
									}
									if ( is_string( $value ) ) {
										$country = $value;
									}

									$element = array_shift( $keys );
								}
							} else {
								$country = isset( $data[ $service->field ] ) ? $data[ $service->field ] : null;
							}
						}
					}
				}
			}
		}

		return $country;
	}

	/**
	 * Updates ip-country map and stores in  options ( sitemeta ) table
	 *
	 * @param string $ip IP.
	 * @param string $country Country.
	 * @return mixed
	 */
	private function update_ip_county_map( $ip, $country ) {
		$country_ip_map        = $this->get_ip_county_map();
		$country_ip_map[ $ip ] = $country;

		update_option( self::COUNTRY_IP_MAP, $country_ip_map );
		return $country;
	}

	/**
	 * Retrieves ip-country map from options ( sitemeta ) table
	 *
	 * @return array
	 */
	private function get_ip_county_map() {
		return get_option( self::COUNTRY_IP_MAP, array() );
	}

	/**
	 * Checks if the user is a crawler/bot.
	 *
	 * @return bool
	 */
	private static function is_crawler() {

		$user_agent = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
		if ( $user_agent && preg_match( '/bot|crawler|ia_archiver|mediapartners-google|80legs|wget|voyager|baiduspider|curl|yahoo!|slurp/i', $user_agent ) ) {
			return true;
		}

		return false;
	}

	/**
	 * Returns country string using ip address
	 *
	 * @param string $ip IP.
	 * @return string
	 */
	public function get_country_from_ip( $ip ) {
		// check for bot.
		if ( self::is_crawler() ) {
			return false;
		}

		$ip = (string) $ip;

		if ( '127.0.0.1' === $ip ) {
			return $this->update_ip_county_map( $ip, 'localhost' );
		}

		// See if we have it cached/saved already.
		$country = $this->find_saved_ip_country( $ip );
		if ( ! empty( $country ) ) {
			return $country;
		}

		// Query external geo-API.
		$country = $this->api_find_country( $ip );
		if ( ! empty( $country ) ) {
			// Save it for next time.
			$this->update_ip_country( $ip, $country );
			return $country;
		}

		return 'XX';
	}

	/**
	 * Returns country string using ip address
	 *
	 * @param string $ip_address IP address.
	 * @return string|false
	 */
	public function find_saved_ip_country( $ip_address ) {
		$ip_country = self::get_cached_ip_country( $ip_address );
		if ( $ip_country ) {
			return $ip_country;
		}

		$country_ip_map = $this->get_ip_county_map();
		if ( isset( $country_ip_map[ $ip_address ] ) ) {
			if ( ! empty( $country_ip_map[ $ip_address ] ) ) {
				return $country_ip_map[ $ip_address ];
			}
		}

		return false;
	}

	/**
	 * Get cached ip country.
	 *
	 * @param string $ip_address IP address.
	 * @return string|false
	 */
	private static function get_cached_ip_country( $ip_address ) {
		$hash = md5( $ip_address );
		return wp_cache_get( $hash, self::IP_CACHE_GROUP );
	}

	/**
	 * Queries an external geo-API to find the country of the specified IP.
	 *
	 * @param string $ip_address IP address.
	 * @return string
	 */
	private function api_find_country( $ip_address ) {
		$service = $this->get_service();
		return $this->country_from_api( $ip_address, $service );
	}

	/**
	 * Update ip country.
	 *
	 * @param string $ip_address IP address.
	 * @param string $country Country code.
	 * @return string
	 */
	public function update_ip_country( $ip_address, $country ) {
		self::cache_ip_country( $ip_address, $country );
		return $this->update_ip_county_map( $ip_address, $country );
	}

	/**
	 * Cache ip country.
	 *
	 * @param string $ip_address IP address.
	 * @param string $country Country code.
	 * @return void
	 */
	private static function cache_ip_country( $ip_address, $country ) {
		$hash = md5( $ip_address );
		wp_cache_set( $hash, $country, self::IP_CACHE_GROUP, DAY_IN_SECONDS );
	}
}


Current_dir [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ] Document_root [ 𝗪𝗥𝗜𝗧𝗘𝗔𝗕𝗟𝗘 ]


[ Back ]
𝗡𝗔𝗠𝗘
𝗦𝗜𝗭𝗘
𝗟𝗔𝗦𝗧 𝗧𝗢𝗨𝗖𝗛
𝗨𝗦𝗘𝗥
𝗦𝗧𝗔𝗧𝗨𝗦
𝗙𝗨𝗡𝗖𝗧𝗜𝗢𝗡𝗦
..
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
display-conditions
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
front
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
helpers
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
metas
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
multisite
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
palettes
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
provider
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
providers
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
templates
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
update
--
9 Jun 2026 8.38 AM
builxejc / builxejc
0755
class-hustle-admin-page-abstract.php
17.655 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-auth-token.php
2.666 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
class-hustle-condition-factory.php
0.964 KB
26 May 2020 3.58 PM
builxejc / builxejc
0644
class-hustle-cross-sell.php
1.597 KB
15 Sep 2025 10.29 AM
builxejc / builxejc
0644
class-hustle-dashboard-admin.php
15.469 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-data.php
3.123 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-db.php
8.669 KB
12 Oct 2023 2.01 PM
builxejc / builxejc
0644
class-hustle-installer.php
1.258 KB
3 Jan 2022 12.51 PM
builxejc / builxejc
0644
class-hustle-meta.php
1.9 KB
6 Apr 2023 4.20 PM
builxejc / builxejc
0644
class-hustle-module-admin.php
9.39 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-module-collection.php
12.108 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
class-hustle-module-fields.php
0.436 KB
18 Mar 2026 9.34 PM
builxejc / builxejc
0644
class-hustle-module-page-abstract.php
43.598 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-module-validator.php
2.074 KB
18 Mar 2026 9.34 PM
builxejc / builxejc
0644
class-hustle-notifications.php
29.269 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-settings-admin.php
16.863 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
class-hustle-wp-dashboard-page.php
16.575 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
class-opt-in.php
2.35 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-background-conversion-log.php
2.701 KB
18 Mar 2026 9.34 PM
builxejc / builxejc
0644
hustle-deletion.php
7.746 KB
18 Mar 2026 9.34 PM
builxejc / builxejc
0644
hustle-embedded-admin.php
0.712 KB
13 Oct 2022 9.51 AM
builxejc / builxejc
0644
hustle-entries-admin.php
29.812 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-entry-model.php
32.216 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-general-data-protection.php
11.44 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-init.php
1.382 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-mail.php
6.206 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-migration.php
55.115 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-model.php
34.073 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-module-model.php
30.92 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-module-widget-legacy.php
4.953 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-module-widget.php
3.903 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-modules-common-admin-ajax.php
32.168 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-popup-admin.php
0.639 KB
13 Oct 2022 9.51 AM
builxejc / builxejc
0644
hustle-providers-admin.php
6.822 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-providers.php
16.267 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
hustle-settings-admin-ajax.php
24.727 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-settings-page.php
5.03 KB
17 Apr 2023 3.18 PM
builxejc / builxejc
0644
hustle-slidein-admin.php
0.651 KB
13 Oct 2022 9.51 AM
builxejc / builxejc
0644
hustle-sshare-admin.php
2.503 KB
13 Oct 2022 9.51 AM
builxejc / builxejc
0644
hustle-sshare-model.php
21.675 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
hustle-tracking-model.php
25.706 KB
18 Mar 2026 9.34 PM
builxejc / builxejc
0644
interface-hustle-auth-provider.php
0.509 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
opt-in-geo.php
13.099 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644
opt-in-utils.php
41.588 KB
25 May 2026 1.17 PM
builxejc / builxejc
0644
opt-in-wpmudev-api.php
3.985 KB
26 Jan 2026 12.22 PM
builxejc / builxejc
0644

✘✘ GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME ✘✘
Static GIF Static GIF