2011-12-14 10:35:25 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: WP-GPX-Maps
|
|
|
|
Plugin URI: http://www.darwinner.it/
|
2011-12-19 13:27:22 +00:00
|
|
|
Description: Draws a gpx track with altitude graph
|
2012-07-06 15:40:38 +00:00
|
|
|
Version: 1.1.31
|
2011-12-14 10:35:25 +00:00
|
|
|
Author: Bastianon Massimo
|
|
|
|
Author URI: http://www.pedemontanadelgrappa.it/
|
|
|
|
License: GPL
|
|
|
|
*/
|
|
|
|
|
2012-01-08 16:47:40 +00:00
|
|
|
//error_reporting (E_ALL);
|
|
|
|
|
2012-06-21 13:29:17 +00:00
|
|
|
load_plugin_textdomain('wp-gpx-maps', "/wp-content/plugins/wp-gpx-maps/languages/");
|
|
|
|
|
2012-03-17 11:46:00 +00:00
|
|
|
include 'wp-gpx-maps_utils.php';
|
2011-12-19 13:27:22 +00:00
|
|
|
include 'wp-gpx-maps_admin.php';
|
2011-12-14 10:35:25 +00:00
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
add_action( 'wp_print_scripts', 'print_WP_GPX_Maps_scripts' );
|
2011-12-19 13:27:22 +00:00
|
|
|
add_shortcode('sgpx','handle_WP_GPX_Maps_Shortcodes');
|
|
|
|
register_activation_hook(__FILE__,'WP_GPX_Maps_install');
|
|
|
|
register_deactivation_hook( __FILE__, 'WP_GPX_Maps_remove');
|
|
|
|
add_filter('plugin_action_links', 'WP_GPX_Maps_action_links', 10, 2);
|
2012-04-07 09:11:37 +00:00
|
|
|
add_action('wp_enqueue_scripts', 'enqueue_WP_GPX_Maps_scripts');
|
|
|
|
|
2011-12-19 13:27:22 +00:00
|
|
|
function WP_GPX_Maps_action_links($links, $file) {
|
|
|
|
static $this_plugin;
|
|
|
|
|
|
|
|
if (!$this_plugin) {
|
|
|
|
$this_plugin = plugin_basename(__FILE__);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to make sure we are on the correct plugin
|
|
|
|
if ($file == $this_plugin) {
|
|
|
|
// the anchor tag and href to the URL we want. For a "Settings" link, this needs to be the url of your settings page
|
|
|
|
$settings_link = '<a href="' . get_bloginfo('wpurl') . '/wp-admin/options-general.php?page=WP-GPX-Maps">Settings</a>';
|
|
|
|
// add the link to the list
|
|
|
|
array_unshift($links, $settings_link);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $links;
|
|
|
|
}
|
2011-12-14 10:35:25 +00:00
|
|
|
|
|
|
|
function enqueue_WP_GPX_Maps_scripts()
|
2012-04-07 09:11:37 +00:00
|
|
|
{
|
2012-05-30 09:14:42 +00:00
|
|
|
|
|
|
|
//wp_enqueue_script( 'jquery' );
|
|
|
|
|
2012-06-04 12:31:21 +00:00
|
|
|
wp_deregister_script( 'googleapis' );
|
|
|
|
wp_register_script( 'googleapis', 'https://maps.googleapis.com/maps/api/js?sensor=false&v=3.9', null, null);
|
|
|
|
wp_enqueue_script( 'googleapis' );
|
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
wp_deregister_script( 'WP-GPX-Maps' );
|
2012-07-06 15:40:38 +00:00
|
|
|
wp_register_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery'), "1.1.31");
|
2012-04-07 09:11:37 +00:00
|
|
|
wp_enqueue_script( 'WP-GPX-Maps' );
|
2012-05-30 09:14:42 +00:00
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
wp_deregister_script( 'highcharts' );
|
2012-05-11 18:47:32 +00:00
|
|
|
wp_register_script( 'highcharts', plugins_url('/highcharts.js', __FILE__), array('jquery'), "2.2.1", true);
|
2012-04-07 09:11:37 +00:00
|
|
|
wp_enqueue_script( 'highcharts' );
|
2012-05-30 09:14:42 +00:00
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function print_WP_GPX_Maps_scripts()
|
2011-12-14 10:35:25 +00:00
|
|
|
{
|
|
|
|
?>
|
2012-06-04 12:31:21 +00:00
|
|
|
<style type="text/css">
|
|
|
|
.wpgpxmaps { clear:both; }
|
|
|
|
#content .wpgpxmaps img,
|
|
|
|
.entry-content .wpgpxmaps img,
|
2012-06-27 13:48:34 +00:00
|
|
|
.wpgpxmaps img { max-width: none; width: none; padding:0; background:none; margin:0; border:none; }
|
2012-06-04 12:31:21 +00:00
|
|
|
.wpgpxmaps .ngimages { display:none; }
|
|
|
|
.wpgpxmaps .myngimages { border:1px solid #fff;position:absolute;cursor:pointer;margin:0;z-index:1; }
|
2012-06-25 10:22:56 +00:00
|
|
|
.wpgpxmaps_summary .summarylabel { }
|
|
|
|
.wpgpxmaps_summary .summaryvalue { font-weight: bold; }
|
2012-06-04 12:31:21 +00:00
|
|
|
</style>
|
2011-12-14 10:35:25 +00:00
|
|
|
<?php
|
|
|
|
}
|
2011-12-20 17:17:24 +00:00
|
|
|
|
2012-01-08 16:47:40 +00:00
|
|
|
function findValue($attr, $attributeName, $optionName, $defaultValue)
|
2011-12-15 17:10:41 +00:00
|
|
|
{
|
2012-01-08 16:47:40 +00:00
|
|
|
$val = '';
|
|
|
|
if ( isset($attr[$attributeName]) )
|
2011-12-19 13:27:22 +00:00
|
|
|
{
|
2012-01-08 16:47:40 +00:00
|
|
|
$val = $attr[$attributeName];
|
2011-12-19 13:27:22 +00:00
|
|
|
}
|
2012-01-08 16:47:40 +00:00
|
|
|
if ($val == '')
|
2011-12-19 13:27:22 +00:00
|
|
|
{
|
2012-01-08 16:47:40 +00:00
|
|
|
$val = get_option($optionName);
|
2011-12-19 13:27:22 +00:00
|
|
|
}
|
2012-06-21 13:29:17 +00:00
|
|
|
if ($val == '' && isset($_GET[$attributeName]) && $attributeName != "download")
|
2012-06-11 15:24:58 +00:00
|
|
|
{
|
|
|
|
$val = $_GET[$attributeName];
|
|
|
|
}
|
2012-01-08 16:47:40 +00:00
|
|
|
if ($val == '')
|
2011-12-19 13:27:22 +00:00
|
|
|
{
|
2012-01-08 16:47:40 +00:00
|
|
|
$val = $defaultValue;
|
2011-12-19 13:27:22 +00:00
|
|
|
}
|
2012-01-08 16:47:40 +00:00
|
|
|
return $val;
|
|
|
|
}
|
2012-01-03 09:53:36 +00:00
|
|
|
|
2012-01-08 16:47:40 +00:00
|
|
|
function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
|
|
|
|
{
|
|
|
|
|
2012-04-23 08:06:21 +00:00
|
|
|
$error = '';
|
|
|
|
|
2012-03-05 07:57:36 +00:00
|
|
|
$gpx = findValue($attr, "gpx", "", "");
|
|
|
|
$w = findValue($attr, "width", "wpgpxmaps_width", "100%");
|
|
|
|
$mh = findValue($attr, "mheight", "wpgpxmaps_height", "450px");
|
|
|
|
$mt = findValue($attr, "mtype", "wpgpxmaps_map_type", "HYBRID");
|
|
|
|
$gh = findValue($attr, "gheight", "wpgpxmaps_graph_height", "200px");
|
2012-04-12 14:49:22 +00:00
|
|
|
$showCad = findValue($attr, "showcad", "wpgpxmaps_show_cadence", false);
|
2012-04-07 09:11:37 +00:00
|
|
|
$showHr = findValue($attr, "showhr", "wpgpxmaps_show_hr", false);
|
2012-03-05 07:57:36 +00:00
|
|
|
$showW = findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false);
|
|
|
|
$showSpeed = findValue($attr, "showspeed", "wpgpxmaps_show_speed", false);
|
2012-06-11 15:24:58 +00:00
|
|
|
$zoomOnScrollWheel = findValue($attr, "zoomonscrollwheel", "wpgpxmaps_zoomonscrollwheel", false);
|
2012-03-05 07:57:36 +00:00
|
|
|
$donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false);
|
|
|
|
$pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10);
|
|
|
|
$uom = findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0");
|
|
|
|
$uomspeed = findValue($attr, "uomspeed", "wpgpxmaps_unit_of_measure_speed", "0");
|
|
|
|
$color_map = findValue($attr, "mlinecolor", "wpgpxmaps_map_line_color", "#3366cc");
|
|
|
|
$color_graph = findValue($attr, "glinecolor", "wpgpxmaps_graph_line_color", "#3366cc");
|
|
|
|
$color_graph_speed = findValue($attr, "glinecolorspeed", "wpgpxmaps_graph_line_color_speed", "#ff0000");
|
2012-04-07 09:11:37 +00:00
|
|
|
$color_graph_hr = findValue($attr, "glinecolorhr", "wpgpxmaps_graph_line_color_hr", "#ff77bd");
|
2012-04-12 14:49:22 +00:00
|
|
|
$color_graph_cad = findValue($attr, "glinecolorcad", "wpgpxmaps_graph_line_color_cad", "#beecff");
|
2012-03-05 07:57:36 +00:00
|
|
|
$chartFrom1 = findValue($attr, "chartfrom1", "wpgpxmaps_graph_offset_from1", "");
|
2012-06-07 12:00:57 +00:00
|
|
|
$chartTo1 = findValue($attr, "chartto1", "wpgpxmaps_graph_offset_to1", "");
|
2012-03-05 07:57:36 +00:00
|
|
|
$chartFrom2 = findValue($attr, "chartfrom2", "wpgpxmaps_graph_offset_from2", "");
|
|
|
|
$chartTo2 = findValue($attr, "chartto2", "wpgpxmaps_graph_offset_to2", "");
|
|
|
|
$startIcon = findValue($attr, "starticon", "wpgpxmaps_map_start_icon", "");
|
|
|
|
$endIcon = findValue($attr, "endicon", "wpgpxmaps_map_end_icon", "");
|
|
|
|
$currentIcon = findValue($attr, "currenticon", "wpgpxmaps_map_current_icon", "");
|
2012-07-02 12:51:45 +00:00
|
|
|
$waypointIcon = findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", "");
|
2012-03-17 11:46:00 +00:00
|
|
|
$ngGalleries = findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", "");
|
|
|
|
$ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", "");
|
2012-07-02 12:51:45 +00:00
|
|
|
$download = findValue($attr, "download", "wpgpxmaps_download", "");
|
|
|
|
$summary = findValue($attr, "summary", "wpgpxmaps_summary", "");
|
|
|
|
$dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0);
|
2012-07-04 12:06:44 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$r = rand(1,5000000);
|
2012-03-18 10:44:11 +00:00
|
|
|
|
2012-06-21 13:29:17 +00:00
|
|
|
$gpxurl = $gpx;
|
|
|
|
|
2012-07-02 12:51:45 +00:00
|
|
|
$cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showW,$showHr,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$uomspeed,$uom,v1.1.30";
|
2012-03-20 07:31:51 +00:00
|
|
|
|
|
|
|
$cacheFileName = md5($cacheFileName);
|
2012-02-29 14:01:40 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$gpxcache = gpxCacheFolderPath();
|
2011-12-29 09:54:00 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
if(!(file_exists($gpxcache) && is_dir($gpxcache)))
|
|
|
|
@mkdir($gpxcache,0755,true);
|
|
|
|
|
|
|
|
$gpxcache.= DIRECTORY_SEPARATOR.$cacheFileName.".tmp";
|
2012-06-25 10:22:56 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
|
|
|
|
// Try to load cache
|
|
|
|
if (file_exists($gpxcache))
|
2012-01-24 17:05:59 +00:00
|
|
|
{
|
2012-02-07 13:06:51 +00:00
|
|
|
try {
|
|
|
|
$cache_str = file_get_contents($gpxcache);
|
|
|
|
$cache_obj = unserialize($cache_str);
|
|
|
|
$points_maps = $cache_obj["points_maps"];
|
2012-07-02 12:51:45 +00:00
|
|
|
$points_x_time = $cache_obj["points_x_time"];
|
|
|
|
$points_x_lat = $cache_obj["points_x_lat"];
|
|
|
|
$points_x_lon = $cache_obj["points_x_lon"];
|
2012-04-07 09:11:37 +00:00
|
|
|
$points_graph_dist = $cache_obj["points_graph_dist"];
|
|
|
|
$points_graph_ele = $cache_obj["points_graph_ele"];
|
|
|
|
$points_graph_speed = $cache_obj["points_graph_speed"];
|
2012-04-12 14:49:22 +00:00
|
|
|
$points_graph_hr = $cache_obj["points_graph_hr"];
|
|
|
|
$points_graph_cad = $cache_obj["points_graph_cad"];
|
2012-02-07 13:06:51 +00:00
|
|
|
$waypoints = $cache_obj["waypoints"];
|
2012-06-25 10:22:56 +00:00
|
|
|
$max_ele = $cache_obj["max_ele"];
|
|
|
|
$min_ele = $cache_obj["min_ele"];
|
|
|
|
$total_ele_up = $cache_obj["total_ele_up"];
|
|
|
|
$total_ele_down = $cache_obj["total_ele_down"];
|
|
|
|
$avg_speed = $cache_obj["avg_speed"];
|
|
|
|
$tot_len = $cache_obj["tot_len"];
|
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
} catch (Exception $e) {
|
2012-07-02 12:51:45 +00:00
|
|
|
$points_maps = '';
|
|
|
|
$points_x_time = '';
|
|
|
|
$points_x_lat = '';
|
|
|
|
$points_x_lon = '';
|
2012-04-07 09:11:37 +00:00
|
|
|
$points_graph_dist = '';
|
|
|
|
$points_graph_ele = '';
|
|
|
|
$points_graph_speed = '';
|
|
|
|
$points_graph_hr = '';
|
2012-04-12 14:49:22 +00:00
|
|
|
$points_graph_cad = '';
|
2012-02-07 13:06:51 +00:00
|
|
|
$waypoints= '';
|
2012-06-25 10:22:56 +00:00
|
|
|
$max_ele = 0;
|
|
|
|
$min_ele = 0;
|
|
|
|
$total_ele_up = 0;
|
|
|
|
$total_ele_down = 0;
|
|
|
|
$avg_speed = 0;
|
|
|
|
$tot_len = 0;
|
2012-02-07 13:06:51 +00:00
|
|
|
}
|
2012-01-24 17:05:59 +00:00
|
|
|
}
|
2011-12-14 10:35:25 +00:00
|
|
|
|
2012-03-17 11:46:00 +00:00
|
|
|
if ($points_maps == '' && $gpx != '')
|
2012-02-15 16:04:18 +00:00
|
|
|
{
|
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$sitePath = sitePath();
|
2012-01-28 11:56:52 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$gpx = trim($gpx);
|
|
|
|
|
2012-06-22 07:41:42 +00:00
|
|
|
$isGpxUrl = (preg_match('/^(http(s)?\:\/\/)/', $gpx) == 1);
|
|
|
|
|
|
|
|
if ($isGpxUrl == true)
|
2012-01-28 11:56:52 +00:00
|
|
|
{
|
2012-07-02 12:51:45 +00:00
|
|
|
$gpx = downloadRemoteFile($gpx);
|
2012-01-28 11:56:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-22 07:41:42 +00:00
|
|
|
$gpx = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gpx);
|
|
|
|
$gpx = $sitePath . $gpx;
|
2012-01-28 11:56:52 +00:00
|
|
|
}
|
2012-02-15 16:04:18 +00:00
|
|
|
|
|
|
|
if ($gpx == '')
|
|
|
|
{
|
|
|
|
return "No gpx found";
|
|
|
|
}
|
2012-02-07 13:06:51 +00:00
|
|
|
|
|
|
|
$points = getPoints( $gpx, $pointsoffset, $donotreducegpx);
|
2012-04-07 09:11:37 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$points_maps = '';
|
2012-04-07 09:11:37 +00:00
|
|
|
$points_graph_dist = '';
|
|
|
|
$points_graph_ele = '';
|
|
|
|
$points_graph_speed = '';
|
|
|
|
$points_graph_hr = '';
|
2012-04-12 14:49:22 +00:00
|
|
|
$points_graph_cad = '';
|
2012-02-07 13:06:51 +00:00
|
|
|
$waypoints = '';
|
2012-07-02 12:51:45 +00:00
|
|
|
|
|
|
|
$points_x_time = $points->dt;
|
|
|
|
$points_x_lat = $points->lat;
|
|
|
|
$points_x_lon = $points->lon;
|
2012-06-25 10:22:56 +00:00
|
|
|
|
|
|
|
$max_ele = $points->maxEle;
|
|
|
|
$min_ele = $points->minEle;
|
|
|
|
$total_ele_up = $points->totalEleUp;
|
|
|
|
$total_ele_down = $points->totalEleDown;
|
|
|
|
$avg_speed = $points->avgSpeed;
|
|
|
|
$tot_len = $points->totalLength;
|
2012-04-07 09:11:37 +00:00
|
|
|
|
|
|
|
foreach(array_keys($points->lat) as $i)
|
|
|
|
{
|
2012-02-22 14:29:44 +00:00
|
|
|
|
2012-07-02 12:51:45 +00:00
|
|
|
$_lat = (float)$points->lat[$i];
|
|
|
|
$_lon = (float)$points->lon[$i];
|
2012-04-07 09:11:37 +00:00
|
|
|
|
2012-07-02 12:51:45 +00:00
|
|
|
if ( $_lat == 0 && $_lon == 0 )
|
2012-04-07 09:11:37 +00:00
|
|
|
{
|
2012-07-02 12:51:45 +00:00
|
|
|
$points_maps .= 'null,';
|
|
|
|
$points_graph_dist .= 'null,';
|
|
|
|
$points_graph_ele .= 'null,';
|
|
|
|
|
|
|
|
if ($showSpeed == true)
|
|
|
|
$points_graph_speed .= 'null,';
|
|
|
|
|
|
|
|
if ($showHr == true)
|
|
|
|
$points_graph_hr .= 'null,';
|
|
|
|
|
|
|
|
if ($showCad == true)
|
|
|
|
$points_graph_cad .= 'null,';
|
2012-02-22 14:29:44 +00:00
|
|
|
}
|
2012-07-02 12:51:45 +00:00
|
|
|
else
|
2012-04-12 14:49:22 +00:00
|
|
|
{
|
2012-07-02 12:51:45 +00:00
|
|
|
$points_maps .= '['.(float)$points->lat[$i].','.(float)$points->lon[$i].'],';
|
|
|
|
|
|
|
|
$_ele = (float)$points->ele[$i];
|
|
|
|
$_dist = (float)$points->dist[$i];
|
|
|
|
|
|
|
|
if ($uom == '1')
|
|
|
|
{
|
|
|
|
// Miles and feet
|
|
|
|
$_dist *= 0.000621371192;
|
|
|
|
$_ele *= 3.2808399;
|
|
|
|
} else if ($uom == '2')
|
|
|
|
{
|
|
|
|
// meters / kilometers
|
|
|
|
$_dist = (float)($_dist / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
$points_graph_dist .= $_dist.',';
|
|
|
|
$points_graph_ele .= $_ele.',';
|
|
|
|
|
|
|
|
if ($showSpeed == true) {
|
|
|
|
|
|
|
|
$_speed = (float)$points->speed[$i];
|
|
|
|
|
|
|
|
$points_graph_speed .= convertSpeed($_speed,$uomspeed).',';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($showHr == true)
|
|
|
|
{
|
|
|
|
$points_graph_hr .= $points->hr[$i].',';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($showCad == true)
|
|
|
|
{
|
|
|
|
$points_graph_cad .= $points->cad[$i].',';
|
|
|
|
}
|
2012-04-12 14:49:22 +00:00
|
|
|
}
|
|
|
|
|
2012-06-25 10:22:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($uom == '1')
|
|
|
|
{
|
|
|
|
// Miles and feet
|
2012-06-27 13:48:34 +00:00
|
|
|
$tot_len = round($tot_len * 0.000621371192, 2)." mi";
|
|
|
|
$max_ele = round($max_ele * 3.2808399, 0)." ft";
|
|
|
|
$min_ele = round($min_ele * 3.2808399, 0)." ft";
|
|
|
|
$total_ele_up = round($total_ele_up * 3.2808399, 0)." ft";
|
|
|
|
$total_ele_down = round($total_ele_down * 3.2808399, 0)." ft";
|
2012-06-25 10:22:56 +00:00
|
|
|
} else if ($uom == '2')
|
|
|
|
{
|
|
|
|
// meters / kilometers
|
2012-06-27 13:48:34 +00:00
|
|
|
$tot_len = round($tot_len / 1000, 2)." km";
|
|
|
|
$max_ele = round($max_ele, 0) ." m";
|
|
|
|
$min_ele = round($min_ele, 0) ." m";
|
|
|
|
$total_ele_up = round($total_ele_up, 0) ." m";
|
|
|
|
$total_ele_down = round($total_ele_down, 0) ." m";
|
2012-06-25 10:22:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-25 12:59:57 +00:00
|
|
|
// meters / meters
|
2012-06-27 13:48:34 +00:00
|
|
|
$tot_len = round($tot_len, 0) ." m";
|
|
|
|
$max_ele = round($max_ele, 0) ." m";
|
|
|
|
$min_ele = round($min_ele, 0) ." m";
|
|
|
|
$total_ele_up = round($total_ele_up, 0) ." m";
|
|
|
|
$total_ele_down = round($total_ele_down, 0) ." m";
|
2012-02-15 16:04:18 +00:00
|
|
|
}
|
2012-06-25 10:22:56 +00:00
|
|
|
|
|
|
|
$avg_speed = convertSpeed($avg_speed,$uomspeed,true);
|
2012-04-07 09:11:37 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
if ($showW == true)
|
|
|
|
{
|
|
|
|
$wpoints = getWayPoints($gpx);
|
|
|
|
foreach ($wpoints as $p) {
|
|
|
|
$waypoints .= '['.(float)$p[0].','.(float)$p[1].',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],';
|
|
|
|
}
|
2011-12-24 14:37:05 +00:00
|
|
|
}
|
2012-03-17 11:46:00 +00:00
|
|
|
|
2012-07-02 12:51:45 +00:00
|
|
|
$p="/(,|,null,)$/";
|
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$points_maps = preg_replace($p, "", $points_maps);
|
2012-07-02 12:51:45 +00:00
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
$points_graph_dist = preg_replace($p, "", $points_graph_dist);
|
|
|
|
$points_graph_ele = preg_replace($p, "", $points_graph_ele);
|
|
|
|
$points_graph_speed = preg_replace($p, "", $points_graph_speed);
|
|
|
|
$points_graph_hr = preg_replace($p, "", $points_graph_hr);
|
2012-04-12 14:49:22 +00:00
|
|
|
$points_graph_cad = preg_replace($p, "", $points_graph_cad);
|
2012-04-07 09:11:37 +00:00
|
|
|
|
2012-02-07 13:06:51 +00:00
|
|
|
$waypoints = preg_replace($p, "", $waypoints);
|
|
|
|
|
2012-04-07 09:11:37 +00:00
|
|
|
if (preg_match("/^(0,?)+$/", $points_graph_dist))
|
|
|
|
$points_graph_dist = "";
|
|
|
|
|
|
|
|
if (preg_match("/^(0,?)+$/", $points_graph_ele))
|
|
|
|
$points_graph_ele = "";
|
|
|
|
|
|
|
|
if (preg_match("/^(0,?)+$/", $points_graph_speed))
|
|
|
|
$points_graph_speed = "";
|
|
|
|
|
|
|
|
if (preg_match("/^(0,?)+$/", $points_graph_hr))
|
|
|
|
$points_graph_hr = "";
|
2012-04-12 14:49:22 +00:00
|
|
|
|
|
|
|
if (preg_match("/^(0,?)+$/", $points_graph_cad))
|
|
|
|
$points_graph_cad = "";
|
2012-04-07 09:11:37 +00:00
|
|
|
|
2011-12-24 14:37:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-20 07:31:51 +00:00
|
|
|
$ngimgs_data = '';
|
|
|
|
if ( $ngGalleries != '' || $ngImages != '' )
|
|
|
|
{
|
2012-07-02 12:51:45 +00:00
|
|
|
|
|
|
|
//print_r($points);
|
|
|
|
|
|
|
|
$ngimgs = getNGGalleryImages($ngGalleries, $ngImages, $points_x_time, $points_x_lat, $points_x_lon, $dtoffset, $error);
|
2012-04-23 08:06:21 +00:00
|
|
|
$ngimgs_data ='';
|
2012-03-20 07:31:51 +00:00
|
|
|
foreach ($ngimgs as $img) {
|
|
|
|
$data = $img['data'];
|
|
|
|
$data = str_replace("\n","",$data);
|
|
|
|
$ngimgs_data .= '<span lat="'.$img['lat'].'" lon="'.$img['lon'].'">'.$data.'</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@file_put_contents($gpxcache,
|
2012-07-02 12:51:45 +00:00
|
|
|
serialize(array( "points_maps" => $points_maps,
|
|
|
|
"points_x_time" => $points_x_time,
|
|
|
|
"points_x_lat" => $points_x_lat,
|
|
|
|
"points_x_lon" => $points_x_lon,
|
|
|
|
"points_graph_dist" => $points_graph_dist,
|
|
|
|
"points_graph_ele" => $points_graph_ele,
|
|
|
|
"points_graph_speed" => $points_graph_speed,
|
|
|
|
"points_graph_hr" => $points_graph_hr,
|
|
|
|
"points_graph_cad" => $points_graph_cad,
|
|
|
|
"waypoints" => $waypoints,
|
|
|
|
"max_ele" => $max_ele,
|
|
|
|
"min_ele" => $min_ele,
|
|
|
|
"total_ele_up" => $total_ele_up,
|
|
|
|
"total_ele_down" => $total_ele_down,
|
|
|
|
"avg_speed" => $avg_speed,
|
|
|
|
"tot_len" => $tot_len
|
2012-06-25 10:22:56 +00:00
|
|
|
)
|
2012-03-20 07:31:51 +00:00
|
|
|
),
|
|
|
|
LOCK_EX);
|
2012-06-25 10:22:56 +00:00
|
|
|
|
2012-03-17 11:46:00 +00:00
|
|
|
@chmod($gpxcache,0755);
|
|
|
|
|
2012-07-02 12:51:45 +00:00
|
|
|
if ($gh == "0" || $gh == "0px")
|
|
|
|
{
|
|
|
|
$points_graph_dist = '';
|
|
|
|
$points_graph_ele = '';
|
|
|
|
$points_graph_speed = '';
|
|
|
|
$points_graph_hr = '';
|
|
|
|
$points_graph_cad = '';
|
|
|
|
}
|
|
|
|
|
2011-12-24 14:37:05 +00:00
|
|
|
$output = '
|
2012-04-04 15:38:07 +00:00
|
|
|
<div id="wpgpxmaps_'.$r.'" class="wpgpxmaps">
|
2011-12-19 13:27:22 +00:00
|
|
|
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div>
|
2012-04-07 09:11:37 +00:00
|
|
|
<div id="hchart_'.$r.'" class="plot" style="width:'.$w.'; height:'.$gh.'"></div>
|
2012-04-04 15:38:07 +00:00
|
|
|
<div id="ngimages_'.$r.'" class="ngimages" style="display:none">'.$ngimgs_data.'</div>
|
2011-12-14 10:35:25 +00:00
|
|
|
</div>
|
2012-04-23 08:06:21 +00:00
|
|
|
'. $error .'
|
2011-12-14 10:35:25 +00:00
|
|
|
<script type="text/javascript">
|
2012-04-07 09:11:37 +00:00
|
|
|
jQuery(document).ready(function() {
|
|
|
|
wpgpxmaps({ targetId : "'.$r.'",
|
|
|
|
mapType : "'.$mt.'",
|
|
|
|
mapData : ['.$points_maps.'],
|
|
|
|
graphDist : ['.$points_graph_dist.'],
|
|
|
|
graphEle : ['.$points_graph_ele.'],
|
|
|
|
graphSpeed : ['.$points_graph_speed.'],
|
|
|
|
graphHr : ['.$points_graph_hr.'],
|
2012-04-12 14:49:22 +00:00
|
|
|
graphCad : ['.$points_graph_cad.'],
|
2012-04-07 09:11:37 +00:00
|
|
|
waypoints : ['.$waypoints.'],
|
|
|
|
unit : "'.$uom.'",
|
|
|
|
unitspeed : "'.$uomspeed.'",
|
|
|
|
color1 : "'.$color_map.'",
|
|
|
|
color2 : "'.$color_graph.'",
|
|
|
|
color3 : "'.$color_graph_speed.'",
|
|
|
|
color4 : "'.$color_graph_hr.'",
|
2012-04-12 14:49:22 +00:00
|
|
|
color5 : "'.$color_graph_cad.'",
|
2012-04-07 09:11:37 +00:00
|
|
|
chartFrom1 : "'.$chartFrom1.'",
|
|
|
|
chartTo1 : "'.$chartTo1.'",
|
|
|
|
chartFrom2 : "'.$chartFrom2.'",
|
|
|
|
chartTo2 : "'.$chartTo2.'",
|
|
|
|
startIcon : "'.$startIcon.'",
|
|
|
|
endIcon : "'.$endIcon.'",
|
2012-06-11 15:24:58 +00:00
|
|
|
currentIcon : "'.$currentIcon.'",
|
2012-06-21 13:29:17 +00:00
|
|
|
waypointIcon : "'.$waypointIcon.'",
|
|
|
|
zoomOnScrollWheel : "'.$zoomOnScrollWheel.'",
|
|
|
|
pluginUrl : "'.plugins_url().'",
|
|
|
|
langs : { altitude : "'.__("Altitude", "wp-gpx-maps").'",
|
|
|
|
currentPosition : "'.__("Current Position", "wp-gpx-maps").'",
|
|
|
|
speed : "'.__("Speed", "wp-gpx-maps").'",
|
|
|
|
heartRate : "'.__("Heart rate", "wp-gpx-maps").'",
|
|
|
|
cadence : "'.__("Cadence", "wp-gpx-maps").'",
|
|
|
|
gofullscreen : "'.__("Go Full Screen", "wp-gpx-maps").'",
|
|
|
|
exitfullscreen : "'.__("Exit Full Screen", "wp-gpx-maps").'"
|
|
|
|
}
|
2012-04-07 09:11:37 +00:00
|
|
|
});
|
|
|
|
});
|
2011-12-24 14:37:05 +00:00
|
|
|
</script>';
|
2012-06-21 13:29:17 +00:00
|
|
|
|
2012-06-25 10:22:56 +00:00
|
|
|
// print summary
|
|
|
|
if ($summary=='true' && ( $points_graph_speed != '' || $points_graph_ele != '' || $points_graph_dist != '') )
|
|
|
|
{
|
|
|
|
|
|
|
|
$output .= "<div id='wpgpxmaps_summary_".$r."' class='wpgpxmaps_summary'>";
|
|
|
|
if ($points_graph_dist != '')
|
|
|
|
{
|
|
|
|
$output .= "<span class='summarylabel'>".__("Total distance", "wp-gpx-maps").":</span><span class='summaryvalue'> $tot_len</span><br />";
|
|
|
|
}
|
|
|
|
if ($points_graph_ele != '')
|
|
|
|
{
|
|
|
|
$output .= "<span class='summarylabel'>".__("Max elevation", "wp-gpx-maps").":</span><span class='summaryvalue'> $max_ele</span><br />";
|
|
|
|
$output .= "<span class='summarylabel'>".__("Min elevation", "wp-gpx-maps").":</span><span class='summaryvalue'> $min_ele</span><br />";
|
|
|
|
$output .= "<span class='summarylabel'>".__("Total climbing", "wp-gpx-maps").":</span><span class='summaryvalue'> $total_ele_up</span><br />";
|
|
|
|
$output .= "<span class='summarylabel'>".__("Total descent", "wp-gpx-maps").":</span><span class='summaryvalue'> $total_ele_down</span><br />";
|
|
|
|
}
|
|
|
|
if ($points_graph_speed != '')
|
|
|
|
{
|
|
|
|
$output .= "<span class='summarylabel'>".__("Average speed", "wp-gpx-maps").":</span><span class='summaryvalue'> $avg_speed</span><br />";
|
|
|
|
}
|
|
|
|
$output .= "</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
// print download link
|
2012-06-21 13:29:17 +00:00
|
|
|
if ($download=='true' && $gpxurl != '')
|
2012-06-13 13:14:18 +00:00
|
|
|
{
|
2012-06-22 07:41:42 +00:00
|
|
|
if ($isGpxUrl == true)
|
2012-06-19 11:40:24 +00:00
|
|
|
{
|
2012-06-21 13:29:17 +00:00
|
|
|
|
2012-06-19 11:40:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-21 13:29:17 +00:00
|
|
|
$gpxurl = get_bloginfo('url').$gpxurl;
|
2012-06-19 11:40:24 +00:00
|
|
|
}
|
2012-06-21 13:29:17 +00:00
|
|
|
$output.="<a href='$gpxurl' target='_new'>".__("Download", "wp-gpx-maps")."</a>";
|
2012-06-13 13:14:18 +00:00
|
|
|
}
|
2012-03-05 07:57:36 +00:00
|
|
|
|
2011-12-24 14:37:05 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2011-12-20 17:17:24 +00:00
|
|
|
|
2012-06-27 13:48:34 +00:00
|
|
|
function convertSeconds($s)
|
|
|
|
{
|
|
|
|
if ($s ==0)
|
|
|
|
return 0;
|
|
|
|
$s = 1.0 / $s;
|
|
|
|
$_sSecT = $s * 60; //sec/km
|
|
|
|
$_sMin = floor ( $_sSecT / 60 );
|
|
|
|
$_sSec = $_sSecT - $_sMin * 60;
|
|
|
|
return $_sMin + $_sSec / 100;
|
|
|
|
}
|
|
|
|
|
2012-06-25 10:22:56 +00:00
|
|
|
function convertSpeed($speed,$uomspeed, $addUom = false)
|
|
|
|
{
|
|
|
|
if ($uomspeed == '4') // min/mi
|
|
|
|
{
|
2012-06-27 13:48:34 +00:00
|
|
|
$speed = convertSeconds($speed * 0.037282272);
|
2012-06-25 10:22:56 +00:00
|
|
|
if ($addUom == true) $speed = round($speed,2) . " min/mi";
|
|
|
|
}
|
|
|
|
else if ($uomspeed == '3') // min/km
|
|
|
|
{
|
2012-06-27 13:48:34 +00:00
|
|
|
$speed = convertSeconds($speed * 0.06);
|
2012-06-25 10:22:56 +00:00
|
|
|
if ($addUom == true) $speed = round($speed,2) . " min/km";
|
|
|
|
}
|
|
|
|
else if ($uomspeed == '2') // miles/h
|
|
|
|
{
|
|
|
|
$speed *= 2.2369362920544025;
|
|
|
|
if ($addUom == true) $speed = round($speed,2) . " mi/h";
|
|
|
|
}
|
|
|
|
else if ($uomspeed == '1') // km/h
|
|
|
|
{
|
|
|
|
$speed *= 3.6;
|
|
|
|
if ($addUom == true) $speed = round($speed,2) . " km/h";
|
|
|
|
}
|
|
|
|
else // dafault m/s
|
|
|
|
{
|
|
|
|
if ($addUom == true) $speed = round($speed,2) . " m/s";
|
|
|
|
}
|
|
|
|
return $speed;
|
|
|
|
}
|
|
|
|
|
2012-01-24 17:05:59 +00:00
|
|
|
function downloadRemoteFile($remoteFile)
|
|
|
|
{
|
2012-02-15 16:04:18 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $remoteFile);
|
|
|
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
|
|
|
|
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
|
|
|
|
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
|
|
|
|
$resp = curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
$tmpfname = tempnam ( '/tmp', 'gpx' );
|
|
|
|
|
|
|
|
$fp = fopen($tmpfname, "w");
|
|
|
|
fwrite($fp, $resp);
|
|
|
|
fclose($fp);
|
|
|
|
|
|
|
|
return $tmpfname;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return '';
|
|
|
|
}
|
2012-01-24 17:05:59 +00:00
|
|
|
}
|
|
|
|
|
2011-12-24 14:37:05 +00:00
|
|
|
function unescape($value)
|
|
|
|
{
|
|
|
|
$value = str_replace("'", "\'", $value);
|
|
|
|
$value = str_replace(array("\n","\r"), "", $value);
|
|
|
|
return $value;
|
2011-12-15 16:03:29 +00:00
|
|
|
}
|
2011-12-14 10:35:25 +00:00
|
|
|
|
|
|
|
function WP_GPX_Maps_install() {
|
|
|
|
add_option("wpgpxmaps_width", '100%', '', 'yes');
|
2011-12-19 13:27:22 +00:00
|
|
|
add_option("wpgpxmaps_graph_height", '200px', '', 'yes');
|
2011-12-14 10:35:25 +00:00
|
|
|
add_option("wpgpxmaps_height", '450px', '', 'yes');
|
|
|
|
add_option('wpgpxmaps_map_type','HYBRID','','yes');
|
2011-12-24 14:37:05 +00:00
|
|
|
add_option('wpgpxmaps_show_waypoint','','','yes');
|
2012-02-15 16:04:18 +00:00
|
|
|
add_option('wpgpxmaps_show_speed','','','yes');
|
2012-01-03 09:53:36 +00:00
|
|
|
add_option('wpgpxmaps_pointsoffset','10','','yes');
|
|
|
|
add_option('wpgpxmaps_donotreducegpx','true','','yes');
|
2012-02-15 16:04:18 +00:00
|
|
|
add_option("wpgpxmaps_unit_of_measure", '0', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_unit_of_measure_speed", '0', '', 'yes');
|
2012-01-28 11:56:52 +00:00
|
|
|
add_option("wpgpxmaps_graph_line_color", '#3366cc', '', 'yes');
|
2012-02-15 16:04:18 +00:00
|
|
|
add_option("wpgpxmaps_graph_line_color_speed", '#ff0000', '', 'yes');
|
2012-01-28 11:56:52 +00:00
|
|
|
add_option("wpgpxmaps_map_line_color", '#3366cc', '', 'yes');
|
2012-04-12 14:49:22 +00:00
|
|
|
add_option("wpgpxmaps_graph_line_color_cad", '#beecff', '', 'yes');
|
2012-03-05 07:57:36 +00:00
|
|
|
add_option("wpgpxmaps_graph_offset_from1", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_graph_offset_to1", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_graph_offset_from2", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_graph_offset_to2", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_map_start_icon", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_map_end_icon", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_map_current_icon", '', '', 'yes');
|
2012-06-21 13:29:17 +00:00
|
|
|
add_option("wpgpxmaps_map_waypoint_icon", '', '', 'yes');
|
2012-03-17 11:46:00 +00:00
|
|
|
add_option("wpgpxmaps_map_nggallery", '', '', 'yes');
|
2012-04-07 09:11:37 +00:00
|
|
|
add_option("wpgpxmaps_show_hr", '', '', 'yes');
|
|
|
|
add_option("wpgpxmaps_graph_line_color_hr", '#ff77bd', '', 'yes');
|
2012-04-12 14:49:22 +00:00
|
|
|
add_option('wpgpxmaps_show_cadence','','','yes');
|
2012-06-11 15:24:58 +00:00
|
|
|
add_option('wpgpxmaps_zoomonscrollwheel','','','yes');
|
2012-06-13 13:14:18 +00:00
|
|
|
add_option('wpgpxmaps_download','','','yes');
|
2012-06-25 10:22:56 +00:00
|
|
|
add_option('wpgpxmaps_summary','','','yes');
|
2011-12-14 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function WP_GPX_Maps_remove() {
|
|
|
|
delete_option('wpgpxmaps_width');
|
2011-12-19 13:27:22 +00:00
|
|
|
delete_option('wpgpxmaps_graph_height');
|
2011-12-14 10:35:25 +00:00
|
|
|
delete_option('wpgpxmaps_height');
|
|
|
|
delete_option('wpgpxmaps_map_type');
|
2011-12-24 14:37:05 +00:00
|
|
|
delete_option('wpgpxmaps_show_waypoint');
|
2012-02-15 16:04:18 +00:00
|
|
|
delete_option('wpgpxmaps_show_speed');
|
2012-01-03 09:53:36 +00:00
|
|
|
delete_option('wpgpxmaps_pointsoffset');
|
|
|
|
delete_option('wpgpxmaps_donotreducegpx');
|
2012-01-28 11:56:52 +00:00
|
|
|
delete_option('wpgpxmaps_unit_of_measure');
|
2012-02-15 16:04:18 +00:00
|
|
|
delete_option('wpgpxmaps_unit_of_measure_speed');
|
2012-01-28 11:56:52 +00:00
|
|
|
delete_option('wpgpxmaps_graph_line_color');
|
|
|
|
delete_option('wpgpxmaps_map_line_color');
|
2012-02-15 16:04:18 +00:00
|
|
|
delete_option('wpgpxmaps_graph_line_color_speed');
|
2012-03-05 07:57:36 +00:00
|
|
|
delete_option('wpgpxmaps_graph_offset_from1');
|
|
|
|
delete_option('wpgpxmaps_graph_offset_to1');
|
|
|
|
delete_option('wpgpxmaps_graph_offset_from2');
|
|
|
|
delete_option('wpgpxmaps_graph_offset_to2');
|
|
|
|
delete_option('wpgpxmaps_map_start_icon');
|
|
|
|
delete_option('wpgpxmaps_map_end_icon');
|
|
|
|
delete_option('wpgpxmaps_map_current_icon');
|
2012-06-21 13:29:17 +00:00
|
|
|
delete_option('wpgpxmaps_map_waypoint_icon');
|
2012-03-17 11:46:00 +00:00
|
|
|
delete_option('wpgpxmaps_map_nggallery');
|
2012-04-07 09:11:37 +00:00
|
|
|
delete_option('wpgpxmaps_show_hr');
|
|
|
|
delete_option('wpgpxmaps_graph_line_color_hr');
|
2012-04-12 14:49:22 +00:00
|
|
|
delete_option('wpgpxmaps_show_cadence');
|
|
|
|
delete_option('wpgpxmaps_graph_line_color_cad');
|
2012-06-11 15:24:58 +00:00
|
|
|
delete_option('wpgpxmaps_zoomonscrollwheel');
|
2012-06-13 13:14:18 +00:00
|
|
|
delete_option('wpgpxmaps_download');
|
2012-06-25 10:22:56 +00:00
|
|
|
delete_option('wpgpxmaps_summary');
|
2011-12-14 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 16:03:29 +00:00
|
|
|
?>
|