Test Failed
Push — trunk ( e02d87...314b8c )
by SuperNova.WS
07:20
created

invokeUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 04.12.2017 4:45
4
 */
5
6
// ----------------------------------------------------------------------------------------------------------------
7
function sys_redirect($url) {
8
  header("Location: {$url}");
9
  ob_end_flush();
10
  die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
11
}
12
13
/**
14
 * Redirects via JS-script
15
 *
16
 * @param string $url
17
 */
18
function sys_redirect_js($url) {
19
  ob_end_flush();
20
21
  $redirectTemplate = SnTemplate::gettemplate('_redirect');
22
  $redirectTemplate->assign_vars(array(
23
    'URL' => js_safe_string($url),
24
  ));
25
26
  SnTemplate::display($redirectTemplate);
27
  die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
28
}
29
30
31
// ----------------------------------------------------------------------------------------------------------------
32
/**
33
 * Wrapper for header() function
34
 *
35
 * @param string $header
36
 */
37
function setHeader($header) {
38
  header($header);
39
}
40
41
42
// ----------------------------------------------------------------------------------------------------------------
43
function sn_get_url_contents($url) {
44
  if (function_exists('curl_init')) {
45
    $crl = curl_init();
46
    $timeout = 5;
47
    curl_setopt($crl, CURLOPT_URL, $url);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
    curl_setopt(/** @scrutinizer ignore-type */ $crl, CURLOPT_URL, $url);
Loading history...
48
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
49
    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
50
    $return = curl_exec($crl);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
    $return = curl_exec(/** @scrutinizer ignore-type */ $crl);
Loading history...
51
    curl_close($crl);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
    curl_close(/** @scrutinizer ignore-type */ $crl);
Loading history...
52
  } else {
53
    $return = @file_get_contents($url);
54
  }
55
56
  return $return;
57
}
58
59
/**
60
 * @param $url
61
 * @param array $data
62
 *
63
 * @return bool|false|string
64
 */
65
function sn_post_url_contents($url, $data) {
66
  if (function_exists('curl_init')) {
67
    $crl = curl_init();
68
    $timeout = 5;
69
    curl_setopt($crl, CURLOPT_URL, $url);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

69
    curl_setopt(/** @scrutinizer ignore-type */ $crl, CURLOPT_URL, $url);
Loading history...
70
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
71
    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
72
    curl_setopt($crl, CURLOPT_POST, true);
73
    curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
74
    $return = curl_exec($crl);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
    $return = curl_exec(/** @scrutinizer ignore-type */ $crl);
Loading history...
75
76
//    var_dump('error: ' . curl_error($crl));
77
78
    curl_close($crl);
0 ignored issues
show
Bug introduced by
It seems like $crl can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
    curl_close(/** @scrutinizer ignore-type */ $crl);
Loading history...
79
  } else {
80
    $return = @file_get_contents($url);
81
  }
82
83
  return $return;
84
}
85
86
function invokeUrl($url) {
87
  exec("curl $url > /dev/null 2>&1 &");
88
}
89
90
// ----------------------------------------------------------------------------------------------------------------
91
function sn_setcookie($name, $value = null, $expire = null, $path = SN_ROOT_RELATIVE, $domain = null, $secure = null, $httponly = null) {
92
  $_COOKIE[$name] = $value;
93
94
  return setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
95
}
96
97
98
// ----------------------------------------------------------------------------------------------------------------
99
/**
100
 * Возвращает информацию об IPv4 адресах пользователя
101
 *
102
 * НЕ ПОДДЕРЖИВАЕТ IPv6!
103
 *
104
 * @return array
105
 */
106
function sec_player_ip() {
107
  // TODO - IPv6 support
108
  $ip = array(
109
    'ip'          => $_SERVER["REMOTE_ADDR"],
110
    'proxy_chain' => $_SERVER["HTTP_X_FORWARDED_FOR"]
111
      ? $_SERVER["HTTP_X_FORWARDED_FOR"]
112
      : ($_SERVER["HTTP_CLIENT_IP"]
113
        ? $_SERVER["HTTP_CLIENT_IP"]
114
        : '' // $_SERVER["REMOTE_ADDR"]
115
      ),
116
  );
117
118
  // Quick hack to support IPv6 at least on local host
119
  if($ip['ip'] == '::1') {
120
    $ip['ip'] = '127.0.0.1';
121
  }
122
123
  return array_map('db_escape', $ip);
124
}
125