From be86126aa68c0e645fd4d88f459201918ea29468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E8=90=BD?= Date: Thu, 26 Mar 2020 22:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/points/class-points-shortcodes.php | 6 +- class/wechat.php | 213 ++--------------------- framework/plugin-options.php | 6 +- functions/Common.php | 38 ++-- functions/advanced.php | 6 +- functions/security.php | 16 +- 6 files changed, 53 insertions(+), 232 deletions(-) diff --git a/class/points/class-points-shortcodes.php b/class/points/class-points-shortcodes.php index d45e6b4..53dc1f1 100644 --- a/class/points/class-points-shortcodes.php +++ b/class/points/class-points-shortcodes.php @@ -80,13 +80,13 @@ class GDK_Points_Shortcodes $notice .= ''; } else { if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) { - $notice .= '
付费内容'; + $notice .= '
付费内容'; $notice .= '

当前隐藏内容需要支付

' . $point . '金币'; $notice .= '

您当前拥有' . GDK_Points::get_user_total_points($user_id, 'accepted') . '金币,金币不足,请充值

'; $notice .= buy_points(); $notice .= '
'; } else { - $notice .= '
付费内容'; + $notice .= '
付费内容'; $notice .= '

当前隐藏内容需要支付

' . $point . '金币'; $notice .= '

您当前拥有' . GDK_Points::get_user_total_points($user_id, 'accepted') . '金币

'; $notice .= '

'; @@ -94,7 +94,7 @@ class GDK_Points_Shortcodes } } } else { - $notice .= '
付费内容'; + $notice .= '
付费内容'; $notice .= '

当前隐藏内容需要支付

' . $point . '金币'; $notice .= '

您当前尚未登陆,请登陆后查看

'; $notice .= weixin_login_btn(); diff --git a/class/wechat.php b/class/wechat.php index 5c29d5f..788adbf 100644 --- a/class/wechat.php +++ b/class/wechat.php @@ -1,5 +1,5 @@ MsgType); //取得消息类型 - $this->fromUser = "" . $object->FromUserName; //记录消息发送方(不是发送者的微信号,而是一个加密后的OpenID) - $this->toUser = "" . $object->ToUserName; //记录消息接收方(就是公共平台的OpenID) + $this->fromUser = $object->FromUserName; //记录消息发送方(不是发送者的微信号,而是一个加密后的OpenID) + $this->toUser = $object->ToUserName; //记录消息接收方(就是公共平台的OpenID) //如果回调函数没有设置,则退出 if (!is_callable($this->callback_function)) { return; } - //根据不同的消息类型,分别处理 - switch ($messgeType) { - case "text": //文本消息 - //调用回调函数 - call_user_func($this->callback_function, $this, "text", $object->Content, "", ""); - break; - case "event": //事件 - switch ($object->Event) { - case "subscribe": //订阅事件 - call_user_func($this->callback_function, $this, "subscribe", $object->FromUserName, "", ""); - break; - default: - //Unknow Event - break; - } - break; - default: - //Unknow msg type - break; + if ($messgeType == "text") { + call_user_func($this->callback_function, $this, "text", $object->Content, "", ""); } } @@ -158,41 +139,6 @@ class WeChat return $xmlText; } - /** - * 形成 图文消息响应值 - * - * @param string $toUser - * @param string $fromUser - * @param array $articles 一个array,每个元素保存一条图文信息;每个元素也是一个array, 有Title,Description,PicUrl,Url四个键值 - * - * @return string - */ - protected function _newsResponse($toUser, $fromUser, $articles) - { - $xmlTemplate = " - - - %s - - "; - $xmlText = sprintf($xmlTemplate, $toUser, $fromUser, time()); - $xmlText .= '' . count($articles) . ''; - $xmlText .= ''; - - foreach ($articles as $article) { - $xmlText .= ''; - $xmlText .= '<![CDATA[' . $article['Title'] . ']]>'; - $xmlText .= ''; - $xmlText .= ''; - $xmlText .= ''; - $xmlText .= ''; - } - - $xmlText .= ' '; - - return $xmlText; - } - /** * 发送文本内容 * @@ -203,51 +149,21 @@ class WeChat echo $this->textResponse($this->fromUser, $this->toUser, $content); } - /** - * 添加一条图文信息 - * - * @param string $title 标题 - * @param string $description 内容 - * @param string $url 网页链接URL - * @param string $pictureUrl 图片的URL - */ - public function addNews($title, $description, $url, $pictureUrl) - { - $article = array('Title' => $title, - 'Description' => $description, - 'PicUrl' => $pictureUrl, - 'Url' => $url); - $this->articles[] = $article; - } - - /** - * 发送图文信息 - * 用法:首先用addNews()函数一条一条地添加图文信息,添加完成后用本函数发送 - */ - public function sendNews() - { - echo $this->newsResponse($this->fromUser, $this->toUser, $this->articles); - } - } -define("WX_WELCOME", '欢迎关注极客公园'); //欢迎词 -define("POSTNUM", '5'); //文章数量 -define("DEFAULT_THUMB", ''); //封面 - -add_action('pre_get_posts', 'wm_preprocess', 4); +add_action('pre_get_posts', 'wx_preprocess', 4); /** * 预处理函数 * * @param $wp_query */ -function wm_preprocess($wp_query) +function wx_preprocess($wp_query) { global $object; $wx_token = trim(gdk_option('gdk_wxmp_token')); if (!isset($object)) { - //创建一个WeChat类的实例, 回调函数名称为"onMessage",即消息处理函数 - $object = new WeChat($wx_token, "onMessage"); + //创建一个WeChat类的实例, 回调函数名称为"CaptchaMessage",即消息处理函数 + $object = new WeChat($wx_token, "CaptchaMessage"); $object->process(); //处理消息 return; } @@ -262,113 +178,12 @@ function wm_preprocess($wp_query) * @param string $arg1 * @param string $arg2 */ -function onMessage(WeChat $object, $messageType, $content, $arg1, $arg2) +function CaptchaMessage(WeChat $object, $messageType, $content, $arg1, $arg2) { - - //处理subscribe消息 - switch ($messageType) { - case "subscribe": //当用户关注 - $object->addNews(WX_WELCOME, "", "", ""); - $object->sendNews(); - break; - case "text": - $keyword = trim($content); - switch ($keyword) { - case 'yzm': - case 'Yzm': - case 'yZm': - case 'yzM': - case 'YZM': - case '验证码': - $object->sendText('您的验证码为:【' . wx_captcha() . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请'); - break; - case 'r': - send_post($object, 'r'); - break; - case "help": - case "h": - case "?": - case "?": - case "???": - $object->sendText(WX_WELCOME); - break; - default: - send_post($object, 'r'); - break; - } - break; - default: - $object->sendText("暂无设置此功能"); //否则,显示出错信息 - } -} - -//获取博客文章 -function wm_query_posts($q, $s = "") -{ - global $wp_query; - $articles = []; - $query_base = array( - 'ignore_sticky_posts' => true, - 'posts_per_page' => POSTNUM, - 'post_status' => 'publish', - ); - if (empty($s)) { - switch ($q) { - case "n": - $query_more = array( - "order" => "DESC", - "orderby" => "date", - ); - break; - case "r": - $query_more = array( - "orderby" => "rand", - ); - break; - default: - $query_more = []; - break; - } - } else { - $query_more = array( - 's' => $s, - ); - } - $weixin_query_array = array_merge($query_base, $query_more); - $wp_query->query($weixin_query_array); - if (have_posts()) { - while (have_posts()) { - the_post(); - global $post; - $title = get_the_title(); - $excerpt = gdk_print_excerpt(120, $post, false); - $thumbnail_id = get_post_thumbnail_id($post->ID); - if ($thumbnail_id) { - $thumb = wp_get_attachment_image_src($thumbnail_id, 'full'); - $thumb = $thumb[0]; - } else { - $thumb = gdk_thumbnail_src(); - } - if (empty(DEFAULT_THUMB) && !empty(DEFAULT_THUMB)) { - $thumb = DEFAULT_THUMB; - } - $link = get_permalink(); - $articles[] = array($title, $excerpt, $link, $thumb); + if ($messageType == "text") { + $keyword = trim($content); + if (in_string($keyword, '验证码')) { + $object->sendText('您的验证码为:【' . wx_captcha() . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请'); } } - - return $articles; -} - -function send_post(WeChat $object, $type = '', $value = '') -{ - $articles = wm_query_posts($type, $value); - if (empty($articles)) { - $no_post = '暂无相关文章'; - $object->sendText($no_post); - } - foreach ($articles as $v) { - $object->addNews($v['0'], $v['1'], $v['2'], $v['3']); - } - $object->sendNews(); } diff --git a/framework/plugin-options.php b/framework/plugin-options.php index 407c834..698108d 100644 --- a/framework/plugin-options.php +++ b/framework/plugin-options.php @@ -380,9 +380,9 @@ jQuery(function ($) { function(a) { a = $.trim(a); if (a == '200') { - alert("测试成功,您的SMTP邮箱邮件发送已成功,Enjoy it"); + alert("测试成功,您的SMTP邮箱邮件发送已成功,Enjoy it"); }else{ - alert("测试失败,您的SMTP邮箱邮件响应失败,请重试"); + alert("测试失败,您的SMTP邮箱邮件响应失败,请重试"); } }); }); @@ -401,7 +401,7 @@ jQuery(function ($) { $(".install_new_version").show(); } }else{ - $(".get_new_version").after("检测失败,网络错误"); + $(".get_new_version").after("检测失败,网络错误"); } }); }); diff --git a/functions/Common.php b/functions/Common.php index 1855f0a..9925eaf 100644 --- a/functions/Common.php +++ b/functions/Common.php @@ -759,17 +759,17 @@ function gdk_panlinks($links) //一个简单可重复使用的邮件模板 function mail_temp($mail_title, $mail_cotent, $link, $link_title) { - ?> -
-
-
- + + $content = '
+
' . $mail_title . '
+
' . $mail_cotent . '
+ ' . $link_title . '

