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

code style cleanup

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