PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.0.4
JetFormBuilder — Dynamic Blocks Form Builder v2.0.4
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / classes / http / http-tools.php
jetformbuilder / includes / classes / http Last commit date
http-tools.php 4 years ago utm-url.php 4 years ago
http-tools.php
101 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes\Http;
5
6 use Jet_Form_Builder\Plugin;
7
8 class Http_Tools {
9
10 public static function get_site_host() {
11 return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) );
12 }
13
14 /**
15 * Get current user IP Address.
16 *
17 * Taken from:
18 * https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-geolocation.php#L80-L91
19 * (WC_Geolocation::get_ip_address)
20 *
21 * @return string
22 */
23 public static function get_ip_address(): string {
24 if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
25 return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) );
26 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27 // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
28 // Make sure we always only send through the first IP in the list which should always be the client IP.
29 return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) );
30 } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
31 return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
32 }
33
34 return '';
35 }
36
37 public static function get_user_agent(): string {
38 return sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' ) );
39 }
40
41 public static function replace_path_args( string $path, array $path_args ): string {
42 $patterns = array();
43
44 foreach ( $path_args as $key => $value ) {
45 $patterns[ "#\(\?P<$key\>\S+\)#" ] = function ( $matches ) use ( $value ) {
46 return (string) $value;
47 };
48 }
49
50 return implode(
51 '/',
52 preg_replace_callback_array(
53 $patterns,
54 explode( '/', $path )
55 )
56 );
57 }
58
59 /**
60 * Returns form action url
61 *
62 * @param array $args
63 *
64 * @return string [type] [description]
65 */
66 public static function get_form_action_url( array $args = array() ): string {
67 $args = array_merge(
68 array(
69 Plugin::instance()->form_handler->hook_key => Plugin::instance()->form_handler->hook_val,
70 'method' => 'reload',
71 ),
72 $args
73 );
74
75 $action = home_url(
76 add_query_arg( $args )
77 );
78
79 return apply_filters( 'jet-form-builder/form-action-url', $action );
80 }
81
82 /**
83 * Returns form refer url
84 *
85 * @return [type] [description]
86 */
87 public static function get_form_refer_url(): string {
88
89 global $wp;
90
91 $refer = home_url( $wp->request );
92
93 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
94 $refer = trailingslashit( $refer ) . '?' . $_SERVER['QUERY_STRING'];
95 }
96
97 return apply_filters( 'jet-form-builder/form-refer-url', $refer );
98 }
99
100 }
101