Release 2.0.1, merged in 1181 to HEAD.
[htmlpurifier.git] / library / HTMLPurifier / URIScheme / ftp.php
blob3dbb1446b725458d0902464fc1e83f5633954a3e
1 <?php
3 require_once 'HTMLPurifier/URIScheme.php';
5 /**
6 * Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738.
7 */
8 class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme {
10 var $default_port = 21;
11 var $browsable = true; // usually
13 function validateComponents(
14 $userinfo, $host, $port, $path, $query, $config, &$context
15 ) {
16 list($userinfo, $host, $port, $path, $query) =
17 parent::validateComponents(
18 $userinfo, $host, $port, $path, $query, $config, $context );
19 $semicolon_pos = strrpos($path, ';'); // reverse
20 if ($semicolon_pos !== false) {
21 // typecode check
22 $type = substr($path, $semicolon_pos + 1); // no semicolon
23 $path = substr($path, 0, $semicolon_pos);
24 $type_ret = '';
25 if (strpos($type, '=') !== false) {
26 // figure out whether or not the declaration is correct
27 list($key, $typecode) = explode('=', $type, 2);
28 if ($key !== 'type') {
29 // invalid key, tack it back on encoded
30 $path .= '%3B' . $type;
31 } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
32 $type_ret = ";type=$typecode";
34 } else {
35 $path .= '%3B' . $type;
37 $path = str_replace(';', '%3B', $path);
38 $path .= $type_ret;
40 return array($userinfo, $host, $port, $path, null);