ftp.php 1.4 KB

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