This commit is contained in:
parent
bf466863af
commit
835f873705
|
@ -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.4
|
Stable tag: 1.1.5
|
||||||
License: GPLv2 or later
|
License: GPLv2 or later
|
||||||
|
|
||||||
Draws a gpx track with altitude graph
|
Draws a gpx track with altitude graph
|
||||||
|
@ -79,6 +79,9 @@ Yes!
|
||||||
2. Admin area - Settings
|
2. Admin area - Settings
|
||||||
|
|
||||||
== Changelog ==
|
== Changelog ==
|
||||||
|
= 1.1.5 =
|
||||||
|
* implemented cache (the plugin is much faster, especially on slow servers or external gpx)
|
||||||
|
* minor bug fixes
|
||||||
= 1.1.4 =
|
= 1.1.4 =
|
||||||
* improved admin area
|
* improved admin area
|
||||||
* added miles/feet unit of measure
|
* added miles/feet unit of measure
|
||||||
|
@ -121,6 +124,7 @@ Yes!
|
||||||
* Initial release.
|
* Initial release.
|
||||||
|
|
||||||
== Upgrade Notice ==
|
== Upgrade Notice ==
|
||||||
|
= 1.1.5 =
|
||||||
= 1.1.4 =
|
= 1.1.4 =
|
||||||
= 1.1.3 =
|
= 1.1.3 =
|
||||||
= 1.1.2 =
|
= 1.1.2 =
|
||||||
|
|
108
wp-gpx-maps.php
108
wp-gpx-maps.php
|
@ -3,7 +3,7 @@
|
||||||
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.4
|
Version: 1.1.5
|
||||||
Author: Bastianon Massimo
|
Author: Bastianon Massimo
|
||||||
Author URI: http://www.pedemontanadelgrappa.it/
|
Author URI: http://www.pedemontanadelgrappa.it/
|
||||||
License: GPL
|
License: GPL
|
||||||
|
@ -85,55 +85,93 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
|
||||||
|
|
||||||
$r = rand(1,5000000);
|
$r = rand(1,5000000);
|
||||||
|
|
||||||
$sitePath = sitePath();
|
$cacheFileName = md5($gpx.$w.$mh.$mt.$gh.$showW.$donotreducegpx.$pointsoffset);
|
||||||
|
$gpxcache = gpxCacheFolderPath();
|
||||||
|
|
||||||
$gpx = trim($gpx);
|
if(!(file_exists($gpxcache) && is_dir($gpxcache)))
|
||||||
|
|
||||||
if (strpos($gpx, "http://") !== 0)
|
|
||||||
{
|
{
|
||||||
$gpx = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gpx);
|
@mkdir($gpxcache,0755,true);
|
||||||
$gpx = $sitePath . $gpx;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$gpx = downloadRemoteFile($gpx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$points = getPoints( $gpx, $pointsoffset, $donotreducegpx);
|
$gpxcache.= DIRECTORY_SEPARATOR.$cacheFileName.".tmp";
|
||||||
$points_maps = '';
|
|
||||||
$points_graph = '';
|
|
||||||
$waypoints = '';
|
|
||||||
|
|
||||||
foreach ($points as $p) {
|
// Try to load cache
|
||||||
$points_maps .= '['.(float)$p[0].','.(float)$p[1].'],';
|
if (file_exists($gpxcache))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$cache_str = file_get_contents($gpxcache);
|
||||||
|
$cache_obj = unserialize($cache_str);
|
||||||
|
$points_maps = $cache_obj["points_maps"];
|
||||||
|
$points_graph = $cache_obj["points_graph"];
|
||||||
|
$waypoints = $cache_obj["waypoints"];
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$points_maps= '';
|
||||||
|
$points_graph= '';
|
||||||
|
$waypoints= '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($uom == '1')
|
if ($points_maps == '')
|
||||||
|
{
|
||||||
|
|
||||||
|
$sitePath = sitePath();
|
||||||
|
|
||||||
|
$gpx = trim($gpx);
|
||||||
|
|
||||||
|
if (strpos($gpx, "http://") !== 0)
|
||||||
{
|
{
|
||||||
// Miles and feet
|
$gpx = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gpx);
|
||||||
$points_graph .= '['.((float)$p[3]*0.000621371192).','.((float)$p[2]*3.2808399).'],';
|
$gpx = $sitePath . $gpx;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$points_graph .= '['.(float)$p[3].','.(float)$p[2].'],';
|
$gpx = downloadRemoteFile($gpx);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($showW == true)
|
$points = getPoints( $gpx, $pointsoffset, $donotreducegpx);
|
||||||
{
|
$points_maps = '';
|
||||||
$wpoints = getWayPoints($gpx);
|
$points_graph = '';
|
||||||
foreach ($wpoints as $p) {
|
$waypoints = '';
|
||||||
$waypoints .= '['.(float)$p[0].','.(float)$p[1].',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],';
|
|
||||||
|
foreach ($points as $p) {
|
||||||
|
$points_maps .= '['.(float)$p[0].','.(float)$p[1].'],';
|
||||||
|
|
||||||
|
if ($uom == '1')
|
||||||
|
{
|
||||||
|
// Miles and feet
|
||||||
|
$points_graph .= '['.((float)$p[3]*0.000621371192).','.((float)$p[2]*3.2808399).'],';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$points_graph .= '['.(float)$p[3].','.(float)$p[2].'],';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$p="/,$/";
|
if ($showW == true)
|
||||||
$points_maps = preg_replace($p, "", $points_maps);
|
{
|
||||||
$points_graph = preg_replace($p, "", $points_graph);
|
$wpoints = getWayPoints($gpx);
|
||||||
$waypoints = preg_replace($p, "", $waypoints);
|
foreach ($wpoints as $p) {
|
||||||
|
$waypoints .= '['.(float)$p[0].','.(float)$p[1].',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match("/^(\[0,0\],?)+$/", $points_graph))
|
$p="/,$/";
|
||||||
{
|
$points_maps = preg_replace($p, "", $points_maps);
|
||||||
$points_graph = "";
|
$points_graph = preg_replace($p, "", $points_graph);
|
||||||
|
$waypoints = preg_replace($p, "", $waypoints);
|
||||||
|
|
||||||
|
if (preg_match("/^(\[0,0\],?)+$/", $points_graph))
|
||||||
|
{
|
||||||
|
$points_graph = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@file_put_contents($gpxcache,
|
||||||
|
serialize(array("points_maps" => $points_maps,
|
||||||
|
"points_graph" => $points_graph,
|
||||||
|
"waypoints" => $waypoints)
|
||||||
|
),
|
||||||
|
LOCK_EX);
|
||||||
|
@chmod($gpxcache,0755);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output = '
|
$output = '
|
||||||
|
|
|
@ -15,6 +15,14 @@
|
||||||
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
|
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function gpxCacheFolderPath()
|
||||||
|
{
|
||||||
|
$upload_dir = wp_upload_dir();
|
||||||
|
$uploadsPath = $upload_dir['basedir'];
|
||||||
|
$ret = $uploadsPath.DIRECTORY_SEPARATOR."gpx".DIRECTORY_SEPARATOR."cache";
|
||||||
|
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
|
||||||
|
}
|
||||||
|
|
||||||
function relativeGpxFolderPath()
|
function relativeGpxFolderPath()
|
||||||
{
|
{
|
||||||
$sitePath = sitePath();
|
$sitePath = sitePath();
|
||||||
|
@ -23,6 +31,43 @@
|
||||||
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
|
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function recursive_remove_directory($directory, $empty=FALSE)
|
||||||
|
{
|
||||||
|
if(substr($directory,-1) == '/')
|
||||||
|
{
|
||||||
|
$directory = substr($directory,0,-1);
|
||||||
|
}
|
||||||
|
if(!file_exists($directory) || !is_dir($directory))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}elseif(is_readable($directory))
|
||||||
|
{
|
||||||
|
$handle = opendir($directory);
|
||||||
|
while (FALSE !== ($item = readdir($handle)))
|
||||||
|
{
|
||||||
|
if($item != '.' && $item != '..')
|
||||||
|
{
|
||||||
|
$path = $directory.'/'.$item;
|
||||||
|
if(is_dir($path))
|
||||||
|
{
|
||||||
|
recursive_remove_directory($path);
|
||||||
|
}else{
|
||||||
|
unlink($path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
if($empty == FALSE)
|
||||||
|
{
|
||||||
|
if(!rmdir($directory))
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
function getPoints($gpxPath,$gpxOffset = 10, $donotreducegpx)
|
function getPoints($gpxPath,$gpxOffset = 10, $donotreducegpx)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ function ilc_admin_tabs( $current ) {
|
||||||
|
|
||||||
function WP_GPX_Maps_html_page() {
|
function WP_GPX_Maps_html_page() {
|
||||||
$realGpxPath = gpxFolderPath();
|
$realGpxPath = gpxFolderPath();
|
||||||
|
$cacheGpxPath = gpxCacheFolderPath();
|
||||||
$relativeGpxPath = relativeGpxFolderPath();
|
$relativeGpxPath = relativeGpxFolderPath();
|
||||||
$relativeGpxPath = str_replace("\\","/", $relativeGpxPath);
|
$relativeGpxPath = str_replace("\\","/", $relativeGpxPath);
|
||||||
$gpxRegEx = '/.gpx$/';
|
$gpxRegEx = '/.gpx$/';
|
||||||
|
@ -42,7 +43,7 @@ function WP_GPX_Maps_html_page() {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!@mkdir($realGpxPath,755,true)) {
|
if (!@mkdir($realGpxPath,0755,true)) {
|
||||||
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!
|
||||||
|
@ -50,6 +51,20 @@ function WP_GPX_Maps_html_page() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(file_exists($cacheGpxPath) && is_dir($cacheGpxPath))
|
||||||
|
{
|
||||||
|
//dir exsist!
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!@mkdir($cacheGpxPath,0755,true)) {
|
||||||
|
echo '<div class="error" style="padding:10px">
|
||||||
|
Can\'t create <b>'.$cacheGpxPath.'</b> folder. Please create it and make it writable!<br />
|
||||||
|
If not, cache will not created and your site could be slower!
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ilc_admin_tabs($tab);
|
ilc_admin_tabs($tab);
|
||||||
|
|
||||||
if ($tab == "tracks")
|
if ($tab == "tracks")
|
||||||
|
|
|
@ -9,12 +9,18 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isset($_POST['clearcache']) )
|
||||||
|
{
|
||||||
|
echo "pulisco la cahce";
|
||||||
|
recursive_remove_directory($cacheGpxPath,true);
|
||||||
|
}
|
||||||
|
|
||||||
if ( is_writable ( $realGpxPath ) ){
|
if ( is_writable ( $realGpxPath ) ){
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="tablenav top">
|
<div class="tablenav top">
|
||||||
<form enctype="multipart/form-data" method="POST">
|
<form enctype="multipart/form-data" method="POST" style="float:left; margin:5px 20px 0 0">
|
||||||
Choose a file to upload: <input name="uploadedfile" type="file" onchange="submitgpx(this);" />
|
Choose a file to upload: <input name="uploadedfile" type="file" onchange="submitgpx(this);" />
|
||||||
<?php
|
<?php
|
||||||
if ( isset($_FILES['uploadedfile']) )
|
if ( isset($_FILES['uploadedfile']) )
|
||||||
|
@ -35,6 +41,11 @@
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form method="POST" style="float:left; margin:5px 20px 0 0">
|
||||||
|
<input type="submit" name="clearcache" value="Clear Cache" />
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
@ -83,11 +94,11 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan=3 style="padding: 0px 7px 7px 7px;">
|
<td colspan=3 style="padding: 0px 7px 7px 7px;">
|
||||||
<a href="#" onclick="delgpx('<?php echo $entry ?>'); return false;">Delete</a>
|
<a href="#" onclick="delgpx('<?php echo $entry ?>'); return false;">Delete</a>
|
||||||
|
|
|
|
||||||
<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="<?php echo $relativeGpxPath . $entry; ?>"]
|
Shortcode: [sgpx gpx="<?php echo $relativeGpxPath . $entry; ?>"]
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
|
|
Loading…
Reference in New Issue