PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / trunk
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment vtrunk
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 / Cookie.php

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

137 lines 3.2 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 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 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 class Cookie
20 {
21 /**
22 * The box instance
23 *
24 * @var object
25 */
26 private $box;
27
28 /**
29 * The cookie instance
30 *
31 * @var object
32 */
33 private $cookie;
34
35 /**
36 * The value of the cookie
37 *
38 * @var int
39 */
40 private $cookie_value = 1;
41
42 /**
43 * Class constructor
44 *
45 * @param integer $box_id The box's ID
46 */
47 public function __construct($box)
48 {
49 $this->box = $box;
50 $this->cookie = new \FPFramework\Libs\Cookie();
51 }
52
53 /**
54 * Get the name of the cookie
55 *
56 * @return string
57 */
58 private function getName()
59 {
60 return isset($this->box->ID) ? \FireBox\Core\Helpers\BoxHelper::cookiePrefix() . $this->box->ID : '';
61 }
62
63 /**
64 * Store cookie in the browser
65 *
66 * @return void
67 */
68 public function set()
69 {
70 if (!is_object($this->box) || !isset($this->box->params))
71 {
72 return;
73 }
74
75 $cookie_type = $this->box->params->get('assign_cookietype', 'days');
76
77 switch ($cookie_type)
78 {
79 case 'never':
80 return;
81
82 case 'ever':
83 $expire = strtotime('now +20 years'); // forever
84 break;
85
86 case 'custom':
87 $assign_cookietype_param_custom_period_times = (int) $this->box->params->get('assign_cookietype_param_custom_period_times', 1);
88 $assign_cookietype_param_custom_period = $this->box->params->get('assign_cookietype_param_custom_period', 'days');
89
90 $expire = strtotime('now +' . (int) $assign_cookietype_param_custom_period_times . ' ' . $assign_cookietype_param_custom_period);
91 break;
92
93 default:
94 $expire = 0; // session
95 }
96
97 $this->cookie->set(
98 $this->getName(),
99 $this->cookie_value,
100 $expire,
101 \FireBox\Core\Helpers\BoxHelper::cookiePath(),
102 \FireBox\Core\Helpers\BoxHelper::cookieDomain(),
103 true
104 );
105 }
106
107 /**
108 * Check if the cookie of the box exist
109 *
110 * @return bool
111 */
112 public function exist()
113 {
114 return $this->cookie->get($this->getName());
115 }
116
117 /**
118 * Removes the cookie from the browser
119 *
120 * @return void
121 */
122 public function remove()
123 {
124 // Expire it on every path it may have been written to, or an older
125 // cookie at '/' would keep suppressing the campaign.
126 foreach (\FireBox\Core\Helpers\BoxHelper::cookiePathsToClear() as $path)
127 {
128 $this->cookie->set(
129 $this->getName(),
130 $this->cookie_value,
131 strtotime('-1 day'),
132 $path,
133 \FireBox\Core\Helpers\BoxHelper::cookieDomain()
134 );
135 }
136 }
137 }