PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 3.2.4.5
Adminify – White Label, Admin Menu Editor, Login Customizer v3.2.4.5
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.2.4.5, at Inc/Classes/Notifications/Notifications.php

267 lines 7.0 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 $image_url = $popup->get_content('image_url');
175 $notice = !empty($popup->get_content('notice')) ? $popup->get_content('notice') : '';
176 ?>
177
178 <div class="wp-adminify-popup" id="wp-adminify-popup" data-plugin="<?php echo esc_attr($this->slug); ?>" tabindex="1">
179
180 <div class="wp-adminify-popup-overlay"></div>
181
182 <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')); ?>;">
183
184 <!-- close -->
185 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
186
187 <!-- content section -->
188 <div class="wp-adminify-popup-modal-footer">
189
190 <!-- countdown -->
191 <div class="wp-adminify-popup-countdown" style="display: none;">
192
193 <?php if ($notice) { ?>
194 <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;">
195 <?php echo esc_html__('Notice:', 'adminify'); ?> <?php echo esc_html($notice); ?>
196 </span>
197 <?php } ?>
198
199 <span class="wp-adminify-popup-countdown-text"><?php echo esc_html__('Deal Ends In', 'adminify'); ?></span>
200 <div class="wp-adminify-popup-countdown-time">
201 <div>
202 <span data-counter="days">00</span>
203 <span><?php echo esc_html__('Days', 'adminify'); ?></span>
204 </div>
205 <span>:</span>
206 <div>
207 <span data-counter="hours">00</span>
208 <span><?php echo esc_html__('Hours', 'adminify'); ?></span>
209 </div>
210 <span>:</span>
211 <div>
212 <span data-counter="minutes">00</span>
213 <span><?php echo esc_html__('Minutes', 'adminify'); ?></span>
214 </div>
215 <span>:</span>
216 <div>
217 <span data-counter="seconds">00</span>
218 <span><?php echo esc_html__('Seconds', 'adminify'); ?></span>
219 </div>
220 </div>
221 </div>
222
223 <!-- button -->
224 <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url($popup->get_content('button_url')); ?>">
225 <?php
226 if (jltwp_adminify()->can_use_premium_code()) {
227 echo esc_html__('Upgrade Now', 'adminify');
228 } else {
229 echo esc_html($popup->get_content('button_text'));
230 }
231 ?>
232 </a>
233 </div>
234 </div>
235 </div>
236
237 <script>
238 function jltwp_adminify_popup_action(evt, $this, $action_type) {
239
240 evt.preventDefault();
241
242 $this.closest('.wp-adminify-popup').fadeOut(200);
243
244 jQuery.post('<?php echo esc_url(admin_url('admin-ajax.php')); ?>', {
245 action: 'jltwp_adminify_notification_action',
246 _wpnonce: '<?php echo esc_js(wp_create_nonce('jltwp_adminify_notification_nonce')); ?>',
247 action_type: $action_type,
248 notification_type: 'popup',
249 trigger_time: '<?php echo esc_attr($trigger_time); ?>'
250 });
251 }
252
253 // Notice Dismiss
254 jQuery('body').on('click', '.wp-adminify-popup .popup-dismiss', function(evt) {
255 jltwp_adminify_popup_action(evt, jQuery(this), 'dismiss');
256 });
257
258 // Notice Disable
259 jQuery('body').on('click', '.wp-adminify-popup .popup-disable', function(evt) {
260 jltwp_adminify_popup_action(evt, jQuery(this), 'disable');
261 });
262 </script>
263
264 <?php
265 }
266 }
267