1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| <?php
/**
* Create tt_address phone link
*
* @param string $orig tt_address telephone number
* @param array $conf Typoscript configuration for this userfunc
*
* @return string HTML code with a link to the telephone number
*/
function user_tt_address_tel($orig, $conf)
{
return '<a class="tel" href="tel:'
. htmlspecialchars(format_telephone_number_rfc3966($orig, $conf))
. '">' . $orig . '</a>';
}
/**
* Convert a telephone number into a full-featured RFC 3966 telephone number
*
* @param string $orig Original telephone number, may be partial
* @param array $conf Configuration. Keys:
* - "countryCode": default country code, "49" for Germany
* - "areaCode": default area code, without leading zero
*
* @return string Full RFC 3966-compatible telephone number
*
* @author Christian Weiske <cweiske@cweiske.de>
*/
function format_telephone_number_rfc3966($orig, $conf)
{
if (!isset($conf['countryCode'])) {
$conf['countryCode'] = '49';//germany
}
if (!isset($conf['areaCode'])) {
$conf['areaCode'] = '3425';
}
$num = preg_replace('#[^+0-9]#', '', $orig);
if (substr($num, 0, 1) == '+') {
//full telephone number
$tel = $num;
} else if (substr($num, 0, 2) == '00') {
//full number with country code, but 00 instead of +
$tel = '+' . substr($num, 2);
} else if (substr($num, 0, 1) == '0') {
//full number without country code
$tel = '+' . $conf['countryCode'] . substr($num, 1);
} else {
//partial number, no country or area code
$tel = '+' . $conf['countryCode'] . $conf['areaCode'] . $num;
}
return $tel;
}
?>
|