PluginSuggestions
2 months ago
TrackingSettings
2 months ago
views
2 months ago
AccessSettings.php
4 years ago
AdBlockDetector.php
7 months ago
Admin.php
2 months ago
AdminSettings.php
2 months ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
10 months ago
Chart.php
2 months ago
CookieConsent.php
4 years ago
Dashboard.php
2 months ago
ExclusionSettings.php
7 months ago
GeolocationSettings.php
2 years ago
GetStarted.php
2 months ago
ImportWpStatistics.php
2 months ago
Info.php
2 months ago
InvalidIpException.php
4 years ago
Marketplace.php
2 months ago
MarketplaceSetupWizard.php
2 months ago
MarketplaceSetupWizardBody.php
3 months ago
MatomoPage.php
2 months ago
MatomoPageContent.php
2 months ago
Menu.php
2 months ago
PluginMeasurableSettings.php
2 years ago
PrivacySettings.php
1 year ago
SafeModeMenu.php
2 months ago
Summary.php
2 months ago
SystemReport.php
2 months ago
TrackingSettings.php
4 months ago
WhatsNewNotifications.php
2 months ago
Marketplace.php
108 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Matomo - free/libre analytics platform |
| 4 | * |
| 5 | * @link https://matomo.org |
| 6 | * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 7 | * @package matomo |
| 8 | */ |
| 9 | |
| 10 | namespace WpMatomo\Admin; |
| 11 | |
| 12 | use WpMatomo\Feature; |
| 13 | use WpMatomo\Settings; |
| 14 | use WpMatomo\Capabilities; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; // if accessed directly |
| 18 | } |
| 19 | |
| 20 | class Marketplace implements MatomoPageContent { |
| 21 | |
| 22 | /** |
| 23 | * @var Settings |
| 24 | */ |
| 25 | private $settings; |
| 26 | |
| 27 | public function __construct( Settings $settings ) { |
| 28 | $this->settings = $settings; |
| 29 | } |
| 30 | |
| 31 | public function get_active_tab() { |
| 32 | $active_tab = 'marketplace'; |
| 33 | |
| 34 | $valid_tabs = $this->get_valid_tabs(); |
| 35 | |
| 36 | if ( isset( $_REQUEST['tab'] ) |
| 37 | && in_array( wp_unslash( $_REQUEST['tab'] ), $valid_tabs, true ) |
| 38 | ) { |
| 39 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 40 | $active_tab = wp_unslash( $_REQUEST['tab'] ); |
| 41 | } |
| 42 | |
| 43 | return $active_tab; |
| 44 | } |
| 45 | |
| 46 | public function show() { |
| 47 | $settings = $this->settings; |
| 48 | $valid_tabs = []; |
| 49 | $active_tab = ''; |
| 50 | |
| 51 | if ( ! is_plugin_active( MATOMO_MARKETPLACE_PLUGIN_NAME ) ) { |
| 52 | $active_tab = $this->get_active_tab(); |
| 53 | $valid_tabs = $this->get_valid_tabs(); |
| 54 | |
| 55 | $marketplace_setup_wizard = \WpMatomo::get_active_feature( MarketplaceSetupWizard::class ); |
| 56 | } |
| 57 | |
| 58 | $matomo_currency = $this->get_currency_based_on_timezone(); |
| 59 | |
| 60 | include dirname( __FILE__ ) . '/views/marketplace.php'; |
| 61 | } |
| 62 | |
| 63 | private function get_valid_tabs() { |
| 64 | $valid_tabs = [ 'marketplace' ]; |
| 65 | if ( $this->can_user_manage() ) { |
| 66 | if ( current_user_can( 'install_plugins' ) ) { |
| 67 | $valid_tabs[] = 'install'; |
| 68 | } |
| 69 | $valid_tabs[] = 'subscriptions'; |
| 70 | } |
| 71 | return $valid_tabs; |
| 72 | } |
| 73 | |
| 74 | private function can_user_manage() { |
| 75 | // only someone who can activate plugins is allowed to manage subscriptions |
| 76 | if ( $this->is_multisite() ) { |
| 77 | return is_super_admin(); |
| 78 | } |
| 79 | |
| 80 | return current_user_can( Capabilities::KEY_SUPERUSER ); |
| 81 | } |
| 82 | |
| 83 | private function is_multisite() { |
| 84 | return function_exists( 'is_multisite' ) && is_multisite(); |
| 85 | } |
| 86 | |
| 87 | private function get_currency_based_on_timezone() { |
| 88 | if ( ! function_exists( 'wp_timezone' ) ) { |
| 89 | return 'EUR'; |
| 90 | } |
| 91 | |
| 92 | $timezone = \wp_timezone(); |
| 93 | $now = new \DateTime( 'now', $timezone ); |
| 94 | $offset = $now->getOffset() / 3600; |
| 95 | |
| 96 | // if timezone is not european, use USD |
| 97 | if ( $offset >= 0 && $offset <= 4 ) { |
| 98 | return 'EUR'; |
| 99 | } else { |
| 100 | return 'USD'; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | public function get_title() { |
| 105 | return null; |
| 106 | } |
| 107 | } |
| 108 |