Index: phone.module
===================================================================
--- phone.module	(revision 32874)
+++ phone.module	(working copy)
@@ -10,6 +10,36 @@
  */
 
 /**
+ * Implementation of hook_menu.
+ */
+function phone_menu() {
+  $items = array(
+    'admin/settings/phone' => array(
+      'title'             => 'Phone Field Settings',
+      'description'       => 'Configure options for the phone CCK field.',
+      'page callback'     => 'drupal_get_form',
+      'page arguments'    => array('phone_settings'),
+      'access callback'   => 'user_access',
+      'access arguments'  => array('administer content types'),
+      'type'              => MENU_NORMAL_ITEM,
+    ),
+  );
+
+  return $items;
+}
+
+function phone_settings () {
+  $form['phone_formats'] = array(
+    '#type'           => 'checkboxes',
+    '#title'          => 'Available formats',
+    '#options'        => _phone_formats(),
+    '#description'    => t('Select all the phone number formats that should be available on this site.'),
+    '#default_value'  => variable_get('phone_formats', _phone_formats()),
+  );
+  return system_settings_form($form);
+}
+
+/**
  * Implementation of hook_field_info().
  *
  * Here we indicate that the content module will use its default
@@ -27,40 +57,17 @@
  * the database and in internal arrays, like content_fields().
  */
 function phone_field_info() {
-  return array(
-    'fr_phone' => array('label' => t('Phone Numbers - France')),
-    'be_phone' => array('label' => t('Phone Numbers - Belgium')),
-    'it_phone' => array('label' => t('Phone Numbers - Italy')),
-    'el_phone' => array('label' => t('Phone Numbers - Greece')),    
-    'ch_phone' => array('label' => t('Phone Numbers - Switzerland')),
-    'ca_phone' => array('label' => t('Phone Numbers - US & Canada')),
-    'cr_phone' => array('label' => t('Phone Numbers - Costa Rica')),
-    'pa_phone' => array('label' => t('Phone Numbers - Panama')),
-    'gb_phone' => array('label' => t('Phone Numbers - Great Britain - United Kingdom')),
-    'ru_phone' => array('label' => t('Phone Numbers - Russia')),
-    'ua_phone' => array('label' => t('Phone Numbers - Ukraine - in Kiev')),    
-    'es_phone' => array('label' => t('Phone Numbers - Spain')),
-    'au_phone' => array('label' => t('Phone Numbers - Australia')),
-    'cs_phone' => array('label' => t('Phone Numbers - Czech Republic')),
-    'hu_phone' => array('label' => t('Phone Numbers - Hungary')),
-    'pl_phone' => array('label' => t('Phone Numbers - Poland - mobiles only')),    
-    'nl_phone' => array('label' => t('Phone Numbers - Netherland')),
-    'se_phone' => array('label' => t('Phone Numbers - Sweden')),
-    'za_phone' => array('label' => t('Phone Numbers - South Africa')),    
-    'il_phone' => array('label' => t('Phone Numbers - Israel')),
-    'nz_phone' => array('label' => t('Phone Numbers - New Zealand')),
-    'br_phone' => array('label' => t('Phone Numbers - Brazil')),
-    'cl_phone' => array('label' => t('Phone Numbers - Chile')),    
-    'cn_phone' => array('label' => t('Phone Numbers - China')),    
-    'hk_phone' => array('label' => t('Phone Numbers - Hong-Kong')),
-    'mo_phone' => array('label' => t('Phone Numbers - Macao')),
-    'ph_phone' => array('label' => t('Phone Numbers - The Philippines')),
-    'sg_phone' => array('label' => t('Phone Numbers - Singapore')),    
-    'jo_phone' => array('label' => t('Phone Numbers - Jordan')),
-    'eg_phone' => array('label' => t('Phone Numbers - Egypt')),
-    'pk_phone' => array('label' => t('Phone Numbers - Pakistan')),    
-    'int_phone'=> array('label' => t('Phone Numbers - International Phone Numbers per E.123'))
-   );
+  $available_formats = variable_get('phone_formats', _phone_formats());
+  $global_formats = _phone_formats();
+  $formats = array();
+
+  foreach ($available_formats as $format) {
+    if ($format) {
+      $formats[$format] = array('label' => $global_formats[$format]);
+    }
+  }
+
+  return $formats;
 }
 
 /**
@@ -199,9 +206,9 @@
        || $field['type'] == 'pk_phone'
        || $field['type'] == 'int_phone'
        ) {
-      	$columns = array(
-        	'value' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
-      	);
+        $columns = array(
+          'value' => array('type' => 'varchar', 'length' => 255, 'not null' => FALSE),
+        );
       }
       return $columns;
   }
@@ -265,10 +272,10 @@
           if ($field['type'] == 'ca_phone' && !valid_phone_number('ca', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid North American phone number<br>North American Phone numbers should only contain numbers and + and - and ( and ) and spaces and be like 999-999-9999. Please enter a valid ten-digit phone number with optional extension.', array('%value' => $item['value'])));
           }
-	  if ($field['type'] == 'cr_phone' && !valid_phone_number('cr', $item['value'])) {
+    if ($field['type'] == 'cr_phone' && !valid_phone_number('cr', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Costa Rican phone number!<br>Costa Rican phone numbers should contain only numbers and spaces be like 99 99 99 99 with an optional prefix of "+506" or "00506".', array('%value' => $item['value'])));
           }
-	  if ($field['type'] == 'pa_phone' && !valid_phone_number('pa', $item['value'])) {
+    if ($field['type'] == 'pa_phone' && !valid_phone_number('pa', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Panamanian phone number!<br>Panamanian phone numbers should contain only numbers, spaces and dashes be like 9999-999, 9999 999 or 9999999 with an optional prefix of "+507" or "00507".', array('%value' => $item['value'])));
           }
           if ($field['type'] == 'gb_phone' && !valid_phone_number('gb', $item['value'])) {
@@ -326,7 +333,7 @@
             form_set_error($field['field_name'], t('"%value" is not a valid Macau phone number!<br>Macau phone numbers should contain only numbers and spaces and be like 9999 9999 with an optional prefix of "+853" or "853".', array('%value' => $item['value'])));
           }
           if ($field['type'] == 'ph_phone' && !valid_phone_number('ph', $item['value'])) {
-            form_set_error($field['field_name'], t('"%value" is not a valid Philippine phone number!<br>Example of valid Philippine phone numbers: +63 (2) 123-4567 or +63 (2) 123-4567 loc. 123	or mobile +63 (919) 123-4567', array('%value' => $item['value'])));
+            form_set_error($field['field_name'], t('"%value" is not a valid Philippine phone number!<br>Example of valid Philippine phone numbers: +63 (2) 123-4567 or +63 (2) 123-4567 loc. 123  or mobile +63 (919) 123-4567', array('%value' => $item['value'])));
           }
           if ($field['type'] == 'sg_phone' && !valid_phone_number('sg', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Singaporean phone number!<br>Singaporean phone numbers should ....', array('%value' => $item['value'])));
@@ -538,38 +545,38 @@
     'default' => array(
       'label' => 'Default',
       'field types' => array('fr_phone',
-      			'be_phone',
-      			'it_phone',
-      			'el_phone',      			
-      			'ch_phone',
-      			'ca_phone',
-    			'cr_phone',
-    			'pa_phone',
-      			'gb_phone',
-      			'ru_phone',
-      			'ua_phone',
-      			'es_phone',
-      			'au_phone',
-      			'cs_phone',
-      			'hu_phone',
-      			'pl_phone',
-      			'nl_phone',
-      			'se_phone',
-      			'za_phone',
-      			'il_phone',
-      			'nz_phone',
-      			'br_phone',
-      			'cl_phone',
-      			'cn_phone',      			
-      			'hk_phone',
-      			'mo_phone',
-      			'ph_phone',
-      			'sg_phone',
-      			'jo_phone',
-      			'eg_phone',
-      			'pk_phone',
-      			'int_phone'
-      			),
+            'be_phone',
+            'it_phone',
+            'el_phone',            
+            'ch_phone',
+            'ca_phone',
+          'cr_phone',
+          'pa_phone',
+            'gb_phone',
+            'ru_phone',
+            'ua_phone',
+            'es_phone',
+            'au_phone',
+            'cs_phone',
+            'hu_phone',
+            'pl_phone',
+            'nl_phone',
+            'se_phone',
+            'za_phone',
+            'il_phone',
+            'nz_phone',
+            'br_phone',
+            'cl_phone',
+            'cn_phone',            
+            'hk_phone',
+            'mo_phone',
+            'ph_phone',
+            'sg_phone',
+            'jo_phone',
+            'eg_phone',
+            'pk_phone',
+            'int_phone'
+            ),
       'multiple values' => CONTENT_HANDLE_CORE,
     ),
   );
@@ -637,38 +644,38 @@
     'phone_textfield' => array(
       'label' => t('Textfield'),
       'field types' => array('fr_phone',
-      			'be_phone',
-      			'it_phone',
-      			'el_phone',      			
-      			'ch_phone',
-      			'ca_phone',
-    			'cr_phone',
-    			'pa_phone',
-      			'gb_phone',
-      			'ru_phone',
-      			'ua_phone',
-      			'es_phone',
-      			'au_phone',
-      			'cs_phone',
-      			'hu_phone',
-      			'pl_phone',
-      			'nl_phone',
-      			'se_phone',
-      			'za_phone',
-      			'il_phone',
-      			'nz_phone',
-      			'br_phone',
-      			'cl_phone',
-      			'cn_phone',      			
-      			'hk_phone',
-       			'mo_phone',
-       			'ph_phone',
-       			'sg_phone',
-       			'jo_phone',
-       			'eg_phone',
-       			'pk_phone',
-      			'int_phone'
-      			),
+            'be_phone',
+            'it_phone',
+            'el_phone',            
+            'ch_phone',
+            'ca_phone',
+          'cr_phone',
+          'pa_phone',
+            'gb_phone',
+            'ru_phone',
+            'ua_phone',
+            'es_phone',
+            'au_phone',
+            'cs_phone',
+            'hu_phone',
+            'pl_phone',
+            'nl_phone',
+            'se_phone',
+            'za_phone',
+            'il_phone',
+            'nz_phone',
+            'br_phone',
+            'cl_phone',
+            'cn_phone',            
+            'hk_phone',
+             'mo_phone',
+             'ph_phone',
+             'sg_phone',
+             'jo_phone',
+             'eg_phone',
+             'pk_phone',
+            'int_phone'
+            ),
       'multiple values' => CONTENT_HANDLE_CORE,
       'callbacks' => array(
       'default value' => CONTENT_CALLBACK_DEFAULT,
@@ -880,43 +887,43 @@
  */
 function phone_supported_countrycode($countrycode) {
   if ($countrycode == 'fr'
-  	|| $countrycode == 'be'
-  	|| $countrycode == 'it'
-  	|| $countrycode == 'el'  	
-  	|| $countrycode == 'ch'
-  	|| $countrycode == 'ca'
-  	|| $countrycode == 'cr'
-  	|| $countrycode == 'pa'
-  	|| $countrycode == 'gb'
-  	|| $countrycode == 'ru'
-  	|| $countrycode == 'ua'
-  	|| $countrycode == 'es'
-  	|| $countrycode == 'au'
-  	|| $countrycode == 'cs'
-  	|| $countrycode == 'hu'
-  	|| $countrycode == 'pl'
-  	|| $countrycode == 'nl'
-  	|| $countrycode == 'se'
-  	|| $countrycode == 'za'
-  	|| $countrycode == 'il'
-  	|| $countrycode == 'nz'
-  	|| $countrycode == 'br'
-  	|| $countrycode == 'cl'
-  	|| $countrycode == 'cn'  	
-  	|| $countrycode == 'hk'
-  	|| $countrycode == 'mo'
-  	|| $countrycode == 'ph'
-  	|| $countrycode == 'sg'
-  	|| $countrycode == 'jo'
-  	|| $countrycode == 'eg'
-  	|| $countrycode == 'pk'
-  	|| $countrycode == 'int'
-  	) {
+    || $countrycode == 'be'
+    || $countrycode == 'it'
+    || $countrycode == 'el'
+    || $countrycode == 'ch'
+    || $countrycode == 'ca'
+    || $countrycode == 'cr'
+    || $countrycode == 'pa'
+    || $countrycode == 'gb'
+    || $countrycode == 'ru'
+    || $countrycode == 'ua'
+    || $countrycode == 'es'
+    || $countrycode == 'au'
+    || $countrycode == 'cs'
+    || $countrycode == 'hu'
+    || $countrycode == 'pl'
+    || $countrycode == 'nl'
+    || $countrycode == 'se'
+    || $countrycode == 'za'
+    || $countrycode == 'il'
+    || $countrycode == 'nz'
+    || $countrycode == 'br'
+    || $countrycode == 'cl'
+    || $countrycode == 'cn'
+    || $countrycode == 'hk'
+    || $countrycode == 'mo'
+    || $countrycode == 'ph'
+    || $countrycode == 'sg'
+    || $countrycode == 'jo'
+    || $countrycode == 'eg'
+    || $countrycode == 'pk'
+    || $countrycode == 'int'
+    ) {
         return TRUE;
   }
   else {
-  	//Country not taken into account yet
-  	return FALSE;
+    //Country not taken into account yet
+    return FALSE;
   }
 }
 
