使用评论说说

This commit is contained in:
浪子 2024-06-07 14:28:35 +08:00
parent 9d4433a74d
commit f44fd96544
5 changed files with 460 additions and 26 deletions

View File

@ -54,31 +54,6 @@
</g>
</svg><?php $this->commentsNum(_t('0'), _t('1'), _t('%d')); ?>
</h3>
<ol class="commentlist sulliComment--list"></ol>
<?php if ($comments->have()): ?>
<?php $comments->listComments(); ?>
<?php
$comments->pageNav(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10.8284 12.0007L15.7782 16.9504L14.364 18.3646L8 12.0007L14.364 5.63672L15.7782 7.05093L10.8284 12.0007Z" fill="var(--main)"></path></svg>',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13.1714 12.0007L8.22168 7.05093L9.63589 5.63672L15.9999 12.0007L9.63589 18.3646L8.22168 16.9504L13.1714 12.0007Z" fill="var(--main)"></path></svg>',
1,
'...',
array(
'wrapTag' => 'div',
'wrapClass' => 'pagination_page',
'itemTag' => '',
'textTag' => 'a',
'currentClass' => 'active',
'prevClass' => 'prev',
'nextClass' => 'next'
)
);
?>
<?php else: ?>
<center><h3><?php _e('暂无评论'); ?></h3></center>
<?php endif; ?>
<div id="<?php $this->respondId(); ?>" class="comment-respond">
<div class="cancel-comment-reply cancel-comment-reply-link"><?php $comments->cancelReply(); ?></div>
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form" class="comment-form">
@ -112,6 +87,29 @@
<?php else: ?>
<?php _e(''); ?>
<?php endif; ?>
<ol class="commentlist sulliComment--list"></ol>
<?php if ($comments->have()): ?>
<?php $comments->listComments(); ?>
<?php
$comments->pageNav(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10.8284 12.0007L15.7782 16.9504L14.364 18.3646L8 12.0007L14.364 5.63672L15.7782 7.05093L10.8284 12.0007Z" fill="var(--main)"></path></svg>',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13.1714 12.0007L8.22168 7.05093L9.63589 5.63672L15.9999 12.0007L9.63589 18.3646L8.22168 16.9504L13.1714 12.0007Z" fill="var(--main)"></path></svg>',
1,
'...',
array(
'wrapTag' => 'div',
'wrapClass' => 'pagination_page',
'itemTag' => '',
'textTag' => 'a',
'currentClass' => 'active',
'prevClass' => 'prev',
'nextClass' => 'next'
)
);
?>
<?php else: ?>
<center><h3><?php _e('暂无评论'); ?></h3></center>
<?php endif; ?>
<?php $this->options->twikoo(); ?>
</div>
<?php
@ -142,7 +140,6 @@ function threadedComments($comments, $options) {
<?php else: ?>
<?php echo $comments->gravatar('40', ''); ?>
<?php endif; ?>
</div>
<div class="comment--meta">
<div class="comment--author"><?php echo $comments->author; ?><span class="dot"></span>

18
page-times.php Normal file
View File

@ -0,0 +1,18 @@
<?php
/**
* 说说页面 - 时光机
*
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<section class="site--main">
<header class="archive--header">
<h1 class="post--single__title"><?php $this->title() ?></h1>
<h2 class="post--single__subtitle"><?php $this->content(); ?> </h2>
</header>
<article class="post--single">
<?php $this->need('times/dycomment.php'); ?>
</article>
</section>
<?php $this->need('footer.php'); ?>

56
times/Content.php Normal file
View File

@ -0,0 +1,56 @@
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
class Content
{
public static function postCommentContent($content, $isLogin, $rememberEmail, $currentEmail, $parentEmail, $isTime = false)
{
//解析私密评论
$flag = true;
if (strpos($content, '[secret]') !== false) {//提高效率,避免每篇文章都要解析
$pattern = self::get_shortcode_regex(array('secret'));
$content = preg_replace_callback("/$pattern/", array('Content', 'secretContentParseCallback'), $content);
if ($isLogin || ($currentEmail == $rememberEmail && $currentEmail != "") || ($parentEmail == $rememberEmail && $rememberEmail != "")) {
$flag = true;
} else {
$flag = false;
}
}
if ($flag) {
$content = Content::parseContentPublic($content);
return $content;
} else {
if ($isTime) {
return '<div class="hideContent">此条为私密说说,仅发布者可见</div>';
} else {
return '<div class="hideContent">该评论仅登录用户及评论双方可见</div>';
}
}
}
/**
* 解析时光机页面的评论内容
* @param $content
* @return string
*/
public static function timeMachineCommentContent($content)
{
return Content::parseContentPublic($content);
}
/**
* 一些公用的解析,文章、评论、时光机公用的,与用户状态无关
* @param $content
* @return null|string|string[]
*/
public static function parseContentPublic($content)
{
$options = Helper::options();
//倒计时
if (strpos($content, '[countdown') !== false) {
$pattern = self::get_shortcode_regex(array('countdown'));
$content = preg_replace_callback("/$pattern/", array('Content', 'countdownParseCallback'),
$content);
}
return $content;
}
}

