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
GetStarted.php
127 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\Settings; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // if accessed directly |
| 16 | } |
| 17 | |
| 18 | class GetStarted implements MatomoPageContent { |
| 19 | const NONCE_NAME = 'matomo_enable_tracking'; |
| 20 | const FORM_NAME = 'matomo'; |
| 21 | |
| 22 | /** |
| 23 | * @var Settings |
| 24 | */ |
| 25 | private $settings; |
| 26 | |
| 27 | /** |
| 28 | * @param Settings $settings |
| 29 | */ |
| 30 | public function __construct( $settings ) { |
| 31 | $this->settings = $settings; |
| 32 | } |
| 33 | |
| 34 | public static function register_hooks() { |
| 35 | add_action( 'matomo_before_add_menu', [ self::class, 'on_marketplace_plugin_activated' ] ); |
| 36 | } |
| 37 | |
| 38 | public static function on_marketplace_plugin_activated() { |
| 39 | $settings = new Settings(); |
| 40 | |
| 41 | $is_hidden = self::auto_hide_page_if_steps_completed( $settings ); |
| 42 | if ( |
| 43 | $is_hidden |
| 44 | && isset( $_REQUEST['page'] ) |
| 45 | && Menu::SLUG_GET_STARTED === $_REQUEST['page'] |
| 46 | ) { |
| 47 | wp_safe_redirect( admin_url( 'admin.php?page=' . Menu::SLUG_REPORT_SUMMARY ) ); |
| 48 | exit; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | public static function auto_hide_page_if_steps_completed( Settings $settings ) { |
| 53 | if ( self::should_auto_hide_get_started_page( $settings ) ) { |
| 54 | $settings->apply_changes( |
| 55 | [ |
| 56 | Settings::SHOW_GET_STARTED_PAGE => 0, |
| 57 | ] |
| 58 | ); |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | return false; |
| 64 | } |
| 65 | public function show() { |
| 66 | $was_updated = $this->update_if_submitted(); |
| 67 | $settings = $this->settings; |
| 68 | $can_user_edit = $this->can_user_manage(); |
| 69 | $show_this_page = $this->settings->get_global_option( Settings::SHOW_GET_STARTED_PAGE ); |
| 70 | $matomo_is_marketplace_active = $this->is_marketplace_installed_and_active(); |
| 71 | |
| 72 | $matomo_marketplace_setup_wizard = new MarketplaceSetupWizard(); |
| 73 | $matomo_marketplace_setup_wizard_body = $matomo_marketplace_setup_wizard->get_body( false ); |
| 74 | |
| 75 | include dirname( __FILE__ ) . '/views/get_started.php'; |
| 76 | } |
| 77 | |
| 78 | private function update_if_submitted() { |
| 79 | if ( isset( $_POST ) |
| 80 | && ! empty( $_POST[ self::FORM_NAME ] ) |
| 81 | && is_admin() |
| 82 | && check_admin_referer( self::NONCE_NAME ) |
| 83 | && $this->can_user_manage() ) { |
| 84 | if ( ! empty( $_POST[ self::FORM_NAME ][ Settings::SHOW_GET_STARTED_PAGE ] ) |
| 85 | && 'no' === $_POST[ self::FORM_NAME ][ Settings::SHOW_GET_STARTED_PAGE ] ) { |
| 86 | $this->settings->apply_changes( |
| 87 | [ |
| 88 | Settings::SHOW_GET_STARTED_PAGE => 0, |
| 89 | ] |
| 90 | ); |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | if ( ! empty( $_POST[ self::FORM_NAME ]['track_mode'] ) |
| 95 | && TrackingSettings::TRACK_MODE_DEFAULT === $_POST[ self::FORM_NAME ]['track_mode'] ) { |
| 96 | $this->settings->apply_tracking_related_changes( [ 'track_mode' => TrackingSettings::TRACK_MODE_DEFAULT ] ); |
| 97 | |
| 98 | self::auto_hide_page_if_steps_completed( $this->settings ); |
| 99 | |
| 100 | return true; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | public static function should_auto_hide_get_started_page( Settings $settings ) { |
| 108 | return $settings->is_tracking_enabled() |
| 109 | && self::is_marketplace_installed_and_active(); |
| 110 | } |
| 111 | |
| 112 | public static function is_marketplace_installed_and_active() { |
| 113 | return MarketplaceSetupWizard::is_marketplace_installed() |
| 114 | && is_plugin_active( MarketplaceSetupWizard::MARKETPLACE_PLUGIN_FILE ); |
| 115 | } |
| 116 | |
| 117 | public function can_user_manage() { |
| 118 | $tracking_settings = new TrackingSettings( $this->settings ); |
| 119 | |
| 120 | return $tracking_settings->can_user_manage(); |
| 121 | } |
| 122 | |
| 123 | public function get_title() { |
| 124 | return __( 'Start getting a full picture of your visitors', 'matomo' ); |
| 125 | } |
| 126 | } |
| 127 |