@@ -935,19 +942,19 @@
   if (phone_supported_countrycode($countrycode)) {
         //drupal_set_message('langue = ' . $countrycode, 'error');
 
-  	$valid_phone_function = 'valid_'. $countrycode . '_phone_number';
-  	module_load_include('inc', 'phone', 'phone.'. $countrycode);
+    $valid_phone_function = 'valid_'. $countrycode . '_phone_number';
+    module_load_include('inc', 'phone', 'phone.'. $countrycode);
 
-	if (function_exists($valid_phone_function)) {
-	    return $valid_phone_function($phonenumber);
-	}
-	else  {
-	    return FALSE;
-	}
+    if (function_exists($valid_phone_function)) {
+      return $valid_phone_function($phonenumber);
+    }
+    else  {
+      return FALSE;
+    }
   }
   else {
-  	//Country not taken into account yet
-  	return FALSE;
+    //Country not taken into account yet
+    return FALSE;
   }
 }
 
@@ -966,19 +973,19 @@
   if (phone_supported_countrycode($countrycode)) {
         //drupal_set_message('langue = ' . $countrycode, 'error');
 
-  	$format_phone_function = 'format_'. $countrycode . '_phone_number';
-  	module_load_include('inc', 'phone', 'phone.'. $countrycode);
+    $format_phone_function = 'format_'. $countrycode . '_phone_number';
+    module_load_include('inc', 'phone', 'phone.'. $countrycode);
 
-	if (function_exists($format_phone_function)) {
-	    return $format_phone_function($phonenumber, $field);
-	}
-	else {
-	    return FALSE;
-	}
+    if (function_exists($format_phone_function)) {
+      return $format_phone_function($phonenumber, $field);
+    }
+    else {
+      return FALSE;
+    }
   }
   else {
-  	//Country not taken into account yet
-  	return FALSE;
+    //Country not taken into account yet
+    return FALSE;
   }
 }
 
