PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.0
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.0
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.0, at Inc/Core/Admin/Analytics/Overview/Overview.php

306 lines 8.5 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.0 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2021 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
174
175 'boxes_pro' => [
176 'overview_title' => firebox()->_('FB_TOP_BOXES'),
177 'overview_type' => 'pro',
178 'layout' => 'pro',
179 'redirect_base' => true,
180 'feature' => firebox()->_('FB_TOP_BOXES'),
181 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_boxes.png',
182 'show_overlay_message' => true,
183 'class' => 'overlay-bg full-width',
184 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
185 ],
186 'devices_pro' => [
187 'overview_title' => fpframework()->_('FPF_TOP_DEVICES'),
188 'overview_type' => 'pro',
189 'layout' => 'pro',
190 'redirect_base' => true,
191 'feature' => fpframework()->_('FPF_TOP_DEVICES'),
192 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_devices.png',
193 'show_overlay_message' => true,
194 'class' => 'overlay-bg full-width',
195 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
196 ],
197 'countries_pro' => [
198 'overview_title' => fpframework()->_('FPF_TOP_COUNTRIES'),
199 'overview_type' => 'pro',
200 'layout' => 'pro',
201 'redirect_base' => true,
202 'feature' => fpframework()->_('FPF_TOP_COUNTRIES'),
203 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_countries.png',
204 'show_overlay_message' => true,
205 'class' => 'overlay-bg full-width',
206 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
207 ],
208 'referrers_pro' => [
209 'overview_title' => fpframework()->_('FPF_TOP_REFERRERS'),
210 'overview_type' => 'pro',
211 'layout' => 'pro',
212 'redirect_base' => true,
213 'feature' => fpframework()->_('FPF_TOP_REFERRERS'),
214 'image' => FBOX_MEDIA_ADMIN_URL . 'images/analytics_overview_referrers.png',
215 'show_overlay_message' => true,
216 'class' => 'overlay-bg full-width',
217 'message' => 'FPF_ANALYTICS_OVERVIEW_OVERLAY_PRO_MSG1'
218 ],
219
220 ];
221 }
222
223 public function getFilters($plain = false)
224 {
225
226
227 return [
228
229
230 'box_pro' => [
231 'default_label' => firebox()->_('FB_ALL_POPUPS'),
232 'item' => firebox()->_('FB_POPUP_SELECTION')
233 ],
234 'date_pro' => [
235 'default_label' => fpframework()->_('FB_THIS_MONTH'),
236 'item' => fpframework()->_('FPF_DATE_PERIOD')
237 ]
238
239 ];
240 }
241
242 /**
243 * Load media for the Analytics Overview page
244 *
245 * @return void
246 */
247 private function loadMedia()
248 {
249 // Countries Icons CSS Library
250 wp_register_style(
251 'firebox-analytics-overview-countries-icons',
252 FBOX_MEDIA_ADMIN_URL . 'css/flag-icon.min.css',
253 [],
254 FBOX_VERSION,
255 false
256 );
257 wp_enqueue_style('firebox-analytics-overview-countries-icons');
258
259 // Chart JS CSS Library
260 wp_register_style(
261 'firebox-analytics-chart',
262 FBOX_MEDIA_ADMIN_URL . 'css/chart.min.css',
263 [],
264 FBOX_VERSION,
265 false
266 );
267 wp_enqueue_style('firebox-analytics-chart');
268
269 // Moments JS
270 wp_register_script(
271 'firebox-analytics-moment-js-library',
272 includes_url('js/dist/vendor/moment.min.js'),
273 [],
274 FBOX_VERSION,
275 false
276 );
277 wp_enqueue_script('firebox-analytics-moment-js-library');
278
279 // Chart JS
280 wp_register_script(
281 'firebox-analytics-chart',
282 FBOX_MEDIA_ADMIN_URL . 'js/chart.min.js',
283 ['firebox-analytics-moment-js-library'],
284 FBOX_VERSION,
285 false
286 );
287 wp_enqueue_script('firebox-analytics-chart');
288
289
290
291 // FireBox Analytics Overview JS
292 wp_register_script(
293 'firebox-analytics-overview',
294 FBOX_MEDIA_ADMIN_URL . 'js/fb_analytics_overview.js',
295 [],
296 FBOX_VERSION,
297 false
298 );
299 wp_enqueue_script('firebox-analytics-overview');
300 }
301
302 public function getToolbar()
303 {
304 return $this->toolbar;
305 }
306 }