Set config files override configuration

This commit is contained in:
Sharif El Shobkshy 2021-01-04 17:21:43 -03:00
parent 26415833cf
commit 5f69cbf1d6
2 changed files with 41 additions and 59 deletions

View file

@ -10,14 +10,6 @@ or
-Put inside this file all the static configuration you want and forgot to configure "tinyfilemanager.php".
#################################################################################################################
*/
// SHARIF.
$GLOBALS['CONFIG'] = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false}';
$GLOBALS['root_path'] = $_SERVER['DOCUMENT_ROOT'] . '/sites/default/files/public';
$GLOBALS['root_url'] = 'sites/default/files/public';
$GLOBALS['lang_list'] = ['en' => 'English'];
$GLOBALS['sticky_navbar'] = TRUE;
$GLOBALS['favicon_path'] = '?img=favicon';
$fm_base_path = '/browse';
// Auth with login/password
@ -63,7 +55,7 @@ $root_path = $_SERVER['DOCUMENT_ROOT'] . '/sites/default/files/public';
// Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
// Will not working if $root_path will be outside of server document root
$root_url = 'sites/default/files/public';
$root_url = $GLOBALS['root_url'] = 'sites/default/files/public';
// Server hostname. Can set manually if wrong
$http_host = $_SERVER['HTTP_HOST'];
@ -90,7 +82,7 @@ $allowed_upload_extensions = '';
// Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
// full path, e.g http://example.com/favicon.png
// local path, e.g images/icons/favicon.png
$favicon_path = '?img=favicon';
$GLOBALS['favicon_path'] = '?img=favicon';
// Files and folders to excluded from listing
// e.g. array('myfile.html', 'personal-folder', '*.php', ...)
@ -106,9 +98,11 @@ $online_viewer = 'google';
// Sticky Nav bar
// true => enable sticky header
// false => disable sticky header
$sticky_navbar = true;
$GLOBALS['sticky_navbar'] = true;
// Maximum file upload size
// Increase the following values in php.ini to work properly
// memory_limit, upload_max_filesize, post_max_size
// max upload file size
$max_upload_size_bytes = 2048;

View file

