From ac8a67bd06a3739d94c5b3d4990f93a16dabdaa6 Mon Sep 17 00:00:00 2001
From: fbotp <46618620+fbotp@users.noreply.github.com>
Date: Fri, 13 Jan 2023 11:56:56 +0800
Subject: [PATCH] Move config from .php to config.json
---
config.json | 1 +
tinyfilemanager.php | 43 +++++++++++--------------------------------
2 files changed, 12 insertions(+), 32 deletions(-)
create mode 100644 config.json
diff --git a/config.json b/config.json
new file mode 100644
index 0000000..b4bbe3f
--- /dev/null
+++ b/config.json
@@ -0,0 +1 @@
+{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}
\ No newline at end of file
diff --git a/tinyfilemanager.php b/tinyfilemanager.php
index 6a29403..4324a75 100644
--- a/tinyfilemanager.php
+++ b/tinyfilemanager.php
@@ -1,7 +1,4 @@
data = array(
- 'lang' => 'en',
- 'error_reporting' => true,
- 'show_hidden' => true
- );
- $data = false;
- if (strlen($CONFIG)) {
- $data = fm_object_to_array(json_decode($CONFIG));
- } else {
+ $this->data = json_decode(@file_get_contents('config.json'), true);
+ if($this->data == "") {
$msg = 'Tiny File Manager
Error: Cannot load configuration';
- if (substr($fm_url, -1) == '/') {
+ if ($fm_url == '/' || $fm_url == "/index.php") {
$fm_url = rtrim($fm_url, '/');
$msg .= '
';
- $msg .= '
Seems like you have a trailing slash on the URL.';
- $msg .= '
Try this link: ' . $fm_url . '';
+ $msg .= '
Seems config.json does not exists or has no content.';
+ $msg .= '
Try create config.json with content: {"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"theme":"light"}';
}
die($msg);
}
- if (is_array($data) && count($data)) $this->data = $data;
- else $this->save();
}
function save()
{
- $fm_file = __FILE__;
- $var_name = '$CONFIG';
- $var_value = var_export(json_encode($this->data), true);
- $config_string = "data, JSON_PRETTY_PRINT);
+ $config_file = "config.json";
+ if (is_writable($config_file)) {
+ file_put_contents($config_file, $var_value);
}
}
}