swicher.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. function font_end_js_control() {
  3. function check($a) {
  4. if ($a) {
  5. return true;
  6. }
  7. return false;
  8. };
  9. function ecs_src($a) {
  10. global $core_lib_basepath;
  11. return $core_lib_basepath.'/css/theme/'.$a.'.css?'.IRO_VERSION.iro_opt('cookie_version', '');
  12. };
  13. /**
  14. * 通过ID获取作者公开显示的昵称
  15. * 在head中无法通过get_the_author()函数获取作者信息,改用通过作者ID获取
  16. */
  17. function iro_get_the_author_name() {
  18. global $post;
  19. if ($post) {
  20. $author_id = $post->post_author;
  21. $author_name = get_the_author_meta('display_name', $author_id);
  22. return $author_name;
  23. }
  24. return get_the_author_meta( 'display_name', 1 );
  25. };
  26. $vision_resource_basepath = iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/');
  27. $movies = iro_opt('cover_video') ?
  28. array(
  29. 'url' => iro_opt('cover_video_link'),
  30. 'name' => iro_opt('cover_video_title'),
  31. 'live' => iro_opt('cover_video_live') ? true : false,
  32. 'loop' => iro_opt('cover_video_loop') ? true : false
  33. )
  34. : 'close';
  35. $auto_height = !iro_opt('cover_full_screen') ? 'fixed' : 'auto';
  36. if (iro_opt('gravatar_proxy') == 'custom_proxy_address_of_gravatar') {
  37. $gravatar_url = iro_opt('custom_proxy_address_of_gravatar') ?: 'secure.gravatar.com/avatar';
  38. } else {
  39. $gravatar_url = iro_opt('gravatar_proxy') ?: 'secure.gravatar.com/avatar';
  40. }
  41. $iro_opt = [
  42. // Poi
  43. 'pjax' => check(iro_opt('poi_pjax')),
  44. 'movies' => $movies,
  45. 'windowheight' => $auto_height,
  46. 'ajaxurl' => admin_url('admin-ajax.php'),
  47. 'order' => get_option('comment_order'), // ajax comments
  48. 'formpostion' => 'bottom', // ajax comments 默认为bottom,如果你的表单在顶部则设置为top。
  49. 'api' => esc_url_raw(rest_url()),
  50. 'nonce' => wp_create_nonce('wp_rest'),
  51. 'google_analytics_id' => iro_opt('google_analytics_id', ''),
  52. 'gravatar_url' => $gravatar_url,
  53. // options
  54. 'NProgressON' => check(iro_opt('nprogress_on')),
  55. 'audio' => check(iro_opt('note_effects')),
  56. 'baguetteBox' => check(iro_opt('baguetteBox')),
  57. 'fancybox' => check(iro_opt('fancybox')),
  58. 'darkmode' => check(iro_opt('theme_darkmode_auto')),
  59. 'email_domain' => iro_opt('email_domain', ''),
  60. 'email_name' => iro_opt('email_name', ''),
  61. 'ext_shared_lib'=>iro_opt('external_vendor_lib'),
  62. 'cookie_version_control' => iro_opt('cookie_version', ''),
  63. 'qzone_autocomplete' => false,
  64. 'site_name' => get_bloginfo('name'),
  65. 'author_name' => iro_get_the_author_name(),
  66. 'template_url' => get_template_directory_uri(),
  67. 'site_url' => site_url(),
  68. 'qq_api_url' => rest_url('sakura/v1/qqinfo/json'),
  69. 'land_at_home' => check(is_home()),
  70. 'live_search' => check(iro_opt('live_search')),
  71. 'loading_ph'=>iro_opt('load_in_svg'),
  72. 'clipboardCopyright' => iro_opt('clipboard_copyright') == '0' ? false:true,
  73. 'entry_content_style' => iro_opt('entry_content_style'),
  74. 'random_graphs_mts' => check(iro_opt('random_graphs_mts' )),
  75. 'code_highlight' => iro_opt('code_highlight_method','hljs'),
  76. 'comment_upload_img' => iro_opt('img_upload_api')=='off' ? false : true,
  77. 'cache_cover' => check(iro_opt('cache_cover')),
  78. 'site_bg_as_cover' => check(iro_opt('site_bg_as_cover')),
  79. 'yiyan_api' => json_decode(iro_opt('yiyan_api')),
  80. 'skin_bg0' => '',
  81. 'skin_bg1' => $vision_resource_basepath.'background/foreground/bg1.png',
  82. 'skin_bg2' => $vision_resource_basepath.'background/foreground/bg2.png',
  83. 'skin_bg3' => $vision_resource_basepath.'background/foreground/bg3.png',
  84. 'skin_bg4' => $vision_resource_basepath.'background/foreground/bg4.png',
  85. ];
  86. $reception_background = iro_opt('reception_background');
  87. // 判空 empty 如果变量不存在也会返回true
  88. if (iro_opt('random_graphs_options') == 'external_api') {
  89. if (wp_is_mobile()) {
  90. $iro_opt['cover_api'] = iro_opt('random_graphs_mts')?iro_opt('random_graphs_link_mobile'):iro_opt('random_graphs_link');
  91. }else{
  92. $iro_opt['cover_api'] = iro_opt('random_graphs_link');
  93. }
  94. } else {
  95. $iro_opt['cover_api'] = rest_url('sakura/v1/image/cover');
  96. }
  97. !empty($reception_background['img1']) && $iro_opt['skin_bg0'] = $reception_background['img1'];
  98. !empty($reception_background['img2']) && $iro_opt['skin_bg1'] = $reception_background['img2'];
  99. !empty($reception_background['img3']) && $iro_opt['skin_bg2'] = $reception_background['img3'];
  100. !empty($reception_background['img4']) && $iro_opt['skin_bg3'] = $reception_background['img4'];
  101. !empty($reception_background['img5']) && $iro_opt['skin_bg4'] = $reception_background['img5'];
  102. if (iro_opt('lightgallery')){
  103. # 请务必使用正确标准的json格式
  104. $lightGallery = str_replace(PHP_EOL, '', iro_opt('lightgallery_option'));
  105. $iro_opt['lightGallery'] = json_decode($lightGallery,true);
  106. }
  107. if (iro_opt('aplayer_server') != 'off'){
  108. $iro_opt['float_player_on'] = true;
  109. $iro_opt['meting_api_url'] = rest_url('sakura/v1/meting/aplayer');
  110. }
  111. if (iro_opt('code_highlight_method','hljs')=='prism'){
  112. $iro_opt['code_highlight_prism'] = [
  113. 'line_number_all' => check(iro_opt('code_highlight_prism_line_number_all')),
  114. 'autoload_path' => iro_opt('code_highlight_prism_autoload_path','') ?: null
  115. ];
  116. $theme_light = iro_opt('code_highlight_prism_theme_light');
  117. $theme_dark = iro_opt('code_highlight_prism_theme_dark');
  118. if($theme_light){
  119. if($theme_dark){
  120. $iro_opt['code_highlight_prism']['theme'] = ['light' => $theme_light,'dark' => $theme_dark];
  121. }else{
  122. $iro_opt['code_highlight_prism']['theme'] = ['light' => $theme_light];
  123. }
  124. }else if($theme_dark){
  125. $iro_opt['code_highlight_prism']['theme'] = ['dark' => $theme_dark];
  126. }
  127. }
  128. $preload_blur = iro_opt('preload_blur',0);
  129. if ($preload_blur) $iro_opt['preload_blur'] = $preload_blur;
  130. $sakura_effect = iro_opt('sakura_falling_effects');
  131. if($sakura_effect != 'off') $iro_opt['effect'] = array('amount'=>$sakura_effect);
  132. if (iro_opt('theme_darkmode_auto')) $iro_opt['dm_strategy'] = iro_opt('theme_darkmode_strategy','time');
  133. wp_add_inline_script('app', 'var _iro = '.json_encode($iro_opt,JSON_NUMERIC_CHECK|JSON_UNESCAPED_UNICODE),'before');
  134. }
  135. add_action('wp_head', 'font_end_js_control');