PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / trunk
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits vtrunk
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / classes / notifications / notifications.php

notifications.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits trunk, at inc/classes/notifications/notifications.php

280 lines 7.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Classes\Notifications;
4
5 use MasterAddons\Inc\Classes\Notifications\Base\Date;
6 use MasterAddons\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 * Constructor method
31 */
32 public function __construct()
33 {
34 $this->manager = new Manager();
35
36 $this->slug = Helper::jltma_slug_cleanup();
37
38 add_action('admin_print_scripts', array($this, 'init_notifications'), 99999999);
39
40 add_action('jltma_display_notice', array($this, 'display_notice'), 10, 2);
41 add_action('jltma_display_popup', array($this, 'display_popup'), 10, 2);
42
43 add_action('wp_ajax_jltma_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('jltma_notification_nonce');
54
55 if ( ! current_user_can( 'manage_options' ) ) {
56 wp_send_json_error( [ 'message' => __( 'Insufficient permissions', 'master-addons' ) ] );
57 }
58
59 $action_type = !empty($_REQUEST['action_type']) ? sanitize_key($_REQUEST['action_type']) : '';
60 $notification_type = !empty($_REQUEST['notification_type']) ? sanitize_key($_REQUEST['notification_type']) : '';
61 $trigger_time = !empty($_REQUEST['trigger_time']) ? sanitize_text_field(wp_unslash($_REQUEST['trigger_time'])) : '';
62
63 $exec_notifications = $this->manager->get_exec_notifications($trigger_time, $notification_type);
64
65 // No Executable Notifications found .
66 if (empty($exec_notifications)) {
67 die(0);
68 }
69
70 $count = 0;
71
72 foreach ($exec_notifications as $index => $notification) {
73 if (0 === $index) {
74 if ('disable' === $action_type) {
75 $notification->is_active = false;
76 }
77 $notification->fire($trigger_time, $notification_type)->save();
78 } else {
79 $count++;
80 $notification->maybe_delay($this->date_increment($trigger_time, $this->conflict_days * $count))->save();
81 }
82 }
83
84 die(0);
85 }
86
87
88 /**
89 * Notification Setup
90 *
91 * @param [type] $type .
92 *
93 * @author Jewel Theme <support@jeweltheme.com>
94 */
95 public function setup_notifications_by_type($type)
96 {
97 // $trigger_time should be today .
98 $trigger_time = $this->current_time();
99
100 // Block if necessary .
101 $notification_last_fired = get_option("jltma_{$type}_last_interact");
102
103 if ($notification_last_fired) {
104 $notification_enable_date = $this->date_increment($notification_last_fired, $this->conflict_days);
105
106 if ($this->date_is_prev($trigger_time, $notification_enable_date)) {
107 return;
108 }
109 }
110
111 // Get Executable Notifications .
112 $exec_notifications = $this->manager->get_exec_notifications($trigger_time, $type);
113
114 // No Executable Notifications found .
115 if (empty($exec_notifications)) {
116 return;
117 }
118
119 $notification = $exec_notifications[0];
120
121 do_action("jltma_display_{$type}", $notification, $trigger_time);
122 }
123
124 /**
125 * Notification initialization
126 *
127 * @author Jewel Theme <support@jeweltheme.com>
128 */
129 public function init_notifications()
130 {
131 add_action('admin_notices', array($this, 'setup_notifications'));
132 }
133
134 /**
135 * Notification setup
136 *
137 * @author Jewel Theme <support@jeweltheme.com>
138 */
139 public function setup_notifications()
140 {
141 $this->setup_notifications_by_type('notice');
142 $this->setup_notifications_by_type('popup');
143 }
144
145
146
147 /**
148 * Display notice
149 *
150 * @param [type] $notice .
151 * @param [type] $trigger_time .
152 *
153 * @return void
154 * @author Jewel Theme <support@jeweltheme.com>
155 */
156 public function display_notice($notice, $trigger_time)
157 {
158 $notice->notice_header();
159 $notice->notice_content();
160 $notice->notice_footer();
161
162 $notice->core_script($trigger_time);
163 }
164
165 /**
166 * Display Popup
167 *
168 * @param [type] $popup .
169 * @param [type] $trigger_time .
170 *
171 * @return void
172 * @author Jewel Theme <support@jeweltheme.com>
173 */
174 public function display_popup($popup, $trigger_time)
175 {
176 $screen = get_current_screen();
177
178 // Screens where the notification popup is allowed to show.
179 $allowed_screens = array(
180 'dashboard', // index.php
181 'toplevel_page_master-addons-settings', // admin.php?page=master-addons-settings
182 'master-addons_page_jltma-template-library', // admin.php?page=jltma-template-library
183 'master-addons_page_jltma-template-kits', // admin.php?page=jltma-template-kits
184 'master-addons_page_master-addons-recommended-plugins', // admin.php?page=master-addons-recommended-plugins
185 'master-addons_page_master-addons-settings-account', // admin.php?page=master-addons-settings-account
186 'edit-master_template', // edit.php?post_type=master_template
187 'edit-jltma_popup', // edit.php?post_type=jltma_popup
188 );
189
190 if ( ! $screen || ! in_array( $screen->id, $allowed_screens, true ) ) {
191 return;
192 }
193
194 $image_url = $popup->get_content('image_url');
195 $notice = !empty($popup->get_content('notice')) ? $popup->get_content('notice') : '';
196
197 ?>
198
199 <div class="jltma-popup" id="jltma-popup" data-plugin="<?php echo esc_attr($this->slug); ?>" tabindex="1">
200
201 <div class="jltma-popup-overlay"></div>
202
203 <div class="jltma-popup-modal" style="background-image: url('<?php echo esc_url($image_url); ?>'); --jltma-popup-color: <?php echo esc_attr($popup->get_content('btn_color')); ?>;">
204
205 <!-- close -->
206 <div class="jltma-popup-modal-close popup-dismiss">×</div>
207
208 <!-- content section -->
209 <div class="jltma-popup-modal-footer">
210
211 <!-- countdown -->
212 <div class="jltma-popup-countdown" style="display: none;">
213
214 <?php if ($notice) { ?>
215 <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;">
216 <?php echo esc_html__('Notice:', 'master-addons'); ?> <?php echo esc_html($notice); ?>
217 </span>
218 <?php } ?>
219
220 <span class="jltma-popup-countdown-text"><?php echo esc_html__('Deal Ends In', 'master-addons'); ?></span>
221 <div class="jltma-popup-countdown-time">
222 <div>
223 <span data-counter="days">00</span>
224 <span><?php echo esc_html__('Days', 'master-addons'); ?></span>
225 </div>
226 <span>:</span>
227 <div>
228 <span data-counter="hours">00</span>
229 <span><?php echo esc_html__('Hours', 'master-addons'); ?></span>
230 </div>
231 <span>:</span>
232 <div>
233 <span data-counter="minutes">00</span>
234 <span><?php echo esc_html__('Minutes', 'master-addons'); ?></span>
235 </div>
236 <span>:</span>
237 <div>
238 <span data-counter="seconds">00</span>
239 <span><?php echo esc_html__('Seconds', 'master-addons'); ?></span>
240 </div>
241 </div>
242 </div>
243
244 <!-- button -->
245 <a class="jltma-popup-button" target="_blank" href="<?php echo esc_url($popup->get_content('button_url')); ?>"><?php echo esc_html($popup->get_content('button_text')); ?></a>
246 </div>
247 </div>
248 </div>
249
250 <script>
251 function jltma_popup_action(evt, $this, $action_type) {
252
253 evt.preventDefault();
254
255 $this.closest('.jltma-popup').fadeOut(200);
256
257 jQuery.post('<?php echo esc_url(admin_url('admin-ajax.php')); ?>', {
258 action: 'jltma_notification_action',
259 _wpnonce: '<?php echo esc_js(wp_create_nonce('jltma_notification_nonce')); ?>',
260 action_type: $action_type,
261 notification_type: 'popup',
262 trigger_time: '<?php echo esc_attr($trigger_time); ?>'
263 });
264 }
265
266 // Notice Dismiss
267 jQuery('body').on('click', '.jltma-popup .popup-dismiss', function(evt) {
268 jltma_popup_action(evt, jQuery(this), 'dismiss');
269 });
270
271 // Notice Disable
272 jQuery('body').on('click', '.jltma-popup .popup-disable', function(evt) {
273 jltma_popup_action(evt, jQuery(this), 'disable');
274 });
275 </script>
276
277 <?php
278 }
279 }
280