| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.1 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2021 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2026 FirePlugins All Rights Reserved | |
| 9 | 9 | * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | namespace FireBox\Core\FB; |
| @@ -25,8 +25,15 @@ | ||
| 25 | 25 | */ |
| 26 | 26 | private $box; |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | + * The cookie instance | |
| 30 | + * | |
| 31 | + * @var object | |
| 32 | + */ | |
| 33 | + private $cookie; | |
| 34 | + | |
| 35 | + /** | |
| 29 | 36 | * The value of the cookie |
| 30 | 37 | * |
| 31 | 38 | * @var int |
| 32 | 39 | */ |
| @@ -32,22 +39,15 @@ | ||
| 32 | 39 | */ |
| 33 | 40 | private $cookie_value = 1; |
| 34 | 41 | |
| 35 | 42 | /** |
| 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 | 43 | * Class constructor |
| 44 | 44 | * |
| 45 | 45 | * @param integer $box_id The box's ID |
| 46 | 46 | */ |
| 47 | - public function __construct($box_id) | |
| 47 | + public function __construct($box) | |
| 48 | 48 | { |
| 49 | - $this->box = firebox()->boxes->getBox()->get($box_id, null); | |
| 49 | + $this->box = $box; | |
| 50 | 50 | $this->cookie = new \FPFramework\Libs\Cookie(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| @@ -56,9 +56,9 @@ | ||
| 56 | 56 | * @return string |
| 57 | 57 | */ |
| 58 | 58 | private function getName() |
| 59 | 59 | { |
| 60 | - return isset($this->box->ID) ? 'firebox_' . $this->box->ID : ''; | |
| 60 | + return isset($this->box->ID) ? \FireBox\Core\Helpers\BoxHelper::cookiePrefix() . $this->box->ID : ''; | |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Store cookie in the browser |
| @@ -66,8 +66,13 @@ | ||
| 66 | 66 | * @return void |
| 67 | 67 | */ |
| 68 | 68 | public function set() |
| 69 | 69 | { |
| 70 | + if (!is_object($this->box) || !isset($this->box->params)) | |
| 71 | + { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + | |
| 70 | 75 | $cookie_type = $this->box->params->get('assign_cookietype', 'days'); |
| 71 | 76 | |
| 72 | 77 | switch ($cookie_type) |
| 73 | 78 | { |
| @@ -88,9 +93,16 @@ | ||
| 88 | 93 | default: |
| 89 | 94 | $expire = 0; // session |
| 90 | 95 | } |
| 91 | 96 | |
| 92 | - $this->cookie->set($this->getName(), $this->cookie_value, $expire, $this->cookie_path); | |
| 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 | + ); | |
| 93 | 105 | } |
| 94 | 106 | |
| 95 | 107 | /** |
| 96 | 108 | * Check if the cookie of the box exist |
| @@ -108,7 +120,18 @@ | ||
| 108 | 120 | * @return void |
| 109 | 121 | */ |
| 110 | 122 | public function remove() |
| 111 | 123 | { |
| 112 | - $this->cookie->set($this->getName(), $this->cookie_value, strtotime('-1 day'), $this->cookie_path); | |
| 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 | + } | |
| 113 | 136 | } |
| 114 | 137 | } |