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

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