functions.php 87 KB

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