1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage HTML
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * HTML helper class for rendering telephone numbers.
14 *
15 * @since 1.6
16 */
17 abstract class JHtmlTel
18 {
19 /**
20 * Converts strings of integers into more readable telephone format
21 *
22 * By default, the ITU-T format will automatically be used.
23 * However, one of the allowed unit types may also be used instead.
24 *
25 * @param integer $number The integers in a phone number with dot separated country code
26 * ccc.nnnnnnn where ccc represents country code and nnn represents the local number.
27 * @param string $displayplan The numbering plan used to display the numbers.
28 *
29 * @return string The formatted telephone number.
30 *
31 * @see JFormRuleTel
32 * @since 1.6
33 */
34 public static function tel($number, $displayplan)
35 {
36 $number = explode('.', $number);
37 $countrycode = $number[0];
38 $number = $number[1];
39
40 if ($displayplan === 'ITU-T' || $displayplan === 'International' || $displayplan === 'int' || $displayplan === 'missdn' || $displayplan == null)
41 {
42 $display[0] = '+';
43 $display[1] = $countrycode;
44 $display[2] = ' ';
45 $display[3] = implode(str_split($number, 2), ' ');
46 }
47 elseif ($displayplan === 'NANP' || $displayplan === 'northamerica' || $displayplan === 'US')
48 {
49 $display[0] = '(';
50 $display[1] = substr($number, 0, 3);
51 $display[2] = ') ';
52 $display[3] = substr($number, 3, 3);
53 $display[4] = '-';
54 $display[5] = substr($number, 6, 4);
55 }
56 elseif ($displayplan === 'EPP' || $displayplan === 'IETF')
57 {
58 $display[0] = '+';
59 $display[1] = $countrycode;
60 $display[2] = '.';
61 $display[3] = $number;
62 }
63 elseif ($displayplan === 'ARPA' || $displayplan === 'ENUM')
64 {
65 $number = implode(str_split(strrev($number), 1), '.');
66 $display[0] = '+';
67 $display[1] = $number;
68 $display[2] = '.';
69 $display[3] = $countrycode;
70 $display[4] = '.e164.arpa';
71 }
72
73 return implode($display, '');
74 }
75 }
76