PluginProbe
Gravity Forms Eway / 2.4.1
Gravity Forms Eway v2.4.1
2.7.0 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 All 56 releases
gravityforms-eway / includes / functions.php

functions.php in Gravity Forms Eway 2.4.1, at includes/functions.php

117 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace webaware\gfeway;
3
4 use \GFCommon;
5 use \GFEwayException;
6 use \GFEwayCurlException;
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 /**
13 * compare Gravity Forms version against target
14 * @param string $target
15 * @param string $operator
16 * @return bool
17 */
18 function gform_version_compare($target, $operator) {
19 if (class_exists('GFCommon', false)) {
20 return version_compare(GFCommon::$version, $target, $operator);
21 }
22
23 return false;
24 }
25
26 /**
27 * test whether the minimum required Gravity Forms is installed / activated
28 * @return bool
29 */
30 function has_required_gravityforms() {
31 return gform_version_compare(GFEWAY_MIN_VERSION_GF, '>=');
32 }
33
34 /**
35 * get the customer's IP address dynamically from server variables
36 * @param bool $is_test_site
37 * @return string
38 */
39 function get_customer_IP($is_test_site) {
40 $ip = '';
41
42 if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
43 $ip = is_IP_address($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : '';
44 }
45
46 elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
47 $proxies = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
48 $ip = trim(current($proxies));
49 $ip = is_IP_address($ip) ? $ip : '';
50 }
51
52 elseif (!empty($_SERVER['REMOTE_ADDR'])) {
53 $ip = is_IP_address($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
54 }
55
56 // if test mode and running on localhost, then kludge to an Aussie IP address
57 if ($ip === '127.0.0.1' && $is_test_site) {
58 $ip = '103.29.100.101';
59 }
60
61 // allow hookers to override for network-specific fixes
62 $ip = apply_filters('gfeway_customer_ip', $ip);
63
64 return $ip;
65 }
66
67 /**
68 * check whether a given string is an IP address
69 * @param string $maybeIP
70 * @return bool
71 */
72 function is_IP_address($maybeIP) {
73 // check for IPv4 and IPv6 addresses
74 return !!inet_pton($maybeIP);
75 }
76
77 /**
78 * send data via HTTP and return response
79 * @deprecated only used now for legacy Direct API and its friends
80 * @param string $url
81 * @param string $data
82 * @param bool $sslVerifyPeer whether to validate the SSL certificate
83 * @return string $response
84 * @throws GFEwayCurlException
85 */
86 function send_xml_request($url, $data, $sslVerifyPeer = true) {
87 // send data via HTTPS and receive response
88 $response = wp_remote_post($url, [
89 'user-agent' => 'Gravity Forms Eway ' . GFEWAY_PLUGIN_VERSION,
90 'sslverify' => $sslVerifyPeer,
91 'timeout' => 60,
92 'headers' => ['Content-Type' => 'text/xml; charset=utf-8'],
93 'body' => $data,
94 ]);
95
96 // failure to handle the http request
97 if (is_wp_error($response)) {
98 throw new GFEwayCurlException($response->get_error_message());
99 }
100
101 // error code returned by request
102 $code = wp_remote_retrieve_response_code($response);
103 if ($code !== 200) {
104 $msg = wp_remote_retrieve_response_message($response);
105
106 if (empty($msg)) {
107 $msg = sprintf(__('Error posting Eway request: %s', 'gravityforms-eway'), $code);
108 }
109 else {
110 $msg = sprintf(__('Error posting Eway request: %1$s, %2$s', 'gravityforms-eway'), $code, $msg);
111 }
112 throw new GFEwayException($msg);
113 }
114
115 return wp_remote_retrieve_body($response);
116 }
117