Commit f0206254 authored by Matthias Hutterer's avatar Matthias Hutterer
Browse files

code style cleanup

parent b856d449
<?php
// $Id$
/**
* @file
* Defines schema for email fields
*/
/**
* Implements hook_field_schema().
*/
......
......@@ -37,7 +37,7 @@ function email_field_validate($obj_type, $object, $field, $instance, $langcode,
/**
* Implements of hook_content_is_empty().
* Implements hook_content_is_empty().
*/
function email_field_is_empty($item, $field) {
if (empty($item['email'])) {
......@@ -87,39 +87,39 @@ function email_field_formatter_view($object_type, $object, $field, $instance, $l
switch ($display['type']) {
case 'email_default':
foreach ($items as $delta => $item) {
$output = l($item['email'], 'mailto:'. $item['email']);
$output = l($item['email'], 'mailto:' . $item['email']);
$element[$delta] = array('#markup' => $output);
}
break;
case 'email_contact':
$ids = entity_extract_ids($object_type, $object);
foreach ($items as $delta => $item) {
$element[$delta] = array('#markup' => l(t('Contact person by email'), 'email/'. $object_type .'/'. $ids[0] .'/'. $instance['field_name']));
// since email is always sent to first item's email, break after any email address found
$element[$delta] = array('#markup' => l(t('Contact person by email'), 'email/' . $object_type . '/' . $ids[0] . '/' . $instance['field_name']));
// Since email is always sent to first item's email, break after any email address found.
break;
}
break;
case 'email_plain':
foreach ($items as $delta => $item) {
$element[$delta] = array('#markup' => check_plain($item['email']));
}
break;
case 'email_spamspan':
foreach ($items as $delta => $item) {
if (module_exists('spamspan')) {
$element[$delta] = spamspan($item['email']);
}
else {
$output = l($item['email'], 'mailto:'. $item['email']);
$output = l($item['email'], 'mailto:' . $item['email']);
$element[$delta] = array('#markup' => $output);
}
}
break;
}
return $element;
return $element;
}
......@@ -169,7 +169,7 @@ function email_field_widget_form(&$form, &$form_state, $field, $instance, $langc
}
/**
* Implementation of hook_menu().
* Implements hook_menu().
*/
function email_menu() {
$items['email/%/%/%'] = array(
......@@ -202,23 +202,23 @@ function email_mail_page($object_type, $object_id, $field_name) {
drupal_not_found();
return;
}
//verify this is an email field
$field_info = field_info_field($field_name);
if ($field_info['type'] != 'email') {
drupal_not_found();
return;
}
$objects = entity_load($object_type, array($object_id));
$object = $objects[$object_id];
//verify the object really exists
if (!$object) {
drupal_not_found();
return;
}
//check field perm
if (module_exists('field_permissions')) {
if (!field_permissions_field_access('view', $field_info, $object_type, $object, $user)) {
......@@ -226,7 +226,7 @@ function email_mail_page($object_type, $object_id, $field_name) {
return;
}
}
//use the first email address as receiver
$field = array_pop($object->$field_name);
foreach ($field as $delta => $item) {
......@@ -241,13 +241,13 @@ function email_mail_page($object_type, $object_id, $field_name) {
drupal_not_found();
return;
}
$entity_info = entity_extract_ids($object_type, $object);
$settings = field_info_instance($object_type, $field_name, $entity_info[2]);
$found = false;
$found = FALSE;
foreach ($settings['display'] as $display_name => $display_data) {
if (isset($display_data['type']) && ($display_data['type'] === 'email_contact')) {
$found = true;
$found = TRUE;
break;
}
}
......@@ -259,7 +259,7 @@ function email_mail_page($object_type, $object_id, $field_name) {
if (!flood_is_allowed('email', variable_get('email_hourly_threshold', 3))) {
return t("You cannot send more than %number messages per hour. Please try again later.", array('%number' => variable_get('email_hourly_threshold', 3)));
}
return drupal_get_form('email_mail_page_form', $object_type, $object_id, $field_name, $email);
}
......@@ -328,7 +328,7 @@ function email_mail_page_form_validate($form, &$form_state) {
}
if (preg_match("/\r|\n/", $form_state['values']['subject'])) {
form_set_error('subject', t('The subject cannot contain linebreaks.'));
watchdog('mail', 'Email injection exploit attempted in email form subject: '. check_plain($form_state['values']['subject']), WATCHDOG_NOTICE);
watchdog('mail', 'Email injection exploit attempted in email form subject: ' . check_plain($form_state['values']['subject']), WATCHDOG_NOTICE);
}
}
......@@ -340,55 +340,55 @@ function email_mail_page_form_submit($form, &$form_state) {
$object_id = $form_state['values']['object_id'];
$field_name = $form_state['values']['field_name'];
$email = $form_state['values']['email'];
//load entity
// Load entity
$objects = entity_load($object_type, array($object_id));
$object = $objects[$object_id];
$object_info = entity_get_info($object_type);
// E-mail address of the sender: as the form field is a text field,
// all instances of \r and \n have been automatically stripped from it.
$from = $form_state['values']['mail'];
$params['object'] = $object;
$params['subject'] = $form_state['values']['subject'];
$params['name'] = $form_state['values']['name'];
$params['message'] = $form_state['values']['message'];
$path = "";
if (isset($object_info['path callback']) && function_exists($object_info['path callback'])) {
$path = $object_info['path callback']($object);
}
$params['url'] = url($path, array('absolute' => TRUE));
// Send the e-mail to the recipients:
drupal_mail('email', 'contact', $email, language_default(), $params, $from);
// Log the operation:
flood_register_event('email');
watchdog('mail', t('%name-from sent an e-mail at %form.', array('%name-from' => $form_state['values']['name'], '%form' => url($_GET['q'], array('absolute' => TRUE)))));
drupal_set_message(t('Your message has been sent.'));
$form_state['redirect'] = $path;
}
/**
* Implementation of hook_mail()
* Implements hook_mail().
*/
function email_mail($key, &$message, $params) {
$language = $message['language'];
switch($key) {
switch ($key) {
case 'contact':
// Compose the body:
$message['body'][] = t('@name sent a message using the contact form at @url.', array('@name' => $params['name'], '@url' => $params['url']), array('langcode' =>$language->language));
$message['body'][] = $params['message'];
$message['subject'] = "";
//include the title of the entity, if one exists
$message['subject'] = "";
// Include the title of the entity, if one exists
$object = $params['object'];
if (isset($object->title) && !empty($object->title)) {
$message['subject'] = "[". check_plain(preg_replace("/\r|\n/",'', $object->title)) ."]";
$message['subject'] = "[" . check_plain(preg_replace("/\r|\n/", '', $object->title)) . "]";
}
$message['subject'] .= " " . check_plain($params['subject']);
break;
......@@ -399,7 +399,7 @@ function email_mail($key, &$message, $params) {
//TODO Token support
/**
* Implements of hook_token_list()
* Implements hook_token_list().
*
function email_token_list($type = 'all') {
if ($type == 'field' || $type == 'all') {
......@@ -410,7 +410,7 @@ function email_token_list($type = 'all') {
}
/**
* Implements of hook token_values().
* Implements hook token_values().
*
function email_token_values($type, $object = NULL, $options = array()) {
if ($type == 'field') {
......@@ -420,7 +420,8 @@ function email_token_values($type, $object = NULL, $options = array()) {
return $tokens;
}
}
*/
*/
/**
* Settings for contact form
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment