| 1 |
<?php |
| 2 |
|
| 3 |
namespace Leadin\utils; |
| 4 |
|
| 5 |
use Leadin\data\Portal_Options; |
| 6 |
use Leadin\data\Filters; |
| 7 |
/** |
| 8 |
* Static class containing all the utility functions related to proxy mappings. |
| 9 |
*/ |
| 10 |
class ProxyUtils { |
| 11 |
|
| 12 |
/** |
| 13 |
* Info logger function to log messages. |
| 14 |
* |
| 15 |
* @param string $message The message to log. |
| 16 |
*/ |
| 17 |
public static function info_log( $message ) { |
| 18 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 19 |
do_action( 'qm/debug', $message ); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Error logger function to log messages. |
| 24 |
* |
| 25 |
* @param string $message The message to log. |
| 26 |
*/ |
| 27 |
public static function error_log( $message ) { |
| 28 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound, WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 29 |
do_action( 'qm/error', $message ); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the client IP address. |
| 34 |
* |
| 35 |
* @return string The client IP address. |
| 36 |
*/ |
| 37 |
public static function get_client_ip() { |
| 38 |
$ip_keys = array( |
| 39 |
'HTTP_CLIENT_IP', |
| 40 |
'HTTP_X_FORWARDED_FOR', |
| 41 |
'HTTP_X_FORWARDED', |
| 42 |
'HTTP_FORWARDED_FOR', |
| 43 |
'HTTP_FORWARDED', |
| 44 |
'REMOTE_ADDR', |
| 45 |
); |
| 46 |
foreach ( $ip_keys as $key ) { |
| 47 |
if ( isset( $_SERVER[ $key ] ) && ! empty( $_SERVER[ $key ] ) ) { |
| 48 |
return sanitize_text_field( wp_unslash( $_SERVER[ $key ] ) ); |
| 49 |
} |
| 50 |
} |
| 51 |
return ''; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get the destination domain. |
| 56 |
* |
| 57 |
* @return string The destination domain. |
| 58 |
*/ |
| 59 |
public static function get_destination_domain() { |
| 60 |
return isset( $_SERVER['HTTP_HOST'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) ) : ''; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Get the proxy plugin mapping API base URL. |
| 65 |
* |
| 66 |
* @return string The API base URL. |
| 67 |
*/ |
| 68 |
public static function get_plugin_mappings_api_url() { |
| 69 |
return Filters::apply_plugin_mappings_api_url(); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Get the proxy base URL. |
| 74 |
* |
| 75 |
* @return string The proxy base URL. |
| 76 |
*/ |
| 77 |
public static function get_proxy_base_url() { |
| 78 |
return Filters::apply_sites_proxy_cdn_filters(); |
| 79 |
} |
| 80 |
} |
| 81 |
|