PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.4
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.4
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 1.0.4, at Inc/Core/FB/Cookie.php

114 lines 2.7 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.4 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\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 value of the cookie
30 *
31 * @var int
32 */
33 private $cookie_value = 1;
34
35 /**
36 * The path of the cookie. It should be available in the whole domain.
37 *
38 * @var string
39 */
40 private $cookie_path = '/';
41
42 /**
43 * Class constructor
44 *
45 * @param integer $box_id The box's ID
46 */
47 public function __construct($box_id)
48 {
49 $this->box = firebox()->box->get($box_id);
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_' . $this->box->ID : '';
61 }
62
63 /**
64 * Store cookie in the browser
65 *
66 * @return void
67 */
68 public function set()
69 {
70 $cookie_type = $this->box->params->get('assign_cookietype', 'days');
71
72 switch ($cookie_type)
73 {
74 case 'never':
75 return;
76
77 case 'ever':
78 $expire = strtotime('now +20 years'); // forever
79 break;
80
81 case 'custom':
82 $assign_cookietype_param_custom_period_times = (int) $this->box->params->get('assign_cookietype_param_custom_period_times', 1);
83 $assign_cookietype_param_custom_period = $this->box->params->get('assign_cookietype_param_custom_period', 'days');
84
85 $expire = strtotime('now +' . (int) $assign_cookietype_param_custom_period_times . ' ' . $assign_cookietype_param_custom_period);
86 break;
87
88 default:
89 $expire = 0; // session
90 }
91
92 $this->cookie->set($this->getName(), $this->cookie_value, $expire, $this->cookie_path, '', true);
93 }
94
95 /**
96 * Check if the cookie of the box exist
97 *
98 * @return bool
99 */
100 public function exist()
101 {
102 return $this->cookie->get($this->getName());
103 }
104
105 /**
106 * Removes the cookie from the browser
107 *
108 * @return void
109 */
110 public function remove()
111 {
112 $this->cookie->set($this->getName(), $this->cookie_value, strtotime('-1 day'), $this->cookie_path);
113 }
114 }