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
GeolocationSettings.php
72 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\Capabilities; |
| 13 | use WpMatomo\ScheduledTasks; |
| 14 | use WpMatomo\Settings; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; // if accessed directly |
| 18 | } |
| 19 | |
| 20 | class GeolocationSettings implements AdminSettingsInterface { |
| 21 | const NONCE_NAME = 'matomo_geolocation'; |
| 22 | const FORM_NAME = 'matomo_maxmind_license'; |
| 23 | |
| 24 | /** |
| 25 | * @var Settings |
| 26 | */ |
| 27 | private $settings; |
| 28 | |
| 29 | public function __construct( Settings $settings ) { |
| 30 | $this->settings = $settings; |
| 31 | } |
| 32 | |
| 33 | public function get_title() { |
| 34 | return esc_html__( 'Geolocation', 'matomo' ); |
| 35 | } |
| 36 | |
| 37 | public function show_settings() { |
| 38 | $invalid_format = $this->update_if_submitted() === false; |
| 39 | |
| 40 | $current_maxmind_license = $this->settings->get_global_option( 'maxmind_license_key' ); |
| 41 | |
| 42 | include dirname( __FILE__ ) . '/views/geolocation_settings.php'; |
| 43 | } |
| 44 | |
| 45 | private function update_if_submitted() { |
| 46 | if ( isset( $_POST ) |
| 47 | && isset( $_POST[ self::FORM_NAME ] ) |
| 48 | && is_admin() |
| 49 | && check_admin_referer( self::NONCE_NAME ) |
| 50 | && current_user_can( Capabilities::KEY_SUPERUSER ) ) { |
| 51 | $maxmind_license = trim( stripslashes( sanitize_text_field( wp_unslash( $_POST[ self::FORM_NAME ] ) ) ) ); |
| 52 | |
| 53 | if ( empty( $maxmind_license ) ) { |
| 54 | $maxmind_license = ''; |
| 55 | } elseif ( strlen( $maxmind_license ) > 20 || strlen( $maxmind_license ) < 7 || ! ctype_graph( $maxmind_license ) ) { |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | $this->settings->apply_changes( |
| 60 | [ |
| 61 | 'maxmind_license_key' => $maxmind_license, |
| 62 | ] |
| 63 | ); |
| 64 | |
| 65 | // update geoip in the backgronud |
| 66 | wp_schedule_single_event( time() + 10, ScheduledTasks::EVENT_GEOIP ); |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 |