PluginProbe
گیت‌لند | درگاه پرداخت هوشمند گیت‌لند / 2.3.1
گیت‌لند | درگاه پرداخت هوشمند گیت‌لند v2.3.1
trunk 1.9.9 2.1.0 2.1.1 2.3.1
gateland / src / Helper.php

Helper.php in گیت‌لند | درگاه پرداخت هوشمند گیت‌لند 2.3.1, at src/Helper.php

124 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Nabik\Gateland;
4
5 defined( 'ABSPATH' ) || exit;
6
7 class Helper {
8
9 public static function redirect( string $url ) {
10 header( 'Content-type: text/html; charset=utf-8' );
11
12 header( "Location: " . $url, true, 307 );
13
14 echo "<html lang='fa'></html>";
15 flush();
16 ob_flush();
17 exit;
18 }
19
20 /**
21 * @param string $string
22 *
23 * @return string
24 */
25 public static function fa_num( string $string ): string {
26 return str_replace( range( 0, 9 ), [ '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ], $string );
27 }
28
29 public static function mobile( string $mobile, $link = true ): string {
30
31 $_mobile = str_replace( [ '+98', ' ' ], [ '0', '' ], $mobile );
32 $_mobile = self::fa_num( $_mobile );
33
34 if ( $link ) {
35 $mobile = sprintf( '<a href="tel:%s" target="_blank">%s</a>', $mobile, $_mobile );
36 } else {
37 $mobile = $_mobile;
38 }
39
40 return $mobile;
41 }
42
43 /**
44 * @param $dateTime
45 * @param $format
46 *
47 * @return false|string
48 */
49 public static function date( $dateTime, $format = 'Y/m/d H:i:s' ) {
50 return wp_date( $format, strtotime( $dateTime ) );
51 }
52
53 /**
54 * @param string $string
55 *
56 * @return string
57 */
58 public static function en_num( string $string ): string {
59 return str_replace( [ '۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹' ], range( 0, 9 ), $string );
60 }
61
62 /**
63 * @return false|mixed|string
64 */
65 public static function get_real_ip() {
66
67 $proxy_headers = [
68 'HTTP_CF_CONNECTING_IP',
69 'CLIENT_IP',
70 'FORWARDED',
71 'FORWARDED_FOR',
72 'FORWARDED_FOR_IP',
73 'HTTP_CLIENT_IP',
74 'HTTP_FORWARDED',
75 'HTTP_FORWARDED_FOR',
76 'HTTP_FORWARDED_FOR_IP',
77 'HTTP_PC_REMOTE_ADDR',
78 'HTTP_PROXY_CONNECTION',
79 'HTTP_VIA',
80 'HTTP_X_FORWARDED',
81 'HTTP_X_FORWARDED_FOR',
82 'HTTP_X_FORWARDED_FOR_IP',
83 'HTTP_X_IMFORWARDS',
84 'HTTP_XROXY_CONNECTION',
85 'VIA',
86 'X_FORWARDED',
87 'X_FORWARDED_FOR',
88 'REMOTE_ADDR',
89 ];
90
91 $pattern = "/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/";
92
93 foreach ( $proxy_headers as $proxy_header ) {
94
95 $ip = $_SERVER[ $proxy_header ] ?? null;
96
97 if ( ! filter_var( $ip, FILTER_VALIDATE_IP ) ) {
98 continue;
99 }
100
101 if ( preg_match( $pattern, $ip ) ) {
102 return $ip;
103 }
104
105 if ( stristr( ',', $ip ) !== false ) {
106
107 $server = explode( ',', $ip );
108 $proxy_header_temp = trim( array_shift( $server ) );
109
110 if ( ( $pos_temp = stripos( $proxy_header_temp, ':' ) ) !== false ) {
111 $proxy_header_temp = substr( $proxy_header_temp, 0, $pos_temp );
112 }
113
114 if ( preg_match( $pattern, $proxy_header_temp ) ) {
115 return $proxy_header_temp;
116 }
117
118 }
119
120 }
121
122 return '127.0.0.1';
123 }
124 }