tel.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Validates tel (for phone numbers).
  4. *
  5. * The relevant specifications for this protocol are RFC 3966 and RFC 5341,
  6. * but this class takes a much simpler approach: we normalize phone
  7. * numbers so that they only include (possibly) a leading plus,
  8. * and then any number of digits and x'es.
  9. */
  10. class HTMLPurifier_URIScheme_tel extends HTMLPurifier_URIScheme
  11. {
  12. /**
  13. * @type bool
  14. */
  15. public $browsable = false;
  16. /**
  17. * @type bool
  18. */
  19. public $may_omit_host = true;
  20. /**
  21. * @param HTMLPurifier_URI $uri
  22. * @param HTMLPurifier_Config $config
  23. * @param HTMLPurifier_Context $context
  24. * @return bool
  25. */
  26. public function doValidate(&$uri, $config, $context)
  27. {
  28. $uri->userinfo = null;
  29. $uri->host = null;
  30. $uri->port = null;
  31. // Delete all non-numeric characters, non-x characters
  32. // from phone number, EXCEPT for a leading plus sign.
  33. $uri->path = preg_replace('/(?!^\+)[^\dx]/', '',
  34. // Normalize e(x)tension to lower-case
  35. str_replace('X', 'x', $uri->path));
  36. return true;
  37. }
  38. }
  39. // vim: et sw=4 sts=4