swicher.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. $vision_resource_basepath = iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.5/');
  14. $movies = iro_opt('cover_video') ?
  15. array(
  16. 'url' => iro_opt('cover_video_link'),
  17. 'name' => iro_opt('cover_video_title'),
  18. 'live' => iro_opt('cover_video_live') ? true : false,
  19. 'loop' => iro_opt('cover_video_loop') ? true : false
  20. )
  21. : 'close';
  22. $auto_height = !iro_opt('cover_full_screen') ? 'fixed' : 'auto';
  23. $gravatar_url = iro_opt('gravatar_proxy') ?: 'secure.gravatar.com/avatar';
  24. $iro_opt = [
  25. // Poi
  26. 'pjax' => check(iro_opt('poi_pjax')),
  27. 'movies' => $movies,
  28. 'windowheight' => $auto_height,
  29. 'ajaxurl' => admin_url('admin-ajax.php'),
  30. 'order' => get_option('comment_order'), // ajax comments
  31. 'formpostion' => 'bottom', // ajax comments 默认为bottom,如果你的表单在顶部则设置为top。
  32. 'api' => esc_url_raw(rest_url()),
  33. 'nonce' => wp_create_nonce('wp_rest'),
  34. 'google_analytics_id' => iro_opt('google_analytics_id', ''),
  35. 'gravatar_url' => $gravatar_url,
  36. // options
  37. 'NProgressON' => check(iro_opt('nprogress_on')),
  38. 'audio' => check(iro_opt('note_effects')),
  39. 'baguetteBox' => check(iro_opt('baguetteBox')),
  40. 'fancybox' => check(iro_opt('fancybox')),
  41. 'darkmode' => check(iro_opt('theme_darkmode_auto')),
  42. 'email_domain' => iro_opt('email_domain', ''),
  43. 'email_name' => iro_opt('email_name', ''),
  44. 'ext_shared_lib'=>iro_opt('external_vendor_lib'),
  45. 'cookie_version_control' => iro_opt('cookie_version', ''),
  46. 'qzone_autocomplete' => false,
  47. 'site_name' => iro_opt('site_name', ''),
  48. 'author_name' => iro_opt('author_name', ''),
  49. 'template_url' => get_template_directory_uri(),
  50. 'site_url' => site_url(),
  51. 'qq_api_url' => rest_url('sakura/v1/qqinfo/json'),
  52. 'land_at_home' => check(is_home()),
  53. 'live_search' => check(iro_opt('live_search')),
  54. 'loading_ph'=>iro_opt('load_in_svg'),
  55. 'clipboardCopyright' => iro_opt('clipboard_copyright') == '0' ? false:true,
  56. 'entry_content_style' => iro_opt('entry_content_style'),
  57. 'random_graphs_mts' => check(iro_opt('random_graphs_mts' )),
  58. 'code_highlight' => iro_opt('code_highlight_method','hljs'),
  59. 'comment_upload_img' => iro_opt('img_upload_api')=='off' ? false : true,
  60. 'cache_cover' => check(iro_opt('cache_cover')),
  61. 'site_bg_as_cover' => check(iro_opt('site_bg_as_cover')),
  62. 'yiyan_api' => json_decode(iro_opt('yiyan_api')),
  63. 'skin_bg0' => '',
  64. 'skin_bg1' => $vision_resource_basepath.'background/foreground/bg1.png',
  65. 'skin_bg2' => $vision_resource_basepath.'background/foreground/bg2.png',
  66. 'skin_bg3' => $vision_resource_basepath.'background/foreground/bg3.png',
  67. 'skin_bg4' => $vision_resource_basepath.'background/foreground/bg4.png',
  68. ];
  69. $reception_background = iro_opt('reception_background');
  70. // 判空 empty 如果变量不存在也会返回true
  71. if (iro_opt('random_graphs_options') == 'external_api') {
  72. if (wp_is_mobile()) {
  73. $iro_opt['cover_api'] = iro_opt('random_graphs_mts')?iro_opt('random_graphs_link_mobile'):iro_opt('random_graphs_link');
  74. }else{
  75. $iro_opt['cover_api'] = iro_opt('random_graphs_link');
  76. }
  77. } else {
  78. $iro_opt['cover_api'] = rest_url('sakura/v1/image/cover');
  79. }
  80. !empty($reception_background['img1']) && $iro_opt['skin_bg0'] = $reception_background['img1'];
  81. !empty($reception_background['img2']) && $iro_opt['skin_bg1'] = $reception_background['img2'];
  82. !empty($reception_background['img3']) && $iro_opt['skin_bg2'] = $reception_background['img3'];
  83. !empty($reception_background['img4']) && $iro_opt['skin_bg3'] = $reception_background['img4'];
  84. !empty($reception_background['img5']) && $iro_opt['skin_bg4'] = $reception_background['img5'];
  85. $iro_opt['jsdelivr_css_src'] = iro_opt('shared_library_basepath') ? (get_template_directory_uri().'/css/lib.css?'.IRO_VERSION.iro_opt('cookie_version', '')) : ('https://s.nmxc.ltd/sakurairo/@'.IRO_VERSION.'/css/lib.css');
  86. if (iro_opt('lightgallery')){
  87. # 请务必使用正确标准的json格式
  88. $lightGallery = str_replace(PHP_EOL, '', iro_opt('lightgallery_option'));
  89. $iro_opt['lightGallery'] = json_decode($lightGallery,true);
  90. }
  91. if (iro_opt('aplayer_server') != 'off'){
  92. $iro_opt['float_player_on'] = true;
  93. $iro_opt['meting_api_url'] = rest_url('sakura/v1/meting/aplayer');
  94. }
  95. if (iro_opt('code_highlight_method','hljs')=='prism'){
  96. $iro_opt['code_highlight_prism'] = [
  97. 'line_number_all' => check(iro_opt('code_highlight_prism_line_number_all')),
  98. 'autoload_path' => iro_opt('code_highlight_prism_autoload_path','') ?: null
  99. ];
  100. $theme_light = iro_opt('code_highlight_prism_theme_light');
  101. $theme_dark = iro_opt('code_highlight_prism_theme_dark');
  102. $preload_blur = iro_opt('preload_blur',0);
  103. if ($preload_blur) $iro_opt['preload_blur'] = $preload_blur;
  104. if ($theme_light) $iro_opt['code_highlight_prism']['theme'] = ['light' => $theme_light];
  105. if ($theme_dark) $iro_opt['code_highlight_prism']['theme'] = ['dark' => $theme_dark];
  106. }
  107. $sakura_effect = iro_opt('sakura_falling_effects');
  108. if($sakura_effect != 'off') $iro_opt['effect'] = array('amount'=>$sakura_effect);
  109. if (iro_opt('theme_darkmode_auto')) $iro_opt['dm_strategy'] = iro_opt('theme_darkmode_strategy','time');
  110. wp_add_inline_script('app', 'var _iro = '.json_encode($iro_opt,JSON_NUMERIC_CHECK|JSON_UNESCAPED_UNICODE),'before');
  111. }
  112. add_action('wp_head', 'font_end_js_control');