Index: email.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/email/email.info,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 email.info
--- email.info	18 Jun 2007 23:06:37 -0000	1.1.2.2
+++ email.info	2 Apr 2008 15:00:27 -0000
@@ -1,5 +1,6 @@
 ; $Id: email.info,v 1.1.2.2 2007/06/18 23:06:37 dww Exp $
 name = EMail
 description = Defines an email field type for cck
-dependencies = content
+dependencies[] = content
 package = CCK
+core = 6.x
Index: email.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/email/email.module,v
retrieving revision 1.9.2.3
diff -u -p -r1.9.2.3 email.module
--- email.module	17 Apr 2007 05:58:31 -0000	1.9.2.3
+++ email.module	2 Apr 2008 15:00:28 -0000
@@ -12,14 +12,39 @@ function email_help($section) {
   }
 }
 
+/**
+ * Implementation of hook_theme().
+ */
+function email_theme() {
+  return array(
+    'email_textfield' => array(
+      'arguments' => array('element' => NULL),
+    ),
+    'email_formatter_default' => array(
+      'arguments' => array('element' => NULL),
+    ),
+    'email_formatter_spamspan' => array(
+      'arguments' => array('element' => NULL),
+    ),
+    'email_formatter_contact' => array(
+      'arguments' => array('element' => NULL),
+    ),
+  );
+}
 
 /**
  * Implementation of hook_field_info().
  */
 function email_field_info() {
   return array(
-    'email' => array('label' => t('E-Mail')),
-   );
+    'email' => array(
+      'label' => 'E-Mail',
+      'callbacks' => array(
+        'tables' => CONTENT_CALLBACK_DEFAULT,
+        'arguments' => CONTENT_CALLBACK_DEFAULT,
+      ),
+    ),
+  );
 }
 
 
