1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-12 11:17:12 +02:00

好多修改的

This commit is contained in:
云落 2020-01-27 22:28:34 +08:00
parent 59a16c642d
commit eb4c64564b
16 changed files with 682 additions and 632 deletions

View file

@ -191,6 +191,7 @@ function wp_clean_up_optimize(){
}
?>
<p>
<table class="widefat" style="width:550px;">
<thead>

View file

@ -6,79 +6,90 @@
$gdk_options = [
'优化选项' => [
[
'name' => '新版编辑器开关',
'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议禁用',
'name' => '禁用新版编辑器',
'desc' => '新版编辑器尚不成熟,很多主题不兼容,建议开启',
'id' => 'gdk_diasble_gutenberg',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '禁用头部冗余代码',
'desc' => 'WordPress头部自带很多无用代码不安全且浪费建议禁用',
'desc' => 'WordPress头部自带很多无用代码不安全且浪费建议开启',
'id' => 'gdk_diasble_head_useless',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '禁用WordPress更新',
'desc' => 'WordPress更新会不时发送请求数据所以可以关闭WordPress更新包括主题插件和内核更新',
'desc' => 'WordPress更新会不时发送请求数据所以可以关闭WordPress更新包括主题插件和内核更新,默认禁用',
'id' => 'gdk_diasble_wp_update',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
'std' => '0'
],
[
'name' => '禁用Emojis功能',
'desc' => 'WordPress的Emojis功能会加载国外资源那是网站速度所以建议禁用',
'desc' => 'WordPress的Emojis功能会加载国外资源那是网站速度所以建议开启',
'id' => 'gdk_disable_emojis',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '禁用XML-RPC功能',
'desc' => '该功能有安全风险如果不使用WordPress的手机客户端或者第三方编辑器软件那么建议禁用',
'desc' => '该功能有安全风险如果不使用WordPress的手机客户端或者第三方编辑器软件那么建议开启',
'id' => 'gdk_disable_xmlrpc',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '禁用文章版本功能',
'desc' => '该功能有会造成数据库体量暴增为了你的数据库考虑,建议禁用',
'desc' => '该功能有会造成数据库体量暴增为了你的数据库考虑,建议开启',
'id' => 'gdk_disable_revision',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '禁用pingback功能',
'desc' => '该功能会增加垃圾评论的几率,建议禁用',
'desc' => '该功能会增加垃圾评论的几率,建议开启',
'id' => 'gdk_disable_trackbacks',
'type' => 'radio',
'options' => [
'1' => '禁用',
'0' => '开启'
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '文件上传重命名',
'desc' => '该功能会将zip,rar,7z格式以外的所有全部数字重命名服务器文件不建议使用中文,默认开启',
'id' => 'gdk_upload_rename',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
@ -103,7 +114,7 @@ $gdk_options = [
'2' => 'V2EX头像镜像',
'3' => '七牛头像镜像',
],
'std' => '1'
'std' => '3'
]
],
'SEO设置' => [
@ -127,6 +138,17 @@ $gdk_options = [
'type' => 'text',
'std' => '|'
],
[
'name' => '自动添加nofollow',
'desc' => '该功能会给外链自动添加nofollow,默认开启',
'id' => 'gdk_nofollow',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '文章自动内链',
'desc' => '该功能会将文章中与标签匹配的文字自动添加标签链接,如果是纯文字的内容建议打开,默认禁用',
@ -156,6 +178,17 @@ $gdk_options = [
],
'std' => '1'
],
[
'name' => '禁止蜘蛛爬取作者页面',
'desc' => '该功能会屏蔽蜘蛛访问作者页面,如果是单作者网站没必要展示作者页,根据自己网站实际情况选择是否开启,默认禁用',
'id' => 'gdk_no_author_page',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '0'
],
[
'name' => '网站地图 sitemap_xml',
'desc' => '该功能会自动生成网站地图链接:域名/sitemap_xml,开启后建议更新固定链接一次,默认开启',
@ -168,10 +201,15 @@ $gdk_options = [
'std' => '1'
],
[
'name' => '图片自动添加alt以及title',
'desc' => '启用',
'id' => 'git_imgalt_b',
'type' => 'checkbox'
'name' => '文章图片自动添加alt以及title',
'desc' => '该功能会自动给文章中图片添加alt和title,并且是按照文章标题进行命名,默认开启',
'id' => 'gdk_seo_img',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '外链自动GO跳转',
@ -180,29 +218,35 @@ $gdk_options = [
'type' => 'checkbox'
],
[
'name' => '外链自动添加nofollow',
'desc' => '启用',
'id' => 'git_nofollow',
'type' => 'checkbox'
],
[
'name' => 'Robot.txt优化',
'desc' => '启用 【开启本项之后,将只对搜索引擎开放首页,页面,文章页,其他一律屏蔽】',
'id' => 'git_robot_b',
'type' => 'checkbox'
],
[
'title' => '百度主动推送 <a href="http://zhanzhang.baidu.com/linksubmit/index" target="_blank">查看主动推送效果</a>',//标题文字
'type' => 'title'//title 是标签下的标题
'name' => '百度自动&主动推送',
'desc' => '该功能会自动给文章中图片添加alt和title,并且是按照文章标题进行命名,默认开启',
'id' => 'gdk_baidu_push',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '1'
],
[
'name' => '主动推送接口地址,填写本项即开启推送',
'desc' => '在百度站长平台获取主动推送接口地址比如http://data.zz.baidu.com/urls?site=域名&token=一组字符, <a class="button-primary" rel="nofollow" href="http://zhanzhang.baidu.com/linksubmit/index" target="_blank">主动推送接口地址</a>',
'id' => 'git_sitemap_api',
'desc' => '在百度站长平台获取主动推送接口地址比如http://data.zz.baidu.com/urls?site=域名&token=一组字符, <a class="key_word" rel="nofollow" href="http://zhanzhang.baidu.com/linksubmit/index" target="_blank">主动推送接口地址</a>',
'id' => 'gdk_baidu_api',
'type' => 'text'
]
],
'安全设置' => [
[
'name' => '屏蔽各种不正常的请求',
'desc' => '该功能会将各种不正常的请求比如破解,注入类的屏蔽掉,默认开启',
'id' => 'gdk_block_requst',
'type' => 'radio',
'options' => [
'1' => '开启',
'0' => '禁用'
],
'std' => '1'
],
[
'title' => '登陆安全防御',
'type' => 'title'
@ -244,7 +288,7 @@ $gdk_options = [
],
[
'name' => '关键词IP邮箱屏蔽',
'desc' => '开启 【启用后在WordPress-设置-讨论-黑名单中添加想要屏蔽的关键词邮箱网址IP地址每行一个】<a class="button-primary" target="_blank" href="https://img.alicdn.com/imgextra/i4/1597576229/TB2FnxnlpXXXXcDXXXXXXXXXXXX_!!1597576229.png">如图设置</a>',
'desc' => '开启 【启用后在WordPress-设置-讨论-黑名单中添加想要屏蔽的关键词邮箱网址IP地址每行一个】<a class="key_word" target="_blank" href="https://img.alicdn.com/imgextra/i4/1597576229/TB2FnxnlpXXXXcDXXXXXXXXXXXX_!!1597576229.png">如图设置</a>',
'id' => 'git_spam_keywords',
'type' => 'checkbox'
],
@ -260,142 +304,6 @@ $gdk_options = [
'id' => 'git_spam_long',
'type' => 'checkbox'
],
[
'title' => '评论设置属性',
'type' => 'title'
],
[
'name' => '贴图',
'desc' => '不显示',
'id' => 'git_tietu',
'type' => 'checkbox'
],
[
'name' => '加粗',
'desc' => '不显示',
'id' => 'git_jiacu',
'type' => 'checkbox'
],
[
'name' => '删除线',
'desc' => '不显示',
'id' => 'git_shanchu',
'type' => 'checkbox'
],
[
'name' => '居中',
'desc' => '不显示',
'id' => 'git_juzhong',
'type' => 'checkbox'
],
[
'name' => '斜体',
'desc' => '不显示',
'id' => 'git_xieti',
'type' => 'checkbox'
],
[
'name' => '签到',
'desc' => '不显示',
'id' => 'git_qiandao',
'type' => 'checkbox'
],
[
'title' => '评论VIP设置',
'type' => 'title'
],
[
'name' => '启用',
'desc' => ' 【启用之后,您需要在下面设置用户的评论数字区间】',
'id' => 'git_vip',
'type' => 'checkbox'
],
[
'name' => 'VIP 1',
'desc' => '输入的数字减一就是VIP 1的所要求的评论数字区间默认是5',
'id' => 'git_vip1',
'type' => 'number',
'std' => 5
],
[
'name' => 'VIP 2',
'desc' => '输入的数字减去上面的数字就是VIP 2的所要求的评论数字区间,默认是10',
'id' => 'git_vip2',
'type' => 'number',
'std' => 10
],
[
'name' => 'VIP 3',
'desc' => '输入的数字减去上面的数字就是VIP 3的所要求的评论数字区间默认是20',
'id' => 'git_vip3',
'type' => 'number',
'std' => 20
],
[
'name' => 'VIP 4',
'desc' => '输入的数字减去上面的数字就是VIP 4的所要求的评论数字区间默认是40',
'id' => 'git_vip4',
'type' => 'number',
'std' => 30
],
[
'name' => 'VIP 5',
'desc' => '输入的数字减去上面的数字就是VIP 5的所要求的评论数字区间默认是70',
'id' => 'git_vip5',
'type' => 'number',
'std' => 40
],
[
'name' => 'VIP 6',
'desc' => '输入的数字减去上面的数字就是VIP 6的所要求的评论数字区间默认是110',
'id' => 'git_vip6',
'type' => 'number',
'std' => 50
],
[
'name' => '文章摘要',
'desc' => '个字',
'id' => 'git_excerpt_length',
'type' => 'number',
'std' => 180
],
[
'name' => '文章二维码',
'desc' => '启用',
'id' => 'git_qr_b',
'type' => 'checkbox'
],
[
'name' => '作者模块',
'desc' => '启用',
'id' => 'git_auther_b',
'type' => 'checkbox'
],
[
'name' => '文章目录索引',
'desc' => '启用 【开启之后默认索引文章H2标题】',
'id' => 'git_article_list',
'type' => 'checkbox'
],
[
'name' => '相关文章显示条数',
'desc' => '条&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这是是显示文章下面的相关文章数目的',
'id' => 'git_related_count',
'type' => 'number',
'std' => 8
],
[
'name' => '禁止站内文章Pingback',
'desc' => '开启&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 开启后不会发送站内Pingback建议开启',
'id' => 'git_pingback_b',
'type' => 'checkbox'
],
[
'name' => '禁止后台编辑时自动保存',
'desc' => '开启&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 开启后,后台编辑文章时候不会定时保存,有效缩减数据库存储量;但是,一般不建议开启,除非你的数据库容量很小',
'id' => 'git_autosave_b',
'type' => 'checkbox'
],
[
'name' => '文章版权声明',
'desc' => '此处输入的文字将出现在每篇文章最底部,你可以使用:{{title}}表示文章标题,{{link}}表示文章链接',
@ -412,20 +320,20 @@ $gdk_options = [
[
'name' => '金币和RMB兑换关系',
'desc' => '请输入兑换关系比如1RMB=10金币请慎重选择一旦设置好后面不能修改的',
'id' => 'git_chongzhi_dh',
'id' => 'git_payjs_rate',
'type' => 'number',
'std' => 10
],
[
'name' => '选择一个支付方式',
'desc' => '两种方案选择其中一种,必须选择一个哦',
'id' => 'git_pay_way',
'id' => 'git_payjs',
'type' => 'radio',
'options' => [
'git_payjs_ok' => '调用Payjs支付',
'git_eapay_ok' => '调用简付支付'
'0' => '禁用',
'1' => '开启'
],
'std' => 'git_payjs_ok'
'std' => '1'
],
[
'title' => 'PayJs支付设置&nbsp;&nbsp;&nbsp;<a href="https://payjs.cn/ref/ZVEMKD" target="_blank" >注册PayJs</a>&nbsp;&nbsp;&nbsp;【微信官方,微信正规渠道,强烈推荐】',
@ -444,37 +352,19 @@ $gdk_options = [
'id' => 'git_payjs_secret',
'type' => 'text',
'std' => 444444444
],
[
'title' => '简付支付设置&nbsp;&nbsp;&nbsp;<a href="https://b.eapay.cc" target="_blank" >注册简付</a>',
'type' => 'title'
],
[
'name' => '简付App ID',
'desc' => '',
'id' => 'git_eapay_id',
'type' => 'text',
'std' => 2333333333
],
[
'name' => '简付App Key',
'desc' => '',
'id' => 'git_eapay_secret',
'type' => 'text',
'std' => 444444444
]
],
'高级设置' => [
[
'name' => 'jQuery来源设置',
'desc' => '选择一个适合自己的jQuery公共库来源',
'id' => 'git_jqcdn',
'id' => 'git_jq',
'type' => 'radio',
'options' => [
'git_jqcdn_upai' => '远程jQuery库【底部加载速度快兼容差】',
'git_jqcdn_bendi' => '本地jQuery库【头部加载速度慢兼容好】'
'1' => '远程jQuery库【底部加载速度快兼容差】',
'0' => '本地jQuery库【头部加载速度慢兼容好】'
],
'std' => 'git_jqcdn_upai'
'std' => '1'
],
[
'name' => 'HTML代码压缩',
@ -517,7 +407,7 @@ $gdk_options = [
],
[
'name' => 'CDN域名',
'desc' => '输入您的CDN域名一般需要到cdn后台获取必须带 <font color="#cc0000"><strong>http(s):// ,且结尾不能带/ </strong></font>',
'desc' => '输入您的CDN域名一般需要到cdn后台获取必须带 <span class="key_word">http(s):// ,且结尾不能带/ </span>',
'id' => 'gdk_cdn_host',
'type' => 'text',
'std' => ''
@ -549,7 +439,7 @@ $gdk_options = [
],
[
'name' => 'CDN水印',
'desc' => '启用【如果启用请在七牛又拍OSS等CDN中设置自定义样式名字为<font color="#cc0000"><strong>water.jpg</strong></font>,分隔符为 ! 】',
'desc' => '启用【如果启用请在七牛又拍OSS等CDN中设置自定义样式名字为<span class="key_word">water.jpg</span>,分隔符为<span class="key_word">!</span> 】',
'id' => 'git_cdn_water',
'type' => 'checkbox'
],
@ -611,7 +501,7 @@ $gdk_options = [
'desc' => '在本输入框内输入您的微信公众号描述信息支持html代码字数合适就行不能太多',
'id' => 'git_mp_tips',
'type' => 'textarea',
'std' => '请关注极客公园官方微信公众号,关注并订阅<span style="color:#E96463;font-weight:bold;">云落极客公园</span>获取验证码。在微信里搜索<span style="color:#E96463;font-weight:bold;">云落极客公园</span>或者微信扫描二维码都可以关注极客公园官方微信公众号。'
'std' => '请关注极客公园官方微信公众号,关注并订阅<span class="key_word">云落极客公园</span>获取验证码。在微信里搜索<span class="key_word">云落极客公园</span>或者微信扫描二维码都可以关注极客公园官方微信公众号。'
],
[
'title' => 'HTML5 桌面推送',
@ -664,50 +554,48 @@ $gdk_options = [
'type' => 'title'
],
[
'name' => '发件人地址',
'desc' => '请输入您的邮箱地址',
'id' => 'git_maildizhi_b',
'type' => 'text',
'std' => ''
'name' => 'SMTP邮箱发送',
'desc' => '该功能利用第三方SMTP邮箱服务发送邮件,比如评论邮件,需要配置好再开启',
'id' => 'gdk_smtp',
'type' => 'radio',
'options' => [
'0' => '禁用',
'1' => '开启'
],
'std' => '0'
],
[
'name' => '发件人昵称',
'desc' => '请输入您的网站名称',
'id' => 'git_mailnichen_b',
'desc' => '请输入您的网站名称,比如:云落',
'id' => 'gdk_smtp_username',
'type' => 'text',
'std' => ''
],
[
'name' => 'SMTP服务器地址',
'desc' => '请输入您的邮箱的SMTP服务器查看<a class="button-primary" target="_blank" href="http://wenku.baidu.com/link?url=Xc_mRFw2K-dimKX845QalqLpZzly07mC4a_t_QjOSPov0uFx3MWTl3wgw4tOAyTbDlS7lT8TOAj8VOxDYU186wQLKPt1fKncz7k_jbP_RQi">查看常用SMTP地址</a>',
'id' => 'git_mailsmtp_b',
'desc' => '请输入您的邮箱的SMTP服务器<a class="key_word" target="_blank" href="https://blog.csdn.net/whyhonest/article/details/7289420">点击查看常用SMTP地址</a>',
'id' => 'gdk_smtp_host',
'type' => 'text',
'std' => 'smtp.qq.com'
],
[
'name' => 'SSL安全连接',
'desc' => '启用【如果你布吉岛这个是什么东东,那么请不要启用】',
'id' => 'git_smtpssl_b',
'type' => 'checkbox'
],
[
'name' => 'SMTP服务器端口',
'desc' => '请输入您的smtp端口一般QQ邮箱25就可以了,如果选择了上面的SSL推荐使用465端口',
'id' => 'git_mailport_b',
'desc' => '请输入您的smtp端口一般QQ邮箱推荐使用465端口',
'id' => 'gdk_smtp_port',
'type' => 'number',
'std' => 465
],
[
'name' => '邮箱账号',
'desc' => '请输入您的邮箱地址比如云落的sp91@qq.com',
'id' => 'git_mailuser_b',
'id' => 'gdk_smtp_mail',
'type' => 'text',
'std' => ''
],
[
'name' => '邮箱密码',
'desc' => '请输入您的邮箱授权码',
'id' => 'git_mailpass_b',
'desc' => '请输入您的邮箱授权码,<span class="key_word">注意不同邮箱服务器的密码不一样,有的是密码,有的比如QQ邮箱就是授权码</span>',
'id' => 'gdk_smtp_password',
'type' => 'password',
'std' => ''
],

View file

@ -1,6 +1,6 @@
<?php
/**
* Git 主题后台选项
* Git 插件后台选项
*/
if ( ! defined( 'WPINC' ) ) {
@ -59,9 +59,9 @@ foreach ( array_keys($gdk_options) as $i => $name ) {
}
?>
<li><a href="#panel_data" data-panel="data">数据清理</a></li>
<li><a href="#panel_about" data-panel="about">关于主题</a></li>
<li><a href="#panel_about" data-panel="about">关于插件</a></li>
</ul>
<div class="search-form"><label class="screen-reader-text" for="wp-filter-search-input">筛选主题选项…</label><input placeholder="筛选主题选项…" type="search" id="wp-filter-search-input" class="wp-filter-search"></div>
<div class="search-form"><label class="screen-reader-text" for="wp-filter-search-input">筛选插件选项…</label><input placeholder="筛选插件选项…" type="search" id="wp-filter-search-input" class="wp-filter-search"></div>
</div>
<form method="post">
@ -241,6 +241,12 @@ switch ( $type ) {
border-bottom: 1px solid #d2d3e0;
padding-bottom: 5px;
}
.key_word{
color:#f70044;
font-weight:bold;
text-decoration:none;
margin: 10px;
}
.panel th {
font-weight: normal;
}
@ -328,6 +334,22 @@ jQuery(function ($) {
$(".submit .button").prop("disabled", true);
$(this).find(".submit .button").val("正在提交…");
});
/* 配置文本框以隐藏显示功能*/
function depend(n, e, i, c, t, u) {
$("input[name=" + n + "]:checked").val(function() {
"0" == this.value && $(e, i, c, t, u).hide();
}), $("input[name=" + n + "]").click(function() {
$(e, i, c, t, u).toggle();
});
}
//依赖关系,第一个是需要点击的name值,后面是需要伸缩的ID值,参照下面写
depend('gdk_lock_login','#row-gdk_failed_login_limit,#row-gdk_lockout_duration');
depend('gdk_smtp','#row-gdk_smtp_username,#row-gdk_smtp_host,#row-gdk_smtp_port,#row-gdk_smtp_mail,#row-gdk_smtp_password');
depend('gdk_baidu_push','#row-gdk_baidu_api');
});
</script>
<?php

18
functions/Ajax.php Normal file
View file

@ -0,0 +1,18 @@
<?php
/*
*Ajax操作
*/
function nc_test_email() {
$is_error = !wp_mail('donotreply@mywpku.com', '测试发信', 'WP 积木测试发信');
if ($is_error) {
exit('0');
}else{
exit('1');
}
}
add_action('wp_ajax_nopriv_nc_test_email', 'nc_test_email');
add_action('wp_ajax_nc_test_email', 'nc_test_email');

View file

@ -5,7 +5,7 @@ function gdk_switch_get_avatar( $avatar ) {
switch (gdk_option('gdk_switch_get_avatar')) {
case 1:
$avatarsrc = 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/avatar/' . mt_rand(1, 1999) . '.jpg';
$avatar = "<img src=$avatarsrc class='avatar rand_avatar photo' />";
$avatar = "<img src=$avatar src class='avatar rand_avatar photo' />";
break;
case 2:
$avatar = preg_replace("/http[s]{0,1}:\/\/(secure|www|\d).gravatar.com\/avatar\//","//cdn.v2ex.com/gravatar/",$avatar);
@ -26,4 +26,81 @@ function fancybox($content) {
}
add_filter('the_content', 'fancybox');
//邮箱SMTP设置
if (gdk_option('gdk_smtp')) {
function gdk_smtp( $phpmailer ) {
$phpmailer->FromName = gdk_option('gdk_smtp_mail'); //邮箱地址
$phpmailer->Host = gdk_option('gdk_smtp_host');//服务器地址
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
$phpmailer->Username = gdk_option('gdk_smtp_username'); //昵称
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = 'ssl';
$phpmailer->IsSMTP();
}
add_action('phpmailer_init', 'gdk_smtp');
}
//七牛CDN
if (gdk_option('gdk_cdn')) {
add_action('wp_loaded', 'gdk_cdn_start');
function gdk_cdn_start() {
ob_start('gdk_cdn_replace');
}
function gdk_cdn_replace($html) {
$local_host = home_url(); //博客域名
$qiniu_host = gdk_option('git_cdnurl_b'); //七牛域名
$cdn_exts = gdk_option('git_cdnurl_format'); //扩展名(使用|分隔)
$cdn_dirs = gdk_option('git_cdnurl_dir'); //目录(使用|分隔)
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
if ($cdn_dirs) {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$4', $html);
} else {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$3', $html);
}
return $html;
}
}
//CDN水印
if (gdk_option('git_cdn_water')) {
function cdn_water($content){
if (get_post_type() == 'post') {
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<img$1src=$2$3.$4!water.jpg$5$6>';
$content = preg_replace($pattern, $replacement, $content);
}
return $content;
}
add_filter('the_content', 'cdn_water');
}
//自动替换媒体库图片的域名
if (is_admin() && gdk_option('git_cdnurl_b') && gdk_option('git_adminqn_b')) {
function attachment_replace($text) {
$replace = array(
home_url() => gdk_option('git_cdnurl_b')
);
$text = str_replace(array_keys($replace) , $replace, $text);
return $text;
}
add_filter('wp_get_attachment_url', 'attachment_replace');
}
//一个简单可重复使用的邮件模板
function mail_temp($mail_title,$mail_cotent,$link,$link_title){
?>
<div style="width:500px;margin:auto">
<div style="background:#2695f3;color:#FFF;padding:20px 10px;"><?php echo $mail_title;?></div>
<div style="padding:10px;margin:5px;border-bottom:dashed 1px #ddd;"><?php echo $mail_cotent;?></div>
<a href="<?php echo $link;?>" style="display:block;margin:auto;margin-top:40px;padding:10px;width:107px;outline:0;border:1px solid #2695f3;border-radius:25px;color:#2695f3;text-align:center;font-weight:700;font-size:14pxtext-decoration:none;" rel="noopener" target="_blank"><?php echo $link_title;?></a>
<br><br>
<div style="color:#cecece;font-size: 12px;">本邮件为系统自动发送,请勿回复。<br>
如果不想被此类邮件打扰,请前往 <a style="color: #cecece;" href="<?php echo home_url();?>" rel="noopener" target="_blank"><?php echo get_option('blogname');?></a> 留言说明,由我们来操作处理。
</div>
</div>
<?php
}

View file

@ -1,8 +0,0 @@
<?php
//头像镜像

View file

@ -1,6 +1,15 @@
<?php
function wpjam_feed_disabled() {
wp_die('Feed已经关闭, 请访问网站<a href="'.get_bloginfo('url').'">首页</a>');
}
add_action('do_feed', 'wpjam_feed_disabled', 1);
add_action('do_feed_rdf', 'wpjam_feed_disabled', 1);
add_action('do_feed_rss', 'wpjam_feed_disabled', 1);
add_action('do_feed_rss2', 'wpjam_feed_disabled', 1);
add_action('do_feed_atom', 'wpjam_feed_disabled', 1);
//禁用新版编辑器
if(gdk_option('gdk_diasble_gutenberg')){
@ -139,12 +148,20 @@ add_action('init', 'gdk_page_permalink', -1);
//中文文件重命名
function gdk_upload_rename($file) {
$time = date("YmdHis");
$file['name'] = $time . "" . mt_rand(1, 100) . "." . pathinfo($file['name'], PATHINFO_EXTENSION);
return $file;
if(gdk_option('gdk_upload_rename')){
add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename' );
function gdk_upload_rename( $file ){
$info = pathinfo($file['name']);
$ext = $info['extension'];
$ignore_exts = ['zip', 'rar', '7z'];//被忽略的文件格式
if (!in_array($ext, $ignore_exts)) {
$filedate = date('YmdHis').mt_rand(100, 999);
$file['name'] = $filedate.'.'.$ext;
}
return $file;
}
}
add_filter('wp_handle_upload_prefilter', 'gdk_upload_rename');
// 搜索结果为1时候自动跳转到对应页面
@ -277,4 +294,21 @@ function log_login( $username, $password ) {
}
}
}
}
//前台禁止加载语言包
add_filter('locale', function($locale) {
$locale = ( is_admin() ) ? $locale : 'en_US';
return $locale;
});
// 定制登录页面链接的连接
add_filter('login_headerurl', function (){
return home_url();
});
// 定制登录页面链接的标题
add_filter('login_headertext', function (){
return get_bloginfo('name');
});

View file

@ -3,7 +3,7 @@
define('DISALLOW_FILE_MODS',true);
//阻止乱七八糟的请求
add_action( 'wp', 'gdk_prevent_script_injection' );
if(gdk_option('gdk_block_requst')){
function gdk_prevent_script_injection() {
global $user_ID;
if( ! current_user_can( 'level_10' )) {
@ -27,19 +27,21 @@ add_action( 'wp', 'gdk_prevent_script_injection' );
}
}
}
add_action( 'wp', 'gdk_prevent_script_injection' );
}
if(gdk_option('gdk_lock_login')){
if ( ! class_exists( 'GDK_Limit_Login_Attempts' ) ) {
class GDK_Limit_Login_Attempts {
var $failed_login_limit = 3;
private $failed_login_limit;
//登录失败的次数限制
var $lockout_duration = 60;
private $lockout_duration;
//暂停登陆时间
var $transient_name = 'attempted_login';
//Transient used
public function __construct() {
$failed_login_limit = gdk_option('gdk_failed_login_limit');
$lockout_duration = gdk_option('gdk_lockout_duration');
public function __construct($config = null) {
$this->failed_login_limit = $config['failed_login_limit'];
$this->lockout_duration = $config['lockout_duration'];
add_filter( 'authenticate', array( $this, 'check_attempted_login' ), 30, 3 );
add_action( 'wp_login_failed', array( $this, 'login_failed' ), 10, 1 );
}
@ -91,7 +93,7 @@ if(gdk_option('gdk_lock_login')){
if ( $diff < $minute * 2 )
return esc_attr( 'about 1 minute ago' );
if ( $diff < $hour )
return floor( $diff / $minute ) . ' ' . esc_attr( '分' );
return floor( $diff / $minute ) . ' ' . esc_attr( '分' );
if ( $diff < $hour * 2 )
return esc_attr( 'about 1 hour');
return floor( $diff / $hour ) . ' ' . esc_attr( '小时' );
@ -99,7 +101,11 @@ if(gdk_option('gdk_lock_login')){
}
}
//Enable it:
new GDK_Limit_Login_Attempts();
$config = [
'failed_login_limit' => gdk_option('gdk_failed_login_limit'), // 登录失败的次数限制
'lockout_duration' => gdk_option('gdk_lockout_duration'), // 暂停登陆时间
];
new GDK_Limit_Login_Attempts($config);
}
@ -109,7 +115,7 @@ function gdk_disable_login_errors( $error ) {
$err_codes = $errors->get_error_codes();
if ( ! in_array( 'too_many_tried', $err_codes ) ) {
// For security reason
return esc_attr('Access denied!');
return esc_attr('Access Denied!');
}
return $error;
}
@ -147,4 +153,15 @@ function gdk_comment_lang($incoming_comment) {
}
return($incoming_comment);
}
add_filter('preprocess_comment', 'gdk_comment_lang');
add_filter('preprocess_comment', 'gdk_comment_lang');
//禁止使用admin登录
add_filter( 'wp_authenticate', function ($user){
if($user == 'admin') exit;
});
add_filter('sanitize_user', function ($username, $raw_username, $strict){
if($raw_username == 'admin' || $username == 'admin'){
exit;
}
return $username;
}, 10, 3);

View file

@ -5,6 +5,18 @@ if(gdk_option('gdk_sitemap_xml')){
include('sitemap-xml.php');
}
// 屏蔽蜘蛛爬取作者页面
if(gdk_option('gdk_no_author_page')){
function gdk_no_author_page()
{
if (is_author()) {
wp_no_robots();
}
}
add_action('wp_head', 'gdk_no_author_page');
}
//robots.txt优化功能
if(gdk_option('gdk_robots')){
add_filter('robots_txt', 'gdk_robots_txt', 10, 2);
@ -50,6 +62,97 @@ if(gdk_option('gdk_tag_link')){
add_filter('the_content', 'gdk_tag_link', 1);
}
// 自动添加nofloow
if(gdk_option('gdk_nofollow')){
add_filter('the_content', 'gdk_nofollow');
add_filter('the_excerpt', 'gdk_nofollow');
function gdk_nofollow($content)
{
return preg_replace_callback('/<a[^>]+/', 'gdk_nofollow_callback', $content);
}
function gdk_nofollow_callback($matches)
{
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=\S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
}
return $link;
}
}
if (isset($others_seo['baidu_submit']) && $others_seo['baidu_submit']) {
add_action('post_updated', 'nc_baidu_submit');
function nc_baidu_submit($post_ID)
{
global $post;
$bd_submit_site = get_bloginfo('url');
$bd_submit_token = $others_seo['baidu_submit_key'];
if (empty($post_ID) || empty($bd_submit_site) || empty($bd_submit_token)) {
return;
}
$api = 'http://data.zz.baidu.com/urls?site='.$bd_submit_site.'&token='.$bd_submit_token;
$status = $post->post_status;
if ($status != '' && $status != 'publish') {
$url = get_permalink($post_ID);
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain')
);
curl_setopt_array($ch, $options);
}
}
function nc_baidu_auto_code(){
echo '<script>
(function(){
var bp = document.createElement(\'script\');
bp.src = \'https://zz.bdstatic.com/linksubmit/push.js\';
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>';
}
}
add_action('wp_footer', 'nc_baidu_auto_code', 500);
if(gdk_option('gdk_seo_img')) {
//给文章图片自动添加alt和title信息
function nc_imagesalt($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 alt="'.strip_tags($post->post_title).'" title="'.strip_tags($post->post_title).'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'nc_imagesalt');
function nc_image_alt_tag($content) {
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {
foreach($images[1] as $index => $value) {
$new_img = str_replace('<img', '<img alt="'.strip_tags($post->post_title).'-'.get_option('blogname').'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
return $content;
}
add_filter('the_content', 'nc_image_alt_tag', 99999);
}
//给外部链接加上跳转
@ -136,42 +239,7 @@ function deel_description() {
add_action('wp_head', 'deel_description');
//WordPress文字标签关键词自动内链
/*
$match_num_min = git_get_option('git_autolink_1'); //一篇文章中同一個標籤少於幾次不自動鏈接
$match_num_max = git_get_option('git_autolink_2'); //一篇文章中同一個標籤最多自動鏈接幾次
function tag_sort($a, $b) {
if ($a->name == $b->name) return 0;
return (strlen($a->name) > strlen($b->name)) ? -1 : 1;
}
function tag_link($content) {
global $match_num_min, $match_num_max;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach ($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = "<a href=\"$link\" title=\"" . str_replace('%s', addcslashes($cleankeyword, '$') , '查看更多关于%s的文章') . "\"";
$url.= ' target="_blank"';
$url.= ">" . addcslashes($cleankeyword, '$') . "</a>";
$limit = $match_num_max;
$content = preg_replace('|(<a[^>]+>)(.*)(' . $keyword . ')(.*)(</a[^>]*>)|U' . $case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace('|(<img)(.*?)(' . $keyword . ')(.*?)(>)|U' . $case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace('|(<h[^>]+>)(.*)(' . $keyword . ')(.*)(</h[^>]*>)|U' . $case, '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword, '\'');
$regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx, $url, $content, $limit);
$content = str_replace('%&&&&&%', stripslashes($keyword) , $content);
}
}
return $content;
}
add_filter('the_content', 'tag_link', 1);
*/
//图片img标签添加alttitle属性
function imagesalt($content){
@ -192,37 +260,7 @@ function tag_link($content) {
}
add_filter('the_content', 'aimagesalt');
//自动给文章以及评论添加nofollow属性
function git_auto_nofollow($content)
{
$regexp = "<a\\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
if (preg_match_all("/{$regexp}/siU", $content, $matches, PREG_SET_ORDER)) {
if (!empty($matches)) {
$srcUrl = get_option('siteurl');
for ($i = 0; $i < count($matches); $i++) {
$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];
$noFollow = '';
$pattern = '/rel\\s*=\\s*"\\s*[n|d]ofollow\\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if (count($match) < 1) {
$noFollow .= ' rel="nofollow" ';
}
$pos = strpos($url, $srcUrl);
if ($pos === false) {
$tag = rtrim($tag, '>');
$tag .= $noFollow . '>';
$content = str_replace($tag2, $tag, $content);
}
}
}
}
$content = str_replace(']]>', ']]>', $content);
return $content;
}
add_filter('the_content', 'git_auto_nofollow');
//评论分页的seo处理

View file

@ -2,53 +2,8 @@
//七牛CDN
if (!is_admin() && git_get_option('git_qncdn_b')) {
add_action('wp_loaded', 'gdk_cdn_start');
function gdk_cdn_start() {
ob_start('gdk_cdn_replace');
}
function gdk_cdn_replace($html) {
$local_host = home_url(); //博客域名
$qiniu_host = git_get_option('git_cdnurl_b'); //七牛域名
$cdn_exts = git_get_option('git_cdnurl_format'); //扩展名(使用|分隔)
$cdn_dirs = git_get_option('git_cdnurl_dir'); //目录(使用|分隔)
$cdn_dirs = str_replace('-', '\-', $cdn_dirs);
if ($cdn_dirs) {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/((' . $cdn_dirs . ')\/[^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$4', $html);
} else {
$regex = '/' . str_replace('/', '\/', $local_host) . '\/([^\s\?\\\'\"\;\>\<]{1,}.(' . $cdn_exts . '))([\"\\\'\s\?]{1})/';
$html = preg_replace($regex, $qiniu_host . '/$1$3', $html);
}
return $html;
}
}
//CDN水印
if (git_get_option('git_cdn_water')) {
function cdn_water($content){
if (get_post_type() == 'post') {
$pattern = "/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<img$1src=$2$3.$4!water.jpg$5$6>';
$content = preg_replace($pattern, $replacement, $content);
}
return $content;
}
add_filter('the_content', 'cdn_water');
}
//自动替换媒体库图片的域名
if (is_admin() && git_get_option('git_cdnurl_b') && git_get_option('git_adminqn_b')) {
function attachment_replace($text) {
$replace = array(
home_url() => git_get_option('git_cdnurl_b')
);
$text = str_replace(array_keys($replace) , $replace, $text);
return $text;
}
add_filter('wp_get_attachment_url', 'attachment_replace');
}

View file

@ -1,7 +1,7 @@
<?php
// ----------------------
// 开一个api的统一URL
function sitemap_xml_flush_rules(){
function gdk_sitemap_xml_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( !isset( $rules['^sitemap(.*?)\.xml$'] ) ) {
global $wp_rewrite;
@ -10,16 +10,16 @@ function sitemap_xml_flush_rules(){
}
// 添加自定义URL重写
function sitemap_xml_custom_rewrite_rule() {
function gdk_sitemap_xml_custom_rewrite_rule() {
add_rewrite_rule('^sitemap(.*?)\.xml$','index.php?sitemap=gdk$matches[1]','top');
}
function sitemap_xml_insert_query_vars( $vars ){
function gdk_sitemap_xml_insert_query_vars( $vars ){
array_push($vars, 'sitemap');
return $vars;
}
function sitemap_xml_cancel_redirect( $redirect_url ) {
function gdk_sitemap_xml_cancel_redirect( $redirect_url ) {
$api_type = get_query_var('sitemap');
if ( !empty($api_type) ){
return false;
@ -28,7 +28,7 @@ function sitemap_xml_cancel_redirect( $redirect_url ) {
}
}
function sitemap_xml_api_handlers( $template ){
function gdk_sitemap_xml_api_handlers( $template ){
$hook = explode('-', get_query_var( 'sitemap' ) );
@ -57,11 +57,11 @@ function sitemap_xml_api_handlers( $template ){
return $template;
}
add_action( 'init', 'sitemap_xml_custom_rewrite_rule' , 10, 0);
add_filter( 'query_vars', 'sitemap_xml_insert_query_vars' );
add_filter( 'redirect_canonical', 'sitemap_xml_cancel_redirect' );
add_action( 'wp_loaded', 'sitemap_xml_flush_rules' );
add_filter( 'template_include', 'sitemap_xml_api_handlers', 99 );
add_action( 'init', 'gdk_sitemap_xml_custom_rewrite_rule' , 10, 0);
add_filter( 'query_vars', 'gdk_sitemap_xml_insert_query_vars' );
add_filter( 'redirect_canonical', 'gdk_sitemap_xml_cancel_redirect' );
add_action( 'wp_loaded', 'gdk_sitemap_xml_flush_rules' );
add_filter( 'template_include', 'gdk_sitemap_xml_api_handlers', 99 );
function gdk_create_sitemap() {

View file

@ -550,4 +550,262 @@ function gdk_die($ErrMsg) {
header('HTTP/1.1 405 Method Not Allowed');
echo $ErrMsg;
exit;
}
//设置cookie数据
function gdk_set_cookie($key, $value, $expire){
$expire = ($expire < time())?$expire+time():$expire;
$secure = ('https' === parse_url(get_option('home'), PHP_URL_SCHEME));
setcookie($key, $value, $expire, COOKIEPATH, COOKIE_DOMAIN, $secure);
if ( COOKIEPATH != SITECOOKIEPATH ){
setcookie($key, $value, $expire, SITECOOKIEPATH, COOKIE_DOMAIN, $secure);
}
$_COOKIE[$key] = $value;
}
//判断是否是电话号码,是号码返回 true 不是返回false
function gdk_is_mobile_number($number){
return (bool)preg_match('/^0{0,1}(1[3,5,8][0-9]|14[5,7]|166|17[0,1,3,6,7,8]|19[8,9])[0-9]{8}$/', $number);
}
//获取纯文本
function gdk_plain_text($text) {
$text = wp_strip_all_tags($text);
$text = str_replace('"', '', $text);
$text = str_replace('\'', '', $text);
$text = str_replace("\r\n", ' ', $text);
$text = str_replace("\n", ' ', $text);
$text = str_replace(" ", ' ', $text);
return trim($text);
}
// 获取第一段
function gdk_first_p($text) {
if($text) {
$text = explode("\n", trim(strip_tags($text)));
$text = trim($text['0']);
}
return $text;
}
//获取当前页面链接
function gdk_get_current_url(){
$ssl = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true:false;
$sp = strtolower($_SERVER['SERVER_PROTOCOL']);
$protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : '');
$port = $_SERVER['SERVER_PORT'];
$port = ((!$ssl && $port=='80') || ($ssl && $port=='443')) ? '' : ':'.$port;
$host = $_SERVER['HTTP_X_FORWARDED_HOST'] ?? $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'];
return $protocol . '://' . $host . $port . $_SERVER['REQUEST_URI'];
}
//黑名单检测
function gdk_blacklist_check($str){
$moderation_keys = trim(get_option('moderation_keys'));
$blacklist_keys = trim(get_option('blacklist_keys'));
$words = explode("\n", $moderation_keys ."\n".$blacklist_keys);
foreach ((array)$words as $word){
$word = trim($word);
// Skip empty linesgdk_
if ( empty($word) ) continue;
// Do some escaping magic so that '#' chars in the
// spam words don't break things:
$word = preg_quote($word, '#');
if ( preg_match("#$word#i", $str) ) return true;
}
return false;
}
//
function gdk_http_request($url, $args=array(), $err_args=array()){
$args = wp_parse_args( $args, array(
'timeout' => 5,
'method' => '',
'body' => array(),
'sslverify' => false,
'blocking' => true, // 如果不需要立刻知道结果,可以设置为 false
'stream' => false, // 如果是保存远程的文件,这里需要设置为 true
'filename' => null, // 设置保存下来文件的路径和名字
'need_json_decode' => true,
'need_json_encode' => false,
// 'headers' => array('Accept-Encoding'=>'gzip;'), //使用压缩传输数据
// 'headers' => array('Accept-Encoding'=>''),
// 'compress' => false,
'decompress' => true,
));
if(isset($_GET['debug'])){
print_r($args);
}
$need_json_decode = $args['need_json_decode'];
$need_json_encode = $args['need_json_encode'];
$method = ($args['method'])?strtoupper($args['method']):($args['body']?'POST':'GET');
unset($args['need_json_decode']);
unset($args['need_json_encode']);
unset($args['method']);
if($method == 'GET'){
$response = wp_remote_get($url, $args);
}elseif($method == 'POST'){
if($need_json_encode && is_array($args['body'])){
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_post($url, $args);
}elseif($method == 'FILE'){ // 上传文件
$args['method'] = ($args['body'])?'POST':'GET';
$args['sslcertificates'] = isset($args['sslcertificates'])?$args['sslcertificates']: ABSPATH.WPINC.'/certificates/ca-bundle.crt';
$args['user-agent'] = isset($args['user-agent'])?$args['user-agent']:'WordPress';
$wp_http_curl = new WP_Http_Curl();
$response = $wp_http_curl->request($url, $args);
}elseif($method == 'HEAD'){
if($need_json_encode && is_array($args['body'])){
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_head($url, $args);
}else{
if($need_json_encode && is_array($args['body'])){
$args['body'] = json_encode($args['body']);
}
$response = wp_remote_request($url, $args);
}
if(is_wp_error($response)){
trigger_error($url."\n".$response->get_error_code().' : '.$response->get_error_message()."\n".var_export($args['body'],true));
return $response;
}
$headers = $response['headers'];
$response = $response['body'];
if($need_json_decode || isset($headers['content-type']) && strpos($headers['content-type'], '/json')){
if($args['stream']){
$response = file_get_contents($args['filename']);
}
$response = json_decode($response);
if(get_current_blog_id() == 339){
// print_r($response);
}
if(is_wp_error($response)){
return $response;
}
}
extract(wp_parse_args($err_args, array(
'errcode' =>'errcode',
'errmsg' =>'errmsg',
'detail' =>'detail',
'success' =>0,
)));
if(isset($response[$errcode]) && $response[$errcode] != $success){
$errcode = $response[$errcode];
$errmsg = isset($response[$errmsg])?$response[$errmsg]:'';
if(isset($response[$detail])){
$detail = $response[$detail];
trigger_error($url."\n".$errcode.' : '.$errmsg."\n".var_export($detail,true)."\n".var_export($args['body'],true));
return new WP_Error($errcode, $errmsg, $detail);
}else{
trigger_error($url."\n".$errcode.' : '.$errmsg."\n".var_export($args['body'],true));
return new WP_Error($errcode, $errmsg);
}
}
if(isset($_GET['debug'])){
echo $url;
print_r($response);
}
return $response;
}
//
function gdk_get_qq_vid($id_or_url){
if(filter_var($id_or_url, FILTER_VALIDATE_URL)){
if(preg_match('#https://v.qq.com/x/page/(.*?).html#i',$id_or_url, $matches)){
return $matches[1];
}elseif(preg_match('#https://v.qq.com/x/cover/.*/(.*?).html#i',$id_or_url, $matches)){
return $matches[1];
}else{
return '';
}
}else{
return $id_or_url;
}
}
function get_video_mp4($id_or_url){
if(filter_var($id_or_url, FILTER_VALIDATE_URL)){
if(preg_match('#http://www.miaopai.com/show/(.*?).htm#i',$id_or_url, $matches)){
return 'http://gslb.miaopai.com/stream/'.esc_attr($matches[1]).'.mp4';
}elseif(preg_match('#https://v.qq.com/x/page/(.*?).html#i',$id_or_url, $matches)){
return get_qqv_mp4($matches[1]);
}elseif(preg_match('#https://v.qq.com/x/cover/.*/(.*?).html#i',$id_or_url, $matches)){
return get_qqv_mp4($matches[1]);
}else{
return str_replace(['%3A','%2F'], [':','/'], urlencode($id_or_url));
}
}else{
return get_qqv_mp4($id_or_url);
}
}
function get_qqv_mp4($vid){
if(strlen($vid) > 20){
return new WP_Error('invalid_qqv_vid', '非法的腾讯视频 ID');
}
$mp4 = wp_cache_get($vid, 'qqv_mp4');
if($mp4 === false){
$response = gdk_http_request('http://vv.video.qq.com/getinfo?otype=json&platform=11001&vid='.$vid, array(
'timeout' =>4,
'need_json_decode' =>false
));
if(is_wp_error($response)){
return $response;
}
$response = trim(substr($response, strpos($response, '{')),';');
$response = json_decode($response);
if(is_wp_error($response)){
return $response;
}
if(empty($response['vl'])){
return new WP_Error('illegal_qqv', '该腾讯视频不存在或者为收费视频!');
}
$u = $response['vl']['vi'][0];
$p0 = $u['ul']['ui'][0]['url'];
$p1 = $u['fn'];
$p2 = $u['fvkey'];
$mp4 = $p0.$p1.'?vkey='.$p2;
wp_cache_set($vid, $mp4, 'qqv_mp4', HOUR_IN_SECONDS*6);
}
return $mp4;
}

View file

@ -1,2 +0,0 @@
<?php

View file

@ -1,93 +0,0 @@
<?php
$nc_option = get_option('nc_option');
$others_seo = $nc_option['others_seo'];
if ($others_seo['noindex_author_page']) {
if (!function_exists('nc_no_index_author_page')):
function nc_no_index_author_page()
{
if (is_author()) {
wp_no_robots();
}
}
add_action('wp_head', 'nc_no_index_author_page');
endif;
}
if ($others_seo['sitemap_xml']) {
$GLOBALS['nice_sitemap_xml'] = true;
include(NC_OPTIMIZEUP_DIR . '/functions/sitemap-xml.php');
}
if ($others_seo['auto_nofollow']) {
if (!function_exists('nc_nofollow')):
add_filter('the_content', 'nc_nofollow');
add_filter('the_excerpt', 'nc_nofollow');
function nc_nofollow($content)
{
return preg_replace_callback('/<a[^>]+/', 'nc_nofollow_callback', $content);
}
function nc_nofollow_callback($matches)
{
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=\S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
}
return $link;
}
endif;
}
if (isset($others_seo['baidu_submit']) && $others_seo['baidu_submit']) {
add_action('post_updated', 'nc_baidu_submit');
function nc_baidu_submit($post_ID)
{
global $post;
$bd_submit_site = get_bloginfo('url');
$bd_submit_token = $others_seo['baidu_submit_key'];
if (empty($post_ID) || empty($bd_submit_site) || empty($bd_submit_token)) {
return;
}
$api = 'http://data.zz.baidu.com/urls?site='.$bd_submit_site.'&token='.$bd_submit_token;
$status = $post->post_status;
if ($status != '' && $status != 'publish') {
$url = get_permalink($post_ID);
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $url,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain')
);
curl_setopt_array($ch, $options);
}
}
add_action('wp_footer', 'nc_baidu_auto_code', 500);
function nc_baidu_auto_code()
{
echo '<script>
(function(){
var bp = document.createElement(\'script\');
var curProtocol = window.location.protocol.split(\':\')[0];
if (curProtocol === \'https\') {
bp.src = \'https://zz.bdstatic.com/linksubmit/push.js\';
}
else {
bp.src = \'http://push.zhanzhang.baidu.com/push.js\';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>';
}
}

View file

@ -1,40 +0,0 @@
<?php
$nc_option = get_option('nc_option');
if (!function_exists('nc_mail_smtp')):
add_action('phpmailer_init', 'nc_mail_smtp');
function nc_mail_smtp( $phpmailer ) {
$nc_option = get_option('nc_option');
$smtp = $nc_option['smtp'];
$phpmailer->FromName = $smtp['smtp_fromname'];
$phpmailer->Host = $smtp['smtp_host'];
$phpmailer->Port = $smtp['smtp_port'];
$phpmailer->Username = $smtp['smtp_username'];
$phpmailer->Password = $smtp['smtp_password'];
$phpmailer->From = $smtp['smtp_display_mail'];
$phpmailer->SMTPAuth = true;
$phpmailer->SMTPSecure = $smtp['smtp_secure'] == 'none' ? '' : $smtp['smtp_secure'];
$phpmailer->IsSMTP();
}
endif;
if (!function_exists('nc_test_email')):
add_action('wp_ajax_nopriv_nc_test_email', 'nc_test_email');
add_action('wp_ajax_nc_test_email', 'nc_test_email');
function nc_test_email() {
$is_error = !wp_mail('donotreply@mywpku.com', '测试发信', 'WP 积木测试发信');
if ($is_error) {
echo json_encode(array(
's' => 400,
'm' => '发信失败,请检查配置是否正确'
));
die();
}
echo json_encode(array(
's' => 200,
'm' => '测试成功'
));
die();
}
endif;

View file

@ -2,33 +2,7 @@
$nc_option = get_option('nc_option');
$usability = $nc_option['usability'];
if ($usability['friendly_images']) {
//给文章图片自动添加alt和title信息
if (!function_exists('nc_imagesalt')):
function nc_imagesalt($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 alt="'.strip_tags($post->post_title).'" title="'.strip_tags($post->post_title).'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'nc_imagesalt');
endif;
if (!function_exists('nc_image_alt_tag')):
function nc_image_alt_tag($content) {
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {
foreach($images[1] as $index => $value){
$new_img = str_replace('<img', '<img alt="'.strip_tags($post->post_title).'-'.get_option('blogname').'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
return $content;
}
add_filter('the_content', 'nc_image_alt_tag', 99999);
endif;
}
if ($usability['no_category_base']) {
if (!function_exists('nc_no_category_base_refresh_rules')):
@ -95,23 +69,7 @@ if ($usability['no_category_base']) {
endif;
}
if ($usability['auto_rename_media_files']) {
if (!function_exists('nc_rename_upload_filter')):
add_filter('wp_handle_upload_prefilter', 'nc_rename_upload_filter' );
function nc_rename_upload_filter( $file ){
$info = pathinfo($file['name']);
$ext = $info['extension'];
$ignore_exts = ['zip', 'rar', '7z'];
if (!in_array($ext, $ignore_exts)) {
$filedate = date('YmdHis').rand(10,99); //为了避免时间重复再加一段2位的随机数
$file['name'] = $filedate.'.'.$ext;
}
return $file;
}
endif;
}
if (!function_exists('nc_custom_head_code')):
add_action('wp_head', 'nc_custom_head_code');
function nc_custom_head_code() {
@ -130,9 +88,7 @@ if (!function_exists('nc_custom_footer_code')):
}
endif;
if ($usability['disable_admin_bar']) {
add_filter('show_admin_bar', '__return_false');
}
if( $usability['nc_highlight'] == 1 ){
@ -169,76 +125,7 @@ if( $usability['nc_highlight'] == 1 && is_admin() ){
}
if( $usability['nc_lazyload'] == 1 && !is_admin() ){
require_once( NC_OPTIMIZEUP_DIR . '/lib/phpQuery/phpQuery.php' );
function usability_lazyload(){
wp_register_script( 'ncLazyloadJs', NC_OPTIMIZEUP_URL . 'assets/lazyload/lazyload.min.js', array(), NC_OPTIMIZEUP_VERSION, true );
wp_enqueue_script('ncLazyloadJs');
}
add_action( 'wp_enqueue_scripts', 'usability_lazyload' );
add_action( 'wp', 'nc_lazyload_start');
}
function nc_lazyload_start(){
ob_start( 'lazyload_replaces' );
}
function lazyload_replaces( $buffer ){
$html = phpQuery::newDocument( $buffer );
phpQuery::selectDocument($html);
pq('body pre *,body code *')->addClass('nc-no-lazy');
$images = pq('body img:not(.nc-no-lazy, .post_cover_image, .loading)');
$other = pq('body *[style]:not(.nc-no-lazy, .post_cover_image, .loading)');
pq('body pre *,body code *')->removeClass('nc-no-lazy');
foreach ($images as $key => $image) {
$src = pq( $image )->attr( 'src' );
if( $src ){
pq( $image )
->attr( 'src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' )
->attr( 'data-src', $src )
->attr( 'data-nclazyload', 'true');
}
$srcset = pq( $image )->attr( 'srcset' );
if( $srcset ){
pq( $image )->attr('data-srcset', $srcset )->removeAttr('srcset');
}
$sizes = pq( $image )->attr( 'sizes' );
if( $sizes ){
pq( $image )->attr('data-sizes', $sizes )->removeAttr('sizes');
}
}
foreach ($other as $key => $item) {
$style = pq($item)->attr('style');
preg_match('/(.*?)background(-image)?:(\s?url\(.*?\))(.*?)/im', $style, $matches );
if( isset( $matches[3] ) ){
pq($item)->attr('style', $matches[1] . 'background' . $matches[2] . ':url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")' . $matches[4] );
pq($item)->attr('data-bg', $matches[3])->attr( 'data-nclazyload', 'true');
}
}
return $html->htmlOuter();
}
if( $usability['nc_lightgallery'] == 1 && !is_admin() ){
@ -264,9 +151,7 @@ if( $usability['nc_lightgallery'] == 1 && !is_admin() ){
}
if ($nc_option['wechat_qq_share_custom']) {
include( NC_STORE_ROOT_PATH . 'modules/pluggable/custom_share.php' );
}
if( isset( $usability['hide_author_url_user_name'] ) && $usability['hide_author_url_user_name'] == 1 ){