functions.php 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467
  1. <?php
  2. /**
  3. * iro functions and definitions.
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package iro
  8. */
  9. define('IRO_VERSION', wp_get_theme()->get('Version'));
  10. define('INT_VERSION', '18.3.1');
  11. define('BUILD_VERSION', '2');
  12. function check_php_version($preset_version) {
  13. $current_version = phpversion();
  14. return version_compare($current_version, $preset_version, '>=') ? true : false;
  15. }
  16. //Option-Framework
  17. require get_template_directory() . '/opt/option-framework.php';
  18. if (!function_exists('iro_opt')) {
  19. $GLOBALS['iro_options'] = get_option('iro_options');
  20. function iro_opt($option = '', $default = null)
  21. {
  22. return $GLOBALS['iro_options'][$option] ?? $default;
  23. }
  24. }
  25. if (!function_exists('iro_opt_update')) {
  26. function iro_opt_update($option = '', $value = null)
  27. {
  28. $options = get_option('iro_options'); // 当数据库没有指定项时,WordPress会返回false
  29. if($options){
  30. $options[$option] = $value;
  31. }else{
  32. $options = array($option => $value);
  33. }
  34. update_option('iro_options', $options);
  35. }
  36. }
  37. $shared_lib_basepath = iro_opt('shared_library_basepath') ? get_template_directory_uri() : (iro_opt('lib_cdn_path','https://fastly.jsdelivr.net/gh/mirai-mamori/Sakurairo@'). IRO_VERSION);
  38. $core_lib_basepath = iro_opt('core_library_basepath') ? get_template_directory_uri() : (iro_opt('lib_cdn_path','https://fastly.jsdelivr.net/gh/mirai-mamori/Sakurairo@'). IRO_VERSION);
  39. /**
  40. * composer autoload
  41. */
  42. if ((check_php_version('7.4.0')) && iro_opt('composer_load')) {
  43. require_once 'vendor/autoload.php';
  44. }
  45. //Update-Checker
  46. require 'update-checker/update-checker.php';
  47. use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
  48. function UpdateCheck($url,$flag = 'Sakurairo'){
  49. return PucFactory::buildUpdateChecker(
  50. $url,
  51. __FILE__,
  52. $flag
  53. );
  54. }
  55. switch(iro_opt('iro_update_source')){
  56. case 'github':
  57. $iroThemeUpdateChecker = UpdateCheck('https://github.com/mirai-mamori/Sakurairo','Sakurairo');
  58. break;
  59. case 'upyun':
  60. $iroThemeUpdateChecker = UpdateCheck('https://update.maho.cc/jsdelivr.json');
  61. break;
  62. case 'official_building':
  63. $iroThemeUpdateChecker = UpdateCheck('https://update.maho.cc/'.iro_opt('iro_update_channel').'/check.json');
  64. }
  65. //ini_set('display_errors', true);
  66. //error_reporting(E_ALL);
  67. error_reporting(E_ALL & ~E_NOTICE);
  68. if (!function_exists('akina_setup'))
  69. {
  70. function akina_setup()
  71. {
  72. /*
  73. * Make theme available for translation.
  74. * Translations can be filed in the /languages/ directory.
  75. * If you're building a theme based on Akina, use a find and replace
  76. * to change 'akina' to the name of your theme in all the template files.
  77. */
  78. load_theme_textdomain('sakurairo', get_template_directory() . '/languages');
  79. /*
  80. * Enable support for Post Thumbnails on posts and pages.
  81. *
  82. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  83. */
  84. add_theme_support('post-thumbnails');
  85. set_post_thumbnail_size(150, 150, true);
  86. // This theme uses wp_nav_menu() in one location.
  87. register_nav_menus(array(
  88. 'primary' => __('Nav Menus', 'sakurairo'), //导航菜单
  89. ));
  90. /*
  91. * Switch default core markup for search form, comment form, and comments
  92. * to output valid HTML5.
  93. */
  94. add_theme_support('html5', array(
  95. 'search-form',
  96. 'comment-form',
  97. 'comment-list',
  98. 'gallery',
  99. 'caption',
  100. ));
  101. /*
  102. * Enable support for Post Formats.
  103. * See https://developer.wordpress.org/themes/functionality/post-formats/
  104. */
  105. add_theme_support('post-formats', array(
  106. 'aside',
  107. 'image',
  108. 'status',
  109. ));
  110. // Set up the WordPress core custom background feature.
  111. add_theme_support('custom-background', apply_filters('akina_custom_background_args', array(
  112. 'default-color' => 'ffffff',
  113. 'default-image' => '',
  114. )));
  115. /**
  116. * 废弃过时的wp_title
  117. * @seealso https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/
  118. */
  119. add_theme_support( 'title-tag' );
  120. add_filter('pre_option_link_manager_enabled', '__return_true');
  121. // 优化代码
  122. //去除头部冗余代码
  123. remove_action('wp_head', 'feed_links_extra', 3);
  124. remove_action('wp_head', 'rsd_link');
  125. remove_action('wp_head', 'wlwmanifest_link');
  126. remove_action('wp_head', 'index_rel_link');
  127. remove_action('wp_head', 'start_post_rel_link', 10, 0);
  128. remove_action('wp_head', 'wp_generator');
  129. remove_action('wp_head', 'wp_generator'); //隐藏wordpress版本
  130. remove_filter('the_content', 'wptexturize'); //取消标点符号转义
  131. //remove_action('rest_api_init', 'wp_oembed_register_route');
  132. //remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4);
  133. //remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
  134. //remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4);
  135. //remove_action('wp_head', 'wp_oembed_add_discovery_links');
  136. //remove_action('wp_head', 'wp_oembed_add_host_js');
  137. remove_action('template_redirect', 'rest_output_link_header', 11, 0);
  138. function coolwp_remove_open_sans_from_wp_core()
  139. {
  140. wp_deregister_style('open-sans');
  141. wp_register_style('open-sans', false);
  142. wp_enqueue_style('open-sans', '');
  143. }
  144. add_action('init', 'coolwp_remove_open_sans_from_wp_core');
  145. if (!function_exists('disable_emojis')) {
  146. /**
  147. * Disable the emoji's
  148. * @see https://wordpress.org/plugins/disable-emojis/
  149. */
  150. function disable_emojis()
  151. {
  152. remove_action('wp_head', 'print_emoji_detection_script', 7);
  153. remove_action('admin_print_scripts', 'print_emoji_detection_script');
  154. remove_action('wp_print_styles', 'print_emoji_styles');
  155. remove_action('admin_print_styles', 'print_emoji_styles');
  156. remove_filter('the_content_feed', 'wp_staticize_emoji');
  157. remove_filter('comment_text_rss', 'wp_staticize_emoji');
  158. remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
  159. add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
  160. }
  161. add_action('init', 'disable_emojis');
  162. }
  163. if (!function_exists('disable_emojis_tinymce'))
  164. {
  165. /**
  166. * Filter function used to remove the tinymce emoji plugin.
  167. *
  168. * @param array $plugins
  169. * @return array Difference betwen the two arrays
  170. */
  171. function disable_emojis_tinymce($plugins)
  172. {
  173. if (is_array($plugins)) {
  174. return array_diff($plugins, array('wpemoji'));
  175. } else {
  176. return array();
  177. }
  178. }
  179. }
  180. // 移除菜单冗余代码
  181. add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
  182. add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
  183. add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
  184. function my_css_attributes_filter($var)
  185. {
  186. return is_array($var) ? array_intersect($var, array('current-menu-item', 'current-post-ancestor', 'current-menu-ancestor', 'current-menu-parent')) : '';
  187. }
  188. }
  189. };
  190. add_action('after_setup_theme', 'akina_setup');
  191. //说说页面
  192. function shuoshuo_custom_init()
  193. {
  194. $labels = array(
  195. 'name' => __("Ideas", "sakurairo"),
  196. 'singular_name' => __("Idea", "sakurairo"),
  197. 'add_new' => __("Publish New Idea", "sakurairo"),
  198. 'add_new_item' => __("Publish New Idea", "sakurairo"),
  199. 'edit_item' => __("Edit Idea", "sakurairo"),
  200. 'new_item' => __("New Idea", "sakurairo"),
  201. 'view_item' => __("View Idea", "sakurairo"),
  202. 'search_items' => __("Search Idea", "sakurairo"),
  203. 'not_found' => __("Not Found Idea", "sakurairo"),
  204. 'not_found_in_trash' => __("No Idea in the Trash", "sakurairo"),
  205. 'parent_item_colon' => '',
  206. 'menu_name' => __("Ideas", "sakurairo")
  207. );
  208. $args = array(
  209. 'labels' => $labels,
  210. 'public' => true,
  211. 'publicly_queryable' => true,
  212. 'show_ui' => true,
  213. 'show_in_menu' => true,
  214. 'query_var' => true,
  215. 'rewrite' => true,
  216. 'capability_type' => 'post',
  217. 'has_archive' => true,
  218. 'hierarchical' => false,
  219. 'menu_position' => null,
  220. 'supports' => array(
  221. 'title',
  222. 'editor',
  223. 'comments',
  224. 'thumbnail',
  225. 'author'
  226. )
  227. );
  228. register_post_type('shuoshuo', $args);
  229. }
  230. add_action('init', 'shuoshuo_custom_init');
  231. function admin_lettering()
  232. {
  233. echo '<style>body{font-family: Microsoft YaHei;}</style>';
  234. }
  235. add_action('admin_head', 'admin_lettering');
  236. /**
  237. * Set the content width in pixels, based on the theme's design and stylesheet.
  238. *
  239. * Priority 0 to make it available to lower priority callbacks.
  240. *
  241. * @global int $content_width
  242. */
  243. function akina_content_width()
  244. {
  245. $GLOBALS['content_width'] = apply_filters('akina_content_width', 640);
  246. }
  247. add_action('after_setup_theme', 'akina_content_width', 0);
  248. /**
  249. * Enqueue scripts and styles.
  250. */
  251. function sakura_scripts()
  252. {
  253. global $core_lib_basepath;
  254. global $shared_lib_basepath;
  255. if (iro_opt('smoothscroll_option')) {
  256. wp_enqueue_script('SmoothScroll', $shared_lib_basepath. '/js/smoothscroll.js', array(), IRO_VERSION . iro_opt('cookie_version', ''), true);
  257. }
  258. wp_enqueue_style('saukra-css', $core_lib_basepath.'/style.css', array(), IRO_VERSION);
  259. if (!is_home()){
  260. //非主页的资源
  261. wp_enqueue_style('entry-content',
  262. $core_lib_basepath.'/css/theme/'.(iro_opt('entry_content_style') == 'sakurairo' ?'sakura' : 'github').'.css',
  263. array(), IRO_VERSION);
  264. wp_enqueue_script('app-page', $core_lib_basepath . '/js/page.js', array('app','polyfills'), IRO_VERSION, true);
  265. }
  266. wp_enqueue_script('app', $core_lib_basepath . '/js/app.js', array('polyfills'), IRO_VERSION, true);
  267. wp_enqueue_script('polyfills', $core_lib_basepath . '/js/polyfill.js', array(), IRO_VERSION, true);
  268. if (is_singular() && comments_open() && get_option('thread_comments')) {
  269. wp_enqueue_script('comment-reply');
  270. }
  271. //前端脚本本地化
  272. if (get_locale() != 'zh_CN') {
  273. wp_localize_script('app', '_sakurairoi18n', array(
  274. '复制成功!' => __("Copied!", 'sakurairo'),
  275. '拷贝代码' => __("Copy Code", 'sakurairo'),
  276. '你的封面API好像不支持跨域调用,这种情况下缓存是不会生效的哦' => __("Your cover API seems to not support Cross Origin Access. In this case, Cover Cache won't take effect.", 'sakurairo'),
  277. '提交中....' => __('Commiting....', 'sakurairo'),
  278. '提交成功' => __('Succeed', 'sakurairo'),
  279. '每次上传上限为10张' => __('10 files max per request', 'sakurairo'),
  280. "图片上传大小限制为5 MB\n\n「{0}」\n\n这张图太大啦~请重新上传噢!" => __("5 MB max per file.\n\n「{0}」\n\nThis image is too large~Please reupload!", 'sakurairo'),
  281. '上传中...' => __('Uploading...', 'sakurairo'),
  282. '图片上传成功~' => __('Uploaded successfully~', 'sakurairo'),
  283. "上传失败!\n文件名=> {0}\ncode=> {1}\n{2}" => __("Upload failed!\nFile Name=> {0}\ncode=> {1}\n{2}", 'sakurairo'),
  284. '上传失败,请重试.' => __('Upload failed, please retry.', 'sakurairo'),
  285. '页面加载出错了 HTTP {0}' => __("Page Load failed. HTTP {0}", 'sakurairo'),
  286. '很高兴你翻到这里,但是真的没有了...' => __("Glad you come, but we've got nothing left.", 'sakurairo'),
  287. "文章" => __("Post", 'sakurairo'),
  288. "标签" => __("Tag", 'sakurairo'),
  289. "分类" => __("Category", 'sakurairo'),
  290. "页面" => __("Page", 'sakurairo'),
  291. "评论" => __("Comment", 'sakurairo'),
  292. "已暂停..." => __("Paused...", 'sakurairo'),
  293. "正在载入视频 ..." => __("Loading Video...", 'sakurairo'),
  294. "将从网络加载字体,流量请注意" => __("Downloading fonts, be aware of your data usage.", 'sakurairo'),
  295. "您真的要设为私密吗?" => __("Are you sure you want set it private?", 'sakurairo'),
  296. "您之前已设过私密评论" => __("You had set private comment before", 'sakurairo')
  297. ));
  298. }
  299. }
  300. add_action('wp_enqueue_scripts', 'sakura_scripts');
  301. /**
  302. * load .php.
  303. */
  304. require get_template_directory() . '/inc/decorate.php';
  305. require get_template_directory() . '/inc/swicher.php';
  306. require get_template_directory() . '/inc/api.php';
  307. /**
  308. * Custom template tags for this theme.
  309. */
  310. require get_template_directory() . '/inc/template-tags.php';
  311. /**
  312. * Customizer additions.
  313. */
  314. require get_template_directory() . '/inc/customizer.php';
  315. /**
  316. * function update
  317. */
  318. require get_template_directory() . '/inc/theme_plus.php';
  319. require get_template_directory() . '/inc/categories-images.php';
  320. //Comment Location Start
  321. function convertip($ip)
  322. {
  323. if (empty($ip)) $ip = get_comment_author_IP();
  324. $ch = curl_init();
  325. $url = 'https://api.nmxc.ltd/ip/' . $ip;
  326. $timeout = 5;
  327. curl_setopt($ch, CURLOPT_URL, $url);
  328. // curl_setopt ($ch, CURLOPT_URL, 'http://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip='.$ip);
  329. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  330. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  331. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  332. $file_contents = curl_exec($ch);
  333. curl_close($ch);
  334. $result = null;
  335. $result = json_decode($file_contents, true);
  336. if ($result && $result['code'] != 0) {
  337. return "未知";
  338. }
  339. if ($result['data']['country'] != '中国') {
  340. return $result['data']['country'];
  341. }
  342. return $result['data']['country'] . '&nbsp;·&nbsp;' . $result['data']['region'] . '&nbsp;·&nbsp;' . $result['data']['city'];
  343. }
  344. //Comment Location End
  345. if (!function_exists('akina_comment_format')) {
  346. function akina_comment_format($comment, $args, $depth)
  347. {
  348. $GLOBALS['comment'] = $comment;
  349. ?>
  350. <li <?php comment_class(); ?> id="comment-<?php echo esc_attr(comment_ID()); ?>">
  351. <div class="contents">
  352. <div class="comment-arrow">
  353. <div class="main shadow">
  354. <div class="profile">
  355. <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>
  356. </div>
  357. <div class="commentinfo">
  358. <section class="commeta">
  359. <div class="left">
  360. <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>
  361. </div>
  362. <?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
  363. <div class="right">
  364. <div class="info"><time datetime="<?php comment_date('Y-m-d'); ?>"><?php echo poi_time_since(strtotime($comment->comment_date), true); //comment_date(get_option('date_format'));
  365. ?></time><?= siren_get_useragent($comment->comment_agent); ?><?php echo mobile_get_useragent_icon($comment->comment_agent); ?>&nbsp;<?php if (iro_opt('comment_location')) {
  366. _e('Location', 'sakurairo'); /*来自*/ ?>: <?php echo convertip(get_comment_author_ip());
  367. } ?>
  368. <?php if (current_user_can('manage_options') and (wp_is_mobile() == false)) {
  369. $comment_ID = $comment->comment_ID;
  370. $i_private = get_comment_meta($comment_ID, '_private', true);
  371. $flag = null;
  372. $flag .= ' <i class="fa-regular fa-snowflake"></i> <a href="javascript:;" data-actionp="set_private" data-idp="' . get_comment_id() . '" id="sp" class="sm">' . __("Private", "sakurairo") . ': <span class="has_set_private">';
  373. if (!empty($i_private)) {
  374. $flag .= __("Yes", "sakurairo") . ' <i class="fa-solid fa-lock"></i>';
  375. } else {
  376. $flag .= __("No", "sakurairo") . ' <i class="fa-solid fa-lock-open"></i>';
  377. }
  378. $flag .= '</span></a>';
  379. $flag .= edit_comment_link('<i class="fa-solid fa-pen-to-square"></i> ' . __("Edit", "mashiro"), ' <span style="color:rgba(0,0,0,.35)">', '</span>');
  380. echo $flag;
  381. } ?></div>
  382. </div>
  383. </section>
  384. </div>
  385. <div class="body">
  386. <?php comment_text(); ?>
  387. </div>
  388. </div>
  389. <div class="arrow-left"></div>
  390. </div>
  391. </div>
  392. <hr>
  393. <?php
  394. }
  395. }
  396. /**
  397. * 获取访客VIP样式
  398. */
  399. function get_author_class($comment_author_email, $user_id)
  400. {
  401. global $wpdb;
  402. $author_count = count($wpdb->get_results(
  403. "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "
  404. ));
  405. # 等级梯度
  406. $lv_array = [0, 5, 10, 20, 40, 80, 160];
  407. $Lv = 0;
  408. foreach ($lv_array as $key => $value) {
  409. if ($value >= $author_count) break;
  410. $Lv = $key;
  411. }
  412. // $Lv = $author_count < 5 ? 0 : ($author_count < 10 ? 1 : ($author_count < 20 ? 2 : ($author_count < 40 ? 3 : ($author_count < 80 ? 4 : ($author_count < 160 ? 5 : 6)))));
  413. echo "<span class=\"showGrade{$Lv}\" title=\"Lv{$Lv}\"><img alt=\"level_img\" src=\"".iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/')."comment_level/level_{$Lv}.svg\" style=\"height: 1.5em; max-height: 1.5em; display: inline-block;\"></span>";
  414. }
  415. /**
  416. * post views
  417. */
  418. function restyle_text($number)
  419. {
  420. switch (iro_opt('statistics_format')) {
  421. case "type_2": //23,333 次访问
  422. return number_format($number);
  423. case "type_3": //23 333 次访问
  424. return number_format($number, 0, '.', ' ');
  425. case "type_4": //23k 次访问
  426. if ($number >= 1000) {
  427. return round($number / 1000, 2) . 'k';
  428. }
  429. return $number;
  430. default:
  431. return $number;
  432. }
  433. }
  434. function set_post_views()
  435. {
  436. if (!is_singular()) return;
  437. global $post;
  438. $post_id = intval($post->ID);
  439. if (!$post_id) return;
  440. $views = (int) get_post_meta($post_id, 'views', true);
  441. if (!update_post_meta($post_id, 'views', ($views + 1))) {
  442. add_post_meta($post_id, 'views', 1, true);
  443. }
  444. }
  445. add_action('get_header', 'set_post_views');
  446. function get_post_views($post_id) {
  447. // 检查传入的参数是否有效
  448. if (empty($post_id) || !is_numeric($post_id)) {
  449. return 'Error: Invalid post ID.';
  450. }
  451. // 检查 WP-Statistics 插件是否安装
  452. if ((function_exists('wp_statistics_pages')) && (iro_opt('statistics_api') == 'wp_statistics')){
  453. // 使用 WP-Statistics 插件获取浏览量
  454. $views = wp_statistics_pages('total', 'uri', $post_id);
  455. return empty($views) ? 0 : $views;
  456. } else {
  457. // 使用文章自定义字段获取浏览量
  458. $views = get_post_meta($post_id, 'views', true);
  459. // 格式化浏览量
  460. $views = restyle_text($views);
  461. return empty($views) ? 0 : $views;
  462. }
  463. }
  464. function is_webp(): bool
  465. {
  466. return (isset($_COOKIE['su_webp']) || (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'image/webp')));
  467. }
  468. /**
  469. * 获取友情链接列表
  470. * @Param: string $sorting_mode 友情链接列表排序模式,name、updated、rating、rand四种模式
  471. * @Param: string $link_order 友情链接列表排序方法,ASC、DESC(升序或降序)
  472. * @Param: mixed $id 友情链接ID
  473. * @Param: string $output HTML格式化输出
  474. */
  475. function get_the_link_items($id = null)
  476. { $sorting_mode = iro_opt('friend_link_sorting_mode');
  477. $link_order = iro_opt('friend_link_order');
  478. $bookmarks = get_bookmarks(array(
  479. 'orderby' => $sorting_mode,
  480. 'order' => $link_order,
  481. 'category' => $id
  482. ));
  483. $output = '';
  484. if (!empty($bookmarks)) {
  485. $output .= '<ul class="link-items fontSmooth">';
  486. foreach ($bookmarks as $bookmark) {
  487. if (empty($bookmark->link_description)) {
  488. $bookmark->link_description = __('This guy is so lazy ╮(╯▽╰)╭', 'sakurairo');
  489. }
  490. if (empty($bookmark->link_image)) {
  491. $bookmark->link_image = 'https://s.nmxc.ltd/sakurairo_vision/@2.6/basic/friendlink.jpg';
  492. }
  493. $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 alt="friend_avator" class="lazyload" onerror="imgError(this,1)" data-src="' . $bookmark->link_image . '" src="' . iro_opt('load_in_svg') . '"></br><span class="sitename" style="'. $bookmark->link_notes .'">' . $bookmark->link_name . '</span><div class="linkdes">' . $bookmark->link_description . '</div></a></li>';
  494. }
  495. $output .= '</ul>';
  496. }
  497. return $output;
  498. }
  499. function get_link_items()
  500. {
  501. $linkcats = get_terms('link_category');
  502. $result = null;
  503. if (empty($linkcats)) return get_the_link_items(); // 友链无分类,直接返回全部列表
  504. $link_category_need_display = get_post_meta(get_queried_object_id(), 'link_category_need_display', false);
  505. foreach ($linkcats as $linkcat) {
  506. if (!empty($link_category_need_display) && !in_array($linkcat->name, $link_category_need_display, true)) {
  507. continue;
  508. }
  509. $result .= '<h3 class="link-title"><span class="link-fix">' . $linkcat->name . '</span></h3>';
  510. if ($linkcat->description) {
  511. $result .= '<div class="link-description">' . $linkcat->description . '</div>';
  512. }
  513. $result .= get_the_link_items($linkcat->term_id);
  514. }
  515. return $result;
  516. }
  517. /*
  518. * Gravatar头像使用中国服务器
  519. */
  520. function gravatar_cn(string $url):string
  521. {
  522. $gravatar_url = array('0.gravatar.com/avatar', '1.gravatar.com/avatar', '2.gravatar.com/avatar', 'secure.gravatar.com/avatar');
  523. if (iro_opt('gravatar_proxy') == 'custom_proxy_address_of_gravatar') {
  524. return str_replace($gravatar_url, iro_opt('custom_proxy_address_of_gravatar'), $url);
  525. } else {
  526. return str_replace($gravatar_url, iro_opt('gravatar_proxy'), $url);
  527. }
  528. }
  529. if (iro_opt('gravatar_proxy')) {
  530. add_filter('get_avatar_url', 'gravatar_cn', 4);
  531. }
  532. /*
  533. * 检查主题版本号,并在更新主题后执行设置选项值的更新
  534. */
  535. function visual_resource_updates($specified_version, $option_name, $new_value) {
  536. $theme = wp_get_theme();
  537. $current_version = $theme->get('Version');
  538. // Check if the function has already been triggered
  539. $function_triggered = get_transient('visual_resource_updates_triggered18');
  540. if ($function_triggered) {
  541. return; // Function has already been triggered, do nothing
  542. }
  543. if (version_compare($current_version, $specified_version, '>')) {
  544. $option_value = iro_opt($option_name);
  545. if (empty($option_value)) {
  546. $option_value = "https://s.nmxc.ltd/sakurairo_vision/@2.6/";
  547. } else if (strpos($option_value, '@') === false || substr($option_value, strpos($option_value, '@') + 1) !== $new_value) {
  548. $option_value = preg_replace('/@.*/', '@' . $new_value, $option_value);
  549. }
  550. iro_opt_update($option_name, $option_value);
  551. // Set transient to indicate that the function has been triggered
  552. set_transient('visual_resource_updates_triggered18', true);
  553. }
  554. }
  555. visual_resource_updates('2.5.6', 'vision_resource_basepath', '2.6/');
  556. function gfonts_updates($specified_version, $option_name) {
  557. $theme = wp_get_theme();
  558. $current_version = $theme->get('Version');
  559. // Check if the function has already been triggered
  560. $function_triggered = get_transient('gfonts_updates_triggered18');
  561. if ($function_triggered) {
  562. return; // Function has already been triggered, do nothing
  563. }
  564. if (version_compare($current_version, $specified_version, '>')) {
  565. $option_value = iro_opt($option_name);
  566. if (empty($option_value) || $option_value !== 'cdn2.tianli0.top/fonts') {
  567. $option_value = 'cdn2.tianli0.top/fonts';
  568. iro_opt_update($option_name, $option_value);
  569. }
  570. // Set transient to indicate that the function has been triggered
  571. set_transient('gfonts_updates_triggered18', true);
  572. }
  573. }
  574. gfonts_updates('2.5.6', 'gfonts_api');
  575. function gravater_updates($specified_version, $option_name) {
  576. $theme = wp_get_theme();
  577. $current_version = $theme->get('Version');
  578. // Check if the function has already been triggered
  579. $function_triggered = get_transient('gravater_updates_triggered181');
  580. if ($function_triggered) {
  581. return; // Function has already been triggered, do nothing
  582. }
  583. if (version_compare($current_version, $specified_version, '>')) {
  584. $option_value = iro_opt($option_name);
  585. if (empty($option_value) || $option_value !== 'weavatar.com/avatar') {
  586. $option_value = 'weavatar.com/avatar';
  587. iro_opt_update($option_name, $option_value);
  588. }
  589. // Set transient to indicate that the function has been triggered
  590. set_transient('gravater_updates_triggered181', true);
  591. }
  592. }
  593. gravater_updates('2.5.6', 'gravatar_proxy');
  594. /*
  595. * 阻止站内文章互相Pingback
  596. */
  597. function theme_noself_ping(&$links)
  598. {
  599. $home = get_option('home');
  600. foreach ($links as $l => $link) {
  601. if (0 === strpos($link, $home)) {
  602. unset($links[$l]);
  603. }
  604. }
  605. }
  606. add_action('pre_ping', 'theme_noself_ping');
  607. /*
  608. * 订制body类
  609. */
  610. function akina_body_classes($classes)
  611. {
  612. // Adds a class of group-blog to blogs with more than 1 published author.
  613. if (is_multi_author()) {
  614. $classes[] = 'group-blog';
  615. }
  616. // Adds a class of hfeed to non-singular pages.
  617. if (!is_singular()) {
  618. $classes[] = 'hfeed';
  619. }
  620. // 定制中文字体class
  621. $classes[] = 'chinese-font';
  622. /*if(!wp_is_mobile()) {
  623. $classes[] = 'serif';
  624. }*/
  625. if (isset($_COOKIE['dark' . iro_opt('cookie_version', '')])) {
  626. $classes[] = $_COOKIE['dark' . iro_opt('cookie_version', '')] == '1' ? 'dark' : ' ';
  627. } else {
  628. $classes[] = ' ';
  629. }
  630. return $classes;
  631. }
  632. add_filter('body_class', 'akina_body_classes');
  633. /*
  634. * 图片CDN
  635. */
  636. add_filter('upload_dir', 'wpjam_custom_upload_dir');
  637. function wpjam_custom_upload_dir($uploads)
  638. {
  639. /* $upload_path = '';
  640. */ $upload_url_path = iro_opt('image_cdn');
  641. /* if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
  642. $uploads['basedir'] = WP_CONTENT_DIR . '/uploads';
  643. } elseif (0 !== strpos($upload_path, ABSPATH)) {
  644. $uploads['basedir'] = path_join(ABSPATH, $upload_path);
  645. } else {
  646. $uploads['basedir'] = $upload_path;
  647. } */
  648. $uploads['path'] = $uploads['basedir'] . $uploads['subdir'];
  649. if ($upload_url_path) {
  650. $uploads['baseurl'] = $upload_url_path;
  651. $uploads['url'] = $uploads['baseurl'] . $uploads['subdir'];
  652. }
  653. return $uploads;
  654. }
  655. /*
  656. * 删除自带小工具
  657. */
  658. function unregister_default_widgets()
  659. {
  660. unregister_widget('WP_Widget_Pages');
  661. unregister_widget('WP_Widget_Calendar');
  662. unregister_widget('WP_Widget_Archives');
  663. unregister_widget('WP_Widget_Links');
  664. unregister_widget('WP_Widget_Meta');
  665. unregister_widget('WP_Widget_Search');
  666. //unregister_widget('WP_Widget_Text');
  667. unregister_widget('WP_Widget_Categories');
  668. unregister_widget('WP_Widget_Recent_Posts');
  669. //unregister_widget('WP_Widget_Recent_Comments');
  670. //unregister_widget('WP_Widget_RSS');
  671. //unregister_widget('WP_Widget_Tag_Cloud');
  672. unregister_widget('WP_Nav_Menu_Widget');
  673. }
  674. add_action("widgets_init", "unregister_default_widgets", 11);
  675. /**
  676. * Jetpack setup function.
  677. *
  678. * See: https://jetpack.com/support/infinite-scroll/
  679. * See: https://jetpack.com/support/responsive-videos/
  680. */
  681. function akina_jetpack_setup()
  682. {
  683. // Add theme support for Infinite Scroll.
  684. add_theme_support('infinite-scroll', array(
  685. 'container' => 'main',
  686. 'render' => 'akina_infinite_scroll_render',
  687. 'footer' => 'page',
  688. ));
  689. // Add theme support for Responsive Videos.
  690. add_theme_support('jetpack-responsive-videos');
  691. }
  692. add_action('after_setup_theme', 'akina_jetpack_setup');
  693. /**
  694. * Custom render function for Infinite Scroll.
  695. */
  696. function akina_infinite_scroll_render()
  697. {
  698. while (have_posts()) {
  699. the_post();
  700. get_template_part('tpl/content', is_search() ? 'search' : get_post_format());
  701. }
  702. }
  703. /*
  704. * 编辑器增强
  705. */
  706. function enable_more_buttons($buttons)
  707. {
  708. $buttons[] = 'hr';
  709. $buttons[] = 'del';
  710. $buttons[] = 'sub';
  711. $buttons[] = 'sup';
  712. $buttons[] = 'fontselect';
  713. $buttons[] = 'fontsizeselect';
  714. $buttons[] = 'cleanup';
  715. $buttons[] = 'styleselect';
  716. $buttons[] = 'wp_page';
  717. $buttons[] = 'anchor';
  718. $buttons[] = 'backcolor';
  719. return $buttons;
  720. }
  721. add_filter("mce_buttons_3", "enable_more_buttons");
  722. // 下载按钮
  723. function download($atts, $content = null)
  724. {
  725. return '<a class="download" href="' . $content . '" rel="external"
  726. target="_blank" title="'.__("Download Link","sakurairo").'">
  727. <span><i class="fa-solid fa-download"></i>Download</span></a>';
  728. }
  729. add_shortcode("download", "download");
  730. add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
  731. function bolo_after_wp_tiny_mce($mce_settings)
  732. {
  733. ?>
  734. <script type="text/javascript">
  735. QTags.addButton('download', '下载按钮', "[download]下载地址[/download]");
  736. function bolo_QTnextpage_arg1() {}
  737. </script>
  738. <?php }
  739. /*
  740. * 后台登录页
  741. * @M.J
  742. */
  743. //Login Page style
  744. $custom_login_switch = iro_opt('custom_login_switch');
  745. if ($custom_login_switch) {
  746. function custom_login() {
  747. require get_template_directory() . '/inc/login_addcss.php';
  748. //echo '<link rel="stylesheet" type="text/css" href="' . get_bloginfo('template_directory') . '/inc/login.css" />'."\n";
  749. echo '<link rel="stylesheet" type="text/css" href="' . get_template_directory_uri() . '/inc/login.css?' . IRO_VERSION . '" />' . "\n";
  750. //echo '<script type="text/javascript" src="'.get_bloginfo('template_directory').'/js/jquery.min.js"></script>'."\n";
  751. }
  752. add_action('login_head', 'custom_login');
  753. //Login Page Title
  754. function custom_headertitle($title) {
  755. return get_bloginfo('name');
  756. }
  757. add_filter('login_headertext', 'custom_headertitle');
  758. //Login Page Link
  759. function custom_loginlogo_url($url) {
  760. return esc_url(home_url('/'));
  761. }
  762. add_filter('login_headerurl', 'custom_loginlogo_url');
  763. //Login Page Footer
  764. function custom_html() {
  765. $loginbg = iro_opt('login_background') ?: iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'series/login_background.webp';
  766. ?>
  767. <script type="text/javascript">
  768. document.body.insertAdjacentHTML("afterbegin", "<div class=\"loading\"><img src=\"<?=iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/')
  769. ?>basic/login_loading.gif\" width=\"58\" height=\"10\"></div>");
  770. document.head.insertAdjacentHTML("afterbegin", "<style>.show{opacity:1;}.hide{opacity:0;transition: opacity 400ms;}</style>");
  771. const loading = document.querySelector(".loading"),
  772. src = "<?= $loginbg ?>",
  773. afterLoaded = () => {
  774. document.body.style.backgroundImage = `url(${src})`
  775. loading.classList.add("hide");
  776. loading.classList.remove("show");
  777. setTimeout(function() {
  778. loading.remove()
  779. }, 400);
  780. },
  781. img = document.createElement('img')
  782. img.src = src
  783. img.addEventListener('load',afterLoaded,{once:true})
  784. <?php //3秒钟内加载不到图片也移除加载中提示
  785. ?>
  786. setTimeout(afterLoaded, 3000)
  787. document.addEventListener("DOMContentLoaded", ()=>{
  788. document.querySelector("h1 a").style.backgroundImage = "url('<?= iro_opt('login_logo_img')?>')";
  789. forgetmenot = document.querySelector(".forgetmenot");
  790. if (forgetmenot){
  791. forgetmenot.outerHTML = '<p class="forgetmenot"><?=__("Remember me","sakurairo")?><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>';
  792. }
  793. const captchaimg = document.getElementById("captchaimg");
  794. captchaimg && captchaimg.addEventListener("click",(e)=>{
  795. fetch("<?= rest_url('sakura/v1/captcha/create')?>")
  796. .then(resp=>resp.json())
  797. .then(json=>{
  798. e.target.src = json["data"];
  799. document.querySelector("input[name=\'timestamp\']").value = json["time"];
  800. document.querySelector("input[name=\'id\']").value = json["id"];
  801. });
  802. })
  803. }, false);
  804. </script>
  805. <?php
  806. }
  807. add_action('login_footer', 'custom_html');
  808. }
  809. //Login message
  810. //* Add custom message to WordPress login page
  811. function smallenvelop_login_message($message)
  812. {
  813. return empty($message) ? '<p class="message"><strong>You may try 3 times for every 5 minutes!</strong></p>' : $message;
  814. }
  815. //add_filter( 'login_message', 'smallenvelop_login_message' );
  816. //Fix password reset bug </>
  817. function resetpassword_message_fix($message)
  818. {
  819. return str_replace(['>','<'], '', $message);
  820. // $message = str_replace('<', '', $message);
  821. // $message = str_replace('>', '', $message);
  822. // return $message;
  823. }
  824. add_filter('retrieve_password_message', 'resetpassword_message_fix');
  825. //Fix register email bug </>
  826. function new_user_message_fix($message)
  827. {
  828. $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";
  829. $message = str_replace('To set your password, visit the following address:', $show_register_ip . '在此设置密码 | To set your password, visit the following address:', $message);
  830. $message = str_replace('<', '', $message);
  831. $message = str_replace('>', "\r\n\r\n设置密码后在此登录 | Login here after setting password: ", $message);
  832. return $message;
  833. }
  834. add_filter('wp_new_user_notification_email', 'new_user_message_fix');
  835. /*
  836. * 评论邮件回复
  837. */
  838. function comment_mail_notify($comment_id)
  839. {
  840. $mail_user_name = iro_opt('mail_user_name') ? iro_opt('mail_user_name') : 'poi';
  841. $comment = get_comment($comment_id);
  842. $parent_id = $comment->comment_parent ?: '';
  843. $spam_confirmed = $comment->comment_approved;
  844. $mail_notify = iro_opt('mail_notify') ? get_comment_meta($parent_id, 'mail_notify', false) : false;
  845. $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');
  846. if (($parent_id != '') && ($spam_confirmed != 'spam') && ($admin_notify != '0') && (!$mail_notify)) {
  847. $wp_email = $mail_user_name . '@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
  848. $to = trim(get_comment($parent_id)->comment_author_email);
  849. $subject = '你在 [' . get_option("blogname") . '] 的留言有了回应';
  850. $message = '
  851. <div style="background: white;
  852. width: 95%;
  853. max-width: 800px;
  854. margin: auto auto;
  855. border-radius: 5px;
  856. border: ' . iro_opt('theme_skin') . ' 1px solid;
  857. overflow: hidden;
  858. -webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.12);
  859. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.18);">
  860. <header style="overflow: hidden;">
  861. <img style="width:100%;z-index: 666;" src="' . iro_opt('mail_img') . '">
  862. </header>
  863. <div style="padding: 5px 20px;">
  864. <p style="position: relative;
  865. color: white;
  866. float: left;
  867. z-index: 999;
  868. background: ' . iro_opt('theme_skin') . ';
  869. padding: 5px 30px;
  870. margin: -25px auto 0 ;
  871. box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.30)">Dear&nbsp;' . trim(get_comment($parent_id)->comment_author) . '</p>
  872. <br>
  873. <h3>您有一条来自<a style="text-decoration: none;color: ' . iro_opt('theme_skin') . ' " target="_blank" href="' . home_url() . '/">' . get_option("blogname") . '</a>的回复</h3>
  874. <br>
  875. <p style="font-size: 14px;">您在文章《' . get_the_title($comment->comment_post_ID) . '》上发表的评论:</p>
  876. <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">'
  877. . trim(get_comment($parent_id)->comment_content) . '</div>
  878. <p style="font-size: 14px;">' . trim($comment->comment_author) . ' 给您的回复如下:</p>
  879. <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">'
  880. . trim($comment->comment_content) . '</div>
  881. <div style="text-align: center;">
  882. <img src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'basic/comment-mail.png" alt="hr" style="width:100%;
  883. margin:5px auto 5px auto;
  884. display: block;">
  885. <a style="text-transform: uppercase;
  886. text-decoration: none;
  887. font-size: 14px;
  888. border: 2px solid #6c7575;
  889. color: #2f3333;
  890. padding: 10px;
  891. display: inline-block;
  892. margin: 10px auto 0; " target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">点击查看回复的完整內容</a>
  893. </div>
  894. <p style="font-size: 12px;text-align: center;color: #999;">本邮件为系统自动发出,请勿直接回复<br>
  895. &copy; ' . date('Y') . ' ' . get_option("blogname") . '</p>
  896. </div>
  897. </div>
  898. ';
  899. $message = convert_smilies($message);
  900. $message = str_replace('{{', '<img src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'/smilies/bilipng/emoji_', $message);
  901. $message = str_replace('}}', '.png" alt="emoji" style="height: 2em; max-height: 2em;">', $message);
  902. $message = str_replace('{UPLOAD}', 'https://i.loli.net/', $message);
  903. $message = str_replace('[/img][img]', '[/img^img]', $message);
  904. $message = str_replace('[img]', '<img src="', $message);
  905. $message = str_replace('[/img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;">', $message);
  906. $message = str_replace('[/img^img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;"><img src="', $message);
  907. $from = 'From: "' . get_option('blogname') . "\" <$wp_email>";
  908. $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n";
  909. wp_mail($to, $subject, $message, $headers);
  910. }
  911. }
  912. add_action('comment_post', 'comment_mail_notify');
  913. /*
  914. * 链接新窗口打开
  915. */
  916. function rt_add_link_target($content)
  917. {
  918. $content = str_replace('<a', '<a rel="nofollow"', $content);
  919. // use the <a> tag to split into segments
  920. $bits = explode('<a ', $content);
  921. // loop though the segments
  922. foreach ($bits as $key => $bit) {
  923. // fix the target="_blank" bug after the link
  924. if (strpos($bit, 'href') === false) {
  925. continue;
  926. }
  927. // fix the target="_blank" bug in the codeblock
  928. if (strpos(preg_replace('/code([\s\S]*?)\/code[\s]*/m', 'temp', $content), $bit) === false) {
  929. continue;
  930. }
  931. // find the end of each link
  932. $pos = strpos($bit, '>');
  933. // check if there is an end (only fails with malformed markup)
  934. if ($pos !== false) {
  935. // get a string with just the link's attibutes
  936. $part = substr($bit, 0, $pos);
  937. // for comparison, get the current site/network url
  938. $siteurl = network_site_url();
  939. // if the site url is in the attributes, assume it's in the href and skip, also if a target is present
  940. if (strpos($part, $siteurl) === false && strpos($part, 'target=') === false) {
  941. // add the target attribute
  942. $bits[$key] = 'target="_blank" ' . $bits[$key];
  943. }
  944. }
  945. }
  946. // re-assemble the content, and return it
  947. return implode('<a ', $bits);
  948. }
  949. add_filter('comment_text', 'rt_add_link_target');
  950. // 评论通过BBCode插入图片
  951. function comment_picture_support($content)
  952. {
  953. $content = str_replace('http://', 'https://', $content); // 干掉任何可能的 http
  954. $content = str_replace('{UPLOAD}', 'https://i.loli.net/', $content);
  955. $content = str_replace('[/img][img]', '[/img^img]', $content);
  956. $content = str_replace('[img]', '<br><img src="' . iro_opt('load_in_svg') . '" data-src="', $content);
  957. $content = str_replace('[/img]', '" class="lazyload comment_inline_img" onerror="imgError(this)"><br>', $content);
  958. $content = str_replace('[/img^img]', '" class="lazyload comment_inline_img" onerror="imgError(this)"><img src="' . iro_opt('load_in_svg') . '" data-src="', $content);
  959. return $content;
  960. }
  961. add_filter('comment_text', 'comment_picture_support');
  962. /*
  963. * 修改评论表情调用路径
  964. */
  965. // 简单遍历系统表情库,今后应考虑标识表情包名——使用增加的扩展名,同时保留原有拓展名
  966. // 还有一个思路是根据表情调用路径来判定<-- 此法最好!
  967. // 贴吧
  968. /**
  969. * 通过文件夹获取自定义表情列表,使用Transients来存储获得的列表,除非手动清除,数据永不过期。
  970. * 数据格式如下:
  971. * Array
  972. * (
  973. * [0] => Array
  974. * (
  975. * [path] => C:\xampp\htdocs\wordpress/wp-content/uploads/sakurairo_vision/@2.4/smilies\bilipng\emoji_2233_chijing.png
  976. * [little_path] => /sakurairo_vision/@2.4/smilies\bilipng\emoji_2233_chijing.png
  977. * [file_url] => http://192.168.233.174/wordpress/wp-content/uploads/sakurairo_vision/@2.4/smilies\bilipng\emoji_2233_chijing.png
  978. * [name] => emoji_2233_chijing.png
  979. * [base_name] => emoji_2233_chijing
  980. * [extension] => png
  981. * )
  982. * ...
  983. * )
  984. *
  985. * @return array
  986. */
  987. function get_custom_smilies_list() {
  988. $custom_smilies_list = get_transient("custom_smilies_list");
  989. if ($custom_smilies_list !== false) {
  990. return $custom_smilies_list;
  991. }
  992. $custom_smilies_list = array();
  993. $custom_smilies_dir = iro_opt('smilies_dir');
  994. if (!$custom_smilies_dir) {
  995. return $custom_smilies_list;
  996. }
  997. $custom_smilies_extension = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'avif','webp'];
  998. $custom_smilies_path = wp_get_upload_dir()['basedir'] . $custom_smilies_dir;
  999. if (!is_dir($custom_smilies_path)) {
  1000. return $custom_smilies_list;
  1001. }
  1002. $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($custom_smilies_path), RecursiveIteratorIterator::LEAVES_ONLY);
  1003. foreach ($files as $file) {
  1004. if ($file->isFile()) {
  1005. $file_name = $file->getFilename();
  1006. $file_base_name = pathinfo($file_name, PATHINFO_FILENAME);
  1007. $file_extension = pathinfo($file_name, PATHINFO_EXTENSION);
  1008. $file_path = $file->getPathname();
  1009. $file_little_path = str_replace(wp_get_upload_dir()['basedir'], '' , $file_path);
  1010. $file_url = wp_get_upload_dir()['baseurl'] . $file_little_path;
  1011. if (in_array($file_extension, $custom_smilies_extension)) {
  1012. $custom_smilies_list[] = array(
  1013. 'path' => $file_path,
  1014. 'little_path' => $file_little_path,
  1015. 'file_url' => $file_url,
  1016. 'name' => $file_name,
  1017. 'base_name' => $file_base_name,
  1018. 'extension' => $file_extension
  1019. );
  1020. }
  1021. }
  1022. }
  1023. set_transient("custom_smilies_list", $custom_smilies_list);
  1024. return $custom_smilies_list;
  1025. }
  1026. /**
  1027. * 通过 GET 方法更新自定义表情包列表
  1028. */
  1029. function update_custom_smilies_list() {
  1030. if (!is_admin() || !current_user_can('manage_options')) {
  1031. return;
  1032. }
  1033. if (!isset($_GET['update_custom_smilies'])) {
  1034. return;
  1035. }
  1036. $transient_name = sanitize_key($_GET['update_custom_smilies']);
  1037. if ($transient_name === 'true') {
  1038. delete_transient("custom_smilies_list");
  1039. $custom_smilies_list = get_custom_smilies_list();
  1040. $much = count($custom_smilies_list);
  1041. echo '自定义表情列表更新完成!总共有' . $much . '个表情。';
  1042. }
  1043. }
  1044. update_custom_smilies_list();
  1045. $custom_smiliestrans = array();
  1046. /**
  1047. * 输出表情列表
  1048. *
  1049. */
  1050. function push_custom_smilies() {
  1051. global $custom_smiliestrans;
  1052. $custom_smilies_panel = '';
  1053. $custom_smilies_list = get_custom_smilies_list();
  1054. if (!$custom_smilies_list) {
  1055. $custom_smilies_panel = '<div style="font-size: 20px;text-align: center;width: 300px;height: 100px;line-height: 100px;">File does not exist!</div>';
  1056. return $custom_smilies_panel;
  1057. }
  1058. $custom_smilies_cdn = iro_opt('smilies_proxy');
  1059. foreach ($custom_smilies_list as $smiley) {
  1060. if ($custom_smilies_cdn) {
  1061. $smiley_url = $custom_smilies_cdn . $smiley['little_path'];
  1062. } else {
  1063. $smiley_url = $smiley['file_url'];
  1064. }
  1065. $custom_smilies_panel = $custom_smilies_panel . '<span title="' . $smiley['base_name'] . '" onclick="grin(' . "'" . $smiley['base_name'] . "'" . ',type = \'Math\')"><img alt="custom_smilies" loading="lazy" style="height: 60px;" src="' . $smiley_url . '" /></span>';
  1066. $custom_smiliestrans['{{' . $smiley['base_name'] . '}}'] = '<span title="' . $smiley['base_name'] . '" ><img alt="custom_smilies" loading="lazy" style="height: 60px;" src="' . $smiley_url . '" /></span>';
  1067. }
  1068. return $custom_smilies_panel;
  1069. }
  1070. /**
  1071. * 替换评论、文章中的表情符号
  1072. *
  1073. */
  1074. function custom_smilies_filter($content) {
  1075. push_custom_smilies();
  1076. global $custom_smiliestrans;
  1077. $content = str_replace(array_keys($custom_smiliestrans), $custom_smiliestrans, $content);
  1078. return $content;
  1079. }
  1080. add_filter('the_content', 'custom_smilies_filter');
  1081. add_filter('comment_text', 'custom_smilies_filter');
  1082. $wpsmiliestrans = array();
  1083. function push_tieba_smilies()
  1084. {
  1085. global $wpsmiliestrans;
  1086. // don't bother setting up smilies if they are disabled
  1087. if (!get_option('use_smilies'))
  1088. return;
  1089. $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');
  1090. $return_smiles = '';
  1091. $type = is_webp() ? 'webp' : 'png';
  1092. $tiebaimgdir = 'tieba' . $type . '/';
  1093. $smiliesgs = '.' . $type;
  1094. foreach ($tiebaname as $tieba_Name) {
  1095. // 选择面版
  1096. $return_smiles = $return_smiles . '<span title="' . $tieba_Name . '" onclick="grin(' . "'" . $tieba_Name . "'" . ',type = \'tieba\')"><img alt="tieba_smilie" loading="lazy" src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'smilies/' . $tiebaimgdir . 'icon_' . $tieba_Name . $smiliesgs . '" /></span>';
  1097. // 正文转换
  1098. $wpsmiliestrans['::' . $tieba_Name . '::'] = '<span title="' . $tieba_Name . '" onclick="grin(' . "'" . $tieba_Name . "'" . ',type = \'tieba\')"><img alt="tieba_smilie" loading="lazy" src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'smilies/' . $tiebaimgdir . 'icon_' . $tieba_Name . $smiliesgs . '" /></span>';
  1099. }
  1100. return $return_smiles;
  1101. }
  1102. push_tieba_smilies();
  1103. function tieba_smile_filter($content)
  1104. {
  1105. global $wpsmiliestrans;
  1106. $content = str_replace(array_keys($wpsmiliestrans), $wpsmiliestrans, $content);
  1107. return $content;
  1108. }
  1109. add_filter('the_content', 'tieba_smile_filter'); //替换文章关键词
  1110. add_filter('comment_text', 'tieba_smile_filter'); //替换评论关键词
  1111. function push_emoji_panel()
  1112. {
  1113. $emojis = ['(⌒▽⌒)', '( ̄▽ ̄)', '(=・ω・=)', '(`・ω・´)', '(〜 ̄△ ̄)〜', '(・∀・)', '(°∀°)ノ', '( ̄3 ̄)', '╮( ̄▽ ̄)╭', '(´_ゝ`)', '←_←', '→_→', '(&lt;_&lt;)', '(&gt;_&gt;)', '(;¬_¬)', '("▔□▔)/', '(゚Д゚≡゚д゚)!?', 'Σ(゚д゚;)', 'Σ( ̄□ ̄||)', '(’;ω;‘)', '(/TДT)/', '(^・ω・^ )', '(。・ω・。)', '(● ̄(エ) ̄●)', 'ε=ε=(ノ≧∇≦)ノ', '(’・_・‘)', '(-_-#)', '( ̄へ ̄)', '( ̄ε(# ̄)Σ', 'ヽ(‘Д’)ノ', '(#-_-)┯━┯', '(╯°口°)╯(┴—┴', '←◡←', '( ♥д♥)', '_(:3」∠)_', 'Σ&gt;―(〃°ω°〃)♡→', '⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄', '(╬゚д゚)▄︻┻┳═一', '・*・:≡( ε:)', '(笑)', '(汗)', '(泣)', '(苦笑)'];
  1114. return join('', array_map(function ($emoji) {
  1115. return '<a class="emoji-item">' . $emoji . '</a>';
  1116. }, $emojis));
  1117. }
  1118. // bilibili smiles
  1119. $bilismiliestrans = array();
  1120. function push_bili_smilies()
  1121. {
  1122. global $bilismiliestrans;
  1123. $name = array('baiyan', 'bishi', 'bizui', 'chan', 'dai', 'daku', 'dalao', 'dalian', 'dianzan', 'doge', 'facai', 'fanu', 'ganga', 'guilian', 'guzhang', 'haixiu', 'heirenwenhao', 'huaixiao', 'jingxia', 'keai', 'koubizi', 'kun', 'lengmo', 'liubixue', 'liuhan', 'liulei', 'miantian', 'mudengkoudai', 'nanguo', 'outu', 'qinqin', 'se', 'shengbing', 'shengqi', 'shuizhao', 'sikao', 'tiaokan', 'tiaopi', 'touxiao', 'tuxue', 'weiqu', 'weixiao', 'wunai', 'xiaoku', 'xieyanxiao', 'yiwen', 'yun', 'zaijian', 'zhoumei', 'zhuakuang');
  1124. $return_smiles = '';
  1125. $type = is_webp() ? 'webp' : 'png';
  1126. $biliimgdir = 'bili' . $type . '/';
  1127. $smiliesgs = '.' . $type;
  1128. foreach ($name as $smilies_Name) {
  1129. // 选择面版
  1130. $return_smiles = $return_smiles . '<span title="' . $smilies_Name . '" onclick="grin(' . "'" . $smilies_Name . "'" . ',type = \'Math\')"><img alt="bili_smilies" loading="lazy" src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'smilies/' . $biliimgdir . 'emoji_' . $smilies_Name . $smiliesgs . '" /></span>';
  1131. // 正文转换
  1132. $bilismiliestrans['{{' . $smilies_Name . '}}'] = '<span title="' . $smilies_Name . '" onclick="grin(' . "'" . $smilies_Name . "'" . ',type = \'Math\')"><img alt="bili_smilies" loading="lazy" src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'smilies/' . $biliimgdir . 'emoji_' . $smilies_Name . $smiliesgs . '" /></span>';
  1133. }
  1134. return $return_smiles;
  1135. }
  1136. push_bili_smilies();
  1137. function bili_smile_filter($content)
  1138. {
  1139. global $bilismiliestrans;
  1140. $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content);
  1141. return $content;
  1142. }
  1143. add_filter('the_content', 'bili_smile_filter'); //替换文章关键词
  1144. add_filter('comment_text', 'bili_smile_filter'); //替换评论关键词
  1145. function featuredtoRSS($content)
  1146. {
  1147. global $post;
  1148. if (has_post_thumbnail($post->ID)) {
  1149. $content = '<div>' . get_the_post_thumbnail($post->ID, 'medium', array('style' => 'margin-bottom: 15px;')) . '</div>' . $content;
  1150. }
  1151. return $content;
  1152. }
  1153. add_filter('the_excerpt_rss', 'featuredtoRSS');
  1154. add_filter('the_content_feed', 'featuredtoRSS');
  1155. //
  1156. function bili_smile_filter_rss($content)
  1157. {
  1158. $type = is_webp() ? 'webp' : 'png';
  1159. $biliimgdir = 'bili' . $type . '/';
  1160. $smiliesgs = '.' . $type;
  1161. $content = str_replace('{{', '<img src="'.iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.6/').'smilies/' . $biliimgdir, $content);
  1162. $content = str_replace('}}', $smilesgs . '" alt="emoji" style="height: 2em; max-height: 2em;">', $content);
  1163. $content = str_replace('[img]', '<img src="', $content);
  1164. $content = str_replace('[/img]', '" style="display: block;margin-left: auto;margin-right: auto;">', $content);
  1165. return $content;
  1166. }
  1167. add_filter('comment_text_rss', 'bili_smile_filter_rss'); //替换评论rss关键词
  1168. function toc_support($content)
  1169. {
  1170. $content = str_replace('[toc]', '<div class="has-toc have-toc"></div>', $content); // TOC 支持
  1171. $content = str_replace('[begin]', '<span class="begin">', $content); // 首字格式支持
  1172. $content = str_replace('[/begin]', '</span>', $content); // 首字格式支持
  1173. return $content;
  1174. }
  1175. add_filter('the_content', 'toc_support');
  1176. add_filter('the_excerpt_rss', 'toc_support');
  1177. add_filter('the_content_feed', 'toc_support');
  1178. function check_title_tags($content) {
  1179. if (!empty($content)) {
  1180. $dom = new DOMDocument();
  1181. @$dom->loadHTML($content);
  1182. $headings = $dom->getElementsByTagName('h1');
  1183. for ($i = 1; $i <= 6; $i++) {
  1184. $headings = $dom->getElementsByTagName('h' . $i);
  1185. foreach ($headings as $heading) {
  1186. if (trim($heading->nodeValue) != '') {
  1187. return true;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. return false;
  1193. }
  1194. // 显示访客当前 IP
  1195. function get_the_user_ip()
  1196. {
  1197. // if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
  1198. // //check ip from share internet
  1199. // $ip = $_SERVER['HTTP_CLIENT_IP'];
  1200. // } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
  1201. // //to check ip is pass from proxy
  1202. // $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  1203. // } else {
  1204. // $ip = $_SERVER['REMOTE_ADDR'];
  1205. // }
  1206. // 简略版
  1207. // $ip = $_SERVER['HTTP_CLIENT_IP'] ?: ($_SERVER['HTTP_X_FORWARDED_FOR'] ?: $_SERVER['REMOTE_ADDR']);
  1208. $ip = $_SERVER['HTTP_CLIENT_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];
  1209. return apply_filters('wpb_get_ip', $ip);
  1210. }
  1211. add_shortcode('show_ip', 'get_the_user_ip');
  1212. /*歌词*/
  1213. function hero_get_lyric()
  1214. {
  1215. /** These are the lyrics to Hero */
  1216. $lyrics = "";
  1217. // Here we split it into lines
  1218. $lyrics = explode("\n", $lyrics);
  1219. // And then randomly choose a line
  1220. return wptexturize($lyrics[mt_rand(0, count($lyrics) - 1)]);
  1221. }
  1222. // This just echoes the chosen line, we'll position it later
  1223. function hello_hero()
  1224. {
  1225. $chosen = hero_get_lyric();
  1226. echo $chosen;
  1227. }
  1228. /*私密评论*/
  1229. add_action('wp_ajax_nopriv_siren_private', 'siren_private');
  1230. add_action('wp_ajax_siren_private', 'siren_private');
  1231. function siren_private()
  1232. {
  1233. $comment_id = $_POST["p_id"];
  1234. $action = $_POST["p_action"];
  1235. if ($action == 'set_private') {
  1236. update_comment_meta($comment_id, '_private', 'true');
  1237. $i_private = get_comment_meta($comment_ID, '_private', true);
  1238. echo empty($i_private) ? '是' : '否';
  1239. }
  1240. die;
  1241. }
  1242. //时间序列
  1243. function memory_archives_list() {
  1244. // 尝试从缓存中获取结果
  1245. $cache_key = 'memory_archives_list_' . get_locale();
  1246. $output = get_transient($cache_key);
  1247. if ($output !== false) {
  1248. echo $output;
  1249. return;
  1250. }
  1251. $output = '<div id="archives"><p style="text-align:right;">[<span id="al_expand_collapse">' . __("All expand/collapse", "sakurairo") /*全部展开/收缩*/ . '</span>]<!-- (注: 点击月份可以展开)--></p>';
  1252. $posts = get_posts(array(
  1253. 'posts_per_page' => -1,
  1254. 'ignore_sticky_posts' => true,
  1255. 'post_type' => 'post'
  1256. ));
  1257. $posts_sorted_by_time = [];
  1258. foreach ($posts as $post) {
  1259. $post_id = $post->ID;
  1260. $post_time = get_post_time('U', false, $post_id);
  1261. $posts_sorted_by_time[$post_time] = $post;
  1262. }
  1263. krsort($posts_sorted_by_time); // 按时间倒序排列
  1264. $year = 0;
  1265. $mon = 0;
  1266. foreach ($posts_sorted_by_time as $post) {
  1267. setup_postdata($post);
  1268. $year_tmp = get_post_time('Y', false, $post);
  1269. $mon_tmp = get_post_time('m', false, $post);
  1270. $post_id = $post->ID;
  1271. $post_views = get_post_views($post_id);
  1272. if ($mon != $mon_tmp && $mon > 0) {
  1273. $output .= '</ul></li>';
  1274. }
  1275. if ($year != $year_tmp && $year > 0) {
  1276. $output .= '</ul>';
  1277. }
  1278. if ($year != $year_tmp) {
  1279. $year = $year_tmp;
  1280. $output .= '<h3 class="al_year">' . $year . __(" ", "year", "sakurairo") . /*年*/ ' </h3><ul class="al_mon_list">'; //输出年份
  1281. }
  1282. if ($mon != $mon_tmp) {
  1283. $mon = $mon_tmp;
  1284. $output .= '<li class="al_li"><span class="al_mon"><span style="color:' . iro_opt('theme_skin') . ';">' . get_post_time('M', false, $post) . '</span> (<span id="post-num"></span>' . __(" post(s)", "sakurairo") /*篇文章*/ . ')</span><ul class="al_post_list">'; //输出月份
  1285. }
  1286. $output .= '<li>' . '<a href="' . get_permalink($post) . '"><span style="color:' . iro_opt('theme_skin') . ';">' /*get_post_time('d'.__(" ","sakurairo"), false, $post) 日*/ . '</span>' . get_the_title($post) . ' <span>(' . $post_views . ' <span class="fa-regular fa-gem" aria-hidden="true"></span> / ' . get_comments_number($post) . ' <span class="fa-regular fa-comment-dots" aria-hidden="true"></span>)</span></a></li>';
  1287. }
  1288. wp_reset_postdata();
  1289. $output .= '</ul></li></ul> <!--<ul class="al_mon_list"><li><ul class="al_post_list" style="display: block;"><li>博客已经萌萌哒运行了<span id="monitorday"></span>天</li></ul></li></ul>--></div>';
  1290. set_transient($cache_key, $output, 3600);
  1291. echo $output;
  1292. }
  1293. // 在保存文章后清空缓存
  1294. function clear_memory_archives_list_cache($post_id) {
  1295. delete_transient('memory_archives_list_' . get_locale());
  1296. }
  1297. add_action('save_post', 'clear_memory_archives_list_cache');
  1298. /*
  1299. * 隐藏 Dashboard
  1300. */
  1301. /* Remove the "Dashboard" from the admin menu for non-admin users */
  1302. function remove_dashboard()
  1303. {
  1304. global $current_user, $menu, $submenu;
  1305. wp_get_current_user();
  1306. if (!in_array('administrator', $current_user->roles)) {
  1307. reset($menu);
  1308. $page = key($menu);
  1309. while ((__('Dashboard') != $menu[$page][0]) && next($menu)) {
  1310. $page = key($menu);
  1311. }
  1312. if (__('Dashboard') == $menu[$page][0]) {
  1313. unset($menu[$page]);
  1314. }
  1315. reset($menu);
  1316. $page = key($menu);
  1317. while (!$current_user->has_cap($menu[$page][1]) && next($menu)) {
  1318. $page = key($menu);
  1319. }
  1320. if (
  1321. preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) &&
  1322. ('index.php' != $menu[$page][2])
  1323. ) {
  1324. wp_redirect(get_option('siteurl') . '/wp-admin/profile.php');
  1325. }
  1326. }
  1327. }
  1328. add_action('admin_menu', 'remove_dashboard');
  1329. /**
  1330. * Filter the except length to 20 words. 限制摘要长度
  1331. *
  1332. * @param int $length Excerpt length.
  1333. * @return int (Maybe) modified excerpt length.
  1334. */
  1335. function GBsubstr($string, $start, $length)
  1336. {
  1337. if (strlen($string) > $length) {
  1338. $str = null;
  1339. $len = 0;
  1340. $i = $start;
  1341. while ($len < $length) {
  1342. if (ord(substr($string, $i, 1)) > 0xc0) {
  1343. $str .= substr($string, $i, 3);
  1344. $i += 3;
  1345. } elseif (ord(substr($string, $i, 1)) > 0xa0) {
  1346. $str .= substr($string, $i, 2);
  1347. $i += 2;
  1348. } else {
  1349. $str .= substr($string, $i, 1);
  1350. $i++;
  1351. }
  1352. $len++;
  1353. }
  1354. return $str;
  1355. } else {
  1356. return $string;
  1357. }
  1358. }
  1359. /**
  1360. * chatgpt excerpt
  1361. */
  1362. require_once __DIR__.'/inc/chatgpt/hooks.php';
  1363. IROChatGPT\apply_chatgpt_hook();
  1364. function excerpt_length($exp)
  1365. {
  1366. if (!function_exists('mb_substr')) {
  1367. $exp = GBsubstr($exp, 0, 80);
  1368. } else {
  1369. /*
  1370. * To use mb_substr() function, you should uncomment "extension=php_mbstring.dll" in php.ini
  1371. */
  1372. $exp = mb_substr($exp, 0, 80);
  1373. }
  1374. return $exp;
  1375. }
  1376. add_filter('the_excerpt', 'excerpt_length',11);
  1377. /*
  1378. * 后台路径
  1379. */
  1380. /*
  1381. add_filter('site_url', 'wpadmin_filter', 10, 3);
  1382. function wpadmin_filter( $url, $path, $orig_scheme ) {
  1383. $old = array( "/(wp-admin)/");
  1384. $admin_dir = WP_ADMIN_DIR;
  1385. $new = array($admin_dir);
  1386. return preg_replace( $old, $new, $url, 1);
  1387. }
  1388. */
  1389. function admin_ini()
  1390. {
  1391. wp_enqueue_style('admin-styles-fix-icon', get_site_url() . '/wp-includes/css/dashicons.css');
  1392. wp_enqueue_style('cus-styles-fit', get_template_directory_uri() . '/css/dashboard-fix.css');
  1393. }
  1394. add_action('admin_enqueue_scripts', 'admin_ini');
  1395. /*
  1396. * 后台通知
  1397. */
  1398. /**
  1399. * 在提供权限的情况下,为管理员用户显示通知并更新 meta 值
  1400. */
  1401. function theme_admin_notice_callback() {
  1402. // 判断当前用户是否为管理员
  1403. if ( !current_user_can( 'manage_options' ) ) {
  1404. return;
  1405. }
  1406. // 读取 meta 值
  1407. $meta_value = get_user_meta( get_current_user_id(), 'theme_admin_notice', true );
  1408. // 判断 meta 值是否存在
  1409. if ( $meta_value ) {
  1410. return; // 如果存在,退出函数,避免重复加载通知
  1411. }
  1412. // 显示通知
  1413. $theme_name = 'Sakurairo';
  1414. switch ( get_locale() ) {
  1415. case 'zh_CN':
  1416. $thankyou = '感谢你使用 '.$theme_name.' 主题!这里有一些需要你的许可的东西(*/ω\*)';
  1417. $dislike = '不,谢谢';
  1418. $allow_send = '允许发送你的主题版本数据以便官方统计';
  1419. break;
  1420. case 'zh_TW':
  1421. $thankyou = '感謝你使用 '.$theme_name.' 主題!以下是一些需要你許可的內容。';
  1422. $dislike = '謝謝,不用了';
  1423. $allow_send = '允許出於統計目的發送主題版本数据';
  1424. break;
  1425. case 'ja':
  1426. $thankyou = 'ご使用いただきありがとうございます!以下は、あなたの許可が必要なコンテンツです。';
  1427. $dislike = 'いいえ、結構です';
  1428. $allow_send = '統計目的のためにあなたのテーマバージョンを送信することを許可する';
  1429. break;
  1430. default:
  1431. $thankyou = 'Thank you for using the '.$theme_name.' theme! There is something that needs your approval.';
  1432. $dislike = 'No, thanks';
  1433. $allow_send = 'Allow sending your theme version for statistical purposes';
  1434. break;
  1435. }
  1436. ?>
  1437. <div class="notice notice-success" id="send-ver-tip">
  1438. <p><?php echo $thankyou; ?></p>
  1439. <button class="button" onclick="dismiss_notice()"><?php echo $dislike; ?></button>
  1440. <button class="button" onclick="update_option()"><?php echo $allow_send; ?></button>
  1441. </div>
  1442. <script>
  1443. function dismiss_notice() {
  1444. // 隐藏通知
  1445. document.getElementById( "send-ver-tip" ).style.display = "none";
  1446. // 写入 1 到 meta
  1447. var data = new FormData();
  1448. data.append( 'action', 'update_theme_admin_notice_meta' );
  1449. data.append( 'user_id', '<?php echo get_current_user_id(); ?>' );
  1450. data.append( 'meta_key', 'theme_admin_notice' );
  1451. data.append( 'meta_value', '1' );
  1452. fetch( '<?php echo admin_url( 'admin-ajax.php' ); ?>', {
  1453. method: 'POST',
  1454. body: data
  1455. } );
  1456. }
  1457. function update_option() {
  1458. // 隐藏通知
  1459. document.getElementById( "send-ver-tip" ).style.display = "none";
  1460. // 发送 AJAX 请求
  1461. var xhr = new XMLHttpRequest();
  1462. xhr.open( "POST", "<?php echo admin_url( 'admin-ajax.php' ); ?>", true );
  1463. xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
  1464. xhr.send( "action=update_theme_option&option=send_theme_version&value=true" );
  1465. // 写入 1 到 meta
  1466. var data = new FormData();
  1467. data.append( 'action', 'update_theme_admin_notice_meta' );
  1468. data.append( 'user_id', '<?php echo get_current_user_id(); ?>' );
  1469. data.append( 'meta_key', 'theme_admin_notice' );
  1470. data.append( 'meta_value', '1' );
  1471. fetch( '<?php echo admin_url( 'admin-ajax.php' ); ?>', {
  1472. method: 'POST',
  1473. body: data
  1474. } );
  1475. }
  1476. </script>
  1477. <?php
  1478. }
  1479. add_action('admin_notices', 'theme_admin_notice_callback');
  1480. // AJAX 处理函数 - 更新主题选项
  1481. add_action( 'wp_ajax_update_theme_option', 'update_theme_option' );
  1482. function update_theme_option() {
  1483. $option = $_POST['option'];
  1484. $value = sanitize_text_field( $_POST['value'] );
  1485. iro_opt_update( $option, $value );
  1486. wp_die();
  1487. }
  1488. // AJAX 处理函数 - 写入 theme_admin_notice 元值
  1489. add_action( 'wp_ajax_update_theme_admin_notice_meta', 'update_theme_admin_notice_meta' );
  1490. function update_theme_admin_notice_meta() {
  1491. $user_id = $_POST['user_id'];
  1492. $meta_key = $_POST['meta_key'];
  1493. $meta_value = sanitize_text_field( $_POST['meta_value'] );
  1494. update_user_meta( $user_id, $meta_key, $meta_value );
  1495. wp_die();
  1496. }
  1497. //dashboard scheme
  1498. function dash_scheme($key, $name, $col1, $col2, $col3, $col4, $base, $focus, $current, $rules = "")
  1499. {
  1500. $hash = 'rules='. urlencode($rules);
  1501. if($col1){
  1502. $hash .= '&color_1=' . str_replace("#", "", $col1);
  1503. }
  1504. if($col2){
  1505. $hash .= '&color_2=' . str_replace("#", "", $col2);
  1506. }
  1507. if($col3){
  1508. $hash .= '&color_3=' . str_replace("#", "", $col3);
  1509. }
  1510. if($col4){
  1511. $hash .= '&color_4=' . str_replace("#", "", $col4);
  1512. }
  1513. wp_admin_css_color(
  1514. $key,
  1515. $name,
  1516. get_template_directory_uri() . "/inc/dash-scheme.php?" . $hash,
  1517. array($col1, $col2, $col3, $col4),
  1518. array('base' => $base, 'focus' => $focus, 'current' => $current)
  1519. );
  1520. }
  1521. //Sakurairo
  1522. dash_scheme(
  1523. $key = "sakurairo",
  1524. $name = "Sakurairo🌸",
  1525. $col1 = iro_opt('admin_second_class_color'),
  1526. $col2 = iro_opt('admin_first_class_color'),
  1527. $col3 = iro_opt('admin_emphasize_color'),
  1528. $col4 = iro_opt('admin_emphasize_color'),
  1529. $base = "#FFF",
  1530. $focus = "#FFF",
  1531. $current = "#FFF",
  1532. $rules = '#adminmenu .wp-has-current-submenu .wp-submenu a,#adminmenu .wp-has-current-submenu.opensub .wp-submenu a,#adminmenu .wp-submenu a,#adminmenu a.wp-has-current-submenu:focus+.wp-submenu a,#wpadminbar .ab-submenu .ab-item,#wpadminbar .quicklinks .menupop ul li a,#wpadminbar .quicklinks .menupop.hover ul li a,#wpadminbar.nojs .quicklinks .menupop:hover ul li a,.folded #adminmenu .wp-has-current-submenu .wp-submenu a{color:' . iro_opt('admin_text_color') . '}body{background-image:url(' . iro_opt('admin_background') . ');background-attachment:fixed;background-size:cover;}#wpcontent{background:rgba(255,255,255,.0)}.wp-core-ui .button-primary{background:' . iro_opt('admin_button_color') . '!important;border-color:' . iro_opt('admin_button_color') . '!important;color:' . iro_opt('admin_text_color') . '!important;box-shadow:0 1px 0 ' . iro_opt('admin_button_color') . '!important;text-shadow:0 -1px 1px ' . iro_opt('admin_button_color') . ',1px 0 1px ' . iro_opt('admin_button_color') . ',0 1px 1px ' . iro_opt('admin_button_color') . ',-1px 0 1px ' . iro_opt('admin_button_color') . '!important}'
  1533. );
  1534. //Set Default Admin Color Scheme for New Users
  1535. function set_default_admin_color($user_id)
  1536. {
  1537. $args = array(
  1538. 'ID' => $user_id,
  1539. 'admin_color' => 'sunrise',
  1540. );
  1541. wp_update_user($args);
  1542. }
  1543. //add_action('user_register', 'set_default_admin_color');
  1544. //Stop Users From Switching Admin Color Schemes
  1545. //if ( !current_user_can('manage_options') ) remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
  1546. // WordPress Custom style @ Admin
  1547. function custom_admin_open_sans_style()
  1548. {
  1549. require get_template_directory() . '/inc/admin_addcss.php';
  1550. }
  1551. add_action('admin_head', 'custom_admin_open_sans_style');
  1552. // WordPress Custom Font @ Admin
  1553. function custom_admin_open_sans_font()
  1554. {
  1555. echo '<link href="https://' . iro_opt('gfonts_api','fonts.loli.net') . '/css?family=Noto+Serif+SC&display=swap" rel="stylesheet">' . PHP_EOL;
  1556. echo '<style>body, #wpadminbar *:not([class="ab-icon"]), .wp-core-ui, .media-menu, .media-frame *, .media-modal *{font-family: "Noto Serif SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;}</style>' . PHP_EOL;
  1557. }
  1558. add_action('admin_head', 'custom_admin_open_sans_font');
  1559. // WordPress Custom Font @ Admin Frontend Toolbar
  1560. function custom_admin_open_sans_font_frontend_toolbar()
  1561. {
  1562. if (current_user_can('administrator') && is_admin_bar_showing()) {
  1563. echo '<link href="https://' . iro_opt('gfonts_api','fonts.loli.net') . '/css?family=Noto+Serif+SC&display=swap" rel="stylesheet">' . PHP_EOL;
  1564. echo '<style>#wpadminbar *:not([class="ab-icon"]){font-family: "Noto Serif SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;}</style>' . PHP_EOL;
  1565. }
  1566. }
  1567. add_action('wp_head', 'custom_admin_open_sans_font_frontend_toolbar');
  1568. // WordPress Custom Font @ Admin Login
  1569. function custom_admin_open_sans_font_login_page()
  1570. {
  1571. if (stripos($_SERVER["SCRIPT_NAME"], strrchr(wp_login_url(), '/')) !== false) {
  1572. echo '<link href="https://' . iro_opt('gfonts_api','fonts.loli.net') . '/css?family=Noto+Serif+SC&display=swap" rel="stylesheet">' . PHP_EOL;
  1573. echo '<style>body{font-family: "Noto Serif SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;}</style>' . PHP_EOL;
  1574. }
  1575. }
  1576. add_action('login_head', 'custom_admin_open_sans_font_login_page');
  1577. // 阻止垃圾注册
  1578. add_action('register_post', 'codecheese_register_post', 10, 3);
  1579. function codecheese_register_post($sanitized_user_login, $user_email, $errors)
  1580. {
  1581. // Blocked domains
  1582. $domains = array(
  1583. 'net.buzzcluby.com',
  1584. 'buzzcluby.com',
  1585. 'mail.ru',
  1586. 'h.captchaeu.info',
  1587. 'edge.codyting.com'
  1588. );
  1589. // Get visitor email domain
  1590. $email = explode('@', $user_email);
  1591. // Check and display error message for the registration form if exists
  1592. if (in_array($email[1], $domains)) {
  1593. $errors->add('invalid_email', __('<b>ERROR</b>: This email domain (<b>@' . $email[1] . '</b>) has been blocked. Please use another email.'));
  1594. }
  1595. }
  1596. function array_html_props(array $props)
  1597. {
  1598. $props_string = '';
  1599. foreach ($props as $key => $value) {
  1600. $props_string .= ' ' . $key . '="' . $value . '"';
  1601. }
  1602. return $props_string;
  1603. }
  1604. /**
  1605. * 渲染一个懒加载的<img>
  1606. * @author KotoriK
  1607. */
  1608. function lazyload_img(string $src, string $class = '', array $otherParam = array())
  1609. {
  1610. $noscriptParam = $otherParam;
  1611. if ($class) $noscriptParam['class'] = $class;
  1612. $noscriptParam['src'] = $src;
  1613. $otherParam['class'] = 'lazyload' . ($class ? ' ' . $class : '');
  1614. $otherParam['data-src'] = $src;
  1615. $otherParam['onerror'] = 'imgError(this)';
  1616. $otherParam['src'] = iro_opt('page_lazyload_spinner');
  1617. $noscriptProps = '';
  1618. $props = array_html_props($otherParam);
  1619. $noscriptProps = array_html_props($noscriptParam);
  1620. return "<img$props/><noscript><img$noscriptProps/></noscript>";
  1621. }
  1622. // html 标签处理器
  1623. function html_tag_parser($content)
  1624. {
  1625. if (!is_feed()) {
  1626. //图片懒加载标签替换
  1627. if (iro_opt('page_lazyload') && iro_opt('page_lazyload_spinner')) {
  1628. $img_elements = array();
  1629. $is_matched = preg_match_all('/<img[^<]*>/i', $content, $img_elements);
  1630. if ($is_matched) {
  1631. array_walk($img_elements[0], function ($img) use (&$content) {
  1632. $class_found = 0;
  1633. $new_img = preg_replace('/class=[\'"]([^\'"]+)[\'"]/i', 'class="$1 lazyload"', $img, -1, $class_found);
  1634. if ($class_found == 0) {
  1635. $new_img = str_replace('<img ', '<img class="lazyload"', $new_img);
  1636. }
  1637. $new_img = preg_replace('/srcset=[\'"]([^\'"]+)[\'"]/i', 'data-srcset="$1"', $new_img);
  1638. $new_img = preg_replace('/src=[\'"]([^\'"]+)[\'"]/i', 'data-src="$1" src="' . iro_opt('page_lazyload_spinner') . '" onerror="imgError(this)"', $new_img);
  1639. $content = str_replace($img, $new_img . '<noscript>' . $img . '</noscript>', $content);
  1640. });
  1641. }
  1642. }
  1643. //Fancybox
  1644. /* Markdown Regex Pattern for Matching URLs:
  1645. * https://daringfireball.net/2010/07/improved_regex_for_matching_urls
  1646. */
  1647. $url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
  1648. //With Thumbnail: !{alt}(url)[th_url]
  1649. if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
  1650. foreach($matches as $result){
  1651. $content = str_replace(
  1652. $result,
  1653. preg_replace(
  1654. '/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i',
  1655. '<a data-fancybox="gallery"
  1656. data-caption="$1"
  1657. class="fancybox"
  1658. href="$2"
  1659. alt="$1"
  1660. title="$1"><img src="$7" target="_blank" rel="nofollow" class="fancybox"></a>',
  1661. $result
  1662. ),
  1663. $content
  1664. );
  1665. }
  1666. }
  1667. //Without Thumbnail :!{alt}(url)
  1668. $content = preg_replace(
  1669. '/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i',
  1670. '<a data-fancybox="gallery"
  1671. data-caption="$1"
  1672. class="fancybox"
  1673. href="$2"
  1674. alt="$1"
  1675. title="$1"><img src="$2" target="_blank" rel="nofollow" class="fancybox"></a>',
  1676. $content
  1677. );
  1678. }
  1679. //html tag parser for rss
  1680. if (is_feed()) {
  1681. //Fancybox
  1682. $url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))';
  1683. if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) {
  1684. foreach ($matches as $result){
  1685. $content = str_replace(
  1686. $result,
  1687. preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '<a href="$2"><img src="$7" alt="$1" title="$1"></a>', $result),
  1688. $content
  1689. );
  1690. }
  1691. }
  1692. $content = preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i', '<a href="$2"><img src="$2" alt="$1" title="$1"></a>', $content);
  1693. }
  1694. return $content;
  1695. }
  1696. add_filter('the_content', 'html_tag_parser'); //替换文章关键词
  1697. //add_filter( 'comment_text', 'html_tag_parser' );//替换评论关键词
  1698. /*
  1699. * QQ 评论
  1700. */
  1701. // 数据库插入评论表单的qq字段
  1702. add_action('wp_insert_comment', 'sql_insert_qq_field', 10, 2);
  1703. function sql_insert_qq_field($comment_ID, $commmentdata)
  1704. {
  1705. $qq = isset($_POST['new_field_qq']) ? $_POST['new_field_qq'] : false;
  1706. update_comment_meta($comment_ID, 'new_field_qq', $qq); // new_field_qq 是表单name值,也是存储在数据库里的字段名字
  1707. }
  1708. // 后台评论中显示qq字段
  1709. add_filter('manage_edit-comments_columns', 'add_comments_columns');
  1710. add_action('manage_comments_custom_column', 'output_comments_qq_columns', 10, 2);
  1711. function add_comments_columns($columns)
  1712. {
  1713. $columns['new_field_qq'] = __('QQ'); // 新增列名称
  1714. return $columns;
  1715. }
  1716. function output_comments_qq_columns($column_name, $comment_id)
  1717. {
  1718. switch ($column_name) {
  1719. case "new_field_qq":
  1720. // 这是输出值,可以拿来在前端输出,这里已经在钩子manage_comments_custom_column上输出了
  1721. echo get_comment_meta($comment_id, 'new_field_qq', true);
  1722. break;
  1723. }
  1724. }
  1725. /**
  1726. * 头像调用路径
  1727. */
  1728. add_filter('get_avatar', 'change_avatar', 10, 3);
  1729. function change_avatar($avatar)
  1730. {
  1731. global $comment, $sakura_privkey;
  1732. if ($comment && get_comment_meta($comment->comment_ID, 'new_field_qq', true)) {
  1733. $qq_number = get_comment_meta($comment->comment_ID, 'new_field_qq', true);
  1734. if (iro_opt('qq_avatar_link') == 'off') {
  1735. return '<img src="https://q2.qlogo.cn/headimg_dl?dst_uin=' . $qq_number . '&spec=100" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
  1736. }
  1737. if (iro_opt('qq_avatar_link') == 'type_3') {
  1738. $qqavatar = file_get_contents('http://ptlogin2.qq.com/getface?appid=1006102&imgtype=3&uin=' . $qq_number);
  1739. preg_match('/:\"([^\"]*)\"/i', $qqavatar, $matches);
  1740. return '<img src="' . $matches[1] . '" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
  1741. }
  1742. $iv = str_repeat($sakura_privkey, 2);
  1743. $encrypted = openssl_encrypt($qq_number, 'aes-128-cbc', $sakura_privkey, 0, $iv);
  1744. $encrypted = urlencode(base64_encode($encrypted));
  1745. return '<img src="' . rest_url("sakura/v1/qqinfo/avatar") . '?qq=' . $encrypted . '" class="lazyload avatar avatar-24 photo" alt="😀" width="24" height="24" onerror="imgError(this,1)">';
  1746. }
  1747. return $avatar;
  1748. }
  1749. function get_random_url(string $url):string
  1750. {
  1751. $array = parse_url($url);
  1752. if (!isset($array['query'])) {
  1753. // 无参数
  1754. $url .= '?';
  1755. } else {
  1756. // 有参数
  1757. $url .= '&';
  1758. }
  1759. return $url.random_int(1,100);
  1760. }
  1761. // default feature image
  1762. function DEFAULT_FEATURE_IMAGE(string $size='source'):string
  1763. {
  1764. if (iro_opt('post_cover_options') == 'type_2') {
  1765. return get_random_url(iro_opt('post_cover'));
  1766. }
  1767. if (iro_opt('random_graphs_options') == 'external_api'){
  1768. return get_random_url(iro_opt('random_graphs_link'));
  1769. }
  1770. $_api_url = rest_url('sakura/v1/image/feature');
  1771. $rand = rand(1, 100);
  1772. # 拼接符
  1773. $splice = strpos($_api_url, 'index.php?') !== false ? '&' : '?';
  1774. $_api_url = "{$_api_url}{$splice}size={$size}&$rand";
  1775. return $_api_url;
  1776. }
  1777. //评论回复
  1778. function sakura_comment_notify($comment_id)
  1779. {
  1780. if (!isset($_POST['mail-notify'])) {
  1781. update_comment_meta($comment_id, 'mail_notify', 'false');
  1782. }
  1783. }
  1784. add_action('comment_post', 'sakura_comment_notify');
  1785. //侧栏小工具
  1786. if (iro_opt('sakura_widget')) {
  1787. if (function_exists('register_sidebar')) {
  1788. register_sidebar(array(
  1789. 'name' => __('Sidebar'), //侧栏
  1790. 'id' => 'sakura_widget',
  1791. 'before_widget' => '<div class="widget %2$s">',
  1792. 'after_widget' => '</div>',
  1793. 'before_title' => '<div class="title"><h2>',
  1794. 'after_title' => '</h2></div>',
  1795. ));
  1796. }
  1797. }
  1798. // 评论Markdown解析
  1799. function markdown_parser($incoming_comment)
  1800. {
  1801. global $wpdb, $comment_markdown_content;
  1802. $re = '/```([\s\S]*?)```[\s]*|`{1,2}[^`](.*?)`{1,2}|\[.*?\]\([\s\S]*?\)/m';
  1803. if (preg_replace($re, 'temp', $incoming_comment['comment_content']) != strip_tags(preg_replace($re, 'temp', $incoming_comment['comment_content']))) {
  1804. siren_ajax_comment_err('评论只支持Markdown啦,见谅╮( ̄▽ ̄)╭<br>Markdown Supported while <i class="fa-solid fa-code"></i> Forbidden');
  1805. return ($incoming_comment);
  1806. }
  1807. $column_names = $wpdb->get_row("SELECT * FROM information_schema.columns where
  1808. table_name='wp_comments' and column_name = 'comment_markdown' LIMIT 1");
  1809. //Add column if not present.
  1810. if (!isset($column_names)) {
  1811. $wpdb->query("ALTER TABLE wp_comments ADD comment_markdown text");
  1812. }
  1813. $comment_markdown_content = $incoming_comment['comment_content'];
  1814. include 'inc/Parsedown.php';
  1815. $Parsedown = new Parsedown();
  1816. $incoming_comment['comment_content'] = $Parsedown->setUrlsLinked(false)->text($incoming_comment['comment_content']);
  1817. return $incoming_comment;
  1818. }
  1819. add_filter('preprocess_comment', 'markdown_parser');
  1820. remove_filter('comment_text', 'make_clickable', 9);
  1821. //保存Markdown评论
  1822. function save_markdown_comment($comment_ID, $comment_approved)
  1823. {
  1824. global $wpdb, $comment_markdown_content;
  1825. $comment = get_comment($comment_ID);
  1826. $comment_content = $comment_markdown_content;
  1827. //store markdow content
  1828. $wpdb->query("UPDATE wp_comments SET comment_markdown='" . $comment_content . "' WHERE comment_ID='" . $comment_ID . "';");
  1829. }
  1830. add_action('comment_post', 'save_markdown_comment', 10, 2);
  1831. //打开评论HTML标签限制
  1832. function allow_more_tag_in_comment()
  1833. {
  1834. global $allowedtags;
  1835. $allowedtags['pre'] = array('class' => array());
  1836. $allowedtags['code'] = array('class' => array());
  1837. $allowedtags['h1'] = array('class' => array());
  1838. $allowedtags['h2'] = array('class' => array());
  1839. $allowedtags['h3'] = array('class' => array());
  1840. $allowedtags['h4'] = array('class' => array());
  1841. $allowedtags['h5'] = array('class' => array());
  1842. $allowedtags['ul'] = array('class' => array());
  1843. $allowedtags['ol'] = array('class' => array());
  1844. $allowedtags['li'] = array('class' => array());
  1845. $allowedtags['td'] = array('class' => array());
  1846. $allowedtags['th'] = array('class' => array());
  1847. $allowedtags['tr'] = array('class' => array());
  1848. $allowedtags['table'] = array('class' => array());
  1849. $allowedtags['thead'] = array('class' => array());
  1850. $allowedtags['tbody'] = array('class' => array());
  1851. $allowedtags['span'] = array('class' => array());
  1852. }
  1853. add_action('pre_comment_on_post', 'allow_more_tag_in_comment');
  1854. /*
  1855. * 随机图
  1856. */
  1857. function create_sakura_table()
  1858. {
  1859. if (iro_opt('random_graphs_mts')) {
  1860. global $wpdb, $sakura_image_array, $sakura_mobile_image_array, $sakura_privkey;
  1861. } else {
  1862. global $wpdb, $sakura_image_array, $sakura_privkey;
  1863. }
  1864. $sakura_table_name = $wpdb->base_prefix . 'sakurairo';
  1865. require_once ABSPATH . "wp-admin/includes/upgrade.php";
  1866. dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` (
  1867. `mate_key` varchar(50) COLLATE utf8_bin NOT NULL,
  1868. `mate_value` text COLLATE utf8_bin NOT NULL,
  1869. PRIMARY KEY (`mate_key`)
  1870. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;");
  1871. //default data
  1872. if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'")) {
  1873. $manifest = array(
  1874. "mate_key" => "manifest_json",
  1875. "mate_value" => file_get_contents(get_template_directory() . "/manifest/manifest.json"),
  1876. );
  1877. $wpdb->insert($sakura_table_name, $manifest);
  1878. }
  1879. if (iro_opt('random_graphs_mts') && !$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'mobile_manifest_json'")) {
  1880. $mobile_manifest = array(
  1881. "mate_key" => "mobile_manifest_json",
  1882. "mate_value" => file_get_contents(get_template_directory() . "/manifest/manifest_mobile.json"),
  1883. );
  1884. $wpdb->insert($sakura_table_name, $mobile_manifest);
  1885. }
  1886. if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'json_time'")) {
  1887. $time = array(
  1888. "mate_key" => "json_time",
  1889. "mate_value" => date("Y-m-d H:i:s", time()),
  1890. );
  1891. $wpdb->insert($sakura_table_name, $time);
  1892. }
  1893. if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'privkey'")) {
  1894. $privkey = array(
  1895. "mate_key" => "privkey",
  1896. "mate_value" => wp_generate_password(8),
  1897. );
  1898. $wpdb->insert($sakura_table_name, $privkey);
  1899. }
  1900. //reduce sql query
  1901. $sakura_image_array = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='manifest_json'");
  1902. if (iro_opt('random_graphs_mts')) {
  1903. $sakura_mobile_image_array = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='mobile_manifest_json'");
  1904. }
  1905. $sakura_privkey = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='privkey'");
  1906. }
  1907. add_action('after_setup_theme', 'create_sakura_table');
  1908. //rest api支持
  1909. function permalink_tip()
  1910. {
  1911. if (!get_option('permalink_structure')) {
  1912. $msg = __('<b> For a better experience, please do not set <a href="/wp-admin/options-permalink.php"> permalink </a> as plain. To do this, you may need to configure <a href="https://www.wpdaxue.com/wordpress-rewriterule.html" target="_blank"> pseudo-static </a>. </ b>', 'sakurairo'); /*<b>为了更好的使用体验,请不要将<a href="/wp-admin/options-permalink.php">固定链接</a>设置为朴素。为此,您可能需要配置<a href="https://www.wpdaxue.com/wordpress-rewriterule.html" target="_blank">伪静态</a>。</b>*/
  1913. echo '<div class="notice notice-success is-dismissible" id="scheme-tip"><p><b>' . $msg . '</b></p></div>';
  1914. }
  1915. }
  1916. add_action('admin_notices', 'permalink_tip');
  1917. //code end
  1918. //发送主题版本号
  1919. function send_theme_version() {
  1920. $theme = wp_get_theme();
  1921. $version = $theme->get('Version');
  1922. $data = array(
  1923. 'date' => date('Y-m-d H:i:s'),
  1924. 'version' => $version
  1925. );
  1926. $args = array(
  1927. 'body' => $data,
  1928. 'timeout' => '5',
  1929. 'redirection' => '5',
  1930. 'httpversion' => '1.0',
  1931. 'blocking' => true,
  1932. 'headers' => array(),
  1933. 'cookies' => array()
  1934. );
  1935. wp_remote_post('https://api.maho.cc/ver-stat/index.php', $args);
  1936. }
  1937. if (iro_opt('send_theme_version') == '1') {
  1938. if (!wp_next_scheduled('daily_event')) {
  1939. wp_schedule_event(time(), 'daily', 'daily_event');
  1940. }
  1941. add_action('daily_event', 'send_theme_version');
  1942. }
  1943. //解析短代码
  1944. add_shortcode('task', 'task_shortcode');
  1945. function task_shortcode($attr, $content = '')
  1946. {
  1947. $out = '<div class="task shortcodestyle"><i class="fa-solid fa-bars"></i>' . $content . '</div>';
  1948. return $out;
  1949. }
  1950. add_shortcode('warning', 'warning_shortcode');
  1951. function warning_shortcode($attr, $content = '')
  1952. {
  1953. $out = '<div class="warning shortcodestyle"><i class="fa-solid fa-triangle-exclamation"></i>' . $content . '</div>';
  1954. return $out;
  1955. }
  1956. add_shortcode('noway', 'noway_shortcode');
  1957. function noway_shortcode($attr, $content = '')
  1958. {
  1959. $out = '<div class="noway shortcodestyle"><i class="fa-solid fa-rectangle-xmark"></i>' . $content . '</div>';
  1960. return $out;
  1961. }
  1962. add_shortcode('buy', 'buy_shortcode');
  1963. function buy_shortcode($attr, $content = '')
  1964. {
  1965. $out = '<div class="buy shortcodestyle"><i class="fa-solid fa-check-to-slot"></i>' . $content . '</div>';
  1966. return $out;
  1967. }
  1968. add_shortcode('ghcard', 'gh_card');
  1969. function gh_card($attr, $content = '')
  1970. {
  1971. extract(shortcode_atts(array("path" => ""), $attr));
  1972. return '<div class="ghcard"><a href="https://github.com/'. $path .'"><img src="http://github-profile-summary-cards.vercel.app/api'. $content .'" alt="Github-Card"></a></div>';
  1973. }
  1974. add_shortcode('showcard', 'show_card');
  1975. function show_card($attr, $content = '')
  1976. {
  1977. extract(shortcode_atts(array("icon" => "", "title" => "", "img" => "", "color" => ""), $attr));
  1978. return '<section class="showcard">
  1979. <div class="img" alt="Show-Card" style="background:url('. $img .');background-size:cover;background-position: center;">
  1980. <a href="'. $content .'"><button class="showcard-button" style="color:'. $color .' !important;"><i class="fa-solid fa-angle-right"></i></button> </a>
  1981. </div>
  1982. <br>
  1983. <div class="icon">
  1984. <i class="'. $icon .'"></i>
  1985. </div>
  1986. <div class="title">
  1987. '. $title .'
  1988. </div>
  1989. </section>';
  1990. }
  1991. add_shortcode('conversations', 'conversations');
  1992. function conversations($attr, $content = '')
  1993. {
  1994. extract(shortcode_atts(array("avatar" => "", "direction" => ""), $attr));
  1995. $output = '<div class="conversations-code" style="display: flex; flex-direction: ' . $direction . '; padding: 10px;">';
  1996. $output .= '<img src="' . $avatar . '" style="width: 40px; height: 40px; border-radius: 50%;">';
  1997. $output .= '<div class="conversations-code-text">' . $content . '</div>';
  1998. $output .= '</div>';
  1999. return $output;
  2000. }
  2001. //code end
  2002. //WEBP支持
  2003. function mimvp_filter_mime_types($array)
  2004. {
  2005. $array['webp'] = 'image/webp';
  2006. return $array;
  2007. }
  2008. add_filter('mime_types', 'mimvp_filter_mime_types', 10, 1);
  2009. function mimvp_file_is_displayable_image($result, $path)
  2010. {
  2011. $info = @getimagesize($path);
  2012. // if ($info['mime'] == 'image/webp') {
  2013. // $result = true;
  2014. // }
  2015. // return $result;
  2016. return (bool)($info); // 根据文档这里需要返回一个bool
  2017. }
  2018. add_filter('file_is_displayable_image', 'mimvp_file_is_displayable_image', 10, 2);
  2019. //code end
  2020. //展开收缩功能
  2021. function xcollapse($atts, $content = null) {
  2022. $atts = shortcode_atts(array("title" => ""), $atts);
  2023. ob_start(); // 开启输出缓存
  2024. // HTML 结构
  2025. ?>
  2026. <div style="margin: 0.5em 0;">
  2027. <div class="xControl">
  2028. <i class="fa-solid fa-angle-down" style="color: #16AF90;"></i> &nbsp;&nbsp;
  2029. <span class="xTitle"><?= $atts['title'] ?></span>&nbsp;&nbsp;==>&nbsp;&nbsp;<a href="javascript:void(0)" class="collapseButton xButton"><span class="xbtn02"><?php _e('Expand / Collapse', 'sakurairo'); ?></span></a>
  2030. <div style="clear: both;"></div>
  2031. </div>
  2032. <div class="xContent" style="display: none;"><?= do_shortcode($content) ?></div>
  2033. </div>
  2034. <?php
  2035. $output = ob_get_contents(); // 获取输出缓存
  2036. ob_end_clean(); // 清空输出缓存
  2037. return $output; // 返回 HTML 结构
  2038. }
  2039. add_shortcode('collapse', 'xcollapse');
  2040. //code end
  2041. // add_action("wp_ajax_nopriv_getPhoto", "get_photo");
  2042. // add_action("wp_ajax_getPhoto", "get_photo");
  2043. // /**
  2044. // * 相册模板
  2045. // * @author siroi <mrgaopw@hotmail.com>
  2046. // * @return Json
  2047. // */
  2048. // function get_photo()
  2049. // {
  2050. // $postId = $_GET['post'];
  2051. // $page = get_post($postId);
  2052. // if ($page->post_type != "page") {
  2053. // $back['code'] = 201;
  2054. // } else {
  2055. // $back['code'] = 200;
  2056. // $back['imgs'] = array();
  2057. // $dom = new DOMDocument('1.0', 'utf-8');
  2058. // $meta = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
  2059. // $dom->loadHTML($meta . $page->post_content);
  2060. // $imgS = $dom->getElementsByTagName('img');
  2061. // //<img src="..." data-header="标题" data-info="信息" vertical=false>
  2062. // foreach ($imgS as $key => $value) {
  2063. // $attr = $value->attributes;
  2064. // $header = $attr->getNamedItem('header');
  2065. // $info = $attr->getNamedItem('data-info');
  2066. // $vertical = $attr->getNamedItem('vertical');
  2067. // //图片资源地址
  2068. // $temp['img'] = $value->attributes->getNamedItem('src')->nodeValue;
  2069. // //图片上的标题
  2070. // $temp['header'] = $header->nodeValue ?? null;
  2071. // //图片上的信息
  2072. // $temp['info'] = $info->nodeValue ?? null;
  2073. // //是否竖向展示 默认false
  2074. // $temp['vertical'] = $vertical->nodeValue ?? null;
  2075. // array_push($back['imgs'], $temp);
  2076. // }
  2077. // }
  2078. // header('Content-Type:application/json;charset=utf-8');
  2079. // echo json_encode($back);
  2080. // exit();
  2081. // }
  2082. if (!iro_opt('login_language_opt') == '1') {
  2083. add_filter( 'login_display_language_dropdown', '__return_false' );
  2084. }
  2085. if (iro_opt('captcha_select') === 'iro_captcha') {
  2086. function login_CAPTCHA()
  2087. {
  2088. include_once('inc/classes/Captcha.php');
  2089. $img = new Sakura\API\Captcha;
  2090. $test = $img->create_captcha_img();
  2091. echo '<p><label for="captcha" class="captcha">验证码<br><img id="captchaimg" width="120" height="40" src="', $test['data'], '"><input type="text" name="yzm" id="yzm" class="input" value="" size="20" tabindex="4" placeholder="请输入验证码"><input type="hidden" name="timestamp" value="', $test['time'], '"><input type="hidden" name="id" value="', $test['id'], '">'
  2092. . "</label></p>";
  2093. }
  2094. add_action('login_form', 'login_CAPTCHA');
  2095. add_action('register_form', 'login_CAPTCHA');
  2096. add_action('lostpassword_form', 'login_CAPTCHA');
  2097. /**
  2098. * 登录界面验证码验证
  2099. */
  2100. function CAPTCHA_CHECK($user, $username, $password)
  2101. {
  2102. if (empty($_POST)) {
  2103. return new WP_Error();
  2104. }
  2105. if (!(isset($_POST['yzm']) && !empty(trim($_POST['yzm'])))) {
  2106. return new WP_Error('prooffail', '<strong>错误</strong>:验证码为空!');
  2107. }
  2108. if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) {
  2109. return new WP_Error('prooffail', '<strong>错误</strong>:非法数据');
  2110. }
  2111. include_once('inc/classes/Captcha.php');
  2112. $img = new Sakura\API\Captcha;
  2113. $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']);
  2114. if ($check['code'] == 5) {
  2115. return $user;
  2116. }
  2117. return new WP_Error('prooffail', '<strong>错误</strong>:' . $check['msg']);
  2118. //return home_url('/wp-admin/');
  2119. }
  2120. add_filter('authenticate', 'CAPTCHA_CHECK', 20, 3);
  2121. /**
  2122. * 忘记密码界面验证码验证
  2123. */
  2124. function lostpassword_CHECK($errors)
  2125. {
  2126. if (empty($_POST)) {
  2127. return false;
  2128. }
  2129. if (isset($_POST['yzm']) && !empty(trim($_POST['yzm']))) {
  2130. if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) {
  2131. return new WP_Error('prooffail', '<strong>错误</strong>:非法数据');
  2132. }
  2133. include_once('inc/classes/Captcha.php');
  2134. $img = new Sakura\API\Captcha;
  2135. $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']);
  2136. if ($check['code'] != 5) {
  2137. return $errors->add('invalid_department ', '<strong>错误</strong>:' . $check['msg']);
  2138. }
  2139. } else {
  2140. return $errors->add('invalid_department', '<strong>错误</strong>:验证码为空!');
  2141. }
  2142. }
  2143. add_action('lostpassword_post', 'lostpassword_CHECK');
  2144. /**
  2145. * 注册界面验证码验证
  2146. */
  2147. function registration_CAPTCHA_CHECK($errors, $sanitized_user_login, $user_email)
  2148. {
  2149. if (empty($_POST)) {
  2150. return new WP_Error();
  2151. }
  2152. if (!(isset($_POST['yzm']) && !empty(trim($_POST['yzm'])))) {
  2153. return new WP_Error('prooffail', '<strong>错误</strong>:验证码为空!');
  2154. }
  2155. if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) {
  2156. return new WP_Error('prooffail', '<strong>错误</strong>:非法数据');
  2157. }
  2158. include_once('inc/classes/Captcha.php');
  2159. $img = new Sakura\API\Captcha;
  2160. $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']);
  2161. if ($check['code'] == 5) return $errors;
  2162. return new WP_Error('prooffail', '<strong>错误</strong>:' . $check['msg']);
  2163. }
  2164. add_filter('registration_errors', 'registration_CAPTCHA_CHECK', 2, 3);
  2165. } elseif ((iro_opt('captcha_select') === 'vaptcha') && (!empty(iro_opt("vaptcha_vid")) && !empty(iro_opt("vaptcha_key")))) {
  2166. function vaptchaInit()
  2167. {
  2168. include_once('inc/classes/Vaptcha.php');
  2169. $vaptcha = new Sakura\API\Vaptcha;
  2170. echo $vaptcha->html();
  2171. echo $vaptcha->script();
  2172. }
  2173. add_action('login_form', 'vaptchaInit');
  2174. function checkVaptchaAction($user)
  2175. {
  2176. if (empty($_POST)) {
  2177. return new WP_Error();
  2178. }
  2179. if (!(isset($_POST['vaptcha_server']) && isset($_POST['vaptcha_token']))) {
  2180. return new WP_Error('prooffail', '<strong>错误</strong>:请先进行人机验证');
  2181. }
  2182. if (!preg_match('/^https:\/\/([\w-]+\.)+[\w-]*([^<>=?\"\'])*$/', $_POST['vaptcha_server']) || !preg_match('/^[\w\-\$]+$/', $_POST['vaptcha_token'])) {
  2183. return new WP_Error('prooffail', '<strong>错误</strong>:非法数据');
  2184. }
  2185. include_once('inc/classes/Vaptcha.php');
  2186. $url = $_POST['vaptcha_server'];
  2187. $token = $_POST['vaptcha_token'];
  2188. $ip = get_the_user_ip();
  2189. $vaptcha = new Sakura\API\Vaptcha;
  2190. $response = $vaptcha->checkVaptcha($url, $token, $ip);
  2191. if ($response->msg && $response->success && $response->score) {
  2192. if ($response->success === 1 && $response->score >= 70) {
  2193. return $user;
  2194. }
  2195. if ($response->success === 0) {
  2196. $errorcode = $response->msg;
  2197. return new WP_Error('prooffail', '<strong>错误</strong>:' . $errorcode);
  2198. }
  2199. return new WP_Error('prooffail', '<strong>错误</strong>:人机验证失败');
  2200. } else if (is_string($response)) {
  2201. return new WP_Error('prooffail', '<strong>错误</strong>:' . $response);
  2202. }
  2203. return new WP_Error('prooffail', '<strong>错误</strong>:未知错误');
  2204. }
  2205. add_filter('authenticate', 'checkVaptchaAction', 20, 3);
  2206. }
  2207. /**
  2208. * 返回是否应当显示文章标题。
  2209. *
  2210. */
  2211. function should_show_title():bool{
  2212. $id = get_the_ID();
  2213. $use_as_thumb = get_post_meta($id, 'use_as_thumb', true); //'true','only',(default)
  2214. return !iro_opt('patternimg')
  2215. || !get_post_thumbnail_id($id)
  2216. && $use_as_thumb != 'true' && !get_post_meta($id, 'video_cover', true);
  2217. }
  2218. /**
  2219. * 修复 WordPress 搜索结果为空,返回为 200 的问题。
  2220. * @author ivampiresp <im@ivampiresp.com>
  2221. */
  2222. function search_404_fix_template_redirect()
  2223. {
  2224. if (is_search()) {
  2225. global $wp_query;
  2226. if ($wp_query->found_posts == 0) {
  2227. status_header(404);
  2228. }
  2229. }
  2230. }
  2231. add_action('template_redirect', 'search_404_fix_template_redirect');
  2232. // 给上传图片增加时间戳
  2233. add_filter('wp_handle_upload_prefilter', function($file){
  2234. $file['name'] = time().'-'.$file['name'];
  2235. return $file;
  2236. });