256
times/UA.php Normal file
View File

@ -0,0 +1,256 @@
<?php
class UA{
public $ua;
public function __construct($ua = '')
{
$this->ua = $ua;
}
public function returnBrowser(){
$ua = $this->ua;
if(preg_match('/rv:(11.0)/i', $ua, $matches)){
$title = 'Internet Explorer '. $matches[1];
$icon = 'fa fa-internet-explorer';//ie11
}elseif (preg_match('#MSIE ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Internet Explorer '. $matches[1];
if ( strpos($matches[1], '7') !== false || strpos($matches[1], '8') !== false)
$icon = 'fa fa-internet-explorer';//ie8
elseif ( strpos($matches[1], '9') !== false)
$icon = 'fa fa-internet-explorer';//ie9
elseif ( strpos($matches[1], '10') !== false)
$icon = 'fa fa-internet-explorer';//ie10
}elseif (preg_match('#Edge/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Edge '. $matches[1];
$icon = 'fa fa-edge';
}elseif (preg_match('#TheWorld ([a-zA-Z0-9.]+)#i', $ua, $matches)){
$title = 'TheWorld(世界之窗) '. $matches[1];
$icon = 'iconfont icon-theworld';
}elseif (preg_match('#JuziBrowser#i', $ua, $matches)){
$title = 'Juzi(桔子) '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#KBrowser#i', $ua, $matches)){
$title = 'KBrowser(超快) '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#MyIE#i', $ua, $matches)){
$title = 'MyIE(蚂蚁) '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#(Firefox|Phoenix|Firebird|BonEcho|GranParadiso|Minefield|Iceweasel)/([a-zA-Z0-9.]+)#i', $ua, $matches)){
$title = 'Firefox '. $matches[1];
$icon = 'fa fa-firefox';
}elseif (preg_match('#CriOS/([a-zA-Z0-9.]+)#i', $ua, $matches)){
$title = 'Chrome for iOS '. $matches[1];
$icon = 'fa fa-chrome';
} elseif (preg_match('#LBBROWSER#i', $ua, $matches)) {
$title = '猎豹';
$icon = 'iconfont icon-liebaoliulanqi';
}elseif (preg_match('#Opera.(.*)Version[ /]([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Opera '. $matches[2];
$icon = 'fa fa-opera';
if (preg_match('#opera mini#i', $ua))
$title = 'Opera Mini '. $matches[2];
}elseif (preg_match('#Maxthon( |\/)([a-zA-Z0-9.]+)#i', $ua,$matches)) {
$title = 'Maxthon(遨游) '. $matches[2];
$icon = 'iconfont icon-liulanqi-aoyou';
}elseif (preg_match('#360([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '360 Browser '. $matches[1];
$icon = 'iconfont icon-liulanqi-jisu';
}elseif (preg_match('#SE 2([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'SouGou Browser 2 '.$matches[1];
$icon = 'iconfont icon-liulanqi-sougou';
}elseif (preg_match('#QQBrowser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'QQBrowser '.$matches[1];
$icon = 'iconfont icon-QQliulanqi';
if (preg_match('#Mobile MQQBrowser/([a-zA-Z0-9.]+)#i', $ua,$matches)) {
$title = 'Mobile MQQBrowser '. $matches[1];
$icon = 'fa fa-qq';
}elseif (preg_match('#MicroMessenger/([a-zA-Z0-9.]+)#i', $ua,$matches)) {
$title = 'Wechat Browser '. $matches[1];
$icon = 'weixin';
}
}elseif (preg_match('#QQ/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'QQ '.$matches[1];
$icon = 'fa fa-qq';
}elseif (preg_match('#YYE/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'YYE '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#115Browser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '115 '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#37abc/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '37abc '.$matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#TheWorld ([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '世界之窗 '.$matches[1];
$icon = 'iconfont icon-theworld';
}elseif (preg_match('#UCWEB([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'UCWEB '. $matches[1];
$icon = 'icon-win8 icon-ucliulanqi';
}elseif (preg_match('#UBrowser/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'UBrowser '. $matches[1];
$icon = 'iconfont icon-ucliulanqi';
}elseif (preg_match('#Quark/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Quark '. $matches[1];
$icon = 'iconfont icon-ucliulanqi'; //
}elseif (preg_match('#2345Explorer/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = '2345Explorer '. $matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('#XiaoMi/MiuiBrowser/([0-9.]+)#i', $ua, $matches)) {
$title = '小米 '. $matches[1];
$icon = 'iconfont icon-xiaomi';
}elseif (preg_match('/WeiBo/i', $ua, $matches)) {
$title = '微博 '. $matches[1];
$icon = 'iconfont icon-weibo';
}elseif (preg_match('/BIDU/i', $ua, $matches)) {
$title = '百度 '. $matches[1];
$icon = 'iconfont icon-setting';
}elseif (preg_match('/mailapp/i', $ua, $matches)) {
$title = 'EmailApp '. $matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('/Sleipnir/i', $ua, $matches)) {
$title = '神马 '. $matches[1];
$icon = 'iconfont icon-weibiaoti--';
}elseif (preg_match('/MZBrowser/i', $ua, $matches)) {
$title = '魅族 '. $matches[1];
$icon = 'iconfont icon-meizu';
}elseif (preg_match('/VivoBrowser/i', $ua, $matches)) {
$title = 'Vivo '. $matches[1];
$icon = 'iconfont icon-VIVO';
}elseif (preg_match('/mixia/i', $ua, $matches)) {
$title = '米侠 '. $matches[1];
$icon = 'fa fa-globe';
}elseif (preg_match('/CoolMarket/i', $ua, $matches)) {
$title = '酷安 '. $matches[1];
$icon = 'iconfont icon-coolapk';
}elseif (preg_match('/YaBrowser/i', $ua, $matches)) {
$title = 'Yandex '. $matches[1];
$icon = 'iconfont icon-yandex';
}elseif (preg_match('/Kraitnabo\/([^\s|;]+)/i', $ua, $matches)) {
$title = '南博 '. $matches[1];
$icon = 'anzhuo';
}elseif (preg_match('#Chrome/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Google Chrome '. $matches[1];
$icon = 'fa fa-chrome';
if (preg_match('#OPR/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Opera '. $matches[1];
$icon = 'fa fa-opera';
}
}elseif (preg_match('#Safari/([a-zA-Z0-9.]+)#i', $ua, $matches)) {
$title = 'Safari '. $matches[1];
$icon = 'fa fa-safari';
}
return array("title"=>$title,
"icon"=>$icon);
}
public function returnOS(){
$ua = $this->ua;
$title = "未知浏览器";
$icon = "";
if (preg_match('/win/i', $ua)) {
if (preg_match('/Windows NT 6.1/i', $ua)) {
$title = "Windows 7";
$icon = "iconfont icon-win";
}elseif (preg_match('/Windows 98/i', $ua)) {
$title = "Windows 98";
$icon = "iconfont icon-win2";
}elseif (preg_match('/Windows NT 5.0/i', $ua)) {
$title = "Windows 2000";
$icon = "iconfont icon-win2";
}elseif (preg_match('/Windows NT 5.1/i', $ua)) {
$title = "Windows XP";
$icon = "iconfont icon-win";
}elseif (preg_match('/Windows NT 5.2/i', $ua)) {
if (preg_match('/Win64/i', $ua)) {
$title = "Windows XP 64 bit";
} else {
$title = "Windows Server 2003";
}
$icon = 'iconfont icon-win';
}elseif (preg_match('/Windows NT 6.0/i', $ua)) {
$title = "Windows Vista";
$icon = "fa fa-windows";
}elseif (preg_match('/Windows NT 6.2/i', $ua)) {
$title = "Windows 8";
$icon = "iconfont icon-win8";
}elseif (preg_match('/Windows NT 6.3/i', $ua)) {
$title = "Windows 8.1";
$icon = "iconfont icon-win8";
}elseif (preg_match('/Windows NT 10.0/i', $ua)) {
$title = "Windows 10";
$icon = "iconfont icon-win3";
}elseif (preg_match('/Windows Phone/i', $ua)) {
$matches = explode(';',$ua);
$title = $matches[2];
$icon = "iconfont icon-winphone";
}
} elseif (preg_match('#iPod.*.CPU.([a-zA-Z0-9.( _)]+)#i', $ua, $matches)) {
$title = "iPod ";//.$matches[1]
$icon = "iconfont icon-ipod";
} elseif (preg_match('/iPhone OS ([_0-9]+)/i', $ua, $matches)) {
$title = "Iphone ";//.$matches[1]
$icon = "iconfont icon-iphone";
} elseif (preg_match('/iPad; CPU OS ([_0-9]+)/i', $ua, $matches)) {
$title = "iPad ";//.$matches[1]
$icon = "iconfont icon-ipad";
} elseif (preg_match('/Mac OS X ([0-9_]+)/i', $ua, $matches)) {
if(count(explode(7,$matches[1]))>1) $matches[1] = 'Lion '.$matches[1];
elseif(count(explode(8,$matches[1]))>1) $matches[1] = 'Mountain Lion '.$matches[1];
$title = "Mac OSX";
$icon = "iconfont icon-macosdeicon";
} elseif (preg_match('/Macintosh/i', $ua)) {
$title = "Mac OS";
$icon = "iconfont icon-iconmacos";
} elseif (preg_match('/CrOS/i', $ua)){
$title = "Google Chrome OS";
$icon = "iconfont icon-iconchromeos";
} elseif (preg_match('/Linux/i', $ua)) {
$title = 'Linux';
$icon = 'fa fa-linux';
if (preg_match('/Ubuntu/i', $ua)) {
$title = "Ubuntu Linux";
$icon = "iconfont icon-ubuntu";
}elseif(preg_match('#Debian#i', $ua)) {
$title = "Debian GNU/Linux";
$icon = "iconfont icon-debian";
}elseif (preg_match('#Fedora#i', $ua)) {
$title = "Fedora Linux";
$icon = "iconfont icon-fedora";
}elseif (preg_match('/Kraitnabo\/([^\s|;]+)/i', $ua, $matches)) {
$title = '南博app '. $matches[1];
$icon = 'anzhuo';
}elseif (preg_match('/Android.([0-9. _]+)/i',$ua, $matches)) {
$title= "Android";
$icon = "iconfont icon-android";
}
} elseif (preg_match('/Android.([0-9. _]+)/i',$ua, $matches)) {
$title= "Android";
$icon = "iconfont icon-android";
}
return array("title"=>$title,
"icon"=>$icon);
}
/**
* 时光机页面ua如果是手机设备只显示设备类型如果是电脑设备只显示电脑设备类型如果是扩展发送显示发送自「扩展」如果是微信公众号显示
*/
public function returnTimeUa(){
if ($this->ua == "weixin" || $this->ua == "weChat"){
return array("title"=>("微信公众号"),
"icon"=>"weixin");
}elseif ($this->ua == "crx"){
return array("title"=>("Chrome扩展"),
"icon"=>"liulanqi");
}elseif ($this->ua == "yearcross"){
return array("title"=>("YearCross"),
"icon"=>"QQ");
}elseif ($this->ua == "Kraitnabo"){
return array("title"=>("南博app"),
"icon"=>"anzhuo");
}elseif ($this->ua == "python"){
return array("title"=>("python脚本"),
"icon"=>"python");
}else{
$ua = $this->returnOS();
$ua["icon"] = "anzhuo";
return $ua;
}
}
}

107
times/dycomment.php Normal file
View File

@ -0,0 +1,107 @@
<?php
require_once 'UA.php';
require_once 'Content.php';
if ($this->user->hasLogin()){
$GLOBALS['isLogin'] = true;
}else{
$GLOBALS['isLogin'] = false;
}
function threadedComments($comments, $options)
{
$db = Typecho_Db::get();
?>
<article class='post--item post--item__status'>
<div class='content'>
<header>
<?php $ua = new UA($comments->agent); ?>
<div class="comment--avatar"><?php echo $comments->gravatar('48', ''); ?></div>
<?php $comments->author(); ?>
<span class="dot"></span>
<p class="humane--time"><?php $comments->date('Y年m月d日 H:i'); ?></p>
<span class="dot"></span>
<?php echo "发自" . $ua->returnTimeUa()['title'];?>
</header>
<div class="description" itemprop="about">
<?php echo Content::postCommentContent(Content::timeMachineCommentContent($comments->text),$GLOBALS['isLogin'] ,"","","",true); ?>
</div>
</div>
</article>
<?php } ?>
<?php $this->comments()->to($comments); ?>
<input type="hidden" class="j-comment-url" value="<?php $this->commentUrl() ?>">
<?php if ($this->user->hasLogin()) : ?>
<div class="respond" id="comments">
<div class="comments--title">有什么新鲜事想告诉大家?</div>
<form method="post" id="textarea" class="comment-form" action="<?php $this->commentUrl() ?>">
<p class="comment-form-comment">
<textarea name="text" id="j-dynamic-form-text" class="textarea" autocomplete="off" rows="3" placeholder="发表您的新鲜事儿..."></textarea>
<input type="hidden" value="<?php $this->user->screenName(); ?>" name="author" />
<input type="hidden" value="<?php $this->user->mail(); ?>" name="mail" />
<input type="hidden" value="<?php $this->options->siteUrl(); ?>" name="url" />
<input type="hidden" name="_" value="<?php Typecho_Widget::widget('Widget_Security')->to($security);
echo $security->getToken($this->request->getRequestUrl()); ?>">
</p>
<p class="form-submit">
<button type="submit" class="submit"><?php _e('发表Ctrl+Enter'); ?></button>
</p>
</form>
</div>
<?php endif; ?>
<?php $comments->listComments(['commentUrl'=>$this->commentUrl,'class'=>$this]); ?>
<?php
$comments->pageNav(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10.8284 12.0007L15.7782 16.9504L14.364 18.3646L8 12.0007L14.364 5.63672L15.7782 7.05093L10.8284 12.0007Z" fill="var(--main)"></path></svg>',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13.1714 12.0007L8.22168 7.05093L9.63589 5.63672L15.9999 12.0007L9.63589 18.3646L8.22168 16.9504L13.1714 12.0007Z" fill="var(--main)"></path></svg>',
1,
'...',
array(
'wrapTag' => 'div',
'wrapClass' => 'pagination_page',
'itemTag' => '',
'textTag' => 'a',
'currentClass' => 'active',
'prevClass' => 'prev',
'nextClass' => 'next'
)
);
?>
<style>
/* 分页 */
.pagination_page{
display: flex;
align-items: center;
justify-content: center;
margin-top: var(--margin);
gap: 0.5rem;
}
.pagination_page li.active a {
background: var(--theme);
color: #fff;
font-weight: 500;
}
.pagination_page a{
display: flex;
padding: 0.5rem;
font-size: 0.9rem;
width: 1.75rem;
height: 1.75rem;
background: var(--background);
border-radius: 50%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
transition: 0.2s;
-webkit-transition: 0.2s;
justify-content: center;
align-items: center;
letter-spacing: 0;
}
.pagination_page span.next{
cursor: pointer;
}
.pagination_page li.active a:hover{
cursor: not-allowed;
}
/* 分页 */
</style>