PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.10
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.10
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.10, at includes/NotificationX.php

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