1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
<?php
use mystic\forum\orm\UserPermissions;
use mystic\forum\utils\RequestUtils;
use mystic\forum\utils\StringUtils;
/** @var mystic\forum\orm\User $user */
/** @var bool $lastNameChangeTooRecent */
$canEdit = ($user->id === $GLOBALS["currentUser"]?->id && $user->hasPermission(UserPermissions::EDIT_OWN_USER))
|| $GLOBALS["currentUser"]?->hasPermission(UserPermissions::EDIT_OTHER_USER);
$isOwnProfile = $user->id === $GLOBALS["currentUser"]?->id;
$sUserPossessive = "";
if ($isOwnProfile)
$sUserPossessive = "Your posts";
else
$sUserPossessive = "%display_name%'s posts";
$dateJoined = DateTime::createFromImmutable($user->created);
$dateJoined->setTime(0, 0, 0, 0);
$emailPending = $isOwnProfile && $user->pendingEmail !== null;
?>
<div class="clearfix page-header margin-top-0">
<img class="pull-left margin-right" src="?_action=profilepicture&user=<?= htmlentities(urlencode($user->id)) ?>" alt="<?= __("Profile picture") ?>" width="64" height="64">
<span class="h1"><?= htmlentities($user->displayName) ?></span>
<?php if ($isOwnProfile): ?>
<span class="label label-primary"><?= __("You") ?></span>
<?php endif; ?><br>
@<?= htmlentities($user->name) ?> • <span class="text-muted"><?= __("Member since %join_date%", [
"join_date" => '<span class="_date">' . htmlentities($dateJoined->format("c")) . '</span>',
]) ?></span>
</div>
<?php if ($canEdit): ?>
<div class="row">
<div class="col-md-9">
<?php endif; ?>
<h3><?= __($sUserPossessive, [
"display_name" => $user->displayName,
]) ?></h3>
<?php if (count($posts) > 0): ?>
<div class="post-container">
<div class="post-container-posts">
<div class="list-group margin-top">
<?php foreach ($posts as $post):
if ($post->deleted) continue;
$hasAttachments = count($attachments[$post->id]) > 0;
?>
<a href="?_action=viewtopic&topic=<?= htmlentities(urlencode($post->topicId)) ?>#post-<?= htmlentities(urlencode($post->id)) ?>" class="list-group-item">
<?php if ($hasAttachments): ?>
<span class="badge"><span class="glyphicon glyphicon-paperclip"></span></span>
<?php endif; ?>
<?= htmlentities(StringUtils::truncate(strip_tags(renderPost($post->content)), 100)) ?><br>
<span class="text-muted"><?= __("posted on %post_date% in %topic%", [
"post_date" => '<span class="_time">' . htmlentities($post->postDate->format("c")) . '</span>',
"topic" => '<em>' .
($topics[$post->topicId]?->isLocked ? '<span class="glyphicon glyphicon-lock text-muted" aria-hidden="true"></span> ' : '') .
htmlentities($topics[$post->topicId]?->title ?? "unknown") . '</em>',
]) ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
<div class="post-container-controls">
<button class="btn btn-default"><?= __("Show all posts") ?></button>
</div>
</div>
<?php else: ?>
<div class="well icon-well text-info margin-top margin-bottom">
<span class="glyphicon glyphicon-info-sign text-info" aria-hidden="true"></span>
<em><?= __("This user has not posted anything yet") ?></em>
</div>
<?php endif; ?>
<?php if ($canEdit): ?>
</div>
<div class="col-md-3">
<h3><?= __("Edit profile") ?></h3>
<?php
if (($_formError = RequestUtils::getAndClearFormError("update_profile")) !== null) {
_view("alert_error", ["message" => $_formError]);
}
?>
<form action="<?= htmlentities($_SERVER["REQUEST_URI"]) ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="form_id" value="update_profile">
<div class="form-group">
<label for="i_display_name"><?= __("Display name:") ?></label>
<input required class="form-control" type="text" name="display_name" id="i_display_name" value="<?= htmlentities($user->displayName) ?>">
</div>
<div class="form-group">
<label for="i_name"><?= __("Username:") ?></label>
<?php if ($lastNameChangeTooRecent): ?>
<input class="form-control" type="text" id="i_name" value="<?= htmlentities($user->name) ?>" disabled>
<small class="text-danger"><strong><?= __("You can only change your username every 30 days!") ?></strong></small>
<?php else: ?>
<input required class="form-control" type="text" name="name" id="i_name" value="<?= htmlentities($user->name) ?>">
<?php endif; ?>
</div>
<div class="form-group">
<label for="i_email"><?= __("Email address:") ?></label>
<?php if ($emailPending): ?>
<input class="form-control" type="email" id="i_email" value="<?= htmlentities($user->email) ?>" disabled>
<?php else: ?>
<input required class="form-control" type="email" id="i_email" name="email" value="<?= htmlentities($user->email) ?>">
<?php endif; ?>
</div>
<div class="form-group">
<label><?= __("Profile picture:") ?></label>
<?php
$_checkbox_disabled = empty($user->profilePicture);
$_checkbox_disabled_class = $_checkbox_disabled ? " disabled text-muted" : "";
?>
<div class="radio margin-top-0 <?= $_checkbox_disabled_class ?>">
<label>
<input type="radio" name="pfp_action" id="pfp_action_1" value="keep"<?= !empty($user->profilePicture) ? ' checked' : ' disabled' ?>>
<?= __("Keep current profile picture") ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="pfp_action" id="pfp_action_2" value="remove"<?= empty($user->profilePicture) ? ' checked' : '' ?>>
<?php if (empty($user->profilePicture)): ?>
<?= __("No profile picture") ?>
<?php else: ?>
<?= __("Remove profile picture") ?>
<?php endif; ?>
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="pfp_action" value="replace" id="pfp_action_3">
<?= __("Upload new profile picture") ?>
</label>
</div>
<input type="file" name="pfp" id="i_pfp" accept="image/png,image/jpeg" class="margin-left-3x small">
</div>
<div class="form-group">
<button type="submit" class="btn btn-success"><?= __("Save changes") ?></button>
</div>
</form>
<?php if ($isOwnProfile): ?>
<h3><?= __("Change password") ?></h3>
<?php
if (($_formError = RequestUtils::getAndClearFormError("update_password")) !== null) {
_view("alert_error", ["message" => $_formError]);
}
?>
<form action="<?= htmlentities($_SERVER["REQUEST_URI"]) ?>" method="post">
<input type="hidden" name="form_id" value="update_password">
<div class="form-group">
<label for="i_current_password"><?= __("Current password:") ?></label>
<input autocomplete="current-password" required class="form-control" type="password" name="current_password" id="i_current_password" required>
</div>
<div class="form-group">
<label for="i_new_password"><?= __("New password:") ?></label>
<input autocomplete="new-password" required class="form-control" type="password" name="new_password" id="i_new_password" required>
</div>
<div class="form-group">
<label for="i_retype_password"><?= __("Retype password:") ?></label>
<input autocomplete="new-password" required class="form-control" type="password" name="retype_password" id="i_retype_password" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success"><?= __("Change password") ?></button>
</div>
</form>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<script>
$(function() {
$(".post-container").each(function(i, e) {
if ($(e).height() > 900) { // more than 800 so it doesn't collapse just a few pixels
$(e).addClass("collapsed");
}
$(e).find(".post-container-controls button").click(function() {
$(e).removeClass("collapsed");
});
});
});
<?php if ($canEdit): ?>
$(function() {
function _hide() {
$("#i_pfp").hide().prop("disabled", true).prop("required", false);
$("#i_pfp + .file-input-group").hide().find("button").prop("disabled", true);
}
_hide();
setTimeout(_hide, 10);
$("[name='pfp_action']").on("change input check click", function() {
if ($("#pfp_action_3").is(":checked")) {
$("#i_pfp").show().prop("disabled", false).prop("required", true);
$("#i_pfp + .file-input-group").show().find("button").prop("disabled", false);
} else {
_hide();
}
})
});
<?php endif; ?>
</script>
|