From 29477e67ede12347b153e2255325327374e1b073 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 9 Dec 2025 01:43:12 +0500 Subject: feat: new configuration --- lib/accounts.php | 2 +- lib/config.php | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/config.sample.php | 74 --------------------------------- lib/partials.php | 16 +++---- 4 files changed, 122 insertions(+), 83 deletions(-) create mode 100644 lib/config.php delete mode 100644 lib/config.sample.php (limited to 'lib') diff --git a/lib/accounts.php b/lib/accounts.php index 51cb3f6..2ddb796 100644 --- a/lib/accounts.php +++ b/lib/accounts.php @@ -28,7 +28,7 @@ function authorize_user(bool $required = false): bool include_once "config.php"; - $db = new PDO(DB_URL, DB_USER, DB_PASS); + $db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['pass']); $key = $_SERVER["HTTP_AUTHORIZATION"] ?? $_COOKIE["secret_key"]; diff --git a/lib/config.php b/lib/config.php new file mode 100644 index 0000000..1c6797d --- /dev/null +++ b/lib/config.php @@ -0,0 +1,113 @@ + [ + 'name' => $_SERVER['HTTP_HOST'] + ], + 'database' => [ + 'name' => '', + 'user' => '', + 'pass' => '', + 'host' => 'localhost', + 'url' => '' + ], + 'anonymous' => [ + 'upload' => false, + 'defaultname' => 'Anonymous' + ], + 'emote' => [ + 'upload' => true, + 'nameregex' => "/^[A-Za-z0-9_]+$/", + 'defaultvisibility' => 2, + 'maxnamelength' => 100, + 'maxcommentlength' => 100, + 'maxsizex' => 128, + 'maxsizey' => 128, + 'storeoriginal' => true + ], + 'rating' => [ + 'enable' => true, + 'names' => "-1=COAL\n1=GEM", + 'minvotes' => 10 + ], + 'tags' => [ + 'enable' => true, + 'regex' => "/^[A-Za-z0-9_]+$/", + 'maxcount' => 10 + ], + 'emoteset' => [ + 'public' => true + ], + 'mod' => [ + 'dashboard' => true, + 'approve' => true + ], + 'reports' => [ + 'enable' => true + ], + 'account' => [ + 'registration' => true, + 'maxcookielifetime' => 86400 * 30, + 'regex' => "/^[A-Za-z0-9_]+$/", + 'minusernamelength' => 2, + 'maxusernamelength' => 20, + 'minpasswordlength' => 10, + 'secretkeylength' => 32, + 'pfpsizex' => 128, + 'pfpsizey' => 128, + 'bannersizex' => 1920, + 'bannersizey' => 1080, + 'badgesizex' => 72, + 'badgesizey' => 72, + 'publiclist' => true, + 'log' => true + ], + 'twitch' => [ + 'registration' => false, + 'clientid' => '', + 'clientsecret' => '', + 'redirecturi' => ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http") . "://$_SERVER[HTTP_HOST]/account/login/twitch.php" + ], + 'captcha' => [ + 'enable' => false, + 'x' => 580, + 'y' => 220, + 'force' => false + ] +]; + +if (file_exists(CFG_PATH)) { + $c = json_decode(file_get_contents(CFG_PATH), true); + foreach ($cfg as $sk => $sv) { + if (!is_array($sv) || !array_key_exists($sk, $c)) { + continue; + } + + foreach ($sv as $k => $v) { + if (array_key_exists($k, $c[$sk])) { + $cfg[$sk][$k] = $c[$sk][$k]; + } + } + } +} + +if (!empty($cfg['database']['host'])) { + $cfg['database']['url'] = "mysql:host={$cfg['database']['host']};dbname={$cfg['database']['name']};port=3306"; +} + +$cfg['rating']['names_string'] = $cfg['rating']['names']; +$n = []; +foreach (explode("\n", $cfg['rating']['names']) as $_ => $v) { + [$k, $v] = explode('=', $v, 2); + $n[intval($k)] = $v; +} +$cfg['rating']['names'] = $n; + +define('CONFIG', $cfg); + +define("INSTANCE_STATIC_FOLDER", "static"); // Static folder. Used only in /404.php. + +// FOR DEVELOPERS +define("CLIENT_REQUIRES_JSON", isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json"); \ No newline at end of file diff --git a/lib/config.sample.php b/lib/config.sample.php deleted file mode 100644 index 3d30044..0000000 --- a/lib/config.sample.php +++ /dev/null @@ -1,74 +0,0 @@ - "COAL", - "1" => "GEM", -]); // Rating names. The schema is [ "id/rating_point" => "name" ]. -define("RATING_EMOTE_MIN_VOTES", 10); // Minimal amount of votes to display emote rating. - -// UPLOADS -define("ANONYMOUS_UPLOAD", false); // Allow anonymous upload for emotes. -define("ANONYMOUS_DEFAULT_NAME", "Anonymous"); // Default uploader name for anonymous emotes. It's also used when original uploader has been deleted. - -// EMOTES -define("EMOTE_UPLOAD", true); // Enable emote upload. -define("EMOTE_NAME_MAX_LENGTH", 100); // Max length for emote name. -define("EMOTE_COMMENT_MAX_LENGTH", 100); // Max length for emote comment. -define("EMOTE_VISIBILITY_DEFAULT", 2); // Default visibility for emotes. 0 - unlisted, 1 - public, 2 - pending approval (same as unlisted). -define("EMOTE_MAX_SIZE", [128, 128]); // Max size of emote. -define("EMOTE_NAME_REGEX", "/^[A-Za-z0-9_]+$/"); // RegEx filter for emote names. -define("EMOTE_STORE_ORIGINAL", true); // Store original uploads of emotes. - -// TAGS -define("TAGS_ENABLE", true); // Allow emote tagging. -define("TAGS_CODE_REGEX", "/^[A-Za-z0-9_]+$/"); -define("TAGS_MAX_COUNT", 10); // Maximum tags per emote. Set -1 for unlimited amount. - -// EMOTESETS -define("EMOTESET_PUBLIC_LIST", true); // Show emotesets public. - -// MODERATION -define("MOD_SYSTEM_DASHBOARD", true); // Enable system dashboard for moderators (/system). -define("MOD_EMOTES_APPROVE", true); // Enable manual emote approval (/system/emotes). - -// REPORTS -define("REPORTS_ENABLE", true); // Enable emote, user reports. - -// ACCOUNTS -define("ACCOUNT_REGISTRATION_ENABLE", true); // Enable account registration. -define("ACCOUNT_COOKIE_MAX_LIFETIME", 86400 * 30); // Remember user for a month. -define("ACCOUNT_USERNAME_REGEX", "/^[A-Za-z0-9_]+$/"); // RegEx filter for account usernames. -define("ACCOUNT_USERNAME_LENGTH", [2, 20]); // [Min, Max] length for account usernames. -define("ACCOUNT_PASSWORD_MIN_LENGTH", 10); // Minimal length for passwords. -define("ACCOUNT_SECRET_KEY_LENGTH", 32); // The length for secret keys. -define("ACCOUNT_PFP_MAX_SIZE", [128, 128]); // Max dimensions for account pictures. -define("ACCOUNT_BANNER_MAX_SIZE", [1920, 1080]); // Max dimensions for account banners. -define("ACCOUNT_BADGE_MAX_SIZE", [72, 72]); // Max dimensions for account badges. -define("ACCOUNT_PUBLIC_LIST", true); // The public list of accounts. -define("ACCOUNT_LOG_ACTIONS", true); // Log user's actions (emote addition, etc.). - -// TWITCH -define("TWITCH_REGISTRATION_ENABLE", false); // Enable account registration via Twitch. -define("TWITCH_CLIENT_ID", "AAAAAAAAA"); // Client ID of your Twitch application. -define("TWITCH_SECRET_KEY", "BBBBBBBBB"); // Secret key of your Twitch application. -define("TWITCH_REDIRECT_URI", ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http") . "://$_SERVER[HTTP_HOST]/account/login/twitch.php"); // Redirect URI of your Twitch application. - -// CAPTCHA -define("CAPTCHA_ENABLE", true); // Enable built-in captcha. -define("CAPTCHA_SIZE", [580, 220]); // Captcha size. -define("CAPTCHA_FORCE_USERS", false); // Force authorized users to solve captcha. - -// FOR DEVELOPERS -define("CLIENT_REQUIRES_JSON", isset($_SERVER["HTTP_ACCEPT"]) && $_SERVER["HTTP_ACCEPT"] == "application/json"); \ No newline at end of file diff --git a/lib/partials.php b/lib/partials.php index 760923a..979621d 100644 --- a/lib/partials.php +++ b/lib/partials.php @@ -7,26 +7,26 @@ function html_navigation_bar()