升级至 3.8 版本

This commit is contained in:
feng 2025-01-02 10:36:40 +08:00
parent 8d3a71414d
commit 5370b07c36
78 changed files with 1261 additions and 890 deletions

2
Plugin.php Normal file → Executable file
View file

@ -45,7 +45,7 @@ class Plugin {
*/
add_filter( sprintf( '%splugin_action_links', is_multisite() ? 'network_admin_' : '' ), function ( $links, $plugin = '' ) {
$links[] = '<a target="_blank" href="https://translate.wenpai.org/projects/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">参与翻译</a>';
$links[] = '<a target="_blank" href="https://wp-china-yes.com/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">去广告</a>';
$links[] = '<a target="_blank" href="https://wpcy.com/plugins/' . substr( $plugin, 0, strpos( $plugin, '/' ) ) . '/">去广告</a>';
return $links;
}, 10, 2 );

6
Service/Base.php Normal file → Executable file
View file

@ -16,11 +16,13 @@ class Base {
new Super();
// 监控服务
new Monitor();
// 内存服务
new Memory();
// 更新服务
new Update();
if ( is_admin() ) {
// 设置服务
new Setting();
// 设置服务
new Setting();
}
}
}

254
Service/Memory.php Executable file
View file

@ -0,0 +1,254 @@
<?php
namespace WenPai\ChinaYes\Service;
defined( 'ABSPATH' ) || exit;
use function WenPai\ChinaYes\get_settings;
/**
* Class Memory
* 显示服务器 IP 和内存使用情况
* @package WenPai\ChinaYes\Service
*/
class Memory {
private $memory = [];
private $server_ip_address = '';
private $os_info = '';
private $debug_status = '';
private $cpu_usage = null;
private $mysql_version = '';
public function __construct() {
$settings = get_settings();
if (!empty($settings['memory'])) {
add_action('plugins_loaded', [$this, 'initialize']);
}
register_activation_hook(CHINA_YES_PLUGIN_FILE, [$this, 'check_php_version']);
}
/**
* 初始化插件
*/
public function initialize() {
add_action('init', [$this, 'check_memory_limit']);
add_filter('admin_footer_text', [$this, 'add_footer']);
}
/**
* 获取操作系统信息
*/
private function get_os_info() {
$os = php_uname('s');
// 转换为更直观的名称
switch (strtolower($os)) {
case 'linux':
if (file_exists('/etc/os-release')) {
$content = parse_ini_file('/etc/os-release');
return $content['PRETTY_NAME'] ?? 'Linux';
}
return 'Linux';
case 'darwin':
return 'macOS';
case 'windows nt':
return 'Windows';
default:
return $os;
}
}
/**
* 获取调试状态
*/
private function get_debug_status() {
if (defined('WP_DEBUG') && true === WP_DEBUG) {
return '<strong><font color="#F60">' . __('WP_DEBUG', 'wp-china-yes') . '</font></strong>';
}
return '<span style="text-decoration: line-through;">' . __('WP_DEBUG', 'wp-china-yes') . '</span>';
}
/**
* 获取 CPU 使用率
*/
private function get_cpu_usage() {
if (function_exists('sys_getloadavg') && is_callable('sys_getloadavg')) {
$load = sys_getloadavg();
return round($load[0] * 100 / 4, 2); // 假设是4核CPU
}
return false;
}
/**
* 获取 MySQL 版本
*/
private function get_mysql_version() {
global $wpdb;
return $wpdb->get_var("SELECT VERSION()");
}
/**
* 检查 PHP 内存限制
*/
public function check_memory_limit() {
$this->memory['limit'] = (int) ini_get('memory_limit');
}
/**
* 检查内存使用情况
*/
private function check_memory_usage() {
$this->memory['usage'] = function_exists('memory_get_peak_usage')
? round(memory_get_peak_usage(true) / 1024 / 1024, 2)
: 0;
if (!empty($this->memory['usage']) && !empty($this->memory['limit'])) {
$this->memory['percent'] = round($this->memory['usage'] / $this->memory['limit'] * 100, 0);
$this->memory['color'] = $this->get_memory_color($this->memory['percent']);
}
}
/**
* 获取内存使用率的颜色
*/
private function get_memory_color($percent) {
if ($percent > 90) {
return 'font-weight:bold;color:red';
} elseif ($percent > 75) {
return 'font-weight:bold;color:#E66F00';
}
return 'font-weight:normal;';
}
/**
* 格式化 WordPress 内存限制
*/
private function format_wp_limit($size) {
$unit = strtoupper(substr($size, -1));
$value = (int) substr($size, 0, -1);
switch ($unit) {
case 'P': $value *= 1024;
case 'T': $value *= 1024;
case 'G': $value *= 1024;
case 'M': $value *= 1024;
case 'K': $value *= 1024;
}
return $value;
}
/**
* 获取 WordPress 内存限制
*/
private function check_wp_limit() {
$memory = $this->format_wp_limit(WP_MEMORY_LIMIT);
return $memory ? size_format($memory) : __('N/A', 'wp-china-yes');
}
/**
* 添加信息到管理界面页脚
*/
public function add_footer($content) {
$settings = get_settings();
// 确保 memory_display 是数组,如果不是则使用空数组
$display_options = is_array($settings['memory_display'] ?? []) ? $settings['memory_display'] : [];
// 如果 memory 设置未启用,直接返回原始内容
if (empty($settings['memory'])) {
return $content;
}
$this->check_memory_usage();
$this->server_ip_address = $_SERVER['SERVER_ADDR'] ?? ($_SERVER['LOCAL_ADDR'] ?? '');
$this->os_info = $this->get_os_info();
$footer_parts = [];
// 内存使用量
if (in_array('memory_usage', $display_options)) {
$footer_parts[] = sprintf('%s: %s %s %s MB (<span style="%s">%s%%</span>)',
__('Memory', 'wp-china-yes'),
$this->memory['usage'],
__('of', 'wp-china-yes'),
$this->memory['limit'],
$this->memory['color'],
$this->memory['percent']
);
}
// WP内存限制
if (in_array('wp_limit', $display_options)) {
$footer_parts[] = sprintf('%s: %s',
__('WP LIMIT', 'wp-china-yes'),
$this->check_wp_limit()
);
}
// 服务器IP和主机名
if (in_array('server_ip', $display_options)) {
$hostname_part = in_array('hostname', $display_options) ? " (" . gethostname() . ")" : "";
$footer_parts[] = sprintf('IP: %s%s',
$this->server_ip_address,
$hostname_part
);
}
// 操作系统信息
if (in_array('os_info', $display_options)) {
$footer_parts[] = sprintf('OS: %s', $this->os_info);
}
// PHP信息
if (in_array('php_info', $display_options)) {
$footer_parts[] = sprintf('PHP: %s @%sBitOS',
PHP_VERSION,
PHP_INT_SIZE * 8
);
}
// Debug状态
if (in_array('debug_status', $display_options)) {
$footer_parts[] = $this->get_debug_status();
}
// CPU使用率
if (in_array('cpu_usage', $display_options)) {
$cpu_usage = $this->get_cpu_usage();
if ($cpu_usage !== false) {
$footer_parts[] = sprintf('CPU: %s%%', $cpu_usage);
}
}
// MySQL版本
if (in_array('mysql_version', $display_options)) {
$footer_parts[] = sprintf('MySQL: %s', $this->get_mysql_version());
}
if (!empty($footer_parts)) {
$content .= ' | WPCY - ' . implode(' | ', $footer_parts);
}
return $content;
}
/**
* 检查 PHP 版本
*/
public function check_php_version() {
if (version_compare(PHP_VERSION, '7.0', '<')) {
deactivate_plugins(plugin_basename(CHINA_YES_PLUGIN_FILE));
wp_die(
sprintf(
'<h1>%s</h1><p>%s</p>',
__('插件无法激活PHP 版本过低', 'wp-china-yes'),
__('请升级 PHP 至 7.0 或更高版本。', 'wp-china-yes')
),
__('PHP 版本错误', 'wp-china-yes'),
['back_link' => true]
);
}
}
}

