@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | ) |
785 | 785 | ); |
786 | 786 | while ($row = $smcFunc['db_fetch_assoc']($request)) |
787 | - $error_ips[] = inet_dtop($row['ip']); |
|
787 | + $error_ips[] = inet_dtop($row['ip']); |
|
788 | 788 | $smcFunc['db_free_result']($request); |
789 | 789 | |
790 | 790 | return $error_ips; |
@@ -2168,9 +2168,9 @@ discard block |
||
2168 | 2168 | |
2169 | 2169 | if ($low == '255.255.255.255') return 'unknown'; |
2170 | 2170 | if ($low == $high) |
2171 | - return $low; |
|
2171 | + return $low; |
|
2172 | 2172 | else |
2173 | - return $low . '-' . $high; |
|
2173 | + return $low . '-' . $high; |
|
2174 | 2174 | } |
2175 | 2175 | |
2176 | 2176 | /** |
@@ -94,12 +94,12 @@ discard block |
||
94 | 94 | public $headers; |
95 | 95 | |
96 | 96 | /** |
97 | - * Start the curl object |
|
98 | - * - allow for user override values |
|
99 | - * |
|
100 | - * @param array $options An array of cURL options |
|
101 | - * @param int $max_redirect Maximum number of redirects |
|
102 | - */ |
|
97 | + * Start the curl object |
|
98 | + * - allow for user override values |
|
99 | + * |
|
100 | + * @param array $options An array of cURL options |
|
101 | + * @param int $max_redirect Maximum number of redirects |
|
102 | + */ |
|
103 | 103 | public function __construct($options = array(), $max_redirect = 3) |
104 | 104 | { |
105 | 105 | // Initialize class variables |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Main calling function, |
|
112 | - * - will request the page data from a given $url |
|
113 | - * - optionally will post data to the page form if post data is supplied |
|
114 | - * - passed arrays will be converted to a post string joined with &'s |
|
115 | - * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | - * |
|
117 | - * @param string $url the site we are going to fetch |
|
118 | - * @param array $post_data any post data as form name => value |
|
119 | - * @return object An instance of the curl_fetch_web_data class |
|
120 | - */ |
|
111 | + * Main calling function, |
|
112 | + * - will request the page data from a given $url |
|
113 | + * - optionally will post data to the page form if post data is supplied |
|
114 | + * - passed arrays will be converted to a post string joined with &'s |
|
115 | + * - calls set_options to set the curl opts array values based on the defaults and user input |
|
116 | + * |
|
117 | + * @param string $url the site we are going to fetch |
|
118 | + * @param array $post_data any post data as form name => value |
|
119 | + * @return object An instance of the curl_fetch_web_data class |
|
120 | + */ |
|
121 | 121 | public function get_url_data($url, $post_data = array()) |
122 | 122 | { |
123 | 123 | // POSTing some data perhaps? |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
137 | - * Makes the actual cURL call |
|
138 | - * - stores responses (url, code, error, headers, body) in the response array |
|
139 | - * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | - * |
|
141 | - * @param string $url The site to fetch |
|
142 | - * @param bool $redirect Whether or not this was a redirect request |
|
143 | - * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | - */ |
|
137 | + * Makes the actual cURL call |
|
138 | + * - stores responses (url, code, error, headers, body) in the response array |
|
139 | + * - detects 301, 302, 307 codes and will redirect to the given response header location |
|
140 | + * |
|
141 | + * @param string $url The site to fetch |
|
142 | + * @param bool $redirect Whether or not this was a redirect request |
|
143 | + * @return void|bool Sets various properties of the class or returns false if the URL isn't specified |
|
144 | + */ |
|
145 | 145 | private function curl_request($url, $redirect = false) |
146 | 146 | { |
147 | 147 | // we do have a url I hope |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | - * Used if being redirected to ensure we have a fully qualified address |
|
197 | - * |
|
198 | - * @param string $last_url The URL we went to |
|
199 | - * @param string $new_url The URL we were redirected to |
|
200 | - * @return string The new URL that was in the HTTP header |
|
201 | - */ |
|
196 | + * Used if being redirected to ensure we have a fully qualified address |
|
197 | + * |
|
198 | + * @param string $last_url The URL we went to |
|
199 | + * @param string $new_url The URL we were redirected to |
|
200 | + * @return string The new URL that was in the HTTP header |
|
201 | + */ |
|
202 | 202 | private function get_redirect_url($last_url = '', $new_url = '') |
203 | 203 | { |
204 | 204 | // Get the elements for these urls |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Used to return the results to the calling program |
|
220 | - * - called as ->result() will return the full final array |
|
221 | - * - called as ->result('body') to just return the page source of the result |
|
222 | - * |
|
223 | - * @param string $area Used to return an area such as body, header, error |
|
224 | - * @return string The response |
|
225 | - */ |
|
219 | + * Used to return the results to the calling program |
|
220 | + * - called as ->result() will return the full final array |
|
221 | + * - called as ->result('body') to just return the page source of the result |
|
222 | + * |
|
223 | + * @param string $area Used to return an area such as body, header, error |
|
224 | + * @return string The response |
|
225 | + */ |
|
226 | 226 | public function result($area = '') |
227 | 227 | { |
228 | 228 | $max_result = count($this->response) - 1; |
@@ -235,13 +235,13 @@ discard block |
||
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
238 | - * Will return all results from all loops (redirects) |
|
239 | - * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | - * - Call as ->result_raw() for everything. |
|
241 | - * |
|
242 | - * @param string $response_number Which response we want to get |
|
243 | - * @return array|string The entire response array or just the specified response |
|
244 | - */ |
|
238 | + * Will return all results from all loops (redirects) |
|
239 | + * - Can be called as ->result_raw(x) where x is a specific loop results. |
|
240 | + * - Call as ->result_raw() for everything. |
|
241 | + * |
|
242 | + * @param string $response_number Which response we want to get |
|
243 | + * @return array|string The entire response array or just the specified response |
|
244 | + */ |
|
245 | 245 | public function result_raw($response_number = '') |
246 | 246 | { |
247 | 247 | if (!is_numeric($response_number)) |
@@ -254,13 +254,13 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
257 | - * Takes supplied POST data and url encodes it |
|
258 | - * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | - * - drops vars with @ since we don't support sending files (uploading) |
|
260 | - * |
|
261 | - * @param array|string $post_data The raw POST data |
|
262 | - * @return string A string of post data |
|
263 | - */ |
|
257 | + * Takes supplied POST data and url encodes it |
|
258 | + * - forms the date (for post) in to a string var=xyz&var2=abc&var3=123 |
|
259 | + * - drops vars with @ since we don't support sending files (uploading) |
|
260 | + * |
|
261 | + * @param array|string $post_data The raw POST data |
|
262 | + * @return string A string of post data |
|
263 | + */ |
|
264 | 264 | private function build_post_data($post_data) |
265 | 265 | { |
266 | 266 | if (is_array($post_data)) |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | } |
280 | 280 | |
281 | 281 | /** |
282 | - * Sets the final cURL options for the current call |
|
283 | - * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | - * - sets the callback function now that $this is existing |
|
285 | - * @return void |
|
286 | - */ |
|
282 | + * Sets the final cURL options for the current call |
|
283 | + * - overwrites our default values with user supplied ones or appends new user ones to what we have |
|
284 | + * - sets the callback function now that $this is existing |
|
285 | + * @return void |
|
286 | + */ |
|
287 | 287 | private function set_options() |
288 | 288 | { |
289 | 289 | // Callback to parse the returned headers, if any |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | - * - resets the cURL options for the loop, sets the referrer flag |
|
313 | - * |
|
314 | - * @param string $target_url The URL we want to redirect to |
|
315 | - * @param string $referer_url The URL that we're redirecting from |
|
316 | - */ |
|
311 | + * Called to initiate a redirect from a 301, 302 or 307 header |
|
312 | + * - resets the cURL options for the loop, sets the referrer flag |
|
313 | + * |
|
314 | + * @param string $target_url The URL we want to redirect to |
|
315 | + * @param string $referer_url The URL that we're redirecting from |
|
316 | + */ |
|
317 | 317 | private function redirect($target_url, $referer_url) |
318 | 318 | { |
319 | 319 | // no no I last saw that over there ... really, 301, 302, 307 |
@@ -323,13 +323,13 @@ discard block |
||
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
326 | - * Callback function to parse returned headers |
|
327 | - * - lowercases everything to make it consistent |
|
328 | - * |
|
329 | - * @param type $cr Not sure what this is used for? |
|
330 | - * @param string $header The header |
|
331 | - * @return int The length of the header |
|
332 | - */ |
|
326 | + * Callback function to parse returned headers |
|
327 | + * - lowercases everything to make it consistent |
|
328 | + * |
|
329 | + * @param type $cr Not sure what this is used for? |
|
330 | + * @param string $header The header |
|
331 | + * @return int The length of the header |
|
332 | + */ |
|
333 | 333 | private function header_callback($cr, $header) |
334 | 334 | { |
335 | 335 | $_header = trim($header); |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | { |
838 | 838 | uasort($loaded_attachments, function($a, $b) { |
839 | 839 | if ($a['filesize'] == $b['filesize']) |
840 | - return 0; |
|
840 | + return 0; |
|
841 | 841 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
842 | 842 | }); |
843 | 843 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
1242 | 1242 | { |
1243 | 1243 | uasort($loaded_attachments, function($a, $b) { |
1244 | 1244 | if ($a['filesize'] == $b['filesize']) |
1245 | - return 0; |
|
1245 | + return 0; |
|
1246 | 1246 | return ($a['filesize'] < $b['filesize']) ? -1 : 1; |
1247 | 1247 | }); |
1248 | 1248 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | cache_put_data('wave_file/' . $user_info['ip2'], $ip2 ? $ip2 + 1 : 1, 20); |
39 | 39 | |
40 | 40 | // Fixate randomization for this word. |
41 | - $tmp = unpack('n', md5($word . session_id())); |
|
41 | + $tmp = unpack('n', md5($word . session_id())); |
|
42 | 42 | mt_srand(end($tmp)); |
43 | 43 | |
44 | 44 | // Try to see if there's a sound font in the user's language. |
@@ -18,10 +18,10 @@ |
||
18 | 18 | */ |
19 | 19 | class Birthday_Notify_Background extends SMF_BackgroundTask |
20 | 20 | { |
21 | - /** |
|
22 | - * This executes the task. It loads up the birthdays, figures out the greeting, etc. |
|
23 | - * @return bool Always returns true |
|
24 | - */ |
|
21 | + /** |
|
22 | + * This executes the task. It loads up the birthdays, figures out the greeting, etc. |
|
23 | + * @return bool Always returns true |
|
24 | + */ |
|
25 | 25 | public function execute() |
26 | 26 | { |
27 | 27 | global $txt, $smcFunc, $txtBirthdayEmails, $modSettings, $sourcedir; |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | class EventNew_Notify_Background extends SMF_BackgroundTask |
21 | 21 | { |
22 | 22 | /** |
23 | - * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
23 | + * This executes the task - loads up the information, puts the email in the queue and inserts alerts as needed. |
|
24 | 24 | * @return bool Always returns true |
25 | 25 | */ |
26 | 26 | public function execute() |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'content_action' => empty($this->_details['sender_id']) ? 'new_guest' : 'new', |
82 | 82 | 'is_read' => 0, |
83 | 83 | 'extra' => $smcFunc['json_encode']( |
84 | - array( |
|
85 | - "event_id" => $this->_details['event_id'], |
|
84 | + array( |
|
85 | + "event_id" => $this->_details['event_id'], |
|
86 | 86 | "event_title" => $this->_details['event_title'] |
87 | 87 | ) |
88 | 88 | ), |
@@ -5495,7 +5495,6 @@ discard block |
||
5495 | 5495 | |
5496 | 5496 | /** |
5497 | 5497 | * Tries different modes to make file/dirs writable. Wrapper function for chmod() |
5498 | - |
|
5499 | 5498 | * @param string $file The file/dir full path. |
5500 | 5499 | * @param int $value Not needed, added for legacy reasons. |
5501 | 5500 | * @return boolean true if the file/dir is already writable or the function was able to make it writable, false if the function couldn't make the file/dir writable. |
@@ -5535,7 +5534,6 @@ discard block |
||
5535 | 5534 | |
5536 | 5535 | /** |
5537 | 5536 | * Wrapper function for json_decode() with error handling. |
5538 | - |
|
5539 | 5537 | * @param string $json The string to decode. |
5540 | 5538 | * @param bool $returnAsArray To return the decoded string as an array or an object, SMF only uses Arrays but to keep on compatibility with json_decode its set to false as default. |
5541 | 5539 | * @param bool $logIt To specify if the error will be logged if theres any. |
@@ -6029,7 +6027,7 @@ discard block |
||
6029 | 6027 | $params = stream_context_get_params($stream); |
6030 | 6028 | $result = isset($params["options"]["ssl"]["peer_certificate"]) ? true : false; |
6031 | 6029 | } |
6032 | - return $result; |
|
6030 | + return $result; |
|
6033 | 6031 | } |
6034 | 6032 | |
6035 | 6033 | /** |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | |
21 | 21 | if (!defined('SMF')) |
22 | - die('No direct access...'); |
|
22 | + die('No direct access...'); |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * Punycode implementation as described in RFC 3492 |
@@ -28,332 +28,332 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class Punycode |
30 | 30 | { |
31 | - /** |
|
32 | - * Bootstring parameter values |
|
33 | - * |
|
34 | - */ |
|
35 | - const BASE = 36; |
|
36 | - const TMIN = 1; |
|
37 | - const TMAX = 26; |
|
38 | - const SKEW = 38; |
|
39 | - const DAMP = 700; |
|
40 | - const INITIAL_BIAS = 72; |
|
41 | - const INITIAL_N = 128; |
|
42 | - const PREFIX = 'xn--'; |
|
43 | - const DELIMITER = '-'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Encode table |
|
47 | - * |
|
48 | - * @param array |
|
49 | - */ |
|
50 | - protected static $encodeTable = array( |
|
51 | - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
|
52 | - 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', |
|
53 | - 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
|
54 | - ); |
|
55 | - |
|
56 | - /** |
|
57 | - * Decode table |
|
58 | - * |
|
59 | - * @param array |
|
60 | - */ |
|
61 | - protected static $decodeTable = array( |
|
62 | - 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, |
|
63 | - 'g' => 6, 'h' => 7, 'i' => 8, 'j' => 9, 'k' => 10, 'l' => 11, |
|
64 | - 'm' => 12, 'n' => 13, 'o' => 14, 'p' => 15, 'q' => 16, 'r' => 17, |
|
65 | - 's' => 18, 't' => 19, 'u' => 20, 'v' => 21, 'w' => 22, 'x' => 23, |
|
66 | - 'y' => 24, 'z' => 25, '0' => 26, '1' => 27, '2' => 28, '3' => 29, |
|
67 | - '4' => 30, '5' => 31, '6' => 32, '7' => 33, '8' => 34, '9' => 35 |
|
68 | - ); |
|
69 | - |
|
70 | - /** |
|
71 | - * Character encoding |
|
72 | - * |
|
73 | - * @param string |
|
74 | - */ |
|
75 | - protected $encoding; |
|
76 | - |
|
77 | - /** |
|
78 | - * Constructor |
|
79 | - * |
|
80 | - * @param string $encoding Character encoding |
|
81 | - */ |
|
82 | - public function __construct($encoding = 'UTF-8') |
|
83 | - { |
|
84 | - $this->encoding = $encoding; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Encode a domain to its Punycode version |
|
89 | - * |
|
90 | - * @param string $input Domain name in Unicode to be encoded |
|
91 | - * @return string Punycode representation in ASCII |
|
92 | - */ |
|
93 | - public function encode($input) |
|
94 | - { |
|
95 | - $input = mb_strtolower($input, $this->encoding); |
|
96 | - $parts = explode('.', $input); |
|
97 | - foreach ($parts as &$part) { |
|
98 | - $part = $this->encodePart($part); |
|
99 | - } |
|
100 | - $output = implode('.', $parts); |
|
101 | - $length = strlen($output); |
|
102 | - |
|
103 | - return $output; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Encode a part of a domain name, such as tld, to its Punycode version |
|
108 | - * |
|
109 | - * @param string $input Part of a domain name |
|
110 | - * @return string Punycode representation of a domain part |
|
111 | - */ |
|
112 | - protected function encodePart($input) |
|
113 | - { |
|
114 | - $codePoints = $this->listCodePoints($input); |
|
115 | - |
|
116 | - $n = static::INITIAL_N; |
|
117 | - $bias = static::INITIAL_BIAS; |
|
118 | - $delta = 0; |
|
119 | - $h = $b = count($codePoints['basic']); |
|
120 | - |
|
121 | - $output = ''; |
|
122 | - foreach ($codePoints['basic'] as $code) { |
|
123 | - $output .= $this->codePointToChar($code); |
|
124 | - } |
|
125 | - if ($input === $output) { |
|
126 | - return $output; |
|
127 | - } |
|
128 | - if ($b > 0) { |
|
129 | - $output .= static::DELIMITER; |
|
130 | - } |
|
131 | - |
|
132 | - $codePoints['nonBasic'] = array_unique($codePoints['nonBasic']); |
|
133 | - sort($codePoints['nonBasic']); |
|
134 | - |
|
135 | - $i = 0; |
|
136 | - $length = mb_strlen($input, $this->encoding); |
|
137 | - while ($h < $length) { |
|
138 | - $m = $codePoints['nonBasic'][$i++]; |
|
139 | - $delta = $delta + ($m - $n) * ($h + 1); |
|
140 | - $n = $m; |
|
141 | - |
|
142 | - foreach ($codePoints['all'] as $c) { |
|
143 | - if ($c < $n || $c < static::INITIAL_N) { |
|
144 | - $delta++; |
|
145 | - } |
|
146 | - if ($c === $n) { |
|
147 | - $q = $delta; |
|
148 | - for ($k = static::BASE;; $k += static::BASE) { |
|
149 | - $t = $this->calculateThreshold($k, $bias); |
|
150 | - if ($q < $t) { |
|
151 | - break; |
|
152 | - } |
|
153 | - |
|
154 | - $code = $t + (($q - $t) % (static::BASE - $t)); |
|
155 | - $output .= static::$encodeTable[$code]; |
|
156 | - |
|
157 | - $q = ($q - $t) / (static::BASE - $t); |
|
158 | - } |
|
159 | - |
|
160 | - $output .= static::$encodeTable[$q]; |
|
161 | - $bias = $this->adapt($delta, $h + 1, ($h === $b)); |
|
162 | - $delta = 0; |
|
163 | - $h++; |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - $delta++; |
|
168 | - $n++; |
|
169 | - } |
|
170 | - $out = static::PREFIX . $output; |
|
171 | - |
|
172 | - return $out; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Decode a Punycode domain name to its Unicode counterpart |
|
177 | - * |
|
178 | - * @param string $input Domain name in Punycode |
|
179 | - * @return string Unicode domain name |
|
180 | - */ |
|
181 | - public function decode($input) |
|
182 | - { |
|
183 | - $input = strtolower($input); |
|
184 | - $parts = explode('.', $input); |
|
185 | - foreach ($parts as &$part) { |
|
186 | - if (strpos($part, static::PREFIX) !== 0) { |
|
187 | - continue; |
|
188 | - } |
|
189 | - |
|
190 | - $part = substr($part, strlen(static::PREFIX)); |
|
191 | - $part = $this->decodePart($part); |
|
192 | - } |
|
193 | - $output = implode('.', $parts); |
|
194 | - |
|
195 | - return $output; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Decode a part of domain name, such as tld |
|
200 | - * |
|
201 | - * @param string $input Part of a domain name |
|
202 | - * @return string Unicode domain part |
|
203 | - */ |
|
204 | - protected function decodePart($input) |
|
205 | - { |
|
206 | - $n = static::INITIAL_N; |
|
207 | - $i = 0; |
|
208 | - $bias = static::INITIAL_BIAS; |
|
209 | - $output = ''; |
|
210 | - |
|
211 | - $pos = strrpos($input, static::DELIMITER); |
|
212 | - if ($pos !== false) { |
|
213 | - $output = substr($input, 0, $pos++); |
|
214 | - } else { |
|
215 | - $pos = 0; |
|
216 | - } |
|
217 | - |
|
218 | - $outputLength = strlen($output); |
|
219 | - $inputLength = strlen($input); |
|
220 | - while ($pos < $inputLength) { |
|
221 | - $oldi = $i; |
|
222 | - $w = 1; |
|
223 | - |
|
224 | - for ($k = static::BASE;; $k += static::BASE) { |
|
225 | - $digit = static::$decodeTable[$input[$pos++]]; |
|
226 | - $i = $i + ($digit * $w); |
|
227 | - $t = $this->calculateThreshold($k, $bias); |
|
228 | - |
|
229 | - if ($digit < $t) { |
|
230 | - break; |
|
231 | - } |
|
232 | - |
|
233 | - $w = $w * (static::BASE - $t); |
|
234 | - } |
|
235 | - |
|
236 | - $bias = $this->adapt($i - $oldi, ++$outputLength, ($oldi === 0)); |
|
237 | - $n = $n + (int) ($i / $outputLength); |
|
238 | - $i = $i % ($outputLength); |
|
239 | - $output = mb_substr($output, 0, $i, $this->encoding) . $this->codePointToChar($n) . mb_substr($output, $i, $outputLength - 1, $this->encoding); |
|
240 | - |
|
241 | - $i++; |
|
242 | - } |
|
243 | - |
|
244 | - return $output; |
|
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Calculate the bias threshold to fall between TMIN and TMAX |
|
249 | - * |
|
250 | - * @param integer $k |
|
251 | - * @param integer $bias |
|
252 | - * @return integer |
|
253 | - */ |
|
254 | - protected function calculateThreshold($k, $bias) |
|
255 | - { |
|
256 | - if ($k <= $bias + static::TMIN) { |
|
257 | - return static::TMIN; |
|
258 | - } elseif ($k >= $bias + static::TMAX) { |
|
259 | - return static::TMAX; |
|
260 | - } |
|
261 | - return $k - $bias; |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * Bias adaptation |
|
266 | - * |
|
267 | - * @param integer $delta |
|
268 | - * @param integer $numPoints |
|
269 | - * @param boolean $firstTime |
|
270 | - * @return integer |
|
271 | - */ |
|
272 | - protected function adapt($delta, $numPoints, $firstTime) |
|
273 | - { |
|
274 | - $delta = (int) ( |
|
275 | - ($firstTime) |
|
276 | - ? $delta / static::DAMP |
|
277 | - : $delta / 2 |
|
278 | - ); |
|
279 | - $delta += (int) ($delta / $numPoints); |
|
280 | - |
|
281 | - $k = 0; |
|
282 | - while ($delta > ((static::BASE - static::TMIN) * static::TMAX) / 2) { |
|
283 | - $delta = (int) ($delta / (static::BASE - static::TMIN)); |
|
284 | - $k = $k + static::BASE; |
|
285 | - } |
|
286 | - $k = $k + (int) (((static::BASE - static::TMIN + 1) * $delta) / ($delta + static::SKEW)); |
|
287 | - |
|
288 | - return $k; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * List code points for a given input |
|
293 | - * |
|
294 | - * @param string $input |
|
295 | - * @return array Multi-dimension array with basic, non-basic and aggregated code points |
|
296 | - */ |
|
297 | - protected function listCodePoints($input) |
|
298 | - { |
|
299 | - $codePoints = array( |
|
300 | - 'all' => array(), |
|
301 | - 'basic' => array(), |
|
302 | - 'nonBasic' => array(), |
|
303 | - ); |
|
304 | - |
|
305 | - $length = mb_strlen($input, $this->encoding); |
|
306 | - for ($i = 0; $i < $length; $i++) { |
|
307 | - $char = mb_substr($input, $i, 1, $this->encoding); |
|
308 | - $code = $this->charToCodePoint($char); |
|
309 | - if ($code < 128) { |
|
310 | - $codePoints['all'][] = $codePoints['basic'][] = $code; |
|
311 | - } else { |
|
312 | - $codePoints['all'][] = $codePoints['nonBasic'][] = $code; |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - return $codePoints; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Convert a single or multi-byte character to its code point |
|
321 | - * |
|
322 | - * @param string $char |
|
323 | - * @return integer |
|
324 | - */ |
|
325 | - protected function charToCodePoint($char) |
|
326 | - { |
|
327 | - $code = ord($char[0]); |
|
328 | - if ($code < 128) { |
|
329 | - return $code; |
|
330 | - } elseif ($code < 224) { |
|
331 | - return (($code - 192) * 64) + (ord($char[1]) - 128); |
|
332 | - } elseif ($code < 240) { |
|
333 | - return (($code - 224) * 4096) + ((ord($char[1]) - 128) * 64) + (ord($char[2]) - 128); |
|
334 | - } else { |
|
335 | - return (($code - 240) * 262144) + ((ord($char[1]) - 128) * 4096) + ((ord($char[2]) - 128) * 64) + (ord($char[3]) - 128); |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Convert a code point to its single or multi-byte character |
|
341 | - * |
|
342 | - * @param integer $code |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - protected function codePointToChar($code) |
|
346 | - { |
|
347 | - if ($code <= 0x7F) { |
|
348 | - return chr($code); |
|
349 | - } elseif ($code <= 0x7FF) { |
|
350 | - return chr(($code >> 6) + 192) . chr(($code & 63) + 128); |
|
351 | - } elseif ($code <= 0xFFFF) { |
|
352 | - return chr(($code >> 12) + 224) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); |
|
353 | - } else { |
|
354 | - return chr(($code >> 18) + 240) . chr((($code >> 12) & 63) + 128) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); |
|
355 | - } |
|
356 | - } |
|
31 | + /** |
|
32 | + * Bootstring parameter values |
|
33 | + * |
|
34 | + */ |
|
35 | + const BASE = 36; |
|
36 | + const TMIN = 1; |
|
37 | + const TMAX = 26; |
|
38 | + const SKEW = 38; |
|
39 | + const DAMP = 700; |
|
40 | + const INITIAL_BIAS = 72; |
|
41 | + const INITIAL_N = 128; |
|
42 | + const PREFIX = 'xn--'; |
|
43 | + const DELIMITER = '-'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Encode table |
|
47 | + * |
|
48 | + * @param array |
|
49 | + */ |
|
50 | + protected static $encodeTable = array( |
|
51 | + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', |
|
52 | + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', |
|
53 | + 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
|
54 | + ); |
|
55 | + |
|
56 | + /** |
|
57 | + * Decode table |
|
58 | + * |
|
59 | + * @param array |
|
60 | + */ |
|
61 | + protected static $decodeTable = array( |
|
62 | + 'a' => 0, 'b' => 1, 'c' => 2, 'd' => 3, 'e' => 4, 'f' => 5, |
|
63 | + 'g' => 6, 'h' => 7, 'i' => 8, 'j' => 9, 'k' => 10, 'l' => 11, |
|
64 | + 'm' => 12, 'n' => 13, 'o' => 14, 'p' => 15, 'q' => 16, 'r' => 17, |
|
65 | + 's' => 18, 't' => 19, 'u' => 20, 'v' => 21, 'w' => 22, 'x' => 23, |
|
66 | + 'y' => 24, 'z' => 25, '0' => 26, '1' => 27, '2' => 28, '3' => 29, |
|
67 | + '4' => 30, '5' => 31, '6' => 32, '7' => 33, '8' => 34, '9' => 35 |
|
68 | + ); |
|
69 | + |
|
70 | + /** |
|
71 | + * Character encoding |
|
72 | + * |
|
73 | + * @param string |
|
74 | + */ |
|
75 | + protected $encoding; |
|
76 | + |
|
77 | + /** |
|
78 | + * Constructor |
|
79 | + * |
|
80 | + * @param string $encoding Character encoding |
|
81 | + */ |
|
82 | + public function __construct($encoding = 'UTF-8') |
|
83 | + { |
|
84 | + $this->encoding = $encoding; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Encode a domain to its Punycode version |
|
89 | + * |
|
90 | + * @param string $input Domain name in Unicode to be encoded |
|
91 | + * @return string Punycode representation in ASCII |
|
92 | + */ |
|
93 | + public function encode($input) |
|
94 | + { |
|
95 | + $input = mb_strtolower($input, $this->encoding); |
|
96 | + $parts = explode('.', $input); |
|
97 | + foreach ($parts as &$part) { |
|
98 | + $part = $this->encodePart($part); |
|
99 | + } |
|
100 | + $output = implode('.', $parts); |
|
101 | + $length = strlen($output); |
|
102 | + |
|
103 | + return $output; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Encode a part of a domain name, such as tld, to its Punycode version |
|
108 | + * |
|
109 | + * @param string $input Part of a domain name |
|
110 | + * @return string Punycode representation of a domain part |
|
111 | + */ |
|
112 | + protected function encodePart($input) |
|
113 | + { |
|
114 | + $codePoints = $this->listCodePoints($input); |
|
115 | + |
|
116 | + $n = static::INITIAL_N; |
|
117 | + $bias = static::INITIAL_BIAS; |
|
118 | + $delta = 0; |
|
119 | + $h = $b = count($codePoints['basic']); |
|
120 | + |
|
121 | + $output = ''; |
|
122 | + foreach ($codePoints['basic'] as $code) { |
|
123 | + $output .= $this->codePointToChar($code); |
|
124 | + } |
|
125 | + if ($input === $output) { |
|
126 | + return $output; |
|
127 | + } |
|
128 | + if ($b > 0) { |
|
129 | + $output .= static::DELIMITER; |
|
130 | + } |
|
131 | + |
|
132 | + $codePoints['nonBasic'] = array_unique($codePoints['nonBasic']); |
|
133 | + sort($codePoints['nonBasic']); |
|
134 | + |
|
135 | + $i = 0; |
|
136 | + $length = mb_strlen($input, $this->encoding); |
|
137 | + while ($h < $length) { |
|
138 | + $m = $codePoints['nonBasic'][$i++]; |
|
139 | + $delta = $delta + ($m - $n) * ($h + 1); |
|
140 | + $n = $m; |
|
141 | + |
|
142 | + foreach ($codePoints['all'] as $c) { |
|
143 | + if ($c < $n || $c < static::INITIAL_N) { |
|
144 | + $delta++; |
|
145 | + } |
|
146 | + if ($c === $n) { |
|
147 | + $q = $delta; |
|
148 | + for ($k = static::BASE;; $k += static::BASE) { |
|
149 | + $t = $this->calculateThreshold($k, $bias); |
|
150 | + if ($q < $t) { |
|
151 | + break; |
|
152 | + } |
|
153 | + |
|
154 | + $code = $t + (($q - $t) % (static::BASE - $t)); |
|
155 | + $output .= static::$encodeTable[$code]; |
|
156 | + |
|
157 | + $q = ($q - $t) / (static::BASE - $t); |
|
158 | + } |
|
159 | + |
|
160 | + $output .= static::$encodeTable[$q]; |
|
161 | + $bias = $this->adapt($delta, $h + 1, ($h === $b)); |
|
162 | + $delta = 0; |
|
163 | + $h++; |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + $delta++; |
|
168 | + $n++; |
|
169 | + } |
|
170 | + $out = static::PREFIX . $output; |
|
171 | + |
|
172 | + return $out; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Decode a Punycode domain name to its Unicode counterpart |
|
177 | + * |
|
178 | + * @param string $input Domain name in Punycode |
|
179 | + * @return string Unicode domain name |
|
180 | + */ |
|
181 | + public function decode($input) |
|
182 | + { |
|
183 | + $input = strtolower($input); |
|
184 | + $parts = explode('.', $input); |
|
185 | + foreach ($parts as &$part) { |
|
186 | + if (strpos($part, static::PREFIX) !== 0) { |
|
187 | + continue; |
|
188 | + } |
|
189 | + |
|
190 | + $part = substr($part, strlen(static::PREFIX)); |
|
191 | + $part = $this->decodePart($part); |
|
192 | + } |
|
193 | + $output = implode('.', $parts); |
|
194 | + |
|
195 | + return $output; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Decode a part of domain name, such as tld |
|
200 | + * |
|
201 | + * @param string $input Part of a domain name |
|
202 | + * @return string Unicode domain part |
|
203 | + */ |
|
204 | + protected function decodePart($input) |
|
205 | + { |
|
206 | + $n = static::INITIAL_N; |
|
207 | + $i = 0; |
|
208 | + $bias = static::INITIAL_BIAS; |
|
209 | + $output = ''; |
|
210 | + |
|
211 | + $pos = strrpos($input, static::DELIMITER); |
|
212 | + if ($pos !== false) { |
|
213 | + $output = substr($input, 0, $pos++); |
|
214 | + } else { |
|
215 | + $pos = 0; |
|
216 | + } |
|
217 | + |
|
218 | + $outputLength = strlen($output); |
|
219 | + $inputLength = strlen($input); |
|
220 | + while ($pos < $inputLength) { |
|
221 | + $oldi = $i; |
|
222 | + $w = 1; |
|
223 | + |
|
224 | + for ($k = static::BASE;; $k += static::BASE) { |
|
225 | + $digit = static::$decodeTable[$input[$pos++]]; |
|
226 | + $i = $i + ($digit * $w); |
|
227 | + $t = $this->calculateThreshold($k, $bias); |
|
228 | + |
|
229 | + if ($digit < $t) { |
|
230 | + break; |
|
231 | + } |
|
232 | + |
|
233 | + $w = $w * (static::BASE - $t); |
|
234 | + } |
|
235 | + |
|
236 | + $bias = $this->adapt($i - $oldi, ++$outputLength, ($oldi === 0)); |
|
237 | + $n = $n + (int) ($i / $outputLength); |
|
238 | + $i = $i % ($outputLength); |
|
239 | + $output = mb_substr($output, 0, $i, $this->encoding) . $this->codePointToChar($n) . mb_substr($output, $i, $outputLength - 1, $this->encoding); |
|
240 | + |
|
241 | + $i++; |
|
242 | + } |
|
243 | + |
|
244 | + return $output; |
|
245 | + } |
|
246 | + |
|
247 | + /** |
|
248 | + * Calculate the bias threshold to fall between TMIN and TMAX |
|
249 | + * |
|
250 | + * @param integer $k |
|
251 | + * @param integer $bias |
|
252 | + * @return integer |
|
253 | + */ |
|
254 | + protected function calculateThreshold($k, $bias) |
|
255 | + { |
|
256 | + if ($k <= $bias + static::TMIN) { |
|
257 | + return static::TMIN; |
|
258 | + } elseif ($k >= $bias + static::TMAX) { |
|
259 | + return static::TMAX; |
|
260 | + } |
|
261 | + return $k - $bias; |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * Bias adaptation |
|
266 | + * |
|
267 | + * @param integer $delta |
|
268 | + * @param integer $numPoints |
|
269 | + * @param boolean $firstTime |
|
270 | + * @return integer |
|
271 | + */ |
|
272 | + protected function adapt($delta, $numPoints, $firstTime) |
|
273 | + { |
|
274 | + $delta = (int) ( |
|
275 | + ($firstTime) |
|
276 | + ? $delta / static::DAMP |
|
277 | + : $delta / 2 |
|
278 | + ); |
|
279 | + $delta += (int) ($delta / $numPoints); |
|
280 | + |
|
281 | + $k = 0; |
|
282 | + while ($delta > ((static::BASE - static::TMIN) * static::TMAX) / 2) { |
|
283 | + $delta = (int) ($delta / (static::BASE - static::TMIN)); |
|
284 | + $k = $k + static::BASE; |
|
285 | + } |
|
286 | + $k = $k + (int) (((static::BASE - static::TMIN + 1) * $delta) / ($delta + static::SKEW)); |
|
287 | + |
|
288 | + return $k; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * List code points for a given input |
|
293 | + * |
|
294 | + * @param string $input |
|
295 | + * @return array Multi-dimension array with basic, non-basic and aggregated code points |
|
296 | + */ |
|
297 | + protected function listCodePoints($input) |
|
298 | + { |
|
299 | + $codePoints = array( |
|
300 | + 'all' => array(), |
|
301 | + 'basic' => array(), |
|
302 | + 'nonBasic' => array(), |
|
303 | + ); |
|
304 | + |
|
305 | + $length = mb_strlen($input, $this->encoding); |
|
306 | + for ($i = 0; $i < $length; $i++) { |
|
307 | + $char = mb_substr($input, $i, 1, $this->encoding); |
|
308 | + $code = $this->charToCodePoint($char); |
|
309 | + if ($code < 128) { |
|
310 | + $codePoints['all'][] = $codePoints['basic'][] = $code; |
|
311 | + } else { |
|
312 | + $codePoints['all'][] = $codePoints['nonBasic'][] = $code; |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + return $codePoints; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Convert a single or multi-byte character to its code point |
|
321 | + * |
|
322 | + * @param string $char |
|
323 | + * @return integer |
|
324 | + */ |
|
325 | + protected function charToCodePoint($char) |
|
326 | + { |
|
327 | + $code = ord($char[0]); |
|
328 | + if ($code < 128) { |
|
329 | + return $code; |
|
330 | + } elseif ($code < 224) { |
|
331 | + return (($code - 192) * 64) + (ord($char[1]) - 128); |
|
332 | + } elseif ($code < 240) { |
|
333 | + return (($code - 224) * 4096) + ((ord($char[1]) - 128) * 64) + (ord($char[2]) - 128); |
|
334 | + } else { |
|
335 | + return (($code - 240) * 262144) + ((ord($char[1]) - 128) * 4096) + ((ord($char[2]) - 128) * 64) + (ord($char[3]) - 128); |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Convert a code point to its single or multi-byte character |
|
341 | + * |
|
342 | + * @param integer $code |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + protected function codePointToChar($code) |
|
346 | + { |
|
347 | + if ($code <= 0x7F) { |
|
348 | + return chr($code); |
|
349 | + } elseif ($code <= 0x7FF) { |
|
350 | + return chr(($code >> 6) + 192) . chr(($code & 63) + 128); |
|
351 | + } elseif ($code <= 0xFFFF) { |
|
352 | + return chr(($code >> 12) + 224) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); |
|
353 | + } else { |
|
354 | + return chr(($code >> 18) + 240) . chr((($code >> 12) & 63) + 128) . chr((($code >> 6) & 63) + 128) . chr(($code & 63) + 128); |
|
355 | + } |
|
356 | + } |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | ?> |
360 | 360 | \ No newline at end of file |
@@ -429,7 +429,7 @@ |
||
429 | 429 | */ |
430 | 430 | function matchIPtoCIDR($ip_address, $cidr_address) |
431 | 431 | { |
432 | - list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address); |
|
432 | + list ($cidr_network, $cidr_subnetmask) = preg_split('/', $cidr_address); |
|
433 | 433 | |
434 | 434 | //v6? |
435 | 435 | if ((strpos($cidr_network, ':') !== false)) |