Completed
Push — master ( 14e79d...7a4940 )
by Richard
08:21
created

HTMLPurifier_URIScheme_tel::doValidate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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