Index: phone/phone.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/phone.module,v
retrieving revision 1.13
diff -u -p -r1.13 phone.module
--- phone/phone.module	28 May 2008 22:45:34 -0000	1.13
+++ phone/phone.module	12 Aug 2008 07:18:44 -0000
@@ -1,12 +1,12 @@
 <?php
 // $Id: phone.module,v 1.13 2008/05/28 22:45:34 thierrygd Exp $
 
-// Copyright 2007 Thierry GUEGAN http://www.arvoriad.com 
+// Copyright 2007 Thierry GUEGAN http://www.arvoriad.com
 
 /**
  * @file
  * Defines phone number fields for CCK.
- * Provide some verifications on the phone numbers 
+ * Provide some verifications on the phone numbers
  */
 
 /**
@@ -15,21 +15,21 @@
 function phone_field_info() {
   return array(
     'fr_phone' => array('label' => t('French Phone Numbers')),
-    'it_phone' => array('label' => t('Italian Phone Numbers')),    
+    'it_phone' => array('label' => t('Italian Phone Numbers')),
     'ca_phone' => array('label' => t('US & Canadian Phone Numbers')),
     'uk_phone' => array('label' => t('British (UK) Phone Numbers')),
     'ru_phone' => array('label' => t('Russian Phone Numbers')),
     'es_phone' => array('label' => t('Spanish Phone Numbers')),
     'au_phone' => array('label' => t('Australian Phone Numbers')),
-    'cs_phone' => array('label' => t('Czech Phone Numbers'))    
-   );
+    'cs_phone' => array('label' => t('Czech Phone Numbers'))
+  );
 }
 
 /**
  * Implementation of hook_field_settings().
  */
-function phone_field_settings($op, $field) {      
-  switch ($op) { 
+function phone_field_settings($op, $field) {
+  switch ($op) {
     case 'form':
       $form = array();
       $form['phone_country_code'] = array(
@@ -49,7 +49,7 @@ function phone_field_settings($op, $fiel
           '#title' => t('Use parentheses around area code'),
           '#default_value' => isset($field['ca_phone_parentheses']) ? $field['ca_phone_parentheses'] : 1,
         );
-      }            
+      }
       return $form;
 
     case 'save':
@@ -57,22 +57,22 @@ function phone_field_settings($op, $fiel
       if ($field['type'] == 'ca_phone') {
         array_push($settings, 'ca_phone_separator', 'ca_phone_parentheses');
       }
-      return $settings;        
+      return $settings;
     case 'database columns':
       if ($field['type'] == 'fr_phone'
-       || $field['type'] == 'it_phone'
-       || $field['type'] == 'ca_phone'
-       || $field['type'] == 'uk_phone'
-       || $field['type'] == 'ru_phone'
-       || $field['type'] == 'es_phone'
-       || $field['type'] == 'au_phone'
-       || $field['type'] == 'cs_phone'
-       ){ 
-      	$columns = array(
-        	'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
-      	);
-      }   
-      return $columns;     
+          || $field['type'] == 'it_phone'
+          || $field['type'] == 'ca_phone'
+          || $field['type'] == 'uk_phone'
+          || $field['type'] == 'ru_phone'
+          || $field['type'] == 'es_phone'
+          || $field['type'] == 'au_phone'
+          || $field['type'] == 'cs_phone'
+          ) {
+        $columns = array(
+          'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
+        );
+      }
+      return $columns;
   }
 }
 
@@ -85,7 +85,7 @@ function phone_field($op, &$node, $field
       foreach ($node_field as $delta => $item) {
         $node_field[$delta]['view'] = content_format($field, $item, 'default', $node);
       }
-      return theme('field', $node, $field, $node_field, $teaser, $page); 
+      return theme('field', $node, $field, $node_field, $teaser, $page);
   }
 }
 
@@ -99,30 +99,30 @@ function phone_field_view_item($field, $
     return $phonenumber;
 }
 */
