PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.14.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.14.2
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 / classes / WpMatomo / Db / Settings.php
matomo / classes / WpMatomo / Db Last commit date
Settings.php 4 years ago WordPress.php 4 years ago WordPressDbStatement.php 4 years ago WordPressTracker.php 4 years ago
Settings.php
127 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\Db;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit; // if accessed directly
14 }
15 /**
16 * We want a real data, not something coming from cache
17 * phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
18 *
19 * This is a report error, so silent the possible errors
20 * phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged
21 *
22 * We cannot use parameters of statements as this is the table names we build
23 * phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
24 * phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
25 */
26 class Settings {
27
28 /**
29 * This feature can be used to read data from matomo tables without needing to bootstrap matomo
30 *
31 * @param string $table_name_to_prefix
32 *
33 * @return string
34 * @api
35 */
36 public function prefix_table_name( $table_name_to_prefix = '' ) {
37 global $wpdb;
38
39 return $wpdb->prefix . MATOMO_DATABASE_PREFIX . $table_name_to_prefix;
40 }
41
42 /**
43 * @return string[]
44 */
45 public function get_matomo_tables() {
46 // we need to hard code them unfortunately for tests cause there are temporary tables used and we can't find a
47 // list of existing temp tables
48 $tables = [
49 'access',
50 'archive_invalidations',
51 'brute_force_log',
52 'changes',
53 'goal',
54 'locks',
55 'log_action',
56 'log_conversion',
57 'log_conversion_item',
58 'log_link_visit_action',
59 'log_profiling',
60 'log_visit',
61 'logger_message',
62 'option',
63 'plugin_setting',
64 'privacy_logdata_anonymizations',
65 'report',
66 'report_subscriptions',
67 'segment',
68 'sequence',
69 'session',
70 'site',
71 'site_setting',
72 'site_url',
73 'tracking_failure',
74 'twofactor_recovery_code',
75 'user',
76 'user_dashboard',
77 'user_language',
78 'user_token_auth',
79 ];
80 if ( ! is_multisite() ) {
81 $tables = array_merge(
82 $tables,
83 [
84 'tagmanager_container',
85 'tagmanager_container_release',
86 'tagmanager_container_version',
87 'tagmanager_tag',
88 'tagmanager_trigger',
89 'tagmanager_variable',
90 ]
91 );
92 }
93
94 return $tables;
95 }
96
97 public function get_installed_matomo_tables() {
98 global $wpdb;
99
100 $table_names = [];
101
102 $tables = $wpdb->get_results( 'SHOW TABLES LIKE "' . $this->prefix_table_name() . '%"', ARRAY_N );
103 foreach ( $tables as $table_name_to_look_for ) {
104 $table_names[] = array_shift( $table_name_to_look_for );
105 }
106
107 $table_names_to_look_for = $this->get_matomo_tables();
108
109 foreach ( range( 2010, gmdate( 'Y' ) + 1 ) as $year ) {
110 foreach ( range( 1, 12 ) as $month ) {
111 $table_names_to_look_for[] = 'archive_numeric_' . $year . '_' . str_pad( $month, 2, '0' );
112 $table_names_to_look_for[] = 'archive_blob_' . $year . '_' . str_pad( $month, 2, '0' );
113 }
114 }
115 $table_names_to_look_for = apply_filters( 'matomo_install_tables', $table_names_to_look_for );
116
117 foreach ( $table_names_to_look_for as $table_name_to_look_for ) {
118 $table_name_to_test = $this->prefix_table_name( $table_name_to_look_for );
119 if ( ! in_array( $table_name_to_test, $table_names, true ) ) {
120 $table_names[] = $table_name_to_test;
121 }
122 }
123
124 return $table_names;
125 }
126 }
127