forked from mirai-mamori/Sakurairo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
1917 lines (1760 loc) · 80.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
/**
* iro functions and definitions.
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package iro
*/
define('SAKURA_VERSION', wp_get_theme()->get('Version'));
define('BUILD_VERSION', '3');
//Option-Framework
require get_template_directory() . '/opt/option-framework.php';
if (! function_exists('iro_opt')) {
function iro_opt($option = '', $default = null) {
$options = get_option('iro_options');
return (isset($options[$option])) ? $options[$option] : $default;
}
}
//Update-Checker
require 'update-checker/update-checker.php';
$iro_update_source = iro_opt('iro_update_source');
$iro_update_channel = iro_opt('iro_update_channel');
if ($iro_update_source == 'github'){
$iroThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/mirai-mamori/Sakurairo',
__FILE__,
'unique-plugin-or-theme-slug'
);
}else if ($iro_update_source == 'jsdelivr'){
$iroThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://update.maho.cc/jsdelivr.json',
__FILE__,
'Sakurairo'
);
}else if ($iro_update_source == 'official_building'){
if ($iro_update_channel == 'stable'){
$iroThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://update.maho.cc/stable/check.json',
__FILE__,
'Sakurairo'
);
}else if ($iro_update_channel == 'beta'){
$iroThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://update.maho.cc/beta/check.json',
__FILE__,
'Sakurairo'
);
}else if ($iro_update_channel == 'preview'){
$iroThemeUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
'https://update.maho.cc/preview/check.json',
__FILE__,
'Sakurairo'
);
}
}
//ini_set('display_errors', true);
//error_reporting(E_ALL);
error_reporting(E_ALL & ~E_NOTICE);
if (!function_exists('akina_setup')):
function akina_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Akina, use a find and replace
* to change 'akina' to the name of your theme in all the template files.
*/
load_theme_textdomain('sakurairo', get_template_directory() . '/languages');
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support('post-thumbnails');
set_post_thumbnail_size(150, 150, true);
// This theme uses wp_nav_menu() in one location.
register_nav_menus(array(
'primary' => __('Nav Menus', 'sakurairo'), //导航菜单
));
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support('html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
));
/*
* Enable support for Post Formats.
* See https://developer.wordpress.org/themes/functionality/post-formats/
*/
add_theme_support('post-formats', array(
'aside',
'image',
'status',
));
// Set up the WordPress core custom background feature.
add_theme_support('custom-background', apply_filters('akina_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
)));
add_filter('pre_option_link_manager_enabled', '__return_true');
// 优化代码
//去除头部冗余代码
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'wp_generator'); //隐藏wordpress版本
remove_filter('the_content', 'wptexturize'); //取消标点符号转义
//remove_action('rest_api_init', 'wp_oembed_register_route');
//remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4);
//remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
//remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4);
//remove_action('wp_head', 'wp_oembed_add_discovery_links');
//remove_action('wp_head', 'wp_oembed_add_host_js');
remove_action('template_redirect', 'rest_output_link_header', 11, 0);
function coolwp_remove_open_sans_from_wp_core()
{
wp_deregister_style('open-sans');
wp_register_style('open-sans', false);
wp_enqueue_style('open-sans', '');
}
add_action('init', 'coolwp_remove_open_sans_from_wp_core');
/**
* Disable the emoji's
*/
function disable_emojis()
{
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
}
add_action('init', 'disable_emojis');
/**
* Filter function used to remove the tinymce emoji plugin.
*
* @param array $plugins
* @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce($plugins)
{
if (is_array($plugins)) {
return array_diff($plugins, array('wpemoji'));
} else {
return array();
}
}
// 移除菜单冗余代码
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
function my_css_attributes_filter($var)
{
return is_array($var) ? array_intersect($var, array('current-menu-item', 'current-post-ancestor', 'current-menu-ancestor', 'current-menu-parent')) : '';
}
}
endif;
add_action('after_setup_theme', 'akina_setup');
//说说页面
function shuoshuo_custom_init()
{
$labels = array(
'name' => '说说',
'singular_name' => '说说',
'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'
)
);
register_post_type('shuoshuo', $args);
}
add_action('init', 'shuoshuo_custom_init');
function admin_lettering()
{
echo '<style>body{font-family: Microsoft YaHei;}</style>';
}
add_action('admin_head', 'admin_lettering');
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function akina_content_width()
{
$GLOBALS['content_width'] = apply_filters('akina_content_width', 640);
}
add_action('after_setup_theme', 'akina_content_width', 0);
/**
* Enqueue scripts and styles.
*/
function sakura_scripts()
{
if (iro_opt('local_global_library')) {
//wp_enqueue_script('js_lib', get_template_directory_uri() . '/cdn/js/lib.js', array(), SAKURA_VERSION . iro_opt('cookie_version', ''), true);
if (iro_opt('smoothscroll_option')) {
wp_enqueue_script('SmoothScroll', get_template_directory_uri() . '/js/smoothscroll.js', array(), SAKURA_VERSION . iro_opt('cookie_version', ''), true);
}
} elseif (iro_opt('smoothscroll_option')) {
wp_enqueue_script('SmoothScroll', 'https://cdn.jsdelivr.net/combine/gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/js/smoothscroll.js', array(), SAKURA_VERSION . iro_opt('cookie_version', ''), true);
//wp_enqueue_script('js_lib', 'https://cdn.jsdelivr.net/combine/gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/cdn/js/lib.min.js,gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/cdn/js/smoothscroll.js', array(), SAKURA_VERSION, true);
}/* else {
wp_enqueue_script('js_lib', 'https://cdn.jsdelivr.net/gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/cdn/js/lib.min.js', array(), SAKURA_VERSION, true);
} */
if (iro_opt('local_application_library')) {
wp_enqueue_style('saukra_css', get_stylesheet_uri(), array(), SAKURA_VERSION);
wp_enqueue_script('app', get_template_directory_uri() . '/js/app.js', array(), SAKURA_VERSION, true);
} else {
wp_enqueue_style('saukra_css', 'https://cdn.jsdelivr.net/gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/style.min.css', array(), SAKURA_VERSION);
wp_enqueue_script('app', 'https://cdn.jsdelivr.net/gh/mirai-mamori/Sakurairo@' . SAKURA_VERSION . '/js/app.js', array(), SAKURA_VERSION, true);
}
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
// 20161116 @Louie
$mv_live = iro_opt('cover_video_loop') ? 'open' : 'close';
$movies = iro_opt('cover_video') ? array('url' => iro_opt('cover_video_link'), 'name' => iro_opt('cover_video_title'), 'live' => $mv_live) : 'close';
$auto_height = !iro_opt('cover_full_screen') ? 'fixed' : 'auto';
/* $code_lamp = 'close';
*/ // if (wp_is_mobile()) {
// $auto_height = 'fixed';
// }
//拦截移动端
version_compare($GLOBALS['wp_version'], '5.1', '>=') ? $reply_link_version = 'new' : $reply_link_version = 'old';
$gravatar_url = iro_opt('gravatar_proxy') ?: 'secure.gravatar.com/avatar';
wp_localize_script('app', 'Poi', array(
'pjax' => iro_opt('poi_pjax')?'1':'',
'movies' => $movies,
'windowheight' => $auto_height,
/* 'codelamp' => $code_lamp,
*/ 'ajaxurl' => admin_url('admin-ajax.php'),
'order' => get_option('comment_order'), // ajax comments
'formpostion' => 'bottom', // ajax comments 默认为bottom,如果你的表单在顶部则设置为top。
'reply_link_version' => $reply_link_version,
'api' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest'),
'google_analytics_id' => iro_opt('google_analytics_id', ''),
'gravatar_url' => $gravatar_url
));
}
add_action('wp_enqueue_scripts', 'sakura_scripts');
/**
* load .php.
*/
require get_template_directory() . '/inc/decorate.php';
require get_template_directory() . '/inc/swicher.php';
require get_template_directory() . '/inc/api.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* function update
*/
require get_template_directory() . '/inc/theme_plus.php';
require get_template_directory() . '/inc/categories-images.php';
//Comment Location Start
function convertip($ip)
{
if(empty($ip)) $ip = get_comment_author_IP();
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip='.$ip);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
$result = null;
$result = json_decode($file_contents,true);
if ($result['data']['country'] != '中国') {
return $result['data']['country'];
} else {
return $result['data']['country'].' · '.$result['data']['region'].' · '.$result['data']['city'].' · '.$result['data']['isp'];
}
}
//Comment Location End
/**
* COMMENT FORMATTING
*
* 标准的 lazyload 输出头像
* <?php echo str_replace( 'src=', 'src="https://cdn.jsdelivr.net/gh/moezx/[email protected]/img/svg/loader/index.ajax-spinner-preloader.svg" onerror="imgError(this,1)" data-src=', get_avatar( $comment->comment_author_email, '80', '', get_comment_author(), array( 'class' => array( 'lazyload' ) ) ) ); ?>
*
* 如果不延时是这样的
* <?php echo get_avatar( $comment->comment_author_email, '80', '', get_comment_author() ); ?>
*
*/
if (!function_exists('akina_comment_format')) {
function akina_comment_format($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
?>
<li <?php comment_class();?> id="comment-<?php echo esc_attr(comment_ID()); ?>">
<div class="contents">
<div class="comment-arrow">
<div class="main shadow">
<div class="profile">
<a href="<?php comment_author_url();?>" target="_blank" rel="nofollow"><?php echo str_replace('src=', 'src="'.iro_opt('load_in_svg').'" onerror="imgError(this,1)" data-src=', get_avatar($comment->comment_author_email, '80', '', get_comment_author(), array('class' => array('lazyload')))); ?></a>
</div>
<div class="commentinfo">
<section class="commeta">
<div class="left">
<h4 class="author"><a href="<?php comment_author_url();?>" target="_blank" rel="nofollow"><?php echo get_avatar($comment->comment_author_email, '24', '', get_comment_author()); ?><span class="bb-comment isauthor" title="<?php _e('Author', 'sakurairo');?>"><?php _e('Blogger', 'sakurairo'); /*博主*/?></span> <?php comment_author();?> <?php echo get_author_class($comment->comment_author_email, $comment->user_id); ?></a></h4>
</div>
<?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth'])));?>
<div class="right">
<div class="info"><time datetime="<?php comment_date('Y-m-d');?>"><?php echo poi_time_since(strtotime($comment->comment_date_gmt), true); //comment_date(get_option('date_format')); ?></time><?php echo siren_get_useragent($comment->comment_agent); ?><?php echo mobile_get_useragent_icon($comment->comment_agent); ?> <?php if(iro_opt('comment_location')){ _e('Location', 'sakurairo'); /*来自*/?>: <?php echo convertip(get_comment_author_ip());} ?>
<?php if (current_user_can('manage_options') and (wp_is_mobile() == false)) {
$comment_ID = $comment->comment_ID;
$i_private = get_comment_meta($comment_ID, '_private', true);
$flag=null;
$flag .= ' <i class="fa fa-snowflake-o" aria-hidden="true"></i> <a href="javascript:;" data-actionp="set_private" data-idp="' . get_comment_id() . '" id="sp" class="sm" style="color:rgba(0,0,0,.35)">' . __("Private", "sakurairo") . ': <span class="has_set_private">';
if (!empty($i_private)) {
$flag .= __("Yes", "sakurairo") . ' <i class="fa fa-lock" aria-hidden="true"></i>';
} else {
$flag .= __("No", "sakurairo") . ' <i class="fa fa-unlock" aria-hidden="true"></i>';
}
$flag .= '</span></a>';
$flag .= edit_comment_link('<i class="fa fa-pencil-square-o" aria-hidden="true"></i> ' . __("Edit", "mashiro"), ' <span style="color:rgba(0,0,0,.35)">', '</span>');
echo $flag;
}?></div>
</div>
</section>
</div>
<div class="body">
<?php comment_text();?>
</div>
</div>
<div class="arrow-left"></div>
</div>
</div>
<hr>
<?php
}
}
/**
* 获取访客VIP样式
*/
function get_author_class($comment_author_email, $user_id)
{
global $wpdb;
$author_count = count($wpdb->get_results(
"SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
if ($author_count >= 1 && $author_count < 5) //数字可自行修改,代表评论次数。
{
echo '<span class="showGrade0" title="Lv0"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_0.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 6 && $author_count < 10) {
echo '<span class="showGrade1" title="Lv1"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_1.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 10 && $author_count < 20) {
echo '<span class="showGrade2" title="Lv2"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_2.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 20 && $author_count < 40) {
echo '<span class="showGrade3" title="Lv3"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_3.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 40 && $author_count < 80) {
echo '<span class="showGrade4" title="Lv4"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_4.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 80 && $author_count < 160) {
echo '<span class="showGrade5" title="Lv5"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_5.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
} else if ($author_count >= 160) {
echo '<span class="showGrade6" title="Lv6"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/level/level_6.svg" style="height: 1.5em; max-height: 1.5em; display: inline-block;"></span>';
}
}
/**
* post views
*/
function restyle_text($number)
{
switch (iro_opt('statistics_format')) {
case "type_2": //23,333 次访问
return number_format($number);
break;
case "type_3": //23 333 次访问
return number_format($number, 0, '.', ' ');
break;
case "type_4": //23k 次访问
if ($number >= 1000) {
return round($number / 1000, 2) . 'k';
} else {
return $number;
}
break;
default:
return $number;
}
}
function set_post_views()
{
if (is_singular()) {
global $post;
$post_id = intval($post->ID);
if ($post_id) {
$views = (int) get_post_meta($post_id, 'views', true);
if (!update_post_meta($post_id, 'views', ($views + 1))) {
add_post_meta($post_id, 'views', 1, true);
}
}
}
}
add_action('get_header', 'set_post_views');
function get_post_views($post_id)
{
if (iro_opt('statistics_api') == 'wp_statistics') {
if (!function_exists('wp_statistics_pages')) {
return __('Please install pulgin <a href="https://wordpress.org/plugins/wp-statistics/" target="_blank">WP-Statistics</a>', 'sakurairo');
} else {
return restyle_text(wp_statistics_pages('total', 'uri', $post_id));
}
} else {
$views = get_post_meta($post_id, 'views', true);
if ($views == '') {
return 0;
} else {
return restyle_text($views);
}
}
}
function is_webp():bool{
return (isset($_COOKIE["su_webp"]) || strpos($_SERVER['HTTP_ACCEPT'], 'image/webp'));
}
$block_library_css = iro_opt('block_library_css');
if ($block_library_css != '1'){
add_action( 'wp_enqueue_scripts', 'fanly_remove_block_library_css', 100 );
function fanly_remove_block_library_css() {
wp_dequeue_style( 'wp-block-library' );
}
}
/*
* 友情链接
*/
function get_the_link_items($id = null)
{
$bookmarks = get_bookmarks('orderby=date&category=' . $id);
$output = '';
if (!empty($bookmarks)) {
$output .= '<ul class="link-items fontSmooth">';
foreach ($bookmarks as $bookmark) {
if (empty($bookmark->link_description)) {
$bookmark->link_description = __('This guy is so lazy ╮(╯▽╰)╭', 'sakurairo');
}
if (empty($bookmark->link_image)) {
$bookmark->link_image = 'https://view.moezx.cc/images/2017/12/30/Transparent_Akkarin.th.jpg';
}
$output .= '<li class="link-item"><a class="link-item-inner effect-apollo" href="' . $bookmark->link_url . '" title="' . $bookmark->link_description . '" target="_blank" rel="friend"><img class="lazyload" onerror="imgError(this,1)" data-src="' . $bookmark->link_image . '" src="'.iro_opt('load_in_svg').'"><span class="sitename">' . $bookmark->link_name . '</span><div class="linkdes">' . $bookmark->link_description . '</div></a></li>';
}
$output .= '</ul>';
}
return $output;
}
function get_link_items()
{
$linkcats = get_terms('link_category');
$result = null;
if (!empty($linkcats)) {
foreach ($linkcats as $linkcat) {
$result .= '<h3 class="link-title"><span class="link-fix">' . $linkcat->name . '</span></h3>';
if ($linkcat->description) {
$result .= '<div class="link-description">' . $linkcat->description . '</div>';
}
$result .= get_the_link_items($linkcat->term_id);
}
} else {
$result = get_the_link_items();
}
return $result;
}
/*
* Gravatar头像使用中国服务器
*/
function gravatar_cn($url)
{
$gravatar_url = array('0.gravatar.com/avatar','1.gravatar.com/avatar','2.gravatar.com/avatar','secure.gravatar.com/avatar');
return str_replace( $gravatar_url, iro_opt('gravatar_proxy'), $url );
}
if(iro_opt('gravatar_proxy')){
add_filter('get_avatar_url', 'gravatar_cn', 4);
}
/*
* 自定义默认头像
*/
add_filter('avatar_defaults', 'mytheme_default_avatar');
function mytheme_default_avatar($avatar_defaults)
{
//$new_avatar_url = get_template_directory_uri() . '/images/default_avatar.png';
$new_avatar_url = 'https://cn.gravatar.com/avatar/b745710ae6b0ce9dfb13f5b7c0956be1';
$avatar_defaults[$new_avatar_url] = 'Default Avatar';
return $avatar_defaults;
}
/*
* 阻止站内文章互相Pingback
*/
function theme_noself_ping(&$links)
{
$home = get_option('home');
foreach ($links as $l => $link) {
if (0 === strpos($link, $home)) {
unset($links[$l]);
}
}
}
add_action('pre_ping', 'theme_noself_ping');
/*
* 订制body类
*/
function akina_body_classes($classes)
{
// Adds a class of group-blog to blogs with more than 1 published author.
if (is_multi_author()) {
$classes[] = 'group-blog';
}
// Adds a class of hfeed to non-singular pages.
if (!is_singular()) {
$classes[] = 'hfeed';
}
// 定制中文字体class
$classes[] = 'chinese-font';
/*if(!wp_is_mobile()) {
$classes[] = 'serif';
}*/
if (isset($_COOKIE['dark'.iro_opt('cookie_version', '')])){
$classes[] = $_COOKIE['dark'.iro_opt('cookie_version', '')] == '1' ? 'dark' : ' ';
}else{
$classes[] = ' ';
}
return $classes;
}
add_filter('body_class', 'akina_body_classes');
/*
* 图片CDN
*/
add_filter('upload_dir', 'wpjam_custom_upload_dir');
function wpjam_custom_upload_dir($uploads)
{
$upload_path = '';
$upload_url_path = iro_opt('image_cdn');
if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
$uploads['basedir'] = WP_CONTENT_DIR . '/uploads';
} elseif (0 !== strpos($upload_path, ABSPATH)) {
$uploads['basedir'] = path_join(ABSPATH, $upload_path);
} else {
$uploads['basedir'] = $upload_path;
}
$uploads['path'] = $uploads['basedir'] . $uploads['subdir'];
if ($upload_url_path) {
$uploads['baseurl'] = $upload_url_path;
$uploads['url'] = $uploads['baseurl'] . $uploads['subdir'];
}
return $uploads;
}
/*
* 删除自带小工具
*/
function unregister_default_widgets()
{
unregister_widget("WP_Widget_Pages");
unregister_widget("WP_Widget_Calendar");
unregister_widget("WP_Widget_Archives");
unregister_widget("WP_Widget_Links");
unregister_widget("WP_Widget_Meta");
unregister_widget("WP_Widget_Search");
//unregister_widget("WP_Widget_Text");
unregister_widget("WP_Widget_Categories");
unregister_widget("WP_Widget_Recent_Posts");
//unregister_widget("WP_Widget_Recent_Comments");
//unregister_widget("WP_Widget_RSS");
//unregister_widget("WP_Widget_Tag_Cloud");
unregister_widget("WP_Nav_Menu_Widget");
}
add_action("widgets_init", "unregister_default_widgets", 11);
/**
* Jetpack setup function.
*
* See: https://jetpack.com/support/infinite-scroll/
* See: https://jetpack.com/support/responsive-videos/
*/
function akina_jetpack_setup()
{
// Add theme support for Infinite Scroll.
add_theme_support('infinite-scroll', array(
'container' => 'main',
'render' => 'akina_infinite_scroll_render',
'footer' => 'page',
));
// Add theme support for Responsive Videos.
add_theme_support('jetpack-responsive-videos');
}
add_action('after_setup_theme', 'akina_jetpack_setup');
/**
* Custom render function for Infinite Scroll.
*/
function akina_infinite_scroll_render()
{
while (have_posts()) {
the_post();
if (is_search()):
get_template_part('tpl/content', 'search');
else:
get_template_part('tpl/content', get_post_format());
endif;
}
}
/*
* 编辑器增强
*/
function enable_more_buttons($buttons)
{
$buttons[] = 'hr';
$buttons[] = 'del';
$buttons[] = 'sub';
$buttons[] = 'sup';
$buttons[] = 'fontselect';
$buttons[] = 'fontsizeselect';
$buttons[] = 'cleanup';
$buttons[] = 'styleselect';
$buttons[] = 'wp_page';
$buttons[] = 'anchor';
$buttons[] = 'backcolor';
return $buttons;
}
add_filter("mce_buttons_3", "enable_more_buttons");
// 下载按钮
function download($atts, $content = null)
{
return '<a class="download" href="' . $content . '" rel="external"
target="_blank" title="下载地址">
<span><i class="iconfont down icon-pulldown"></i>Download</span></a>';}
add_shortcode("download", "download");
add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
function bolo_after_wp_tiny_mce($mce_settings)
{
?>
<script type="text/javascript">
QTags.addButton( 'download', '下载按钮', "[download]下载地址[/download]" );
function bolo_QTnextpage_arg1() {
}
</script>
<?php }
/*
* 后台登录页
* @M.J
*/
//Login Page style
function custom_login()
{
require get_template_directory() . '/inc/login_addcss.php';
//echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/inc/login.css" />'."\n";
echo '<link rel="stylesheet" type="text/css" href="' . get_template_directory_uri() . '/inc/login.css?' . SAKURA_VERSION . '" />' . "\n";
//echo '<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/jquery.min.js"></script>'."\n";
echo '<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/jquery/[email protected]/dist/jquery.min.js"></script>' . "\n";
}
add_action('login_head', 'custom_login');
//Login Page Title
function custom_headertitle($title)
{
return get_bloginfo('name');
}
add_filter('login_headertext', 'custom_headertitle');
//Login Page Link
function custom_loginlogo_url($url)
{
return esc_url(home_url('/'));
}
add_filter('login_headerurl', 'custom_loginlogo_url');
//Login Page Footer
function custom_html()
{
$loginbg = iro_opt('login_background') ?: 'https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/encore/login_background.jpg';
echo '<script type="text/javascript" src="' . get_template_directory_uri() . '/js/login.js"></script>' . "\n";
echo '<script type="text/javascript">
document.body.insertAdjacentHTML("afterbegin","<div class=\"loading\"><img src=\"https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/basic/login_loading.gif\" width=\"58\" height=\"10\"></div><div id=\"bg\"><img /></div>");
document.head.insertAdjacentHTML("afterbegin","<style>.show{opacity:1;}.hide{opacity:0;transition: opacity 400ms;}</style>");
const bg_img = document.querySelector("#bg img"),loading = document.querySelector(".loading");
bg_img.setAttribute("src","',$loginbg, '");
bg_img.addEventListener("load",function(){
resizeImage(\'bg\');
window.onresize = ()=>{resizeImage("bg");}
loading.classList.add("hide");
loading.classList.remove("show");
loading.addEventListener("transitionend",function(){this.style.display="none"});
});
</script>',"\n";
echo '<script>
document.addEventListener("DOMContentLoaded", ()=>{
document.querySelector("h1 a").style.backgroundImage = "url(\'' ,iro_opt('login_logo_img') , '\') ";
document.querySelector(".forgetmenot").outerHTML = \'<p class="forgetmenot">Remember Me<input name="rememberme" id="rememberme" value="forever" type="checkbox"><label for="rememberme" style="float: right;margin-top: 5px;transform: scale(2);margin-right: -10px;"></label></p> \';
const captchaimg = document.getElementById("captchaimg");
captchaimg && captchaimg.addEventListener("click",(e)=>{
fetch("',rest_url('sakura/v1/captcha/create'),'")
.then(response=>response.json())
.then(json=>{
e.target.src = json["data"];
document.querySelector("input[name=\'timestamp\']").value = json["time"];
document.querySelector("input[name=\'id\']").value = json["id"];
});
})
}, false);
</script>';
}
add_action('login_footer', 'custom_html');
//Login message
//* Add custom message to WordPress login page
function smallenvelop_login_message($message)
{
if (empty($message)) {
return '<p class="message"><strong>You may try 3 times for every 5 minutes!</strong></p>';
} else {
return $message;
}
}
//add_filter( 'login_message', 'smallenvelop_login_message' );
//Fix password reset bug </>
function resetpassword_message_fix($message)
{
$message = str_replace("<", "", $message);
$message = str_replace(">", "", $message);
return $message;
}
add_filter('retrieve_password_message', 'resetpassword_message_fix');
//Fix register email bug </>
function new_user_message_fix($message)
{
$show_register_ip = "注册IP | Registration IP: " . get_the_user_ip() . " (" . convertip(get_the_user_ip()) . ")\r\n\r\n如非本人操作请忽略此邮件 | Please ignore this email if this was not your operation.\r\n\r\n";
$message = str_replace("To set your password, visit the following address:", $show_register_ip . "在此设置密码 | To set your password, visit the following address:", $message);
$message = str_replace("<", "", $message);
$message = str_replace(">", "\r\n\r\n设置密码后在此登录 | Login here after setting password: ", $message);
return $message;
}
add_filter('wp_new_user_notification_email', 'new_user_message_fix');
/*
* 评论邮件回复
*/
function comment_mail_notify($comment_id)
{
$mail_user_name = iro_opt('mail_user_name') ? iro_opt('mail_user_name') : 'poi';
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ?: '';
$spam_confirmed = $comment->comment_approved;
$mail_notify = iro_opt('mail_notify') ? get_comment_meta($parent_id, 'mail_notify', false) : false;
$admin_notify = iro_opt('admin_notify') ? '1' : ((isset(get_comment($parent_id)->comment_author_email) && get_comment($parent_id)->comment_author_email) != get_bloginfo('admin_email') ? '1' : '0');
if (($parent_id != '') && ($spam_confirmed != 'spam') && ($admin_notify != '0') && (!$mail_notify)) {
$wp_email = $mail_user_name . '@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$to = trim(get_comment($parent_id)->comment_author_email);
$subject = '你在 [' . get_option("blogname") . '] 的留言有了回应';
$message = '
<div style="background: white;
width: 95%;
max-width: 800px;
margin: auto auto;
border-radius: 5px;
border: '.iro_opt('theme_skin').' 1px solid;
overflow: hidden;
-webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12);
box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18);">
<header style="overflow: hidden;">
<img style="width:100%;z-index: 666;" src="'.iro_opt('mail_img').'">
</header>
<div style="padding: 5px 20px;">
<p style="position: relative;
color: white;
float: left;
z-index: 999;
background: '.iro_opt('theme_skin').';
padding: 5px 30px;
margin: -25px auto 0 ;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.30)">Dear ' . trim(get_comment($parent_id)->comment_author) . '</p>
<br>
<h3>您有一条来自<a style="text-decoration: none;color: '.iro_opt('theme_skin').' " target="_blank" href="' . home_url() . '/">' . get_option("blogname") . '</a>的回复</h3>
<br>
<p style="font-size: 14px;">您在文章《' . get_the_title($comment->comment_post_ID) . '》上发表的评论:</p>
<div style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">'
. trim(get_comment($parent_id)->comment_content) . '</div>
<p style="font-size: 14px;">' . trim($comment->comment_author) . ' 给您的回复如下:</p>
<div style="border-bottom:#ddd 1px solid;border-left:#ddd 1px solid;padding-bottom:20px;background-color:#eee;margin:15px 0px;padding-left:20px;padding-right:20px;border-top:#ddd 1px solid;border-right:#ddd 1px solid;padding-top:20px">'
. trim($comment->comment_content) . '</div>
<div style="text-align: center;">
<img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/comment/comment-mail.png" alt="hr" style="width:100%;
margin:5px auto 5px auto;
display: block;">
<a style="text-transform: uppercase;
text-decoration: none;
font-size: 14px;
border: 2px solid #6c7575;
color: #2f3333;
padding: 10px;
display: inline-block;
margin: 10px auto 0; " target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">点击查看回复的完整內容</a>
</div>
<p style="font-size: 12px;text-align: center;color: #999;">本邮件为系统自动发出,请勿直接回复<br>
© ' . date(Y) . ' ' . get_option("blogname") . '</p>
</div>
</div>
';
$message = convert_smilies($message);
$message = str_replace("{{", '<img src="https://cdn.jsdelivr.net/gh/Fuukei/[email protected]/vision/smilies/bilipng/emoji_', $message);
$message = str_replace("}}", '.png" alt="emoji" style="height: 2em; max-height: 2em;">', $message);
$message = str_replace('{UPLOAD}', 'https://i.loli.net/', $message);
$message = str_replace('[/img][img]', '[/img^img]', $message);
$message = str_replace('[img]', '<img src="', $message);
$message = str_replace('[/img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;">', $message);
$message = str_replace('[/img^img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;"><img src="', $message);
$from = "From: \"" . get_option('blogname') . "\" <$wp_email>";
$headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
wp_mail($to, $subject, $message, $headers);
}
}
add_action('comment_post', 'comment_mail_notify');
/*
* 链接新窗口打开
*/
function rt_add_link_target($content)
{
$content = str_replace('<a', '<a rel="nofollow"', $content);
// use the <a> tag to split into segments
$bits = explode('<a ', $content);
// loop though the segments
foreach ($bits as $key => $bit) {
// fix the target="_blank" bug after the link
if (strpos($bit, 'href') === false) {
continue;
}
// fix the target="_blank" bug in the codeblock
if (strpos(preg_replace('/code([\s\S]*?)\/code[\s]*/m', 'temp', $content), $bit) === false) {
continue;
}
// find the end of each link
$pos = strpos($bit, '>');
// check if there is an end (only fails with malformed markup)
if ($pos !== false) {
// get a string with just the link's attibutes
$part = substr($bit, 0, $pos);
// for comparison, get the current site/network url
$siteurl = network_site_url();
// if the site url is in the attributes, assume it's in the href and skip, also if a target is present
if (strpos($part, $siteurl) === false && strpos($part, 'target=') === false) {
// add the target attribute
$bits[$key] = 'target="_blank" ' . $bits[$key];
}
}
}
// re-assemble the content, and return it
return implode('<a ', $bits);
}
add_filter('comment_text', 'rt_add_link_target');
// 评论通过BBCode插入图片
function comment_picture_support($content)
{
$content = str_replace('http://', 'https://', $content); // 干掉任何可能的 http
$content = str_replace('{UPLOAD}', 'https://i.loli.net/', $content);
$content = str_replace('[/img][img]', '[/img^img]', $content);
$content = str_replace('[img]', '<br><img src="'.iro_opt('load_in_svg').'" data-src="', $content);
$content = str_replace('[/img]', '" class="lazyload comment_inline_img" onerror="imgError(this)"><br>', $content);
$content = str_replace('[/img^img]', '" class="lazyload comment_inline_img" onerror="imgError(this)"><img src="'.iro_opt('load_in_svg').'" data-src="', $content);
return $content;
}
add_filter('comment_text', 'comment_picture_support');
/*
* 修改评论表情调用路径
*/
// 简单遍历系统表情库,今后应考虑标识表情包名——使用增加的扩展名,同时保留原有拓展名
// 还有一个思路是根据表情调用路径来判定<-- 此法最好!
// 贴吧
$wpsmiliestrans = array();
function push_tieba_smilies() {
global $wpsmiliestrans;
// don't bother setting up smilies if they are disabled
if ( !get_option('use_smilies'))
return;
$tiebaname = array('good','han','spray','Grievance','shui','reluctantly','anger','tongue','se','haha','rmb','doubt','tear','surprised2','Happy','ku','surprised','theblackline','smilingeyes','spit','huaji','bbd','hu','shame','naive','rbq','britan','aa','niconiconi','niconiconi_t','niconiconit','awesome');
$return_smiles = '';
$type = is_webp() ? 'webp' : 'png';
$tiebaimgdir = 'tieba' . $type . '/';
$smiliesgs='.' . $type;
foreach ($tiebaname as $tieba_Name){
// 选择面版
$return_smiles = $return_smiles . '<span title="'.$tieba_Name.'" onclick="grin('."'".$tieba_Name."'".',type = \'tieba\')"><img src="https://cdn.jsdelivr.net/gh/Fuukei/Public_Repository@latest/vision/smilies/'. $tiebaimgdir .'icon_'. $tieba_Name . $smiliesgs.'" /></span>';
// 正文转换