HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: /var/www/javaapp.co.uk/wp-content/plugins/royal-elementor-addons/classes/plugin-sale-notice.php
<?php 
namespace WprAddons\Classes;

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

class WprPluginSaleNotice {
    public function __construct() {
        // delete_option('wpr_plugin_sale_dismiss_notice'); // uncomment for testing
        
        $this->past_date = strtotime( '-2 days' );
        $this->past_date_rml = strtotime( '-15 days' );
        $this->install_date = get_option('royal_elementor_addons_activation_time_for_sale');
        $this->remind_me_later = get_option('wpr_sale_remind_me_later');
        // add_action( 'admin_init', [$this, 'render_notice'] ); // uncomment for testing

        if ( current_user_can('administrator') ) {
            if ( !get_option('wpr_plugin_sale_dismiss_notice') ) {
                add_action( 'admin_init', [$this, 'render_notice'] );
            }
        }

        if ( is_admin() ) {
            add_action( 'admin_head', [$this, 'enqueue_scripts' ] );
        }

        add_action( 'wp_ajax_wpr_plugin_sale_dismiss_notice', [$this, 'wpr_plugin_sale_dismiss_notice'] );
        add_action( 'wp_ajax_wpr_sale_remind_me_later', [$this, 'wpr_sale_remind_me_later'] );
    }

    public function render_notice() {
        // add_action( 'admin_notices', [$this, 'render_plugin_sale_notice' ]); // uncomment for testing
        if ( $this->past_date >= $this->install_date ) {
            if ( get_option('wpr_sale_remind_me_later') && !($this->past_date_rml >= $this->remind_me_later) ) {
                return;
            }
            add_action( 'admin_notices', [$this, 'render_plugin_sale_notice' ]);
        }
    }
    
    public function wpr_plugin_sale_dismiss_notice() {
        add_option( 'wpr_plugin_sale_dismiss_notice', true );
    }
    
    public function wpr_sale_remind_me_later() {
        update_option( 'wpr_sale_remind_me_later', absint(intval(strtotime('now'))) );
    }

    public function render_plugin_sale_notice() {
        if ( is_admin() ) {
            echo '<div class="notice wpr-plugin-sale-notice is-dismissible">
                        <div>
                            <h3><span>Flash Sale</span><br> Royal Elementor Addons Pro</h3>
                            <ul>
                                <li>
                                    <img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/check-mark.png">
                                    50+ Designer Made Templates Kit
                                </li>
                                <li>
                                    <img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/check-mark.png">
                                    80+ Advanced Elementor Widgets
                                </li>
                                <li>
                                    <img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/check-mark.png">
                                    Advanced Theme Builder
                                </li>
                                <li>
                                    <img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/check-mark.png">
                                    Advanced WooCommerce Builder
                                </li>
                                <li>
                                    <img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/check-mark.png">
                                    Advanced Popup Builder
                                </li>
                            </ul>
                            <p>
                                Hurry up! Upgrade within the <strong>next 24 hours</strong> and get a 
                                <strong>20% Discount</strong>.<br><br>
                                Use Promo Code: &nbsp;&nbsp;&nbsp;<strong style="border: 1px dashed #C3C4C7;padding: 2px 10px;">REAFLASH20</strong>
                            </p>
                            <br>
                            <div>
                                <a href="https://royal-elementor-addons.com/?ref=rea-plugin-backend-salebanner-upgrade-pro#purchasepro" target="_blank" class="wpr-upgrade-to-pro-button button button-secondary">Upgrade to Pro <span class="dashicons dashicons-arrow-right-alt"></span></a>
                                <a target="#" target="_blank" class="wpr-upgrade-to-pro-button button button-secondary wpr-remind-later">Remind Me Later</a>
                            </div>
                        </div>
                        <div class="image-wrap"><img src="'. esc_url(WPR_ADDONS_ASSETS_URL) .'img/sale-banner-20.png"></div>
                        <canvas id="wpr-notice-confetti"></canvas>
                </div>';
        }
    }
    
