Allow avatar for users

This commit is contained in:
danpros 2024-04-28 11:11:50 +07:00
commit 32659cd9e9
5 changed files with 75 additions and 5 deletions

View file

@ -840,7 +840,7 @@ function edit_category($title, $url, $content, $oldfile, $destination = null, $d
}
// Edit user profile
function edit_profile($title, $content, $user, $description = null)
function edit_profile($title, $content, $user, $description = null, $image = null)
{
$description = safe_html($description);
if ($description !== null) {
@ -852,8 +852,13 @@ function edit_profile($title, $content, $user, $description = null)
} else {
$profile_description = "";
}
if ($image !== null) {
$avatar = "\n<!--image " . $image . " image-->";
} else {
$avatar = "";
}
$user_title = safe_html($title);
$user_content = '<!--t ' . $user_title . ' t-->' . $profile_description . "\n\n" . $content;
$user_content = '<!--t ' . $user_title . ' t-->' . $profile_description . $avatar . "\n\n" . $content;
if (!empty($user_title) && !empty($user_content)) {
@ -952,7 +957,6 @@ function delete_page($file, $destination)
$deleted_content = $file;
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
$arr = explode('/', $file);
// realpath resolves all traversal operations like ../
$realFilePath = realpath($file);

View file

@ -25,10 +25,12 @@ if ($type == 'is_frontpage') {
$oldtitle = get_content_tag('t', $content, 'user');
$olddescription = get_content_tag('d', $content, remove_html_comments($content));
$oldcontent = remove_html_comments($content);
$oldimage = get_content_tag('image', $content);
} else {
$oldtitle = $user;
$olddescription = i18n('Author_Description');
$oldcontent = i18n('Author_Description');
$oldimage = '';
}
} elseif ($type == 'is_category') {
@ -116,6 +118,20 @@ $images = image_gallery(null, 1, 40);
<input type="text" id="pURL" name="url" class="form-control text" value="<?php echo $oldmd ?>" placeholder="<?php echo i18n('If_the_url_leave_empty_we_will_use_the_page_title');?>"/>
<br>
<?php } ?>
<?php if ($type == 'is_profile'):?>
<style>.imgPrev img {width:50%;} </style>
<label for="pImage">Avatar (<?php echo i18n('optional');?>)</label>
<br>
<label class="btn btn-primary btn-sm" id="insertButton"><?php echo i18n('Insert_Image');?></label>
<br>
<div class="imgPrev"><img id="imgFile" src="<?php echo $oldimage; ?>"/></div>
<br>
<input type="text" class="media-uploader form-control text <?php if (isset($postImage)) { if (empty($postImage)) { echo 'error';}} ?>" id="pImage" name="image" readonly value="<?php echo $oldimage; ?>">
<input type="hidden" name="is_image" value="is_image">
<br>
<?php endif;?>
</div>
</div>
@ -209,10 +225,50 @@ $images = image_gallery(null, 1, 40);
</div>
</div>
</div>
<?php if ($type == 'is_profile'):?>
<div class="modal fade" id="insertMediaDialog" tabindex="-1" role="dialog" aria-labelledby="insertMediaDialogTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="insertMediaDialogTitle"><?php echo i18n('Insert_Image');?></h5>
<button type="button" class="close" id="insertMediaDialogClose" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<div class="row-fluid img-container" id="gallery-2">
<?php echo $images;?>
</div>
</div>
<hr>
<div class="form-group">
<label for="insertMediaDialogURL">URL</label>
<input type="text" class="form-control" id="insertMediaDialogURL" size="48" placeholder="<?php echo i18n('Enter_image_URL');?>" />
</div>
<hr>
<div class="form-group">
<label for="insertMediaDialogFile"><?php echo i18n('Upload');?></label>
<input type="file" class="form-control-file" name="file" id="insertMediaDialogFile" accept="image/png,image/jpeg,image/gif" />
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="insertMediaDialogInsert"><?php echo i18n('Insert_Image');?></button>
<button type="button" class="btn btn-secondary" id="insertMediaDialogCancel" data-dismiss="modal"><?php echo i18n('Cancel');?></button>
</div>
</div>
</div>
</div>
<?php endif;?>
</div>
<!-- Declare the base path. Important -->
<script type="text/javascript">var base_path = '<?php echo site_url() ?>'; var initial_image = '<?php echo $images;?>';</script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/editor.js"></script>
<?php if ($type == 'is_profile'):?>
<script type="text/javascript" src="<?php echo site_url() ?>system/resources/js/media.uploader.js"></script>
<?php endif;?>
<script>
function loadImages(page) {
$.ajax({

View file

@ -15,6 +15,7 @@
<?php if (login()) {
$user = $_SESSION[site_url()]['user'];
$role = user('role', $user);
$author = get_author($user);
if (isset($_GET['search'])) {
$search = _h($_GET['search']);
$url = site_url() . 'search/' . remove_accent($search);
@ -54,7 +55,7 @@ if (isset($_GET['search'])) {
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<img src="<?php echo site_url(); ?>system/resources/images/logo-small.png" class="img-circle elevation-2" alt="HTMLy logo">
<img src="<?php echo $author[0]->avatar; ?>" class="img-circle elevation-2" alt="HTMLy logo">
</div>
<div class="info">
<a href="<?php echo site_url();?>admin" class="d-block"><?php echo i18n('Dashboard')?></a>

View file

@ -316,9 +316,10 @@ post('/edit/profile', function () {
$user = $_SESSION[site_url()]['user'];
$title = from($_REQUEST, 'title');
$description = from($_REQUEST, 'description');
$image = from($_REQUEST, 'image');
$content = from($_REQUEST, 'content');
if ($proper && !empty($title) && !empty($content)) {
edit_profile($title, $content, $user, $description);
edit_profile($title, $content, $user, $description, $image);
} else {
$message['error'] = '';
if (empty($title)) {
@ -340,6 +341,7 @@ post('/edit/profile', function () {
'error' => '<ul>' . $message['error'] . '</ul>',
'postTitle' => $title,
'postContent' => $content,
'postImage' => $image,
'type' => 'is_profile',
'is_admin' => true,
'bodyclass' => 'edit-profile',
@ -3151,6 +3153,7 @@ get('/post/:name', function ($name) {
$author->name = $current->authorName;
$author->description = $current->authorDescription;
$author->about = $current->authorAbout;
$author->avatar = $current->authorAvatar;
if (array_key_exists('prev', $post)) {
$prev = $post['prev'];
@ -4329,6 +4332,7 @@ get('/:year/:month/:name', function ($year, $month, $name) {
$author->name = $current->authorName;
$author->description = $current->authorDescription;
$author->about = $current->authorAbout;
$author->avatar = $current->authorAvatar;
if (array_key_exists('prev', $post)) {
$prev = $post['prev'];

View file

@ -447,10 +447,12 @@ function get_posts($posts, $page = 1, $perpage = 0)
$post->authorName = $profile[0]->name;
$post->authorDescription = $profile[0]->description;
$post->authorAbout = $profile[0]->about;
$post->authorAvatar = $profile[0]->avatar;
} else {
$post->authorName = $author;
$post->authorDescription = i18n('Author_Description');
$post->authorAbout = i18n('Author_Description');
$post->authorAvatar = site_url() . 'system/resources/images/logo-small.png';
}
$post->type = $type;
@ -1225,6 +1227,8 @@ function get_author($name)
$author->description = get_content_tag("d", $content, get_description($author->about));
$author->avatar = get_content_tag("image", $content, site_url() . 'system/resources/images/logo-small.png');
$toc = explode('<!--toc-->', $author->about);
if (isset($toc['1'])) {
$author->about = insert_toc('profile-' . $author->slug, $toc['0'], $toc['1']);
@ -1256,6 +1260,7 @@ function default_profile($name)
$author->about = '<p>' . i18n('Author_Description') . '</p>';
$author->body = '<p>' . i18n('Author_Description') . '</p>';
$author->description = i18n('Author_Description');
$author->avatar = site_url() . 'system/resources/images/logo-small.png';
$author->url = site_url(). 'author/' . $name;
$author->slug = $name;
$author->file = '';