本邮件为系统自动发送,请勿回复。
- 如果不想被此类邮件打扰,请前往 留言说明,由我们来操作处理。 -
-
- ' . get_option('blogname') . ' 留言说明,由我们来操作处理。 +
'; + + return $content; } //获取所有站点分类id,带缓存 @@ -829,10 +829,12 @@ function gdk_thumbnail_src() { global $post; $gdk_thumbnail_src = ''; - if ($values = get_post_custom_values('gdk_thumb')) { //输出自定义域图片地址 + if ($values = get_post_custom_values('gdk_thumb')) { + //输出自定义域图片地址 $values = get_post_custom_values('gdk_thumb'); $gdk_thumbnail_src = $values[0]; - } elseif (has_post_thumbnail()) { //如果有特色缩略图,则输出缩略图地址 + } elseif (has_post_thumbnail()) { + //如果有特色缩略图,则输出缩略图地址 $thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full'); $gdk_thumbnail_src = $thumbnail_src[0]; } else { @@ -840,7 +842,8 @@ function gdk_thumbnail_src() ob_end_clean(); $output = preg_match_all('//i', $post->post_content, $matches); $gdk_thumbnail_src = $matches[1][0]; //获取该图片 src - if (empty($gdk_thumbnail_src)) { //如果日志中没有图片,则显示随机图片 + if (empty($gdk_thumbnail_src)) { + //如果日志中没有图片,则显示随机图片 $random = mt_rand(1, 12); $gdk_thumbnail_src = GDK_BASE_URL . 'assets/img/thumb/' . $random . '.jpg'; } @@ -861,7 +864,8 @@ function gdk_thumbnail_src() function gdk_thumb_img($way, $width, $height, $style = '', $atrr = 'class="thumb_img"') { $url = gdk_thumbnail_src(); - if ($way === 1) { //cdn + if ($way === 1) { + //cdn $src = $url . '!' . $style; } elseif ($way === 2) { $src = GDK_BASE_URL . 'public/timthumb.php?src=' . $url . '&h=' . $height . '&w=' . $width . '&q=90&zc=1&ct=1'; @@ -1028,7 +1032,8 @@ function payjs_notify() //充值按钮 function buy_points() { - if (is_user_logged_in()) { //logined + if (is_user_logged_in()) { + //logined $result = ' 点击充值 '; - } else { // no login + } else { + // no login $result = '
本页面需要您登录才可以操作,请先 ' . weixin_login_btn() . ' 或者立即注册
'; } return $result; @@ -1322,4 +1328,4 @@ function blank_open() echo 'target="_blank"'; } -} \ No newline at end of file +} diff --git a/functions/advanced.php b/functions/advanced.php index 44758ad..23a8b70 100644 --- a/functions/advanced.php +++ b/functions/advanced.php @@ -163,14 +163,14 @@ function gdk_link_go($content) //邮箱SMTP设置 function gdk_smtp($phpmailer) { - $phpmailer->FromName = gdk_option('gdk_smtp_mail'); //邮箱地址 + $phpmailer->FromName = gdk_option('gdk_smtp_username'); //邮箱地址 $phpmailer->Host = gdk_option('gdk_smtp_host'); //服务器地址 $phpmailer->Port = gdk_option('gdk_smtp_port'); //端口 - $phpmailer->Username = gdk_option('gdk_smtp_username'); //昵称 + $phpmailer->Username = gdk_option('gdk_smtp_mail'); //昵称 $phpmailer->Password = gdk_option('gdk_smtp_password'); //密码 $phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址 $phpmailer->SMTPAuth = true; - $phpmailer->SMTPSecure = 'ssl'; + $phpmailer->SMTPSecure = 'ssl'; $phpmailer->IsSMTP(); } diff --git a/functions/security.php b/functions/security.php index 9958f93..130845f 100644 --- a/functions/security.php +++ b/functions/security.php @@ -321,7 +321,7 @@ function log_login($username, $password) if (is_wp_error($check)) { $ua = getBrowser(); - $agent = $ua['name'] . " " . $ua['version']; + $agent = $ua['name']; $referrer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : $_SERVER['PHP_SELF']; if (strstr($referrer, 'wp-login')) { @@ -334,7 +334,7 @@ function log_login($username, $password) $contact_errors = false; // get the posted data - $name = "WordPress " . get_bloginfo('name'); + $name = get_bloginfo('name'); $email_address = get_bloginfo('admin_email'); // write the email content @@ -342,23 +342,23 @@ function log_login($username, $password) $header .= "Content-Type: text/html; charset=utf-8\n"; $header .= "From: $name <$email_address>\n"; - $message = "Failed login attempt on " . $name . "
" . PHP_EOL; - $message .= 'IP: ' . gdk_get_ip() . "
" . PHP_EOL; - $message .= 'WhoIs: ' . gdk_get_ip() . "
" . PHP_EOL; + $message = "" . $name . " 登陆失败提醒
" . PHP_EOL; + $message .= "Browser: " . $agent . "
" . PHP_EOL; $message .= "OS: " . $ua['platform'] . "
" . PHP_EOL; + $message .= 'IP: '. gdk_get_ip() . '
' . PHP_EOL; $message .= "Date: " . date('Y-m-d H:i:s') . "
" . PHP_EOL; $message .= "Referrer: " . $referrer . "
" . PHP_EOL; $message .= "User Agent: " . $ua['userAgent'] . "
" . PHP_EOL; $message .= "Username: " . $username . "
" . PHP_EOL; $message .= "Password: " . $password . "
" . PHP_EOL; - $subject = "Failed login attempt - " . $name; - $subject = "=?utf-8?B?" . base64_encode($subject) . "?="; + $subject = "登陆失败提醒 - " . $name; $to = $email_address; + $mail_content = mail_temp($subject, $message , home_url(), $name ); if (!empty($to)) { // send the email using wp_mail() - if (!wp_mail($to, $subject, $message, $header)) { + if (!wp_mail($to, $subject, $mail_content , $header)) { $contact_errors = true; } }