PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.6
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.6
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 / Toolbar.php

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

303 lines 7.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 1.0.6 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;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Toolbar
20 {
21
22
23 /**
24 * The default Toolbar Item
25 *
26 * @var string
27 */
28 const default_toolbar_item = 'date';
29
30 /**
31 * Configuration data
32 *
33 * @var array
34 */
35 private $configuration;
36
37 /**
38 * Toolbar Items
39 *
40 * @var array
41 */
42 private $settings;
43
44 /**
45 * Selected Toolbar Items
46 *
47 * @var array
48 */
49 private $selectedToolbarItems;
50
51 /**
52 * Toolbar Items Classes Objects
53 *
54 * @var array
55 */
56 private $toolbarItems;
57
58 /**
59 * Which toolbar item we currently edited
60 *
61 * @var string
62 */
63 private $editing_toolbar_item;
64
65 /**
66 * DB
67 *
68 * @var DB
69 */
70 private $db;
71
72 /**
73 * Toolbar Constructor
74 *
75 * @param array $toolbarItems
76 *
77 * @return void
78 */
79 public function __construct($configuration = [], $db = null, $toolbarItems = null)
80 {
81 $this->configuration = $configuration;
82 $this->db = $db;
83
84 if (!$toolbarItems)
85 {
86 $toolbarItems = $this->initializeToolbarItems();
87 }
88 $this->toolbarItems = $toolbarItems;
89
90 $this->setUpAvailableToolbarItems();
91
92
93 }
94
95
96
97 /**
98 * Retrieves the currently selected Toolbar Items
99 *
100 * @return array
101 */
102 public function setSelectedToolbarItems($selected_toolbar_items = [])
103 {
104 if (!$selected_toolbar_items)
105 {
106 $selected_toolbar_items = $this->getDefaultToolbarItems();
107 }
108
109 // if the saved toolbar items are the ones we have already processed, then return them and do not do the process below again.
110 if ($this->selectedToolbarItems == $selected_toolbar_items)
111 {
112 return $this->selectedToolbarItems;
113 }
114
115
116
117 // validate and set other toolbar items data
118 foreach ($selected_toolbar_items as $key => &$value)
119 {
120 if (!$key)
121 {
122 continue;
123 }
124
125 if (empty($value))
126 {
127 unset($selected_toolbar_items[$key]);
128 continue;
129 }
130
131 // ensure only valid toolbar items are processed
132 if (!isset($this->toolbarItems[$key]))
133 {
134 unset($selected_toolbar_items[$key]);
135 continue;
136 }
137
138 $toolbarItem = $this->toolbarItems[$key];
139
140 // set popup title
141 $value['popup_title'] = $toolbarItem->getPopupTitle();
142
143 $itemValue = isset($value['value']) ? $value['value'] : '';
144
145 // x axis labels
146 $xAxisLabels = $toolbarItem->getXAxisLabels($value['method'], $value['options_key'], $itemValue);
147 $value['xAxisLabel'] = $xAxisLabels['xAxisLabel'];
148 $value['xAxisLabelPreviousPeriod'] = $xAxisLabels['xAxisLabelPreviousPeriod'];
149
150 // unset toolbar item if no value is returned
151 if (!$toolbarItemLabelValue = $toolbarItem->getToolbarItemLabelValue($value))
152 {
153 unset($selected_toolbar_items[$key]);
154 continue;
155 }
156
157 $value['title'] = $value['popup_title'] . ': ' . $toolbarItemLabelValue;
158 }
159
160 // add date if not exist
161 $this->checkAndAddDateToolbarItem($selected_toolbar_items);
162
163 $this->selectedToolbarItems = $selected_toolbar_items;
164 }
165
166 public function getSelectedToolbarItems()
167 {
168 return $this->selectedToolbarItems;
169 }
170
171 /**
172 * Adds the date toolbar item at the front of the selected toolbar_items if it does not exist
173 *
174 * @param array $selected_toolbar_items
175 *
176 * @return void
177 */
178 private function checkAndAddDateToolbarItem(&$selected_toolbar_items)
179 {
180 if (!isset($selected_toolbar_items[self::default_toolbar_item]))
181 {
182 $selected_toolbar_items = $this->toolbarItems[self::default_toolbar_item]->getDefaultToolbarItemData() + $selected_toolbar_items;
183 }
184 }
185
186
187
188 /**
189 * Default Selected Toolbar Items
190 *
191 * @return array
192 */
193 private function getDefaultSelectedToolbarItems()
194 {
195 return [
196 'toolbar_items' => $this->getDefaultToolbarItems(),
197 'editing_toolbar_item' => self::default_toolbar_item
198 ];
199 }
200
201 /**
202 * Returns the default Toolbar Items
203 * - Date - Filter : This Month
204 *
205 * @return array
206 */
207 public function getDefaultToolbarItems()
208 {
209 return [
210 'date' => [
211 'method' => 'filter',
212 'options_key' => 'this_month',
213 ]
214 ];
215 }
216
217 /**
218 * Initialize all toolbar items
219 *
220 * @return array
221 */
222 private function initializeToolbarItems()
223 {
224 // get all Toolbar Namespace Files
225 if (!$files = \scandir(__DIR__ . '/Toolbar'))
226 {
227 return [];
228 }
229
230 $items = [];
231
232 foreach ($files as $key => $file)
233 {
234 // ignore unimportant files
235 if (in_array($file, ['index.php', '.', '..']))
236 {
237 continue;
238 }
239
240 $file = basename($file, '.php');
241
242 // instantiate class
243 $className = '\FireBox\Core\Admin\Analytics\Toolbar\\' . $file;
244
245 if (!class_exists($className))
246 {
247 continue;
248 }
249
250 $items[strtolower($file)] = new $className($this->db);
251 }
252
253 return $items;
254 }
255
256 /**
257 * Set up each available toolbar item by giving the selected toolbar items to each toolbar item
258 *
259 * @return void
260 */
261 public function setUpAvailableToolbarItems()
262 {
263 foreach ($this->toolbarItems as $key => $value)
264 {
265 $this->toolbarItems[$key]->setupVariables($this->configuration, $this->selectedToolbarItems);
266 }
267 }
268
269 /**
270 * Returns the Toolbar Items
271 *
272 * @return array
273 */
274 public function getToolbarItems()
275 {
276 return $this->toolbarItems;
277 }
278
279 /**
280 * Returns the toolbar settings
281 *
282 * @return array
283 */
284 public function getSettings()
285 {
286 return $this->settings;
287 }
288
289 public function setSelectedToolbarItemsValue($value)
290 {
291 $this->selectedToolbarItems = $value;
292 }
293
294 public function setEditingToolbarItem($editing_toolbar_item)
295 {
296 $this->editing_toolbar_item = $editing_toolbar_item;
297 }
298
299 public function getConfiguration()
300 {
301 return $this->configuration;
302 }
303 }