Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/README.txt,v
retrieving revision 1.19
diff -u -r1.19 README.txt
--- README.txt	8 Mar 2009 00:04:26 -0000	1.19
+++ README.txt	27 Mar 2009 22:24:51 -0000
@@ -20,6 +20,7 @@
 	+ Czech, 
 	+ Hungarian,
 	+ Costa Rican, 
+  + Brazilian,
 	+ US 
 	and Canadian phone numbers 
 * Formating of phone numbers 
Index: phone.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/phone.module,v
retrieving revision 1.23
diff -u -r1.23 phone.module
--- phone.module	8 Mar 2009 00:04:26 -0000	1.23
+++ phone.module	1 Apr 2009 02:47:55 -0000
@@ -38,7 +38,8 @@
     'au_phone' => array('label' => t('Australian Phone Numbers')),
     'cs_phone' => array('label' => t('Czech Phone Numbers')), 
     'hu_phone' => array('label' => t('Hungarian Phone Numbers')),
-    'nl_phone' => array('label' => t('Dutch Phone Numbers'))    
+    'nl_phone' => array('label' => t('Dutch Phone Numbers')),    
+    'br_phone' => array('label' => t('Brazilian Phone Numbers')),
    );
 }
 
@@ -116,6 +117,19 @@
           '#default_value' => isset($field['ca_phone_parentheses']) ? $field['ca_phone_parentheses'] : 1,
         );
       }            
+      if ($field['type'] == 'br_phone') {
+        $form['br_phone_separator'] = array(
+          '#type' => 'textfield',
+          '#title' => t('Separator'),
+          '#default_value' => isset($field['br_phone_separator']) ? $field['br_phone_separator'] : '-',
+          '#size' => 2,
+        );
+        $form['br_phone_parentheses'] = array(
+          '#type' => 'checkbox',
+          '#title' => t('Use parentheses around area code'),
+          '#default_value' => isset($field['br_phone_parentheses']) ? $field['br_phone_parentheses'] : 1,
+        );
+      }            
       return $form;
 
     case 'save':
@@ -123,6 +137,9 @@
       if ($field['type'] == 'ca_phone') {
         array_push($settings, 'ca_phone_separator', 'ca_phone_parentheses');
       }
+      if ($field['type'] == 'br_phone') {
+        array_push($settings, 'br_phone_separator', 'br_phone_parentheses');
+      }
       return $settings;        
     case 'database columns':
       if ($field['type'] == 'fr_phone'
@@ -134,8 +151,9 @@
        || $field['type'] == 'es_phone'
        || $field['type'] == 'au_phone'
        || $field['type'] == 'cs_phone'
-       || $field['type'] == 'hu_phone'       
-       || $field['type'] == 'nl_phone'              
+       || $field['type'] == 'hu_phone'         
+       || $field['type'] == 'nl_phone'     
+       || $field['type'] == 'br_phone'              
        ) { 
       	$columns = array(
         	'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
@@ -217,7 +235,10 @@
           }                  
           if ($field['type'] == 'nl_phone' && !valid_phone_number('nl', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Dutch phone number!<br>Dutch phone numbers should contain only numbers and spaces and - and be like 099-9999999 with an optional prefix of "+31".', array('%value' => $item['value'])));
-          }            
+          }                      
+          if ($field['type'] == 'br_phone' && !valid_phone_number('br', $item['value'])) {
+            form_set_error($field['field_name'], t('"%value" is not a valid Brazilian phone number!<br>Brazilian phone numbers should contain only numbers and spaces and - and be like 99 999-9999 or 99 9999-9999 with an optional prefix of "+55" or "0".', array('%value' => $item['value'])));
+          }        
         }
       }
       break;
@@ -258,7 +279,10 @@
           }  
           if ($field['type'] == 'nl_phone') {
             $node_field[$delta]['value'] = format_phone_number('nl', $node_field[$delta]['value'], $field);
-          }            
+          }       
+          if ($field['type'] == 'br_phone') {
+            $node_field[$delta]['value'] = format_phone_number('br', $node_field[$delta]['value'], $field);
+          }          
         }
       }
       break;
@@ -359,7 +383,8 @@
       			'au_phone',
       			'cs_phone', 
       			'hu_phone',
-      			'nl_phone'      			
+      			'nl_phone',
+      			'br_phone'       			
       			),
       'multiple values' => CONTENT_HANDLE_CORE,		
     ),
@@ -437,7 +462,8 @@
       			'au_phone',
       			'cs_phone',
       			'hu_phone',
-      			'nl_phone'      			
+      			'nl_phone',
+      			'br_phone'       			
       			),
       'multiple values' => CONTENT_HANDLE_CORE,
       'callbacks' => array(
@@ -645,7 +671,8 @@
   	|| $countrycode == 'au'
   	|| $countrycode == 'cs'  	
   	|| $countrycode == 'hu' 
-  	|| $countrycode == 'nl'   	
+  	|| $countrycode == 'nl'  
+  	|| $countrycode == 'br'  	
   	) { 
 	
         //drupal_set_message('langue = ' . $countrycode, 'error');
@@ -688,7 +715,8 @@
   	|| $countrycode == 'au'
    	|| $countrycode == 'cs' 	
    	|| $countrycode == 'hu' 	   	
-   	|| $countrycode == 'nl' 	   	   	
+   	|| $countrycode == 'nl' 	    	
+   	|| $countrycode == 'br' 	  	   	
   	) { 
 	
         //drupal_set_message('langue = ' . $countrycode, 'error');       
--- phone.br.inc
+++ phone.br.inc
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * @file
+ * CCK Field for Brazilian phone numbers.
+ * (based on CCK Field for French phone numbers.)
+ */
+
+define('PHONE_BR_REGEX', "/^(0055|55|0)?([1-9]{2})([2-9]\d{2,3})(\d{4})$/");
+
+/**  
+ * Verification for Brazilian Phone Numbers.  
+ *
+ * @param string $phonenumber
+ * @return boolean Returns boolean FALSE if the phone number is not valid. 
+ */
+function valid_br_phone_number($phonenumber, $field) {
+  $phonenumber  = str_replace(array(' ','-','+','(',')'), '', $phonenumber);
+  return (bool) preg_match(PHONE_BR_REGEX, $phonenumber);
+}
+
+/**
+ * Formatting for Brazilian Phone Numbers.  
+ *
+ * @param string $phonenumber
+ * @return string Returns a string containting the phone number with some formatting.
+ */
+function format_br_phone_number($phonenumber, $field) {
+  $phone  = str_replace(array(' ','-','+','(',')'), '', $phonenumber);
+  if (preg_match(PHONE_BR_REGEX, $phone, $matches) != 1) {
+    return $phonenumber;
+  }
+  
+  $separator = isset($field['br_phone_separator']) ? $field['br_phone_separator'] : '-';
+  
+  $formattedphone = '';
+  if ($field && $field['phone_country_code']) {
+    $formattedphone .= '+55 ';
+  }
+  if ($field['br_phone_parentheses']) {
+    $formattedphone .= '(' . $matches[2] . ') ';
+  }
+  else {
+    $formattedphone .= $matches[2] . ' ';
+  }
+  $formattedphone .= $matches[3] . $separator;
+  $formattedphone .= $matches[4];
+
+  return $formattedphone;
+}


