用户功能设置收口与废弃后台链路清理
This commit is contained in:
1 parent
081eb0870d
commit
86692ff3f9
59 files changed
+506
-1767
No files matched your search
@@ -37,18 +37,98 @@ if (!function_exists('aksrt_resolve_avatar_user_id')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_resolve_avatar_email')) {
|
||||
/**
|
||||
* Resolve an email address from an avatar subject.
|
||||
*
|
||||
* @param mixed $subject User ID, WP_User, comment, post, or email.
|
||||
*/
|
||||
function aksrt_resolve_avatar_email($subject): string {
|
||||
if ($subject instanceof WP_User) {
|
||||
return sanitize_email((string) $subject->user_email);
|
||||
}
|
||||
if ($subject instanceof WP_Comment && is_email((string) $subject->comment_author_email)) {
|
||||
return sanitize_email((string) $subject->comment_author_email);
|
||||
}
|
||||
if (is_object($subject) && isset($subject->comment_author_email) && is_email((string) $subject->comment_author_email)) {
|
||||
return sanitize_email((string) $subject->comment_author_email);
|
||||
}
|
||||
if (is_string($subject) && is_email($subject)) {
|
||||
return sanitize_email($subject);
|
||||
}
|
||||
|
||||
$user_id = aksrt_resolve_avatar_user_id($subject);
|
||||
$user = $user_id > 0 ? get_userdata($user_id) : false;
|
||||
return $user instanceof WP_User ? sanitize_email((string) $user->user_email) : '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_feature_settings')) {
|
||||
/**
|
||||
* Return the canonical user media and signature settings.
|
||||
*
|
||||
* @return array{avatar_upload_s:bool,avatar_external:string,avatar_default_img:string,user_cover_upload_s:bool,user_cover_img:string,user_desc_std:string}
|
||||
*/
|
||||
function aksrt_get_user_feature_settings(): array {
|
||||
if (class_exists('\AKSRT\Settings\Settings')) {
|
||||
return \AKSRT\Settings\Settings::get_user_feature_settings();
|
||||
}
|
||||
|
||||
return [
|
||||
'avatar_upload_s' => true,
|
||||
'avatar_external' => '',
|
||||
'avatar_default_img' => get_theme_file_uri('assets/img/avatar-default.png'),
|
||||
'user_cover_upload_s' => true,
|
||||
'user_cover_img' => get_theme_file_uri('assets/img/user_t.jpg'),
|
||||
'user_desc_std' => '这家伙很懒,什么都没有写...',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_default_avatar_url')) {
|
||||
/**
|
||||
* Return the bundled avatar used when a user has no custom image.
|
||||
*/
|
||||
function aksrt_get_default_avatar_url(): string {
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
return (string) apply_filters(
|
||||
'aksrt_default_avatar_url',
|
||||
get_theme_file_uri('assets/img/user/default-avatar.svg')
|
||||
(string) $settings['avatar_default_img']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_external_avatar_url')) {
|
||||
/**
|
||||
* Return the configured external avatar for a subject.
|
||||
*
|
||||
* @param mixed $subject User subject.
|
||||
*/
|
||||
function aksrt_get_external_avatar_url($subject, int $size = 96): string {
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
$hosts = [
|
||||
'gravatar' => 'https://www.gravatar.com/avatar/',
|
||||
'weavatar' => 'https://weavatar.com/avatar/',
|
||||
'cravatar' => 'https://cn.cravatar.com/avatar/',
|
||||
'geekzu' => 'https://sdn.geekzu.org/avatar/',
|
||||
'loli' => 'https://gravatar.loli.net/avatar/',
|
||||
'sep' => 'https://cdn.sep.cc/avatar/',
|
||||
'v2ex' => 'https://cdn.v2ex.com/gravatar/',
|
||||
];
|
||||
$host = $hosts[(string) $settings['avatar_external']] ?? '';
|
||||
$email = aksrt_resolve_avatar_email($subject);
|
||||
if ($host === '' || $email === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$size = max(1, min(2048, $size));
|
||||
return add_query_arg([
|
||||
's' => $size,
|
||||
'd' => aksrt_get_default_avatar_url(),
|
||||
], $host . hash('sha256', strtolower(trim($email))));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_custom_avatar_url')) {
|
||||
/**
|
||||
* Return the locally uploaded avatar URL.
|
||||
@@ -91,6 +171,10 @@ if (!function_exists('aksrt_get_avatar_url')) {
|
||||
if ($custom !== '') {
|
||||
return $custom;
|
||||
}
|
||||
$external = aksrt_get_external_avatar_url($subject, $size);
|
||||
if ($external !== '') {
|
||||
return $external;
|
||||
}
|
||||
return aksrt_get_default_avatar_url();
|
||||
}
|
||||
}
|
||||
@@ -133,9 +217,7 @@ if (!function_exists('aksrt_get_avatar_html')) {
|
||||
}
|
||||
|
||||
add_filter('get_avatar_data', static function (array $args, $subject): array {
|
||||
$user_id = aksrt_resolve_avatar_user_id($subject);
|
||||
$custom = aksrt_get_custom_avatar_url($user_id, (int) ($args['size'] ?? 96));
|
||||
$args['url'] = $custom !== '' ? $custom : aksrt_get_default_avatar_url();
|
||||
$args['url'] = aksrt_get_avatar_url($subject, ['size' => (int) ($args['size'] ?? 96)]);
|
||||
$args['found_avatar'] = true;
|
||||
return $args;
|
||||
}, 20, 2);
|
||||
@@ -151,7 +233,37 @@ if (!function_exists('aksrt_is_avatar_upload_enabled')) {
|
||||
* Whether local avatar uploads are enabled by attachment policy.
|
||||
*/
|
||||
function aksrt_is_avatar_upload_enabled(): bool {
|
||||
return function_exists('aksrt_user_can') && aksrt_user_can('upload_avatar', get_current_user_id());
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
return !empty($settings['avatar_upload_s']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_is_user_cover_upload_enabled')) {
|
||||
function aksrt_is_user_cover_upload_enabled(): bool {
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
return !empty($settings['user_cover_upload_s']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_cover_url')) {
|
||||
function aksrt_get_user_cover_url(int $user_id): string {
|
||||
$custom = $user_id > 0 ? esc_url_raw((string) get_user_meta($user_id, 'aksrt_background_image', true)) : '';
|
||||
if ($custom !== '') {
|
||||
return $custom;
|
||||
}
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
return (string) $settings['user_cover_img'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_get_user_description')) {
|
||||
function aksrt_get_user_description(int $user_id): string {
|
||||
$description = $user_id > 0 ? trim((string) get_user_meta($user_id, 'description', true)) : '';
|
||||
if ($description !== '') {
|
||||
return $description;
|
||||
}
|
||||
$settings = aksrt_get_user_feature_settings();
|
||||
return (string) $settings['user_desc_std'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -261,10 +261,7 @@ if (!function_exists('aksrt_author_minicard')) :
|
||||
}
|
||||
}
|
||||
|
||||
$desc = trim((string) get_user_meta($user_id, 'description', true));
|
||||
if ($desc === '') {
|
||||
$desc = __('这家伙很懒,什么都没有写…', 'aksrt');
|
||||
}
|
||||
$desc = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : trim((string) get_user_meta($user_id, 'description', true));
|
||||
|
||||
$blur = '';
|
||||
if ($blur_bg) {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
* Gates:
|
||||
* master: ip_geo_enabled
|
||||
* surface: ip_geo_display ∈ {comment, user_home, user_center, post}
|
||||
* users: user_city_s (+ user_city_type)
|
||||
* comments: comment_city_s (+ comment_city_type) via comments/geo.php
|
||||
*
|
||||
* Meta:
|
||||
@@ -74,9 +73,6 @@ if (!function_exists('aksrt_ip_geo_display_enabled')) :
|
||||
if (!in_array($location, aksrt_ip_geo_display_list(), true)) {
|
||||
return false;
|
||||
}
|
||||
if (in_array($location, ['user_home', 'user_center'], true) && !aksrt_user_city_enabled()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
endif;
|
||||
@@ -90,37 +86,6 @@ if (!function_exists('aksrt_ip_geo_format_key')) :
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_user_city_enabled')) :
|
||||
/**
|
||||
* Users feature: show city on user home / user center.
|
||||
* Default true when key absent (legacy parity for new installs).
|
||||
*/
|
||||
function aksrt_user_city_enabled(): bool {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) {
|
||||
return true;
|
||||
}
|
||||
$all = \AKSRT\Settings\Settings::get_all();
|
||||
if (!array_key_exists('user_city_s', $all)) {
|
||||
return true;
|
||||
}
|
||||
return !empty($all['user_city_s']);
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_user_city_type')) :
|
||||
function aksrt_user_city_type(): string {
|
||||
if (!class_exists('\AKSRT\Settings\Settings')) {
|
||||
return aksrt_ip_geo_format_key();
|
||||
}
|
||||
$all = \AKSRT\Settings\Settings::get_all();
|
||||
$type = sanitize_key((string) ($all['user_city_type'] ?? ''));
|
||||
if (in_array($type, ['province_city', 'province', 'country_province'], true)) {
|
||||
return $type;
|
||||
}
|
||||
return aksrt_ip_geo_format_key();
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_normalize_geo_addr')) :
|
||||
/**
|
||||
* @param mixed $raw Meta value.
|
||||
@@ -229,8 +194,7 @@ if (!function_exists('aksrt_store_user_addr')) :
|
||||
if ($user_id <= 0 || !aksrt_ip_geo_master_enabled()) {
|
||||
return;
|
||||
}
|
||||
$need = aksrt_user_city_enabled()
|
||||
|| in_array('post', aksrt_ip_geo_display_list(), true)
|
||||
$need = in_array('post', aksrt_ip_geo_display_list(), true)
|
||||
|| in_array('user_home', aksrt_ip_geo_display_list(), true)
|
||||
|| in_array('user_center', aksrt_ip_geo_display_list(), true);
|
||||
if (!$need) {
|
||||
@@ -286,7 +250,7 @@ if (!function_exists('aksrt_get_user_city_badge_html')) :
|
||||
if ($user_id <= 0 || !aksrt_ip_geo_display_enabled($location)) {
|
||||
return '';
|
||||
}
|
||||
return aksrt_get_geo_badge_html(aksrt_get_user_addr($user_id), aksrt_user_city_type(), $class);
|
||||
return aksrt_get_geo_badge_html(aksrt_get_user_addr($user_id), aksrt_ip_geo_format_key(), $class);
|
||||
}
|
||||
endif;
|
||||
|
||||
@@ -304,8 +268,7 @@ if (!function_exists('aksrt_get_post_author_city_badge_html')) :
|
||||
if ($author_id <= 0) {
|
||||
return '';
|
||||
}
|
||||
$type = aksrt_user_city_enabled() ? aksrt_user_city_type() : aksrt_ip_geo_format_key();
|
||||
return aksrt_get_geo_badge_html(aksrt_get_user_addr($author_id), $type, $class);
|
||||
return aksrt_get_geo_badge_html(aksrt_get_user_addr($author_id), aksrt_ip_geo_format_key(), $class);
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
@@ -330,7 +330,7 @@ if (!function_exists('aksrt_single_render_author_card')) :
|
||||
}
|
||||
$author_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($author_id) : get_author_posts_url($author_id);
|
||||
$author_name = get_the_author();
|
||||
$bio = trim((string) get_the_author_meta('description'));
|
||||
$bio = function_exists('aksrt_get_user_description') ? aksrt_get_user_description($author_id) : trim((string) get_the_author_meta('description'));
|
||||
$name_html = function_exists('aksrt_get_user_name')
|
||||
? aksrt_get_user_name([
|
||||
'id' => $author_id,
|
||||
|
||||
@@ -137,11 +137,11 @@ if (!function_exists('aksrt_get_user_center_tab_url')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_normalize_user_center_tabs')) {
|
||||
if (!function_exists('aksrt_normalize_user_center_panels')) {
|
||||
/**
|
||||
* Normalize the dashboard tab contract.
|
||||
*/
|
||||
function aksrt_normalize_user_center_tabs(array $tabs): array {
|
||||
function aksrt_normalize_user_center_panels(array $tabs): array {
|
||||
$normalized = [];
|
||||
foreach ($tabs as $key => $tab) {
|
||||
$key = sanitize_key((string) $key);
|
||||
@@ -296,7 +296,7 @@ if (!function_exists('aksrt_user_center_resolve_tabs')) {
|
||||
'favorites' => ['label' => __('我的收藏', 'aksrt'), 'icon' => 'star'],
|
||||
'settings' => ['label' => __('账号设置', 'aksrt'), 'icon' => 'cog'],
|
||||
];
|
||||
$tabs = aksrt_normalize_user_center_tabs($tabs);
|
||||
$tabs = aksrt_normalize_user_center_panels($tabs);
|
||||
$keys = array_keys($tabs);
|
||||
$default = in_array('vip', $keys, true)
|
||||
? 'vip'
|
||||
@@ -420,7 +420,7 @@ if (!function_exists('aksrt_user_center_cover_upload_config')) {
|
||||
'imageId' => 'aksrt-cover-img',
|
||||
'fieldName' => 'background',
|
||||
'maxSize' => $max_size,
|
||||
'fallbackImage' => AKSRT_URI . '/assets/img/person_background.png',
|
||||
'fallbackImage' => function_exists('aksrt_get_user_cover_url') ? aksrt_get_user_cover_url(get_current_user_id()) : get_theme_file_uri('assets/img/user_t.jpg'),
|
||||
'idleText' => __('修改背景图', 'aksrt'),
|
||||
'loadingText' => __('上传中…', 'aksrt'),
|
||||
'tooLargeText' => sprintf(__('图片大小不能超过 %dMB', 'aksrt'), (int) ($max_size / MB_IN_BYTES)),
|
||||
@@ -459,9 +459,9 @@ if (!function_exists('aksrt_get_user_center_render_context')) {
|
||||
$comment_count = (int) ($dashboard['comment_count'] ?? get_comments(['user_id' => $user_id, 'count' => true, 'status' => 'approve']));
|
||||
$favorite_post_ids = $dashboard['favorite_post_ids'] ?? [];
|
||||
$favorite_count = (int) ($dashboard['favorite_count'] ?? count($favorite_post_ids));
|
||||
$user_background_url = (string) ($dashboard['background_url'] ?? get_user_meta($user_id, 'aksrt_background_image', true));
|
||||
$allow_avatar_upload = function_exists('aksrt_user_can') && aksrt_user_can('upload_avatar', $user_id);
|
||||
$allow_bg_upload = function_exists('aksrt_user_can') && aksrt_user_can('upload_profile_background', $user_id);
|
||||
$user_background_url = function_exists('aksrt_get_user_cover_url') ? aksrt_get_user_cover_url($user_id) : '';
|
||||
$allow_avatar_upload = function_exists('aksrt_is_avatar_upload_enabled') && aksrt_is_avatar_upload_enabled();
|
||||
$allow_bg_upload = function_exists('aksrt_is_user_cover_upload_enabled') && aksrt_is_user_cover_upload_enabled();
|
||||
$messages_enabled = !class_exists('\AKSRT\Settings\Settings') || \AKSRT\Settings\Settings::message_enabled();
|
||||
$follower_count = class_exists('\AKSRT\User\Follow')
|
||||
? \AKSRT\User\Follow::get_instance()->get_follower_count($user_id)
|
||||
|
||||
@@ -67,7 +67,7 @@ function aksrt_get_user_dashboard_view(int $user_id, array $args = []): array {
|
||||
? aksrt_get_visible_user_profile_details($user_id, $viewer_id)
|
||||
: ['gender' => '', 'website' => '', 'qq' => '', 'wechat' => '', 'github' => ''];
|
||||
|
||||
$background_url = get_user_meta($user_id, 'aksrt_background_image', true) ?: '';
|
||||
$background_url = function_exists('aksrt_get_user_cover_url') ? aksrt_get_user_cover_url($user_id) : '';
|
||||
|
||||
$credits_enabled = class_exists('\AKSRT\Settings\Settings') && \AKSRT\Settings\Settings::credits_enabled();
|
||||
$credit_balance = $credits_enabled && $is_own_profile && function_exists('aksrt_user_credits')
|
||||
|
||||
@@ -67,10 +67,7 @@ if (!function_exists('aksrt_get_header_nav_context')) :
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
$user_id = (int) $current_user->ID;
|
||||
$user_desc = $user_id > 0 ? (string) get_user_meta($user_id, 'description', true) : '';
|
||||
if ($user_desc === '' && $user_id > 0) {
|
||||
$user_desc = (string) $current_user->user_email;
|
||||
}
|
||||
$user_desc = $user_id > 0 && function_exists('aksrt_get_user_description') ? aksrt_get_user_description($user_id) : '';
|
||||
|
||||
$ctx = [
|
||||
'settings' => $settings,
|
||||
|
||||
@@ -12,7 +12,7 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
|
||||
?>
|
||||
<div class="uc-header">
|
||||
<div class="uc-header__cover">
|
||||
<img id="aksrt-cover-img" class="uc-header__cover-img" src="<?php echo esc_url($user_background_url ? $user_background_url : get_theme_file_uri('assets/img/person_background.png')); ?>" alt="">
|
||||
<img id="aksrt-cover-img" class="uc-header__cover-img" src="<?php echo esc_url($user_background_url); ?>" alt="">
|
||||
<div class="uc-header__cover-mask"></div>
|
||||
<div class="aksrt-cover-menu" data-aksrt-menu>
|
||||
<button type="button" class="aksrt-cover-menu__trigger" aria-haspopup="true" aria-expanded="false" aria-label="<?php esc_attr_e('个人主页操作', 'aksrt'); ?>">
|
||||
@@ -58,7 +58,7 @@ extract($context, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
// IP 归属地 (legacy user_page_header_desc + user_city_s).
|
||||
// IP 归属地由扩展设置统一控制。
|
||||
$uc_city = function_exists('aksrt_get_user_city_badge_html')
|
||||
? aksrt_get_user_city_badge_html((int) $user_id, 'user_center', 'badg')
|
||||
: '';
|
||||
|
||||
Reference in new issue
Block a user