| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Tour |
| 5 |
* @subpackage Tour in Booking Calendar |
| 6 |
* @category Tour |
| 7 |
* |
| 8 |
* @author wpdevelop |
| 9 |
* @link https://wpbookingcalendar.com/ |
| 10 |
* @email info@wpbookingcalendar.com |
| 11 |
* |
| 12 |
* @modified 2024-07-31 |
| 13 |
*/ |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; |
| 17 |
} // Exit if accessed directly |
| 18 |
|
| 19 |
// FixIn: 10.4.0.1. |
| 20 |
|
| 21 |
class WPBC_Tour_01 { |
| 22 |
|
| 23 |
// <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " > |
| 24 |
|
| 25 |
// A J A X ===================================================================================================== |
| 26 |
|
| 27 |
/** |
| 28 |
* Define HOOKs for start loading Ajax |
| 29 |
*/ |
| 30 |
public function define_ajax_hook() { |
| 31 |
|
| 32 |
// Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php |
| 33 |
add_action( 'wp_ajax_' . 'WPBC_AJX_FEEDBACK', array( $this, 'ajax_' . 'ajax_WPBC_AJX_Response' ) ); // Admin & Client (logged in usres) |
| 34 |
|
| 35 |
// Ajax Handlers for actions |
| 36 |
// add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in) |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Ajax - Get Listing Data and Response to JS script |
| 42 |
*/ |
| 43 |
public function ajax_WPBC_AJX_Response() { |
| 44 |
|
| 45 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 46 |
if ( ! isset( $_POST['action_params'] ) || empty( $_POST['action_params'] ) ) { |
| 47 |
exit; |
| 48 |
} |
| 49 |
|
| 50 |
$ajax_errors = new WPBC_AJAX_ERROR_CATCHING(); |
| 51 |
|
| 52 |
// Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ), |
| 53 |
$action_name = 'wpbc_ajx__feedback_ajx' . '_wpbcnonce'; |
| 54 |
$nonce_post_key = 'nonce'; |
| 55 |
$result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 56 |
|
| 57 |
$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 |
| 58 |
|
| 59 |
/** |
| 60 |
* SQL --------------------------------------------------------------------------- |
| 61 |
* |
| 62 |
* in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params() |
| 63 |
* |
| 64 |
* Use prefix "search_params", if Ajax sent - |
| 65 |
* $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],.. |
| 66 |
*/ |
| 67 |
|
| 68 |
$user_request = new WPBC_AJX__REQUEST( array( |
| 69 |
'db_option_name' => 'booking_feedback_request_params', |
| 70 |
'user_id' => $user_id, |
| 71 |
'request_rules_structure' => array( |
| 72 |
'booking_action' => array( 'validate' => array( 'feedback_01' ), 'default' => 'none' ), |
| 73 |
'feedback_stars' => array( 'validate' => 'd', 'default' => 0 ), |
| 74 |
'feedback__note' => array( 'validate' => 's', 'default' => '' ), |
| 75 |
'ui_clicked_element_id' => array( 'validate' => 's', 'default' => '' ) |
| 76 |
) |
| 77 |
) |
| 78 |
); |
| 79 |
$request_prefix = 'action_params'; |
| 80 |
$request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['action_params']['feedback_stars'] |
| 81 |
|
| 82 |
//---------------------------------------------------------------------------------------------------------- |
| 83 |
|
| 84 |
$action_result = wpbc_booking_do_action__feedback_01( $request_params |
| 85 |
, array( |
| 86 |
'user_id' => $user_id |
| 87 |
) |
| 88 |
); |
| 89 |
|
| 90 |
$defaults = array( |
| 91 |
'new_listing_params' => false, // required for Import Google Calendar bookings |
| 92 |
'after_action_result' => false, |
| 93 |
/* translators: 1: ... */ |
| 94 |
'after_action_message' => sprintf( __( 'No actions %s has been processed.', 'booking' ) |
| 95 |
, ' <strong>' . $request_params['booking_action'] . '</strong> ' ) |
| 96 |
); |
| 97 |
$action_result = wp_parse_args( $action_result, $defaults ); |
| 98 |
|
| 99 |
// Check if there were some errors -------------------------------------------------------------------------------- |
| 100 |
$error_messages = $ajax_errors->get_error_messages(); |
| 101 |
if ( ! empty( $error_messages ) ) { |
| 102 |
$action_result['after_action_message'] .= $error_messages; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
//------------------------------------------------------------------------------------------------------------------ |
| 107 |
// 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. |
| 108 |
wp_send_json( array( |
| 109 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 110 |
'ajx_action_params' => $_REQUEST['action_params'], // Do not clean input parameters |
| 111 |
'ajx_cleaned_params' => $request_params, // Cleaned input parameters |
| 112 |
'ajx_after_action_message' => $action_result['after_action_message'], // Message to show |
| 113 |
'ajx_after_action_result' => (int) $action_result['after_action_result'], // Result key 0 | 1 |
| 114 |
'ajx_after_action_result_all_params_arr' => $action_result // All result parameters |
| 115 |
) ); |
| 116 |
} |
| 117 |
|
| 118 |
// </editor-fold> |
| 119 |
|
| 120 |
|
| 121 |
/** |
| 122 |
* Define HOOKs for loading CSS and JavaScript files |
| 123 |
*/ |
| 124 |
public function init_load_css_js() { |
| 125 |
|
| 126 |
//TODO: Uncomment this: // JS & CSS Load in all Plugins menus |
| 127 |
// add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 ); |
| 128 |
// add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 ); |
| 129 |
|
| 130 |
|
| 131 |
add_action( 'admin_enqueue_scripts', array( $this, 'load_tour_in_plugins' ) ); |
| 132 |
|
| 133 |
// Template |
| 134 |
//add_action( 'wpbc_hook_settings_page_footer', array( $this, 'wpbc_hidden_template__content_for_feedback_01' ), 50 ); |
| 135 |
} |
| 136 |
|
| 137 |
public function load_tour_in_plugins($hook) { |
| 138 |
|
| 139 |
$pages = array( 'plugins.php' ); |
| 140 |
|
| 141 |
if ( ! in_array( $hook, $pages ) ) { |
| 142 |
return; |
| 143 |
} |
| 144 |
|
| 145 |
$this->js_load_files( 'admin' ); |
| 146 |
$this->enqueue_css_files( 'admin' ); |
| 147 |
} |
| 148 |
|
| 149 |
|
| 150 |
/** JSS */ |
| 151 |
public function js_load_files( $where_to_load ) { |
| 152 |
|
| 153 |
$in_footer = true; |
| 154 |
|
| 155 |
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { |
| 156 |
|
| 157 |
wp_enqueue_script( 'wpbc_tether', wpbc_plugin_url( '/assets/libs/tether/tether.js' ), array( 'jquery' ), WP_BK_VERSION_NUM, $in_footer ); |
| 158 |
wp_enqueue_script( 'wpbc_shepherd', wpbc_plugin_url( '/assets/libs/tether-shepherd/shepherd.js' ), array( 'wpbc_tether' ), WP_BK_VERSION_NUM, $in_footer ); |
| 159 |
wp_enqueue_script( 'wpbc_tour_01', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc_tour.js', array( 'wpbc_shepherd' ), WP_BK_VERSION_NUM, $in_footer ); |
| 160 |
//wp_enqueue_script( 'wpbc_shepherd', wpbc_plugin_url( '/assets/libs/shepherd.js/dist/esm/shepherd.mjs' ) , array( 'wpbc_all' ), WP_BK_VERSION_NUM, $in_footer ); |
| 161 |
|
| 162 |
$tour_data = array( |
| 163 |
'plugins_page' => array( |
| 164 |
/* translators: 1: ... */ |
| 165 |
'title' => sprintf( __( 'Welcome to %s', 'booking' ), '<strong>WP Booking Calendar</strong>' ), |
| 166 |
'text' => sprintf( __('We\'ll guide you through the steps to set up WP Booking Calendar on your site.','booking'), '<strong>WP Booking Calendar</strong>' ), |
| 167 |
'button' => array( |
| 168 |
'text' => __( 'Let\'s go', 'booking' ), |
| 169 |
'url' => wpbc_get_setup_wizard_page_url() // URL to start new Guide: wpbc_get_settings_url() . '&wpbc_setup_wizard=reset&_wpnonce=' . wp_create_nonce( 'wpbc_settings_url_nonce' ) |
| 170 |
) |
| 171 |
), |
| 172 |
'setup_page' => array( |
| 173 |
'title' => 'Step 1 / 10', |
| 174 |
'text' => 'To make a simple backup to your server, press this button. Or to set up regular backups and remote storage, go to <strong>settings</strong> ', |
| 175 |
), |
| 176 |
'button_end_tour' => array( 'text' => __( 'End Tour', 'booking' ) ), |
| 177 |
'button_next' => array( 'text' => __( 'Next', 'booking' ) ) |
| 178 |
); |
| 179 |
wp_localize_script( 'wpbc_tour_01', 'wpbc_tour_i18n', $tour_data ); |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
/** CSS */ |
| 184 |
public function enqueue_css_files( $where_to_load ) { |
| 185 |
|
| 186 |
if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ) ) ) ) { |
| 187 |
|
| 188 |
//wp_enqueue_style( 'wpbc-tour_01', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/tour.css', array(), WP_BK_VERSION_NUM ); |
| 189 |
// wp_enqueue_style( 'wpbc_tour_01', wpbc_plugin_url('assets/libs/shepherd.js/dist/css/shepherd.css'), array(), WP_BK_VERSION_NUM ); |
| 190 |
// wp_enqueue_style( 'wpbc_shepherd', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/tether-shepherd/shepherd-theme-arrows-plain-buttons.css', array(), WP_BK_VERSION_NUM ); |
| 191 |
//wp_enqueue_style( 'wpbc_shepherd', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/tether-shepherd/shepherd-theme-dark.css', array(), WP_BK_VERSION_NUM ); |
| 192 |
//wp_enqueue_style( 'wpbc_shepherd', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/tether-shepherd/shepherd-theme-arrows.css', array(), WP_BK_VERSION_NUM ); |
| 193 |
|
| 194 |
wp_enqueue_style( 'wpbc_tour_01', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/wpbc-tour.css', array(), WP_BK_VERSION_NUM ); |
| 195 |
|
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
/** |
| 202 |
* Just for loading CSS and JavaScript files and define Ajax hook |
| 203 |
*/ |
| 204 |
if ( |
| 205 |
( ! wpbc_is_this_demo() ) && |
| 206 |
( wpbc_setup_wizard_page__is_need_start() ) && |
| 207 |
( wpbc_is_user_can_access_wizard_page() ) |
| 208 |
) { |
| 209 |
$js_css_loading = new WPBC_Tour_01; |
| 210 |
$js_css_loading->init_load_css_js(); |
| 211 |
} |
| 212 |
|