PluginProbe
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress / 8.5.79
WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress v8.5.79
9.1.3 9.1.2 9.1.1 9.1.0 9.0.3 9.0.2 9.0.1 9.0.0 8.5.79 8.5.78 8.5.77 8.5.76 8.5.75 8.5.74 8.5.73 8.5.72 8.5.71 8.5.70 8.5.69 8.5.68 8.5.35 8.5.36 8.5.37 8.5.38 8.5.39 All 222 releases
wpvr / admin / classes / class-wpvr-occasion-banner.php

class-wpvr-occasion-banner.php in WPVR – 360 Panorama viewer and Virtual Tour Builder for WordPress 8.5.79, at admin/classes/class-wpvr-occasion-banner.php

619 lines 23.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * SpecialOccasionBanner Class
5 *
6 * This class is responsible for displaying a special occasion banner in the WordPress admin.
7 *
8 */
9 class WPVR_Special_Occasion_Banner
10 {
11
12 /**
13 * The occasion identifier.
14 *
15 * @var string
16 */
17 private $occasion;
18
19 /**
20 * The start date and time for displaying the banner.
21 *
22 * @var int
23 */
24 private $start_date;
25
26 /**
27 * The end date and time for displaying the banner.
28 *
29 * @var int
30 */
31 private $end_date;
32
33 /**
34 * Constructor method for SpecialOccasionBanner class.
35 *
36 * @param string $occasion The occasion identifier.
37 * @param string $start_date The start date and time for displaying the banner.
38 * @param string $end_date The end date and time for displaying the banner.
39 */
40 public function __construct($occasion, $start_date, $end_date)
41 {
42 $this->occasion = "rex_wpvr_{$occasion}";
43 $this->start_date = strtotime($start_date);
44 $this->end_date = strtotime($end_date);
45
46 if (!defined('WPVR_PRO_VERSION') && 'hidden' !== get_option( $this->occasion, '') ) {
47 // Hook into the admin_notices action to display the banner
48 add_action('admin_notices', array($this, 'display_banner'));
49
50 // Add styles
51 add_action('admin_head', array($this, 'add_styles'));
52
53 add_action( 'wp_ajax_rex_wpvr_hide_deal_notice', [ $this, 'hide_special_deal_notice' ] );
54 }
55 }
56
57 /**
58 * Calculate time remaining until Halloween
59 *
60 * @return array Time remaining in days, hours, and minutes
61 */
62 public function rex_get_halloween_countdown() {
63 $diff = $this->end_date - current_time( 'timestamp' );
64 return [
65 'days' => sprintf("%02d", floor( $diff / ( 60 * 60 * 24 ) )),
66 'hours' => sprintf("%02d", floor( ( $diff % ( 60 * 60 * 24 ) ) / ( 60 * 60 ) ) ),
67 'mins' => sprintf("%02d", floor( ( $diff % ( 60 * 60 ) ) / 60 ) ),
68 'secs' => sprintf("%02d", floor( $diff % 60 ) )
69
70 ];
71 }
72
73
74 /**
75 * Displays the special occasion banner if the current date and time are within the specified range.
76 */
77 public function display_banner()
78 {
79 $screen = get_current_screen();
80 $plugin_banner_constant = 'REX_SPECIAL_OCCASION_BANNER_SHOWN_WPVR';
81
82 $promotional_notice_pages = ['dashboard', 'plugins', 'edit-wpvr_item', 'toplevel_page_wpvr', 'wp-vr_page_wpvr-setup-wizard', 'wpvr_item', 'wp-vr_page_wpvr-addons', 'wp-vr_page_wpvr-setting'];
83 $current_date_time = current_time('timestamp');
84
85 if (!($current_date_time >= $this->start_date && $current_date_time <= $this->end_date)) {
86 return;
87 }
88
89 if (!in_array($screen->id, $promotional_notice_pages)) {
90 return;
91 }
92
93 $should_show_banner = false;
94
95 if ($screen->base === 'plugins' || $screen->base === 'dashboard') {
96 if (!defined('WPVR_SPECIAL_OCCASION_BANNER_SHOWN_GLOBAL')) {
97 $should_show_banner = true;
98 define('WPVR_SPECIAL_OCCASION_BANNER_SHOWN_GLOBAL', true);
99 }
100 } else {
101 if (!defined($plugin_banner_constant)) {
102 $should_show_banner = true;
103 define($plugin_banner_constant, true);
104 }
105 }
106
107 if ($should_show_banner) {
108 echo wp_kses_post('<input type=\"hidden\" id=\"rex_wpvr_special_occasion\" name=\"rex_wpvr_special_occasion\" value=\"'.esc_attr($this->occasion).'\">');
109 $time_remaining = $this->end_date - $current_date_time;
110 $countdown = $this->rex_get_halloween_countdown();
111 ?>
112
113 <div class="rex-feed-tb__notification wpvr-banner" id="rex_wpvr_deal_notification">
114 <div class="banner-overflow">
115 <div class="rex-notification-counter">
116 <div class="rex-notification-counter__container">
117 <div class="rex-notification-counter__content">
118
119 <figure class="rex-notification-counter__figure-logo">
120 <img src="<?php echo esc_url(WPVR_PLUGIN_DIR_URL . 'admin/icon/banner-images/4th-of-july.webp'); ?>" alt="<?php esc_attr_e('4th of july special offer logo', 'wpvr'); ?>" class="rex-notification-counter__img" >
121 </figure>
122
123 <figure class="rex-notification-counter__biggest-sale">
124 <img src="<?php echo esc_url(WPVR_PLUGIN_DIR_URL . 'admin/icon/banner-images/twenty-five-discount.webp'); ?>" alt="<?php esc_attr_e('Biggest sale of the year!', 'wpvr'); ?>" class="rex-notification-counter__img" >
125 </figure>
126
127 <figure class="rex-notification-counter__figure-percentage">
128 <img src="<?php echo esc_url(WPVR_PLUGIN_DIR_URL . 'admin/icon/banner-images/wpvr-logo.webp'); ?>" alt="<?php esc_attr_e('4th of july special discount', 'wpvr'); ?>" class="rex-notification-counter__img" >
129 </figure>
130
131 <div id="rex-halloween-countdown" class="rex-notification-counter__countdown" aria-live="polite">
132 <span class="screen-reader-text">
133 <?php esc_html_e('Offer Countdown', 'wpvr'); ?>
134 </span>
135 <ul class="rex-notification-counter__list">
136 <?php foreach (['days', 'hours', 'mins','secs'] as $unit): ?>
137 <li class="rex-notification-counter__item">
138 <span id="rex-wpvr-halloween-<?php echo esc_attr($unit); ?>" class="rex-notification-counter__time">
139 <?php echo esc_html($countdown[$unit]); ?>
140 </span>
141 <span class="rex-notification-counter__label">
142 <?php echo esc_html($unit); ?>
143 </span>
144 </li>
145 <?php endforeach; ?>
146 </ul>
147 </div>
148
149 <div class="rex-notification-counter__btn-area">
150 <a href="<?php echo esc_url( 'https://rextheme.com/wpvr/wpvr-pricing/?utm_source=website&utm_medium=plugin-ban-wpvr&utm_campaign=4thofjuly' ); ?>" class="rex-notification-counter__btn" target="_blank">
151 <span class="screen-reader-text">
152 <?php esc_html_e('Click to view 4th of july sale products', 'wpvr'); ?>
153 </span>
154 <?php esc_html_e('Get The Deal', 'wpvr'); ?>
155 </a>
156 </div>
157 </div>
158 </div>
159 </div>
160 </div>
161
162 <a class="close-promotional-banner wpvr-black-friday-close-promotional-banner rex-feed-tb__cross-top" type="button" aria-label="close banner" id="wpvr-black-friday-close-button">
163 <svg width="12" height="13" fill="none" viewBox="0 0 12 13" xmlns="http://www.w3.org/2000/svg">
164 <path stroke="#7A8B9A" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 1.97L1 11.96m0-9.99l10 9.99" />
165 </svg>
166 </a>
167 </div>
168
169 <script>
170 //rexfeed_deal_countdown_handler();
171
172 function rexfeed_deal_countdown_handler() {
173 let timeRemaining = <?php echo esc_js( $time_remaining ); ?>;
174
175 setInterval(function() {
176 const daysElement = document.getElementById('rex-wpvr-halloween-days');
177 const hoursElement = document.getElementById('rex-wpvr-halloween-hours');
178 const minutesElement = document.getElementById('rex-wpvr-halloween-mins');
179 const secondsElement = document.getElementById('rex-wpvr-halloween-secs');
180
181 timeRemaining--;
182
183 if (daysElement && hoursElement && minutesElement && secondsElement) {
184 let days = Math.floor(timeRemaining / (60 * 60 * 24)).toString().padStart(2, '0');
185 let hours = Math.floor((timeRemaining % (60 * 60 * 24)) / (60 * 60)).toString().padStart(2, '0');
186 let minutes = Math.floor((timeRemaining % (60 * 60)) / 60).toString().padStart(2, '0');
187 let seconds = (timeRemaining % 60).toString().padStart(2, '0');
188
189 daysElement.textContent = days;
190 hoursElement.textContent = hours;
191 minutesElement.textContent = minutes;
192 secondsElement.textContent = seconds;
193 }
194
195 if (timeRemaining <= 0) {
196 rexfeed_hide_deal_notice();
197 }
198 }, 1000);
199 }
200
201 document.getElementById('wpvr-black-friday-close-button').addEventListener('click', rexfeed_hide_deal_notice);
202
203 function rexfeed_hide_deal_notice() {
204 document.getElementById('rex_wpvr_deal_notification').style.display = 'none';
205
206 jQuery.ajax({
207 type: "POST",
208 url: wpvr_global_obj?.ajaxurl,
209 data: {
210 action: "rex_wpvr_hide_deal_notice",
211 nonce : wpvr_global_obj.ajax_nonce,
212 occasion: document.getElementById('rex_wpvr_special_occasion')?.value
213 },
214 });
215 }
216 </script>
217 <?php
218 }
219 }
220
221
222 /**
223 * Hides the special deal notice.
224 *
225 * This method updates the option to hide the special deal notice
226 * based on the provided payload.
227 *
228 * @return array The status of the operation.
229 */
230 public function hide_special_deal_notice() {
231 if( !current_user_can( 'manage_options' ) ){
232 wp_send_json_error( array( 'message' => 'Unauthorized user' ), 403 );
233 return;
234 }
235 $nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
236 if ( ! wp_verify_nonce( $nonce, 'wpvr' ) ) {
237 return [ 'status' => false ];
238 }
239
240 $occasion = filter_input( INPUT_POST, 'occasion', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
241 if ( $occasion ) {
242 update_option( $occasion, 'hidden' );
243
244 return [ 'status' => true ];
245 }
246
247 return [ 'status' => false ];
248 }
249
250 /**
251 * Adds internal CSS styles for the special occasion banners.
252 */
253 public function add_styles()
254 {
255 $plugin_dir_url = plugin_dir_url(__FILE__);
256 ?>
257 <style id="promotional-banner-style" type="text/css">
258 @font-face {
259 font-family: 'Inter';
260 src: url(<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'admin/fonts/campaign-font/Inter-Bold.woff2' ); ?>) format('woff2');
261 font-weight: 700;
262 font-style: normal;
263 font-display: swap;
264 }
265
266 @font-face {
267 font-family: 'Inter';
268 src: url(<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'admin/fonts/campaign-font/Inter-SemiBold.woff2' ); ?>) format('woff2');
269 font-weight: 600;
270 font-style: normal;
271 font-display: swap;
272 }
273
274 @font-face {
275 font-family: "Inter";
276 src: url(<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'admin/fonts/campaign-font/Inter-Regular.woff2' ); ?>) format('woff2');
277 font-weight: 400;
278 font-style: normal;
279 font-display: swap;
280 }
281
282 .rex-feed-tb__notification,
283 .rex-feed-tb__notification * {
284 box-sizing: border-box;
285 }
286
287 .rex-feed-tb__notification.wpvr-banner {
288 background-color: #05041E;
289 width: calc(100% - 20px);
290 margin: 50px 0 20px;
291 background-image: url(<?php echo esc_url( WPVR_PLUGIN_DIR_URL . 'admin/icon/banner-images/independence-day-bg.webp' ); ?>);
292 background-position: 24%;
293 background-repeat: no-repeat;
294 background-size: cover;
295 position: relative;
296 border: none;
297 box-shadow: none;
298 display: block;
299 max-height: 110px;
300 object-fit: cover;
301 }
302
303 .wpvr-banner .rex-notification-counter {
304 position: relative;
305 z-index: 1111;
306 }
307
308 .wpvr-banner .rex-notification-counter figure {
309 margin: 0;
310 }
311
312 .wpvr-banner .rex-notification-counter__container {
313 position: relative;
314 width: 100%;
315 max-height: 110px;
316 max-width: 1312px;
317 margin: 0 auto;
318 padding: 0px 15px;
319 }
320 .wpvr-banner .rex-notification-counter__content {
321 display: flex;
322 justify-content: space-between;
323 align-items: center;
324 gap: 20px;
325 }
326 .wpvr-banner .rex-notification-counter__biggest-sale {
327 max-width: 219px;
328 }
329 .wpvr-banner .rex-notification-counter__figure-logo {
330 max-width: 218px;
331 }
332 .wpvr-banner .rex-notification-counter__figure-percentage {
333 max-width: 108px;
334 }
335 .wpvr-banner .rex-notification-counter__img {
336 width: 100%;
337 max-width: 100%;
338 display: block;
339 }
340 .wpvr-banner .rex-notification-counter__list {
341 display: flex;
342 justify-content: center;
343 gap: 10px;
344 margin: 0;
345 padding: 0;
346 list-style: none;
347 }
348
349 @media only screen and (max-width: 991px) {
350 .wpvr-banner .rex-notification-counter__list {
351 gap: 10px;
352 }
353 }
354 @media only screen and (max-width: 767px) {
355 .wpvr-banner .rex-notification-counter__list {
356 align-items: center;
357 justify-content: center;
358 gap: 15px;
359 }
360 }
361 .wpvr-banner .rex-notification-counter__item {
362 display: flex;
363 flex-direction: column;
364 width: 49px;
365 font-family: "Inter";
366 font-size: 14px;
367 font-weight: 400;
368 line-height: 1;
369 letter-spacing: 0.75px;
370 text-transform: uppercase;
371 text-align: center;
372 color: #fff;
373 margin: 0;
374 }
375 @media only screen and (max-width: 1199px) {
376 .wpvr-banner .rex-notification-counter__item {
377 width: 44px;
378 font-size: 12px;
379 }
380 }
381 @media only screen and (max-width: 991px) {
382 .wpvr-banner .rex-notification-counter__item {
383 font-size: 10px;
384 }
385 }
386 @media only screen and (max-width: 767px) {
387 .wpvr-banner .rex-notification-counter__item {
388 font-size: 13px;
389 width: 47px;
390 }
391 }
392 .wpvr-banner .rex-notification-counter__label {
393 font-weight: 400;
394 }
395
396 .wpvr-banner .rex-notification-counter__time {
397 position: relative;
398 font-size: 28px;
399 font-family: "Inter";
400 font-weight: 600;
401 line-height: normal;
402 letter-spacing: -0.56px;
403 color: #211CFD;
404 text-align: center;
405 height: 40px;
406 display: flex;
407 align-items: center;
408 justify-content: center;
409 margin-bottom: 10px;
410 border-radius: 10px;
411 background: linear-gradient(#fff, #fff) padding-box, linear-gradient(0deg, #00B4FF, #211CFD 100%) border-box;
412 border: 1px solid transparent;
413 box-shadow: 0px 3px 0px 0px #00B4FF;
414 }
415
416 @media only screen and (max-width: 1199px) {
417 .wpvr-banner .rex-notification-counter__time {
418 font-size: 30px;
419 }
420 }
421 @media only screen and (max-width: 991px) {
422 .wpvr-banner .rex-notification-counter__time {
423 font-size: 24px;
424 }
425 }
426 .wpvr-banner .rex-notification-counter__btn-area {
427 display: flex;
428 align-items: flex-end;
429 justify-content: flex-end;
430 }
431 .wpvr-banner .rex-notification-counter__btn {
432 position: relative;
433 font-family: "Inter";
434 font-size: 18px;
435 font-weight: 600;
436 line-height: 1;
437 color: #fff;
438 text-align: center;
439 box-shadow: 0 10px 30px 0 rgba(12, 10, 81, .25);
440 padding: 19px 33px;
441 display: inline-block;
442 cursor: pointer;
443 text-transform: capitalize;
444 border-radius: 30px;
445 transition: all .3s ease;
446 border: 2px solid #24ec2c;
447 text-decoration: none;
448 background: linear-gradient(96deg, #201cfe 39.04%, #00b4ff 115.96%);
449 }
450 .wpvr-banner .rex-notification-counter__btn:hover {
451 background: linear-gradient(96deg, #00b4ff 39.04%, #201cfe 115.96%);
452 color: #fff;
453 box-shadow: 0 12px 35px 0 rgba(12, 10, 81, .35);
454 transform: translateY(-2px);
455 border-color: #00b4ff;
456 }
457 .wpvr-banner .rex-notification-counter__stroke-font {
458 font-size: 26px;
459 font-family: "Inter";
460 font-weight: 600;
461 }
462
463 .rex-feed-tb__notification.wpvr-banner .rex-feed-tb__cross-top {
464 position: absolute;
465 top: -10px;
466 right: -9px;
467 background: #fff;
468 border: none;
469 padding: 0;
470 border-radius: 50%;
471 cursor: pointer;
472 z-index: 9999;
473 width: 30px;
474 height: 30px;
475 display: flex;
476 align-items: center;
477 justify-content: center;
478 }
479
480
481 @media only screen and (max-width: 1599px) {
482
483 .rex-feed-tb__notification.wpvr-banner {
484 background-position: 14%;
485 }
486 .wpvr-banner .rex-notification-counter__container {
487 max-width: 1010px;
488 }
489 .wpvr-banner .rex-notification-counter__figure-logo {
490 max-width: 180px;
491 }
492
493 .wpvr-banner .rex-notification-counter__biggest-sale {
494 max-width: 200px;
495 }
496
497 .wpvr-banner .rex-notification-counter__btn {
498 font-size: 16px;
499 padding: 15px 25px;
500 }
501
502 }
503
504 @media only screen and (max-width: 1399px) {
505 .rex-feed-tb__notification.wpvr-banner {
506 background-position: center;
507 }
508
509 .wpvr-banner .rex-notification-counter__container {
510 max-width: 1000px;
511 }
512
513 .wpvr-banner .rex-notification-counter__biggest-sale {
514 max-width: 210px;
515 }
516 .wpvr-banner .rex-notification-counter__figure-logo {
517 max-width: 160px;
518 }
519
520 .wpvr-banner .rex-notification-counter__list {
521 gap: 8px;
522 }
523 .wpvr-banner .rex-notification-counter__item {
524 width: 44px;
525 font-size: 12px;
526 }
527 .wpvr-banner .rex-notification-counter__time {
528 font-size: 24px;
529 height: 36px;
530 }
531
532 .wpvr-banner .rex-notification-counter__btn {
533 padding: 15px 20px;
534 }
535
536 }
537
538 @media only screen and (max-width: 1199px) {
539 .wpvr-banner .rex-notification-counter__container {
540 max-width: 780px;
541 }
542
543 .rex-feed-tb__notification.wpvr-banner .rex-feed-tb__cross-top {
544 top: -7px;
545 right: -7px;
546 width: 22px;
547 height: 22px;
548 }
549
550 .rex-feed-tb__notification.wpvr-banner .rex-feed-tb__cross-top svg {
551 width: 10px;
552 height: 10px;
553 }
554
555 .wpvr-banner .rex-notification-counter__biggest-sale {
556 max-width: 140px;
557 }
558 .wpvr-banner .rex-notification-counter__figure-logo {
559 max-width: 140px;
560 }
561 .wpvr-banner .rex-notification-counter__figure-percentage {
562 max-width: 60px;
563 }
564 .wpvr-banner .rex-notification-counter__time {
565 font-size: 16px;
566 height: 30px;
567 font-weight: 500;
568 }
569 .wpvr-banner .rex-notification-counter__item {
570 font-size: 11px;
571 width: 35px;
572 }
573 .wpvr-banner .rex-notification-counter__btn {
574 font-size: 13px;
575 padding: 12px 20px;
576 }
577 .wpvr-banner .rex-notification-counter__stroke-font {
578 font-size: 20px;
579 }
580
581 }
582
583 @media only screen and (max-width: 991px) {
584 .wpvr-banner .rex-notification-counter__biggest-sale {
585 max-width: 130px;
586 }
587
588 .rex-feed-tb__notification.wpvr-banner {
589 margin: 65px 0 20px;
590 }
591
592 .wpvr-banner .rex-notification-counter__figure-logo {
593 max-width: 120px;
594 }
595
596 .wpvr-banner .rex-notification-counter__item {
597 width: 36px;
598 font-size: 10px;
599 }
600 .wpvr-banner .rex-notification-counter__time {
601 height: 28px;
602 }
603 /* .wpvr-banner .rex-notification-counter__figure-percentage {
604 max-width: 60px;
605 } */
606
607 .wpvr-banner .rex-notification-counter__btn {
608 padding: 10px 14px;
609 border-radius: 6px;
610 }
611
612 }
613
614 </style>
615 <?php
616
617 }
618 }
619