[PHP] 纯文本查看 复制代码
<?php
class Config {
public static $default = [
'root' => '',
'root_url_path' => null,
'root_lock' => null,
'start_path' => false,
'username' => '',
'password' => '',
'load_images' => true,
'load_files_proxy_php' => false,
'load_images_max_filesize' => 1000000,
'image_resize_enabled' => true,
'image_resize_use_imagemagick' => false,
'image_resize_cache' => true,
'image_resize_cache_use_dir' => false,
'image_resize_dimensions' => 320,
'image_resize_dimensions_retina' => 480,
'image_resize_dimensions_allowed' => '',
'image_resize_quality' => 85,
'image_resize_function' => 'imagecopyresampled',
'image_resize_sharpen' => true,
'image_resize_memory_limit' => 256,
'image_resize_max_pixels' => 60000000,
'image_resize_min_ratio' => 1.5,
'image_resize_cache_direct' => false,
'folder_preview_image' => true,
'folder_preview_default' => '_filespreview.jpg',
'menu_enabled' => true,
'menu_max_depth' => 5,
'menu_sort' => 'name_asc',
'menu_cache_validate' => true,
'menu_load_all' => false,
'menu_recursive_symlinks' => true,
'layout' => 'rows',
'cache' => true,
'cache_key' => 0,
'clean_cache_interval' => 7,
'clean_cache_allow_manual' => false,
'image_cache_file' => 'cache.txt',
'image_cache_max_last_access_time' => 90,
'image_cache_validate_time' => true,
'storage_path' => '_files',
'files_include' => '',
'files_exclude' => '',
'dirs_include' => '',
'dirs_exclude' => '',
'allow_symlinks' => true,
'get_mime_type' => false,
'license_key' => '',
'download_dir' => 'browser',
'download_dir_cache' => 'dir',
'assets' => '',
'allow_all' => false,
'allow_upload' => false,
'allow_delete' => false,
'allow_rename' => false,
'allow_new_folder' => false,
'allow_new_file' => false,
'allow_duplicate' => false,
'allow_text_edit' => false,
'allow_zip' => false,
'allow_unzip' => false,
'allow_move' => false,
'allow_copy' => false,
'allow_download' => true,
'allow_mass_download' => false,
'allow_mass_copy_links' => false,
'allow_settings' => false,
'allow_check_updates' => false,
'allow_tests' => true,
'allow_tasks' => false,
'demo_mode' => false,
'upload_allowed_file_types' => '',
'upload_max_filesize' => 0,
'upload_exists' => 'increment',
'ffmpeg_path' => 'ffmpeg',
'imagemagick_path' => 'convert',
'imagemagick_image_types' => 'heif, heic, tiff, tif, psd, dng',
'use_google_docs_viewer' => false,
'lang_default' => 'en',
'lang_auto' => true,
'index_cache' => false,
];
// global application variables created on new Config()
public static $version = '0.14.2'; // Files Gallery version
public static $config = []; // config array merged from _filesconfig.php, config.php and default config
public static $localconfigpath = '_filesconfig.php'; // optional config file in current dir, useful when overriding shared configs
public static $localconfig = []; // config array from localconfigpath
public static $storagepath; // absolute storage path for cache, config, plugins and more, normally _files dir
public static $storageconfigpath; // absolute path to storage config, normally _files/config/config.php
public static $storageconfig = []; // config array from storage path, normally _files/config/config.php
public static $cachepath; // absolute cache path shortcut
public static $__dir__; // absolute __DIR__ path with normalized OS path
public static $__file__; // absolute __FILE__ path with normalized OS path
public static $root; // absolute root path interpolated from config root option, normally current dir
public static $document_root; // absolute server document root with normalized OS path
public static $created = []; // checks what dirs and files get created by config on ?action=tests
// config construct created static app vars and merge configs
public function __construct() {
// get absolute __DIR__ and __FILE__ paths with normalized OS paths
self::$__dir__ = Path::realpath(__DIR__);
self::$__file__ = Path::realpath(__FILE__);
// load local config _filesconfig.php if exists
self::$localconfig = $this->load(self::$localconfigpath);
// create initial config array from default and localconfig
self::$config = array_replace(self::$default, self::$localconfig);
// set absolute storagepath, create storage dirs if required, and load, create or update storage config.php
$this->storage();
// get server document root with normalized OS path
self::$document_root = Path::realpath($_SERVER['DOCUMENT_ROOT']);
// install.php - allow edit settings and create users from interface temporarily when file is named "install.php"
// useful when installing Files Gallery, allows editing settings and creating users without having to modify config.php manually
// remember to rename the file back to index.php once you have edited settings and/or created users.
if(U::basename(__FILE__) === 'install.php') self::$config['allow_settings'] = true;
// at this point we must check if login is required or user is already logged in, and then merge user config
new Login();
// assign root realpath after login user is resolved
self::$root = Path::valid_root(self::get('root'));
// error if root path does not exist
if(!self::$root) U::error('Invalid root dir "' . self::get('root') . '"');
// shortcut option `allow_all` allows all file actions (except settings, check_updates, tests, tasks)
if(self::get('allow_all')) foreach (['upload', 'delete', 'rename', 'new_folder', 'new_file', 'duplicate', 'text_edit', 'zip', 'unzip', 'move', 'copy', 'download', 'mass_download', 'mass_copy_links'] as $k) self::$config['allow_'.$k] = true;
}
// public shortcut function to get config option Config::get('option')
public static function get($option){
return self::$config[$option];
}
// public get config comma-delimited string option as array
public static function get_array($option) {
$str = self::$config[$option];
return !empty($str) && is_string($str) ? array_map('trim', explode(',', $str)) : [];
}
// load a config file and trim values / returns empty array if file doesn't exist
private function load($path) {
if(empty($path) || !file_exists($path)) return [];
$config = include $path;
if(empty($config) || !is_array($config)) return [];
return array_map(function($v){
return is_string($v) ? trim($v) : $v;
}, $config);
}