Added nonce on clear cache command

renamed functions
This commit is contained in:
bastianonm 2018-03-14 15:51:31 +00:00
parent a69955a186
commit 297238152d
5 changed files with 42 additions and 25 deletions

12
js/mColorPicker_min.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -49,8 +49,9 @@ function WP_GPX_Maps_action_links($links, $file) {
function enqueue_WP_GPX_Maps_scripts_admin($hook) function enqueue_WP_GPX_Maps_scripts_admin($hook)
{ {
if ( strpos($hook, 'WP-GPX-Maps') !== false ) if ( strpos($hook, 'WP-GPX-Maps') !== false ) {
{ wp_register_script('mColorPicker', plugins_url( '/js/mColorPicker_min.js', __FILE__ ), array(), "1.0 r39" );
wp_enqueue_script('mColorPicker');
wp_register_script('bootstrap-table', plugins_url( '/js/bootstrap-table.min.js', __FILE__ ), array(), "1.11.1" ); wp_register_script('bootstrap-table', plugins_url( '/js/bootstrap-table.min.js', __FILE__ ), array(), "1.11.1" );
wp_enqueue_script('bootstrap-table'); wp_enqueue_script('bootstrap-table');
wp_register_style('bootstrap-table', plugins_url( '/css/bootstrap-table.min.css', __FILE__ ), array(), "1.11.1" ); wp_register_style('bootstrap-table', plugins_url( '/css/bootstrap-table.min.css', __FILE__ ), array(), "1.11.1" );
@ -155,7 +156,7 @@ function handle_WP_GPX_Maps_folder_Shortcodes($attr, $content='') {
if (substr($file, - 4) == ".gpx" ) { if (substr($file, - 4) == ".gpx" ) {
$gpx = $folder . DIRECTORY_SEPARATOR . $file; $gpx = $folder . DIRECTORY_SEPARATOR . $file;
$points = getPoints($gpx, $pointsoffset, $donotreducegpx, $distanceType); $points = wpgpxmaps_getPoints($gpx, $pointsoffset, $donotreducegpx, $distanceType);
$points_maps = ''; $points_maps = '';
$points_graph_dist = ''; $points_graph_dist = '';
@ -371,7 +372,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
return "No gpx found"; return "No gpx found";
} }
$points = getPoints( $gpx, $pointsoffset, $donotreducegpx, $distanceType); $points = wpgpxmaps_getPoints( $gpx, $pointsoffset, $donotreducegpx, $distanceType);
$points_maps = ''; $points_maps = '';
$points_graph_dist = ''; $points_graph_dist = '';
@ -536,7 +537,7 @@ function handle_WP_GPX_Maps_Shortcodes($attr, $content='')
$waypoints = '[]'; $waypoints = '[]';
if ($showW == true) { if ($showW == true) {
$wpoints = getWayPoints($gpx); $wpoints = wpgpxmaps_getWayPoints($gpx);
/* /*
foreach ($wpoints as $p) { foreach ($wpoints as $p) {
$waypoints .= '['.number_format ( (float)$p[0] , 7 , '.' , '' ).','.number_format ( (float)$p[1] , 7 , '.' , '' ).',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],'; $waypoints .= '['.number_format ( (float)$p[0] , 7 , '.' , '' ).','.number_format ( (float)$p[1] , 7 , '.' , '' ).',\''.unescape($p[4]).'\',\''.unescape($p[5]).'\',\''.unescape($p[7]).'\'],';

View File

@ -3,13 +3,6 @@
if ( !current_user_can('manage_options') ) if ( !current_user_can('manage_options') )
return; return;
?>
<script type="text/javascript" src="//meta100.github.com/mColorPicker/javascripts/mColorPicker_min.js" charset="UTF-8"></script>
<?php
$po = get_option('wpgpxmaps_pointsoffset'); $po = get_option('wpgpxmaps_pointsoffset');
$showW = get_option("wpgpxmaps_show_waypoint"); $showW = get_option("wpgpxmaps_show_waypoint");
$donotreducegpx = get_option("wpgpxmaps_donotreducegpx"); $donotreducegpx = get_option("wpgpxmaps_donotreducegpx");

View File

@ -7,13 +7,21 @@
if ( $is_admin != 1 ) if ( $is_admin != 1 )
return; return;
$gpxRegEx = '/.gpx$/'; $gpxRegEx = '/.gpx$/';
if ( isset($_POST['clearcache']) ) if ( isset($_POST['clearcache']) )
{ {
echo "Cache is now empty!";
recursive_remove_directory($cacheGpxPath,true); if ( isset($_GET['_wpnonce'])
&&
wp_verify_nonce( $_GET['_wpnonce'], 'wpgpx_clearcache_nonce' . $entry )
)
{
echo "Cache is now empty!";
wpgpxmaps_recursive_remove_directory($cacheGpxPath, true);
}
} }
if ( is_writable ( $realGpxPath ) ){ if ( is_writable ( $realGpxPath ) ){
@ -47,8 +55,8 @@
?> ?>
</form> </form>
<form method="POST" style="float:left; margin:5px 20px 0 0"> <form method="POST" style="float:left; margin:5px 20px 0 0" action="/wp-admin/options-general.php?page=WP-GPX-Maps&_wpnonce=<?php echo wp_create_nonce( 'wpgpx_clearcache_nonce' ) ?>" >
<input type="submit" name="clearcache" value="Clear Cache" /> <input type="submit" name="clearcache" value="Clear Cache" />
</form> </form>
</div> </div>
@ -115,7 +123,10 @@
} }
closedir($handle); closedir($handle);
} }
?>
$wpgpxmaps_gpxRelativePath = get_site_url(null, '/wp-content/uploads/gpx/');
?>
<table id="table" class="wp-list-table widefat plugins"></table> <table id="table" class="wp-list-table widefat plugins"></table>
@ -140,7 +151,7 @@
'<b>' + row.name + '</b><br />', '<b>' + row.name + '</b><br />',
'<a class="delete_gpx_row" href="/wp-admin/options-general.php?page=WP-GPX-Maps&_wpnonce=' + row.nonce + '" >Delete</a>', '<a class="delete_gpx_row" href="/wp-admin/options-general.php?page=WP-GPX-Maps&_wpnonce=' + row.nonce + '" >Delete</a>',
' | ', ' | ',
'<a href="../wp-content/uploads/gpx/' + row.name + '">Download</a>', '<a href="<?php echo $wpgpxmaps_gpxRelativePath ?>' + row.name + '">Download</a>',
' | ', ' | ',
'Shortcode: [sgpx gpx="<?php echo $relativeGpxPath ?>' + row.name + '"]', 'Shortcode: [sgpx gpx="<?php echo $relativeGpxPath ?>' + row.name + '"]',
].join('') ].join('')

View File

@ -101,7 +101,7 @@
return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret); return str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $ret);
} }
function recursive_remove_directory($directory, $empty=FALSE) function wpgpxmaps_recursive_remove_directory($directory, $empty=FALSE)
{ {
if(substr($directory,-1) == '/') if(substr($directory,-1) == '/')
{ {
@ -120,7 +120,7 @@
$path = $directory.'/'.$item; $path = $directory.'/'.$item;
if(is_dir($path)) if(is_dir($path))
{ {
recursive_remove_directory($path); wpgpxmaps_recursive_remove_directory($path);
}else{ }else{
unlink($path); unlink($path);
} }
@ -138,7 +138,7 @@
return TRUE; return TRUE;
} }
function getPoints($gpxPath, $gpxOffset = 10, $donotreducegpx, $distancetype) function wpgpxmaps_getPoints($gpxPath, $gpxOffset = 10, $donotreducegpx, $distancetype)
{ {
$points = array(); $points = array();
@ -151,7 +151,7 @@
if (file_exists($gpxPath)) if (file_exists($gpxPath))
{ {
$points = @parseXml($gpxPath, $gpxOffset, $distancetype); $points = @wpgpxmaps_parseXml($gpxPath, $gpxOffset, $distancetype);
} }
else else
{ {
@ -185,7 +185,7 @@
return $points; return $points;
} }
function parseXml($filePath, $gpxOffset, $distancetype) function wpgpxmaps_parseXml($filePath, $gpxOffset, $distancetype)
{ {
$points = null; $points = null;
@ -567,7 +567,7 @@
return $points; return $points;
} }
function getWayPoints($gpxPath) function wpgpxmaps_getWayPoints($gpxPath)
{ {
$points = array(); $points = array();
if (file_exists($gpxPath)) if (file_exists($gpxPath))