updated mailgun, mailsystem, honeypot, googleanalitycs, features, content_taxonomy

This commit is contained in:
2019-05-13 17:55:28 +02:00
parent 2ffad14939
commit e08a2639c6
54 changed files with 1911 additions and 423 deletions
@@ -16,11 +16,12 @@
* @return array
* An array containing form items to place on the module settings page.
*/
function mailgun_admin_settings($form, &$form_state) {
$library = libraries_detect('mailgun');
if (!$library['installed']) {
drupal_set_message(t('The Mailgun PHP library is not installed. Please see <a href="@url">documentation</a> for more information.', array('@url' => url('https://www.drupal.org/node/2547591'))), 'error');
function mailgun_admin_settings(array $form, array &$form_state) {
// Check if the Mailgun PHP library is installed.
if (!mailgun_check_library()) {
drupal_set_message(t('The Mailgun PHP library is not installed. Please see Installation section in the !link.', array(
'!link' => l(t('documentation'), MAILGUN_DOCUMENTATION_LINK),
)), 'error');
}
$key = variable_get('mailgun_api_key', '');
@@ -28,7 +29,9 @@ function mailgun_admin_settings($form, &$form_state) {
$form['mailgun_api_key'] = array(
'#title' => t('Mailgun API key'),
'#type' => 'textfield',
'#description' => t('Get your Secret API key from the <a href="@url">Mailgun dashboard</a>.', array('@url' => url('https://mailgun.com/app/dashboard'))),
'#description' => t('Get your Secret API key from the !link.', array(
'!link' => l(t('Mailgun dashboard'), MAILGUN_DASHBOARD_LINK),
)),
'#default_value' => $key,
'#required' => TRUE,
);
@@ -37,23 +40,25 @@ function mailgun_admin_settings($form, &$form_state) {
if (!empty($key)) {
try {
$client = mailgun_get_client($key);
} catch (Exception $e) {
watchdog('mailgun', 'An exception occurred. @code: @message', array('@code' => $e->getCode(), '@message' => $e->getMessage()), WATCHDOG_WARNING, 'admin/config/system/mailgun');
}
catch (Exception $e) {
watchdog('mailgun', 'An exception occurred. @code: @message', array(
'@code' => $e->getCode(),
'@message' => $e->getMessage(),
), WATCHDOG_WARNING, MAILGUN_ADMIN_PAGE);
drupal_set_message(t('Mailgun: %message', array('%message' => $e->getMessage())), 'error');
}
}
// Display settings only when a valid API key is present and client is active
// Display settings only when a valid API key is present and client is active.
if ($client) {
$domain_options = array(
'_sender' => t('Get domain from sender address'),
);
$domains = array();
$result = $client->get('domains');
if ($result && $result->http_response_code == 200) {
foreach ($result->http_response_body->items as $domain) {
$domains[$domain->name] = $domain;
$domain_options[$domain->name] = $domain->name;
$result = $client->domains()->index();
if (!empty($result)) {
foreach ($result->getDomains() as $domain) {
$domain_options[$domain->getName()] = $domain->getName();
}
}
@@ -61,7 +66,7 @@ function mailgun_admin_settings($form, &$form_state) {
'#title' => t('Domain'),
'#type' => 'select',
'#options' => $domain_options,
'#description' => t('Mails will be sent using this domain'),
'#description' => t('Mails will be sent using this domain.'),
'#default_value' => variable_get('mailgun_domain', '_sender'),
);
@@ -69,31 +74,70 @@ function mailgun_admin_settings($form, &$form_state) {
'#title' => t('Test mode'),
'#type' => 'checkbox',
'#default_value' => variable_get('mailgun_test', FALSE),
'#description' => t('Enables sending in test mode'),
);
$form['mailgun_queue'] = array(
'#title' => t('Queue mails'),
'#type' => 'checkbox',
'#description' => t('Mails will be queued and sent during cron runs. Useful for sending a large number of emails.'),
'#default_value' => variable_get('mailgun_queue', FALSE),
'#description' => t('Mailgun will accept the message but will not send it. This is useful for testing purposes.'),
);
$form['mailgun_log'] = array(
'#title' => t('Log mails'),
'#type' => 'checkbox',
'#description' => t('Log mails sent through Mailgun. Should not be enabled on production sites. Messages fail to send will be logged regardless of this setting.'),
'#description' => t('Log all mails sent through Mailgun. Messages fail to send will be logged regardless of this setting.'),
'#default_value' => variable_get('mailgun_log', FALSE),
);
$form['extra'] = array(
'#type' => 'fieldset',
'#title' => t('Additional settings'),
'#description' => t('These default settings apply to messages sent using Mailgun and may be overriden on a per-message basis.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// We have the same options for all settings.
$options = array(
'default' => t('Use default setting'),
'enabled' => t('Enabled'),
'disabled' => t('Disabled'),
);
$form['extra']['tracking'] = array(
'#type' => 'fieldset',
'#title' => t('Tracking'),
);
$form['extra']['tracking']['mailgun_tracking'] = array(
'#title' => t('Enable tracking'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Whether to enable event tracking by default or not. See !link for details.', array(
'!link' => l(t('Tracking Messages'), 'https://documentation.mailgun.com/user_manual.html#tracking-messages'),
)),
'#default_value' => variable_get('mailgun_tracking', 'default'),
);
$form['extra']['tracking']['mailgun_tracking_clicks'] = array(
'#title' => t('Enable click tracking'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Whether to enable click tracking by default or not.'),
'#default_value' => variable_get('mailgun_tracking_clicks', 'default'),
);
$form['extra']['tracking']['mailgun_tracking_opens'] = array(
'#title' => t('Enable open tracking'),
'#type' => 'select',
'#options' => $options,
'#description' => t('Whether to enable open tracking by default or not.'),
'#default_value' => variable_get('mailgun_tracking_opens', 'default'),
);
$formats = array('_none' => t('- None -'));
foreach (filter_formats() as $format) {
if ($format->format == 'php_code') {
if ($format->format === 'php_code') {
continue;
}
$formats[$format->format] = t($format->name);
$formats[$format->format] = $format->name;
}
$form['mailgun_format'] = array(
$form['extra']['mailgun_format'] = array(
'#title' => t('Text format'),
'#type' => 'select',
'#description' => t('Specify an additional text format to filter the message through before sending the email.'),
@@ -101,36 +145,24 @@ function mailgun_admin_settings($form, &$form_state) {
'#default_value' => variable_get('mailgun_format', '_none'),
);
$form['defaults'] = array(
'#type' => 'fieldset',
'#title' => t('Default settings'),
'#description' => t('These default settings apply to messages sent using Mailgun and may be overriden on a per-message basis.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
$form['extra']['mailgun_queue'] = array(
'#title' => t('Queue mails'),
'#type' => 'checkbox',
'#description' => t('Mails will be queued and sent during cron runs. Useful for sending a large number of emails.'),
'#default_value' => variable_get('mailgun_queue', FALSE),
);
$form['defaults']['mailgun_tracking'] = array(
'#title' => t('Enable tracking'),
'#type' => 'select',
'#options' => array('default' => t('Use default setting'), 'enabled' => t('Enabled'), 'disabled' => t('Disabled')),
'#description' => t('Whether to enable event tracking by default or not. See <a href="@url">Tracking Messages</a> for details.', array('@url' => url('https://documentation.mailgun.com/user_manual.html#tracking-messages'))),
'#default_value' => variable_get('mailgun_tracking', 'default'),
);
$form['defaults']['mailgun_tracking_clicks'] = array(
'#title' => t('Enable click tracking'),
'#type' => 'select',
'#options' => array('default' => t('Use default setting'), 'enabled' => t('Enabled'), 'disabled' => t('Disabled')),
'#description' => t('Whether to enable click tracking by default or not.'),
'#default_value' => variable_get('mailgun_tracking_clicks', 'default'),
);
$form['defaults']['mailgun_tracking_opens'] = array(
'#title' => t('Enable open tracking'),
'#type' => 'select',
'#options' => array('default' => t('Use default setting'), 'enabled' => t('Enabled'), 'disabled' => t('Disabled')),
'#description' => t('Whether to enable open tracking by default or not.'),
'#default_value' => variable_get('mailgun_tracking_opens', 'default'),
$form['extra']['mailgun_tagging_mailkey'] = array(
'#type' => 'checkbox',
'#title' => t('Enable tags by mail key'),
'#description' => t('See !url for details.', array(
'!url' => l(t('Tagging'), 'https://documentation.mailgun.com/user_manual.html#tagging', array(
'attributes' => array(
'onclick' => "target='_blank'",
),
)),
)),
'#default_value' => variable_get('mailgun_tagging_mailkey', TRUE),
);
}
@@ -150,11 +182,21 @@ function mailgun_admin_settings_validate($form, &$form_state) {
// The API key has changed. Perform validation.
$form_state['values']['mailgun_api_key'] = trim($form_state['values']['mailgun_api_key']);
$client = mailgun_get_client($form_state['values']['mailgun_api_key']);
if ($client === FALSE) {
drupal_set_message(t('Could not connect to Mailgun API. Please check your settings'), 'warning');
return;
}
try {
$result = $client->get('domains');
$client->domains()->index();
drupal_set_message(t('Your API key has been successfully validated.'));
} catch (Exception $e) {
form_set_error('mailgun_api_key', t('An exception occurred. @code: @message', array('@code' => $e->getCode(), '@message' => $e->getMessage())));
}
catch (Exception $e) {
form_set_error('mailgun_api_key', t('An exception occurred. @code: @message', array(
'@code' => $e->getCode(),
'@message' => $e->getMessage(),
)));
}
}
}
@@ -173,9 +215,11 @@ function mailgun_test_form($form, &$form_state) {
'#required' => TRUE,
);
$message = "Howdy!\n\nIf this e-mail is displayed correctly and delivered sound and safe, congrats! You have successfully configured Mailgun.";
$message .= ' Visit the <a href="@project">project page</a> to contribute or read <a href="@documentation">documentation</a> to learn more.';
$message = t($message, array('@project' => url('https://www.drupal.org/project/mailgun'), '@documentation' => url('https://www.drupal.org/node/2547591')));
$message = "Howdy!\n\nIf this e-mail is displayed correctly and delivered sound and safe, congrats! You have successfully configured Mailgun. ";
$message .= t('Visit the !project to contribute or read !documentation to learn more.', array(
'!project' => l(t('project page'), 'https://www.drupal.org/project/mailgun'),
'!documentation' => l(t('documentation'), MAILGUN_DOCUMENTATION_LINK),
));
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message'),
@@ -196,7 +240,7 @@ function mailgun_test_form($form, &$form_state) {
);
$form['cancel'] = array(
'#type' => 'link',
'#href' => 'admin/config/system/mailgun',
'#href' => MAILGUN_ADMIN_PAGE,
'#title' => t('Cancel'),
);
@@ -205,17 +249,26 @@ function mailgun_test_form($form, &$form_state) {
/**
* Form submission handler for mailgun_test_form().
*
* Send the test e-mail.
*/
function mailgun_test_form_submit($form, &$form_state) {
$to = $form_state['values']['to'];
$body = explode('\n', $form_state['values']['message']);
$params = array(
'message' => $form_state['values']['message'],
'message' => $body,
'attachment' => $form_state['values']['attachment'],
);
$site_name = variable_get('site_name', '');
$default_from = variable_get('site_mail', ini_get('sendmail_from'));
$from = (!empty($site_name)) ? $site_name . ' <' . $default_from . '>' : $default_from;
$result = drupal_mail('mailgun', 'test', $to, $GLOBALS['language'], $params, $from);
drupal_set_message(t('Test email sent from %from to %to. If you have the "Log mails" setting enabled, check the <a href="@url">database log</a> for details.', array('%from' => $result['from'], '%to' => $result['to'], '@url' => url('admin/reports/dblog'))), 'status');
drupal_set_message(t('Test email sent from %from to %to. If you have the "Log mails" setting enabled, check the <a href="@url">database log</a> for details.',
array(
'%from' => $result['from'],
'%to' => $result['to'],
'@url' => url('admin/reports/dblog'),
)), 'status');
}