This commit is contained in:
bastianonm 2012-01-08 16:47:40 +00:00
parent 8a4a510722
commit 2f6aae8455
4 changed files with 90 additions and 76 deletions

View File

@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=basti
Tags: maps, gpx, gps, graph, google maps, google chart, track, garmin Tags: maps, gpx, gps, graph, google maps, google chart, track, garmin
Requires at least: 2.0.0 Requires at least: 2.0.0
Tested up to: 3.3 Tested up to: 3.3
Stable tag: 1.1.1 Stable tag: 1.1.2
License: GPLv2 or later License: GPLv2 or later
Draws a gpx track with altitude graph Draws a gpx track with altitude graph
@ -72,6 +72,9 @@ Yes!
2. Admin area 2. Admin area
== Changelog == == Changelog ==
= 1.1.2 =
* Improved page load time
* Added compatibility to Wordpress Multisite (WPMU)
= 1.1.1 = = 1.1.1 =
* minor bug fixes * minor bug fixes
= 1.1.0 = = 1.1.0 =
@ -104,6 +107,7 @@ Yes!
* Initial release. * Initial release.
== Upgrade Notice == == Upgrade Notice ==
= 1.1.2 =
= 1.1.1 = = 1.1.1 =
= 1.1.0 = = 1.1.0 =
= 1.0.9 = = 1.0.9 =

View File

