From 4d1ef1e7c3b4deeff4f55fb114be856aa3ed3bf5 Mon Sep 17 00:00:00 2001 From: bastianonm Date: Tue, 24 Jan 2012 17:05:59 +0000 Subject: [PATCH] --- readme.txt | 7 +++++-- wp-gpx-maps.php | 32 +++++++++++++++++++++++++++++--- wp-gpx-maps_Utils.php | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/readme.txt b/readme.txt index e9ae85b..1d9297e 100644 --- a/readme.txt +++ b/readme.txt @@ -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 Requires at least: 2.0.0 Tested up to: 3.3 -Stable tag: 1.1.2 +Stable tag: 1.1.3 License: GPLv2 or later Draws a gpx track with altitude graph @@ -34,7 +34,7 @@ Supported gpx namespace are: 1. Activate the plugin through the 'Plugins' menu in WordPress -1. Add the shortcode [sgpx gpx=">relative path to your gpx<"] +1. Add the shortcode [sgpx gpx=">relative path to your gpx<"] or [sgpx gpx=">http://somesite.com/files/yourfile.gpx<"] == Frequently Asked Questions == @@ -72,6 +72,8 @@ Yes! 2. Admin area == Changelog == += 1.1.3 = +* Allowed gpx files from http url = 1.1.2 = * Improved page load time * Added compatibility to Wordpress Multisite (WPMU) @@ -107,6 +109,7 @@ Yes! * Initial release. == Upgrade Notice == += 1.1.3 = = 1.1.2 = = 1.1.1 = = 1.1.0 = diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index 6600b31..bc2e62f 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -3,7 +3,7 @@ Plugin Name: WP-GPX-Maps Plugin URI: http://www.darwinner.it/ Description: Draws a gpx track with altitude graph -Version: 1.1.2 +Version: 1.1.3 Author: Bastianon Massimo Author URI: http://www.pedemontanadelgrappa.it/ License: GPL @@ -86,9 +86,17 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $gpx = trim($gpx); - $gpx = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gpx); + if (strpos($gpx, "http://") !== 0) + { + $gpx = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $gpx); + $gpx = $sitePath . $gpx; + } + else + { + $gpx = downloadRemoteFile($gpx); + print_r($gpx); + } - $gpx = $sitePath . $gpx; $points = getPoints( $gpx, $pointsoffset, $donotreducegpx); $points_maps = ''; @@ -133,6 +141,24 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') return $output; } +function downloadRemoteFile($remoteFile) +{ + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $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"); + fwrite($fp, $resp); + fclose($fp); + + return $tmpfname; +} + function unescape($value) { $value = str_replace("'", "\'", $value); diff --git a/wp-gpx-maps_Utils.php b/wp-gpx-maps_Utils.php index 7343866..bc646dc 100644 --- a/wp-gpx-maps_Utils.php +++ b/wp-gpx-maps_Utils.php @@ -25,7 +25,7 @@ function getPoints($gpxPath,$gpxOffset = 10, $donotreducegpx) { - + $points = array(); $dist=0;