get('Version')); define('INT_VERSION', '17.1.0A'); define('BUILD_VERSION', '2'); //Option-Framework require get_template_directory() . '/opt/option-framework.php'; if (!function_exists('iro_opt')) { $GLOBALS['iro_options'] = get_option('iro_options'); function iro_opt($option = '', $default = null) { return $GLOBALS['iro_options'][$option] ?? $default; } } $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); $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); //Update-Checker require 'update-checker/update-checker.php'; function UpdateCheck($url,$flag = 'Sakurairo'){ return Puc_v4_Factory::buildUpdateChecker( $url, __FILE__, $flag ); } switch(iro_opt('iro_update_source')){ case 'github': $iroThemeUpdateChecker = UpdateCheck('https://github.com/mirai-mamori/Sakurairo','unique-plugin-or-theme-slug'); break; case 'upyun': $iroThemeUpdateChecker = UpdateCheck('https://update.maho.cc/jsdelivr.json'); break; case 'official_building': $iroThemeUpdateChecker = UpdateCheck('https://update.maho.cc/'.iro_opt('iro_update_channel').'/check.json'); } //ini_set('display_errors', true); //error_reporting(E_ALL); error_reporting(E_ALL & ~E_NOTICE); if (!function_exists('akina_setup')) { function akina_setup() { /* * Make theme available for translation. * Translations can be filed in the /languages/ directory. * If you're building a theme based on Akina, use a find and replace * to change 'akina' to the name of your theme in all the template files. */ load_theme_textdomain('sakurairo', get_template_directory() . '/languages'); /* * Enable support for Post Thumbnails on posts and pages. * * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support('post-thumbnails'); set_post_thumbnail_size(150, 150, true); // This theme uses wp_nav_menu() in one location. register_nav_menus(array( 'primary' => __('Nav Menus', 'sakurairo'), //导航菜单 )); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support('html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', )); /* * Enable support for Post Formats. * See https://developer.wordpress.org/themes/functionality/post-formats/ */ add_theme_support('post-formats', array( 'aside', 'image', 'status', )); // Set up the WordPress core custom background feature. add_theme_support('custom-background', apply_filters('akina_custom_background_args', array( 'default-color' => 'ffffff', 'default-image' => '', ))); /** * 废弃过时的wp_title * @seealso https://make.wordpress.org/core/2015/10/20/document-title-in-4-4/ */ add_theme_support( 'title-tag' ); add_filter('pre_option_link_manager_enabled', '__return_true'); // 优化代码 //去除头部冗余代码 remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'start_post_rel_link', 10, 0); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'wp_generator'); //隐藏wordpress版本 remove_filter('the_content', 'wptexturize'); //取消标点符号转义 //remove_action('rest_api_init', 'wp_oembed_register_route'); //remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4); //remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); //remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4); //remove_action('wp_head', 'wp_oembed_add_discovery_links'); //remove_action('wp_head', 'wp_oembed_add_host_js'); remove_action('template_redirect', 'rest_output_link_header', 11, 0); function coolwp_remove_open_sans_from_wp_core() { wp_deregister_style('open-sans'); wp_register_style('open-sans', false); wp_enqueue_style('open-sans', ''); } add_action('init', 'coolwp_remove_open_sans_from_wp_core'); if (!function_exists('disable_emojis')) { /** * Disable the emoji's * @see https://wordpress.org/plugins/disable-emojis/ */ function disable_emojis() { remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); add_filter('tiny_mce_plugins', 'disable_emojis_tinymce'); } add_action('init', 'disable_emojis'); } if (!function_exists('disable_emojis_tinymce')) { /** * Filter function used to remove the tinymce emoji plugin. * * @param array $plugins * @return array Difference betwen the two arrays */ function disable_emojis_tinymce($plugins) { if (is_array($plugins)) { return array_diff($plugins, array('wpemoji')); } else { return array(); } } } // 移除菜单冗余代码 add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); function my_css_attributes_filter($var) { return is_array($var) ? array_intersect($var, array('current-menu-item', 'current-post-ancestor', 'current-menu-ancestor', 'current-menu-parent')) : ''; } } }; add_action('after_setup_theme', 'akina_setup'); //说说页面 function shuoshuo_custom_init() { $labels = array( 'name' => __("Ideas", "sakurairo"), 'singular_name' => __("Idea", "sakurairo"), 'add_new' => __("Publish New Idea", "sakurairo"), 'add_new_item' => __("Publish New Idea", "sakurairo"), 'edit_item' => __("Edit Idea", "sakurairo"), 'new_item' => __("New Idea", "sakurairo"), 'view_item' => __("View Idea", "sakurairo"), 'search_items' => __("Search Idea", "sakurairo"), 'not_found' => __("Not Found Idea", "sakurairo"), 'not_found_in_trash' => __("No Idea in the Trash", "sakurairo"), 'parent_item_colon' => '', 'menu_name' => __("Ideas", "sakurairo") ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'author' ) ); register_post_type('shuoshuo', $args); } add_action('init', 'shuoshuo_custom_init'); function admin_lettering() { echo ''; } add_action('admin_head', 'admin_lettering'); /** * Set the content width in pixels, based on the theme's design and stylesheet. * * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function akina_content_width() { $GLOBALS['content_width'] = apply_filters('akina_content_width', 640); } add_action('after_setup_theme', 'akina_content_width', 0); /** * Enqueue scripts and styles. */ function sakura_scripts() { global $core_lib_basepath; global $shared_lib_basepath; if (iro_opt('smoothscroll_option')) { wp_enqueue_script('SmoothScroll', $shared_lib_basepath. '/js/smoothscroll.js', array(), IRO_VERSION . iro_opt('cookie_version', ''), true); } wp_enqueue_style('saukra-css', $core_lib_basepath.'/style.css', array(), IRO_VERSION); if (!is_home()){ //非主页的资源 wp_enqueue_style('entry-content', $core_lib_basepath.'/css/theme/'.(iro_opt('entry_content_style') == 'sakurairo' ?'sakura' : 'github').'.css', array(), IRO_VERSION); wp_enqueue_script('app-page', $core_lib_basepath . '/js/page.js', array('app','polyfills'), IRO_VERSION, true); } wp_enqueue_script('app', $core_lib_basepath . '/js/app.js', array('polyfills'), IRO_VERSION, true); wp_enqueue_script('polyfills', $core_lib_basepath . '/js/polyfills.js', array(), IRO_VERSION, true); if (is_singular() && comments_open() && get_option('thread_comments')) { wp_enqueue_script('comment-reply'); } //前端脚本本地化 if (get_locale() != 'zh_CN') { wp_localize_script('app', '_sakurairoi18n', array( '复制成功!' => __("Copied!", 'sakurairo'), '拷贝代码' => __("Copy Code", 'sakurairo'), '你的封面API好像不支持跨域调用,这种情况下缓存是不会生效的哦' => __("Your cover API seems to not support Cross Origin Access. In this case, Cover Cache won't take effect.", 'sakurairo'), '提交中....' => __('Commiting....', 'sakurairo'), '提交成功' => __('Succeed', 'sakurairo'), '每次上传上限为10张' => __('10 files max per request', 'sakurairo'), "图片上传大小限制为5 MB\n\n「{0}」\n\n这张图太大啦~请重新上传噢!" => __("5 MB max per file.\n\n「{0}」\n\nThis image is too large~Please reupload!", 'sakurairo'), '上传中...' => __('Uploading...', 'sakurairo'), '图片上传成功~' => __('Uploaded successfully~', 'sakurairo'), "上传失败!\n文件名=> {0}\ncode=> {1}\n{2}" => __("Upload failed!\nFile Name=> {0}\ncode=> {1}\n{2}", 'sakurairo'), '上传失败,请重试.' => __('Upload failed, please retry.', 'sakurairo'), '页面加载出错了 HTTP {0}' => __("Page Load failed. HTTP {0}", 'sakurairo'), '很高兴你翻到这里,但是真的没有了...' => __("Glad you come, but we've got nothing left.", 'sakurairo'), "文章" => __("Post", 'sakurairo'), "标签" => __("Tag", 'sakurairo'), "分类" => __("Category", 'sakurairo'), "页面" => __("Page", 'sakurairo'), "评论" => __("Comment", 'sakurairo'), "已暂停..." => __("Paused...", 'sakurairo'), "正在载入视频 ..." => __("Loading Video...", 'sakurairo'), "将从网络加载字体,流量请注意" => __("Downloading fonts, be aware of your data usage.", 'sakurairo'), "您真的要设为私密吗?" => __("Are you sure you want set it private?", 'sakurairo'), "您之前已设过私密评论" => __("You had set private comment before", 'sakurairo') )); } } add_action('wp_enqueue_scripts', 'sakura_scripts'); /** * load .php. */ require get_template_directory() . '/inc/decorate.php'; require get_template_directory() . '/inc/swicher.php'; require get_template_directory() . '/inc/api.php'; /** * Custom template tags for this theme. */ require get_template_directory() . '/inc/template-tags.php'; /** * Customizer additions. */ require get_template_directory() . '/inc/customizer.php'; /** * function update */ require get_template_directory() . '/inc/theme_plus.php'; require get_template_directory() . '/inc/categories-images.php'; //Comment Location Start function convertip($ip) { if (empty($ip)) $ip = get_comment_author_IP(); $ch = curl_init(); $timeout = 5; if (iro_opt('ipsource') === 'type_1') { $url = 'https://api.nmxc.ltd/ip/' . $ip; } else { $url = 'https://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip=' . $ip; } $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt ($ch, CURLOPT_URL, 'http://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip='.$ip); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $file_contents = curl_exec($ch); curl_close($ch); $result = null; $result = json_decode($file_contents, true); if ($result && $result['code'] == 0) { if ($result['data']['country'] != '中国') { return $result['data']['country']; } else { return $result['data']['country'] . ' · ' . $result['data']['region'] . ' · ' . $result['data']['city'] . ' · ' . $result['data']['isp']; } } else { return "未知"; } } //Comment Location End /** * COMMENT FORMATTING * * 标准的 lazyload 输出头像 * comment_author_email, '80', '', get_comment_author(), array( 'class' => array( 'lazyload' ) ) ) ); ?> * * 如果不延时是这样的 * comment_author_email, '80', '', get_comment_author() ); ?> * */ if (!function_exists('akina_comment_format')) { function akina_comment_format($comment, $args, $depth) { $GLOBALS['comment'] = $comment; ?>
  • id="comment-">
    $depth, 'max_depth' => $args['max_depth']))); ?>
    comment_agent); ?>comment_agent); ?> : comment_ID; $i_private = get_comment_meta($comment_ID, '_private', true); $flag = null; $flag .= ' ' . __("Private", "sakurairo") . ': '; if (!empty($i_private)) { $flag .= __("Yes", "sakurairo") . ' '; } else { $flag .= __("No", "sakurairo") . ' '; } $flag .= ''; $flag .= edit_comment_link(' ' . __("Edit", "mashiro"), ' ', ''); echo $flag; } ?>

    get_results( "SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' " )); $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))))); echo ""; } /** * post views */ function restyle_text($number) { switch (iro_opt('statistics_format')) { case "type_2": //23,333 次访问 return number_format($number); case "type_3": //23 333 次访问 return number_format($number, 0, '.', ' '); case "type_4": //23k 次访问 if ($number >= 1000) { return round($number / 1000, 2) . 'k'; } else { return $number; } default: return $number; } } function set_post_views() { if (is_singular()) { global $post; $post_id = intval($post->ID); if ($post_id) { $views = (int) get_post_meta($post_id, 'views', true); if (!update_post_meta($post_id, 'views', ($views + 1))) { add_post_meta($post_id, 'views', 1, true); } } } } add_action('get_header', 'set_post_views'); function get_post_views($post_id) { if (iro_opt('statistics_api') == 'wp_statistics') { if (!function_exists('wp_statistics_pages')) { return __('Please install pulgin WP-Statistics', 'sakurairo'); } else { return restyle_text(wp_statistics_pages('total', 'uri', $post_id)); } } else { $views = get_post_meta($post_id, 'views', true); if ($views == '') { return 0; } else { return restyle_text($views); } } } function is_webp(): bool { return (isset($_COOKIE['su_webp']) || (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'image/webp'))); } /* * 友情链接 */ function get_the_link_items($id = null) { $bookmarks = get_bookmarks('orderby=date&category=' . $id); $output = ''; if (!empty($bookmarks)) { $output .= ''; } return $output; } function get_link_items() { $linkcats = get_terms('link_category'); $result = null; if (!empty($linkcats)) { foreach ($linkcats as $linkcat) { $result .= ''; if ($linkcat->description) { $result .= ''; } $result .= get_the_link_items($linkcat->term_id); } } else { $result = get_the_link_items(); } return $result; } /* * Gravatar头像使用中国服务器 */ function gravatar_cn(string $url):string { $gravatar_url = array('0.gravatar.com/avatar', '1.gravatar.com/avatar', '2.gravatar.com/avatar', 'secure.gravatar.com/avatar'); return str_replace($gravatar_url, iro_opt('gravatar_proxy'), $url); } if (iro_opt('gravatar_proxy')) { add_filter('get_avatar_url', 'gravatar_cn', 4); } /* * 自定义默认头像 */ add_filter('avatar_defaults', 'mytheme_default_avatar'); function mytheme_default_avatar($avatar_defaults) { //$new_avatar_url = get_template_directory_uri() . '/images/default_avatar.png'; $new_avatar_url = 'https://cn.gravatar.com/avatar/b745710ae6b0ce9dfb13f5b7c0956be1'; $avatar_defaults[$new_avatar_url] = 'Default Avatar'; return $avatar_defaults; } /* * 阻止站内文章互相Pingback */ function theme_noself_ping(&$links) { $home = get_option('home'); foreach ($links as $l => $link) { if (0 === strpos($link, $home)) { unset($links[$l]); } } } add_action('pre_ping', 'theme_noself_ping'); /* * 订制body类 */ function akina_body_classes($classes) { // Adds a class of group-blog to blogs with more than 1 published author. if (is_multi_author()) { $classes[] = 'group-blog'; } // Adds a class of hfeed to non-singular pages. if (!is_singular()) { $classes[] = 'hfeed'; } // 定制中文字体class $classes[] = 'chinese-font'; /*if(!wp_is_mobile()) { $classes[] = 'serif'; }*/ if (isset($_COOKIE['dark' . iro_opt('cookie_version', '')])) { $classes[] = $_COOKIE['dark' . iro_opt('cookie_version', '')] == '1' ? 'dark' : ' '; } else { $classes[] = ' '; } return $classes; } add_filter('body_class', 'akina_body_classes'); /* * 图片CDN */ add_filter('upload_dir', 'wpjam_custom_upload_dir'); function wpjam_custom_upload_dir($uploads) { $upload_path = ''; $upload_url_path = iro_opt('image_cdn'); if (empty($upload_path) || 'wp-content/uploads' == $upload_path) { $uploads['basedir'] = WP_CONTENT_DIR . '/uploads'; } elseif (0 !== strpos($upload_path, ABSPATH)) { $uploads['basedir'] = path_join(ABSPATH, $upload_path); } else { $uploads['basedir'] = $upload_path; } $uploads['path'] = $uploads['basedir'] . $uploads['subdir']; if ($upload_url_path) { $uploads['baseurl'] = $upload_url_path; $uploads['url'] = $uploads['baseurl'] . $uploads['subdir']; } return $uploads; } /* * 删除自带小工具 */ function unregister_default_widgets() { unregister_widget('WP_Widget_Pages'); unregister_widget('WP_Widget_Calendar'); unregister_widget('WP_Widget_Archives'); unregister_widget('WP_Widget_Links'); unregister_widget('WP_Widget_Meta'); unregister_widget('WP_Widget_Search'); //unregister_widget('WP_Widget_Text'); unregister_widget('WP_Widget_Categories'); unregister_widget('WP_Widget_Recent_Posts'); //unregister_widget('WP_Widget_Recent_Comments'); //unregister_widget('WP_Widget_RSS'); //unregister_widget('WP_Widget_Tag_Cloud'); unregister_widget('WP_Nav_Menu_Widget'); } add_action("widgets_init", "unregister_default_widgets", 11); /** * Jetpack setup function. * * See: https://jetpack.com/support/infinite-scroll/ * See: https://jetpack.com/support/responsive-videos/ */ function akina_jetpack_setup() { // Add theme support for Infinite Scroll. add_theme_support('infinite-scroll', array( 'container' => 'main', 'render' => 'akina_infinite_scroll_render', 'footer' => 'page', )); // Add theme support for Responsive Videos. add_theme_support('jetpack-responsive-videos'); } add_action('after_setup_theme', 'akina_jetpack_setup'); /** * Custom render function for Infinite Scroll. */ function akina_infinite_scroll_render() { while (have_posts()) { the_post(); get_template_part('tpl/content', is_search() ? 'search' : get_post_format()); } } /* * 编辑器增强 */ function enable_more_buttons($buttons) { $buttons[] = 'hr'; $buttons[] = 'del'; $buttons[] = 'sub'; $buttons[] = 'sup'; $buttons[] = 'fontselect'; $buttons[] = 'fontsizeselect'; $buttons[] = 'cleanup'; $buttons[] = 'styleselect'; $buttons[] = 'wp_page'; $buttons[] = 'anchor'; $buttons[] = 'backcolor'; return $buttons; } add_filter("mce_buttons_3", "enable_more_buttons"); // 下载按钮 function download($atts, $content = null) { return ' Download'; } add_shortcode("download", "download"); add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce'); function bolo_after_wp_tiny_mce($mce_settings) { ?> '."\n"; echo '' . "\n"; //echo ''."\n"; } add_action('login_head', 'custom_login'); //Login Page Title function custom_headertitle($title) { return get_bloginfo('name'); } add_filter('login_headertext', 'custom_headertitle'); //Login Page Link function custom_loginlogo_url($url) { return esc_url(home_url('/')); } add_filter('login_headerurl', 'custom_loginlogo_url'); //Login Page Footer function custom_html() { $loginbg = iro_opt('login_background') ?: iro_opt('vision_resource_basepath','https://s.nmxc.ltd/sakurairo_vision/@2.5/').'series/login_background.webp'; ?> You may try 3 times for every 5 minutes!

    '; } else { return $message; } } //add_filter( 'login_message', 'smallenvelop_login_message' ); //Fix password reset bug function resetpassword_message_fix($message) { $message = str_replace('<', '', $message); $message = str_replace('>', '', $message); return $message; } add_filter('retrieve_password_message', 'resetpassword_message_fix'); //Fix register email bug function new_user_message_fix($message) { $show_register_ip = '注册IP | Registration IP: ' . get_the_user_ip() . ' (' . convertip(get_the_user_ip()) . ")\r\n\r\n如非本人操作请忽略此邮件 | Please ignore this email if this was not your operation.\r\n\r\n"; $message = str_replace('To set your password, visit the following address:', $show_register_ip . '在此设置密码 | To set your password, visit the following address:', $message); $message = str_replace('<', '', $message); $message = str_replace('>', "\r\n\r\n设置密码后在此登录 | Login here after setting password: ", $message); return $message; } add_filter('wp_new_user_notification_email', 'new_user_message_fix'); /* * 评论邮件回复 */ function comment_mail_notify($comment_id) { $mail_user_name = iro_opt('mail_user_name') ? iro_opt('mail_user_name') : 'poi'; $comment = get_comment($comment_id); $parent_id = $comment->comment_parent ?: ''; $spam_confirmed = $comment->comment_approved; $mail_notify = iro_opt('mail_notify') ? get_comment_meta($parent_id, 'mail_notify', false) : false; $admin_notify = iro_opt('admin_notify') ? '1' : ((isset(get_comment($parent_id)->comment_author_email) && get_comment($parent_id)->comment_author_email) != get_bloginfo('admin_email') ? '1' : '0'); if (($parent_id != '') && ($spam_confirmed != 'spam') && ($admin_notify != '0') && (!$mail_notify)) { $wp_email = $mail_user_name . '@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); $to = trim(get_comment($parent_id)->comment_author_email); $subject = '你在 [' . get_option("blogname") . '] 的留言有了回应'; $message = '

    Dear ' . trim(get_comment($parent_id)->comment_author) . '


    您有一条来自' . get_option("blogname") . '的回复


    您在文章《' . get_the_title($comment->comment_post_ID) . '》上发表的评论:

    ' . trim(get_comment($parent_id)->comment_content) . '

    ' . trim($comment->comment_author) . ' 给您的回复如下:

    ' . trim($comment->comment_content) . '
    hr 点击查看回复的完整內容

    本邮件为系统自动发出,请勿直接回复
    © ' . date('Y') . ' ' . get_option("blogname") . '

    '; $message = convert_smilies($message); $message = str_replace('{{', 'emoji', $message); $message = str_replace('{UPLOAD}', 'https://i.loli.net/', $message); $message = str_replace('[/img][img]', '[/img^img]', $message); $message = str_replace('[img]', '', $message); $message = str_replace('[/img^img]', '" style="width:80%;display: block;margin-left: auto;margin-right: auto;">"; $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; wp_mail($to, $subject, $message, $headers); } } add_action('comment_post', 'comment_mail_notify'); /* * 链接新窗口打开 */ function rt_add_link_target($content) { $content = str_replace(' tag to split into segments $bits = explode(' $bit) { // fix the target="_blank" bug after the link if (strpos($bit, 'href') === false) { continue; } // fix the target="_blank" bug in the codeblock if (strpos(preg_replace('/code([\s\S]*?)\/code[\s]*/m', 'temp', $content), $bit) === false) { continue; } // find the end of each link $pos = strpos($bit, '>'); // check if there is an end (only fails with malformed markup) if ($pos !== false) { // get a string with just the link's attibutes $part = substr($bit, 0, $pos); // for comparison, get the current site/network url $siteurl = network_site_url(); // if the site url is in the attributes, assume it's in the href and skip, also if a target is present if (strpos($part, $siteurl) === false && strpos($part, 'target=') === false) { // add the target attribute $bits[$key] = 'target="_blank" ' . $bits[$key]; } } } // re-assemble the content, and return it return implode('
    ', $content); $content = str_replace('[/img^img]', '" class="lazyload comment_inline_img" onerror="imgError(this)">'; // 正文转换 $wpsmiliestrans['::' . $tieba_Name . '::'] = ''; } return $return_smiles; } push_tieba_smilies(); function tieba_smile_filter($content) { global $wpsmiliestrans; $content = str_replace(array_keys($wpsmiliestrans), $wpsmiliestrans, $content); return $content; } add_filter('the_content', 'tieba_smile_filter'); //替换文章关键词 add_filter('comment_text', 'tieba_smile_filter'); //替换评论关键词 function push_emoji_panel() { return '
    (⌒▽⌒) ( ̄▽ ̄) (=・ω・=) (`・ω・´) (〜 ̄△ ̄)〜 (・∀・) (°∀°)ノ ( ̄3 ̄) ╮( ̄▽ ̄)╭ (´_ゝ`) ←_← →_→ (<_<) (>_>) (;¬_¬) ("▔□▔)/ (゚Д゚≡゚д゚)!? Σ(゚д゚;) Σ( ̄□ ̄||) (’;ω;‘) (/TДT)/ (^・ω・^ ) (。・ω・。) (● ̄(エ) ̄●) ε=ε=(ノ≧∇≦)ノ (’・_・‘) (-_-#) ( ̄へ ̄) ( ̄ε(# ̄)Σ ヽ(‘Д’)ノ (#-_-)┯━┯ (╯°口°)╯(┴—┴ ←◡← ( ♥д♥) _(:3」∠)_ Σ>―(〃°ω°〃)♡→ ⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄ (╬゚д゚)▄︻┻┳═一 ・*・:≡( ε:) (笑) (汗) (泣) (苦笑) '; } // bilibili smiles $bilismiliestrans = array(); function push_bili_smilies() { global $bilismiliestrans; $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'); $return_smiles = ''; $type = is_webp() ? 'webp' : 'png'; $biliimgdir = 'bili' . $type . '/'; $smiliesgs = '.' . $type; foreach ($name as $smilies_Name) { // 选择面版 $return_smiles = $return_smiles . ''; // 正文转换 $bilismiliestrans['{{' . $smilies_Name . '}}'] = ''; } return $return_smiles; } push_bili_smilies(); function bili_smile_filter($content) { global $bilismiliestrans; $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content); return $content; } add_filter('the_content', 'bili_smile_filter'); //替换文章关键词 add_filter('comment_text', 'bili_smile_filter'); //替换评论关键词 function featuredtoRSS($content) { global $post; if (has_post_thumbnail($post->ID)) { $content = '
    ' . get_the_post_thumbnail($post->ID, 'medium', array('style' => 'margin-bottom: 15px;')) . '
    ' . $content; } return $content; } add_filter('the_excerpt_rss', 'featuredtoRSS'); add_filter('the_content_feed', 'featuredtoRSS'); // function bili_smile_filter_rss($content) { $type = is_webp() ? 'webp' : 'png'; $biliimgdir = 'bili' . $type . '/'; $smiliesgs = '.' . $type; $content = str_replace('{{', 'emoji', $content); $content = str_replace('[img]', '', $content); return $content; } add_filter('comment_text_rss', 'bili_smile_filter_rss'); //替换评论rss关键词 function toc_support($content) { $content = str_replace('[toc]', '
    ', $content); // TOC 支持 $content = str_replace('[begin]', '', $content); // 首字格式支持 $content = str_replace('[/begin]', '', $content); // 首字格式支持 return $content; } add_filter('the_content', 'toc_support'); add_filter('the_excerpt_rss', 'toc_support'); add_filter('the_content_feed', 'toc_support'); // 显示访客当前 IP function get_the_user_ip() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } // 简略版 // $ip = $_SERVER['HTTP_CLIENT_IP'] ?: ($_SERVER['HTTP_X_FORWARDED_FOR'] ?: $_SERVER['REMOTE_ADDR']); return apply_filters('wpb_get_ip', $ip); } add_shortcode('show_ip', 'get_the_user_ip'); /*歌词*/ function hero_get_lyric() { /** These are the lyrics to Hero */ $lyrics = ""; // Here we split it into lines $lyrics = explode("\n", $lyrics); // And then randomly choose a line return wptexturize($lyrics[mt_rand(0, count($lyrics) - 1)]); } // This just echoes the chosen line, we'll position it later function hello_hero() { $chosen = hero_get_lyric(); echo $chosen; } /*私密评论*/ add_action('wp_ajax_nopriv_siren_private', 'siren_private'); add_action('wp_ajax_siren_private', 'siren_private'); function siren_private() { $comment_id = $_POST["p_id"]; $action = $_POST["p_action"]; if ($action == 'set_private') { update_comment_meta($comment_id, '_private', 'true'); $i_private = get_comment_meta($comment_ID, '_private', true); echo !empty($i_private) ? '否' : '是'; } die; } //时间序列 function memory_archives_list() { // 始终为true, 为什么要这么做呢 if (true) { $output = '

    [' . __("All expand/collapse", "sakurairo") /*全部展开/收缩*/ . ']

    '; $the_query = new WP_Query('posts_per_page=-1&ignore_sticky_posts=1&post_type=post'); //update: 加上忽略置顶文章 $year = 0; $mon = 0; $i = 0; $j = 0; while ($the_query->have_posts()) : $the_query->the_post(); $year_tmp = get_the_time('Y'); $mon_tmp = get_the_time('m'); $y = $year; $m = $mon; if ($mon != $mon_tmp && $mon > 0) { $output .= '
  • '; } if ($year != $year_tmp && $year > 0) { $output .= ''; } if ($year != $year_tmp) { $year = $year_tmp; $output .= '

    ' . $year . __(" ", "year", "sakurairo") . /*年*/ '

    '; #update_option('memory_archives_list', $output); } echo $output; } /* * 隐藏 Dashboard */ /* Remove the "Dashboard" from the admin menu for non-admin users */ function remove_dashboard() { global $current_user, $menu, $submenu; wp_get_current_user(); if (!in_array('administrator', $current_user->roles)) { reset($menu); $page = key($menu); while ((__('Dashboard') != $menu[$page][0]) && next($menu)) { $page = key($menu); } if (__('Dashboard') == $menu[$page][0]) { unset($menu[$page]); } reset($menu); $page = key($menu); while (!$current_user->has_cap($menu[$page][1]) && next($menu)) { $page = key($menu); } if ( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) && ('index.php' != $menu[$page][2]) ) { wp_redirect(get_option('siteurl') . '/wp-admin/profile.php'); } } } add_action('admin_menu', 'remove_dashboard'); /** * Filter the except length to 20 words. 限制摘要长度 * * @param int $length Excerpt length. * @return int (Maybe) modified excerpt length. */ function GBsubstr($string, $start, $length) { if (strlen($string) > $length) { $str = null; $len = 0; $i = $start; while ($len < $length) { if (ord(substr($string, $i, 1)) > 0xc0) { $str .= substr($string, $i, 3); $i += 3; } elseif (ord(substr($string, $i, 1)) > 0xa0) { $str .= substr($string, $i, 2); $i += 2; } else { $str .= substr($string, $i, 1); $i++; } $len++; } return $str; } else { return $string; } } function excerpt_length($exp) { if (!function_exists('mb_substr')) { $exp = GBsubstr($exp, 0, 80); } else { /* * To use mb_substr() function, you should uncomment "extension=php_mbstring.dll" in php.ini */ $exp = mb_substr($exp, 0, 80); } return $exp; } add_filter('the_excerpt', 'excerpt_length'); /* * 后台路径 */ /* add_filter('site_url', 'wpadmin_filter', 10, 3); function wpadmin_filter( $url, $path, $orig_scheme ) { $old = array( "/(wp-admin)/"); $admin_dir = WP_ADMIN_DIR; $new = array($admin_dir); return preg_replace( $old, $new, $url, 1); } */ function admin_ini() { wp_enqueue_style('admin-styles-fix-icon', get_site_url() . '/wp-includes/css/dashicons.css'); wp_enqueue_style('cus-styles-fit', get_template_directory_uri() . '/css/dashboard-fix.css'); wp_enqueue_script('lazyload', get_template_directory_uri() . '/js/lazyload.min.js'); } add_action('admin_enqueue_scripts', 'admin_ini'); function custom_admin_js() { echo ''; } add_action('admin_footer', 'custom_admin_js'); /* * 后台通知 */ function scheme_tip() { switch(get_user_locale(get_current_user_id())){ case 'zh_CN': $msg = '试一试新后台界面配色方案吧?'; break; case 'zh_TW': $msg = '試一試新後台界面色彩配置吧?'; break; case 'ja-JP': $msg = '新しい管理画面の配色を試しますか?'; break; default: $msg = 'Why not try the new admin dashboard color scheme here?'; } $user_id = get_current_user_id(); if (!get_user_meta($user_id, 'scheme-tip-dismissed' . BUILD_VERSION)) { echo '

    ' . $msg . '

    '; } } add_action('admin_notices', 'scheme_tip'); function scheme_tip_dismissed() { $user_id = get_current_user_id(); if (isset($_GET['scheme-tip-dismissed' . BUILD_VERSION])) { add_user_meta($user_id, 'scheme-tip-dismissed' . BUILD_VERSION, 'true', true); } } add_action('admin_init', 'scheme_tip_dismissed'); //dashboard scheme function dash_scheme($key, $name, $col1, $col2, $col3, $col4, $base, $focus, $current, $rules = "") { $hash = "color_1=" . str_replace("#", "", $col1) . "&color_2=" . str_replace("#", "", $col2) . "&color_3=" . str_replace("#", "", $col3) . "&color_4=" . str_replace("#", "", $col4) . "&rules=" . urlencode($rules); wp_admin_css_color( $key, $name, get_template_directory_uri() . "/inc/dash-scheme.php?" . $hash, array($col1, $col2, $col3, $col4), array('base' => $base, 'focus' => $focus, 'current' => $current) ); } //Sakurairo dash_scheme( $key = "sakurairo", $name = "Sakurairo🌸", $col1 = iro_opt('admin_second_class_color'), $col2 = iro_opt('admin_first_class_color'), $col3 = iro_opt('admin_emphasize_color'), $col4 = iro_opt('admin_emphasize_color'), $base = "#FFF", $focus = "#FFF", $current = "#FFF", $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}' ); //Set Default Admin Color Scheme for New Users function set_default_admin_color($user_id) { $args = array( 'ID' => $user_id, 'admin_color' => 'sunrise', ); wp_update_user($args); } //add_action('user_register', 'set_default_admin_color'); //Stop Users From Switching Admin Color Schemes //if ( !current_user_can('manage_options') ) remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' ); // WordPress Custom style @ Admin function custom_admin_open_sans_style() { require get_template_directory() . '/inc/admin_addcss.php'; } add_action('admin_head', 'custom_admin_open_sans_style'); // WordPress Custom Font @ Admin function custom_admin_open_sans_font() { echo '' . PHP_EOL; echo '' . PHP_EOL; } add_action('admin_head', 'custom_admin_open_sans_font'); // WordPress Custom Font @ Admin Frontend Toolbar function custom_admin_open_sans_font_frontend_toolbar() { if (current_user_can('administrator') && is_admin_bar_showing()) { echo '' . PHP_EOL; echo '' . PHP_EOL; } } add_action('wp_head', 'custom_admin_open_sans_font_frontend_toolbar'); // WordPress Custom Font @ Admin Login function custom_admin_open_sans_font_login_page() { if (stripos($_SERVER["SCRIPT_NAME"], strrchr(wp_login_url(), '/')) !== false) { echo '' . PHP_EOL; echo '' . PHP_EOL; } } add_action('login_head', 'custom_admin_open_sans_font_login_page'); // 阻止垃圾注册 add_action('register_post', 'codecheese_register_post', 10, 3); function codecheese_register_post($sanitized_user_login, $user_email, $errors) { // Blocked domains $domains = array( 'net.buzzcluby.com', 'buzzcluby.com', 'mail.ru', 'h.captchaeu.info', 'edge.codyting.com' ); // Get visitor email domain $email = explode('@', $user_email); // Check and display error message for the registration form if exists if (in_array($email[1], $domains)) { $errors->add('invalid_email', __('ERROR: This email domain (@' . $email[1] . ') has been blocked. Please use another email.')); } } function array_html_props(array $props) { $props_string = ''; foreach ($props as $key => $value) { $props_string .= ' ' . $key . '="' . $value . '"'; } return $props_string; } /** * 渲染一个懒加载的 * @author KotoriK */ function lazyload_img(string $src, string $class = '', array $otherParam = array()) { $noscriptParam = $otherParam; if ($class) $noscriptParam['class'] = $class; $noscriptParam['src'] = $src; $otherParam['class'] = 'lazyload' . ($class ? ' ' . $class : ''); $otherParam['data-src'] = $src; $otherParam['onerror'] = 'imgError(this)'; $otherParam['src'] = iro_opt('page_lazyload_spinner'); $noscriptProps = ''; $props = array_html_props($otherParam); $noscriptProps = array_html_props($noscriptParam); return ""; } // html 标签处理器 function html_tag_parser($content) { if (!is_feed()) { //图片懒加载标签替换 if (iro_opt('page_lazyload') && iro_opt('page_lazyload_spinner')) { $img_elements = array(); $is_matched = preg_match_all('//i', $content, $img_elements); if ($is_matched) { array_walk($img_elements[0], function ($img) use (&$content) { $class_found = 0; $new_img = preg_replace('/class=[\'"]([^\'"]+)[\'"]/i', 'class="$1 lazyload"', $img, -1, $class_found); if ($class_found == 0) { $new_img = str_replace('' . $img . '', $content); }); } } //Fancybox /* Markdown Regex Pattern for Matching URLs: * https://daringfireball.net/2010/07/improved_regex_for_matching_urls */ $url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'; //With Thumbnail: !{alt}(url)[th_url] if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) { foreach($matches as $result){ $content = str_replace( $result, preg_replace( '/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '', $result ), $content ); } } //Without Thumbnail :!{alt}(url) $content = preg_replace( '/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i', '', $content ); } //html tag parser for rss if (is_feed()) { //Fancybox $url_regex = '((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))'; if (preg_match_all('/\!\{.*?\)\[.*?\]/i', $content, $matches)) { foreach ($matches as $result){ $content = str_replace( $result, preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)\[' . $url_regex . '\]/i', '$1', $result), $content ); } } $content = preg_replace('/!\{([^\{\}]+)*\}\(' . $url_regex . '\)/i', '$1', $content); } return $content; } add_filter('the_content', 'html_tag_parser'); //替换文章关键词 //add_filter( 'comment_text', 'html_tag_parser' );//替换评论关键词 /* * QQ 评论 */ // 数据库插入评论表单的qq字段 add_action('wp_insert_comment', 'sql_insert_qq_field', 10, 2); function sql_insert_qq_field($comment_ID, $commmentdata) { $qq = isset($_POST['new_field_qq']) ? $_POST['new_field_qq'] : false; update_comment_meta($comment_ID, 'new_field_qq', $qq); // new_field_qq 是表单name值,也是存储在数据库里的字段名字 } // 后台评论中显示qq字段 add_filter('manage_edit-comments_columns', 'add_comments_columns'); add_action('manage_comments_custom_column', 'output_comments_qq_columns', 10, 2); function add_comments_columns($columns) { $columns['new_field_qq'] = __('QQ'); // 新增列名称 return $columns; } function output_comments_qq_columns($column_name, $comment_id) { switch ($column_name) { case "new_field_qq": // 这是输出值,可以拿来在前端输出,这里已经在钩子manage_comments_custom_column上输出了 echo get_comment_meta($comment_id, 'new_field_qq', true); break; } } /** * 头像调用路径 */ add_filter('get_avatar', 'change_avatar', 10, 3); function change_avatar($avatar) { global $comment, $sakura_privkey; if ($comment && get_comment_meta($comment->comment_ID, 'new_field_qq', true)) { $qq_number = get_comment_meta($comment->comment_ID, 'new_field_qq', true); if (iro_opt('qq_avatar_link') == 'off') { return '😀'; } elseif (iro_opt('qq_avatar_link') == 'type_3') { $qqavatar = file_get_contents('http://ptlogin2.qq.com/getface?appid=1006102&imgtype=3&uin=' . $qq_number); preg_match('/:\"([^\"]*)\"/i', $qqavatar, $matches); return '😀'; } else { $iv = str_repeat($sakura_privkey, 2); $encrypted = openssl_encrypt($qq_number, 'aes-128-cbc', $sakura_privkey, 0, $iv); $encrypted = urlencode(base64_encode($encrypted)); return '😀'; } } return $avatar; } // default feature image function DEFAULT_FEATURE_IMAGE(string $size='source'):string { if (iro_opt('post_cover_options') == 'type_2') { return iro_opt('post_cover').'?'.rand(1,100); } if (iro_opt('random_graphs_options') == 'external_api'){ return iro_opt('random_graphs_link').'?'.rand(1,100); } $_api_url = rest_url('sakura/v1/image/feature'); $rand = rand(1, 100); if (strpos($_api_url, 'index.php?') !== false) { $_api_url = "{$_api_url}&size={$size}&$rand"; }else{ $_api_url = "{$_api_url}?size={$size}&$rand"; } return $_api_url; } //评论回复 function sakura_comment_notify($comment_id) { if (!isset($_POST['mail-notify'])) { update_comment_meta($comment_id, 'mail_notify', 'false'); } } add_action('comment_post', 'sakura_comment_notify'); //侧栏小工具 if (iro_opt('sakura_widget')) { if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => __('Sidebar'), //侧栏 'id' => 'sakura_widget', 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', 'after_title' => '

    ', )); } } // 评论Markdown解析 function markdown_parser($incoming_comment) { global $wpdb, $comment_markdown_content; $re = '/```([\s\S]*?)```[\s]*|`{1,2}[^`](.*?)`{1,2}|\[.*?\]\([\s\S]*?\)/m'; if (preg_replace($re, 'temp', $incoming_comment['comment_content']) != strip_tags(preg_replace($re, 'temp', $incoming_comment['comment_content']))) { siren_ajax_comment_err('评论只支持Markdown啦,见谅╮( ̄▽ ̄)╭
    Markdown Supported while Forbidden'); return ($incoming_comment); } $column_names = $wpdb->get_row("SELECT * FROM information_schema.columns where table_name='wp_comments' and column_name = 'comment_markdown' LIMIT 1"); //Add column if not present. if (!isset($column_names)) { $wpdb->query("ALTER TABLE wp_comments ADD comment_markdown text"); } $comment_markdown_content = $incoming_comment['comment_content']; include 'inc/Parsedown.php'; $Parsedown = new Parsedown(); $incoming_comment['comment_content'] = $Parsedown->setUrlsLinked(false)->text($incoming_comment['comment_content']); return $incoming_comment; } add_filter('preprocess_comment', 'markdown_parser'); remove_filter('comment_text', 'make_clickable', 9); //保存Markdown评论 function save_markdown_comment($comment_ID, $comment_approved) { global $wpdb, $comment_markdown_content; $comment = get_comment($comment_ID); $comment_content = $comment_markdown_content; //store markdow content $wpdb->query("UPDATE wp_comments SET comment_markdown='" . $comment_content . "' WHERE comment_ID='" . $comment_ID . "';"); } add_action('comment_post', 'save_markdown_comment', 10, 2); //打开评论HTML标签限制 function allow_more_tag_in_comment() { global $allowedtags; $allowedtags['pre'] = array('class' => array()); $allowedtags['code'] = array('class' => array()); $allowedtags['h1'] = array('class' => array()); $allowedtags['h2'] = array('class' => array()); $allowedtags['h3'] = array('class' => array()); $allowedtags['h4'] = array('class' => array()); $allowedtags['h5'] = array('class' => array()); $allowedtags['ul'] = array('class' => array()); $allowedtags['ol'] = array('class' => array()); $allowedtags['li'] = array('class' => array()); $allowedtags['td'] = array('class' => array()); $allowedtags['th'] = array('class' => array()); $allowedtags['tr'] = array('class' => array()); $allowedtags['table'] = array('class' => array()); $allowedtags['thead'] = array('class' => array()); $allowedtags['tbody'] = array('class' => array()); $allowedtags['span'] = array('class' => array()); } add_action('pre_comment_on_post', 'allow_more_tag_in_comment'); /* * 随机图 */ function create_sakura_table() { if (iro_opt('random_graphs_mts')) { global $wpdb, $sakura_image_array, $sakura_mobile_image_array, $sakura_privkey; } else { global $wpdb, $sakura_image_array, $sakura_privkey; } $sakura_table_name = $wpdb->base_prefix . 'sakurairo'; require_once ABSPATH . "wp-admin/includes/upgrade.php"; dbDelta("CREATE TABLE IF NOT EXISTS `" . $sakura_table_name . "` ( `mate_key` varchar(50) COLLATE utf8_bin NOT NULL, `mate_value` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`mate_key`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=1 ;"); //default data if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'manifest_json'")) { $manifest = array( "mate_key" => "manifest_json", "mate_value" => file_get_contents(get_template_directory() . "/manifest/manifest.json"), ); $wpdb->insert($sakura_table_name, $manifest); } if (iro_opt('random_graphs_mts')) { if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'mobile_manifest_json'")) { $mobile_manifest = array( "mate_key" => "mobile_manifest_json", "mate_value" => file_get_contents(get_template_directory() . "/manifest/manifest_mobile.json"), ); $wpdb->insert($sakura_table_name, $mobile_manifest); } } if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'json_time'")) { $time = array( "mate_key" => "json_time", "mate_value" => date("Y-m-d H:i:s", time()), ); $wpdb->insert($sakura_table_name, $time); } if (!$wpdb->get_var("SELECT COUNT(*) FROM $sakura_table_name WHERE mate_key = 'privkey'")) { $privkey = array( "mate_key" => "privkey", "mate_value" => wp_generate_password(8), ); $wpdb->insert($sakura_table_name, $privkey); } //reduce sql query $sakura_image_array = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='manifest_json'"); if (iro_opt('random_graphs_mts')) { $sakura_mobile_image_array = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='mobile_manifest_json'"); } $sakura_privkey = $wpdb->get_var("SELECT `mate_value` FROM $sakura_table_name WHERE `mate_key`='privkey'"); } add_action('after_setup_theme', 'create_sakura_table'); //rest api支持 function permalink_tip() { if (!get_option('permalink_structure')) { $msg = __(' For a better experience, please do not set permalink as plain. To do this, you may need to configure pseudo-static . ', 'sakurairo'); /*为了更好的使用体验,请不要将固定链接设置为朴素。为此,您可能需要配置伪静态*/ echo '

    ' . $msg . '

    '; } } add_action('admin_notices', 'permalink_tip'); //code end //解析短代码 add_shortcode('task', 'task_shortcode'); function task_shortcode($attr, $content = '') { $out = '
    ' . $content . '
    '; return $out; } add_shortcode('warning', 'warning_shortcode'); function warning_shortcode($attr, $content = '') { $out = '
    ' . $content . '
    '; return $out; } add_shortcode('noway', 'noway_shortcode'); function noway_shortcode($attr, $content = '') { $out = '
    ' . $content . '
    '; return $out; } add_shortcode('buy', 'buy_shortcode'); function buy_shortcode($attr, $content = '') { $out = '
    ' . $content . '
    '; return $out; } //code end //WEBP支持 function mimvp_filter_mime_types($array) { $array['webp'] = 'image/webp'; return $array; } add_filter('mime_types', 'mimvp_filter_mime_types', 10, 1); function mimvp_file_is_displayable_image($result, $path) { $info = @getimagesize($path); if ($info['mime'] == 'image/webp') { $result = true; } return $result; } add_filter('file_is_displayable_image', 'mimvp_file_is_displayable_image', 10, 2); //code end //展开收缩功能 function xcollapse($atts, $content = null) { extract(shortcode_atts(array("title" => ""), $atts)); return '
       ' . $title . '  ==>  展开 / 收缩
    '; } add_shortcode('collapse', 'xcollapse'); //code end add_action("wp_ajax_nopriv_getPhoto", "get_photo"); add_action("wp_ajax_getPhoto", "get_photo"); /** * 相册模板 * @author siroi * @return Json */ function get_photo() { $postId = $_GET['post']; $page = get_post($postId); if ($page->post_type != "page") { $back['code'] = 201; } else { $back['code'] = 200; $back['imgs'] = array(); $dom = new DOMDocument('1.0', 'utf-8'); $meta = ''; $dom->loadHTML($meta . $page->post_content); $imgS = $dom->getElementsByTagName('img'); // foreach ($imgS as $key => $value) { $attr = $value->attributes; $header = $attr->getNamedItem('header'); $info = $attr->getNamedItem('data-info'); $vertical = $attr->getNamedItem('vertical'); //图片资源地址 $temp['img'] = $value->attributes->getNamedItem('src')->nodeValue; //图片上的标题 $temp['header'] = $header->nodeValue ?? null; //图片上的信息 $temp['info'] = $info->nodeValue ?? null; //是否竖向展示 默认false $temp['vertical'] = $vertical->nodeValue ?? null; array_push($back['imgs'], $temp); } } header('Content-Type:application/json;charset=utf-8'); echo json_encode($back); exit(); } if (!iro_opt('login_language_opt') == '1') { add_filter( 'login_display_language_dropdown', '__return_false' ); } if (iro_opt('captcha_select') === 'iro_captcha') { function login_CAPTCHA() { include_once('inc/classes/Captcha.php'); $img = new Sakura\API\Captcha; $test = $img->create_captcha_img(); echo '

    "; } add_action('login_form', 'login_CAPTCHA'); add_action('register_form', 'login_CAPTCHA'); add_action('lostpassword_form', 'login_CAPTCHA'); /** * 登录界面验证码验证 */ function CAPTCHA_CHECK($user, $username, $password) { if (empty($_POST)) { return new WP_Error(); } if (isset($_POST['yzm']) && !empty(trim($_POST['yzm']))) { if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) { return new WP_Error('prooffail', '错误:非法数据'); } include_once('inc/classes/Captcha.php'); $img = new Sakura\API\Captcha; $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']); if ($check['code'] == 5) { return $user; } else { return new WP_Error('prooffail', '错误:' . $check['msg']); //return home_url('/wp-admin/'); } } else { return new WP_Error('prooffail', '错误:验证码为空!'); } } add_filter('authenticate', 'CAPTCHA_CHECK', 20, 3); /** * 忘记密码界面验证码验证 */ function lostpassword_CHECK($errors) { if (empty($_POST)) { return false; } if (isset($_POST['yzm']) && !empty(trim($_POST['yzm']))) { if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) { return new WP_Error('prooffail', '错误:非法数据'); } include_once('inc/classes/Captcha.php'); $img = new Sakura\API\Captcha; $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']); if ($check['code'] != 5) { return $errors->add('invalid_department ', '错误:' . $check['msg']); } } else { return $errors->add('invalid_department', '错误:验证码为空!'); } } add_action('lostpassword_post', 'lostpassword_CHECK'); /** * 注册界面验证码验证 */ function registration_CAPTCHA_CHECK($errors, $sanitized_user_login, $user_email) { if (empty($_POST)) { return new WP_Error(); } if (isset($_POST['yzm']) && !empty(trim($_POST['yzm']))) { if (!isset($_POST['timestamp']) || !isset($_POST['id']) || !preg_match('/^[\w$.\/]+$/', $_POST['id']) || !ctype_digit($_POST['timestamp'])) { return new WP_Error('prooffail', '错误:非法数据'); } include_once('inc/classes/Captcha.php'); $img = new Sakura\API\Captcha; $check = $img->check_captcha($_POST['yzm'], $_POST['timestamp'], $_POST['id']); if ($check['code'] == 5) { return $errors; } else { return new WP_Error('prooffail', '错误:' . $check['msg']); } } else { return new WP_Error('prooffail', '错误:验证码为空!'); } } add_filter('registration_errors', 'registration_CAPTCHA_CHECK', 2, 3); } elseif (iro_opt('captcha_select') === 'vaptcha') { function vaptchaInit() { include_once('inc/classes/Vaptcha.php'); $vaptcha = new Sakura\API\Vaptcha; echo $vaptcha->html(); echo $vaptcha->script(); } add_action('login_form', 'vaptchaInit'); function checkVaptchaAction($user) { if (empty($_POST)) { return new WP_Error(); } if (isset($_POST['vaptcha_server']) && isset($_POST['vaptcha_token'])) { if (!preg_match('/^https:\/\/([\w-]+\.)+[\w-]*([^<>=?\"\'])*$/', $_POST['vaptcha_server']) || !preg_match('/^[\w\-\$]+$/', $_POST['vaptcha_token'])) { return new WP_Error('prooffail', '错误:非法数据'); } include_once('inc/classes/Vaptcha.php'); $url = $_POST['vaptcha_server']; $token = $_POST['vaptcha_token']; $ip = get_the_user_ip(); $vaptcha = new Sakura\API\Vaptcha; $response = $vaptcha->checkVaptcha($url, $token, $ip); if ($response->msg && $response->success && $response->score) { if ($response->success === 1 && $response->score >= 70) { return $user; } else if ($response->success === 0) { $errorcode = $response->msg; return new WP_Error('prooffail', '错误:' . $errorcode); } else { return new WP_Error('prooffail', '错误:人机验证失败'); } } else if (is_string($response)) { return new WP_Error('prooffail', '错误:' . $response); } else { return new WP_Error('prooffail', '错误:未知错误'); } } else { return new WP_Error('prooffail', '错误:请先进行人机验证'); } } add_filter('authenticate', 'checkVaptchaAction', 20, 3); } /** * 返回是否应当显示文章标题。 * */ function should_show_title():bool{ $id = get_the_ID(); $use_as_thumb = get_post_meta($id, 'use_as_thumb', true); //'true','only',(default) return !iro_opt('patternimg') || !get_post_thumbnail_id($id) && $use_as_thumb != 'true' && !get_post_meta($id, 'video_cover', true); }