TrackingSettings
4 years ago
views
3 years ago
AccessSettings.php
4 years ago
Admin.php
4 years ago
AdminSettings.php
4 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
4 years ago
Chart.php
4 years ago
CookieConsent.php
4 years ago
Dashboard.php
4 years ago
ExclusionSettings.php
4 years ago
GeolocationSettings.php
4 years ago
GetStarted.php
4 years ago
ImportWpStatistics.php
4 years ago
Info.php
4 years ago
InvalidIpException.php
4 years ago
Marketplace.php
4 years ago
Menu.php
3 years ago
PrivacySettings.php
4 years ago
SafeModeMenu.php
4 years ago
Summary.php
4 years ago
SystemReport.php
3 years ago
TrackingSettings.php
4 years ago
GetStarted.php
76 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 { |
| 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 function show() { |
| 35 | $was_updated = $this->update_if_submitted(); |
| 36 | $settings = $this->settings; |
| 37 | $can_user_edit = $this->can_user_manage(); |
| 38 | $show_this_page = $this->settings->get_global_option( Settings::SHOW_GET_STARTED_PAGE ); |
| 39 | |
| 40 | include dirname( __FILE__ ) . '/views/get_started.php'; |
| 41 | } |
| 42 | |
| 43 | private function update_if_submitted() { |
| 44 | if ( isset( $_POST ) |
| 45 | && ! empty( $_POST[ self::FORM_NAME ] ) |
| 46 | && is_admin() |
| 47 | && check_admin_referer( self::NONCE_NAME ) |
| 48 | && $this->can_user_manage() ) { |
| 49 | if ( ! empty( $_POST[ self::FORM_NAME ][ Settings::SHOW_GET_STARTED_PAGE ] ) |
| 50 | && 'no' === $_POST[ self::FORM_NAME ][ Settings::SHOW_GET_STARTED_PAGE ] ) { |
| 51 | $this->settings->apply_changes( |
| 52 | [ |
| 53 | Settings::SHOW_GET_STARTED_PAGE => 0, |
| 54 | ] |
| 55 | ); |
| 56 | |
| 57 | return true; |
| 58 | } |
| 59 | if ( ! empty( $_POST[ self::FORM_NAME ]['track_mode'] ) |
| 60 | && TrackingSettings::TRACK_MODE_DEFAULT === $_POST[ self::FORM_NAME ]['track_mode'] ) { |
| 61 | $this->settings->apply_tracking_related_changes( [ 'track_mode' => TrackingSettings::TRACK_MODE_DEFAULT ] ); |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | public function can_user_manage() { |
| 71 | $tracking_settings = new TrackingSettings( $this->settings ); |
| 72 | |
| 73 | return $tracking_settings->can_user_manage(); |
| 74 | } |
| 75 | } |
| 76 |