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.
yanzong/vendor/ezyang/htmlpurifier/library/HTMLPurifier/URIScheme/tel.php

47 lines
1.2 KiB

11 months ago
<?php
/**
* Validates tel (for phone numbers).
*
* The relevant specifications for this protocol are RFC 3966 and RFC 5341,
* but this class takes a much simpler approach: we normalize phone
* numbers so that they only include (possibly) a leading plus,
* and then any number of digits and x'es.
*/
class HTMLPurifier_URIScheme_tel extends HTMLPurifier_URIScheme
{
/**
* @type bool
*/
public $browsable = false;
/**
* @type bool
*/
public $may_omit_host = true;
/**
* @param HTMLPurifier_URI $uri
* @param HTMLPurifier_Config $config
* @param HTMLPurifier_Context $context
* @return bool
*/
public function doValidate(&$uri, $config, $context)
{
$uri->userinfo = null;
$uri->host = null;
$uri->port = null;
6 months ago
// Delete all non-numeric characters, commas, and non-x characters
11 months ago
// from phone number, EXCEPT for a leading plus sign.
6 months ago
$uri->path = preg_replace('/(?!^\+)[^\dx,]/', '',
11 months ago
// Normalize e(x)tension to lower-case
6 months ago
str_replace('X', 'x', rawurldecode($uri->path)));
11 months ago
return true;
}
}
// vim: et sw=4 sts=4