From 02d456b00ba117821fd5665934246bc2664488f4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 26 Aug 2026 23:52:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/FrontSubmit.php | 2 - src/Core/FrontSubmitPay.php | 48 +---------------------- tests/asset-ledger/FrontSubmitPayTest.php | 22 +++++++++++ 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/src/Core/FrontSubmit.php b/src/Core/FrontSubmit.php index 1f5747ea..1ff17247 100644 --- a/src/Core/FrontSubmit.php +++ b/src/Core/FrontSubmit.php @@ -175,8 +175,6 @@ class FrontSubmit { $attachment_id = (int) $attachment_id; wp_update_post(['ID' => $attachment_id, 'post_author' => $user_id]); - update_post_meta($attachment_id, '_aksrt_front_submit_upload_type', $kind); - update_post_meta($attachment_id, '_aksrt_front_submit_upload_user_id', $user_id); $url = wp_get_attachment_url($attachment_id); if (!$url) { diff --git a/src/Core/FrontSubmitPay.php b/src/Core/FrontSubmitPay.php index d930d392..16c5a923 100644 --- a/src/Core/FrontSubmitPay.php +++ b/src/Core/FrontSubmitPay.php @@ -48,7 +48,7 @@ trait FrontSubmitPay { $pay_type = DomainModel::PAY_TYPE_READING; } - $downloads = $this->normalize_front_downloads($raw['downloads'] ?? [], $user_id); + $downloads = DomainModel::sanitize_downloads($raw['downloads'] ?? []); if (!empty($downloads) && $this->user_can_cap('new_post_pay_download', $user_id)) { $pay_type = DomainModel::PAY_TYPE_DOWNLOAD; $meta['downloads'] = $downloads; @@ -202,52 +202,6 @@ trait FrontSubmitPay { return $this->parse_front_points((string) $matches[1]) ?? 0; } - /** - * @param mixed $raw - * @return array> - */ - private function normalize_front_downloads($raw, int $user_id): array { - if (!is_array($raw)) { - return []; - } - $out = []; - foreach ($raw as $row) { - if (!is_array($row)) { - continue; - } - $url = (string) ($row['url'] ?? ''); - $url = esc_url_raw(trim($url)); - if ($url === '') { - continue; - } - $attachment_id = attachment_url_to_postid($url); - if ($attachment_id > 0 && !$this->can_use_front_submit_resource($attachment_id, $user_id)) { - continue; - } - $out[] = [ - 'label' => sanitize_text_field((string) ($row['label'] ?? '')), - 'url' => $url, - 'type' => $attachment_id > 0 ? 'direct' : 'external', - 'extract_code' => sanitize_text_field((string) ($row['extract_code'] ?? '')), - 'copy_key' => sanitize_text_field((string) ($row['copy_key'] ?? '')), - 'copy_val' => sanitize_text_field((string) ($row['copy_val'] ?? '')), - 'class' => sanitize_key((string) ($row['class'] ?? '')), - ]; - } - return DomainModel::sanitize_downloads($out); - } - - private function can_use_front_submit_resource(int $attachment_id, int $user_id): bool { - if ($attachment_id <= 0 || !$this->user_can_cap('upload_resource_attachment', $user_id)) { - return false; - } - $attachment = get_post($attachment_id); - return $attachment instanceof \WP_Post - && $attachment->post_type === 'attachment' - && (int) $attachment->post_author === $user_id - && get_post_meta($attachment_id, '_aksrt_front_submit_upload_type', true) === 'resource'; - } - /** * @param array $meta */ diff --git a/tests/asset-ledger/FrontSubmitPayTest.php b/tests/asset-ledger/FrontSubmitPayTest.php index 89489b2e..a6b173fc 100644 --- a/tests/asset-ledger/FrontSubmitPayTest.php +++ b/tests/asset-ledger/FrontSubmitPayTest.php @@ -106,6 +106,28 @@ final class FrontSubmitPayTest extends TestCase { self::assertSame('jb-blue', $downloads[0]['class']); } + public function test_submit_saves_download_url_without_attachment_ownership_filter(): void { + $url = 'https://localhost/wp-content/uploads/2026/08/resource.zip'; + $result = $this->submit->save(105, [ + 'pay_enabled' => '1', + 'aksrt_pay' => [ + 'price' => '10.00', + 'downloads' => [ + [ + 'url' => $url, + 'label' => '本地资源', + ], + ], + ], + ], $this->settings(false, false)); + + self::assertTrue($result['success']); + $meta = $GLOBALS['aksrt_test_post_meta'][105][DomainModel::PAY_META_KEY]; + self::assertSame(DomainModel::PAY_TYPE_DOWNLOAD, $meta['pay_type']); + self::assertCount(1, $meta['downloads']); + self::assertSame($url, $meta['downloads'][0]['url']); + } + private function settings(bool $vip1_enabled, bool $vip2_enabled): array { return [ 'pay_free_s' => true,