From 7a5d98134c7b24b395e4685708c487b39ac0d2eb Mon Sep 17 00:00:00 2001 From: wehaox <wehaox@gmail.com> Date: Thu, 2 Mar 2023 19:49:58 +0800 Subject: [PATCH] update 1.7.5 --- comments.php | 7 ++++++- css/style.css | 2 +- functions.php | 54 +++++++++++++++++++++++++++++++++++++++++++----- header_com.php | 2 +- index.php | 4 ++-- post_sidebar.php | 7 ++++--- sidebar.php | 4 +++- 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/comments.php b/comments.php index f4eb11e..21a0c95 100644 --- a/comments.php +++ b/comments.php @@ -43,7 +43,12 @@ <div class="commentsFormArea" style="text-align: right;"> <button class="submit" type="submit" ><?php _e('评论'); ?></button> </div> - <?php if($this->options->siteKey !== "" && $this->options->siteKey !== ""){RecapOutPut($this->user->hasLogin()) ;?><script>$(document).ready(function(){if($("#comment_keys").length == 0){$(".g-recaptcha").css({"position":"relative","top":"-40px"})}})</script> <?php }?> + <?php if($this->options->siteKey !== "" && $this->options->siteKey !== ""){RecapOutPut($this->user->hasLogin()) ;?><script>$(document).ready(function(){if($("#comment_keys").length == 0){$(".g-recaptcha").css({"position":"relative","top":"-40px"})}})</script> <?php }?> + + <?php if($this->options->hcaptchaSecretKey !== "" && $this->options->hcaptchaAPIKey !== ""){ + RecapOutPut($this->user->hasLogin());?> + <script>$(document).ready(function(){if($("#comment_keys").length == 0){$(".h-captcha").css({"position":"relative","top":"-40px"})}})</script> + <?php }?> </form> <?php if(!$this->user->hasLogin() && $this->options->EnableCommentsLogin === 'on'): ?> <div id="comment_login" style="display:none"> diff --git a/css/style.css b/css/style.css index 2fb937e..3666e4a 100644 --- a/css/style.css +++ b/css/style.css @@ -531,7 +531,7 @@ code[class*="language-"], pre[class*="language-"] { } /*懒加载结束*/ .comment-ua .iconfont{font-size: 14px!important;} -.g-recaptcha {transform:scale(0.77);transform-origin:0 0;margin-top:10px;} +.g-recaptcha,.h-captcha {transform:scale(0.77);transform-origin:0 0;margin-top:10px;} .OwO-logo{border:none!important;background:none!important} .OwO-logo span .iconfont{font-size:25px} diff --git a/functions.php b/functions.php index 379114e..855a0fb 100644 --- a/functions.php +++ b/functions.php @@ -288,6 +288,7 @@ function themeConfig($form) { $sidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('sidebarBlock', array( + 'ShowAuthorInfo' => _t('显示作者信息'), 'ShowAnnounce' => _t('显示公告'), 'ShowRecentPosts' => _t('显示最新文章'), 'ShowRecentComments' => _t('显示最近回复'), @@ -299,7 +300,7 @@ function themeConfig($form) { 'ShowMobileSide' => _t('手机端显示侧栏'), 'ShowWeiboHot' => _t('显示微博热搜') ), - array('ShowAnnounce','ShowRecentPosts', 'ShowRecentComments', 'ShowCategory','ShowTag', 'ShowArchive', 'ShowWebinfo', 'ShowOther','ShowMobileSide'), _t('侧边栏显示')); + array('ShowAuthorInfo','ShowAnnounce','ShowRecentPosts', 'ShowRecentComments', 'ShowCategory','ShowTag', 'ShowArchive', 'ShowWebinfo', 'ShowOther','ShowMobileSide'), _t('侧边栏显示')); $sidebarBlock->setAttribute('id', 'aside'); $form->addInput($sidebarBlock->multiMode()); // 在线人数显示 @@ -320,14 +321,14 @@ function themeConfig($form) { // 文章侧边栏设置 $PostSidebarBlock = new Typecho_Widget_Helper_Form_Element_Checkbox('PostSidebarBlock', array( - // 'ShowAuthorInfo' => _t('显示作者信息'), - // 'ShowAnnounce' => _t('显示公告'), + 'ShowAuthorInfo' => _t('显示作者信息'), + 'ShowAnnounce' => _t('显示公告'), 'ShowRecentPosts' => _t('显示最新文章'), 'ShowWebinfo' => _t('显示网站咨询'), 'ShowOther' => _t('显示其它杂项'), 'ShowWeiboHot' => _t('显示微博热搜') ), - array('ShowRecentPosts', 'ShowWebinfo', 'ShowOther'), _t('文章侧边栏显示'),_t('说明:单独设置文章内侧栏')); + array('ShowAuthorInfo','ShowAnnounce','ShowRecentPosts', 'ShowWebinfo', 'ShowOther'), _t('文章侧边栏显示'),_t('说明:单独设置文章内侧栏')); $form->addInput($PostSidebarBlock->multiMode()); // 美化选项 @@ -567,6 +568,21 @@ function themeConfig($form) { $secretKey = new Typecho_Widget_Helper_Form_Element_Text('secretKey', NULL, null, _t('Serect Key for reCAPTCHAv2:'), _t('填写两处密钥评论区自动开启谷歌验证码')); $form->addInput($siteKey); $form->addInput($secretKey); + + + $hcaptchaSecretKey = new Typecho_Widget_Helper_Form_Element_Text('hcaptchaSecretKey', + NULL, + null, + '<hr> 评论区hcaptch人机验证 <br> 密钥(sietkey)- 使用它作为 secret 来检查用户令牌:', + '<a href="https://dashboard.hcaptcha.com/welcome">点击获取密钥</a>' + ); + + $hcaptchaAPIKey = new Typecho_Widget_Helper_Form_Element_Text('hcaptchaAPIKey', NULL, null, _t('API 密钥:'), _t('填写两处密钥评论区自动开启hcaptch人机验证')); + + $form->addInput($hcaptchaSecretKey); + $form->addInput($hcaptchaAPIKey); + + $db = Typecho_Db::get(); @@ -1183,7 +1199,9 @@ function themeInit($archive) { if(Helper::options()->siteKey !== "" && Helper::options()->secretKey !=="" && !$loginStatus){ comments_filter($archive); } - ; + if (Helper::options()->hcaptchaSecretKey !== "" && Helper::options()->hcaptchaAPIKey !== "" && !$loginStatus) { + hcaptcha_filter($archive); + } if ($archive->is('index')) { // echo '<script src="'..'"></script>'; } @@ -1730,8 +1748,12 @@ function RecapOutPut($login) { if ($siteKey !== "" && $secretKey !== "" && !$login) { echo '<script src="https://recaptcha.net/recaptcha/api.js" async defer data-no-instant></script> <div class="g-recaptcha" data-sitekey=' . $siteKey . '></div>'; + } + if (Helper::options()->hcaptchaSecretKey !== "" && Helper::options()->hcaptchaAPIKey !== "" && !$login) { + echo '<script src="https://www.hCaptcha.com/1/api.js" async defer></script><div class="h-captcha" data-sitekey='. Helper::options()->hcaptchaSecretKey .'></div>'; } } + function comments_filter($comment) { if (isset($_REQUEST['text']) != null) { if($_POST['g-recaptcha-response'] == null) { @@ -1768,6 +1790,28 @@ function getCaptcha($recaptcha_response, $secretKey) { return $comment; } + +function hcaptcha_filter($comment){ +if (isset($_REQUEST['text']) != null) { + if($_POST['h-captcha-response'] == null) { + throw new Typecho_Widget_Exception(_t('人机验证失败,确认你加载了hcaptcha人机验证并通过验证')); + }else{ + if(isset($_POST['h-captcha-response']) && !empty($_POST['h-captcha-response'])){ + $secret = Helper::options()->hcaptchaAPIKey; + $verifyResponse = file_get_contents('https://hcaptcha.com/siteverify?secret='.$secret.'&response='.$_POST['h-captcha-response'].'&remoteip='.$_SERVER['REMOTE_ADDR']); + $responseData = json_decode($verifyResponse); + if($responseData->success == true) + { + return $comments; + }else{ + throw new Typecho_Widget_Exception(_t($responseData->error-codes)); + } + } + } +} +return $comment; +} + // 微博热搜 function weibohot(){ $api = file_get_contents('https://weibo.com/ajax/side/hotSearch'); diff --git a/header_com.php b/header_com.php index 1a46765..b4fa755 100644 --- a/header_com.php +++ b/header_com.php @@ -22,7 +22,7 @@ <link rel="preconnect" href="//cdn.staticfile.org" /> <!--<link rel="stylesheet" href="https://gcore.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css">--> <link rel="stylesheet" href="<?php $this->options->themeUrl('index.css?v1.7.3'); ?>"> - <link rel="stylesheet" href="<?php $this->options->themeUrl('css/style.css?v1.7.3'); ?>"> + <link rel="stylesheet" href="<?php $this->options->themeUrl('css/style.css?v1.7.4'); ?>"> <!--魔改美化--> <?php if (!empty($this->options->beautifyBlock) && in_array('ShowBeautifyChange',$this->options->beautifyBlock)): ?> <link rel="stylesheet" href="<?php $this->options->themeUrl('css/custom.css?v1.5.9'); ?>"> diff --git a/index.php b/index.php index 21b0f2d..cc5b7eb 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ * <a href="https://www.wehaox.com">个人网站</a> | <a href="https://blog.wehaox.com/archives/typecho-butterfly.html">主题使用文档</a> * @package Typecho-Butterfly * @author b站:wehao- - * @version 1.7.4 + * @version 1.7.5 * @link https://space.bilibili.com/34174433 */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; @@ -112,7 +112,7 @@ function ver() {console.log(` # # # # # # # # # # # # ##### #### # # ###### # # # ###### # - 1.7.4 + 1.7.5 =================================================================== `);} </script> \ No newline at end of file diff --git a/post_sidebar.php b/post_sidebar.php index 62198d8..74affe1 100644 --- a/post_sidebar.php +++ b/post_sidebar.php @@ -1,5 +1,6 @@ <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <div class="aside-content" id="aside-content" role="complementary"> +<?php if (!empty($this->options->PostSidebarBlock) && in_array('ShowAuthorInfo', $this->options->PostSidebarBlock)): ?> <div class="card-widget card-info"> <div class="card-info-avatar is-center"> <div class="avatar-img"> @@ -46,7 +47,8 @@ <?php elseif(!$this->options->author_bottom) : ?> <?php endif; ?> </div> -<?php if (!empty($this->options->sidebarBlock) && in_array('ShowAnnounce', $this->options->sidebarBlock)): ?> +<?php endif; ?> +<?php if (!empty($this->options->PostSidebarBlock) && in_array('ShowAnnounce', $this->options->PostSidebarBlock)): ?> <div class="card-widget card-announcement"><div class="item-headline"> <i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div> <div class="announcement_content"><?php $this->options->announcement() ?></div></div> @@ -168,6 +170,5 @@ </div > </div> <?php endif; ?> - - </div> +</div> </div><!-- end #sidebar --> \ No newline at end of file diff --git a/sidebar.php b/sidebar.php index 7ebd184..e36a9ed 100644 --- a/sidebar.php +++ b/sidebar.php @@ -1,6 +1,7 @@ <?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> <div class="aside-content" id="aside-content"> - <div class="card-widget card-info"> + <?php if (!empty($this->options->sidebarBlock) && in_array('ShowAuthorInfo', $this->options->sidebarBlock)): ?> + <div class="card-widget card-info"> <div class="card-info-avatar is-center"> <div class="avatar-img"> <img data-lazy-src="<?php $this->options->logoUrl() ?>" onerror="this.onerror=null;this.src='/usr/themes/butterfly/img/friend_404.gif'" src="<?php echo GetLazyLoad() ?>" alt="avatar"> @@ -46,6 +47,7 @@ <?php elseif(!$this->options->author_bottom) : ?> <?php endif; ?> </div> + <?php endif; ?> <?php if (!empty($this->options->sidebarBlock) && in_array('ShowAnnounce', $this->options->sidebarBlock)): ?> <div class="card-widget card-announcement"><div class="item-headline"> <i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div>