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

603 lines 18.3 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( 'str_getcsv', explode( "\n", $response ) );
379 $header = array_shift( $data );
380 $data = array_map( function ( array $row ) use($header) {
381 return array_combine( $header, $row );
382 }, $data );
383 // filter plugin is not empty .
384 $data = array_filter( $data, function ( $row ) {
385 return !empty( $row['name'] );
386 } );
387 $plugin_slug = Helper::jltwp_adminify_slug_cleanup();
388 $data = wp_list_filter( $data, array(
389 'product_slug' => $plugin_slug,
390 ) );
391 if ( !empty( $data ) ) {
392 $data = array_values( $data )[0];
393 }
394 set_transient( $transient_key, $data, HOUR_IN_SECONDS );
395 return $data;
396 }
397
398 /**
399 * Display popup contents
400 *
401 * @author Jewel Theme <support@jeweltheme.com>
402 */
403 public function display_popup() {
404 if ( 'FALSE' === $this->get_content( 'is_campaign' ) ) {
405 $image_url = WP_ADMINIFY_ASSETS_IMAGE . 'promo-image.png';
406 $notice = 'Use "SPECIAL40" to Get Flat 40% OFF';
407 $btn_url = 'https://wpadminify.com/pricing/';
408 $btn_text = 'GET THE DEAL';
409 } else {
410 $image_url = $this->get_content( 'image_url' );
411 $notice = $this->get_content( 'notice' );
412 $btn_url = $this->get_content( 'button_url' );
413 $btn_text = $this->get_content( 'button_text' );
414 }
415 ?>
416
417 <div class="wp-adminify-popup wp-adminify-upgrade-popup" id="wp-adminify-popup" data-plugin="<?php
418 echo esc_attr( $this->slug );
419 ?>" tabindex="1" style="display: none;">
420
421 <div class="wp-adminify-popup-overlay"></div>
422
423 <div class="wp-adminify-popup-modal" style="background-image: url('<?php
424 echo esc_url( $image_url );
425 ?>'); --wp-adminify-popup-color: <?php
426 echo esc_attr( $this->get_content( 'btn_color' ) );
427 ?>;">
428
429 <!-- close -->
430 <div class="wp-adminify-popup-modal-close popup-dismiss">×</div>
431
432 <!-- content section -->
433 <div class="wp-adminify-popup-modal-footer">
434 <!-- countdown -->
435 <div class="wp-adminify-popup-countdown" style="display: none;">
436
437 <?php
438 if ( !empty( $notice ) ) {
439 ?>
440 <span data-counter="notice" style="color:#F4B740; font-size:14px; padding-bottom:20px; font-style:italic;"><?php
441 echo esc_html__( 'Notice:', 'adminify' );
442 ?> <?php
443 echo $notice;
444 ?></span>
445 <?php
446 }
447 ?>
448
449 <span class="wp-adminify-popup-countdown-text"><?php
450 echo esc_html__( 'Deal Ends In', 'adminify' );
451 ?></span>
452 <div class="wp-adminify-popup-countdown-time">
453 <div>
454 <span data-counter="days">00</span>
455 <span><?php
456 echo esc_html__( 'Days', 'adminify' );
457 ?></span>
458 </div>
459 <span>:</span>
460 <div>
461 <span data-counter="hours">00</span>
462 <span><?php
463 echo esc_html__( 'Hours', 'adminify' );
464 ?></span>
465 </div>
466 <span>:</span>
467 <div>
468 <span data-counter="minutes">00</span>
469 <span><?php
470 echo esc_html__( 'Minutes', 'adminify' );
471 ?></span>
472 </div>
473 <span>:</span>
474 <div>
475 <span data-counter="seconds">00</span>
476 <span><?php
477 echo esc_html__( 'Seconds', 'adminify' );
478 ?></span>
479 </div>
480 </div>
481 </div>
482
483 <!-- button -->
484 <a class="wp-adminify-popup-button" target="_blank" href="<?php
485 echo esc_url( $btn_url );
486 ?>"><?php
487 echo esc_html( $btn_text );
488 ?></a>
489 </div>
490 </div>
491 </div>
492
493 <script>
494 var $container = jQuery('#wp-adminify-popup'),
495 plugin_data = <?php
496 echo json_encode( $this->get_sheet_promo_remote_data(), true );
497 ?>,
498 events = {}; //Events
499
500 // Update Counter
501 function updateCounter(seconds) {
502 const $counter = $container.find(".wp-adminify-popup-countdown-time");
503 const $days = $counter.find("[data-counter='days']");
504 const $hours = $counter.find("[data-counter='hours']");
505 const $minutes = $counter.find("[data-counter='minutes']");
506 const $seconds = $counter.find("[data-counter='seconds']");
507 const days = Math.floor(seconds / (3600 * 24));
508 seconds -= days * 3600 * 24;
509 const hrs = Math.floor(seconds / 3600);
510 seconds -= hrs * 3600;
511 const mnts = Math.floor(seconds / 60);
512 seconds -= mnts * 60;
513
514 $days.text(days);
515 $hours.text(hrs);
516 $minutes.text(mnts);
517 $seconds.text(seconds);
518 }
519
520 // Trigger Event
521 function trigger(event, args = []) {
522 if (typeof(events[event]) !== 'undefined') {
523 events[event].forEach(callback => {
524 callback.apply(this, args);
525 });
526 }
527 }
528
529 // initCounter
530 function initCounter(last_date) {
531 $container.find(".wp-adminify-popup-countdown-time").show();
532
533 const countdown = () => {
534
535 // system time
536 const now = new Date().getTime();
537
538 // set end time to 11:59:59 PM
539 const endDate = new Date(last_date);
540 endDate.setHours(23);
541 endDate.setMinutes(59);
542 endDate.setSeconds(59);
543
544 const seconds = Math.floor((endDate.getTime() - now) / 1000);
545
546 if (seconds < 0) {
547 return false;
548 }
549
550 updateCounter(seconds);
551
552 return true;
553 }
554
555 let result = countdown();
556
557
558 if (result) {
559 trigger("countdownStart", [plugin_data]);
560 $container.find(".wp-adminify-popup-countdown").show(0);
561 } else {
562 trigger("countdownFinish", [plugin_data]);
563 $container.find(".wp-adminify-popup-countdown").hide(0);
564 }
565
566 // update counter every 1 second
567 const counter = setInterval(() => {
568
569 const result = countdown();
570
571 if (!result) {
572 clearInterval(counter);
573 trigger("counter_end", [plugin_data]);
574 $container.find(".wp-adminify-popup-countdown").hide(0);
575 }
576
577 }, 1000);
578 }
579
580 initCounter('<?php
581 echo esc_attr( $this->counter_date() );
582 ?>');
583 </script>
584
585 <?php
586 }
587
588 /**
589 * Counter Date
590 *
591 * @author Jewel Theme <support@jeweltheme.com>
592 */
593 public function counter_date() {
594 $endDate = $this->get_content( 'end_date' );
595 $is_active = $this->date_is_current_or_next( $endDate );
596 if ( $is_active ) {
597 return $endDate;
598 }
599 return $this->date_increment( $this->current_time(), 3 );
600 }
601
602 }
603