views
1 week ago
Assets.php
1 week ago
OptInOptOut.php
1 week ago
OptInPage.php
1 week ago
OptOut.php
1 week ago
PluginActionLinks.php
1 week ago
Shop.php
1 week ago
Tracker.php
1 week ago
Shop.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Tracker; |
| 4 | |
| 5 | /** |
| 6 | * Provides shop data. |
| 7 | */ |
| 8 | class Shop |
| 9 | { |
| 10 | /** |
| 11 | * @var string |
| 12 | */ |
| 13 | private $default_shop = 'wpdesk.pl'; |
| 14 | /** |
| 15 | * @var string |
| 16 | */ |
| 17 | private $default_shop_name = 'WP Desk'; |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | private $default_logo = 'logo.png'; |
| 22 | /** |
| 23 | * @var array<string, string> |
| 24 | */ |
| 25 | private $shops_usage_tracking_pages = ['wpdesk.pl' => 'https://www.wpdesk.pl/sk/', 'wpdesk.net' => 'https://www.wpdesk.net/sk/', 'octolize.com' => 'https://octolize.com/usage-tracking/', 'shopmagic.app' => 'https://www.shopmagic.app/sk/', 'flexibleinvoices.com' => 'https://www.flexibleinvoices.com/sk/', 'flexiblecoupons.net' => 'https://www.flexiblecoupons.net/sk/']; |
| 26 | /** |
| 27 | * @var array<string, string> |
| 28 | */ |
| 29 | private $shop_short_slug = ['wpdesk.pl' => 'pl', 'wpdesk.net' => 'net', 'shopmagic.app' => 'sm', 'flexibleinvoices.com' => 'fi', 'flexiblecoupons.net' => 'fc']; |
| 30 | /** |
| 31 | * @var array<string, string> |
| 32 | */ |
| 33 | private $shops_usage_tracking_names = ['octolize.com' => 'Octolize']; |
| 34 | /** |
| 35 | * @var string |
| 36 | */ |
| 37 | private $shop; |
| 38 | /** |
| 39 | * @var string |
| 40 | */ |
| 41 | private $plugin_slug; |
| 42 | /** |
| 43 | * @param string $shop_url |
| 44 | * @param string $plugin_slug |
| 45 | */ |
| 46 | public function __construct($shop_url, $plugin_slug) |
| 47 | { |
| 48 | $this->shop = $this->prepare_shop_from_shop_url($shop_url); |
| 49 | $this->plugin_slug = $plugin_slug; |
| 50 | } |
| 51 | /** |
| 52 | * @return string |
| 53 | */ |
| 54 | public function get_usage_tracking_page() |
| 55 | { |
| 56 | $usage_tracking_page = isset($this->shops_usage_tracking_pages[$this->shop]) ? $this->shops_usage_tracking_pages[$this->shop] : $this->shops_usage_tracking_pages[$this->default_shop]; |
| 57 | if ($this->shop !== 'octolize.com') { |
| 58 | $shop_shor_slug = isset($this->shop_short_slug[$this->shop]) ? $this->shop_short_slug[$this->default_shop] : 'pl'; |
| 59 | $usage_tracking_page .= $this->plugin_slug . '-usage-tracking-' . $shop_shor_slug; |
| 60 | } |
| 61 | return apply_filters_ref_array('wpdesk/tracker/usage_tracking_page', [$usage_tracking_page, $this->shop]); |
| 62 | } |
| 63 | /** |
| 64 | * @return string |
| 65 | */ |
| 66 | public function get_shop_name() |
| 67 | { |
| 68 | return apply_filters_ref_array('wpdesk/tracker/shop_name', [$this->shops_usage_tracking_names[$this->shop] ?? $this->default_shop_name, $this->shop]); |
| 69 | } |
| 70 | /** |
| 71 | * @return string |
| 72 | */ |
| 73 | public function get_shop_logo_file() |
| 74 | { |
| 75 | $logo_file = isset($this->shops_usage_tracking_pages[$this->shop]) ? $this->shop : $this->default_shop; |
| 76 | $logo_file .= '.png'; |
| 77 | $logo_file = apply_filters_ref_array('wpdesk/tracker/logo_file', [$logo_file, $this->shop]); |
| 78 | // Look for our assets folder from package root directory. |
| 79 | if (!file_exists(dirname(__DIR__) . '/assets/images/' . $logo_file)) { |
| 80 | $logo_file = $this->default_logo; |
| 81 | } |
| 82 | return $logo_file; |
| 83 | } |
| 84 | /** |
| 85 | * @param string $shop_url |
| 86 | */ |
| 87 | private function prepare_shop_from_shop_url($shop_url) |
| 88 | { |
| 89 | $host = parse_url($shop_url, \PHP_URL_HOST); |
| 90 | return str_replace('www.', '', $host ?? ''); |
| 91 | } |
| 92 | } |
| 93 |