2018-03-09 09:02:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( !is_admin() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
$gpxRegEx = '/.gpx$/';
|
|
|
|
|
|
|
|
if ( isset($_POST['clearcache']) )
|
|
|
|
{
|
|
|
|
echo "Cache is now empty!";
|
|
|
|
recursive_remove_directory($cacheGpxPath,true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_writable ( $realGpxPath ) ){
|
|
|
|
|
|
|
|
?>
|
2018-03-10 10:40:30 +00:00
|
|
|
|
|
|
|
<!-- 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>
|
2018-03-09 09:02:25 +00:00
|
|
|
|
|
|
|
<div class="tablenav top">
|
2018-03-10 10:40:30 +00:00
|
|
|
<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);" multiple />
|
2018-03-09 09:02:25 +00:00
|
|
|
<?php
|
|
|
|
if ( isset($_FILES['uploadedfile']) )
|
2018-03-10 10:40:30 +00:00
|
|
|
{
|
|
|
|
$total = count($_FILES['uploadedfile']['name']);
|
|
|
|
for($i=0; $i<$total; $i++) {
|
|
|
|
$uploadingFileName = basename( $_FILES['uploadedfile']['name'][$i]);
|
|
|
|
$target_path = $realGpxPath ."/". $uploadingFileName;
|
|
|
|
if (preg_match($gpxRegEx, $target_path))
|
|
|
|
{
|
|
|
|
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!";
|
|
|
|
}
|
2018-03-09 09:02:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<form method="POST" style="float:left; margin:5px 20px 0 0">
|
|
|
|
<input type="submit" name="clearcache" value="Clear Cache" />
|
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
}
|
2018-03-10 10:40:30 +00:00
|
|
|
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 ),
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
2018-03-09 09:02:25 +00:00
|
|
|
|
2018-03-10 10:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
2018-03-09 09:02:25 +00:00
|
|
|
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) {
|
|
|
|
while (false !== ($entry = readdir($handle))) {
|
|
|
|
if (preg_match($gpxRegEx,$entry ))
|
|
|
|
{
|
|
|
|
$filenames[] = $realGpxPath . "/" . $entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
|
2018-03-10 10:40:30 +00:00
|
|
|
<table id="table" class="wp-list-table widefat plugins"></table>
|
|
|
|
|
2018-03-09 09:02:25 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
function submitgpx(el)
|
|
|
|
{
|
|
|
|
var newEl = document.createElement('span');
|
|
|
|
newEl.innerHTML = 'Uploading file...';
|
|
|
|
el.parentNode.insertBefore(newEl,el.nextSibling);
|
|
|
|
el.parentNode.submit()
|
|
|
|
}
|
2018-03-10 10:40:30 +00:00
|
|
|
|
|
|
|
jQuery('#table').bootstrapTable({
|
|
|
|
columns: [{
|
|
|
|
field: 'name',
|
|
|
|
title: 'File',
|
|
|
|
sortable: true,
|
|
|
|
formatter: function(value, row, index) {
|
2018-03-09 09:02:25 +00:00
|
|
|
|
2018-03-10 10:40:30 +00:00
|
|
|
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';
|
2018-03-09 09:02:25 +00:00
|
|
|
}
|
2018-03-10 10:40:30 +00:00
|
|
|
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];
|
2018-03-09 09:02:25 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 10:40:30 +00:00
|
|
|
|
2018-03-09 09:02:25 +00:00
|
|
|
</script>
|
2018-03-10 10:40:30 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
#table tr:hover {
|
|
|
|
background:#eeeeee;
|
|
|
|
}
|
|
|
|
</style>
|