Skip to content

Commit

Permalink
fix: misc comment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiZapic committed Nov 5, 2024
1 parent 4af2bf0 commit 1b82365
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
45 changes: 27 additions & 18 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ function themeConfig(Form $form): void {
<a href="/admin/options-reading.php">修改设置</a>
</div>
<?php }
if ($options->commentsPageBreak) { ?>
<div>
<b>警告:</b> 已启用评论分页, 主题不支持该功能, 会导致评论缺失.
<a href="/admin/options-discussion.php">修改设置</a>
</div>
<?php }
$form->addInput(new Text("ColorScheme", null, "", "主题色", "十六进制的主题色, 如#E91E63."));
$form->addInput(new Text("GravatarURL", null, "https://gravatar.loli.net/avatar/", "Gravatar镜像", ""));
if (!is_writable(__DIR__."/assets/color-scheme.css")) {
Expand Down Expand Up @@ -227,7 +233,9 @@ static function ExSearchURL(): string {
}

static function Gravatar(string $mail,int $size = 40): void {
echo Helper::options()->GravatarURL.md5(strtolower($mail)).'?s='.$size.'&d=mp';
$options = Helper::options();
$rating = $options->commentsAvatarRating;
echo $options->GravatarURL . md5(strtolower($mail)).'?s='.$size.'&d=mp&r=' . $rating;
}

static function cover(Archive $archive): void {
Expand Down Expand Up @@ -388,36 +396,37 @@ static function activePage(Archive $archive, string $type, int $id = -1): void {

static function toComment(\Widget\Comments\Archive &$comments, bool $allowComment): void {
$isTopLevel = $comments->levels === 0;
if ($isTopLevel) {
$options = Helper::options();
if ($isTopLevel || !$options->commentsThreaded) {
?>
<div class="w-full box-border matecho-comment-wrapper matecho-comment-parent" id="comment-<?php echo $comments->coid ?>">
<div class="flex items-center">
<mdui-avatar class="matecho-comment-avatar"><?php $comments->gravatar(40) ?></mdui-avatar>
<mdui-avatar class="matecho-comment-avatar" src="<?php self::Gravatar($comments->mail, 40) ?>"></mdui-avatar>
<div class="ml-4 matecho-comment-author">
<?php $comments->author(); ?>
</div>
<span class="flex-grow text-right text-sm opacity-60">#<?php echo $comments->coid; ?></span>
</div>
<div class="pl-56px">
<div class="mdui-prose mb-2">
<?php if($comments->levels > 0) { ?>
<a class="text-sm" href="#comment-<?php echo $comments->parent; ?>">回复 #<?php echo $comments->parent; ?>:</a>
<?php } ?>
<?php $comments->content(); ?>
</div>
<div class="flex items-center">

<div class="opacity-60 text-sm">
<?php $comments->date(); ?>
<?php if ($comments->status === "waiting") { ?>
<span class="ml-2 text-sm">等待审核</span>
<div class="opacity-60 text-sm">
<?php $comments->date(); ?>
<?php if ($comments->status === "waiting") { ?>
<span class="ml-2 text-sm">等待审核</span>
<?php } ?>
</div>
<?php if ($options->commentsThreaded) { ?>
<mdui-button class="matecho-comment-reply h-6 min-w-0 w-3rem ml-2 inline-block" data-to-comment="<?php echo $comments->coid ?>" variant="text" class="h-8 min-w-0" <?php if(!$allowComment) {echo "disabled"; } ?>>
回复
</mdui-button>
<?php } ?>
</div>

<mdui-button class="matecho-comment-reply h-6 min-w-0 w-3rem ml-2 inline-block" data-to-comment="<?php echo $comments->coid ?>" variant="text" class="h-8 min-w-0" <?php if(!$allowComment) {echo "disabled"; } ?>>
回复
</mdui-button>
</div>
</div>
<div>

</div>
<?php if (count($comments->children) > 0) { ?>
<div class="w-full pl-56px box-border mt-4 matecho-comment-children-list">
Expand All @@ -439,14 +448,14 @@ static function toComment(\Widget\Comments\Archive &$comments, bool $allowCommen
<?php } else {?>
<div class="w-full box-border matecho-comment-wrapper matecho-comment-child" id="comment-<?php echo $comments->coid ?>">
<div class="flex items-center">
<mdui-avatar class="matecho-comment-avatar w-28px h-28px flex-shrink-0"><?php $comments->gravatar(28) ?></mdui-avatar>
<mdui-avatar class="matecho-comment-avatar w-28px h-28px flex-shrink-0" src="<?php self::Gravatar($comments->mail, 28) ?>"></mdui-avatar>
<div class="ml-2 matecho-comment-author">
<?php $comments->author(); ?>
</div>
<span class="flex-grow text-right text-sm opacity-60">#<?php echo $comments->coid; ?></span>
</div>
<div class="pl-35px">
<div class="mdui-prose mb-2">
<div class="mdui-prose">
<?php if($comments->levels > 1) { ?>
<a class="text-sm" href="#comment-<?php echo $comments->parent; ?>">回复 #<?php echo $comments->parent; ?>:</a>
<?php } ?>
Expand Down
2 changes: 1 addition & 1 deletion src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
);
?>
<?php if ($TotalPage > 1){ ?>
<div class="flex justify-center items-center mt-6 mb-3 line-height-0 select-none text-sm ">
<div class="flex justify-center items-center mt-6 mb-3 line-height-0 select-none text-sm">
<?php if ($CurrentPage > 1) {
$this->pageLink('<mdui-button-icon><mdui-icon-chevron-left></mdui-icon-chevron-left></mdui-button-icon>');
} else { ?>
Expand Down
5 changes: 1 addition & 4 deletions src/pages/post/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ function initCommentForm(formWrapper: HTMLDivElement) {
const commentList = document.querySelector(
"#matecho-comment-list"
) as HTMLDivElement;
const token = window.__MATECHO_ANTI_SPAM__;
if (!token) return;
if (!form.reportValidity()) return;
const data = new FormData(form);
data.set("_", token);
data.set("receiveMail", "yes");
formWrapper.classList.add("matecho-form__loading");
try {
const { success, error, root } = await sendComment(form.action, data);
if (success) {
if (!commentList) return location.reload();
document.querySelector("#matecho-no-comment-placeholder")?.remove();
root
.querySelectorAll("#matecho-comment-list .matecho-comment-wrapper")
.forEach(v => {
Expand Down
8 changes: 4 additions & 4 deletions src/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@
</div>
<div id="matecho-comment-list">
<?php
while ($comments->next()) {
Matecho::toComment($comments, $this->allowComment);
}
while ($comments->next()) {
Matecho::toComment($comments, $this->allowComment);
}
?>
</div>
<?php if ($comments->___length() === 0) { ?>
<?php if ($this->commentsNum === 0) { ?>
<div class="my-12 text-md text-center opacity-50" id="matecho-no-comment-placeholder">没有评论</div>
<?php } ?>
<div class="py-4 matecho-comment-form matecho-comment-form__main w-full box-border relative <?php echo $this->allowComment ? "" : "matecho-comment-form__lock"; ?>"
Expand Down

0 comments on commit 1b82365

Please sign in to comment.