Admin
6 years ago
Commands
6 years ago
Db
6 years ago
Ecommerce
6 years ago
Report
6 years ago
Site
6 years ago
TrackingCode
6 years ago
User
6 years ago
views
6 years ago
API.php
6 years ago
Access.php
6 years ago
AjaxTracker.php
6 years ago
Annotations.php
6 years ago
Bootstrap.php
6 years ago
Capabilities.php
6 years ago
Compatibility.php
6 years ago
Email.php
6 years ago
Installer.php
6 years ago
Logger.php
6 years ago
OptOut.php
6 years ago
Paths.php
6 years ago
PrivacyBadge.php
6 years ago
Referral.php
6 years ago
Roles.php
6 years ago
ScheduledTasks.php
6 years ago
Settings.php
6 years ago
Site.php
6 years ago
TrackingCode.php
6 years ago
Uninstaller.php
6 years ago
Updater.php
6 years ago
User.php
6 years ago
OptOut.php
75 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; |
| 11 | |
| 12 | use WP_Roles; |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit; // if accessed directly |
| 16 | } |
| 17 | |
| 18 | class OptOut { |
| 19 | |
| 20 | public function register_hooks() { |
| 21 | add_shortcode( 'matomo_opt_out', array( $this, 'show_opt_out' ) ); |
| 22 | } |
| 23 | |
| 24 | public function show_opt_out( $atts ) { |
| 25 | $a = shortcode_atts( |
| 26 | array( |
| 27 | 'language' => '', |
| 28 | 'background_color' => '', |
| 29 | 'font_color' => '', |
| 30 | 'font_size' => '', |
| 31 | 'font_family' => '', |
| 32 | 'width' => '600', |
| 33 | 'height' => '200', |
| 34 | ), |
| 35 | $atts |
| 36 | ); |
| 37 | |
| 38 | $url = plugins_url( 'app', MATOMO_ANALYTICS_FILE ) . '/index.php'; |
| 39 | |
| 40 | $map = array( |
| 41 | 'background_color' => 'backgroundColor', |
| 42 | 'font_color' => 'fontColor', |
| 43 | 'font_size' => 'fontSize', |
| 44 | 'font_family' => 'fontFamily', |
| 45 | ); |
| 46 | $params = array( |
| 47 | 'module' => 'CoreAdminHome', |
| 48 | 'action' => 'optOut', |
| 49 | ); |
| 50 | if ( ! empty( $a['language'] ) ) { |
| 51 | $params['language'] = $a['language']; |
| 52 | } |
| 53 | foreach ( $map as $param => $urlparam ) { |
| 54 | if ( ! empty( $a[ $param ] ) ) { |
| 55 | $params[ $urlparam ] = rawurlencode( $a[ $param ] ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | $url = $url . '?' . http_build_query( $params ); |
| 60 | $sizes = array( 'width', 'height' ); |
| 61 | $add_style = ''; |
| 62 | foreach ( $sizes as $size ) { |
| 63 | if ( is_numeric( $a[ $size ] ) || preg_match( '/\d+px/', $a[ $size ] ) || preg_match( '/\d+%/', $a[ $size ] ) ) { |
| 64 | if ( is_numeric( $a[ $size ] ) ) { |
| 65 | $a[ $size ] = $a[ $size ] . 'px'; |
| 66 | } |
| 67 | $add_style .= $size . ':' . $a[ $size ] . ';'; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return '<iframe style="border: 0; ' . $add_style . '" src="' . $url . '"></iframe>'; |
| 72 | } |
| 73 | |
| 74 | } |
| 75 |