Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Fix & UI | #19 & Comment UI
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingSky-CN committed Feb 7, 2020
1 parent e381e5c commit a72d78b
Show file tree
Hide file tree
Showing 7 changed files with 352 additions and 483 deletions.
226 changes: 127 additions & 99 deletions comments.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function threadedComments($comments, $options) {
$commentClass = '';
if ($comments->authorId) {
Expand Down Expand Up @@ -39,105 +38,134 @@ function threadedComments($comments, $options) {
<?php } ?>
</div>
<?php } ?>

<!-- mdr | Comments -->
<div id="comments">
<?php $this->comments()->to($comments); ?>
<?php if ($comments->have()): ?>
<h3><?php $this->commentsNum(_t('暂无评论'), _t('已有 <span class="comment-num">%d</span> 条评论')); ?></h3>
<?php $comments->listComments(); ?>
<?php $comments->pageNav('上一页', '下一页', 0, '..'); ?>
<?php endif; ?>
<?php if($this->allow('comment')): ?>
<div id="<?php $this->respondId(); ?>" class="respond">
<div class="cancel-comment-reply" style="padding-right: 24px;">
<?php $comments->cancelReply(); ?>
<?php $this->comments()->to($comments); ?>
<?php if($this->allow('comment')): ?>
<!-- mdr | allowComment -->
<div class="mdui-card respond" id="<?php $this->respondId(); ?>">
<div class="mdui-card-primary">
<div class="mdui-card-primary-title" id="response">发表评论</div>
<div class="mdui-card-primary-subtitle"><?php $this->commentsNum(_t('暂无评论'), _t('已有 <span class="comment-num">%d</span> 条评论')); ?></div>
</div>
<h3 id="response">添加新评论</h3>
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form"<?php if(!$this->user->hasLogin()): ?> class="comment-form clearfix"<?php endif; ?>>
<?php if($this->user->hasLogin()): ?>
<p>登录身份: <a href="<?php $this->options->profileUrl(); ?>" target="_blank"><?php $this->user->screenName(); ?></a>. <a href="<?php $this->options->logoutUrl(); ?>" title="Logout"<?php if ($this->options->PjaxOption): ?> no-pjax <?php endif; ?>>退出 &raquo;</a></p>
<?php endif; ?>
<p <?php if(!$this->user->hasLogin()): ?>class="textarea"<?php else: ?>style="margin-bottom:5px"<?php endif; ?>>
<textarea name="text" id="textarea" placeholder="加入讨论..." required ><?php $this->remember('text'); ?></textarea>
</p>
<?php if(!$this->user->hasLogin()): ?>
<p class="textbutton">
<input type="text" name="author" id="author" class="text" placeholder="称呼 *" value="<?php $this->remember('author'); ?>" required />
<input type="email" name="mail" id="mail" class="text" placeholder="邮箱<?php if ($this->options->commentsRequireMail): ?> *<?php endif; ?>" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?> />
<input type="url" name="url" id="url" class="text" placeholder="http://<?php if ($this->options->commentsRequireURL): ?> *<?php endif; ?>" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?> />
<?php endif; ?>
<button type="submit" class="submit mdui-btn mdui-btn-raised mdui-btn-dense mdui-color-theme-accent mdui-ripple">提交评论</button>
<?php if(!$this->user->hasLogin()): ?>
</p>
<?php endif; ?>
</form>
<div class="mdui-card-content">
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" class="comment-form mdui-row">
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-md-12">
<i class="mdui-icon material-icons">textsms</i>
<label class="mdui-textfield-label">说点什么...</label>
<textarea class="mdui-textfield-input" name="text" id="textarea" require><?php $this->remember('text'); ?></textarea>
<div class="mdui-textfield-error" role="alert">内容不能为空</div>
</div>
<?php if($this->user->hasLogin()): ?>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-md-12">
<i class="mdui-icon material-icons">account_circle</i>
<label class="mdui-textfield-label">登录身份</label>
<input class="mdui-textfield-input text" value="<?php $this->user->screenName(); ?>" readonly>
<div class="mdui-textfield-error" role="alert">昵称不能为空</div>
</div>
<?php else: ?>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-md-4">
<i class="mdui-icon material-icons">account_circle</i>
<label class="mdui-textfield-label">昵称</label>
<input class="mdui-textfield-input text" type="text" name="author" id="author" value="<?php $this->remember('author'); ?>" required>
<div class="mdui-textfield-error" role="alert">昵称不能为空</div>
</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-md-4">
<i class="mdui-icon material-icons">email</i>
<label class="mdui-textfield-label">邮箱</label>
<input class="mdui-textfield-input text" type="email" name="mail" id="mail" value="<?php $this->remember('mail'); ?>"<?php if ($this->options->commentsRequireMail): ?> required<?php endif; ?>>
<div class="mdui-textfield-error" role="alert">请按格式填写邮箱</div>
</div>
<div class="mdui-textfield mdui-textfield-floating-label mdui-col-md-4">
<i class="mdui-icon material-icons">link</i>
<label class="mdui-textfield-label">网站</label>
<input class="mdui-textfield-input text" type="url" name="url" id="url" value="<?php $this->remember('url'); ?>"<?php if ($this->options->commentsRequireURL): ?> required<?php endif; ?>>
<div class="mdui-textfield-error" role="alert">请按格式填写网站</div>
</div>
<?php endif; ?>
<div class="mdui-col-md-12">
<div class="mdui-btn mdui-ripple cancel-comment-reply" style="display:none">
<?php $comments->cancelReply(); ?>
</div>
<button type="submit" class="submit mdui-btn mdui-ripple mdui-color-theme-accent mdui-float-right">提交评论</button>
</div>
</form>
</div>
<?php if ($this->options->commentsThreaded): ?>
<script>
(function() {
window.TypechoComment = {
dom: function(id) {
return document.getElementById(id)
},
create: function(tag, attr) {
var el = document.createElement(tag);
for (var key in attr) {
el.setAttribute(key, attr[key])
}
return el
},
reply: function(cid, coid) {
var comment = this.dom(cid),
parent = comment.parentNode,
response = this.dom('<?php $this->respondId(); ?>'),
input = this.dom('comment-parent'),
form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],
textarea = response.getElementsByTagName('textarea')[0];
if (null == input) {
input = this.create('input', {
'type': 'hidden',
'name': 'parent',
'id': 'comment-parent'
});
form.appendChild(input)
}
input.setAttribute('value', coid);
if (null == this.dom('comment-form-place-holder')) {
var holder = this.create('div', {
'id': 'comment-form-place-holder'
});
response.parentNode.insertBefore(holder, response)
}
comment.appendChild(response);
this.dom('cancel-comment-reply-link').style.display = '';
if (null != textarea && 'text' == textarea.name) {
textarea.focus()
}
response.style.padding='8px';
<?php if(!$this->user->hasLogin()): ?>
response.style.paddingBottom='5px';
<?php endif; ?>
return false
},
cancelReply: function() {
var response = this.dom('<?php $this->respondId(); ?>'),
holder = this.dom('comment-form-place-holder'),
input = this.dom('comment-parent');
if (null != input) {
input.parentNode.removeChild(input)
}
if (null == holder) {
return true
}
this.dom('cancel-comment-reply-link').style.display = 'none';
holder.parentNode.insertBefore(response, holder);
response.style.padding='0px';
return false
}
}
})();
</script>
<?php endif; ?>
<?php else: ?>
<?php endif; ?>
</div>
<?php if ($this->options->commentsThreaded): ?>
<?php /**Note commentsThreaded => 启用评论回复 */ ?>
<!-- mdr | commentsThreaded -->
<script>
(function(){window.TypechoComment={
dom: function(id) {
return document.getElementById(id)
},
create: function(tag, attr) {
var el = document.createElement(tag);
for (var key in attr) {
el.setAttribute(key, attr[key])
}
return el
},
reply: function(cid, coid) {
var comment = this.dom(cid),
parent = comment.parentNode,
response = this.dom('<?php $this->respondId(); ?>'),
input = this.dom('comment-parent'),
form = 'form' == response.tagName ? response : response.getElementsByTagName('form')[0],
textarea = response.getElementsByTagName('textarea')[0];
if (null == input) {
input = this.create('input', {
'type': 'hidden',
'name': 'parent',
'id': 'comment-parent'
});
form.appendChild(input)
}
input.setAttribute('value', coid);
if (null == this.dom('comment-form-place-holder')) {
var holder = this.create('div', {
'id': 'comment-form-place-holder'
});
response.parentNode.insertBefore(holder, response)
}
comment.appendChild(response);
this.dom('cancel-comment-reply-link').parentNode.style.display = 'inline-block';
this.dom('cancel-comment-reply-link').style.display = '';
response.style.borderTopLeftRadius = '0';
response.style.borderTopRightRadius = '0';
if (null != textarea && 'text' == textarea.name) {
textarea.focus()
}
<?php if(!$this->user->hasLogin()): ?>
<?php endif; ?>
return false
},
cancelReply: function() {
var response = this.dom('<?php $this->respondId(); ?>'),
holder = this.dom('comment-form-place-holder'),
input = this.dom('comment-parent');
if (null != input) {
input.parentNode.removeChild(input)
}
if (null == holder) {
return true
}
this.dom('cancel-comment-reply-link').parentNode.style.display = 'none';
this.dom('cancel-comment-reply-link').style.display = 'none';
response.style.borderTopLeftRadius = '2px';
response.style.borderTopRightRadius = '2px';
holder.parentNode.insertBefore(response, holder);
return false
}
}})();
</script>
<?php endif; ?>
<?php else: ?>
<!-- mdr | unallowComment -->
<?php endif; ?>
<?php if ($comments->have()): ?>
<?php $comments->listComments(); ?>
<?php $comments->pageNav('上一页', '下一页', 0, '..'); ?>
<?php endif; ?>
</div>
7 changes: 5 additions & 2 deletions footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function show_runtime() {
$('#s').val("");
})
.on('pjax:end', function() {
mdui.mutation();
if ( document.body.clientWidth < 1024 ) {
mdui.Drawer('#mdrDrawerL').close();
mdui.Drawer('#mdrDrawerR').close();
Expand Down Expand Up @@ -167,8 +168,10 @@ function ac() {
position: '<?=$this->options->mdrSnackbar?>',
timeout: 5000
});
if (ar[1]['name'] == 'parent') {
l = 'comment-'+ar[1]['value'];
if (ar[1]) {
if (ar[1]['name'] == 'parent') {
l = 'comment-'+ar[1]['value'];
}
}
$.ajax({
url: $(this).attr('action'),
Expand Down
2 changes: 1 addition & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ function Whisper($sidebar = NULL) {
$options = Helper::options();
$page = FindContents('page-whisper.php', 'commentsNum', 'd');
$p = $sidebar ? 'li' : 'p';
if (isset($page)) {
if (isset($page[0])) {
$page = $page[0];
$title = $sidebar ? '' : '<h2 class="post-title"><a href="'.$page['permalink'].'">'.$page['title'].'<span class="more">···</span></a></h2>'."\n";
$comment = $db->fetchAll($db->select()->from('table.comments')
Expand Down
6 changes: 3 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
}
</style>
<?php endif; ?>
<link rel="stylesheet" href="<?php cjUrl('mdr.css?v=2') ?>" />
<link rel="stylesheet" href="<?php cjUrl('style.css?v=20') ?>" />
<link rel="stylesheet" href="<?php cjUrl('mdr.css?v=3') ?>" />
<!--<link rel="stylesheet" href="<?php cjUrl('style.css?v=20') ?>" />-->
<?php if ($this->options->ViewImg): ?>
<link rel="stylesheet" href="//<?php if ($this->options->cjCDN == 'bc'): ?>cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.css<?php elseif ($this->options->cjCDN == 'cf'): ?>cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css<?php else: ?>cdn.jsdelivr.net/npm/[email protected]/dist/css/jquery.fancybox.css<?php endif; ?>"/>
<?php endif; ?>
</head>
<body class="<?php if($_COOKIE['dark']=='1'): ?>mdui-theme-layout-dark<?php endif; ?> <?php if ($this->options->mdrNavDefOpen): ?>mdui-drawer-body-left<?php endif; ?> mdui-appbar-with-toolbar mdui-drawer-body-right mdui-theme-accent-<?php if($_COOKIE['dark']=='1'){$this->options->mdrAccentD();}else{$this->options->mdrAccent();}?> mdui-theme-primary-<?=$this->options->mdrPrimary?>">
<body class="<?php if(@$_COOKIE['dark'] == '1'): ?>mdui-theme-layout-dark<?php endif; ?> <?php if ($this->options->mdrNavDefOpen): ?>mdui-drawer-body-left<?php endif; ?> mdui-appbar-with-toolbar mdui-drawer-body-right mdui-theme-accent-<?=((@$_COOKIE['dark']=='1') ? $this->options->mdrAccentD() : $this->options->mdrAccent() )?> mdui-theme-primary-<?=$this->options->mdrPrimary?>">
<div class="mdui-progress" style="z-index:9999;position: fixed; <?php if ($this->options->mdrLoading == 'bottom') { ?> bottom:0 <?php } else { ?> top:0 <?php } ?>; left:0;display:none;border-radius: 0px;" id="loading">
<div class="mdui-progress-indeterminate"></div>
</div>
Expand Down
22 changes: 10 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
<div id="main">
<?php if ($this->_currentPage==1&&!empty($this->options->ShowWhisper)&&in_array('index',$this->options->ShowWhisper)): ?>
<article class="post whisper">
<div class="post-content">
<?php Whisper(); ?>
<?php if ($this->user->pass('editor', true) && (!FindContents('page-whisper.php') || isset(FindContents('page-whisper.php')[1]))): ?>
<p class="notice">
<b>仅管理员可见: </b><br>
<?php if (FindContents('page-whisper.php')): ?>
发现多个"轻语"模板页面,已自动选取内容最多的页面作为展示,请删除多余模板页面。
<?php else: ?>
未找到"轻语"模板页面,请检查是否创建模板页面。
<?php endif; ?>
</p>
<?php Whisper(); ?>
<?php if ($this->user->pass('editor', true) && (!FindContents('page-whisper.php') || isset(FindContents('page-whisper.php')[1]))): ?>
<p class="notice">
<b>仅管理员可见: </b><br>
<?php if (FindContents('page-whisper.php')): ?>
发现多个"轻语"模板页面,已自动选取内容最多的页面作为展示,请删除多余模板页面。
<?php else: ?>
未找到"轻语"模板页面,请检查是否创建模板页面。
<?php endif; ?>
</div>
</p>
<?php endif; ?>
</article>
<?php endif; ?>
<?php while($this->next()): ?>
Expand Down
Loading

0 comments on commit a72d78b

Please sign in to comment.