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

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