PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 1.0.5
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v1.0.5
5.13.0 5.12.1 5.12.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 / 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
143 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 $all_reports = self::get_all_reports();
63
64 if ( isset( $all_reports[ $unique_id ] ) ) {
65 return $all_reports[ $unique_id ];
66 }
67 }
68
69 public function get_all_report_pages() {
70 if ( ! empty( self::$CACHE_ALL_REPORT_PAGES ) ) {
71 return self::$CACHE_ALL_REPORT_PAGES;
72 }
73
74 $site = new Site();
75 $idsite = $site->get_current_matomo_site_id();
76
77 if ( $idsite ) {
78 Bootstrap::do_bootstrap();
79
80 self::$CACHE_ALL_REPORT_PAGES = Request::processRequest(
81 'API.getReportPagesMetadata',
82 array(
83 'idSite' => $idsite,
84 'filter_limit' => - 1,
85 )
86 );
87 }
88
89 return self::$CACHE_ALL_REPORT_PAGES;
90 }
91
92 public function find_report_page_params_by_report_metadata( $report_metadata ) {
93 if ( empty( $report_metadata['module'] )
94 || empty( $report_metadata['action'] ) ) {
95 return array();
96 }
97
98 $report_pages = self::get_all_report_pages();
99
100 foreach ( $report_pages as $report_page ) {
101 if ( ! empty( $report_page['widgets'] ) ) {
102 foreach ( $report_page['widgets'] as $widget ) {
103 if ( ! empty( $widget['module'] ) && $widget['module'] === $report_metadata['module']
104 && ! empty( $widget['action'] ) && $widget['action'] === $report_metadata['action'] ) {
105 return array(
106 'category' => $report_page['category']['id'],
107 'subcategory' => $report_page['subcategory']['id'],
108 );
109 }
110 }
111 }
112 }
113
114 // we can't resolve all automatically since reportId != widgetId and the used action may differe etc...
115 // we're hard coding some manually
116
117 if ( 'Actions_get' === $report_metadata['uniqueId'] ) {
118 return array(
119 'category' => 'General_Visitors',
120 'subcategory' => 'General_Overview',
121 );
122 } elseif ( 'Goals_get' === $report_metadata['uniqueId'] ) {
123 return array(
124 'category' => 'Goals_Goals',
125 'subcategory' => 'General_Overview',
126 );
127 } elseif ( 'Goals_get_idGoal--ecommerceOrder' === $report_metadata['uniqueId'] ) {
128 return array(
129 'category' => 'Goals_Ecommerce',
130 'subcategory' => 'General_Overview',
131 );
132 } elseif ( 'Goals_getItemsName' === $report_metadata['uniqueId'] ) {
133 return array(
134 'category' => 'Goals_Ecommerce',
135 'subcategory' => 'Goals_Products',
136 );
137 }
138
139 return array();
140 }
141
142 }
143