You are here

function webform_mollom_form_info in Webform 6.3

Same name and namespace in other branches
  1. 7.3 webform.module \webform_mollom_form_info()

Implements hook_mollom_form_info().

File

./webform.module, line 3673

Code

function webform_mollom_form_info($form_id) {
  module_load_include('inc', 'webform', 'includes/webform.components');
  $nid = drupal_substr($form_id, 20);
  $node = node_load($nid);
  $form_info = array(
    'title' => t('@name form', array(
      '@name' => $node->title,
    )),
    'mode' => MOLLOM_MODE_ANALYSIS,
    'bypass access' => array(
      'edit all webform submissions',
      'edit any webform content',
    ),
    'entity' => 'webform',
    'elements' => array(),
    'mapping' => array(
      'post_id' => 'details][sid',
      'author_id' => 'details][uid',
    ),
  );

  // Add components as elements.
  // These components can be enabled for textual analysis (when not using a
  // CAPTCHA-only protection) in Mollom's form configuration.
  foreach ($node->webform['components'] as $cid => $component) {
    if (webform_component_feature($component['type'], 'spam_analysis')) {
      $parents = implode('][', webform_component_parent_keys($node, $component));
      $form_info['elements']['submitted][' . $parents] = check_plain(t($component['name']));
    }
  }

  // Assign field mappings based on webform configuration.
  // Since multiple emails can be configured, we iterate over all and take
  // over the assigned component for the field mapping in any email, unless
  // we already assigned one. We are not interested in administratively
  // configured static strings, only user-submitted values.
  foreach ($node->webform['emails'] as $email) {

    // Subject (post_title).
    if (!isset($form_info['mapping']['post_title'])) {
      $cid = $email['subject'];
      if (is_numeric($cid)) {
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
        $form_info['mapping']['post_title'] = 'submitted][' . $parents;
      }
    }

    // From name (author_name).
    if (!isset($form_info['mapping']['author_name'])) {
      $cid = $email['from_name'];
      if (is_numeric($cid)) {
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
        $form_info['mapping']['author_name'] = 'submitted][' . $parents;
      }
    }

    // From address (author_mail).
    if (!isset($form_info['mapping']['author_mail'])) {
      $cid = $email['from_address'];
      if (is_numeric($cid)) {
        $parents = implode('][', webform_component_parent_keys($node, $node->webform['components'][$cid]));
        $form_info['mapping']['author_mail'] = 'submitted][' . $parents;
      }
    }
  }
  return $form_info;
}