Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/phone/README.txt,v
retrieving revision 1.18
diff -u -r1.18 README.txt
--- README.txt	8 Dec 2008 01:26:54 -0000	1.18
+++ README.txt	1 Apr 2009 02:43:20 -0000
@@ -19,6 +19,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.22
diff -u -r1.22 phone.module
--- phone.module	8 Dec 2008 01:26:54 -0000	1.22
+++ phone.module	1 Apr 2009 02:50:00 -0000
@@ -37,7 +37,8 @@
     'es_phone' => array('label' => t('Spanish Phone Numbers')),
     'au_phone' => array('label' => t('Australian Phone Numbers')),
     'cs_phone' => array('label' => t('Czech Phone Numbers')), 
-    'hu_phone' => array('label' => t('Hungarian Phone Numbers'))
+    'hu_phone' => array('label' => t('Hungarian Phone Numbers')),
+    'br_phone' => array('label' => t('Brazilian Phone Numbers'))
    );
 }
 
@@ -115,6 +116,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':
@@ -122,6 +136,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,6 +151,7 @@
        || $field['type'] == 'au_phone'
        || $field['type'] == 'cs_phone'
        || $field['type'] == 'hu_phone'       
+       || $field['type'] == 'br_phone'
        ) { 
       	$columns = array(
         	'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
@@ -213,6 +231,9 @@
           if ($field['type'] == 'hu_phone' && !valid_phone_number('hu', $item['value'])) {
             form_set_error($field['field_name'], t('"%value" is not a valid Hungarian phone number!<br>Hungarian phone numbers should contain only numbers and spaces be like 70 999 9999 with an optional prefix of "+36" or "06".', 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;
@@ -251,6 +272,9 @@
           if ($field['type'] == 'hu_phone') {
             $node_field[$delta]['value'] = format_phone_number('hu', $node_field[$delta]['value'], $field);
           }          
+          if ($field['type'] == 'br_phone') {
+            $node_field[$delta]['value'] = format_phone_number('br', $node_field[$delta]['value'], $field);
+          }
         }
       }
       break;
@@ -350,7 +374,8 @@
       			'es_phone',
       			'au_phone',
       			'cs_phone', 
-      			'hu_phone'      			      			
+      			'hu_phone',
+            'br_phone'
       			),
       'multiple values' => CONTENT_HANDLE_CORE,		
     ),
@@ -427,7 +452,8 @@
       			'es_phone',
       			'au_phone',
       			'cs_phone',
-      			'hu_phone'      			      			
+      			'hu_phone',
+      			'br_phone'     			      			
       			),
       'multiple values' => CONTENT_HANDLE_CORE,
       'callbacks' => array(
@@ -635,6 +661,7 @@
   	|| $countrycode == 'au'
   	|| $countrycode == 'cs'  	
   	|| $countrycode == 'hu'  	  	
+    || $countrycode == 'br'
   	) { 
 	
         //drupal_set_message('langue = ' . $countrycode, 'error');
@@ -677,6 +704,7 @@
   	|| $countrycode == 'au'
    	|| $countrycode == 'cs' 	
    	|| $countrycode == 'hu' 	   	
+    || $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;
+}


