PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.0.2.5
Adminify – White Label, Admin Menu Editor, Login Customizer v4.0.2.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 / Pro_Upgrade.php

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

610 lines 16.1 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;
4
5 use WPAdminify\Inc\Classes\Helper;
6 use WPAdminify\Inc\Classes\Notifications\Base\Date;
7
8
9 // No, Direct access Sir !!!
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 /**
15 * Upgrade to Pro Class
16 *
17 * Jewel Theme <support@jeweltheme.com>
18 */
19 class Pro_Upgrade
20 {
21
22 use Date;
23
24 public $slug;
25
26 protected $data = array();
27
28 protected $modes = array(
29 'development' => array(
30 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q',
31 'tab_id' => 0,
32 ),
33 'production' => array(
34 'sheet_id' => '1VLpfKspHHNM6JIFOQtohqDRyHR85J3KR5RLF4jqlz0Q',
35 'tab_id' => 0,
36 ),
37 );
38
39 /**
40 * Construct method
41 */
42 public function __construct()
43 {
44 $this->slug = Helper::jltwp_adminify_slug_cleanup();
45
46 $this->maybe_sync_remote_data();
47 $this->register_sync_hook();
48 $this->set_data();
49
50 add_action('admin_footer', array($this, 'display_popup'));
51
52 add_action('wp_dashboard_setup', array($this, 'dashboard_widget'));
53 add_action('wp_network_dashboard_setup', array($this, 'dashboard_widget'));
54 }
55
56 /**
57 * Register Dashboard widget
58 *
59 * @return void
60 * @author Jewel Theme <support@jeweltheme.com>
61 */
62 public function dashboard_widget()
63 {
64 wp_add_dashboard_widget(
65 'jltwp_adminify_dashboard_widget', // Widget slug.
66 esc_html__('WP Adminify News & Updates', 'adminify'), // Title.
67 array($this, 'dashboard_widget_render') // Display function.
68 );
69
70 // Globalize the metaboxes array, this holds all the widgets for wp-admin.
71 global $wp_meta_boxes;
72
73 // Get the regular dashboard widgets array
74 // (which already has our new widget but appended at the end).
75
76 if (is_network_admin()) {
77 $default_dashboard = $wp_meta_boxes['dashboard-network']['normal']['core'];
78 } else {
79 $default_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
80 }
81
82 // Backup and delete our new dashboard widget from the end of the array.
83 $example_widget_backup = array('jltwp_adminify_dashboard_widget' => $default_dashboard['jltwp_adminify_dashboard_widget']);
84 unset($default_dashboard['jltwp_adminify_dashboard_widget']);
85
86 // Merge the two arrays together so our widget is at the beginning.
87 $sorted_dashboard = array_merge($example_widget_backup, $default_dashboard);
88
89 // Save the sorted array back into the original metaboxes .
90 if (is_network_admin()) {
91 $wp_meta_boxes['dashboard-network']['normal']['core'] = $sorted_dashboard;
92 } else {
93 $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
94 }
95 }
96
97 /**
98 * Render dashboard widget
99 *
100 * @author Jewel Theme <support@jeweltheme.com>
101 */
102 public function dashboard_widget_render()
103 {
104 include_once ABSPATH . WPINC . '/feed.php';
105
106 $feed_url = 'https://jeweltheme.com/feed.xml';
107
108 // Get a SimplePie feed object from the specified feed source .
109 $rss = fetch_feed($feed_url);
110 $maxitems = 0;
111
112 if (!is_wp_error($rss)) { // Checks that the object is created correctly .
113 // Figure out how many total items there are, and choose a limit .
114 $maxitems = $rss->get_item_quantity(5);
115
116 // Build an array of all the items, starting with element 0 (first element).
117 $rss_items = $rss->get_items(0, $maxitems);
118
119 // Get RSS title .
120 $rss_title = '<a href="' . $rss->get_permalink() . '" target="_blank">' . strtoupper($rss->get_title()) . '</a>';
121 }
122
123 // Display the container .
124 echo '<div class="wp-adminify-rss-widget">';
125
126 if (wp_validate_boolean($this->get_content('is_campaign'))) { ?>
127
128 <div class="wp-adminify-dashboard-promo" style="--wp-adminify-popup-color: <?php echo esc_attr($this->get_content('btn_color')); ?>;">
129 <a target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>">
130 <img src="<?php echo esc_url($this->get_content('image_url')); ?>" alt="WP Adminify Promo Image" style="width: 100%; height: auto;">
131 </a>
132
133 <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>">
134 <?php
135 if (jltwp_adminify()->can_use_premium_code()) {
136 echo esc_html__('Upgrade Now', 'adminify');
137 } else {
138 echo esc_html($this->get_content('button_text'));
139 } ?>
140 </a>
141 </div>
142
143 <?php
144 }
145
146 // Starts items listing within <ul> tag
147 // Check items .
148 if (!empty($maxitems)) {
149 echo '<ul>';
150 // Loop through each feed item and display each item as a hyperlink.
151 foreach ($rss_items as $item) {
152 // Uncomment line below to display non human date
153 // $item_date = $item->get_date( get_option('date_format').' @ '.get_option('time_format') ); .
154
155 // Get human date (comment if you want to use non human date) .
156 // $item_date = human_time_diff( $item->get_date( 'U' ), current_time( 'timestamp' ) ) . ' ' . __( 'ago', 'adminify' );
157
158 // Start displaying item content within a <li> tag .
159 echo '<li>';
160 // create item link .
161 echo '<a href="' . esc_url($item->get_permalink()) . '" title="' . esc_attr($item->get_title()) . '" target="_blank">';
162 // Get item title .
163 echo esc_html($item->get_title());
164 echo '</a>';
165 // Display date .
166 // echo ' <span class="rss-date">' . esc_html( $item_date ) . '</span><br />';
167 // Get item content .
168 $content = $item->get_content();
169 // Shorten content .
170 $content = wp_html_excerpt($content, 120) . ' ';
171 // Display content .
172 echo esc_html($content);
173 // End <li> tag .
174 echo '</li>';
175 }
176 echo '</ul>';
177 // End <ul> tag .
178 }
179 ?>
180
181 <div class="wp-adminify-dashboard_footer">
182 <ul>
183 <li class="wp-adminify-overview__blog">
184 <a href="https://wpadminify.com/blog" target="_blank">
185 Blog
186 <span class="screen-reader-text">
187 <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
188 </span>
189 <span aria-hidden="true" class="dashicons dashicons-external"></span>
190 </a>
191 </li>
192 <li class="wp-adminify-overview__help">
193 <a href="https://wpadminify.com/docs" target="_blank">
194 Help
195 <span class="screen-reader-text">
196 <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
197 </span>
198 <span aria-hidden="true" class="dashicons dashicons-external"></span>
199 </a>
200 </li>
201 <li class="wp-adminify-overview__upgrade">
202 <a href="https://wpadminify.com/pricing" target="_blank">
203 Upgrade
204 <span class="screen-reader-text">
205 <?php echo esc_html__('(opens in a new window)', 'adminify'); ?>
206 </span>
207 <span aria-hidden="true" class="dashicons dashicons-external"></span>
208 </a>
209 </li>
210
211 </ul>
212 </div>
213 <style>
214 /* News Dashboard Widget */
215 .wp-adminify-rss-widget .hndle.ui-sortable-handle img {
216 margin: -5px 10px -5px 0;
217 }
218
219 .wp-adminify-rss-widget .wp-adminify-dashboard_footer {
220 margin: 0 -12px -12px;
221 padding: 0 12px;
222 border-top: 1px solid #eee;
223 }
224
225 .wp-adminify-rss-widget .wp-adminify-dashboard_footer ul {
226 display: flex;
227 list-style: none;
228 }
229
230 .wp-adminify-rss-widget .wp-adminify-dashboard_footer ul li:first-child {
231 padding-left: 0;
232 border: none;
233 }
234
235 .wp-adminify-rss-widget .wp-adminify-dashboard_footer li {
236 padding: 0 10px;
237 margin: 0;
238 border-left: 1px solid #ddd;
239 }
240
241 .wp-adminify-rss-widget .wp-adminify-overview__go-pro a {
242 color: #FCB92C;
243 font-weight: 500;
244 }
245 </style>
246
247 <?php
248 echo '</div>';
249 }
250
251
252 /**
253 * Set merged data
254 *
255 * @return void
256 * @author Jewel Theme <support@jeweltheme.com>
257 */
258 public function set_data()
259 {
260 $this->data = Helper::get_merged_data(self::get_data());
261 }
262
263 /**
264 * Get Sheet data
265 *
266 * @author Jewel Theme <support@jeweltheme.com>
267 */
268 public static function get_data()
269 {
270 return get_option('jltwp_adminify_sheet_promo_data');
271 }
272
273 /**
274 * Get Contents
275 *
276 * @param [type] $key .
277 *
278 * @author Jewel Theme <support@jeweltheme.com>
279 */
280 public function get_content($key)
281 {
282 return $this->data[$key];
283 }
284
285 /**
286 * Get Option has data
287 *
288 * @author Jewel Theme <support@jeweltheme.com>
289 */
290 public function get_data_hash()
291 {
292 return get_option('jltwp_adminify_sheet_promo_data_hash');
293 }
294
295 /**
296 * Sync to remote data
297 *
298 * @author Jewel Theme <support@jeweltheme.com>
299 */
300 public function maybe_sync_remote_data()
301 {
302 $data = self::get_data();
303
304 if (empty($data)) {
305 $this->sheet_data_remote_sync();
306 }
307 }
308
309 /**
310 * Register Sync hook
311 *
312 * @return void
313 * @author Jewel Theme <support@jeweltheme.com>
314 */
315 public function register_sync_hook()
316 {
317 $hook_action = 'jltwp_adminify_sheet_promo_data_remote_sync';
318 add_action($hook_action, array($this, 'sheet_data_remote_sync'));
319
320 if (!wp_next_scheduled($hook_action)) {
321 wp_schedule_event(time(), 'daily', $hook_action);
322 }
323
324 register_deactivation_hook(WP_ADMINIFY_FILE, array($this, 'clear_register_sync_hook'));
325 }
326
327 /**
328 * Clear register sync hook
329 *
330 * @return void
331 * @author Jewel Theme <support@jeweltheme.com>
332 */
333 public function clear_register_sync_hook()
334 {
335 wp_clear_scheduled_hook('jltwp_adminify_sheet_promo_data_remote_sync');
336 }
337
338 /**
339 * Data sync with remote
340 *
341 * @return void
342 * @author Jewel Theme <support@jeweltheme.com>
343 */
344 public function sheet_data_remote_sync()
345 {
346 $data = self::get_data();
347 $force = false;
348
349 if (empty($data)) {
350 $force = true;
351 }
352
353 $sheet_hash_data = $this->get_data_hash();
354 $remote_data = $this->get_sheet_promo_remote_data();
355 $sheet_data_hash = base64_encode(json_encode($remote_data));
356
357 if ($force || $sheet_hash_data !== $sheet_data_hash) {
358 update_option('jltwp_adminify_sheet_promo_data', $remote_data);
359 update_option('jltwp_adminify_sheet_promo_data_hash', $sheet_data_hash);
360 do_action('jltwp_adminify_sheet_promo_data_reset');
361 }
362 }
363
364 /**
365 * Get Environment mode
366 *
367 * @author Jewel Theme <support@jeweltheme.com>
368 */
369 public function get_mode()
370 {
371 return defined('WP_DEBUG') && WP_DEBUG ? 'development' : 'production';
372 }
373
374 /**
375 * Get Sheet URL
376 *
377 * @author Jewel Theme <support@jeweltheme.com>
378 */
379 public function get_sheet_url()
380 {
381 $sheet_id = $this->modes[$this->get_mode()]['sheet_id'];
382 $tab_id = $this->modes[$this->get_mode()]['tab_id'];
383
384 return "https://docs.google.com/spreadsheets/export?format=csv&id={$sheet_id}&gid={$tab_id}";
385 }
386
387 /**
388 * Promotional remote data
389 *
390 * @author Jewel Theme <support@jeweltheme.com>
391 */
392 public function get_sheet_promo_remote_data()
393 {
394 $transient_key = $this->slug . '_sheet_promo_data';
395
396 $data = get_transient($transient_key);
397 if ($data !== false) return $data;
398
399 $url = $this->get_sheet_url();
400
401 $response = wp_remote_get($url);
402
403 if (is_wp_error($response)) {
404 return false;
405 }
406
407 $response = wp_remote_retrieve_body($response);
408
409 if (!$response) {
410 return false;
411 }
412
413 $data = array_map('str_getcsv', explode("\n", $response));
414
415 $header = array_shift($data);
416
417 $data = array_map(function (array $row) use ($header) {
418 return array_combine($header, $row);
419 }, $data);
420
421 // filter plugin is not empty .
422 $data = array_filter($data, function ($row) {
423 return !empty($row['name']);
424 });
425
426 $plugin_slug = Helper::jltwp_adminify_slug_cleanup();
427 $data = wp_list_filter($data, array('product_slug' => $plugin_slug));
428
429 if (!empty($data)) {
430 $data = array_values($data)[0];
431 }
432
433 set_transient($transient_key, $data, HOUR_IN_SECONDS);
434
435 return $data;
436 }
437
438 /**
439 * Display popup contents
440 *
441 * @author Jewel Theme <support@jeweltheme.com>
442 */
443 public function display_popup()
444 {
445 $image_url = $this->get_content('image_url');
446 ?>
447
448 <div class="wp-adminify-popup wp-adminify-upgrade-popup" id="wp-adminify-popup" data-plugin="<?php echo esc_attr($this->slug); ?>" tabindex="1" style="display: none;">
449
450 <div class="wp-adminify-popup-overlay"></div>
451
452 <div class="wp-adminify-popup-modal" style="background-image: url('<?php echo esc_url($image_url); ?>'); --wp-adminify-popup-color: <?php echo esc_attr($this->get_content('btn_color')); ?>;">
453
454 <!-- close -->
455 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
456
457 <!-- content section -->
458 <div class="wp-adminify-popup-modal-footer">
459 <!-- countdown -->
460 <div class="wp-adminify-popup-countdown" style="display: none;">
461
462 <?php if (!empty($this->get_content('notice'))) { ?>
463 <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;"><?php echo esc_html__('Notice:', 'adminify'); ?> <?php echo $this->get_content('notice'); ?></span>
464 <?php } ?>
465
466 <span class="wp-adminify-popup-countdown-text"><?php echo esc_html__('Deal Ends In', 'adminify'); ?></span>
467 <div class="wp-adminify-popup-countdown-time">
468 <div>
469 <span data-counter="days">00</span>
470 <span><?php echo esc_html__('Days', 'adminify'); ?></span>
471 </div>
472 <span>:</span>
473 <div>
474 <span data-counter="hours">00</span>
475 <span><?php echo esc_html__('Hours', 'adminify'); ?></span>
476 </div>
477 <span>:</span>
478 <div>
479 <span data-counter="minutes">00</span>
480 <span><?php echo esc_html__('Minutes', 'adminify'); ?></span>
481 </div>
482 <span>:</span>
483 <div>
484 <span data-counter="seconds">00</span>
485 <span><?php echo esc_html__('Seconds', 'adminify'); ?></span>
486 </div>
487 </div>
488 </div>
489
490 <!-- button -->
491 <a class="wp-adminify-popup-button" target="_blank" href="<?php echo esc_url($this->get_content('button_url')); ?>"><?php
492 if (jltwp_adminify()->can_use_premium_code()) {
493 echo esc_html__('Upgrade Now', 'adminify');
494 } else {
495 echo esc_html($this->get_content('button_text'));
496 } ?></a>
497 </div>
498 </div>
499 </div>
500
501 <script>
502 var $container = jQuery('#wp-adminify-popup'),
503 plugin_data = <?php echo json_encode($this->get_sheet_promo_remote_data(), true); ?>,
504 events = {}; //Events
505
506 // Update Counter
507 function updateCounter(seconds) {
508 const $counter = $container.find(".wp-adminify-popup-countdown-time");
509 const $days = $counter.find("[data-counter='days']");
510 const $hours = $counter.find("[data-counter='hours']");
511 const $minutes = $counter.find("[data-counter='minutes']");
512 const $seconds = $counter.find("[data-counter='seconds']");
513 const days = Math.floor(seconds / (3600 * 24));
514 seconds -= days * 3600 * 24;
515 const hrs = Math.floor(seconds / 3600);
516 seconds -= hrs * 3600;
517 const mnts = Math.floor(seconds / 60);
518 seconds -= mnts * 60;
519
520 $days.text(days);
521 $hours.text(hrs);
522 $minutes.text(mnts);
523 $seconds.text(seconds);
524 }
525
526 // Trigger Event
527 function trigger(event, args = []) {
528 if (typeof(events[event]) !== 'undefined') {
529 events[event].forEach(callback => {
530 callback.apply(this, args);
531 });
532 }
533 }
534
535 // initCounter
536 function initCounter(last_date) {
537 $container.find(".wp-adminify-popup-countdown-time").show();
538
539 const countdown = () => {
540
541 // system time
542 const now = new Date().getTime();
543
544 // set end time to 11:59:59 PM
545 const endDate = new Date(last_date);
546 endDate.setHours(23);
547 endDate.setMinutes(59);
548 endDate.setSeconds(59);
549
550 const seconds = Math.floor((endDate.getTime() - now) / 1000);
551
552 if (seconds < 0) {
553 return false;
554 }
555
556 updateCounter(seconds);
557
558 return true;
559 }
560
561 let result = countdown();
562
563
564 if (result) {
565 trigger("countdownStart", [plugin_data]);
566 $container.find(".wp-adminify-popup-countdown").show(0);
567 } else {
568 trigger("countdownFinish", [plugin_data]);
569 $container.find(".wp-adminify-popup-countdown").hide(0);
570 }
571
572 // update counter every 1 second
573 const counter = setInterval(() => {
574
575 const result = countdown();
576
577 if (!result) {
578 clearInterval(counter);
579 trigger("counter_end", [plugin_data]);
580 $container.find(".wp-adminify-popup-countdown").hide(0);
581 }
582
583 }, 1000);
584 }
585
586 initCounter('<?php echo esc_attr($this->counter_date()); ?>');
587 </script>
588
589 <?php
590 }
591
592 /**
593 * Counter Date
594 *
595 * @author Jewel Theme <support@jeweltheme.com>
596 */
597 public function counter_date()
598 {
599 $endDate = $this->get_content('end_date');
600
601 $is_active = $this->date_is_current_or_next($endDate);
602
603 if ($is_active) {
604 return $endDate;
605 }
606
607 return $this->date_increment($this->current_time(), 3);
608 }
609 }
610