'wpbc-ajx_booking_availability', // Name of page, where to load feedback. Defined in pages, like this: do_action( 'wpbc_hook_settings_page_footer', 'wpbc-ajx_booking_availability' ); 'max_version' => '12.0', // If version of Booking Calendar 12.0 or newer than do not show this Feedback 'feedback_email' => 'feedback2@wpbookingcalendar.com' ); return $defaults[ $param_name ]; } class WPBC_Feedback_01 { // // A J A X ===================================================================================================== /** * Define HOOKs for start loading Ajax */ public function define_ajax_hook(){ // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php add_action( 'wp_ajax_' . 'WPBC_AJX_FEEDBACK', array( $this, 'ajax_' . 'WPBC_AJX_FEEDBACK' ) ); // Admin & Client (logged in usres) // Ajax Handlers for actions // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in) } /** * Ajax - Get Listing Data and Response to JS script */ public function ajax_WPBC_AJX_FEEDBACK() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing if ( ! isset( $_POST['action_params'] ) || empty( $_POST['action_params'] ) ) { exit; } $ajax_errors = new WPBC_AJAX_ERROR_CATCHING(); // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), $action_name = 'wpbc_ajx__feedback_ajx' . '_wpbcnonce'; $nonce_post_key = 'nonce'; $result_check = check_ajax_referer( $action_name, $nonce_post_key ); $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing /** * SQL --------------------------------------------------------------------------- * * in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params() * * Use prefix "search_params", if Ajax sent - * $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],.. */ $user_request = new WPBC_AJX__REQUEST( array( 'db_option_name' => 'booking_feedback_request_params', 'user_id' => $user_id, 'request_rules_structure' => array( 'booking_action' => array( 'validate' => array( 'feedback_01' ), 'default' => 'none' ) , 'feedback_stars' => array( 'validate' => 'd', 'default' => 0 ) , 'feedback__note' => array( 'validate' => 's', 'default' => '' ) , 'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' ) ) ) ); $request_prefix = 'action_params'; $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['action_params']['feedback_stars'] //---------------------------------------------------------------------------------------------------------- $action_result = wpbc_booking_do_action__feedback_01( $request_params , array( 'user_id' => $user_id ) ); $defaults = array( 'new_listing_params' => false // required for Import Google Calendar bookings , 'after_action_result' => false /* translators: 1: ... */ , 'after_action_message' => sprintf( __( 'No actions %s has been processed.', 'booking') , ' ' . $request_params['booking_action'] . ' ' ) ); $action_result = wp_parse_args( $action_result, $defaults ); // Check if there were some errors -------------------------------------------------------------------------------- $error_messages = $ajax_errors->get_error_messages(); if ( ! empty( $error_messages ) ) { $action_result['after_action_message'] .= $error_messages; } //------------------------------------------------------------------------------------------------------------------ // Send JSON. Its will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success. wp_send_json( array( // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 'ajx_action_params' => $_REQUEST['action_params'], // Do not clean input parameters 'ajx_cleaned_params' => $request_params, // Cleaned input parameters 'ajx_after_action_message' => $action_result['after_action_message'], // Message to show 'ajx_after_action_result' => (int) $action_result['after_action_result'], // Result key 0 | 1 'ajx_after_action_result_all_params_arr' => $action_result // All result parameters ) ); } // /** * Define HOOKs for loading CSS and JavaScript files */ public function init_load_css_js() { // JS & CSS add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 ); add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 ); // Template add_action( 'wpbc_hook_settings_page_footer', array( $this, 'wpbc_hidden_template__content_for_feedback_01' ), 50 ); } /** JSS */ public function js_load_files( $where_to_load ) { $in_footer = true; if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { wp_enqueue_script( 'wpbc-feedback_02', trailingslashit( plugins_url( '', __FILE__ ) ) . 'feedback.js' /* wpbc_plugin_url( '/_out/js/code_mirror.js' ) */ , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); /** wp_localize_script( 'wpbc_all', 'wpbc_live_request_obj' , array( 'contacts' => '', 'reminders' => '' ) ); */ } } /** CSS */ public function enqueue_css_files( $where_to_load ) { if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { wp_enqueue_style( 'wpbc-feedback_02', trailingslashit( plugins_url( '', __FILE__ ) ) . 'feedback.css', array(), WP_BK_VERSION_NUM ); } } /** Feedback Layout - Modal Window structure */ function wpbc_hidden_template__content_for_feedback_01( $page ) { if ( wpbc_get_feedback_defaults( 'page_where_load' ) != $page ) { // Load feedback only at this page return false; } if ( wpbc_is__feedback_01__timeout_need_to_show() ) { // Check if time go out update_option( 'booking_feedback_04', '' ); } else { return false; } // Nonce for Ajax and some other data ?>
' . $feedback_stars . '/5' ); if ( 'remind_later' == $feedback__note ) { $after_action_message = __( 'Done', 'booking' ); // Update new period for showing Feedback $feedback_date = gmdate('Y-m-d H:i:s', strtotime( WPBC_FEEDBACK_TIMEOUT, strtotime( 'now' ) ) ); update_option('booking_feedback_04', $feedback_date ); } elseif ( ( $feedback_stars > 0 ) && ( $feedback_stars <= 5 ) ) { // Send email wpbc_feedback_01__send_email( $feedback_stars, $feedback__note ); update_option('booking_feedback_04_rating', $feedback_stars ); } if ( ( 5 == $feedback_stars ) && ( 'rate5' != $feedback__note ) ) { $feedback_stars = 0; } return array( 'after_action_result' => $after_action_result, 'after_action_message' => $after_action_message, 'feedback_stars' => $feedback_stars ); } /** * Send email with feedback * * @param $stars_num * @param $feedback_description * * @return void */ function wpbc_feedback_01__send_email( $stars_num, $feedback_description ) { $us_data = wp_get_current_user(); $fields_values = array(); $fields_values['from_email'] = get_option( 'admin_email' ); $fields_values['from_name'] = $us_data->display_name; $fields_values['from_name'] = wp_specialchars_decode( esc_html( stripslashes( $fields_values['from_name'] ) ), ENT_QUOTES ); $fields_values['from_email'] = sanitize_email( $fields_values['from_email'] ); $subject = 'Booking Calendar Feedback ' . $stars_num . '/5'; $message = '=============================================' . "\n"; $message .= $feedback_description . "\n"; $message .= '=============================================' . "\n"; $message .="\n"; $message .= $fields_values['from_name'] . "\n"; $message .="\n"; $message .= 'Booking Calendar Rating: ' . $stars_num . '/5' . "\n"; $message .= '---------------------------------------------' . "\n"; $message .= 'Booking Calendar ' . wpbc_feedback_01_get_version() . "\n"; $how_old_info_arr = wpbc_get_info__about_how_old(); if ( ! empty( $how_old_info_arr ) ) { $message .= "\n"; $message .= 'From: ' . $how_old_info_arr['date_echo']; $message .= ' - ' . $how_old_info_arr['days'] . ' days ago.'; } $message .="\n"; $message .= '---------------------------------------------' . "\n"; $message .= '[' . date_i18n( get_bk_option( 'booking_date_format' ) ) . ' ' . date_i18n( get_bk_option( 'booking_time_format' ) ) . ']'. "\n"; $message .= home_url() ; $headers = ''; if ( ! empty( $fields_values['from_email'] ) ) { $headers .= 'From: ' . $fields_values['from_name'] . ' <' . $fields_values['from_email'] . '> ' . "\r\n"; } else { /* If we don't have an email from the input headers default to wordpress@$sitename * Some hosts will block outgoing mail from this address if it doesn't exist but * there's no easy alternative. Defaulting to admin_email might appear to be another * option but some hosts may refuse to relay mail from an unknown domain. See * https://core.trac.wordpress.org/ticket/5007. */ } $headers .= 'Content-Type: ' . 'text/plain' . "\r\n" ; // 'text/html' $attachments = ''; $to = wpbc_get_feedback_defaults( 'feedback_email' ); // debuge('In email', htmlentities($to), $subject, htmlentities($message), $headers, $attachments) ; // debuge( '$to, $subject, $message, $headers, $attachments',htmlspecialchars($to), htmlspecialchars($subject), htmlspecialchars($message), htmlspecialchars($headers), htmlspecialchars($attachments)); if ( wpbc_email_api_is_allow_send( true, '', '' ) ) { $return = wp_mail( $to, $subject, $message, $headers, $attachments ); } } /** * Get data about Booking Calendar version. Support function * @return string */ function wpbc_feedback_01_get_version(){ // if ( substr( WPDEV_BK_VERSION, 0, 3 ) == '11.' ) { // $show_version = substr( WPDEV_BK_VERSION, 3 ); // if ( substr( $show_version, ( - 1 * ( strlen( WP_BK_VERSION_NUM ) ) ) ) === WP_BK_VERSION_NUM ) { // $show_version = substr( $show_version, 0, ( - 1 * ( strlen( WP_BK_VERSION_NUM ) ) - 1 ) ); // $show_version = str_replace( '.', ' ', $show_version ) . ' ' . WP_BK_VERSION_NUM; // } // // } else { // $show_version = WPDEV_BK_VERSION; // } $show_version = wpbc_get_wpbc_versions_numbers(); $ver = wpbc_get_plugin_version_type(); if ( class_exists( 'wpdev_bk_multiuser' ) ) { $ver = 'MultiUser'; } $ver = str_replace( '_m', ' Medium', $ver ); $ver = str_replace( '_l', ' Large', $ver ); $ver = str_replace( '_s', ' Small', $ver ); $ver = str_replace( 'biz', 'Business', $ver ); $ver = ucwords( $ver ); $v_type = ''; if ( strpos( strtolower( WPDEV_BK_VERSION ), 'multisite' ) !== false ) { $v_type = '5'; } else if ( strpos( strtolower( WPDEV_BK_VERSION ), 'develop' ) !== false ) { $v_type = '2'; } if ( ! empty( $v_type ) ) { $v_type = ' ' . $v_type . ' ' . __( 'websites', 'booking' ); } else { $v_type = ' 1' . ' ' . __( 'website', 'booking' ); } return $ver . ' (' . $show_version . ') ' . ( ( 'Free' !== $ver ) ? ' :: ' . $v_type . '.' : '' ) . ' :: ' . gmdate( "d.m.Y", filemtime( WPBC_FILE ) ); } /** * Check if we need to show the Feedback - is it Timer expired already ? * @return bool */ function wpbc_is__feedback_01__timeout_need_to_show() { //return true; $feedback_01_date = get_option( 'booking_feedback_04' ); if ( ( ! empty( $feedback_01_date ) ) && ( ( strtotime( 'now' ) - strtotime( $feedback_01_date ) ) > 0 ) ) { return true; } else { return false; } } /** * Set timer to show Feedback after this amount of time * @return void */ function wpbc_is__feedback_01__timer_install() { // If version of Booking Calendar 9.6 (e.g. 'max_version') or newer than do not show this Feedback if ( version_compare( WP_BK_VERSION_NUM, wpbc_get_feedback_defaults( 'max_version' ) , '>=') ) { return false; } $feedback_date = gmdate( 'Y-m-d H:i:s', strtotime( WPBC_FEEDBACK_TIMEOUT, strtotime( 'now' ) ) ); add_option( 'booking_feedback_04', $feedback_date ); } add_bk_action( 'wpbc_before_activation' , 'wpbc_is__feedback_01__timer_install' ); /** * Just for loading CSS and JavaScript files and define Ajax hook */ if ( ( ! wpbc_is_this_demo() ) ) { $wpbc_js_css_loading = new WPBC_Feedback_01; $wpbc_js_css_loading->define_ajax_hook(); if ( ! empty( get_option( 'booking_feedback_04' ) ) ){ $wpbc_js_css_loading->init_load_css_js(); } }