Changed avatar limitations.
This commit is contained in:
parent
885b76fce3
commit
c2b3becc14
6 changed files with 36 additions and 70 deletions
11
misuzu.php
11
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,
|
||||
|
|
|
@ -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(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -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'] ?? '')) {
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
10
src/db.php
Normal file
10
src/db.php
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
define('MSZ_DATABASE_NAMES', [
|
||||
'mysql-main',
|
||||
]);
|
||||
|
||||
function db_setup(string $name, array $options): void
|
||||
{
|
||||
// todo: :puke:
|
||||
new Misuzu\Database([$name => $options], $name);
|
||||
}
|
Loading…
Reference in a new issue