PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.5.4
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.5.4
4.3.2 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 All 165 releases
adminify / Inc / Classes / Notifications / Notifications.php

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

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