@@ -1013,3 +1020,49 @@
   $tests = file_scan_directory($dir, '\.test$');
   return array_keys($tests);
 }
+
+/**
+ * Helper function that retuns an array of all avaliable phone number formats.
+ */
+function _phone_formats() {
+  static $formats = array();
+
+  if (empty($formats)) {
+    $formats = array(
+      'fr_phone' => t('Phone Numbers - France'),
+      'be_phone' => t('Phone Numbers - Belgium'),
+      'it_phone' => t('Phone Numbers - Italy'),
+      'el_phone' => t('Phone Numbers - Greece'),
+      'ch_phone' => t('Phone Numbers - Switzerland'),
+      'ca_phone' => t('Phone Numbers - US & Canada'),
+      'cr_phone' => t('Phone Numbers - Costa Rica'),
+      'pa_phone' => t('Phone Numbers - Panama'),
+      'gb_phone' => t('Phone Numbers - Great Britain - United Kingdom'),
+      'ru_phone' => t('Phone Numbers - Russia'),
+      'ua_phone' => t('Phone Numbers - Ukraine - in Kiev'),
+      'es_phone' => t('Phone Numbers - Spain'),
+      'au_phone' => t('Phone Numbers - Australia'),
+      'cs_phone' => t('Phone Numbers - Czech Republic'),
+      'hu_phone' => t('Phone Numbers - Hungary'),
+      'pl_phone' => t('Phone Numbers - Poland - mobiles only'),
+      'nl_phone' => t('Phone Numbers - Netherland'),
+      'se_phone' => t('Phone Numbers - Sweden'),
+      'za_phone' => t('Phone Numbers - South Africa'),
+      'il_phone' => t('Phone Numbers - Israel'),
+      'nz_phone' => t('Phone Numbers - New Zealand'),
+      'br_phone' => t('Phone Numbers - Brazil'),
+      'cl_phone' => t('Phone Numbers - Chile'),
+      'cn_phone' => t('Phone Numbers - China'),
+      'hk_phone' => t('Phone Numbers - Hong-Kong'),
+      'mo_phone' => t('Phone Numbers - Macao'),
+      'ph_phone' => t('Phone Numbers - The Philippines'),
+      'sg_phone' => t('Phone Numbers - Singapore'),
+      'jo_phone' => t('Phone Numbers - Jordan'),
+      'eg_phone' => t('Phone Numbers - Egypt'),
+      'pk_phone' => t('Phone Numbers - Pakistan'),
+      'int_phone'=> t('Phone Numbers - International Phone Numbers per E.123'),
+    );
+  }
+
+  return $formats;
+}
