PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.10.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.10.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 / Dates.php
matomo / classes / WpMatomo / Report Last commit date
views 3 months ago Data.php 2 months ago Dates.php 1 year ago Metadata.php 1 year ago Renderer.php 2 months ago
Dates.php
136 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\Plugins\UsersManager\UserPreferences;
13 use WpMatomo\Bootstrap;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // if accessed directly
17 }
18
19 class Dates {
20 const TODAY = 'today';
21 const YESTERDAY = 'yesterday';
22 const THIS_WEEK = 'thisweek';
23 const LAST_WEEK = 'lastweek';
24 const THIS_MONTH = 'thismonth';
25 const LAST_MONTH = 'lastmonth';
26 const THIS_YEAR = 'thisyear';
27
28 public function get_supported_dates() {
29 return [
30 self::YESTERDAY => 'Yesterday',
31 self::TODAY => 'Today',
32 self::THIS_WEEK => 'This week',
33 self::LAST_WEEK => 'Last week',
34 self::THIS_MONTH => 'This month',
35 self::LAST_MONTH => 'Last month',
36 self::THIS_YEAR => 'This year',
37 ];
38 }
39
40 public function detect_period_and_date( $report_date ) {
41 $period = 'day';
42 $date = 'yesterday';
43
44 switch ( $report_date ) {
45 case self::TODAY:
46 $period = 'day';
47 $date = 'today';
48 break;
49 case self::YESTERDAY:
50 $period = 'day';
51 $date = 'yesterday';
52 break;
53 case self::THIS_MONTH:
54 $period = 'month';
55 $date = 'today';
56 break;
57 case self::LAST_MONTH:
58 $period = 'month';
59 $date = gmdate( 'Y-m-d', strtotime( '1 month ago' ) );
60 break;
61 case self::THIS_WEEK:
62 $period = 'week';
63 $date = 'today';
64 break;
65 case self::LAST_WEEK:
66 $period = 'week';
67 $date = gmdate( 'Y-m-d', strtotime( '1 week ago' ) );
68 break;
69 case self::THIS_YEAR:
70 $period = 'year';
71 $date = 'today';
72 break;
73 default:
74 if ( preg_match( '/\d{4}-\d{2}-\d{2}/', $report_date ) ) {
75 $period = 'day';
76 $date = $report_date;
77 }
78 }
79
80 return [ $period, $date ];
81 }
82
83 public function get_date_from_query() {
84 Bootstrap::do_bootstrap();
85
86 $report_dates = $this->get_supported_dates();
87
88 $report_date = 'yesterday';
89
90 $user_preference = new UserPreferences();
91 $default_date = $user_preference->getDefaultDate();
92 $report_period = $user_preference->getDefaultPeriod();
93 switch ( $report_period ) {
94 case 'day':
95 $report_date = $default_date;
96 break;
97 case 'year':
98 case 'month':
99 case 'week':
100 switch ( $default_date ) {
101 case 'yesterday':
102 $report_date = 'last' . $report_period;
103 break;
104 case 'today':
105 $report_date = 'this' . $report_period;
106 break;
107 }
108 break;
109 case 'range':
110 switch ( $default_date ) {
111 case 'previous30':
112 $report_date = 'lastmonth';
113 break;
114 case 'previous7':
115 $report_date = 'lastweek';
116 break;
117 case 'last30':
118 $report_date = 'thismonth';
119 break;
120 case 'last7':
121 $report_date = 'thisweek';
122 break;
123 default:
124 break;
125 }
126 break;
127 default:
128 break;
129 }
130 if ( isset( $_REQUEST['report_date'] ) && isset( $report_dates[ $_REQUEST['report_date'] ] ) ) {
131 $report_date = sanitize_text_field( wp_unslash( $_REQUEST['report_date'] ) );
132 }
133 return $report_date;
134 }
135 }
136