File indexing completed on 2024-12-22 05:36:21

0001 <?php
0002 
0003 /**
0004  * Validates tel (for phone numbers).
0005  *
0006  * The relevant specifications for this protocol are RFC 3966 and RFC 5341,
0007  * but this class takes a much simpler approach: we normalize phone
0008  * numbers so that they only include (possibly) a leading plus,
0009  * and then any number of digits and x'es.
0010  */
0011 
0012 class HTMLPurifier_URIScheme_tel extends HTMLPurifier_URIScheme
0013 {
0014     /**
0015      * @type bool
0016      */
0017     public $browsable = false;
0018 
0019     /**
0020      * @type bool
0021      */
0022     public $may_omit_host = true;
0023 
0024     /**
0025      * @param HTMLPurifier_URI $uri
0026      * @param HTMLPurifier_Config $config
0027      * @param HTMLPurifier_Context $context
0028      * @return bool
0029      */
0030     public function doValidate(&$uri, $config, $context)
0031     {
0032         $uri->userinfo = null;
0033         $uri->host     = null;
0034         $uri->port     = null;
0035 
0036         // Delete all non-numeric characters, non-x characters
0037         // from phone number, EXCEPT for a leading plus sign.
0038         $uri->path = preg_replace('/(?!^\+)[^\dx]/', '',
0039                      // Normalize e(x)tension to lower-case
0040                      str_replace('X', 'x', $uri->path));
0041 
0042         return true;
0043     }
0044 }
0045 
0046 // vim: et sw=4 sts=4