Skip to content

Commit

Permalink
Re-build 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
morehawes committed Apr 16, 2024
1 parent 4d35cd6 commit 047f519
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 303 deletions.
8 changes: 4 additions & 4 deletions build/App/Admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class InMap_Admin extends Joe_v1_2_Admin {
class InMap_Admin extends Joe_v1_3_Admin {

function __construct() {
parent::__construct();
Expand All @@ -15,14 +15,14 @@ function __construct() {

//Actions
add_action('admin_init', array($this, 'load_assets'));
add_filter('plugin_action_links_' . Joe_v1_2_Helper::plugin_file_path(), array($this, 'add_action_links'));
add_filter('plugin_action_links_' . Joe_v1_3_Helper::plugin_file_path(), array($this, 'add_action_links'));
}

function add_action_links($links) {
$links_before = array();

$links_after = array(
'<a href="' . admin_url('options-general.php?page=' . Joe_v1_2_Helper::slug_prefix('settings', '-')) . '">' . esc_html__('Settings', Joe_v1_2_Config::get_item('plugin_text_domain')) . '</a>'
'<a href="' . admin_url('options-general.php?page=' . Joe_v1_3_Helper::slug_prefix('settings', '-')) . '">' . esc_html__('Settings', Joe_v1_3_Config::get_item('plugin_text_domain')) . '</a>'
);

return array_merge($links_before, $links, $links_after);
Expand All @@ -32,6 +32,6 @@ function load_assets() {
parent::load_assets();

//Joe CSS
// Joe_v1_2_Assets::css_enqueue(Joe_v1_2_Helper::asset_url('css/admin.min.css'));
// Joe_v1_3_Assets::css_enqueue(Joe_v1_3_Helper::asset_url('css/admin.min.css'));
}
}
4 changes: 2 additions & 2 deletions build/App/Front.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class InMap_Front extends Joe_v1_2_Front {
class InMap_Front extends Joe_v1_3_Front {
function __construct() {
parent::__construct();

Expand All @@ -15,6 +15,6 @@ function __construct() {
}

function wp_head() {
echo '<meta name="' . Joe_v1_2_Config::get_name(true, true) . ' Version" content="' . Joe_v1_2_Config::get_version() . '" />' . "\n";
echo '<meta name="' . Joe_v1_3_Config::get_name(true, true) . ' Version" content="' . Joe_v1_3_Config::get_version() . '" />' . "\n";
}
}
78 changes: 39 additions & 39 deletions build/App/Inreach.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class InMap_Inreach extends Joe_v1_2_Class {
class InMap_Inreach extends Joe_v1_3_Class {

// private $request_endpoint = 'https://explore.garmin.com/feed/share/';
private $request_endpoint = 'https://share.garmin.com/feed/share/';
Expand Down Expand Up @@ -28,16 +28,16 @@ function __construct($params_in = null) {

parent::__construct($params_in);

Joe_v1_2_Log::reset();
Joe_v1_3_Log::reset();
foreach([
'setup_request',
'execute_request',
'process_kml',
'build_geojson',
] as $call) {
//Stop if error
if($log = Joe_v1_2_Log::in_error()) {
Joe_v1_2_Log::render();
if($log = Joe_v1_3_Log::in_error()) {
Joe_v1_3_Log::render();

return;
}
Expand All @@ -50,11 +50,11 @@ function execute_request() {
//Request is setup
if($this->cache_id) {
//Cached response ** GET STALE!
$this->cache_response = Joe_v1_2_Cache::get_item($this->cache_id, true);
$this->cache_response = Joe_v1_3_Cache::get_item($this->cache_id, true);

//Fresh
if($this->cache_response && $this->cache_response['status'] == 'fresh') {
Joe_v1_2_Log::add(__('Response retrieved from Cache.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'info', 'cache_fresh');
Joe_v1_3_Log::add(__('Response retrieved from Cache.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'info', 'cache_fresh');

$this->response_string = $this->cache_response['value'];
//Nothing fresh...
Expand Down Expand Up @@ -90,26 +90,26 @@ function execute_request() {
$this->response_string = $response_string;

//Insert into cache
Joe_v1_2_Cache::set_item($this->cache_id, $response_string);
Joe_v1_3_Cache::set_item($this->cache_id, $response_string);

Joe_v1_2_Log::add(__('Garmin provided a valid KML response, which has been added to Cache.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'info', 'response_cached');
Joe_v1_3_Log::add(__('Garmin provided a valid KML response, which has been added to Cache.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'info', 'response_cached');
} else {
Joe_v1_2_Log::add(__('Received invalid KML response from Garmin. Check your MapShare Settings', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'invalid_kml');
Joe_v1_3_Log::add(__('Received invalid KML response from Garmin. Check your MapShare Settings', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'invalid_kml');
}
//Invalid identifier
} else {
Joe_v1_2_Log::add(__('Garmin does not recognise this MapShare Identifier.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'identifier');
Joe_v1_3_Log::add(__('Garmin does not recognise this MapShare Identifier.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'identifier');
}

break;
//Fail
case $response_code == '401' :
Joe_v1_2_Log::add(__('There was a problem with your MapShare Password.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'error_password');
Joe_v1_3_Log::add(__('There was a problem with your MapShare Password.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'error_password');

break;
//Other
default :
Joe_v1_2_Log::add(sprintf(__('Garmin returned a %s error.', Joe_v1_2_Config::get_item('plugin_text_domain')), $response_code), 'error', 'error_' . $response_code);
Joe_v1_3_Log::add(sprintf(__('Garmin returned a %s error.', Joe_v1_3_Config::get_item('plugin_text_domain')), $response_code), 'error', 'error_' . $response_code);

break;
}
Expand All @@ -121,13 +121,13 @@ function execute_request() {
if(! $this->response_string) {
//Check for stale cache
if($this->cache_response && $this->cache_response['status'] == 'stale') {
Joe_v1_2_Log::add(sprintf(__('Unable to get updated KML from Garmin. Last update: %s minutes ago.', Joe_v1_2_Config::get_item('plugin_text_domain')), round($this->cache_response['minutes'])), 'warning', 'cache_stale');
Joe_v1_3_Log::add(sprintf(__('Unable to get updated KML from Garmin. Last update: %s minutes ago.', Joe_v1_3_Config::get_item('plugin_text_domain')), round($this->cache_response['minutes'])), 'warning', 'cache_stale');

//Better than nothing
$this->response_string = $this->cache_response['value'];
//No cache either
} else {
Joe_v1_2_Log::add(__('Garmin provided an empty response. Check your MapShare Settings.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'empty_response');
Joe_v1_3_Log::add(__('Garmin provided an empty response. Check your MapShare Settings.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'empty_response');
}
}
}
Expand All @@ -138,26 +138,26 @@ function setup_request() {

//Required
if(! $url_identifier) {
Joe_v1_2_Log::add(__('No MapShare identifier provided.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'missing_identifier');
Joe_v1_3_Log::add(__('No MapShare identifier provided.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'missing_identifier');

return false;
//Load Demo
} elseif($url_identifier == 'demo') {
$demo_kml = file_get_contents(Joe_v1_2_Helper::asset_url('geo/demo.kml'));
$demo_kml = file_get_contents(Joe_v1_3_Helper::asset_url('geo/demo.kml'));

if($demo_kml) {
$this->response_string = $demo_kml;
Joe_v1_2_Log::add(__('Demo mode enabled!', Joe_v1_2_Config::get_item('plugin_text_domain')), 'info', 'do_demo');
Joe_v1_3_Log::add(__('Demo mode enabled!', Joe_v1_3_Config::get_item('plugin_text_domain')), 'info', 'do_demo');
} else {
Joe_v1_2_Log::add(__('Unable to read Demo KML.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'warning', 'demo_kml_unreadable');
Joe_v1_3_Log::add(__('Unable to read Demo KML.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'warning', 'demo_kml_unreadable');
}

return true;
}

//Password warning
if($this->get_parameter('mapshare_password')) {
Joe_v1_2_Log::add(sprintf(__('Remember that you are responsible for <a%s>protecting access</a> if needed!', Joe_v1_2_Config::get_item('plugin_text_domain')), ' href=\"https://wordpress.org/support/article/using-password-protection/\"'), 'warning', 'password_set');
Joe_v1_3_Log::add(sprintf(__('Remember that you are responsible for <a%s>protecting access</a> if needed!', Joe_v1_3_Config::get_item('plugin_text_domain')), ' href=\"https://wordpress.org/support/article/using-password-protection/\"'), 'warning', 'password_set');
}

//Start building the request
Expand All @@ -175,7 +175,7 @@ function setup_request() {

//Open-ended request warning
if($data_start && ! $data_end) {
Joe_v1_2_Log::add(__('Be careful when creating Shortcodes with no end date. <strong>All future MapShare data will be displayed!</strong>', Joe_v1_2_Config::get_item('plugin_text_domain')), 'warning', 'no_end_date');
Joe_v1_3_Log::add(__('Be careful when creating Shortcodes with no end date. <strong>All future MapShare data will be displayed!</strong>', Joe_v1_3_Config::get_item('plugin_text_domain')), 'warning', 'no_end_date');
}

//Append data
Expand All @@ -187,7 +187,7 @@ function setup_request() {
//Determine cache ID
$this->cache_id = md5(json_encode($this->get_parameters()));

Joe_v1_2_Log::add($this->request_string, 'info', 'request_ready');
Joe_v1_3_Log::add($this->request_string, 'info', 'request_ready');

return true;
}
Expand All @@ -207,14 +207,14 @@ function process_kml() {
$this->get_point_count();

if($this->point_count) {
$point_text = ($this->point_count == 1) ? __('Point', Joe_v1_2_Config::get_item('plugin_text_domain')) : __('Points', Joe_v1_2_Config::get_item('plugin_text_domain'));
$point_text = ($this->point_count == 1) ? __('Point', Joe_v1_3_Config::get_item('plugin_text_domain')) : __('Points', Joe_v1_3_Config::get_item('plugin_text_domain'));

Joe_v1_2_Log::add(__('The KML response contains ' . $this->point_count . ' ' . $point_text . '.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'info', 'has_points');
Joe_v1_3_Log::add(__('The KML response contains ' . $this->point_count . ' ' . $point_text . '.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'info', 'has_points');
} else {
Joe_v1_2_Log::add(__('The KML response contains no Points.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'no_points');
Joe_v1_3_Log::add(__('The KML response contains no Points.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'no_points');
}
} else {
Joe_v1_2_Log::add(__('The KML response is invalid.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'empty_kml');
Joe_v1_3_Log::add(__('The KML response is invalid.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'empty_kml');
}
}

Expand Down Expand Up @@ -245,12 +245,12 @@ function build_geojson() {
$class_append = [];

//Demo!
if(! Joe_v1_2_Log::has('do_demo')) {
$time_ago = Joe_v1_2_Helper::time_ago(strtotime($Placemark->TimeStamp->when));
if(! Joe_v1_3_Log::has('do_demo')) {
$time_ago = Joe_v1_3_Helper::time_ago(strtotime($Placemark->TimeStamp->when));
} else {
$class_append[] = 'inmap-demo';

$time_ago = Joe_v1_2_Helper::time_ago(strtotime($Placemark->TimeStamp->when), strtotime('5/21/2022 11:04:30 PM'));
$time_ago = Joe_v1_3_Helper::time_ago(strtotime($Placemark->TimeStamp->when), strtotime('5/21/2022 11:04:30 PM'));
}

//Coordinates
Expand All @@ -274,7 +274,7 @@ function build_geojson() {
$key = (string)$Placemark->ExtendedData->Data[$j]->attributes()->name;

//Must be a key we are interested in
if(in_array($key, Joe_v1_2_Config::get_item('kml_data_include'))) {
if(in_array($key, Joe_v1_3_Config::get_item('kml_data_include'))) {
$value = (string)$Placemark->ExtendedData->Data[$j]->value;

//By Key
Expand Down Expand Up @@ -304,9 +304,9 @@ function build_geojson() {
}

//Demo Time
if(Joe_v1_2_Log::has('do_demo')) {
$key = esc_attr__('Demo', Joe_v1_2_Config::get_item('plugin_text_domain'));
$extended_data[$key] = esc_attr__('This is a demo!', Joe_v1_2_Config::get_item('plugin_text_domain'));
if(Joe_v1_3_Log::has('do_demo')) {
$key = esc_attr__('Demo', Joe_v1_3_Config::get_item('plugin_text_domain'));
$extended_data[$key] = esc_attr__('This is a demo!', Joe_v1_3_Config::get_item('plugin_text_domain'));
}

//Title
Expand All @@ -324,10 +324,10 @@ function build_geojson() {
//**Only**
if($this->point_count === 1) {
$class_append[] = 'inmap-last inmap-active inmap-only';
$Feature['properties']['title'] = '[' . __('Latest', Joe_v1_2_Config::get_item('plugin_text_domain')) . ']';
$Feature['properties']['title'] = '[' . __('Latest', Joe_v1_3_Config::get_item('plugin_text_domain')) . ']';
//First
} else {
$Feature['properties']['title'] = '[' . __('First', Joe_v1_2_Config::get_item('plugin_text_domain')) . ']';
$Feature['properties']['title'] = '[' . __('First', Joe_v1_3_Config::get_item('plugin_text_domain')) . ']';
}

//Most recent
Expand All @@ -341,7 +341,7 @@ function build_geojson() {
$class_append[] = 'inmap-last inmap-active';

//Most recent
$Feature['properties']['title'] = '[' . __('Latest', Joe_v1_2_Config::get_item('plugin_text_domain')) . ']';
$Feature['properties']['title'] = '[' . __('Latest', Joe_v1_3_Config::get_item('plugin_text_domain')) . ']';
$Feature['properties']['title'] .= $time_ago;
}

Expand Down Expand Up @@ -393,9 +393,9 @@ function build_geojson() {

//We have data
if(sizeof($extended_data)) {
$description .= Joe_v1_2_Helper::assoc_array_table($extended_data);
$description .= Joe_v1_3_Helper::assoc_array_table($extended_data);

$description .= '<div class="inmap-info-expand">' . __('More detail', Joe_v1_2_Config::get_item('plugin_text_domain')) . ' +</div>';
$description .= '<div class="inmap-info-expand">' . __('More detail', Joe_v1_3_Config::get_item('plugin_text_domain')) . ' +</div>';
}
$description .= '</div>';

Expand Down Expand Up @@ -429,7 +429,7 @@ function build_geojson() {

//Style
$Feature['properties']['style']['weight'] = 2;
$Feature['properties']['style']['color'] = Joe_v1_2_Config::get_setting('appearance', 'colours', 'tracking_colour');
$Feature['properties']['style']['color'] = Joe_v1_3_Config::get_setting('appearance', 'colours', 'tracking_colour');

$this->FeatureCollection['features'][] = $Feature;
}
Expand All @@ -438,7 +438,7 @@ function build_geojson() {
$this->FeatureCollection['features'] = array_reverse($this->FeatureCollection['features']);
//No points in KML
} else {
Joe_v1_2_Log::add(__('The KML response contains no Points.', Joe_v1_2_Config::get_item('plugin_text_domain')), 'error', 'no_points');
Joe_v1_3_Log::add(__('The KML response contains no Points.', Joe_v1_3_Config::get_item('plugin_text_domain')), 'error', 'no_points');
}
}

Expand Down
Loading

0 comments on commit 047f519

Please sign in to comment.