- 
+
 /**
- *Implementation of hook_field_formatter_info
+ * Implementation of hook_field_formatter_info
  */
 function phone_field_formatter_info() {
   return array(
     'default' => array(
       'label' => 'Default',
-      'field types' => array('fr_phone', 
-      			'it_phone', 
-      			'ca_phone', 
-      			'uk_phone', 
-      			'ru_phone',
-      			'es_phone',
-      			'au_phone',
-      			'cs_phone'      			
-      			),
+      'field types' => array('fr_phone',
+            'it_phone',
+            'ca_phone',
+            'uk_phone',
+            'ru_phone',
+            'es_phone',
+            'au_phone',
+            'cs_phone'
+            ),
     ),
   );
- } 
- 
+}
+
 /**
-* Implementation of hook_field_formatter().
-**/
+ * Implementation of hook_field_formatter().
+ */
 function phone_field_formatter($field, $item, $formatter, $node) {
   if (!isset($item['value'])) {
     return '';
@@ -133,10 +133,10 @@ function phone_field_formatter($field, $
   else {
     $text = check_plain($item['value']);
   }
-  // iPhone Support 
+  // iPhone Support
   if (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== FALSE) {
-     $text = '<a href="tel:' . $text . '">' . $text . '</a>';
-  }  
+    $text = '<a href="tel:'. $text .'">'. $text .'</a>';
+  }
   return $text;
 }
 
@@ -147,15 +147,15 @@ function phone_widget_info() {
   return array(
     'phone' => array(
       'label' => t('Textfield'),
-      'field types' => array('fr_phone', 
-      			'it_phone', 
-      			'ca_phone', 
-      			'uk_phone', 
-      			'ru_phone',
-      			'es_phone',
-      			'au_phone',
-      			'cs_phone'      			
-      			),
+      'field types' => array('fr_phone',
+            'it_phone',
+            'ca_phone',
+            'uk_phone',
+            'ru_phone',
+            'es_phone',
+            'au_phone',
+            'cs_phone'
+            ),
     ),
   );
 }
@@ -168,7 +168,7 @@ function phone_widget_settings($op, $wid
     case 'form':
 
     case 'validate':
-      break; //do nothing 
+      break; //do nothing
 
     case 'save':
       return array();
@@ -179,16 +179,16 @@ function phone_widget_settings($op, $wid
  * Implementation of hook_widget().
  */
 function phone_widget($op, &$node, $field, &$node_field) {
-  switch ($op) {   
+  switch ($op) {
     case 'form':
       $form = array();
-      
+
       $form[$field['field_name']] = array('#tree' => TRUE);
-      
+
       if ($field['multiple']) {
         $form[$field['field_name']]['#type'] = 'fieldset';
         $form[$field['field_name']]['#title'] = t($field['widget']['label']);
-        foreach (range(0,2) as $delta) {
+        foreach (range(0, 2) as $delta) {
           $form[$field['field_name']][$delta]['value'] = array(
             '#type' => 'textfield',
             '#title' => '',
@@ -197,10 +197,10 @@ function phone_widget($op, &$node, $fiel
             '#maxlength' => 255,
             '#weight' => $field['widget']['weight'],
             '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 20,
-            '#description' => $field['widget']['description'],            
+            '#description' => $field['widget']['description'],
           );
         }
-      }        
+      }
       else {
         $form[$field['field_name']][0]['value'] = array(
           '#type' => 'textfield',
@@ -210,161 +210,157 @@ function phone_widget($op, &$node, $fiel
           '#maxlength' => 255,
           '#weight' => $field['widget']['weight'],
           '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 20,
-          '#description' => $field['widget']['description'],          
+          '#description' => $field['widget']['description'],
         );
       }
-               
+
       return $form;
-    
+
     case 'process form values':
-          if (is_array($node_field)) {
-            foreach ($node_field as $delta => $item) {
-    	    //format the phone number
-    	      if ($item['value'] != '') 
-	      { 
-    	        if ($field['type'] == 'fr_phone') { 
-	  	  $node_field[0]['value'] = format_phone_number('fr', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'it_phone') { 
-	  	  $node_field[0]['value'] = format_phone_number('it', $node_field[0]['value'], $field);
-	        }	        
-    	        if ($field['type'] == 'ca_phone') { 
-	          $node_field[0]['value'] = format_phone_number('ca', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'uk_phone') { 
-	          $node_field[0]['value'] = format_phone_number('uk', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'ru_phone') { 
-	          $node_field[0]['value'] = format_phone_number('ru', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'es_phone') { 
-	          $node_field[0]['value'] = format_phone_number('es', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'au_phone') { 
-	          $node_field[0]['value'] = format_phone_number('au', $node_field[0]['value'], $field);
-	        }
-    	        if ($field['type'] == 'cs_phone') { 
-	          $node_field[0]['value'] = format_phone_number('cs', $node_field[0]['value'], $field);
-	        }	        
-	      }
-	    }
-	  }
-    break;
-    
-    case 'validate':
       if (is_array($node_field)) {
-          foreach ($node_field as $delta => $item) {
+        foreach ($node_field as $delta => $item) {
+          //format the phone number
+          if ($item['value'] != '') {
+            if ($field['type'] == 'fr_phone') {
+              $node_field[$delta]['value'] = format_phone_number('fr', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'it_phone') {
+              $node_field[$delta]['value'] = format_phone_number('it', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'ca_phone') {
+              $node_field[$delta]['value'] = format_phone_number('ca', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'uk_phone') {
+              $node_field[$delta]['value'] = format_phone_number('uk', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'ru_phone') {
+              $node_field[$delta]['value'] = format_phone_number('ru', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'es_phone') {
+              $node_field[$delta]['value'] = format_phone_number('es', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'au_phone') {
+              $node_field[$delta]['value'] = format_phone_number('au', $node_field[$delta]['value'], $field);
+            }
+            if ($field['type'] == 'cs_phone') {
+              $node_field[$delta]['value'] = format_phone_number('cs', $node_field[$delta]['value'], $field);
+            }
+          }
+        }
+      }
+      break;
 
-	    if ($item['value'] != '') 
-	    { 
-              if ($field['type'] == 'fr_phone' && !valid_phone_number('fr', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid French phone number<br>French phone numbers should only contain numbers and spaces and be like 99 99 99 99 99', array('%value' => $item['value'])));
-              }
-              if ($field['type'] == 'it_phone' && !valid_phone_number('it', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid Italian phone number<br>Italian phone numbers should only ...', array('%value' => $item['value'])));
-              }              
-              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'] == 'uk_phone' && !valid_phone_number('uk', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid British phone number<br>British Phone numbers should .... ', array('%value' => $item['value'])));
-              }    
-              if ($field['type'] == 'ru_phone' && !valid_phone_number('ru', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid Russian phone number<br>Russian Phone numbers should .... ', array('%value' => $item['value'])));
-              }
-              if ($field['type'] == 'es_phone' && !valid_phone_number('es', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid Spanish phone number<br>Spanish phone numbers should only contains numbers and spaces and be like 999 999 999', array('%value' => $item['value'])));
-              }  
-              if ($field['type'] == 'au_phone' && !valid_phone_number('au', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid Australian phone number<br>Australian phone numbers should contain only numbers with an optional prefix of "+61"', array('%value' => $item['value'])));
-              }   
-              if ($field['type'] == 'cs_phone' && !valid_phone_number('cs', $item['value'])) {
-                form_set_error($field['field_name'],t('"%value" is not a valid Czech phone number!<br>Czech phone numbers should contain only numbers and spaces be like 999 999 999 with an optional prefix of "+420" or "00420".', array('%value' => $item['value'])));
-              }                 
+    case 'validate':
+      if (is_array($node_field)) {
+        foreach ($node_field as $delta => $item) {
+          if ($item['value'] != '') {
+            if ($field['type'] == 'fr_phone' && !valid_phone_number('fr', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid French phone number<br />French phone numbers should only contain numbers and spaces and be like 99 99 99 99 99', array('%value' => $item['value'])));
+            }
+            if ($field['type'] == 'it_phone' && !valid_phone_number('it', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid Italian phone number<br />Italian phone numbers should only ...', array('%value' => $item['value'])));
+            }
+            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'] == 'uk_phone' && !valid_phone_number('uk', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid British phone number<br />British Phone numbers should .... ', array('%value' => $item['value'])));
+            }
+            if ($field['type'] == 'ru_phone' && !valid_phone_number('ru', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid Russian phone number<br />Russian Phone numbers should .... ', array('%value' => $item['value'])));
+            }
+            if ($field['type'] == 'es_phone' && !valid_phone_number('es', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid Spanish phone number<br />Spanish phone numbers should only contains numbers and spaces and be like 999 999 999', array('%value' => $item['value'])));
+            }
+            if ($field['type'] == 'au_phone' && !valid_phone_number('au', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid Australian phone number<br />Australian phone numbers should contain only numbers with an optional prefix of "+61"', array('%value' => $item['value'])));
+            }
+            if ($field['type'] == 'cs_phone' && !valid_phone_number('cs', $item['value'])) {
+              form_set_error($field['field_name'], t('"%value" is not a valid Czech phone number!<br />Czech phone numbers should contain only numbers and spaces be like 999 999 999 with an optional prefix of "+420" or "00420".', array('%value' => $item['value'])));
             }
           }
-      }      
+        }
+      }
       break;
-  }                   
+  }
 }
 
 /**
- * Verification for Phone Numbers.  
+ * Verification for Phone Numbers.
  *
  * @param string $countrycode
  * @param string $phonenumber
- * @return boolean Returns boolean FALSE if the phone number is not valid.  
+ * @return boolean Returns boolean FALSE if the phone number is not valid.
  */
 function valid_phone_number($countrycode, $phonenumber) {
 
-  $countrycode = trim($countrycode); 
+  $countrycode = trim($countrycode);
   $phonenumber = trim($phonenumber);
 
-  if ($countrycode == 'fr' 
-  	|| $countrycode == 'it'  
-  	|| $countrycode == 'ca'
-  	|| $countrycode == 'uk'
-  	|| $countrycode == 'ru'
-  	|| $countrycode == 'es'
-  	|| $countrycode == 'au'
-  	|| $countrycode == 'cs'  	
-  	) { 
-	
+  if ($countrycode == 'fr'
+    || $countrycode == 'it'
+    || $countrycode == 'ca'
+    || $countrycode == 'uk'
+    || $countrycode == 'ru'
+    || $countrycode == 'es'
+    || $countrycode == 'au'
+    || $countrycode == 'cs'
+    ) {
+
         //drupal_set_message('langue = ' . $countrycode, 'error');
 
-  	$valid_phone_function = 'valid_'. $countrycode . '_phone_number';  	
-  	include_once('./'. drupal_get_path('module', 'phone') . '/phone.'. $countrycode . '.inc');
-  	
-	if (function_exists($valid_phone_function)) {
-	    return $valid_phone_function($phonenumber);
-	}
-	else  { 
-	    return false; 	
-	}
+    $valid_phone_function = 'valid_'. $countrycode .'_phone_number';
+    include_once('./'. drupal_get_path('module', 'phone') .'/phone.'. $countrycode .'.inc');
+
+  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;
   }
-}  
+}
 
 /**
- * Verification for Phone Numbers.  
+ * Verification for Phone Numbers.
  *
  * @param string $countrycode
  * @param string $phonenumber
- * @return boolean Returns boolean FALSE if the phone number is not valid.  
+ * @return boolean Returns boolean FALSE if the phone number is not valid.
  */
 function format_phone_number($countrycode, $phonenumber, $field) {
 
-  $countrycode = trim($countrycode); 
+  $countrycode = trim($countrycode);
   $phonenumber = trim($phonenumber);
 
-  if ($countrycode == 'fr' 
-  	|| $countrycode == 'it'
-  	|| $countrycode == 'ca'
-  	|| $countrycode == 'uk'
-  	|| $countrycode == 'ru'
-  	|| $countrycode == 'es'
-  	|| $countrycode == 'au'
-   	|| $countrycode == 'cs' 	
-  	) { 
-	
-        //drupal_set_message('langue = ' . $countrycode, 'error');       
-
-  	$format_phone_function = 'format_'. $countrycode . '_phone_number';  	
-  	include_once('./'. drupal_get_path('module', 'phone') . '/phone.'. $countrycode . '.inc');
-  	
-	if (function_exists($format_phone_function)) {
-	    return $format_phone_function($phonenumber, $field);
-	}
-	else {
-	    return false; 
-	}
+  if ($countrycode == 'fr'
+      || $countrycode == 'it'
+      || $countrycode == 'ca'
+      || $countrycode == 'uk'
+      || $countrycode == 'ru'
+      || $countrycode == 'es'
+      || $countrycode == 'au'
+      || $countrycode == 'cs'
+      ) {
+        //drupal_set_message('langue = ' . $countrycode, 'error');
+
+    $format_phone_function = 'format_'. $countrycode .'_phone_number';
+    include_once('./'. drupal_get_path('module', 'phone') .'/phone.'. $countrycode .'.inc');
+
+  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;
   }
-}  
+}
 