    public static function enqueue_scripts() {
        // Load Confetti
        wp_enqueue_script( 'wpr-confetti-js', WPR_ADDONS_URL .'assets/js/admin/lib/confetti/confetti.min.js', ['jquery'] );

        // Scripts & Styles
        echo "
        <script>
        jQuery( document ).ready( function() {

            if ( jQuery('#wpr-notice-confetti').length ) {
                const wprConfetti = confetti.create( document.getElementById('wpr-notice-confetti'), {
                    resize: true
                });

                setTimeout( function () {
                    wprConfetti( {
                        particleCount: 150,
                        origin: { x: 1, y: 2 },
                        gravity: 0.3,
                        spread: 50,
                        ticks: 150,
                        angle: 120,
                        startVelocity: 60,
                        colors: [
                            '#0e6ef1',
                            '#f5b800',
                            '#ff344c',
                            '#98e027',
                            '#9900f1',
                        ],
                    } );
                }, 500 );

                setTimeout( function () {
                    wprConfetti( {
                        particleCount: 150,
                        origin: { x: 0, y: 2 },
                        gravity: 0.3,
                        spread: 50,
                        ticks: 200,
                        angle: 60,
                        startVelocity: 60,
                        colors: [
                            '#0e6ef1',
                            '#f5b800',
                            '#ff344c',
                            '#98e027',
                            '#9900f1',
                        ],
                    } );
                }, 900 );
            }

                jQuery(document).on( 'click', '.wpr-plugin-sale-notice .notice-dismiss', function() {
                    jQuery(document).find('.wpr-plugin-sale-notice').slideUp();
                    jQuery.post({
                        url: ajaxurl,
                        data: {
                            action: 'wpr_plugin_sale_dismiss_notice',
                        }
                    });
                });
                
                jQuery(document).on( 'click', '.wpr-plugin-sale-notice .wpr-remind-later', function(e) {
                    e.preventDefault();
                    jQuery(document).find('.wpr-plugin-sale-notice').slideUp();
                    jQuery.post({
                        url: ajaxurl,
                        data: {
                            action: 'wpr_sale_remind_me_later',
                        }
                    });
                }); 
            });
        </script>

        <style>
            .wpr-plugin-sale-notice {
                position: relative;
                display: flex;
                align-items: center;
                margin-top: 20px;
                margin-bottom: 20px;
                padding: 30px;
                border: 0 !important;
                box-shadow: 0 0 5px rgb(0 0 0 / 0.1);

                padding-left: 40px;
            }

            .wpr-plugin-sale-notice-logo {
                display: none;
                margin-right: 30px;
            }

            .wpr-plugin-sale-notice-logo img {
                max-width: 100%;
            }

            .wpr-plugin-sale-notice h3 {
                font-size: 36px;
                margin-top: 0;
                margin-bottom: 35px;
            }

            .wpr-plugin-sale-notice h3 span {
              display: inline-block;
              margin-bottom: 15px;
              font-size: 12px;
              color: #fff;
              background-color: #f51f3d;
              padding: 2px 12px 4px;
              border-radius: 3px;
            }

            .wpr-plugin-sale-notice ul li {
                font-size: 14px;
            }

            .wpr-plugin-sale-notice ul img {
                display: inline-block;
                width: 11px;
                margin-right: 2px;
            }

            .wpr-plugin-sale-notice p {
              margin-top: 10px;
              margin-bottom: 15px;
              font-size: 14px;
            }
            
            .wpr-plugin-sale-notice .wpr-upgrade-to-pro-button {
                border: 2px solid #e4e4e4;
                color: #9f9c9c;
                background-color: #fff;
                padding: 5px 25px;
                font-weight: bold;
                letter-spacing: 0.3px;
            }
            
            .wpr-plugin-sale-notice .wpr-upgrade-to-pro-button:hover {
              border: 2px solid #6a4bff4f;
              color: #6A4BFF;
              background: #f6f7f7;
            }
            
            .wpr-plugin-sale-notice .wpr-upgrade-to-pro-button:first-child {
              border: 2px solid #6A4BFF;
              color: #ffffff;
              background-color: #6A4BFF;
              text-transform: uppercase;
            }

            .wpr-plugin-sale-notice .wpr-upgrade-to-pro-button .dashicons {
              font-size: 14px;
              line-height: 30px;
            }
            
            .wpr-plugin-sale-notice .image-wrap {
              margin-left: auto;
            }

            #wpr-notice-confetti {
              position: absolute;
              top: 0;
              left: 0;
              width: 100%;
              height: 100%;
              pointer-events: none;
            }

            @media screen and (max-width: 1400px) {
                .wpr-plugin-sale-notice .image-wrap img {
                  zoom: 0.9;
                }
            }

            @media screen and (max-width: 1366px) {
                .wpr-plugin-sale-notice .image-wrap img {
                  zoom: 0.7;
                }
            }
        </style>";

        
    }
}

if ( 'Royal Addons' === Utilities::get_plugin_name() ) {
    new WprPluginSaleNotice();
}