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

853 lines 31.0 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
69 public static $enabled_types = [];
70 public static $active_items = [];
71
72 public function __construct( $plugin_name, $version ) {
73
74 $this->plugin_name = $plugin_name;
75 $this->version = $version;
76 self::$settings = NotificationX_DB::get_settings();
77 }
78 /**
79 * Get all active items.
80 *
81 * @return void
82 */
83 public static function get_active_items() {
84 // WP Query arguments.
85 $source_types = NotificationX_Helper::source_types();
86 $args = array(
87 'post_type' => 'notificationx',
88 'posts_per_page' => '-1',
89 'post_status' => 'publish',
90 );
91 self::$active_items = [];
92 // Get the notification posts.
93 $posts = get_posts( $args );
94 if ( count( $posts ) ) {
95 foreach ( $posts as $post ) {
96 $settings = NotificationX_MetaBox::get_metabox_settings( $post->ID );
97 $type = '';
98 if( array_key_exists( $settings->display_type, $source_types ) ) {
99 $type = $settings->{ $source_types[ $settings->display_type ] };
100 }
101 self::$active_items[ $type ][] = $post->ID;
102 }
103 }
104
105 return self::$active_items;
106 }
107
108 public function trashed_notificationx(){
109 $screen = get_current_screen();
110 if( $screen->id == 'edit-notificationx' ) {
111 if( isset( $_GET['trashed'] ) ){
112 $intval = intval($_GET['trashed']);
113 if( $intval > 0 ) {
114 $current_url = admin_url('admin.php?page=nx-admin');
115 wp_safe_redirect( $current_url );
116 exit;
117 }
118 }
119 }
120 }
121
122 public function redirect_after_publish( $post_ID, $post, $update ){
123 if( ( isset( $_POST['is_quick_builder'] ) && $_POST['is_quick_builder'] == true ) || ( isset( $_GET['action'], $_GET['page'] ) && $_GET['action'] == 'nxduplicate' ) ) {
124 return;
125 }
126 if( isset( $post->post_type ) && $post->post_type == 'notificationx' ) {
127 if( isset( $post->post_status ) && $post->post_status == 'publish' ) {
128 $current_url = admin_url('admin.php?page=nx-admin');
129 wp_safe_redirect( $current_url );
130 exit;
131 }
132 }
133 return $post_ID;
134 }
135
136 public static function get_enabled_types() {
137 // WP Query arguments.
138 $source_types = NotificationX_Helper::source_types();
139 $args = array(
140 'post_type' => 'notificationx',
141 'posts_per_page' => '-1',
142 'post_status' => 'publish',
143 'meta_key' => '_nx_meta_active_check',
144 'meta_value' => 1
145 );
146 self::$enabled_types = [];
147 // Get the notification posts.
148 $posts = get_posts( $args );
149 if ( count( $posts ) ) {
150 foreach ( $posts as $post ) {
151 $settings = NotificationX_MetaBox::get_metabox_settings( $post->ID );
152 $type = '';
153 if( array_key_exists( $settings->display_type, $source_types ) ) {
154 $type = $settings->{ $source_types[ $settings->display_type ] };
155 }
156 self::$enabled_types[ $type ][] = $post->ID;
157 }
158 }
159
160 return self::$enabled_types;
161 }
162 /**
163 * Register the stylesheets for the admin area.
164 *
165 * @since 1.0.0
166 */
167 public function enqueue_styles( $hook ) {
168 global $post_type;
169 $page_status = false;
170 wp_enqueue_style(
171 $this->plugin_name . '-admin-global',
172 NOTIFICATIONX_ADMIN_URL . 'assets/css/nx-admin-global.min.css',
173 array(), $this->version, 'all'
174 );
175 if( $hook == 'notificationx_page_nx-builder' || $hook == 'notificationx_page_nx-settings' ) {
176 $page_status = true;
177 }
178
179 if( $post_type != $this->type && ! $page_status ) {
180 return;
181 }
182
183 wp_enqueue_style( 'wp-color-picker' );
184 wp_enqueue_style(
185 $this->plugin_name . '-select2',
186 NOTIFICATIONX_ADMIN_URL . 'assets/css/select2.min.css',
187 array(), $this->version, 'all'
188 );
189 wp_enqueue_style(
190 $this->plugin_name,
191 NOTIFICATIONX_ADMIN_URL . 'assets/css/nx-admin.min.css',
192 array(), $this->version, 'all'
193 );
194 }
195 /**
196 * Register the JavaScript for the admin area.
197 *
198 * @since 1.0.0
199 */
200 public function enqueue_scripts( $hook ) {
201 global $post_type;
202 $page_status = false;
203
204 if( $hook == 'notificationx_page_nx-builder' || $hook == 'notificationx_page_nx-settings' ) {
205 $page_status = true;
206 }
207
208 if( $hook === 'toplevel_page_nx-admin' ) {
209 wp_enqueue_script(
210 $this->plugin_name . '-sweetalert',
211 NOTIFICATIONX_ADMIN_URL . 'assets/js/sweetalert.min.js',
212 array( 'jquery' ), $this->version, true
213 );
214 wp_enqueue_script(
215 $this->plugin_name,
216 NOTIFICATIONX_ADMIN_URL . 'assets/js/nx-admin.min.js',
217 array( 'jquery' ), $this->version, true
218 );
219 }
220
221
222 if( $post_type != $this->type && ! $page_status ) {
223 return;
224 }
225
226 wp_enqueue_script( 'wp-color-picker' );
227 wp_enqueue_script( 'jquery-ui-datepicker' );
228 wp_enqueue_media();
229 wp_enqueue_script(
230 $this->plugin_name . '-sweetalert',
231 NOTIFICATIONX_ADMIN_URL . 'assets/js/sweetalert.min.js',
232 array( 'jquery' ), $this->version, true
233 );
234 wp_enqueue_script(
235 $this->plugin_name . '-select2',
236 NOTIFICATIONX_ADMIN_URL . 'assets/js/select2.min.js',
237 array( 'jquery' ), $this->version, true
238 );
239 wp_enqueue_script(
240 $this->plugin_name,
241 NOTIFICATIONX_ADMIN_URL . 'assets/js/nx-admin.min.js',
242 array( 'jquery' ), $this->version, true
243 );
244
245 wp_localize_script( $this->plugin_name, 'notificationx', self::toggleFields() );
246 }
247
248 public function toggleFields( $builder = false ){
249 $args = NotificationX_MetaBox::get_args();
250 if( $builder ) {
251 $args = NotificationX_MetaBox::get_builder_args();
252 }
253
254 $toggleFields = $hideFields = $conditions = array();
255
256 $tabs = $args[ 'tabs' ];
257 if( ! empty( $tabs ) ) {
258 foreach( $tabs as $tab_id => $tab ) {
259 $sections = isset( $tab['sections'] ) ? $tab[ 'sections' ] : [];
260 if( ! empty( $sections ) ) {
261 foreach( $sections as $section_id => $section ) {
262 $fields = isset( $section['fields'] ) ? $section[ 'fields' ] : [];
263 if( ! empty( $fields ) ) {
264 foreach( $fields as $field_key => $field ) {
265 if( isset( $field['fields'] ) ) {
266 foreach( $field['fields'] as $inner_field_key => $inner_field ) {
267 if( isset( $inner_field['hide'] ) && ! empty( $inner_field['hide'] ) && is_array( $inner_field['hide'] ) ) {
268 foreach( $inner_field['hide'] as $key => $hide ) {
269 $hideFields[ $inner_field_key ][ $key ] = $hide;
270 }
271 }
272 if( isset( $inner_field['dependency'] ) && ! empty( $inner_field['dependency'] ) && is_array( $inner_field['dependency'] ) ) {
273 foreach( $inner_field['dependency'] as $key => $dependency ) {
274 $conditions[ $inner_field_key ][ $key ] = $dependency;
275 }
276 }
277 }
278 }
279
280 if( isset( $field['hide'] ) && ! empty( $field['hide'] ) && is_array( $field['hide'] ) ) {
281 foreach( $field['hide'] as $key => $hide ) {
282 $hideFields[ $field_key ][ $key ] = $hide;
283 }
284 }
285 if( isset( $field['dependency'] ) && ! empty( $field['dependency'] ) && is_array( $field['dependency'] ) ) {
286 foreach( $field['dependency'] as $key => $dependency ) {
287 $conditions[ $field_key ][ $key ] = $dependency;
288 }
289 }
290 }
291 }
292 }
293 }
294 }
295 }
296
297 $template = apply_filters( 'nx_template_name', array() );
298 $template_settings = apply_filters( 'nx_template_settings_by_theme', array() );
299
300 return array(
301 'toggleFields' => $conditions, // TODO: toggling system has to be more optimized!
302 'hideFields' => $hideFields,
303 'template' => $template,
304 'template_settings' => $template_settings,
305 'source_types' => NotificationX_Helper::source_types(),
306 'theme_sources' => NotificationX_Helper::theme_sources(),
307 'template_keys' => NotificationX_Helper::template_keys(),
308 );
309 }
310
311 public function custom_columns( $columns ) {
312 $title_column = $columns['title'];
313 $date_column = $columns['date'];
314
315 unset( $columns['title'] );
316 unset( $columns['date'] );
317
318 $columns['notification_status'] = __('Enable / Disable', 'notificationx');
319 $columns['title'] = $title_column;
320
321 $columns['notification_type'] = __('Type', 'notificationx');
322
323 $columns['date'] = $date_column;
324
325 return apply_filters('nx_post_columns', $columns );
326 }
327
328 public function manage_custom_columns( $column, $post_id ){
329 switch ( $column ) {
330 case 'notification_type':
331 $type = get_post_meta( $post_id, '_nx_meta_display_type', true );
332 if ( $type ) {
333 $type = NotificationX_Helper::notification_types( $type );
334 if( $type !== 'Conversions' ) {
335 echo $type;
336 } else {
337 $from = get_post_meta( $post_id, '_nx_meta_conversion_from', true );
338 echo $type . ' - ' . NotificationX_Helper::conversion_from( $from );
339 }
340 }
341 break;
342 case 'notification_status':
343 $status = get_post_meta( $post_id, '_nx_meta_active_check', true );
344 self::notification_toggle( $status, $post_id );
345 break;
346 }
347
348 do_action( 'nx_post_columns_content', $column, $post_id );
349 }
350
351 public static function notification_toggle( $status = '1', $post_id ){
352 $text = __('Active', 'notificationx');
353 $img_active = NOTIFICATIONX_ADMIN_URL . 'assets/img/active1.png';
354 $img_inactive = NOTIFICATIONX_ADMIN_URL . 'assets/img/active0.png';
355 $active = 'true';
356 $img = $img_active;
357
358 if ( ! $status ) {
359 $text = __('Inactive', 'notificationx');
360 $img = $img_inactive;
361 $active = 'false';
362 }
363 ?>
364 <img
365 src="<?php echo $img; ?>"
366 style="cursor: pointer; height: 16px; vertical-align: middle;"
367 alt="<?php echo $text; ?>" title="<?php echo $text; ?>"
368 data-nonce="<?php echo wp_create_nonce('notificationx_status_nonce'); ?>"
369 data-post="<?php echo $post_id; ?>" />
370 <?php
371 }
372
373 public function notification_status(){
374 $error = false;
375
376 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'notificationx_status_nonce' ) ) {
377 $error = true;
378 }
379
380 if ( ! isset( $_POST['post_id'] ) || empty( $_POST['post_id'] ) || ! absint( $_POST['post_id'] ) ) {
381 $error = true;
382 }
383
384 if ( $error ) {
385 echo __('There is an error updating status.', 'notificationx');
386 die();
387 }
388
389 $post_id = absint( $_POST['post_id'] );
390 $status = $_POST['status'] == 'active' ? '1' : '0';
391
392 update_post_meta( $post_id, '_nx_meta_active_check', $status );
393 if( isset( $_POST['url'] ) ) {
394 wp_safe_redirect( $_POST['url'] );
395 }
396 echo 'success';
397 die();
398 }
399 /**
400 * Register the NotificationX custom post type.
401 *
402 * @since 1.0.0
403 */
404 public function register(){
405
406 $labels = array(
407 'name' => 'NotificationX',
408 'singular_name' => 'NotificationX',
409 'add_new' => esc_html__( 'Add New', 'notificationx' ) ,
410 'add_new_item' => esc_html__( 'Add New', 'notificationx' ),
411 'edit_item' => esc_html__( 'Edit', 'notificationx' ),
412 'new_item' => esc_html__( 'New', 'notificationx' ),
413 'view_item' => esc_html__( 'View', 'notificationx' ),
414 'search_items' => esc_html__( 'Search', 'notificationx' ),
415 'not_found' => esc_html__( 'No notification x is found', 'notificationx' ),
416 'not_found_in_trash' => esc_html__( 'No notification x is found in Trash', 'notificationx' ),
417 'menu_name' => 'NotificationX',
418 );
419
420 $args = array(
421 'labels' => $labels,
422 'hierarchical' => false,
423 'description' => '',
424 'taxonomies' => array( '' ),
425 'public' => false,
426 'show_ui' => true,
427 'show_in_menu' => 'notificationx',
428 'show_in_admin_bar' => true,
429 'show_in_rest' => false,
430 'menu_position' => 80,
431 'menu_icon' => NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon-colored.png',
432 'show_in_nav_menus' => false,
433 'publicly_queryable' => false,
434 'exclude_from_search' => true,
435 'has_archive' => false,
436 'query_var' => true,
437 'can_export' => true,
438 'rewrite' => '',
439 'capability_type' => 'post',
440 'supports' => array( 'title' ),
441 );
442
443 register_post_type( $this->type, $args );
444 add_image_size( "_nx_notification_thumb", 100, 100, true );
445 }
446
447 public function upgrade_notificationx(){
448
449 }
450
451 /**
452 * Admin Menu Page
453 *
454 * @return void
455 */
456 public function menu_page(){
457
458 $this->builder_args = NotificationX_MetaBox::get_builder_args();
459 $this->metabox_id = $this->builder_args['id'];
460
461 if( ! current_user_can( 'manage_options' ) ) {
462 return;
463 }
464
465 $settings_class = new NotificationX_Settings();
466
467 $settings = apply_filters( 'notificationx_admin_menu', array(
468 'nx-settings' => array(
469 'title' => __('Settings', 'notificationx'),
470 'capability' => 'delete_users',
471 'callback' => array( $settings_class, 'settings_page' )
472 ),
473 'nx-builder' => array(
474 'title' => __('Quick Builder', 'notificationx'),
475 'capability' => 'delete_users',
476 'callback' => array( $this, 'quick_builder' )
477 ),
478 ) );
479
480 add_menu_page( 'NotificationX', 'NotificationX', 'delete_users', 'nx-admin', array( $this, 'notificationx' ), NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon.png', 80 );
481 foreach( $settings as $slug => $setting ) {
482 $cap = isset( $setting['capability'] ) ? $setting['capability'] : 'delete_users';
483 $hook = add_submenu_page( 'nx-admin', $setting['title'], $setting['title'], $cap, $slug, $setting['callback'] );
484 }
485 }
486
487 public function highlight_admin_menu( $parent_file ){
488 if( $parent_file === 'notificationx' ) {
489 return 'nx-admin';
490 }
491 return $parent_file;
492 }
493 public function highlight_admin_submenu( $submenu_file, $parent_file ){
494 if( $parent_file == 'nx-admin' && $submenu_file == 'edit.php?post_type=notificationx' ) {
495 return "nx-admin";
496 }
497 return $submenu_file;
498 }
499
500 public static function count_posts( $type = 'notificationx', $perm = '' ) {
501 global $wpdb;
502 if ( ! post_type_exists( $type ) ) {
503 return new stdClass;
504 }
505 $cache_key = 'nx_counts_cache';
506 self::$counts = wp_cache_get( $cache_key, 'counts' );
507 if ( false !== self::$counts ) {
508 return self::$counts;
509 }
510 $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'";
511 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
512 $counts = array_fill_keys( array( 'enabled', 'disabled', 'trash', 'publish' ), 0 );
513 $disable = 0;
514 $enable = 0;
515 foreach ( $results as $row ) {
516 $counts[ 'publish' ] = $counts['publish'] + ( $row['post_status'] === 'publish' ? 1 : 0 );
517 $counts[ 'trash' ] = $counts['trash'] + ( $row['post_status'] === 'trash' ? 1 : 0 );
518
519 if( $row[ 'meta_value' ] == 0 ) {
520 $disable = 1;
521 $enable = 0;
522 }
523 if( $row[ 'meta_value' ] == 1 ) {
524 $disable = 0;
525 $enable = 1;
526 }
527
528 if( $disable == 1 && $row['post_status'] == 'trash' ) {
529 $disable = 0;
530 }
531
532 if( $enable == 1 && $row['post_status'] == 'trash' ) {
533 $enable = 0;
534 }
535
536 $counts[ 'disabled' ] = $counts[ 'disabled' ] + $disable;
537 $counts[ 'enabled' ] = $counts[ 'enabled' ] + $enable;
538 }
539 self::$counts = (object) $counts;
540 wp_cache_set( $cache_key, self::$counts, 'counts' );
541 return self::$counts;
542 }
543
544 public function notificationx(){
545 $notificationx = new WP_Query(array(
546 'post_type' => 'notificationx',
547 'post_status' => array('publish', 'trash', 'draft'),
548 'numberposts' => -1,
549 ));
550
551 $table_header = apply_filters( 'nx_admin_table_header', array(
552 'NotificationX Title',
553 __('Preview', 'notificationx'),
554 __('Status', 'notificationx'),
555 __('Type', 'notificationx'),
556 __('Stats', 'notificationx'),
557 __('Date', 'notificationx'),
558 ));
559 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin.php';
560 }
561
562 public function get_stats( $idd ){
563 $from_pro = apply_filters('nx_admin_table_stats', '', $idd );
564 if( $from_pro == '' ) {
565 echo '<img data-swal="true" class="nx-stats-tease" width="45" src="'. NOTIFICATIONX_ADMIN_URL .'/assets/img/pro.svg"/>';
566 }
567 echo $from_pro;
568 }
569
570 public function quick_builder(){
571 $builder_args = $this->builder_args;
572 $tabs = $this->builder_args['tabs'];
573 $prefix = self::$prefix;
574 $metabox_id = $this->metabox_id;
575 /**
576 * This lines of code is for editing a notification in simple|quick builder
577 *
578 * @var [type]
579 */
580 $idd = null;
581 if( isset( $_GET['post_id'] ) && ! empty( $_GET['post_id'] )) {
582 $idd = intval( $_GET['post_id'] );
583 }
584 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-quick-builder-display.php';
585 }
586 /**
587 * Generate the builder data acording to default meta data
588 *
589 * @param array $data
590 * @return array
591 */
592 protected function builder_data( $data ) {
593 $post_data = [];
594 $prefix = self::$prefix;
595 $meta_fields = NotificationX_MetaBox::get_metabox_fields( $prefix );
596 foreach( $meta_fields as $meta_key => $meta_field ) {
597 if( in_array( $meta_key, array_keys($data) ) ) {
598 $post_data[ $meta_key ] = $data[ $meta_key ];
599 } else {
600 $post_data[ $meta_key ] = '';
601
602 if( isset( $meta_field['defaults'] ) ) {
603 $post_data[ $meta_key ] = $meta_field['defaults'];
604 }
605 if( isset( $meta_field['default'] ) ) {
606 $post_data[ $meta_key ] = $meta_field['default'];
607 }
608 }
609 }
610
611 return array_merge( $post_data, $data );
612 }
613
614 public static function get_form_action( $query_var = '', $builder_form = false ) {
615 $page = '/admin.php?page=nx-settings';
616 if( $builder_form ) {
617 $page = '/admin.php?page=nx-builder';
618 }
619
620 if ( is_network_admin() ) {
621 return network_admin_url( $page . $query_var );
622 } else {
623 return admin_url( $page . $query_var );
624 }
625 }
626
627 public function notification_preview(){
628 global $pagenow, $post_type, $post;
629 if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) {
630 return false;
631 }
632 if ( $this->type != $post_type ) {
633 return false;
634 }
635 $display_type = get_post_meta( $post->ID, '_nx_meta_display_type', true );
636
637 include NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin-preview.php';
638 }
639 //TODO: Notification Preview Not Visible for now.
640 public function preview_html( $settings, $type = 'conversion' ){
641 $data = array(
642 'comment' => array(
643 'link' => '#',
644 'post_title' => 'Hello world!',
645 'post_link' => '#',
646 'timestamp' => '1550986787',
647 'user_id' => get_current_user_id(),
648 'name' => 'John D',
649 ),
650 'conversion' => array(
651 'link' => '#',
652 'title' => 'Hello world!',
653 'timestamp' => '1550986787',
654 'user_id' => get_current_user_id(),
655 'name' => 'John D',
656 )
657 );
658
659 $unique_id = uniqid( 'notificationx-' );
660 $output = '<div id="'. esc_attr( $unique_id ) .'" class="nx-notification '. implode( ' ', NotificationX_Extension::get_classes( $settings ) ) .'">';
661 $output .= '<div '. NotificationX_Public::generate_preview_css( $settings ) .' class="notificationx-inner '. implode( ' ', NotificationX_Extension::get_classes( $settings, 'inner' ) ) .'">';
662 $output .= '<div class="notificationx-image nx-preview-image">';
663 $output .= '<img class="'. implode( ' ', NotificationX_Extension::get_classes( $settings, 'img' ) ) .'" src="'. NOTIFICATIONX_ADMIN_URL . 'assets/img/placeholder-300x300.png" alt="">';
664 $output .= '</div>';
665 $output .= '<div class="notificationx-content">';
666 if( $type === 'conversion' ) :
667 $output .= NotificationX_Template::get_template_ready( $settings->woo_template, NotificationX_Extension::newData( $data[ 'conversion' ] ), $settings );
668 endif;
669 if( $type === 'comment' ) :
670 $output .= NotificationX_Template::get_template_ready( $settings->comments_template, NotificationX_Extension::newData( $data[ 'comment' ] ), $settings );
671 endif;
672 if( $settings->close_button ) :
673 $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>';
674 endif;
675 if( is_null( NotificationX_Extension::$powered_by ) ) :
676 $output .= '<small class="nx-branding">';
677 $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>';
678 $output .= ' by <a href="'. NOTIFICATIONX_PLUGIN_URL .'?utm_source='. urlencode( home_url() ) .'&utm_medium=notificationx" target="_blank" class="nx-powered-by">NotificationX</a>';
679 $output .= '</small>';
680 endif;
681 $output .= '</div>';
682 $output .= '</div>';
683 $output .= '</div>';
684
685 return $output;
686 }
687
688 public static function get_post_meta( $post_id, $key, $single = true ) {
689 return get_post_meta( $post_id, '_nx_meta_' . $key, $single );
690 }
691 public static function update_post_meta( $post_id, $key, $value ) {
692 update_post_meta( $post_id, '_nx_meta_' . $key, $value );
693 }
694 /**
695 * Admin Init For User Interactions
696 * @return void
697 */
698 public function admin_init( $hook ){
699 /**
700 * NotificationX Admin URL
701 */
702 $current_url = admin_url('admin.php?page=nx-admin');
703 /**
704 * For Duplicate NotificationX
705 */
706 $this->duplicate_notificationx( $current_url );
707 /**
708 * For Empty Trash
709 */
710 $this->empty_trash( $current_url );
711 /**
712 * For Enable And Disable
713 */
714 $this->enable_disable( $current_url );
715 /**
716 * For Quick Builder Submit
717 */
718 $this->quick_builder_submit( $current_url );
719 }
720 /**
721 * For Empty Trash
722 * @return void
723 */
724 protected function empty_trash( $current_url = '' ) {
725 if( empty( $current_url ) ) {
726 return;
727 }
728 if( isset( $_GET['delete_all'], $_GET['page'] ) && $_GET['delete_all'] == true && $_GET['page'] == 'nx-admin' ) {
729 $notificationx = new WP_Query(array(
730 'post_type' => 'notificationx',
731 'post_status' => array('trash'),
732 'numberposts' => -1,
733 ));
734 if( $notificationx->have_posts() ) {
735 while( $notificationx->have_posts() ) : $notificationx->the_post();
736 $iddd = get_the_ID();
737 wp_delete_post( $iddd );
738 endwhile;
739 wp_safe_redirect( $current_url ); // TODO: after all remove trash redirect.
740 die;
741 }
742 }
743 }
744 /**
745 * For Enable and Disable NotificationX.
746 * @param string $current_url
747 * @return void
748 */
749 protected function enable_disable( $current_url = '' ){
750 if( empty( $current_url ) ) {
751 return;
752 }
753 // For Enable & Disable
754 if( isset( $_GET['status'], $_GET['page'] ) && $_GET['page'] == 'nx-admin' ) {
755 $post_status = self::count_posts();
756 $get_enabled_post = $post_status->enabled;
757 $get_disabled_post = $post_status->disabled;
758 $trash_notificationx = $post_status->trash;
759
760 if( ( $_GET['status'] == 'disabled' && $get_disabled_post == 0 )
761 || ( $_GET['status'] == 'trash' && $trash_notificationx == 0 )
762 || ( $_GET['status'] == 'enabled' && $get_enabled_post == 0 )
763 ) {
764 wp_safe_redirect( $current_url );
765 die;
766 }
767 }
768 }
769 /**
770 * For Duplicate NotificationX
771 * @param string $current_url
772 * @return void
773 */
774 protected function duplicate_notificationx( $current_url = '' ){
775 if( empty( $current_url ) ) {
776 return;
777 }
778 // Duplicating NotificationX
779 if( isset( $_GET['action'], $_GET['page'], $_GET['post'], $_GET['nx_duplicate_nonce'] )
780 && $_GET['action'] === 'nxduplicate' && $_GET['page'] === 'nx-admin' ) {
781 if( wp_verify_nonce( $_GET['nx_duplicate_nonce'], 'nx_duplicate_nonce' ) ) {
782 $nx_post_id = intval( $_GET['post'] );
783 $get_post = get_post( $nx_post_id );
784 $post_data = json_decode( json_encode( $get_post ), true );
785 unset( $post_data['ID'] );
786 $post_data['post_title'] = $post_data['post_title'] . ' - Copy';
787 $duplicate_post_id = wp_insert_post( $post_data );
788 $duplicate_post_id = intval( $duplicate_post_id );
789 $get_post_meta = get_metadata( 'post', $nx_post_id );
790 if( ! empty( $get_post_meta ) ) {
791 foreach( $get_post_meta as $key => $value ){
792 if( in_array( $key, array( '_edit_lock', '_edit_last' ) ) ) {
793 continue;
794 }
795 add_post_meta( $duplicate_post_id, $key, $value[0] );
796 }
797 }
798 wp_safe_redirect( $current_url );
799 exit;
800 }
801 }
802 }
803 /**
804 * For Quick Builder Submit
805 * @return void
806 */
807 protected function quick_builder_submit( $current_url = '' ){
808 if( empty( $current_url ) ) {
809 return;
810 }
811 if( isset( $_POST[ 'nx_builder_add_submit' ], $_POST['is_quick_builder'] ) && $_POST['is_quick_builder'] ) :
812 $flag = true;
813 if ( ! isset( $_POST[$this->metabox_id . '_nonce'] ) || ! wp_verify_nonce( $_POST[$this->metabox_id . '_nonce'], $this->metabox_id ) ) {
814 $flag = false;
815 return;
816 }
817
818 if( $flag ) {
819 if( $_POST['nx_meta_display_type'] == 'press_bar' ) {
820 $title = __('NotificationX - Notification Bar', 'notificationx');
821 } elseif( $_POST['nx_meta_display_type'] == 'comments' ) {
822 $title = __('NotificationX - WP Comments', 'notificationx');
823 } elseif( $_POST['nx_meta_display_type'] == 'conversions' ) {
824 $conversions = NotificationX_Helper::conversion_from();
825 $title = 'NotificationX - ' . $conversions[$_POST['nx_meta_conversion_from']];
826 } else {
827 $title_temp = NotificationX_Helper::notification_types( $_POST['nx_meta_display_type'] );
828 $title = 'NotificationX - ' . $title_temp;
829 }
830 $_POST['post_type'] = 'notificationx';
831 $postdata = array(
832 'post_type' => 'notificationx',
833 'post_title' => $title . ' - ' . date( get_option( 'date_format' ), current_time( 'timestamp' ) ),
834 'post_status' => 'publish',
835 'post_author' => get_current_user_id(),
836 );
837 $p_id = null;
838 $p_id = wp_insert_post($postdata);
839 if( ( $p_id || ! is_wp_error( $p_id ) ) && ! is_null( $p_id ) ) {
840 do_action( 'nx_before_builder_submit', $_POST );
841 // saving builder meta data with post
842 NotificationX_MetaBox::save_data( $this->builder_data( $_POST ), $p_id );
843 /**
844 * Safely Redirect to NotificationX Page
845 */
846 wp_safe_redirect( $current_url );
847 exit;
848 }
849 }
850 endif;
851 }
852 }
853