PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / router_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 3 months ago agent_helper.php 3 months ago analytics_helper.php 1 week ago auth_helper.php 6 days ago blocks_helper.php 3 weeks ago booking_helper.php 4 days ago bricks_helper.php 3 months ago bundles_helper.php 4 days ago calendar_helper.php 2 days ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 1 month ago customer_import_helper.php 1 month ago database_helper.php 1 week ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 weeks ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 3 weeks ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 2 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 2 months ago plugin_version_update_helper.php 2 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago razorpay_connect_helper.php 1 week ago replacer_helper.php 3 months ago resource_helper.php 4 days ago roles_helper.php 3 weeks ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 1 week ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 weeks ago sms_helper.php 3 months ago steps_helper.php 1 week ago stripe_connect_helper.php 1 week ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 2 months ago timeline_helper.php 2 months ago transaction_helper.php 1 month ago transaction_intent_helper.php 3 months ago util_helper.php 1 month ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 1 month ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
router_helper.php
127 lines
1 <?php
2
3 class OsRouterHelper {
4
5 public static function build_pre_route_link( $route, $params = array() ) {
6 return self::build_link( $route, array_merge( array( 'pre_route' => 1 ), $params ) );
7 }
8
9 public static function add_extension( $string = '', $extension = '.php' ) {
10 if ( substr( $string, -strlen( $extension ) ) === $extension ) {
11 return $string;
12 } else {
13 return $string . $extension;
14 }
15 }
16
17 public static function build_link( $route, $params = array() ) {
18 $params_query = '';
19 if ( $params ) {
20 $params_query = '&' . http_build_query( $params );
21 }
22 if ( is_array( $route ) && ( count( $route ) == 2 ) ) {
23 $route = OsRouterHelper::build_route_name( $route[0], $route[1] );
24 }
25 return admin_url( 'admin.php?page=latepoint&route_name=' . $route . $params_query );
26 }
27
28 public static function build_admin_post_link( $route, $params = array() ) {
29 $params_query = '';
30 if ( $params ) {
31 $params_query = '&' . http_build_query( $params );
32 }
33 if ( is_array( $route ) && ( count( $route ) == 2 ) ) {
34 $route = OsRouterHelper::build_route_name( $route[0], $route[1] );
35 }
36 return admin_url( 'admin-post.php?action=latepoint_route_call&route_name=' . $route . $params_query );
37 }
38
39 public static function link_has_route( $route_name, $link ) {
40 $link_params = wp_parse_url( $link );
41 if ( empty( $link_params['query'] ) ) {
42 return false;
43 }
44 parse_str( $link_params['query'], $link_query_params );
45 return ( $link_query_params && isset( $link_query_params['route_name'] ) && ( $link_query_params['route_name'] == $route_name ) );
46 }
47
48 public static function build_front_link( $route, $params = array() ) {
49 $params_query = '';
50 if ( $params ) {
51 $params_query = '&' . http_build_query( $params );
52 }
53 if ( is_array( $route ) && ( count( $route ) == 2 ) ) {
54 $route = OsRouterHelper::build_route_name( $route[0], $route[1] );
55 }
56 return site_url( 'index.php?latepoint_is_custom_route=true&route_name=' . $route . $params_query );
57 }
58
59 public static function build_route_name( $controller, $action ) {
60 return $controller . '__' . $action;
61 }
62
63 public static function convert_route_name_to_controller_and_action( $route_name ): array {
64 list($controller_name, $action) = explode( '__', $route_name );
65 if ( empty( $controller_name ) || empty( $action ) ) {
66 return [];
67 }
68 $controller_name = str_replace( '_', '', ucwords( $controller_name, '_' ) );
69 $controller_class_name = 'Os' . $controller_name . 'Controller';
70 if ( class_exists( $controller_class_name ) ) {
71 $controller_obj = new $controller_class_name();
72 if ( method_exists( $controller_obj, $action ) ) {
73 // check if action is valid
74 return [
75 'controller' => $controller_obj,
76 'action' => $action,
77 ];
78 } else {
79 return [];
80 }
81 } else {
82 return [];
83 }
84 }
85
86 public static function call_by_route_name( $route_name, $return_format = 'html' ) {
87 OsDebugHelper::log_route( $route_name, $return_format );
88 $route_data = self::convert_route_name_to_controller_and_action( $route_name );
89 if ( ! empty( $route_data ) ) {
90 $controller_obj = $route_data['controller'];
91 $action = $route_data['action'];
92 if ( $return_format ) {
93 $controller_obj->set_return_format( $return_format );
94 }
95 // check if user is allowed to access this route
96 if ( $controller_obj->can_current_user_access_action( $action ) ) {
97 $controller_obj->route_name = $route_name;
98 $controller_obj->$action();
99 } else {
100 if ( $controller_obj->get_return_format() == 'json' ) {
101 $controller_obj->send_json(
102 [
103 'status' => LATEPOINT_STATUS_ERROR,
104 'message' => __( 'Not Authorized', 'latepoint' ),
105 ]
106 );
107 } else {
108 echo '<div class="latepoint-not-authorized"><div class="not-authorized-message">' . esc_html__( 'Not Authorized', 'latepoint' ) . '</div></div>';
109 }
110 }
111 } else {
112 esc_html_e( 'Page Not Found', 'latepoint' );
113 }
114 }
115
116 public static function get_request_param( $name, $default = false ) {
117 if ( isset( $_GET[ $name ] ) ) {
118 $param = sanitize_text_field( wp_unslash( $_GET[ $name ] ) );
119 } elseif ( isset( $_POST[ $name ] ) ) {
120 $param = sanitize_text_field( wp_unslash( $_POST[ $name ] ) );
121 } else {
122 $param = $default;
123 }
124 return $param;
125 }
126 }
127