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
|
2011-12-29 09:54:00 +00:00
|
|
|
Version: 1.0.8
|
2011-12-14 10:35:25 +00:00
|
|
|
Author: Bastianon Massimo
|
|
|
|
Author URI: http://www.pedemontanadelgrappa.it/
|
|
|
|
License: GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
add_action( 'wp_print_scripts', 'enqueue_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);
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-12-20 17:17:24 +00:00
|
|
|
|
2011-12-14 10:35:25 +00:00
|
|
|
function enqueue_WP_GPX_Maps_scripts()
|
|
|
|
{
|
|
|
|
?>
|
|
|
|
<script type='text/javascript' src='https://www.google.com/jsapi?ver=3.2.1'></script>
|
2011-12-14 13:05:57 +00:00
|
|
|
<script type='text/javascript'>
|
2011-12-14 10:35:25 +00:00
|
|
|
google.load('visualization', '1', {'packages':['corechart']});
|
2011-12-20 17:17:24 +00:00
|
|
|
google.load("maps", "3", {other_params: 'sensor=false'});
|
2011-12-14 10:35:25 +00:00
|
|
|
</script>
|
2011-12-20 17:17:24 +00:00
|
|
|
<script type='text/javascript' src='<?php echo plugins_url('/WP-GPX-Maps.js', __FILE__) ?>'></script>
|
2011-12-14 10:35:25 +00:00
|
|
|
<?php
|
|
|
|
}
|
2011-12-20 17:17:24 +00:00
|
|
|
|
2011-12-14 10:35:25 +00:00
|
|
|
|
2011-12-15 17:10:41 +00:00
|
|
|
function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
|
|
|
|
{
|
2011-12-14 10:35:25 +00:00
|
|
|
$gpx = $attr["gpx"];
|
2011-12-19 13:27:22 +00:00
|
|
|
$w = $attr["width"];
|
|
|
|
$mh = $attr["mheight"];
|
|
|
|
$mt = $attr["mtype"];
|
|
|
|
$gh = $attr["gheight"];
|
2011-12-24 14:37:05 +00:00
|
|
|
$showW = $attr['waypoints'];
|
2011-12-19 13:27:22 +00:00
|
|
|
|
|
|
|
if ($w == '')
|
|
|
|
{
|
|
|
|
$w = get_option("wpgpxmaps_width");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($mh == '')
|
|
|
|
{
|
|
|
|
$mh = get_option("wpgpxmaps_height");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($gh == '')
|
|
|
|
{
|
|
|
|
$gh = get_option("wpgpxmaps_graph_height");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($mt == '')
|
|
|
|
{
|
|
|
|
$mt = get_option("wpgpxmaps_map_type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($gh == '')
|
|
|
|
{
|
2011-12-19 13:32:38 +00:00
|
|
|
$gh = "200px";
|
2011-12-19 13:27:22 +00:00
|
|
|
}
|
2011-12-24 14:37:05 +00:00
|
|
|
|
|
|
|
if ($showW == '')
|
|
|
|
{
|
|
|
|
$showW = get_option("wpgpxmaps_show_waypoint");
|
|
|
|
}
|
|
|
|
|
2011-12-14 10:35:25 +00:00
|
|
|
$r = rand(1,5000000);
|
|
|
|
|
2011-12-29 09:54:00 +00:00
|
|
|
$gpx = trim($gpx);
|
|
|
|
|
2011-12-14 10:35:25 +00:00
|
|
|
$points = getPoints($gpx);
|
|
|
|
$points_maps = '';
|
|
|
|
$points_graph = '';
|
2011-12-24 14:37:05 +00:00
|
|
|
$waypoints = '';
|
2011-12-14 10:35:25 +00:00
|
|
|
|
|
|
|
foreach ($points as $p) {
|
|
|
|
$points_maps .= "[".(float)$p[0].",".(float)$p[1]."],";
|
|
|
|
$points_graph .= "[".(float)$p[3].",".(float)$p[2]."],";
|
2011-12-20 15:37:26 +00:00
|
|
|
} //all the points are [0,0] $points_graph = preg_replace("/^(\[0,0\],)+$/", "", $points_graph);
|
2011-12-24 14:37:05 +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-14 10:35:25 +00:00
|
|
|
$p="/,$/";
|
|
|
|
$points_maps = preg_replace($p, "", $points_maps);
|
2011-12-24 14:37:05 +00:00
|
|
|
$points_graph = preg_replace($p, "", $points_graph);
|
|
|
|
$waypoints = preg_replace($p, "", $waypoints);
|
|
|
|
|
|
|
|
if (preg_match("/^(\[0,0\],?)+$/", $points_graph))
|
|
|
|
{
|
|
|
|
$points_graph = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = '
|
2011-12-14 10:35:25 +00:00
|
|
|
<div id="wpgpxmaps_'.$r.'" style="clear:both;">
|
2011-12-19 13:27:22 +00:00
|
|
|
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div>
|
|
|
|
<div id="chart_'.$r.'" class="plot" style="width:'.$w.'; height:'.$gh.'"></div>
|
2011-12-14 10:35:25 +00:00
|
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
2011-12-20 17:17:24 +00:00
|
|
|
var m_'.$r.' = ['.$points_maps.'];
|
|
|
|
var c_'.$r.' = ['.$points_graph.'];
|
2011-12-24 14:37:05 +00:00
|
|
|
var w_'.$r.' = ['.$waypoints.'];
|
|
|
|
wpgpxmaps("'.$r.'","'.$mt.'",m_'.$r.',c_'.$r.', w_'.$r.');
|
|
|
|
</script>';
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
2011-12-20 17:17:24 +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');
|
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');
|
2011-12-14 10:35:25 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 16:03:29 +00:00
|
|
|
?>
|