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 / Renderer.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
Renderer.php
115 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 WpMatomo\Capabilities;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // if accessed directly
16 }
17
18 class Renderer {
19 CONST CUSTOM_UNIQUE_ID_VISITS_OVER_TIME = 'visits_over_time';
20
21 public function register_hooks() {
22 add_shortcode( 'matomo_report', array( $this, 'show_report' ) );
23 }
24
25 public function show_visits_over_time($limit)
26 {
27 $cannot_view = $this->check_cannot_view();
28 if ($cannot_view) {
29 return $cannot_view;
30 }
31
32 if (is_numeric($limit)) {
33 $limit = (int) $limit;
34 } else {
35 $limit = 14;
36 }
37
38 $report_meta = array('module' => 'VisitsSummary', 'action' => 'get');
39
40 $data = new Data();
41 $report = $data->fetch_report($report_meta, 'day', 'last' . $limit, 'label', $limit);
42 $first_metric_name = 'nb_visits';
43
44 ob_start();
45
46 include 'views/table_map_no_dimension.php';
47
48 return ob_get_clean();
49 }
50
51 private function check_cannot_view()
52 {
53 if ( ! current_user_can( Capabilities::KEY_VIEW ) ) {
54 // not needed as processRequest checks permission anyway but it's faster this way and double ensures to not
55 // letting users view it when they have no access.
56 return esc_html__( 'Sorry, you are not allowed to view this report.', 'matomo' );
57 }
58 }
59
60 public function show_report( $atts ) {
61 $a = shortcode_atts(
62 array(
63 'unique_id' => '',
64 'report_date' => Dates::YESTERDAY,
65 'limit' => 10,
66 ),
67 $atts
68 );
69
70 $cannot_view = $this->check_cannot_view();
71 if ($cannot_view) {
72 return $cannot_view;
73 }
74
75 if ($a['unique_id'] === 'visits_over_time') {
76 $is_default_limit = $a['limit'] === 10;
77 if ($is_default_limit) {
78 $a['limit'] = 14;
79 }
80 return $this->show_visits_over_time($a['limit']);
81 }
82
83 $metadata = new Metadata();
84 $report_meta = $metadata->find_report_by_unique_id( $a['unique_id'] );
85
86 if ( empty( $report_meta ) ) {
87 return sprintf( esc_html__( 'Report %s not found', 'matomo' ), esc_html( $a['unique_id'] ) );
88 }
89
90 $metric_keys = array_keys( $report_meta['metrics'] );
91 $first_metric_name = reset( $metric_keys );
92 $first_metric_display_name = reset( $report_meta['metrics'] );
93
94 $dates = new Dates();
95 list( $period, $date ) = $dates->detect_period_and_date( $a['report_date'] );
96
97 $report_data = new Data();
98 $report = $report_data->fetch_report( $report_meta, $period, $date, $first_metric_name, $a['limit'] );
99 $has_report_data = ! empty( $report['reportData'] ) && $report['reportData']->getRowsCount();
100
101 ob_start();
102
103 if ( ! $has_report_data ) {
104 include 'views/table_no_data.php';
105 } elseif ( empty( $report_meta['dimension'] ) ) {
106 include 'views/table_no_dimension.php';
107 } else {
108 include 'views/table.php';
109 }
110
111 return ob_get_clean();
112 }
113
114 }
115