@ -3,12 +3,14 @@
Plugin Name: WP-GPX-Maps Plugin Name: WP-GPX-Maps
Plugin URI: http://www.darwinner.it/ Plugin URI: http://www.darwinner.it/
Description: Draws a gpx track with altitude graph Description: Draws a gpx track with altitude graph
Version: 1.1.1 Version: 1.1.2
Author: Bastianon Massimo Author: Bastianon Massimo
Author URI: http://www.pedemontanadelgrappa.it/ Author URI: http://www.pedemontanadelgrappa.it/
License: GPL License: GPL
*/ */
//error_reporting (E_ALL);
include 'wp-gpx-maps_Utils.php'; include 'wp-gpx-maps_Utils.php';
include 'wp-gpx-maps_admin.php'; include 'wp-gpx-maps_admin.php';
@ -36,7 +38,6 @@ function WP_GPX_Maps_action_links($links, $file) {
return $links; return $links;
} }
function enqueue_WP_GPX_Maps_scripts() function enqueue_WP_GPX_Maps_scripts()
{ {
?> ?>
@ -49,65 +50,39 @@ function enqueue_WP_GPX_Maps_scripts()
<?php <?php
} }
function findValue($attr, $attributeName, $optionName, $defaultValue)
{
$val = '';
if ( isset($attr[$attributeName]) )
{
$val = $attr[$attributeName];
}
if ($val == '')
{
$val = get_option($optionName);
}
if ($val == '')
{
$val = $defaultValue;
}
return $val;
}
function handle_WP_GPX_Maps_Shortcodes($attr, $content='') function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
{ {
$gpx = $attr["gpx"];
$w = $attr["width"];
$mh = $attr["mheight"];
$mt = $attr["mtype"];
$gh = $attr["gheight"];
$showW = $attr['waypoints'];
$donotreducegpx = $attr['donotreducegpx'];
$pointsoffset = $attr['pointsoffset'];
if ($w == '') $gpx = findValue($attr, "gpx", "", "");
{ $w = findValue($attr, "width", "wpgpxmaps_width", "100%");
$w = get_option("wpgpxmaps_width"); $mh = findValue($attr, "mheight", "wpgpxmaps_height", "450px");
} $mt = findValue($attr, "mtype", "wpgpxmaps_map_type", "HYBRID");
$gh = findValue($attr, "gheight", "wpgpxmaps_graph_height", "200px");
if ($mh == '') $showW = findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false);
{ $donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false);
$mh = get_option("wpgpxmaps_height"); $pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10);
}
if ($gh == '')
{
$gh = get_option("wpgpxmaps_graph_height");
}
if ($gh == '')
{
$gh = "200px";
}
if ($pointsoffset == '')
{
$pointsoffset = get_option("wpgpxmaps_pointsoffset");
}
if ($pointsoffset == '')
{
$pointsoffset = 10;
}
if ($mt == '')
{
$mt = get_option("wpgpxmaps_map_type");
}
if ($donotreducegpx == '')
{
$donotreducegpx = get_option("wpgpxmaps_donotreducegpx");
}
if ($showW == '')
{
$showW = get_option("wpgpxmaps_show_waypoint");
}
$r = rand(1,5000000); $r = rand(1,5000000);
$sitePath = substr (__FILE__, 0, strrpos(__FILE__,'wp-content')).DIRECTORY_SEPARATOR; $sitePath = sitePath();
$gpx = trim($gpx); $gpx = trim($gpx);
@ -121,15 +96,15 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$waypoints = ''; $waypoints = '';
foreach ($points as $p) { foreach ($points as $p) {
$points_maps .= "[".(float)$p[0].",".(float)$p[1]."],"; $points_maps .= '['.(float)$p[0].','.(float)$p[1].'],';
$points_graph .= "[".(float)$p[3].",".(float)$p[2]."],"; $points_graph .= '['.(float)$p[3].','.(float)$p[2].'],';
} //all the points are [0,0] $points_graph = preg_replace("/^(\[0,0\],)+$/", "", $points_graph); } //all the points are [0,0] $points_graph = preg_replace("/^(\[0,0\],)+$/", "", $points_graph);
if ($showW == true) if ($showW == true)
{ {
$wpoints = getWayPoints($gpx); $wpoints = getWayPoints($gpx);
foreach ($wpoints as $p) { foreach ($wpoints as $p) {
$waypoints .= "[".(float)$p[0].",".(float)$p[1].",'".unescape($p[4])."','".unescape($p[5])."','".unescape($p[7])."'],"; $waypoints .= '['.(float)$p[0].','.(float)$p[1].',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],';
} }
} }

View File

@ -1,4 +1,28 @@
<?php <?php
function sitePath()
{
return substr(substr(__FILE__, 0, strrpos(__FILE__,'wp-content')), 0, -1);
// $uploadsPath = substr($uploadsPath, 0, -1);
}
function gpxFolderPath()
{
$upload_dir = wp_upload_dir();
$uploadsPath = $upload_dir['basedir'];
$ret = $uploadsPath.DIRECTORY_SEPARATOR."gpx";
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
}
function relativeGpxFolderPath()
{
$sitePath = sitePath();
$realGpxPath = gpxFolderPath();
$ret = str_replace($sitePath,'',$realGpxPath).DIRECTORY_SEPARATOR;
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
}
function getPoints($gpxPath,$gpxOffset = 10, $donotreducegpx) function getPoints($gpxPath,$gpxOffset = 10, $donotreducegpx)
{ {
@ -41,6 +65,10 @@
$points = array(); $points = array();
$gpx = simplexml_load_file($filePath); $gpx = simplexml_load_file($filePath);
if($gpx === FALSE)
return;
$gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0'); $gpx->registerXPathNamespace('10', 'http://www.topografix.com/GPX/1/0');
$gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1'); $gpx->registerXPathNamespace('11', 'http://www.topografix.com/GPX/1/1');
$gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3'); $gpx->registerXPathNamespace('gpxx', 'http://www.garmin.com/xmlschemas/GpxExtensions/v3');
@ -49,6 +77,13 @@
if ( count($nodes) > 0 ) if ( count($nodes) > 0 )
{ {
$lastLat = 0;
$lastLon = 0;
$lastEle = 0;
$dist = 0;
$lastOffset = 0;
// normal case // normal case
foreach($nodes as $trkpt) foreach($nodes as $trkpt)
{ {
@ -84,6 +119,7 @@
$lastLon=$lon; $lastLon=$lon;
$lastEle=$ele; $lastEle=$ele;
} }
unset($nodes);
} }
else else
@ -94,6 +130,12 @@
if ( count($nodes) > 0 ) if ( count($nodes) > 0 )
{ {
$lastLat = 0;
$lastLon = 0;
$lastEle = 0;
$dist = 0;
$lastOffset = 0;
// Garmin case // Garmin case
foreach($nodes as $rpt) foreach($nodes as $rpt)
{ {
@ -127,13 +169,14 @@
$lastLat=$lat; $lastLat=$lat;
$lastLon=$lon; $lastLon=$lon;
} }
unset($nodes);
} }
else else
{ {
echo "Gpx Empty or not supported!"; echo "Empty Gpx or not supported File!";
} }
} }
unset($gpx);
return $points; return $points;
} }

