ftp.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 doValidate(&$uri, $config, $context) {
  10. $uri->query = null;
  11. // typecode check
  12. $semicolon_pos = strrpos($uri->path, ';'); // reverse
  13. if ($semicolon_pos !== false) {
  14. $type = substr($uri->path, $semicolon_pos + 1); // no semicolon
  15. $uri->path = substr($uri->path, 0, $semicolon_pos);
  16. $type_ret = '';
  17. if (strpos($type, '=') !== false) {
  18. // figure out whether or not the declaration is correct
  19. list($key, $typecode) = explode('=', $type, 2);
  20. if ($key !== 'type') {
  21. // invalid key, tack it back on encoded
  22. $uri->path .= '%3B' . $type;
  23. } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
  24. $type_ret = ";type=$typecode";
  25. }
  26. } else {
  27. $uri->path .= '%3B' . $type;
  28. }
  29. $uri->path = str_replace(';', '%3B', $uri->path);
  30. $uri->path .= $type_ret;
  31. }
  32. return true;
  33. }
  34. }
  35. // vim: et sw=4 sts=4