| 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\Notices; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use \FireBox\Core\Helpers\Plugin; |
| 20 |
|
| 21 |
class Notices |
| 22 |
{ |
| 23 |
/** |
| 24 |
* The payload. |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
private $payload; |
| 29 |
|
| 30 |
/** |
| 31 |
* The notices to exclude. |
| 32 |
* |
| 33 |
* @var array |
| 34 |
*/ |
| 35 |
private $exclude = []; |
| 36 |
|
| 37 |
/** |
| 38 |
* Define how old (in days) the file that holds all extensions data needs to be set as expired, |
| 39 |
* so we can fetch new data. |
| 40 |
* |
| 41 |
* @var int |
| 42 |
*/ |
| 43 |
private $extensions_data_file_days_old = 1; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* The license data for the given download key. |
| 49 |
* |
| 50 |
* @var array |
| 51 |
*/ |
| 52 |
protected $license_data = []; |
| 53 |
|
| 54 |
/** |
| 55 |
* Notices Instance. |
| 56 |
* |
| 57 |
* @var Notices |
| 58 |
*/ |
| 59 |
private static $instance; |
| 60 |
|
| 61 |
public function __construct($payload = []) |
| 62 |
{ |
| 63 |
$this->payload = $payload; |
| 64 |
|
| 65 |
$this->exclude = isset($this->payload['exclude']) ? $this->payload['exclude'] : []; |
| 66 |
|
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns class instance |
| 72 |
* |
| 73 |
* @param array $payload |
| 74 |
* |
| 75 |
* @return object |
| 76 |
*/ |
| 77 |
public static function getInstance($payload = []) |
| 78 |
{ |
| 79 |
if (is_null(self::$instance)) |
| 80 |
{ |
| 81 |
self::$instance = new self($payload); |
| 82 |
} |
| 83 |
|
| 84 |
return self::$instance; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Show all available notices. |
| 89 |
* |
| 90 |
* @return void |
| 91 |
*/ |
| 92 |
public function show() |
| 93 |
{ |
| 94 |
// Show only for Super Users |
| 95 |
if (!$this->isSuperUser()) |
| 96 |
{ |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
$this->loadAssets(); |
| 101 |
|
| 102 |
$payload = [ |
| 103 |
'exclude' => $this->exclude |
| 104 |
]; |
| 105 |
|
| 106 |
echo firebox()->renderer->admin->render('notices/tmpl', $payload); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 107 |
} |
| 108 |
|
| 109 |
private function loadAssets() |
| 110 |
{ |
| 111 |
wp_register_style( |
| 112 |
'firebox-notices', |
| 113 |
FBOX_MEDIA_ADMIN_URL . 'css/notices.css', |
| 114 |
[], |
| 115 |
FBOX_VERSION, |
| 116 |
false |
| 117 |
); |
| 118 |
wp_enqueue_style('firebox-notices'); |
| 119 |
|
| 120 |
if (apply_filters('firebox/load_notices', true)) |
| 121 |
{ |
| 122 |
// load notices js |
| 123 |
wp_register_script( |
| 124 |
'firebox-notices', |
| 125 |
FBOX_MEDIA_ADMIN_URL . 'js/notices.js', |
| 126 |
[], |
| 127 |
FBOX_VERSION, |
| 128 |
true |
| 129 |
); |
| 130 |
wp_enqueue_script('firebox-notices'); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Check if the current user is a Super User. |
| 138 |
* |
| 139 |
* @return bool |
| 140 |
*/ |
| 141 |
private function isSuperUser() |
| 142 |
{ |
| 143 |
return current_user_can('manage_options'); |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* Returns the base notices. |
| 148 |
* |
| 149 |
* @param array $notices |
| 150 |
* |
| 151 |
* @return array |
| 152 |
*/ |
| 153 |
private function getBaseNotices() |
| 154 |
{ |
| 155 |
$base_notices = [ |
| 156 |
'UsageTracking', |
| 157 |
'UpgradeToPro', |
| 158 |
'Outdated', |
| 159 |
|
| 160 |
]; |
| 161 |
|
| 162 |
// Exclude notices we should not display |
| 163 |
if (count($this->exclude)) |
| 164 |
{ |
| 165 |
foreach ($base_notices as $key => $notice) |
| 166 |
{ |
| 167 |
if (!in_array($notice, $this->exclude)) |
| 168 |
{ |
| 169 |
continue; |
| 170 |
} |
| 171 |
|
| 172 |
unset($base_notices[$key]); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
// Allow to filter which base notices to display |
| 177 |
$base_notices = apply_filters('firebox/base_notices', $base_notices); |
| 178 |
|
| 179 |
if (!$base_notices) |
| 180 |
{ |
| 181 |
return []; |
| 182 |
} |
| 183 |
|
| 184 |
$notices = []; |
| 185 |
|
| 186 |
// Initialize notices |
| 187 |
foreach ($base_notices as $key => $notice) |
| 188 |
{ |
| 189 |
$class = '\FireBox\Core\Notices\Notices\\' . $notice; |
| 190 |
|
| 191 |
// Skip empty notice |
| 192 |
if (!$html = (new $class($this->payload))->render()) |
| 193 |
{ |
| 194 |
continue; |
| 195 |
} |
| 196 |
|
| 197 |
$notices[strtolower($notice)] = $html; |
| 198 |
} |
| 199 |
|
| 200 |
return $notices; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
/** |
| 206 |
* Returns the based notices: |
| 207 |
* |
| 208 |
* Notices: |
| 209 |
* - Base notices |
| 210 |
* - Outdated |
| 211 |
* - Download Key |
| 212 |
* - Geolocation |
| 213 |
* - Upgrade To Pro |
| 214 |
* - Update notice |
| 215 |
* - Extension expires in date |
| 216 |
* - Extension expired at date |
| 217 |
* - Rate (If none of the license-related notices appear) |
| 218 |
* |
| 219 |
* @return string |
| 220 |
*/ |
| 221 |
public function getNotices() |
| 222 |
{ |
| 223 |
// Check and Update the local licenses data |
| 224 |
$this->checkAndUpdateExtensionsData(); |
| 225 |
|
| 226 |
$notices = $this->getBaseNotices(); |
| 227 |
|
| 228 |
// Show Update Notice |
| 229 |
if (!isset($notices['outdated']) && $update_html = (new Notices\Update($this->payload))->render()) |
| 230 |
{ |
| 231 |
$notices['update'] = $update_html; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
if ($rate_html = (new Notices\Rate($this->payload))->render()) |
| 236 |
{ |
| 237 |
$notices['rate'] = $rate_html; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
return $notices; |
| 242 |
} |
| 243 |
|
| 244 |
/** |
| 245 |
* Checks whether the current extensions data has expired and updates the data file. |
| 246 |
* |
| 247 |
* Also checks and sets the installation date of the extension. |
| 248 |
* |
| 249 |
* @return void |
| 250 |
*/ |
| 251 |
public function checkAndUpdateExtensionsData() |
| 252 |
{ |
| 253 |
|
| 254 |
|
| 255 |
// Set installation date |
| 256 |
Plugin::setExtensionData('install_date', gmdate('Y-m-d H:i:s')); |
| 257 |
|
| 258 |
// Set annual recurring cost |
| 259 |
if (isset($this->license_data['annual_recurring_cost'])) |
| 260 |
{ |
| 261 |
Plugin::setExtensionData('annual_recurring_cost', $this->license_data['annual_recurring_cost'], true, 15); |
| 262 |
} |
| 263 |
|
| 264 |
// Set user_id |
| 265 |
if (isset($this->license_data['user_id'])) |
| 266 |
{ |
| 267 |
Plugin::setExtensionData('user_id', $this->license_data['user_id'], true, 15); |
| 268 |
} |
| 269 |
} |
| 270 |
} |