4
Service/Monitor.php Normal file → Executable file
View file

@ -30,9 +30,7 @@ class Monitor {
] );
}
} else {
if ( wp_get_scheduled_event( 'wp_china_yes_monitor' ) ) {
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
}
wp_clear_scheduled_hook( 'wp_china_yes_monitor' );
}
}

File diff suppressed because one or more lines are too long

59
Service/Super.php Normal file → Executable file
View file

@ -55,9 +55,7 @@ HTML;
|
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
<a href="https://wptea.com/instructions-for-submission/" target="_blank">文章投稿</a>
|
<a href="https://wp-china-yes.com/document/news-source" target="_blank">自选新闻源</a>
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
</p>
<style>
#wenpai_tea .rss-widget {
@ -113,9 +111,7 @@ HTML;
|
<a href="https://translate.wenpai.org/" target="_blank">翻译平台</a>
|
<a href="https://wptea.com/instructions-for-submission/" target="_blank">文章投稿</a>
|
<a href="https://wptea.com/document/news-source/" target="_blank">自选新闻源</a>
<a href="https://wptea.com/newsletter/" target="_blank">订阅推送</a>
</p>
<style>
#wenpai_tea .rss-widget {
@ -276,12 +272,23 @@ HTML;
*/
if ( in_array( 'jsdelivr', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'jsd.admincdn.com',
'cdn.jsdelivr.net',
'jsd.admincdn.com'
] );
}
/**
* BootstrapCDN 前端公共库替换
*/
if ( in_array( 'bootstrapcdn', (array) $this->settings['admincdn'] ) ) {
$this->page_str_replace( 'init', 'str_replace', [
'maxcdn.bootstrapcdn.com',
'jsd.admincdn.com'
] );
}
}
/**
* 加载文风字体
*/
@ -442,6 +449,44 @@ HTML
remove_filter( $qmr_work_tag, 'wptexturize' );
}
}
// 支持中文排版段首缩进 2em
if ( in_array( 'indent', (array) $this->settings['windfonts_typography'] ) ) {
add_action( 'wp_head', function () {
echo '<style>
.entry-content p {
text-indent: 2em;
}
.entry-content .wp-block-group p,
.entry-content .wp-block-columns p,
.entry-content .wp-block-media-text p,
.entry-content .wp-block-quote p {
text-indent: 0;
}
</style>';
} );
}
// 支持中文排版两端对齐
if ( in_array( 'align', (array) $this->settings['windfonts_typography'] ) ) {
add_action( 'wp_head', function () {
echo '<style>
.entry-content p {
text-align: justify;
}
.entry-content .wp-block-group p,
.entry-content .wp-block-columns p,
.entry-content .wp-block-media-text p,
.entry-content .wp-block-quote p {
text-align: unset !important;
}
.entry-content .wp-block-columns p.has-text-align-center {
text-align: center !important;
}
</style>';
} );
}
}
/**

0
Service/Update.php Normal file → Executable file
View file

View file

@ -90,6 +90,9 @@
box-shadow: 0 0 0 1px #ccd0d4, 0 1px 1px 1px rgba(0, 0, 0, .04);
}
.wp_china_yes-field-checkbox .wp_china_yes--inline-list li, .wp_china_yes-field-radio .wp_china_yes--inline-list li {
margin-right: 20px;
}
.wp_china_yes-section {
margin: 50px auto;

BIN
assets/images/qr-banner.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 47 KiB

Before After
Before After

0
framework/assets/css/style-rtl.min.css vendored Normal file → Executable file
View file

0
framework/assets/css/style.min.css vendored Normal file → Executable file
View file

0
framework/assets/images/checkerboard.png Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before After
Before After

0
framework/assets/images/wp-logo.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 940 B

After

Width:  |  Height:  |  Size: 940 B

Before After
Before After

0
framework/assets/images/wp-plugin-logo.svg Normal file → Executable file
View file

Before

Width:  |  Height:  |  Size: 482 B

After

Width:  |  Height:  |  Size: 482 B

Before After
Before After

0
framework/assets/js/main.min.js vendored Normal file → Executable file
View file

0
framework/assets/js/plugins.min.js vendored Normal file → Executable file
View file

0
framework/classes/abstract.class.php Normal file → Executable file
View file

0
framework/classes/admin-options.class.php Normal file → Executable file
View file

0
framework/classes/fields.class.php Normal file → Executable file
View file

0
framework/fields/accordion/accordion.php Normal file → Executable file
View file

0
framework/fields/background/background.php Normal file → Executable file
View file

0
framework/fields/backup/backup.php Normal file → Executable file
View file

0
framework/fields/border/border.php Normal file → Executable file
View file

0
framework/fields/button_set/button_set.php Normal file → Executable file
View file

0
framework/fields/callback/callback.php Normal file → Executable file
View file

0
framework/fields/checkbox/checkbox.php Normal file → Executable file
View file

0
framework/fields/code_editor/code_editor.php Normal file → Executable file
View file

0
framework/fields/color/color.php Normal file → Executable file
View file

0
framework/fields/color_group/color_group.php Normal file → Executable file
View file

0
framework/fields/content/content.php Normal file → Executable file
View file

0
framework/fields/date/date.php Normal file → Executable file
View file

0
framework/fields/datetime/datetime.php Normal file → Executable file
View file

0
framework/fields/dimensions/dimensions.php Normal file → Executable file
View file

0
framework/fields/fieldset/fieldset.php Normal file → Executable file
View file

0
framework/fields/gallery/gallery.php Normal file → Executable file
View file

0
framework/fields/group/group.php Normal file → Executable file
View file

0
framework/fields/heading/heading.php Normal file → Executable file
View file

0
framework/fields/icon/fa4-icons.php Normal file → Executable file
View file

0
framework/fields/icon/fa5-icons.php Normal file → Executable file
View file

0
framework/fields/icon/icon.php Normal file → Executable file
View file

0
framework/fields/image_select/image_select.php Normal file → Executable file
View file

0
framework/fields/index.php Normal file → Executable file
View file

0
framework/fields/link/link.php Normal file → Executable file
View file

0
framework/fields/link_color/link_color.php Normal file → Executable file
View file

0
framework/fields/map/map.php Normal file → Executable file
View file

0
framework/fields/media/media.php Normal file → Executable file
View file

0
framework/fields/notice/notice.php Normal file → Executable file
View file

0
framework/fields/number/number.php Normal file → Executable file
View file

0
framework/fields/palette/palette.php Normal file → Executable file
View file

0
framework/fields/radio/radio.php Normal file → Executable file
View file

0
framework/fields/repeater/repeater.php Normal file → Executable file
View file

0
framework/fields/select/select.php Normal file → Executable file
View file

0
framework/fields/slider/slider.php Normal file → Executable file
View file

0
framework/fields/sortable/sortable.php Normal file → Executable file
View file

0
framework/fields/sorter/sorter.php Normal file → Executable file
View file

0
framework/fields/spacing/spacing.php Normal file → Executable file
View file

0
framework/fields/spinner/spinner.php Normal file → Executable file
View file

0
framework/fields/subheading/subheading.php Normal file → Executable file
View file

0
framework/fields/submessage/submessage.php Normal file → Executable file
View file

0
framework/fields/switcher/switcher.php Normal file → Executable file
View file

0
framework/fields/tabbed/tabbed.php Normal file → Executable file
View file

0
framework/fields/text/text.php Normal file → Executable file
View file

0
framework/fields/textarea/textarea.php Normal file → Executable file
View file

0
framework/fields/typography/google-fonts.php Normal file → Executable file
View file

0
framework/fields/typography/typography.php Normal file → Executable file
View file

0
framework/fields/upload/upload.php Normal file → Executable file
View file

0
framework/fields/wp_editor/wp_editor.php Normal file → Executable file
View file

0
framework/functions/actions.php Normal file → Executable file
View file

0
framework/functions/customize.php Normal file → Executable file
View file

0
framework/functions/helpers.php Normal file → Executable file
View file

0
framework/functions/sanitize.php Normal file → Executable file
View file

0
framework/functions/validate.php Normal file → Executable file
View file

0
framework/functions/walker.php Normal file → Executable file
View file

0
framework/index.php Normal file → Executable file
View file

0
framework/languages/zh_CN.mo Normal file → Executable file
View file

0
framework/languages/zh_CN.po Normal file → Executable file
View file

1
helpers.php Normal file → Executable file
View file

@ -20,6 +20,7 @@ function get_settings() {
'plane' => 'off',
'plane_rule' => [],
'monitor' => true,
'memory' => true,
'hide' => false,
'custom_name' => 'WP-China-Yes',
] );