feat: add recent comments tool (#273)

pull/307/head
Seaton Jiang 2020-12-14 00:25:50 +08:00
parent d18485082b
commit 872277649d
No known key found for this signature in database
GPG Key ID: C1086BAE716FF138
4 changed files with 214 additions and 37 deletions

View File

@ -1866,7 +1866,7 @@ button:focus {
.k-main .sidebar .widget_links ul li:hover,
.k-main .sidebar .widget_categories ul li:hover,
.k-main .sidebar .widget_archive ul li:hover {
background-color: #eeeeee;
background-color: #f7f6f6;
}
.nav-tabs .nav-item.show .nav-link,
@ -1930,6 +1930,53 @@ button:focus {
display: none;
}
.k-main .sidebar .w-comments .comments a {
display: block;
padding: 13px 0;
}
.k-main .sidebar .w-comments .comments a:first-child {
padding: 0 0 13px;
}
.k-main .sidebar .w-comments .comments a:not(:last-child) {
border-bottom: 1px solid #eee;
}
.k-main .sidebar .w-comments .comments .message {
overflow: hidden;
color: #394a58;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 14px;
word-break: keep-all;
}
.k-main .sidebar .w-comments .comments .meta .avatar img {
float: left;
margin-right: 7px;
width: 50px;
height: 50px;
max-width: 100%;
border-radius: 50%;
border: 1px solid #eaeaea;
}
.k-main .sidebar .w-comments .comments .meta .author {
color: #777;
font-size: 12px;
}
.k-main .sidebar .w-comments .comments .meta .profile {
padding-top: 5px;
font-size: 12px;
}
.k-main .sidebar .w-comments .comments .meta .date {
color: #777;
font-size: 12px;
}
.btn-search {
background-color: #00a2ff;
border-color: #00a2ff;

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@
* 侧栏小工具
* @author Seaton Jiang <seaton@vtrois.com>
* @license MIT License
* @version 2020.12.13
* @version 2020.12.14
*/
// 添加小工具
@ -62,7 +62,63 @@ function most_comm_posts($days = 30, $nums = 6)
echo $output;
}
class widget_search extends WP_Widget {
function timeago($ptime){
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if($etime < 1)
return'刚刚';
$interval = array(
12*30*24*60*60 => ' 年前('.date('m月d日',$ptime).'',
30*24*60*60 => ' 个月前('.date('m月d日',$ptime).'',
7*24*60*60 => ' 周前('.date('m月d日',$ptime).'',
24*60*60 => ' 天前('.date('m月d日',$ptime).'',
60*60 => ' 小时前('.date('m月d日',$ptime).'',
60 => ' 分钟前('.date('m月d日',$ptime).'',
1 => ' 秒前('.date('m月d日',$ptime).'',
);
foreach($interval as$secs=>$str){
$d=$etime/$secs;
if($d>=1){
$r=round($d);
return$r.$str;
}
}
}
function string_cut($string, $sublen, $start = 0, $code = 'UTF-8') {
if($code == 'UTF-8') {
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen)) . "...";
return join('', array_slice($t_string[0], $start, $sublen));
} else {
$start = $start * 2;
$sublen = $sublen * 2;
$strlen = strlen($string);
$tmpstr = '';
for($i = 0; $i < $strlen; $i++) {
if($i >= $start && $i < ($start + $sublen)) {
if(ord(substr($string, $i, 1)) > 129) $tmpstr .= substr($string, $i, 2);
else $tmpstr .= substr($string, $i, 1);
}
if(ord(substr($string, $i, 1)) > 129) $i++;
}
return $tmpstr;
}
}
function latest_comments($list_number=5, $cut_length=50)
{
global $wpdb,$output;
$comments = $wpdb->get_results("SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, comment_author_url, comment_author_email, comment_content AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND (comment_type = '' OR comment_type = 'comment') AND user_id != '1' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $list_number");
foreach ($comments as $comment) {
$output .= ' <a href="'.get_the_permalink($comment->comment_post_ID) .'#commentform"> <div class="meta clearfix"> <div class="avatar float-left">'.get_avatar( $comment, 60 ).'</div> <div class="profile d-block"> <span class="date"> '.__( '发布于 ' , 'kratos').timeago($comment->comment_date_gmt).'</span> <span class="message d-block">'.convert_smilies(string_cut(strip_tags($comment->com_excerpt), $cut_length)).'</span> </div> </div> </a>';
}
return $output;
}
class widget_search extends WP_Widget
{
public function __construct() {
$widget_ops = array(
@ -395,6 +451,57 @@ class widget_posts extends WP_Widget
}
}
class widget_comments extends WP_Widget
{
public function __construct()
{
$widget_ops = array(
'name' => __('最近评论', 'kratos'),
'description' => __('展示站点最近的评论', 'kratos'),
);
parent::__construct(false, false, $widget_ops);
}
public function widget($args, $instance)
{
$number = !empty($instance['number']) ? $instance['number'] : '5';
$title = !empty($instance['title']) ? $instance['title'] : '最近评论';
echo '<div class="widget w-comments"><div class="title">'. $title .'</div><div class="comments">';
echo latest_comments($number, 50);
echo '</div></div>';
}
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['number'] = (!empty($new_instance['number'])) ? $new_instance['number'] : '';
$instance['title'] = (!empty($new_instance['title'])) ? $new_instance['title'] : '';
return $instance;
}
public function form($instance)
{
global $wpdb;
$number = !empty($instance['number']) ? $instance['number'] : '5';
$title = !empty($instance['title']) ? $instance['title'] : '最近评论';
?>
<div class="media-widget-control">
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('栏目标题:', 'kratos');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('展示数量:', 'kratos');?></label>
<input class="widefat" id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo esc_attr($number); ?>" />
</p>
</div>
<?php
}
}
function register_widgets()
{
register_widget('widget_ad');
@ -402,5 +509,6 @@ function register_widgets()
register_widget('widget_tags');
register_widget('widget_search');
register_widget('widget_posts');
register_widget('widget_comments');
}
add_action('widgets_init', 'register_widgets');

View File

@ -3,14 +3,14 @@ msgid ""
msgstr ""
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"Project-Id-Version: Kratos\n"
"POT-Creation-Date: 2020-10-26 09:27+0800\n"
"POT-Creation-Date: 2020-12-14 00:21+0800\n"
"PO-Revision-Date: 2020-02-14 23:32+0800\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.4.1\n"
"X-Generator: Poedit 2.4.2\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: style.css\n"
@ -74,7 +74,7 @@ msgstr ""
msgid "提交评论"
msgstr ""
#: footer.php:27 inc/theme-widgets.php:81
#: footer.php:27 inc/theme-widgets.php:140
msgid "搜点什么呢?"
msgstr ""
@ -641,11 +641,11 @@ msgstr ""
msgid "个人昵称"
msgstr ""
#: inc/theme-options.php:463 inc/theme-widgets.php:178
#: inc/theme-options.php:463 inc/theme-widgets.php:237
msgid "个人简介"
msgstr ""
#: inc/theme-options.php:464 inc/theme-widgets.php:195
#: inc/theme-options.php:464 inc/theme-widgets.php:254
#: pages/page-toolbar.php:18
msgid "保持饥渴的专注,追求最佳的品质"
msgstr ""
@ -952,117 +952,139 @@ msgstr ""
msgid "侧边栏工具"
msgstr ""
#: inc/theme-widgets.php:67
#: inc/theme-widgets.php:115
msgid "发布于 "
msgstr ""
#: inc/theme-widgets.php:126
msgid "A search form for your site."
msgstr ""
#: inc/theme-widgets.php:70
#: inc/theme-widgets.php:129
msgctxt "Search widget"
msgid "Search"
msgstr ""
#: inc/theme-widgets.php:81
#: inc/theme-widgets.php:140
msgid "搜索"
msgstr ""
#: inc/theme-widgets.php:89
#: inc/theme-widgets.php:148
msgid "Title:"
msgstr ""
#: inc/theme-widgets.php:109
#: inc/theme-widgets.php:168
msgid "图片广告"
msgstr ""
#: inc/theme-widgets.php:110
#: inc/theme-widgets.php:169
msgid "显示自定义图片广告的工具"
msgstr ""
#: inc/theme-widgets.php:126 inc/theme-widgets.php:148
#: inc/theme-widgets.php:185 inc/theme-widgets.php:207
msgid "广告"
msgstr ""
#: inc/theme-widgets.php:154
#: inc/theme-widgets.php:213
msgid "副标题:"
msgstr ""
#: inc/theme-widgets.php:158
#: inc/theme-widgets.php:217
msgid "链接地址:"
msgstr ""
#: inc/theme-widgets.php:162
#: inc/theme-widgets.php:221
msgid "广告图片:"
msgstr ""
#: inc/theme-widgets.php:164 inc/theme-widgets.php:234
#: inc/theme-widgets.php:223 inc/theme-widgets.php:293
msgid "选择图片"
msgstr ""
#: inc/theme-widgets.php:179
#: inc/theme-widgets.php:238
msgid "站长个人简介的展示工具"
msgstr ""
#. Theme Name of the plugin/theme
#: inc/theme-widgets.php:196
#: inc/theme-widgets.php:255
msgid "Kratos"
msgstr ""
#: inc/theme-widgets.php:232
#: inc/theme-widgets.php:291
msgid "背景图片:"
msgstr ""
#: inc/theme-widgets.php:246 inc/theme-widgets.php:269
#: inc/theme-widgets.php:305 inc/theme-widgets.php:328
msgid "标签聚合"
msgstr ""
#: inc/theme-widgets.php:247
#: inc/theme-widgets.php:306
msgid "文章标签的展示工具"
msgstr ""
#: inc/theme-widgets.php:292
#: inc/theme-widgets.php:351
msgid "显示数量:"
msgstr ""
#: inc/theme-widgets.php:296
#: inc/theme-widgets.php:355
msgid "显示排序:"
msgstr ""
#: inc/theme-widgets.php:298
#: inc/theme-widgets.php:357
msgid "降序"
msgstr ""
#: inc/theme-widgets.php:299
#: inc/theme-widgets.php:358
msgid "升序"
msgstr ""
#: inc/theme-widgets.php:300 inc/theme-widgets.php:330
#: inc/theme-widgets.php:335
#: inc/theme-widgets.php:359 inc/theme-widgets.php:390
#: inc/theme-widgets.php:395 inc/theme-widgets.php:446
msgid "随机"
msgstr ""
#: inc/theme-widgets.php:313
#: inc/theme-widgets.php:372
msgid "文章聚合"
msgstr ""
#: inc/theme-widgets.php:314
#: inc/theme-widgets.php:373
msgid "展示最热、随机、最新文章的工具"
msgstr ""
#: inc/theme-widgets.php:328 inc/theme-widgets.php:333
#: inc/theme-widgets.php:388 inc/theme-widgets.php:393
#: inc/theme-widgets.php:444
msgid "最新"
msgstr ""
#: inc/theme-widgets.php:329 inc/theme-widgets.php:334
#: inc/theme-widgets.php:389 inc/theme-widgets.php:394
#: inc/theme-widgets.php:445
msgid "热点"
msgstr ""
#: inc/theme-widgets.php:372
#: inc/theme-widgets.php:434 inc/theme-widgets.php:497
msgid "展示数量:"
msgstr ""
#: inc/theme-widgets.php:376
#: inc/theme-widgets.php:438
msgid "统计天数:"
msgstr ""
#: inc/theme-widgets.php:442
msgid "默认显示:"
msgstr ""
#: inc/theme-widgets.php:459
msgid "最近评论"
msgstr ""
#: inc/theme-widgets.php:460
msgid "展示站点最近的评论"
msgstr ""
#: inc/theme-widgets.php:493
msgid "栏目标题:"
msgstr ""
#: inc/update-checker/Puc/v4p10/Plugin/Ui.php:54
msgid "View details"
msgstr ""