@@ -34,15 +34,15 @@ class CleantalkHelper
3434 ),
3535 ),
3636 );
37-
37+
3838 private static $ private_networks = array (
3939 '10.0.0.0/8 ' ,
4040 '100.64.0.0/10 ' ,
4141 '172.16.0.0/12 ' ,
4242 '192.168.0.0/16 ' ,
4343 '127.0.0.1/32 ' ,
4444 );
45-
45+
4646 /*
4747 * Getting arrays of IP (REMOTE_ADDR, X-Forwarded-For, X-Real-Ip, Cf_Connecting_Ip)
4848 * reutrns array('remote_addr' => 'val', ['x_forwarded_for' => 'val', ['x_real_ip' => 'val', ['cloud_flare' => 'val']]])
@@ -53,30 +53,30 @@ static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwa
5353 foreach ($ ips_input as $ ip_type ){
5454 $ ips [$ ip_type ] = '' ;
5555 } unset($ ip_type );
56-
56+
5757 $ headers = apache_request_headers ();
58-
58+
5959 // REMOTE_ADDR
6060 if (isset ($ ips ['remote_addr ' ])){
6161 $ ips ['remote_addr ' ] = $ _SERVER ['REMOTE_ADDR ' ];
6262 }
63-
63+
6464 // X-Forwarded-For
6565 if (isset ($ ips ['x_forwarded_for ' ])){
6666 if (isset ($ headers ['X-Forwarded-For ' ])){
6767 $ tmp = explode (", " , trim ($ headers ['X-Forwarded-For ' ]));
6868 $ ips ['x_forwarded_for ' ]= trim ($ tmp [0 ]);
6969 }
7070 }
71-
71+
7272 // X-Real-Ip
7373 if (isset ($ ips ['x_real_ip ' ])){
7474 if (isset ($ headers ['X-Real-Ip ' ])){
7575 $ tmp = explode (", " , trim ($ headers ['X-Real-Ip ' ]));
7676 $ ips ['x_real_ip ' ]= trim ($ tmp [0 ]);
7777 }
7878 }
79-
79+
8080 // Cloud Flare
8181 if (isset ($ ips ['cloud_flare ' ])){
8282 if (isset ($ headers ['Cf-Connecting-Ip ' ])){
@@ -85,12 +85,12 @@ static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwa
8585 }
8686 }
8787 }
88-
88+
8989 // Getting real IP from REMOTE_ADDR or Cf_Connecting_Ip if set or from (X-Forwarded-For, X-Real-Ip) if REMOTE_ADDR is local.
9090 if (isset ($ ips ['real ' ])){
91-
91+
9292 $ ips ['real ' ] = $ _SERVER ['REMOTE_ADDR ' ];
93-
93+
9494 // Cloud Flare
9595 if (isset ($ headers ['Cf-Connecting-Ip ' ])){
9696 if (self ::ip_mask_match ($ ips ['real ' ], self ::$ cdn_pool ['cloud_flare ' ]['ipv4 ' ])){
@@ -110,7 +110,7 @@ static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwa
110110 }
111111 }
112112 }
113-
113+
114114 // Validating IPs
115115 $ result = array ();
116116 foreach ($ ips as $ key => $ ip ){
@@ -122,19 +122,19 @@ static public function ip_get($ips_input = array('real', 'remote_addr', 'x_forwa
122122 $ result [$ key ] = $ ip ;
123123 }
124124 }
125-
125+
126126 $ result = array_unique ($ result );
127-
128- return count ($ ips_input ) > 1
129- ? $ result
127+
128+ return count ($ ips_input ) > 1
129+ ? $ result
130130 : (reset ($ result ) !== false
131131 ? reset ($ result )
132132 : null );
133133 }
134-
134+
135135 /*
136136 * Check if the IP belong to mask. Recursivly if array given
137- * @param ip string
137+ * @param ip string
138138 * @param cird mixed (string|array of strings)
139139 */
140140 static public function ip_mask_match ($ ip , $ cidr ){
@@ -151,7 +151,7 @@ static public function ip_mask_match($ip, $cidr){
151151 $ mask = 4294967295 << (32 - $ exploded [1 ]);
152152 return (ip2long ($ ip ) & $ mask ) == (ip2long ($ net ) & $ mask );
153153 }
154-
154+
155155 /*
156156 * Validating IPv4, IPv6
157157 * param (string) $ip
@@ -164,7 +164,7 @@ static public function ip_validate($ip)
164164 if (filter_var ($ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV6 )) return 'v6 ' ; // IPv6
165165 return false ; // Unknown
166166 }
167-
167+
168168 /**
169169 * Function sends raw http request
170170 *
@@ -173,17 +173,17 @@ static public function ip_validate($ip)
173173 * dont_wait_for_answer - async requests
174174 * get - GET-request
175175 * ssl - use SSL
176- *
176+ *
177177 * @param string result
178178 * @param string request_method
179179 * @return mixed (array || array('error' => true))
180180 */
181181 static public function http__request ($ url , $ data = array (), $ presets = null , $ opts = array ())
182182 {
183183 if (function_exists ('curl_init ' )){
184-
184+
185185 $ ch = curl_init ();
186-
186+
187187 // Obligatory options
188188 $ opts = array (
189189 CURLOPT_URL => $ url ,
@@ -197,48 +197,48 @@ static public function http__request($url, $data = array(), $presets = null, $op
197197 CURLOPT_SSL_VERIFYHOST => 0 ,
198198 CURLOPT_HTTPHEADER => array ('Expect: ' ), // Fix for large data and old servers http://php.net/manual/ru/function.curl-setopt.php#82418
199199 );
200-
200+
201201 // Use presets
202202 $ presets = is_array ($ presets ) ? $ presets : array ($ presets );
203203 foreach ($ presets as $ preset ){
204-
204+
205205 switch ($ preset ){
206-
206+
207207 // Get headers only
208208 case 'get_code ' :
209209 $ opts [CURLOPT_HEADER ] = true ;
210210 $ opts [CURLOPT_NOBODY ] = true ;
211211 break ;
212-
212+
213213 // Make a request, don't wait for an answer
214214 case 'dont_wait_for_answer ' :
215215 $ opts [CURLOPT_CONNECTTIMEOUT_MS ] = 1000 ;
216216 $ opts [CURLOPT_TIMEOUT_MS ] = 500 ;
217217 break ;
218-
218+
219219 case 'get ' :
220220 $ opts [CURLOPT_URL ] .= '? ' .str_replace ("& " , "& " , http_build_query ($ data ));
221221 $ opts [CURLOPT_POST ] = false ;
222222 $ opts [CURLOPT_POSTFIELDS ] = null ;
223223 break ;
224-
224+
225225 case 'ssl ' :
226226 $ opts [CURLOPT_SSL_VERIFYPEER ] = true ;
227227 $ opts [CURLOPT_SSL_VERIFYHOST ] = 2 ;
228228 break ;
229-
229+
230230 default :
231-
231+
232232 break ;
233233 }
234-
234+
235235 } unset($ preset );
236-
236+
237237 curl_setopt_array ($ ch , $ opts );
238238 $ result = @curl_exec ($ ch );
239-
239+
240240 if (in_array ('dont_wait_for_answer ' , $ presets )) return true ;
241-
241+
242242 if ($ result ){
243243 $ result = explode (PHP_EOL , $ result );
244244 if (in_array ('get_code ' , $ presets )) $ result = curl_getinfo ($ ch , CURLINFO_RESPONSE_CODE );
@@ -248,18 +248,18 @@ static public function http__request($url, $data = array(), $presets = null, $op
248248 $ error = array ('error ' => true , 'error_string ' => curl_error ($ ch ));
249249 }else
250250 $ error = array ('error ' => true , 'error_string ' => 'CURL_NOT_INSTALLED ' );
251-
251+
252252 /** Fix for get_code preset */
253253 if ($ presets && ($ presets == 'get_code ' || (is_array ($ presets ) && in_array ('get_code ' , $ presets ) ) )
254254 && (isset ($ error ) && $ error ['error_string ' ] == 'CURL_NOT_INSTALLED ' )
255255 ){
256256 $ headers = get_headers ($ url );
257257 $ out = (int )preg_replace ('/.*(\d{3}).*/ ' , '$1 ' , $ headers [0 ]);
258258 }
259-
259+
260260 return $ out ;
261261 }
262-
262+
263263 /**
264264 * Checks if the string is JSON type
265265 * @param string
@@ -269,7 +269,7 @@ static public function is_json($string)
269269 {
270270 return is_string ($ string ) && is_array (json_decode ($ string , true )) ? true : false ;
271271 }
272-
272+
273273 /**
274274 * Function removing non UTF8 characters from array||string
275275 * @param mixed(array||string)
@@ -286,7 +286,7 @@ static public function removeNonUTF8FromArray($data)
286286 }
287287 return $ data ;
288288 }
289-
289+
290290 /**
291291 * Function removing non UTF8 characters from array||string
292292 * param mixed(array||string)
@@ -300,25 +300,25 @@ public static function removeNonUTF8FromString($data)
300300 }
301301
302302 /**
303- * Function convert array to UTF8 and removes non UTF8 characters
303+ * Function convert array to UTF8 and removes non UTF8 characters
304304 * param array
305305 * param string
306306 * @return array
307307 */
308308 public static function arrayToUTF8 ($ array , $ data_codepage = null )
309309 {
310310 foreach ($ array as $ key => $ val ){
311-
311+
312312 if (is_array ($ val ))
313313 $ array [$ key ] = self ::arrayToUTF8 ($ val , $ data_codepage );
314314 else
315315 $ array [$ key ] = self ::stringToUTF8 ($ val , $ data_codepage );
316316 }
317317 return $ array ;
318318 }
319-
319+
320320 /**
321- * Function convert string to UTF8 and removes non UTF8 characters
321+ * Function convert string to UTF8 and removes non UTF8 characters
322322 * param string
323323 * param string
324324 * @return string
@@ -330,18 +330,18 @@ public static function stringToUTF8($str, $data_codepage = null)
330330 $ str = '' ;
331331 }
332332 if (!preg_match ('//u ' , $ str ) && function_exists ('mb_detect_encoding ' ) && function_exists ('mb_convert_encoding ' )){
333-
333+
334334 if ($ data_codepage !== null )
335335 return mb_convert_encoding ($ str , 'UTF-8 ' , $ data_codepage );
336-
336+
337337 $ encoding = mb_detect_encoding ($ str );
338-
338+
339339 if ($ encoding )
340340 return mb_convert_encoding ($ str , 'UTF-8 ' , $ encoding );
341341 }
342342 return $ str ;
343343 }
344-
344+
345345 /**
346346 * Function convert string from UTF8
347347 * param string
0 commit comments