PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.37
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.37
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Analytics / Metrics / Views.php

Views.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.37, at Inc/Core/Analytics/Metrics/Views.php

229 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.1.37 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2025 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Analytics\Metrics;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Views extends Metric
20 {
21 public function getData()
22 {
23 $this->applyFilters();
24
25 $sql = "SELECT
26 {$this->getSelect()}
27 FROM
28 {$this->wpdb->prefix}firebox_logs as l
29 {$this->getJOINs()}
30 CROSS JOIN (
31 SELECT '%s' AS start_date, '%s' AS end_date
32 ) AS outer_query
33 WHERE
34 1
35 {$this->getWherePeriod()}
36 {$this->sql_filters}
37 {$this->getWhere()}
38 {$this->getGroupBy()}
39 {$this->getOrderBy()}
40 {$this->getLimit()}
41 {$this->getOffset()}";
42
43 $sql = $this->wpdb->prepare($sql, $this->query_placeholders); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
44
45 $data = [];
46
47 if ($this->type === 'count')
48 {
49 $column_value = $this->wpdb->get_col($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
50 $data = array_sum(array_map('intval', $column_value));
51 }
52 else
53 {
54 $data = $this->wpdb->get_results($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
55 }
56
57 return $data;
58 }
59
60 private function getSelect()
61 {
62 $select = '';
63
64 switch ($this->type)
65 {
66 case 'top_campaign':
67 $select = 'l.box as id, (select p.post_title from ' . $this->wpdb->prefix . 'posts as p WHERE p.ID = l.box) as label, COUNT(*) as total';
68 break;
69
70 case 'popular_view_times':
71 $select = 'CONCAT(DATE_FORMAT(l.date, \'%H\'), \':00\') as label, COUNT(*) as total';
72 break;
73
74 case 'countries':
75 $select = 'l.country as label, COUNT(*) as total';
76 break;
77
78 case 'referrers':
79 $select = 'l.referrer as label, COUNT(*) as total';
80 break;
81
82 case 'devices':
83 $select = 'l.device as label, COUNT(*) as total';
84 break;
85
86 case 'events':
87 $filter = '';
88
89 if (array_key_exists('campaign', $this->filters) && isset($this->filters['campaign']['value']) && is_array($this->filters['campaign']['value']))
90 {
91 $filter .= 'AND ll.box IN (' . implode(',', array_map('intval', $this->filters['campaign']['value'])) . ')';
92 }
93
94 $select = '
95 IF(ld.event IS NOT NULL, ld.event, \'open\') AS label,
96 IF(ld.event IS NOT NULL, COUNT(l.id), (
97 SELECT COUNT(ll.id)
98 FROM wp_firebox_logs AS ll
99 WHERE (ll.date >= outer_query.start_date
100 AND ll.date <= outer_query.end_date)
101 ' . $filter . '
102 )) AS total
103 ';
104 break;
105
106 case 'pages':
107 $select = 'l.page as label, COUNT(*) as total';
108 break;
109
110 case 'weekly':
111 $select = 'DATE_FORMAT(STR_TO_DATE(CONCAT(yearweek(l.date), " ' . firebox()->_('FB_MONDAY') . '"), \'%%X%%V %%W\'), \'%%d %%b %%y\') as label, count(*) as total';
112 break;
113
114 case 'monthly':
115 $select = 'DATE_FORMAT(l.date, \'%%b %%Y\') as label, COUNT(*) as total';
116 break;
117
118 case 'day_of_week':
119 $select = 'DAYNAME(l.date) as label, COUNT(*) as total';
120 break;
121
122 case 'list':
123 default:
124 $partA = 'date(l.date) as label';
125
126 if ($this->isSingleDay())
127 {
128 $partA = 'CONCAT(DATE_FORMAT(l.date, \'%H\'), \':00\') as label';
129 }
130
131 $select = $partA . ', COUNT(*) as total';
132 break;
133
134 case 'count':
135 $select = 'COUNT(*) as total';
136 break;
137 }
138
139 return $select;
140 }
141
142 private function getGroupBy()
143 {
144 if ($this->type === 'count')
145 {
146 return;
147 }
148
149 $groupby = 'date(l.date)';
150
151 if ($this->isSingleDay() || $this->type === 'popular_view_times')
152 {
153 $groupby = 'CONCAT(DATE_FORMAT(l.date, \'%H\'), \':00\')';
154 }
155
156 if ($this->type === 'top_campaign')
157 {
158 $groupby = 'l.box';
159 }
160 else if ($this->type === 'countries')
161 {
162 $groupby = 'l.country';
163 }
164 else if ($this->type === 'referrers')
165 {
166 $groupby = 'l.referrer';
167 }
168 else if ($this->type === 'devices')
169 {
170 $groupby = 'l.device';
171 }
172 else if ($this->type === 'events')
173 {
174 $groupby = 'ld.event';
175 }
176 else if ($this->type === 'pages')
177 {
178 $groupby = 'l.page';
179 }
180 else if ($this->type === 'weekly')
181 {
182 $groupby = 'yearweek(l.date)';
183 }
184 else if ($this->type === 'monthly')
185 {
186 $groupby = 'YEAR(l.date), MONTH(l.date)';
187 }
188 else if ($this->type === 'day_of_week')
189 {
190 $groupby = 'label';
191 }
192
193 return 'GROUP BY ' . $groupby;
194 }
195
196 private function getOrderBy()
197 {
198 if ($this->type === 'count')
199 {
200 return;
201 }
202
203 $orderby = 'l.date DESC';
204
205 if (in_array($this->type, ['top_campaign', 'countries', 'referrers', 'devices', 'events', 'pages', 'day_of_week']))
206 {
207 $orderby = 'total DESC';
208 }
209
210 if (isset($this->options['orderby']))
211 {
212 $orderby = $this->options['orderby'];
213 }
214
215 return 'ORDER BY ' . $orderby;
216 }
217
218 private function getWhere()
219 {
220 $where = '';
221
222 if ($this->type === 'popular_view_times' && isset($this->options['weekday']))
223 {
224 $where = 'AND WEEKDAY(l.date) = \'' . $this->options['weekday'] . '\'';
225 }
226
227 return $where;
228 }
229 }