PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.12
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.12
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 / Core / Migration.php

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

1,279 lines 66.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Extension Factory
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Core;
10
11 use NotificationX\Admin\Cron;
12 use NotificationX\Admin\Settings;
13 use NotificationX\Extensions\ConvertKit\ConvertKit;
14 use NotificationX\Extensions\CustomNotification\CustomNotification;
15 use NotificationX\Extensions\CustomNotification\CustomNotificationConversions;
16 use NotificationX\Extensions\Envato\Envato;
17 use NotificationX\Extensions\ExtensionFactory;
18 use NotificationX\Extensions\Freemius\FreemiusConversions;
19 use NotificationX\Extensions\Freemius\FreemiusReviews;
20 use NotificationX\Extensions\Freemius\FreemiusStats;
21 use NotificationX\Extensions\Google_Analytics\Google_Analytics;
22 use NotificationX\Extensions\MailChimp\MailChimp;
23 use NotificationX\Extensions\WooCommerce\WooCommerce as WooCommerce;
24 use NotificationX\Extensions\WordPress\WPOrgReview;
25 use NotificationX\Extensions\WordPress\WPOrgStats;
26 use NotificationX\GetInstance;
27 use NotificationX\Types\Conversions;
28 use NotificationXPro\Feature\SalesFeatures;
29
30 /**
31 * Migration Class
32 * @method static Migration get_instance($args = null)
33 */
34 class Migration {
35 /**
36 * Instance of Migration
37 *
38 * @var Migration
39 */
40 use GetInstance;
41
42 private $stats = [];
43
44 /**
45 * Initially Invoked when initialized.
46 */
47 public function __construct() {
48 add_action('plugins_loaded', [$this, 'plugins_loaded']);
49 }
50
51 public function plugins_loaded() {
52 // @todo check version.
53 global $wpdb;
54 $wpdb->show_errors();
55 $this->migrate_options();
56 $posts = $this->migrate_posts();
57 $this->migrate_entries($posts);
58
59 // delete options
60 // @todo uncomment
61 // delete_option('notificationx_data');
62 // delete_option('notificationx_settings');
63 }
64
65 public function migrate_options() {
66 $settings = get_option('notificationx_settings', []);
67 if($settings){
68 if(!empty($settings['nx_modules'])){
69 $settings['modules'] = $settings['nx_modules'];
70 unset($settings['nx_modules']);
71 }
72 $settings['is_migrated'] = true;
73 Settings::get_instance()->set('settings', $settings);
74
75 $ga_option_key = Google_Analytics::get_instance()->option_key;
76 $pa_options = get_option($ga_option_key, []);
77 if($pa_options){
78 Settings::get_instance()->set("settings.{$ga_option_key}", $pa_options);
79 }
80 if(!empty($settings['ga_profile'])){
81 $ga_profile = $settings['ga_profile'];
82 Settings::get_instance()->set("settings.ga_profile", $ga_profile);
83 }
84
85
86 $convertkit_api_key = get_option( 'nxpro_convertkit_api_key', '' );
87 $convertkit_api_secret = get_option( 'nxpro_convertkit_api_secret', '' );
88 Settings::get_instance()->set('settings.convertkit_api_key', $convertkit_api_key);
89 Settings::get_instance()->set('settings.convertkit_api_secret', $convertkit_api_secret);
90
91 }
92
93 // @todo move to ReportEmail.php
94 $nx_daily = get_option("nx_daily_mail_sent", false);
95 $nx_weekly = get_option("nx_weekly_mail_sent", false);
96 $nx_monthly = get_option("nx_monthly_mail_sent", false);
97 Settings::get_instance()->set("reporting", [
98 'mail_sent' => [
99 'daily' => $nx_daily,
100 'weekly' => $nx_weekly,
101 'monthly' => $nx_monthly,
102 ]
103 ]);
104 }
105
106 public function migrate_posts() {
107 global $wpdb;
108 $posts = [];
109 $post_meta = [];
110 $query = "SELECT * FROM $wpdb->posts WHERE post_type = 'notificationx'"; // AND ID = $id
111 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- False positive: the query is prepared via $this->wpdb->prepare(), which this sniff does not recognise, and only $wpdb->prefix table names are interpolated. Audited 2026-07-16.
112 $_posts = $wpdb->get_results($query, ARRAY_A);
113 // $nx_ids = array_column($_posts, 'ID');
114
115 if(empty($_posts)) return false;
116
117 // $nx_ids = implode(", ", $nx_ids);
118 // $main_query = "SELECT * FROM $wpdb->postmeta WHERE post_id IN ( $nx_ids )";
119 // $_post_meta = $wpdb->get_results($main_query, ARRAY_A);
120
121 // foreach ($_post_meta as $meta) {
122 // $pid = $meta['post_id'];
123 // $key = $meta['meta_key'];
124 // $_value = maybe_unserialize($meta['meta_value']);
125 // if ($key == '_nx_meta' && is_array($_value)) {
126 // foreach ($_value as $key => $value) {
127 // $post_meta[$pid]["_nx_meta_$key"] = $value;
128 // }
129 // } else {
130 // if( $key === "_nx_meta_impression_per_day" ) {
131 // $post_meta[$pid][$key][] = $_value;
132 // } else {
133 // $post_meta[$pid][$key] = $_value;
134 // }
135 // }
136 // }
137 // wp_send_json($post_meta);
138
139 foreach ($_posts as $key => $post) {
140 if ($post['post_type'] != 'notificationx' || $post['post_status'] == 'auto-draft' || $post['post_status'] == 'draft') { // && $post['post_status'] == 'trash'
141 continue;
142 }
143
144 $pid = $post['ID'];
145
146 $is_exist = PostType::get_instance()->get_col('nx_id', ['nx_id' => $pid]);
147
148 if (empty($is_exist)) {
149 try {
150 $post_meta = $this->get_normalize_meta( $pid );
151 if(!empty($post_meta)){
152 // we need to do create post first so that we can save entries.
153 $nx_id = PostType::get_instance()->insert_post([
154 'nx_id' => $post['ID'],
155 'title' => $post['post_title'],
156 ]);
157 $post = array_merge($post, $post_meta, ['nx_id' => $nx_id]);
158 $data = $this->migrate_post($post);
159 $posts[$pid] = [ 'source' => $data['source'] ];
160 $this->migrate_stats($post);
161 $post_date = (!empty($post['post_date_gmt']) && $post['post_date_gmt'] != '0000-00-00 00:00:00' ) ? $post['post_date_gmt'] : get_gmt_from_date($post['post_date']);
162 $post_modified = (!empty($post['post_modified_gmt']) && $post['post_modified_gmt'] != '0000-00-00 00:00:00' ) ? $post['post_modified_gmt'] : get_gmt_from_date($post['post_modified']);
163 $status = !empty($data['enabled']) ? $data['enabled'] : false;
164 if($post['post_status'] == 'trash'){
165 $status = false;
166 $data['trash'] = true;
167 // $post['post_title'] = "Trash > " . $post['post_title'];
168 }
169
170 PostType::get_instance()->update_post([
171 'nx_id' => $data['nx_id'],
172 'type' => $data['type'],
173 'source' => $data['source'],
174 'theme' => $data['themes'],
175 'global_queue' => !empty($data['global_queue']) ? $data['global_queue'] : false,
176 'enabled' => $status,
177 'title' => $post['post_title'],
178 'data' => $data,
179 'created_at' => $post_date,
180 'updated_at' => $post_modified,
181 ], $nx_id);
182 }
183
184 } catch (\Exception $e) {
185 //throw $th;
186 }
187 }
188 }
189
190 // delete post & meta;
191 // @todo uncomment
192 // $query = "DELETE FROM $wpdb->posts WHERE ID in ($nx_ids)"; // AND ID = $id
193 // $wpdb->query($query);
194 // $query = "DELETE FROM $wpdb->postmeta WHERE post_id in ($nx_ids)"; // AND ID = $id
195 // $wpdb->query($query);
196
197 return $posts;
198 }
199
200 public function get_normalize_meta( $id ){
201 $metas = get_post_meta( $id );
202 $_metas = [];
203 if( ! empty( $metas ) && is_array( $metas ) ) {
204 array_walk( $metas, function( $value, $key ) use ( &$_metas ) {
205 $_value = maybe_unserialize( $value[0] );
206 if ($key == '_nx_meta' && is_array($_value)) {
207 foreach ($_value as $_key => $value) {
208 $_metas["_nx_meta_$_key"] = $value;
209 }
210 } else {
211 if( $key === "_nx_meta_impression_per_day" ) {
212 $_metas[$key][] = $_value;
213 } else {
214 $_metas[$key] = $_value;
215 }
216 }
217 });
218 }
219
220 return $_metas;
221 }
222
223 public function migrate_post($_post) {
224 $post = [];
225 // get() function use $this->_post
226 $this->_post = $_post;
227 $nx_id = $this->get('ID');
228
229 $post['id'] = $this->get('ID');
230 $post['nx_id'] = $this->get('ID');
231 $post['title'] = $this->get('post_title');
232 $post['type'] = $this->get('_nx_meta_display_type');
233 $post['currentTab'] = $this->get('_nx_builder_current_tab');
234 $post['enabled'] = $this->get('_nx_meta_active_check');
235 $post['is_migrated'] = true;
236
237 $post['utm_campaign'] = $this->get("_nx_meta_utm_campaign");
238 $post['utm_medium'] = $this->get("_nx_meta_utm_medium");
239 $post['utm_source'] = $this->get("_nx_meta_utm_source");
240 $post['utm_source'] = $this->get("_nx_meta_utm_source");
241
242 // Display
243 $post['show_on'] = $this->get("_nx_meta_show_on");
244 $post['all_locations'] = $this->get("_nx_meta_all_locations");
245 $post['show_on_display'] = $this->get("_nx_meta_show_on_display");
246
247 $post['notification-template'] = [];
248
249 // Customize
250 $post['position'] = $this->get("_nx_meta_conversion_position");
251 $post['size'] = $this->get("_nx_meta_conversion_size");
252 $post['close_button'] = (bool) $this->get("_nx_meta_close_button");
253 $post['hide_on_mobile'] = (bool) $this->get("_nx_meta_hide_on_mobile");
254 $post['global_queue'] = (bool) $this->get("_nx_meta_global_queue_active");
255 $post['delay_before'] = $this->get("_nx_meta_delay_before");
256 $post['initial_delay'] = $this->get("_nx_meta_initial_delay");
257 $post['auto_hide'] = $this->get("_nx_meta_auto_hide");
258 $post['hide_after'] = $this->get("_nx_meta_hide_after");
259 $post['display_for'] = $this->get("_nx_meta_display_for");
260 $post['delay_between'] = $this->get("_nx_meta_delay_between");
261 $post['display_last'] = $this->get("_nx_meta_display_last");
262 $post['display_from'] = $this->get("_nx_meta_display_from");
263 $post['loop'] = (bool) $this->get("_nx_meta_loop");
264 $post['link_open'] = (bool) $this->get("_nx_meta_link_open");
265 $post['custom_ids'] = $this->get("_nx_meta_custom_ids");
266 if ($this->get("_nx_meta_sound_checkbox")) {
267 $post['volume'] = $this->get("_nx_meta_volume") * 100;
268 }
269
270 // Display Tab
271 $post['show_notification_image'] = $this->get("_nx_meta_show_notification_image");
272 $post['show_default_image'] = (bool) $this->get("_nx_meta_show_default_image");
273 $post['default_avatar'] = $this->get("_nx_meta_default_avatar");
274 $post['image_url'] = $this->get("_nx_meta_image_url");
275
276
277 switch ($post['type']) {
278 case 'conversions':
279 // Source Tab
280 $post['source'] = $this->get("_nx_meta_conversion_from");
281
282 // Theme Tab
283 $post['themes'] = $this->get("_nx_meta_theme");
284 $post['advance_edit'] = $this->get("_nx_meta_advance_edit");
285 $post['bg_color'] = $this->get("_nx_meta_bg_color");
286 $post['text_color'] = $this->get("_nx_meta_text_color");
287 $post['border'] = $this->get("_nx_meta_border");
288 $post['border_size'] = $this->get("_nx_meta_border_size");
289 $post['border_style'] = $this->get("_nx_meta_border_style");
290 $post['border_color'] = $this->get("_nx_meta_border_color");
291 $post['image_shape'] = $this->get("_nx_meta_image_shape");
292 $post['image_position'] = $this->get("_nx_meta_image_position");
293 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
294 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
295 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
296 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
297
298 // Content Tab
299 $post['notification-template'] = $this->get("_nx_meta_woo_template_new");
300 if($post['template_adv'] = $this->get("_nx_meta_woo_template_adv")){
301 $post['advanced_template'] = $this->get("_nx_meta_woo_template");
302 }
303
304 $post['combine_multiorder'] = $this->get("_nx_meta_combine_multiorder");
305 $post['combine_multiorder_text'] = $this->get("_nx_meta_combine_multiorder_text");
306 $post['random_order'] = $this->get("_nx_meta_random_order");
307
308 $post['link_type'] = $this->get("_nx_meta_conversion_url");
309 $post['custom_url'] = $this->get("_nx_meta_conversions_custom_url");
310
311 $post['sound'] = $this->get("_nx_meta_conversions_sound");
312
313
314 switch ($post['source']) {
315 case 'woocommerce':
316 $post['product_control'] = $this->get("_nx_meta_product_control");
317 $post['category_list'] = $this->get("_nx_meta_category_list");
318 $post['product_list'] = $this->get("_nx_meta_product_list");
319 $post['product_exclude_by'] = $this->get("_nx_meta_product_exclude_by");
320 $post['exclude_categories'] = $this->get("_nx_meta_exclude_categories");
321 $post['exclude_products'] = $this->get("_nx_meta_exclude_products");
322 break;
323 case 'edd':
324 $post['product_control'] = $this->get("_nx_meta_edd_product_control");
325 $post['category_list'] = $this->get("_nx_meta_edd_category_list");
326 $post['product_list'] = $this->get("_nx_meta_edd_product_list");
327 $post['product_exclude_by'] = $this->get("_nx_meta_edd_product_exclude_by");
328 $post['exclude_categories'] = $this->get("_nx_meta_edd_exclude_categories");
329 $post['exclude_products'] = $this->get("_nx_meta_edd_exclude_products");
330 break;
331 case 'surecart':
332 $post['product_control'] = $this->get("_nx_meta_surecart_product_control");
333 $post['category_list'] = $this->get("_nx_meta_surecart_category_list");
334 $post['product_list'] = $this->get("_nx_meta_surecart_product_list");
335 $post['product_exclude_by'] = $this->get("_nx_meta_surecart_product_exclude_by");
336 $post['exclude_categories'] = $this->get("_nx_meta_surecart_exclude_categories");
337 $post['exclude_products'] = $this->get("_nx_meta_surecart_exclude_products");
338 break;
339 case 'freemius':
340 if( boolval( $post['enabled'] ) ) {
341 Cron::get_instance()->set_cron($nx_id, 'nx_freemius_interval');
342 }
343 $post['source'] = 'freemius_conversions';
344 $post['freemius_item_type'] = $this->get("_nx_meta_freemius_item_type");
345 $post['freemius_themes'] = $this->get("_nx_meta_freemius_themes");
346 $post['freemius_plugins'] = $this->get("_nx_meta_freemius_plugins");
347
348 $sales = $this->get("_nx_meta_freemius_content");
349 $freemius = FreemiusConversions::get_instance();
350 if(is_array($sales)){
351 foreach ($sales as $key => $sale) {
352 $sales[$key] = [
353 'nx_id' => $_post['nx_id'],
354 'source' => $freemius->id,
355 'entry_key' => $sale['id'],
356 'data' => $sale,
357 ];
358 }
359 $freemius->update_notifications($sales);
360 }
361
362 break;
363 case 'zapier':
364 $post['source'] = 'zapier_conversions';
365 break;
366 case 'envato':
367 if( boolval( $post['enabled'] ) ) {
368 Cron::get_instance()->set_cron($nx_id, 'nx_envato_interval');
369 }
370 $sales = $this->get('_nx_meta_envato_content');
371 $envato = Envato::get_instance();
372 if(is_array($sales)){
373 foreach ($sales as $key => $sale) {
374 $sales[$key] = [
375 'nx_id' => $_post['nx_id'],
376 'source' => $envato->id,
377 'entry_key' => $sale['id'],
378 'data' => $sale,
379 ];
380 }
381 $envato->update_notifications($sales);
382 }
383
384 break;
385 case 'custom_notification':
386 // $post['themes'] = $this->get("_nx_meta_theme");
387 $post['sound'] = $this->get("_nx_meta_custom_sound");
388 $custom_notification = CustomNotificationConversions::get_instance();
389 $post['source'] = $custom_notification->id;
390 $post['custom_contents'] = $this->get('_nx_meta_custom_contents');
391 if(is_array($post['custom_contents'])){
392 foreach($post['custom_contents'] as &$entry){
393 if((empty($entry['name']) || $entry['name'] == __('Someone', 'notificationx')) && isset($entry['first_name']) || isset($entry['last_name'])){
394 $entry['name'] = Helper::name($entry['first_name'], $entry['last_name']);
395 }
396 if(!empty($entry['name']) && empty($entry['first_name']) && empty($entry['last_name'])){
397 $entry['first_name'] = $entry['name'];
398 }
399 }
400 }
401 break;
402 default:
403 # code...
404 break;
405 }
406
407 break;
408 case 'comments':
409 // Source Tab
410 $post['source'] = $this->get('_nx_meta_comments_source');
411 $post['themes'] = $this->get('_nx_meta_comment_theme');
412 $post['advance_edit'] = $this->get('_nx_meta_comment_advance_edit');
413
414
415 // Theme Tab
416 $post['bg_color'] = $this->get('_nx_meta_comment_bg_color');
417 $post['text_color'] = $this->get('_nx_meta_comment_text_color');
418 $post['border'] = $this->get('_nx_meta_comment_border');
419 $post['border_size'] = $this->get('_nx_meta_comment_border_size');
420 $post['border_style'] = $this->get('_nx_meta_comment_border_style');
421 $post['border_color'] = $this->get('_nx_meta_comment_border_color');
422 $post['image_shape'] = $this->get("_nx_meta_comment_image_shape");
423 $post['image_position'] = $this->get("_nx_meta_comment_image_position");
424 $post['custom_image_shape'] = $this->get("_nx_meta_comment_image_custom_shape");
425 $post['first_font_size'] = $this->get("_nx_meta_comment_first_font_size");
426 $post['second_font_size'] = $this->get("_nx_meta_comment_second_font_size");
427 $post['third_font_size'] = $this->get("_nx_meta_comment_third_font_size");
428
429 // Content Tab
430 $post['notification-template'] = $this->get("_nx_meta_comments_template_new");
431 if($post['template_adv'] = $this->get("_nx_meta_comments_template_adv")){
432 $post['advanced_template'] = $this->get("_nx_meta_comments_template");
433 }
434
435 $post['content_trim_length'] = $this->get('_nx_meta_content_trim_length');
436 $post['link_type'] = $this->get("_nx_meta_comments_url");
437 $post['custom_url'] = $this->get("_nx_meta_comments_custom_url");
438 $show_avatar = $this->get("_nx_meta_show_avatar");
439 if($show_avatar){
440 $post['show_notification_image'] = 'gravatar';
441 }
442
443 $post['sound'] = $this->get("_nx_meta_comments_sound");
444
445 switch ($post['source']) {
446 case 'wp_comments':
447 # code...
448 break;
449 default:
450 # code...
451 break;
452 }
453 break;
454 case 'reviews':
455 // Source Tab
456 $post['source'] = $this->get('_nx_meta_reviews_source');
457 $post['themes'] = $this->get('_nx_meta_wporg_theme');
458 $post['advance_edit'] = $this->get('_nx_meta_wporg_advance_edit');
459
460 // Theme Tab
461 $post['bg_color'] = $this->get('_nx_meta_wporg_bg_color');
462 $post['text_color'] = $this->get('_nx_meta_wporg_text_color');
463 $post['border'] = $this->get('_nx_meta_wporg_border');
464 $post['border_size'] = $this->get('_nx_meta_wporg_border_size');
465 $post['border_style'] = $this->get('_nx_meta_wporg_border_style');
466 $post['border_color'] = $this->get('_nx_meta_wporg_border_color');
467 $post['image_shape'] = $this->get("_nx_meta_wporg_image_shape");
468 $post['image_position'] = $this->get("_nx_meta_wporg_image_position");
469 $post['first_font_size'] = $this->get("_nx_meta_wporg_first_font_size");
470 $post['second_font_size'] = $this->get("_nx_meta_wporg_second_font_size");
471 $post['third_font_size'] = $this->get("_nx_meta_wporg_third_font_size");
472
473 // Content Tab
474 $post['wp_reviews_product_type'] = $this->get("_nx_meta_wp_reviews_product_type");
475 $post['wp_reviews_slug'] = $this->get("_nx_meta_wp_reviews_slug");
476 if ($post['themes'] == 'review_saying') {
477 $post['notification-template'] = $this->get("_nx_meta_review_saying_template_new");
478 } else {
479 $post['notification-template'] = $this->get("_nx_meta_wp_reviews_template_new");
480 }
481 if($post['template_adv'] = $this->get("_nx_meta_wp_reviews_template_adv")){
482 $post['advanced_template'] = $this->get("_nx_meta_wp_reviews_template");
483 }
484
485 $post['content_trim_length'] = $this->get('_nx_meta_content_trim_length');
486 $post['link_type'] = $this->get("_nx_meta_rs_url");
487 $post['custom_url'] = $this->get("_nx_meta_rs_custom_url");
488
489 $post['sound'] = $this->get("_nx_meta_reviews_sound");
490
491 switch ($post['source']) {
492 case 'wp_reviews':
493 if( boolval( $post['enabled'] ) ) {
494 Cron::get_instance()->set_cron($nx_id, 'nx_wp_review_interval');
495 }
496
497 $plugin_data = $this->get('_nx_meta_wporg_review_content');
498 if (!empty($plugin_data['reviews'])) {
499 $reviews = $plugin_data['reviews'];
500 unset($plugin_data['reviews']);
501 $WPR = WPOrgReview::get_instance();
502 if(is_array($reviews)){
503 foreach ($reviews as $key => $review) {
504 $reviews[$key] = [
505 'nx_id' => $_post['nx_id'],
506 'source' => $WPR->id,
507 'entry_key' => $review['username'],
508 'data' => array_merge($review, $plugin_data),
509 ];
510 }
511 $WPR->update_notifications($reviews);
512 }
513 }
514
515 break;
516 case 'woo_reviews':
517 if(!empty($post['notification-template']) && is_array($post['notification-template'])){
518 foreach ($post['notification-template'] as $key => &$value) {
519 if($key == 'third_param' && $value == 'tag_plugin_name'){
520 $value = 'tag_product_title';
521 }
522 }
523 }
524 if(!empty($post['advanced_template']) && is_array($post['advanced_template'])){
525 foreach ($post['advanced_template'] as $key => &$value) {
526 $value = str_replace('{{plugin_name}}', '{{product_title}} ', $value);
527 }
528 }
529 # code...
530 break;
531 case 'reviewx':
532 # code...
533 break;
534 case 'freemius':
535 if( boolval( $post['enabled'] ) ) {
536 Cron::get_instance()->set_cron($nx_id, 'nx_freemius_interval');
537 }
538 // Content Tab
539 $post['source'] = 'freemius_reviews';
540 $post['freemius_item_type'] = $this->get("_nx_meta_freemius_item_type");
541 $post['freemius_themes'] = $this->get("_nx_meta_freemius_themes");
542 $post['freemius_plugins'] = $this->get("_nx_meta_freemius_plugins");
543
544
545 $sales = $this->get("_nx_meta_freemius_content");
546 $freemius = FreemiusReviews::get_instance();
547 if(is_array($sales)){
548 foreach ($sales as $key => $sale) {
549 $sales[$key] = [
550 'nx_id' => $_post['nx_id'],
551 'source' => $freemius->id,
552 'entry_key' => $sale['id'],
553 'data' => $sale,
554 ];
555 }
556 $freemius->update_notifications($sales);
557 }
558
559 break;
560 case 'zapier':
561 $post['source'] = 'zapier_reviews';
562 break;
563 default:
564 # code...
565 break;
566 }
567 break;
568 case 'download_stats':
569 // Source Tab
570 $post['source'] = $this->get('_nx_meta_stats_source');
571 $post['themes'] = $this->get('_nx_meta_wpstats_theme');
572 $post['advance_edit'] = $this->get('_nx_meta_wpstats_advance_edit');
573
574
575
576 // Theme Tab
577 $post['bg_color'] = $this->get('_nx_meta_wpstats_bg_color');
578 $post['text_color'] = $this->get('_nx_meta_wpstats_text_color');
579 $post['border'] = $this->get('_nx_meta_wpstats_border');
580 $post['border_size'] = $this->get('_nx_meta_wpstats_border_size');
581 $post['border_style'] = $this->get('_nx_meta_wpstats_border_style');
582 $post['border_color'] = $this->get('_nx_meta_wpstats_border_color');
583 $post['image_position'] = $this->get("_nx_meta_wpstats_image_position");
584 $post['first_font_size'] = $this->get("_nx_meta_wpstats_first_font_size");
585 $post['second_font_size'] = $this->get("_nx_meta_wpstats_second_font_size");
586 $post['third_font_size'] = $this->get("_nx_meta_wpstats_third_font_size");
587
588 // Content Tab
589 $post['wp_stats_product_type'] = $this->get("_nx_meta_wp_stats_product_type");
590 $post['wp_stats_slug'] = $this->get("_nx_meta_wp_stats_slug");
591 //
592 if ($post['themes'] == 'actively_using') {
593 $post['notification-template'] = $this->get("_nx_meta_actively_using_template_new");
594 if(!empty($post['notification-template']['third_param']) && $post['notification-template']['third_param'] == 'tag_name'){
595 $post['notification-template']['third_param'] = 'tag_plugin_theme_name';
596 }
597 } else {
598 $post['notification-template'] = $this->get("_nx_meta_wp_stats_template_new");
599 if(!empty($post['notification-template']['first_param']) && $post['notification-template']['first_param'] == 'tag_name'){
600 $post['notification-template']['first_param'] = 'tag_plugin_theme_name';
601 }
602 }
603 if($post['template_adv'] = $this->get("_nx_meta_wp_stats_template_adv")){
604 $post['advanced_template'] = $this->get("_nx_meta_wp_stats_template");
605 if(!empty($post['advanced_template']) && is_array($post['advanced_template'])){
606 foreach ($post['advanced_template'] as $key => &$value) {
607 $value = str_replace('{{name}}', '{{plugin_theme_name}} ', $value);
608 }
609 }
610 }
611
612 $post['link_type'] = $this->get("_nx_meta_rs_url");
613 if($post['link_type'] == 'product_page'){
614 $post['link_type'] = 'stats_page';
615 }
616 $post['custom_url'] = $this->get("_nx_meta_rs_custom_url");
617 $post['sound'] = $this->get("_nx_meta_download_stats_sound");
618
619 switch ($post['source']) {
620 case 'wp_stats':
621 if( boolval( $post['enabled'] ) ) {
622 Cron::get_instance()->set_cron($nx_id, 'nx_wp_stats_interval');
623 }
624 $plugin_data = $this->get('_nx_meta_wporg_stats_content');
625 if (!empty($plugin_data)) {
626 $WPS = WPOrgStats::get_instance();
627 $reviews = [];
628 if(is_array($plugin_data)){
629 foreach ($plugin_data as $key => $stats) {
630 $reviews[$key] = [
631 'nx_id' => $_post['nx_id'],
632 'source' => $WPS->id,
633 'entry_key' => '',
634 'data' => $stats,
635 ];
636 }
637 $WPS->update_notifications($reviews);
638 }
639 }
640 # code...
641 break;
642 case 'freemius':
643 if( boolval( $post['enabled'] ) ) {
644 Cron::get_instance()->set_cron($nx_id, 'nx_freemius_interval');
645 }
646 $post['source'] = 'freemius_stats';
647 $post['freemius_item_type'] = $this->get("_nx_meta_freemius_item_type");
648 $post['freemius_themes'] = $this->get("_nx_meta_freemius_themes");
649 $post['freemius_plugins'] = $this->get("_nx_meta_freemius_plugins");
650
651 $sales = $this->get("_nx_meta_freemius_content");
652 $freemius = FreemiusStats::get_instance();
653 if(is_array($sales)){
654 foreach ($sales as $key => $sale) {
655 $sales[$key] = [
656 'nx_id' => $_post['nx_id'],
657 'source' => $freemius->id,
658 'entry_key' => $sale['id'],
659 'data' => $sale,
660 ];
661 }
662 $freemius->update_notifications($sales);
663 }
664
665 break;
666 default:
667 # code...
668 break;
669 }
670 break;
671 case 'elearning':
672 // Source Tab
673 $post['source'] = $this->get('_nx_meta_elearning_source');
674 $post['themes'] = $this->get('_nx_meta_elearning_theme');
675 $post['advance_edit'] = $this->get('_nx_meta_elearning_advance_edit');
676
677
678 // Theme Tab
679 $post['bg_color'] = $this->get("_nx_meta_bg_color");
680 $post['text_color'] = $this->get("_nx_meta_text_color");
681 $post['border'] = $this->get("_nx_meta_border");
682 $post['border_size'] = $this->get("_nx_meta_border_size");
683 $post['border_style'] = $this->get("_nx_meta_border_style");
684 $post['border_color'] = $this->get("_nx_meta_border_color");
685 $post['image_shape'] = $this->get("_nx_meta_image_shape");
686 $post['image_position'] = $this->get("_nx_meta_image_position");
687 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
688 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
689 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
690 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
691
692 // Content Tab
693 // $post['elearning_template'] = $this->get("");
694 $post['notification-template'] = $this->get("_nx_meta_elearning_template_new");
695 if($post['template_adv'] = $this->get("_nx_meta_elearning_template_adv")){
696 $post['advanced_template'] = $this->get("_nx_meta_elearning_template");
697 }
698 $post['link_type'] = $this->get("_nx_meta_elearning_url");
699 if($post['link_type'] == 'product_page'){
700 $post['link_type'] = 'course_page';
701 }
702 $post['custom_url'] = $this->get("_nx_meta_elearning_custom_url");
703
704 $post['sound'] = $this->get("_nx_meta_comments_sound");
705
706 switch ($post['source']) {
707 case 'tutor':
708 $post['ld_product_control'] = $this->get("_nx_meta_tutor_product_control");
709 $post['ld_course_list'] = $this->get("_nx_meta_tutor_course_list");
710 break;
711 case 'learndash':
712 $post['ld_product_control'] = $this->get("_nx_meta_ld_product_control");
713 $post['ld_course_list'] = $this->get("_nx_meta_ld_course_list");
714 break;
715 default:
716 # code...
717 break;
718 }
719 break;
720 case 'donation':
721 // Source Tab
722 $post['source'] = $this->get('_nx_meta_donation_source');
723 $post['themes'] = $this->get('_nx_meta_donation_theme');
724 $post['advance_edit'] = $this->get('_nx_meta_donation_advance_edit');
725
726 // Theme Tab
727 $post['bg_color'] = $this->get("_nx_meta_bg_color");
728 $post['text_color'] = $this->get("_nx_meta_text_color");
729 $post['border'] = $this->get("_nx_meta_border");
730 $post['border_size'] = $this->get("_nx_meta_border_size");
731 $post['border_style'] = $this->get("_nx_meta_border_style");
732 $post['border_color'] = $this->get("_nx_meta_border_color");
733 $post['image_shape'] = $this->get("_nx_meta_image_shape");
734 $post['image_position'] = $this->get("_nx_meta_image_position");
735 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
736 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
737 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
738 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
739
740 // Content Tab
741 $post['notification-template'] = $this->get("_nx_meta_donation_template_new");
742 if($post['template_adv'] = $this->get("_nx_meta_donation_template_adv")){
743 $post['advanced_template'] = $this->get("_nx_meta_donation_template");
744 }
745 $post['give_forms_control'] = $this->get("_nx_meta_give_forms_control");
746 $post['give_form_list'] = $this->get("_nx_meta_give_form_list");
747
748 $post['link_type'] = $this->get("_nx_meta_donation_url");
749 if($post['link_type'] == 'product_page'){
750 $post['link_type'] = 'donation_page';
751 }
752 $post['custom_url'] = $this->get("_nx_meta_donation_custom_url");
753
754 $post['sound'] = $this->get("_nx_meta_comments_sound");
755
756 switch ($post['source']) {
757 case 'give':
758 # code...
759 break;
760 default:
761 # code...
762 break;
763 }
764 break;
765 case 'press_bar':
766 // Source Tab
767 $post['type'] = 'notification_bar';
768 $post['source'] = 'press_bar';
769 $post['themes'] = $this->get('_nx_meta_bar_theme');
770 $post['advance_edit'] = $this->get('_nx_meta_bar_advance_edit');
771
772 // Theme Tab
773 $post['bg_color'] = $this->get('_nx_meta_bar_bg_color');
774 $post['text_color'] = $this->get('_nx_meta_bar_text_color');
775 $post['btn_bg'] = $this->get('_nx_meta_bar_btn_bg');
776 $post['btn_text_color'] = $this->get('_nx_meta_bar_btn_text_color');
777 $post['counter_bg'] = $this->get('_nx_meta_bar_counter_bg');
778 $post['counter_text_color'] = $this->get('_nx_meta_bar_counter_text_color');
779 $post['close_color'] = $this->get('_nx_meta_bar_close_color');
780 $post['close_position'] = $this->get('_nx_meta_bar_close_position');
781 $post['bar_font_size'] = $this->get('_nx_meta_bar_font_size');
782 $post['press_content'] = $this->get('_nx_meta_press_content');
783 $post['button_text'] = $this->get('_nx_meta_button_text');
784 $post['button_url'] = $this->get('_nx_meta_button_url');
785 $post['content_trim_length'] = $this->get('_nx_meta_content_trim_length');
786
787 // Content Tab
788 $post['enable_countdown'] = $this->get('_nx_meta_enable_countdown');
789 $post['evergreen_timer'] = $this->get('_nx_meta_evergreen_timer');
790 $post['countdown_text'] = $this->get('_nx_meta_countdown_text');
791 $post['countdown_expired_text'] = $this->get('_nx_meta_countdown_expired_text');
792 $post['countdown_start_date'] = $this->get('_nx_meta_countdown_start_date');
793 $post['countdown_end_date'] = $this->get('_nx_meta_countdown_end_date');
794 $post['time_rotation'] = $this->get('_nx_meta_time_rotation');
795 $post['countdown_rand'] = time();
796 $post['time_randomize'] = $this->get('_nx_meta_time_randomize');
797 $post['time_randomize_between'] = $this->get('_nx_meta_time_randomize_between');
798 // $post['start_time'] = $this->get('start_time');
799 // $post['end_time'] = $this->get('end_time');
800 $post['time_reset'] = $this->get('_nx_meta_time_reset');
801 $post['close_forever'] = $this->get('_nx_meta_close_forever');
802 if(empty($post['close_forever']) && !empty($this->get('_nx_meta_close_forever_2'))){
803 $post['close_forever'] = $this->get('_nx_meta_close_forever_2');
804 }
805
806 $post['position'] = $this->get('_nx_meta_pressbar_position');
807 $post['sticky_bar'] = $this->get('_nx_meta_sticky_bar');
808 $post['pressbar_body'] = $this->get('_nx_meta_pressbar_body');
809 $post['elementor_id'] = (int) $this->get('_nx_bar_elementor_type_id');
810 // if($post['nx_id'] == 4386){
811 // wp_send_json([$post, $_post]);
812 // }
813
814 break;
815 case 'form':
816 // Source Tab
817 $post['source'] = $this->get('_nx_meta_form_source');
818 $post['themes'] = $this->get('_nx_meta_form_theme');
819 $post['advance_edit'] = $this->get('_nx_meta_form_advance_edit');
820
821 // Theme Tab
822 $post['bg_color'] = $this->get("_nx_meta_bg_color");
823 $post['text_color'] = $this->get("_nx_meta_text_color");
824 $post['border'] = $this->get("_nx_meta_border");
825 $post['border_size'] = $this->get("_nx_meta_border_size");
826 $post['border_style'] = $this->get("_nx_meta_border_style");
827 $post['border_color'] = $this->get("_nx_meta_border_color");
828 $post['image_shape'] = $this->get("_nx_meta_image_shape");
829 $post['image_position'] = $this->get("_nx_meta_image_position");
830 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
831 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
832 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
833 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
834
835 $post['sound'] = $this->get("_nx_meta_comments_sound");
836
837 switch ($post['source']) {
838 case 'cf7':
839
840 // Content Tab
841 $post['form_list'] = "{$post['source']}_" . $this->get('_nx_meta_cf7_form');
842 $post['notification-template'] = $this->get('_nx_meta_form_template_new');
843 break;
844 case 'wpf':
845 // Content Tab
846 $post['form_list'] = "{$post['source']}_" . $this->get('_nx_meta_wpf_form');
847 $post['notification-template'] = $this->get('_nx_meta_wpf_template_new');
848 break;
849 case 'njf':
850 // Content Tab
851 $post['form_list'] = "{$post['source']}_" . $this->get('_nx_meta_njf_form');
852 $post['notification-template'] = $this->get('_nx_meta_njf_template_new');
853 break;
854 case 'grvf':
855 // Content Tab
856 $post['form_list'] = "{$post['source']}_" . $this->get('_nx_meta_grvf_form');
857 $post['notification-template'] = $this->get('_nx_meta_grvf_template_new');
858 break;
859 default:
860 # code...
861 break;
862 }
863 break;
864 case 'email_subscription':
865 // Source Tab
866 $post['source'] = $this->get('_nx_meta_subscription_source');
867 $post['themes'] = $this->get('_nx_meta_mailchimp_theme');
868 $post['advance_edit'] = $this->get('_nx_meta_mailchimp_advance_edit');
869
870
871
872 // Theme Tab
873 $post['bg_color'] = $this->get('_nx_meta_mailchimp_bg_color');
874 $post['text_color'] = $this->get('_nx_meta_mailchimp_text_color');
875 $post['border'] = $this->get('_nx_meta_mailchimp_border');
876 $post['border_size'] = $this->get('_nx_meta_mailchimp_border_size');
877 $post['border_style'] = $this->get('_nx_meta_mailchimp_border_style');
878 $post['border_color'] = $this->get('_nx_meta_mailchimp_border_color');
879 $post['first_font_size'] = $this->get("_nx_meta_mailchimp_first_font_size");
880 $post['second_font_size'] = $this->get("_nx_meta_mailchimp_second_font_size");
881 $post['third_font_size'] = $this->get("_nx_meta_mailchimp_third_font_size");
882
883 // Content Tab
884 $post['notification-template'] = $this->get("_nx_meta_mailchimp_template_new");
885 if($post['template_adv'] = $this->get("_nx_meta_mailchimp_template_adv")){
886 $post['advanced_template'] = $this->get("_nx_meta_mailchimp_template");
887 }
888 $show_avatar = $this->get("_nx_meta_show_avatar");
889 if($show_avatar){
890 $post['show_notification_image'] = 'gravatar';
891 }
892 $post['sound'] = $this->get("_nx_meta_email_subscription_sound");
893
894 switch ($post['source']) {
895 case 'mailchimp':
896 if( boolval( $post['enabled'] ) ) {
897 Cron::get_instance()->set_cron($nx_id, 'nx_mailchimp_interval');
898 }
899 $post['mailchimp_list'] = $this->get("_nx_meta_mailchimp_list");
900 $sales = $this->get("_nx_meta_mailchimp_content");
901 $mailchimp = MailChimp::get_instance();
902 if(is_array($sales)){
903 foreach ($sales as $key => $sale) {
904 $sales[$key] = [
905 'nx_id' => $_post['nx_id'],
906 'source' => $mailchimp->id,
907 'entry_key' => isset($sale['timestamp']) ? $sale['timestamp'] : '',
908 'data' => $sale,
909 ];
910 }
911 $mailchimp->update_notifications($sales);
912 }
913 # code...
914 break;
915 case 'convertkit':
916 if( boolval( $post['enabled'] ) ) {
917 Cron::get_instance()->set_cron($nx_id, 'nx_convertkit_interval');
918 }
919 $post['convertkit_form'] = $this->get("_nx_meta_convertkit_form");
920 $sales = $this->get("_nx_meta_convertkit_content");
921 $convertkit = ConvertKit::get_instance();
922 if(is_array($sales)){
923 foreach ($sales as $key => $sale) {
924 $sales[$key] = [
925 'nx_id' => $_post['nx_id'],
926 'source' => $convertkit->id,
927 'entry_key' => isset($sale['timestamp']) ? $sale['timestamp'] : '',
928 'data' => $sale,
929 ];
930 }
931 $convertkit->update_notifications($sales);
932 }
933 break;
934 case 'zapier':
935 $post['source'] = 'zapier_email_subscription';
936 break;
937 default:
938 # code...
939 break;
940 }
941 break;
942 case 'page_analytics':
943 if( boolval( $post['enabled'] ) ) {
944 Cron::get_instance()->set_cron($nx_id, 'nx_ga_cache_duration');
945 }
946 // Source Tab
947 $post['source'] = $this->get('_nx_meta_page_analytics_source');
948 $post['themes'] = $this->get('_nx_meta_page_analytics_theme');
949
950 // Theme Tab
951 $post['bg_color'] = $this->get("_nx_meta_bg_color");
952 $post['text_color'] = $this->get("_nx_meta_text_color");
953 $post['border'] = $this->get("_nx_meta_border");
954 $post['border_size'] = $this->get("_nx_meta_border_size");
955 $post['border_style'] = $this->get("_nx_meta_border_style");
956 $post['border_color'] = $this->get("_nx_meta_border_color");
957 $post['image_shape'] = $this->get("_nx_meta_image_shape");
958 $post['image_position'] = $this->get("_nx_meta_image_position");
959 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
960 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
961 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
962 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
963
964 // Content Tab
965 $template = $this->get("_nx_meta_page_analytics_template_new");
966 $post['notification-template']['first_param'] = $this->get('first_param', '', $template);
967 $post['notification-template']['second_param'] = $this->get('second_param', '', $template);
968 $post['notification-template']['third_param'] = $this->get('page_third_param', '', $template);
969 $post['notification-template']['custom_third_param'] = $this->get('custom_page_third_param', '', $template);
970 if($this->get('first_param', '', $template) == 'tag_siteview'){
971 $post['notification-template']['ga_fourth_param'] = $this->get('analytics_fourth_param', '', $template);
972 }
973 else if($this->get('first_param', '', $template) == 'tag_realtime_siteview'){
974 $post['notification-template']['ga_fourth_param'] = $this->get('realtime_fourth_param', '', $template);
975 }
976 $post['notification-template']['ga_fifth_param'] = $this->get('fifth_param', '', $template);
977 $post['notification-template']['sixth_param'] = $this->get('sixth_param', '', $template);
978
979 $post['advance_edit'] = $this->get('_nx_meta_page_analytics_advance_edit');
980
981 $post['sound'] = $this->get("_nx_meta_conversions_sound");
982
983 // @todo check with new version.
984 $sales = $this->get("_nx_meta_custom_contents");
985 if( boolval( $post['enabled'] ) ) {
986 Cron::get_instance()->set_cron($nx_id, 'nx_ga_cache_duration');
987 }
988
989 $ga = Google_Analytics::get_instance();
990 if(is_array($sales)){
991 foreach ($sales as $key => $sale) {
992 $sales[$key] = [
993 'nx_id' => $_post['nx_id'],
994 'source' => $ga->id,
995 'data' => $sale,
996 ];
997 }
998 $ga->update_notifications($sales);
999 }
1000
1001 break;
1002 case 'custom':
1003 // Source Tab
1004 $post['source'] = 'custom_notification';
1005 $post['themes'] = $this->get('_nx_meta_custom_theme');
1006 $post['advance_edit'] = $this->get('_nx_meta_custom_advance_edit');
1007
1008 // Theme Tab
1009 $post['bg_color'] = $this->get("_nx_meta_bg_color");
1010 $post['text_color'] = $this->get("_nx_meta_text_color");
1011 $post['border'] = $this->get("_nx_meta_border");
1012 $post['border_size'] = $this->get("_nx_meta_border_size");
1013 $post['border_style'] = $this->get("_nx_meta_border_style");
1014 $post['border_color'] = $this->get("_nx_meta_border_color");
1015 $post['image_shape'] = $this->get("_nx_meta_image_shape");
1016 $post['image_position'] = $this->get("_nx_meta_image_position");
1017 $post['custom_image_shape'] = $this->get("_nx_meta_image_custom_shape");
1018 $post['first_font_size'] = $this->get("_nx_meta_first_font_size");
1019 $post['second_font_size'] = $this->get("_nx_meta_second_font_size");
1020 $post['third_font_size'] = $this->get("_nx_meta_third_font_size");
1021
1022 // Content Tab
1023 $custom = CustomNotification::get_instance()->supported_themes();
1024 $conv_themes = array_keys(Conversions::get_instance()->get_themes());
1025 $temp_meta_key = '_nx_meta_type_custom_contents';
1026 $_themes = $post['themes'] = str_replace([
1027 'comments-',
1028 'reviews-',
1029 'stats-',
1030 'subs-',
1031 ], [
1032 'comments_',
1033 'reviews_',
1034 'download_stats_',
1035 'email_subscription_',
1036 ], $post['themes']); // = CustomNotification::get_instance()->get_theme_type($post);
1037
1038 switch (true) {
1039 case in_array($_themes, array_merge($conv_themes, ['maps_theme'])):
1040 $post['themes'] = 'conversions_' . $post['themes'];
1041 $final_meta_key = $temp_meta_key;
1042 if (in_array($_themes, $custom['sales_count'])) {
1043 $final_meta_key = $temp_meta_key . '_sales_count';
1044 }
1045 if (in_array($_themes, ['maps_theme'])) {
1046 $final_meta_key = $temp_meta_key . '_maps_theme';
1047 }
1048 break;
1049 case in_array($_themes, array_merge($custom['comments'], ['comments_maps_theme'])):
1050 $final_meta_key = $temp_meta_key . '_comments';
1051 if (in_array($_themes, array('comments_maps_theme'))) {
1052 $final_meta_key = $temp_meta_key . '_maps_theme';
1053 }
1054 break;
1055 case in_array($_themes, $custom['reviews']):
1056 $final_meta_key = $temp_meta_key . '_reviews';
1057
1058 break;
1059 case in_array($_themes, $custom['stats']):
1060 $final_meta_key = $temp_meta_key . '_stats';
1061 break;
1062 case in_array($_themes, array_merge($custom['subs'], ['email_subscription_maps_theme'])):
1063 $final_meta_key = $temp_meta_key . '_subs';
1064 if (in_array($_themes, array('email_subscription_maps_theme'))) {
1065 $final_meta_key = $temp_meta_key . '_maps_theme';
1066 }
1067 break;
1068 }
1069
1070
1071 $post['notification-template'] = $this->get("_nx_meta_woo_template_new");
1072
1073 if (in_array($this->get('_nx_meta_custom_theme'), array('maps_theme', 'subs-maps_theme', 'comments-maps_theme'))) {
1074 $template = $this->get('_nx_meta_maps_theme_template_new');
1075 if(!empty($template)){
1076 $p_template = &$post['notification-template'];
1077 $p_template['first_param'] = $template['first_param'];
1078 $p_template['custom_first_param'] = $template['custom_first_param'];
1079 $p_template['second_param'] = $template['from'];
1080 $p_template['third_param'] = $template['second_param'];
1081 $p_template['map_fourth_param'] = $template['third_param'];
1082 $p_template['fourth_param'] = $template['fourth_param'];
1083 $p_template['fifth_param'] = $template['fifth_param'];
1084 $p_template['custom_fourth_param'] = $template['custom_fourth_param'];
1085 }
1086 if($post['template_adv'] = $this->get("_nx_meta_maps_theme_template_adv")){
1087 $post['advanced_template'] = $this->get("_nx_meta_maps_theme_template");
1088 }
1089 }
1090
1091 if (in_array($this->get('_nx_meta_custom_theme'), array('reviews-review-comment-3', 'reviews-review-comment-2', 'reviews-review-comment', 'reviews-reviewed', 'reviews-total-rated'))) {
1092 $post['notification-template'] = $this->get('_nx_meta_wp_reviews_template_new');
1093 if($post['template_adv'] = $this->get("_nx_meta_wp_reviews_template_adv")){
1094 $post['advanced_template'] = $this->get("_nx_meta_wp_reviews_template");
1095 }
1096 }
1097
1098 if ($this->get('_nx_meta_custom_theme') === 'reviews-review_saying') {
1099 $post['notification-template'] = $this->get('_nx_meta_review_saying_template_new');
1100 if($post['template_adv'] = $this->get("_nx_meta_wp_reviews_template_adv")){
1101 $post['advanced_template'] = $this->get("_nx_meta_wp_reviews_template");
1102 }
1103 }
1104
1105 if (in_array($this->get('_nx_meta_custom_theme'), array('stats-today-download', 'stats-total-download', 'stats-7day-download'))) {
1106 $post['notification-template'] = $this->get('_nx_meta_wp_stats_template_new');
1107 if($post['template_adv'] = $this->get("_nx_meta_wp_stats_template_adv")){
1108 $post['advanced_template'] = $this->get("_nx_meta_wp_stats_template");
1109 }
1110 }
1111
1112 if ($this->get('_nx_meta_custom_theme') === 'stats-actively_using') {
1113 $post['notification-template'] = $this->get('_nx_meta_actively_using_template_new');
1114 if($post['template_adv'] = $this->get("_nx_meta_wp_stats_template_adv")){
1115 $post['advanced_template'] = $this->get("_nx_meta_wp_stats_template");
1116 }
1117 }
1118
1119 if (in_array($this->get('_nx_meta_custom_theme'), array('subs-theme-one', 'subs-theme-two', 'subs-theme-three'))) {
1120 $post['notification-template'] = $this->get('_nx_meta_mailchimp_template_new');
1121 if($post['template_adv'] = $this->get("_nx_meta_mailchimp_template_adv")){
1122 $post['advanced_template'] = $this->get("_nx_meta_mailchimp_template");
1123 }
1124 }
1125
1126 if (in_array($this->get('_nx_meta_custom_theme'), array('comments-theme-one', 'comments-theme-two', 'comments-theme-three', 'comments-theme-six-free', 'comments-theme-seven-free', 'comments-theme-eight-free', 'comments-theme-four', 'comments-theme-five'))) {
1127 $post['notification-template'] = $this->get('_nx_meta_mailchimp_template_new');
1128 if($post['template_adv'] = $this->get("_nx_meta_mailchimp_template_adv")){
1129 $post['advanced_template'] = $this->get("_nx_meta_mailchimp_template");
1130 }
1131 }
1132
1133 if(!empty($_post[$final_meta_key])){
1134 $post['custom_contents'] = $_post[$final_meta_key];
1135 if(is_array($post['custom_contents'])){
1136 foreach($post['custom_contents'] as &$entry){
1137 if(!empty($entry['time'])){
1138 $entry['timestamp'] = Helper::mysql_time($entry['time']);
1139 }
1140 }
1141 }
1142 }
1143
1144
1145
1146 $post['sound'] = $this->get("_nx_meta_custom_sound");
1147
1148 break;
1149
1150 default:
1151 break;
1152 }
1153
1154 if(in_array($post['themes'], ['conv-theme-six', 'maps_theme'])){
1155 $template = $this->get('_nx_meta_maps_theme_template_new');
1156 if(!empty($template)){
1157 $p_template = &$post['notification-template'];
1158 $p_template['first_param'] = $template['first_param'];
1159 $p_template['custom_first_param'] = $template['custom_first_param'];
1160 $p_template['second_param'] = $template['from'];
1161 $p_template['third_param'] = $template['second_param'];
1162 $p_template['map_fourth_param'] = $template['third_param'];
1163 $p_template['fourth_param'] = $template['fourth_param'];
1164 $p_template['fifth_param'] = $template['fifth_param'];
1165 $p_template['custom_fourth_param'] = $template['custom_fourth_param'];
1166 }
1167 if($post['template_adv'] = $this->get("_nx_meta_maps_theme_template_adv")){
1168 $post['advanced_template'] = $this->get("_nx_meta_maps_theme_template");
1169 }
1170 }
1171
1172 if($post['show_notification_image'] == 'product_image'){
1173 $post['show_notification_image'] = 'featured_image';
1174 }
1175
1176 if (!empty($post['advanced_template']) && is_array($post['advanced_template'])) {
1177 $post['advanced_template'] = implode("\n", array_filter($post['advanced_template'], 'trim'));
1178 }
1179
1180 if (empty($post['image_url']['id']) && empty($post['image_url']['url'])) {
1181 unset($post['image_url']);
1182 }
1183 if ($post['type'] == 'custom') {
1184 $post['themes'] = $post['themes'];
1185 } else if($post['source'] == 'woo_reviews'||$post['source'] == 'reviewx') {
1186 $post['themes'] = $post['source'] . '_' . $post['themes'];
1187 } else if($post['source'] == 'press_bar') {
1188 $post['themes'] = $post['source'] . '_' . $post['themes'];
1189 } else {
1190 $post['themes'] = $post['type'] . '_' . $post['themes'];
1191 }
1192
1193 return $post;
1194 }
1195
1196 public function migrate_entries($posts) {
1197 $notifications = get_option('notificationx_data', []);
1198 if(is_array($notifications)){
1199 foreach ($notifications as $source => $entries) {
1200 // @todo review later if it covers all case.
1201 $source = $this->normalize_source($source, $posts);
1202 $ext = ExtensionFactory::get_instance()->get($source);
1203 if ($ext && is_array($entries)) {
1204 foreach ($entries as $key => $entry) {
1205 $_entry = [
1206 'source' => $source,
1207 'entry_key' => $key,
1208 'data' => $entry,
1209 ];
1210 $ext->update_notification($_entry);
1211 }
1212 } else {
1213 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- deliberate failure logging, not debug output.
1214 error_log("$source not found");
1215 }
1216 }
1217 }
1218 }
1219
1220 public function normalize_source($source, $posts) {
1221 $prefix = [
1222 'zapier',
1223 'grvf',
1224 'wpf',
1225 'njf',
1226 'cf7',
1227 ];
1228 if (strpos($source, 'zapier') === 0) {
1229 $nx_id = str_replace('zapier_', '', $source);
1230 if(!empty($posts[$nx_id])){
1231 return $posts[$nx_id]['source'];
1232 }
1233
1234 }
1235 foreach ($prefix as $key => $value) {
1236 if (strpos($source, $value) === 0) {
1237 return $value;
1238 }
1239 }
1240 return $source;
1241 }
1242
1243 public function migrate_stats($post) {
1244 $nx_id = $post['ID'];
1245 if (!empty($post['_nx_meta_impression_per_day'])) {
1246 $impression = $post['_nx_meta_impression_per_day'];
1247 if(is_array($impression)){
1248 $stats = [];
1249 foreach ($impression as $_impressions) {
1250 foreach ($_impressions as $date => $value) {
1251 $data = [
1252 'nx_id' => $nx_id,
1253 'clicks' => !empty($value['clicks']) ? $value['clicks'] : 0,
1254 'views' => !empty($value['impressions']) ? $value['impressions'] : 0,
1255 'created_at' => gmdate(Analytics::$date_format, strtotime($date)),
1256 ];
1257 $stats[] = $data;
1258 }
1259 }
1260 if( ! empty( $stats ) ) {
1261 Analytics::get_instance()->migrate_analytics($stats);
1262 }
1263 }
1264 }
1265 }
1266
1267 protected function get($index, $default = '', $arr = []){
1268 if(empty($arr)){
1269 $arr = $this->_post;
1270 }
1271
1272 if(isset($arr[$index])){
1273 return $arr[$index];
1274 }
1275 return $default;
1276 }
1277
1278 }
1279