mirror of
https://github.com/yunluo/gdk.git
synced 2024-06-05 07:12:21 +02:00
更新一些东西
This commit is contained in:
parent
130aef4a60
commit
57182522ff
|
@ -86,6 +86,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
* 已经密码可见的自动从浏览器读取内容
|
||||
* 并显示,这里加个延时处理
|
||||
*/
|
||||
|
||||
(function () {
|
||||
if ($("#submit_pass_view").length > 0) { /**如果网站有密码可见,就执行 */
|
||||
setTimeout(function () {
|
||||
|
@ -94,7 +95,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
for (var i = 0; i < length; i++) {
|
||||
var key = localStorage.key(i),
|
||||
value = localStorage.getItem(key);
|
||||
if (key.indexOf(id) >= 0) { /**发现目标 */
|
||||
if (key.indexOf(id) >= 0) { /*发现目标 */
|
||||
show_hide_content('.pass_viewbox', value);
|
||||
break;
|
||||
}
|
||||
|
@ -103,6 +104,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
}, 900);
|
||||
}
|
||||
}());
|
||||
|
||||
/**密码可见end */
|
||||
|
||||
|
||||
|
|
|
@ -9,4 +9,5 @@ include( 'updates.php' );//在线更新
|
|||
include( 'Payjs.php' );//支付功能
|
||||
include( 'points/points.php' );//积分功能
|
||||
|
||||
include( 'aq_resizer.php' );//缩略图功能
|
||||
include( 'aq_resizer.php' );//缩略图功能
|
||||
include( 'wechat.php' );//微信功能
|
387
class/wechat.php
Normal file
387
class/wechat.php
Normal file
|
@ -0,0 +1,387 @@
|
|||
<?php
|
||||
error_reporting(0);
|
||||
|
||||
/**
|
||||
* 微信(或易信)公共平台处理类
|
||||
*
|
||||
* 用于创建微信(或易信)公共平台服务
|
||||
*
|
||||
* @author: Specs
|
||||
* Email: specs@9iphp.com
|
||||
* Blog: http://www.9iphp.com
|
||||
*/
|
||||
class WeChat
|
||||
{
|
||||
|
||||
private $token = ""; //TOKEN值
|
||||
private $callback_function = NULL; //回调函数名称
|
||||
private $articles = array(); //图文信息array
|
||||
|
||||
public $debug = false; //是否调试状态
|
||||
public $fromUser = ""; //当前消息的发送者
|
||||
public $toUser = ""; //当前消息的接收者
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param string $token 设置在公共平台的TOKEN值
|
||||
* @param callable $callback_function_name 回调函数名称
|
||||
*/
|
||||
function __construct($token, $callback_function_name)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->callback_function = $callback_function_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查签名是否正确
|
||||
*
|
||||
* @return boolean 正确返回true,否则返回false
|
||||
*/
|
||||
private function checkSignature()
|
||||
{
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
|
||||
$token = $this->token;
|
||||
|
||||
$tmpArr = array($token, $timestamp, $nonce);
|
||||
sort($tmpArr, SORT_STRING);
|
||||
$tmpStr = implode($tmpArr);
|
||||
$tmpStr = sha1($tmpStr);
|
||||
|
||||
|
||||
if ($tmpStr == $signature)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名是否有效
|
||||
*/
|
||||
protected function valid()
|
||||
{
|
||||
$echoStr = $_GET["echostr"];
|
||||
//valid signature , option
|
||||
if ($this->checkSignature()) {
|
||||
echo $echoStr;
|
||||
exit;
|
||||
} else {
|
||||
echo 'error signature';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理来自微信服务器的消息
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
//如果是验证请求,则执行签名验证并退出
|
||||
if (!empty($_GET["echostr"])) {
|
||||
$this->valid(); //验证签名是否有效
|
||||
return; //返回退出
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
echo '';
|
||||
return;
|
||||
}
|
||||
|
||||
//如果不是验证请求,则
|
||||
//首先,取得POST原始数据(XML格式)
|
||||
//$postData = $GLOBALS["HTTP_RAW_POST_DATA"];
|
||||
$postData = file_get_contents('php://input');
|
||||
if (empty($postData)) {
|
||||
echo '';
|
||||
return;
|
||||
} //如果没有POST数据,则退出
|
||||
|
||||
|
||||
//解析POST数据(XML格式)
|
||||
$object = simplexml_load_string($postData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$messgeType = trim($object->MsgType); //取得消息类型
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 形成 文本消息响应值
|
||||
*
|
||||
* @param string $toUser
|
||||
* @param string $fromUser
|
||||
* @param string $content
|
||||
* @param integer $flag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function textResponse($toUser, $fromUser, $content, $flag = 0)
|
||||
{
|
||||
$xmlTemplate = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
<CreateTime>%s</CreateTime>
|
||||
<MsgType><![CDATA[text]]></MsgType>
|
||||
<Content><![CDATA[%s]]></Content>
|
||||
<FuncFlag>%d</FuncFlag>
|
||||
</xml>";
|
||||
|
||||
$xmlText = sprintf($xmlTemplate, $toUser, $fromUser, time(), $content, $flag);
|
||||
|
||||
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 = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
<CreateTime>%s</CreateTime>
|
||||
<MsgType><![CDATA[news]]></MsgType>
|
||||
";
|
||||
$xmlText = sprintf($xmlTemplate, $toUser, $fromUser, time());
|
||||
$xmlText .= '<ArticleCount>' . count($articles) . '</ArticleCount>';
|
||||
$xmlText .= '<Articles>';
|
||||
|
||||
foreach ($articles as $article) {
|
||||
$xmlText .= '<item>';
|
||||
$xmlText .= '<Title><![CDATA[' . $article['Title'] . ']]></Title>';
|
||||
$xmlText .= '<Description><![CDATA[' . $article['Description'] . ']]></Description>';
|
||||
$xmlText .= '<PicUrl><![CDATA[' . $article['PicUrl'] . ']]></PicUrl>';
|
||||
$xmlText .= '<Url><![CDATA[' . $article['Url'] . ']]></Url>';
|
||||
$xmlText .= '</item>';
|
||||
}
|
||||
|
||||
$xmlText .= '</Articles> </xml>';
|
||||
|
||||
return $xmlText;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送文本内容
|
||||
*
|
||||
* @param string $content 文本内容
|
||||
*/
|
||||
public function sendText($content)
|
||||
{
|
||||
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("TOKEN", 'wxcaptcha'); //TOKEN值
|
||||
define("WX_WELCOME", '欢迎关注极客公园'); //欢迎词
|
||||
define("POSTNUM", '5'); //文章数量
|
||||
define("DEFAULT_THUMB", '');//封面
|
||||
|
||||
|
||||
|
||||
add_action('pre_get_posts', 'wm_preprocess', 4);
|
||||
/**
|
||||
* 预处理函数
|
||||
*
|
||||
* @param $wp_query
|
||||
*/
|
||||
function wm_preprocess($wp_query)
|
||||
{
|
||||
global $object;
|
||||
if (!isset($object)) {
|
||||
//创建一个WeChat类的实例, 回调函数名称为"onMessage",即消息处理函数
|
||||
$object = new WeChat(TOKEN, "onMessage");
|
||||
$object->process(); //处理消息
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息处理函数
|
||||
*
|
||||
* @param WeChat $object
|
||||
* @param string $messageType
|
||||
* @param string $content
|
||||
* @param string $arg1
|
||||
* @param string $arg2
|
||||
*/
|
||||
function onMessage(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);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
|
@ -72,8 +72,9 @@ function gdk_pass_view() {
|
|||
$action = $_POST['action'];
|
||||
$post_id = $_POST['id'];
|
||||
$pass = $_POST['pass'];
|
||||
$wxcaptcha = wx_captcha();
|
||||
if(!isset( $action ) || !isset( $post_id ) || !isset( $pass ) ) exit('400');
|
||||
if($pass == '2233') {
|
||||
if($pass == $wxcaptcha ) {
|
||||
$pass_content = get_post_meta($post_id, '_pass_content')[0];
|
||||
exit($pass_content);
|
||||
}else{
|
||||
|
|
|
@ -34,7 +34,7 @@ function nc_reverse_strrchr($haystack, $needle, $trail)
|
|||
/**
|
||||
* 获取完整的句子
|
||||
*/
|
||||
function nc_print_excerpt($length, $post = null, $echo = true)
|
||||
function gdk_print_excerpt($length, $post = null, $echo = true)
|
||||
{
|
||||
global $post;
|
||||
$text = $post->post_excerpt;
|
||||
|
@ -64,6 +64,9 @@ function nc_print_excerpt($length, $post = null, $echo = true)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function nc_comment_add_at($comment_text, $comment = '')
|
||||
{
|
||||
if (!empty($comment) && $comment->comment_parent > 0) {
|
||||
|
@ -965,11 +968,11 @@ function gdk_thumb_img($way,$width,$height,$style = '',$atrr = 'class="thumb_img
|
|||
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';
|
||||
$src = GDK_BASE_URL . 'public/timthumb.php?src='.$url.'&h='.$height.'&w='.$width.'&q=90&zc=1&ct=1';
|
||||
}elseif ($way === 3) {
|
||||
$src = aq_resize( $url, $width , $height , true);
|
||||
if(empty($src)){
|
||||
$src = GDK_BASE_URL . '/public/timthumb.php?src='.$url.'&h='.$height.'&w='.$width.'&q=90&zc=1&ct=1';
|
||||
$src = GDK_BASE_URL . 'public/timthumb.php?src='.$url.'&h='.$height.'&w='.$width.'&q=90&zc=1&ct=1';
|
||||
}
|
||||
}else{
|
||||
return false;
|
||||
|
@ -1027,7 +1030,7 @@ function gdk_get_the_link_items($id = null) {
|
|||
if (!empty($bookmarks)) {
|
||||
foreach ($bookmarks as $bookmark) {
|
||||
$output.= '<div class="sm-6 md-4 lg-3">
|
||||
<div class="card"><a class="card-heading link-tooltip bg-lvs' . $bookmark->link_rating . '" href="' . $bookmark->link_url . '" target="_blank"><span class="card-icon"><img src="https://ico.mikelin.cn/' . $bookmark->link_url . '"></span><span class="card-title">' . $bookmark->link_name . '</span></a><div class="card-body">'.$bookmark->link_description.' : '.$bookmark->link_notes.'</div></div></div>';
|
||||
<div class="card"><a class="card-heading link-tooltip bg-lvs' . $bookmark->link_rating . '" href="' . $bookmark->link_url . '" target="_blank"><span class="card-icon"><img src="' . $bookmark->link_image . '"></span><span class="card-title">' . $bookmark->link_name . '</span></a><div class="card-body">'.$bookmark->link_description.' : '.$bookmark->link_notes.'</div></div></div>';
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
|
@ -1116,11 +1119,11 @@ function payjs_notify() {
|
|||
function buy_points(){
|
||||
if(is_user_logged_in()) {//logined
|
||||
$result = '
|
||||
<a data-fancybox="pay_fancybox" data-src="#pay_fancybox" href="javascript:;" class="button">点击充值</a>
|
||||
<a data-fancybox="pay_fancybox" data-src="#pay_fancybox" href="javascript:;" class="cm-btn primary">点击充值</a>
|
||||
<form id="pay_fancybox" name="pay_form" style="display: none; width: 100%; max-width: 500px;" class="pure-form">
|
||||
<h2 class="mb-3">积分充值</h2>
|
||||
<p>请在下面输入充值金额以及支付工具,微信支付宝都可以,如果下面选项中有支付宝一般建议支付宝</p>
|
||||
<p class="alert info">本站支付比例为: 1 RMB = '.gdk_option('gdk_rate').'金币</p></blockquote>
|
||||
<p class="cm-alert success">本站支付比例为: 1 RMB = '.gdk_option('gdk_rate').'金币</p></blockquote>
|
||||
<label for="money">支付金额</label>
|
||||
<input name="money" id="money" min="1" value="2" type="number" required>
|
||||
<br /><label for="pay_way">支付方式</label>';
|
||||
|
@ -1131,12 +1134,12 @@ function buy_points(){
|
|||
$result .= '<br /><label><input name="pay_way" type="radio" value = "wechat" checked/> 微信</label>';
|
||||
}
|
||||
$result .= '
|
||||
<p class="mb-0 text-right">
|
||||
<input data-fancybox-close type="button" id="submit_pay" data-action="pay_points" data-id="'.get_current_user_id().'" class="pure-button pure-button-primary" value="提交">
|
||||
<p class="mb-0 cm-text-right">
|
||||
<input data-fancybox-close type="button" id="submit_pay" data-action="pay_points" data-id="'.get_current_user_id().'" class="cm-btn primary" value="提交">
|
||||
</p>
|
||||
</form>';
|
||||
}else{// no login
|
||||
$result = '<div class=\'alert info\'>本页面需要您登录才可以操作,请先 <a target="_blank" href="'.esc_url( wp_login_url( get_permalink() ) ).'">点击登录</a> 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
|
||||
$result = '<div class=\'cm-alert error\'>本页面需要您登录才可以操作,请先 <a target="_blank" href="'.esc_url( wp_login_url( get_permalink() ) ).'">点击登录</a> 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -1240,3 +1243,69 @@ function create_user_id( $userdata ){
|
|||
return $user_id;
|
||||
}
|
||||
|
||||
|
||||
//生成hover颜色
|
||||
function editorial_hover_color( $hex, $steps ) {
|
||||
// Steps should be between -255 and 255. Negative = darker, positive = lighter
|
||||
$steps = max( -255, min( 255, $steps ) );
|
||||
// Normalize into a six character long hex string
|
||||
$hex = str_replace( '#', '', $hex );
|
||||
if ( strlen( $hex ) == 3) {
|
||||
$hex = str_repeat( substr( $hex,0,1 ), 2 ).str_repeat( substr( $hex, 1, 1 ), 2 ).str_repeat( substr( $hex,2,1 ), 2 );
|
||||
}
|
||||
// Split into three parts: R, G and B
|
||||
$color_parts = str_split( $hex, 2 );
|
||||
$return = '#';
|
||||
foreach ( $color_parts as $color ) {
|
||||
$color = hexdec( $color );
|
||||
// Convert to decimal
|
||||
$color = max( 0, min( 255, $color + $steps ) );
|
||||
// Adjust color
|
||||
$return .= str_pad( dechex( $color ), 2, '0', STR_PAD_LEFT );
|
||||
// Make two char hex code
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get minified css and removed space
|
||||
*
|
||||
* @since 1.2.5
|
||||
*/
|
||||
/**
|
||||
* Minify CSS
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function pwd_minify_css( $css ) {
|
||||
|
||||
// Normalize whitespace
|
||||
$css = preg_replace( '/\s+/', ' ', $css );
|
||||
// Remove ; before }
|
||||
$css = preg_replace( '/;(?=\s*})/', '', $css );
|
||||
// Remove space after , : ; { } */ >
|
||||
$css = preg_replace( '/(,|:|;|\{|}|\*\/|>) /', '$1', $css );
|
||||
// Remove space before , ; { }
|
||||
$css = preg_replace( '/ (,|;|\{|})/', '$1', $css );
|
||||
// Strips leading 0 on decimal values (converts 0.5px into .5px)
|
||||
$css = preg_replace( '/(:| )0\.([0-9]+)(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}.${2}${3}', $css );
|
||||
// Strips units if value is 0 (converts 0px to 0)
|
||||
$css = preg_replace( '/(:| )(\.?)0(%|em|ex|px|in|cm|mm|pt|pc)/i', '${1}0', $css );
|
||||
// Return minified CSS
|
||||
return trim( $css );
|
||||
}
|
||||
|
||||
//生成微信验证码
|
||||
function wx_captcha(){
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
$min = floor(date("i")/2);
|
||||
$day = date("d");
|
||||
$day = ltrim($day,0);
|
||||
$url = 'https://gitcafe.net';//home_url();
|
||||
$captcha = sha1($min.$url);
|
||||
$captcha = substr($captcha , $day , 6);
|
||||
return $captcha;
|
||||
|
||||
}
|
99
functions/email.php
Normal file
99
functions/email.php
Normal file
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
|
||||
//SMTP邮箱设置
|
||||
/*
|
||||
if (gdk_option('gdk_mailsmtp_b')) {
|
||||
function googlo_mail_smtp($phpmailer) {
|
||||
$phpmailer->From = gdk_option('gdk_maildizhi_b'); //发件人地址
|
||||
$phpmailer->FromName = gdk_option('gdk_mailnichen_b'); //发件人昵称
|
||||
$phpmailer->Host = gdk_option('gdk_mailsmtp_b'); //SMTP服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_mailport_b'); //SMTP邮件发送端口
|
||||
if (gdk_option('gdk_smtpssl_b')) {
|
||||
$phpmailer->SMTPSecure = 'ssl';
|
||||
} else {
|
||||
$phpmailer->SMTPSecure = '';
|
||||
} //SMTP加密方式(SSL/TLS)没有为空即可
|
||||
$phpmailer->Username = gdk_option('gdk_mailuser_b'); //邮箱帐号
|
||||
$phpmailer->Password = gdk_option('gdk_mailpass_b'); //邮箱密码
|
||||
$phpmailer->IsSMTP();
|
||||
$phpmailer->SMTPAuth = true; //启用SMTPAuth服务
|
||||
|
||||
}
|
||||
add_action('phpmailer_init', 'googlo_mail_smtp');
|
||||
}
|
||||
*/
|
||||
//修改默认发信地址
|
||||
function deel_res_from_email($email) {
|
||||
$wp_from_email = get_option('admin_email');
|
||||
return $wp_from_email;
|
||||
}
|
||||
function deel_res_from_name($email) {
|
||||
$wp_from_name = get_option('blogname');
|
||||
return $wp_from_name;
|
||||
}
|
||||
add_filter('wp_mail_from', 'deel_res_from_email');
|
||||
add_filter('wp_mail_from_name', 'deel_res_from_name');
|
||||
|
||||
//评论回应邮件通知
|
||||
function comment_mail_notify($comment_id) {
|
||||
$admin_notify = '0'; // admin 要不要收回复通知 ( '1'=要 ; '0'=不要 )
|
||||
$admin_email = get_bloginfo('admin_email'); // $admin_email 可改为你指定的 e-mail.
|
||||
$comment = get_comment($comment_id);
|
||||
$comment_author_email = trim($comment->comment_author_email);
|
||||
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
|
||||
$blogname = get_option("blogname");
|
||||
global $wpdb;
|
||||
if ($wpdb->query("Describe {$wpdb->comments} comment_mail_notify") == '') $wpdb->query("ALTER TABLE {$wpdb->comments} ADD COLUMN comment_mail_notify TINYINT NOT NULL DEFAULT 0;");
|
||||
if (($comment_author_email != $admin_email && isset($_POST['comment_mail_notify'])) || ($comment_author_email == $admin_email && $admin_notify == '1')) $wpdb->query("UPDATE {$wpdb->comments} SET comment_mail_notify='1' WHERE comment_ID='$comment_id'");
|
||||
$notify = $parent_id ? get_comment($parent_id)->comment_mail_notify : '0';
|
||||
$spam_confirmed = $comment->comment_approved;
|
||||
if ($parent_id != '' && $spam_confirmed != 'spam' && $notify == '1') {
|
||||
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); // e-mail 发出点, no-reply 可改为可用的 e-mail.
|
||||
$to = trim(get_comment($parent_id)->comment_author_email);
|
||||
$subject = 'Hi,您在 [' . get_option("blogname") . '] 的留言有人回复啦!';
|
||||
$message = '<div style="color:#555;font:12px/1.5 微软雅黑,Tahoma,Helvetica,Arial,sans-serif;width:650px;margin:50px auto;border-top: none;box-shadow:0 0px 3px #aaaaaa;" ><table border="0" cellspacing="0" cellpadding="0"><tbody><tr valign="top" height="2"><td valign="top"><div style="background-color:white;border-top:2px solid #12ADDB;line-padding:0 15px 12px;width:650px;color:#555555;font-family:微软雅黑, Arial;;font-size:12px;"><h2 style="border-bottom:1px solid #DDD;font-size:14px;font-weight:normal;padding:8px 0 10px 8px;"><span style="color: #12ADDB;font-weight: bold;">> </span>您在 <a style="text-decoration:none; color:#58B5F5;font-weight:600;" target="_blank" href="' . home_url() . '">' . $blogname . '</a> 网站上的留言有回复啦!</h2><div style="padding:0 12px 0 12px;margin-top:18px"><p>您好, ' . trim(get_comment($parent_id)->comment_author) . '! 您发表在文章 <a style="text-decoration:none;" target="_blank" href="' . get_the_permalink($comment->comment_post_ID) . '">《' . get_the_title($comment->comment_post_ID) . '》</a> 的评论:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags(get_comment($parent_id)->comment_content)) . '</p><p>' . trim($comment->comment_author) . ' 给您的回复如下:</p><p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px;margin: 15px 0;">' . nl2br(strip_tags($comment->comment_content)) . '</p><p>您可以点击 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">这里查看回复的完整內容</a>,也欢迎再次光临 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>。祝您天天开心,欢迎下次访问 <a style="text-decoration:none; color:#5692BC" target="_blank" href="' . home_url() . '">' . $blogname . '</a>!谢谢。</p><p style="float:right;">(此邮件由系统自动发出, 请勿回复)</p></div></div></td></tr></tbody></table><div style="color:#fff;background-color: #12ADDB;text-align : center;height:35px;padding-top:15px">Copyright © 2013-2018 ' . $blogname . '</div></div>';
|
||||
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
|
||||
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
}
|
||||
add_action('comment_post', 'comment_mail_notify');
|
||||
|
||||
//站长评论邮件添加评论链接
|
||||
function gdk_notify_postauthor($notify_message,$comment_ID) {
|
||||
$notify = $notify_message;
|
||||
$notify.= '快速回复此评论: ' . admin_url("edit-comments.php").'#comment-'.$comment_ID;
|
||||
return $notify;
|
||||
}
|
||||
add_filter('comment_notification_text', 'gdk_notify_postauthor', 10, 2);
|
||||
|
||||
|
||||
//欢迎新用户邮件
|
||||
|
||||
function gdk_register_mail($user_id) {
|
||||
$user = get_user_by('id', $user_id);
|
||||
$user_pass = $_POST['password'];
|
||||
$blogname = get_option('blogname');
|
||||
$message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff;background:#51a0e3;line-height:70px;font-size:24px;font-weight:400;padding-left:40px;margin:0">注册成功通知</h1><div class="emailtext" style="background:#fff;padding:20px 32px 20px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的' . $user->user_login . ',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">欢迎您注册[' . $blogname . '],下面是您的账号信息,请妥善保管!</p><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"><thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8">您的详细注册信息</th></tr></thead><tbody><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录邮箱</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user->user_email . '</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">登录密码</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $user_pass . '</td></tr></tbody></table><p style="color:#6e6e6e;font-size:13px;line-height:24px">如果您的账号有异常,请您在第一时间和我们取得联系哦,联系邮箱:' . get_bloginfo('admin_email') . '</p></div><div class="emailad" style="margin-top:4px"><a href="' . home_url() . '"><img src="http://reg.163.com/images/secmail/adv.png" alt="" style="margin:auto;width:100%;max-width:700px;height:auto"></a></div></div></div>';
|
||||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
wp_mail($user->user_email, '[' . $blogname . ']欢迎注册' . $blogname, $message, $headers);
|
||||
}
|
||||
add_action('user_register', 'gdk_register_mail');
|
||||
|
||||
|
||||
|
||||
//登录失败提醒
|
||||
|
||||
function gdk_login_failed_notify() {
|
||||
date_default_timezone_set('PRC');
|
||||
$admin_email = get_bloginfo('admin_email');
|
||||
$to = $admin_email;
|
||||
$subject = '您的网站登录错误警告';
|
||||
$message = '<p>您好!您的网站(' . get_option("blogname") . ')有登录错误!</p>' . '<p>请确定是您自己的登录失误,以防别人攻击!登录信息如下:</p>' . '<p>登录名:' . $_POST['log'] . '</p>' . '<p>登录密码:' . $_POST['pwd'] . '</p>' . '<p>登录时间:' . date("Y-m-d H:i:s") . '</p>' . '<p>登录IP:' . $_SERVER['REMOTE_ADDR'] . '</p>' . '<p style="float:right">————本邮件由系统发送,无需回复</p>';
|
||||
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
|
||||
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
|
||||
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
|
||||
wp_mail($to, $subject, $message, $headers);
|
||||
}
|
||||
add_action('wp_login_failed', 'gdk_login_failed_notify');
|
|
@ -204,14 +204,26 @@ add_shortcode('vip', 'gdk_login_to_read');
|
|||
|
||||
// 部分内容输入密码可见
|
||||
function gdk_secret_view($atts, $content = null) {
|
||||
extract(shortcode_atts(array('wx' => null) , $atts));
|
||||
$pid = get_the_ID();
|
||||
add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content);
|
||||
if ( current_user_can( 'administrator' ) || gdk_is_weixin()) { return $content; }//admin show
|
||||
return '<div class="pass_viewbox"><input id="pass_view" type="text"> <input id="submit_pass_view" data-action="gdk_pass_view" data-id="'.$pid.'" type="button" value="提交"></div>';
|
||||
return '<div class="cm-grid cm-card pass_viewbox">
|
||||
<div class="cm-row">
|
||||
<div class="cm-col-md-4">
|
||||
<img src="https://p.ssl.qhimg.com/t0162cc8398cbf7dea3.jpg" class="cm-resp-img">
|
||||
</div>
|
||||
<div class="cm-col-md-8">
|
||||
<div class="hide_content_info" style="margin:10px 0">
|
||||
<div class="cm-alert primary">本段内容已被隐藏,您需要扫码关注微信公众号申请验证码查看,发送【验证码】获取验证码,验证码2分钟有效</div>
|
||||
<input type="text" id="pass_view" placeholder="输入验证码并提交" style="width:70%"> <input id="submit_pass_view" class="cm-btn success" data-action="gdk_pass_view" data-id="'.$pid.'" type="button" value="提交">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
}
|
||||
add_shortcode('secret', 'gdk_secret_view');
|
||||
add_shortcode('wxcaptcha', 'gdk_secret_view');
|
||||
|
||||
|
||||
// 支持文章和页面运行PHP代码
|
||||
function gdk_php_include($attr) {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue