PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Admin / ExclusionSettings.php
matomo / classes / WpMatomo / Admin Last commit date
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
ExclusionSettings.php
138 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\IP;
13 use Piwik\Plugins\SitesManager\API;
14 use WpMatomo\Bootstrap;
15 use WpMatomo\Capabilities;
16 use WpMatomo\Settings;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // if accessed directly
20 }
21
22 class ExclusionSettings implements AdminSettingsInterface {
23 const NONCE_NAME = 'matomo_exclusion';
24 const FORM_NAME = 'matomo_exclusions';
25
26 /**
27 * @var Settings
28 */
29 private $settings;
30
31 public function __construct( Settings $settings ) {
32 $this->settings = $settings;
33 }
34
35 public function get_title() {
36 return esc_html__( 'Exclusions', 'matomo' );
37 }
38
39 private function update_if_submitted() {
40 if ( isset( $_POST )
41 && ! empty( $_POST[ self::FORM_NAME ] )
42 && is_admin()
43 && check_admin_referer( self::NONCE_NAME )
44 && current_user_can( Capabilities::KEY_SUPERUSER ) ) {
45 Bootstrap::do_bootstrap();
46
47 $post = $_POST[ self::FORM_NAME ];
48
49 $api = API::getInstance();
50 if ( isset( $post['excluded_ips'] ) ) {
51 $ips = $this->to_comma_list( $post['excluded_ips'] );
52 if ( $ips !== $api->getExcludedIpsGlobal() ) {
53 $api->setGlobalExcludedIps( $ips );
54 }
55 }
56
57 if ( isset( $post['excluded_query_parameters'] ) ) {
58 $params = $this->to_comma_list( $post['excluded_query_parameters'] );
59 if ( $params !== $api->getExcludedQueryParametersGlobal() ) {
60 $api->setGlobalExcludedQueryParameters( $params );
61 }
62 }
63
64 if ( isset( $post['excluded_user_agents'] ) ) {
65 $useragents = $this->to_comma_list( $post['excluded_user_agents'] );
66 if ( $useragents !== $api->getExcludedUserAgentsGlobal() ) {
67 $api->setGlobalExcludedUserAgents( $useragents );
68 }
69 }
70
71 $keep_fragments = ! empty( $post['keep_url_fragments'] );
72 if ( $keep_fragments != $api->getKeepURLFragmentsGlobal() ) {
73 $api->setKeepURLFragmentsGlobal( $keep_fragments );
74 }
75
76 $setting_values = array( Settings::OPTION_KEY_STEALTH => array() );
77 if ( ! empty( $post[ Settings::OPTION_KEY_STEALTH ] ) ) {
78 $setting_values[ Settings::OPTION_KEY_STEALTH ] = $post[ Settings::OPTION_KEY_STEALTH ];
79 }
80
81 $this->settings->apply_changes( $setting_values );
82
83 return true;
84 }
85
86 return false;
87 }
88
89 private function to_comma_list( $value ) {
90 if ( empty( $value ) ) {
91 return '';
92 }
93 $value = stripslashes( $value ); // WordPress adds slashes
94 $value = str_replace( "\r", '', $value );
95
96 return implode( ',', array_filter( explode( "\n", $value ) ) );
97 }
98
99 private function from_comma_list( $value ) {
100 if ( empty( $value ) ) {
101 return '';
102 }
103
104 return implode( "\n", array_filter( explode( ',', $value ) ) );
105 }
106
107 public function show_settings() {
108 global $wp_roles;
109
110 $was_updated = $this->update_if_submitted();
111
112 Bootstrap::do_bootstrap();
113
114 $api = API::getInstance();
115 $excluded_ips = $this->from_comma_list( $api->getExcludedIpsGlobal() );
116 $excluded_query_params = $this->from_comma_list( $api->getExcludedQueryParametersGlobal() );
117 $excluded_user_agents = $this->from_comma_list( $api->getExcludedUserAgentsGlobal() );
118 $keep_url_fragments = $api->getKeepURLFragmentsGlobal();
119 $current_ip = $this->get_current_ip();
120 $settings = $this->settings;
121
122 include dirname( __FILE__ ) . '/views/exclusion_settings.php';
123 }
124
125 private function get_current_ip() {
126 if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
127 $ip = $_SERVER['HTTP_CLIENT_IP'];
128 } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
129 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
130 } else {
131 $ip = IP::getIpFromHeader();
132 }
133
134 return $ip;
135 }
136
137 }
138