PluginProbe
Adminify – White Label, Admin Menu Editor, Login Customizer / 4.1.3
Adminify – White Label, Admin Menu Editor, Login Customizer v4.1.3
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.1.3, at Inc/Classes/Pro_Upgrade.php

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