activities_helper.php
1 year ago
agent_helper.php
1 year ago
auth_helper.php
9 months ago
blocks_helper.php
1 year ago
booking_helper.php
1 year ago
bricks_helper.php
1 year ago
bundles_helper.php
1 year ago
calendar_helper.php
9 months ago
carts_helper.php
1 year ago
connector_helper.php
1 year ago
csv_helper.php
9 months ago
customer_helper.php
9 months ago
customer_import_helper.php
9 months ago
database_helper.php
9 months ago
debug_helper.php
1 year ago
defaults_helper.php
1 year ago
elementor_helper.php
1 year ago
email_helper.php
9 months ago
encrypt_helper.php
1 year ago
events_helper.php
1 year ago
form_helper.php
9 months ago
icalendar_helper.php
1 year ago
image_helper.php
1 year ago
invoices_helper.php
9 months ago
license_helper.php
1 year ago
location_helper.php
1 year ago
marketing_systems_helper.php
1 year ago
meeting_systems_helper.php
1 year ago
menu_helper.php
9 months ago
meta_helper.php
1 year ago
migrations_helper.php
1 year ago
money_helper.php
1 year ago
notifications_helper.php
9 months ago
order_intent_helper.php
9 months ago
orders_helper.php
1 year ago
otp_helper.php
9 months ago
pages_helper.php
1 year ago
params_helper.php
1 year ago
payments_helper.php
1 year ago
price_breakdown_helper.php
1 year ago
process_jobs_helper.php
1 year ago
processes_helper.php
1 year ago
replacer_helper.php
1 year ago
resource_helper.php
1 year ago
roles_helper.php
9 months ago
router_helper.php
1 year ago
service_helper.php
1 year ago
sessions_helper.php
1 year ago
settings_helper.php
9 months ago
short_links_systems_helper.php
9 months ago
shortcodes_helper.php
9 months ago
sms_helper.php
1 year ago
steps_helper.php
9 months ago
stripe_connect_helper.php
9 months ago
styles_helper.php
9 months ago
support_topics_helper.php
1 year ago
time_helper.php
9 months ago
timeline_helper.php
9 months ago
transaction_helper.php
1 year ago
transaction_intent_helper.php
1 year ago
util_helper.php
9 months ago
version_specific_updates_helper.php
9 months ago
whatsapp_helper.php
1 year ago
work_periods_helper.php
1 year ago
wp_datetime.php
1 year ago
wp_user_helper.php
1 year ago
router_helper.php
103 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) return $string; |
| 11 | else return $string.$extension; |
| 12 | } |
| 13 | |
| 14 | public static function build_link($route, $params = array()){ |
| 15 | $params_query = ''; |
| 16 | if($params){ |
| 17 | $params_query = '&'.http_build_query($params); |
| 18 | } |
| 19 | if(is_array($route) && (count($route) == 2)) $route = OsRouterHelper::build_route_name($route[0], $route[1]); |
| 20 | return admin_url('admin.php?page=latepoint&route_name='.$route.$params_query); |
| 21 | } |
| 22 | |
| 23 | public static function build_admin_post_link($route, $params = array()){ |
| 24 | $params_query = ''; |
| 25 | if($params){ |
| 26 | $params_query = '&'.http_build_query($params); |
| 27 | } |
| 28 | if(is_array($route) && (count($route) == 2)) $route = OsRouterHelper::build_route_name($route[0], $route[1]); |
| 29 | return admin_url('admin-post.php?action=latepoint_route_call&route_name='.$route.$params_query); |
| 30 | } |
| 31 | |
| 32 | public static function link_has_route($route_name, $link){ |
| 33 | $link_params = wp_parse_url($link); |
| 34 | if(empty($link_params['query'])) return false; |
| 35 | parse_str($link_params['query'], $link_query_params); |
| 36 | return ($link_query_params && isset($link_query_params['route_name']) && ($link_query_params['route_name'] == $route_name)); |
| 37 | } |
| 38 | |
| 39 | public static function build_front_link($route, $params = array()){ |
| 40 | $params_query = ''; |
| 41 | if($params){ |
| 42 | $params_query = '&'.http_build_query($params); |
| 43 | } |
| 44 | if(is_array($route) && (count($route) == 2)) $route = OsRouterHelper::build_route_name($route[0], $route[1]); |
| 45 | return site_url('index.php?latepoint_is_custom_route=true&route_name='.$route.$params_query); |
| 46 | } |
| 47 | |
| 48 | public static function build_route_name($controller, $action){ |
| 49 | return $controller.'__'.$action; |
| 50 | } |
| 51 | |
| 52 | public static function convert_route_name_to_controller_and_action($route_name): array{ |
| 53 | list($controller_name, $action) = explode('__', $route_name); |
| 54 | if(empty($controller_name) || empty($action)) return []; |
| 55 | $controller_name = str_replace('_', '', ucwords($controller_name, '_')); |
| 56 | $controller_class_name = 'Os'.$controller_name.'Controller'; |
| 57 | if(class_exists($controller_class_name)) { |
| 58 | $controller_obj = new $controller_class_name(); |
| 59 | if(method_exists($controller_obj, $action)) { |
| 60 | // check if action is valid |
| 61 | return ['controller' => $controller_obj, 'action' => $action]; |
| 62 | }else{ |
| 63 | return []; |
| 64 | } |
| 65 | }else{ |
| 66 | return []; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | public static function call_by_route_name($route_name, $return_format = 'html'){ |
| 71 | OsDebugHelper::log_route($route_name, $return_format); |
| 72 | $route_data = self::convert_route_name_to_controller_and_action($route_name); |
| 73 | if(!empty($route_data)){ |
| 74 | $controller_obj = $route_data['controller']; |
| 75 | $action = $route_data['action']; |
| 76 | if($return_format) $controller_obj->set_return_format($return_format); |
| 77 | // check if user is allowed to access this route |
| 78 | if($controller_obj->can_current_user_access_action($action)){ |
| 79 | $controller_obj->route_name = $route_name; |
| 80 | $controller_obj->$action(); |
| 81 | }else{ |
| 82 | if($controller_obj->get_return_format() == 'json'){ |
| 83 | $controller_obj->send_json( ['status' => LATEPOINT_STATUS_ERROR, 'message' => __('Not Authorized', 'latepoint')] ); |
| 84 | }else{ |
| 85 | echo '<div class="latepoint-not-authorized"><div class="not-authorized-message">'.esc_html__('Not Authorized', 'latepoint').'</div></div>'; |
| 86 | } |
| 87 | } |
| 88 | }else{ |
| 89 | esc_html_e('Page Not Found', 'latepoint'); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | public static function get_request_param($name, $default = false){ |
| 94 | if(isset($_GET[$name])){ |
| 95 | $param = sanitize_text_field(wp_unslash($_GET[$name])); |
| 96 | }elseif(isset($_POST[$name])){ |
| 97 | $param = sanitize_text_field(wp_unslash($_POST[$name])); |
| 98 | }else{ |
| 99 | $param = $default; |
| 100 | } |
| 101 | return $param; |
| 102 | } |
| 103 | } |