PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.2.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.2.0
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 / matomo.php
matomo Last commit date
app 5 years ago assets 5 years ago classes 5 years ago config 5 years ago languages 6 years ago plugins 5 years ago .htaccess 6 years ago LEGALNOTICE 6 years ago LICENSE 6 years ago matomo.php 5 years ago readme.txt 5 years ago shared.php 6 years ago uninstall.php 6 years ago
matomo.php
202 lines
1 <?php
2 /**
3 * Plugin Name: Matomo Analytics - Ethical Stats. Powerful Insights.
4 * Description: The #1 Google Analytics alternative that gives you full control over your data and protects the privacy for your users. Free, secure and open.
5 * Author: Matomo
6 * Author URI: https://matomo.org
7 * Version: 1.2.0
8 * Domain Path: /languages
9 * WC requires at least: 2.4.0
10 * WC tested up to: 4.0.0
11 *
12 * Matomo - free/libre analytics platform
13 *
14 * @link https://matomo.org
15 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
16 * @package matomo
17 */
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit; // if accessed directly
21 }
22
23 load_plugin_textdomain( 'matomo', false, basename( dirname( __FILE__ ) ) . '/languages' );
24
25 if ( ! defined( 'MATOMO_ANALYTICS_FILE' ) ) {
26 define( 'MATOMO_ANALYTICS_FILE', __FILE__ );
27 }
28
29 if ( ! defined('MATOMO_MARKETPLACE_PLUGIN_NAME' )) {
30 define( 'MATOMO_MARKETPLACE_PLUGIN_NAME', 'matomo-marketplace-for-wordpress/matomo-marketplace-for-wordpress.php' );
31 }
32
33 $GLOBALS['MATOMO_PLUGINS_ENABLED'] = array();
34
35 /** MATOMO_PLUGIN_FILES => used to check for updates etc */
36 $GLOBALS['MATOMO_PLUGIN_FILES'] = array( MATOMO_ANALYTICS_FILE );
37
38 function matomo_has_compatible_content_dir() {
39 if ( !empty( $_SERVER['MATOMO_WP_ROOT_PATH'] )
40 && file_exists( rtrim($_SERVER['MATOMO_WP_ROOT_PATH'], '/') . '/wp-load.php' ) ) {
41 return true;
42 }
43
44 if ( ! defined( 'WP_CONTENT_DIR' ) ) {
45 return false;
46 }
47
48 $contentDir = rtrim(rtrim( WP_CONTENT_DIR, '/' ), DIRECTORY_SEPARATOR );
49 $contentDir = wp_normalize_path($contentDir);
50 $absPath = wp_normalize_path(ABSPATH);
51
52 $absPaths = array(
53 $absPath . 'wp-content',
54 $absPath . '/wp-content',
55 $absPath . DIRECTORY_SEPARATOR . 'wp-content'
56 );
57
58 if (in_array($contentDir, $absPaths, true)) {
59 return true;
60 }
61
62 $wpload_base = '../../../wp-load.php';
63 $wpload_full = dirname( __FILE__ ) . '/' . $wpload_base;
64 if ( file_exists($wpload_full ) && is_readable( $wpload_full ) ) {
65 return true;
66 } elseif (realpath( $wpload_full ) && file_exists(realpath( $wpload_full )) && is_readable(realpath( $wpload_full ))) {
67 return true;
68 } elseif (!empty($_SERVER['SCRIPT_FILENAME']) && file_exists($_SERVER['SCRIPT_FILENAME'])) {
69 // seems symlinked... eg the wp-content dir or wp-content/plugins dir is symlinked from some very much other place...
70 $wpload_full = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $wpload_base;
71 if ( file_exists($wpload_full ) ) {
72 return true;
73 } elseif (realpath( $wpload_full ) && file_exists(realpath( $wpload_full ))) {
74 return true;
75 } elseif (file_exists(dirname( $_SERVER['SCRIPT_FILENAME'] )) . '/wp-load.php') {
76 return true;
77 }
78 }
79
80 // look in plugins directory if there is a config file for us
81 $wpload_config = dirname(__FILE__) . '/../matomo.wpload_dir.php';
82 if (file_exists( $wpload_config) && is_readable($wpload_config)) {
83 $content = @file_get_contents($wpload_config); // we do not include that file for security reasons
84 if (!empty($content)) {
85 $content = str_replace(array('<?php', 'exit;'), '', $content);
86 $content = preg_replace('/\s/', '', $content);
87 $content = trim(ltrim(trim($content), '#')); // the path may be commented out # /abs/path
88 if (strpos($content, DIRECTORY_SEPARATOR) === 0) {
89 $wpload_file = rtrim($content, DIRECTORY_SEPARATOR) . '/wp-load.php';
90 return file_exists($wpload_file) && is_readable($wpload_file);
91 }
92 }
93 }
94
95 return false;
96 }
97
98 function matomo_header_icon( $full = false ) {
99 $file = 'logo';
100 if ($full) {
101 $file = 'logo-full';
102 }
103 echo '<img height="32" src="' . plugins_url( 'assets/img/'.$file.'.png', MATOMO_ANALYTICS_FILE ) . '" class="matomo-header-icon">';
104 }
105
106 function matomo_is_app_request() {
107 return ! empty( $_SERVER['SCRIPT_NAME'] )
108 && ( substr( $_SERVER['SCRIPT_NAME'], - 1 * strlen( 'matomo/app/index.php' ) ) === 'matomo/app/index.php' );
109 }
110
111 function matomo_has_tag_manager() {
112 if ( defined( 'MATOMO_ENABLE_TAG_MANAGER' ) ) {
113 return !empty(MATOMO_ENABLE_TAG_MANAGER);
114 }
115
116 $is_multisite = function_exists( 'is_multisite' ) && is_multisite();
117 if ( $is_multisite ) {
118 return false;
119 }
120
121 return true;
122 }
123
124 function matomo_anonymize_value( $value ) {
125 if ( is_string( $value ) && ! empty( $value ) ) {
126 $values_to_anonymize = array(
127 ABSPATH => '$ABSPATH/',
128 str_replace( '/', '\/', ABSPATH ) => '$ABSPATH\/',
129 WP_CONTENT_DIR => '$WP_CONTENT_DIR/',
130 home_url() => '$home_url',
131 site_url() => '$site_url',
132 DB_PASSWORD => '$DB_PASSWORD',
133 DB_USER => '$DB_USER',
134 DB_HOST => '$DB_HOST',
135 DB_NAME => '$DB_NAME',
136 );
137 $keys = array('AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'AUTH_SALT', 'NONCE_KEY', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT');
138 foreach ($keys as $key) {
139 if (defined($key)) {
140 $const_value = constant($key);
141 if (!empty($const_value) && is_string($const_value) && strlen($key) > 3) {
142 $values_to_anonymize[$const_value] = '$' . $key;
143 }
144 }
145 }
146 foreach ( $values_to_anonymize as $search => $replace ) {
147 if ($search) {
148 $value = str_replace( $search, $replace, $value );
149 }
150 }
151 // replace anything like token_auth etc or md5 or sha1 ...
152 $value = preg_replace('/[[:xdigit:]]{31,80}/', 'TOKEN_REPLACED', $value);
153 }
154
155 return $value;
156 }
157
158 $GLOBALS['MATOMO_MARKETPLACE_PLUGINS'] = array();
159
160 function matomo_add_plugin( $plugins_directory, $wp_plugin_file, $is_marketplace_plugin = false ) {
161 if ( ! in_array( $wp_plugin_file, $GLOBALS['MATOMO_PLUGIN_FILES'], true ) ) {
162 $GLOBALS['MATOMO_PLUGIN_FILES'][] = $wp_plugin_file;
163 }
164
165 if ( empty( $GLOBALS['MATOMO_PLUGIN_DIRS'] ) ) {
166 $GLOBALS['MATOMO_PLUGIN_DIRS'] = array();
167 }
168
169 if ( $is_marketplace_plugin && dirname( $wp_plugin_file ) === $plugins_directory ) {
170 $GLOBALS['MATOMO_MARKETPLACE_PLUGINS'][] = $wp_plugin_file;
171 }
172
173 $GLOBALS['MATOMO_PLUGINS_ENABLED'][] = basename( $plugins_directory );
174 $root_dir = dirname( $plugins_directory );
175 foreach ( $GLOBALS['MATOMO_PLUGIN_DIRS'] as $path ) {
176 if ( $path['pluginsPathAbsolute'] === $root_dir ) {
177 return; // already added
178 }
179 }
180
181 $matomo_dir = __DIR__ . '/app';
182 $matomo_dir_parts = explode( DIRECTORY_SEPARATOR, $matomo_dir );
183 $root_dir_parts = explode( DIRECTORY_SEPARATOR, $root_dir );
184 $webroot_dir = '';
185 foreach ( $matomo_dir_parts as $index => $part ) {
186 if ( isset( $root_dir_parts[ $index ] ) && $root_dir_parts[ $index ] === $part ) {
187 continue;
188 }
189 $webroot_dir .= '../';
190 }
191 $GLOBALS['MATOMO_PLUGIN_DIRS'][] = array(
192 'pluginsPathAbsolute' => $root_dir,
193 'webrootDirRelativeToMatomo' => $webroot_dir,
194 );
195 }
196
197
198 require_once __DIR__ . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'WpMatomo.php';
199 require 'shared.php';
200 matomo_add_plugin( __DIR__ . '/plugins/WordPress', MATOMO_ANALYTICS_FILE );
201 new WpMatomo();
202