acf-boolean.php
4 years ago
acf-choice.php
4 years ago
acf-text.php
4 years ago
browser.php
4 years ago
condition.php
4 years ago
date-range.php
4 years ago
date.php
4 years ago
day.php
4 years ago
device.php
4 years ago
ip-location.php
4 years ago
lang.php
4 years ago
login-status.php
4 years ago
operating-system.php
4 years ago
page.php
4 years ago
post-type.php
4 years ago
post.php
4 years ago
time-range.php
4 years ago
url-referer.php
4 years ago
user-role.php
4 years ago
woo-cat-page.php
4 years ago
woo-category.php
4 years ago
woo-last-purchase.php
4 years ago
woo-orders.php
4 years ago
woo-product-cat.php
4 years ago
woo-product-price.php
4 years ago
woo-product-stock.php
4 years ago
woo-total-price.php
4 years ago
ip-location.php
96 lines
| 1 | <?php |
| 2 | /** |
| 3 | * IP Location Condition Handler. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes\PA_Display_Conditions\Conditions; |
| 7 | |
| 8 | // Elementor Classes. |
| 9 | use Elementor\Controls_Manager; |
| 10 | |
| 11 | // PA Classes. |
| 12 | use PremiumAddons\Includes\Helper_Functions; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // Exit if accessed directly. |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Class Ip_Location |
| 20 | */ |
| 21 | class Ip_Location extends Condition { |
| 22 | |
| 23 | /** |
| 24 | * Get Controls Options. |
| 25 | * |
| 26 | * @access public |
| 27 | * @since 4.7.0 |
| 28 | * |
| 29 | * @return array|void controls options |
| 30 | */ |
| 31 | public function get_control_options() { |
| 32 | |
| 33 | $country_list = array(); |
| 34 | |
| 35 | $countries = array( 'Afghanistan', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antarctica', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bahamas', 'Bahrain', 'Bangladesh', 'Barbados', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegowina', 'Botswana', 'Bouvet Island', 'Brazil', 'British Indian Ocean Territory', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo', 'Congo, the Democratic Republic of the', 'Cook Islands', 'Costa Rica', "Cote d'Ivoire", 'Croatia (Hrvatska)', 'Cuba', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'Egypt', 'El Salvador', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands (Malvinas)', 'Faroe Islands', 'Fiji', 'Finland', 'France', 'France Metropolitan', 'French Guiana', 'French Polynesia', 'French Southern Territories', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard and Mc Donald Islands', 'Holy See (Vatican City State)', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iran (Islamic Republic of)', 'Iraq', 'Ireland', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', "Korea, Democratic People's Republic of", 'Korea, Republic of', 'Kuwait', 'Kyrgyzstan', "Lao, People's Democratic Republic", 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libyan Arab Jamahiriya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia, The Former Yugoslav Republic of', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Micronesia, Federated States of', 'Moldova, Republic of', 'Monaco', 'Mongolia', 'Montserrat', 'Morocco', 'Mozambique', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'Netherlands Antilles', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Reunion', 'Romania', 'Russian Federation', 'Rwanda', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Vincent and the Grenadines', 'Samoa', 'San Marino', 'Sao Tome and Principe', 'Saudi Arabia', 'Scotland', 'Senegal', 'Seychelles', 'Sierra Leone', 'Singapore', 'Slovakia (Slovak Republic)', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia and the South Sandwich Islands', 'Spain', 'Sri Lanka', 'St. Helena', 'St. Pierre and Miquelon', 'Sudan', 'Suriname', 'Svalbard and Jan Mayen Islands', 'Swaziland', 'Sweden', 'Switzerland', 'Syrian Arab Republic', 'Taiwan, Province of China', 'Tajikistan', 'Tanzania, United Republic of', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'United States Minor Outlying Islands', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Venezuela', 'Vietnam', 'Virgin Islands (British)', 'Virgin Islands (U.S.)', 'Wales', 'Wallis and Futuna Islands', 'Western Sahara', 'Yemen', 'Yugoslavia', 'Zambia', 'Zimbabwe' ); |
| 36 | |
| 37 | foreach ( $countries as $country ) { |
| 38 | $key = strtolower( $country ); |
| 39 | /* translators: %s: Country Name */ |
| 40 | $val = sprintf( __( '%s', 'premium-addons-for-elementor' ), ucwords( $country ) ); |
| 41 | $country_list[ $key ] = $val; |
| 42 | } |
| 43 | |
| 44 | return array( |
| 45 | 'label' => __( 'Value', 'premium-addons-for-elementor' ), |
| 46 | 'type' => Controls_Manager::SELECT2, |
| 47 | 'label_block' => true, |
| 48 | 'default' => array(), |
| 49 | 'options' => $country_list, |
| 50 | 'multiple' => true, |
| 51 | 'condition' => array( |
| 52 | 'pa_condition_key' => 'ip_location', |
| 53 | ), |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Compare Condition Value. |
| 59 | * |
| 60 | * @access public |
| 61 | * @since 4.7.0 |
| 62 | * |
| 63 | * @param array $settings element settings. |
| 64 | * @param string $operator condition operator. |
| 65 | * @param string $value condition value. |
| 66 | * @param string $compare_val compare value. |
| 67 | * @param string|bool $tz time zone. |
| 68 | * |
| 69 | * @return bool|void |
| 70 | */ |
| 71 | public function compare_value( $settings, $operator, $value, $compare_val, $tz ) { |
| 72 | |
| 73 | if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 74 | $http_x_headers = explode( ',', filter_var_array( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ); |
| 75 | |
| 76 | $_SERVER['REMOTE_ADDR'] = $http_x_headers[0]; |
| 77 | } |
| 78 | |
| 79 | $ip_address = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; |
| 80 | |
| 81 | $location_data = unserialize( rplg_urlopen( 'http://www.geoplugin.net/php.gp?ip=' . $ip_address )['data'] ); |
| 82 | |
| 83 | if ( 404 === $location_data['geoplugin_status'] ) { |
| 84 | return; // localhost. |
| 85 | } |
| 86 | |
| 87 | $location = strtolower( $location_data['geoplugin_countryName'] ); |
| 88 | |
| 89 | $condition_result = is_array( $value ) && ! empty( $value ) ? in_array( $location, $value, true ) : $value === $location; |
| 90 | |
| 91 | return Helper_Functions::get_final_result( $condition_result, $operator ); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | } |
| 96 |