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
Info.php
71 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 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // if accessed directly |
| 16 | } |
| 17 | |
| 18 | class Info { |
| 19 | const NONCE_NAME = 'matomo_newsletter'; |
| 20 | const FORM_NAME = 'matomo_newsletter_signup'; |
| 21 | |
| 22 | private function update_if_submitted() { |
| 23 | if ( isset( $_POST ) |
| 24 | && ! empty( $_POST[ self::FORM_NAME ] ) |
| 25 | && is_admin() |
| 26 | && check_admin_referer( self::NONCE_NAME ) |
| 27 | && $this->show_newsletter_signup() |
| 28 | && current_user_can( Capabilities::KEY_VIEW ) ) { |
| 29 | $user = wp_get_current_user(); |
| 30 | $locale = explode( '_', get_user_locale( $user->ID ) ); |
| 31 | wp_remote_get( |
| 32 | 'https://api.matomo.org/1.0/subscribeNewsletter/?' . http_build_query( |
| 33 | [ |
| 34 | 'email' => $user->user_email, |
| 35 | 'wordpress' => 1, |
| 36 | 'language' => $locale[0], |
| 37 | ] |
| 38 | ) |
| 39 | ); |
| 40 | update_user_meta( $user->ID, self::FORM_NAME, '1' ); |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | private function show_newsletter_signup() { |
| 47 | if ( ! is_user_logged_in() ) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | $user = wp_get_current_user(); |
| 52 | |
| 53 | return ! get_user_meta( $user->ID, self::FORM_NAME, true ); |
| 54 | } |
| 55 | |
| 56 | public function show() { |
| 57 | $this->render( 'info' ); |
| 58 | } |
| 59 | |
| 60 | public function show_multisite() { |
| 61 | $this->render( 'info_multisite' ); |
| 62 | } |
| 63 | |
| 64 | private function render( $template ) { |
| 65 | $signedup_newsletter = $this->update_if_submitted(); |
| 66 | $show_newsletter = $this->show_newsletter_signup(); |
| 67 | |
| 68 | include dirname( __FILE__ ) . '/views/' . $template . '.php'; |
| 69 | } |
| 70 | } |
| 71 |