📄 urlformatrule.class.php
字号:
*/ /* Check the protocol */ if ($url['Protocol']) { $tmp = preg_replace("/[^a-z0-9+-.]/", '', $url['Protocol']); if ($tmp != $url['Protocol']) { $errArr[EW_ERR_URL_INVALID_PROTOCOL] = EW_ERR_URL_INVALID_PROTOCOL; } if (count($options['AllowedProtocols'])) if (!in_array($url['Protocol'], $options['AllowedProtocols'])) $errArr[EW_ERR_URL_INVALID_PROTOCOL] = EW_ERR_URL_INVALID_PROTOCOL; } /* check userinfo */ if ($url['User']) { /* Check for % that is NOT an escape sequence */ if (preg_match('/%[^a-f0-9]/i', $url['User']) || preg_match("/[^a-z0-9;&=+$,_.!~*'()%-]/i", $url['User'])) { $errArr[EW_ERR_URL_INVALID_USER] = EW_ERR_URL_INVALID_USER; $url['User'] = urlencode(urldecode($url['User'])); } } if ($url['Password']) { /* Check for % that is NOT an escape sequence */ if (preg_match('/%[^a-f0-9]/i', $url['Password']) || preg_match("/[^a-z0-9;&=+$,_.!~*'()%-]/i", $url['Password'])) { $errArr[EW_ERR_URL_INVALID_PASSWORD] = EW_ERR_URL_INVALID_PASSWORD; } $url['Password'] = urlencode(urldecode($url['Password'])); } // userinfo = *( unreserved | escaped | // ";" | ":" | "&" | "=" | "+" | "$" | "," ) // unreserved = alphanum | mark // mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | // "(" | ")" // escaped = "%" hex hex /* Check if the server part is an ip */ if ($url['Server']) { if (!preg_match('/[^.0-9]/', $url['Server'])) { $ServerIsIP = true; $ipErr = false; $ipPart = explode('.', $url['Server']); if ($ipPart[0] > 224 || $ipPart[0] == 0) { $errArr[EW_ERR_URL_INVALID_SERVER] = EW_ERR_URL_INVALID_SERVER; } else { for ($i = 1; $i < 4; $i ++) { $ipPart[$i] = (integer) $ipPart[$i]; if ($ipPart[$i] > 255) $errArr[EW_ERR_URL_INVALID_SERVER] = EW_ERR_URL_INVALID_SERVER; } } /** * @todo Implement checking for reserved class D and E, and * other reserved addresses such as 0.0.0.0 or 255.255.255.255 * and ip-addresses where either the host or the network part * is all binary 0s or all binary 1s * check: * http://www.cisco.com/univercd/cc/td/doc/product/atm/l2020/2020r21x/planning/appndxa.htm#xtocid87496 */ $url['Server'] = join('.', $ipPart); } /* url is not an ip */ else { $ServerIsIP = false; $serverParts = explode('.', $url['Server']); /* check serverparts */ for ($i = 0; $i < count($serverParts); $i ++) { $tmp = preg_replace('/[^a-z0-9-]/', '', $serverParts[$i]); /* Check if it is a top-level server */ if ($i && $i == count($serverParts) - 1) $tmp = preg_replace('/^[^a-z]/', '', $tmp); else $tmp = preg_replace('/^[^a-z0-9]/', '', $serverParts[$i]); $tmp = preg_replace('/[^a-z0-9]$/', '', $tmp); if ($serverParts[$i] == '' || $tmp != $serverParts[$i]) { if ($tmp != '') $serverParts[$i] = $tmp; else unset($serverParts[$i]); $errArr[EW_ERR_URL_INVALID_SERVER] = EW_ERR_URL_INVALID_SERVER; } } if (count($serverParts) < 2) { if ($Require['TLD']) { $errArr[EW_ERR_URL_MISSING_TLD] = EW_ERR_URL_MISSING_TLD; } } else { $url['TLD'] = $serverParts[count($serverParts) - 1]; } $url['Server'] = join('.', $serverParts); } } /* Check the Port */ if ($url['Port']) { $tmp = (integer) $url['Port']; if ($url['Port'] != (string) $tmp) { $errArr[EW_ERR_URL_INVALID_PORT] = EW_ERR_URL_INVALID_PORT; $url['Port'] = ''; } else { $url['Port'] = $tmp; if ($url['Port'] > 65535) $errArr[EW_ERR_URL_INVALID_PORT] = EW_ERR_URL_INVALID_PORT; } } /* Check the resource */ //path = [ abs_path | opaque_part ] //path_segments = segment *( "/" segment ) //segment = *pchar *( ";" param ) //param = *pchar //pchar = unreserved | escaped | // ":" | "@" | "&" | "=" | "+" | "$" | "," if ($url['Resource']) { $resourceParts = explode('/', $url['Resource']); if ($resourceParts[count($resourceParts) - 1] == '') array_pop($resourceParts); if ($resourceParts[0] == '') unset($resourceParts[0]); foreach ($resourceParts as $key => $part) { if ($part == '') { $errArr[EW_ERR_URL_INVALID_RESOURCE] = EW_ERR_URL_INVALID_RESOURCE; unset($resourceParts[$key]); } /* Check for % that is NOT an escape sequence || invalid chars*/ elseif (preg_match('/%[^a-f0-9]/i', $part) || preg_match("/[^@a-z0-9_.!~*'()$+&,%:=;?-]/i", $part)) { $errArr[EW_ERR_URL_INVALID_RESOURCE] = EW_ERR_URL_INVALID_RESOURCE; $resourceParts[$key] = urlencode(urldecode($part)); } /* check for invalid chars */ } $url['Resource'] = join('/', $resourceParts); } if ($url['QueryString']) { /* Check for % NOT part of an escape sequence || invalid chars */ $tmp = $options['AllowBracks'] ? /**/ "^a-z0-9_.!~*'()%;\/?:@&=+$,\[\]-" : /**/ "^a-z0-9_.!~*'()%;\/?:@&=+$,-"; /**/ if (preg_match('/%[^a-f0-9]/i', $url['QueryString']) || preg_match("/[$tmp]+/i", $url['QueryString'])) { $errArr[EW_ERR_URL_INVALID_QUERYSTRING] = EW_ERR_URL_INVALID_QUERYSTRING; $url['QueryString'] = $url['QueryString']; } } if ($url['Anchor']) { if (preg_match('/%[^a-f0-9][a-f0-9]?/i', $url['Anchor']) || // preg_match("/[^a-z0-9-_.!~*'()%;\/?:@&=+$,]/i", $url['Anchor'])) { $errArr[EW_ERR_URL_INVALID_ANCHOR] = EW_ERR_URL_INVALID_ANCHOR; $url['Anchor'] = $url['Anchor']; } } foreach ($url as $partName => $notused) { if ($partName == 'TLD' && $ServerIsIP) continue; if ($Require[$partName] && !$url[$partName]) $errArr[$errCodeMissing[$partName]] = $errCodeMissing[$partName]; if ($Forbid[$partName] && $url[$partName]) $errArr[$errCodeMissing[$partName]] = $errCodeInvalid[$partName]; } /* Construct an estimate of what the value should've been */ if ($options['AssumeProtocol'] && !$url['Protocol'] && ($url['Server'] || (!$url['Server'] && !$url['Resource']))) $url['Protocol'] = $options['AssumeProtocol']; $value = $url['Protocol']; if ($url['Protocol']) { if ($url['Protocol'] == 'mailto' | $url['Protocol'] == 'mailto') $value.= ':'; else $value.= '://'; } if ($url['User']) { if ($url['Password']) $value.= "{$url['User']}:{$url['Password']}"; else $value.= "{$url['User']}"; if ($url['Server']) $value.= '@'; } $value.= $url['Server']; if ($url['Port']) $value.= ":{$url['Port']}"; if ($url['Server'] && $url['Resource']) $value.= "/"; $value.= $url['Resource']; if ($url['QueryString']) $value.= "?{$url['QueryString']}"; if ($url['Anchor']) $value.= "#{$url['Anchor']}"; $r = array('Result' => count($errArr) ? $errArr : EW_OK, 'Value' => $value, 'URLParts' => $url); return $r; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -