PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / 1.10.14
ووسلام – همگام سازی ووکامرس و باسلام v1.10.14
1.10.19 1.10.20 1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 All 53 releases
sync-basalam / includes / Services / Products / VideoSourceResolver.php

VideoSourceResolver.php in ووسلام – همگام سازی ووکامرس و باسلام 1.10.14, at includes/Services/Products/VideoSourceResolver.php

99 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Services\Products;
4
5 use SyncBasalam\Admin\Settings\SettingsConfig;
6 use SyncBasalam\Utilities\ProductMetaKey;
7
8 defined('ABSPATH') || exit;
9
10 class VideoSourceResolver
11 {
12 private const AUTO_DETECT_META_KEYS = [
13 '_woodmart_product_video',
14 '_woodmart_product_video_gallery',
15 '_product_video',
16 '_product_video_gallery',
17 '_yith_wcpv_product_video',
18 '_elementor_video_url',
19 '_xstore_product_video',
20 'featured_video',
21 '_featured_video',
22 ];
23
24 public static function resolveMetaKey(): ?string
25 {
26 $settings = syncBasalamSettings();
27 $source = $settings->getSettings(SettingsConfig::VIDEO_SOURCE);
28
29 if ($source === 'plugin_box') {
30 return ProductMetaKey::basalamProductVideo();
31 }
32
33 $mode = $settings->getSettings(SettingsConfig::VIDEO_INHERIT_MODE);
34
35 if ($mode === 'manual') {
36 $key = trim((string) $settings->getSettings(SettingsConfig::VIDEO_META_KEY));
37
38 return $key !== '' ? $key : null;
39 }
40
41 return null;
42 }
43
44 public static function resolveValue(int $productId): ?string
45 {
46 $settings = syncBasalamSettings();
47 $source = $settings->getSettings(SettingsConfig::VIDEO_SOURCE);
48
49 if ($source === 'plugin_box') {
50 return self::readMeta($productId, ProductMetaKey::basalamProductVideo());
51 }
52
53 $mode = $settings->getSettings(SettingsConfig::VIDEO_INHERIT_MODE);
54
55 if ($mode === 'manual') {
56 $key = trim((string) $settings->getSettings(SettingsConfig::VIDEO_META_KEY));
57
58 return $key !== '' ? self::readMeta($productId, $key) : null;
59 }
60
61 foreach (self::AUTO_DETECT_META_KEYS as $key) {
62 $value = self::readMeta($productId, $key);
63
64 if ($value !== null) {
65 return $value;
66 }
67 }
68
69 return null;
70 }
71
72 public static function isUsingPluginBox(): bool
73 {
74 $source = syncBasalamSettings()->getSettings(SettingsConfig::VIDEO_SOURCE);
75
76 return $source === 'plugin_box';
77 }
78
79 public static function autoDetectMetaKeys(): array
80 {
81 return self::AUTO_DETECT_META_KEYS;
82 }
83
84 private static function readMeta(int $productId, string $key): ?string
85 {
86 $value = get_post_meta($productId, $key, true);
87
88 if (is_array($value)) {
89 $value = reset($value);
90 }
91
92 if ($value === '' || $value === null || $value === false) {
93 return null;
94 }
95
96 return (string) $value;
97 }
98 }
99