Add files via upload

pull/8/head
SuperDev 3 years ago committed by GitHub
parent 012588e6cf
commit 9afd6f3701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because it is too large Load Diff

@ -0,0 +1,546 @@
$font: -apple-system, BlinkMacSystemFont, "segoe ui", roboto, oxygen, ubuntu, cantarell, "fira sans", "droid sans", "helvetica neue", Arial, sans-serif;
$font-size: 16px;
$header-size: 55px;
$aside-width: 260px;
$text-color: #555555;
$header-color: #4a5361;
$admin-color: #383c46;
$background-color: mix($admin-color, #fff, 10);
$btn-color: #4a79b4;
$btn-alt-color: #b44a4a;
* {
box-sizing: border-box;
font-family: $font;
font-size: $font-size;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
html {
height: 100%;
}
body {
position: relative;
min-height: 100%;
color: $text-color;
background-color: $background-color;
margin: 0;
}
h1, h2, h3, h4, h5 {
color: $header-color;
margin: 0;
padding: 0;
}
header {
display: flex;
position: fixed;
top: 0;
left: 0;
padding-left: $aside-width;
z-index: 999;
width: 100%;
height: $header-size;
background-color: #fff;
box-shadow: 0px 0px 4px 1px rgba(0,0,0,0.15);
a {
display: inline-flex;
color: $header-color;
height: 100%;
text-decoration: none;
justify-content: center;
align-items: center;
padding: 0 20px;
i {
font-size: 16px;
}
&:hover, &:active {
color: lighten($header-color, 10);
}
}
.space-between {
flex: 1;
}
&.full {
padding-left: 0;
}
}
aside {
position: fixed;
z-index: 999999;
height: 100%;
width: $aside-width;
display: flex;
flex-flow: column;
background-color: darken($admin-color, 8);
h1 {
display: inline-flex;
background-color: #5472bd;
width: 100%;
height: $header-size;
color: #fff;
padding: 0;
margin: 0;
font-weight: 600;
font-size: 14px;
align-items: center;
padding: 0 20px;
justify-content: center;
}
> a {
font-size: 14px;
font-weight: 600;
text-decoration: none;
color: mix($admin-color, #fff, 40);
padding: 15px 20px;
i {
width: 40px;
}
&:hover, &.selected {
background-color: mix($admin-color, #4a79b4, 98);
color: #fff;
border-left: 3px solid #4a79b4;
padding: 15px 17px;
}
&.selected + .sub {
display: flex;
}
.note {
background-color: darken($admin-color, 0);
padding: 1px 5px;
border-radius: 4px;
font-size: 12px;
margin-left: 10px;
}
}
.sub {
display: none;
flex-flow: column;
background-color: darken($admin-color, 12);
padding: 13px 0;
a {
font-size: 14px;
color: mix($admin-color, #fff, 40);
text-decoration: none;
padding: 4px 20px;
span {
display: inline-block;
width: 40px;
font-size: 12px;
}
&:hover, &.selected {
color: #fff;
}
}
}
&.closed {
display: none;
}
}
main {
$padding: 30px;
padding: $padding;
padding-left: $aside-width + $padding;
padding-top: $header-size + $padding;
&.full {
padding-left: $padding;
padding-right: $padding;
}
h2 {
font-size: 20px;
padding-bottom: 20px;
border-bottom: 1px solid darken($background-color, 6);
span {
font-size: 16px;
margin-left: 5px;
font-weight: 600;
color: lighten($header-color, 30);
}
}
.msg {
display: flex;
align-items: center;
margin: 15px 0 0 0;
padding: 15px;
font-weight: 500;
box-shadow: 0px 0px 2px 0px rgba(0,0,0,0.1);
p {
margin: 0;
padding: 0 15px;
font-size: 14px;
flex: 1;
}
i.fa-times {
align-self: flex-end;
justify-content: flex-end;
cursor: pointer;
&:hover {
opacity: .9;
}
}
&.success {
background-color: #C3F3D7;
border-left: 4px solid #51a775;
color: #51a775;
i {
color: #51a775;
}
}
&.error {
background-color: #f3c3c3;
border-left: 4px solid #a75151;
color: #a75151;
i {
color: #a75151;
}
}
}
.content-header {
display: flex;
justify-content: space-between;
form {
display: flex;
justify-content: space-between;
}
.search {
label {
position: relative;
}
input {
background-color: transparent;
outline: none;
border: none;
padding: 10px 0;
width: 250px;
border-bottom: 1px solid darken($background-color, 10);
padding-right: 25px;
&:hover, &:active {
border-bottom: 1px solid darken($background-color, 20);
}
}
i {
position: absolute;
right: 4px;
top: 4px;
bottom: 0;
font-size: 14px;
margin-top: auto;
margin-bottom: auto;
color: darken($background-color, 20);
}
}
}
.content-block {
background-color: #fff;
margin-top: 25px;
padding: 15px;
box-shadow: 0px 0px 5px 1px rgba(0,0,0,0.03);
}
.tabs {
display: flex;
background-color: darken($background-color, 5);
margin-top: 25px;
box-shadow: 0px 0px 4px 1px rgba(0,0,0,0.03);
z-index: 100;
a {
display: flex;
text-decoration: none;
padding: 12px 15px;
border: 0;
color: lighten($header-color, 15);
font-weight: 600;
font-size: 14px;
&:hover {
background-color: darken($background-color, 7);;
}
&.active {
color: $header-color;
background-color: #fff;
}
}
}
.tabs ~ .content-block {
margin-top: 0;
box-shadow: 0px 6px 5px 1px rgba(0,0,0,0.03);
}
.tab-content {
display: none;
&.active {
display: block;
}
}
.dashboard {
display: flex;
justify-content: space-between;
padding-bottom: 40px;
.stat {
width: 24%;
display: flex;
justify-content: space-between;
i {
display: inline-flex;
justify-content: center;
padding: 15px;
margin: 20px 15px 0 0;
align-items: center;
font-size: 18px;
height: 50px;
width: 50px;
border-radius: 50%;
background-color: #d5e7fa;
color: #6e94ba;
}
h3 {
font-size: 16px;
font-weight: 400;
padding: 15px 15px 0 15px;
}
p {
margin: 0;
padding: 15px;
font-size: 26px;
font-weight: 700;
}
}
}
.filters {
display: flex;
position: relative;
margin-right: 25px;
margin-bottom: 3px;
align-items: center;
a {
text-decoration: none;
font-weight: 600;
color: $header-color;
white-space: nowrap;
&:hover {
color: darken($header-color, 10);
}
}
.list {
display: none;
top: calc(100% + 5px);
width: 180px;
flex-flow: column;
position: absolute;
background-color: #fff;
padding: 10px;
box-shadow: 0px 0px 5px 1px rgba(0,0,0,0.1);
label {
padding-bottom: 5px;
font-size: 14px;
}
input {
margin-right: 10px;
}
button {
background: $btn-color;
border: 0;
color: #FFFFFF;
padding: 5px 0;
font-size: 12px;
font-weight: 600;
margin-top: 5px;
cursor: pointer;
border-radius: 4px;
&:hover {
background: darken($btn-color, 3);
}
}
}
}
.table {
padding: 0 10px;
table {
width: 100%;
border-collapse: collapse;
thead {
td {
font-weight: 600;
font-size: 14px;
padding: 15px 0;
a {
font-weight: inherit;
font-size: inherit;
color: inherit;
text-decoration: none;
}
i {
padding-left: 5px;
}
}
tr {
border-bottom: 1px solid lighten($background-color, 2);
}
}
tbody {
tr:first-child td {
padding-top: 10px;
}
td {
padding: 5px 0;
}
.img {
width: 50px;
}
}
}
}
tbody td a, .link1 {
text-decoration: none;
color: #0060ba;
border-bottom: 1px dotted;
margin: 0 5px 0 0;
&:hover {
color: #003260;
}
}
.form {
display: flex;
flex-flow: column;
width: 500px;
padding: 20px;
input, textarea, select {
width: 100%;
padding: 15px 5px;
margin-bottom: 25px;
border: 0;
border-bottom: 1px solid darken($background-color, 5);
&:hover, &:active {
border-bottom: 1px solid darken($background-color, 20);
}
}
textarea {
height: 200px;
}
input[type="checkbox"] {
width: auto;
margin: 15px 0 25px 2px;
transform: scale(1.2);
}
input[type="submit"] {
background: $btn-color;
border: 0;
color: #FFFFFF;
width: auto;
padding: 12px 15px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
border-radius: 4px;
&:hover {
background: darken($btn-color, 3);
}
}
label {
display: block;
font-weight: 600;
}
button {
background-color: darken($background-color, 5);
color: darken($background-color, 50);
border: 0;
padding: 5px;
width: 100%;
font-weight: 600;
font-size: 14px;
cursor: pointer;
&:hover {
background-color: darken($background-color, 8);
}
}
.submit-btns {
display: flex;
input:first-child {
margin-right: 10px;
}
.delete {
background-color: #b03b3b;
&:hover {
background-color: darken(#b03b3b, 3);
}
}
}
}
.links {
display: flex;
flex-flow: wrap;
padding-top: 20px;
> a {
display: inline-flex;
text-decoration: none;
background: $btn-color;
color: #FFFFFF;
padding: 12px 15px;
margin-right: 10px;
font-size: 14px;
font-weight: 600;
border-radius: 4px;
&:hover {
background: darken($btn-color, 3);
}
&.alt {
background: $btn-alt-color;
&:hover {
background: darken($btn-alt-color, 3);
}
}
}
}
.error {
padding: 15px;
margin: 0;
}
.pagination {
display: flex;
align-items: center;
padding: 25px 0;
a {
display: inline-flex;
text-decoration: none;
background-color: #758497;
font-size: 14px;
font-weight: 600;
color: #fff;
border-radius: 4px;
padding: 7px 10px;
&:hover {
background-color: darken(#758497, 3);
}
&:first-child {
margin-right: 10px;
}
&:last-child {
margin-left: 10px;
}
}
span {
font-weight: 600;
}
}
}
@media screen and (max-width: 1000px) {
header {
padding-left: 0;
}
.responsive-hidden {
display: none;
}
.responsive-width-100 {
width: 100% !important;
}
.responsive-flex-column {
flex-flow: column;
}
main {
padding: 70px 7px 20px 7px;
.content-block {
padding: 5px;
}
.dashboard {
flex-flow: column;
.stat {
width: 100%;
}
}
}
}

@ -0,0 +1,231 @@
<?php
include 'main.php';
$dir = "../../files/";
/*
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
*/
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = 'File deleted successfully!';
}
if ($_GET['success_msg'] == 2) {
$success_msg = 'File updated successfully!';
}
if ($_GET['success_msg'] == 3) {
$success_msg = 'File created successfully!';
}
if ($_GET['success_msg'] == 4) {
$success_msg = 'Files deleted successfully!';
}
}
// Handle error messages
if (isset($_GET['error_msg'])) {
if ($_GET['error_msg'] == 1) {
$error_msg = 'File Cant Be Deleted';
}
if ($_GET['error_msg'] == 2) {
$error_msg = 'File Upload Error';
}
if ($_GET['error_msg'] == 3) {
$error_msg = 'An Error Occured';
}
if ($_GET['error_msg'] == 4) {
$error_msg = 'File path doesnt exist.';
}
if ($_GET['error_msg'] == 5) {
$error_msg = 'File path not found.';
}
}
// filelist
function list_directory_files($dir) {
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if ($file != "." && $file != ".." && $file != "Thumbs.db" && $file != "index.php") {
echo '<tr>';
echo '<td>';
echo $file;
echo '</td>';
echo '<td>';
echo '<a class="link1" href="?path='.$dir.''.$file.'">Download</a>';
echo '<a class="link1" href="?delete&file='.$dir.''.$file.'">Delete</a>';
echo '</td>';
echo '</tr>';
}
}
closedir($handle);
}
}
}
// download file
if(isset($_GET['path']))
{
//Read the url
$url = $_GET['path'];
//Clear the cache
clearstatcache();
//Check the file path exists or not
if(file_exists($url)) {
//Define header information
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($url).'"');
header('Content-Length: ' . filesize($url));
header('Pragma: public');
//Clear system output buffer
flush();
//Read the size of the file
readfile($url,true);
//Terminate from the script
die();
}
else{
// do nothing
}
}
// do nothing
if(isset($_GET['delete'], $_GET['file'])){
$delfile = $_GET['file'];
/*
header("Location: $delfile");
*/
If (unlink($delfile)) {
// file was successfully deleted
header("Refresh:0 url=files.php?success_msg=1");
} else {
// there was a problem deleting the file
header("Refresh:0 url=files.php?error_msg=1");
}
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<?=template_admin_header('Files', 'files')?>
<h2>Files</h2>
<div class="content-header links">
<button class="btn" onclick="exportTableToExcel('data');"><i class="fa-solid fa-file-excel"></i>&nbsp;Export page to .xls</button>
</div>
<!-- Display Success Alert -->
<?php if (isset($success_msg)): ?>
<div class="msg success">
<i class="fas fa-check-circle"></i>
<p><?=$success_msg?></p>
<i class="fas fa-times"></i>
</div>
<?php endif; ?>
<!-- Display Error Message -->
<?php if (isset($error_msg)): ?>
<div class="msg error">
<i class="fa fa-exclamation-triangle"></i>
<p><?=$error_msg?></p>
<i class="fas fa-times"></i>
</div>
<?php endif; ?>
<div class="content-block">
<div class="table">
<table id="data">
<thead>
<tr>
<td>File</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<tr>
<?php list_directory_files($dir); ?>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function(){
$('#data').after('<div id="nav"></div>');
var rowsShown = 25;
var rowsTotal = $('#data tbody tr').length;
var numPages = rowsTotal/rowsShown;
for(i = 0;i < numPages;i++) {
var pageNum = i + 1;
$('#nav').append('<a class="btn disabled" href="#" rel="'+i+'">'+pageNum+'</a> ');
}
$('#data tbody tr').hide();
$('#data tbody tr').slice(0, rowsShown).show();
$('#nav a:first').addClass('active');
$('#nav a').bind('click', function(){
$('#nav a').removeClass('active');
$(this).addClass('active');
var currPage = $(this).attr('rel');
var startItem = currPage * rowsShown;
var endItem = startItem + rowsShown;
$('#data tbody tr').css('opacity','0.0').hide().slice(startItem, endItem).
css('display','table-row').animate({opacity:1}, 300);
});
});
function exportTableToExcel(tableID, filename = ''){
var downloadLink;
var dataType = 'application/vnd.ms-excel';
var tableSelect = document.getElementById(tableID);
var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
// Specify file name
filename = filename?filename+'.xls':'exported_data.xls';
// Create download link element
downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob){
var blob = new Blob(['\ufeff', tableHTML], {
type: dataType
});
navigator.msSaveOrOpenBlob( blob, filename);
}else{
// Create a link to the file
downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
// Setting the file name
downloadLink.download = filename;
//triggering the function
downloadLink.click();
}
}
</script>
<?=template_admin_footer()?>

