PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.0.12
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.0.12
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 2.0.12, at Inc/Core/Admin/Analytics/Toolbar.php

287 lines 6.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.0.12 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2023 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 = null;
50
51 /**
52 * Default toolbar items.
53 *
54 * @var array
55 */
56 private $defaultToolbarItems = [
57 'Box',
58 'Country',
59 'Date',
60 'Device',
61 'Event',
62 'Page',
63 'Referrer'
64 ];
65
66 /**
67 * Toolbar Items Classes Objects
68 *
69 * @var array
70 */
71 private $toolbarItems;
72
73 /**
74 * Which toolbar item we currently edited
75 *
76 * @var string
77 */
78 private $editing_toolbar_item;
79
80 /**
81 * DB
82 *
83 * @var DB
84 */
85 private $db;
86
87 /**
88 * Toolbar Constructor
89 *
90 * @param array $db
91 * @param array $selectedToolbarItems
92 * @param array $toolbarItems
93 *
94 * @return void
95 */
96 public function __construct($db = null, $selectedToolbarItems = null, $toolbarItems = null)
97 {
98 $this->configuration = firebox()->analytics_configuration;
99 $this->db = $db;
100
101 $this->selectedToolbarItems = $selectedToolbarItems;
102
103 if (!$toolbarItems)
104 {
105 $toolbarItems = $this->getNewToolbarItems();
106 }
107 $this->toolbarItems = $toolbarItems;
108
109 $this->setSelectedToolbarItems($this->selectedToolbarItems);
110
111
112 }
113
114
115
116 /**
117 * Retrieves the currently selected Toolbar Items
118 *
119 * @return array
120 */
121 public function setSelectedToolbarItems($selected_toolbar_items = [])
122 {
123 if (!$selected_toolbar_items)
124 {
125 $selected_toolbar_items = $this->getDefaultToolbarItems();
126 }
127
128
129
130 // validate and set other toolbar items data
131 foreach ($selected_toolbar_items as $key => &$value)
132 {
133 if (!$key)
134 {
135 continue;
136 }
137
138 if (empty($value))
139 {
140 unset($selected_toolbar_items[$key]);
141 continue;
142 }
143
144 // ensure only valid toolbar items are processed
145 if (!isset($this->toolbarItems[$key]))
146 {
147 unset($selected_toolbar_items[$key]);
148 continue;
149 }
150
151
152 }
153
154 // add date if not exist
155 $this->checkAndAddDateToolbarItem($selected_toolbar_items);
156
157 $this->selectedToolbarItems = $selected_toolbar_items;
158 }
159
160 public function getSelectedToolbarItems()
161 {
162 return $this->selectedToolbarItems;
163 }
164
165 /**
166 * Adds the date toolbar item at the front of the selected toolbar_items if it does not exist
167 *
168 * @param array $selected_toolbar_items
169 *
170 * @return void
171 */
172 private function checkAndAddDateToolbarItem(&$selected_toolbar_items)
173 {
174 if (!isset($selected_toolbar_items[self::default_toolbar_item]))
175 {
176 $selected_toolbar_items = $this->toolbarItems[self::default_toolbar_item]->getDefaultToolbarItemData() + $selected_toolbar_items;
177 }
178 }
179
180
181
182 /**
183 * Default Selected Toolbar Items
184 *
185 * @return array
186 */
187 private function getDefaultSelectedToolbarItems()
188 {
189 return [
190 'toolbar_items' => $this->getDefaultToolbarItems(),
191 'editing_toolbar_item' => self::default_toolbar_item
192 ];
193 }
194
195 /**
196 * Returns the default Toolbar Items
197 * - Date - Filter : This Month
198 *
199 * @return array
200 */
201 public function getDefaultToolbarItems()
202 {
203 return [
204 'date' => [
205 'method' => 'filter',
206 'options_key' => 'this_month',
207 ]
208 ];
209 }
210
211 /**
212 * Re-initialize all toolbar items
213 *
214 * @return array
215 */
216 public function getNewToolbarItems()
217 {
218 if (!empty($this->toolbarItems))
219 {
220 return $this->toolbarItems;
221 }
222
223 $items = [];
224
225 foreach ($this->defaultToolbarItems as $toolbar_class_name)
226 {
227 // instantiate class
228 $className = '\FireBox\Core\Admin\Analytics\Toolbar\\' . $toolbar_class_name;
229
230 if (!class_exists($className))
231 {
232 continue;
233 }
234
235 $items[strtolower($toolbar_class_name)] = new $className($this->db, $this->configuration, $this->getSelectedToolbarItems());
236 }
237
238 return $items;
239 }
240
241 /**
242 * Set the Toolbar Items
243 *
244 * @param array $items
245 *
246 * @return array
247 */
248 public function setToolbarItems($items = [])
249 {
250 $this->toolbarItems = $items;
251 }
252
253 /**
254 * Returns the Toolbar Items
255 *
256 * @return array
257 */
258 public function getToolbarItems()
259 {
260 return $this->toolbarItems;
261 }
262
263 /**
264 * Returns the toolbar settings
265 *
266 * @return array
267 */
268 public function getSettings()
269 {
270 return $this->settings;
271 }
272
273 public function setSelectedToolbarItemsValue($value)
274 {
275 $this->selectedToolbarItems = $value;
276 }
277
278 public function setEditingToolbarItem($editing_toolbar_item)
279 {
280 $this->editing_toolbar_item = $editing_toolbar_item;
281 }
282
283 public function getConfiguration()
284 {
285 return $this->configuration;
286 }
287 }