Updated profile.php in accordance with user assets no longer being served through it.
This commit is contained in:
parent
5fbad79c23
commit
17fa18665f
5 changed files with 349 additions and 328 deletions
|
@ -198,6 +198,10 @@
|
|||
text-align: left;
|
||||
}
|
||||
|
||||
&--link {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@media (max-width: @site-mobile-width) {
|
||||
&--date &__value {
|
||||
text-align: right;
|
||||
|
|
|
@ -1,19 +1,280 @@
|
|||
<?php
|
||||
$mode = (string)($_GET['m'] ?? null);
|
||||
$misuzuBypassLockdown = $mode === 'avatar';
|
||||
|
||||
require_once '../misuzu.php';
|
||||
|
||||
switch ($mode) {
|
||||
case 'following':
|
||||
$userId = (int)($_GET['u'] ?? 0);
|
||||
$userId = user_find_for_profile($_GET['u'] ?? 0);
|
||||
|
||||
if (!user_exists($userId)) {
|
||||
http_response_code(404);
|
||||
echo tpl_render('user.notfound');
|
||||
break;
|
||||
if ($userId < 1) {
|
||||
http_response_code(404);
|
||||
echo tpl_render('user.notfound');
|
||||
return;
|
||||
}
|
||||
|
||||
$mode = (string)($_GET['m'] ?? null);
|
||||
$isEditing = !empty($_GET['edit']) || !empty($_POST);
|
||||
$notices = [];
|
||||
|
||||
$currentUserId = user_session_current('user_id', 0);
|
||||
$viewingAsGuest = $currentUserId === 0;
|
||||
$viewingOwnProfile = $currentUserId === $userId;
|
||||
|
||||
$isBanned = user_warning_check_restriction($userId);
|
||||
$userPerms = perms_get_user(MSZ_PERMS_USER, $currentUserId);
|
||||
$canManageWarnings = perms_check($userPerms, MSZ_PERM_USER_MANAGE_WARNINGS);
|
||||
$canEdit = !$isBanned
|
||||
&& user_session_active()
|
||||
&& (
|
||||
$viewingOwnProfile
|
||||
|| user_check_super($userId)
|
||||
|| (
|
||||
perms_check($userPerms, MSZ_PERM_USER_MANAGE_USERS)
|
||||
&& user_check_authority($currentUserId, $userId)
|
||||
)
|
||||
);
|
||||
|
||||
if ($isEditing) {
|
||||
if (!$canEdit) {
|
||||
echo render_error(403);
|
||||
return;
|
||||
}
|
||||
|
||||
$perms = [
|
||||
'edit_profile' => perms_check($userPerms, MSZ_PERM_USER_EDIT_PROFILE),
|
||||
'edit_avatar' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_AVATAR),
|
||||
'edit_background' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_BACKGROUND),
|
||||
'edit_about' => perms_check($userPerms, MSZ_PERM_USER_EDIT_ABOUT),
|
||||
'edit_birthdate' => perms_check($userPerms, MSZ_PERM_USER_EDIT_BIRTHDATE),
|
||||
'edit_signature' => perms_check($userPerms, MSZ_PERM_USER_EDIT_SIGNATURE),
|
||||
];
|
||||
|
||||
tpl_vars([
|
||||
'perms' => $perms,
|
||||
'guidelines' => [
|
||||
'avatar' => $avatarProps = user_avatar_default_options(),
|
||||
'background' => $backgroundProps = user_background_default_options(),
|
||||
],
|
||||
'background_attachments' => MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES,
|
||||
]);
|
||||
|
||||
if (!csrf_verify('profile', $_POST['csrf'] ?? '')) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['csrf'];
|
||||
} else {
|
||||
if (!empty($_POST['profile']) && is_array($_POST['profile'])) {
|
||||
if (!$perms['edit_profile']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['profile']['not-allowed'];
|
||||
} else {
|
||||
$setUserFieldErrors = user_profile_fields_set($userId, $_POST['profile']);
|
||||
|
||||
if (count($setUserFieldErrors) > 0) {
|
||||
foreach ($setUserFieldErrors as $name => $error) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['profile'][$error] ?? MSZ_TMP_USER_ERROR_STRINGS['profile']['_'],
|
||||
$name,
|
||||
user_profile_field_get_display_name($name)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['about']) && is_array($_POST['about'])) {
|
||||
if (!$perms['edit_about']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['about']['not-allowed'];
|
||||
} else {
|
||||
$setAboutError = user_set_about_page(
|
||||
$userId,
|
||||
$_POST['about']['text'] ?? '',
|
||||
(int)($_POST['about']['parser'] ?? MSZ_PARSER_PLAIN)
|
||||
);
|
||||
|
||||
if ($setAboutError !== MSZ_E_USER_ABOUT_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['about'][$setAboutError] ?? MSZ_TMP_USER_ERROR_STRINGS['about']['_'],
|
||||
MSZ_USER_ABOUT_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['signature']) && is_array($_POST['signature'])) {
|
||||
if (!$perms['edit_signature']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['signature']['not-allowed'];
|
||||
} else {
|
||||
$setSignatureError = user_set_signature(
|
||||
$userId,
|
||||
$_POST['signature']['text'] ?? '',
|
||||
(int)($_POST['signature']['parser'] ?? MSZ_PARSER_PLAIN)
|
||||
);
|
||||
|
||||
if ($setSignatureError !== MSZ_E_USER_SIGNATURE_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['signature'][$setSignatureError] ?? MSZ_TMP_USER_ERROR_STRINGS['signature']['_'],
|
||||
MSZ_USER_SIGNATURE_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['birthdate']) && is_array($_POST['birthdate'])) {
|
||||
if (!$perms['edit_birthdate']) {
|
||||
$notices[] = "You aren't allow to change your birthdate.";
|
||||
} else {
|
||||
$setBirthdate = user_set_birthdate(
|
||||
$userId,
|
||||
(int)($_POST['birthdate']['day'] ?? 0),
|
||||
(int)($_POST['birthdate']['month'] ?? 0),
|
||||
(int)($_POST['birthdate']['year'] ?? 0)
|
||||
);
|
||||
|
||||
switch ($setBirthdate) {
|
||||
case MSZ_E_USER_BIRTHDATE_USER:
|
||||
$notices[] = 'Invalid user specified while setting birthdate?';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_DATE:
|
||||
$notices[] = 'The given birthdate is invalid.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_FAIL:
|
||||
$notices[] = 'Failed to set birthdate.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_YEAR:
|
||||
$notices[] = 'The given birth year is invalid.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_OK:
|
||||
break;
|
||||
default:
|
||||
$notices[] = 'Something unexpected happened while setting your birthdate.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_FILES['avatar'])) {
|
||||
if (!empty($_POST['avatar']['delete'])) {
|
||||
user_avatar_delete($userId);
|
||||
} else {
|
||||
if (!$perms['edit_avatar']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['avatar']['not-allowed'];
|
||||
} elseif (!empty($_FILES['avatar'])
|
||||
&& is_array($_FILES['avatar'])
|
||||
&& !empty($_FILES['avatar']['name']['file'])) {
|
||||
if ($_FILES['avatar']['error']['file'] !== UPLOAD_ERR_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload'][$_FILES['avatar']['error']['file']]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload']['_'],
|
||||
$_FILES['avatar']['error']['file'],
|
||||
byte_symbol($avatarProps['max_size'], true),
|
||||
$avatarProps['max_width'],
|
||||
$avatarProps['max_height']
|
||||
);
|
||||
} else {
|
||||
$setAvatar = user_avatar_set_from_path(
|
||||
$userId,
|
||||
$_FILES['avatar']['tmp_name']['file'],
|
||||
$avatarProps
|
||||
);
|
||||
|
||||
if ($setAvatar !== MSZ_USER_AVATAR_NO_ERRORS) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['avatar']['set'][$setAvatar]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['avatar']['set']['_'],
|
||||
$setAvatar,
|
||||
byte_symbol($avatarProps['max_size'], true),
|
||||
$avatarProps['max_width'],
|
||||
$avatarProps['max_height']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_FILES['background'])) {
|
||||
if ((int)($_POST['background']['attach'] ?? -1) === 0) {
|
||||
user_background_delete($userId);
|
||||
user_background_set_settings($userId, MSZ_USER_BACKGROUND_ATTACHMENT_NONE);
|
||||
} else {
|
||||
if (!$perms['edit_background']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['background']['not-allowed'];
|
||||
} elseif (!empty($_FILES['background'])
|
||||
&& is_array($_FILES['background'])) {
|
||||
if (!empty($_FILES['background']['name']['file'])) {
|
||||
if ($_FILES['background']['error']['file'] !== UPLOAD_ERR_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['background']['upload'][$_FILES['background']['error']['file']]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['background']['upload']['_'],
|
||||
$_FILES['background']['error']['file'],
|
||||
byte_symbol($backgroundProps['max_size'], true),
|
||||
$backgroundProps['max_width'],
|
||||
$backgroundProps['max_height']
|
||||
);
|
||||
} else {
|
||||
$setBackground = user_background_set_from_path(
|
||||
$userId,
|
||||
$_FILES['background']['tmp_name']['file'],
|
||||
$backgroundProps
|
||||
);
|
||||
|
||||
if ($setBackground !== MSZ_USER_BACKGROUND_NO_ERRORS) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['background']['set'][$setBackground]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['background']['set']['_'],
|
||||
$setBackground,
|
||||
byte_symbol($backgroundProps['max_size'], true),
|
||||
$backgroundProps['max_width'],
|
||||
$backgroundProps['max_height']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$backgroundSettings = in_array($_POST['background']['attach'] ?? '', MSZ_USER_BACKGROUND_ATTACHMENTS)
|
||||
? (int)($_POST['background']['attach'])
|
||||
: MSZ_USER_BACKGROUND_ATTACHMENTS[0];
|
||||
|
||||
if (!empty($_POST['background']['attr']['blend'])) {
|
||||
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND;
|
||||
}
|
||||
|
||||
if (!empty($_POST['background']['attr']['slide'])) {
|
||||
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE;
|
||||
}
|
||||
|
||||
user_background_set_settings($userId, $backgroundSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unset $isEditing and hope the user doesn't refresh their profile!
|
||||
if (empty($notices)) {
|
||||
$isEditing = false;
|
||||
}
|
||||
}
|
||||
|
||||
$profile = user_profile_get($userId);
|
||||
$relationInfo = user_session_active()
|
||||
? user_relation_info($currentUserId, $profile['user_id'])
|
||||
: [];
|
||||
|
||||
$backgroundPath = sprintf('%s/backgrounds/original/%d.msz', MSZ_STORAGE, $profile['user_id']);
|
||||
|
||||
if (is_file($backgroundPath)) {
|
||||
$backgroundInfo = getimagesize($backgroundPath);
|
||||
|
||||
if ($backgroundInfo) {
|
||||
tpl_var('site_background', [
|
||||
'url' => url('user-background', ['user' => $profile['user_id']]),
|
||||
'width' => $backgroundInfo[0],
|
||||
'height' => $backgroundInfo[1],
|
||||
'settings' => $profile['user_background_settings'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
default:
|
||||
echo render_error(404);
|
||||
return;
|
||||
|
||||
case 'following':
|
||||
$followingIds = user_relation_users_from($userId, MSZ_USER_RELATION_FOLLOW);
|
||||
|
||||
foreach ($followingIds as $user) {
|
||||
|
@ -22,14 +283,6 @@ switch ($mode) {
|
|||
break;
|
||||
|
||||
case 'followers':
|
||||
$userId = (int)($_GET['u'] ?? 0);
|
||||
|
||||
if (!user_exists($userId)) {
|
||||
http_response_code(404);
|
||||
echo tpl_render('user.notfound');
|
||||
break;
|
||||
}
|
||||
|
||||
$followerIds = user_relation_users_to($userId, MSZ_USER_RELATION_FOLLOW);
|
||||
|
||||
foreach ($followerIds as $user) {
|
||||
|
@ -37,30 +290,8 @@ switch ($mode) {
|
|||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$userId = user_find_for_profile($_GET['u'] ?? 0);
|
||||
|
||||
if ($userId < 1) {
|
||||
http_response_code(404);
|
||||
echo tpl_render('user.notfound');
|
||||
break;
|
||||
}
|
||||
|
||||
$viewingAsGuest = user_session_current('user_id', 0) === 0;
|
||||
$viewingOwnProfile = user_session_current('user_id', 0) === $userId;
|
||||
$isRestricted = user_warning_check_restriction($userId);
|
||||
$userPerms = perms_get_user(MSZ_PERMS_USER, user_session_current('user_id', 0));
|
||||
$canManageWarnings = perms_check($userPerms, MSZ_PERM_USER_MANAGE_WARNINGS);
|
||||
$canEdit = !$isRestricted && user_session_active() && (
|
||||
$viewingOwnProfile || user_check_super($userId) || (perms_check($userPerms, MSZ_PERM_USER_MANAGE_USERS) && user_check_authority(user_session_current('user_id', 0), $userId))
|
||||
);
|
||||
$isEditing = $mode === 'edit';
|
||||
|
||||
if (!$canEdit && $isEditing) {
|
||||
echo render_error(403);
|
||||
break;
|
||||
}
|
||||
|
||||
case '':
|
||||
$template = 'user.profile';
|
||||
$warnings = $viewingAsGuest
|
||||
? []
|
||||
: user_warning_fetch(
|
||||
|
@ -74,251 +305,24 @@ switch ($mode) {
|
|||
: MSZ_WARN_TYPES_VISIBLE_TO_PUBLIC
|
||||
)
|
||||
);
|
||||
$notices = [];
|
||||
|
||||
if ($isEditing) {
|
||||
$perms = [
|
||||
'edit_profile' => perms_check($userPerms, MSZ_PERM_USER_EDIT_PROFILE),
|
||||
'edit_avatar' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_AVATAR),
|
||||
'edit_background' => perms_check($userPerms, MSZ_PERM_USER_CHANGE_BACKGROUND),
|
||||
'edit_about' => perms_check($userPerms, MSZ_PERM_USER_EDIT_ABOUT),
|
||||
'edit_birthdate' => perms_check($userPerms, MSZ_PERM_USER_EDIT_BIRTHDATE),
|
||||
'edit_signature' => perms_check($userPerms, MSZ_PERM_USER_EDIT_SIGNATURE),
|
||||
];
|
||||
|
||||
tpl_vars([
|
||||
'perms' => $perms,
|
||||
'guidelines' => [
|
||||
'avatar' => $avatarProps = user_avatar_default_options(),
|
||||
'background' => $backgroundProps = user_background_default_options(),
|
||||
],
|
||||
'background_attachments' => MSZ_USER_BACKGROUND_ATTACHMENTS_NAMES,
|
||||
]);
|
||||
|
||||
if (!empty($_POST)) {
|
||||
if (!csrf_verify('profile', $_POST['csrf'] ?? '')) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['csrf'];
|
||||
} else {
|
||||
if (!empty($_POST['profile']) && is_array($_POST['profile'])) {
|
||||
if (!$perms['edit_profile']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['profile']['not-allowed'];
|
||||
} else {
|
||||
$setUserFieldErrors = user_profile_fields_set($userId, $_POST['profile']);
|
||||
|
||||
if (count($setUserFieldErrors) > 0) {
|
||||
foreach ($setUserFieldErrors as $name => $error) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['profile'][$error] ?? MSZ_TMP_USER_ERROR_STRINGS['profile']['_'],
|
||||
$name,
|
||||
user_profile_field_get_display_name($name)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['about']) && is_array($_POST['about'])) {
|
||||
if (!$perms['edit_about']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['about']['not-allowed'];
|
||||
} else {
|
||||
$setAboutError = user_set_about_page(
|
||||
$userId,
|
||||
$_POST['about']['text'] ?? '',
|
||||
(int)($_POST['about']['parser'] ?? MSZ_PARSER_PLAIN)
|
||||
);
|
||||
|
||||
if ($setAboutError !== MSZ_E_USER_ABOUT_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['about'][$setAboutError] ?? MSZ_TMP_USER_ERROR_STRINGS['about']['_'],
|
||||
MSZ_USER_ABOUT_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['signature']) && is_array($_POST['signature'])) {
|
||||
if (!$perms['edit_signature']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['signature']['not-allowed'];
|
||||
} else {
|
||||
$setSignatureError = user_set_signature(
|
||||
$userId,
|
||||
$_POST['signature']['text'] ?? '',
|
||||
(int)($_POST['signature']['parser'] ?? MSZ_PARSER_PLAIN)
|
||||
);
|
||||
|
||||
if ($setSignatureError !== MSZ_E_USER_SIGNATURE_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['signature'][$setSignatureError] ?? MSZ_TMP_USER_ERROR_STRINGS['signature']['_'],
|
||||
MSZ_USER_SIGNATURE_MAX_LENGTH
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_POST['birthdate']) && is_array($_POST['birthdate'])) {
|
||||
if (!$perms['edit_birthdate']) {
|
||||
$notices[] = "You aren't allow to change your birthdate.";
|
||||
} else {
|
||||
$setBirthdate = user_set_birthdate(
|
||||
$userId,
|
||||
(int)($_POST['birthdate']['day'] ?? 0),
|
||||
(int)($_POST['birthdate']['month'] ?? 0),
|
||||
(int)($_POST['birthdate']['year'] ?? 0)
|
||||
);
|
||||
|
||||
switch ($setBirthdate) {
|
||||
case MSZ_E_USER_BIRTHDATE_USER:
|
||||
$notices[] = 'Invalid user specified while setting birthdate?';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_DATE:
|
||||
$notices[] = 'The given birthdate is invalid.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_FAIL:
|
||||
$notices[] = 'Failed to set birthdate.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_YEAR:
|
||||
$notices[] = 'The given birth year is invalid.';
|
||||
break;
|
||||
case MSZ_E_USER_BIRTHDATE_OK:
|
||||
break;
|
||||
default:
|
||||
$notices[] = 'Something unexpected happened while setting your birthdate.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_FILES['avatar'])) {
|
||||
if (!empty($_POST['avatar']['delete'])) {
|
||||
user_avatar_delete($userId);
|
||||
} else {
|
||||
if (!$perms['edit_avatar']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['avatar']['not-allowed'];
|
||||
} elseif (!empty($_FILES['avatar'])
|
||||
&& is_array($_FILES['avatar'])
|
||||
&& !empty($_FILES['avatar']['name']['file'])) {
|
||||
if ($_FILES['avatar']['error']['file'] !== UPLOAD_ERR_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload'][$_FILES['avatar']['error']['file']]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['avatar']['upload']['_'],
|
||||
$_FILES['avatar']['error']['file'],
|
||||
byte_symbol($avatarProps['max_size'], true),
|
||||
$avatarProps['max_width'],
|
||||
$avatarProps['max_height']
|
||||
);
|
||||
} else {
|
||||
$setAvatar = user_avatar_set_from_path(
|
||||
$userId,
|
||||
$_FILES['avatar']['tmp_name']['file'],
|
||||
$avatarProps
|
||||
);
|
||||
|
||||
if ($setAvatar !== MSZ_USER_AVATAR_NO_ERRORS) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['avatar']['set'][$setAvatar]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['avatar']['set']['_'],
|
||||
$setAvatar,
|
||||
byte_symbol($avatarProps['max_size'], true),
|
||||
$avatarProps['max_width'],
|
||||
$avatarProps['max_height']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($_FILES['background'])) {
|
||||
if ((int)($_POST['background']['attach'] ?? -1) === 0) {
|
||||
user_background_delete($userId);
|
||||
user_background_set_settings($userId, MSZ_USER_BACKGROUND_ATTACHMENT_NONE);
|
||||
} else {
|
||||
if (!$perms['edit_background']) {
|
||||
$notices[] = MSZ_TMP_USER_ERROR_STRINGS['background']['not-allowed'];
|
||||
} elseif (!empty($_FILES['background'])
|
||||
&& is_array($_FILES['background'])) {
|
||||
if (!empty($_FILES['background']['name']['file'])) {
|
||||
if ($_FILES['background']['error']['file'] !== UPLOAD_ERR_OK) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['background']['upload'][$_FILES['background']['error']['file']]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['background']['upload']['_'],
|
||||
$_FILES['background']['error']['file'],
|
||||
byte_symbol($backgroundProps['max_size'], true),
|
||||
$backgroundProps['max_width'],
|
||||
$backgroundProps['max_height']
|
||||
);
|
||||
} else {
|
||||
$setBackground = user_background_set_from_path(
|
||||
$userId,
|
||||
$_FILES['background']['tmp_name']['file'],
|
||||
$backgroundProps
|
||||
);
|
||||
|
||||
if ($setBackground !== MSZ_USER_BACKGROUND_NO_ERRORS) {
|
||||
$notices[] = sprintf(
|
||||
MSZ_TMP_USER_ERROR_STRINGS['background']['set'][$setBackground]
|
||||
?? MSZ_TMP_USER_ERROR_STRINGS['background']['set']['_'],
|
||||
$setBackground,
|
||||
byte_symbol($backgroundProps['max_size'], true),
|
||||
$backgroundProps['max_width'],
|
||||
$backgroundProps['max_height']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$backgroundSettings = in_array($_POST['background']['attach'] ?? '', MSZ_USER_BACKGROUND_ATTACHMENTS)
|
||||
? (int)($_POST['background']['attach'])
|
||||
: MSZ_USER_BACKGROUND_ATTACHMENTS[0];
|
||||
|
||||
if (!empty($_POST['background']['attr']['blend'])) {
|
||||
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_BLEND;
|
||||
}
|
||||
|
||||
if (!empty($_POST['background']['attr']['slide'])) {
|
||||
$backgroundSettings |= MSZ_USER_BACKGROUND_ATTRIBUTE_SLIDE;
|
||||
}
|
||||
|
||||
user_background_set_settings($userId, $backgroundSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no notices, redirect to regular profile.
|
||||
if (empty($notices)) {
|
||||
header('Location: ' . url('user-profile', ['user' => $userId]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$profile = user_profile_get($userId);
|
||||
$backgroundPath = MSZ_STORAGE . "/backgrounds/original/{$profile['user_id']}.msz";
|
||||
|
||||
if (is_file($backgroundPath)) {
|
||||
$backgroundInfo = getimagesize($backgroundPath);
|
||||
|
||||
if ($backgroundInfo) {
|
||||
tpl_var('site_background', [
|
||||
'url' => url('user-background', ['user' => $userId]),
|
||||
'width' => $backgroundInfo[0],
|
||||
'height' => $backgroundInfo[1],
|
||||
'settings' => $profile['user_background_settings'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
echo tpl_render('user.profile', [
|
||||
'profile' => $profile,
|
||||
'profile_notices' => $notices,
|
||||
'can_edit' => $canEdit,
|
||||
'is_editing' => $isEditing,
|
||||
'warnings' => $warnings,
|
||||
'can_view_private_note' => $viewingOwnProfile,
|
||||
'can_manage_warnings' => $canManageWarnings,
|
||||
'is_restricted' => $isRestricted,
|
||||
tpl_vars([
|
||||
'profile_warnings' => $warnings,
|
||||
'prpfile_warnings_view_private' => $viewingOwnProfile,
|
||||
'profile_warnings_can_manage' => $canManageWarnings,
|
||||
'profile_fields' => user_session_active() ? user_profile_fields_display($profile, !$isEditing) : [],
|
||||
'friend_info' => user_session_active() ? user_relation_info(user_session_current('user_id', 0), $profile['user_id']) : [],
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($template)) {
|
||||
echo tpl_render($template, [
|
||||
'profile' => $profile,
|
||||
'profile_mode' => $mode,
|
||||
'profile_notices' => $notices,
|
||||
'profile_can_edit' => $canEdit,
|
||||
'profile_is_editing' => $isEditing,
|
||||
'profile_is_banned' => $isBanned,
|
||||
'profile_relation_info' => $relationInfo,
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -41,10 +41,13 @@ define('MSZ_URLS', [
|
|||
'forum-post-edit' => ['/forum/posting.php', ['p' => '<post>', 'm' => 'edit']],
|
||||
|
||||
'user-profile' => ['/profile.php', ['u' => '<user>']],
|
||||
'user-profile-edit' => ['/profile.php', ['u' => '<user>', 'm' => 'edit']],
|
||||
'user-profile-following' => ['/profile.php', ['u' => '<user>', 'm' => 'following']],
|
||||
'user-profile-followers' => ['/profile.php', ['u' => '<user>', 'm' => 'followers']],
|
||||
'user-profile-edit' => ['/profile.php', ['u' => '<user>', 'edit' => '1']],
|
||||
'user-account-standing' => ['/profile.php', ['u' => '<user>'], 'account-standing'],
|
||||
|
||||
'user-avatar' => ['/user-assets.php', ['u' => '<user>', 'm' => 'avatar']],
|
||||
'user-background' => ['/user-assets.php', ['u' => '<user>', 'm' => 'background']],
|
||||
'user-account-standing' => ['/profile.php', ['u' => '<user>'], 'account-standing'],
|
||||
|
||||
'user-relation-none' => ['/relations.php', ['u' => '<user>', 'm' => '[MSZ_USER_RELATION_NONE]', 'c' => '{user_relation}']],
|
||||
'user-relation-follow' => ['/relations.php', ['u' => '<user>', 'm' => '[MSZ_USER_RELATION_FOLLOW]', 'c' => '{user_relation}']],
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<div class="profile__header__details">
|
||||
<div class="profile__header__avatar">
|
||||
{% if is_editing and perms.edit_avatar %}
|
||||
{% if profile_is_editing and perms.edit_avatar %}
|
||||
<label class="avatar profile__header__avatar__image profile__header__avatar__image--edit"
|
||||
style="background-image:url('{{ image }}')"
|
||||
id="avatar-preview"
|
||||
|
@ -46,13 +46,13 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% if friend_info|length > 0 and (friend_info.subject_relation is not null or friend_info.user_relation is not null) %}
|
||||
<div class="profile__header__details__relation" title="Since {{ friend_info.relation_created|date('r') }}">
|
||||
{% if friend_info.subject_relation and friend_info.user_relation %}
|
||||
{% if profile_relation_info|length > 0 and (profile_relation_info.subject_relation is not null or profile_relation_info.user_relation is not null) %}
|
||||
<div class="profile__header__details__relation" title="Since {{ profile_relation_info.relation_created|date('r') }}">
|
||||
{% if profile_relation_info.subject_relation and profile_relation_info.user_relation %}
|
||||
Mutual Friends
|
||||
{% elseif friend_info.user_relation %}
|
||||
{% elseif profile_relation_info.user_relation %}
|
||||
You Follow
|
||||
{% elseif friend_info.subject_relation %}
|
||||
{% elseif profile_relation_info.subject_relation %}
|
||||
Follows You
|
||||
{% endif %}
|
||||
</div>
|
||||
|
@ -61,20 +61,24 @@
|
|||
|
||||
<div class="profile__header__options">
|
||||
<div class="profile__header__actions">
|
||||
{% if is_editing %}
|
||||
<button class="input__button input__button--save profile__header__action">Save</button>
|
||||
<a href="{{ url('user-profile', {'user': profile.user_id}) }}" class="input__button input__button--destroy profile__header__action">Discard</a>
|
||||
<a href="{{ url('settings-index') }}" class="input__button profile__header__action">Settings</a>
|
||||
{% elseif can_edit %}
|
||||
<a href="{{ url('user-profile-edit', {'user': profile.user_id}) }}" class="input__button profile__header__action">Edit Profile</a>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user is defined and current_user.user_id != profile.user_id and not is_editing %}
|
||||
{% if friend_info.user_relation == constant('MSZ_USER_RELATION_FOLLOW') %}
|
||||
<a href="{{ url('user-relation-none', {'user': profile.user_id}) }}" class="input__button input__button--destroy profile__header__action js-user-relation-action" data-relation-user="{{ profile.user_id }}" data-relation-type="{{ constant('MSZ_USER_RELATION_NONE') }}">Unfollow</a>
|
||||
{% else %}
|
||||
<a href="{{ url('user-relation-follow', {'user': profile.user_id}) }}" class="input__button profile__header__action js-user-relation-action" data-relation-user="{{ profile.user_id }}" data-relation-type="{{ constant('MSZ_USER_RELATION_FOLLOW') }}">Follow</a>
|
||||
{% if profile_mode is empty %}
|
||||
{% if profile_is_editing %}
|
||||
<button class="input__button input__button--save profile__header__action">Save</button>
|
||||
<a href="{{ url('user-profile', {'user': profile.user_id}) }}" class="input__button input__button--destroy profile__header__action">Discard</a>
|
||||
<a href="{{ url('settings-index') }}" class="input__button profile__header__action">Settings</a>
|
||||
{% elseif profile_can_edit %}
|
||||
<a href="{{ url('user-profile-edit', {'user': profile.user_id}) }}" class="input__button profile__header__action">Edit Profile</a>
|
||||
{% endif %}
|
||||
|
||||
{% if current_user is defined and current_user.user_id != profile.user_id and not profile_is_editing %}
|
||||
{% if profile_relation_info.user_relation == constant('MSZ_USER_RELATION_FOLLOW') %}
|
||||
<a href="{{ url('user-relation-none', {'user': profile.user_id}) }}" class="input__button input__button--destroy profile__header__action js-user-relation-action" data-relation-user="{{ profile.user_id }}" data-relation-type="{{ constant('MSZ_USER_RELATION_NONE') }}">Unfollow</a>
|
||||
{% else %}
|
||||
<a href="{{ url('user-relation-follow', {'user': profile.user_id}) }}" class="input__button profile__header__action js-user-relation-action" data-relation-user="{{ profile.user_id }}" data-relation-type="{{ constant('MSZ_USER_RELATION_FOLLOW') }}">Follow</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<a href="{{ url('user-profile', {'user': profile.user_id}) }}" class="input__button profile__header__action">Return</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
@ -83,8 +87,13 @@
|
|||
{% for stat in stats %}
|
||||
{% if stat.value|default(false) %}
|
||||
{% set is_date = stat.is_date|default(false) %}
|
||||
{% set is_url = stat.url is defined %}
|
||||
|
||||
<div class="profile__header__stat{% if is_date %} profile__header__stat--date" title="{{ stat.value|date('r') }}{% endif %}">
|
||||
{% if is_url %}
|
||||
<a class="profile__header__stat profile__header__stat--link" href="{{ stat.url }}">
|
||||
{% else %}
|
||||
<div class="profile__header__stat{% if is_date %} profile__header__stat--date" title="{{ stat.value|date('r') }}{% endif %}">
|
||||
{% endif %}
|
||||
<div class="profile__header__stat__name">
|
||||
{{ stat.title }}
|
||||
</div>
|
||||
|
@ -98,7 +107,7 @@
|
|||
{{ stat.value|number_format }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if is_url %}</a>{% else %}</div>{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -22,10 +22,12 @@
|
|||
{
|
||||
'title': 'Following',
|
||||
'value': profile.following_count,
|
||||
'url': url('user-profile-following', {'user': profile.user_id}),
|
||||
},
|
||||
{
|
||||
'title': 'Followers',
|
||||
'value': profile.followers_count,
|
||||
'url': url('user-profile-followers', {'user': profile.user_id}),
|
||||
},
|
||||
{
|
||||
'title': 'Topics',
|
||||
|
@ -46,9 +48,8 @@
|
|||
] %}
|
||||
|
||||
{% block content %}
|
||||
{% if is_editing %}
|
||||
<form class="profile" method="post" action="" enctype="multipart/form-data">
|
||||
{{ input_hidden('user', profile.user_id) }}
|
||||
{% if profile_is_editing %}
|
||||
<form class="profile" method="post" action="{{ url('user-profile', {'user': profile.user_id}) }}" enctype="multipart/form-data">
|
||||
{{ input_csrf('profile') }}
|
||||
|
||||
{% if perms.edit_avatar %}
|
||||
|
@ -73,7 +74,7 @@
|
|||
|
||||
{% include 'user/_layout/header.twig' %}
|
||||
|
||||
{% if is_editing %}
|
||||
{% if profile_is_editing %}
|
||||
<div class="container profile__container profile__guidelines">
|
||||
<ul class="profile__guidelines__section">
|
||||
<li class="profile__guidelines__line profile__guidelines__line--header">General</li>
|
||||
|
@ -113,9 +114,9 @@
|
|||
{% endif %}
|
||||
|
||||
<div class="profile__content">
|
||||
{% set show_profile_fields = is_editing ? perms.edit_profile : profile_fields|default([])|length > 0 %}
|
||||
{% set show_background_settings = is_editing and perms.edit_background %}
|
||||
{% set show_birthdate = is_editing and perms.edit_birthdate %}
|
||||
{% set show_profile_fields = profile_is_editing ? perms.edit_profile : profile_fields|default([])|length > 0 %}
|
||||
{% set show_background_settings = profile_is_editing and perms.edit_background %}
|
||||
{% set show_birthdate = profile_is_editing and perms.edit_birthdate %}
|
||||
{% set show_sidebar = current_user is not defined or show_profile_fields or show_background_settings %}
|
||||
|
||||
{% if show_sidebar %}
|
||||
|
@ -154,7 +155,7 @@
|
|||
{{ data.name }}
|
||||
</div>
|
||||
|
||||
{% if is_editing %}
|
||||
{% if profile_is_editing %}
|
||||
{{ input_text('profile[' ~ name ~ ']', 'profile__accounts__input', profile['user_' ~ name], data.type|default('text')) }}
|
||||
{% else %}
|
||||
<div class="profile__accounts__value"
|
||||
|
@ -210,48 +211,48 @@
|
|||
{% endif %}
|
||||
|
||||
<div class="profile__content__main">
|
||||
{% if (is_editing and perms.edit_about) or profile.user_about_content|length > 0 %}
|
||||
{% if (profile_is_editing and perms.edit_about) or profile.user_about_content|length > 0 %}
|
||||
<div class="container profile__container profile__about" id="about">
|
||||
{{ container_title('About ' ~ profile.username) }}
|
||||
|
||||
{% if is_editing %}
|
||||
{% if profile_is_editing %}
|
||||
<div class="profile__signature__editor">
|
||||
{{ input_select('about[parser]', constant('MSZ_PARSERS_NAMES'), profile.user_about_parser, '', '', false, 'profile__about__select') }}
|
||||
<textarea name="about[text]" class="input__textarea profile__about__text" id="about-textarea">{{ profile.user_about_content|escape }}</textarea>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="profile__about__content{% if is_editing %} profile__about__content--edit{% elseif profile.user_about_parser == constant('MSZ_PARSER_MARKDOWN') %} markdown{% endif %}">
|
||||
<div class="profile__about__content{% if profile_is_editing %} profile__about__content--edit{% elseif profile.user_about_parser == constant('MSZ_PARSER_MARKDOWN') %} markdown{% endif %}">
|
||||
{{ profile.user_about_content|escape|parse_text(profile.user_about_parser)|raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if (is_editing and perms.edit_signature) or profile.user_signature_content|length > 0 %}
|
||||
{% if (profile_is_editing and perms.edit_signature) or profile.user_signature_content|length > 0 %}
|
||||
<div class="container profile__container profile__signature" id="signature">
|
||||
{{ container_title('Signature') }}
|
||||
|
||||
{% if is_editing %}
|
||||
{% if profile_is_editing %}
|
||||
<div class="profile__signature__editor">
|
||||
{{ input_select('signature[parser]', constant('MSZ_PARSERS_NAMES'), profile.user_signature_parser, '', '', false, 'profile__signature__select') }}
|
||||
<textarea name="signature[text]" class="input__textarea profile__signature__text" id="signature-textarea">{{ profile.user_signature_content|escape }}</textarea>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="profile__signature__content{% if is_editing %} profile__signature__content--edit{% elseif profile.user_signature_parser == constant('MSZ_PARSER_MARKDOWN') %} markdown{% endif %}">
|
||||
<div class="profile__signature__content{% if profile_is_editing %} profile__signature__content--edit{% elseif profile.user_signature_parser == constant('MSZ_PARSER_MARKDOWN') %} markdown{% endif %}">
|
||||
{{ profile.user_signature_content|escape|parse_text(profile.user_signature_parser)|raw }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if warnings|length > 0 %}
|
||||
{% if profile_warnings|length > 0 %}
|
||||
<div class="container profile__container profile__warning__container" id="account-standing">
|
||||
{{ container_title('Account Standing', false, can_manage_warnings ? '/manage/users.php?v=warnings&u=' ~ profile.user_id : '') }}
|
||||
{{ container_title('Account Standing', false, profile_warnings_can_manage ? '/manage/users.php?v=warnings&u=' ~ profile.user_id : '') }}
|
||||
|
||||
<div class="profile__warning">
|
||||
<div class="profile__warning__background"></div>
|
||||
|
||||
{% if can_manage_warnings %}
|
||||
{% if profile_warnings_can_manage %}
|
||||
<div class="profile__warning__tools">
|
||||
<div class="profile__warning__user">
|
||||
<div class="profile__warning__user__ip">
|
||||
|
@ -289,14 +290,14 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{% for warning in warnings %}
|
||||
{{ user_profile_warning(warning, can_view_private_note, can_manage_warnings, can_manage_warnings ? csrf_token('warning-delete[%d]'|format(warning.warning_id)) : '') }}
|
||||
{% for warning in profile_warnings %}
|
||||
{{ user_profile_warning(warning, prpfile_warnings_view_private, profile_warnings_can_manage, profile_warnings_can_manage ? csrf_token('warning-delete[%d]'|format(warning.warning_id)) : '') }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if is_editing %}
|
||||
{% if profile_is_editing %}
|
||||
</form>
|
||||
<script>
|
||||
let profilePreviousBackground = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue