You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 8 години
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. {
  7. /**
  8. * @type int
  9. */
  10. public $default_port = 21;
  11. /**
  12. * @type bool
  13. */
  14. public $browsable = true; // usually
  15. /**
  16. * @type bool
  17. */
  18. public $hierarchical = true;
  19. /**
  20. * @param HTMLPurifier_URI $uri
  21. * @param HTMLPurifier_Config $config
  22. * @param HTMLPurifier_Context $context
  23. * @return bool
  24. */
  25. public function doValidate(&$uri, $config, $context)
  26. {
  27. $uri->query = null;
  28. // typecode check
  29. $semicolon_pos = strrpos($uri->path, ';'); // reverse
  30. if ($semicolon_pos !== false) {
  31. $type = substr($uri->path, $semicolon_pos + 1); // no semicolon
  32. $uri->path = substr($uri->path, 0, $semicolon_pos);
  33. $type_ret = '';
  34. if (strpos($type, '=') !== false) {
  35. // figure out whether or not the declaration is correct
  36. list($key, $typecode) = explode('=', $type, 2);
  37. if ($key !== 'type') {
  38. // invalid key, tack it back on encoded
  39. $uri->path .= '%3B' . $type;
  40. } elseif ($typecode === 'a' || $typecode === 'i' || $typecode === 'd') {
  41. $type_ret = ";type=$typecode";
  42. }
  43. } else {
  44. $uri->path .= '%3B' . $type;
  45. }
  46. $uri->path = str_replace(';', '%3B', $uri->path);
  47. $uri->path .= $type_ret;
  48. }
  49. return true;
  50. }
  51. }
  52. // vim: et sw=4 sts=4