Skip to content

Commit

Permalink
switching from json array to more usable text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tamw-wnet committed Jun 28, 2024
1 parent 1edb010 commit 617f4d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
5 changes: 3 additions & 2 deletions classes/class-pbs-check-dma-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ 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.'));
add_settings_field('ip_zip_override_array', 'Override zipcode for IPs', array( $this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_override_array', 'class' => 'regular-text', 'type' => 'array', 'options' => array('count_source' => 'ip_zip_count', 'ip' => array('label' => 'IP Num', 'class' => 'medium-text'), 'zip' => array('label' => '5-digit zipcode', 'class' => 'medium-text'), 'note' => array('label' => 'Note', 'class' => 'regular-text')), 'label' => 'For debugging issues outside your physical DMA. Enter a specific IP number and the zipcode you want to appear to be there. Put a note describing who its for, and delete when done testing.<br /><b>WARNING:</b> if you\'re in an office or home network, this will probably apply to ALL devices in that network making requests to this server, as they will appear to the server to have the same IP number.'));
add_settings_field( 'ip_zip_count', 'IP-Zip Count', array($this, 'settings_field'), $this->token, 'generalsettings', array('setting' => $this->token, 'field' => 'ip_zip_count', 'type' => 'text', 'default' => 1, 'label' => 'Increase from 1 if you need to have more IP zip overrides active. If you have more than 1 active and reduce back to 1, please save this page twice to remove any old data', 'class' => 'small-text') );

}

Expand All @@ -73,7 +74,7 @@ public function settings_field( $args ) {
$settingname = esc_attr( $args['setting'] );
$setting = get_option($settingname);
$field = esc_attr( $args['field'] );
$label = esc_attr( $args['label'] );
$label = !empty($args['label']) ? trim($args['label']) : '';
$class = esc_attr( $args['class'] );
$type = ($args['type'] ? esc_attr( $args['type'] ) : 'text' );
$options = (is_array($args['options']) ? $args['options'] : array('true', 'false') );
Expand Down
31 changes: 14 additions & 17 deletions classes/class-pbs-check-dma.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,20 @@ public function manually_override_zipcode_from_ip($client_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;
}
}
}
if (empty($defaults['ip_zip_override_array'])) {
return false;
}
$raw_pairs = $defaults['ip_zip_override_array'];
foreach ($raw_pairs as $pair) {
$this_ip = trim($pair['ip']);
if (!filter_var($this_ip, FILTER_VALIDATE_IP)){
continue;
}
if ($client_ip == $this_ip) {
$this_zip = trim($pair['zip']);
if (is_string($this_zip) && 1 === preg_match("/^[0-9]{5}$/", $this_zip)) {
$return = $this_zip;
break;
}
}
}
Expand Down

0 comments on commit 617f4d0

Please sign in to comment.