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