summaryrefslogtreecommitdiff
path: root/admin_site_clean.php
diff options
context:
space:
mode:
Diffstat (limited to 'admin_site_clean.php')
-rw-r--r--admin_site_clean.php119
1 files changed, 70 insertions, 49 deletions
diff --git a/admin_site_clean.php b/admin_site_clean.php
index 61d73d165e..85e248dd2c 100644
--- a/admin_site_clean.php
+++ b/admin_site_clean.php
@@ -1,6 +1,6 @@
<?php
// webtrees: Web based Family History software
-// Copyright (C) 2014 webtrees development team.
+// Copyright (C) 2015 webtrees development team.
//
// Derived from PhpGedView
// Copyright (C) 2002 to 2010 PGV Development Team.
@@ -20,75 +20,96 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
use WT\Auth;
+use Rhumsaa\Uuid\Uuid;
define('WT_SCRIPT_NAME', 'admin_site_clean.php');
require './includes/session.php';
+
+$to_delete = WT_Filter::postArray('to_delete');
+if ($to_delete && WT_Filter::checkCsrf()) {
+ foreach ($to_delete as $path) {
+ $is_dir = is_dir(WT_DATA_DIR . $path);
+ if (WT_File::delete(WT_DATA_DIR . $path)) {
+ if ($is_dir) {
+ WT_FlashMessages::addMessage(WT_I18N::translate('The folder %s was deleted.', WT_Filter::escapeHtml($path)), 'success');
+ } else {
+ WT_FlashMessages::addMessage(WT_I18N::translate('The file %s was deleted.', WT_Filter::escapeHtml($path)), 'success');
+ }
+ } else {
+ if ($is_dir) {
+ WT_FlashMessages::addMessage(WT_I18N::translate('The folder %s could not be deleted.', WT_Filter::escapeHtml($path)), 'danger');
+ } else {
+ WT_FlashMessages::addMessage(WT_I18N::translate('The file %s could not be deleted.', WT_Filter::escapeHtml($path)), 'danger');
+ }
+ }
+ }
+
+ header('Location: ' . WT_SERVER_NAME . WT_SCRIPT_PATH . WT_SCRIPT_NAME);
+
+ return;
+}
+
$controller = new WT_Controller_Page();
$controller
->restrictAccess(Auth::isAdmin())
->setPageTitle(/* I18N: The “Data folder” is a configuration setting */ WT_I18N::translate('Clean up data folder'))
->pageHeader();
-require WT_ROOT.'includes/functions/functions_edit.php';
+$do_not_delete = array('index.php', 'config.ini.php');
-// Vars
-$ajaxdeleted = false;
-$locked_by_context = array('index.php', 'config.ini.php');
-
-// If we are storing the media in the data folder (this is the
-// defaultl), then don’t delete it.
-// Need to consider the settings for all gedcoms
+// If we are storing the media in the data folder (this is the default), then don’t delete it.
foreach (WT_Tree::getAll() as $tree) {
- $MEDIA_DIRECTORY=$tree->getPreference('MEDIA_DIRECTORY');
+ $MEDIA_DIRECTORY = $tree->getPreference('MEDIA_DIRECTORY');
- if (substr($MEDIA_DIRECTORY, 0, 3) !='../') {
+ if (substr($MEDIA_DIRECTORY, 0, 3) != '../') {
// Just need to add the first part of the path
$tmp = explode('/', $MEDIA_DIRECTORY);
- $locked_by_context[] = $tmp[0];
+ $do_not_delete[] = $tmp[0];
}
}
-echo
- '<h3>', $controller->getPageTitle(), '</h3>',
- '<p>',
- WT_I18N::translate('Files marked with %s are required for proper operation and cannot be removed.', '<i class="icon-resn-confidential"></i>'),
- '</p>';
+$locked_icon = '<i class="fa fa-ban text-danger"></i>';
-//post back
-if (isset($_REQUEST['to_delete'])) {
- echo '<div class="error">', WT_I18N::translate('Deleted files:'), '</div>';
- foreach ($_REQUEST['to_delete'] as $k=>$v) {
- WT_File::delete(WT_DATA_DIR.$v);
- echo '<div class="error">', $v, '</div>';
+$dir = dir(WT_DATA_DIR);
+$entries = array();
+while (false !== ($entry = $dir->read())) {
+ if ($entry[0] != '.') {
+ $entries[] = $entry;
}
}
-echo '<form name="delete_form" method="post" action="?">';
-echo '<div id="cleanup"><ul>';
-
-$dir=dir(WT_DATA_DIR);
-$entries=array();
-while (false !== ($entry=$dir->read())) {
- $entries[]=$entry;
-}
sort($entries);
-foreach ($entries as $entry) {
- if ($entry[0] != '.') {
- if (in_array($entry, $locked_by_context)) {
- echo "<li class=\"facts_value\" name=\"$entry\" id=\"lock_$entry\" >";
- echo '<i class="icon-resn-confidential"></i> <span>', $entry, '</span>';
- } else {
- echo "<li class=\"facts_value\" name=\"$entry\" id=\"li_$entry\" >";
- echo '<input type="checkbox" name="to_delete[]" value="', $entry, '">', $entry;
- $element[] = "li_".$entry;
+
+?>
+<ol class="breadcrumb small">
+ <li><a href="admin.php"><?php echo WT_I18N::translate('Administration'); ?></a></li>
+ <li class="active"><?php echo $controller->getPageTitle(); ?></li>
+</ol>
+<h2><?php echo $controller->getPageTitle(); ?></h2>
+
+<p>
+ <?php echo WT_I18N::translate('Files marked with %s are required for proper operation and cannot be removed.', $locked_icon); ?>
+</p>
+
+<form method="post">
+ <?php echo WT_Filter::getCsrf(); ?>
+ <ul class="fa-ul">
+ <?php
+ foreach ($entries as $entry) {
+ if (in_array($entry, $do_not_delete)) {
+ echo '<li><i class="fa-li fa fa-ban text-danger"></i>', WT_Filter::escapeHtml($entry), '</li>';
+ } else {
+ $uuid = 'label-' . Uuid::uuid4();
+ echo '<li><i class="fa-li fa fa-trash-o"></i>';
+ echo '<label>';
+ echo WT_Filter::escapeHtml($entry);
+ echo ' <input type="checkbox" name="to_delete[]" value="', WT_Filter::escapeHtml($entry), '">';
+ echo '</label></li>';
+ }
}
- echo '</li>';
- }
-}
-$dir->close();
-echo
- '</ul>',
- '<button type="submit">', WT_I18N::translate('Delete'), '</button>',
- '</div>',
- '</form>';
+ $dir->close();
+ ?>
+ </ul>
+ <button class="btn btn-primary" type="submit"><?php echo /* I18N: Button label */ WT_I18N::translate('Delete'); ?></button>
+</form>