Skip to content

Commit

Permalink
Merge pull request #3006 from NamelessMC/bugfix/fix-profile-images
Browse files Browse the repository at this point in the history
Fix several profile images issues
  • Loading branch information
samerton authored Aug 11, 2022
2 parents 5d56470 + fbbc44b commit 26525ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 10 additions & 2 deletions core/includes/image_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* Made by Samerton
* https://github.com/NamelessMC/Nameless/
* NamelessMC version 2.0.0-pr9
* NamelessMC version 2.0.2
*
* License: MIT
*
Expand Down Expand Up @@ -83,6 +83,14 @@
Redirect::to(URL::build('/profile/' . urlencode($user->data()->username)));
}

if (
!is_dir(join(DIRECTORY_SEPARATOR, [ROOT_PATH, 'uploads', 'profile_images', $user->data()->id]))
&& !mkdir(join(DIRECTORY_SEPARATOR, [ROOT_PATH, 'uploads', 'profile_images', $user->data()->id]))
) {
Session::flash('profile_banner_error', $language->get('admin', 'x_directory_not_writable', ['directory' => 'uploads/profile_images']));
Redirect::to(URL::build('/profile/' . urlencode($user->data()->username)));
}

$folder = implode(DIRECTORY_SEPARATOR, ['profile_images', $user->data()->id]);
break;

Expand All @@ -103,7 +111,7 @@
try {
if (!$image->upload()) {
if (Input::get('type') === 'profile_banner') {
Session::flash('profile_banner_error', $image->getError());
Session::flash('profile_banner_error', $image->getError() ?: $language->get('api', 'unknown_error'));
Redirect::to(URL::build('/profile/' . urlencode($user->data()->username)));
}

Expand Down
10 changes: 4 additions & 6 deletions modules/Core/pages/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@
]
);

// Requery to update banner
$user = new User();
$profile_user = new User($profile, 'username');
$query = $profile_user->data();
// Refresh to update banner
Redirect::to($profile_user->getProfileURL());
}
}
}
Expand Down Expand Up @@ -402,7 +400,7 @@
case 'reset_banner':
if (Token::check($_POST['token'])) {
if ($user->hasPermission('modcp.profile_banner_reset')) {
DB::getInstance()->update('users', $query->id, [
$profile_user->update([
'banner' => null
]);
}
Expand Down Expand Up @@ -514,7 +512,7 @@
$banners[] = [
'src' => ((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/') . 'uploads/profile_images/' . Output::getClean($user->data()->id) . '/' . Output::getClean($image),
'name' => Output::getClean($user->data()->id) . '/' . Output::getClean($image),
'active' => $user->data()->banner == $image
'active' => $user->data()->banner == $user->data()->id . '/' . $image
];
}
}
Expand Down

0 comments on commit 26525ec

Please sign in to comment.