diff --git a/misuzu.php b/misuzu.php index 022fea25..fb089990 100644 --- a/misuzu.php +++ b/misuzu.php @@ -33,6 +33,7 @@ require_once 'src/colour.php'; require_once 'src/comments.php'; require_once 'src/config.php'; require_once 'src/csrf.php'; +require_once 'src/db.php'; require_once 'src/general.php'; require_once 'src/git.php'; require_once 'src/mail.php'; @@ -70,7 +71,7 @@ if (!empty($errorReporter)) { ); } -$app->startDatabase(); +db_setup(MSZ_DATABASE_NAMES[0], config_get_default([], 'Database.' . MSZ_DATABASE_NAMES[0])); if (PHP_SAPI === 'cli') { if ($argv[0] === basename(__FILE__)) { @@ -242,7 +243,13 @@ MIG; exit; } - $app->startCache(); + new Cache( + config_get('Cache', 'host'), + config_get('Cache', 'port'), + config_get('Cache', 'database'), + config_get('Cache', 'password'), + config_get_default('', 'Cache', 'prefix') + ); tpl_init([ 'debug' => MSZ_DEBUG, diff --git a/public/profile.php b/public/profile.php index 8796c565..e87c3c07 100644 --- a/public/profile.php +++ b/public/profile.php @@ -148,8 +148,8 @@ switch ($mode) { if ($isEditing) { tpl_vars([ 'guidelines' => [ - 'avatar' => $app->getAvatarProps(), - 'background' => $app->getBackgroundProps(), + 'avatar' => user_avatar_default_options(), + 'background' => user_background_default_options(), ], ]); } diff --git a/public/settings.php b/public/settings.php index 03755fc5..e6b56d8a 100644 --- a/public/settings.php +++ b/public/settings.php @@ -55,8 +55,8 @@ $disableAccountOptions = !MSZ_DEBUG && boolval(config_get_default(false, 'Private', 'enabled')) && boolval(config_get_default(false, 'Private', 'disable_account_settings')); $avatarFileName = "{$settingsUserId}.msz"; -$avatarProps = $app->getAvatarProps(); -$backgroundProps = $app->getBackgroundProps(); +$avatarProps = user_avatar_default_options(); +$backgroundProps = user_background_default_options(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!csrf_verify('settings', $_POST['csrf'] ?? '')) { diff --git a/src/Application.php b/src/Application.php index 9f446af5..84b69c8d 100644 --- a/src/Application.php +++ b/src/Application.php @@ -12,13 +12,6 @@ final class Application { private static $instance = null; - /** - * Array of database connection names, first in the list is assumed to be the default. - */ - private const DATABASE_CONNECTIONS = [ - 'mysql-main', - ]; - private $geoipInstance = null; public function __construct() @@ -39,42 +32,6 @@ final class Application return create_directory(config_get_default(MSZ_ROOT . '/store', 'Storage', 'path')); } - /** - * Sets up the database module. - */ - public function startDatabase(): void - { - if (Database::hasInstance()) { - throw new UnexpectedValueException('Database has already been started.'); - } - - $connections = []; - - foreach (self::DATABASE_CONNECTIONS as $name) { - $connections[$name] = config_get_default([], "Database.{$name}"); - } - - new Database($connections, self::DATABASE_CONNECTIONS[0]); - } - - /** - * Sets up the caching stuff. - */ - public function startCache(): void - { - if (Cache::hasInstance()) { - throw new UnexpectedValueException('Cache has already been started.'); - } - - new Cache( - config_get('Cache', 'host'), - config_get('Cache', 'port'), - config_get('Cache', 'database'), - config_get('Cache', 'password'), - config_get_default('', 'Cache', 'prefix') - ); - } - public function startGeoIP(): void { if (!empty($this->geoipInstance)) { @@ -98,24 +55,6 @@ final class Application return self::getInstance()->getGeoIP(); } - public function getAvatarProps(): array - { - return [ - 'max_width' => intval(config_get_default(1000, 'Avatar', 'max_width')), - 'max_height' => intval(config_get_default(1000, 'Avatar', 'max_height')), - 'max_size' => intval(config_get_default(500000, 'Avatar', 'max_filesize')), - ]; - } - - public function getBackgroundProps(): array - { - return [ - 'max_width' => intval(config_get_default(3840, 'Avatar', 'max_width')), - 'max_height' => intval(config_get_default(2160, 'Avatar', 'max_height')), - 'max_size' => intval(config_get_default(1000000, 'Avatar', 'max_filesize')), - ]; - } - // used in some of the user functions still, fix that public static function getInstance(): Application { diff --git a/src/Users/user.php b/src/Users/user.php index a4ee2f86..1779872b 100644 --- a/src/Users/user.php +++ b/src/Users/user.php @@ -163,11 +163,16 @@ function user_avatar_is_allowed_type(int $type): bool } define('MSZ_USER_AVATAR_OPTIONS', [ - 'max_width' => 4000, - 'max_height' => 4000, - 'max_size' => 1000000, + 'max_width' => 1000, + 'max_height' => 1000, + 'max_size' => 500000, ]); +function user_avatar_default_options(): array +{ + return array_merge(MSZ_USER_AVATAR_OPTIONS, config_get_default([], 'Avatar')); +} + define('MSZ_USER_AVATAR_NO_ERRORS', 0); define('MSZ_USER_AVATAR_ERROR_INVALID_IMAGE', 1); define('MSZ_USER_AVATAR_ERROR_PROHIBITED_TYPE', 2); @@ -337,6 +342,11 @@ define('MSZ_USER_BACKGROUND_OPTIONS', [ 'max_size' => 1000000, ]); +function user_background_default_options(): array +{ + return array_merge(MSZ_USER_BACKGROUND_OPTIONS, config_get_default([], 'Background')); +} + define('MSZ_USER_BACKGROUND_NO_ERRORS', 0); define('MSZ_USER_BACKGROUND_ERROR_INVALID_IMAGE', 1); define('MSZ_USER_BACKGROUND_ERROR_PROHIBITED_TYPE', 2); diff --git a/src/db.php b/src/db.php new file mode 100644 index 00000000..c4670f69 --- /dev/null +++ b/src/db.php @@ -0,0 +1,10 @@ + $options], $name); +}