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