@@ -29,9 +54,7 @@ function email_field_info() {
 function email_field_settings($op, $field) {
   switch ($op) {
     case 'database columns':
-      $columns = array(
-        'email' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
-      );
+      $columns['email'] = array('type' => 'varchar', 'length' => 255, 'not null' => FALSE);
       return $columns;
   }
 }
@@ -40,58 +63,77 @@ function email_field_settings($op, $fiel
 /**
  * Implementation of hook_field().
  */
-function email_field($op, &$node, $field, &$node_field, $teaser, $page) {
+function email_field($op, &$node, $field, &$items, $teaser, $page) {
   switch ($op) {
-    case 'view':     
-      foreach ($node_field as $delta => $item) {
-        $node_field[$delta]['view'] = content_format($field, $item, 'email', $node);
+    case 'validate':
+      if (is_array($items)) {
+          foreach ($items as $delta => $item) {
+            if ($item['email'] != '' && !valid_email_address(trim($item['email']))) {
+              form_set_error($field['field_name'],t('"%mail" is not a valid email address',array('%mail' => $item['email'])));
+            }
+          }
       }
-      return theme('field', $node, $field, $node_field, $teaser, $page);
+      break;
   }
 }
 
 /**
+ * Implementation of hook_content_is_empty().
+ */
+function email_content_is_empty($item, $field) {
+  if (empty($item['email'])) {
+    return TRUE;
+  }
+  return FALSE;
+}
+
+/**
  * Implementation of hook_field_formatter_info().
- *
  */
 function email_field_formatter_info() {
-  return array(
+  $a = array(
     'default' => array(
-      'label' => 'Default Email-Link',
-      'field types' => array('email'),
-    ),
-    'invisi' => array(
-      'label' => 'Email-Invisimail',
+      'label' => t('Default email link'),
       'field types' => array('email'),
+      'multiple values' => CONTENT_HANDLE_CORE,
     ),
     'contact' => array(
-      'label' => 'Email-Contact Form',
+      'label' => t('Email contact form'),
       'field types' => array('email'),
+      'multiple values' => CONTENT_HANDLE_CORE,
     ),
   );
+  if (module_exists('spamspan')) {
+    $a += array(
+      'spamspan' => array(
+        'label' => t('Email-SpamSpan'),
+        'field types' => array('email'),
+        'multiple values' => CONTENT_HANDLE_CORE,
+      ),
+    );
+  }
+  return $a;
 }
 
-function email_field_formatter($field, $item, $formatter, $node) {
-  if (empty($item['email'])) {
-    return '';
-  }
-  else {
-    if ($field['widget']['link_type'] == 'form' || $formatter == 'contact') {
-      $mailto = l(t('Email Contact Form'), 'email/'.$node->nid.'/'.$field['field_name']);
-    }
-    elseif (($field['widget']['link_type'] == 'mailto_encrypt' || $formatter == 'invisi') && module_exists('invisimail')) {
-      $format = $GLOBALS['invisimail_format'];
-      if (!(variable_get('invisimail_link_'.$format, TRUE))) {     
-        variable_set('invisimail_link_'.$format, TRUE);
-        variable_set('invisimail_js_'.$format, TRUE);
-      }
-      $mailto = invisimail_ascii_encode($item['email']);
-    }
-    else {
-      $mailto =  '<a href="mailto:'. $item['email']. '">'. check_plain($item['email']) .'</a>';
-    }
-    return $mailto;
-  }
+/**
+ * Theme function for 'default' email field formatter.
+ */
+function theme_email_formatter_default($element) {
+  return '<a href="mailto:'. $element['#item']['email'] .'">'. check_plain($element['#item']['email']) .'</a>';
+}
+
+/**
+ * Theme function for 'spamspan' email field formatter.
+ */
+function theme_email_formatter_spamspan($element) {
+  return spamspan($element['#item']['email']);
+}
+
+/**
+ * Theme function for 'contact' email field formatter.
+ */
+function theme_email_formatter_contact($element) {
+  return l(t('Email contact form'), 'email/'. arg(1) .'/'. $element['#field_name']);
 }
 
 
@@ -100,13 +142,30 @@ function email_field_formatter($field, $
  */
 function email_widget_info() {
   return array(
-    'email' => array(
-      'label' => t('Textfield'),
+    'email_textfield' => array(
+      'label' => t('Text field'),
       'field types' => array('email'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array(
+        'default value' => CONTENT_CALLBACK_DEFAULT,
+      ),
     ),
   );
 }
 
+/**
+ * Implementation of FAPI hook_elements().
+ */
+function email_elements() {
+  return array(
+    'email_textfield' => array(
+      '#input' => TRUE,
+      '#columns' => array('email'),
+      '#delta' => 0,
+      '#process' => array('email_textfield_process'),
+    ),
+  );
+}
 
 /**
  * Implementation of hook_widget_settings().
@@ -122,117 +181,74 @@ function email_widget_settings($op, $wid
         '#required' => FALSE,
         '#description' => t('Size of textfield'),
       );
-      
-      $options = array(
-        'mailto' => t('Mailto: Direct link'), 
-        'form' => t('Contact form'), 
-      );
-      if (module_exists('invisimail')) {
-        $options += array('mailto_encrypt' => t('Mailto: Direct link with invisimail encryption'));
-      }
-      $form['link_type'] = array(
-        '#type' => 'radios',
-        '#title' => t('Email Link Type'),
-        '#default_value' => isset($widget['link_type']) ? $widget['link_type'] : 'mailto',
-        '#options' => $options,
-      );
-      
       return $form;
-      
+
     case 'validate':
-      if (!empty($widget['size']) && (!is_numeric($widget['size']) || intval($widget['size']) != $widget['size'] || $widget['size'] <= 0)) {
-        form_set_error('size', t('"Size" must be a positive integer.'));
+      if (!is_numeric($widget['size']) || intval($widget['size']) != $widget['size'] || $widget['size'] <= 0) {
+        form_set_error('size', t('"size" must be a positive integer.'));
       }
       break;
 
     case 'save':
-      return array('size', 'link_type');
+      return array('size');
   }
 }
 
-
 /**
  * Implementation of hook_widget().
  */
-function email_widget($op, &$node, $field, &$node_field) {
-  switch ($op) {   
-    case 'form':
-      $form = array();
-      $form[$field['field_name']] = array(
-        '#tree' => TRUE, 
-        '#weight' => $field['widget']['weight'],
-      );
-      
-      if ($field['multiple']) {
-        $form[$field['field_name']]['#type'] = 'fieldset';
-        $form[$field['field_name']]['#title'] = t($field['widget']['label']);
-        foreach (range(0,2) as $delta) {
-          $default_value = "";
-          if (isset($field['widget']['default_value'][$delta]['email'])) {
-            $default_value = $field['widget']['default_value'][$delta]['email'];
-          }
-          $form[$field['field_name']][$delta]['email'] = array(
-            '#type' => 'textfield',
-            '#title' => '',
-            '#default_value' => isset($node_field[$delta]['email']) ? $node_field[$delta]['email'] : $default_value,
-            '#required' => $field['required'] ? $field['required'] : FALSE,
-            '#maxlength' => 255,
-            '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
-            '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
-          );
-        }
-      }
-      else {
-        $default_value = "";
-        if (isset($field['widget']['default_value'][0]['email'])) {
-          $default_value = $field['widget']['default_value'][0]['email'];
-        }
-        $form[$field['field_name']][0]['email'] = array(
-          '#type' => 'textfield',
-          '#title' => $field['widget']['label'],
-          '#default_value' => isset($node_field[0]['email']) ? $node_field[0]['email'] : $default_value,
-          '#required' => $field['required'] ? $field['required'] : FALSE,
-          '#maxlength' => 255,
-          '#size' => isset($field['widget']['size']) ? $field['widget']['size'] : 60,
-          '#description' => isset($field['widget']['description']) ? $field['widget']['description'] : '',
-        );
-      }
-      
-      return $form;
-    
-    case 'validate':
-      if (is_array($node_field)) {
-          foreach ($node_field as $delta => $item) {
-            if ($item['email'] != '' && !valid_email_address($item['email'])) {
-              form_set_error($field['field_name'],t('"%mail" is not a valid email address',array('%mail' => $item['email'])));
-            }
-          }
-      }
-      break;
-  }           
+function email_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  $element = array(
+    '#type' => $field['widget']['type'],
+    '#default_value' => isset($items[$delta]) ? $items[$delta] : '',
+  );
+  return $element;
 }
 
 /**
- * Implementation of hook_menu().
+ * Process an individual element.
  */
-function email_menu($may_cache) {
-  $items = array();
+function email_textfield_process($element, $edit, $form_state, $form) {
+  $field = $form['#field_info'][$element['#field_name']];
+  $field_key = $element['#columns'][0];
+  $delta = $element['#delta'];
 
-  if ($may_cache) {
-    $items[] = array('path' => 'email',
-      'title' => t('Email Contact Form'),
-      'callback' => 'email_mail_page',
-      'access' => user_access('access content'),
-      'type' => MENU_CALLBACK,
-    );
-  }
+  $element[$field_key] = array(
+    '#type' => 'textfield',
+    '#title' => t($field['widget']['label']),
+    '#description' => t($field['widget']['description']),
+    '#required' => $element['#required'],
+    '#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
+  );
+  return $element;
+}
+
+/**
+ * FAPI theme for an individual text elements.
+ */
+function theme_email_textfield($element) {
+  return $element['#children'];
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function email_menu() {
+  $items['email/%nid/%field'] = array(
+    'title' => t('Email Contact Form'),
+    'page callback' => 'email_mail_page',
+    'page arguments' => array(1, 2),
+    'access callback' => 'node_access',
+    'access arguments' => array('view', 1),
+    'type' => MENU_CALLBACK,
+  );
   return $items;
 }
 
 /**
  * The contact form page.
  */
-function email_mail_page($nid=null, $fieldname=null) {
+function email_mail_page($nid = NULL, $fieldname = NULL) {
   if (empty($nid) || empty($fieldname)) {
     drupal_not_found();
     return;
@@ -268,7 +284,7 @@ function email_mail_page($nid=null, $fie
 
 function email_mail_page_form() {
   global $user;
-  
+
   if ($user->uid) {
     $edit['name'] = $user->name;
     $edit['mail'] = $user->mail;
@@ -377,4 +393,3 @@ function email_mail_page_form_submit($fo
   // Jump to home page rather than back to contact page to avoid contradictory messages if flood control has been activated.
   return 'node/'.$node->nid;
 }
-?>
\ No newline at end of file
