2006-08-12 18:58:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/URIScheme.php';
|
|
|
|
|
2006-08-20 22:06:11 +00:00
|
|
|
/**
|
|
|
|
* Validates ftp (File Transfer Protocol) URIs as defined by generic RFC 1738.
|
|
|
|
*/
|
2006-08-12 18:58:54 +00:00
|
|
|
class HTMLPurifier_URIScheme_ftp extends HTMLPurifier_URIScheme {
|
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
public $default_port = 21;
|
|
|
|
public $browsable = true; // usually
|
|
|
|
public $hierarchical = true;
|
2006-08-12 18:58:54 +00:00
|
|
|
|
2007-11-25 02:24:39 +00:00
|
|
|
public function validate(&$uri, $config, &$context) {
|
2007-08-01 18:34:46 +00:00
|
|
|
parent::validate($uri, $config, $context);
|
|
|
|
$uri->query = null;
|
|
|
|
|
|
|
|
// typecode check
|
|
|
|
$semicolon_pos = strrpos($uri->path, ';'); // reverse
|
2006-09-30 17:24:12 +00:00
|
|
|
if ($semicolon_pos !== false) {
|
2007-08-01 18:34:46 +00:00
|
|
|
$type = substr($uri->path, $semicolon_pos + 1); // no semicolon
|
|
|
|
$uri->path = substr($uri->path, 0, $semicolon_pos);
|
2006-09-30 17:24:12 +00:00
|
|
|
$type_ret = '';
|
|
|
|
if (strpos($type, '=') !== false) {
|
|
|
|
// figure out whether or not the declaration is correct
|
|
|
|
list($key, $typecode) = explode('=', $type, 2);
|
|
|
|
if ($key !== 'type') {
|
|
|
|
// invalid key, tack it back on encoded
|
2007-08-01 18:34:46 +00:00
|
|
|
$uri->path .= '%3B' . $type;
|
2006-09-30 17:24:12 +00:00
|
|
|
} elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
|
|
|
|
$type_ret = ";type=$typecode";
|
|
|
|
}
|
|
|
|
} else {
|
2007-08-01 18:34:46 +00:00
|
|
|
$uri->path .= '%3B' . $type;
|
2006-09-30 17:24:12 +00:00
|
|
|
}
|
2007-08-01 18:34:46 +00:00
|
|
|
$uri->path = str_replace(';', '%3B', $uri->path);
|
|
|
|
$uri->path .= $type_ret;
|
2006-09-30 17:24:12 +00:00
|
|
|
}
|
2007-08-01 18:34:46 +00:00
|
|
|
|
|
|
|
return true;
|
2006-08-12 18:58:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|