Révision ac1bc5de
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.admin.inc | ||
---|---|---|
3 | 3 |
/** |
4 | 4 |
* @file |
5 | 5 |
* Functions for administration/settings interface. |
6 |
* |
|
7 | 6 |
*/ |
8 | 7 |
|
9 |
|
|
10 | 8 |
/** |
11 | 9 |
* Configuration form for image_captcha. |
12 | 10 |
*/ |
... | ... | |
19 | 17 |
// Use javascript for some added usability on admin form. |
20 | 18 |
$form['#attached']['js'] = array(drupal_get_path('module', 'image_captcha') . '/image_captcha.js'); |
21 | 19 |
|
22 |
|
|
23 | 20 |
// First some error checking. |
24 | 21 |
$setup_status = _image_captcha_check_setup(FALSE); |
25 | 22 |
if ($setup_status & IMAGE_CAPTCHA_ERROR_NO_GDLIB) { |
... | ... | |
70 | 67 |
); |
71 | 68 |
} |
72 | 69 |
|
73 |
|
|
74 | 70 |
// Font related stuff. |
75 | 71 |
$form['image_captcha_font_settings'] = _image_captcha_settings_form_font_section(); |
76 | 72 |
|
77 |
// Color and file format settings.
|
|
73 |
// Color and file format settings. |
|
78 | 74 |
$form['image_captcha_color_settings'] = array( |
79 | 75 |
'#type' => 'fieldset', |
80 | 76 |
'#title' => t('Color and image settings'), |
... | ... | |
121 | 117 |
), |
122 | 118 |
); |
123 | 119 |
|
124 |
// distortion and noise settings
|
|
120 |
// Distortion and noise settings.
|
|
125 | 121 |
$form['image_captcha_distortion_and_noise'] = array( |
126 | 122 |
'#type' => 'fieldset', |
127 | 123 |
'#title' => t('Distortion and noise'), |
128 | 124 |
'#description' => t('With these settings you can control the degree of obfuscation by distortion and added noise. Do not exaggerate the obfuscation and assure that the code in the image is reasonably readable. For example, do not combine high levels of distortion and noise.'), |
129 | 125 |
); |
130 |
// distortion
|
|
126 |
// Distortion.
|
|
131 | 127 |
$form['image_captcha_distortion_and_noise']['image_captcha_distortion_amplitude'] = array( |
132 | 128 |
'#type' => 'select', |
133 | 129 |
'#title' => t('Distortion level'), |
... | ... | |
153 | 149 |
'#default_value' => variable_get('image_captcha_bilinear_interpolation', FALSE), |
154 | 150 |
'#description' => t('This option enables bilinear interpolation of the distortion which makes the image look smoother, but it is more CPU intensive.'), |
155 | 151 |
); |
156 |
// noise
|
|
152 |
// Noise.
|
|
157 | 153 |
$form['image_captcha_distortion_and_noise']['image_captcha_dot_noise'] = array( |
158 | 154 |
'#type' => 'checkbox', |
159 | 155 |
'#title' => t('Add salt and pepper noise'), |
... | ... | |
192 | 188 |
return $form; |
193 | 189 |
} |
194 | 190 |
|
195 |
|
|
196 | 191 |
/** |
197 | 192 |
* Form elements for the font specific setting. |
198 | 193 |
* |
... | ... | |
200 | 195 |
* general form function image_captcha_settings_form with some |
201 | 196 |
* specific logic. |
202 | 197 |
* |
203 |
* @return $form, the font settings specific form elements. |
|
198 |
* @return array |
|
199 |
* the font settings specific form elements. |
|
204 | 200 |
*/ |
205 | 201 |
function _image_captcha_settings_form_font_section() { |
206 | 202 |
// Put it all in a fieldset. |
... | ... | |
212 | 208 |
// First check if there is TrueType support. |
213 | 209 |
$setup_status = _image_captcha_check_setup(FALSE); |
214 | 210 |
if ($setup_status & IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT) { |
215 |
// Show a warning that there is no TrueType support |
|
211 |
// Show a warning that there is no TrueType support.
|
|
216 | 212 |
$form['no_ttf_support'] = array( |
217 | 213 |
'#type' => 'item', |
218 | 214 |
'#title' => t('No TrueType support'), |
... | ... | |
221 | 217 |
|
222 | 218 |
} |
223 | 219 |
else { |
224 |
|
|
225 | 220 |
// Build a list of all available fonts. |
226 | 221 |
$available_fonts = array(); |
227 | 222 |
|
... | ... | |
231 | 226 |
// in separate requests, and we don't want to rescan the filesystem |
232 | 227 |
// every time, so we cache the result. |
233 | 228 |
variable_set('image_captcha_fonts_preview_map_cache', $fonts); |
234 |
// Put these fonts with preview image in the list |
|
229 |
// Put these fonts with preview image in the list.
|
|
235 | 230 |
foreach ($fonts as $token => $font) { |
236 | 231 |
$img_src = check_url(url('admin/config/people/captcha/image_captcha/font_preview/' . $token)); |
237 | 232 |
$title = t('Font preview of @font (@file)', array('@font' => $font->name, '@file' => $font->uri)); |
... | ... | |
261 | 256 |
'#process' => array('form_process_checkboxes'), |
262 | 257 |
); |
263 | 258 |
|
264 |
|
|
265 | 259 |
// Font size. |
266 | 260 |
$form['image_captcha_font_size'] = array( |
267 | 261 |
'#type' => 'select', |
... | ... | |
302 | 296 |
/** |
303 | 297 |
* Helper function to get fonts from the given directories. |
304 | 298 |
* |
305 |
* @param $directories (optional) an array of directories |
|
299 |
* @param array|null $directories |
|
300 |
* an array of directories |
|
306 | 301 |
* to recursively search through, if not given, the default |
307 | 302 |
* directories will be used. |
308 | 303 |
* |
309 |
* @return an array of fonts file objects (with fields 'name', |
|
304 |
* @return array |
|
305 |
* an array of fonts file objects (with fields 'name', |
|
310 | 306 |
* 'basename' and 'filename'), keyed on the md5 hash of the font |
311 | 307 |
* path (to have an easy token that can be used in an url |
312 | 308 |
* without en/decoding issues). |
313 | 309 |
*/ |
314 |
function _image_captcha_get_available_fonts_from_directories($directories=NULL) {
|
|
310 |
function _image_captcha_get_available_fonts_from_directories($directories = NULL) {
|
|
315 | 311 |
// If no fonts directories are given: use the default. |
316 | 312 |
if ($directories === NULL) { |
317 | 313 |
$directories = array( |
... | ... | |
331 | 327 |
return $fonts; |
332 | 328 |
} |
333 | 329 |
|
334 |
|
|
335 | 330 |
/** |
336 |
* Validation function for image_captcha configuration form |
|
331 |
* Validation function for image_captcha configuration form.
|
|
337 | 332 |
*/ |
338 | 333 |
function image_captcha_settings_form_validate($form, &$form_state) { |
339 | 334 |
// Check image_captcha_image_allowed_chars for spaces. |
... | ... | |
360 | 355 |
} |
361 | 356 |
} |
362 | 357 |
|
363 |
// check color settings
|
|
358 |
// Check color settings.
|
|
364 | 359 |
if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_state['values']['image_captcha_background_color'])) { |
365 | 360 |
form_set_error('image_captcha_background_color', t('Background color is not a valid hexadecimal color value.')); |
366 | 361 |
} |
... | ... | |
382 | 377 |
|
383 | 378 |
/** |
384 | 379 |
* Menu handler for font preview request. |
385 |
* |
|
386 | 380 |
*/ |
387 | 381 |
function image_captcha_font_preview($font_token) { |
388 | 382 |
|
... | ... | |
394 | 388 |
// Get the mapping of font tokens to font file objects. |
395 | 389 |
$fonts = variable_get('image_captcha_fonts_preview_map_cache', array()); |
396 | 390 |
if (!isset($fonts[$font_token])) { |
397 |
echo('bad token'); |
|
391 |
echo ('bad token');
|
|
398 | 392 |
exit(); |
399 | 393 |
} |
400 | 394 |
// Get the font path. |
401 | 395 |
$font = $fonts[$font_token]->uri; |
402 | 396 |
// Some sanity checks if the given font is valid. |
403 | 397 |
if (!is_file($font) || !is_readable($font)) { |
404 |
echo('bad font'); |
|
398 |
echo ('bad font');
|
|
405 | 399 |
exit(); |
406 | 400 |
} |
407 | 401 |
} |
... | ... | |
422 | 416 |
$color = imagecolorallocate($image, 0, 0, 0); |
423 | 417 |
imagefilledrectangle($image, 0, 0, $width, $height, $background_color); |
424 | 418 |
|
425 |
// Draw preview text |
|
419 |
// Draw preview text.
|
|
426 | 420 |
if ($font == 'BUILTIN') { |
427 |
imagestring($image, 5, 1, .5*$height-10, $text, $color);
|
|
421 |
imagestring($image, 5, 1, .5 * $height - 10, $text, $color);
|
|
428 | 422 |
} |
429 | 423 |
else { |
430 |
imagettftext($image, $font_size, 0, 1, 1.5*$font_size, $color, realpath($font), $text);
|
|
424 |
imagettftext($image, $font_size, 0, 1, 1.5 * $font_size, $color, realpath($font), $text);
|
|
431 | 425 |
} |
432 | 426 |
|
433 | 427 |
// Set content type. |
Formats disponibles : Unified diff
Weekly update of contrib modules