From d00e3816d5f829f092e6b6e9a6ae13f05c0af47d Mon Sep 17 00:00:00 2001 From: bastianonm Date: Fri, 20 Mar 2015 09:26:20 +0000 Subject: [PATCH] NextGen Gallery's Attachment support. Thanks to Stephan Klein (https://klein-gedruckt.de/2015/03/wordpress-plugin-wp-gpx-maps/) --- readme.txt | 12 +++++-- wp-gpx-maps.php | 11 ++++++ wp-gpx-maps_admin.php | 2 ++ wp-gpx-maps_utils.php | 60 +++++++++++++++++++++++++++++++++ wp-gpx-maps_utils_nggallery.php | 2 +- 5 files changed, 83 insertions(+), 4 deletions(-) diff --git a/readme.txt b/readme.txt index 5135dd0..e5f9485 100644 --- a/readme.txt +++ b/readme.txt @@ -1,11 +1,11 @@ === WP GPX Maps === -Contributors: bastianonm +Contributors: bastianonm, Stephan Klein 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: 4.0 -Stable tag: 1.3.6 +Tested up to: 4.1.1 +Stable tag: 1.3.7 Draws a gpx track with altitude graph. You can also display your nextgen gallery images in the map. @@ -33,6 +33,10 @@ Even if you don't have a gps camera, this plugin can retrive the image position Old NGGallery Images (without gps data) and gpx: http://www.pedemontanadelgrappa.it/mappe/itinerario-3-alta-via-degli-eroi/ +Post Attachments Integration: + +This version is extended by Stephan Klein (https://klein-gedruckt.de/2015/03/wordpress-plugin-wp-gpx-maps/) and supports displaying all images attached to a post without using NGG. + Translated into 14 languages: - Catalan ca @@ -187,6 +191,8 @@ Yes! 1. Altitude & Speed & Hearth rate == Changelog == += 1.3.7 = +* NextGen Gallery's Attachment support. Thanks to Stephan Klein (https://klein-gedruckt.de/2015/03/wordpress-plugin-wp-gpx-maps/) = 1.3.6 = * Fix: remote file download issue * Fix: download file link with WPML diff --git a/wp-gpx-maps.php b/wp-gpx-maps.php index e30b312..783370f 100644 --- a/wp-gpx-maps.php +++ b/wp-gpx-maps.php @@ -226,6 +226,8 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $waypointIcon = findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", ""); $ngGalleries = findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", ""); $ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", ""); + // folgende Zeile hinzugefügt: + $attachments = findValue($attr, "attachments", "wpgpxmaps_map_attachments", false); $download = findValue($attr, "download", "wpgpxmaps_download", ""); $dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0); $distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); @@ -564,6 +566,15 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='') $ngimgs_data .= ''.$data.''; } } +// Folgende Zeilen hinzugefügt + if ($attachments == true) { + $attimgs = getAttachedImages($points_x_time, $points_x_lat, $points_x_lon, $dtoffset, $error); + foreach ($attimgs as $img) { + $data = $img['data']; + $data = str_replace("\n","",$data); + $ngimgs_data .= ''.$data.''; + } + } if (!($skipcache == true)) { diff --git a/wp-gpx-maps_admin.php b/wp-gpx-maps_admin.php index 34e58cd..1f0d50e 100644 --- a/wp-gpx-maps_admin.php +++ b/wp-gpx-maps_admin.php @@ -130,6 +130,8 @@ function WP_GPX_Maps_html_page() {
  • currentIcon: Current position icon (when mouse hover)
  • nggalleries: NextGen Gallery id or a list of Galleries id separated by a comma
  • ngimages: NextGen Image id or a list of Images id separated by a comma
  • + +
  • attachments: show all images that are attached to post (default is false)
  • dtoffset: the difference (in seconds) between your gpx tool date and your camera date
  • zoomonscrollwheel: zoom on map when mouse scroll wheel (default is FALSE)
  • download: Allow users to download your GPX file (default is FALSE)
  • diff --git a/wp-gpx-maps_utils.php b/wp-gpx-maps_utils.php index 73e02f5..1aba4c3 100644 --- a/wp-gpx-maps_utils.php +++ b/wp-gpx-maps_utils.php @@ -2,6 +2,66 @@ require_once("wp-gpx-maps_utils_nggallery.php"); + function getAttachedImages($dt, $lat, $lon, $dtoffset, &$error) + { + $result = array(); + + try { + $attachments = get_children( array( + 'post_parent' => get_the_ID(), + 'post_type' => 'attachment', + 'numberposts' => -1, // show all -1 + 'post_status' => 'inherit', + 'post_mime_type' => 'image', + 'order' => 'ASC', + 'orderby' => 'menu_order ASC') + ); + + foreach ($attachments as $attachment_id => $attachment) { + + $img_src = wp_get_attachment_image_src($attachment_id,'full'); + $img_thmb = wp_get_attachment_image_src($attachment_id,'thumbnail'); + $img_metadata = wp_get_attachment_metadata( $attachment_id); + + $item = array(); + $item["data"] = wp_get_attachment_link( $attachment_id, array(105,105) ); + + if (is_callable('exif_read_data')) { + $exif = @exif_read_data($img_src[0]); + if ($exif !== false) + { + $item["lon"] = getExifGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']); + $item["lat"] = getExifGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']); + if (($item["lat"] != 0) || ($item["lon"] != 0)) + { + $result[] = $item; + } + else if (isset($p->imagedate)) + { + $_dt = strtotime($p->imagedate) + $dtoffset; + $_item = findItemCoordinate($_dt, $dt, $lat, $lon); + if ($_item != null) + { + $item["lat"] = $_item["lat"]; + $item["lon"] = $_item["lon"]; + $result[] = $item; + } + } + } + } + else + { + $error .= "Sorry, exif_read_data function not found! check your hosting..
    "; + } + } + + } catch (Exception $e) { + $error .= 'Error When Retrieving attached images: $e
    '; + } + + return $result; + } + function sitePath() { return substr(substr(__FILE__, 0, strrpos(__FILE__,'wp-content')), 0, -1); diff --git a/wp-gpx-maps_utils_nggallery.php b/wp-gpx-maps_utils_nggallery.php index 3a5c9f0..0c98a12 100644 --- a/wp-gpx-maps_utils_nggallery.php +++ b/wp-gpx-maps_utils_nggallery.php @@ -14,6 +14,7 @@ return is_plugin_active("nextgen-gallery-pro/nggallery-pro.php"); } + function getNGGalleryImages($ngGalleries, $ngImages, $dt, $lat, $lon, $dtoffset, &$error) { @@ -95,7 +96,6 @@ } } } - /* END FIX NEXT GEN GALLERY PRO */ }