View File

@ -10,11 +10,10 @@ if ( is_admin() ){
} }
function WP_GPX_Maps_html_page() { function WP_GPX_Maps_html_page() {
$realGpxPath = gpxFolderPath();
$uploadsPath = substr (__FILE__, 0, strrpos(__FILE__,'wp-content')).DIRECTORY_SEPARATOR."wp-content".DIRECTORY_SEPARATOR."uploads"; $relativeGpxPath = relativeGpxFolderPath();
$realGpxPath = substr (__FILE__, 0, strrpos(__FILE__,'wp-content')).DIRECTORY_SEPARATOR."wp-content".DIRECTORY_SEPARATOR."uploads".DIRECTORY_SEPARATOR."gpx"; $relativeGpxPath = str_replace("\\","/", $relativeGpxPath);
$gpxRegEx = '/.gpx$/'; $gpxRegEx = '/.gpx$/';
?> ?>
<div> <div>
@ -28,13 +27,7 @@ function WP_GPX_Maps_html_page() {
} }
else else
{ {
if (!@mkdir($realGpxPath,755,true)) {
if(!file_exists($uploadsPath))
{
@mkdir($uploadsPath);
}
if (!@mkdir($realGpxPath)) {
echo '<div class="error" style="padding:10px"> echo '<div class="error" style="padding:10px">
Can\'t create <b>'.$realGpxPath.'</b> folder. Please create it and make it writable!<br /> Can\'t create <b>'.$realGpxPath.'</b> folder. Please create it and make it writable!<br />
If not, you will must update the file manually! If not, you will must update the file manually!
@ -54,9 +47,9 @@ function WP_GPX_Maps_html_page() {
<div style="padding:10px;"> <div style="padding:10px;">
<b>The fastest way to use this plugin:</b> upload the file using the uploader below, than put this <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. shotcode: <b>[sgpx gpx="<?php echo $relativeGpxPath; ?>&lt gpx file name &gt"]</b> in the pages/posts.
<p> <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 waypoints=true donotreducegpx=false pointsoffset=10]</b> <i>Full set of attributes:</i> <b>[sgpx gpx="<?php echo $relativeGpxPath; ?>&lt gpx file name &gt" width=100% mheight=450px gheight=200px mtype=SATELLITE waypoints=true donotreducegpx=false pointsoffset=10]</b>
</p> </p>
</div> </div>
@ -115,7 +108,6 @@ function WP_GPX_Maps_html_page() {
} }
} }
if ( is_writable ( $realGpxPath ) ){ if ( is_writable ( $realGpxPath ) ){
?> ?>
@ -194,7 +186,7 @@ function WP_GPX_Maps_html_page() {
| |
<a href="../wp-content/uploads/gpx/<?php echo $entry?>">Download</a> <a href="../wp-content/uploads/gpx/<?php echo $entry?>">Download</a>
| |
Shortcode: [sgpx gpx="/wp-content/uploads/gpx/<?php echo $entry?>"] Shortcode: [sgpx gpx="<?php echo $relativeGpxPath . $entry; ?>"]
</td> </td>
</tr> </tr>
<?php <?php