PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.1.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.1.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
210 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: 4.1.0
8 * Domain Path: /languages
9 * WC requires at least: 2.4.0
10 * WC tested up to: 4.8.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 str_replace( '/', '\\', ABSPATH ) => '$ABSPATH\/',
130 WP_CONTENT_DIR => '$WP_CONTENT_DIR/',
131 str_replace( '/', '\\', WP_CONTENT_DIR ) => '$WP_CONTENT_DIR\\',
132 home_url() => '$home_url',
133 site_url() => '$site_url',
134 DB_PASSWORD => '$DB_PASSWORD',
135 DB_USER => '$DB_USER',
136 DB_HOST => '$DB_HOST',
137 DB_NAME => '$DB_NAME',
138 );
139 $keys = array('AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'AUTH_SALT', 'NONCE_KEY', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT');
140 foreach ($keys as $key) {
141 if (defined($key)) {
142 $const_value = constant($key);
143 if (!empty($const_value) && is_string($const_value) && strlen($key) > 3) {
144 $values_to_anonymize[$const_value] = '$' . $key;
145 }
146 }
147 }
148 foreach ( $values_to_anonymize as $search => $replace ) {
149 if ($search) {
150 $value = str_replace( $search, $replace, $value );
151 }
152 }
153 // replace anything like token_auth etc or md5 or sha1 ...
154 $value = preg_replace('/[[:xdigit:]]{31,80}/', 'TOKEN_REPLACED', $value);
155 }
156
157 return $value;
158 }
159
160 $GLOBALS['MATOMO_MARKETPLACE_PLUGINS'] = array();
161
162 function matomo_add_plugin( $plugins_directory, $wp_plugin_file, $is_marketplace_plugin = false ) {
163 if ( ! in_array( $wp_plugin_file, $GLOBALS['MATOMO_PLUGIN_FILES'], true ) ) {
164 $GLOBALS['MATOMO_PLUGIN_FILES'][] = $wp_plugin_file;
165 }
166
167 if ( empty( $GLOBALS['MATOMO_PLUGIN_DIRS'] ) ) {
168 $GLOBALS['MATOMO_PLUGIN_DIRS'] = array();
169 }
170
171 if ( $is_marketplace_plugin && dirname( $wp_plugin_file ) === $plugins_directory ) {
172 $GLOBALS['MATOMO_MARKETPLACE_PLUGINS'][] = $wp_plugin_file;
173 }
174
175 $GLOBALS['MATOMO_PLUGINS_ENABLED'][] = basename( $plugins_directory );
176 $root_dir = dirname( $plugins_directory );
177 foreach ( $GLOBALS['MATOMO_PLUGIN_DIRS'] as $path ) {
178 if ( $path['pluginsPathAbsolute'] === $root_dir ) {
179 return; // already added
180 }
181 }
182
183 $matomo_dir = __DIR__ . '/app';
184 $matomo_dir_parts = explode( DIRECTORY_SEPARATOR, $matomo_dir );
185 $root_dir_parts = explode( DIRECTORY_SEPARATOR, $root_dir );
186 $webroot_dir = '';
187 foreach ( $matomo_dir_parts as $index => $part ) {
188 if ( isset( $root_dir_parts[ $index ] ) && $root_dir_parts[ $index ] === $part ) {
189 continue;
190 }
191 $webroot_dir .= '../';
192 }
193 $GLOBALS['MATOMO_PLUGIN_DIRS'][] = array(
194 'pluginsPathAbsolute' => $root_dir,
195 'webrootDirRelativeToMatomo' => $webroot_dir,
196 );
197 }
198
199 if (matomo_is_app_request() || !empty($GLOBALS['MATOMO_LOADED_DIRECTLY'])) {
200 // prevent layout being broken when thegem theme is used. their lazy items class causes the reporting UI to not appear
201 // because it creates a JS error because of escaping " too often. only breaks when " Activate image loading optimization (for desktops)"
202 // is enabled in the general theme settings
203 add_filter('thegem_lazy_items_need_process_content', '__return_false', 99999999, $args = 0);
204 }
205
206 require_once __DIR__ . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'WpMatomo.php';
207 require 'shared.php';
208 matomo_add_plugin( __DIR__ . '/plugins/WordPress', MATOMO_ANALYTICS_FILE );
209 new WpMatomo();
210