FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,165 @@
<?php
/**
* @file
* Phone Number custom country API
*
* 'CC' will be used throughout this document to indicate country code
* abbreviation. You should replace it with the correct country code
* in the following functions name. For full list of country code
* abbreviation, refer to the 2 alphabet list in the countries.txt.
*/
/**
* Country field settings.
* Country can provide additional field settings for the phone number
* field as needed.
*
* @param $op
* The operation to be performed. Possible values:
* - "form": Display the field settings form.
* - "validate": Check the field settings form for errors.
* - "save": Declare which fields to save back to the database.
* - "database columns": Declare the columns that content.module should create
* and manage on behalf of the field. If the field module wishes to handle
* its own database storage, this should be omitted.
* - "filters": Declare the Views filters available for the field.
* (this is used in CCK's default Views tables definition)
* They always apply to the first column listed in the "database columns"
* array.
* @param $field
* The field on which the operation is to be performed.
* @return
* This varies depending on the operation.
* - "form": an array of form elements to add to
* the settings page.
* - "validate": no return value. Use form_set_error().
* - "save": an array of names of form elements to
* be saved in the database.
* - "database columns": an array keyed by column name, with arrays of column
* information as values. This column information must include "type", the
* MySQL data type of the column, and may also include a "sortable" parameter
* to indicate to views.module that the column contains ordered information.
* TODO: Details of other information that can be passed to the database layer can
* be found in the API for the Schema API.
* - "filters": an array of 'filters' definitions as expected by views.module
* (see Views Documentation).
* When providing several filters, it is recommended to use the 'name'
* attribute in order to let the user distinguish between them. If no 'name'
* is specified for a filter, the key of the filter will be used instead.
*/
function CC_phone_field_settings($op, $field) {
switch ($op) {
// Country specific field settings
case 'form':
// ...
return $form;
// Country specific field validation
case 'validate':
// ...
break;
// Country specific field save
case 'save':
// ...
return $settings;
}
}
/**
* Validate country level phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC (check_plain'ed)
* - "%phone_input": the original number input by user (check_plain'ed)
* - "%min_length": allowed minimum length of the phone number
* - "%max_length": allowed maximum length of the phone number
* - "%ext_input": the original extension input by user (check_plain'ed)
* - "%ext_max_length": allowed maximum length of the phone extension
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function CC_validate_number($number, $ext = '', &$error) {
// Don't need to check for extension because it has been checked by generic validation as all digits, unless has special format/requirements
// your validation
if (FALSE) {
// t() is no needed
$error = '"%phone_input" is not a valid North American phone number, it should be a 10 digit number like "999 999 9999"';
return FALSE;
}
return TRUE;
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function CC_sanitize_number(&$number) {
// your cleanup like removing trunk prefix
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC (check_plain'ed)
* - "%phone_input": the original number input by user (check_plain'ed)
* - "%min_length": allowed minimum length of the phone number
* - "%max_length": allowed maximum length of the phone number
* - "%ext_input": the original extension input by user (check_plain'ed)
* - "%ext_max_length": allowed maximum length of the phone extension
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function CC_formatter_default($element) {
$item = $element['#item'];
// Display a global phone number with country code.
$cc = cck_phone_countrycodes($item['country_codes']);
// Format the phone number however you like, this is the default
$phone = $cc['code'] . '-' . $item['number'];
return $phone;
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function CC_formatter_local($element) {
// Display a local phone number without country code.
// Format the phone number however you like, this is the default
$phone = $element['#item']['number'];
return $phone;
}

View File

@@ -0,0 +1,241 @@
File an issue if we miss any country codes.
Use the CC in the custom country code includes
e.g.
- file name: phone.CC.inc
- function names: cck_phone_CC_settings_validate, cck_phone_CC_settings_save
CC Country name (+Code)
--------------------------
af - Afghanistan (+93)
al - Albania (+355)
dz - Algeria (+213)
as - American Samoa (+1)
ad - Andorra (+376)
ao - Angola (+244)
ai - Anguilla (+1)
ag - Antigua and Barbuda (+1)
ar - Argentina (+54)
am - Armenia (+374)
aw - Aruba (+297)
au - Australia (+61)
at - Austria (+43)
az - Azerbaijan (+994)
bs - Bahamas, The (+1)
bh - Bahrain (+973)
bd - Bangladesh (+880)
bb - Barbados (+1)
by - Belarus (+375)
be - Belgium (+32)
bz - Belize (+501)
bj - Benin (+229)
bm - Bermuda (+1)
bt - Bhutan (+975)
bo - Bolivia (+591)
ba - Bosnia and Herzegovina (+387)
bw - Botswana (+267)
br - Brazil (+55)
io - British Indian Ocean Territory (+246)
vg - British Virgin Islands (+1)
bn - Brunei (+673)
bg - Bulgaria (+359)
bf - Burkina Faso (+226)
bi - Burundi (+257)
kh - Cambodia (+855)
cm - Cameroon (+237)
ca - Canada (+1)
cv - Cape Verde (+238)
ky - Cayman Islands (+1)
cf - Central African Republic (+236)
td - Chad (+235)
cl - Chile (+56)
cn - China (+86)
cx - Christmas Island (+61)
cc - Cocos-Keeling Islands (+61)
co - Colombia (+57)
km - Comoros (+269)
cg - Congo, Republic of the (+242)
cd - Congo, Democratic Republic of (+243)
ck - Cook Islands (+682)
cr - Costa Rica (+506)
hr - Croatia (+385)
cu - Cuba (+53)
cy - Cyprus (+357)
cz - Czech Republic (+420)
dk - Denmark (+45)
dj - Djibouti (+253)
dm - Dominica (+1)
do - Dominican Republic (+1)
tp - East Timor (+670)
ec - Ecuador (+593)
eg - Egypt (+20)
sv - El Salvador (+503)
gq - Equatorial Guinea (+240)
er - Eritrea (+291)
ee - Estonia (+372)
et - Ethiopia (+251)
fk - Falkland Islands (+500)
fo - Faroe Islands (+298)
fj - Fiji (+679)
fi - Finland (+358)
fr - France (+33)
gf - French Guiana (+594)
pf - French Polynesia (+689)
ga - Gabon (+241)
gm - Gambia, The (+220)
ge - Georgia (+995)
de - Germany (+49)
gh - Ghana (+233)
gi - Gibraltar (+350)
gr - Greece (+30)
gl - Greenland (+299)
gd - Grenada (+1)
gp - Guadeloupe (+590)
gu - Guam (+1)
gt - Guatemala (+502)
gn - Guinea (+224)
gw - Guinea-Bissau (+245)
gy - Guyana (+592)
ht - Haiti (+509)
hn - Honduras (+504)
hk - Hong Kong (+852)
hu - Hungary (+36)
is - Iceland (+354)
in - India (+91)
id - Indonesia (+62)
ir - Iran (+98)
iq - Iraq (+964)
ie - Ireland (+353)
il - Israel (+972)
it - Italy (+39)
ci - Ivory Coast (+225)
jm - Jamaica (+1)
jp - Japan (+81)
jo - Jordan (+962)
kz - Kazakhstan (+7)
ke - Kenya (+254)
ki - Kiribati (+686)
kw - Kuwait (+965)
kg - Kyrgyzstan (+996)
la - Laos (+856)
lv - Latvia (+371)
lb - Lebanon (+961)
ls - Lesotho (+266)
lr - Liberia (+231)
ly - Libya (+218)
li - Liechtenstein (+423)
lt - Lithuania (+370)
lu - Luxembourg (+352)
mo - Macau (+853)
mk - Macedonia (+389)
mg - Madagascar (+261)
mw - Malawi (+265)
my - Malaysia (+60)
mv - Maldives (+960)
ml - Mali (+223)
mt - Malta (+356)
mh - Marshall Islands (+692)
mq - Martinique (+596)
mr - Mauritania (+222)
mu - Mauritius (+230)
yt - Mayotte (+269)
mx - Mexico (+52)
fm - Micronesia, Federated States of (+691)
md - Moldova (+373)
mc - Monaco (+377)
mn - Mongolia (+976)
me - Montenegro (+382)
ms - Montserrat (+1)
ma - Morocco (+212)
mz - Mozambique (+258)
mm - Myanmar (+95)
na - Namibia (+264)
nr - Nauru (+674)
np - Nepal (+977)
nl - Netherlands (+31)
an - Netherlands Antilles (+599)
nc - New Caledonia (+687)
nz - New Zealand (+64)
ni - Nicaragua (+505)
ne - Niger (+227)
ng - Nigeria (+234)
nu - Niue (+683)
nf - Norfolk Island (+672)
kp - North Korea (+850)
mp - Northern Mariana Islands (+1)
no - Norway (+47)
om - Oman (+968)
pk - Pakistan (+92)
pw - Palau (+680)
ps - Palestine (+970)
pa - Panama (+507)
pg - Papua New Guinea (+675)
py - Paraguay (+595)
pe - Peru (+51)
ph - Philippines (+63)
pl - Poland (+48)
pt - Portugal (+351)
pr - Puerto Rico (+1)
qa - Qatar (+974)
ro - Romania (+40)
ru - Russia (+7)
rw - Rwanda (+250)
sh - Saint Helena (+290)
kn - Saint Kitts and Nevis (+1)
lc - Saint Lucia (+1)
pm - Saint Pierre and Miquelon (+508)
vc - Saint Vincent and the Grenadines (+1)
ws - Samoa (+1)
sm - San Marino (+378)
st - Sao Tome and Principe (+239)
sa - Saudi Arabia (+966)
sn - Senegal (+221)
rs - Serbia (+381)
sc - Seychelles (+248)
sl - Sierra Leone (+232)
sg - Singapore (+65)
sk - Slovakia (+421)
si - Slovenia (+386)
sb - Solomon Islands (+677)
so - Somalia (+252)
za - South Africa (+27)
kr - South Korea (+82)
ss - South Sudan (+211)
es - Spain (+34)
lk - Sri Lanka (+94)
sd - Sudan (+249)
sr - Suriname (+597)
sz - Swaziland (+268)
se - Sweden (+46)
ch - Switzerland (+41)
sy - Syria (+963)
tw - Taiwan (+886)
tj - Tajikistan (+992)
tz - Tanzania (+255)
th - Thailand (+66)
tg - Togo (+228)
tk - Tokelau (+690)
to - Tonga (+676)
tt - Trinidad and Tobago (+1)
tn - Tunisia (+216)
tr - Turkey (+90)
tm - Turkmenistan (+993)
tc - Turks and Caicos Islands (+1)
tv - Tuvalu (+688)
ug - Uganda (+256)
ua - Ukraine (+380)
ae - United Arab Emirates (+971)
gb - United Kingdom (+44)
us - United States (+1)
uy - Uruguay (+598)
vi - US Virgin Islands (+1)
uz - Uzbekistan (+998)
vu - Vanuatu (+678)
va - Vatican City (+39)
ve - Venezuela (+58)
vn - Vietnam (+84)
wf - Wallis and Futuna (+681)
ye - Yemen (+967)
zm - Zambia (+260)
zw - Zimbabwe (+263)

View File

@@ -0,0 +1,173 @@
<?php
/**
* @file
* CCK Field for Australia phone numbers.
*/
/**
* Patterns generated from Telecommunications Numbering Plan 1997
* http://www.comlaw.gov.au/comlaw/management.nsf/lookupindexpagesbyid/IP200506356?OpenDocument
*/
function _cck_phone_au_number_patterns() {
$valid_patterns = array(
// Geographic numbers (10 digits) - Central East Region (NSW, ACT, Northern VIC).
'/^02[4,6-9][0-9]{7}$/',
'/^023[3,8][0-9]{6}$/',
'/^025[0-3,5-9][0-9]{6}$/',
// Geographic numbers (10 digits) - South East Region (TAS, Southern NSW, VIC).
'/^03[5,7-9][0-9]{7}$/',
'/^034[0-5,7-9][0-9]{6}$/',
'/^036[1-5,7][0-9]{6}$/',
// Geographic numbers (10 digits) - North East Region (QLD).
'/^07[2-4][0-9]{7}$/',
'/^075[2-7][0-9]{6}$/',
'/^0776[0-9]{6}$/',
// Geographic numbers (10 digits) - Central and West Region (WA, SA, NT and Western NSW).
'/^08[7-9][0-9]{7}$/',
'/^085[1-4][0-9]{6}$/',
'/^086[0-8][0-9]{6}$/',
// Mobile numbers (10 digits).
'/^04[0-9]{8}$/',
// Local rate special numbers (10 digits).
'/^130[0-9]{7}$/',
// Local rate special numbers (6 digits).
'/^13[1-3,5-9][0-9]{3}$/',
'/^134[0-4,6-9][0-9]{2}$/',
// Free phone numbers (10 digits).
'/^180[0-1][0-9]{6}$/',
// Satelite telephone numbers (10 digits).
'/^014[1-3,5,7][0-9]{6}$/',
// Satelite telephone numbers (9 digits).
'/^014[0,4,6,8-9][0-9]{5}$/',
'/^015[0-9]{6}$/',
'/^017[1,2,8,9][0-9]{5}$/',
'/^018[0-9]{6}$/',
);
$invalid_patterns = array(
// Invalid geographic phone numbers.
'/^0[2,3,7]5550[0-9]{4}$/',
);
$format_search_patterns = array(
// Geographic numbers (10 digits).
'/^(0)([2,3,7,8])([0-9]{4})([0-9]{4})$/',
// Mobile numbers (10 digits).
'/^(0)(4[0-9]{2})([0-9]{3})([0-9]{3})$/',
// 1300 numbers, 1800 numbers (10 digits).
'/^(1[3,8][0-9]{2})([0-9]{3})([0-9]{3})$/',
// 13 numbers (6 digits).
'/^(13)([0-9]{2})([0-9]{2})$/',
// Satelite telephone numbers (10 digits).
'/^(0)(14)([0-9])([0-9]{3})([0-9]{3})$/',
// Satelite telephone numbers (9 digits).
'/^(0)(1[4,5,7,8])([0-9]{3})([0-9]{3})$/',
);
$format_replace_patterns = array(
// Geographic numbers (10 digits).
'($1$2) $3 $4',
// Mobile numbers (10 digits).
'$1$2 $3 $4',
// 1300 numbers, 1800 numbers (10 digits).
'$1 $2 $3',
// 13 numbers (6 digits).
'$1 $2 $3',
// Satelite telephone numbers (10 digits).
'$1$2 $3 $4 $5',
// Satelite telephone numbers (9 digits).
'$1$2 $3 $4',
);
$format_replace_patterns_international = array(
// Geographic numbers (10 digits).
'$2 $3 $4',
// Mobile numbers (10 digits).
'$2 $3 $4',
// 1300 numbers, 1800 numbers (10 digits).
'$1 $2 $3',
// 13 numbers (6 digits).
'$1 $2 $3',
// Satelite telephone numbers (10 digits).
'$2 $3 $4 $5',
// Satelite telephone numbers (9 digits).
'$2 $3 $4',
);
return array($valid_patterns, $invalid_patterns, $format_search_patterns, $format_replace_patterns, $format_replace_patterns_international);
}
/**
* Verifies that $number is a valid Australian phone number.
*/
function au_validate_number($number, $ext = '', &$error) {
// Don't need to check for extension because it has been checked by generic validation as all digits, unless has special format/requirements
// We don't want to worry about separators
$number = cck_phone_clean_number($number);
if (empty($number)) {
return TRUE;
}
list($valid_patterns, $invalid_patterns, $format_search_patterns, $format_replace_patterns, $format_replace_patterns_international) = _cck_phone_au_number_patterns();
$invalid_number = preg_replace($invalid_patterns, '', $number);
$correct_number = preg_replace($valid_patterns, '', $number);
if (empty($invalid_number)) {
$error = 'The phone number you have entered is classified as unusable by the Australian telecommunications authority.';
return FALSE;
}
elseif (!empty($correct_number)) {
$error = 'You have not entered a valid australian phone number. Please enter a 10 digit phone number including the area code, but not including the 61 international prefix. Valid 1800, 1300, and 13 numbers are accepted, as are satilite and AMPS numbers.';
return FALSE;
}
return TRUE;
}
/**
* Default formatter for Australian phone number.
*/
function au_formatter_default($element) {
// Display a global phone number with country code.
$cc = cck_phone_countrycodes($element['country_codes']);
list($valid_patterns, $invalid_patterns, $format_search_patterns, $format_replace_patterns, $format_replace_patterns_international) = _cck_phone_au_number_patterns();
return $cc['code'] .' '. preg_replace($format_search_patterns, $format_replace_patterns_international, $element['number']);
}
/**
* Local formatter for local Australian phone number.
*/
function au_formatter_local($element) {
list($valid_patterns, $invalid_patterns, $format_search_patterns, $format_replace_patterns, $format_replace_patterns_international) = _cck_phone_au_number_patterns();
return preg_replace($format_search_patterns, $format_replace_patterns, $element['number']);
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* @file
* CCK Field for Canada phone numbers.
*/
/**
* Verifies that $number is a valid ten-digit North American phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function ca_validate_number($number, $ext = '', &$error) {
return us_validate_number($number, $ext = '', $error);
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function ca_sanitize_number(&$number) {
us_sanitize_number($number);
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function ca_formatter_default($element) {
return us_formatter_default($element);
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function ca_formatter_local($element) {
return us_formatter_local($element);
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* @file
* CCK Field for United Kingdom phone numbers.
*/
function _uk_phone_rules() {
// TODO: more detailed check by area codes
return '/^
0*(2[03489])(\d{4})(\d{4}) # 02x [eight-digit local number]
|
0*(11[3-8])(\d{3})(\d{4}) # 011x [seven-digit local number]
|
0*(1[2-9]1)(\d{3})(\d{4}) # 01x1 [seven-digit local number]
|
0*(1[2-9][0|2-9]\d)(\d{5,6}) # 01xxx [mostly six-digit local numbers] (but not 01x1 codes)
$/x';
}
/**
* Validate country level phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function gb_validate_number($number, $ext = '', &$error) {
// We don't want to worry about separators
$number = cck_phone_clean_number($number);
if (preg_match(_uk_phone_rules(), $number)) {
return TRUE;
}
// t() is not needed
$error = '"%phone_input" is not a valid United Kingdom phone number, it should be a 10 digit number like "99 9999 9999", with optional leading "0"';
return FALSE;
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function gb_sanitize_number(&$number) {
// Remove trunk prefix '0'
$number = preg_replace('/^([0]*)/', '', $number);
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function gb_formatter_default($element) {
// Display a global phone number with country code.
$phone = '';
$number = $element['number'];
if ($number) {
$cc = cck_phone_countrycodes($element['country_codes']);
if (preg_match(_uk_phone_rules(), $number, $matches)) {
// output as +44 AA BBBB CCCC, +44 AAA BBB CCCC or +44 AAAA BBB CCC
array_shift($matches);
$phone = $cc['code'] . ' ' . implode(' ', $matches);
}
else {
$phone = "$cc[code] $number";
}
}
return $phone;
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function gb_formatter_local($element) {
// Display a local phone number without country code.
$phone = '';
$number = $element['number'];
if ($number) {
if (preg_match(_uk_phone_rules(), $number, $matches)) {
// output as 0AA BBBB CCCC, 0AAA BBB CCCC or 0AAAA BBB CCC
array_shift($matches);
$phone = '0' . implode(' ', $matches);
}
else {
$phone = "0$number";
}
}
return $phone;
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* @file
* CCK Field for Hungarian phone numbers.
*/
/**
* Verifies and mage parts from $number
*
* @param $number
* Digits only value.
* @return boolean
* Array
* if array['error'] is present, the validation fails
* else ['area'] for area number
* ['first'] ['second'] for the AA/BBB-CCC numbers
* ['first'] ['second'] ['third'] for the A(A)/BBB-CC-DD numbers
*/
function hu_parts($number) {
/**
* Because Hungary an telephone numbers are both in open and closed number region, the area code length may be vary. If the area code is 1, 7 more digits follow it.
* If the area code is 20/30/70, also 7 more digits.
* If any other 2 digits are code is appear, we want 6 more digits.
*
* So complecated, I know :)
*
*/
$result = array();
// Last 9 digits
$n = drupal_substr($number, -9);
if ($n === FALSE || (drupal_substr($n, 0, 1) != 2 && drupal_substr($n, 0, 1) != 3 && drupal_substr($n, 0, 1) != 7)) {
// No 9 digit, check for 8 digit
if (drupal_substr($number, -8) === FALSE) {
// No 8 digit, too short for valid telephone number
$result['error'] = '"%phone_input" is not a valid Hungarian phone number, it should be a 9 digit number like "20/123-45-67" or a 8 digit number like "23/123-456"';
}
else {
$n = drupal_substr($number, -8);
// It is 8 digits
if (drupal_substr($n, 0, 1) == 1) {
// A number from Budapest
$result['area'] = drupal_substr($n, 0, 1);
$result['first'] = drupal_substr($n, 1, 3);
$result['second'] = drupal_substr($n, 4, 2);
$result['third'] = drupal_substr($n, 6, 2);
}
else {
// A number from countryside
$result['area'] = drupal_substr($n, 0, 2);
$result['first'] = drupal_substr($n, 2, 3);
$result['second'] = drupal_substr($n, 5, 3);
}
}
}
else {
// Cell phone number
$result['area'] = drupal_substr($n, 0, 2);
$result['first'] = drupal_substr($n, 2, 3);
$result['second'] = drupal_substr($n, 5, 2);
$result['third'] = drupal_substr($n, 7, 2);
}
return $result;
}
/**
* Verifies that $number is a valid nine digit Hungarian phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function hu_validate_number($number, $ext = '', &$error) {
// Don't need to check for extension because it has been checked by generic validation as all digits, unless has special format/requirements
// We don't want to worry about separators
$number = cck_phone_clean_number($number);
$result = hu_parts($number);
if (isset($result['error'])) {
// t() is no needed
$error = $result['error'];
return FALSE;
}
return true;
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function hu_sanitize_number(&$number) {
// Remove prefix '36' or '+36'
$number = preg_replace('/^(?:\+?36|06*)/', '', $number);
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['country_codes']: alpha-2 country code
* $element['number']: phone number
* $element['extension']: ext
* @return boolean
* STRING The formatted number
*/
function hu_formatter_default($element) {
$number = $element['number'];
$ext = $element['extension'];
$result = hu_parts($number);
if (isset($result['error'])) {
return $number . ($ext ? '/' . $ext : '');
}
// output as +36 (AA) BBB CCDD/ext or +36 (AA) BBB CCC/ext
$phone = '+36 (' . $result['area'] . ') ' . $result['first'] . ' ' . $result['second'] . $result['third'];
return $phone . ($ext ? '/' . $ext : '');
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['country_codes']: alpha-2 country code
* $element['number']: phone number
* $element['extension']: ext
* @return boolean
* STRING The formatted number
*/
function hu_formatter_local($element) {
$number = $element['number'];
$ext = $element['extension'];
$result = hu_parts($number);
if (isset($result['error'])) {
return $number . ($ext ? '/' . $ext : '');
}
// output as AA/BBB-CC-DD or AA/BBB-CCC
$phone = $result['area'] . '/' . $result['first'] . '-' . $result['second'] . (isset($result['third']) ? '-' . $result['third'] : '');
return $phone . ($ext ? '/' . $ext : '');
}

View File

@@ -0,0 +1,178 @@
<?php
/**
* @file
* CCK Field for Malaysia phone numbers.
*/
function _my_phone_rules() {
$rules = array();
// rule: 'area code, min length, max length'
// Geographic land line number
$rules[] = array("2", 7); // Domestic access code to Singapore
$rules[] = array("3", 8); // Selangor & Federal Territories of Kuala Lumpur & Putrajaya
$rules[] = array("4", 7); // Kedah, Penang & Perlis
$rules[] = array("5", 7); // Perak & Cameron Highlands (Pahang)
$rules[] = array("6", 7); // Melaka, Negeri Sembilan & Muar (Johor)
$rules[] = array("7", 7); // Johor (except Muar)
$rules[] = array("80", 6); // Domestic access code to Brunei (East Malaysia only)
// $rules[] = array("81", 6); // reserved
$rules[] = array("82", 6); // Kuching (Sarawak)
$rules[] = array("83", 6); // Sri Aman (Sarawak)
$rules[] = array("84", 6); // Sarikei, Bintangor, Sibu, Kanowit, Song, & Kapit (Sarawak)
$rules[] = array("85", 6); // Lawas, Limbang, Miri (Sarawak)
$rules[] = array("86", 6); // Bintulu, Belaga (Sarawak)
$rules[] = array("87", 6); // Inner District (Sabah) & Federal Territory of Labuan
$rules[] = array("88", 6); // Kota Kinabalu, Kudat (Sabah)
$rules[] = array("89", 6); // Lahad Datu, Sandakan, Tawau (Sabah)
$rules[] = array("9", 7); // Kelantan, Pahang (except Cameron Highlands) & Terengganu
// Mobile number structure
$rules[] = array("10", 7);
$rules[] = array("11", 7);
$rules[] = array("12", 7);
$rules[] = array("13", 7);
$rules[] = array("14", 7);
$rules[] = array("15", 7);
$rules[] = array("16", 7);
$rules[] = array("17", 7);
$rules[] = array("18", 7);
$rules[] = array("19", 7);
return $rules;
}
/**
* Verifies that $number is a valid Malaysia phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function my_validate_number($number, $ext = '', &$error) {
// We don't want to worry about separators
$number = cck_phone_clean_number($number);
foreach (_my_phone_rules() as $rule) {
// define regular expression
$regex = '/^
([0]*) # an optional 0
(' . $rule[0] . ') # area code
\d{' . $rule[1] . '} # local number within length $rule[1] & $rule[2]
$/x';
$result = preg_match($regex, $number, $matches);
if ($result) {
return TRUE;
}
}
// t() is no needed
$error = '"%phone_input" is not a valid Malaysia phone number, it should be a 9-10 digit number like "03-2222 2222", "0" is optional and will be removed.';
return FALSE;
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function my_sanitize_number(&$number) {
// Remove trunk prefix '0'
$number = preg_replace('/^([0]*)/', '', $number);
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function my_formatter_default($element) {
$phone = '';
// Display a global phone number with country code.
$cc = cck_phone_countrycodes($element['country_codes']);
// Format the phone number however you like, this is the default
foreach (_my_phone_rules() as $rule) {
// define regular expression
$regex = '/^
(' . $rule[0] . ') # area code
(\d{3,4})
(\d{4})
$/x';
$result = preg_match($regex, $element['number'], $matches);
if ($result) {
// output as +60A-BBB CCCC or +60A-BBBB CCCC
$phone = $cc['code'] . $matches[1] . '-' . $matches[2] . ' ' . $matches[3];
continue;
}
}
return $phone;
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['#item']['country_codes']: alpha-2 country code
* $element['#item']['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function my_formatter_local($element) {
// Display a local phone number without country code.
$phone = $element['number'];
foreach (_my_phone_rules() as $rule) {
// define regular expression
$regex = '/^
(' . $rule[0] . ') # area code
(\d{3,4})
(\d{4})
$/x';
$result = preg_match($regex, $phone, $matches);
if ($result) {
// output as 0A-BBB CCCC or 0A-BBBB CCCC
$phone = '0' . $matches[1] . '-' . $matches[2] . ' ' . $matches[3];
continue;
}
}
return $phone;
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* @file
* CCK Field for Polish phone numbers.
*/
/**
* Polish phone number regex helper.
*/
function _pl_regex() {
return '/^
([1-9]\d) # 2-digit area code
([1-9]\d{2}) # 3-digit phone prefix (cannot start with 0)
(\d{4})
$/x';
}
/**
* Verifies that $number is a valid 9-digit Polish phone number.
*/
function pl_validate_number($number, $ext = '', &$error) {
$number = cck_phone_clean_number($number);
$regex = _pl_regex();
$result = preg_match($regex, $number, $matches);
if ($result) {
return TRUE;
}
else {
$error = '"%phone_input" is not a valid Polish phone number, it should be a 9-digit
number like "99 999 99 99".';
return FALSE;
}
}
/**
* Helper for formatting output.
* Output as +48 (AA) BBB CCCC
*/
function _pl_formatter($element) {
$phone = '';
$regex = _pl_regex();
$result = preg_match($regex, $element['number'], $matches);
if ($result) {
$phone = '(' . $matches[1] . ') ' . $matches[2] . ' ' . $matches[3];
}
return $phone;
}
/**
* Default formatter for international phone number.
*/
function pl_formatter_default($element) {
$cc = cck_phone_countrycodes($element['country_codes']);
$number = _pl_formatter($element);
return $cc['code'] . ' ' . $number;
}
/**
* Local formatter for local phone number.
*/
function pl_formatter_local($element) {
return _pl_formatter($element);
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* @file
* CCK Field for North American phone numbers.
*/
/**
* Verifies that $number is a valid ten-digit North American phone number.
*
* @param $number
* Digits only value.
* @param $ext
* Digits only value.
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function us_validate_number($number, $ext = '', &$error) {
// Don't need to check for extension because it has been checked by generic validation as all digits, unless has special format/requirements
// We don't want to worry about separators
$number = cck_phone_clean_number($number);
// define regular expression
$regex = '/^
([1]*) # an optional 1
[2-9][0-8]\d # area code (Allowed range of [2-9] for the first digit, [0-8] for the second, and [0-9] for the third digit)
[2-9]\d{2} # 3-digit prefix (cannot start with 0 or 1)
\d{4} # 4-digit line number
$/x';
$result = preg_match($regex, $number, $matches);
if ($result && $matches[1] == '') {
return TRUE;
}
elseif ($result && $matches[1] == '1') {
// t() is no needed
$error = 'Please enter a 10 digit North American phone number like "999 999 9999", without the country code "1" or "+1"';
return FALSE;
}
else {
// t() is no needed
$error = '"%phone_input" is not a valid North American phone number, it should be a 10 digit number like "999 999 9999"';
return FALSE;
}
}
/**
* Cleanup user-entered values for a phone number field for saving to DB.
*
* @param $number
* A single phone number item.
*/
function us_sanitize_number(&$number) {
// Remove prefix '1'
$number = preg_replace('/^([1]*)/', '', $number);
}
/**
* Default formatter for international phone number.
*
* @param $element
* $element['country_codes']: alpha-2 country code
* $element['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function us_formatter_default($element) {
$phone = '';
// Display a global phone number with country code.
$cc = cck_phone_countrycodes($element['country_codes']);
// Format the phone number however you like, this is the default
// define regular expression
$regex = '/^
([2-9][0-8]\d) # area code (Allowed range of [2-9] for the first digit, [0-8] for the second, and [0-9] for the third digit)
([2-9]\d{2}) # 3-digit prefix (cannot start with 0 or 1)
(\d{4}) # 4-digit line number
/x';
$result = preg_match($regex, $element['number'], $matches);
if ($result) {
// output as +1 (AAA) BBB-CCCC
$phone = $cc['code'] . ' (' . $matches[1] . ') ' . $matches[2] . '-' . $matches[3];
}
return $phone;
}
/**
* Local formatter for local phone number.
*
* @param $element
* $element['country_codes']: alpha-2 country code
* $element['number']: phone number
* @param $error
* The error message to shown to user.
* Available parameters to use in the error message are
* - "%countrycode": the alpha-2 CC
* - "%phone_input": the original number input by user (could be invalid)
* - "%max_length": allowed maximum length of the phone number
* @return boolean
* TRUE if it is a valid phone number for that country, FALSE otherwise.
*/
function us_formatter_local($element) {
$phone = '';
// Display a local phone number without country code.
$regex = '/^
([2-9][0-8]\d) # area code (Allowed range of [2-9] for the first digit, [0-8] for the second, and [0-9] for the third digit)
([2-9]\d{2}) # 3-digit prefix (cannot start with 0 or 1)
(\d{4}) # 4-digit line number
/x';
$result = preg_match($regex, $element['number'], $matches);
if ($result) {
// output as (AAA) BBB CCCC
$phone = '(' . $matches[1] . ') ' . $matches[2] . '-' . $matches[3];
}
return $phone;
}