PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.3
JetFormBuilder — Dynamic Blocks Form Builder v3.0.3
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 3 years ago utm-url.php 3 years ago
http-tools.php
132 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 protected static $query;
11
12 public static function get_site_host() {
13 return str_ireplace( 'www.', '', wp_parse_url( home_url(), PHP_URL_HOST ) );
14 }
15
16 /**
17 * Get current user IP Address.
18 *
19 * Taken from:
20 * https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-geolocation.php#L80-L91
21 * (WC_Geolocation::get_ip_address)
22 *
23 * @return string
24 */
25 public static function get_ip_address(): string {
26 if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
27 return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) );
28 } elseif ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
29 // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
30 // Make sure we always only send through the first IP in the list which should always be the client IP.
31 return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) );
32 } elseif ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
33 return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
34 }
35
36 return '';
37 }
38
39 public static function get_user_agent(): string {
40 return sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' ) );
41 }
42
43 public static function replace_path_args( string $path, array $path_args ): string {
44 $patterns = array();
45
46 foreach ( $path_args as $key => $value ) {
47 $patterns["#\(\?P<$key\>\S+\)#"] = function ( $matches ) use ( $value ) {
48 return (string) $value;
49 };
50 }
51
52 return implode(
53 '/',
54 preg_replace_callback_array(
55 $patterns,
56 explode( '/', $path )
57 )
58 );
59 }
60
61 /**
62 * Returns form action url
63 *
64 * @param array $args
65 *
66 * @return string [type] [description]
67 */
68 public static function get_form_action_url( array $args = array() ): string {
69 global $wp;
70
71 $args = array_merge(
72 array(
73 Plugin::instance()->form_handler->hook_key => Plugin::instance()->form_handler->hook_val,
74 'method' => 'reload',
75 ),
76 $args
77 );
78
79 $action = add_query_arg(
80 $args,
81 trailingslashit(
82 home_url( $wp->request )
83 )
84 );
85
86 return apply_filters( 'jet-form-builder/form-action-url', $action );
87 }
88
89 /**
90 * Returns form refer url
91 *
92 * @return [type] [description]
93 */
94 public static function get_form_refer_url(): string {
95
96 global $wp;
97
98 $refer = home_url( $wp->request );
99
100 if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
101 $refer = trailingslashit( $refer ) . '?' . $_SERVER['QUERY_STRING'];
102 }
103
104 return apply_filters( 'jet-form-builder/form-refer-url', $refer );
105 }
106
107 public static function get_query(): array {
108 if ( ! is_null( self::$query ) ) {
109 return self::$query;
110 }
111
112 if ( ! jet_fb_handler()->is_process() ) {
113 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
114 self::$query = wp_unslash( $_GET );
115
116 return self::$query;
117 }
118
119 $query = array();
120
121 wp_parse_str(
122 wp_parse_url( jet_fb_handler()->refer, PHP_URL_QUERY ),
123 $query
124 );
125
126 self::$query = wp_unslash( $query );
127
128 return self::$query;
129 }
130
131 }
132