feat(users): govern profiles and access
Normalize fixed profile fields, profile actions, and the five-column capability matrix for comments, uploads, and downloads.
This commit is contained in:
@@ -183,8 +183,8 @@ class ExtensionController extends ControllerBase {
|
||||
'provider' => (string) ($captcha['provider'] ?? ''),
|
||||
'configured' => !empty($captcha['configured']),
|
||||
'scenes' => $scenes,
|
||||
'download_required' => !empty($features['download_captcha']),
|
||||
'download_active' => !empty($features['download_captcha']) && !empty($scenes['download']),
|
||||
'download_required' => !empty($scenes['download']),
|
||||
'download_active' => !empty($scenes['download']),
|
||||
],
|
||||
'content_audit' => [
|
||||
'enabled' => !empty($services['audit']['enabled']),
|
||||
|
||||
@@ -182,9 +182,7 @@ class GlobalController extends ControllerBase {
|
||||
$params = $this->get_json_params($request);
|
||||
$allowed = [
|
||||
'resource_cpt_enabled' => 'bool',
|
||||
'download_login' => 'bool',
|
||||
'download_credit' => 'bool',
|
||||
'download_captcha' => 'bool',
|
||||
'search_include_resource' => 'bool',
|
||||
];
|
||||
$sanitized = $this->sanitize_fields($params, $allowed);
|
||||
|
||||
@@ -46,7 +46,7 @@ class PermissionsController extends ControllerBase {
|
||||
'groups' => $this->build_capability_groups($defs, $caps, $columns),
|
||||
'summary' => [
|
||||
'cap_count' => count($defs),
|
||||
'group_count' => 3,
|
||||
'group_count' => 5,
|
||||
'column_count' => count($columns),
|
||||
],
|
||||
],
|
||||
@@ -114,6 +114,16 @@ class PermissionsController extends ControllerBase {
|
||||
'title' => __('评论权限', 'aksrt'),
|
||||
'items' => [],
|
||||
],
|
||||
'upload' => [
|
||||
'key' => 'upload',
|
||||
'title' => __('上传权限', 'aksrt'),
|
||||
'items' => [],
|
||||
],
|
||||
'download' => [
|
||||
'key' => 'download',
|
||||
'title' => __('下载权限', 'aksrt'),
|
||||
'items' => [],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($defs as $cap_id => $def) {
|
||||
@@ -122,10 +132,13 @@ class PermissionsController extends ControllerBase {
|
||||
$bucket_key = 'comment';
|
||||
} elseif (str_starts_with($cap_id, 'new_post_')) {
|
||||
$bucket_key = 'post';
|
||||
} elseif (str_starts_with($cap_id, 'upload_')) {
|
||||
$bucket_key = 'upload';
|
||||
} elseif (str_starts_with($cap_id, 'resource_')) {
|
||||
$bucket_key = 'download';
|
||||
}
|
||||
|
||||
$excludes = $def['exclude_roles'] ?? [];
|
||||
$only_roles = $def['roles'] ?? null;
|
||||
$values = $caps[$cap_id] ?? [];
|
||||
|
||||
$visible_columns = [];
|
||||
@@ -133,9 +146,6 @@ class PermissionsController extends ControllerBase {
|
||||
if (in_array($column, $excludes, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($only_roles !== null && !in_array($column, $only_roles, true) && !in_array($column, ['all', 'logged', 'level', 'vip', 'auth'], true)) {
|
||||
continue;
|
||||
}
|
||||
$visible_columns[] = $column;
|
||||
}
|
||||
|
||||
@@ -157,9 +167,6 @@ class PermissionsController extends ControllerBase {
|
||||
'level' => __('等级≥', 'aksrt'),
|
||||
'vip' => __('VIP≥', 'aksrt'),
|
||||
'auth' => __('已认证', 'aksrt'),
|
||||
'moderator' => __('版主', 'aksrt'),
|
||||
'plate_author' => __('超级版主', 'aksrt'),
|
||||
'cat_moderator' => __('分区版主', 'aksrt'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ class SchemaPayment {
|
||||
['label' => '正文底部', 'value' => 'bottom'],
|
||||
['label' => '文章框底部', 'value' => 'box_bottom'],
|
||||
]],
|
||||
['key' => 'pay_free_logged_show', 'label' => '免费资源需登录后下载', 'type' => 'switch', 'default' => false],
|
||||
]],
|
||||
['key' => 'download', 'title' => '下载能力', 'fields' => [
|
||||
['key' => 'payment_download_enable', 'label' => '启用下载能力', 'type' => 'switch', 'default' => false],
|
||||
@@ -308,7 +307,6 @@ class SchemaPayment {
|
||||
['label' => '正文底部', 'value' => 'bottom'],
|
||||
['label' => '文章框底部', 'value' => 'box_bottom'],
|
||||
]],
|
||||
['key' => 'pay_free_logged_show', 'label' => '登录用户显示免费', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'payment_show_ip', 'label' => '显示用户IP', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'payment_show_device', 'label' => '显示设备信息', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'payment_show_order_no', 'label' => '显示订单号', 'type' => 'switch', 'default' => true],
|
||||
|
||||
@@ -11,9 +11,9 @@ class SchemaPermissions {
|
||||
|
||||
public static function build(): array {
|
||||
return [
|
||||
'domain' => 'permissions',
|
||||
'title' => '功能&权限',
|
||||
'sections' => [
|
||||
'domain' => 'permissions',
|
||||
'title' => '功能与权限',
|
||||
'sections' => [
|
||||
'login' => [
|
||||
'key' => 'login',
|
||||
'title' => '人机验证',
|
||||
@@ -54,94 +54,24 @@ class SchemaPermissions {
|
||||
]],
|
||||
],
|
||||
],
|
||||
'comment' => [
|
||||
'key' => 'comment',
|
||||
'title' => '评论权限',
|
||||
'version' => '1.0.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'basic', 'title' => '基础权限', 'fields' => [
|
||||
['key' => 'comment_enabled', 'label' => '全局评论开关', 'type' => 'switch', 'default' => true, 'help' => '关闭后全站禁用评论功能'],
|
||||
['key' => 'comment_guest_allowed', 'label' => '允许游客评论', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_min_length', 'label' => '评论最少字数', 'type' => 'number', 'default' => 2, 'min' => 0, 'max' => 100],
|
||||
['key' => 'comment_max_length', 'label' => '评论最多字数', 'type' => 'number', 'default' => 1000, 'min' => 50, 'max' => 10000],
|
||||
['key' => 'comment_cool_down_seconds', 'label' => '评论冷却时间(秒)', 'type' => 'number', 'default' => 15, 'min' => 0, 'max' => 300],
|
||||
['key' => 'comment_max_links', 'label' => '最大链接数', 'type' => 'number', 'default' => 2, 'min' => 0, 'max' => 10],
|
||||
['key' => 'comment_max_images', 'label' => '最大图片数', 'type' => 'number', 'default' => 3, 'min' => 0, 'max' => 20],
|
||||
]],
|
||||
['key' => 'sensitive', 'title' => '敏感词', 'fields' => [
|
||||
['key' => 'comment_sensitive_words', 'label' => '敏感词列表', 'type' => 'textarea', 'default' => ''],
|
||||
['key' => 'comment_sensitive_action', 'label' => '敏感词处理', 'type' => 'radio', 'default' => 'reject', 'options' => [
|
||||
['label' => '拒绝评论', 'value' => 'reject'],
|
||||
['label' => '替换为***', 'value' => 'replace'],
|
||||
['label' => '转入审核', 'value' => 'pending'],
|
||||
]],
|
||||
['key' => 'comment_sensitive_log', 'label' => '记录敏感词日志', 'type' => 'switch', 'default' => true],
|
||||
]],
|
||||
['key' => 'anti-spam', 'title' => '反垃圾', 'fields' => [
|
||||
['key' => 'comment_link_filter', 'label' => '链接过滤', 'type' => 'switch', 'default' => true, 'help' => '评论包含链接自动进入审核'],
|
||||
['key' => 'comment_flood_protection', 'label' => '防刷评论', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_flood_interval', 'label' => '防刷间隔(秒)', 'type' => 'number', 'default' => 10, 'min' => 3, 'max' => 60],
|
||||
['key' => 'comment_max_per_hour', 'label' => '每小时最大评论数', 'type' => 'number', 'default' => 20, 'min' => 1, 'max' => 200],
|
||||
]],
|
||||
['key' => 'display', 'title' => '展示设置', 'fields' => [
|
||||
['key' => 'comment_avatar_required', 'label' => '要求设置头像', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_nickname_required', 'label' => '要求填写昵称', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_email_required', 'label' => '要求填写邮箱', 'type' => 'switch', 'default' => true],
|
||||
]],
|
||||
],
|
||||
],
|
||||
'attachment' => [
|
||||
'key' => 'attachment',
|
||||
'title' => '附件权限',
|
||||
'version' => '1.0.0',
|
||||
'title' => '附件配置',
|
||||
'version' => '1.1.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'profile', 'title' => '头像与封面', 'fields' => [
|
||||
['key' => 'allow_avatar_upload', 'label' => '允许用户上传头像', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'allow_cover_upload', 'label' => '允许用户上传封面图', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'allow_background_upload', 'label' => '允许用户上传背景图', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'avatar_max_size', 'label' => '头像/封面大小上限 (MB)', 'type' => 'number', 'default' => 2, 'min' => 1, 'max' => 10],
|
||||
['key' => 'profile', 'title' => '用户资料卡背景图', 'fields' => [
|
||||
['key' => 'avatar_max_size', 'label' => '头像/用户资料卡背景图大小上限 (MB)', 'type' => 'number', 'default' => 2, 'min' => 1, 'max' => 10],
|
||||
]],
|
||||
['key' => 'content', 'title' => '内容上传', 'fields' => [
|
||||
['key' => 'allow_submit_images', 'label' => '允许投稿插入图片', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'content', 'title' => '内容上传限制', 'fields' => [
|
||||
['key' => 'submit_image_max_size', 'label' => '投稿图片大小上限 (MB)', 'type' => 'number', 'default' => 5, 'min' => 1, 'max' => 20],
|
||||
['key' => 'allow_comment_images', 'label' => '允许评论插入图片', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_image_max_size', 'label' => '评论图片大小上限 (MB)', 'type' => 'number', 'default' => 2, 'min' => 1, 'max' => 10],
|
||||
]],
|
||||
['key' => 'resource', 'title' => '资源附件', 'fields' => [
|
||||
['key' => 'allow_resource_upload', 'label' => '允许资源附件上传', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'resource', 'title' => '资源附件限制', 'fields' => [
|
||||
['key' => 'resource_max_size', 'label' => '资源附件大小上限 (MB)', 'type' => 'number', 'default' => 50, 'min' => 1, 'max' => 200],
|
||||
]],
|
||||
],
|
||||
],
|
||||
'download' => [
|
||||
'key' => 'download',
|
||||
'title' => '下载权限',
|
||||
'version' => '1.0.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'basic', 'title' => '下载设置', 'fields' => [
|
||||
['key' => 'download_require_login', 'label' => '下载需要登录', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'download_require_credits', 'label' => '允许积分购买模式', 'type' => 'switch', 'default' => false, 'help' => '兼容字段;运行时以 cms_features.download_credit 为准。开启表示 pay_modo=积分 可收银台一次购买,不是按次扣费。'],
|
||||
['key' => 'download_credits_cost', 'label' => '默认积分价参考', 'type' => 'number', 'default' => 1, 'min' => 0, 'max' => 100, 'help' => '仅运营参考/兼容;实际价格以文章付费设置为准。'],
|
||||
['key' => 'download_daily_limit', 'label' => '每日下载限制', 'type' => 'number', 'default' => 0, 'min' => 0, 'help' => '0为不限制'],
|
||||
['key' => 'download_link_expire', 'label' => '下载链接有效期(分钟)', 'type' => 'number', 'default' => 30, 'min' => 5, 'max' => 1440],
|
||||
]],
|
||||
['key' => 'vip', 'title' => 'VIP 特权', 'fields' => [
|
||||
['key' => 'download_vip_free', 'label' => 'VIP 免费下载', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'download_vip_daily_extra', 'label' => 'VIP每日额外次数', 'type' => 'number', 'default' => 10, 'min' => 0, 'max' => 999],
|
||||
]],
|
||||
['key' => 'role', 'title' => '角色权限', 'fields' => [
|
||||
['key' => 'download_role_limits', 'label' => '角色下载限制', 'type' => 'textarea', 'default' => '', 'help' => '格式: role|daily_limit,每行一条'],
|
||||
['key' => 'download_role_size', 'label' => '角色文件大小限制', 'type' => 'textarea', 'default' => '', 'help' => '格式: role|max_size_mb,每行一条'],
|
||||
]],
|
||||
['key' => 'captcha', 'title' => '安全设置', 'fields' => [
|
||||
['key' => 'download_captcha_hint', 'label' => '下载验证码', 'type' => 'notice', 'alertType' => 'info', 'alertContent' => '下载验证码门槛在「功能&权限 → 下载权限」页(cms_features.download_captcha)维护;服务商与场景在「人机验证」。'],
|
||||
['key' => 'download_ip_limit', 'label' => 'IP下载限制', 'type' => 'number', 'default' => 0, 'min' => 0, 'help' => '同一IP每小时最大下载次数,0为不限制'],
|
||||
]],
|
||||
],
|
||||
],
|
||||
'moderation' => [
|
||||
'key' => 'moderation',
|
||||
'title' => '内容审核',
|
||||
@@ -159,9 +89,9 @@ class SchemaPermissions {
|
||||
]],
|
||||
['key' => 'ai', 'title' => 'AI 审核', 'fields' => [
|
||||
['key' => 'ai_enabled', 'label' => '启用 AI 审核', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'enabled', 'value' => true]],
|
||||
['key' => 'ai_api_hint', 'label' => '审核 API 配置', 'type' => 'notice', 'alertType' => 'info', 'alertContent' => 'API 接入(百度/阿里云等)在「扩展 → API内容审核」中统一配置,此处仅控制审核范围和策略。', 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'ai_api_hint', 'label' => '审核 API 配置', 'type' => 'notice', 'alertType' => 'info', 'alertContent' => 'API 接入在「扩展 → API 内容审核」中统一配置;此处仅控制审核范围和策略。', 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'ai_moderate_comments', 'label' => '用户评论', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'ai_moderate_background', 'label' => '用户资料背景', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'ai_moderate_background', 'label' => '用户资料卡背景图', 'type' => 'switch', 'default' => true, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'auto_approve_low_risk', 'label' => '低风险自动通过', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'auto_reject_high_risk', 'label' => '高风险自动拒绝', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
['key' => 'low_risk_max_score', 'label' => '低风险上限', 'type' => 'number', 'default' => 35, 'min' => 0, 'max' => 100, 'dependsOn' => ['key' => 'ai_enabled', 'value' => true]],
|
||||
@@ -175,21 +105,13 @@ class SchemaPermissions {
|
||||
['key' => 'rate_limit_min_interval', 'label' => '最小间隔(秒)', 'type' => 'number', 'default' => 8, 'min' => 1, 'max' => 300, 'dependsOn' => ['key' => 'rate_limit_enabled', 'value' => true]],
|
||||
['key' => 'rate_limit_max_per_hour', 'label' => '每小时上限', 'type' => 'number', 'default' => 15, 'min' => 1, 'max' => 200, 'dependsOn' => ['key' => 'rate_limit_enabled', 'value' => true]],
|
||||
]],
|
||||
['key' => 'geoip', 'title' => 'GeoIP 拦截', 'fields' => [
|
||||
['key' => 'geoip_enabled', 'label' => '启用 GeoIP 拦截', 'type' => 'switch', 'default' => false, 'dependsOn' => ['key' => 'enabled', 'value' => true]],
|
||||
['key' => 'geoip_hint', 'label' => 'IP 数据源', 'type' => 'notice', 'alertType' => 'info', 'alertContent' => '复用「扩展 → IP归属地」中配置的数据源和 API Key。', 'dependsOn' => ['key' => 'geoip_enabled', 'value' => true]],
|
||||
['key' => 'geoip_block_countries', 'label' => '屏蔽国家/地区', 'type' => 'custom', 'default' => [], 'sanitize_type' => 'array', 'dependsOn' => ['key' => 'geoip_enabled', 'value' => true]],
|
||||
]],
|
||||
],
|
||||
],
|
||||
'capabilities' => [
|
||||
'key' => 'capabilities',
|
||||
'title' => '基本权限',
|
||||
'version' => '1.0.0',
|
||||
'version' => '1.1.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
// Live editing uses PermissionsCapabilities.vue + /permissions/capabilities.
|
||||
// Keep an empty schema contract here so domain build() does not fatally call
|
||||
// a missing build_cap_matrix_groups() helper when loading login/moderation.
|
||||
'groups' => [],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -253,8 +253,6 @@ class SchemaPostList {
|
||||
['key' => 'comment_avatar_size', 'label' => '头像大小', 'type' => 'number', 'default' => 48, 'min' => 24, 'max' => 96],
|
||||
]],
|
||||
['key' => 'permissions', 'title' => '评论权限', 'fields' => [
|
||||
['key' => 'comment_require_login', 'label' => '评论需要登录', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_allow_reply', 'label' => '允许回复', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_close_comments', 'label' => '关闭评论', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'comment_edit_window', 'label' => '作者自助编辑时限(分钟)', 'type' => 'number', 'default' => 10, 'min' => 0, 'max' => 1440],
|
||||
]],
|
||||
@@ -262,7 +260,6 @@ class SchemaPostList {
|
||||
['key' => 'comment_smilie', 'label' => 'Emoji表情', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_code', 'label' => '代码插入', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_img', 'label' => '图片上传', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'comment_upload_img', 'label' => '评论图片上传', 'type' => 'switch', 'default' => false],
|
||||
]],
|
||||
['key' => 'interaction', 'title' => '互动功能', 'fields' => [
|
||||
['key' => 'comment_hot_threshold', 'label' => '神评点赞阈值', 'type' => 'number', 'default' => 10, 'min' => 1, 'max' => 999],
|
||||
|
||||
@@ -602,8 +602,6 @@ class SchemaUsers {
|
||||
'groups' => [
|
||||
['key' => 'center', 'title' => '用户中心', 'fields' => [
|
||||
['key' => 'user_center_tabs', 'label' => '用户中心 Tab', 'type' => 'input', 'default' => 'profile,level,comments,favorites,vip,credits,revenue,auth', 'help' => '逗号分隔。level=我的等级;creator=创作中心;revenue=推广收益中心;auth=官方认证;等级、VIP、订单、创作中心、收益中心和认证会按功能开关自动注入'],
|
||||
['key' => 'user_cover_upload', 'label' => '封面上传', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'user_social_links', 'label' => '社交链接', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'user_desc_std', 'label' => '默认签名', 'type' => 'input', 'default' => '这家伙很懒…', 'desc' => '用户未设置个人简介时显示的默认文案'],
|
||||
['key' => 'user_city_s', 'label' => '显示城市(IP 归属地)', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'user_city_type', 'label' => '位置精度', 'type' => 'radio', 'default' => 'province', 'options' => [
|
||||
|
||||
@@ -659,6 +659,9 @@ class UserController extends ControllerBase {
|
||||
if ($user_id <= 0) {
|
||||
return $this->error(__('请先登录', 'aksrt'), 401);
|
||||
}
|
||||
if (!function_exists('aksrt_user_can') || !aksrt_user_can('upload_comment_image', $user_id)) {
|
||||
return $this->error(__('当前账号没有上传评论图片的权限', 'aksrt'), 403);
|
||||
}
|
||||
if (empty($_FILES['image']) && empty($_FILES['file'])) {
|
||||
return $this->error(__('请选择要上传的图片', 'aksrt'), 400);
|
||||
}
|
||||
@@ -667,10 +670,49 @@ class UserController extends ControllerBase {
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
|
||||
$file_key = !empty($_FILES['image']) ? 'image' : 'file';
|
||||
$attachment_id = media_handle_upload($file_key, 0);
|
||||
$file = $_FILES[$file_key];
|
||||
$upload_error = isset($file['error']) ? (int) $file['error'] : UPLOAD_ERR_NO_FILE;
|
||||
if ($upload_error !== UPLOAD_ERR_OK) {
|
||||
return $this->error(__('图片文件上传失败,请重新选择', 'aksrt'), 400);
|
||||
}
|
||||
|
||||
$settings = class_exists('\\AKSRT\\Settings\\Settings') ? \AKSRT\Settings\Settings::get_all() : [];
|
||||
$max_size_mb = max(1, min(10, (int) ($settings['comment_image_max_size'] ?? 2)));
|
||||
$actual_size = !empty($file['tmp_name']) && is_readable($file['tmp_name']) ? (int) filesize($file['tmp_name']) : 0;
|
||||
if ($actual_size <= 0 || $actual_size > $max_size_mb * MB_IN_BYTES) {
|
||||
return $this->error(sprintf(__('图片大小必须在 1 字节至 %dMB 之间', 'aksrt'), $max_size_mb), 413);
|
||||
}
|
||||
|
||||
$mimes = [
|
||||
'jpg|jpeg|jpe' => 'image/jpeg',
|
||||
'png' => 'image/png',
|
||||
'gif' => 'image/gif',
|
||||
'webp' => 'image/webp',
|
||||
];
|
||||
$checked = wp_check_filetype_and_ext($file['tmp_name'], $file['name'], $mimes);
|
||||
$image_size = wp_getimagesize($file['tmp_name']);
|
||||
if (empty($checked['type']) || empty($checked['ext']) || !wp_match_mime_types('image', $checked['type']) || !$image_size || ((int) $image_size[0] * (int) $image_size[1]) > 40000000) {
|
||||
return $this->error(__('仅支持有效的 JPG、PNG、GIF 或 WebP 图片', 'aksrt'), 415);
|
||||
}
|
||||
if (class_exists('\AKSRT\Extensions\ContentAudit')) {
|
||||
$audit = \AKSRT\Extensions\ContentAudit::get_instance()->audit_image((string) $file['tmp_name']);
|
||||
if (empty($audit['passed'])) {
|
||||
return $this->error(__('图片未通过内容审核', 'aksrt'), 422);
|
||||
}
|
||||
}
|
||||
|
||||
$attachment_id = media_handle_upload($file_key, 0, [], [
|
||||
'test_form' => false,
|
||||
'mimes' => $mimes,
|
||||
]);
|
||||
if (is_wp_error($attachment_id)) {
|
||||
return $this->error($attachment_id->get_error_message(), 400);
|
||||
}
|
||||
wp_update_post(['ID' => (int) $attachment_id, 'post_author' => $user_id]);
|
||||
if (!wp_attachment_is_image((int) $attachment_id)) {
|
||||
wp_delete_attachment((int) $attachment_id, true);
|
||||
return $this->error(__('上传文件不是有效图片', 'aksrt'), 415);
|
||||
}
|
||||
$url = wp_get_attachment_url((int) $attachment_id);
|
||||
if (!$url) {
|
||||
return $this->error(__('上传失败', 'aksrt'), 500);
|
||||
|
||||
@@ -54,14 +54,11 @@ trait UserControllerProfileMediaOperations {
|
||||
return $this->error(__('请先登录', 'aksrt'), 401);
|
||||
}
|
||||
|
||||
$center_settings = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_user_center_settings()
|
||||
: ['avatar_upload' => true, 'cover_upload' => true];
|
||||
if ($is_avatar && empty($center_settings['avatar_upload'])) {
|
||||
return $this->error(__('头像上传功能未开启', 'aksrt'), 403);
|
||||
}
|
||||
if (!$is_avatar && (empty($center_settings['cover_upload']) || !aksrt_get_setting('allow_background_upload', false))) {
|
||||
return $this->error(__('背景图上传功能未开启', 'aksrt'), 403);
|
||||
$capability = $is_avatar ? 'upload_avatar' : 'upload_profile_background';
|
||||
if (!function_exists('aksrt_user_can') || !aksrt_user_can($capability, $user_id)) {
|
||||
return $this->error($is_avatar
|
||||
? __('当前账号没有上传头像的权限', 'aksrt')
|
||||
: __('当前账号没有上传用户资料卡背景图的权限', 'aksrt'), 403);
|
||||
}
|
||||
|
||||
$file_key = '';
|
||||
@@ -107,6 +104,12 @@ trait UserControllerProfileMediaOperations {
|
||||
if (!$image_size || empty($image_size[0]) || empty($image_size[1]) || ((int) $image_size[0] * (int) $image_size[1]) > 40000000) {
|
||||
return $this->error(__('图片无效或尺寸过大', 'aksrt'), 415);
|
||||
}
|
||||
if (!$is_avatar && class_exists('\AKSRT\Extensions\ContentAudit')) {
|
||||
$audit = \AKSRT\Extensions\ContentAudit::get_instance()->audit_image((string) $file['tmp_name']);
|
||||
if (empty($audit['passed'])) {
|
||||
return $this->error(__('图片未通过内容审核', 'aksrt'), 422);
|
||||
}
|
||||
}
|
||||
|
||||
$attachment_id = media_handle_upload($file_key, 0, [], [
|
||||
'test_form' => false,
|
||||
|
||||
@@ -451,8 +451,21 @@ trait UserControllerReportOperations {
|
||||
return $this->error('无效的举报类型');
|
||||
}
|
||||
|
||||
$reporter_id = get_current_user_id();
|
||||
if ($reporter_id <= 0) {
|
||||
return $this->error(__('请先登录', 'aksrt'), 401);
|
||||
}
|
||||
if ($target_type === 'user') {
|
||||
if ($target_id === $reporter_id) {
|
||||
return $this->error(__('不能举报自己', 'aksrt'), 400);
|
||||
}
|
||||
if (!function_exists('aksrt_user_can') || !aksrt_user_can('user_report', $reporter_id, $target_id)) {
|
||||
return $this->error(__('当前账号没有举报用户的权限', 'aksrt'), 403);
|
||||
}
|
||||
}
|
||||
|
||||
$report_id = \AKSRT\Messages\ReportCenter::get_instance()->submit(
|
||||
get_current_user_id(),
|
||||
$reporter_id,
|
||||
$target_type,
|
||||
$target_id,
|
||||
$reason,
|
||||
|
||||
Reference in New Issue
Block a user