* Fix: remote file download issue

* Fix: download file link with WPML
* Improved cache with filetime (thanks to David)
This commit is contained in:
bastianonm 2014-09-08 07:19:44 +00:00
parent 59fe169525
commit 9f63c289c9
3 changed files with 50 additions and 20 deletions

View File

@ -4,8 +4,8 @@ Contributors: bastianonm
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8VHWLRW6JBTML Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8VHWLRW6JBTML
Tags: maps, gpx, gps, graph, chart, google maps, track, garmin, image, nextgen-gallery, nextgen, exif, OpenStreetMap, OpenCycleMap, Hike&Bike, heart rate, heartrate, cadence Tags: maps, gpx, gps, graph, chart, google maps, track, garmin, image, nextgen-gallery, nextgen, exif, OpenStreetMap, OpenCycleMap, Hike&Bike, heart rate, heartrate, cadence
Requires at least: 2.0.0 Requires at least: 2.0.0
Tested up to: 3.9 Tested up to: 4.0
Stable tag: 1.3.5 Stable tag: 1.3.6
Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map. Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map.
@ -187,6 +187,10 @@ Yes!
1. Altitude & Speed & Hearth rate 1. Altitude & Speed & Hearth rate
== Changelog == == Changelog ==
= 1.3.6 =
* Fix: remote file download issue
* Fix: download file link with WPML
* Improved cache with filetime (thanks to David)
= 1.3.5 = = 1.3.5 =
* Fix: Garmin cadence again * Fix: Garmin cadence again
* Fix: WP Tabs * Fix: WP Tabs
@ -194,7 +198,7 @@ Yes!
* Fix: Garmin cadence * Fix: Garmin cadence
* Infowindows closing on mouseout * Infowindows closing on mouseout
= 1.3.3 = = 1.3.3 =
* Add feet/Nautical Miles units (thanks to elperepat) * Add feet/Nautical Miles units (thanks to elperepat)
* Update OpenStreetMaps Credits * Update OpenStreetMaps Credits
* WP Tabs fix * WP Tabs fix
= 1.3.2 = = 1.3.2 =

View File

@ -3,7 +3,7 @@
Plugin Name: WP-GPX-Maps Plugin Name: WP-GPX-Maps
Plugin URI: http://www.devfarm.it/ Plugin URI: http://www.devfarm.it/
Description: Draws a GPX track with altitude chart Description: Draws a GPX track with altitude chart
Version: 1.3.5 Version: 1.3.6
Author: Bastianon Massimo Author: Bastianon Massimo
Author URI: http://www.pedemontanadelgrappa.it/ Author URI: http://www.pedemontanadelgrappa.it/
*/ */
@ -244,12 +244,19 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$usegpsposition = findValue($attr, "usegpsposition", "wpgpxmaps_usegpsposition", false); $usegpsposition = findValue($attr, "usegpsposition", "wpgpxmaps_usegpsposition", false);
$currentpositioncon = findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", ""); $currentpositioncon = findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", "");
$colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\""; $colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\"";
$gpxurl = $gpx; $gpxurl = $gpx;
// Add file modification time to cache filename to catch new uploads with same file name
$mtime = sitePath() . str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, trim($gpx));
if(file_exists($mtime)) {
$mtime = filemtime($mtime);
} else {
$mtime = 0;
}
$cacheFileName = "$gpx,$w,$mh,$mt,$gh,$showEle,$showW,$showHr,$showAtemp,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$showGrade,$uomspeed,$uom,$distanceType,v1.3.5"; $cacheFileName = "$gpx,$mtime,$w,$mh,$mt,$gh,$showEle,$showW,$showHr,$showAtemp,$showCad,$donotreducegpx,$pointsoffset,$showSpeed,$showGrade,$uomspeed,$uom,$distanceType,v1.3.5";
$cacheFileName = md5($cacheFileName); $cacheFileName = md5($cacheFileName);
@ -691,7 +698,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
} }
else { else {
$gpxurl = get_bloginfo('url').$gpxurl; // wpml fix
$dummy = ( defined('WP_SITEURL') ) ? WP_SITEURL : get_bloginfo('url');
$gpxurl = $dummy.$gpxurl;
} }
$output.="<a href='$gpxurl' target='_new'>".__("Download", "wp-gpx-maps")."</a>"; $output.="<a href='$gpxurl' target='_new'>".__("Download", "wp-gpx-maps")."</a>";
} }
@ -760,21 +769,38 @@ function downloadRemoteFile($remoteFile)
{ {
try try
{ {
$ch = curl_init(); $newfname = tempnam ( '/tmp', 'gpx' );
curl_setopt($ch, CURLOPT_URL, str_replace(' ', '%20', $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"); if (function_exists ( "file_put_contents" )) // PHP 5.1.0 +
fwrite($fp, $resp); {
fclose($fp); file_put_contents($newfname , fopen($remoteFile, 'r'));
return $newfname;
}
$file = fopen ($remoteFile, "rb");
if ($file) {
$newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
return $newfname;
return $tmpfname;
} catch (Exception $e) { } catch (Exception $e) {
print_r($e);
return ''; return '';
} }
} }

View File

@ -137,7 +137,7 @@ function WP_GPX_Maps_html_page() {
</ul> </ul>
<p> <p>
<a href="http://www.darwinner.it/forums/forum/wp-gpx-maps/">Bugs, problems, thanks and anything else here!</a> <a href="http://devfarm.it/forums/forum/wp-gpx-maps/">Bugs, problems, thanks and anything else here!</a>
</p> </p>
</p> </p>