Skip to content

Commit

Permalink
Revert "Merge branch 'dev' into preprod"
Browse files Browse the repository at this point in the history
This reverts commit 025aa1b, reversing
changes made to 78186af.
  • Loading branch information
tamw-wnet committed Jun 27, 2024
1 parent 025aa1b commit afb9825
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 47 deletions.
7 changes: 1 addition & 6 deletions classes/class-pbs-check-dma-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public function register_settings() {

add_settings_field( 'jwplayer_uri', 'JW Player URI', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'jwplayer_uri', 'class' => 'regular-text', 'label' => 'Full URI to the JW Player javascript, unique to your JWPlayer.com account. <b>Leave blank to use video.js</b>', 'default' => '') );

add_settings_field('ip_zip_override', 'Override zipcode for IPs', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_override', 'class' => 'regular-text', 'type' => 'textarea', 'default' => '', 'label' => 'Add JSON formated pairs of IP -> zipcodes if you want a specific IP address to appear to be in a zipcode eg <br />[<br />{"127.0.0.1":"00001"},<br />{"127.0.0.2":"00002"}<br />]<br />NO TRAILING COMMA ON LAST PAIR, thats invalid JSON<br />Be kind and don\'t delete pairs from other people.'));

}

Expand Down Expand Up @@ -139,11 +138,7 @@ public function settings_field( $args ) {
echo '<select name="' . $settingname . '[' . $field . ']" id="' . $settingname . '[' . $field . ']" class="' . $class . '">' . $optionlist . '</select>';
echo '<label for="' . $field . '"><p class="description">' . $label . '</p></label>';
break;
case 'textarea' :
$value = (($setting[$field] && strlen(trim($setting[$field]))) ? $setting[$field] : $default);
echo '<textarea name="' . $settingname . '[' . $field . ']" id="' . $settingname . '[' . $field . ']" cols=60 rows=5 >' . $value . '</textarea><p class="description">' . $args['label'] . '</p>';
break;


default:
// any case other than selects, radios, checkboxes, or textareas formats like a text input
$value = (($setting[$field] && strlen(trim($setting[$field]))) ? $setting[$field] : $default);
Expand Down
50 changes: 9 additions & 41 deletions classes/class-pbs-check-dma.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct() {
$this->assets_dir = trailingslashit( $this->dir ) . 'assets';
$this->assets_url = trailingslashit(plugin_dir_url( __DIR__ ) ) . 'assets';
$this->token = 'pbs_check_dma';
$this->version = '1.01';
$this->version = '0.94';

// Load public-facing style sheet and JavaScript.
//add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
Expand Down Expand Up @@ -58,8 +58,6 @@ public function use_custom_template($template) {
}

public function get_location_from_ip($client_ip) {
#possibly manually override the zipcode
$override_zipcode = $this->manually_override_zipcode_from_ip($client_ip);
$zip_url = 'https://services.pbs.org/zipcodes/ip/';
$combined_url = $zip_url . $client_ip . '.json';
$response = wp_remote_get($combined_url, array());
Expand All @@ -72,22 +70,20 @@ public function get_location_from_ip($client_ip) {
if ($body) {
$parsed = json_decode($body, TRUE);
$item = !empty($parsed['$items'][0]) ? $parsed['$items'][0] : false;
if (!$item && !$override_zipcode) {
if (!$item) {
return array('errors' => $response);
}
$zipcode = $override_zipcode ? $override_zipcode : $zipcode;
$zipcode = !empty($item['zipcode']) ? (string) $item['zipcode'] : '';
$state = '';
$county = '';
if (!$override_zipcode && (empty($item['$links']) || !is_array($item['$links']))) {
if (empty($item['$links']) || !is_array($item['$links'])) {
return array('errors' => $response);
}
if (isset($item['$links'])) {
foreach ($item['$links'] as $link) {
if ($link['$relationship'] == "related") {
$state = !empty($link['$items'][0]['$links'][0]['state']) ? $link['$items'][0]['$links'][0]['state'] : '';
$county = !empty($link['$items'][0]['county_name']) ? $link['$items'][0]['county_name'] : '';
break;
}
foreach ($item['$links'] as $link) {
if ($link['$relationship'] == "related") {
$state = !empty($link['$items'][0]['$links'][0]['state']) ? $link['$items'][0]['$links'][0]['state'] : '';
$county = !empty($link['$items'][0]['county_name']) ? $link['$items'][0]['county_name'] : '';
break;
}
}
$country = !empty($zipcode) ? 'USA' : 'Outside of the US'; // the PBS endpoint returns a 404 for non-US IP addresses
Expand All @@ -109,34 +105,6 @@ public function get_remote_ip_address() {
return $_SERVER['REMOTE_ADDR'];
}

public function manually_override_zipcode_from_ip($client_ip) {
// returns false unless there's a manually override zipcode assigned to the ip
// in which case it returns the zipcode
$return = false;
$defaults = get_option($this->token);
if (!empty(trim($defaults['ip_zip_override']))) {
$ip_zip_override = str_replace("\n", "", $defaults['ip_zip_override']);
$ip_zip_override = str_replace("\r", "", $ip_zip_override);
if (json_decode($ip_zip_override)){
$json_ary = json_decode($ip_zip_override, true);
foreach ($json_ary as $pair) {
foreach ($pair as $ip => $zip) {
if (!filter_var($ip, FILTER_VALIDATE_IP)){
continue;
}
if ($client_ip == $ip) {
if (is_string($zip) && 1 === preg_match("/^[0-9]{5}$/", $zip)) {
$return = $zip;
break;
}
}
}
}
}
}
return $return;
}


public function format_counties_setting_for_use() {
$defaults = get_option($this->token);
Expand Down

0 comments on commit afb9825

Please sign in to comment.