Moved storage path into a constant.
This commit is contained in:
parent
c2b3becc14
commit
8ff10f9d3c
5 changed files with 15 additions and 25 deletions
|
@ -73,6 +73,9 @@ if (!empty($errorReporter)) {
|
||||||
|
|
||||||
db_setup(MSZ_DATABASE_NAMES[0], config_get_default([], 'Database.' . MSZ_DATABASE_NAMES[0]));
|
db_setup(MSZ_DATABASE_NAMES[0], config_get_default([], 'Database.' . MSZ_DATABASE_NAMES[0]));
|
||||||
|
|
||||||
|
// replace this with a better storage mechanism
|
||||||
|
define('MSZ_STORAGE', create_directory(config_get_default(MSZ_ROOT . '/store', 'Storage', 'path')));
|
||||||
|
|
||||||
if (PHP_SAPI === 'cli') {
|
if (PHP_SAPI === 'cli') {
|
||||||
if ($argv[0] === basename(__FILE__)) {
|
if ($argv[0] === basename(__FILE__)) {
|
||||||
switch ($argv[1] ?? null) {
|
switch ($argv[1] ?? null) {
|
||||||
|
@ -237,8 +240,7 @@ MIG;
|
||||||
// we're running this again because ob_clean breaks gzip otherwise
|
// we're running this again because ob_clean breaks gzip otherwise
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
$mszStoragePath = $app->getStoragePath();
|
if (!is_readable(MSZ_STORAGE) || !is_writable(MSZ_STORAGE)) {
|
||||||
if (!is_readable($mszStoragePath) || !is_writable($mszStoragePath)) {
|
|
||||||
echo 'Cannot access storage directory.';
|
echo 'Cannot access storage directory.';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,14 @@ switch ($mode) {
|
||||||
);
|
);
|
||||||
$user_avatar = "{$userId}.msz";
|
$user_avatar = "{$userId}.msz";
|
||||||
$cropped_avatar = build_path(
|
$cropped_avatar = build_path(
|
||||||
create_directory(build_path($app->getStoragePath(), 'avatars/200x200')),
|
create_directory(build_path(MSZ_STORAGE, 'avatars/200x200')),
|
||||||
$user_avatar
|
$user_avatar
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_file($cropped_avatar)) {
|
if (is_file($cropped_avatar)) {
|
||||||
$avatar_filename = $cropped_avatar;
|
$avatar_filename = $cropped_avatar;
|
||||||
} else {
|
} else {
|
||||||
$original_avatar = build_path($app->getStoragePath(), 'avatars/original', $user_avatar);
|
$original_avatar = build_path(MSZ_STORAGE, 'avatars/original', $user_avatar);
|
||||||
|
|
||||||
if (is_file($original_avatar)) {
|
if (is_file($original_avatar)) {
|
||||||
try {
|
try {
|
||||||
|
@ -45,7 +45,7 @@ switch ($mode) {
|
||||||
|
|
||||||
case 'background':
|
case 'background':
|
||||||
$user_background = build_path(
|
$user_background = build_path(
|
||||||
create_directory(build_path($app->getStoragePath(), 'backgrounds/original')),
|
create_directory(build_path(MSZ_STORAGE, 'backgrounds/original')),
|
||||||
"{$userId}.msz"
|
"{$userId}.msz"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ switch ($mode) {
|
||||||
'is_editing' => $isEditing,
|
'is_editing' => $isEditing,
|
||||||
'perms' => $perms,
|
'perms' => $perms,
|
||||||
'profile_fields' => user_session_active() ? user_profile_fields_display($profile, !$isEditing) : [],
|
'profile_fields' => user_session_active() ? user_profile_fields_display($profile, !$isEditing) : [],
|
||||||
'has_background' => is_file(build_path($app->getStoragePath(), 'backgrounds/original', "{$profile['user_id']}.msz")),
|
'has_background' => is_file(build_path(MSZ_STORAGE, 'backgrounds/original', "{$profile['user_id']}.msz")),
|
||||||
]);
|
]);
|
||||||
echo tpl_render('user.profile');
|
echo tpl_render('user.profile');
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -367,8 +367,8 @@ switch ($settingsMode) {
|
||||||
$getAccountInfo->bindValue('user_id', $settingsUserId);
|
$getAccountInfo->bindValue('user_id', $settingsUserId);
|
||||||
$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : [];
|
$accountInfo = $getAccountInfo->execute() ? $getAccountInfo->fetch(PDO::FETCH_ASSOC) : [];
|
||||||
|
|
||||||
$userHasAvatar = is_file(build_path($app->getStoragePath(), 'avatars/original', $avatarFileName));
|
$userHasAvatar = is_file(build_path(MSZ_STORAGE, 'avatars/original', $avatarFileName));
|
||||||
$userHasBackground = is_file(build_path($app->getStoragePath(), 'backgrounds/original', $avatarFileName));
|
$userHasBackground = is_file(build_path(MSZ_STORAGE, 'backgrounds/original', $avatarFileName));
|
||||||
|
|
||||||
tpl_vars([
|
tpl_vars([
|
||||||
'avatar' => $avatarProps,
|
'avatar' => $avatarProps,
|
||||||
|
|
|
@ -23,15 +23,6 @@ final class Application
|
||||||
self::$instance = $this;
|
self::$instance = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a data storage path.
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getStoragePath(): string
|
|
||||||
{
|
|
||||||
return create_directory(config_get_default(MSZ_ROOT . '/store', 'Storage', 'path'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function startGeoIP(): void
|
public function startGeoIP(): void
|
||||||
{
|
{
|
||||||
if (!empty($this->geoipInstance)) {
|
if (!empty($this->geoipInstance)) {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?php
|
<?php
|
||||||
use Misuzu\Application;
|
|
||||||
use Misuzu\Database;
|
use Misuzu\Database;
|
||||||
|
|
||||||
define('MSZ_PERM_USER_EDIT_PROFILE', 1);
|
define('MSZ_PERM_USER_EDIT_PROFILE', 1);
|
||||||
|
@ -136,11 +135,10 @@ define('MSZ_USER_AVATAR_FORMAT', '%d.msz');
|
||||||
function user_avatar_delete(int $userId): void
|
function user_avatar_delete(int $userId): void
|
||||||
{
|
{
|
||||||
$avatarFileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
|
$avatarFileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
|
||||||
$storePath = Application::getInstance()->getStoragePath();
|
|
||||||
|
|
||||||
$deleteThis = [
|
$deleteThis = [
|
||||||
build_path($storePath, 'avatars/original', $avatarFileName),
|
build_path(MSZ_STORAGE, 'avatars/original', $avatarFileName),
|
||||||
build_path($storePath, 'avatars/200x200', $avatarFileName),
|
build_path(MSZ_STORAGE, 'avatars/200x200', $avatarFileName),
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($deleteThis as $deleteAvatar) {
|
foreach ($deleteThis as $deleteAvatar) {
|
||||||
|
@ -217,7 +215,7 @@ function user_avatar_set_from_path(int $userId, string $path, array $options = [
|
||||||
|
|
||||||
$fileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
|
$fileName = sprintf(MSZ_USER_AVATAR_FORMAT, $userId);
|
||||||
$avatarPath = build_path(
|
$avatarPath = build_path(
|
||||||
create_directory(build_path(Application::getInstance()->getStoragePath(), 'avatars/original')),
|
create_directory(build_path(MSZ_STORAGE, 'avatars/original')),
|
||||||
$fileName
|
$fileName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -320,8 +318,7 @@ function user_background_set_settings(int $userId, int $settings): void
|
||||||
function user_background_delete(int $userId): void
|
function user_background_delete(int $userId): void
|
||||||
{
|
{
|
||||||
$backgroundFileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
$backgroundFileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
||||||
$storePath = Application::getInstance()->getStoragePath();
|
safe_delete(build_path(MSZ_STORAGE, 'backgrounds/original', $backgroundFileName));
|
||||||
safe_delete(build_path($storePath, 'backgrounds/original', $backgroundFileName));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
define('MSZ_USER_BACKGROUND_TYPE_PNG', IMAGETYPE_PNG);
|
define('MSZ_USER_BACKGROUND_TYPE_PNG', IMAGETYPE_PNG);
|
||||||
|
@ -391,7 +388,7 @@ function user_background_set_from_path(int $userId, string $path, array $options
|
||||||
|
|
||||||
$fileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
$fileName = sprintf(MSZ_USER_BACKGROUND_FORMAT, $userId);
|
||||||
$backgroundPath = build_path(
|
$backgroundPath = build_path(
|
||||||
create_directory(build_path(Application::getInstance()->getStoragePath(), 'backgrounds/original')),
|
create_directory(build_path(MSZ_STORAGE, 'backgrounds/original')),
|
||||||
$fileName
|
$fileName
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue