PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.1.7
Adminify – White Label, Admin Menu Editor, Login Customizer v3.1.7
4.3.1 4.3.0 4.2.26 4.2.25 4.2.24 4.2.23 4.2.22 4.2.21 4.2.20 4.2.19 4.2.18 4.2.17 4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 4.1.17 All 164 releases
adminify / Inc / Classes / Notifications / Notifications.php

Notifications.php in Adminify – White Label, Admin Menu Editor, Login Customizer 3.1.7, at Inc/Classes/Notifications/Notifications.php

241 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WPAdminify\Inc\Classes\Notifications;
3
4 use WPAdminify\Inc\Classes\Notifications\Base\Date;
5 use WPAdminify\Inc\Classes\Helper;
6
7 // No, Direct access Sir !!!
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Notification Class
14 *
15 * Jewel Theme <support@jeweltheme.com>
16 */
17 class Notifications {
18
19 use Date;
20
21 public $manager;
22
23 public $conflict_days = 5;
24
25 public $slug;
26
27 /**
28 * Construction method
29 */
30 public function __construct() {
31 $this->manager = new Manager();
32
33 $this->slug = Helper::jltwp_adminify_slug_cleanup();
34
35 add_action( 'admin_notices', array( $this, 'setup_notifications' ) );
36 add_action( 'network_admin_notices', array( $this, 'setup_notifications' ) );
37
38 add_action( 'jltwp_adminify_display_notice', array( $this, 'display_notice' ), 10, 2 );
39 add_action( 'jltwp_adminify_display_popup', array( $this, 'display_popup' ), 10, 2 );
40
41 add_action( 'wp_ajax_jltwp_adminify_notification_action', array( $this, 'notification_action' ) );
42 }
43
44 /**
45 * Notification Action
46 *
47 * @author Jewel Theme <support@jeweltheme.com>
48 */
49 public function notification_action() {
50 check_ajax_referer( 'jltwp_adminify_notification_nonce' );
51
52 $action_type = ! empty( $_REQUEST['action_type'] ) ? sanitize_key( $_REQUEST['action_type'] ) : '';
53 $notification_type = ! empty( $_REQUEST['notification_type'] ) ? sanitize_key( $_REQUEST['notification_type'] ) : '';
54 $trigger_time = ! empty( $_REQUEST['trigger_time'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['trigger_time'] ) ) : '';
55
56 $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $notification_type );
57
58 // No Executable Notifications found .
59 if ( empty( $exec_notifications ) ) {
60 die( 0 );
61 }
62
63 $count = 0;
64
65 foreach ( $exec_notifications as $index => $notification ) {
66 if ( 0 === $index ) {
67 if ( 'disable' === $action_type ) {
68 $notification->is_active = false;
69 }
70 $notification->fire( $trigger_time, $notification_type )->save();
71 } else {
72 ++$count;
73 $notification->maybe_delay( $this->date_increment( $trigger_time, $this->conflict_days * $count ) )->save();
74 }
75 }
76
77 die( 0 );
78 }
79
80
81 /**
82 * Notification Setup
83 *
84 * @param [type] $type .
85 *
86 * @author Jewel Theme <support@jeweltheme.com>
87 */
88 public function setup_notifications_by_type( $type ) {
89 // $trigger_time should be today .
90 $trigger_time = $this->current_time();
91
92 // Block if necessary .
93 $notification_last_fired = get_option( "jltwp_adminify_{$type}_last_interact" );
94
95 if ( $notification_last_fired ) {
96 $notification_enable_date = $this->date_increment( $notification_last_fired, $this->conflict_days );
97
98 if ( $this->date_is_prev( $trigger_time, $notification_enable_date ) ) {
99 return;
100 }
101 }
102
103 // Get Executable Notifications .
104 $exec_notifications = $this->manager->get_exec_notifications( $trigger_time, $type );
105
106 // No Executable Notifications found .
107 if ( empty( $exec_notifications ) ) {
108 return;
109 }
110
111 $notification = $exec_notifications[0];
112
113 do_action( "jltwp_adminify_display_{$type}", $notification, $trigger_time );
114 }
115
116 /**
117 * Notification setup
118 *
119 * @author Jewel Theme <support@jeweltheme.com>
120 */
121 public function setup_notifications() {
122 $this->setup_notifications_by_type( 'notice' );
123 $this->setup_notifications_by_type( 'popup' );
124 }
125
126
127
128 /**
129 * Display notice
130 *
131 * @param [type] $notice .
132 * @param [type] $trigger_time .
133 *
134 * @return void
135 * @author Jewel Theme <support@jeweltheme.com>
136 */
137 public function display_notice( $notice, $trigger_time ) {
138 $notice->notice_header();
139 $notice->notice_content();
140 $notice->notice_footer();
141
142 $notice->core_script( $trigger_time );
143 }
144
145 /**
146 * Display Popup
147 *
148 * @param [type] $popup .
149 * @param [type] $trigger_time .
150 *
151 * @return void
152 * @author Jewel Theme <support@jeweltheme.com>
153 */
154 public function display_popup( $popup, $trigger_time ) {
155 $image_url = $popup->get_content( 'image_url' );
156
157 ?>
158
159 <div class="wp-adminify-popup" id="wp-adminify-popup" data-plugin="<?php echo esc_attr( $this->slug ); ?>" tabindex="1">
160
161 <div class="wp-adminify-popup-overlay"></div>
162
163 <div class="wp-adminify-popup-modal" style="background-image: url('<?php echo esc_url( $image_url ); ?>'); --wp-adminify-popup-color: <?php echo esc_attr( $popup->get_content( 'btn_color' ) ); ?>;">
164
165 <!-- close -->
166 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
167
168 <!-- content section -->
169 <div class="wp-adminify-popup-modal-footer">
170
171 <!-- countdown -->
172 <div class="wp-adminify-popup-countdown" style="display: none;">
173 <span class="wp-adminify-popup-countdown-text"><?php echo esc_html__( 'Deal Ends In', 'adminify' ); ?></span>
174 <div class="wp-adminify-popup-countdown-time">
175 <div>
176 <span data-counter="days">00</span>
177 <span><?php echo esc_html__( 'Days', 'adminify' ); ?></span>
178 </div>
179 <span>:</span>
180 <div>
181 <span data-counter="hours">00</span>
182 <span><?php echo esc_html__( 'Hours', 'adminify' ); ?></span>
183 </div>
184 <span>:</span>
185 <div>
186 <span data-counter="minutes">00</span>
187 <span><?php echo esc_html__( 'Minutes', 'adminify' ); ?></span>
188 </div>
189 <span>:</span>
190 <div>
191 <span data-counter="seconds">00</span>
192 <span><?php echo esc_html__( 'Seconds', 'adminify' ); ?></span>
193 </div>
194 </div>
195 </div>
196
197 <!-- button -->
198 <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url( $popup->get_content( 'button_url' ) ); ?>">
199 <?php
200 if ( jltwp_adminify()->can_use_premium_code() ) {
201 echo esc_html__( 'Upgrade Now', 'adminify' );
202 }else{
203 echo esc_html( $popup->get_content( 'button_text' ) );
204 }
205 ?>
206 </a>
207 </div>
208 </div>
209 </div>
210
211 <script>
212 function jltwp_adminify_popup_action(evt, $this, $action_type) {
213
214 evt.preventDefault();
215
216 $this.closest('.wp-adminify-popup').fadeOut(200);
217
218 jQuery.post('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
219 action: 'jltwp_adminify_notification_action',
220 _wpnonce: '<?php echo esc_js( wp_create_nonce( 'jltwp_adminify_notification_nonce' ) ); ?>',
221 action_type: $action_type,
222 notification_type: 'popup',
223 trigger_time: '<?php echo esc_attr( $trigger_time ); ?>'
224 });
225 }
226
227 // Notice Dismiss
228 jQuery('body').on('click', '.wp-adminify-popup .popup-dismiss', function(evt) {
229 jltwp_adminify_popup_action(evt, jQuery(this), 'dismiss');
230 });
231
232 // Notice Disable
233 jQuery('body').on('click', '.wp-adminify-popup .popup-disable', function(evt) {
234 jltwp_adminify_popup_action(evt, jQuery(this), 'disable');
235 });
236 </script>
237
238 <?php
239 }
240 }
241