This commit is contained in:
bastianonm 2011-12-19 13:27:22 +00:00
parent 07afbd92bb
commit 38ff37c48e
5 changed files with 202 additions and 357 deletions

View File

@ -3,18 +3,14 @@ var loc_en =
"length" : "Length",
"altitude": "Altitude"
};
var loc_it =
{
"length" : "Lunghezza",
"altitude": "Altitudine"
};
var loc = loc_en;
function wpgpxmaps(targhetId,mapType,mapData,graphData)
{
var el = document.getElementById("wpgpxmaps_" + targhetId);
var el_map = document.getElementById("map_" + targhetId);
var el_chart = document.getElementById("chart_" + targhetId);

View File

@ -1,64 +1,59 @@
=== WP-GPX-Maps ===
Contributors: bastianonm
Donate link: http://www.darwinner.it/
Tags: maps, gpx, graph, google maps, google chart
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=bastianonm@hotmail.com&item_name=WP-GRX-Maps&item_number=WP-GRX-Maps&amount=5&currency_code=EUR
Tags: maps, gpx, gps, graph, google maps, google chart
Requires at least: 2.0.0
Tested up to: 3.3
Stable tag: 1.0.2
Stable tag: 1.0.3
License: GPLv2 or later
Add a gpx track with altitude graph
Draws a gpx track with altitude graph
== Description ==
This plugin has, as input, the GPX file with the track you've made. As output it shows the map of the track, fixed with an altitude graph.
- Also working on iphone/ipad/ipod
- iphone/ipad/ipod Compatible
Try this plugin on <a href="http://www.pedemontanadelgrappa.it/category/mappe/">http://www.pedemontanadelgrappa.it/category/mappe/</a>
Thanks to: <a href="http://www.securcube.net/">www.securcube.net</a>, <a href="http://www.darwinner.it/">www.darwinner.it</a>, <a href="http://www.pedemontanadelgrappa.it/">www.pedemontanadelgrappa.it</a>,
<a href="http://www.darwinner.it/featured/wp-gpx-maps/">Bugs, problems, thanks and anything else here!</a>
== Installation ==
1. Use the classic wordpress plugin installer or copy the plugins folder to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
1. Add the shortcode [sgpx gpx="&gt;relative path to your gpx&lt;"]
== Frequently Asked Questions ==
= what are all available shortcode attributes? =
The attributes are:
1. gpx: relative path to gpx
1. width: width in pixels
1. mheight: map height
1. gheight: graph height
1. mtype: map aviable types are: HYBRID, ROADMAP, SATELLITE, TERRAIN
shortcode with all the attributes : [sgpx gpx="&gt;relative path to your gpx&lt;" width=100% mheight=300px gheight=200px mtype=SATELLITE]
= What happening if I've a very large gpx? =
This plugin will print a small amout of points to to speedup javascript and pageload.
= Is it free? =
Yes!
== Screenshots ==
1. Screenshot Sample
2. Screenshot Admin area
== Changelog ==
= 1.0.3 =
* Added Settings link on plugins list
* Added attributes width, mheight, gheight, mtype on shortcode.
= 1.0.2 =
* You can manage your gpx files in the admin area.
= 1.0.1 =
* Small changes on javascript localization.
= 1.0.0 =
* Initial release.
= 1.0.1 =
* Small changes on javascript localization.
= 1.0.2 =
* You can manage your gpx files in the admin area.
== Upgrade Notice ==
= 1.0.3 =
= 1.0.2 =
= 1.0.1 =
= 1.0.0 =
Initial release.
= 1.0.1 =
= 1.0.2 =

View File

@ -2,16 +2,39 @@
/*
Plugin Name: WP-GPX-Maps
Plugin URI: http://www.darwinner.it/
Description: Add a gpx track with altitude graph
Version: 1.0.2
Description: Draws a gpx track with altitude graph
Version: 1.0.3
Author: Bastianon Massimo
Author URI: http://www.pedemontanadelgrappa.it/
License: GPL
*/
include 'wp-gpx-maps_Utils.php';
include 'wp-gpx-maps_admin.php';
add_action( 'wp_print_scripts', 'enqueue_WP_GPX_Maps_scripts' );
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;
}
function enqueue_WP_GPX_Maps_scripts()
{
@ -25,15 +48,38 @@ function enqueue_WP_GPX_Maps_scripts()
<?php
}
add_shortcode('sgpx','handle_WP_GPX_Maps_Shortcodes');
function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
{
$gpx = $attr["gpx"];
$key = get_option("wpgpxmaps_bing_license");
$w = $attr["width"];
$mh = $attr["mheight"];
$mt = $attr["mtype"];
$gh = $attr["gheight"];
if ($w == '')
{
$w = get_option("wpgpxmaps_width");
$h = get_option("wpgpxmaps_height");
$t = get_option("wpgpxmaps_map_type");
}
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 == '')
{
$gh = "150px";
}
$r = rand(1,5000000);
@ -52,228 +98,31 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
echo
'
<div id="wpgpxmaps_'.$r.'" style="clear:both;">
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$h.'"></div>
<div id="chart_'.$r.'" class="plot" style="width:'.$w.'; height:'.(preg_replace("([pxPX%emEM])", "", $h) / 2).'px"></div>
<div id="map_'.$r.'" style="width:'.$w.'; height:'.$mh.'"></div>
<div id="chart_'.$r.'" class="plot" style="width:'.$w.'; height:'.$gh.'"></div>
</div>
<script type="text/javascript">
jQuery(document).ready(function () {
var m_'.$r.' = ['.$points_maps.'];
var c_'.$r.' = ['.$points_graph.'];
wpgpxmaps("'.$r.'",\''.$t.'\',m_'.$r.',c_'.$r.');
wpgpxmaps("'.$r.'",\''.$mt.'\',m_'.$r.',c_'.$r.');
});
</script>';
}
register_activation_hook(__FILE__,'WP_GPX_Maps_install');
register_deactivation_hook( __FILE__, 'WP_GPX_Maps_remove');
function WP_GPX_Maps_install() {
add_option("wpgpxmaps_width", '100%', '', 'yes');
add_option("wpgpxmaps_graph_height", '200px', '', 'yes');
add_option("wpgpxmaps_height", '450px', '', 'yes');
add_option('wpgpxmaps_map_type','HYBRID','','yes');
}
function WP_GPX_Maps_remove() {
delete_option('wpgpxmaps_width');
delete_option('wpgpxmaps_graph_height');
delete_option('wpgpxmaps_height');
delete_option('wpgpxmaps_map_type');
}
if ( is_admin() ){
add_action('admin_menu', 'wpgpxmaps_admin_menu');
function wpgpxmaps_admin_menu() {
add_options_page('WP GPX Maps', 'WP GPX Maps', 'administrator', 'WP-GPX-Maps', 'WP_GPX_Maps_html_page');
}
}
function WP_GPX_Maps_html_page() {
$realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/'))."/wp-content/uploads/gpx";
$gpxRegEx = '/.gpx$/';
?>
<div>
<h2>WP GPX Settings</h2>
<?php
if(file_exists($realGpxPath) && is_dir($realGpxPath))
{
//dir exsist!
}
else
{
if (!@mkdir($dir)) {
echo '<div class="error" style="padding:10px">
Can\'t create <b>'.$realGpxPath.'</b> folder. Please create it and make it writable!<br />
If not, you will must update the file manually!
</div>';
}
}
?>
<div style="padding:10px 10px 30px 10px;">
<b>The fastest way to use this plugin:</b> upload the file using the uploader below, than put this
shotcode: <b>[sgpx gpx="/wp-content/uploads/gpx/&lt gpx file name &gt"]</b> in the pages/posts.
</div>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options') ?>
<table width="100%">
<tr valign="top">
<th width="200" scope="row">Maps Width:</th>
<td>
<input name="wpgpxmaps_width" type="text" id="wpgpxmaps_width" value="<?php echo get_option('wpgpxmaps_width'); ?>" style="width:50px;" />
</td>
</tr>
<tr valign="top">
<th width="200" scope="row">Maps Height:</th>
<td>
<input name="wpgpxmaps_height" type="text" id="wpgpxmaps_height" value="<?php echo get_option('wpgpxmaps_height'); ?>" style="width:50px;" />
</td>
</tr>
<tr>
<th width="200" scope="row">Default Map Type:</th>
<td>
<?php
$t = get_option('wpgpxmaps_map_type');
if (!($t))
$t = 'HYBRID';
?>
<input type="radio" name="wpgpxmaps_map_type" value="HYBRID" <?php if ($t == 'HYBRID') echo 'checked'; ?> > This map type displays a transparent layer of major streets on satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="ROADMAP" <?php if ($t == 'ROADMAP') echo 'checked'; ?>> This map type displays a normal street map.<br />
<input type="radio" name="wpgpxmaps_map_type" value="SATELLITE" <?php if ($t == 'SATELLITE') echo 'checked'; ?>> This map type displays satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="TERRAIN" <?php if ($t == 'TERRAIN') echo 'checked'; ?>> This map type displays maps with physical features such as terrain and vegetation.<br />
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input name="page_options" type="hidden" value="wpgpxmaps_map_type,wpgpxmaps_height,wpgpxmaps_width" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
<?php
if ( isset($_POST['delete']) )
{
$del = $_POST['delete'];
if (preg_match($gpxRegEx, $del ) && file_exists($realGpxPath ."/". $del))
{
unlink($realGpxPath ."/". $del);
}
}
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { ?>
<div class="tablenav top">
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" onchange="this.parentNode.submit()" />
<?php
if ( isset($_FILES['uploadedfile']) )
{
$target_path = $realGpxPath ."/". basename( $_FILES['uploadedfile']['name']);
if (preg_match($gpxRegEx,$target_path ))
{
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
else
{
echo "file not supported!";
}
}
?>
</form>
</div>
<table cellspacing="0" class="wp-list-table widefat plugins">
<thead>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</tfoot>
<tbody id="the-list">
<?php
while (false !== ($entry = readdir($handle))) {
if (preg_match($gpxRegEx,$entry ))
{
$file = $realGpxPath . "/" . $entry;
?>
<tr class="active" id="akismet">
<td class="plugin-title">
<strong><?php echo $entry; ?></strong>
<div class="row-actions-visible">
<a href="#" onclick="delgpx('<?php echo $entry ?>'); return false;">Delete</a>
|
<a href="../wp-content/uploads/gpx/<?php echo $entry?>">Download</a>
</div>
</td>
<td class="column-description desc">
<div class="plugin-description">
<p><?php echo date ("F d Y H:i:s.", filemtime( $file ) ) ?></p>
</div>
</td>
<td class="column-description desc">
<div class="plugin-description">
<p><?php echo number_format ( filesize( $file ) , 0, '.', ',' ) ?></p>
</div>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
closedir($handle);
} ?>
</div>
<script type="text/javascript">
function delgpx(file)
{
if (confirm('Delte this file: ' + file + '?'))
{
document.formdelgpx.delete.value = file;
document.formdelgpx.submit();
}
}
</script>
<form method="post" name="formdelgpx" style="display:none;">
<input type="hidden" name="delete" />
</form>
<?php
}
?>

View File

@ -1,9 +1,7 @@
<?php
function getPoints($gpxPath,$gpxOffset = 10)
{
$points = array();
$dist=0;
$lastLat=0;
@ -64,7 +62,6 @@
{
array_push($points, array((float)0,(float)0,(float)0,(float)0));
}
// riduco l'array a circa 200 punti per non appensantire la pagina(mappa e grafico)!
$count=sizeof($points);
if ($count>200)
@ -92,5 +89,4 @@
$dist = 2 * 3958.75 * atan2(sqrt($a), sqrt(1 - (float) $a));
return sqrt(pow($dist * 1609.00, 2) + pow((float) $lat1 - (float)$lat2, 2));
}
?>

View File

@ -1,5 +1,14 @@
<?php
if ( is_admin() ){
add_action('admin_menu', 'wpgpxmaps_admin_menu');
function wpgpxmaps_admin_menu() {
add_options_page('WP GPX Maps', 'WP GPX Maps', 'administrator', 'WP-GPX-Maps', 'WP_GPX_Maps_html_page');
}
}
function WP_GPX_Maps_html_page() {
$realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'/wp-content/'))."/wp-content/uploads/gpx";
@ -28,9 +37,12 @@ function WP_GPX_Maps_html_page() {
?>
<div style="padding:10px 10px 30px 10px;">
<div style="padding:10px;">
<b>The fastest way to use this plugin:</b> upload the file using the uploader below, than put this
shotcode: <b>[sgpx gpx="/wp-content/uploads/gpx/&lt gpx file name &gt"]</b> in the pages/posts.
<p>
<i>Full set of attributes:</i> <b>[sgpx gpx="/wp-content/uploads/gpx/&lt gpx file name &gt" width=100% mheight=450px gheight=200px mtype=SATELLITE]</b>
</p>
</div>
<form method="post" action="options.php">
@ -38,36 +50,32 @@ function WP_GPX_Maps_html_page() {
<?php wp_nonce_field('update-options') ?>
<table width="100%">
<tr valign="top">
<th width="200" scope="row">Maps Width:</th>
<tr>
<th width="150" scope="row">Default Options:</th>
<td>
<input name="wpgpxmaps_width" type="text" id="wpgpxmaps_width" value="<?php echo get_option('wpgpxmaps_width'); ?>" style="width:50px;" />
</td>
</tr>
<tr valign="top">
<th width="200" scope="row">Maps Height:</th>
<td>
<input name="wpgpxmaps_height" type="text" id="wpgpxmaps_height" value="<?php echo get_option('wpgpxmaps_height'); ?>" style="width:50px;" />
<i>Width:</i> <input name="wpgpxmaps_width" type="text" id="wpgpxmaps_width" value="<?php echo get_option('wpgpxmaps_width'); ?>" style="width:50px;" />,
<i>Maps Height:</i> <input name="wpgpxmaps_height" type="text" id="wpgpxmaps_height" value="<?php echo get_option('wpgpxmaps_height'); ?>" style="width:50px;" />,
<i>Graph Height:</i> <input name="wpgpxmaps_height" type="text" id="wpgpxmaps_height" value="<?php echo get_option('wpgpxmaps_height'); ?>" style="width:50px;" />
</td>
</tr>
<tr>
<th width="200" scope="row">Default Map Type:</th>
<th width="150" scope="row">Default Map Type:</th>
<td>
<?php
$t = get_option('wpgpxmaps_map_type');
if (!($t))
$t = 'HYBRID';
?>
<input type="radio" name="wpgpxmaps_map_type" value="HYBRID" <?php if ($t == 'HYBRID') echo 'checked'; ?> > This map type displays a transparent layer of major streets on satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="ROADMAP" <?php if ($t == 'ROADMAP') echo 'checked'; ?>> This map type displays a normal street map.<br />
<input type="radio" name="wpgpxmaps_map_type" value="SATELLITE" <?php if ($t == 'SATELLITE') echo 'checked'; ?>> This map type displays satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="TERRAIN" <?php if ($t == 'TERRAIN') echo 'checked'; ?>> This map type displays maps with physical features such as terrain and vegetation.<br />
<input type="radio" name="wpgpxmaps_map_type" value="HYBRID" <?php if ($t == 'HYBRID') echo 'checked'; ?> > HYBRID: transparent layer of major streets on satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="ROADMAP" <?php if ($t == 'ROADMAP') echo 'checked'; ?>> ROADMAP: normal street map.<br />
<input type="radio" name="wpgpxmaps_map_type" value="SATELLITE" <?php if ($t == 'SATELLITE') echo 'checked'; ?>> SATELLITE: satellite images.<br />
<input type="radio" name="wpgpxmaps_map_type" value="TERRAIN" <?php if ($t == 'TERRAIN') echo 'checked'; ?>> TERRAIN: maps with physical features such as terrain and vegetation.<br />
</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input name="page_options" type="hidden" value="wpgpxmaps_map_type,wpgpxmaps_height,wpgpxmaps_width" />
<input name="page_options" type="hidden" value="wpgpxmaps_map_type,wpgpxmaps_height,wpgpxmaps_graph_height,wpgpxmaps_width" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
@ -86,7 +94,8 @@ function WP_GPX_Maps_html_page() {
}
}
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { ?>
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) {
?>
<div class="tablenav top">
<form enctype="multipart/form-data" method="POST">