TrackingSettings
4 years ago
views
2 years ago
AccessSettings.php
4 years ago
Admin.php
2 years ago
AdminSettings.php
2 years ago
AdminSettingsInterface.php
6 years ago
AdvancedSettings.php
2 years ago
Chart.php
4 years ago
CookieConsent.php
4 years ago
Dashboard.php
4 years ago
ExclusionSettings.php
4 years ago
GeolocationSettings.php
2 years ago
GetStarted.php
4 years ago
ImportWpStatistics.php
4 years ago
Info.php
4 years ago
InvalidIpException.php
4 years ago
Marketplace.php
2 years ago
MarketplaceSetupWizard.php
2 years ago
Menu.php
2 years ago
PluginMeasurableSettings.php
2 years ago
PrivacySettings.php
4 years ago
SafeModeMenu.php
4 years ago
Summary.php
4 years ago
SystemReport.php
2 years ago
TrackingSettings.php
4 years ago
AdvancedSettings.php
122 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 Piwik\CliMulti\Process; |
| 13 | use Piwik\IP; |
| 14 | use WpMatomo\Bootstrap; |
| 15 | use WpMatomo\Capabilities; |
| 16 | use WpMatomo\Settings; |
| 17 | use WpMatomo\Site\Sync\SyncConfig as SiteConfigSync; |
| 18 | |
| 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | exit; // if accessed directly |
| 21 | } |
| 22 | /** |
| 23 | * phpcs:disable WordPress.Security.NonceVerification.Missing |
| 24 | */ |
| 25 | class AdvancedSettings implements AdminSettingsInterface { |
| 26 | const FORM_NAME = 'matomo'; |
| 27 | const NONCE_NAME = 'matomo_advanced'; |
| 28 | |
| 29 | public static $valid_host_headers = [ |
| 30 | 'HTTP_CLIENT_IP', |
| 31 | 'HTTP_X_REAL_IP', |
| 32 | 'HTTP_X_FORWARDED_FOR', |
| 33 | 'HTTP_X_FORWARDED', |
| 34 | 'HTTP_FORWARDED_FOR', |
| 35 | 'HTTP_FORWARDED', |
| 36 | 'HTTP_CF_CONNECTING_IP', |
| 37 | 'HTTP_TRUE_CLIENT_IP', |
| 38 | 'HTTP_X_CLUSTER_CLIENT_IP', |
| 39 | ]; |
| 40 | |
| 41 | /** |
| 42 | * @var Settings |
| 43 | */ |
| 44 | private $settings; |
| 45 | |
| 46 | /** |
| 47 | * @var SiteConfigSync |
| 48 | */ |
| 49 | private $site_config_sync; |
| 50 | |
| 51 | /** |
| 52 | * @param Settings $settings |
| 53 | */ |
| 54 | public function __construct( $settings ) { |
| 55 | $this->settings = $settings; |
| 56 | $this->site_config_sync = new SiteConfigSync( $settings ); |
| 57 | } |
| 58 | |
| 59 | public function get_title() { |
| 60 | return esc_html__( 'Advanced', 'matomo' ); |
| 61 | } |
| 62 | |
| 63 | public function show_settings() { |
| 64 | $was_updated = $this->update_if_submitted(); |
| 65 | |
| 66 | $matomo_client_headers = $this->site_config_sync->get_config_value( 'General', 'proxy_client_headers' ); |
| 67 | if ( empty( $matomo_client_headers ) ) { |
| 68 | $matomo_client_headers = []; |
| 69 | } |
| 70 | |
| 71 | Bootstrap::do_bootstrap(); |
| 72 | $matomo_detected_ip = IP::getIpFromHeader(); |
| 73 | $matomo_delete_all_data = $this->settings->should_delete_all_data_on_uninstall(); |
| 74 | $matomo_disable_async_archiving = $this->settings->is_async_archiving_disabled_by_option(); |
| 75 | $matomo_async_archiving_supported = $this->settings->is_async_archiving_supported(); |
| 76 | |
| 77 | include dirname( __FILE__ ) . '/views/advanced_settings.php'; |
| 78 | } |
| 79 | |
| 80 | private function update_if_submitted() { |
| 81 | if ( isset( $_POST ) |
| 82 | && ! empty( $_POST[ self::FORM_NAME ] ) |
| 83 | && is_admin() |
| 84 | && check_admin_referer( self::NONCE_NAME ) |
| 85 | && $this->can_user_manage() ) { |
| 86 | $this->apply_settings(); |
| 87 | |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | public function can_user_manage() { |
| 95 | return current_user_can( Capabilities::KEY_SUPERUSER ); |
| 96 | } |
| 97 | |
| 98 | private function apply_settings() { |
| 99 | $changes = [ |
| 100 | Settings::DISABLE_ASYNC_ARCHIVING_OPTION_NAME => ! empty( $_POST['matomo']['disable_async_archiving'] ), |
| 101 | ]; |
| 102 | |
| 103 | if ( ! defined( 'MATOMO_REMOVE_ALL_DATA' ) ) { |
| 104 | $changes[ Settings::DELETE_ALL_DATA_ON_UNINSTALL ] = ! empty( $_POST['matomo']['delete_all_data'] ); |
| 105 | } |
| 106 | |
| 107 | $this->settings->apply_changes( $changes ); |
| 108 | |
| 109 | $client_headers = []; |
| 110 | if ( ! empty( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) ) { |
| 111 | $client_header = sanitize_text_field( wp_unslash( $_POST[ self::FORM_NAME ]['proxy_client_header'] ) ); |
| 112 | if ( in_array( $client_header, self::$valid_host_headers, true ) ) { |
| 113 | $client_headers[] = $client_header; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | $this->site_config_sync->set_config_value( 'General', 'proxy_client_headers', $client_headers ); |
| 118 | |
| 119 | return true; |
| 120 | } |
| 121 | } |
| 122 |