-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathfunctions.php
1688 lines (1613 loc) · 67.5 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
if (phpversion() < 5.5) {
wp_die('本主题不支持在PHP5.5以下版本运行,请升级PHP版本 ^_^');
}
/*定义一些常量*/
define('GIT_VER', wp_get_theme()->get('Version'));
define('GIT_URL', get_template_directory_uri());
add_action('after_setup_theme', 'deel_setup');
require ('admin/theme-options.php');
require ('admin/theme-widgets.php');
require ('admin/theme-metabox.php');
require ('include/func_load.php');
if (!defined('POINTS_CORE_DIR')) {
require ('modules/points.php');
}
function deel_setup() {
//添加主题特性
add_theme_support('post-thumbnails');//缩略图设置
add_theme_support('post-formats', array('aside')); //增加文章形式
add_theme_support('custom-background', array(
'default-image' => GIT_URL . '/assets/img/bg.png',
'default-repeat' => 'repeat',
'default-position-x' => 'left',
'default-position-y' => 'top',
'default-size' => 'auto',
'default-attachment' => 'fixed'
));
//移除WordPress 5.8的小工具区块编辑器
remove_theme_support( 'widgets-block-editor' );
add_editor_style('editor-style.css');
//定义菜单
if (function_exists('register_nav_menus')) {
register_nav_menus(array(
'nav' => '网站导航',
'pagemenu' => '页面导航'
));
}
}
//自定义ajax提醒
function git_err($ErrMsg) {
header('HTTP/1.1 405 Method Not Allowed');
//echo $ErrMsg;
exit($ErrMsg);
}
//去除部分默认小工具
function unregister_d_widget() {
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
}
add_action('widgets_init', 'unregister_d_widget');
//添加后台左下角文字
function git_admin_footer_text($text){
$text = '感谢使用<a target="_blank" href="https://gitcafe.net/" >Git主题 ' . GIT_VER . '</a>进行创作';
return $text;
}
add_filter('admin_footer_text', 'git_admin_footer_text');
//显示数据库查询次数、查询时间及内存占用的代码
function git_performance($visible = false) {
$stat = sprintf('%d 次查询 用时 %.3f 秒, 耗费了 %.2fMB 内存', get_num_queries() , timer_stop(0, 3) , memory_get_peak_usage() / 1024 / 1024);
echo $visible ? $stat : "<!-- {$stat} -->";
}
add_action('wp_footer', 'git_performance', 20);
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => '全站侧栏',
'id' => 'widget_sitesidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
register_sidebar(array(
'name' => '首页侧栏',
'id' => 'widget_sidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
register_sidebar(array(
'name' => '分类/标签/搜索页侧栏',
'id' => 'widget_othersidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
register_sidebar(array(
'name' => '文章页侧栏',
'id' => 'widget_postsidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
register_sidebar(array(
'name' => '页面侧栏',
'id' => 'widget_pagesidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<div class="title"><h2>',
'after_title' => '</h2></div>'
));
}
//面包屑导航
function deel_breadcrumbs(){
if (!is_single() || get_post_type() != 'post') {
return false;
}
$categorys = get_the_category();
$category = $categorys[0];
return '<a title="返回首页" href="' . home_url() . '"><i class="fa fa-home"></i></a> <small>></small> ' . get_category_parents($category->term_id, true, ' <small>></small> ') . '<span class="muted">' . get_the_title() . '</span>';
}
// 取消原有jQuery,加载自定义jQuery
function footerScript() {
if (!is_admin()) {
wp_deregister_script('jquery');
if (git_get_option('git_jqcdn') == 'git_jqcdn_upai') {
wp_register_script('jquery', 'https://cdn.jsdelivr.net/gh/yunluo/GitCafeApi/js/jquery-1.8.3.min.js', false, '1.0', true); //底部加载,速度快,兼容差
} else {
wp_register_script('jquery', GIT_URL . '/assets/js/jquery.min.js', false, '1.0', false); //头部加载,速度慢,兼容好
}
wp_enqueue_script('jquery');
wp_register_script('default', GIT_URL . '/assets/js/app.js', false, '1.0', true); //底部加载
wp_enqueue_script('default');
wp_register_style('style', GIT_URL . '/style.css', false, '1.0');
wp_enqueue_style('style');
}
}
add_action('wp_enqueue_scripts', 'footerScript');
/*
* 来自:https://wp-kama.ru/function/get_comment_reply_link
*/
function git_replace_comment_reply_link($link, $args, $comment, $post) {
if (get_option('comment_registration') && !is_user_logged_in()) {
$link = sprintf(
'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
esc_url(wp_login_url(get_permalink())),
$args['login_text']
);
} else {
$onclick = sprintf(
'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
$args['add_below'],
$comment->comment_ID,
$args['respond_id'],
$post->ID
);
$link = sprintf(
"<a rel='nofollow' class='comment-reply-link' href='%s' onclick='%s' aria-label='%s'>%s</a>",
esc_url(add_query_arg('replytocom', $comment->comment_ID, get_permalink($post->ID))) . "#" . $args['respond_id'],
$onclick,
esc_attr(sprintf($args['reply_to_text'], $comment->comment_author)),
$args['reply_text']
);
}
return $link;
}
add_filter('comment_reply_link', 'git_replace_comment_reply_link', 10, 4);
if (!function_exists('deel_paging')) {
function deel_paging(){
$p = 4;
if (is_singular()) {
return;
}
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ($max_page == 1) {
return;
}
echo '<div class="pagination"><ul>';
if (empty($paged)) {
$paged = 1;
}
// echo '<span class="pages">Page: ' . $paged . ' of ' . $max_page . ' </span> ';
echo '<li class="prev-page">';
previous_posts_link('上一页');
echo '</li>';
if ($paged > $p + 1) {
p_link(1, '<li>第一页</li>');
}
if ($paged > $p + 2) {
echo "<li><span>···</span></li>";
}
for ($i = $paged - $p; $i <= $paged + $p; $i++) {
if ($i > 0 && $i <= $max_page) {
$i == $paged ? print "<li class=\"active\"><span>{$i}</span></li>" : p_link($i);
}
}
if ($paged < $max_page - $p - 1) {
echo "<li><span> ... </span></li>";
}
//if ( $paged < $max_page - $p ) p_link( $max_page, '»' );
echo '<li class="next-page">';
next_posts_link('下一页');
echo '</li>';
// echo '<li><span>共 '.$max_page.' 页</span></li>';
echo '</ul></div>';
}
function p_link($i, $title = '')
{
if ($title == '') {
$title = "第 {$i} 页";
}
echo "<li><a href='", esc_html(get_pagenum_link($i)), "'>{$i}</a></li>";
}
}
function deel_strimwidth($str, $start, $width, $trimmarker) {
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $start . '}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,' . $width . '}).*/s', '\1', $str);
return $output . $trimmarker;
}
if (!function_exists('deel_views')) {
function deel_record_visitors(){
if (is_singular()) {
global $post;
$post_ID = $post->ID;
if ($post_ID) {
$post_views = (int) get_post_meta($post_ID, 'views', true);
if (!update_post_meta($post_ID, 'views', $post_views + 1)) {
add_post_meta($post_ID, 'views', 1, true);
}
}
}
}
add_action('wp_head', 'deel_record_visitors');
function deel_views($after = '')
{
global $post;
$post_ID = $post->ID;
$views = (int) get_post_meta($post_ID, 'views', true);
echo $views, $after;
}
}
//页面伪静态
if (git_get_option('git_pagehtml_b')) {
function html_page_permalink(){
global $wp_rewrite;
if (!strpos($wp_rewrite->get_page_permastruct(), '.html')) {
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
}
}
add_action('init', 'html_page_permalink', -1);
function git_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) && !is_admin()) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'git_search_url_rewrite' );
}
//baidu分享
$dHasShare = false;
function deel_share() {
if (!git_get_option('git_bdshare_b')) return false;
echo '<span class="action action-share bdsharebuttonbox"><i class="fa fa-share-alt"></i>分享 (<span class="bds_count" data-cmd="count" title="累计分享0次">0</span>)<div class="action-popover"><div class="popover top in"><div class="arrow"></div><div class="popover-content"><a href="#" class="sinaweibo fa fa-weibo" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_qzone fa fa-star" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="qq fa fa-qq" data-cmd="sqq" title="分享到QQ好友"></a><a href="#" class="bds_renren fa fa-renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin fa fa-weixin" data-cmd="weixin" title="分享到微信"></a><a href="#" class="bds_more fa fa-ellipsis-h" data-cmd="more"></a></div></div></div></span>';
global $dHasShare;
$dHasShare = true;
}
//搜索表单
function git_searchform() {
?>
<form method="get" class="searchform themeform" action="<?php echo get_option('home'); ?>">
<div><input type="text" class="search" placeholder="<?php echo git_get_option('git_search_placeholder'); ?>" name="s" x-webkit-speech /></div>
</form>
</div>
</div>
<?php
}
//最新发布加new 单位'小时'
function deel_post_new($timer = '48') {
$t = (strtotime(date("Y-m-d H:i:s")) - strtotime($post->post_date)) / 3600;
if ($t < $timer) echo "<i>new</i>";
}
//修改评论表情调用路径
function deel_smilies_src($img_src, $img, $siteurl) {
return GIT_URL . '/assets/img/smilies/' . $img;
}
add_filter('smilies_src', 'deel_smilies_src', 1, 10);
//自动勾选
function deel_add_checkbox() {
echo '<label for="comment_mail_notify" class="checkbox inline" style="padding-top:0;"><input name="comment_mail_notify" id="comment_mail_notify" value="comment_mail_notify" checked="checked" type="checkbox">评论通知</label>';
}
add_action('comment_form', 'deel_add_checkbox');
//时间显示方式‘xx以前’
function time_ago($type = 'commennt', $day = 7) {
$d = $type == 'post' ? 'get_post_time' : 'get_comment_time';
if (time() - $d('U') > 60 * 60 * 24 * $day) return;
echo ' (', human_time_diff($d('U') , strtotime(current_time('mysql', 0))) , '前)';
}
function timeago($ptime) {
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if ($etime < 1) return '刚刚';
$interval = array(
12 * 30 * 24 * 60 * 60 => '年前 (' . date('Y-m-d', $ptime) . ')',
30 * 24 * 60 * 60 => '个月前 (' . date('m-d', $ptime) . ')',
7 * 24 * 60 * 60 => '周前 (' . date('m-d', $ptime) . ')',
24 * 60 * 60 => '天前',
60 * 60 => '小时前',
60 => '分钟前',
1 => '秒前'
);
foreach ($interval as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . $str;
}
};
}
//评论样式
function deel_comment_list($comment, $args, $depth) {
echo '<li ';
comment_class();
echo ' id="comment-' . get_comment_ID() . '">';
//头像
echo '<div class="c-avatar">';
echo str_replace(' src=', ' data-original=', get_avatar($comment->comment_author_email, $size = '54', deel_avatar_default()));
//内容
echo '<div class="c-main" id="div-comment-' . get_comment_ID() . '">';
echo str_replace(' src=', ' data-original=', convert_smilies(get_comment_text()));
if ($comment->comment_approved == '0') {
echo '<span class="c-approved">您的评论正在排队审核中,请稍后!</span><br />';
}
//信息
echo '<div class="c-meta">';
if ($comment->user_id !== '0') {
echo '<span class="c-author"><a target="_blank" href="' . get_author_posts_url($comment->user_id) . '">' . get_comment_author() . '</a></span>';
} else {
echo '<span class="c-author">' . get_comment_author_link() . '</span>';
}
if ($comment->user_id == '1') {
echo '<a title="博主认证" class="vip"></a>';
} elseif (git_get_option('git_vip')) {
echo get_author_class($comment->comment_author_email, $comment->user_id);
}
echo get_comment_time('Y-m-d H:i ');
echo time_ago();
if ($comment->comment_approved !== '0') {
echo comment_reply_link(array_merge($args, array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth']
)));
echo edit_comment_link('(编辑)', ' - ', '');
if (git_get_option('git_ua_b')) echo '<span style="color: #ff6600;"> ' . user_agent($comment->comment_agent) . '</span>';
}
echo '</div>';
echo '</div></div>';
}
//添加编辑器快捷按钮
function my_quicktags() {
global $pagenow;
if ($pagenow == 'post-new.php' || $pagenow == 'post.php') {
wp_enqueue_script('my_quicktags', GIT_URL . '/assets/js/my_quicktags.js', array(
'quicktags'
) , '1.0', true);
}
};
add_action('admin_print_scripts', 'my_quicktags');
//过滤外文评论
if (git_get_option('git_spam_lang')) {
function refused_spam_comments($commentdata){
if (is_user_logged_in()) {
return $commentdata;
}
$pattern = '/[一-龥]/u';
$jpattern = '/[ぁ-ん]+|[ァ-ヴ]+/u';
if (!preg_match($pattern, $commentdata['comment_content'])) {
git_err('写点汉字吧,博主外语很捉急!You should type some Chinese word!');
}
if (preg_match($jpattern, $commentdata['comment_content'])) {
git_err('日文滚粗!Japanese Get out!日本语出て行け! You should type some Chinese word!');
}
return $commentdata;
}
add_filter('preprocess_comment', 'refused_spam_comments');
}
//屏蔽关键词,email,url,ip
if (git_get_option('git_spam_keywords')) {
function Googlofuckspam($commentdata){
if (is_user_logged_in()) {
return $commentdata;
}
if (wp_blacklist_check($commentdata['comment_author'], $commentdata['comment_author_email'], $commentdata['comment_author_url'], $commentdata['comment_content'], $commentdata['comment_author_IP'], $commentdata['comment_agent'])) {
header("Content-type: text/html; charset=utf-8");
git_err('不好意思,您的评论违反本站评论规则');
} else {
return $commentdata;
}
}
add_filter('preprocess_comment', 'Googlofuckspam');
}
//屏蔽长连接评论
if (git_get_option('git_spam_long') && !is_user_logged_in()) {
function lang_url_spamcheck($approved, $commentdata)
{
return strlen($commentdata['comment_author_url']) > 50 ? 'spam' : $approved;
}
add_filter('pre_comment_approved', 'lang_url_spamcheck', 99, 2);
}
//屏蔽昵称,评论内容带链接的评论
if (git_get_option('git_spam_url')) {
function Googlolink($commentdata){
if (is_user_logged_in()) {
return $commentdata;
}
$links = '/http:\\/\\/|https:\\/\\/|www\\./u';
if (preg_match($links, $commentdata['comment_author']) || preg_match($links, $commentdata['comment_content'])) {
git_err('在昵称和评论里面是不准发链接滴.');
}
return $commentdata;
}
add_filter('preprocess_comment', 'Googlolink');
}
//点赞
add_action('wp_ajax_nopriv_bigfa_like', 'bigfa_like');
add_action('wp_ajax_bigfa_like', 'bigfa_like');
function bigfa_like() {
global $wpdb, $post;
$id = filter_var($_POST["um_id"], FILTER_SANITIZE_NUMBER_INT);
$action = $_POST["um_action"];
if ($action == 'ding') {
$bigfa_raters = get_post_meta($id, 'bigfa_ding', true);
$expire = time() + 99999999;
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
setcookie('bigfa_ding_' . $id, $id, $expire, '/', $domain, false);
if (!$bigfa_raters || !is_numeric($bigfa_raters)) {
update_post_meta($id, 'bigfa_ding', 1);
} else {
update_post_meta($id, 'bigfa_ding', ($bigfa_raters + 1));
}
echo get_post_meta($id, 'bigfa_ding', true);
}
die;
}
//密码可见ajax
function pass_view(){
if (isset($_POST['pass']) && isset($_POST['id']) && $_POST['pass'] == git_get_option('git_mp_code') && $_POST['action'] == 'pass_view') {
$pass_content = get_post_meta($_POST['id'], 'pass_content', true);
exit($pass_content);
}else{
exit(0);
}
}
add_action( 'wp_ajax_pass_view', 'pass_view' );
add_action( 'wp_ajax_nopriv_pass_view', 'pass_view' );
//weauth自动登录
function bind_email_check(){
$mail = isset($_POST['email']) ? $_POST['email'] : false;
if($mail && $_POST['action'] == 'bind_email_check'){
$user_id = email_exists( $email );
if ($user_id) {
exit(1);
}
}
}
add_action( 'wp_ajax_bind_email_check', 'bind_email_check' );
add_action( 'wp_ajax_nopriv_bind_email_check', 'bind_email_check' );
//weauth自动登录
function weauth_oauth_login(){
$key = isset($_POST['spam']) ? $_POST['spam'] : false;
$mail = isset($_POST['email']) ? $_POST['email'] : false;
if($key && $_POST['action'] == 'weauth_oauth_login'){
$user_id = get_transient($key.'ok');
if ($user_id != 0) {
wp_set_auth_cookie($user_id,true);
if($mail && !empty($mail) && is_email($mail)){
wp_update_user( array( 'ID' => $user_id, 'user_email' => $mail ) );
}
exit(wp_unique_id());
}
}
}
add_action( 'wp_ajax_weauth_oauth_login', 'weauth_oauth_login' );
add_action( 'wp_ajax_nopriv_weauth_oauth_login', 'weauth_oauth_login' );
//付费可见
function pay_buy(){
if (isset($_POST['point']) && isset($_POST['userid']) &&isset($_POST['id']) && $_POST['action'] == 'pay_buy') {
$all = Points::get_user_total_points($_POST['userid'], 'accepted');
if( $all < $_POST['point']){
exit;
}else{
Points::set_points( -$_POST['point'],$_POST['userid'],
array(
'description' => $_POST['id'],
'status' => 'accepted'
)
);//扣除金币
$pay_content = get_post_meta($_POST['id'], 'pay_content', true);
exit($pay_content);
}
}
}
add_action( 'wp_ajax_pay_buy', 'pay_buy' );
add_action( 'wp_ajax_nopriv_pay_buy', 'pay_buy' );
/*免登陆购买开始*/
//获取加密内容
function getcontent(){
$id = $_POST["id"];
$action = $_POST["action"];
if ( isset($id) && $_POST['action'] == 'getcontent') {
$pay_content = get_post_meta($id, 'git_pay_content', true);
exit($pay_content);
}
}
add_action( 'wp_ajax_getcontent', 'getcontent' );
add_action( 'wp_ajax_nopriv_getcontent', 'getcontent' );
///提取码检测
function check_code() {
$id = $_POST['id'];
$code = $_POST['code'];
if(empty($code))exit('0');
if (isset($id) && $_POST['action'] == 'check_code') {
$pay_log = get_post_meta($id, 'pay_log', true);
//购买记录数据
$pay_arr = explode(",", $pay_log);
if(in_array($code,$pay_arr)) {
exit('1');
} else {
exit('0');
}
}
}
add_action( 'wp_ajax_check_code', 'check_code' );
add_action( 'wp_ajax_nopriv_check_code', 'check_code' );
//在线充值
function payjs_view(){
$id = $_POST['id'];
$money = $_POST['money'];
$way = $_POST['way'];
if (isset($id) && isset($money) && isset($way) && $_POST['action'] == 'payjs_view') {
$config = [
'mchid' => git_get_option('git_payjs_id'), // 配置商户号
'key' => git_get_option('git_payjs_secret'), // 配置通信密钥
];
// 初始化
$payjs = new Payjs($config);
$data = [
'body' => '在线付费查看', // 订单标题
'attach' => 'P'.$id,
'out_trade_no' => git_order_id(), // 订单号
'total_fee' => intval($money)*100, // 金额,单位:分
'notify_url' => GIT_URL.'/modules/push.php',
'hide' => '1'
];
if($way == 1) $data['type'] = 'alipay';
$result_money = intval($money);
$result_trade_no = $data['out_trade_no'];
if(git_is_mobile()){
$rst = $payjs->cashier($data);//手机使用
$result_img = $rst;
}else{
$rst = $payjs->native($data);//电脑使用
$result_img = $rst['code_url'];
}
$result = $result_money.'|'. $result_img.'|'. $result_trade_no;
}
exit($result);
}
add_action( 'wp_ajax_payjs_view', 'payjs_view' );
add_action( 'wp_ajax_nopriv_payjs_view', 'payjs_view' );
function checkpayjs(){
$id = $_POST['id'];
$orderid = $_POST['orderid'];
if (isset($id) && isset($orderid) && $_POST['action'] == 'checkpayjs') {
$sid = get_transient('P'.$id);
if(strpos($sid,'E20') !== false && $orderid == $sid){
exit('1');//OK
}else{
exit('0');//no
}
}
}
add_action( 'wp_ajax_checkpayjs', 'checkpayjs' );
add_action( 'wp_ajax_nopriv_checkpayjs', 'checkpayjs' );
function addcode(){
$id = $_POST['id'];
$code = $_POST['code'];
if (isset($id) && isset($code) && $_POST['action'] == 'addcode') {
$pay_log = get_post_meta($id, 'pay_log', true);//购买记录数据
if(empty($pay_log)){
add_post_meta($id, 'pay_log', $code, true);
}else{
update_post_meta($id, 'pay_log', $pay_log.','.$code);
}
$pay_log = get_post_meta($id, 'pay_log', true);//购买记录数据
$pay_arr = explode(",", $pay_log);
if(in_array($code,$pay_arr)){
exit('1');//OK
}else{
exit('0');//NO
}
}
}
add_action( 'wp_ajax_addcode', 'addcode' );
add_action( 'wp_ajax_nopriv_addcode', 'addcode' );
/*免登陆购买结束*/
//在线充值
function pay_chongzhi(){
if (isset($_POST['jine']) && $_POST['action'] == 'pay_chongzhi') {
$config = [
'mchid' => git_get_option('git_payjs_id'), // 配置商户号
'key' => git_get_option('git_payjs_secret'), // 配置通信密钥
];
// 初始化
$payjs = new Payjs($config);
$data = [
'body' => '积分充值', // 订单标题
'attach' => get_current_user_id(), // 订单备注
'out_trade_no' => git_order_id(), // 订单号
'total_fee' => intval($_POST['jine'])*100, // 金额,单位:分
'notify_url' => GIT_URL.'/modules/push.php',
'hide' => '1'
];
$result_money = intval($_POST['jine']);
$result_trade_no = $data['out_trade_no'];
if( git_get_option('git_payjs_alipay') && $_POST['way'] =='alipay' ){
$data['type'] = 'alipay';
$result_way = '支付宝';
}else{
$result_way = '微信';
}
if(git_is_mobile()){
$rst = $payjs->cashier($data);//手机使用
$result_img = $rst;
}else{
$rst = $payjs->native($data);//电脑使用
$result_img = $rst['code_url'];
}
$result = $result_money.'|'.$result_way.'|'. $result_img.'|'. $result_trade_no;
exit($result);
}
}
add_action( 'wp_ajax_pay_chongzhi', 'pay_chongzhi' );
add_action( 'wp_ajax_nopriv_pay_chongzhi', 'pay_chongzhi' );
//检查付款情况
function payrest(){
if (isset($_POST['check_trade_no']) && $_POST['action'] == 'payrest') {
if (git_check($_POST['check_trade_no'])) {
exit('1');
} else {
exit('0');
}
}
}
add_action( 'wp_ajax_payrest', 'payrest' );
add_action( 'wp_ajax_nopriv_payrest', 'payrest' );
//ajax生成登录二维码
function weauth_qr_gen(){
if (isset($_POST['wastart']) && $_POST['action'] == 'weauth_qr_gen') {
if (!empty($_POST['wastart'])) {
$rest = implode("|", get_weauth_qr());
exit($rest);
}
}
}
add_action( 'wp_ajax_weauth_qr_gen', 'weauth_qr_gen' );
add_action( 'wp_ajax_nopriv_weauth_qr_gen', 'weauth_qr_gen' );
//检查登录状况
function weauth_check(){
if (isset($_POST['sk']) && $_POST['action'] == 'weauth_check') {
$rest = substr($_POST['sk'],-3);//key
$weauth_cache = get_transient($rest.'ok');
if (!empty($weauth_cache)) {
exit($rest);//key
}
}
}
add_action( 'wp_ajax_weauth_check', 'weauth_check' );
add_action( 'wp_ajax_nopriv_weauth_check', 'weauth_check' );
//最热排行
function hot_posts_list() {
if (git_get_option('git_hot_b') == 'git_hot_zd') {
$result = get_posts(array(
'post__in' => get_option('sticky_posts') ,
'order' => 'DESC',
'orderby' => 'comment_count',
'posts_per_page' => '10'
));
} elseif (git_get_option('git_hot_b') == 'git_hot_comment') {
$result = get_posts("numberposts=5&orderby=comment_count&order=desc");
}
$output = '';
if (empty($result)) {
$output = '<li>暂无数据</li>';
} else {
$i = 1;
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
$output.= '<li><p><span class="post-comments">评论 (' . $commentcount . ')</span><span class="muted"><a href="javascript:;" data-action="ding" data-id="' . $postid . '" id="Addlike" class="action';
if (isset($_COOKIE['bigfa_ding_' . $postid])) $output.= ' actived';
$output.= '"><i class="fa fa-heart-o"></i><span class="count">';
if (get_post_meta($postid, 'bigfa_ding', true)) {
$output.= get_post_meta($postid, 'bigfa_ding', true);
} else {
$output.= '0';
}
$output.= '</span>赞</a></span></p><span class="label label-' . $i . '">' . $i . '</span><a href="' . get_permalink($postid) . '" title="' . $title . '">' . $title . '</a></li>';
$i++;
}
}
echo $output;
}
//在 WordPress 编辑器添加“下一页”按钮
function add_next_page_button($mce_buttons) {
$pos = array_search('wp_more', $mce_buttons, true);
if ($pos !== false) {
$tmp_buttons = array_slice($mce_buttons, 0, $pos + 1);
$tmp_buttons[] = 'wp_page';
$mce_buttons = array_merge($tmp_buttons, array_slice($mce_buttons, $pos + 1));
}
return $mce_buttons;
}
add_filter('mce_buttons', 'add_next_page_button');
//判断手机广告
function git_is_mobile() {
if (empty($_SERVER['HTTP_USER_AGENT'])) {
return false;
} elseif ((strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false) // many mobile devices (all iPh, etc.)
|| strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'NetType/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Kindle') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'MQQBrowser') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mobi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'HUAWEI') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'TBS/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'Mi') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false) {
return true;
} else {
return false;
}
}
//搜索结果排除所有页面
function search_filter_page($query) {
if ($query->is_search && !$query->is_admin) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'search_filter_page');
// 更改后台字体
function git_admin_style() {
echo '<style type="text/css">
.setting select.link-to option[value="post"],.setting select[data-setting="link"] option[value="post"]{display:none;}
#wp-admin-bar-git_guide>.ab-item::before {content:"\f331";top:3px;}#wp-admin-bar-git_option>.ab-item::before{content:"\f507";top:3px;}.users #the-list tr:hover{background:rgba(132,219,162,.61)}#role {width:8%;}* { font-family: "Microsoft YaHei" !important; }.wp-admin img.rand_avatar {max-Width:50px !important;}i, .ab-icon, .mce-close, i.mce-i-aligncenter, i.mce-i-alignjustify, i.mce-i-alignleft, i.mce-i-alignright, i.mce-i-blockquote, i.mce-i-bold, i.mce-i-bullist, i.mce-i-charmap, i.mce-i-forecolor, i.mce-i-fullscreen, i.mce-i-help, i.mce-i-hr, i.mce-i-indent, i.mce-i-italic, i.mce-i-link, i.mce-i-ltr, i.mce-i-numlist, i.mce-i-outdent, i.mce-i-pastetext, i.mce-i-pasteword, i.mce-i-redo, i.mce-i-removeformat, i.mce-i-spellchecker, i.mce-i-strikethrough, i.mce-i-underline, i.mce-i-undo, i.mce-i-unlink, i.mce-i-wp-media-library, i.mce-i-wp_adv, i.mce-i-wp_fullscreen, i.mce-i-wp_help, i.mce-i-wp_more, i.mce-i-wp_page, .qt-fullscreen, .star-rating .star,.qt-dfw{ font-family: dashicons !important; }.mce-ico { font-family: tinymce, Arial}.fa { font-family: FontAwesome !important; }.genericon { font-family: "Genericons" !important; }.appearance_page_scte-theme-editor #wpbody *, .ace_editor * { font-family: Monaco, Menlo, "Ubuntu Mono", Consolas, source-code-pro, monospace !important; }
</style>';
}
add_action('admin_head', 'git_admin_style');
//输出缩略图地址
function post_thumbnail_src() {
global $post;
if ($values = get_post_custom_values("git_thumb")) { //输出自定义域图片地址
$values = get_post_custom_values("git_thumb");
$post_thumbnail_src = $values[0];
} elseif (has_post_thumbnail()) { //如果有特色缩略图,则输出缩略图地址
$thumbnail_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID) , 'full');
$post_thumbnail_src = $thumbnail_src[0];
} else {
$post_thumbnail_src = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
@$post_thumbnail_src = $matches[1][0]; //获取该图片 src
if (empty($post_thumbnail_src)) { //如果日志中没有图片,则显示随机图片
$random = mt_rand(1, 12);
echo GIT_URL;
echo '/assets/img/pic/' . $random . '.jpg';
}
};
echo $post_thumbnail_src;
}
//cURL库
if (function_exists('curl_init')) {
function curl_post($url, $postfields = '', $headers = '', $timeout = 20, $file = 0) {
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_NOBODY => false,
CURLOPT_POST => true,
CURLOPT_MAXREDIRS => 20,
CURLOPT_USERAGENT => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
CURLOPT_TIMEOUT => $timeout,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0
);
if (is_array($postfields) && $file == 0) {
$options[CURLOPT_POSTFIELDS] = http_build_query($postfields);
} else {
$options[CURLOPT_POSTFIELDS] = $postfields;
}
curl_setopt_array($ch, $options);
if (is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$result = curl_exec($ch);
$code = curl_errno($ch);
$msg = curl_error($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return array(
'data' => $result,
'code' => $code,
'msg' => $msg,
'info' => $info
);
}
}
//添加文章版权信息
function git_copyright($content) {
if ((is_single() || is_feed()) && git_get_option('git_copyright_b')) {
$copyright = str_replace(array(
'{{title}}',
'{{link}}'
) , array(
get_the_title() ,
get_permalink()
) , stripslashes(git_get_option('git_copyright_b')));
$content.= '<hr /><div class="open-message">' . $copyright . '</div>';
}
return $content;
}
add_filter('the_content', 'git_copyright');
//fancybox图片灯箱效果
function fancybox($content) {
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\\/a>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="box" class="fancybox"$6>$7</a>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter('the_content', 'fancybox');
//输出WordPress表情
function fa_get_wpsmiliestrans() {
global $wpsmiliestrans;
$wpsmilies = array_unique($wpsmiliestrans);
$output = '';
foreach ($wpsmilies as $alt => $src_path) {
$output.= '<a class="add-smily" data-smilies="' . $alt . '"><img class="wp-smiley" style="height:24px;width:24px;" src="' . GIT_URL . '/assets/img/smilies/' . rtrim($src_path, "gif") . 'gif" /></a>';
}
return $output;
}
add_action('media_buttons_context', 'fa_smilies_custom_button');
function fa_smilies_custom_button($context) {
$context = '';
$context.= '<style>.smilies-wrap{background:#fff;border: 1px solid #ccc;box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.24);padding: 10px;position: absolute;top: 60px;width: 375px;display:none}.smilies-wrap img{height:24px;width:24px;cursor:pointer;margin-bottom:5px} .is-active.smilies-wrap{display:block}</style> <a id="insert-media-button" style="position:relative" class="button insert-smilies add_smilies" title="添加表情" data-editor="content" href="javascript:;">^_^ 添加表情</a><div class="smilies-wrap">' . fa_get_wpsmiliestrans() . '</div><script>jQuery(document).ready(function(){jQuery(document).on("click", ".insert-smilies",function() { if(jQuery(".smilies-wrap").hasClass("is-active")){jQuery(".smilies-wrap").removeClass("is-active");}else{jQuery(".smilies-wrap").addClass("is-active");}});jQuery(document).on("click", ".add-smily",function() { send_to_editor(" " + jQuery(this).data("smilies") + " ");jQuery(".smilies-wrap").removeClass("is-active");return false;});});</script>';
return $context;
}
//////// 后台评论列表获取表情按钮//////
function zfunc_smiley_button($custom = false, $before = '', $after = '') {
if ($custom == true) $smiley_url = site_url() . '/wp-includes/images/smilies';
else $customsmiley_url = GIT_URL . '/assets/img/smilies';
echo $before;
?>
<a href="javascript:grin(':?:')"><img src="<?php
echo $customsmiley_url; ?>/icon_question.gif" alt="" /></a>
<a href="javascript:grin(':razz:')"><img src="<?php
echo $customsmiley_url; ?>/icon_razz.gif" alt="" /></a>
<a href="javascript:grin(':sad:')"><img src="<?php
echo $customsmiley_url; ?>/icon_sad.gif" alt="" /></a>
<a href="javascript:grin(':evil:')"><img src="<?php
echo $customsmiley_url; ?>/icon_evil.gif" alt="" /></a>
<a href="javascript:grin(':!:')"><img src="<?php
echo $customsmiley_url; ?>/icon_exclaim.gif" alt="" /></a>
<a href="javascript:grin(':smile:')"><img src="<?php
echo $customsmiley_url; ?>/icon_smile.gif" alt="" /></a>
<a href="javascript:grin(':oops:')"><img src="<?php
echo $customsmiley_url; ?>/icon_redface.gif" alt="" /></a>
<a href="javascript:grin(':grin:')"><img src="<?php
echo $customsmiley_url; ?>/icon_biggrin.gif" alt="" /></a>
<a href="javascript:grin(':eek:')"><img src="<?php
echo $customsmiley_url; ?>/icon_surprised.gif" alt="" /></a>
<a href="javascript:grin(':shock:')"><img src="<?php
echo $customsmiley_url; ?>/icon_eek.gif" alt="" /></a>
<a href="javascript:grin(':???:')"><img src="<?php
echo $customsmiley_url; ?>/icon_confused.gif" alt="" /></a>
<a href="javascript:grin(':cool:')"><img src="<?php
echo $customsmiley_url; ?>/icon_cool.gif" alt="" /></a>
<a href="javascript:grin(':lol:')"><img src="<?php
echo $customsmiley_url; ?>/icon_lol.gif" alt="" /></a>
<a href="javascript:grin(':mad:')"><img src="<?php
echo $customsmiley_url; ?>/icon_mad.gif" alt="" /></a>
<a href="javascript:grin(':twisted:')"><img src="<?php
echo $customsmiley_url; ?>/icon_twisted.gif" alt="" /></a>
<a href="javascript:grin(':roll:')"><img src="<?php
echo $customsmiley_url; ?>/icon_rolleyes.gif" alt="" /></a>
<a href="javascript:grin(':wink:')"><img src="<?php
echo $customsmiley_url; ?>/icon_wink.gif" alt="" /></a>
<a href="javascript:grin(':idea:')"><img src="<?php
echo $customsmiley_url; ?>/icon_idea.gif" alt="" /></a>
<a href="javascript:grin(':arrow:')"><img src="<?php
echo $customsmiley_url; ?>/icon_arrow.gif" alt="" /></a>
<a href="javascript:grin(':neutral:')"><img src="<?php
echo $customsmiley_url; ?>/icon_neutral.gif" alt="" /></a>
<a href="javascript:grin(':cry:')"><img src="<?php
echo $customsmiley_url; ?>/icon_cry.gif" alt="" /></a>
<a href="javascript:grin(':mrgreen:')"><img src="<?php
echo $customsmiley_url; ?>/icon_mrgreen.gif" alt="" /></a>
<?php
echo $after;
}
//Ajax_data_zfunc_smiley_button
function Ajax_data_zfunc_smiley_button() {
if (isset($_GET['action']) && $_GET['action'] == 'Ajax_data_zfunc_smiley_button') {
nocache_headers();
zfunc_smiley_button(false, '<br />');
die();
}
}
add_action('admin_init', 'Ajax_data_zfunc_smiley_button');
//后台回复评论支持表情插入
function zfunc_admin_enqueue_scripts($hook_suffix) {
if ($hook_suffix == 'edit-comments.php') {
wp_enqueue_script('zfunc-comment-reply', GIT_URL . '/assets/js/admin_reply.js', false, '1.0', true);
}
}
add_action('admin_enqueue_scripts', 'zfunc_admin_enqueue_scripts');
//强制阻止WordPress代码转义
function git_esc_html($content) {
$regex = '/(<pre\s+[^>]*?class\s*?=\s*?[",\'].*?prettyprint.*?[",\'].*?>)(.*?)(<\/pre>)/sim';
return preg_replace_callback($regex, 'git_esc_callback', $content);
}
function git_esc_callback($matches) {
$tag_open = $matches[1];
$content = $matches[2];
$tag_close = $matches[3];
$content = esc_html($content);
return $tag_open . $content . $tag_close;
}
add_filter('the_content', 'git_esc_html', 2);
add_filter('comment_text', 'git_esc_html', 2);
//强制兼容<pre>
function git_prettify_replace($text) {
$replace = array(
'<pre>' => '<pre class="prettyprint linenums" >'
);
$text = str_replace(array_keys($replace) , $replace, $text);
return $text;
}
add_filter('the_content', 'git_prettify_replace');
//首页隐藏一些分类
function exclude_category_home($query) {
if ($query->is_home) {
$query->set('cat', git_get_option('git_blockcat')); //隐藏这两个分类
}
return $query;
}
add_filter('pre_get_posts', 'exclude_category_home');
function git_exclude_category_search($query) {
if (!$query->is_admin && $query->is_search) {
$query->set('cat', git_get_option('git_blockcat_search')); //隐藏这两个分类
}
return $query;
}
add_filter('pre_get_posts', 'git_exclude_category_search');
function git_exclude_category_rss($query) {
if ($query->is_feed) {
$query->set('cat', git_get_option('git_blockcat_rss')); //隐藏这两个分类