@ -1 +1,113 @@
<?php
include 'main.php';
include_once '../../system/config.php';
/*
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
*/
// Get total files in uploads directory
?>
<?php
$directory = "../.$file_url_destination./files/"; // dir location
if (glob($directory . "*.*") != false)
{
$filecount = count(glob($directory. "*.*"));
}
// file size of upload dir
function folderSize($dir){
$count_size = 0;
$count = 0;
$dir_array = scandir($dir);
foreach($dir_array as $key=>$filename){
if($filename!=".." && $filename!="." && $filename!="index.php"){
if(is_dir($dir."/".$filename)){
$new_foldersize = foldersize($dir."/".$filename);
$count_size = $count_size+ $new_foldersize;
}else if(is_file($dir."/".$filename)){
$count_size = $count_size + filesize($dir."/".$filename);
$count++;
}
}
}
return $count_size;
}
// size converter
function sizeFormat($bytes){
$kb = 1024;
$mb = $kb * 1024;
$gb = $mb * 1024;
$tb = $gb * 1024;
if (($bytes >= 0) && ($bytes < $kb)) {
return $bytes . ' B';
} elseif (($bytes >= $kb) && ($bytes < $mb)) {
return ceil($bytes / $kb) . ' KB';
} elseif (($bytes >= $mb) && ($bytes < $gb)) {
return ceil($bytes / $mb) . ' MB';
} elseif (($bytes >= $gb) && ($bytes < $tb)) {
return ceil($bytes / $gb) . ' GB';
} elseif ($bytes >= $tb) {
return ceil($bytes / $tb) . ' TB';
} else {
return $bytes . ' B';
}
}
// get size of folders in a folder
$plugin_count = count(glob('../../plugins/*', GLOB_ONLYDIR));
?>
<?=template_admin_header('Dashboard', 'dashboard')?>
<h2>Dashboard</h2>
<div class="dashboard">
<div class="content-block stat">
<div class="data">
<h3>Total Files</h3>
<p><?php echo $filecount ?></p>
</div>
<i class="fas fa-file"></i>
</div>
<div class="content-block stat">
<div class="data">
<h3>Storage Used</h3>
<p><?php echo sizeFormat(folderSize($directory)); ?></p>
</div>
<i class="fas fa-database"></i>
</div>
<div class="content-block stat">
<div class="data">
<h3>Plugins Installed</h3>
<p><?php echo $plugin_count; ?></p>
</div>
<i class="fas fa-plug"></i>
</div>
<div class="content-block stat">
<div class="data">
<h3>Version</h3>
<p>
1.0
</p>
</div>
<i class="fas fa-info"></i>
</div>
</div>
<?=template_admin_footer()?>

@ -0,0 +1,147 @@
<?php
// Check if the user is logged-in
include_once '../protect.php';
// Add/remove roles from the list
$roles_list = ['Admin', 'Member'];
// Logout User on '?logout' -->
if(isset($_GET['logout']))
{
logout();
}
// Logout Function -->
function logout(){
session_destroy();
header("Location: ../");
exit();
}
// Template admin header
function template_admin_header($title, $selected = 'dashboard', $selected_child = '') {
// Admin HTML links
$admin_links = '
<a href="index.php"' . ($selected == 'dashboard' ? ' class="selected"' : '') . '><i class="fas fa-tachometer-alt"></i>Dashboard</a>
<a href="files.php"' . ($selected == 'files' ? ' class="selected"' : '') . '><i class="fas fa-file-alt"></i>Files</a>
<a href="settings.php"' . ($selected == 'settings' ? ' class="selected"' : '') . '><i class="fas fa-tools"></i>Settings</a>
<div class="footer">
<a href="https://support.superdev.one" target="_blank">AnonFiles</a>
Version 1.0.0
</div>
';
// Indenting the below code may cause an error
echo <<<EOT
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<title>$title</title>
<link href="admin.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">
</head>
<body class="admin">
<aside class="responsive-width-100 responsive-hidden">
<h1>Anonfiles Admin Panel</h1>
$admin_links
</aside>
<main class="responsive-width-100">
<header>
<a class="responsive-toggle" href="#">
<i class="fas fa-bars"></i>
</a>
<div class="space-between"></div>
<a href="?logout" class="right"><i class="fas fa-sign-out-alt"></i></a>
</header>
EOT;
}
// Template admin footer
function template_admin_footer() {
// Indenting the below code may cause an error
echo <<<EOT
</main>
<script>
let aside = document.querySelector("aside"), main = document.querySelector("main"), header = document.querySelector("header");
let asideStyle = window.getComputedStyle(aside);
if (localStorage.getItem("admin_menu") == "closed") {
aside.classList.add("closed", "responsive-hidden");
main.classList.add("full");
header.classList.add("full");
}
document.querySelector(".responsive-toggle").onclick = event => {
event.preventDefault();
if (asideStyle.display == "none") {
aside.classList.remove("closed", "responsive-hidden");
main.classList.remove("full");
header.classList.remove("full");
localStorage.setItem("admin_menu", "");
} else {
aside.classList.add("closed", "responsive-hidden");
main.classList.add("full");
header.classList.add("full");
localStorage.setItem("admin_menu", "closed");
}
};
document.querySelectorAll(".tabs a").forEach((element, index) => {
element.onclick = event => {
event.preventDefault();
document.querySelectorAll(".tabs a").forEach((element, index) => element.classList.remove("active"));
document.querySelectorAll(".tab-content").forEach((element2, index2) => {
if (index == index2) {
element.classList.add("active");
element2.style.display = "block";
} else {
element2.style.display = "none";
}
});
};
});
if (document.querySelector(".filters a")) {
let filtersList = document.querySelector(".filters .list");
let filtersListStyle = window.getComputedStyle(filtersList);
document.querySelector(".filters a").onclick = event => {
event.preventDefault();
if (filtersListStyle.display == "none") {
filtersList.style.display = "flex";
} else {
filtersList.style.display = "none";
}
};
document.onclick = event => {
if (!event.target.closest(".filters")) {
filtersList.style.display = "none";
}
};
}
document.querySelectorAll(".msg").forEach(element => {
element.querySelector(".fa-times").onclick = () => {
element.remove();
history.replaceState && history.replaceState(null, '', location.pathname + location.search.replace(/[\?&]success_msg=[^&]+/, '').replace(/^&/, '?') + location.hash);
history.replaceState && history.replaceState(null, '', location.pathname + location.search.replace(/[\?&]error_msg=[^&]+/, '').replace(/^&/, '?') + location.hash);
};
});
history.replaceState && history.replaceState(null, '', location.pathname + location.search.replace(/[\?&]success_msg=[^&]+/, '').replace(/^&/, '?') + location.hash);
history.replaceState && history.replaceState(null, '', location.pathname + location.search.replace(/[\?&]error_msg=[^&]+/, '').replace(/^&/, '?') + location.hash);
</script>
</body>
</html>
EOT;
}
// Convert date to elapsed string function
function time_elapsed_string($datetime, $full = false) {
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = ['y' => 'year','m' => 'month','w' => 'week','d' => 'day','h' => 'hour','i' => 'minute','s' => 'second'];
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full) $string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
?>

@ -0,0 +1,92 @@
<?php
include 'main.php';
// Configuration file
$file = '../../system/config.php';
// Open the configuration file for reading
$contents = file_get_contents($file);
// Format key function
function format_key($key) {
$key = str_replace(['_', 'url', 'db ', ' pass', ' user'], [' ', 'URL', 'Database ', ' Password', ' Username'], strtolower($key));
return ucwords($key);
}
// Format HTML output function
function format_var_html($key, $value) {
$html = '';
$type = 'text';
$value = htmlspecialchars(trim($value, '\''), ENT_QUOTES);
$type = strpos($key, 'pass') !== false ? 'password' : $type;
$type = in_array(strtolower($value), ['true', 'false']) ? 'checkbox' : $type;
$checked = strtolower($value) == 'true' ? ' checked' : '';
$html .= '<label for="' . $key . '">' . format_key($key) . '</label>';
if ($type == 'checkbox') {
$html .= '<input type="hidden" name="' . $key . '" value="false">';
}
$html .= '<input type="' . $type . '" name="' . $key . '" id="' . $key . '" value="' . $value . '" placeholder="' . format_key($key) . '"' . $checked . '>';
return $html;
}
// Format form
function format_form($contents) {
$rows = explode("\n", $contents);
echo '<div class="tab-content active">';
for ($i = 0; $i < count($rows); $i++) {
preg_match('/\/\*(.*?)\*\//', $rows[$i], $match);
if ($match) {
echo '</div><div class="tab-content">';
}
preg_match('/define\(\'(.*?)\', ?(.*?)\)/', $rows[$i], $match);
if ($match) {
echo format_var_html($match[1], $match[2]);
}
}
echo '</div>';
}
if (!empty($_POST)) {
// Update the configuration file with the new keys and values
foreach ($_POST as $k => $v) {
$v = in_array(strtolower($v), ['true', 'false']) ? strtolower($v) : '\'' . $v . '\'';
$contents = preg_replace('/define\(\'' . $k . '\'\, ?(.*?)\)/s', 'define(\'' . $k . '\',' . $v . ')', $contents);
}
file_put_contents('../../system/config.php', $contents);
header('Location: settings.php?success_msg=1');
exit;
}
// Handle success messages
// fas-times-circle for error messages and demo
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = 'Settings updated successfully!';
}
}
?>
<?=template_admin_header('Settings', 'settings')?>
<h2>Settings</h2>
<?php if (isset($success_msg)): ?>
<div class="msg success">
<i class="fas fa-check-circle"></i>
<p><?=$success_msg?></p>
<i class="fas fa-times"></i>
</div>
<?php endif; ?>
<div class="content-block">
<form action="" method="post" class="form responsive-width-100">
<?=format_form($contents)?>
<div>
<input type="submit" class="btn" value="Save">
</div>
</form>
</div>
<script>
document.querySelectorAll("input[type='checkbox']").forEach(checkbox => {
checkbox.onclick = () => {
checkbox.value = checkbox.checked ? 'true' : 'false';
};
});
</script>
<?=template_admin_footer()?>
Loading…
Cancel
Save