| @@ -14,46 +14,60 @@ | ||
| 14 | 14 | |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 16 | 16 | |
| 17 | 17 | |
| 18 | +class WPBC_Notices { | |
| 18 | 19 | |
| 19 | -class WPBC_Notices { | |
| 20 | + private $messages = array(); | |
| 20 | 21 | |
| 21 | - private $messages = array(); | |
| 22 | - | |
| 23 | - function __construct() { | |
| 24 | - $this->hooks(); | |
| 25 | - } | |
| 22 | + /** | |
| 23 | + * Constructor. | |
| 24 | + */ | |
| 25 | + public function __construct() { | |
| 26 | 26 | |
| 27 | + $this->hooks(); | |
| 28 | + } | |
| 27 | 29 | |
| 28 | - private function hooks(){ | |
| 29 | - add_action( 'init', array( $this, 'set_messages' ) ); // FixIn: 10.6.5.1. | |
| 30 | 30 | |
| 31 | - add_action('wpbc_hook_booking_page_header', array( $this, 'show_system_messages') ); | |
| 32 | - add_action('wpbc_hook_add_booking_page_header', array( $this, 'show_system_messages') ); | |
| 31 | + /** | |
| 32 | + * Hooks. | |
| 33 | + * | |
| 34 | + * @return void | |
| 35 | + */ | |
| 36 | + private function hooks() { | |
| 33 | 37 | |
| 34 | - add_action('wpbc_hook_settings_page_header', array( $this, 'show_system_messages') ); | |
| 35 | - } | |
| 38 | + // Define Messages. | |
| 39 | + add_action( 'init', array( $this, 'set_messages' ) ); | |
| 36 | 40 | |
| 37 | - // FixIn: 10.6.5.1. | |
| 38 | - public function set_messages(){ | |
| 41 | + // Where to show messages ? | |
| 42 | + add_action( 'wpbc_hook_booking_page_header', array( $this, 'show_system_messages' ) ); | |
| 43 | + add_action( 'wpbc_hook_add_booking_page_header', array( $this, 'show_system_messages' ) ); | |
| 44 | + add_action( 'wpbc_hook_settings_page_header', array( $this, 'show_system_messages' ) ); | |
| 45 | + } | |
| 39 | 46 | |
| 40 | - $this->messages['updated_paid_to_free'] = '<strong>' . esc_html__('Warning!' ,'booking') . '</strong> ' | |
| 41 | - /* translators: 1: ... */ | |
| 42 | - . sprintf( __( 'Probably you updated your paid version of Booking Calendar by free version or update process failed. You can request the new update of your paid version at %1$sthis page%2$s.', 'booking') | |
| 43 | - , '<a href="https://wpbookingcalendar.com/request-update/" target="_blank">', '</a>' ); | |
| 44 | - } | |
| 45 | 47 | |
| 48 | + /** | |
| 49 | + * Define messageas. | |
| 50 | + * | |
| 51 | + * @return void | |
| 52 | + */ | |
| 53 | + public function set_messages() { | |
| 46 | 54 | |
| 47 | - /** | |
| 48 | - * Define secion for the system messages at the admin panel and show System Messages. | |
| 49 | - * | |
| 50 | - * @param type $my_page | |
| 51 | - */ | |
| 52 | - public function show_system_messages($my_page) { | |
| 55 | + $this->messages['updated_paid_to_free'] = '<strong>' . esc_html__( 'Warning!', 'booking' ) . '</strong> ' . | |
| 56 | + /* translators: 1: ... */ | |
| 57 | + sprintf( __( 'Probably you updated your paid version of Booking Calendar by free version or update process failed. You can request the new update of your paid version at %1$sthis page%2$s.', 'booking' ), '<a href="https://wpbookingcalendar.com/request-update/" target="_blank">', '</a>' ); | |
| 58 | + } | |
| 53 | 59 | |
| 54 | 60 | |
| 61 | + /** | |
| 62 | + * Define secion for the system messages at the admin panel and show System Messages. | |
| 63 | + * | |
| 64 | + * @param string $my_page - tag of the page. | |
| 65 | + */ | |
| 66 | + public function show_system_messages( $my_page ) { | |
| 67 | + | |
| 55 | 68 | if (! empty($this->messages['updated_paid_to_free'])){ |
| 69 | + | |
| 56 | 70 | ?><div class="wpbc_admin_system_message wpbc_page_<?php echo esc_attr( $my_page ); ?>"><?php |
| 57 | 71 | |
| 58 | 72 | /** Static messages - user need to click for closing these messages */ |
| 59 | 73 | |
| @@ -63,86 +77,58 @@ | ||
| 63 | 77 | } |
| 64 | 78 | |
| 65 | 79 | ?></div><?php |
| 66 | 80 | } |
| 67 | - /** Dynamic messages - auto-hide, after specific number of seconds */ | |
| 68 | - | |
| 69 | -// if ( wpbc_is_updated_paid_to_free() ) | |
| 70 | -// $this->show_message( $this->messages['updated_paid_to_free'] , 20 ); | |
| 71 | - | |
| 72 | 81 | } |
| 73 | - | |
| 74 | - | |
| 75 | - /** | |
| 76 | - * Show System Message(s) at the top of the admin page. | |
| 77 | - * | |
| 78 | - * @param string $message | |
| 79 | - * @param int $time_to_show -in seconds if 0 then do not hide message | |
| 80 | - * @param string $message_type : 'updated' | 'error' | |
| 81 | - */ | |
| 82 | - public function show_message ( $message, $time_to_show , $message_type = 'updated') { | |
| 83 | - | |
| 84 | - // Generate unique HTML ID for the message | |
| 85 | - $inner_message_id = intval( time() * wp_rand(10, 100) ); | |
| 86 | - | |
| 87 | - // Get formated HTML message | |
| 88 | - $notice = $this->get_formated_message( $message, $message_type, $inner_message_id ); | |
| 89 | - | |
| 90 | - // Get the time of message showing | |
| 91 | - $time_to_show = intval($time_to_show)*1000; | |
| 92 | - | |
| 93 | - // Show this Message | |
| 94 | - ?> <script type="text/javascript"> | |
| 95 | - if ( jQuery('.wpbc_admin_message').length ) { | |
| 96 | - jQuery('.wpbc_admin_message').append( '<?php | |
| 97 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 98 | - echo $notice ; ?>' ); | |
| 99 | - <?php if ( $time_to_show > 0 ) { ?> | |
| 100 | - jQuery('#wpbc_inner_message_<?php echo esc_attr( $inner_message_id ); ?>').animate({opacity: 1},<?php echo esc_attr( $time_to_show ); ?>).fadeOut( 2000 ); | |
| 101 | - <?php } ?> | |
| 102 | - } | |
| 103 | - </script> <?php | |
| 104 | - } | |
| 105 | - | |
| 106 | - | |
| 107 | - private function get_formated_message ( $message, $message_type = 'updated', $inner_message_id = '') { | |
| 108 | - | |
| 109 | 82 | |
| 110 | - // Recheck for any "lang" shortcodes for replacing to correct language | |
| 111 | - $message = wpbc_lang( $message ); | |
| 112 | - | |
| 113 | - // Escape any JavaScript from message | |
| 114 | - $notice = html_entity_decode( esc_js( $message ) ,ENT_QUOTES) ; | |
| 115 | - | |
| 116 | - $notice .= '<a class="close tooltip_left" rel="tooltip" title="'. esc_js(__("Hide" ,'booking')). '" data-dismiss="alert" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().hide();">×</a>'; | |
| 117 | 83 | |
| 118 | - // $my_close_open_alert_id = 'wpbc_system_message_id_'; | |
| 119 | - // $notice .= '<a class="close tooltip_left" rel="tooltip" title="'. esc_js(__("Don't show the message anymore" ,'booking')). '" data-dismiss="alert" href="javascript:void(0)" onclick="javascript:wpbc_verify_window_opening('. wpbc_get_current_user_id() .', \''. $my_close_open_alert_id .'\');">×</a>'; | |
| 120 | - if (! empty( $inner_message_id )) | |
| 121 | - $inner_message_id = 'id="wpbc_inner_message_'. $inner_message_id .'"'; | |
| 122 | - | |
| 123 | - $notice = '<div '.$inner_message_id.' class="wpbc_inner_message '. $message_type . '">' . $notice . '</div>'; | |
| 124 | - | |
| 84 | + | |
| 85 | + private function get_formated_message( $message, $message_type = 'updated', $inner_message_id = '' ) { | |
| 86 | + | |
| 87 | + | |
| 88 | + // Recheck for any "lang" shortcodes for replacing to correct language. | |
| 89 | + $message = wpbc_lang( $message ); | |
| 90 | + | |
| 91 | + // Escape any JavaScript from message. | |
| 92 | + $notice = html_entity_decode( esc_js( $message ), ENT_QUOTES ); | |
| 93 | + | |
| 94 | + if ( ! empty( $inner_message_id ) ) { | |
| 95 | + $inner_message_id_attr = 'id="wpbc_inner_message_' . $inner_message_id . '"'; | |
| 96 | + } else { | |
| 97 | + $inner_message_id_attr = ''; | |
| 98 | + } | |
| 99 | + | |
| 100 | + | |
| 101 | + $notice_hide = '<a style="border-radius: 7px;margin: 10px 0 0 30px;float: right;font-weight: 600;text-decoration: underline;" title="' . esc_js( __( "Hide", 'booking' ) ) . '" href="javascript:void(0)" onclick="javascript:jQuery(this).parent().parent().fadeOut( 500 );">' . esc_html( __( 'Hide', 'booking' ) ) . '</a>'; | |
| 102 | + $wpbc_metabox_id = 'wpbc_message_update_free_to_paid'; | |
| 103 | + | |
| 104 | + ob_start(); | |
| 105 | + $is_panel_visible = wpbc_is_dismissed( $wpbc_metabox_id, array( | |
| 106 | + 'title' => __( 'Dismiss', 'booking' ), // ' <i class="menu_icon icon-1x wpbc_icn_close"></i> ', // ×. | |
| 107 | + 'hint' => __( 'Dismiss Forever', 'booking' ), | |
| 108 | + 'class' => 'wpbc_message_update_free_to_paid', | |
| 109 | + 'css' => 'border-radius: 7px;margin: 10px 0 0 30px;text-decoration: underline;', | |
| 110 | + ) ); | |
| 111 | + ?> | |
| 112 | + <script type="text/javascript"> | |
| 113 | + jQuery( '#<?php echo esc_js( $wpbc_metabox_id ); ?> .wpbc_message_update_free_to_paid' ).on( 'click', function (event) { | |
| 114 | + jQuery( '#<?php echo esc_attr( $wpbc_metabox_id ); ?>' ).parent().fadeOut(500); | |
| 115 | + } ); | |
| 116 | + </script> | |
| 117 | + <?php | |
| 118 | + $dismiss_button_content = ob_get_clean(); | |
| 119 | + | |
| 120 | + if ( $is_panel_visible ) { | |
| 121 | + | |
| 122 | + $notice = '<div ' . $inner_message_id_attr . ' class="wpbc_inner_message ' . $message_type . '"><div id="' . esc_attr( $wpbc_metabox_id ) . '">' . | |
| 123 | + $dismiss_button_content . | |
| 124 | + $notice_hide . | |
| 125 | + $notice . | |
| 126 | + '</div></div>'; | |
| 127 | + } else { | |
| 128 | + $notice = ''; | |
| 129 | + } | |
| 130 | + | |
| 125 | 131 | return $notice; |
| 126 | 132 | } |
| 127 | - | |
| 128 | - /* | |
| 129 | - function show_alert($message) { | |
| 130 | - | |
| 131 | - $alert_head = __('Note' ,'booking'); | |
| 132 | - | |
| 133 | - $my_close_open_alert_id = 'bk_alert_settings_form_in_free'; | |
| 134 | - | |
| 135 | - ?> | |
| 136 | - <div class="alert alert-warning alert-block alert-info <?php if ( '1' == get_user_option( 'booking_win_' . $my_close_open_alert_id ) ) echo 'closed'; ?>" | |
| 137 | - id="<?php echo esc_attr( $my_close_open_alert_id ); ?>"> | |
| 138 | - <a class="close tooltip_left" rel="tooltip" title="<?php esc_attr_e("Don't show the message anymore" ,'booking');?>" data-dismiss="alert" | |
| 139 | - href="javascript:void(0)" | |
| 140 | - onclick="javascript:wpbc_verify_window_opening(<?php echo esc_attr( wpbc_get_current_user_id() ); ?>, '<?php echo esc_attr( $my_close_open_alert_id ); ?>');" | |
| 141 | - >×</a> | |
| 142 | - <strong class="alert-heading"><?php echo esc_html( $alert_head ); ?></strong><?php echo esc_attr( $message ); ?> | |
| 143 | - </div> | |
| 144 | - <?php | |
| 145 | - }*/ | |
| 146 | - | |
| 147 | 133 | } |
| 148 | 134 | |