* Improved security

* Included external javascript
* Multiple file upload
* Implemented sorting in file list
* Renamed internal function to improve wp compatibility
This commit is contained in:
bastianonm 2018-03-10 10:40:30 +00:00
parent a42f2091c6
commit 529ff95bbe
9 changed files with 232 additions and 169 deletions

10
js/Chart.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
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: 4.9.4 Tested up to: 4.9.4
Stable tag: 1.5.00 Stable tag: 1.5.01
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.
@ -153,6 +153,12 @@ Yes!
1. Altitude & Speed & Hearth rate 1. Altitude & Speed & Hearth rate
== Changelog == == Changelog ==
= 1.5.01 =
* Improved security
* Included javascript
* Multiple file upload
* Implemented sorting in file list
* Renamed internal function to improve wp compatibility
= 1.5.00 = = 1.5.00 =
* replaced highcharts with chartjs. This is a forced choice due highcharts license issue, view: https://devfarm.it/wordpress-plugin/wordpress-plugin-directory-notice-wp-gpx-maps-temporarily-disabled/ * replaced highcharts with chartjs. This is a forced choice due highcharts license issue, view: https://devfarm.it/wordpress-plugin/wordpress-plugin-directory-notice-wp-gpx-maps-temporarily-disabled/
= 1.3.16 = = 1.3.16 =

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.5.00 Version: 1.5.01
Author: Bastianon Massimo Author: Bastianon Massimo
Author URI: http://www.devfarm.it/ Author URI: http://www.devfarm.it/
*/ */
@ -46,22 +46,26 @@ function WP_GPX_Maps_action_links($links, $file) {
return $links; return $links;
} }
function enqueue_WP_GPX_Maps_scripts() function enqueue_WP_GPX_Maps_scripts() {
{
wp_register_script('chartjs', plugins_url( '/js/Chart.min.js', __FILE__ ), array(), "2.7.2" );
wp_register_script('WP-GPX-Maps', plugins_url( '/js/WP-GPX-Maps.js', __FILE__ ), array('jquery','googlemaps','chartjs'), "1.5.00" );
$wpgpxmaps_googlemapsv3_apikey = get_option('wpgpxmaps_googlemapsv3_apikey'); $wpgpxmaps_googlemapsv3_apikey = get_option('wpgpxmaps_googlemapsv3_apikey');
wp_enqueue_script( 'jquery' );
if ($wpgpxmaps_googlemapsv3_apikey) { if ($wpgpxmaps_googlemapsv3_apikey) {
wp_enqueue_script( 'googlemaps', '//maps.googleapis.com/maps/api/js?key='.$wpgpxmaps_googlemapsv3_apikey, null, null); wp_enqueue_script('googlemaps', '//maps.googleapis.com/maps/api/js?key='.$wpgpxmaps_googlemapsv3_apikey, null, null);
} }
else { else {
wp_enqueue_script( 'googlemaps', '//maps.googleapis.com/maps/api/js', null, null); wp_enqueue_script('googlemaps', '//maps.googleapis.com/maps/api/js', null, null);
} }
wp_enqueue_script( 'chartjs', '//cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js', array(), "2.7.2" );
wp_enqueue_script( 'WP-GPX-Maps', plugins_url('/WP-GPX-Maps.js', __FILE__), array('jquery','googlemaps','chartjs'), "1.5.00"); wp_enqueue_script('jquery');
wp_enqueue_script('chartjs');
wp_enqueue_script('WP-GPX-Maps');
} }
function print_WP_GPX_Maps_styles() function print_WP_GPX_Maps_styles() {
{
?> ?>
<style type="text/css"> <style type="text/css">
@ -100,8 +104,7 @@ function print_WP_GPX_Maps_styles()
<?php <?php
} }
function findValue($attr, $attributeName, $optionName, $defaultValue) function wpgpxmaps_findValue($attr, $attributeName, $optionName, $defaultValue) {
{
$val = ''; $val = '';
if ( isset($attr[$attributeName]) ) { if ( isset($attr[$attributeName]) ) {
$val = $attr[$attributeName]; $val = $attr[$attributeName];
@ -118,13 +121,13 @@ function findValue($attr, $attributeName, $optionName, $defaultValue)
return $val; return $val;
} }
function handle_WP_GPX_Maps_folder_Shortcodes($attr, $content=''){ function handle_WP_GPX_Maps_folder_Shortcodes($attr, $content='') {
$folder = findValue($attr, "folder", "", ""); $folder = wpgpxmaps_findValue($attr, "folder", "", "");
$pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10); $pointsoffset = wpgpxmaps_findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10);
$distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); $distanceType = wpgpxmaps_findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0);
$donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false); $donotreducegpx = wpgpxmaps_findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false);
$uom = findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0"); $uom = wpgpxmaps_findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0");
// fix folder path // fix folder path
$sitePath = sitePath(); $sitePath = sitePath();
@ -206,60 +209,60 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$error = ''; $error = '';
$gpx = findValue($attr, "gpx", "", ""); $gpx = wpgpxmaps_findValue($attr, "gpx", "", "");
$w = findValue($attr, "width", "wpgpxmaps_width", "100%"); $w = wpgpxmaps_findValue($attr, "width", "wpgpxmaps_width", "100%");
$mh = findValue($attr, "mheight", "wpgpxmaps_height", "450px"); $mh = wpgpxmaps_findValue($attr, "mheight", "wpgpxmaps_height", "450px");
$mt = findValue($attr, "mtype", "wpgpxmaps_map_type", "HYBRID"); $mt = wpgpxmaps_findValue($attr, "mtype", "wpgpxmaps_map_type", "HYBRID");
$gh = findValue($attr, "gheight", "wpgpxmaps_graph_height", "200px"); $gh = wpgpxmaps_findValue($attr, "gheight", "wpgpxmaps_graph_height", "200px");
$showCad = findValue($attr, "showcad", "wpgpxmaps_show_cadence", false); $showCad = wpgpxmaps_findValue($attr, "showcad", "wpgpxmaps_show_cadence", false);
$showHr = findValue($attr, "showhr", "wpgpxmaps_show_hr", false); $showHr = wpgpxmaps_findValue($attr, "showhr", "wpgpxmaps_show_hr", false);
$showAtemp = findValue($attr, "showatemp", "wpgpxmaps_show_atemp", false); $showAtemp = wpgpxmaps_findValue($attr, "showatemp", "wpgpxmaps_show_atemp", false);
$showW = findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false); $showW = wpgpxmaps_findValue($attr, "waypoints", "wpgpxmaps_show_waypoint", false);
$showEle = findValue($attr, "showele", "wpgpxmaps_show_elevation", "true"); $showEle = wpgpxmaps_findValue($attr, "showele", "wpgpxmaps_show_elevation", "true");
$showSpeed = findValue($attr, "showspeed", "wpgpxmaps_show_speed", false); $showSpeed = wpgpxmaps_findValue($attr, "showspeed", "wpgpxmaps_show_speed", false);
$showGrade = findValue($attr, "showgrade", "wpgpxmaps_show_grade", false); $showGrade = wpgpxmaps_findValue($attr, "showgrade", "wpgpxmaps_show_grade", false);
$zoomOnScrollWheel = findValue($attr, "zoomonscrollwheel", "wpgpxmaps_zoomonscrollwheel", false); $zoomOnScrollWheel = wpgpxmaps_findValue($attr, "zoomonscrollwheel", "wpgpxmaps_zoomonscrollwheel", false);
$donotreducegpx = findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false); $donotreducegpx = wpgpxmaps_findValue($attr, "donotreducegpx", "wpgpxmaps_donotreducegpx", false);
$pointsoffset = findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10); $pointsoffset = wpgpxmaps_findValue($attr, "pointsoffset", "wpgpxmaps_pointsoffset", 10);
$uom = findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0"); $uom = wpgpxmaps_findValue($attr, "uom", "wpgpxmaps_unit_of_measure", "0");
$uomspeed = findValue($attr, "uomspeed", "wpgpxmaps_unit_of_measure_speed", "0"); $uomspeed = wpgpxmaps_findValue($attr, "uomspeed", "wpgpxmaps_unit_of_measure_speed", "0");
$color_map = findValue($attr, "mlinecolor", "wpgpxmaps_map_line_color", "#3366cc"); $color_map = wpgpxmaps_findValue($attr, "mlinecolor", "wpgpxmaps_map_line_color", "#3366cc");
$color_graph = findValue($attr, "glinecolor", "wpgpxmaps_graph_line_color", "#3366cc"); $color_graph = wpgpxmaps_findValue($attr, "glinecolor", "wpgpxmaps_graph_line_color", "#3366cc");
$color_graph_speed = findValue($attr, "glinecolorspeed", "wpgpxmaps_graph_line_color_speed", "#ff0000"); $color_graph_speed = wpgpxmaps_findValue($attr, "glinecolorspeed", "wpgpxmaps_graph_line_color_speed", "#ff0000");
$color_graph_hr = findValue($attr, "glinecolorhr", "wpgpxmaps_graph_line_color_hr", "#ff77bd"); $color_graph_hr = wpgpxmaps_findValue($attr, "glinecolorhr", "wpgpxmaps_graph_line_color_hr", "#ff77bd");
$color_graph_atemp = findValue($attr, "glinecoloratemp", "wpgpxmaps_graph_line_color_atemp", "#ff77bd"); $color_graph_atemp = wpgpxmaps_findValue($attr, "glinecoloratemp", "wpgpxmaps_graph_line_color_atemp", "#ff77bd");
$color_graph_cad = findValue($attr, "glinecolorcad", "wpgpxmaps_graph_line_color_cad", "#beecff"); $color_graph_cad = wpgpxmaps_findValue($attr, "glinecolorcad", "wpgpxmaps_graph_line_color_cad", "#beecff");
$color_graph_grade = findValue($attr, "glinecolorgrade", "wpgpxmaps_graph_line_color_grade", "#beecff"); $color_graph_grade = wpgpxmaps_findValue($attr, "glinecolorgrade", "wpgpxmaps_graph_line_color_grade", "#beecff");
$chartFrom1 = findValue($attr, "chartfrom1", "wpgpxmaps_graph_offset_from1", ""); $chartFrom1 = wpgpxmaps_findValue($attr, "chartfrom1", "wpgpxmaps_graph_offset_from1", "");
$chartTo1 = findValue($attr, "chartto1", "wpgpxmaps_graph_offset_to1", ""); $chartTo1 = wpgpxmaps_findValue($attr, "chartto1", "wpgpxmaps_graph_offset_to1", "");
$chartFrom2 = findValue($attr, "chartfrom2", "wpgpxmaps_graph_offset_from2", ""); $chartFrom2 = wpgpxmaps_findValue($attr, "chartfrom2", "wpgpxmaps_graph_offset_from2", "");
$chartTo2 = findValue($attr, "chartto2", "wpgpxmaps_graph_offset_to2", ""); $chartTo2 = wpgpxmaps_findValue($attr, "chartto2", "wpgpxmaps_graph_offset_to2", "");
$startIcon = findValue($attr, "starticon", "wpgpxmaps_map_start_icon", ""); $startIcon = wpgpxmaps_findValue($attr, "starticon", "wpgpxmaps_map_start_icon", "");
$endIcon = findValue($attr, "endicon", "wpgpxmaps_map_end_icon", ""); $endIcon = wpgpxmaps_findValue($attr, "endicon", "wpgpxmaps_map_end_icon", "");
$currentIcon = findValue($attr, "currenticon", "wpgpxmaps_map_current_icon", ""); $currentIcon = wpgpxmaps_findValue($attr, "currenticon", "wpgpxmaps_map_current_icon", "");
$waypointIcon = findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", ""); $waypointIcon = wpgpxmaps_findValue($attr, "waypointicon", "wpgpxmaps_map_waypoint_icon", "");
$ngGalleries = findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", ""); $ngGalleries = wpgpxmaps_findValue($attr, "nggalleries", "wpgpxmaps_map_ngGalleries", "");
$ngImages = findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", ""); $ngImages = wpgpxmaps_findValue($attr, "ngimages", "wpgpxmaps_map_ngImages", "");
// folgende Zeile hinzugefügt: // folgende Zeile hinzugefügt:
$attachments = findValue($attr, "attachments", "wpgpxmaps_map_attachments", false); $attachments = wpgpxmaps_findValue($attr, "attachments", "wpgpxmaps_map_attachments", false);
$download = findValue($attr, "download", "wpgpxmaps_download", ""); $download = wpgpxmaps_findValue($attr, "download", "wpgpxmaps_download", "");
$dtoffset = findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0); $dtoffset = wpgpxmaps_findValue($attr, "dtoffset", "wpgpxmaps_dtoffset", 0);
$distanceType = findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0); $distanceType = wpgpxmaps_findValue($attr, "distanceType", "wpgpxmaps_distance_type", 0);
$skipcache = findValue($attr, "skipcache", "wpgpxmaps_skipcache", ""); $skipcache = wpgpxmaps_findValue($attr, "skipcache", "wpgpxmaps_skipcache", "");
$summary = findValue($attr, "summary", "wpgpxmaps_summary", ""); $summary = wpgpxmaps_findValue($attr, "summary", "wpgpxmaps_summary", "");
$p_tot_len = findValue($attr, "summarytotlen", "wpgpxmaps_summary_tot_len", false); $p_tot_len = wpgpxmaps_findValue($attr, "summarytotlen", "wpgpxmaps_summary_tot_len", false);
$p_max_ele = findValue($attr, "summarymaxele", "wpgpxmaps_summary_max_ele", false); $p_max_ele = wpgpxmaps_findValue($attr, "summarymaxele", "wpgpxmaps_summary_max_ele", false);
$p_min_ele = findValue($attr, "summaryminele", "wpgpxmaps_summary_min_ele", false); $p_min_ele = wpgpxmaps_findValue($attr, "summaryminele", "wpgpxmaps_summary_min_ele", false);
$p_total_ele_up = findValue($attr, "summaryeleup", "wpgpxmaps_summary_total_ele_up", false); $p_total_ele_up = wpgpxmaps_findValue($attr, "summaryeleup", "wpgpxmaps_summary_total_ele_up", false);
$p_total_ele_down = findValue($attr, "summaryeledown", "wpgpxmaps_summary_total_ele_down", false); $p_total_ele_down = wpgpxmaps_findValue($attr, "summaryeledown", "wpgpxmaps_summary_total_ele_down", false);
$p_avg_speed = findValue($attr, "summaryavgspeed", "wpgpxmaps_summary_avg_speed", false); $p_avg_speed = wpgpxmaps_findValue($attr, "summaryavgspeed", "wpgpxmaps_summary_avg_speed", false);
$p_total_time = findValue($attr, "summarytotaltime", "wpgpxmaps_summary_total_time", false); $p_total_time = wpgpxmaps_findValue($attr, "summarytotaltime", "wpgpxmaps_summary_total_time", false);
$usegpsposition = findValue($attr, "usegpsposition", "wpgpxmaps_usegpsposition", false); $usegpsposition = wpgpxmaps_findValue($attr, "usegpsposition", "wpgpxmaps_usegpsposition", false);
$currentpositioncon = findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", ""); $currentpositioncon = wpgpxmaps_findValue($attr, "currentpositioncon", "wpgpxmaps_currentpositioncon", "");
$colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\""; $colors_map = "\"".implode("\",\"",(explode(" ",$color_map)))."\"";
@ -586,7 +589,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
} }
// Folgende Zeilen hinzugefügt // Folgende Zeilen hinzugefügt
if ($attachments == true) { if ($attachments == true) {
$attimgs = getAttachedImages($points_x_time, $points_x_lat, $points_x_lon, $dtoffset, $error); $attimgs = wpgpxmaps_getAttachedImages($points_x_time, $points_x_lat, $points_x_lon, $dtoffset, $error);
foreach ($attimgs as $img) { foreach ($attimgs as $img) {
$data = $img['data']; $data = $img['data'];
$data = str_replace("\n","",$data); $data = str_replace("\n","",$data);

View File

@ -13,7 +13,7 @@ function wpgpxmaps_admin_menu() {
} }
} }
function ilc_admin_tabs( $current ) { function wpgpxmaps_ilc_admin_tabs( $current ) {
if (current_user_can('manage_options')) if (current_user_can('manage_options'))
{ {
@ -76,7 +76,7 @@ function WP_GPX_Maps_html_page() {
} }
} }
ilc_admin_tabs($tab); wpgpxmaps_ilc_admin_tabs($tab);
if ($tab == "tracks") if ($tab == "tracks")
{ {

View File

@ -5,7 +5,8 @@
?> ?>
<script type="text/javascript" src="http://meta100.github.com/mColorPicker/javascripts/mColorPicker_min.js" charset="UTF-8"></script> <script type="text/javascript" src="//meta100.github.com/mColorPicker/javascripts/mColorPicker_min.js" charset="UTF-8"></script>
<?php <?php

View File

@ -5,15 +5,6 @@
$gpxRegEx = '/.gpx$/'; $gpxRegEx = '/.gpx$/';
if ( isset($_POST['delete']) )
{
$del = $_POST['delete'];
if (preg_match($gpxRegEx, $del ) && file_exists($realGpxPath ."/". $del))
{
unlink($realGpxPath ."/". $del);
}
}
if ( isset($_POST['clearcache']) ) if ( isset($_POST['clearcache']) )
{ {
echo "Cache is now empty!"; echo "Cache is now empty!";
@ -24,24 +15,34 @@
?> ?>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.11.1/bootstrap-table.min.js"></script>
<div class="tablenav top"> <div class="tablenav top">
<form enctype="multipart/form-data" method="POST" style="float:left; margin:5px 20px 0 0"> <form enctype="multipart/form-data" method="POST" style="float:left; margin:5px 20px 0 0" action="/wp-admin/options-general.php?page=WP-GPX-Maps">
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);" multiple />
<?php <?php
if ( isset($_FILES['uploadedfile']) ) if ( isset($_FILES['uploadedfile']) )
{ {
$target_path = $realGpxPath ."/". basename( $_FILES['uploadedfile']['name']); $total = count($_FILES['uploadedfile']['name']);
if (preg_match($gpxRegEx, $target_path)) for($i=0; $i<$total; $i++) {
{ $uploadingFileName = basename( $_FILES['uploadedfile']['name'][$i]);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { $target_path = $realGpxPath ."/". $uploadingFileName;
echo "File <b>". basename( $_FILES['uploadedfile']['name']). "</b> has been uploaded"; if (preg_match($gpxRegEx, $target_path))
} else{ {
echo "There was an error uploading the file, please try again!"; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$i], $target_path)) {
echo "<br />File <b>". $uploadingFileName . "</b> has been uploaded";
} else{
echo "<br />There was an error uploading the file, please try again!";
}
}
else
{
echo "file not supported!";
} }
}
else
{
echo "file not supported!";
} }
} }
?> ?>
@ -56,6 +57,55 @@
<?php <?php
} }
else
{
?>
<br />
<br />
<p style='font-size:2em;'>please make <b><?php echo $realGpxPath ?></b> folder writable. </p>
<br />
<br />
<?php
}
$myGpxFileNames = array();
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) {
while (false !== ($entry = readdir($handle))) {
if (preg_match($gpxRegEx, $entry ))
{
if ( isset($_GET['wpgpxmaps_nonce'])
&&
wp_verify_nonce( $_GET['wpgpxmaps_nonce'], 'wpgpx_deletefile_nonce_' . $entry )
) {
if ( file_exists($realGpxPath ."/". $entry) )
{
unlink($realGpxPath ."/". $entry);
echo "<br/><b>$entry has been deleted.</b>";
}
else {
echo "<br/><b>Can't delete $entry.</b>";
}
}
else
{
$myFile = $realGpxPath . "/" . $entry;
$myGpxFileNames[] = array(
'name' => $entry,
'size' => filesize( $myFile ),
'lastedit' => filemtime( $myFile ),
'nonce' => wp_create_nonce( 'wpgpx_deletefile_nonce_' . $entry ),
);
}
}
}
closedir($handle);
}
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) { if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) {
while (false !== ($entry = readdir($handle))) { while (false !== ($entry = readdir($handle))) {
@ -64,69 +114,11 @@
$filenames[] = $realGpxPath . "/" . $entry; $filenames[] = $realGpxPath . "/" . $entry;
} }
} }
closedir($handle); closedir($handle);
} }
?> ?>
<table cellspacing="0" class="wp-list-table widefat plugins"> <table id="table" class="wp-list-table widefat plugins"></table>
<thead>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</thead>
<tfoot>
<tr>
<th style="" class="manage-column" id="name" scope="col">File</th>
<th style="" class="manage-column" id="name" scope="col">Last modified</th>
<th style="" class="manage-column" id="name" scope="col">File size (Byte)</th>
</tr>
</tfoot>
<tbody id="the-list">
<?php
if ($filenames)
{
$filenames = array_reverse($filenames);
foreach ($filenames as $file) {
$entry = basename($file);
?>
<tr>
<td style="border:none; padding-bottom:0;">
<strong><?php echo $entry; ?></strong>
</td>
<td style="border:none; padding-bottom:0;">
<?php echo date ("F d Y H:i:s.", filemtime( $file ) ) ?>
</td>
<td style="border:none; padding-bottom:0;">
<?php echo number_format ( filesize( $file ) , 0, '.', ',' ) ?>
</td>
</tr>
<tr>
<td colspan=3 style="padding: 0px 7px 7px 7px;">
<a href="#" onclick="delgpx('<?php echo $entry ?>'); return false;">Delete</a>
|
<a href="../wp-content/uploads/gpx/<?php echo $entry?>">Download</a>
|
Shortcode: [sgpx gpx="<?php echo $relativeGpxPath . $entry; ?>"]
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<script type="text/javascript"> <script type="text/javascript">
@ -138,16 +130,67 @@
el.parentNode.submit() el.parentNode.submit()
} }
function delgpx(file) jQuery('#table').bootstrapTable({
{ columns: [{
if (confirm('Delete this file: ' + file + '?')) field: 'name',
{ title: 'File',
document.formdelgpx.delete.value = file; sortable: true,
document.formdelgpx.submit(); formatter: function(value, row, index) {
return [
'<b>' + row.name + '</b><br />',
'<a class="delete_gpx_row" href="/wp-admin/options-general.php?page=WP-GPX-Maps&wpgpxmaps_nonce=' + row.nonce + '" >Delete</a>',
' | ',
'<a href="../wp-content/uploads/gpx/' + row.name + '">Download</a>',
' | ',
'Shortcode: [sgpx gpx="<?php echo $relativeGpxPath ?>' + row.name + '"]',
].join('')
}
}, {
field: 'lastedit',
title: 'Last modified',
sortable: true,
formatter: function(value, row, index) {
var d = new Date(value*1000);
return d.toLocaleDateString() + " " + d.toLocaleTimeString();
}
}, {
field: 'size',
title: 'File size',
sortable: true,
formatter: function(value, row, index) { return humanFileSize(value); }
}],
sortName : 'lastedit',
sortOrder : 'desc',
data: <?php echo json_encode( $myGpxFileNames ) ?>
});
jQuery('.delete_gpx_row').click(function(){
return confirm("Are you sure you want to delete?");
})
function humanFileSize(bytes, si) {
var thresh = si ? 1000 : 1024;
if(Math.abs(bytes) < thresh) {
return bytes + ' B';
} }
var units = si
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(1)+' '+units[u];
} }
</script> </script>
<form method="post" name="formdelgpx" style="display:none;">
<input type="hidden" name="delete" /> <style>
</form> #table tr:hover {
background:#eeeeee;
}
</style>

