1: <?php
2:
3: 4: 5: 6:
7: class HTMLPurifier_URIParser
8: {
9:
10: 11: 12:
13: protected $percentEncoder;
14:
15: public function __construct() {
16: $this->percentEncoder = new HTMLPurifier_PercentEncoder();
17: }
18:
19: 20: 21: 22: 23: 24:
25: public function parse($uri) {
26:
27: $uri = $this->percentEncoder->normalize($uri);
28:
29:
30:
31:
32: $r_URI = '!'.
33: '(([^:/?#"<>]+):)?'.
34: '(//([^/?#"<>]*))?'.
35: '([^?#"<>]*)'.
36: '(\?([^#"<>]*))?'.
37: '(#([^"<>]*))?'.
38: '!';
39:
40: $matches = array();
41: $result = preg_match($r_URI, $uri, $matches);
42:
43: if (!$result) return false;
44:
45:
46: $scheme = !empty($matches[1]) ? $matches[2] : null;
47: $authority = !empty($matches[3]) ? $matches[4] : null;
48: $path = $matches[5];
49: $query = !empty($matches[6]) ? $matches[7] : null;
50: $fragment = !empty($matches[8]) ? $matches[9] : null;
51:
52:
53: if ($authority !== null) {
54: $r_authority = "/^((.+?)@)?(\[[^\]]+\]|[^:]*)(:(\d*))?/";
55: $matches = array();
56: preg_match($r_authority, $authority, $matches);
57: $userinfo = !empty($matches[1]) ? $matches[2] : null;
58: $host = !empty($matches[3]) ? $matches[3] : '';
59: $port = !empty($matches[4]) ? (int) $matches[5] : null;
60: } else {
61: $port = $host = $userinfo = null;
62: }
63:
64: return new HTMLPurifier_URI(
65: $scheme, $userinfo, $host, $port, $path, $query, $fragment);
66: }
67:
68: }
69:
70:
71: