From b419dcc8cae4e293d3ac43b8ae2ba7710e935ed5 Mon Sep 17 00:00:00 2001
From: mashiro
Date: Fri, 27 Dec 2019 10:01:04 +0800
Subject: [PATCH] perf: some enhancement
---
functions.php | 1838 ++++++++++++++++++++++++++-----------------------
1 file changed, 980 insertions(+), 858 deletions(-)
diff --git a/functions.php b/functions.php
index 7be24a7..17a602b 100644
--- a/functions.php
+++ b/functions.php
@@ -6,15 +6,15 @@
*
* @package Sakura
*/
-
-define( 'SAKURA_VERSION', wp_get_theme()->get('Version') );
-define( 'BUILD_VERSION', '3' );
+
+define('SAKURA_VERSION', wp_get_theme()->get('Version'));
+define('BUILD_VERSION', '3');
//ini_set('display_errors', true);
-//error_reporting(E_ALL);
+//error_reporting(E_ALL);
error_reporting(E_ALL ^ E_NOTICE);
-if ( !function_exists( 'akina_setup' ) ) :
+if (!function_exists('akina_setup')):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
@@ -22,134 +22,139 @@ if ( !function_exists( 'akina_setup' ) ) :
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
-
-if ( !function_exists( 'optionsframework_init' ) ) {
- define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
- require_once dirname( __FILE__ ) . '/inc/options-framework.php';
-}
-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( 'sakura', get_template_directory() . '/languages' );
+ if (!function_exists('optionsframework_init')) {
+ define('OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/');
+ require_once dirname(__FILE__) . '/inc/options-framework.php';
+ }
+ 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('sakura', 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 );
+ /*
+ * 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', 'sakura' ), //导航菜单
- ) );
+ // This theme uses wp_nav_menu() in one location.
+ register_nav_menus(array(
+ 'primary' => __('Nav Menus', 'sakura'), //导航菜单
+ ));
- /*
- * 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',
- ) );
+ /*
+ * 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',
- ) );
+ /*
+ * 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' => '',
- ) ) );
-
- 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' );
-
- /**
- * Disable the emoji's
- */
- 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' );
-
- /**
- * 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')) : '';
- }
-
-}
+ // 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' => '',
+ )));
+
+ 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');
+
+ /**
+ * Disable the emoji's
+ */
+ 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');
+
+ /**
+ * 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')) : '';
+ }
+
+ }
endif;
-add_action( 'after_setup_theme', 'akina_setup' );
+add_action('after_setup_theme', 'akina_setup');
-function admin_lettering(){
- echo'';
+function admin_lettering()
+{
+ echo '';
}
add_action('admin_head', 'admin_lettering');
@@ -160,61 +165,66 @@ add_action('admin_head', 'admin_lettering');
*
* @global int $content_width
*/
-function akina_content_width() {
- $GLOBALS['content_width'] = apply_filters( 'akina_content_width', 640 );
+function akina_content_width()
+{
+ $GLOBALS['content_width'] = apply_filters('akina_content_width', 640);
}
-add_action( 'after_setup_theme', 'akina_content_width', 0 );
+add_action('after_setup_theme', 'akina_content_width', 0);
/**
* Enqueue scripts and styles.
*/
-function sakura_scripts() {
- if(akina_option('jsdelivr_cdn_test')){
- wp_enqueue_script( 'js_lib', get_template_directory_uri() . '/cdn/js/lib.js', array(), SAKURA_VERSION.akina_option('cookie_version', ''), true );
- } else {
- wp_enqueue_script( 'js_lib', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/cdn/js/lib.min.js', array(), SAKURA_VERSION, true );
+function sakura_scripts()
+{
+ if (akina_option('jsdelivr_cdn_test')) {
+ wp_enqueue_script('js_lib', get_template_directory_uri() . '/cdn/js/lib.js', array(), SAKURA_VERSION . akina_option('cookie_version', ''), true);
+ } else {
+ wp_enqueue_script('js_lib', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/cdn/js/lib.min.js', array(), SAKURA_VERSION, true);
}
if (akina_option('app_no_jsdelivr_cdn')) {
- wp_enqueue_style( 'saukra_css', get_stylesheet_uri(), array(), SAKURA_VERSION );
- wp_enqueue_script( 'app', get_template_directory_uri() . '/js/sakura-app.js', array(), SAKURA_VERSION, true );
+ wp_enqueue_style('saukra_css', get_stylesheet_uri(), array(), SAKURA_VERSION);
+ wp_enqueue_script('app', get_template_directory_uri() . '/js/sakura-app.js', array(), SAKURA_VERSION, true);
} else {
- wp_enqueue_style( 'saukra_css', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/style.min.css', array(), SAKURA_VERSION );
- wp_enqueue_script( 'app', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/js/sakura-app.min.js', array(), SAKURA_VERSION, true );
- }
- wp_enqueue_script( 'github_card', 'https://cdn.jsdelivr.net/github-cards/latest/widget.js', array(), SAKURA_VERSION, true );
-
- if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
+ wp_enqueue_style('saukra_css', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/style.min.css', array(), SAKURA_VERSION);
+ wp_enqueue_script('app', 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@' . SAKURA_VERSION . '/js/sakura-app.min.js', array(), SAKURA_VERSION, true);
+ }
+ wp_enqueue_script('github_card', 'https://cdn.jsdelivr.net/github-cards/latest/widget.js', array(), SAKURA_VERSION, true);
- // 20161116 @Louie
- $mv_live = akina_option('focus_mvlive') ? 'open' : 'close';
- $movies = akina_option('focus_amv') ? array('url' => akina_option('amv_url'), 'name' => akina_option('amv_title'), 'live' => $mv_live) : 'close';
- $auto_height = akina_option('focus_height') ? 'fixed' : 'auto';
- $code_lamp = 'close';
- if(wp_is_mobile()) $auto_height = 'fixed'; //拦截移动端
- version_compare( $GLOBALS['wp_version'], '5.1', '>=' ) ? $reply_link_version = 'new' : $reply_link_version = 'old';
- wp_localize_script( 'app', 'Poi' , array(
- 'pjax' => akina_option('poi_pjax'),
- 'movies' => $movies,
- 'windowheight' => $auto_height,
- 'codelamp' => $code_lamp,
- 'ajaxurl' => admin_url('admin-ajax.php'),
- 'order' => get_option('comment_order'), // ajax comments
- 'formpostion' => 'bottom', // ajax comments 默认为bottom,如果你的表单在顶部则设置为top。
+ if (is_singular() && comments_open() && get_option('thread_comments')) {
+ wp_enqueue_script('comment-reply');
+ }
+
+ // 20161116 @Louie
+ $mv_live = akina_option('focus_mvlive') ? 'open' : 'close';
+ $movies = akina_option('focus_amv') ? array('url' => akina_option('amv_url'), 'name' => akina_option('amv_title'), 'live' => $mv_live) : 'close';
+ $auto_height = akina_option('focus_height') ? 'fixed' : 'auto';
+ $code_lamp = 'close';
+ if (wp_is_mobile()) {
+ $auto_height = 'fixed';
+ }
+ //拦截移动端
+ version_compare($GLOBALS['wp_version'], '5.1', '>=') ? $reply_link_version = 'new' : $reply_link_version = 'old';
+ wp_localize_script('app', 'Poi', array(
+ 'pjax' => akina_option('poi_pjax'),
+ 'movies' => $movies,
+ 'windowheight' => $auto_height,
+ 'codelamp' => $code_lamp,
+ 'ajaxurl' => admin_url('admin-ajax.php'),
+ 'order' => get_option('comment_order'), // ajax comments
+ 'formpostion' => 'bottom', // ajax comments 默认为bottom,如果你的表单在顶部则设置为top。
'reply_link_version' => $reply_link_version,
- 'api' => esc_url_raw( rest_url() ),
- 'nonce' => wp_create_nonce( 'wp_rest' )
- ));
+ 'api' => esc_url_raw(rest_url()),
+ 'nonce' => wp_create_nonce('wp_rest'),
+ ));
}
-add_action( 'wp_enqueue_scripts', 'sakura_scripts' );
+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';
+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.
@@ -233,10 +243,11 @@ require get_template_directory() . '/inc/theme_plus.php';
require get_template_directory() . '/inc/categories-images.php';
//Comment Location Start
-function convertip($ip) {
+function convertip($ip)
+{
error_reporting(E_ALL ^ E_NOTICE);
- $dat_path = dirname(__FILE__).'/inc/QQWry.Dat';
- if(!$fd = @fopen($dat_path, 'rb')){
+ $dat_path = dirname(__FILE__) . '/inc/QQWry.Dat';
+ if (!$fd = @fopen($dat_path, 'rb')) {
return 'IP date file not exists or access denied';
}
$ip = explode('.', $ip);
@@ -244,42 +255,54 @@ function convertip($ip) {
$DataBegin = fread($fd, 4);
$DataEnd = fread($fd, 4);
$ipbegin = implode('', unpack('L', $DataBegin));
- if($ipbegin < 0) $ipbegin += pow(2, 32);
+ if ($ipbegin < 0) {
+ $ipbegin += pow(2, 32);
+ }
+
$ipend = implode('', unpack('L', $DataEnd));
- if($ipend < 0) $ipend += pow(2, 32);
+ if ($ipend < 0) {
+ $ipend += pow(2, 32);
+ }
+
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = 0;
$EndNum = $ipAllNum;
- while($ip1num>$ipNum || $ip2num<$ipNum) {
- $Middle= intval(($EndNum + $BeginNum) / 2);
+ while ($ip1num > $ipNum || $ip2num < $ipNum) {
+ $Middle = intval(($EndNum + $BeginNum) / 2);
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
- if(strlen($ipData1) < 4) {
+ if (strlen($ipData1) < 4) {
fclose($fd);
return 'System Error';
}
$ip1num = implode('', unpack('L', $ipData1));
- if($ip1num < 0) $ip1num += pow(2, 32);
- if($ip1num > $ipNum) {
+ if ($ip1num < 0) {
+ $ip1num += pow(2, 32);
+ }
+
+ if ($ip1num > $ipNum) {
$EndNum = $Middle;
continue;
}
$DataSeek = fread($fd, 3);
- if(strlen($DataSeek) < 3) {
+ if (strlen($DataSeek) < 3) {
fclose($fd);
return 'System Error';
}
- $DataSeek = implode('', unpack('L', $DataSeek.chr(0)));
+ $DataSeek = implode('', unpack('L', $DataSeek . chr(0)));
fseek($fd, $DataSeek);
$ipData2 = fread($fd, 4);
- if(strlen($ipData2) < 4) {
+ if (strlen($ipData2) < 4) {
fclose($fd);
return 'System Error';
}
$ip2num = implode('', unpack('L', $ipData2));
- if($ip2num < 0) $ip2num += pow(2, 32);
- if($ip2num < $ipNum) {
- if($Middle == $BeginNum) {
+ if ($ip2num < 0) {
+ $ip2num += pow(2, 32);
+ }
+
+ if ($ip2num < $ipNum) {
+ if ($Middle == $BeginNum) {
fclose($fd);
return 'Unknown';
}
@@ -287,78 +310,85 @@ function convertip($ip) {
}
}
$ipFlag = fread($fd, 1);
- if($ipFlag == chr(1)) {
+ if ($ipFlag == chr(1)) {
$ipSeek = fread($fd, 3);
- if(strlen($ipSeek) < 3) {
+ if (strlen($ipSeek) < 3) {
fclose($fd);
return 'System Error';
}
- $ipSeek = implode('', unpack('L', $ipSeek.chr(0)));
+ $ipSeek = implode('', unpack('L', $ipSeek . chr(0)));
fseek($fd, $ipSeek);
$ipFlag = fread($fd, 1);
}
- if($ipFlag == chr(2)) {
+ if ($ipFlag == chr(2)) {
$AddrSeek = fread($fd, 3);
- if(strlen($AddrSeek) < 3) {
+ if (strlen($AddrSeek) < 3) {
fclose($fd);
return 'System Error';
}
$ipFlag = fread($fd, 1);
- if($ipFlag == chr(2)) {
+ if ($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
- if(strlen($AddrSeek2) < 3) {
+ if (strlen($AddrSeek2) < 3) {
fclose($fd);
return 'System Error';
}
- $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
+ $AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
- while(($char = fread($fd, 1)) != chr(0))
- $ipAddr2 .= $char;
- $AddrSeek = implode('', unpack('L', $AddrSeek.chr(0)));
+ while (($char = fread($fd, 1)) != chr(0)) {
+ $ipAddr2 .= $char;
+ }
+
+ $AddrSeek = implode('', unpack('L', $AddrSeek . chr(0)));
fseek($fd, $AddrSeek);
- while(($char = fread($fd, 1)) != chr(0))
- $ipAddr1 .= $char;
+ while (($char = fread($fd, 1)) != chr(0)) {
+ $ipAddr1 .= $char;
+ }
+
} else {
fseek($fd, -1, SEEK_CUR);
- while(($char = fread($fd, 1)) != chr(0))
- $ipAddr1 .= $char;
+ while (($char = fread($fd, 1)) != chr(0)) {
+ $ipAddr1 .= $char;
+ }
$ipFlag = fread($fd, 1);
- if($ipFlag == chr(2)) {
+ if ($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
- if(strlen($AddrSeek2) < 3) {
+ if (strlen($AddrSeek2) < 3) {
fclose($fd);
return 'System Error';
}
- $AddrSeek2 = implode('', unpack('L', $AddrSeek2.chr(0)));
+ $AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
- while(($char = fread($fd, 1)) != chr(0)){
+ while (($char = fread($fd, 1)) != chr(0)) {
$ipAddr2 .= $char;
}
}
fclose($fd);
- if(preg_match('/http/i', $ipAddr2)) {
+ if (preg_match('/http/i', $ipAddr2)) {
$ipAddr2 = '';
}
$ipaddr = "$ipAddr1 $ipAddr2";
$ipaddr = preg_replace('/CZ88.Net/is', '', $ipaddr);
$ipaddr = preg_replace('/^s*/is', '', $ipaddr);
$ipaddr = preg_replace('/s*$/is', '', $ipaddr);
- if(preg_match('/http/i', $ipaddr) || $ipaddr == '') {
+ if (preg_match('/http/i', $ipaddr) || $ipaddr == '') {
$ipaddr = 'Unknown';
}
$ipaddr = iconv('gbk', 'utf-8//IGNORE', $ipaddr);
- if( $ipaddr != ' ' )
+ if ($ipaddr != ' ') {
return $ipaddr;
- else
+ } else {
$ipaddr = 'Unknown';
- return $ipaddr;
+ }
+
+ return $ipaddr;
}
//Comment Location End
@@ -372,43 +402,44 @@ function convertip($ip) {
* 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-">
+if (!function_exists('akina_comment_format')) {
+ function akina_comment_format($comment, $args, $depth)
+ {
+ $GLOBALS['comment'] = $comment;
+ ?>
+ id="comment-">
get_results(
+function get_author_class($comment_author_email, $user_id)
+{
+ global $wpdb;
+ $author_count = count($wpdb->get_results(
"SELECT comment_ID as author_count FROM $wpdb->comments WHERE comment_author_email = '$comment_author_email' "));
- if($author_count>=1 && $author_count< 5 )//数字可自行修改,代表评论次数。
- echo '
';
- else if($author_count>=6 && $author_count< 10)
- echo '
';
- else if($author_count>=10 && $author_count< 20)
- echo '
';
- else if($author_count>=20 && $author_count< 40)
- echo '
';
- else if($author_count>=40 && $author_count< 80)
- echo '
';
- else if($author_count>=80 && $author_count< 160)
- echo '
';
- else if($author_count>=160)
- echo '
';
+ if ($author_count >= 1 && $author_count < 5) //数字可自行修改,代表评论次数。
+ {
+ echo '
';
+ } else if ($author_count >= 6 && $author_count < 10) {
+ echo '
';
+ } else if ($author_count >= 10 && $author_count < 20) {
+ echo '
';
+ } else if ($author_count >= 20 && $author_count < 40) {
+ echo '
';
+ } else if ($author_count >= 40 && $author_count < 80) {
+ echo '
';
+ } else if ($author_count >= 80 && $author_count < 160) {
+ echo '
';
+ } else if ($author_count >= 160) {
+ echo '
';
}
+}
+
/**
* post views
*/
-function restyle_text($number) {
+function restyle_text($number)
+{
switch (akina_option('statistics_format')) {
case "type_2": //23,333 次访问
return number_format($number);
@@ -454,9 +490,9 @@ function restyle_text($number) {
return number_format($number, 0, '.', ' ');
break;
case "type_4": //23k 次访问
- if($number >= 1000) {
- return round($number/1000,2) . 'k';
- }else{
+ if ($number >= 1000) {
+ return round($number / 1000, 2) . 'k';
+ } else {
return $number;
}
break;
@@ -465,13 +501,14 @@ function restyle_text($number) {
}
}
-function set_post_views() {
+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))) {
+ 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);
}
}
@@ -480,298 +517,319 @@ function set_post_views() {
add_action('get_header', 'set_post_views');
-function get_post_views($post_id) {
- if (akina_option('statistics_api')=='wp_statistics'){
+function get_post_views($post_id)
+{
+ if (akina_option('statistics_api') == 'wp_statistics') {
if (!function_exists('wp_statistics_pages')) {
return __('Please install pulgin
WP-Statistics ', 'sakura');
} else {
- return restyle_text(wp_statistics_pages('total','uri',$post_id));
+ return restyle_text(wp_statistics_pages('total', 'uri', $post_id));
}
} else {
$views = get_post_meta($post_id, 'views', true);
- if($views == '') {
+ if ($views == '') {
return 0;
- }else{
+ } else {
return restyle_text($views);
}
}
-}
-
+}
/*
* Ajax点赞
*/
add_action('wp_ajax_nopriv_specs_zan', 'specs_zan');
add_action('wp_ajax_specs_zan', 'specs_zan');
-function specs_zan(){
- global $wpdb,$post;
+function specs_zan()
+{
+ global $wpdb, $post;
$id = $_POST["um_id"];
$action = $_POST["um_action"];
- if ( $action == 'ding'){
- $specs_raters = get_post_meta($id,'specs_zan',true);
+ if ($action == 'ding') {
+ $specs_raters = get_post_meta($id, 'specs_zan', true);
$expire = time() + 99999999;
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
- setcookie('specs_zan_'.$id,$id,$expire,'/',$domain,false);
+ setcookie('specs_zan_' . $id, $id, $expire, '/', $domain, false);
if (!$specs_raters || !is_numeric($specs_raters)) {
update_post_meta($id, 'specs_zan', 1);
- }
- else {
+ } else {
update_post_meta($id, 'specs_zan', ($specs_raters + 1));
}
- echo get_post_meta($id,'specs_zan',true);
- }
+ echo get_post_meta($id, 'specs_zan', true);
+ }
die;
}
-
/*
* 友情链接
*/
-function get_the_link_items($id = null){
- $bookmarks = get_bookmarks('orderby=date&category=' .$id );
- $output = '';
- if ( !empty($bookmarks) ) {
- $output .= '
';
- foreach ($bookmarks as $bookmark) {
- if (empty($bookmark->link_description)) $bookmark->link_description = __('This guy is so lazy ╮(╯▽╰)╭', 'sakura');
- if (empty($bookmark->link_image)) $bookmark->link_image = 'https://view.moezx.cc/images/2017/12/30/Transparent_Akkarin.th.jpg';
- $output .= ''. $bookmark->link_name .' '. $bookmark->link_description .'
';
- }
- $output .= ' ';
- }
- return $output;
+function get_the_link_items($id = null)
+{
+ $bookmarks = get_bookmarks('orderby=date&category=' . $id);
+ $output = '';
+ if (!empty($bookmarks)) {
+ $output .= '
';
+ foreach ($bookmarks as $bookmark) {
+ if (empty($bookmark->link_description)) {
+ $bookmark->link_description = __('This guy is so lazy ╮(╯▽╰)╭', 'sakura');
+ }
+
+ if (empty($bookmark->link_image)) {
+ $bookmark->link_image = 'https://view.moezx.cc/images/2017/12/30/Transparent_Akkarin.th.jpg';
+ }
+
+ $output .= '' . $bookmark->link_name . ' ' . $bookmark->link_description . '
';
+ }
+ $output .= ' ';
+ }
+ return $output;
}
-function get_link_items(){
- $linkcats = get_terms( 'link_category' );
- if ( !empty($linkcats) ) {
- foreach( $linkcats as $linkcat){
- $result .= '
'.$linkcat->name.' ';
- if( $linkcat->description ) $result .= '
' . $linkcat->description . '
';
- $result .= get_the_link_items($linkcat->term_id);
- }
- } else {
- $result = get_the_link_items();
- }
- return $result;
-}
+function get_link_items()
+{
+ $linkcats = get_terms('link_category');
+ if (!empty($linkcats)) {
+ foreach ($linkcats as $linkcat) {
+ $result .= '
' . $linkcat->name . ' ';
+ if ($linkcat->description) {
+ $result .= '
' . $linkcat->description . '
';
+ }
+ $result .= get_the_link_items($linkcat->term_id);
+ }
+ } else {
+ $result = get_the_link_items();
+ }
+ return $result;
+}
/*
* Gravatar头像使用中国服务器
*/
-function gravatar_cn( $url ){
- $gravatar_url = array('0.gravatar.com','1.gravatar.com','2.gravatar.com','secure.gravatar.com');
- return str_replace( $gravatar_url, 'cn.gravatar.com', $url );
+function gravatar_cn($url)
+{
+ $gravatar_url = array('0.gravatar.com', '1.gravatar.com', '2.gravatar.com', 'secure.gravatar.com');
+ return str_replace($gravatar_url, 'cn.gravatar.com', $url);
}
-add_filter( 'get_avatar_url', 'gravatar_cn', 4 );
+add_filter('get_avatar_url', 'gravatar_cn', 4);
/*
* 自定义默认头像
*/
-add_filter( 'avatar_defaults', 'mytheme_default_avatar' );
+add_filter('avatar_defaults', 'mytheme_default_avatar');
-function mytheme_default_avatar ( $avatar_defaults ) {
+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';
+ $new_avatar_url = 'https://cn.gravatar.com/avatar/b745710ae6b0ce9dfb13f5b7c0956be1';
$avatar_defaults[$new_avatar_url] = 'Default Avatar';
return $avatar_defaults;
}
/*
- * 阻止站内文章互相Pingback
+ * 阻止站内文章互相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');
+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';
- }*/
- return $classes;
+ */
+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';
+ }*/
+ return $classes;
}
-add_filter( 'body_class', 'akina_body_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 = akina_option('qiniu_cdn');
+add_filter('upload_dir', 'wpjam_custom_upload_dir');
+function wpjam_custom_upload_dir($uploads)
+{
+ $upload_path = '';
+ $upload_url_path = akina_option('qiniu_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;
- }
+ 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'];
+ $uploads['path'] = $uploads['basedir'] . $uploads['subdir'];
- if ( $upload_url_path ) {
- $uploads['baseurl'] = $upload_url_path;
- $uploads['url'] = $uploads['baseurl'].$uploads['subdir'];
- }
- return $uploads;
+ 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");
+ */
+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_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");
+ 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',
- ) );
+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 theme support for Responsive Videos.
+ add_theme_support('jetpack-responsive-videos');
}
-add_action( 'after_setup_theme', 'akina_jetpack_setup' );
+add_action('after_setup_theme', 'akina_jetpack_setup');
/**
* Custom render function for Infinite Scroll.
*/
-function akina_infinite_scroll_render() {
- while ( have_posts() ) {
- the_post();
- if ( is_search() ) :
- get_template_part( 'tpl/content', 'search' );
- else :
- get_template_part( 'tpl/content', get_post_format() );
- endif;
- }
+function akina_infinite_scroll_render()
+{
+ while (have_posts()) {
+ the_post();
+ if (is_search()):
+ get_template_part('tpl/content', 'search');
+ else:
+ get_template_part('tpl/content', get_post_format());
+ endif;
+ }
}
-
/*
* 编辑器增强
*/
-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;
-}
+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");
+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";
- echo ''."\n";
+function custom_login()
+{
+ //echo '
'."\n";
+ echo '
' . "\n";
+ //echo ''."\n";
+ echo '' . "\n";
}
add_action('login_head', 'custom_login');
//Login Page Title
-function custom_headertitle ( $title ) {
- return get_bloginfo('name');
+function custom_headertitle($title)
+{
+ return get_bloginfo('name');
}
-add_filter('login_headertitle','custom_headertitle');
+add_filter('login_headertitle', 'custom_headertitle');
//Login Page Link
-function custom_loginlogo_url($url) {
- return esc_url( home_url('/') );
+function custom_loginlogo_url($url)
+{
+ return esc_url(home_url('/'));
}
-add_filter( 'login_headerurl', 'custom_loginlogo_url' );
+add_filter('login_headerurl', 'custom_loginlogo_url');
//Login Page Footer
-function custom_html() {
- if ( akina_option('login_bg') ) {
- $loginbg = akina_option('login_bg');
- }else{
- $loginbg = 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.2.7/images/hd.png';
- }
- echo ''."\n";
- echo ''."\n";
- echo '' . "\n";
+ echo '' . "\n";
+ echo '';
- echo '
- ';
+ ';
}
add_action('login_footer', 'custom_html');
//Login message
//* Add custom message to WordPress login page
-function smallenvelop_login_message( $message ) {
- if ( empty($message) ){
+function smallenvelop_login_message($message)
+{
+ if (empty($message)) {
return '
You may try 3 times for every 5 minutes!
';
} else {
return $message;
@@ -842,38 +901,41 @@ function smallenvelop_login_message( $message ) {
//add_filter( 'login_message', 'smallenvelop_login_message' );
//Fix password reset bug >
-function resetpassword_message_fix( $message ) {
+function resetpassword_message_fix($message)
+{
$message = str_replace("<", "", $message);
- $message = str_replace(">", "", $message);
- return $message;
+ $message = str_replace(">", "", $message);
+ return $message;
}
-add_filter( 'retrieve_password_message', 'resetpassword_message_fix' );
+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;
+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' );
+add_filter('wp_new_user_notification_email', 'new_user_message_fix');
/*
* 评论邮件回复
*/
-function comment_mail_notify($comment_id){
- $mail_user_name = akina_option('mail_user_name') ? akina_option('mail_user_name') : 'poi';
+function comment_mail_notify($comment_id)
+{
+ $mail_user_name = akina_option('mail_user_name') ? akina_option('mail_user_name') : 'poi';
$comment = get_comment($comment_id);
$parent_id = $comment->comment_parent ? $comment->comment_parent : '';
$spam_confirmed = $comment->comment_approved;
- $mail_notify = akina_option('mail_notify') ? get_comment_meta($parent_id,'mail_notify',false) : false;
+ $mail_notify = akina_option('mail_notify') ? get_comment_meta($parent_id, 'mail_notify', false) : false;
$admin_notify = akina_option('admin_notify') ? '1' : (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 = '
+ 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_the_title($comment->comment_post_ID) . '》上发表的评论:
'
@@ -919,98 +981,110 @@ function comment_mail_notify($comment_id){
margin: 10px auto 0; " target="_blank" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">点击查看回复的完整內容
本邮件为系统自动发出,请勿直接回复
- © '.date(Y).' '.get_option("blogname").'
-
+ © ' . date(Y) . ' ' . get_option("blogname") . '
+
';
- $message = convert_smilies($message);
- $message = str_replace("{{",' ',$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 );
- }
+ $message = convert_smilies($message);
+ $message = str_replace("{{", ' ', $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( ' 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)"> ', $content);
+ $content = str_replace('[/img^img]', '" class="lazyload comment_inline_img" onerror="imgError(this)"> ';
+ $return_smiles = $return_smiles . ' ';
}
- return $return_smiles;
+ return $return_smiles;
}
-function smilies_reset() {
-global $wpsmiliestrans;
+function smilies_reset()
+{
+ global $wpsmiliestrans;
// don't bother setting up smilies if they are disabled
-if ( !get_option( 'use_smilies' ) )
- return;
+ if (!get_option('use_smilies')) {
+ return;
+ }
$wpsmiliestrans = array(
':good:' => 'icon_good.gif',
@@ -1049,7 +1123,8 @@ if ( !get_option( 'use_smilies' ) )
}
smilies_reset();
-function push_emoji_panel() {
+function push_emoji_panel()
+{
return '
(⌒▽⌒)
( ̄▽ ̄)
@@ -1097,24 +1172,21 @@ function push_emoji_panel() {
';
}
-function get_wp_root_path() {
+function get_wp_root_path()
+{
$base = dirname(__FILE__);
$path = false;
- if (@file_exists(dirname(dirname($base))))
- {
+ if (@file_exists(dirname(dirname($base)))) {
$path = dirname(dirname($base));
- }
- else
- if (@file_exists(dirname(dirname(dirname($base)))))
- {
+ } else
+ if (@file_exists(dirname(dirname(dirname($base))))) {
$path = dirname(dirname(dirname($base)));
+ } else {
+ $path = false;
}
- else
- $path = false;
- if ($path != false)
- {
+ if ($path != false) {
$path = str_replace("\\", "/", $path);
}
return $path;
@@ -1122,45 +1194,48 @@ function get_wp_root_path() {
// bilibili smiles
$bilismiliestrans = array();
-function push_bili_smilies(){
- global $bilismiliestrans;
- $smiles_path = __DIR__. "/images/smilies/bili/";
- $name = array( 'baiyan','fadai','koubi','qinqin','weiqu','bishi','fanu','kun','se','weixiao','bizui','ganga','lengmo','shengbing','wunai','chan','guilian','liubixue','shengqi','xiaoku','daku','guzhang','liuhan','shuizhao','xieyanxiao','dalao','haixiu','liulei','sikao','yiwen','dalian','heirenwenhao','miantian','tiaokan','yun','dianzan','huaixiao','mudengkoudai','tiaopi','zaijian','doge','jingxia','nanguo','touxiao','zhoumei','facai','keai','outu','tuxue','zhuakuang' );
- $return_smiles = '';
- for( $i=0;$i
';
- // 正文转换
- $bilismiliestrans['{{' . $name[$i] . '}}'] = '
';
}
return $return_smiles;
}
push_bili_smilies();
-function bili_smile_filter($content) {
+function bili_smile_filter($content)
+{
global $bilismiliestrans;
- $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content);
+ $content = str_replace(array_keys($bilismiliestrans), $bilismiliestrans, $content);
return $content;
}
add_filter('the_content', 'bili_smile_filter'); //替换文章关键词
-add_filter( 'comment_text', 'bili_smile_filter' );//替换评论关键词
+add_filter('comment_text', 'bili_smile_filter'); //替换评论关键词
-function featuredtoRSS($content) {
+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;
+ if (has_post_thumbnail($post->ID)) {
+ $content = '
' . get_the_post_thumbnail($post->ID, 'medium', array('style' => 'margin-bottom: 15px;')) . '
' . $content;
}
return $content;
}
@@ -1168,19 +1243,21 @@ add_filter('the_excerpt_rss', 'featuredtoRSS');
add_filter('the_content_feed', 'featuredtoRSS');
//
-function bili_smile_filter_rss($content) {
- $content = str_replace("{{",'
',$content);
- $content = str_replace('[img]', '
', $content);
+function bili_smile_filter_rss($content)
+{
+ $content = str_replace("{{", '
', $content);
+ $content = str_replace('[img]', '
', $content);
return $content;
}
-add_filter( 'comment_text_rss', 'bili_smile_filter_rss' );//替换评论rss关键词
+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); // 首字格式支持
+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');
@@ -1188,44 +1265,47 @@ 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'] ) ) {
+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'] ) ) {
+ $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_X_FORWARDED_FOR'];
+ } else {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+ return apply_filters('wpb_get_ip', $ip);
}
-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 = "";
+function hero_get_lyric()
+{
+ /** These are the lyrics to Hero */
+ $lyrics = "";
- // Here we split it into lines
- $lyrics = explode( "\n", $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 ) ] );
+ // 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;
+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(){
+function siren_private()
+{
$comment_id = $_POST["p_id"];
$action = $_POST["p_action"];
if ($action == 'set_private') {
@@ -1241,31 +1321,42 @@ function siren_private(){
}
//时间序列
-function memory_archives_list() {
- if( true ){
- $output = '
['.__( "All expand/collapse", "sakura" )/*全部展开/收缩*/.' ]
';
- $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');
+function memory_archives_list()
+{
+ if (true) {
+ $output = '
[' . __("All expand/collapse", "sakura") /*全部展开/收缩*/ . ' ]
';
+ $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 .= '';
+ $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","sakura"). /*年*/' '; //输出年份
+ $output .= '' . $year . __(" ", "year", "sakura") . /*年*/' '; //输出年份
}
if ($mon != $mon_tmp) {
$mon = $mon_tmp;
- $output .= ''.get_the_time('M').' ( '.__(" post(s)","sakura") /*篇文章*/.')'; //输出月份
+ $output .= '' . get_the_time('M') . ' ( ' . __(" post(s)", "sakura") /*篇文章*/ . ') ';
#update_option('memory_archives_list', $output);
- }
+ }
echo $output;
}
@@ -1273,27 +1364,28 @@ function memory_archives_list() {
* 隐藏 Dashboard
*/
/* Remove the "Dashboard" from the admin menu for non-admin users */
-function remove_dashboard () {
+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 (!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] );
+ 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 );
+ 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');
+ if (preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) &&
+ ('index.php' != $menu[$page][2])) {
+ wp_redirect(get_option('siteurl') . '/wp-admin/profile.php');
}
}
}
@@ -1306,31 +1398,33 @@ add_action('admin_menu', 'remove_dashboard');
* @return int (Maybe) modified excerpt length.
*/
-function GBsubstr($string, $start, $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 ++;
+ 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 {
+ } else {
return $string;
}
}
-
-function excerpt_length($exp) {
+
+function excerpt_length($exp)
+{
if (!function_exists('mb_substr')) {
$exp = GBsubstr($exp, 0, 80);
} else {
@@ -1339,39 +1433,40 @@ function excerpt_length($exp) {
*/
$exp = mb_substr($exp, 0, 80);
}
- return $exp;
+ return $exp;
}
-add_filter( 'the_excerpt', 'excerpt_length' );
-
+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 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() . '/inc/css/dashboard-fix.css');
- wp_enqueue_script( 'lazyload', 'https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.min.js' );
+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() . '/inc/css/dashboard-fix.css');
+ wp_enqueue_script('lazyload', 'https://cdn.jsdelivr.net/npm/lazyload@2.0.0-beta.2/lazyload.min.js');
}
add_action('admin_enqueue_scripts', 'admin_ini');
-function custom_admin_js() {
+function custom_admin_js()
+{
echo '
comment_author_email, '24', '', get_comment_author() ); ?> comment_author_email,$comment->user_id); ?>
+comment_author_email, '24', '', get_comment_author()); ?> comment_author_email, $comment->user_id); ?>