PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 1.1.0
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v1.1.0
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 / admin / class-nx-admin.php

class-nx-admin.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 1.1.0, at admin/class-nx-admin.php

731 lines 28.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link https://wpdeveloper.net
6 * @since 1.0.0
7 *
8 * @package NotificationX
9 * @subpackage NotificationX/admin
10 * @author WPDeveloper <support@wpdeveloper.net>
11 */
12
13 class NotificationX_Admin {
14
15 /**
16 * The ID of this plugin.
17 *
18 * @since 1.0.0
19 * @access private
20 * @var string $plugin_name The ID of this plugin.
21 */
22 private $plugin_name;
23 /**
24 * All builder args
25 *
26 * @var array
27 */
28 private $builder_args;
29 /**
30 * Builder Metabox ID
31 *
32 * @var string
33 */
34 private $metabox_id;
35
36 /**
37 * The version of this plugin.
38 *
39 * @since 1.0.0
40 * @access private
41 * @var string $version The current version of this plugin.
42 */
43 private $version;
44
45 /**
46 * The type.
47 *
48 * @since 1.0.0
49 * @access public
50 * @var string the post type of notificationx.
51 */
52 public $type = 'notificationx';
53
54 public $metabox;
55
56 public static $prefix = 'nx_meta_';
57
58 public static $settings;
59
60 /**
61 * Initialize the class and set its properties.
62 *
63 * @since 1.0.0
64 * @param string $plugin_name The name of this plugin.
65 * @param string $version The version of this plugin.
66 */
67 public static $counts;
68 public function __construct( $plugin_name, $version ) {
69
70 $this->plugin_name = $plugin_name;
71 $this->version = $version;
72 self::$settings = NotificationX_DB::get_settings();
73 }
74 /**
75 * Get all active items.
76 *
77 * @return void
78 */
79 public static function get_active_items() {
80 // WP Query arguments.
81 $source_types = NotificationX_Helper::source_types();
82 $args = array(
83 'post_type' => 'notificationx',
84 'posts_per_page' => '-1',
85 'post_status' => 'publish',
86 );
87 $active = [];
88 // Get the notification posts.
89 $posts = get_posts( $args );
90 if ( count( $posts ) ) {
91 foreach ( $posts as $post ) {
92 $settings = NotificationX_MetaBox::get_metabox_settings( $post->ID );
93 $type = '';
94 if( array_key_exists( $settings->display_type, $source_types ) ) {
95 $type = $settings->{ $source_types[ $settings->display_type ] };
96 }
97 $active[ $type ][] = $post->ID;
98 }
99 }
100
101 return $active;
102 }
103
104 public static function get_enabled_types() {
105 // WP Query arguments.
106 $source_types = NotificationX_Helper::source_types();
107 $args = array(
108 'post_type' => 'notificationx',
109 'posts_per_page' => '-1',
110 'post_status' => 'publish',
111 'meta_key' => '_nx_meta_active_check',
112 'meta_value' => 1
113 );
114 $active = [];
115 // Get the notification posts.
116 $posts = get_posts( $args );
117 if ( count( $posts ) ) {
118 foreach ( $posts as $post ) {
119 $settings = NotificationX_MetaBox::get_metabox_settings( $post->ID );
120 $type = '';
121 if( array_key_exists( $settings->display_type, $source_types ) ) {
122 $type = $settings->{ $source_types[ $settings->display_type ] };
123 }
124 $active[ $type ][] = $post->ID;
125 }
126 }
127
128 return $active;
129 }
130 /**
131 * Register the stylesheets for the admin area.
132 *
133 * @since 1.0.0
134 */
135 public function enqueue_styles( $hook ) {
136 global $post_type;
137 $page_status = false;
138 wp_enqueue_style(
139 $this->plugin_name . '-admin-global',
140 NOTIFICATIONX_ADMIN_URL . 'assets/css/nx-admin-global.min.css',
141 array(), $this->version, 'all'
142 );
143 if( $hook == 'notificationx_page_nx-builder' || $hook == 'notificationx_page_nx-settings' ) {
144 $page_status = true;
145 }
146
147 if( $post_type != $this->type && ! $page_status ) {
148 return;
149 }
150
151 wp_enqueue_style( 'wp-color-picker' );
152 wp_enqueue_style(
153 $this->plugin_name . '-select2',
154 NOTIFICATIONX_ADMIN_URL . 'assets/css/select2.min.css',
155 array(), $this->version, 'all'
156 );
157 wp_enqueue_style(
158 $this->plugin_name,
159 NOTIFICATIONX_ADMIN_URL . 'assets/css/nx-admin.min.css',
160 array(), $this->version, 'all'
161 );
162 }
163 /**
164 * Register the JavaScript for the admin area.
165 *
166 * @since 1.0.0
167 */
168 public function enqueue_scripts( $hook ) {
169 global $post_type;
170 $page_status = false;
171
172 if( $hook == 'notificationx_page_nx-builder' || $hook == 'notificationx_page_nx-settings' ) {
173 $page_status = true;
174 }
175
176 if( $hook === 'toplevel_page_nx-admin' ) {
177 wp_enqueue_script(
178 $this->plugin_name . '-sweetalert',
179 NOTIFICATIONX_ADMIN_URL . 'assets/js/sweetalert.min.js',
180 array( 'jquery' ), $this->version, true
181 );
182 wp_enqueue_script(
183 $this->plugin_name,
184 NOTIFICATIONX_ADMIN_URL . 'assets/js/nx-admin.min.js',
185 array( 'jquery' ), $this->version, true
186 );
187 }
188
189
190 if( $post_type != $this->type && ! $page_status ) {
191 return;
192 }
193
194 wp_enqueue_script( 'wp-color-picker' );
195 wp_enqueue_script( 'jquery-ui-datepicker' );
196 wp_enqueue_media();
197 wp_enqueue_script(
198 $this->plugin_name . '-sweetalert',
199 NOTIFICATIONX_ADMIN_URL . 'assets/js/sweetalert.min.js',
200 array( 'jquery' ), $this->version, true
201 );
202 wp_enqueue_script(
203 $this->plugin_name . '-select2',
204 NOTIFICATIONX_ADMIN_URL . 'assets/js/select2.min.js',
205 array( 'jquery' ), $this->version, true
206 );
207 wp_enqueue_script(
208 $this->plugin_name,
209 NOTIFICATIONX_ADMIN_URL . 'assets/js/nx-admin.min.js',
210 array( 'jquery' ), $this->version, true
211 );
212
213 wp_localize_script( $this->plugin_name, 'notificationx', self::toggleFields() );
214 }
215
216 public function toggleFields( $builder = false ){
217 $args = NotificationX_MetaBox::get_args();
218 if( $builder ) {
219 $args = NotificationX_MetaBox::get_builder_args();
220 }
221
222 $toggleFields = $hideFields = $conditions = array();
223
224 $tabs = $args[ 'tabs' ];
225 if( ! empty( $tabs ) ) {
226 foreach( $tabs as $tab_id => $tab ) {
227 $sections = isset( $tab['sections'] ) ? $tab[ 'sections' ] : [];
228 if( ! empty( $sections ) ) {
229 foreach( $sections as $section_id => $section ) {
230 $fields = isset( $section['fields'] ) ? $section[ 'fields' ] : [];
231 if( ! empty( $fields ) ) {
232 foreach( $fields as $field_key => $field ) {
233 if( isset( $field['fields'] ) ) {
234 foreach( $field['fields'] as $inner_field_key => $inner_field ) {
235 if( isset( $inner_field['hide'] ) && ! empty( $inner_field['hide'] ) && is_array( $inner_field['hide'] ) ) {
236 foreach( $inner_field['hide'] as $key => $hide ) {
237 $hideFields[ $inner_field_key ][ $key ] = $hide;
238 }
239 }
240 if( isset( $inner_field['dependency'] ) && ! empty( $inner_field['dependency'] ) && is_array( $inner_field['dependency'] ) ) {
241 foreach( $inner_field['dependency'] as $key => $dependency ) {
242 $conditions[ $inner_field_key ][ $key ] = $dependency;
243 }
244 }
245 }
246 }
247
248 if( isset( $field['hide'] ) && ! empty( $field['hide'] ) && is_array( $field['hide'] ) ) {
249 foreach( $field['hide'] as $key => $hide ) {
250 $hideFields[ $field_key ][ $key ] = $hide;
251 }
252 }
253 if( isset( $field['dependency'] ) && ! empty( $field['dependency'] ) && is_array( $field['dependency'] ) ) {
254 foreach( $field['dependency'] as $key => $dependency ) {
255 $conditions[ $field_key ][ $key ] = $dependency;
256 }
257 }
258 }
259 }
260 }
261 }
262 }
263 }
264
265 $template = apply_filters( 'nx_template_name', array() );
266 $template_settings = apply_filters( 'nx_template_settings_by_theme', array() );
267
268 return array(
269 'toggleFields' => $conditions, // TODO: toggling system has to be more optimized!
270 'hideFields' => $hideFields,
271 'template' => $template,
272 'template_settings' => $template_settings,
273 'source_types' => NotificationX_Helper::source_types(),
274 'theme_sources' => NotificationX_Helper::theme_sources(),
275 'template_keys' => NotificationX_Helper::template_keys(),
276 );
277 }
278
279 public function custom_columns( $columns ) {
280 $title_column = $columns['title'];
281 $date_column = $columns['date'];
282
283 unset( $columns['title'] );
284 unset( $columns['date'] );
285
286 $columns['notification_status'] = __('Enable / Disable', 'notificationx');
287 $columns['title'] = $title_column;
288
289 $columns['notification_type'] = __('Type', 'notificationx');
290
291 $columns['date'] = $date_column;
292
293 return apply_filters('nx_post_columns', $columns );
294 }
295
296 public function manage_custom_columns( $column, $post_id ){
297 switch ( $column ) {
298 case 'notification_type':
299 $type = get_post_meta( $post_id, '_nx_meta_display_type', true );
300 if ( $type ) {
301 $type = NotificationX_Helper::notification_types( $type );
302 if( $type !== 'Conversions' ) {
303 echo $type;
304 } else {
305 $from = get_post_meta( $post_id, '_nx_meta_conversion_from', true );
306 echo $type . ' - ' . NotificationX_Helper::conversion_from( $from );
307 }
308 }
309 break;
310 case 'notification_status':
311 $status = get_post_meta( $post_id, '_nx_meta_active_check', true );
312 self::notification_toggle( $status, $post_id );
313 break;
314 }
315
316 do_action( 'nx_post_columns_content', $column, $post_id );
317 }
318
319 public static function notification_toggle( $status = '1', $post_id ){
320 $text = __('Active', 'notificationx');
321 $img_active = NOTIFICATIONX_ADMIN_URL . 'assets/img/active1.png';
322 $img_inactive = NOTIFICATIONX_ADMIN_URL . 'assets/img/active0.png';
323 $active = 'true';
324 $img = $img_active;
325
326 if ( ! $status ) {
327 $text = __('Inactive', 'notificationx');
328 $img = $img_inactive;
329 $active = 'false';
330 }
331 ?>
332 <img
333 src="<?php echo $img; ?>"
334 style="cursor: pointer; height: 16px; vertical-align: middle;"
335 alt="<?php echo $text; ?>" title="<?php echo $text; ?>"
336 data-nonce="<?php echo wp_create_nonce('notificationx_status_nonce'); ?>"
337 data-post="<?php echo $post_id; ?>" />
338 <?php
339 }
340
341 public function notification_status(){
342 $error = false;
343
344 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'notificationx_status_nonce' ) ) {
345 $error = true;
346 }
347
348 if ( ! isset( $_POST['post_id'] ) || empty( $_POST['post_id'] ) || ! absint( $_POST['post_id'] ) ) {
349 $error = true;
350 }
351
352 if ( $error ) {
353 echo __('There is an error updating status.', 'notificationx');
354 die();
355 }
356
357 $post_id = absint( $_POST['post_id'] );
358 $status = $_POST['status'] == 'active' ? '1' : '0';
359
360 update_post_meta( $post_id, '_nx_meta_active_check', $status );
361 if( isset( $_POST['url'] ) ) {
362 wp_safe_redirect( $_POST['url'], 200 );
363 }
364 echo 'success';
365 die();
366 }
367 /**
368 * Register the NotificationX custom post type.
369 *
370 * @since 1.0.0
371 */
372 public function register(){
373
374 $labels = array(
375 'name' => 'NotificationX',
376 'singular_name' => 'NotificationX',
377 'add_new' => esc_html__( 'Add New', 'notificationx' ) ,
378 'add_new_item' => esc_html__( 'Add New', 'notificationx' ),
379 'edit_item' => esc_html__( 'Edit', 'notificationx' ),
380 'new_item' => esc_html__( 'New', 'notificationx' ),
381 'view_item' => esc_html__( 'View', 'notificationx' ),
382 'search_items' => esc_html__( 'Search', 'notificationx' ),
383 'not_found' => esc_html__( 'No notification x is found', 'notificationx' ),
384 'not_found_in_trash' => esc_html__( 'No notification x is found in Trash', 'notificationx' ),
385 'menu_name' => 'NotificationX',
386 );
387
388 $args = array(
389 'labels' => $labels,
390 'hierarchical' => false,
391 'description' => '',
392 'taxonomies' => array( '' ),
393 'public' => false,
394 'show_ui' => true,
395 'show_in_menu' => 'notificationx',
396 'show_in_admin_bar' => true,
397 'show_in_rest' => false,
398 'menu_position' => 80,
399 'menu_icon' => NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon-colored.png',
400 'show_in_nav_menus' => false,
401 'publicly_queryable' => false,
402 'exclude_from_search' => true,
403 'has_archive' => false,
404 'query_var' => true,
405 'can_export' => true,
406 'rewrite' => '',
407 'capability_type' => 'post',
408 'supports' => array( 'title' ),
409 );
410
411 register_post_type( $this->type, $args );
412 add_image_size( "_nx_notification_thumb", 100, 100, true );
413 }
414
415 /**
416 * Admin Menu Page
417 *
418 * @return void
419 */
420 public function menu_page(){
421
422 if( ! current_user_can( 'manage_options' ) ) {
423 return;
424 }
425
426 $settings_class = new NotificationX_Settings();
427
428 $settings = apply_filters( 'notificationx_admin_menu', array(
429 'nx-settings' => array(
430 'title' => __('Settings', 'notificationx'),
431 'capability' => 'delete_users',
432 'callback' => array( $settings_class, 'settings_page' )
433 ),
434 'nx-builder' => array(
435 'title' => __('Quick Builder', 'notificationx'),
436 'capability' => 'delete_users',
437 'callback' => array( $this, 'quick_builder' )
438 ),
439 ) );
440
441 $this->builder_args = NotificationX_MetaBox::get_builder_args();
442 $this->metabox_id = $this->builder_args['id'];
443 $flag = true;
444
445 // Enable Disable Redirect for - nx-admin.php in notificationx();
446 $post_status = self::count_posts();
447 $get_enabled_post = $post_status->enabled;
448 $get_disabled_post = $post_status->disabled;
449 $trash_notificationx = $post_status->trash;
450 $current_url = admin_url('admin.php?page=nx-admin');
451 if( isset( $_GET['status'], $_GET['page'] ) && $_GET['page'] == 'nx-admin' ) {
452 if( ( $_GET['status'] == 'disabled' && $get_disabled_post == 0 ) || ( $_GET['status'] == 'trash' && $trash_notificationx == 0 ) || ( $_GET['status'] == 'enabled' && $get_enabled_post == 0 )) {
453 wp_safe_redirect( $current_url, 200 );
454 }
455 }
456 // Duplicating NotificationX
457 if( isset( $_GET['action'], $_GET['page'], $_GET['post'], $_GET['nx_duplicate_nonce'] ) && $_GET['action'] === 'nxduplicate' && $_GET['page'] === 'nx-admin' ) {
458 if( wp_verify_nonce( $_GET['nx_duplicate_nonce'], 'nx_duplicate_nonce' ) ) {
459 $nx_post_id = intval( $_GET['post'] );
460 $get_post = get_post( $nx_post_id );
461 $post_data = json_decode( json_encode( $get_post ), true );
462 unset( $post_data['ID'] );
463 $post_data['post_title'] = $post_data['post_title'] . ' - Copy';
464 $duplicate_post_id = wp_insert_post( $post_data );
465 $get_post_meta = get_metadata( 'post', $nx_post_id );
466 if( ! empty( $get_post_meta ) ) {
467 foreach( $get_post_meta as $key => $value ){
468 if( in_array( $key, array( '_edit_lock', '_edit_last' ) ) ) {
469 continue;
470 }
471 add_post_meta( intval( $duplicate_post_id ), $key, $value[0], true );
472 }
473 }
474 wp_safe_redirect( $current_url, 200 );
475 }
476 }
477
478 if( isset( $_GET['delete_all'], $_GET['page'] ) && $_GET['delete_all'] == true && $_GET['page'] == 'nx-admin' ) {
479 $notificationx = new WP_Query(array(
480 'post_type' => 'notificationx',
481 'post_status' => array('trash'),
482 'numberposts' => -1,
483 ));
484 if( $notificationx->have_posts() ) {
485 while( $notificationx->have_posts() ) : $notificationx->the_post();
486 $iddd = get_the_ID();
487 wp_delete_post( $iddd );
488 endwhile;
489 wp_safe_redirect( $current_url, 200 );
490 }
491 }
492
493 /**
494 * Add Submit
495 */
496 if( isset( $_POST[ 'nx_builder_add_submit' ] ) ) :
497 if ( ! isset( $_POST[$this->metabox_id . '_nonce'] ) || ! wp_verify_nonce( $_POST[$this->metabox_id . '_nonce'], $this->metabox_id ) ) {
498 $flag = false;
499 }
500
501 if( $flag ) {
502
503 if( $_POST['nx_meta_display_type'] == 'press_bar' ) {
504 $title = __('NotificationX - Notification Bar', 'notificationx');
505 } elseif( $_POST['nx_meta_display_type'] == 'comments' ) {
506 $title = __('NotificationX - WP Comments', 'notificationx');
507 } elseif( $_POST['nx_meta_display_type'] == 'conversions' ) {
508 $conversions = NotificationX_Helper::conversion_from();
509 $title = 'NotificationX - ' . $conversions[$_POST['nx_meta_conversion_from']];
510 }
511 $_POST['post_type'] = 'notificationx';
512 $postdata = array(
513 'post_type' => 'notificationx',
514 'post_title' => $title . ' - ' . date( get_option( 'date_format' ), current_time( 'timestamp' ) ),
515 'post_status' => 'publish',
516 'post_author' => get_current_user_id(),
517 );
518
519 $p_id = wp_insert_post($postdata);
520 if( $p_id || ! is_wp_error( $p_id ) ) {
521 do_action( 'nx_before_builder_submit', $_POST );
522 // saving builder meta data with post
523 NotificationX_MetaBox::save_data( $this->builder_data( $_POST ), $p_id );
524 /**
525 * Safely Redirect to NotificationX Page
526 */
527 wp_safe_redirect( add_query_arg( array(
528 'page' => 'nx-admin',
529 ), admin_url( 'admin.php' ) ) );
530 }
531 }
532 endif;
533 add_menu_page( 'NotificationX', 'NotificationX', 'delete_users', 'nx-admin', array( $this, 'notificationx' ), NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon-colored.png', 80 );
534 foreach( $settings as $slug => $setting ) {
535 $cap = isset( $setting['capability'] ) ? $setting['capability'] : 'delete_users';
536 $hook = add_submenu_page( 'nx-admin', $setting['title'], $setting['title'], $cap, $slug, $setting['callback'] );
537 }
538 }
539
540 public function highlight_admin_menu( $parent_file ){
541 if( $parent_file === 'notificationx' ) {
542 return 'nx-admin';
543 }
544 return $parent_file;
545 }
546 public function highlight_admin_submenu( $submenu_file, $parent_file ){
547 if( $parent_file == 'nx-admin' && $submenu_file == 'edit.php?post_type=notificationx' ) {
548 return "nx-admin";
549 }
550 return $submenu_file;
551 }
552
553 public static function count_posts( $type = 'notificationx', $perm = '' ) {
554 global $wpdb;
555 if ( ! post_type_exists( $type ) ) {
556 return new stdClass;
557 }
558 $cache_key = 'nx_counts_cache';
559 self::$counts = wp_cache_get( $cache_key, 'counts' );
560 if ( false !== self::$counts ) {
561 return self::$counts;
562 }
563 $query = "SELECT ID, post_status, meta_key, meta_value FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ID = post_id WHERE post_type = %s AND meta_key = '_nx_meta_active_check'";
564 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
565 $counts = array_fill_keys( array( 'enabled', 'disabled', 'trash', 'publish' ), 0 );
566 $disable = 0;
567 $enable = 0;
568 foreach ( $results as $row ) {
569 $counts[ 'publish' ] = $counts['publish'] + ( $row['post_status'] === 'publish' ? 1 : 0 );
570 $counts[ 'trash' ] = $counts['trash'] + ( $row['post_status'] === 'trash' ? 1 : 0 );
571
572 if( $row[ 'meta_value' ] == 0 ) {
573 $disable = 1;
574 $enable = 0;
575 }
576 if( $row[ 'meta_value' ] == 1 ) {
577 $disable = 0;
578 $enable = 1;
579 }
580
581 if( $disable == 1 && $row['post_status'] == 'trash' ) {
582 $disable = 0;
583 }
584
585 if( $enable == 1 && $row['post_status'] == 'trash' ) {
586 $enable = 0;
587 }
588
589 $counts[ 'disabled' ] = $counts[ 'disabled' ] + $disable;
590 $counts[ 'enabled' ] = $counts[ 'enabled' ] + $enable;
591 }
592 self::$counts = (object) $counts;
593 wp_cache_set( $cache_key, self::$counts, 'counts' );
594 return self::$counts;
595 }
596
597 public function notificationx(){
598 $notificationx = new WP_Query(array(
599 'post_type' => 'notificationx',
600 'post_status' => array('publish', 'trash', 'draft'),
601 'numberposts' => -1,
602 ));
603
604 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin.php';
605 }
606
607 public function quick_builder(){
608 $builder_args = $this->builder_args;
609 $tabs = $this->builder_args['tabs'];
610 $prefix = self::$prefix;
611 $metabox_id = $this->metabox_id;
612 /**
613 * This lines of code is for editing a notification in simple|quick builder
614 *
615 * @var [type]
616 */
617 $idd = null;
618 if( isset( $_GET['post_id'] ) && ! empty( $_GET['post_id'] )) {
619 $idd = intval( $_GET['post_id'] );
620 }
621 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-quick-builder-display.php';
622 }
623 /**
624 * Generate the builder data acording to default meta data
625 *
626 * @param array $data
627 * @return array
628 */
629 protected function builder_data( $data ) {
630 $post_data = [];
631 $prefix = self::$prefix;
632 $meta_fields = NotificationX_MetaBox::get_metabox_fields( $prefix );
633 foreach( $meta_fields as $meta_key => $meta_field ) {
634 if( in_array( $meta_key, array_keys($data) ) ) {
635 $post_data[ $meta_key ] = $data[ $meta_key ];
636 } else {
637 $post_data[ $meta_key ] = '';
638
639 if( isset( $meta_field['defaults'] ) ) {
640 $post_data[ $meta_key ] = $meta_field['defaults'];
641 }
642 if( isset( $meta_field['default'] ) ) {
643 $post_data[ $meta_key ] = $meta_field['default'];
644 }
645 }
646 }
647
648 return array_merge( $post_data, $data );
649 }
650
651 public static function get_form_action( $query_var = '', $builder_form = false ) {
652 $page = '/admin.php?page=nx-settings';
653 if( $builder_form ) {
654 $page = '/admin.php?page=nx-builder';
655 }
656
657 if ( is_network_admin() ) {
658 return network_admin_url( $page . $query_var );
659 } else {
660 return admin_url( $page . $query_var );
661 }
662 }
663
664 public function notification_preview(){
665 global $pagenow, $post_type, $post;
666 if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) {
667 return false;
668 }
669 if ( $this->type != $post_type ) {
670 return false;
671 }
672 $display_type = get_post_meta( $post->ID, '_nx_meta_display_type', true );
673
674 include NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin-preview.php';
675 }
676 //TODO: Notification Preview Not Visible for now.
677 public function preview_html( $settings, $type = 'conversion' ){
678 $data = array(
679 'comment' => array(
680 'link' => '#',
681 'post_title' => 'Hello world!',
682 'post_link' => '#',
683 'timestamp' => '1550986787',
684 'user_id' => get_current_user_id(),
685 'name' => 'John D',
686 ),
687 'conversion' => array(
688 'link' => '#',
689 'title' => 'Hello world!',
690 'timestamp' => '1550986787',
691 'user_id' => get_current_user_id(),
692 'name' => 'John D',
693 )
694 );
695
696 $unique_id = uniqid( 'notificationx-' );
697 $output = '<div id="'. esc_attr( $unique_id ) .'" class="nx-notification '. implode( ' ', NotificationX_Extension::get_classes( $settings ) ) .'">';
698 $output .= '<div '. NotificationX_Public::generate_preview_css( $settings ) .' class="notificationx-inner '. implode( ' ', NotificationX_Extension::get_classes( $settings, 'inner' ) ) .'">';
699 $output .= '<div class="notificationx-image nx-preview-image">';
700 $output .= '<img class="'. implode( ' ', NotificationX_Extension::get_classes( $settings, 'img' ) ) .'" src="'. NOTIFICATIONX_ADMIN_URL . 'assets/img/placeholder-300x300.png" alt="">';
701 $output .= '</div>';
702 $output .= '<div class="notificationx-content">';
703 if( $type === 'conversion' ) :
704 $output .= NotificationX_Template::get_template_ready( $settings->woo_template, NotificationX_Extension::newData( $data[ 'conversion' ] ), $settings );
705 endif;
706 if( $type === 'comment' ) :
707 $output .= NotificationX_Template::get_template_ready( $settings->comments_template, NotificationX_Extension::newData( $data[ 'comment' ] ), $settings );
708 endif;
709 if( $settings->close_button ) :
710 $output .= '<span class="notificationx-close nx-preview-close"><svg width="8px" height="8px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Page-1" stroke="none" stroke-width="1" fill-rule="evenodd"><g id="close" fill-rule="nonzero"><path d="M28.228,23.986 L47.092,5.122 C48.264,3.951 48.264,2.051 47.092,0.88 C45.92,-0.292 44.022,-0.292 42.85,0.88 L23.986,19.744 L5.121,0.88 C3.949,-0.292 2.051,-0.292 0.879,0.88 C-0.293,2.051 -0.293,3.951 0.879,5.122 L19.744,23.986 L0.879,42.85 C-0.293,44.021 -0.293,45.921 0.879,47.092 C1.465,47.677 2.233,47.97 3,47.97 C3.767,47.97 4.535,47.677 5.121,47.091 L23.986,28.227 L42.85,47.091 C43.436,47.677 44.204,47.97 44.971,47.97 C45.738,47.97 46.506,47.677 47.092,47.091 C48.264,45.92 48.264,44.02 47.092,42.849 L28.228,23.986 Z" id="Shape"></path></g></g></svg></span>';
711 endif;
712 if( is_null( NotificationX_Extension::$powered_by ) ) :
713 $output .= '<small class="nx-branding">';
714 $output .= '<svg width="12px" height="16px" viewBox="0 0 387 392" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><desc>Created with Sketch.</desc><defs></defs><g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="NotificationX_final" transform="translate(-1564.000000, -253.000000)"><g id="Group" transform="translate(1564.000000, 253.000000)"><path d="M135.45,358.68 C173.45,358.68 211.27,358.68 249.07,358.68 C247.02,371.83 221.24,388.59 199.26,390.98 C173.92,393.73 143.23,378.38 135.45,358.68 Z" id="Shape" fill="#5614D5" fill-rule="nonzero"></path><path d="M372.31,305.79 C369.97,305.59 367.6,305.71 365.24,305.71 C359.63,305.7 354.02,305.71 347.08,305.71 C347.08,301.43 347.08,298.42 347.08,295.41 C347.07,248.75 347.25,202.09 346.91,155.43 C346.83,144.89 345.88,134.19 343.79,123.87 C326.39,37.9 239.94,-16.19 154.81,5.22 C86.84,22.31 37.91,84.26 38.19,154.7 C38.36,197.12 38.21,239.54 38.2,281.96 C38.2,285.8 38.18,297.79 38.16,305.7 C32.98,305.66 18.07,305.57 12.86,305.88 C5.13,306.33 -0.06,312.31 0.04,319.97 C0.14,327.43 5.08,332.74 12.67,333.42 C14.78,333.61 16.91,333.57 19.03,333.57 C134.74,333.61 250.46,333.64 366.17,333.66 C368.29,333.66 370.42,333.69 372.53,333.48 C380.01,332.73 385.14,327.23 385.28,319.95 C385.41,312.58 379.86,306.44 372.31,305.79 Z" id="Shape" fill="#5614D5" fill-rule="nonzero"></path><circle id="Oval" fill="#836EFF" fill-rule="nonzero" cx="281.55" cy="255.92" r="15.49"></circle><path d="M295.67,140.1 L295.91,139.94 C295.7,138.63 295.52,137.29 295.27,136.02 C285.87,89.57 245.83,55.34 198.79,52.53 C198.73,52.53 198.67,52.52 198.61,52.52 C196.59,52.4 194.57,52.32 192.53,52.32 C192.48,52.32 192.44,52.32 192.39,52.32 C192.34,52.32 192.3,52.32 192.25,52.32 C190.21,52.32 188.18,52.4 186.17,52.52 C186.11,52.52 186.05,52.53 185.99,52.53 C138.95,55.34 98.91,89.57 89.51,136.02 C89.25,137.29 89.07,138.63 88.87,139.94 L89.11,140.1 C88.2,145.6 87.72,151.22 87.74,156.9 C87.76,161.42 87.77,256.77 87.78,269.74 L119.91,304.42 C119.91,280.14 119.9,170.57 119.85,156.78 C119.72,124.18 142.81,94.69 174.76,86.66 C177.41,85.99 180.09,85.5 182.78,85.13 C183.23,85.07 183.67,85 184.13,84.95 C185.15,84.83 186.17,84.74 187.18,84.66 C188.64,84.56 190.1,84.48 191.58,84.47 C191.85,84.47 192.12,84.45 192.39,84.44 C192.66,84.44 192.93,84.46 193.2,84.47 C194.68,84.48 196.14,84.56 197.6,84.66 C198.62,84.74 199.64,84.83 200.65,84.95 C201.1,85 201.55,85.07 202,85.13 C204.69,85.5 207.37,85.99 210.02,86.66 C241.96,94.69 265.06,124.19 264.93,156.78 C264.91,161.95 264.9,207.07 264.89,228.18 L297.03,206.73 C297.03,194.5 297.04,158.28 297.04,156.91 C297.06,151.21 296.59,145.6 295.67,140.1 Z" id="Shape" fill="#836EFF" fill-rule="nonzero"></path><path d="M31.94,305.72 C25.58,305.85 19.2,305.51 12.86,305.88 C5.13,306.33 -0.06,312.31 0.04,319.97 C0.14,327.43 5.08,332.74 12.67,333.42 C14.78,333.61 16.91,333.57 19.03,333.57 C134.74,333.61 250.45,333.63 366.17,333.66 C368.29,333.66 370.42,333.69 372.53,333.48 C380.01,332.73 385.14,327.23 385.28,319.95 C385.42,312.58 379.87,306.45 372.32,305.79 C369.98,305.59 367.61,305.71 365.25,305.71 C359.64,305.7 354.03,305.71 347.09,305.71 C347.09,301.43 347.09,298.42 347.09,295.41 C347.08,254.74 347.2,214.07 347.01,173.41 L131.62,317.03 L53.58,232.81 L87.05,202.02 L138.72,257.62 L343.2,121.26 C324.59,36.81 239.08,-15.98 154.82,5.21 C86.85,22.3 37.92,84.25 38.2,154.69 C38.37,197.11 38.22,239.53 38.21,281.95 C38.21,287.84 38.3,293.74 38.16,299.62" id="Shape"></path><path d="M346.91,155.42 C346.95,161.41 346.97,167.41 347,173.4 L386.14,147.41 L360.9,109.57 L343.2,121.26 C343.39,122.13 343.62,122.98 343.8,123.85 C345.88,134.18 346.84,144.89 346.91,155.42 Z" id="Shape" fill="#00F9AC" fill-rule="nonzero"></path><path d="M87.05,202.03 L53.58,232.82 L131.62,317.04 L347,173.41 C346.97,167.42 346.96,161.42 346.91,155.43 C346.83,144.89 345.88,134.19 343.79,123.87 C343.61,122.99 343.39,122.14 343.19,121.28 L138.72,257.63 L87.05,202.03 Z" id="Shape"></path><path d="M87.05,202.03 L53.58,232.82 L131.62,317.04 L347,173.41 C346.97,167.42 346.96,161.42 346.91,155.43 C346.83,144.89 345.88,134.19 343.79,123.87 C343.61,122.99 343.39,122.14 343.19,121.28 L138.72,257.63 L87.05,202.03 Z" id="Shape" fill="#21D8A3" fill-rule="nonzero" opacity="0.9"></path></g></g></g></svg>';
715 $output .= ' by <a href="'. NOTIFICATIONX_PLUGIN_URL .'?utm_source='. urlencode( home_url() ) .'&utm_medium=notificationx" target="_blank" class="nx-powered-by">NotificationX</a>';
716 $output .= '</small>';
717 endif;
718 $output .= '</div>';
719 $output .= '</div>';
720 $output .= '</div>';
721
722 return $output;
723 }
724
725 public static function get_post_meta( $post_id, $key, $single = true ) {
726 return get_post_meta( $post_id, '_nx_meta_' . $key, $single );
727 }
728 public static function update_post_meta( $post_id, $key, $value ) {
729 update_post_meta( $post_id, '_nx_meta_' . $key, $value );
730 }
731 }