PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
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 / UsageTracking / PluginData.php

PluginData.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.39, at Inc/Core/UsageTracking/PluginData.php

244 lines 6.8 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.1.39 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2025 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\UsageTracking;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class PluginData
20 {
21 public function getViews()
22 {
23 global $wpdb;
24 $table_name = $wpdb->prefix . 'firebox_logs';
25 $total_views = $wpdb->get_var("SELECT COUNT(id) FROM $table_name");
26 return $total_views;
27 }
28
29 public function getCampaigns($status = '')
30 {
31 if (!$status)
32 {
33 return;
34 }
35
36 global $wpdb;
37 $query = "
38 SELECT COUNT(id) as total
39 FROM {$wpdb->posts}
40 WHERE post_type = 'firebox'
41 AND post_status IN ('" . $status . "')
42 ";
43 $results = $wpdb->get_var($query);
44 return $results;
45 }
46
47 public function getSubmissions()
48 {
49 global $wpdb;
50 $table_name = $wpdb->prefix . 'firebox_submissions';
51 $total_submissions = $wpdb->get_var("SELECT COUNT(id) FROM $table_name");
52 return $total_submissions;
53 }
54
55 public function getTotalsBySetting($setting_name = '', $setting_value = '')
56 {
57 if (!$setting_name || !$setting_value)
58 {
59 return;
60 }
61
62 $posts = $this->getCachedCampaigns();
63
64 $count = 0;
65 foreach ($posts as $post)
66 {
67 $tmp_setting_name = $setting_name;
68 $tmp_setting_value = $setting_value;
69
70 $meta = maybe_unserialize($post->meta_value);
71
72 if (strpos($setting_name, '.') !== false)
73 {
74 $keys = explode('.', $setting_name);
75
76 $meta = isset($meta[$keys[0]]) && is_array($meta[$keys[0]]) ? $meta[$keys[0]] : false;
77
78 if (!$meta)
79 {
80 continue;
81 }
82
83 $tmp_setting_name = $keys[1];
84 }
85
86 if (isset($meta[$tmp_setting_name]))
87 {
88 if (strpos($tmp_setting_value, 'cond:') === 0)
89 {
90 $condition = substr($tmp_setting_value, 5);
91 switch ($condition)
92 {
93 case 'not:none':
94 if ($meta[$tmp_setting_name] !== 'none')
95 {
96 $count++;
97 }
98 break;
99 case 'not:empty':
100 if (!empty($meta[$tmp_setting_name]) && !is_null($meta[$tmp_setting_name]))
101 {
102 $count++;
103 }
104 break;
105 case 'not:emptyArray':
106 if (count($meta[$tmp_setting_name]))
107 {
108 $count++;
109 }
110 break;
111 }
112 }
113
114 // Equal comparison
115 if ($meta[$tmp_setting_name] === $tmp_setting_value)
116 {
117 $count++;
118 }
119 // In array comparison
120 else if (is_array($meta[$tmp_setting_name]) && in_array($tmp_setting_value, $meta[$tmp_setting_name]))
121 {
122 $count++;
123 }
124 }
125 }
126
127 return $count;
128 }
129
130 public function getTotalsByCondition($condition = '')
131 {
132 if (!$condition)
133 {
134 return;
135 }
136
137 $posts = $this->getCachedCampaigns();
138
139 $count = 0;
140 foreach ($posts as $post)
141 {
142 $meta = maybe_unserialize($post->meta_value);
143
144 if (!isset($meta['rules']))
145 {
146 continue;
147 }
148
149 if (!$rules = $meta['rules'])
150 {
151 continue;
152 }
153
154 if (is_string($rules))
155 {
156 $rules = json_decode($rules, true);
157 }
158
159 if (!is_array($rules))
160 {
161 continue;
162 }
163
164 foreach ($rules as $key => $group)
165 {
166 if (!isset($group['rules']) || !is_array($group['rules']))
167 {
168 continue;
169 }
170
171 foreach ($group['rules'] as $groupRule)
172 {
173 if (!isset($groupRule['name']))
174 {
175 continue;
176 }
177
178 $groupName = str_replace('\\\\', '\\', $groupRule['name']);
179
180 if ($groupName === $condition)
181 {
182 $count++;
183 }
184 }
185 }
186 }
187
188 return $count;
189 }
190
191 public function getDimensionsData()
192 {
193 $posts = $this->getCachedCampaigns();
194 $dimensions = [];
195
196 foreach ($posts as $post)
197 {
198 $meta = maybe_unserialize($post->meta_value);
199
200 $width = isset($meta['width_control']['width']['desktop']['value']) ? $meta['width_control']['width']['desktop']['value'] : '';
201 $height = isset($meta['height_control']['height']['desktop']['value']) && $meta['height_control']['height']['desktop']['value'] ? $meta['height_control']['height']['desktop']['value'] : 'auto';
202
203 if (!$width || !$height)
204 {
205 continue;
206 }
207
208 // Format: "400xauto" or "500x300"
209 $dimension_key = $width . 'x' . $height;
210
211 if (!isset($dimensions[$dimension_key]))
212 {
213 $dimensions[$dimension_key] = 0;
214 }
215
216 $dimensions[$dimension_key]++;
217 }
218
219 return $dimensions;
220 }
221
222 private function getCachedCampaigns()
223 {
224 global $wpdb;
225 $cache_key = 'firebox_campaigns_for_search';
226 $cached_results = wp_cache_get($cache_key);
227
228 if ($cached_results === false)
229 {
230 $query = "
231 SELECT p.ID, pm.meta_value
232 FROM {$wpdb->posts} p
233 LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id
234 WHERE p.post_type = 'firebox'
235 AND p.post_status IN ('draft', 'trash', 'publish')
236 AND pm.meta_key = 'fpframework_meta_settings'
237 ";
238 $cached_results = $wpdb->get_results($query);
239 wp_cache_set($cache_key, $cached_results, 'firebox', 6 * DAY_IN_SECONDS + 12 * HOUR_IN_SECONDS);
240 }
241
242 return $cached_results;
243 }
244 }