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

859 lines 31.3 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 'title_of_types' => NotificationX_Helper::types_title(),
306 'source_types' => NotificationX_Helper::source_types(),
307 'theme_sources' => NotificationX_Helper::theme_sources(),
308 'template_keys' => NotificationX_Helper::template_keys(),
309 );
310 }
311
312 public function custom_columns( $columns ) {
313 $title_column = $columns['title'];
314 $date_column = $columns['date'];
315
316 unset( $columns['title'] );
317 unset( $columns['date'] );
318
319 $columns['notification_status'] = __('Enable / Disable', 'notificationx');
320 $columns['title'] = $title_column;
321
322 $columns['notification_type'] = __('Type', 'notificationx');
323
324 $columns['date'] = $date_column;
325
326 return apply_filters('nx_post_columns', $columns );
327 }
328
329 public function manage_custom_columns( $column, $post_id ){
330 switch ( $column ) {
331 case 'notification_type':
332 $type = get_post_meta( $post_id, '_nx_meta_display_type', true );
333 if ( $type ) {
334 $type = NotificationX_Helper::notification_types( $type );
335 if( $type !== 'Conversions' ) {
336 echo $type;
337 } else {
338 $from = get_post_meta( $post_id, '_nx_meta_conversion_from', true );
339 echo $type . ' - ' . NotificationX_Helper::conversion_from( $from );
340 }
341 }
342 break;
343 case 'notification_status':
344 $status = get_post_meta( $post_id, '_nx_meta_active_check', true );
345 self::notification_toggle( $status, $post_id );
346 break;
347 }
348
349 do_action( 'nx_post_columns_content', $column, $post_id );
350 }
351
352 public static function notification_toggle( $status = true, $post_id ){
353 $text = __('Active', 'notificationx');
354 $img_active = NOTIFICATIONX_ADMIN_URL . 'assets/img/active1.png';
355 $img_inactive = NOTIFICATIONX_ADMIN_URL . 'assets/img/active0.png';
356 $active = 'true';
357 $img = $img_active;
358
359 if ( ! $status ) {
360 $text = __('Inactive', 'notificationx');
361 $img = $img_inactive;
362 $active = 'false';
363 }
364 ?>
365 <img
366 src="<?php echo $img; ?>"
367 style="cursor: pointer; height: 16px; vertical-align: middle;"
368 alt="<?php echo $text; ?>" title="<?php echo $text; ?>"
369 data-nonce="<?php echo wp_create_nonce('notificationx_status_nonce'); ?>"
370 data-post="<?php echo $post_id; ?>" />
371 <?php
372 }
373
374 public function notification_status(){
375 $error = false;
376
377 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'notificationx_status_nonce' ) ) {
378 $error = true;
379 }
380
381 if ( ! isset( $_POST['post_id'] ) || empty( $_POST['post_id'] ) || ! absint( $_POST['post_id'] ) ) {
382 $error = true;
383 }
384
385 if ( $error ) {
386 echo __('There is an error updating status.', 'notificationx');
387 die();
388 }
389
390 $post_id = absint( $_POST['post_id'] );
391 $status = $_POST['status'] == 'active' ? '1' : '0';
392
393 update_post_meta( $post_id, '_nx_meta_active_check', $status );
394 if( isset( $_POST['url'] ) ) {
395 wp_safe_redirect( $_POST['url'] );
396 }
397 echo 'success';
398 die();
399 }
400 /**
401 * Register the NotificationX custom post type.
402 *
403 * @since 1.0.0
404 */
405 public function register(){
406
407 $labels = array(
408 'name' => 'NotificationX',
409 'singular_name' => 'NotificationX',
410 'add_new' => esc_html__( 'Add New', 'notificationx' ) ,
411 'add_new_item' => esc_html__( 'Add New', 'notificationx' ),
412 'edit_item' => esc_html__( 'Edit', 'notificationx' ),
413 'new_item' => esc_html__( 'New', 'notificationx' ),
414 'view_item' => esc_html__( 'View', 'notificationx' ),
415 'search_items' => esc_html__( 'Search', 'notificationx' ),
416 'not_found' => esc_html__( 'No notification x is found', 'notificationx' ),
417 'not_found_in_trash' => esc_html__( 'No notification x is found in Trash', 'notificationx' ),
418 'menu_name' => 'NotificationX',
419 );
420
421 $args = array(
422 'labels' => $labels,
423 'hierarchical' => false,
424 'description' => '',
425 'taxonomies' => array( '' ),
426 'public' => false,
427 'show_ui' => true,
428 'show_in_menu' => 'notificationx',
429 'show_in_admin_bar' => true,
430 'show_in_rest' => false,
431 'menu_position' => 80,
432 'menu_icon' => NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon-colored.png',
433 'show_in_nav_menus' => false,
434 'publicly_queryable' => false,
435 'exclude_from_search' => true,
436 'has_archive' => false,
437 'query_var' => true,
438 'can_export' => true,
439 'rewrite' => '',
440 'capability_type' => 'post',
441 'supports' => array( 'title' ),
442 );
443
444 register_post_type( $this->type, $args );
445 add_image_size( "_nx_notification_thumb", 100, 100, true );
446 }
447
448 public function upgrade_notificationx(){
449
450 }
451
452 /**
453 * Admin Menu Page
454 *
455 * @return void
456 */
457 public function menu_page(){
458
459 $this->builder_args = NotificationX_MetaBox::get_builder_args();
460 $this->metabox_id = $this->builder_args['id'];
461
462 if( ! current_user_can( 'manage_options' ) ) {
463 return;
464 }
465
466 $settings_class = new NotificationX_Settings();
467
468 $settings = apply_filters( 'notificationx_admin_menu', array(
469 'nx-settings' => array(
470 'title' => __('Settings', 'notificationx'),
471 'capability' => 'delete_users',
472 'callback' => array( $settings_class, 'settings_page' )
473 ),
474 'nx-builder' => array(
475 'title' => __('Quick Builder', 'notificationx'),
476 'capability' => 'delete_users',
477 'callback' => array( $this, 'quick_builder' )
478 ),
479 ) );
480
481 add_menu_page( 'NotificationX', 'NotificationX', 'delete_users', 'nx-admin', array( $this, 'notificationx' ), NOTIFICATIONX_ADMIN_URL . 'assets/img/nx-menu-icon.png', 80 );
482 /**
483 * @since 1.2.1
484 */
485 add_submenu_page( 'nx-admin', __('Add New', 'notificationx'), __('Add New', 'notificationx'), 'delete_users', 'post-new.php?post_type=notificationx');
486 foreach( $settings as $slug => $setting ) {
487 $cap = isset( $setting['capability'] ) ? $setting['capability'] : 'delete_users';
488 $hook = add_submenu_page( 'nx-admin', $setting['title'], $setting['title'], $cap, $slug, $setting['callback'] );
489 }
490 }
491
492 public function highlight_admin_menu( $parent_file ){
493 if( $parent_file === 'notificationx' ) {
494 return 'nx-admin';
495 }
496 return $parent_file;
497 }
498 public function highlight_admin_submenu( $submenu_file, $parent_file ){
499 if( $parent_file == 'nx-admin' && $submenu_file == 'edit.php?post_type=notificationx' ) {
500 return "nx-admin";
501 }
502 return $submenu_file;
503 }
504
505 public static function count_posts( $type = 'notificationx', $perm = '' ) {
506 global $wpdb;
507 if ( ! post_type_exists( $type ) ) {
508 return new stdClass;
509 }
510 $cache_key = 'nx_counts_cache';
511 self::$counts = wp_cache_get( $cache_key, 'counts' );
512 if ( false !== self::$counts ) {
513 return self::$counts;
514 }
515 $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'";
516 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
517 $counts = array_fill_keys( array( 'enabled', 'disabled', 'trash', 'publish' ), 0 );
518 $disable = 0;
519 $enable = 0;
520 foreach ( $results as $row ) {
521 $counts[ 'publish' ] = $counts['publish'] + ( $row['post_status'] === 'publish' ? 1 : 0 );
522 $counts[ 'trash' ] = $counts['trash'] + ( $row['post_status'] === 'trash' ? 1 : 0 );
523
524 if( $row[ 'meta_value' ] == 0 ) {
525 $disable = 1;
526 $enable = 0;
527 }
528 if( $row[ 'meta_value' ] == 1 ) {
529 $disable = 0;
530 $enable = 1;
531 }
532
533 if( $disable == 1 && $row['post_status'] == 'trash' ) {
534 $disable = 0;
535 }
536
537 if( $enable == 1 && $row['post_status'] == 'trash' ) {
538 $enable = 0;
539 }
540
541 $counts[ 'disabled' ] = $counts[ 'disabled' ] + $disable;
542 $counts[ 'enabled' ] = $counts[ 'enabled' ] + $enable;
543 }
544 self::$counts = (object) $counts;
545 wp_cache_set( $cache_key, self::$counts, 'counts' );
546 return self::$counts;
547 }
548
549 public function notificationx(){
550 $notificationx = new WP_Query(array(
551 'post_type' => 'notificationx',
552 'post_status' => array('publish', 'trash', 'draft'),
553 'numberposts' => -1,
554 'posts_per_page' => -1,
555 ));
556
557 $table_header = apply_filters( 'nx_admin_table_header', array(
558 'NotificationX Title',
559 __('Preview', 'notificationx'),
560 __('Status', 'notificationx'),
561 __('Type', 'notificationx'),
562 __('Stats', 'notificationx'),
563 __('Date', 'notificationx'),
564 ));
565 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin.php';
566 }
567
568 public function get_stats( $idd ){
569 $from_pro = apply_filters('nx_admin_table_stats', '', $idd );
570 if( $from_pro == '' ) {
571 echo '<img data-swal="true" class="nx-stats-tease" width="45" src="'. NOTIFICATIONX_ADMIN_URL .'/assets/img/pro.svg"/>';
572 }
573 echo $from_pro;
574 }
575
576 public function quick_builder(){
577 $builder_args = $this->builder_args;
578 $tabs = $this->builder_args['tabs'];
579 $prefix = self::$prefix;
580 $metabox_id = $this->metabox_id;
581 /**
582 * This lines of code is for editing a notification in simple|quick builder
583 *
584 * @var [type]
585 */
586 $idd = null;
587 if( isset( $_GET['post_id'] ) && ! empty( $_GET['post_id'] )) {
588 $idd = intval( $_GET['post_id'] );
589 }
590 include_once NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-quick-builder-display.php';
591 }
592 /**
593 * Generate the builder data acording to default meta data
594 *
595 * @param array $data
596 * @return array
597 */
598 protected function builder_data( $data ) {
599 $post_data = [];
600 $prefix = self::$prefix;
601 $meta_fields = NotificationX_MetaBox::get_metabox_fields( $prefix );
602 foreach( $meta_fields as $meta_key => $meta_field ) {
603 if( in_array( $meta_key, array_keys($data) ) ) {
604 $post_data[ $meta_key ] = $data[ $meta_key ];
605 } else {
606 $post_data[ $meta_key ] = '';
607
608 if( isset( $meta_field['defaults'] ) ) {
609 $post_data[ $meta_key ] = $meta_field['defaults'];
610 }
611 if( isset( $meta_field['default'] ) ) {
612 $post_data[ $meta_key ] = $meta_field['default'];
613 }
614 }
615 }
616
617 return array_merge( $post_data, $data );
618 }
619
620 public static function get_form_action( $query_var = '', $builder_form = false ) {
621 $page = '/admin.php?page=nx-settings';
622 if( $builder_form ) {
623 $page = '/admin.php?page=nx-builder';
624 }
625
626 if ( is_network_admin() ) {
627 return network_admin_url( $page . $query_var );
628 } else {
629 return admin_url( $page . $query_var );
630 }
631 }
632
633 public function notification_preview(){
634 global $pagenow, $post_type, $post;
635 if ( ! in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) {
636 return false;
637 }
638 if ( $this->type != $post_type ) {
639 return false;
640 }
641 $display_type = get_post_meta( $post->ID, '_nx_meta_display_type', true );
642
643 include NOTIFICATIONX_ADMIN_DIR_PATH . 'partials/nx-admin-preview.php';
644 }
645 //TODO: Notification Preview Not Visible for now.
646 public function preview_html( $settings, $type = 'conversion' ){
647 $data = array(
648 'comment' => array(
649 'link' => '#',
650 'post_title' => 'Hello world!',
651 'post_link' => '#',
652 'timestamp' => '1550986787',
653 'user_id' => get_current_user_id(),
654 'name' => 'John D',
655 ),
656 'conversion' => array(
657 'link' => '#',
658 'title' => 'Hello world!',
659 'timestamp' => '1550986787',
660 'user_id' => get_current_user_id(),
661 'name' => 'John D',
662 )
663 );
664
665 $unique_id = uniqid( 'notificationx-' );
666 $output = '<div id="'. esc_attr( $unique_id ) .'" class="nx-notification '. implode( ' ', NotificationX_Extension::get_classes( $settings ) ) .'">';
667 $output .= '<div '. NotificationX_Public::generate_preview_css( $settings ) .' class="notificationx-inner '. implode( ' ', NotificationX_Extension::get_classes( $settings, 'inner' ) ) .'">';
668 $output .= '<div class="notificationx-image nx-preview-image">';
669 $output .= '<img class="'. implode( ' ', NotificationX_Extension::get_classes( $settings, 'img' ) ) .'" src="'. NOTIFICATIONX_ADMIN_URL . 'assets/img/placeholder-300x300.png" alt="">';
670 $output .= '</div>';
671 $output .= '<div class="notificationx-content">';
672 if( $type === 'conversion' ) :
673 $output .= NotificationX_Template::get_template_ready( $settings->woo_template, NotificationX_Extension::newData( $data[ 'conversion' ] ), $settings );
674 endif;
675 if( $type === 'comment' ) :
676 $output .= NotificationX_Template::get_template_ready( $settings->comments_template, NotificationX_Extension::newData( $data[ 'comment' ] ), $settings );
677 endif;
678 if( $settings->close_button ) :
679 $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>';
680 endif;
681 if( is_null( NotificationX_Extension::$powered_by ) ) :
682 $output .= '<small class="nx-branding">';
683 $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>';
684 $output .= ' by <a href="'. NOTIFICATIONX_PLUGIN_URL .'?utm_source='. urlencode( home_url() ) .'&utm_medium=notificationx" target="_blank" class="nx-powered-by">NotificationX</a>';
685 $output .= '</small>';
686 endif;
687 $output .= '</div>';
688 $output .= '</div>';
689 $output .= '</div>';
690
691 return $output;
692 }
693
694 public static function get_post_meta( $post_id, $key, $single = true ) {
695 return get_post_meta( $post_id, '_nx_meta_' . $key, $single );
696 }
697 public static function update_post_meta( $post_id, $key, $value ) {
698 update_post_meta( $post_id, '_nx_meta_' . $key, $value );
699 }
700 /**
701 * Admin Init For User Interactions
702 * @return void
703 */
704 public function admin_init( $hook ){
705 /**
706 * NotificationX Admin URL
707 */
708 $current_url = admin_url('admin.php?page=nx-admin');
709 /**
710 * For Duplicate NotificationX
711 */
712 $this->duplicate_notificationx( $current_url );
713 /**
714 * For Empty Trash
715 */
716 $this->empty_trash( $current_url );
717 /**
718 * For Enable And Disable
719 */
720 $this->enable_disable( $current_url );
721 /**
722 * For Quick Builder Submit
723 */
724 $this->quick_builder_submit( $current_url );
725 }
726 /**
727 * For Empty Trash
728 * @return void
729 */
730 protected function empty_trash( $current_url = '' ) {
731 if( empty( $current_url ) ) {
732 return;
733 }
734 if( isset( $_GET['delete_all'], $_GET['page'] ) && $_GET['delete_all'] == true && $_GET['page'] == 'nx-admin' ) {
735 $notificationx = new WP_Query(array(
736 'post_type' => 'notificationx',
737 'post_status' => array('trash'),
738 'numberposts' => -1,
739 ));
740 if( $notificationx->have_posts() ) {
741 while( $notificationx->have_posts() ) : $notificationx->the_post();
742 $iddd = get_the_ID();
743 wp_delete_post( $iddd );
744 endwhile;
745 wp_safe_redirect( $current_url ); // TODO: after all remove trash redirect.
746 die;
747 }
748 }
749 }
750 /**
751 * For Enable and Disable NotificationX.
752 * @param string $current_url
753 * @return void
754 */
755 protected function enable_disable( $current_url = '' ){
756 if( empty( $current_url ) ) {
757 return;
758 }
759 // For Enable & Disable
760 if( isset( $_GET['status'], $_GET['page'] ) && $_GET['page'] == 'nx-admin' ) {
761 $post_status = self::count_posts();
762 $get_enabled_post = $post_status->enabled;
763 $get_disabled_post = $post_status->disabled;
764 $trash_notificationx = $post_status->trash;
765
766 if( ( $_GET['status'] == 'disabled' && $get_disabled_post == 0 )
767 || ( $_GET['status'] == 'trash' && $trash_notificationx == 0 )
768 || ( $_GET['status'] == 'enabled' && $get_enabled_post == 0 )
769 ) {
770 wp_safe_redirect( $current_url );
771 die;
772 }
773 }
774 }
775 /**
776 * For Duplicate NotificationX
777 * @param string $current_url
778 * @return void
779 */
780 protected function duplicate_notificationx( $current_url = '' ){
781 if( empty( $current_url ) ) {
782 return;
783 }
784 // Duplicating NotificationX
785 if( isset( $_GET['action'], $_GET['page'], $_GET['post'], $_GET['nx_duplicate_nonce'] )
786 && $_GET['action'] === 'nxduplicate' && $_GET['page'] === 'nx-admin' ) {
787 if( wp_verify_nonce( $_GET['nx_duplicate_nonce'], 'nx_duplicate_nonce' ) ) {
788 $nx_post_id = intval( $_GET['post'] );
789 $get_post = get_post( $nx_post_id );
790 $post_data = json_decode( json_encode( $get_post ), true );
791 unset( $post_data['ID'] );
792 $post_data['post_title'] = $post_data['post_title'] . ' - Copy';
793 $duplicate_post_id = wp_insert_post( $post_data );
794 $duplicate_post_id = intval( $duplicate_post_id );
795 $get_post_meta = get_metadata( 'post', $nx_post_id );
796 if( ! empty( $get_post_meta ) ) {
797 foreach( $get_post_meta as $key => $value ){
798 if( in_array( $key, array( '_edit_lock', '_edit_last' ) ) ) {
799 continue;
800 }
801 add_post_meta( $duplicate_post_id, $key, $value[0] );
802 }
803 }
804 wp_safe_redirect( $current_url );
805 exit;
806 }
807 }
808 }
809 /**
810 * For Quick Builder Submit
811 * @return void
812 */
813 protected function quick_builder_submit( $current_url = '' ){
814 if( empty( $current_url ) ) {
815 return;
816 }
817 if( isset( $_POST[ 'nx_builder_add_submit' ], $_POST['is_quick_builder'] ) && $_POST['is_quick_builder'] ) :
818 $flag = true;
819 if ( ! isset( $_POST[$this->metabox_id . '_nonce'] ) || ! wp_verify_nonce( $_POST[$this->metabox_id . '_nonce'], $this->metabox_id ) ) {
820 $flag = false;
821 return;
822 }
823
824 if( $flag ) {
825 if( $_POST['nx_meta_display_type'] == 'press_bar' ) {
826 $title = __('NotificationX - Notification Bar', 'notificationx');
827 } elseif( $_POST['nx_meta_display_type'] == 'comments' ) {
828 $title = __('NotificationX - WP Comments', 'notificationx');
829 } elseif( $_POST['nx_meta_display_type'] == 'conversions' ) {
830 $conversions = NotificationX_Helper::conversion_from();
831 $title = 'NotificationX - ' . $conversions[$_POST['nx_meta_conversion_from']];
832 } else {
833 $title_temp = NotificationX_Helper::notification_types( $_POST['nx_meta_display_type'] );
834 $title = 'NotificationX - ' . $title_temp;
835 }
836 $_POST['post_type'] = 'notificationx';
837 $postdata = array(
838 'post_type' => 'notificationx',
839 'post_title' => $title . ' - ' . date( get_option( 'date_format' ), current_time( 'timestamp' ) ),
840 'post_status' => 'publish',
841 'post_author' => get_current_user_id(),
842 );
843 $p_id = null;
844 $p_id = wp_insert_post($postdata);
845 if( ( $p_id || ! is_wp_error( $p_id ) ) && ! is_null( $p_id ) ) {
846 do_action( 'nx_before_builder_submit', $_POST );
847 // saving builder meta data with post
848 NotificationX_MetaBox::save_data( $this->builder_data( $_POST ), $p_id );
849 /**
850 * Safely Redirect to NotificationX Page
851 */
852 wp_safe_redirect( $current_url );
853 exit;
854 }
855 }
856 endif;
857 }
858 }
859