PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.3.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.3.1
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 / Report / Metadata.php
matomo / classes / WpMatomo / Report Last commit date
views 6 years ago Data.php 6 years ago Dates.php 6 years ago Metadata.php 6 years ago Renderer.php 6 years ago
Metadata.php
146 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\Report;
11
12 use Piwik\API\Request;
13 use WpMatomo\Bootstrap;
14 use WpMatomo\Site;
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // if accessed directly
18 }
19
20 class Metadata {
21 public static $CACHE_ALL_REPORTS = array();
22 public static $CACHE_ALL_REPORT_PAGES = array();
23
24 public function get_all_reports() {
25 if ( ! empty( self::$CACHE_ALL_REPORTS ) ) {
26 return self::$CACHE_ALL_REPORTS;
27 }
28
29 $site = new Site();
30 $idsite = $site->get_current_matomo_site_id();
31
32 if ( $idsite ) {
33 Bootstrap::do_bootstrap();
34
35 $all_reports = Request::processRequest(
36 'API.getReportMetadata',
37 array(
38 'idSite' => $idsite,
39 'filter_limit' => - 1,
40 )
41 );
42 foreach ( $all_reports as $single_report ) {
43 if ( isset( $single_report['uniqueId'] ) ) {
44 self::$CACHE_ALL_REPORTS[ $single_report['uniqueId'] ] = $single_report;
45 }
46 }
47 }
48
49 return self::$CACHE_ALL_REPORTS;
50 }
51
52 /**
53 * @internal
54 * tests only
55 */
56 public static function clear_cache() {
57 self::$CACHE_ALL_REPORTS = array();
58 self::$CACHE_ALL_REPORT_PAGES = array();
59 }
60
61 public function find_report_by_unique_id( $unique_id ) {
62 if ($unique_id === Renderer::CUSTOM_UNIQUE_ID_VISITS_OVER_TIME) {
63 return array('uniqueId' => Renderer::CUSTOM_UNIQUE_ID_VISITS_OVER_TIME, 'name' => 'Visits over time');
64 }
65 $all_reports = self::get_all_reports();
66
67 if ( isset( $all_reports[ $unique_id ] ) ) {
68 return $all_reports[ $unique_id ];
69 }
70 }
71
72 public function get_all_report_pages() {
73 if ( ! empty( self::$CACHE_ALL_REPORT_PAGES ) ) {
74 return self::$CACHE_ALL_REPORT_PAGES;
75 }
76
77 $site = new Site();
78 $idsite = $site->get_current_matomo_site_id();
79
80 if ( $idsite ) {
81 Bootstrap::do_bootstrap();
82
83 self::$CACHE_ALL_REPORT_PAGES = Request::processRequest(
84 'API.getReportPagesMetadata',
85 array(
86 'idSite' => $idsite,
87 'filter_limit' => - 1,
88 )
89 );
90 }
91
92 return self::$CACHE_ALL_REPORT_PAGES;
93 }
94
95 public function find_report_page_params_by_report_metadata( $report_metadata ) {
96 if ( empty( $report_metadata['module'] )
97 || empty( $report_metadata['action'] ) ) {
98 return array();
99 }
100
101 $report_pages = self::get_all_report_pages();
102
103 foreach ( $report_pages as $report_page ) {
104 if ( ! empty( $report_page['widgets'] ) ) {
105 foreach ( $report_page['widgets'] as $widget ) {
106 if ( ! empty( $widget['module'] ) && $widget['module'] === $report_metadata['module']
107 && ! empty( $widget['action'] ) && $widget['action'] === $report_metadata['action'] ) {
108 return array(
109 'category' => $report_page['category']['id'],
110 'subcategory' => $report_page['subcategory']['id'],
111 );
112 }
113 }
114 }
115 }
116
117 // we can't resolve all automatically since reportId != widgetId and the used action may differe etc...
118 // we're hard coding some manually
119
120 if ( 'Actions_get' === $report_metadata['uniqueId'] ) {
121 return array(
122 'category' => 'General_Visitors',
123 'subcategory' => 'General_Overview',
124 );
125 } elseif ( 'Goals_get' === $report_metadata['uniqueId'] ) {
126 return array(
127 'category' => 'Goals_Goals',
128 'subcategory' => 'General_Overview',
129 );
130 } elseif ( 'Goals_get_idGoal--ecommerceOrder' === $report_metadata['uniqueId'] ) {
131 return array(
132 'category' => 'Goals_Ecommerce',
133 'subcategory' => 'General_Overview',
134 );
135 } elseif ( 'Goals_getItemsName' === $report_metadata['uniqueId'] ) {
136 return array(
137 'category' => 'Goals_Ecommerce',
138 'subcategory' => 'Goals_Products',
139 );
140 }
141
142 return array();
143 }
144
145 }
146