PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.14
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.14
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 / Admin / Analytics / Overview / Overview.php

Overview.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 1.0.14, at Inc/Core/Admin/Analytics/Overview/Overview.php

344 lines 9.9 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 1.0.14 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Admin\Analytics\Overview;
13
14 use FireBox\Core\Admin\Analytics\Helpers\AnalyticsHelper;
15
16 if (!defined('ABSPATH'))
17 {
18 exit; // Exit if accessed directly.
19 }
20
21 class Overview
22 {
23 /**
24 * The default Overview filters
25 *
26 * @var array
27 */
28 private $default_filters = [
29 'date' => 'this_month'
30 ];
31
32 /**
33 * Configuration
34 *
35 * @var array
36 */
37 private $configuration;
38
39 /**
40 * Analytics Toolbar
41 *
42 * @var Toolbar
43 */
44 private $toolbar;
45
46 public function __construct($configuration = [])
47 {
48 // set the configuration data of the Analytics Helper class
49 AnalyticsHelper::setConfigurationData($configuration);
50
51 // Ensure we can show analytics overview on current page
52 if (!wp_doing_ajax() && !$this->canRun())
53 {
54 return;
55 }
56
57 $this->configuration = $configuration;
58 $this->toolbar = new \FireBox\Core\Admin\Analytics\Toolbar($configuration);
59
60 $this->ajax = new Ajax($this);
61
62 // render overview filters
63 add_action('firebox/analytics/overview/filters', [$this, 'renderFilters']);
64
65 // render overview
66 add_action('firebox/dashboard/content', [$this, 'render']);
67 }
68
69 /**
70 * Whether we can run analytics overview or not
71 *
72 * @return boolean
73 */
74 protected function canRun()
75 {
76 // we must be on admin panel
77 if (!is_admin())
78 {
79 return false;
80 }
81
82 // ensure we have correct priviledges
83 if (!is_user_logged_in() || !current_user_can('manage_options'))
84 {
85 return false;
86 }
87
88 // we must be on admin.php page
89 global $pagenow;
90 if (!$pagenow == 'admin.php')
91 {
92 return false;
93 }
94
95 // ensure we are on firebox dashboard
96 $page = fpframework()->getPluginPage();
97 if (!$page || !in_array($page, ['firebox']))
98 {
99 return false;
100 }
101
102 return true;
103 }
104
105 /**
106 * Display the Analytics Overview
107 *
108 * @return void
109 */
110 public function render()
111 {
112 // Load CSS & JS files
113 $this->loadMedia();
114
115 $payload = $this->getOverviewItemsPayload();
116
117 firebox()->renderer->admin->render('analytics/overview/tmpl', [
118 'overview_items_names' => $this->getOverviewItemsNames(),
119 'default_filters' => $this->default_filters
120 ]);
121 }
122
123 public function renderFilters()
124 {
125 firebox()->renderer->admin->render('analytics/overview/filters', [
126 'configuration' => $this->configuration,
127 'filters' => $this->getFilters()
128 ]);
129 }
130
131 public function getOverviewItemsNames()
132 {
133 $payload = $this->getOverviewItemsPayload();
134
135 return array_keys($payload);
136 }
137
138 public function getOverviewItemsPayload()
139 {
140 $configuration = $this->toolbar->getConfiguration();
141
142 return [
143 'impressions' => [
144 'overview_type' => 'chart',
145 'url_chart_metrics' => ['impressions'],
146 'metrics' => ['impressions'],
147 'allowed_filters' => [
148 'box',
149 'date'
150 ],
151 'toolbar_items' => [
152 'date' => [
153 'method' => 'filter',
154 'options_key' => 'this_month',
155 ]
156 ],
157 ],
158 'avg_time_open' => [
159 'overview_type' => 'chart',
160 'url_chart_metrics' => ['theaveragetimeopen'],
161 'metrics' => ['theaveragetimeopen'],
162 'allowed_filters' => [
163 'box',
164 'date'
165 ],
166 'toolbar_items' => [
167 'date' => [
168 'method' => 'filter',
169 'options_key' => 'this_month',
170 ]
171 ],
172 ],
173 'boxes' => [
174 'overview_title' => firebox()->_('FB_TOP_BOXES'),
175 'overview_type' => 'boxestable',
176 'layout' => 'table',
177 'reference_toolbar_item' => 'box',
178 'metrics' => ['impressions'],
179 'show_total' => false,
180 'show_percentage' => false,
181 'allowed_filters' => [
182 'box',
183 'date'
184 ],
185 'other_data' => [
186 'modify_query_data' => [
187 'select' => [
188 'boxes.ID as box_id',
189 'boxes.post_title as label',
190 'count(bl.id) as total'
191 ],
192 'join' => [
193 'left join ' . $configuration['boxes_table'] . ' as boxes' => ' ON boxes.ID = bl.box'
194 ],
195 'groupby' => 'bl.box',
196 'orderby' => 'total desc'
197 ],
198 'options' => [
199 'skip_filling_dates' => true,
200 'skip_compare_check_to_retrieve_previous_data' => true
201 ]
202 ],
203 'table_columns' => [
204 'box' => [
205 'label' => firebox()->_('FB_POPUP'),
206 ],
207 'impressions' => [
208 'label' => fpframework()->_('FPF_IMPRESSIONS'),
209 ],
210 'percentage' => [
211 'label' => '%',
212 'title' => fpframework()->_('FPF_PERCENTAGE_CHANGE_OVER_PREVIOUS_PERIOD')
213 ]
214 ],
215 'toolbar_items' => [
216 'date' => [
217 'method' => 'filter',
218 'options_key' => 'this_month',
219 ]
220 ],
221 ],
222
223
224 'devices_pro' => [
225 'overview_title' => fpframework()->_('FPF_TOP_DEVICES'),
226 'overview_type' => 'pro',
227 'layout' => 'pro',
228 'redirect_base' => true,
229 'feature' => fpframework()->_('FPF_TOP_DEVICES'),
230 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_devices.png',
231 'show_overlay_message' => true,
232 'class' => 'overlay-bg corner',
233 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
234 ],
235 'countries_pro' => [
236 'overview_title' => fpframework()->_('FPF_TOP_COUNTRIES'),
237 'overview_type' => 'pro',
238 'layout' => 'pro',
239 'redirect_base' => true,
240 'feature' => fpframework()->_('FPF_TOP_COUNTRIES'),
241 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_countries.png',
242 'show_overlay_message' => true,
243 'class' => 'overlay-bg corner',
244 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
245 ],
246 'referrers_pro' => [
247 'overview_title' => fpframework()->_('FPF_TOP_REFERRERS'),
248 'overview_type' => 'pro',
249 'layout' => 'pro',
250 'redirect_base' => true,
251 'feature' => fpframework()->_('FPF_TOP_REFERRERS'),
252 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_referrers.png',
253 'show_overlay_message' => true,
254 'class' => 'overlay-bg corner',
255 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
256 ],
257
258 ];
259 }
260
261 public function getFilters($plain = false)
262 {
263
264
265 return [
266
267
268 'box_pro' => [
269 'default_label' => firebox()->_('FB_ALL_POPUPS'),
270 'item' => firebox()->_('FB_POPUP_SELECTION')
271 ],
272 'date_pro' => [
273 'default_label' => fpframework()->_('FB_THIS_MONTH'),
274 'item' => fpframework()->_('FPF_DATE_PERIOD')
275 ]
276
277 ];
278 }
279
280 /**
281 * Load media for the Analytics Overview page
282 *
283 * @return void
284 */
285 private function loadMedia()
286 {
287 // Countries Icons CSS Library
288 wp_register_style(
289 'firebox-analytics-overview-countries-icons',
290 FBOX_MEDIA_ADMIN_URL . 'css/flag-icon.min.css',
291 [],
292 FBOX_VERSION,
293 false
294 );
295 wp_enqueue_style('firebox-analytics-overview-countries-icons');
296
297 // Chart JS CSS Library
298 wp_register_style(
299 'firebox-analytics-chart',
300 FBOX_MEDIA_ADMIN_URL . 'css/chart.min.css',
301 [],
302 FBOX_VERSION,
303 false
304 );
305 wp_enqueue_style('firebox-analytics-chart');
306
307 // Moments JS
308 wp_register_script(
309 'firebox-analytics-moment-js-library',
310 includes_url('js/dist/vendor/moment.min.js'),
311 [],
312 FBOX_VERSION,
313 false
314 );
315 wp_enqueue_script('firebox-analytics-moment-js-library');
316
317 // Chart JS
318 wp_register_script(
319 'firebox-analytics-chart',
320 FBOX_MEDIA_ADMIN_URL . 'js/chart.min.js',
321 ['firebox-analytics-moment-js-library'],
322 FBOX_VERSION,
323 false
324 );
325 wp_enqueue_script('firebox-analytics-chart');
326
327
328
329 // FireBox Analytics Overview JS
330 wp_register_script(
331 'firebox-analytics-overview',
332 FBOX_MEDIA_ADMIN_URL . 'js/fb_analytics_overview.js',
333 [],
334 FBOX_VERSION,
335 false
336 );
337 wp_enqueue_script('firebox-analytics-overview');
338 }
339
340 public function getToolbar()
341 {
342 return $this->toolbar;
343 }
344 }