PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.22
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.22
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 / Notices / Notices.php

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

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