PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.13
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.13
3.3.1 3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 All 156 releases
notificationx / includes / NotificationX.php

NotificationX.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.13, at includes/NotificationX.php

347 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * NotificationX File
5 *
6 * @package NotificationX
7 */
8
9 namespace NotificationX;
10
11 use NotificationX\Admin\Admin;
12 use NotificationX\Admin\Cron;
13 use NotificationX\Admin\EntriesMailReceiver;
14 use NotificationX\Admin\Settings;
15 use NotificationX\Blocks\Blocks;
16 use NotificationX\Core\Database;
17 use NotificationX\Core\PostType;
18 use NotificationX\Core\QuickBuild;
19 use NotificationX\Core\REST;
20 use NotificationX\Core\ShortcodeInline;
21 use NotificationX\Core\Targeting;
22 use NotificationX\Core\Upgrader;
23 use NotificationX\Extensions\GlobalFields;
24 use NotificationX\FrontEnd\FrontEnd;
25 use NotificationX\Types\TypeFactory;
26 use NotificationX\Extensions\ExtensionFactory;
27 use NotificationX\ThirdParty\WPML;
28 use NotificationX\Core\WPDRoleManagement;
29 use NotificationX\ThirdParty\VisualPortfolio;
30 use NotificationX\Extensions\Elementor\ElementorManager;
31
32 /**
33 * Plugin Engine.
34 * @method static NotificationX get_instance($args = null)
35 */
36 class NotificationX {
37 /**
38 * Instance of NotificationX
39 * @var NotificationX
40 */
41 use GetInstance;
42 /**
43 * Settings
44 * @var Settings
45 */
46 public $settings;
47 /**
48 * WP_CLI
49 * @var boolean
50 */
51 public static $WP_CLI = false;
52 /**
53 * Invoked initially.
54 */
55 public function __construct() {
56 static::$WP_CLI = defined('WP_CLI') && WP_CLI;
57 $this->settings = Settings::get_instance([
58 'key' => 'notificationx',
59 'auto_commit' => true,
60 'debug' => false,
61 'store' => 'options',
62 ]);
63
64 $args = Settings::get_instance()->get_role_map();
65 new WPDRoleManagement($args);
66
67 Upgrader::get_instance();
68 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Reviewed for the NotificationX codebase: acceptable in this context.
69 if (is_admin() || empty($_GET['frontend']) || $_GET['frontend'] != true) {
70 Admin::get_instance();
71 }
72 FrontEnd::get_instance();
73 add_action('admin_init', [$this, 'maybe_redirect'], 10);
74 add_action('init', [$this, 'init'], 10);
75 add_action('plugins_loaded', array($this, 'init_extension'));
76 add_filter('nx_pro_alert_popup', array($this, 'pro_alert_popup'));
77 add_action( 'init', [ $this, 'register_custom_image_size' ] );
78 /**
79 * Register all REST Endpoint
80 */
81 REST::get_instance();
82 // Country/user-role targeting for ALL notification types (decoupled from the bar module).
83 Targeting::get_instance();
84 Cron::get_instance();
85 QuickBuild::get_instance();
86 ShortcodeInline::get_instance();
87 Blocks::get_instance();
88
89 CoreInstaller::get_instance(basename(NOTIFICATIONX_FILE, '.php'));
90
91 // 3rd Party features.
92 WPML::get_instance();
93 VisualPortfolio::get_instance();
94 if ( did_action( 'elementor/loaded' ) ) {
95 ElementorManager::get_instance();
96 } else {
97 add_action( 'elementor/loaded', [ ElementorManager::class, 'get_instance' ] );
98 }
99 EntriesMailReceiver::get_instance();
100 }
101 /**
102 * The Plugin Activator
103 * @return void
104 */
105 public function activator(){
106 // nx_activated
107 Database::get_instance()->Create_DB();
108 if( ! static::$WP_CLI && current_user_can( 'delete_users' ) ) {
109 set_transient( 'nx_activated', true, 30 );
110 }
111 Upgrader::get_instance()->clear_transient();
112 }
113
114 public function maybe_redirect(){
115 if( static::$WP_CLI || wp_doing_ajax() ) {
116 return;
117 }
118 // Bail if no activation transient is set.
119 if ( ! get_transient( 'nx_activated' ) ) {
120 return;
121 }
122 // Delete the activation transient.
123 delete_transient( 'nx_activated' );
124
125 if ( ! is_multisite() ) {
126 // First activation: launch the onboarding Setup Wizard, otherwise
127 // fall back to the dashboard. The wizard marks itself completed on
128 // finish/skip so this only fires once.
129 $page = \NotificationX\Core\SetupWizard::is_completed() ? 'nx-dashboard' : 'nx-setup-wizard';
130 wp_safe_redirect( add_query_arg( array(
131 'page' => $page
132 ), admin_url( 'admin.php' ) ) );
133 }
134 }
135
136 public function init_extension() {
137 // TypeFactory::get_instance();
138 ExtensionFactory::get_instance();
139 }
140
141 public function init() {
142 /**
143 * Run All Actions and Filters
144 * for GOOD.
145 */
146 // load_plugin_textdomain( 'notificationx', false, dirname( plugin_basename( NOTIFICATIONX_FILE ) ) . '/languages' );
147
148 // @todo remove
149 if(defined('NX_DEBUG') && NX_DEBUG){
150 add_action('wp_ajax_nx', [$this, 'get_tabs']); // executed when logged in
151 }
152
153 add_action( 'plugin_action_links_' . NOTIFICATIONX_BASENAME, array($this, 'nx_action_links'), 10, 1);
154 }
155
156 public function pro_alert_popup($args) {
157 if ( !empty($args)){
158 $args = wp_parse_args($args, [
159 "showConfirmButton"=> true,
160 "showCloseButton"=>true,
161 "title" => __('Opps! This is PRO Feature.', 'notificationx'),
162 "customClass"=> [
163 "container"=> 'pro-video-popup',
164 "closeButton"=> 'pro-video-close-button',
165 "icon"=> 'pro-video-icon',
166 "title"=> 'pro-video-title',
167 "content"=> 'pro-video-content',
168 "actions"=> 'nx-pro-alert-actions',
169 "confirmButton"=> 'pro-video-confirm-button',
170 "denyButton"=> 'pro-video-deny-button',
171 ],
172 ]);
173 }
174 return $args;
175 }
176
177 /**
178 * This function is hooked
179 * @hooked plugin_action_links_
180 * @param array $links
181 * @return array
182 * @since 1.2.4
183 */
184 public function nx_action_links( $links ) {
185 $deactivate_link = isset( $links['deactivate'] ) ? $links['deactivate'] : '';
186 unset($links['deactivate']);
187 $links['settings'] = '<a href="' . admin_url('admin.php?page=nx-settings') . '">' . __('Settings','notificationx') .'</a>';
188 if( ! empty( $deactivate_link ) ) {
189 $links['deactivate'] = $deactivate_link;
190 }
191 if( ! is_plugin_active('notificationx-pro/notificationx-pro.php' ) ) {
192 $links['pro'] = '<a href="' . esc_url('https://notificationx.com/#pricing') . '" target="_blank" style="color: #349e34;"><b>' . __('Go Pro','notificationx') .'</b></a>';
193 }
194 return $links;
195 }
196
197 /**
198 * Checks whether pro plugin is active.
199 *
200 * @return boolean
201 */
202 public static function is_pro() {
203 return class_exists('\NotificationXPro\NotificationX');
204 }
205 /**
206 * Get Tabs array in json.
207 *
208 * @return json
209 */
210 public function get_tabs() {
211 $tabs = GlobalFields::get_instance()->tabs();
212 // $tabs = Settings::get_instance()->get_form_data();
213 $fields = $this->get_field_names($tabs['tabs']);
214 wp_send_json($tabs);
215 }
216 /**
217 * Convert `fields` associative array to numeric array recursively.
218 * @todo improve implementation.
219 *
220 * @param array $arr
221 * @return array
222 */
223 public function normalize($arr) {
224
225 if (!empty($arr['fields'])) {
226 $arr['fields'] = array_values($arr['fields']);
227 }
228
229 if (!empty($arr['options'])) {
230 $arr['options'] = array_values($arr['options']);
231 }
232
233 if (!empty($arr['tabs'])) {
234 $arr['tabs'] = array_values($arr['tabs']);
235 }
236
237 if (is_array($arr)) {
238 foreach ($arr as $key => $value) {
239 if (is_array($value)) {
240 $arr[$key] = $this->normalize($value);
241 }
242 }
243 }
244 return $arr;
245 }
246
247 public function normalize_post($settings) {
248 $fields = $this->get_field_names();
249 foreach ($fields as $key => $value) {
250 if (!isset($settings[$key]) && isset($value['default'])) {
251 $settings[$key] = $value['default'];
252 }
253 if (isset( $value['type'] ) && ($value['type'] == 'checkbox' || $value['type'] == 'toggle')) {
254 $settings[$key] = (bool) (isset($settings[$key]) ? $settings[$key] : false);
255 }
256 if (isset( $value['type'] ) && $value['type'] == 'number') {
257 $settings[$key] = isset($settings[$key]) ? $settings[$key] : 0;
258 $settings[$key] = is_numeric($settings[$key]) ? $settings[$key] + 0 : 0;
259 }
260 }
261 return $settings;
262 }
263
264 public function get_tab(){
265 $tabs = get_transient('nx_builder_fields');
266 if(empty($tabs) || (defined('NX_DEBUG') && NX_DEBUG)){
267 $tabs = GlobalFields::get_instance()->tabs();
268 set_transient( 'nx_builder_fields', $tabs, DAY_IN_SECONDS );
269 }
270 return $tabs;
271 }
272
273 public function get_field_names($tabs = null){
274 $fields = [];
275 if(empty($tabs)){
276 $tabs = $this->get_tab();
277 }
278 if(!empty($tabs['tabs'])){
279 $fields = $this->_get_field_names($tabs['tabs']);
280 }
281 return $fields;
282 }
283
284 public function get_field($field_name){
285 $fields = $this->get_field_names();
286 if(!empty($fields[$field_name])){
287 return $fields[$field_name];
288 }
289 }
290
291 // @todo maybe remove if not used in future.
292 public function _get_field_names($fields, $names = []) {
293 foreach ($fields as $key => $field) {
294 if (empty($field['type'])) {
295 $names = $this->_get_field_names($field['fields'], $names);
296 } else if ($field['type'] == 'section' || $field['type'] == 'group') { //
297 $_names = $this->_get_field_names($field['fields'], []);
298 if ($field['type'] == 'section')
299 $names = array_merge($names, $_names);
300 else
301 foreach ($_names as $key => $value) {
302 $names[$field['name']][$key] = [
303 'type' => $value['type'],
304 'default' => isset($value['default']) ? $value['default'] : '',
305 'help' => isset($value['help']) ? $value['help'] : '',
306 'label' => isset($value['label']) ? $value['label'] : '',
307 'parent_label' => isset($field['label']) ? $field['label'] : '',
308 ];
309 }
310 } elseif (!empty($field['name'])) {
311 $names[$field['name']] = [
312 'type' => $field['type'],
313 'default' => isset($field['default']) ? $field['default'] : '',
314 'help' => isset($field['help']) ? $field['help'] : '',
315 'label' => isset($field['label']) ? $field['label'] : '',
316 'multiple' => isset($field['multiple']) ? $field['multiple'] : '',
317 ];
318 }
319 }
320
321 return $names;
322 }
323
324 function my_upgrade_function( $upgrader_object, $options ) {
325 $current_plugin_path_name = plugin_basename( __FILE__ );
326
327 if ($options['action'] == 'update' && $options['type'] == 'plugin' ) {
328 foreach($options['plugins'] as $each_plugin) {
329 if ($each_plugin==$current_plugin_path_name) {
330 // .......................... YOUR CODES .............
331
332 }
333 }
334 }
335 }
336
337
338 public function register_custom_image_size() {
339 add_image_size('_nx_notification_thumb_100_100', 100, 100, true);
340 add_image_size('_nx_notification_thumb_200_200', 200, 200, true);
341 add_image_size('_nx_notification_thumb_300_300', 300, 300, true);
342 add_image_size('_nx_notification_thumb_400_400', 400, 400, true);
343 add_image_size('_nx_notification_thumb_500_500', 500, 500, true);
344 }
345
346 }
347