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 / Toolbar.php

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

304 lines 7.1 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;
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 // set popup title
139 $value['popup_title'] = $this->toolbarItems[$key]->getPopupTitle();
140
141 $itemValue = isset($value['value']) ? $value['value'] : '';
142
143 // x axis labels
144 $xAxisLabels = $this->toolbarItems[$key]->getXAxisLabels($value['method'], $value['options_key'], $itemValue);
145 $value['xAxisLabel'] = $xAxisLabels['xAxisLabel'];
146 $value['xAxisLabelPreviousPeriod'] = $xAxisLabels['xAxisLabelPreviousPeriod'];
147
148 // toolbar item label prefix and value
149 $prefix = fpframework()->_('FPF_' . strtoupper($key), 'FB_' . strtoupper($key));
150
151 // unset toolbar item if no value is returned
152 if (!$toolbarItemLabelValue = $this->toolbarItems[$key]->getToolbarItemLabelValue($value))
153 {
154 unset($selected_toolbar_items[$key]);
155 continue;
156 }
157
158 $value['title'] = $prefix . ': ' . $toolbarItemLabelValue;
159 }
160
161 // add date if not exist
162 $this->checkAndAddDateToolbarItem($selected_toolbar_items);
163
164 $this->selectedToolbarItems = $selected_toolbar_items;
165 }
166
167 public function getSelectedToolbarItems()
168 {
169 return $this->selectedToolbarItems;
170 }
171
172 /**
173 * Adds the date toolbar item at the front of the selected toolbar_items if it does not exist
174 *
175 * @param array $selected_toolbar_items
176 *
177 * @return void
178 */
179 private function checkAndAddDateToolbarItem(&$selected_toolbar_items)
180 {
181 if (!isset($selected_toolbar_items[self::default_toolbar_item]))
182 {
183 $selected_toolbar_items = $this->toolbarItems[self::default_toolbar_item]->getDefaultToolbarItemData() + $selected_toolbar_items;
184 }
185 }
186
187
188
189 /**
190 * Default Selected Toolbar Items
191 *
192 * @return array
193 */
194 private function getDefaultSelectedToolbarItems()
195 {
196 return [
197 'toolbar_items' => $this->getDefaultToolbarItems(),
198 'editing_toolbar_item' => self::default_toolbar_item
199 ];
200 }
201
202 /**
203 * Returns the default Toolbar Items
204 * - Date - Filter : This Month
205 *
206 * @return array
207 */
208 public function getDefaultToolbarItems()
209 {
210 return [
211 'date' => [
212 'method' => 'filter',
213 'options_key' => 'this_month',
214 ]
215 ];
216 }
217
218 /**
219 * Initialize all toolbar items
220 *
221 * @return array
222 */
223 private function initializeToolbarItems()
224 {
225 // get all Toolbar Namespace Files
226 if (!$files = \scandir(__DIR__ . '/Toolbar'))
227 {
228 return [];
229 }
230
231 $items = [];
232
233 foreach ($files as $key => $file)
234 {
235 // ignore unimportant files
236 if (in_array($file, ['index.php', '.', '..']))
237 {
238 continue;
239 }
240
241 $file = basename($file, '.php');
242
243 // instantiate class
244 $className = '\FireBox\Core\Admin\Analytics\Toolbar\\' . $file;
245
246 if (!class_exists($className))
247 {
248 continue;
249 }
250
251 $items[strtolower($file)] = new $className($this->db);
252 }
253
254 return $items;
255 }
256
257 /**
258 * Set up each available toolbar item by giving the selected toolbar items to each toolbar item
259 *
260 * @return void
261 */
262 public function setUpAvailableToolbarItems()
263 {
264 foreach ($this->toolbarItems as $key => $value)
265 {
266 $this->toolbarItems[$key]->setupVariables($this->configuration, $this->selectedToolbarItems);
267 }
268 }
269
270 /**
271 * Returns the Toolbar Items
272 *
273 * @return array
274 */
275 public function getToolbarItems()
276 {
277 return $this->toolbarItems;
278 }
279
280 /**
281 * Returns the toolbar settings
282 *
283 * @return array
284 */
285 public function getSettings()
286 {
287 return $this->settings;
288 }
289
290 public function setSelectedToolbarItemsValue($value)
291 {
292 $this->selectedToolbarItems = $value;
293 }
294
295 public function setEditingToolbarItem($editing_toolbar_item)
296 {
297 $this->editing_toolbar_item = $editing_toolbar_item;
298 }
299
300 public function getConfiguration()
301 {
302 return $this->configuration;
303 }
304 }