进行了一些小修复
This commit is contained in:
@@ -175,8 +175,6 @@ class FrontSubmit {
|
|||||||
|
|
||||||
$attachment_id = (int) $attachment_id;
|
$attachment_id = (int) $attachment_id;
|
||||||
wp_update_post(['ID' => $attachment_id, 'post_author' => $user_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);
|
$url = wp_get_attachment_url($attachment_id);
|
||||||
if (!$url) {
|
if (!$url) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ trait FrontSubmitPay {
|
|||||||
$pay_type = DomainModel::PAY_TYPE_READING;
|
$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)) {
|
if (!empty($downloads) && $this->user_can_cap('new_post_pay_download', $user_id)) {
|
||||||
$pay_type = DomainModel::PAY_TYPE_DOWNLOAD;
|
$pay_type = DomainModel::PAY_TYPE_DOWNLOAD;
|
||||||
$meta['downloads'] = $downloads;
|
$meta['downloads'] = $downloads;
|
||||||
@@ -202,52 +202,6 @@ trait FrontSubmitPay {
|
|||||||
return $this->parse_front_points((string) $matches[1]) ?? 0;
|
return $this->parse_front_points((string) $matches[1]) ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param mixed $raw
|
|
||||||
* @return array<int, array<string, string>>
|
|
||||||
*/
|
|
||||||
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<string, mixed> $meta
|
* @param array<string, mixed> $meta
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -106,6 +106,28 @@ final class FrontSubmitPayTest extends TestCase {
|
|||||||
self::assertSame('jb-blue', $downloads[0]['class']);
|
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 {
|
private function settings(bool $vip1_enabled, bool $vip2_enabled): array {
|
||||||
return [
|
return [
|
||||||
'pay_free_s' => true,
|
'pay_free_s' => true,
|
||||||
|
|||||||
Reference in New Issue
Block a user