View File

@ -2,7 +2,7 @@
require_once("wp-gpx-maps_utils_nggallery.php"); require_once("wp-gpx-maps_utils_nggallery.php");
function getAttachedImages($dt, $lat, $lon, $dtoffset, &$error) function wpgpxmaps_getAttachedImages($dt, $lat, $lon, $dtoffset, &$error)
{ {
$result = array(); $result = array();

View File

@ -1,13 +1,13 @@
<?php <?php
function isNGGalleryActive() { function wpgpxmaps_isNGGalleryActive() {
if (!function_exists('is_plugin_active')) { if (!function_exists('is_plugin_active')) {
require_once(sitePath() . '/wp-admin/includes/plugin.php'); require_once(sitePath() . '/wp-admin/includes/plugin.php');
} }
return is_plugin_active("nextgen-gallery/nggallery.php"); return is_plugin_active("nextgen-gallery/nggallery.php");
} }
function isNGGalleryProActive() { function wpgpxmaps_isNGGalleryProActive() {
if (!function_exists('is_plugin_active')) { if (!function_exists('is_plugin_active')) {
require_once(sitePath() . '/wp-admin/includes/plugin.php'); require_once(sitePath() . '/wp-admin/includes/plugin.php');
} }
@ -22,7 +22,7 @@
$galids = explode(',', $ngGalleries); $galids = explode(',', $ngGalleries);
$imgids = explode(',', $ngImages); $imgids = explode(',', $ngImages);
if (!isNGGalleryActive()) if (!wpgpxmaps_isNGGalleryActive())
return ''; return '';
try { try {