| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /** |
|---|
| 4 | * Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738. |
|---|
| 5 | */ |
|---|
| 6 | class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme { |
|---|
| 7 | |
|---|
| 8 | public $default_port = 21; |
|---|
| 9 | public $browsable = true; // usually |
|---|
| 10 | public $hierarchical = true; |
|---|
| 11 | |
|---|
| 12 | public function validate(&$uri, $config, $context) { |
|---|
| 13 | parent::validate($uri, $config, $context); |
|---|
| 14 | $uri->query = null; |
|---|
| 15 | |
|---|
| 16 | // typecode check |
|---|
| 17 | $semicolon_pos = strrpos($uri->path, ';'); // reverse |
|---|
| 18 | if ($semicolon_pos !== false) { |
|---|
| 19 | $type = substr($uri->path, $semicolon_pos + 1); // no semicolon |
|---|
| 20 | $uri->path = substr($uri->path, 0, $semicolon_pos); |
|---|
| 21 | $type_ret = ''; |
|---|
| 22 | if (strpos($type, '=') !== false) { |
|---|
| 23 | // figure out whether or not the declaration is correct |
|---|
| 24 | list($key, $typecode) = explode('=', $type, 2); |
|---|
| 25 | if ($key !== 'type') { |
|---|
| 26 | // invalid key, tack it back on encoded |
|---|
| 27 | $uri->path .= '%3B' . $type; |
|---|
| 28 | } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') { |
|---|
| 29 | $type_ret = ";type=$typecode"; |
|---|
| 30 | } |
|---|
| 31 | } else { |
|---|
| 32 | $uri->path .= '%3B' . $type; |
|---|
| 33 | } |
|---|
| 34 | $uri->path = str_replace(';', '%3B', $uri->path); |
|---|
| 35 | $uri->path .= $type_ret; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | return true; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | } |
|---|
| 42 | |
|---|