This repository was archived by the owner on Feb 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocbookwiki.profile
287 lines (265 loc) · 10.9 KB
/
docbookwiki.profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/**
* @file
* Installation steps for the profile DocBookWiki.
*/
/**
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function docbookwiki_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = 'DocBookWiki';
}
/**
* Implements hook_install_tasks().
*/
function docbookwiki_install_tasks($install_state) {
$tasks = array(
'docbookwiki_mail_config' => array(
'display_name' => st('Mail Settings'),
'type' => 'form',
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
'function' => 'docbookwiki_mail_config_form',
),
/*
'docbookwiki_config' => array(
'display_name' => st('DocBookWiki Settings'),
'type' => 'form',
'run' => INSTALL_TASK_RUN_IF_NOT_COMPLETED,
'function' => 'docbookwiki_config',
),
*/
);
return $tasks;
}
/**
* General configuration settings for DocBookWiki.
*
* @return
* An array containing form items to place on the module settings page.
*/
function docbookwiki_config() {
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t('DocBookWiki configuration options'),
);
// . . . . .
return system_settings_form($form);
}
/**
* Form builder for Mail and SMTP settings.
*/
function docbookwiki_mail_config_form($form, $form_state) {
$form['smtp_on'] = array(
'#type' => 'checkbox',
'#title' => t('Use PHPMailer to send e-mails'),
'#default_value' => variable_get('smtp_on', 0),
'#description' => t('When enabled, PHPMailer will be used to deliver all site e-mails.'),
);
// Only allow to send all e-mails if Mime Mail is not configured the same
// (mimemail_alter is the counterpart to smtp_on).
if (module_exists('mimemail') && variable_get('mimemail_alter', 0)) {
$form['smtp_on']['#disabled'] = TRUE;
$form['smtp_on']['#default_value'] = 0;
$form['smtp_on']['#description'] = t('MimeMail has been detected. To enable PHPMailer for mail transport, go to the <a href="@url">MimeMail settings page</a> and select PHPMailer from the available e-mail engines.', array('@url' => url('admin/config/system/mimemail')));
}
elseif (!variable_get('smtp_on', 0) && empty($form_state['input'])) {
drupal_set_message(t('PHPMailer is currently disabled.'), 'warning');
}
$form['server']['smtp_host'] = array(
'#type' => 'textfield',
'#title' => t('Primary SMTP server'),
'#default_value' => variable_get('smtp_host', 'localhost'),
'#description' => t('The host name or IP address of your primary SMTP server. Use !gmail-smtp for Google Mail.', array('!gmail-smtp' => '<code>smtp.gmail.com</code>')),
'#required' => TRUE,
);
$form['server']['smtp_hostbackup'] = array(
'#type' => 'textfield',
'#title' => t('Backup SMTP server'),
'#default_value' => variable_get('smtp_hostbackup', ''),
'#description' => t('Optional host name or IP address of a backup server, if the primary server fails. You may override the default port below by appending it to the host name separated by a colon. Example: !hostname', array('!hostname' => '<code>localhost:465</code>')),
);
$form['server']['smtp_port'] = array(
'#type' => 'textfield',
'#title' => t('SMTP port'),
'#size' => 5,
'#maxlength' => 5,
'#default_value' => variable_get('smtp_port', '25'),
'#description' => t('The standard SMTP port is 25, for Google Mail use 465.'),
'#required' => TRUE,
);
$form['server']['smtp_protocol'] = array(
'#type' => 'select',
'#title' => t('Use secure protocol'),
'#default_value' => variable_get('smtp_protocol', ''),
'#options' => array('' => t('No'), 'ssl' => t('SSL'), 'tls' => t('TLS')),
'#description' => t('Whether to use an encrypted connection to communicate with the SMTP server. Google Mail requires SSL.'),
);
if (!function_exists('openssl_open')) {
$form['server']['smtp_protocol']['#default_value'] = '';
$form['server']['smtp_protocol']['#disabled'] = TRUE;
$form['server']['smtp_protocol']['#description'] .= ' ' . t('Note: This option has been disabled since your PHP installation does not seem to have support for OpenSSL.');
variable_set('smtp_protocol', '');
}
$form['auth'] = array(
'#type' => 'fieldset',
'#title' => t('SMTP authentication'),
'#description' => t('Leave blank if your SMTP server does not require authentication.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['auth']['smtp_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => variable_get('smtp_username', ''),
'#description' => t('For Google Mail, enter your username including "@gmail.com".'),
);
if (!variable_get('smtp_hide_password', 0)) {
$form['auth']['smtp_password'] = array(
'#type' => 'textfield',
'#title' => t('Password'),
'#default_value' => variable_get('smtp_password', ''),
);
$form['auth']['smtp_hide_password'] = array(
'#type' => 'checkbox',
'#title' => t('Hide password'),
'#default_value' => 0,
'#description' => t("Check this option to permanently hide the plaintext password from peeking eyes. You may still change the password afterwards, but it won't be displayed anymore."),
);
}
else {
$have_password = (variable_get('smtp_password', '') != '');
$form['auth']['smtp_password'] = array(
'#type' => 'password',
'#title' => $have_password ? t('Change password') : t('Password'),
'#description' => $have_password ? t('Leave empty if you do not intend to change the current password.') : '',
);
}
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced SMTP settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['smtp_fromname'] = array(
'#type' => 'textfield',
'#title' => t('"From" name'),
'#default_value' => variable_get('smtp_fromname', ''),
'#description' => t('Enter a name that should appear as the sender for all messages. If left blank the site name will be used instead: %sitename.', array('%sitename' => variable_get('site_name', 'Drupal'))),
);
$form['advanced']['smtp_always_replyto'] = array(
'#type' => 'checkbox',
'#title' => t('Always set "Reply-To" address'),
'#default_value' => variable_get('smtp_always_replyto', 0),
'#description' => t('Enables setting the "Reply-To" address to the original sender of the message, if unset. This is required when using Google Mail, which would otherwise overwrite the original sender.'),
);
$form['advanced']['smtp_keepalive'] = array(
'#type' => 'checkbox',
'#title' => t('Keep connection alive'),
'#default_value' => variable_get('smtp_keepalive', 0),
'#description' => t('Whether to reuse an existing connection during a request. Improves performance when sending a lot of e-mails at once.'),
);
$form['advanced']['smtp_debug'] = array(
'#type' => 'select',
'#title' => t('Debug level'),
'#default_value' => variable_get('smtp_debug', 0),
'#options' => array(0 => t('Disabled'), 1 => t('Errors only'), 2 => t('Server responses'), 4 => t('Full communication')),
'#description' => t("Debug the communication with the SMTP server. You normally shouldn't enable this unless you're trying to debug e-mail sending problems."),
);
// Send a test email message if an address has been entered.
if ($test_address = variable_get('phpmailer_test', '')) {
// Delete first to avoid unintended resending in case of an error.
variable_del('phpmailer_test');
// If PHPMailer is enabled, send via regular drupal_mail().
if (phpmailer_enabled()) {
drupal_mail('phpmailer', 'test', $test_address, NULL);
}
// Otherwise, prepare and send the test mail manually.
else {
// Prepare the message without sending.
$message = drupal_mail('phpmailer', 'test', $test_address, NULL, array(), NULL, FALSE);
// Send the message. drupal_mail_wrapper() is only defined when PHPMailer
// is enabled, so drupal_mail_send() cannot be used.
// @see drupal_mail_send()
module_load_include('inc', 'phpmailer', 'includes/phpmailer.drupal');
phpmailer_send($message);
}
drupal_set_message(t('A test e-mail has been sent to %email. <a href="@watchdog-url">Check the logs</a> for any error messages.', array(
'%email' => $test_address,
'@watchdog-url' => url('admin/reports/dblog'),
)));
}
$form['test'] = array(
'#type' => 'fieldset',
'#title' => t('Test configuration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['test']['phpmailer_test'] = array(
'#type' => 'textfield',
'#title' => t('Recipient'),
'#default_value' => '',
'#description' => t('Type in an address to have a test e-mail sent there.'),
);
$form['#submit'] = array('docbookwiki_mail_config_form_submit');
return system_settings_form($form);
}
/**
* Form validation function.
*/
function docbookwiki_mail_config_form_validate($form, &$form_state) {
if ($form_state['values']['smtp_on']) {
if (intval($form_state['values']['smtp_port']) == 0) {
form_set_error('smtp_port', t('You must enter a valid SMTP port number.'));
}
}
}
/**
* Form submit function.
*/
function docbookwiki_mail_config_form_submit($form, &$form_state) {
// Enable/disable mail sending subsystem.
if ($form_state['values']['smtp_on']) {
if (!phpmailer_enabled()) {
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
$mail_system['default-system'] = 'DrupalPHPMailer';
variable_set('mail_system', $mail_system);
drupal_set_message(t('PHPMailer will be used to deliver all site e-mails.'));
watchdog('phpmailer', 'PHPMailer has been enabled.');
}
}
elseif (phpmailer_enabled()) {
// Remove PHPMailer from all mail keys it is configured for.
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
foreach ($mail_system as $key => $class) {
if ($class == 'DrupalPHPMailer') {
if ($key != 'default-system') {
unset($mail_system[$key]);
}
else {
$mail_system[$key] = 'DefaultMailSystem';
}
}
}
variable_set('mail_system', $mail_system);
drupal_set_message(t('PHPMailer has been disabled.'));
watchdog('phpmailer', 'PHPMailer has been disabled.');
}
// Log configuration changes.
$settings = array('host', 'port', 'protocol', 'username');
// Ignore empty passwords if hide password is active.
if (variable_get('smtp_hide_password', 0) && $form_state['values']['smtp_password'] == '') {
unset($form_state['values']['smtp_password']);
}
else {
$settings[] = 'password';
}
foreach ($settings as $setting) {
if ($form_state['values']['smtp_'. $setting] != variable_get('smtp_'. $setting, '')) {
watchdog('phpmailer', 'SMTP configuration changed.');
break;
}
}
}