From 2100ccd70831f71513816f7a8370b35e5cf6c5a4 Mon Sep 17 00:00:00 2001 From: mashiro Date: Fri, 27 Dec 2019 09:59:12 +0800 Subject: [PATCH 1/8] some enhancement --- functions.php | 10 +- options.php | 2129 ++++++++++++++++++++++++------------------------- 2 files changed, 1067 insertions(+), 1072 deletions(-) diff --git a/functions.php b/functions.php index b192a8a..7be24a7 100644 --- a/functions.php +++ b/functions.php @@ -7,7 +7,7 @@ * @package Sakura */ -define( 'SAKURA_VERSION', '3.3.5' ); +define( 'SAKURA_VERSION', wp_get_theme()->get('Version') ); define( 'BUILD_VERSION', '3' ); //ini_set('display_errors', true); @@ -736,7 +736,7 @@ function bolo_QTnextpage_arg1() { //Login Page style function custom_login() { //echo ''."\n"; - echo ''."\n"; + echo ''."\n"; //echo ''."\n"; echo ''."\n"; } @@ -762,7 +762,7 @@ function custom_html() { }else{ $loginbg = 'https://cdn.jsdelivr.net/gh/mashirozx/Sakura@3.2.7/images/hd.png'; } - echo ''."\n"; + echo ''."\n"; echo ' - +'."\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_option("blogname") .'的回复

+

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


您在文章《' . 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("{{",'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 ); - } + $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( ' 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("{{",'emoji',$content); - $content = str_replace('[img]', '', $content); +function bili_smile_filter_rss($content) +{ + $content = str_replace("{{", 'emoji', $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"). /*年*/'

'; #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 '