PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.10
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.10
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 / FB / Log.php

Log.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.10, at Inc/Core/FB/Log.php

222 lines 5.4 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.10 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\FB;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Registry;
20 use FireBox\Core\Helpers\BoxHelper;
21
22 class Log
23 {
24 /**
25 * Factory
26 *
27 * @var Factory
28 */
29 private $factory;
30
31 public function __construct($factory = null)
32 {
33 if (!$factory)
34 {
35 $factory = new \FPFramework\Base\Factory();
36 }
37
38 $this->factory = $factory;
39 }
40
41 /**
42 * Logs box events to the database
43 *
44 * @param integer $boxid The box id
45 * @param string $page The page the box appeared
46 * @param string $referrer The referrer
47 * @param integer $event_id Event id: 1=Open, 2=Close
48 * @param integer $box_log_id The box log ID of the open event that we are closing
49 *
50 * @return bool Returns a boolean indicating if the event logged successfully
51 */
52 public function track($boxid, $event_id = 1, $box_log_id = null, $page = '', $referrer = '')
53 {
54 // Making sure we have a valid Boxid
55 if (!$boxid)
56 {
57 return;
58 }
59
60 // open event
61 if ($event_id == 1)
62 {
63 // Get visitor's token id
64 if (!$visitorID = $this->factory->getVisitorID())
65 {
66 return;
67 }
68
69
70 $country_value = '';
71
72
73
74
75 // Everything seems OK. Let's save data to db.
76 $data = (object) [
77 'sessionid' => $this->factory->getSession()->getSessionID(),
78 'visitorid' => $visitorID,
79 'user' => $this->factory->getUser()->ID,
80 'box' => $boxid,
81 'page' => $page,
82 'country' => $country_value,
83 'device' => $this->factory->getDevice(),
84 'referrer' => $referrer,
85 'date' => $this->factory->getDate()->format('Y-m-d H:i:s')
86 ];
87
88 return $this->handleOpen($data);
89 }
90
91 // other events
92 return $this->handleOtherEvents($box_log_id, $event_id);
93 }
94
95 /**
96 * Handle the logging when opening a box
97 *
98 * @param array $passed_data
99 *
100 * @return mixed
101 */
102 private function handleOpen($passed_data)
103 {
104 // Insert the object into the firebox logs table
105 try
106 {
107 $log_id = firebox()->tables->boxlog->insert($passed_data);
108
109 // clean up
110 $this->clean();
111 return $log_id;
112 }
113 catch (Exception $e)
114 {}
115 }
116
117 /**
118 * Handle the logging of other events
119 *
120 * @param int $box_log_id
121 * @param int $event_id
122 * @param string $event_source
123 * @param string $event_label
124 *
125 * @return mixed
126 */
127 private function handleOtherEvents($box_log_id, $event_id, $event_source = '', $event_label = '')
128 {
129 if (!$box_log_id)
130 {
131 return;
132 }
133
134 // Insert the object into the firebox logs details table
135 try
136 {
137 $data = [
138 'log_id' => $box_log_id,
139 'event' => $this->parseEvent($event_id),
140 'event_source' => $event_source,
141 'event_label' => $event_label,
142 'date' => $this->factory->getDate()->format('Y-m-d H:i:s')
143 ];
144
145 firebox()->tables->boxlogdetails->insert($data);
146
147 // clean up
148 $this->clean();
149 return;
150 }
151 catch (Exception $e)
152 {
153 }
154 }
155
156 /**
157 * Translates the event ID to name
158 *
159 * @param int $id
160 *
161 * @return string
162 */
163 private function parseEvent($id)
164 {
165 $name = '';
166
167 switch ($id)
168 {
169 case 1:
170 $name = 'open';
171 break;
172 case 2:
173 $name = 'close';
174 break;
175 case 3:
176 $name = 'conversion';
177 break;
178 }
179
180 return $name;
181 }
182
183 /**
184 * Removes old rows from the logs table
185 * Runs every 12 hours with a self-check
186 *
187 * @return void
188 */
189 private function clean()
190 {
191 // cache key
192 $hash = md5('fireboxclean');
193
194 // check cache
195 if ($params = wp_cache_get($hash))
196 {
197 return;
198 }
199
200 // Removes rows older than x days
201 $stats = \FireBox\Core\Helpers\BoxHelper::getParams();
202 $stats = new Registry($stats);
203
204 $days = $stats->get('statsdays', 730);
205
206 global $wpdb;
207
208 $sql = 'DELETE bl, bld
209 FROM `' . firebox()->tables->boxlog->getFullTableName() . '` as bl
210 LEFT JOIN `' . firebox()->tables->boxlogdetails->getFullTableName() . '` as bld
211 ON bld.log_id = bl.id
212 WHERE
213 bl.date < DATE_SUB(NOW(), INTERVAL ' . $wpdb->prepare('%d', $days) . ' DAY)';
214
215 firebox()->tables->boxlog->executeRaw($sql);
216
217 // set cache
218 wp_cache_set($hash, $stats, $hash, 720);
219
220 return true;
221 }
222 }