forked from B-Translator/old_btr_server
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbtranslator.profile
315 lines (285 loc) · 12.1 KB
/
btranslator.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
/**
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function btranslator_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = 'B-Translator';
}
/**
* Implements hook_install_tasks().
*/
function btranslator_install_tasks($install_state) {
$tasks = array(
'btranslator_config' => array(
'display_name' => st('B-Translator Settings'),
'type' => 'form',
'run' => INSTALL_TASK_RUN_IF_REACHED,
'function' => 'btranslator_config',
),
'btranslator_smtp' => array(
'display_name' => st('SMTP Settings'),
'type' => 'form',
'run' => INSTALL_TASK_RUN_IF_REACHED,
'function' => 'smtp_config',
),
/*
'btranslator_disqus' => array(
'display_name' => st('Disqus Settings'),
'type' => 'form',
'run' => INSTALL_TASK_RUN_IF_REACHED,
'function' => 'disqus_admin_settings',
),
*/
);
return $tasks;
}
/**
* General configuration settings for B-Translator.
*
* @return
* An array containing form items to place on the module settings page.
*/
function btranslator_config() {
$form['config'] = array(
'#type' => 'fieldset',
'#title' => t('B-Translator configuration options'),
);
// get a list of available languages
$languages = l10n_feedback_get_languages();
foreach ($languages as $code => $lang) $lang_options[$code] = $lang['name'];
unset($lang_options['en']);
// l10n_feedback_translation_lng
$form['config']['l10n_feedback_translation_lng'] = array(
'#type' => 'select',
'#title' => t('Translation Language'),
'#description' => t('The language of translations. This site is about collecting feedback for the translations of this language.'),
'#options' => $lang_options,
'#default_value' => variable_get('l10n_feedback_translation_lng', 'fr'),
);
$voting_mode_options = array(
'single' => t('Single'),
'multiple' => t('Multiple'),
);
$voting_mode_description = t('
When voting mode is <em>Single</em>, only one translation
can be voted as suitable for each string. When voting mode is
<em>Multiple</em>, more than one translation can be selected
as suitable for each string. <br/>
<strong>Note:</strong> Switching back from <em>Multiple</em>
to <em>Single</em> may have a bad impact on the existing votes.
');
$form['config']['l10n_feedback_voting_mode'] = array(
'#type' => 'radios',
'#title' => t('Select Voting Mode'),
'#default_value' => variable_get('l10n_feedback_voting_mode', 'single'),
'#options' => $voting_mode_options,
'#description' => $voting_mode_description,
);
$form['defaults'] = array(
'#type' => 'fieldset',
'#title' => t('B-Translator default settings'),
);
// l10n_feedback_preferred_projects
$preferred_projects_description = t("
Select the projects that will be used for review and translations.
Only strings from these projects will be presented to the users. <br/>
You can enter projects in the form <em>origin/project</em>, for example:
<em>KDE/kdeedu</em>, <em>Mozilla/browser</em>, etc.
Or you can include all the projects from a certain origin,
like this: <em>KDE</em>, <em>LibreOffice</em>, etc. <br/>
Enter each project on a separate line.
See a list of the imported projects <a href='/translations/project/list/*/*/txt' target='_blank'>here</a>.<br/>
<strong>Note</strong>: The user can override the preferred projects on his profile/settings.
If the user does not select any preferred projects on his profile, then the projects listed here
will be used. If this list is empty, then all the imported projects will be used.
");
$form['defaults']['l10n_feedback_preferred_projects'] = array(
'#type' => 'textarea',
'#title' => t('The List of Projects that Will be Used for Voting and Translation'),
'#description' => $preferred_projects_description,
'#default_value' => variable_get('l10n_feedback_preferred_projects', ''),
);
return system_settings_form($form);
} // End of l10n_feedback_config().
/**
* SMTP configuration settings.
*
* @return
* An array containing form items to place on the module settings page.
*/
function smtp_config() {
// Override the smtp_library variable.
if (module_exists('mimemail') &&
strpos(variable_get('smtp_library', ''), 'mimemail')) {
// don't touch smtp_library
}
else {
if (variable_get('smtp_on', 0)) {
$smtp_path = drupal_get_filename('module', 'smtp');
if ($smtp_path) {
variable_set('smtp_library', $smtp_path);
drupal_set_message(t('SMTP.module is active.'));
}
// If drupal can't find the path to the module, display an error.
else {
drupal_set_message(t("SMTP.module error: Can't find file."), 'error');
}
}
// If this module is turned off, delete the variable.
else {
variable_del('smtp_library');
drupal_set_message(t('SMTP.module is INACTIVE.'));
}
}
$form['onoff'] = array(
'#type' => 'fieldset',
'#title' => t('Install options'),
);
$form['onoff']['smtp_on'] = array(
'#type' => 'radios',
'#title' => t('Turn this module on or off'),
'#default_value' => variable_get('smtp_on', 0),
'#options' => array(1 => t('On'), 0 => t('Off')),
'#description' => t('To uninstall this module you must turn it off here first.'),
);
$form['server'] = array(
'#type' => 'fieldset',
'#title' => t('SMTP server settings'),
);
$form['server']['smtp_host'] = array(
'#type' => 'textfield',
'#title' => t('SMTP server'),
'#default_value' => variable_get('smtp_host', ''),
'#description' => t('The address of your outgoing SMTP server.'),
);
$form['server']['smtp_hostbackup'] = array(
'#type' => 'textfield',
'#title' => t('SMTP backup server'),
'#default_value' => variable_get('smtp_hostbackup', ''),
'#description' => t('The address of your outgoing SMTP backup server. If the primary server can\'t be found this one will be tried. This is optional.'),
);
$form['server']['smtp_port'] = array(
'#type' => 'textfield',
'#title' => t('SMTP port'),
'#size' => 6,
'#maxlength' => 6,
'#default_value' => variable_get('smtp_port', '25'),
'#description' => t('The default SMTP port is 25, if that is being blocked try 80. Gmail uses 465. See !url for more information on configuring for use with Gmail.', array('!url' => l(t('this page'), 'http://gmail.google.com/support/bin/answer.py?answer=13287'))),
);
// Only display the option if openssl is installed.
if (function_exists('openssl_open')) {
$encryption_options = array(
'standard' => t('No'),
'ssl' => t('Use SSL'),
'tls' => t('Use TLS'),
);
$encryption_description = t('This allows connection to an SMTP server that requires SSL encryption such as Gmail.');
}
// If openssl is not installed, use normal protocol.
else {
variable_set('smtp_protocol', 'standard');
$encryption_options = array('standard' => t('No'));
$encryption_description = t('Your PHP installation does not have SSL enabled. See the !url page on php.net for more information. Gmail requires SSL.', array('!url' => l(t('OpenSSL Functions'), 'http://php.net/openssl')));
}
$form['server']['smtp_protocol'] = array(
'#type' => 'select',
'#title' => t('Use encrypted protocol'),
'#default_value' => variable_get('smtp_protocol', 'standard'),
'#options' => $encryption_options,
'#description' => $encryption_description,
);
$form['auth'] = array(
'#type' => 'fieldset',
'#title' => t('SMTP Authentication'),
'#description' => t('Leave blank if your SMTP server does not require authentication.'),
);
$form['auth']['smtp_username'] = array(
'#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => variable_get('smtp_username', ''),
'#description' => t('SMTP Username.'),
);
$form['auth']['smtp_password'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#default_value' => variable_get('smtp_password', ''),
'#description' => t('SMTP password. Leave blank if you don\'t wish to change it.'),
);
$form['email_options'] = array(
'#type' => 'fieldset',
'#title' => t('E-mail options'),
);
$form['email_options']['smtp_from'] = array(
'#type' => 'textfield',
'#title' => t('E-mail from address'),
'#default_value' => variable_get('smtp_from', ''),
'#description' => t('The e-mail address that all e-mails will be from.'),
);
$form['email_options']['smtp_fromname'] = array(
'#type' => 'textfield',
'#title' => t('E-mail from name'),
'#default_value' => variable_get('smtp_fromname', ''),
'#description' => t('The name that all e-mails will be from. If left blank will use the site name of:') . ' ' . variable_get('site_name', 'Drupal powered site'),
);
$form['email_options']['smtp_allowhtml'] = array(
'#type' => 'checkbox',
'#title' => t('Allow to send e-mails formated as Html'),
'#default_value' => variable_get('smtp_allowhtml', 0),
'#description' => t('Cheking this box will allow Html formated e-mails to be sent with the SMTP protocol.'),
);
// If an address was given, send a test e-mail message.
$test_address = variable_get('smtp_test_address', '');
if ($test_address != '') {
// Clear the variable so only one message is sent.
variable_del('smtp_test_address');
global $language;
$params['subject'] = t('Drupal SMTP test e-mail');
$params['body'] = array(t('If you receive this message it means your site is capable of using SMTP to send e-mail.'));
drupal_mail('smtp', 'smtp-test', $test_address, $language, $params);
drupal_set_message(t('A test e-mail has been sent to @email. You may want to !check for any error messages.', array('@email' => $test_address, '!check' => l(t('check the logs'), 'admin/reports/dblog'))));
}
$form['email_test'] = array(
'#type' => 'fieldset',
'#title' => t('Send test e-mail'),
);
$form['email_test']['smtp_test_address'] = array(
'#type' => 'textfield',
'#title' => t('E-mail address to send a test e-mail to'),
'#default_value' => '',
'#description' => t('Type in an address to have a test e-mail sent there.'),
);
$form['smtp_debugging'] = array(
'#type' => 'checkbox',
'#title' => t('Enable debugging'),
'#default_value' => variable_get('smtp_debugging', 0),
'#description' => t('Checking this box will print SMTP messages from the server for every e-mail that is sent.'),
);
return system_settings_form($form);
} // End of smtp_config().
/**
* Validataion for the administrative settings form.
*
* @param form
* An associative array containing the structure of the form.
* @param form_state
* A keyed array containing the current state of the form.
*/
function smtp_config_validate($form, &$form_state) {
if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_host'] == '') {
form_set_error('smtp_host', t('You must enter an SMTP server address.'));
}
if ($form_state['values']['smtp_on'] == 1 && $form_state['values']['smtp_port'] == '') {
form_set_error('smtp_port', t('You must enter an SMTP port number.'));
}
if ($form_state['values']['smtp_from'] && !valid_email_address($form_state['values']['smtp_from'])) {
form_set_error('smtp_from', t('The provided from e-mail address is not valid.'));
}
// A little hack. When form is presentend, the password is not shown (Drupal way of doing).
// So, if user submits the form without changing the password, we mus prevent it from being reset.
if (empty($form_state['values']['smtp_password'])) {
unset($form_state['values']['smtp_password']);
}
} // End of smtp_config_validate().