@ -1,6 +1,6 @@
<?php
//Default Configuration
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false}';
$CONFIG = $GLOBALS['CONFIG'] = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false}';
/**
* H3K | Tiny File Manager V2.4.3
@ -57,11 +57,11 @@ $default_timezone = 'Etc/UTC'; // UTC
// use absolute path of directory i.e: '/var/www/folder' or $_SERVER['DOCUMENT_ROOT'].'/folder'
$root_path = $_SERVER['DOCUMENT_ROOT'];
$fm_base_path = '';
// Root url for links in file manager.Relative to $http_host. Variants: '', 'path/to/subfolder'
// Will not working if $root_path will be outside of server document root
$root_url = '';
$fm_base_path = '';
$root_url = $GLOBALS['root_url'] = '';
// Server hostname. Can set manually if wrong
$http_host = $_SERVER['HTTP_HOST'];
@ -88,7 +88,7 @@ $allowed_upload_extensions = '';
// Favicon path. This can be either a full url to an .PNG image, or a path based on the document root.
// full path, e.g http://example.com/favicon.png
// local path, e.g images/icons/favicon.png
$favicon_path = '?img=favicon';
$GLOBALS['favicon_path'] = '?img=favicon';
// Files and folders to excluded from listing
// e.g. array('myfile.html', 'personal-folder', '*.php', ...)
@ -104,11 +104,12 @@ $online_viewer = 'google';
// Sticky Nav bar
// true => enable sticky header
// false => disable sticky header
$sticky_navbar = true;
$GLOBALS['sticky_navbar'] = true;
// Maximum file upload size
// Increase the following values in php.ini to work properly
// memory_limit, upload_max_filesize, post_max_size
// max upload file size
$max_upload_size_bytes = 2048;
// Possible rules are 'OFF', 'AND' or 'OR'
@ -161,23 +162,23 @@ $cfg = new FM_Config();
$GLOBALS['lang'] = isset($cfg->data['lang']) ? $cfg->data['lang'] : 'en';
// Show or hide files and folders that starts with a dot
$show_hidden_files = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
$GLOBALS['show_hidden_files'] = isset($cfg->data['show_hidden']) ? $cfg->data['show_hidden'] : true;
// PHP error reporting - false = Turns off Errors, true = Turns on Errors
$report_errors = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
$GLOBALS['report_errors'] = isset($cfg->data['error_reporting']) ? $cfg->data['error_reporting'] : true;
// Hide Permissions and Owner cols in file-listing
$hide_Cols = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
$GLOBALS['hide_Cols'] = isset($cfg->data['hide_Cols']) ? $cfg->data['hide_Cols'] : true;
// Show directory size: true or speedup output: false
$GLOBALS['calc_folder'] = isset($cfg->data['calc_folder']) ? $cfg->data['calc_folder'] : true;
//available languages
$lang_list = array(
$GLOBALS['lang_list'] = array(
'en' => 'English'
);
if ($report_errors == true) {
if ($GLOBALS['report_errors'] == true) {
@ini_set('error_reporting', E_ALL);
@ini_set('display_errors', 1);
} else {
@ -377,7 +378,7 @@ if (!@is_dir($root_path)) {
exit;
}
defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $show_hidden_files);
defined('FM_SHOW_HIDDEN') || define('FM_SHOW_HIDDEN', $GLOBALS['show_hidden_files']);
defined('FM_ROOT_PATH') || define('FM_ROOT_PATH', $root_path);
defined('FM_LANG') || define('FM_LANG', $GLOBALS['lang']);
defined('FM_FILE_EXTENSION') || define('FM_FILE_EXTENSION', $allowed_file_extensions);
@ -485,7 +486,6 @@ if (isset($_POST['ajax']) && !FM_READONLY) {
// Save Config
if (isset($_POST['type']) && $_POST['type'] == "settings") {
//global $cfg, $lang, $report_errors, $show_hidden_files, $lang_list, $hide_Cols, $calc_folder;
$newLng = $_POST['js-language'];
fm_get_translations([]);
if (!array_key_exists($newLng, $GLOBALS['lang_list'])) {
@ -503,19 +503,19 @@ if (isset($_POST['ajax']) && !FM_READONLY) {
}
if ($cfg->data['error_reporting'] != $erp) {
$cfg->data['error_reporting'] = $erp;
$report_errors = $erp;
$GLOBALS['report_errors'] = $erp;
}
if ($cfg->data['show_hidden'] != $shf) {
$cfg->data['show_hidden'] = $shf;
$show_hidden_files = $shf;
$GLOBALS['show_hidden_files'] = $shf;
}
if ($cfg->data['show_hidden'] != $shf) {
$cfg->data['show_hidden'] = $shf;
$show_hidden_files = $shf;
$GLOBALS['show_hidden_files'] = $shf;
}
if ($cfg->data['hide_Cols'] != $hco) {
$cfg->data['hide_Cols'] = $hco;
$hide_Cols = $hco;
$GLOBALS['hide_Cols'] = $hco;
}
if ($cfg->data['calc_folder'] != $caf) {
$cfg->data['calc_folder'] = $caf;
@ -549,12 +549,10 @@ if (isset($_POST['ajax']) && !FM_READONLY) {
$isFileAllowed = ($allowed) ? in_array($ext, $allowed) : true;
function event_callback ($message) {
//global $callback;
echo json_encode($message);
}
function get_file_path ($fileinfo = [], $path = '') {
//global $path, $fileinfo, $temp_file;
return $path."/".basename($fileinfo->name);
}
@ -1332,7 +1330,6 @@ if (isset($_GET['copy']) && !isset($_GET['finish']) && !FM_READONLY) {
if (isset($_GET['settings']) && !FM_READONLY) {
fm_show_header(); // HEADER
fm_show_nav_path(FM_PATH); // current path
//global $cfg, $lang, $lang_list;
?>
<div class="col-md-8 offset-md-2 pt-3">
@ -1350,7 +1347,6 @@ if (isset($_GET['settings']) && !FM_READONLY) {
<select class="form-control" id="js-language" name="js-language">
<?php
function getSelected($l) {
//global $lang;
return ($GLOBALS['lang'] == $l) ? 'selected' : '';
}
foreach ($GLOBALS['lang_list'] as $k => $v) {
@ -1376,11 +1372,11 @@ if (isset($_GET['settings']) && !FM_READONLY) {
<label for="js-err-rpt-1" class="col-sm-3 col-form-label"><?php echo lng('ErrorReporting') ?></label>
<div class="col-sm-9">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary <?php echo getChecked($report_errors, 1, 'active') ?>">
<input type="radio" name="js-error-report" id="js-err-rpt-1" autocomplete="off" value="true" <?php echo getChecked($report_errors, 1, 'checked') ?> > ON
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['report_errors'], 1, 'active') ?>">
<input type="radio" name="js-error-report" id="js-err-rpt-1" autocomplete="off" value="true" <?php echo getChecked($GLOBALS['report_errors'], 1, 'checked') ?> > ON
</label>
<label class="btn btn-secondary <?php echo getChecked($report_errors, '', 'active') ?>">
<input type="radio" name="js-error-report" id="js-err-rpt-0" autocomplete="off" value="false" <?php echo getChecked($report_errors, '', 'checked') ?> > OFF
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['report_errors'], '', 'active') ?>">
<input type="radio" name="js-error-report" id="js-err-rpt-0" autocomplete="off" value="false" <?php echo getChecked($GLOBALS['report_errors'], '', 'checked') ?> > OFF
</label>
</div>
</div>
@ -1390,11 +1386,11 @@ if (isset($_GET['settings']) && !FM_READONLY) {
<label for="js-hdn-1" class="col-sm-3 col-form-label"><?php echo lng('ShowHiddenFiles') ?></label>
<div class="col-sm-9">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary <?php echo getChecked($show_hidden_files, 1, 'active') ?>">
<input type="radio" name="js-show-hidden" id="js-hdn-1" autocomplete="off" value="true" <?php echo getChecked($show_hidden_files, 1, 'checked') ?> > ON
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['show_hidden_files'], 1, 'active') ?>">
<input type="radio" name="js-show-hidden" id="js-hdn-1" autocomplete="off" value="true" <?php echo getChecked($GLOBALS['show_hidden_files'], 1, 'checked') ?> > ON
</label>
<label class="btn btn-secondary <?php echo getChecked($show_hidden_files, '', 'active') ?>">
<input type="radio" name="js-show-hidden" id="js-hdn-0" autocomplete="off" value="false" <?php echo getChecked($show_hidden_files, '', 'checked') ?> > OFF
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['show_hidden_files'], '', 'active') ?>">
<input type="radio" name="js-show-hidden" id="js-hdn-0" autocomplete="off" value="false" <?php echo getChecked($GLOBALS['show_hidden_files'], '', 'checked') ?> > OFF
</label>
</div>
</div>
@ -1404,11 +1400,11 @@ if (isset($_GET['settings']) && !FM_READONLY) {
<label for="js-hid-1" class="col-sm-3 col-form-label"><?php echo lng('HideColumns') ?></label>
<div class="col-sm-9">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary <?php echo getChecked($hide_Cols, 1, 'active') ?>">
<input type="radio" name="js-hide-cols" id="js-hid-1" autocomplete="off" value="true" <?php echo getChecked($hide_Cols, 1, 'checked') ?> > ON
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['hide_Cols'], 1, 'active') ?>">
<input type="radio" name="js-hide-cols" id="js-hid-1" autocomplete="off" value="true" <?php echo getChecked($GLOBALS['hide_Cols'], 1, 'checked') ?> > ON
</label>
<label class="btn btn-secondary <?php echo getChecked($hide_Cols, '', 'active') ?>">
<input type="radio" name="js-hide-cols" id="js-hid-0" autocomplete="off" value="false" <?php echo getChecked($hide_Cols, '', 'checked') ?> > OFF
<label class="btn btn-secondary <?php echo getChecked($GLOBALS['hide_Cols'], '', 'active') ?>">
<input type="radio" name="js-hide-cols" id="js-hid-0" autocomplete="off" value="false" <?php echo getChecked($GLOBALS['hide_Cols'], '', 'checked') ?> > OFF
</label>
</div>
</div>
@ -1446,7 +1442,6 @@ if (isset($_GET['settings']) && !FM_READONLY) {
if (isset($_GET['help'])) {
fm_show_header(); // HEADER
fm_show_nav_path(FM_PATH); // current path
//global $cfg, $lang;
?>
<div class="col-md-8 offset-md-2 pt-3">
@ -1890,7 +1885,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<th><?php echo lng('Name') ?></th>
<th><?php echo lng('Size') ?></th>
<th><?php echo lng('Modified') ?></th>
<?php if (!FM_IS_WIN && !$hide_Cols): ?>
<?php if (!FM_IS_WIN && !$GLOBALS['hide_Cols']): ?>
<th><?php echo lng('Perms') ?></th>
<th><?php echo lng('Owner') ?></th><?php endif; ?>
<th><?php echo lng('Actions') ?></th>
@ -1906,7 +1901,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<td class="border-0"></td>
<td class="border-0"></td>
<td class="border-0"></td>
<?php if (!FM_IS_WIN && !$hide_Cols) { ?>
<?php if (!FM_IS_WIN && !$GLOBALS['hide_Cols']) { ?>
<td class="border-0"></td>
<td class="border-0"></td>
<?php } ?>
@ -1952,7 +1947,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<?php echo $filesize; ?>
</td>
<td data-sort="a-<?php echo $modif_raw;?>"><?php echo $modif ?></td>
<?php if (!FM_IS_WIN && !$hide_Cols): ?>
<?php if (!FM_IS_WIN && !$GLOBALS['hide_Cols']): ?>
<td><?php if (!FM_READONLY): ?><a title="Change Permissions" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
</td>
<td><?php echo $owner['name'] . ':' . $group['name'] ?></td>
@ -2014,7 +2009,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<?php echo $filesize; ?>
</span></td>
<td data-sort="b-<?php echo $modif_raw;?>"><?php echo $modif ?></td>
<?php if (!FM_IS_WIN && !$hide_Cols): ?>
<?php if (!FM_IS_WIN && !$GLOBALS['hide_Cols']): ?>
<td><?php if (!FM_READONLY): ?><a title="<?php echo 'Change Permissions' ?>" href="?p=<?php echo urlencode(FM_PATH) ?>&amp;chmod=<?php echo urlencode($f) ?>"><?php echo $perms ?></a><?php else: ?><?php echo $perms ?><?php endif; ?>
</td>
<td><?php echo fm_enc($owner['name'] . ':' . $group['name']) ?></td>
@ -2041,7 +2036,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<tfoot>
<tr><?php if (!FM_READONLY): ?>
<td></td><?php endif; ?>
<td colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>"><em><?php echo 'Folder is empty' ?></em></td>
<td colspan="<?php echo (!FM_IS_WIN && !$GLOBALS['hide_Cols']) ? '6' : '4' ?>"><em><?php echo 'Folder is empty' ?></em></td>
</tr>
</tfoot>
<?php
@ -2050,7 +2045,7 @@ $tableTheme = (FM_THEME == "dark") ? "text-white bg-dark table-dark" : "bg-white
<tfoot>
<tr><?php if (!FM_READONLY): ?>
<td class="gray"></td><?php endif; ?>
<td class="gray" colspan="<?php echo (!FM_IS_WIN && !$hide_Cols) ? '6' : '4' ?>">
<td class="gray" colspan="<?php echo (!FM_IS_WIN && !$GLOBALS['hide_Cols']) ? '6' : '4' ?>">
<?php echo lng('FullSize').': <span class="badge badge-light">'.fm_get_filesize($all_files_size).'</span>' ?>
<?php echo lng('File').': <span class="badge badge-light">'.$num_files.'</span>' ?>
<?php echo lng('Folder').': <span class="badge badge-light">'.$num_folders.'</span>' ?>
@ -2397,7 +2392,6 @@ function fm_get_translations($tr) {
$content = @file_get_contents('translation.json');
if($content !== FALSE) {
$lng = json_decode($content, TRUE);
//global $lang_list;
foreach ($lng["language"] as $key => $value)
{
$code = $value["code"];
@ -2483,7 +2477,6 @@ function fm_get_filesize($size)
* @return int
*/
function fm_get_directorysize($directory) {
//global $calc_folder;
if ($GLOBALS['calc_folder']==true) { // Slower output
$size = 0; $count= 0; $dirCount= 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file)
@ -3234,7 +3227,6 @@ class FM_Zipper_Tar
function __construct()
{
//global $root_path, $root_url, $CONFIG;
$fm_url = $GLOBALS['root_url'].FM_BASE_PATH;
$this->data = array(
'lang' => 'en',
@ -3287,7 +3279,6 @@ class FM_Zipper_Tar
*/
function fm_show_nav_path($path)
{
//global $lang, $sticky_navbar;
$isStickyNavBar = $GLOBALS['sticky_navbar'] ? 'fixed-top' : '';
$getTheme = fm_get_theme();
$getTheme .= " navbar-light";
@ -3396,7 +3387,6 @@ header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
//global $lang, $root_url, $favicon_path;
?>
<!DOCTYPE html>
<html lang="en">
@ -3467,7 +3457,6 @@ header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
//global $lang, $root_url, $sticky_navbar, $favicon_path;
$isStickyNavBar = $GLOBALS['sticky_navbar'] ? 'navbar-fixed' : 'navbar-normal';
?>
<!DOCTYPE html>
@ -4006,7 +3995,6 @@ function fm_show_image($img)
* @return string
*/
function lng($txt) {
//global $lang;
// English Language
$tr['en']['AppName'] = 'Tiny File Manager'; $tr['en']['AppTitle'] = 'File Manager';