<?php
/*new berocket_admin_notices(array(
    'start' => 1497880000, // timestamp when notice start
    'end'   => 1497885000, // timestamp when notice end
    'name'  => 'name', //notice name must be unique for this time period
    'html'  => '', //text or html code as content of notice
    'type'  => 'info', //(blue), success(green), error(red), warning(yellow)
    'righthtml'  => '<a class="berocket_no_thanks">No thanks</a>', //content in the right block, this is default value. This html code must be added to all notices
    'rightwidth'  => 80, //width of right content is static and will be as this value. berocket_no_thanks block is 60px and 20px is additional
    'nothankswidth'  => 60, //berocket_no_thanks width. set to 0 if block doesn't uses. Or set to any other value if uses other text inside berocket_no_thanks
    'contentwidth'  => 400, //width that uses for mediaquery is image_width + contentwidth + rightwidth
    'subscribe'  => false, //add subscribe form to the righthtml
    'priority'  => 20, //priority of notice. 1-5 is main priority and displays on settings page always
    'height'  => 50, //height of notice. image will be scaled
    'repeat'  => false, //repeat notice after some time. time can use any values that accept function strtotime
    'repeatcount'  => 1, //repeat count. how many times notice will be displayed after close
    'image'  => array(
        'global' => 'http://berocket.com/images/logo-2.png', //image URL from other site. Image will be copied to uploads folder if it possible
        //'local' => 'http://wordpress-site.com/wp-content/uploads/logo-2.png', //notice will be used this image directly
    ),
    'conditions' => array(//can be removed if not needed
        'plugin_id' => 1,//plugin ID that used to check plugin_version_capability
        'plugin_version_capability' => [0,15],//show notice only when version_capability between 
        'notice_close_status' => array(//show notice only based on closed status of other notice
            'notice_priority' => '20',//other notice priority
            'notice_name' => 'name8',//other notice name
            'closed' => [1,2]//other notice closed status required
        ),
    )
));*/
//delete_option('berocket_admin_notices'); //remove all notice information
//delete_option('berocket_last_close_notices_time'); //remove wait time before next notice
//delete_option('berocket_admin_notices_rate_stars');
if ( ! class_exists( 'berocket_admin_notices' ) ) {
    /**
     * Class berocket_admin_notices
     */

    class berocket_admin_notices {
        public $find_names, $notice_exist = false;
        public static $last_time = '-24 hours';
        public static $end_soon_time = '+1 hour';
        public static $subscribed = false;
        public static $jquery_script_exist = false;
        public static $styles_exist = false;
        public static $notice_index = 0;
        public static $default_notice_options = array(
                'start'         => 0,
                'end'           => 0,
                'name'          => 'sale',
                'html'          => '',
                'type'          => 'info',
                'righthtml'     => '<span class="berocket-notice-dismiss notice-dismiss berocket_no_thanks" role="button" tabindex="0">
						<span class="screen-reader-text">
						<input class="berocket-notice-dismiss-check" type="checkbox" value="1">Dismiss this notice.
						</span>
					</span>',
                'rightwidth'    => 80,
                'nothankswidth' => 60,
                'contentwidth'  => 400,
                'subscribe'     => false,
                'closed'        => '0',
                'priority'      => 20,
                'height'        => 50,
                'repeat'        => false,
                'repeatcount'   => 1,
                'image'         => array(
                    'global'    => ''
                ),
            );
        function __construct($options = array()) {
            if ( ! is_admin() ) return;
            $options = array_merge(self::$default_notice_options, $options);
            self::set_notice_by_path($options);
            add_filter( 'berocket_admin_notice_is_display_notice', array( __CLASS__, 'notice_closed_status' ), 10, 3 );
            add_filter( 'berocket_admin_notice_is_display_notice_priority', array( __CLASS__, 'notice_closed_status' ), 10, 3 );
        }
        public static function sort_notices($notices) {
            return self::sort_array (
                $notices,
                array(
                    1 => 'krsort',
                    2 => 'ksort',
                    3 => 'ksort'
                ),
                array(
                    '1' => SORT_NUMERIC,
                    '2' => SORT_NUMERIC,
                    '3' => SORT_NUMERIC
                )
            );
        }
        public static function sort_array($array, $sort_functions, $options, $count = 3) {
            if( $count > 0 ) {
                if( ! is_array($array) ) {
                    return array();
                }
                $call_function = $sort_functions[$count];
                $call_function($array, $options[$count]);
                if( isset($array[0]) ) {
                    $first_element = $array[0];
                    unset($array[0]);
                    $array[0] = $first_element;
                    unset($first_element);
                }
                foreach($array as $item_id => $item) {
                    if( $count == 2 ) {
                        $time = time();
                        if( $item_id < $time && $item_id != 0 ) {
                            unset($array[$item_id]);
                        } else {
                            $array[$item_id] = self::sort_array($item, $sort_functions, $options, $count - 1);
                        }
                    } else {
                        $array[$item_id] = self::sort_array($item, $sort_functions, $options, $count - 1);
                    }
                    if( isset($array[$item_id]) && ( ! is_array($array[$item_id]) || count($array[$item_id]) == 0 ) ) {
                        unset($array[$item_id]);
                    }
                }
            }
            return $array;
        }
        public static function get_notice_by_path($find_names) {
            $notices = get_option( 'berocket_admin_notices' );
            if ( ! is_array( $notices ) ) {
                $notices = array();
            }

            $current_notice = &$notices;
            foreach ( $find_names as $find_name ) {
                if ( isset( $current_notice[ $find_name ] ) ) {
                    $new_current_notice = &$current_notice[ $find_name ];
                    unset( $current_notice );
                    $current_notice = &$new_current_notice;
                    unset( $new_current_notice );
                } else {
                    unset( $current_notice );
                    break;
                }
            }

            if ( ! isset( $current_notice ) ) $current_notice = false;

            return $current_notice;
        }

	    public static function get_notice_by_priority_and_name( $priority, $name ) {
		    $notices = get_option( 'berocket_admin_notices' );

            if ( is_array( $notices ) and ! empty( $notices[ $priority ] ) ) {
			    foreach ( $notices[ $priority ] as $end_time => $end_level_value ) {
				    foreach ( $end_level_value as $start_time => $start_level_value ) {
					    if ( ! empty( $start_level_value[ $name ] ) ) {
						    return $notices[ $priority ][ $end_time ][ $start_time ][ $name ];
					    }
				    }
			    }
		    }

		    return false;
	    }

        public static function berocket_array_udiff_assoc_notice($a1, $a2) {
            return json_encode($a1) > json_encode($a2);
        }

        public static function set_notice_by_path($options, $replace = false, $find_names = false) {
            self::$subscribed = get_option('berocket_email_subscribed');
            if( self::$subscribed && $options['subscribe'] ) {
                return false;
            }
            if( $options['end'] < time() && $options['end'] != 0 ) {
                return false;
            }

	        $notices = get_option('berocket_admin_notices');

            // search if $current_notice exists, start and end time should be ignored, use priority and name only
	        if ( is_array( $notices ) and ! empty( $notices[ $options['priority'] ] ) ) {
		        foreach ( $notices[ $options['priority'] ] as $end_time => $end_level ) {
			        foreach ( $end_level as $start_time => $start_level ) {
				        if ( ! empty( $start_level[ $options['name'] ] ) ) {
					        $current_notice = &$notices[ $options['priority'] ][ $end_time ][ $start_time ][ $options['name'] ];
					        // if replace is not passed time should not be changed
					        if ( ! $replace )
						        $options['end'] = $current_notice['end'];
					        break 2;
				        }
			        }
		        }
	        }
            // not found, lets create a value
            if ( empty( $current_notice ) || ! is_array( $current_notice ) ) {
                if ( ! isset( $notices[ $options['priority'] ] ) || ! is_array( $notices[ $options['priority'] ] ) ) {
                    $notices[ $options['priority'] ] = array();
                }
                if ( ! isset( $notices[ $options['priority'] ][ $options['end'] ] ) || ! is_array( $notices[ $options['priority'] ][ $options['end'] ] ) ) {
                    $notices[ $options['priority'] ][ $options['end'] ] = array();
                }
                if ( ! isset( $notices[ $options['priority'] ][ $options['end'] ][ $options['start'] ] ) || ! is_array( $notices[ $options['priority'] ][ $options['end'] ][ $options['start'] ] ) ) {
                    $notices[ $options['priority'] ][ $options['end'] ][ $options['start'] ] = array();
                }
		        $notices[ $options['priority'] ][ $options['end'] ][ $options['start'] ][ $options['name'] ] = array();
		        $current_notice = &$notices[ $options['priority'] ][ $options['end'] ][ $options['start'] ][ $options['name'] ];
            }

            $array_diff = array_udiff_assoc($options, $current_notice, array(__CLASS__, 'berocket_array_udiff_assoc_notice'));
            if( isset($array_diff['image']) ) {
                unset($array_diff['image']);
            }

            if( count($array_diff) == 0 ) {
                return true;
            }
            if( empty($options['image']) || (empty($options['image']['local']) && empty($options['image']['global'])) ) {
                $options['image'] = array('width' => 0, 'height' => 0, 'scale' => 0);
            } else {
                $file_exist = false;
                if( isset($options['image']['global']) ) {
                    $wp_upload = wp_upload_dir();
                    if( ! isset($options['image']['local']) ) {
                        $url_global = $options['image']['global'];
                        $img_local = $wp_upload['basedir'] . '/' . basename($url_global);
                        $url_local = $wp_upload['baseurl'] . '/' . basename($url_global);
                        if( ! file_exists($img_local) && is_writable($wp_upload['path']) ) {
                            file_put_contents($img_local, file_get_contents($url_global));
                        }
                        if( file_exists($img_local) ) {
                            $options['image']['local'] = $url_local;
                            $options['image']['pathlocal'] = $img_local;
                        } else {
                            $options['image']['local'] = $url_global;
                            $file_exist = true;
                        }
                    }
                }
                if( ! $file_exist ) {
                    if( ! empty($options['image']['local']) ) {
                        $img_local = $options['image']['local'];
                        $img_local = str_replace(site_url('/'), '', $img_local);
                        $img_local = ABSPATH . $img_local;
                        $file_exist = ( file_exists($img_local) );
                    } else {
                        $file_exist = false;
                    }
                }
                if( $file_exist ) {
                    $check_size = true;
                    if( isset($current_notice['image']['local']) && $current_notice['image']['local'] == $options['image']['local'] ) {
                        if( isset($current_notice['image']['width']) && isset($current_notice['image']['height']) ) {
                            $options['image']['width'] = $current_notice['image']['width'];
                            $options['image']['height'] = $current_notice['image']['height'];
                            $check_size = false;
                        }
                    }
                    if( $check_size ) {
                        $image_size = @ getimagesize($options['image']['local']);
                        if( ! empty($image_size[0]) && ! empty($image_size[1]) ) {
                            $options['image']['width'] = $image_size[0];
                            $options['image']['height'] = $image_size[1];
                        } else {
                            $options['image']['width'] = $options['height'];
                            $options['image']['height'] = $options['height'];
                        }
                    }
                    $options['image']['scale'] = $options['height'] / $options['image']['height'];
                } else {
                    $options['image'] = array('width' => 0, 'height' => 0, 'scale' => 0);
                }
            }
            if( count($current_notice) != 0 ) {
                if( ! empty($options['image']['local']) && $options['image']['local'] != $current_notice['image']['local'] ) {
                    if( isset($current_notice['image']['pathlocal']) ) {
                        unlink($current_notice['image']['pathlocal']);
                    }
                }
                if( ! $replace ) {
                    $options['closed'] = $current_notice['closed'];
                }
            }
	        $current_notice = $options;

            $notices = self::sort_notices($notices);
            update_option('berocket_admin_notices', $notices);
            return true;
        }
        public static function get_notice() {
            $notices = get_option('berocket_admin_notices');
            $last_time = get_option('berocket_last_close_notices_time');
            self::$subscribed = get_option('berocket_email_subscribed');
            if( ! is_array($notices) || count($notices) == 0 ) return false;
            if( $last_time > strtotime(self::$last_time) ) {
                $current_notice = self::get_not_closed_notice($notices, true);
            } else {
                $current_notice = self::get_not_closed_notice($notices);
            }
            update_option('berocket_current_displayed_notice', $current_notice);
            return $current_notice;
        }
        public static function get_notice_for_settings() {
	        $notices          = get_option( 'berocket_admin_notices' );
	        $last_notice      = get_option( 'berocket_admin_notices_last_on_options' );
	        self::$subscribed = get_option( 'berocket_email_subscribed' );
	        $notices          = self::get_notices_with_priority( $notices );
	        if ( ! is_array( $notices ) || count( $notices ) == 0 ) {
		        return false;
	        }
	        if ( $last_notice === false ) {
		        $last_notice = 0;
	        } else {
		        $last_notice ++;
	        }
	        if ( count( $notices ) <= $last_notice ) {
		        $last_notice = 0;
	        }
	        update_option( 'berocket_admin_notices_last_on_options', $last_notice );
	        $notice = $notices[ $last_notice ];

	        return $notice;
        }
        public static function get_not_closed_notice($array, $end_soon = false, $closed = 0, $count = 3) {
            $notice = false;
            if( empty($array) || ! is_array($array) ) {
                $array = array();
            }
            $time = time();
            foreach($array as $item_id => $item) {
                if( $count > 0 ) {
                    if( $count == 2 && $item_id < $time && $item_id != 0 || $count == 1 && $item_id > $time && $item_id != 0 ) {
                        continue;
                    }
                    if( $count == 2 && $item_id < strtotime(self::$end_soon_time) && $item_id != 0 ) {
                        $notice = self::get_not_closed_notice($item, $end_soon, 1, $count - 1);
                    } else {
                        if( $end_soon && $count == 2 ) {
                            break;
                        }
                        $notice = self::get_not_closed_notice($item, $end_soon, $closed, $count - 1);
                    }
                } else {
                    $display_notice = ( $item['closed'] <= $closed && ( ! self::$subscribed || ! $item['subscribe'] ) && ($item['start'] == 0 || $item['start'] < $time) && ($item['end'] == 0 || $item['end'] > $time) );
                    $display_notice = apply_filters( 'berocket_admin_notice_is_display_notice', $display_notice, $item, array(
                        'subscribed' => self::$subscribed,
                        'end_soon'   => $end_soon,
                        'closed'     => $closed,
                    ) );
                    if( $display_notice ) {
                        return $item;
                    }
                }
                if( $notice != false ) break;
            }
            return $notice;
        }
        public static function get_notices_with_priority($array, $priority = 19, $count = 3) {
            if( empty($array) || ! is_array($array) ) {
                $array = array();
            }
            $time = time();
            $notices = array();
            foreach($array as $item_id => $item) {
                if( $count > 0 ) {
                    if( $count == 3 && $item_id > $priority || $count == 2 && $item_id < $time && $item_id != 0 || $count == 1 && $item_id > $time && $item_id != 0 ) {
                        continue;
                    }
                    $notice = self::get_notices_with_priority($item, $priority, $count - 1);
                    $notices = array_merge($notices, $notice);
                } else {
                    $display_notice = ( (!self::$subscribed || ! $item['subscribe']) && ($item['priority'] <= 5 || !$item['closed']) );
                    $display_notice = apply_filters( 'berocket_admin_notice_is_display_notice_priority', $display_notice, $item, array(
                        'subscribed' => self::$subscribed,
                        'priority'   => $priority,
                    ) );
                    if( $display_notice ) {
                        $notices[] = $item;
                    }
                }
            }
            return $notices;
        }
        public static function display_admin_notice() {
            $settings_page = apply_filters('is_berocket_settings_page', false);
            if( $settings_page ) {
                $notice = self::get_notice_for_settings();
            } else {
                $notice = self::get_notice();
            }
            if( ! empty($notice['original']) ) {
                $original_notice = self::get_notice_by_path($notice['original']);
                unset($original_notice['start'], $original_notice['closed'], $original_notice['repeatcount']);
                $notice = array_merge($notice, $original_notice);
            }

            if( $notice !== false ) {
                self::echo_notice($notice);
            }
            $additional_notice = apply_filters('berocket_display_additional_notices', array());
            if( is_array($additional_notice) && count($additional_notice) > 0 ) {
                foreach($additional_notice as $notice) {
                    if( is_array($notice) ) {
                        self::echo_notice($notice);
                    }
                }
            }
        }
        public static function echo_notice($notice) {
            $notice = array_merge(self::$default_notice_options, $notice);
            $settings_page = apply_filters('is_berocket_settings_page', false);
            self::$notice_index++;
            $notice_data = array(
                'start'     => $notice['start'],
                'end'       => $notice['end'],
                'name'      => $notice['name'],
                'priority'  => $notice['priority'],
            );
            if( $notice['end'] < strtotime(self::$end_soon_time) && $notice['end'] != 0 ) {
                $time_left = $notice['end'] - time();
                $time_left_str = "";
                $time = $time_left;
                if ( $time >= 3600 ) {
                    $hours = floor( $time/3600 );
                    $time  = $time%3600;
                    $time_left_str .= sprintf("%02d", $hours) . ":";
                }
                if ( $time >= 60 || $time_left >= 3600 ) {
                    $minutes = floor( $time/60 );
                    $time  = $time%60;
                    $time_left_str .= sprintf("%02d", $minutes) . ":";
                }

                $time_left_str .= sprintf("%02d", $time);
                $notice['rightwidth'] += 60;
                $notice['righthtml'] .= '<div class="berocket_time_left_block">Left<br><span class="berocket_time_left" data-time="' . $time_left . '">' . $time_left_str . '</span></div>';
            }
            if( ! empty($notice['subscribe']) ) {
                $user_email = wp_get_current_user();
                if( isset($user_email->user_email) ) {
                    $user_email = $user_email->user_email;
                } else {
                    $user_email = '';
                }
                $notice['html'] .=
                '<div><form class="berocket_subscribe_form" method="POST" action="' . admin_url( 'admin-ajax.php' ) . '">
                    <input type="hidden" name="berocket_action" value="berocket_subscribe_email">
                    <input class="berocket_subscribe_email" type="email" name="email" value="' . $user_email . '">
                    <input type="submit" class="button-primary button berocket_notice_submit" value="Subscribe">
                </form></div>';
            }
            echo '
                <div class="notice berocket-notice notice-' . $notice['type'] . ' berocket_admin_notice berocket_admin_notice_', self::$notice_index, '" data-notice=\'', json_encode($notice_data), '\' data-nonce="' . wp_create_nonce('berocket_information_close_notice') . '">',
                    ( empty($notice['image']['local']) ? '' : '<img class="berocket_notice_img" src="' . $notice['image']['local'] . '">' ),
                    ( empty($notice['righthtml']) ? '' :
                    '<div class="berocket_notice_right_content">
                        <div class="berocket_notice_content">' . $notice['righthtml'] . '</div>
                        <div class="berocket_notice_after_content"></div>
                    </div>' ),
                    '<div class="berocket_notice_content_wrap">
                        <div class="berocket_notice_content">', $notice['html'], '</div>
                        <div class="berocket_notice_after_content"></div>
                    </div></div>';
            if( $settings_page && $notice['priority'] <= 5 ) {
                $notice['rightwidth'] -= $notice['nothankswidth'];
            }
            echo '<style>
                .berocket_admin_notice.berocket_admin_notice_', self::$notice_index, ' .berocket_no_thanks {',
                    ( $settings_page && $notice['priority'] <= 5 ? 'display: none!important;' : 'cursor: pointer;' ),
                '}
                ', ( empty($notice['subscribe']) ? '' : '
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form {
                    display: inline-block;
                    padding-right: 10px;
                }
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form .berocket_subscribe_email {
                    width: 180px;
                    margin: 0;
                    height: 28px
                    display: inline;
                }
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form .berocket_notice_submit {
                    margin: 0 0 0 10px;
                    min-width: 80px;
                    max-width: 80px;
                    width: 80px;
                    padding: 0;
                    display: inline;
                    vertical-align: baseline;
                    color: #fff;
                    box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
                    text-shadow: none;
                    border: 0 none;
                    -moz-user-select: none;
                    background: #ff5252 none repeat scroll 0 0;
                    box-sizing: border-box;
                    cursor: pointer;
                    font-size: 14px;
                    outline: 0 none;
                    position: relative;
                    text-align: center;
                    text-decoration: none;
                    transition: box-shadow 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s, background-color 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s;
                    white-space: nowrap;
                    height: auto;
                }
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form .berocket_notice_submit:hover,
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form .berocket_notice_submit:focus,
                .berocket_admin_notice.berocket_admin_notice_' . self::$notice_index . ' .berocket_subscribe_form .berocket_notice_submit:active{
                    background: #ff6e68 none repeat scroll 0 0;
                    color: white;
                }' ), '
            </style>
            <script>
                jQuery(document).ready(function() {
                    jQuery(document).on("click", ".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, ' .berocket_no_thanks", function(event){
                        event.preventDefault();
                        var notice = jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").data("notice");
                        var nonce = jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").data("nonce");
                        jQuery.post(ajaxurl, {action:"berocket_admin_close_notice", notice:notice, wp_nonce:nonce}, function(data){});
                        jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").hide();
                    });
                });';
            if ( $notice['end'] < strtotime(self::$end_soon_time) && $notice['end'] != 0 ) {
                echo 'setInterval(function(){
                    jQuery(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, ' .berocket_time_left").each(function(i, o) {
                        var left_time = jQuery(o).data("time");
                        var time = left_time;
                        if( time <= 0 ) {
                            jQuery(o).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").hide();
                        } else {
                            time--;
                            jQuery(o).data("time", time);
                            var str = "";
                            if ( time >= 3600 ) {
                                hours = Math.floor( time/3600 );
                                time  = time%3600;
                                str += ("0" + hours).slice(-2) + ":";
                            }
                            if ( time >= 60 || left_time >= 3600 ) {
                                minutes = Math.floor( time/60 );
                                time  = time%60;
                                str += ("0" + minutes).slice(-2) + ":";
                            }
                            seconds = time;
                            str += ("0" + seconds).slice(-2);
                            jQuery(o).html(str);
                        }
                    });
                }, 1000);';
            }
            echo '</script>';
            self::echo_styles();
            self::echo_jquery_functions();
        }
        public static function echo_styles() {
            if( ! self::$styles_exist ) {
	            self::$styles_exist = true;
	            echo '
                <style>
                .berocket-notice {
                  position:relative
                }
                .berocket-notice .berocket-notice-actions {
                  margin:1em 0
                }
                .berocket-notice.notice-error,
                .berocket-notice.notice-info,
                .berocket-notice.notice-message,
                .berocket-notice.notice-success,
                .berocket-notice.notice-warning {
                  clear:both;
                  background:#fff;
                  border:solid;
                  border-width:0 0 0 4px;
                  border-radius:5px;
                  color:#373737;
                  margin:5px 15px 2px;
                  padding:24px 24px 24px 62px!important
                }
                .berocket-notice.notice-error:before,
                .berocket-notice.notice-info:before,
                .berocket-notice.notice-message:before,
                .berocket-notice.notice-success:before,
                .berocket-notice.notice-warning:before {
                  content:"\f14c";
                  font-family:dashicons;
                  font-size:22px;
                  position:absolute;
                  top:24px;
                  left:24px
                }
                .rtl .berocket-notice.notice-error:before,
                .rtl .berocket-notice.notice-info:before,
                .rtl .berocket-notice.notice-message:before,
                .rtl .berocket-notice.notice-success:before,
                .rtl .berocket-notice.notice-warning:before {
                  top:24px;
                  right:24px;
                  bottom:0;
                  left:0
                }
                .rtl .berocket-notice.notice-error,
                .rtl .berocket-notice.notice-info,
                .rtl .berocket-notice.notice-message,
                .rtl .berocket-notice.notice-success,
                .rtl .berocket-notice.notice-warning {
                  border-left-width:0;
                  border-right-width:4px
                }
                .wrap .berocket-notice.notice-error,
                .wrap .berocket-notice.notice-info,
                .wrap .berocket-notice.notice-message,
                .wrap .berocket-notice.notice-success,
                .wrap .berocket-notice.notice-warning {
                  margin:5px 0 15px
                }
                .berocket-notice.notice-error h2,
                .berocket-notice.notice-info h2,
                .berocket-notice.notice-message h2,
                .berocket-notice.notice-success h2,
                .berocket-notice.notice-warning h2 {
                  font-size:18px;
                  line-height:20px;
                  margin:0 0 16px;
                  padding: 0 !important
                }
                .berocket-notice.notice-error p,
                .berocket-notice.notice-info p,
                .berocket-notice.notice-message p,
                .berocket-notice.notice-success p,
                .berocket-notice.notice-warning p {
                  margin:0;
                  padding:0;
                  line-height:20px;
                  font-size: 18px;
                }
                .berocket-notice.notice-error ol,
                .berocket-notice.notice-error ul,
                .berocket-notice.notice-info ol,
                .berocket-notice.notice-info ul,
                .berocket-notice.notice-message ol,
                .berocket-notice.notice-message ul,
                .berocket-notice.notice-success ol,
                .berocket-notice.notice-success ul,
                .berocket-notice.notice-warning ol,
                .berocket-notice.notice-warning ul {
                  max-height:10em;
                  overflow:auto;
                  padding-left:2em!important
                }
                .rtl .berocket-notice.notice-error ol,
                .rtl .berocket-notice.notice-error ul,
                .rtl .berocket-notice.notice-info ol,
                .rtl .berocket-notice.notice-info ul,
                .rtl .berocket-notice.notice-message ol,
                .rtl .berocket-notice.notice-message ul,
                .rtl .berocket-notice.notice-success ol,
                .rtl .berocket-notice.notice-success ul,
                .rtl .berocket-notice.notice-warning ol,
                .rtl .berocket-notice.notice-warning ul {
                  padding-left:12px!important;
                  padding-right:1em!important
                }
                .berocket-notice.notice-error ul,
                .berocket-notice.notice-info ul,
                .berocket-notice.notice-message ul,
                .berocket-notice.notice-success ul,
                .berocket-notice.notice-warning ul {
                  list-style-type:disc
                }
                .berocket-notice.notice-error.right>*,
                .berocket-notice.notice-info.right>*,
                .berocket-notice.notice-message.right>*,
                .berocket-notice.notice-success.right>*,
                .berocket-notice.notice-warning.right>* {
                  text-align:right
                }
                .rtl .berocket-notice.notice-error.right>*,
                .rtl .berocket-notice.notice-info.right>*,
                .rtl .berocket-notice.notice-message.right>*,
                .rtl .berocket-notice.notice-success.right>*,
                .rtl .berocket-notice.notice-warning.right>* {
                  text-align:left
                }
                .berocket-notice.notice-error.center>*,
                .berocket-notice.notice-info.center>*,
                .berocket-notice.notice-message.center>*,
                .berocket-notice.notice-success.center>*,
                .berocket-notice.notice-warning.center>* {
                  text-align:center
                }
                .berocket-notice.notice-error.center>*>ol,
                .berocket-notice.notice-error.center>*>ul,
                .berocket-notice.notice-info.center>*>ol,
                .berocket-notice.notice-info.center>*>ul,
                .berocket-notice.notice-message.center>*>ol,
                .berocket-notice.notice-message.center>*>ul,
                .berocket-notice.notice-success.center>*>ol,
                .berocket-notice.notice-success.center>*>ul,
                .berocket-notice.notice-warning.center>*>ol,
                .berocket-notice.notice-warning.center>*>ul {
                  text-align:left;
                  padding-left:1em!important;
                  font-weight:400
                }
                .rtl .berocket-notice.notice-error.center>*>ol,
                .rtl .berocket-notice.notice-error.center>*>ul,
                .rtl .berocket-notice.notice-info.center>*>ol,
                .rtl .berocket-notice.notice-info.center>*>ul,
                .rtl .berocket-notice.notice-message.center>*>ol,
                .rtl .berocket-notice.notice-message.center>*>ul,
                .rtl .berocket-notice.notice-success.center>*>ol,
                .rtl .berocket-notice.notice-success.center>*>ul,
                .rtl .berocket-notice.notice-warning.center>*>ol,
                .rtl .berocket-notice.notice-warning.center>*>ul {
                  text-align:right;
                  padding-left:12px!important;
                  padding-right:1em!important
                }
                .berocket-notice.notice-error.center>*>ul,
                .berocket-notice.notice-info.center>*>ul,
                .berocket-notice.notice-message.center>*>ul,
                .berocket-notice.notice-success.center>*>ul,
                .berocket-notice.notice-warning.center>*>ul {
                  list-style-type:disc
                }
                .berocket-notice.notice-info,
                .berocket-notice.notice-message {
                  border-color:#2f7d92;
                  background-color:#f8fbfc
                }
                .berocket-notice.notice-info:before,
                .berocket-notice.notice-info a,
                .berocket-notice.notice-message:before,
                .berocket-notice.notice-message a {
                  color:#2f7d92
                }
                .berocket-notice.notice-info a:focus,
                .berocket-notice.notice-info a:hover,
                .berocket-notice.notice-message a:focus,
                .berocket-notice.notice-message a:hover {
                  color:#2f7d92;
                  text-decoration:none
                }
                .berocket-notice.notice-info .notice-dismiss:before,
                .berocket-notice.notice-message .notice-dismiss:before {
                  color:#2f7d92
                }
                .berocket-notice.notice-warning {
                  border-color:#e8ae57;
                  background-color:#fbf6e5
                }
                .berocket-notice.notice-warning:before {
                  color:#e8ae57
                }
                .berocket-notice.notice-warning a {
                  color:#996415;
                  border-color:#996415
                }
                .berocket-notice.notice-warning a:focus,
                .berocket-notice.notice-warning a:hover {
                  color:#996415;
                  border-color:#996415;
                  text-decoration:none
                }
                .berocket-notice.notice-warning .notice-dismiss:before {
                  color:#e8ae57
                }
                .berocket-notice.notice-error {
                  border-color:#db552b;
                  background-color:rgba(219,85,43,.1)
                }
                .berocket-notice.notice-error:before,
                .berocket-notice.notice-error a {
                  color:#db552b;
                  border-color:#db552b
                }
                .berocket-notice.notice-error a:focus,
                .berocket-notice.notice-error a:hover {
                  color:#db552b;
                  border-color:#db552b;
                  text-decoration:none
                }
                .berocket-notice.notice-error .notice-dismiss:before {
                  color:#db552b
                }
                .berocket-notice.notice-success {
                  border-color:#1c7d6b;
                  background-color:rgba(28,125,107,.1)
                }
                .berocket-notice.notice-success .notice-dismiss:before,
                .berocket-notice.notice-success:before {
                  color:#1c7d6b
                }
                .berocket-notice.is-dismissible {
                  position:relative
                }
                .rtl .berocket-notice.is-dismissible {
                  padding-right:62px;
                  padding-left:24px
                }
                .berocket-notice.is-dismissible .notice-dismiss {
                  text-decoration:none
                }
                .berocket-notice.is-dismissible .notice-dismiss.berocket-notice-dismiss {
                  padding:12px
                }
                .berocket-notice.is-dismissible .notice-dismiss.berocket-notice-dismiss:before {
                  content:"\33";
                  font-family:berocket-icons;
                  font-size:12px
                }
                .berocket-notice.is-dismissible .notice-dismiss.berocket-notice-dismiss:focus:before,
                .berocket-notice.is-dismissible .notice-dismiss.berocket-notice-dismiss:hover:before {
                  color:#373737
                }
                .berocket-notice.is-dismissible p [class*=button-] {
                  margin:-5px 5px
                }
                .berocket-notice .berocket-notice-collapse-hide {
                  position:absolute;
                  top:0;
                  right:1px;
                  border:none;
                  margin:0;
                  padding:9px;
                  background:0 0;
                  color:#b4b9be;
                  cursor:pointer
                }
                .rtl .berocket-notice .berocket-notice-collapse-hide {
                  right:auto;
                  left:1px
                }
                .berocket-notice .berocket-notice-collapse-hide,
                .berocket-notice .berocket-notice-collapse-show {
                  cursor:pointer
                }
                .berocket-notice .berocket-notice-collapse-hide:before,
                .berocket-notice .berocket-notice-collapse-show:before {
                  background:0 0;
                  color:#b4b9be;
                  display:block;
                  font:400 16px/20px dashicons;
                  speak:none;
                  height:20px;
                  width:20px;
                  text-align:center;
                  -webkit-font-smoothing:antialiased;
                  -moz-osx-font-smoothing:grayscale
                }
                .berocket-notice .berocket-notice-collapse-hide:hover:before,
                .berocket-notice .berocket-notice-collapse-show:hover:before {
                  color:#d54e21
                }
                .berocket-notice .berocket-notice-collapse-hide:before {
                  content:"\f460"
                }
                .berocket-notice .berocket-notice-collapsed-text .berocket-notice-collapse-show:before {
                  content:"\f132";
                  float:left
                }
                .rtl .berocket-notice .berocket-notice-collapsed-text .berocket-notice-collapse-show:before {
                  float:right
                }
                .berocket-notice .notice-collapse-header {
                  display:none
                }
                .berocket-notice .notice-action-link {
                  display:block;
                  position:absolute;
                  right:1em;
                  bottom:0.8em;
                  font-size: 1.3em;
                  font-weight: 600;
                }
                .rtl .berocket-notice .notice-action-link {
                  right:auto;
                  left:1em
                }
                .berocket-notice table {
                  border-spacing:0;
                  border-collapse:collapse;
                  margin:0 auto
                }
                .berocket-notice table td,
                .berocket-notice table th {
                  vertical-align:top;
                  text-align:left;
                  padding:2px
                }
                .berocket-notice table thead {
                  font-weight:400
                }
                .berocket-notice table thead tr {
                  background:#222;
                  background:rgba(34,34,34,.8);
                  color:#ccc
                }
                .berocket-notice table thead th {
                  text-transform:capitalize;
                  border-right:1px solid #ccc
                }
                .berocket-notice table thead th:last-child {
                  border-right:none
                }
                .berocket-notice table tbody tr {
                  background:#ccc;
                  background:hsla(0,0%,80%,.8)
                }
                .berocket-notice table tbody tr:nth-child(2n) td:nth-child(odd),
                .berocket-notice table tbody tr:nth-child(odd) td:nth-child(2n) {
                  background:#fff;
                  background:hsla(0,0%,100%,.8)
                }
                .berocket-notice table tbody td p:first-child {
                  margin-top:0;
                  padding-top:0
                }
                .berocket-notice table tbody td p:last-child {
                  margin-bottom:0;
                  padding-bottom:0
                }
                .berocket-notice table tbody td code {
                  font-family:monospace;
                  white-space:pre;
                  display:block
                }
                .berocket-notice-toggle {
                  font-size:.85em;
                  position:absolute;
                  bottom:5px;
                  right:15px;
                  color:#aaa;
                  cursor:pointer
                }
                .rtl .berocket-notice-toggle {
                  right:auto;
                  left:15px
                }
                .berocket-notice-toggle:after {
                  content:"";
                  vertical-align:middle;
                  margin-left:.3em;
                  display:inline-block;
                  border:.3em solid transparent
                }
                .rtl .berocket-notice-toggle:after {
                  margin-left:0;
                  margin-right:.3em
                }
                .expanded .berocket-notice-toggle:after {
                  border-bottom:.45em solid;
                  margin-top:-.25em
                }
                .minimized .berocket-notice-toggle:after {
                  border-left:.5em solid
                }
                .rtl .minimized .berocket-notice-toggle:after {
                  border-left:.3em solid transparent;
                  border-right:.5em solid
                }
                .berocket-notice.scan-links-notice {
                  padding:12px 20px 12px 40px!important
                }
                .rtl .berocket-notice.scan-links-notice {
                  padding:12px 40px 12px 20px!important
                }
                .berocket-notice.scan-links-notice:before {
                  top:12px;
                  left:12px;
                  font-size:16px
                }
                .rtl .berocket-notice.scan-links-notice:before {
                  left:unset;
                  right:12px
                }
                .berocket-notice.scan-links-notice p {
                  margin-bottom:8px
                }
                .berocket-notice-icon {
                  display:flex;
                  align-items:center
                }
                .berocket-notice-icon>i:before {
                  margin-right:16px;
                  font-size:25px
                }
                .rtl .berocket-notice-icon>i:before {
                  margin-right:0;
                  margin-left:16px
                }
                .berocket-notice-icon .berocket-ico-warning:before {
                  color:#ffb900
                }
                .br-notice-text-label {
                    display: inline-block;
                    background-color: #ffd453;
                    padding: 6px 11px 11px;
                    border-radius: 20px;
                }
                /* or 
                    display: inline-block;
                    background-position: center top;
                    background-image: linear-gradient(to bottom, #fbf6e5 0%, #ffe65a 50%, #fbf6e5 100%);
                    background-size: 100% 1em;
                    background-repeat: no-repeat;
                 */
                .berocket-notice-template-big {
                    display: flex
                }
                .berocket-notice-description-container {
                    padding-top: 0;
                    padding-bottom: 0;
                    position: relative;
                    top: -8px; 
                    width: 50%;
                }
                .berocket-notice-actions-container {
                    text-align: center;
                    display: flex;
                    justify-items: center;
                    flex-wrap: wrap;
                    width: 50%;
                    line-height: 
                }
                .berocket-notice-buttons-container {
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    margin-top: 25px;
                    width: 100%;
                }
                @media only screen and (max-width: 1400px) {
                    .berocket-notice-actions-container {
                        width: 370px;
                    }
                    .berocket-notice-buttons-container {
                        flex-wrap: wrap;
                        margin-top: 15px;
                    }
                    .berocket-notice-buttons-container span {
                        display: none;
                    }
                    .berocket-notice-buttons-container a {
                        margin-top: 10px;
                    }
                    .berocket-notice-buttons-container a.button {
                        padding-left: 10px !important;
                        padding-right: 10px !important;
                        font-size: 22px !important;
                        width: 100%;
                    }
                    .berocket-notice-description-container {
                        width: 100%;
                    }
                }
                @media only screen and (max-width: 1200px) {
                    .berocket-notice-template-big {
                        flex-wrap: wrap;
                    }
                    .berocket-notice-description-container {
                        width: 100%;
                        text-align: center;
                    }
                    .berocket-notice-description-container ul {
                        display: none;
                    }
                    .berocket-notice-actions-container {
                        margin: 15px auto 0;
                    }
                }
                @media only screen and (max-width: 782px) {
                    .berocket-notice .notice-action-link {
                        margin-top: 15px !important;
                        display: inline-block;
                        position: static;
                    }
                    .berocket-notice p {
                        margin-right: 0 !important;
                    }
                    .berocket-notice-description-container h1 {
                        line-height: 1.2 !important;
                    }
                    .berocket-notice-actions-container {
                        width: 100%;
                    }
                }
                @media only screen and (max-width: 500px) {
                    .berocket-notice.notice-error, 
                    .berocket-notice.notice-info, 
                    .berocket-notice.notice-message, 
                    .berocket-notice.notice-success, 
                    .berocket-notice.notice-warning {
                        padding: 24px 24px 24px 32px !important;
                    }
                    .berocket-notice.notice-error::before, 
                    .berocket-notice.notice-info::before, 
                    .berocket-notice.notice-message::before, 
                    .berocket-notice.notice-success::before, 
                    .berocket-notice.notice-warning::before {
                        top: 21px;
                        left: 5px;
                    }
                }
                </style>';
            }
        }
        public static function echo_jquery_functions() {
            if( ! self::$jquery_script_exist ) {
                self::$jquery_script_exist = true;
                echo '<script>
                    jQuery(document).on("berocket_subscribed", ".berocket_admin_notice", function(){
                        jQuery(this).find(".berocket_no_thanks").click();
                    });
                    jQuery(document).on("berocket_incorrect_email", ".berocket_admin_notice", function(){
                        jQuery(this).find(".berocket_subscribe_form").addClass("form-invalid");
                    });
                    jQuery(document).on("change", ".berocket_admin_notice", function(){
                        jQuery(this).find(".berocket_subscribe_form").removeClass("form-invalid");
                    });
                    var berocket_email_submited = false;
                    jQuery(document).on("submit berocket_subscribe_send", ".berocket_subscribe_form", function(event){
                        event.preventDefault();
                        event.stopPropagation();
                        var $this = jQuery(this);
                        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
                        var email = $this.find("[name=email]").val();
                        if( ! re.test(email) ) {
                            $this.trigger("berocket_incorrect_email");
                            return false;
                        }
                        if( ! berocket_email_submited ) {
                            berocket_email_submited = true;
                            if( $this.is("form") ) {
                                var data = $this.serialize();
                                data = data+"&action="+$this.find("[name=\'berocket_action\']").val();
                            } else {
                                if( jQuery(".berocket_plugin_id_subscribe").length ) {
                                    var data = {email:email, action: $this.find("[name=\'berocket_action\']").val(), plugin:jQuery(".berocket_plugin_id_subscribe").val()};
                                } else {
                                    var data = {email:email, action: $this.find("[name=\'berocket_action\']").val()};
                                }
                            }
                            var url = $this.attr("action");
                            $this.trigger("berocket_subscribing");
                            jQuery.post(url, data, function(data){
                                $this.trigger("berocket_subscribed");
                            }).fail(function(){
                                $this.trigger("berocket_not_subscribed");
                            });
                        }
                    });
                    jQuery(document).on("berocket_subscribing", ".berocket_subscribe", function(event) {
                        event.preventDefault();
                        jQuery(this).hide();
                    });
                    jQuery(document).on("berocket_incorrect_email", ".berocket_subscribe", function(event) {
                        event.preventDefault();
                        jQuery(this).addClass("form-invalid").find(".error").show();
                    });
                    jQuery(document).on("keyup", ".berocket_subscribe.berocket_subscribe_form .berocket_subscribe_email", function(event) {
                        var keyCode = event.keyCode || event.which;
                        if (keyCode === 13) {
                            event.preventDefault();
                            jQuery(this).parents(".berocket_subscribe_form").trigger("berocket_subscribe_send");
                            return false;
                        }
                    });
                    jQuery(document).on("click", ".berocket_subscribe.berocket_subscribe_form .berocket_notice_submit", function(event) {
                        event.preventDefault();
                        jQuery(this).parents(".berocket_subscribe_form").trigger("berocket_subscribe_send");
                    });

                </script>';
            }
        }
        public static function close_notice($notice = FALSE) {
            $wp_nonce = ( empty($_POST['wp_nonce']) ? '' : $_POST['wp_nonce'] );
            if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'berocket_information_close_notice' ) ) {
                echo __( 'Do not have access for this feature', 'BeRocket_domain' );
                wp_die();
            }
            self::$subscribed = get_option('berocket_email_subscribed');
            if( ( $notice == FALSE || ! is_array($notice) ) && ! empty($_POST['notice']) ) {
                $notice = $_POST['notice'];
            }
            if (empty($notice) || ! is_array($notice)
            || (empty($notice['start']) && $notice['start'] !== '0')
            || (empty($notice['end']) && $notice['end'] !== '0')
            || (empty($notice['priority']) && $notice['priority'] !== '0')
            || (empty($notice['name'])) ) {
                $notice = self::get_notice();
            } else {
                $notice['start']    = intval($notice['start']);
                $notice['end']      = intval($notice['end']);
                $notice['priority'] = intval($notice['priority']);
                $notice['name']     = sanitize_textarea_field($notice['name']);
            }
            if( empty($notice) || ! is_array($notice) ) {
	            echo __( 'Notice not found', 'BeRocket_domain' );
                wp_die();
            }
            $find_names = array($notice['priority'], $notice['end'], $notice['start'], $notice['name']);
            $current_notice = self::get_notice_by_path($find_names);
            if( isset($current_notice) ) {
                if( $current_notice['end'] < strtotime(self::$end_soon_time) ) {
                    $current_notice['closed'] = 2;
                } else {
                    $current_notice['closed'] = 1;
                }
                if( $current_notice['closed'] < 2 && ! empty($current_notice['repeat']) && ! empty($current_notice['repeatcount']) && ( ! self::$subscribed || ! $current_notice['subscribe'] ) ) {
                    $new_notice = $current_notice;
                    if( empty($current_notice['original']) ) {
                        $new_notice['original'] = $find_names;
                    }
                    $new_notice['repeatcount'] = $current_notice['repeatcount'] - 1;
                    $new_notice['start'] = strtotime($current_notice['repeat']);
                    $new_notice['closed'] = 0;
                    self::set_notice_by_path($new_notice);
                }
                self::set_notice_by_path($current_notice, true);
            }
            update_option('berocket_last_close_notices_time', time());
	        echo __( 'Notice updated', 'BeRocket_domain' );
            wp_die();
        }
        public static function subscribe() {
            if ( ! ( current_user_can( 'manage_options' ) ) ) {
                echo __( 'Do not have access for this feature', 'BeRocket_domain' );
                wp_die();
            }
            if( ! empty($_POST['email']) ) {
                $plugins = array();
                if( ! empty($_POST['plugin']) ) {
                    $plugins[] = sanitize_textarea_field($_POST['plugin']);
                }
                $plugins = apply_filters('berocket_admin_notices_subscribe_plugins', $plugins);
                $plugins = array_unique($plugins);
                $plugins = implode(',', $plugins);
                $email = sanitize_email($_POST['email']);
                update_option('berocket_email_subscribed', true);

                $response = wp_remote_post('https://berocket.com/main/subscribe', array(
                    'body' => array(
                        'subs_email' => $email,
                        'plugins'    => $plugins
                    ),
                    'method' => 'POST',
                    'timeout' => 15,
                    'redirection' => 5,
                    'blocking' => true,
                    'sslverify' => false
                ));
                if( ! is_wp_error($response) ) {
                    $out = wp_remote_retrieve_body($response);
                    echo $out;
                }
            }
            wp_die();
        }
        public static function generate_subscribe_notice() {
            new berocket_admin_notices(array(
                'start' => 0,
                'end'   => 0,
                'name'  => 'subscribe',
                'html'  => '<h2>Subscribe to get latest BeRocket news and updates, plugin recommendations and configuration 
						help, promotional email with discount codes.</h2>',
                'subscribe'  => true,
                'image'  => array(
                    'local' => plugin_dir_url( __FILE__ ) . '../assets/images/ad_white_on_orange.webp',
                ),
            ));
        }
        public static function notice_closed_status($display_notice, $item, $search_data) {
            if( ! $display_notice ) {
                return $display_notice;
            }
            if( ! empty($item['conditions']) && is_array($item['conditions'])
                && isset($item['conditions']['notice_close_status']) && is_array($item['conditions']['notice_close_status']) 
                && isset($item['conditions']['notice_close_status']['notice_name']) && isset($item['conditions']['notice_close_status']['notice_priority'])
                && isset($item['conditions']['notice_close_status']['closed']) ) {
                $notices            = get_option('berocket_admin_notices');
                $notice_name        = $item['conditions']['notice_close_status']['notice_name'];
                $notice_priority    = $item['conditions']['notice_close_status']['notice_priority'];
                $closed             = $item['conditions']['notice_close_status']['closed'];
                if( ! is_array($closed) ) {
                    $closed = array($closed);
                }
                $notice_exist = false;
                if ( is_array( $notices ) and ! empty( $notices[ $notice_priority ] ) ) {
                    foreach ( $notices[ $notice_priority ] as $end_time => $end_level ) {
                        foreach ( $end_level as $start_time => $start_level ) {
                            if ( ! empty( $start_level[ $notice_name ] ) ) {
                                $display_notice = in_array($start_level[ $notice_name ]['closed'], $closed);
                                $notice_exist = true;
                                break;
                            }
                        }
                    }
                }
                if( ! $notice_exist ) {
                    $display_notice = false;
                }
            }
            return $display_notice;
        }
    }
    add_action( 'admin_notices', array('berocket_admin_notices', 'display_admin_notice') );
    add_action( 'wp_ajax_berocket_admin_close_notice', array('berocket_admin_notices', 'close_notice') );
    add_action( 'wp_ajax_berocket_subscribe_email', array('berocket_admin_notices', 'subscribe') );
}
if( ! class_exists( 'berocket_admin_notices_rate_stars' ) ) {
    class berocket_admin_notices_rate_stars {
        public $first_time = '+7 days';
        public $later_time = '+7 days';
        function __construct() {
            add_action( 'admin_notices', array($this, 'admin_notices') );
            add_action( 'wp_ajax_berocket_rate_stars_close', array($this, 'disable_rate_notice') );
            add_action( 'wp_ajax_berocket_feature_request_send', array($this, 'feature_request_send') );
            add_action( 'berocket_rate_plugin_window', array($this, 'show_rate_window'), 10, 2 );
            add_action( 'berocket_related_plugins_window', array($this, 'show_related_window'), 10, 3 );
            add_action( 'berocket_above_admin_settings', array($this, 'show_ad_above_admin_settings'), 10, 2 );
            add_action( 'berocket_feature_request_window', array($this, 'show_feature_request_window'), 10, 2 );
        }
        function admin_notices() {
            $display_one = false;
            $disabled = get_option('berocket_admin_notices_rate_stars');
            if( ! is_array($disabled) ) {
                $disabled = array();
            }
            $plugins = apply_filters('berocket_admin_notices_rate_stars_plugins', array());
            foreach($plugins as $plugin_id => $plugin) {
                $display = false;
                if( empty($disabled[$plugin['id']]) ) {
                    $disabled[$plugin['id']] = array(
                        'time' => strtotime($this->first_time),
                        'count' => 0
                    );
                } elseif($disabled[$plugin['id']]['time'] != 0 && $disabled[$plugin['id']]['time'] < time()) {
                    $display = true;
                }
                if( $display ) {
                    $display_one = true;
                    ?>
                    <div class="notice notice-info berocket-rate-stars berocket-rate-stars-block berocket-rate-stars-<?php echo $plugin['id']; ?>">
                        <p><?php
                        $text = __( 'Awesome, you\'ve been using %plugin_name% Plugin for more than 1 week. May we ask you to give it a 5-star rating on WordPress?', 'BeRocket_domain' );
                        $text_mobile = __( 'May we ask you to give our plugin %plugin_name% a 5-star rating?', 'BeRocket_domain' );
                        $plugin['name'] = str_replace(' for WooCommerce', '', $plugin['name']);
                        $text = str_replace('%plugin_name%', '<a href="https://wordpress.org/support/plugin/'.$plugin['free_slug'].'/" target="_blank">'.$plugin['name'].'</a>', $text);
                        $text_mobile = str_replace('%plugin_name%', '<a href="https://wordpress.org/support/plugin/'.$plugin['free_slug'].'/" target="_blank">'.$plugin['name'].'</a>', $text_mobile);
                        $text = '<span class="brfeature_show_mobile">' . $text_mobile.'</span><span class="berocket-right-block">
                            <a class="berocket_rate_close brfirst"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="0"
                                data-function="berocket_rate_star_close_notice"
                                data-later="0"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-thanks_html=\'<picture><source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Thank-you.webp" alt="Feature Request"><img src="https://berocket.com/images/plugin/Thank-you.png" style="max-width: 100%;" alt="Feature Request"></picture><h3 class="berocket_thank_you_rate_us">'.__('Each good feedback is very important for plugin growth', 'BeRocket_domain').'</h3>\'
                                href="https://wordpress.org/support/plugin/'.$plugin['free_slug'].'/reviews/?filter=5#new-post"
                                target="_blank">'.__('Ok, you deserved it', 'BeRocket_domain').'</a>
                            <span class="brfirts"> | </span>
                            <a class="berocket_rate_close brsecond"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="1"
                                data-later="1"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-function="berocket_rate_star_close_notice"
                                href="#later">
                                    <span class="brfeature_hide_mobile">'.__('Maybe later', 'BeRocket_domain').'</span>
                                    <span class="brfeature_show_mobile">'.__('Later', 'BeRocket_domain').'</span>
                                </a>
                            <span class="brsecond"> | </span>
                            <a class="berocket_rate_close brthird"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="1"
                                data-later="0"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-function="berocket_rate_star_close_notice"
                                href="#close">
                                    <span class="brfeature_hide_mobile">'.__('I already did', 'BeRocket_domain').'</span>
                                    <span class="brfeature_show_mobile">'.__('Already', 'BeRocket_domain').'</span>
                                </a>
                        </span><span class="brfeature_hide_mobile">' . $text.'</span>';
                        echo $text;
                        ?></p>
                    </div>
                    <?php
                }
            }
            if( $display_one ) {
                add_action('admin_footer', array($this, 'wp_footer_js'));
                ?>
                <style>
                    .berocket-rate-stars span.brsecond,
                    .berocket-rate-stars a.brthird {
                        color: #999;
                    }
                    .berocket-rate-stars .berocket-right-block > span {
                        display: inline-block;
                        margin-left: 10px;
                        margin-right: 10px;
                    }
                    .berocket-rate-stars a.brthird:hover {
                        color: #00a0d2;
                    }
                    .berocket-rate-stars a {
                        text-decoration: none;
                    }
                    .berocket-rate-stars .berocket-right-block {
                        float: right;
                        padding-left: 20px;
                        display: inline-block;

                    }
                    .berocket-rate-stars .brfeature_show_mobile {
                        display: none;
                    }
                    @media screen and (min-width: 768px) and (max-width: 1024px) {
                        .berocket-rate-stars .berocket-right-block span.brfirts {
                            display: none;
                        }
                        .berocket-rate-stars .berocket-right-block .berocket_rate_close.brfirst {
                            display: block;
                        }
                    }
                    @media screen and (max-width: 768px) {
                        .berocket-rate-stars {
                            display: none;
                        }
                        .berocket-rate-stars .brfeature_show_mobile {
                            display: inline-block;
                        }
                        .berocket-rate-stars .brfeature_hide_mobile {
                            display: none;
                        }
                        .berocket-rate-stars .berocket-right-block {
                            float: none;
                            padding-left: 0;
                        }
                        .berocket-rate-stars .berocket-right-block > span {
                            margin-left: 5px;
                            margin-right: 5px;
                        }
                    }
                </style>
                <?php
            }
            update_option('berocket_admin_notices_rate_stars', $disabled);
        }
        function disable_rate_notice() {
            $wp_nonce = (empty($_GET['wp_nonce']) ? (empty($_POST['wp_nonce']) ? '' : $_POST['wp_nonce']) : $_GET['wp_nonce']);
            if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'berocket_rate_stars_close' ) ) {
                echo __( 'Do not have access for this feature', 'BeRocket_domain' );
                wp_die();
            }
            $plugin = (empty($_GET['plugin']) ? (empty($_POST['plugin']) ? '' : $_POST['plugin']) : $_GET['plugin']);
            $later = (empty($_GET['later']) ? (empty($_POST['later']) ? '' : $_POST['later']) : $_GET['later']);
            $disabled = get_option('berocket_admin_notices_rate_stars');
            if( isset($disabled[$plugin]) && is_array($disabled[$plugin]) && isset($disabled[$plugin]['time']) ) {
                if( empty($later) ) {
                    $disabled[$plugin]['time'] = 0;
                } else {
                    $disabled[$plugin]['time'] = strtotime($this->later_time);
                }
            }
            update_option('berocket_admin_notices_rate_stars', $disabled);
            wp_die();
        }
        function feature_request_send() {
            $wp_nonce = ( empty($_POST['wp_nonce']) ? '' : $_POST['wp_nonce'] );
            if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'berocket_feature_request_send' ) ) {
                echo __( 'Do not have access for this feature', 'BeRocket_domain' );
                wp_die();
            }
            $plugin = (empty($_GET['brfeature_plugin']) ? (empty($_POST['brfeature_plugin']) ? '' : $_POST['brfeature_plugin']) : $_GET['brfeature_plugin']);
            $email = (empty($_GET['brfeature_email']) ? (empty($_POST['brfeature_email']) ? '' : $_POST['brfeature_email']) : $_GET['brfeature_email']);
            $title = (empty($_GET['brfeature_title']) ? (empty($_POST['brfeature_title']) ? '' : $_POST['brfeature_title']) : $_GET['brfeature_title']);
            $description = (empty($_GET['brfeature_description']) ? (empty($_POST['brfeature_description']) ? '' : $_POST['brfeature_description']) : $_GET['brfeature_description']);
            if( ! empty($plugin) && ! empty($title) && ! empty($description) ) {
                $response = wp_remote_post( 'https://berocket.com/api/data/add_feature_request', array(
                    'body'        => array(
                        'plugin'        => $plugin,
                        'email'         => $email,
                        'title'         => $title,
                        'description'   => $description
                    ),
                    'method'      => 'POST',
                    'timeout'     => 5,
                    'redirection' => 5,
                    'blocking'    => true,
                    'sslverify'   => false
                ) );
            }
            wp_die();
        }
        function show_rate_window($html, $plugin_id) {
            $disabled = get_option('berocket_admin_notices_rate_stars');
            if( empty($disabled[$plugin_id]) || $disabled[$plugin_id]['time'] != 0 ) {
                $plugins = apply_filters('berocket_admin_notices_rate_stars_plugins', array());
                foreach($plugins as $plugin) {
                    if( $plugin['id'] == $plugin_id ) {
                        $html = '<div class="berocket_rate_plugin berocket-rate-stars-block berocket-rate-stars-plugin-page-'.$plugin['id'].'">
                            <h3>'.__('May we ask you to give us a 5-star feedback?', 'BeRocket_domain').'</h3>
                            <a class="berocket_rate_close brfirst"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="0"
                                data-later="0"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-function="berocket_rate_star_close_notice"
                                data-thanks_html=\'<picture><source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Thank-you.webp" alt="Feature Request"><img src="https://berocket.com/images/plugin/Thank-you.png" style="max-width: 100%;" alt="Feature Request"></picture><h3 class="berocket_thank_you_rate_us">'.__('Each good feedback is very important for plugin growth', 'BeRocket_domain').'</h3>\'
                                href="https://wordpress.org/support/plugin/'.$plugin['free_slug'].'/reviews/?filter=5#new-post"
                                target="_blank">'.__('Ok, you deserved it', 'BeRocket_domain').'</a>
                                <p>'.__('Support the plugin by setting good feedback.<br>We really need this.', 'BeRocket_domain').'</p>
                        </div>
                        <style>
                        .berocket_rate_plugin {
                            border-radius: 3px;
                            box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.06);
                            overflow: auto;
                            position: relative;
                            background-color: white;
                            color: rgba(0, 0, 0, 0.87);
                            padding: 0 25px;
                            margin-bottom: 30px;
                            box-sizing: border-box;
                            text-align: center;
                            float: right;
                            clear: right;
                            width: 28%;
                        }
                        .berocket_rate_plugin .berocket_rate_close {
                            margin-top: 30px;
                            margin-bottom: 20px;
                            color: #fff;
                            box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
                            text-shadow: none;
                            border: 0 none;
                            min-width: 120px;
                            width: 90%;
                            -moz-user-select: none;
                            background: #ff5252 none repeat scroll 0 0;
                            box-sizing: border-box;
                            cursor: pointer;
                            display: inline-block;
                            font-size: 14px;
                            outline: 0 none;
                            padding: 8px;
                            position: relative;
                            text-align: center;
                            text-decoration: none;
                            transition: box-shadow 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s, background-color 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s;
                            white-space: nowrap;
                            height: auto;
                            vertical-align: top;
                            line-height: 25px;
                            border-radius: 3px;
                            font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
                            font-weight: bold;

                            margin: 5px 0;
                            background: #97b9cf;
                            border: 2px solid #97b9cf;
                            color: white;
                        }
                        .berocket_rate_plugin img {
                            margin-top: 20px;
                        }
                        .berocket_rate_plugin .berocket_thank_you_rate_us {
                            color: #555;
                            margin-bottom: 35px;
                        }
                        .berocket_rate_plugin .berocket_rate_close:hover,
                        .berocket_rate_plugin .berocket_rate_close:focus,
                        .berocket_rate_plugin .berocket_rate_close:active{
                            color: white;
                            background: #87a9bf;
                            border: 2px solid #87a9bf;
                        }
                        @media screen and (min-width: 901px) and (max-width: 1200px) {
                            .berocket_rate_plugin{
                                padding-left: 10px;
                                padding-right: 10px;
                            }
                        }
                        @media screen and (max-width: 900px) {
                            .berocket_rate_plugin {
                                float: none;
                                width: 100%;
                                margin-top: 30px;
                                margin-bottom: 0;
                            }
                            .berocket_rate_plugin .berocket_rate_close{
                                float: none;
                                width: 100%;
                            }
                        }
                        </style>';
                        add_action('admin_footer', array($this, 'wp_footer_js'));
                        return $html;
                    }
                }
            }
            return $html;
        }

        public static function get_plugin_data($plugin_id = false) {
            $host = 'https://berocket.ams3.cdn.digitaloceanspaces.com/plugins/banners/';

            $plugins      = array(
                array(
                    'plugin_id' => 1,
                    'id'        => 1,
                    'price'     => '44',
                    'slug'      => 'ajax_filters',
                    'image'     => $host . 'Filters.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-filters.jpg?v=new',
                    'title'     => 'WooCommerce AJAX Products Filter',
                    'desc'      => "Increase conversions by making the product search easier and suitable for your customers' needs",
                    'desc_top'  => 'Get nice URLs and correct variations filtering for your shop with WooCommerce AJAX Products Filter for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-ajax-products-filter/?coupon=pfum3vap',
                    'bg'        => 'white',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8a46fd 60%)'
                ),
                array(
                    'plugin_id' => 18,
                    'id'        => 35,
                    'price'     => '34',
                    'slug'      => 'products_label',
                    'image'     => $host . 'Labels.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-labels.jpg?v=new',
                    'title'     => 'WooCommerce Advanced Product Labels',
                    'desc'      => "Capture client's attention on needed products. Create labels easily and quickly",
                    'desc_top'  => 'Capture client\'s attention on needed products. Create labels easily and quickly for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-advanced-product-labels/?coupon=pluwq5cq',
                    'bg'        => '#f2f2f2',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8b46fb 50%)'
                ),
                array(
                    'plugin_id' => 2,
                    'id'        => 3,
                    'price'     => '34',
                    'slug'      => 'list_grid',
                    'image'     => $host . 'GridList.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-gridlist.jpg?v=new',
                    'title'     => 'WooCommerce Grid/List View',
                    'desc'      => "Users need option to see more info. Add Grid/List toggle and Products per page to show more",
                    'desc_top'  => 'Users need option to see more info. Add Grid/List toggle and Products per page to show more for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-grid-list-view/?coupon=gluf79j8',
                    'bg'        => '#5f4a8b',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #7631fc 60%)'
                ),
                array(
                    'plugin_id' => 3,
                    'id'        => 5,
                    'price'     => '34',
                    'slug'      => 'BeRocket_LMP',
                    'image'     => $host . 'LoadMore.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-loadmore.jpg?v=new',
                    'title'     => 'WooCommerce Load More Products',
                    'desc'      => "Load next page' products with infinite scrolling, AJAX pagination or load more products button",
                    'desc_top'  => 'Load next page\' products with infinite scrolling, AJAX pagination or load more products button for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-load-more-products/?coupon=lmune6q5',
                    'bg'        => '#5f4a8b',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8a46fd 60%)'
                ),
                array(
                    'plugin_id' => 9,
                    'id'        => 17,
                    'price'     => '34',
                    'slug'      => 'MM_Quantity',
                    'image'     => $host . 'MinMax.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-minmax.jpg?v=new',
                    'title'     => 'WooCommerce Min/Max Quantity',
                    'desc'      => "Define quantity rules for orders, products and variations. Group the products and limit all of them together",
                    'desc_top'  => 'Define quantity rules for orders, products and variations. Group the products and limit all of them together for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-min-max-quantity/?coupon=mmumq2ts',
                    'bg'        => '#f5ebdd',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8244fd 55%)'
                ),
                array(
                    'plugin_id' => 10,
                    'id'        => 19,
                    'price'     => '34',
                    'slug'      => 'tab_manager',
                    'image'     => $host . 'Tabs.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-tabs.jpg?v=new1',
                    'title'     => 'WooCommerce Product Tabs Manager',
                    'desc'      => "Upgrade your tabs to a powerful marketing instrument. Show there related products or special info.",
                    'desc_top'  => 'Upgrade your tabs to a powerful marketing instrument. Show there related products or special info for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-product-tabs-manager/?coupon=tmuufxrb',
                    'bg'        => '#955188',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8346fd 60%)'
                ),
                array(
                    'plugin_id' => 14,
                    'id'        => 27,
                    'price'     => '34',
                    'slug'      => 'image_watermark',
                    'image'     => $host . 'Watermark.png',
                    'image_top' => 'https://e8e3g4v6.delivery.rocketcdn.me/wp-content/uploads/2022/11/top-banner-watermarks.jpg?v=new',
                    'title'     => 'WooCommerce Products Image Watermark',
                    'desc'      => "Don't let them steal it. Add watermarks to protect your images",
                    'desc_top'  => 'Don\'t let them steal it. Add watermarks to protect your images for only ${price}!',
                    'url'       => 'https://berocket.com/woocommerce-products-image-watermark/?coupon=iwujqp3m',
                    'bg'        => '#c2c3c5',
                    'bg_top'    => 'linear-gradient(to right, #b54df8, #8746fc 60%)'
                ),
            );
            $plugin_ids   = array_column( $plugins, 'plugin_id' );
            $plugins_data = BeRocket_Framework::get_product_data_berocket( implode( '-', $plugin_ids ) );

            if ( is_array( $plugins_data ) ) {
                foreach ( $plugins_data as $plugin_data ) {
                    if ( ! is_array( $plugin_data ) ) {
                        continue;
                    }

                    foreach ( $plugins as &$plugin ) {
                        if ( $plugin[ 'plugin_id' ] == berocket_isset( $plugin_data[ 'id' ] ) && isset( $plugin_data[ 'price' ] ) ) {
                            $plugin[ 'price' ] = $plugin_data[ 'price' ];
                            break;
                        }
                    }
                }
            }

            foreach ( $plugins as & $plugin ) {
                $plugin['desc_top'] = str_replace('{price}', $plugin['price'], $plugin['desc_top']);
            }

            if ( $plugin_id !== false ) {
                foreach ( $plugins as $plugin2 ) {
                    if ( $plugin2[ 'plugin_id' ] == $plugin_id ) {
                        return $plugin2;
                    }
                }

                return false;
            }

            return $plugins;
        }

        function show_ad_above_admin_settings($plugin_version_capability, $cur_plugin) {
            if( $plugin_version_capability < 10 ) {
	            $plugin = self::get_plugin_data($cur_plugin->info['id']);
	            if( $plugin === false ) {
		            $plugin = self::get_plugin_data( 1 );
	            }

	            $start_time = mktime(0, 0, 0, 4, 13, 2026);
	            $end_time   = mktime(23, 59, 59, 4, 17, 2026);
	            $c_notice   = berocket_admin_notices::get_notice_by_path(array(
                    19,
                    $end_time,
                    $start_time,
                    'spring_premium_days_2026'
                ));
	            $is_closed = false;
	            if ( ! isset( $c_notice['closed'] ) or $c_notice['closed'] > 0 ) {
		            $is_closed = true;
	            }

                if ( ! $is_closed and time() >= $start_time and time() < $end_time ) {
                    // do nothing
                } else {
	                $banner = [ "get_it_now"              => __( 'Get it now', 'BeRocket_domain' ),
                                "remove_banner"           => __( 'Remove banner', 'BeRocket_domain' ),
                                "unlock_premium"          => __( 'Unlock Premium', 'BeRocket_domain' ),
                                "upgrade_now"             => __( 'Upgrade Now', 'BeRocket_domain' ),
                                "go_premium"              => __( 'Go Premium', 'BeRocket_domain' ),
                                "unlock_all_features"     => __( 'Unlock All Features', 'BeRocket_domain' ),
                                "access_premium_features" => __( 'Access Premium Features', 'BeRocket_domain' ),
                                "power_up_your_store"     => __( 'Power Up Your Store', 'BeRocket_domain' ),
                                "remove_limits"           => __( 'Remove Limits', 'BeRocket_domain' ),
                                "unlock_everything"       => __( 'Unlock Everything', 'BeRocket_domain' ),
                                "remove_this_banner"      => __( 'Remove This Banner', 'BeRocket_domain' ) ];
	                $banner_key = array_rand( $banner );
	                echo "
                    <div class='berocket-above-settings-banner' style='background: {$plugin['bg_top']};'>
                        <div style='background-image: url(\"{$plugin['image_top']}\")'>
                            <div>
                                <h1>{$plugin['title']}</h1>
                                <p>" . ( empty( $plugin['desc_top'] ) ? $plugin['desc'] : $plugin['desc_top'] ) . "</p>
                                <a href='{$plugin['url']}" . ( str_contains( $plugin[ 'url' ], '?') ? '&' : '?' ) .
                                    "utm_source=plugin&utm_medium=banner&utm_campaign=upgrade&utm_content=top_" . $banner_key .
                                    "&utm_term={$cur_plugin->info['plugin_sku']}' target='_blank'>" . $banner[ $banner_key ] .
                                "</a>
                            </div>
                        </div>
                    </div>
                    ";
                }
                echo "
                <style>
                    .berocket-above-settings-banner {
                        width: 100%;
                        color: white;
                        border: 0 none;
                        position: relative;
                        margin: 5px 0 15px;
                        display: block;
                        padding: 0;
                        background: #b54df8;
                        align-items: center;
                        text-align: center;
                        height: 350px;
                    }
                    .berocket-above-settings-banner > div {
                        background-repeat: no-repeat;
                        background-color: transparent;
                        background-size: contain;
                        height: 100%;
                        vertical-align: middle;
                        display: flex;
                        flex-wrap: wrap;
                        align-items: center;
                        justify-content: center;
                    }
                    .berocket-above-settings-banner > div {
                        background-position: center right;
                        padding-right: 250px;
                    }
                    .berocket-above-settings-banner h1 {
                        color: white;
                        padding-bottom: 25px;
                        font-size: 45px;
                        max-width: 550px;
                        margin: 0 auto;
                        font-weight: 700;
                        text-align: center;
                        line-height: 1.1em; 
                    }
                    .berocket-above-settings-banner p {
                        color: white;
                        font-weight: 400;
                        font-size: 18px;
                        max-width: 700px;
                        margin: 0 auto 30px;
                        text-align: center;
                    }
                    .berocket-above-settings-banner a {
                        background: linear-gradient(to right, #ff1305, #fed549) !important;
                        border-radius: 50px !important;
                        padding: 10px 25px 12px !important;
                        min-width: 200px !important;
                        border: 0 !important;
                        text-shadow: none;
                        text-decoration: none;
                        display: inline-block;
                        transition: all 0.2s;
                        position: relative;
                        line-height: 1.4em !important;
                        font-weight: 400 !important;
                        font-size: 22px !important;
                        color: white !important;
                        margin: 5px 5px 15px !important;
                        text-align: center;
                        box-shadow: 0px 4px 12px 0 #3333333b !important;
                        cursor: pointer;
                    }
                    .berocket-cm21-settings {
                        text-align: left;
                        position: relative;
                    }
                    .berocket-cm21-settings > p{
                        font-size: 1.1em;
                        position: absolute;
                    }
                    .berocket-cm21-settings > p > span {
                        position: relative;
                        z-index: 100;
                    }
                    .berocket-cm21-settings > p:after {
                        content: '';
                        position: absolute;
                        left: -10px;
                        bottom: -2px;
                        background: linear-gradient(106deg, #ff30b8, #ffe390 50%, #41ebfd);
                        height: 10px;
                        width: 50%;
                        transform: skewX(-20deg);
                    }
                    .berocket-cm21-settings > p:before {
                        content: '';
                        position: absolute;
                        left: -8px;
                        bottom: 0;
                        background: #07002e;
                        height: 10px;
                        width: 50%;
                        transform: skewX(-20deg);
                        z-index: 10; 
                    }
                    .berocket-cm21-settings-header {
                        margin-top: 20px;
                        background: linear-gradient(106deg, #ff30b8, #ffe390 50%, #41ebfd);
                        padding: 3px;
                    }
                    .berocket-cm21-settings-header p {
                        font-size: 1.2em;
                        background: #07002e;
                        margin: 0;
                        padding: 12px 18px;
                    }
                    .berocket-cm21-settings-wrapper > a {
                        background: linear-gradient(46deg, #07002e 50%, #f743f4);
                        width: auto;
                        border: 0 none;
                        box-shadow: none;
                        padding: 0;
                        margin: 0;
                        display: flex;
                    }
                    @media (max-width: 1500px) {
                        .berocket-above-settings-banner a img {
                            max-height: 200px;
                        }
                        .berocket-cm21-settings-wrapper > a {
                            background: linear-gradient(46deg, #07002e 75%, #f743f4);
                        }
                        .berocket-cm21-settings-header {
                            padding: 2px;
                        }
                        .berocket-cm21-settings-header p {
                            font-size: 1.1em;
                            padding: 9px 14px;
                        }
                    }
                    @media (max-width: 1400px) {
                        .berocket-above-settings-banner {
                            height: 250px;
                        }
                        .berocket-above-settings-banner h1 {
                            font-size: 30px;
                            max-width: 400px;
                            padding-bottom: 15px;
                        }
                        .berocket-above-settings-banner p {
                            font-size: 16px;
                            max-width: 600px;
                            margin: 0 auto 10px;
                        }
                        .berocket-above-settings-banner a {
                            margin: 5px!important;
                        }
                    }
                    @media (max-width: 1200px) {
                        .berocket-above-settings-banner a img {
                            max-height: 150px;
                            max-width: 100%;
                        }
                        .berocket-cm21-settings-header {
                            margin-top: 10px;
                            margin-left: -35px;
                        }
                        .berocket-cm21-settings-header p {
                            font-size: 1em;
                            padding: 6px 11px;
                        }
                        .berocket-cm21-settings > p {
                            font-size: 0.8em;
                        }
                    }
                    @media (max-width: 1200px) {
                        .berocket-cm21-settings-wrapper a img {
                            width: 240px;
                            object-fit: cover;
                            height: 150px;
                        }
                        .berocket-cm21-settings-header {
                            margin-left: -15px;
                        }
                        .berocket-cm21-settings > p {
                            margin-top: 10px;
                        }
                    }
                    @media (max-width: 728px) {
                        .berocket-above-settings-banner > div {
                            background-image: none !important;
                            padding-right: 0;
                        }
                        .berocket-cm21-settings-header {
                            display: block;
                            height: 1px;
                            overflow: hidden;
                            border: 0;
                            padding: 0;
                            background: transparent;
                        }
                        .berocket-cm21-settings-header p{
                            background: transparent;
                        }
                        .berocket-cm21-settings > p {
                            margin-top: -15px;
                            margin-bottom: 30px;
                            margin-left: -10px;
                        }
                        .berocket-cm21-settings > p:nth-child(2n+1) {
                            margin-left: -40px;
                        }
                    }
                    @media (max-width: 620px) {
                        .berocket-cm21-settings > p {
                            display: none;
                        }
                        .berocket-cm21-settings-wrapper > a {
                            display: block;
                            background: linear-gradient(180deg, #07002e 75%, #5b0b5a);
                        }
                        .berocket-cm21-settings-mobiles-title {
                            display: block !important;
                            padding: 10px 10px 30px;
                            font-size: 20px;
                        }
                    }
                    @media (max-width: 400px) {
                        .berocket-above-settings-banner h1 {
                            font-size: 22px;
                        }
                        .berocket-above-settings-banner a {
                            padding: 10px 20px !important;
                        }
                    }
                </style>
                ";
            }
        }

        function show_related_window( $html, $plugin_id, $plugin, $location = 'sidebar' ) {
            add_action( 'admin_footer', array( $this, 'wp_footer_js' ) );
            $plugins = self::get_plugin_data();
            $plugins_use = [array_rand($plugins)];

            foreach($plugins_use as $plugin_use) {
                $plugin_data = $plugins[$plugin_use];
                $html .= '
                <div class="berocket_related_plugins berocket-related-plugins-page-' . $plugin_data[ 'id' ] . '">
                    <div style="background-color: ' . $plugin_data[ 'bg' ] . ';">
                        <img style="object-fit: cover;height: 100%;width: 100%;" src="' . $plugin_data[ 'image' ] . '" />
                    </div>
                    <div>
                        <div>
                            <h3>' . $plugin_data[ 'title' ] . '</h3>
                            <p>' . $plugin_data[ 'desc' ] . '</p>
                            <a class="brfirst" href="' . $plugin_data[ 'url' ]
                                . ( str_contains( $plugin_data[ 'url' ], '?') ? '&' : '?' )
                                . 'utm_source=plugin&utm_medium=settings&utm_term=' . ( $plugin->info['plugin_sku'] ?? $plugin->info['plugin_name'] )
                                . '&utm_campaign=upgrade&utm_content=sidebar"'
                                . ' target="_blank">From: $' . $plugin_data[ 'price' ] . '</a>
                        </div>
                    </div>
                </div>';
            }

            $html .= '
            <style>
            .berocket_related_plugins {
                border-radius: 3px;
                box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.06);
                overflow: auto;
                position: relative;
                background-color: white;
                color: rgba(0, 0, 0, 0.87);
                padding: 0;
                margin-bottom: 30px;
                box-sizing: border-box;
                text-align: center;
                float: right;
                clear: right;
                width: 28%;
                display: flex;
                align-items: stretch;
            }
            .berocket_related_plugins > div {
                box-sizing: border-box;
                display: flex;
                align-items: center;
                float: left;
                width: 45%;
            }
            .berocket_related_plugins > div:last-child {
                width: 55%;
                padding: 4px 10px;
            }
            .berocket_related_plugins > div h3 {
                margin-top: 0;
            }
            .berocket_related_plugins a {
                margin-top: 30px;
                margin-bottom: 20px;
                box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
                text-shadow: none;
                min-width: 120px;
                width: 70%;
                -moz-user-select: none;
                background-color: #a46497;
                background: linear-gradient(to right, #db16fc, #1d63c5) !important;
                box-sizing: border-box;
                cursor: pointer;
                display: inline-block;
                font-size: 17px;
                font-weight: 500;
                outline: 0 none;
                padding: 6px 10px;
                position: relative;
                text-align: center;
                text-decoration: none;
                transition: box-shadow 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s, background-color 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s;
                white-space: nowrap;
                height: auto;
                vertical-align: top;
                line-height: 25px;
                border-radius: 3px;
                font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
                margin: 5px 0;
                color: white;
            }
            .berocket_related_plugins a:hover {
                background: #ff6e68 none repeat scroll 0 0;
            }
            .berocket_related_plugins.berocket-related-plugins-page-1 > div:first-child {
                align-items: start;
            }
            @media screen and (min-width: 901px) and (max-width: 1700px), screen and (max-width: 500px) {
                .berocket_related_plugins > div h3 {
                    margin-bottom: 0;
                    font-size: 14px;
                }
                .berocket_related_plugins > div p {
                    margin-top: 5px;
                    margin-bottom: 5px;
                    font-size: 13px;
                    line-height: 1.3;
                }
                .berocket_related_plugins > div a {
                    padding: 1px 5px;
                    min-width: 100px;
                    width: 60%;
                }
            }
            @media screen and (max-width: 1400px) {
                .berocket_related_plugins > div {
                    width: 30%;
                }
                .berocket_related_plugins > div:last-child {
                    width: 70%;
                }
            }
            @media screen and (min-width: 901px) and (max-width: 1200px) {
                .berocket_related_plugins{
                    display: block;
                }
                .berocket_related_plugins > div{
                    float: none;
                    clear: both;
                    width: 100%;
                }
                .berocket_related_plugins > div:first-child {
                    height: 20px;
                    box-shadow: 0 0 4px 0px #ccc;
                    margin-bottom: 6px;
                }
                .berocket_related_plugins > div:last-child{
                    width: 100%;
                }
                .berocket_related_plugins > div:first-child img {
                    display: none;
                }
            }
            @media screen and (max-width: 900px) {
                .berocket_related_plugins {
                    float: none;
                    width: 100%;
                    margin-top: 30px;
                    margin-bottom: 0;
                }
            }
            </style>';

            return $html;
        }

        function show_feature_request_window($html, $plugin_id) {
            $disabled = get_option('berocket_admin_notices_rate_stars');
            $plugins = apply_filters('berocket_admin_notices_rate_stars_plugins', array());
            foreach($plugins as $plugin) {
                if( $plugin['id'] == $plugin_id ) {
                    add_action('admin_footer', array($this, 'wp_footer_js'));
                    $meta_data = '?utm_source=free_plugin&utm_medium=plugins&utm_campaign='.$plugin['plugin_name'];
                    $html .= '
                    <div class="berocket_feature_request berocket-feature-request berocket-feature-request-'.$plugin['id'].'">
                        <a class="berocket_feature_request_button" href="#feature_request">
                            <picture>
                                <source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Feature-request.webp" alt="Feature Request">
                                <img src="https://berocket.com/images/plugin/Feature-request.png" style="width: 100%;" alt="Feature Request">
                            </picture>
                        </a>
                        <div class="berocket_feature_request_form" style="display: none;">
                            <picture>
                                <source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Feature-request-form-title.webp" alt="Feature Request">
                                <img src="https://berocket.com/images/plugin/Feature-request-form-title.png" style="width: 100%;" alt="Feature Request">
                            </picture>
                            <form class="berocket_feature_request_inside">
                                <input name="brfeature_plugin" type="hidden" value="'.$plugin['id'].'">
                                <input name="wp_nonce" type="hidden" value="' . wp_create_nonce('berocket_feature_request_send') . '">
                                <input name="brfeature_title" placeholder="'.__('Feature Title', 'BeRocket_domain').'">
                                <input name="brfeature_email" placeholder="'.__('Email (optional)', 'BeRocket_domain').'">
                                <textarea name="brfeature_description" placeholder="'.__('Feature Description', 'BeRocket_domain').'"></textarea>
                                <button class="berocket_feature_request_submit" type="submit">'.__('SEND FEATURE REQUEST', 'BeRocket_domain').'</button>
                            </form>
                            <div style="margin-bottom: 10px;">* <small>This form will be sended to <a target="_blank" href="https://berocket.com' . $meta_data . '">berocket.com</a></small></div>
                        </div>
                        <div class="berocket_feature_request_thanks" style="display: none;">
                            <picture>
                                <source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Thank-you.webp" alt="Feature Request">
                                <img src="https://berocket.com/images/plugin/Thank-you.png" style="max-width: 100%;" alt="Feature Request">
                            </picture>';
                    if( empty($disabled[$plugin_id]) || $disabled[$plugin_id]['time'] != 0 ) {
                        $html .= '
                        <div class="berocket_feature_request_rate berocket-rate-stars-plugin-feature-'.$plugin_id.'">
                            <h3>'.__("While you're here, you could rate this plugin", 'BeRocket_domain').'</h3>
                            <ul class="berocket-rate-stars-block">
                            <li><a class="berocket_rate_close brfirst"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="0"
                                data-later="0"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-function="berocket_rate_star_close_notice"
                                data-thanks_html=\'<picture><source type="image/webp" srcset="'.plugin_dir_url( __FILE__ ).'../assets/images/Thank-you.webp" alt="Feature Request"><img src="https://berocket.com/images/plugin/Thank-you.png" style="max-width: 100%;" alt="Feature Request"></picture><h3 class="berocket_thank_you_rate_us">'.__('Each good feedback is very important for plugin growth', 'BeRocket_domain').'</h3>\'
                                href="https://wordpress.org/support/plugin/'.$plugin['free_slug'].'/reviews/?filter=5#new-post"
                                target="_blank">'.__('This plugin deserves 5 stars', 'BeRocket_domain').'</a></li>
                            <li><a class="berocket_rate_next_time brsecond"
                                href="#later">'.__("I'll rate it next time", 'BeRocket_domain').'</a></li>
                            <li><a class="berocket_rate_close brthird"
                                data-plugin="'.$plugin['id'].'"
                                data-action="berocket_rate_stars_close"
                                data-prevent="1"
                                data-later="0"
                                data-wp_nonce="' . wp_create_nonce('berocket_rate_stars_close') . '"
                                data-function="berocket_rate_star_close_notice"
                                href="#close">'.__('I already rated it', 'BeRocket_domain').'</a></li>
                            </ul>
                        </div>';
                    }
                        $html .= '</div>
                    </div>
                    <style>
                        .berocket_feature_request_inside input,
                        .berocket_feature_request_inside textarea,
                        .berocket_feature_request_submit {
                            width: 90%;
                        }
                        .berocket_feature_request_submit {
                            margin-top: 30px;
                            margin-bottom: 20px;
                            color: #fff;
                            box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
                            text-shadow: none;
                            border: 0 none;
                            min-width: 120px;
                            -moz-user-select: none;
                            background: #ff5252 none repeat scroll 0 0;
                            box-sizing: border-box;
                            cursor: pointer;
                            display: inline-block;
                            font-size: 14px;
                            outline: 0 none;
                            padding: 8px;
                            position: relative;
                            text-align: center;
                            text-decoration: none;
                            transition: box-shadow 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s, background-color 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) 0s;
                            white-space: nowrap;
                            height: auto;
                            vertical-align: top;
                            line-height: 25px;
                            border-radius: 3px;
                            font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
                            font-weight: bold;
                            margin: 5px 0 15px;
                            padding: 10px;
                        }
                        .berocket_feature_request_submit:hover,
                        .berocket_feature_request_submit:focus,
                        .berocket_feature_request_submit:active {
                            background: #ff6e68 none repeat scroll 0 0;
                            color: white;
                        }
                        .berocket_feature_request_button {
                            line-height: 0;
                            overflow: hidden;
                            display: inline-block;
                        }
                        .berocket_feature_request_form {
                            overflow: auto;
                        }
                        .berocket_feature_request_button,
                        .berocket_feature_request_form,
                        .berocket_feature_request_thanks {
                            border-radius: 3px;
                            box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.06);
                            position: relative;
                            background-color: white;
                            color: rgba(0, 0, 0, 0.87);
                            margin-bottom: 30px;
                            box-sizing: border-box;
                            text-align: center;
                            float: right;
                            clear: right;
                            width: 28%;
                        }
                        .berocket_feature_request_inside {
                            padding: 0 25px;
                        }
                        .berocket_feature_request_button img,
                        .berocket_feature_request_form img {
                            width: 100%;
                        }
                        .berocket_feature_request_inside input,
                        .berocket_feature_request_inside textarea {
                            outline: none;
                            box-shadow: none;
                            resize: none;
                            margin-bottom: 10px;
                            margin-top: 10px;
                            box-shadow: 0px 0px 15px #aaa;
                            border-radius: 3px;
                            padding: 10px;
                            border: 2px solid #FFFFFF;
                        }
                        .berocket_feature_request_inside textarea {
                            height: 150px;
                            overflow: auto;
                        }
                        @media screen and (min-width: 901px) and (max-width: 1200px) {
                            .berocket_feature_request_inside{
                                padding-left: 10px;
                                padding-right: 10px;
                            }
                        }
                        .berocket_feature_request_thanks .berocket_feature_request_rate ul {
                            margin-left: 20%;
                            list-style: disc;
                        }
                        @media screen and (max-width: 900px) {
                            .berocket_feature_request_thanks .berocket_feature_request_rate ul {
                                margin-left: -80px;
                                padding-left: 50%;
                            }
                            .berocket_feature_request {
                                margin-top: 30px;
                            }
                            .berocket_feature_request_button,
                            .berocket_feature_request_form,
                            .berocket_feature_request_thanks {
                                float: none;
                                width: 100%;
                                margin-bottom: 0;
                            }
                            .berocket_feature_request_inside input,
                            .berocket_feature_request_inside textarea,
                            .berocket_feature_request_submit{
                                float: none;
                                width: 100%;
                            }
                        }
                        .berocket_feature_request_inside input.brfeature_error,
                        .berocket_feature_request_inside textarea.brfeature_error {
                            box-shadow: 0px 0px 15px #f00;
                            border-color: #ff0000;
                            animation-name: brfeature_error;
                            animation-duration: 2s;
                        }
                        @keyframes brfeature_error {
                            0%   {border-color: #ffffff;}
                            10%  {border-color: #ff0000;}
                            20%  {border-color: #ff9999;}
                            30% {border-color: #ff0000;}
                            40%   {border-color: #ff9999;}
                            50%  {border-color: #ff0000;}
                            60%  {border-color: #ff9999;}
                            70% {border-color: #ff0000;}
                            80%   {border-color: #ff9999;}
                            100%  {border-color: #ff0000;}
                        }
                        .berocket_feature_request_thanks {
                            padding-top: 20px;
                            padding-bottom: 20px;
                        }
                        .berocket_feature_request_thanks .berocket_feature_request_rate h3 {
                            color: #555;
                        }
                        .berocket_feature_request_thanks .berocket_feature_request_rate ul li {
                            text-align: left;
                        }
                    </style>';
                    return $html;
                }
            }
        }
        function wp_footer_js() {
            ?>
            <script>
                jQuery(document).on('click', '.berocket-rate-stars-block .berocket_rate_close', function(event) {
                    var $this = jQuery(this);
                    if( $this.data('prevent') ) {
                        event.preventDefault();
                    }
                    var data = $this.data();
                    if( $this.data('function') ) {
                        if( typeof(window[$this.data('function')]) == 'function' ) {
                            window[$this.data('function')](data);
                        }
                    }
                    jQuery.post(ajaxurl, data, function(result) {
                        if( $this.data('function_after') ) {
                            if( typeof(window[$this.data('function_after')]) == 'function' ) {
                                window[$this.data('function_after')](result, data);
                            }
                        }
                    });
                });
                function berocket_rate_star_close_notice(button_data) {
                    jQuery('.berocket-rate-stars-'+button_data.plugin).slideUp('100');
                    console.log(button_data);
                    if( ! button_data.prevent ) {
                        jQuery('.berocket-rate-stars-plugin-page-'+button_data.plugin).html(button_data.thanks_html);
                        jQuery('.berocket-rate-stars-plugin-feature-'+button_data.plugin).slideUp(100);
                    }
                    if( button_data.prevent && ! button_data.later ) {
                        jQuery('.berocket-rate-stars-plugin-page-'+button_data.plugin).slideUp(100);
                        jQuery('.berocket-rate-stars-plugin-feature-'+button_data.plugin).slideUp(100);
                    }
                }
                jQuery(document).on('click', '.berocket_feature_request_button', function(event) {
                    event.preventDefault();
                    var $this = jQuery(this);
                    $this.hide();
                    $this.parents('.berocket_feature_request').find('.berocket_feature_request_form').show();
                });
                jQuery(document).on('submit', '.berocket_feature_request_inside', function(event) {
                    event.preventDefault();
                    var form_data = jQuery(this).serialize();
                    var send = true;
                    if( ! jQuery(this).find('[name=brfeature_title]').val() ) {
                        send = false;
                        jQuery(this).find('[name=brfeature_title]').addClass('brfeature_error');
                    }
                    if( ! jQuery(this).find('[name=brfeature_description]').val() ) {
                        send = false;
                        jQuery(this).find('[name=brfeature_description]').addClass('brfeature_error');
                    }
                    if( send ) {
                        form_data = form_data+'&action=berocket_feature_request_send';
                        jQuery.post(ajaxurl, form_data);
                        jQuery(this).parents('.berocket_feature_request_form').hide().parents('.berocket_feature_request').find('.berocket_feature_request_thanks').show();
                    }
                });
                jQuery(document).on('change', '.brfeature_error', function() {
                    jQuery(this).removeClass('brfeature_error');
                });
                jQuery(document).on('click', '.berocket_feature_request_rate .berocket_rate_close', function(event) {
                    jQuery(this).parents('.berocket_feature_request_rate').slideUp(100);
                });
                jQuery(document).on('click', '.berocket_rate_next_time', function(event) {
                    event.preventDefault();
                    jQuery(this).parents('.berocket_feature_request_rate').slideUp(100);
                });
            </script>
            <?php
        }
    }
    new berocket_admin_notices_rate_stars;
}
