wp-gpx-maps/wp-gpx-maps_admin_tracks.php

143 lines
3.7 KiB
PHP
Raw Normal View History

2012-01-28 11:56:52 +00:00
<?php
2012-06-11 19:43:04 +00:00
if ( !is_admin() )
return;
$gpxRegEx = '/.gpx$/';
2012-01-28 11:56:52 +00:00
if ( isset($_POST['delete']) )
{
$del = $_POST['delete'];
if (preg_match($gpxRegEx, $del ) && file_exists($realGpxPath ."/". $del))
{
unlink($realGpxPath ."/". $del);
}
}
2012-02-07 13:06:51 +00:00
if ( isset($_POST['clearcache']) )
{
2012-02-29 14:01:40 +00:00
echo "Cache is now empty!";
2012-02-07 13:06:51 +00:00
recursive_remove_directory($cacheGpxPath,true);
}
2012-01-28 11:56:52 +00:00
if ( is_writable ( $realGpxPath ) ){
?>
<div class="tablenav top">
2012-02-07 13:06:51 +00:00
<form enctype="multipart/form-data" method="POST" style="float:left; margin:5px 20px 0 0">
2012-01-28 11:56:52 +00:00
Choose a file to upload: <input name="uploadedfile" type="file" onchange="submitgpx(this);" />
<?php
if ( isset($_FILES['uploadedfile']) )
{
$target_path = $realGpxPath ."/". basename( $_FILES['uploadedfile']['name']);
if (preg_match($gpxRegEx, $target_path))
{
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "File <b>". basename( $_FILES['uploadedfile']['name']). "</b> has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
else
{
echo "file not supported!";
}
}
?>
</form>
2012-02-07 13:06:51 +00:00
<form method="POST" style="float:left; margin:5px 20px 0 0">
<input type="submit" name="clearcache" value="Clear Cache" />
</form>
2012-01-28 11:56:52 +00:00
</div>
<?php
}
if ( is_readable ( $realGpxPath ) && $handle = opendir($realGpxPath)) {
?>
<table cellspacing="0" class="wp-list-table widefat plugins">
<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
while (false !== ($entry = readdir($handle))) {
if (preg_match($gpxRegEx,$entry ))
{
$file = $realGpxPath . "/" . $entry;
?>
<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;">
2012-02-07 13:06:51 +00:00
<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; ?>"]
2012-01-28 11:56:52 +00:00
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<?php
closedir($handle);
} ?>
<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()
}
function delgpx(file)
{
if (confirm('Delete this file: ' + file + '?'))
{
document.formdelgpx.delete.value = file;
document.formdelgpx.submit();
}
}
</script>
<form method="post" name="formdelgpx" style="display:none;">
<input type="hidden" name="delete" />
</form>