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