From 9f63c289c9aa95c8e8f092a083ae7f912e6d9b04 Mon Sep 17 00:00:00 2001 From: bastianonm Date: Mon, 8 Sep 2014 07:19:44 +0000 Subject: [PATCH] * Fix: remote file download issue * Fix: download file link with WPML * Improved cache with filetime (thanks to David) --- readme.txt | 10 +++++--- wp-gpx-maps.php | 58 +++++++++++++++++++++++++++++++------------ wp-gpx-maps_admin.php | 2 +- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/readme.txt b/readme.txt index ad73ca7..5135dd0 100644 --- a/readme.txt +++ b/readme.txt @@ -4,8 +4,8 @@ Contributors: bastianonm 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 Requires at least: 2.0.0 -Tested up to: 3.9 -Stable tag: 1.3.5 +Tested up to: 4.0 +Stable tag: 1.3.6 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 == 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 = * Fix: Garmin cadence again * Fix: WP Tabs @@ -194,7 +198,7 @@ Yes! * Fix: Garmin cadence * Infowindows closing on mouseout = 1.3.3 = -* Add feet/Nautical Miles units (thanks to elperepat) +* Add feet/Nautical Miles units (thanks to elperepat) * Update OpenStreetMaps Credits * WP Tabs fix = 1.3.2 = diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index 28aa0cf..e30b312 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -3,7 +3,7 @@ Plugin Name: WP-GPX-Maps Plugin URI: http://www.devfarm.it/ Description: Draws a GPX track with altitude chart -Version: 1.3.5 +Version: 1.3.6 Author: Bastianon Massimo 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); $currentpositioncon = findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", ""); - $colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\""; $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); @@ -691,7 +698,9 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') } else { - $gpxurl = get_bloginfo('url').$gpxurl; + // wpml fix + $dummy = ( defined('WP_SITEURL') ) ? WP_SITEURL : get_bloginfo('url'); + $gpxurl = $dummy.$gpxurl; } $output.="".__("Download", "wp-gpx-maps").""; } @@ -760,21 +769,38 @@ function downloadRemoteFile($remoteFile) { try { - $ch = curl_init(); - 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' ); + $newfname = tempnam ( '/tmp', 'gpx' ); - $fp = fopen($tmpfname, "w"); - fwrite($fp, $resp); - fclose($fp); + if (function_exists ( "file_put_contents" )) // PHP 5.1.0 + + { + 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) { + + print_r($e); + return ''; } } diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php index 425616a..34e58cd 100644 --- a/wp-gpx-maps_admin.php +++ b/wp-gpx-maps_admin.php @@ -137,7 +137,7 @@ function WP_GPX_Maps_html_page() {

- Bugs, problems, thanks and anything else here! + Bugs, problems, thanks and anything else here!