Projet

Général

Profil

Révision ac1bc5de

Ajouté par Assos Assos il y a plus de 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/captcha/captcha.admin.inc
6 6
 */
7 7

  
8 8
/**
9
 * Return an array with the available CAPTCHA types, for use as options array
10
 * for a select form elements.
9
 * Return an array with the available CAPTCHA types, for use as options array for a select form elements.
11 10
 *
12
 * @param $add_special_options if true: also add a 'none' and 'default' option
11
 * @param bool $add_special_options
12
 *   if true: also add a 'none' and 'default' option
13 13
 *
14
 * @return an associative array mapping "$module/$type" to
14
 * @return array
15
 *   Mapping "$module/$type" to
15 16
 *   "$type (from module $module)" with $module the module name implementing the CAPTCHA
16 17
 *   and $type the name of the CAPTCHA type.
17 18
 */
18
function _captcha_available_challenge_types($add_special_options=TRUE) {
19
function _captcha_available_challenge_types($add_special_options = TRUE) {
19 20
  $captcha_types = array();
20 21
  if ($add_special_options) {
21 22
    $captcha_types['none'] = t('- No challenge -');
......
35 36
}
36 37

  
37 38
/**
38
 * Form builder function for the general CAPTCHA configuration
39
 * Form builder function for the general CAPTCHA configuration.
39 40
 */
40 41
function captcha_admin_settings() {
41 42
  module_load_include('inc', 'captcha');
......
88 89
    $form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['operations'] = array(
89 90
      '#markup' => implode(", ", array(
90 91
        l(t('delete'), "admin/config/people/captcha/captcha/captcha_point/{$captcha_point->form_id}/delete"),
91
      ))
92
      )),
92 93
    );
93 94
  }
94 95

  
......
197 198
    '#title' => t('Persistence'),
198 199
    '#default_value' => variable_get('captcha_persistence', CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE),
199 200
    '#options' => array(
200
      CAPTCHA_PERSISTENCE_SHOW_ALWAYS =>
201
        t('Always add a challenge.'),
202
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE =>
203
        t('Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge.'),
204
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE =>
205
        t('Omit challenges on a form type once the user successfully responds to a challenge on a form of that type.'),
206
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL =>
207
        t('Omit challenges on all forms once the user successfully responds to any challenge on the site.'),
201
      CAPTCHA_PERSISTENCE_SHOW_ALWAYS => t('Always add a challenge.'),
202
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_INSTANCE => t('Omit challenges in a multi-step/preview workflow once the user successfully responds to a challenge.'),
203
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE => t('Omit challenges on a form type once the user successfully responds to a challenge on a form of that type.'),
204
      CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL => t('Omit challenges on all forms once the user successfully responds to any challenge on the site.'),
208 205
    ),
209 206
    '#description' => t('Define if challenges should be omitted during the rest of a session once the user successfully responds to a challenge.'),
210 207
  );
......
236 233
}
237 234

  
238 235
/**
239
 * Custom theme function for a table of (form_id -> CAPTCHA type) settings
236
 * Custom theme function for a table of (form_id -> CAPTCHA type) settings.
240 237
 */
241 238
function theme_captcha_admin_settings_captcha_points($variables) {
242 239
  $form = $variables['form'];
......
282 279
  variable_set('captcha_default_challenge', $form_state['values']['captcha_default_challenge']);
283 280
  variable_set('captcha_default_challenge_on_nonlisted_forms', $form_state['values']['captcha_default_challenge_on_nonlisted_forms']);
284 281

  
285
  // Process CAPTCHA points
282
  // Process CAPTCHA points.
286 283
  if (isset($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'])) {
287 284
    foreach ($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'] as $captcha_point_form_id => $data) {
288 285
      captcha_set_form_id_setting($captcha_point_form_id, $data['captcha_type']);
......
332 329
  drupal_set_message(t('The CAPTCHA settings have been saved.'), 'status');
333 330
}
334 331

  
335

  
336

  
337

  
338 332
/**
339 333
 * Submit callback; clear CAPTCHA placement cache.
340 334
 */
......
343 337
  drupal_set_message(t('Cleared the CAPTCHA placement cache.'));
344 338
}
345 339

  
346

  
347 340
/**
348
 * Central handler for CAPTCHA point administration (adding, disabling, deleting)
341
 * Central handler for CAPTCHA point administration (adding, disabling, deleting).
349 342
 */
350
function captcha_point_admin($captcha_point_form_id=NULL, $op=NULL) {
343
function captcha_point_admin($captcha_point_form_id = NULL, $op = NULL) {
351 344
  module_load_include('inc', 'captcha');
352 345

  
353
  // if $captcha_point_form_id and action $op given: do the action
346
  // If $captcha_point_form_id and action $op given: do the action.
354 347
  if ($captcha_point_form_id) {
355 348
    switch ($op) {
356 349
      case 'disable':
357 350
        return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, FALSE);
351

  
358 352
      case 'delete':
359 353
        return drupal_get_form('captcha_point_disable_confirm', $captcha_point_form_id, TRUE);
360 354
    }
361
    // return edit form for CAPTCHA point
355
    // Return edit form for CAPTCHA point.
362 356
    return drupal_get_form('captcha_point_admin_form', $captcha_point_form_id);
363 357
  }
364
  // return add form for CAPTCHA point
358
  // Return add form for CAPTCHA point.
365 359
  return drupal_get_form('captcha_point_admin_form');
366 360
}
367 361

  
368
function captcha_point_admin_form($form, $form_state, $captcha_point_form_id=NULL) {
362
/**
363
 * Admin form.
364
 */
365
function captcha_point_admin_form($form, $form_state, $captcha_point_form_id = NULL) {
369 366
  $form = array();
370 367
  $default_captcha_type = 'none';
371 368
  if (isset($captcha_point_form_id)) {
372
    // use given CAPTCHA point form_id
369
    // Use given CAPTCHA point form_id.
373 370
    $form['captcha_point_form_id'] = array(
374 371
      '#type' => 'textfield',
375 372
      '#title' => t('Form ID'),
......
383 380
    }
384 381
  }
385 382
  else {
386
    // textfield for CAPTCHA point form_id
383
    // Textfield for CAPTCHA point form_id.
387 384
    $form['captcha_point_form_id'] = array(
388 385
      '#type' => 'textfield',
389 386
      '#title' => t('Form ID'),
390 387
      '#description' => t('The Drupal form_id of the form to add the CAPTCHA to.'),
391 388
    );
392 389
  }
393
  // select widget for CAPTCHA type
390
  // Select widget for CAPTCHA type.
394 391
  $form['captcha_type'] = array(
395 392
    '#type' => 'select',
396 393
    '#title' => t('Challenge type'),
......
398 395
    '#default_value' => $default_captcha_type,
399 396
    '#options' => _captcha_available_challenge_types(),
400 397
  );
401
  // redirect to general CAPTCHA settings page after submission
398
  // Redirect to general CAPTCHA settings page after submission.
402 399
  $form['#redirect'] = 'admin/config/people/captcha';
403
  // submit button
400
  // Submit button.
404 401
  $form['actions'] = array('#type' => 'actions');
405 402
  $form['actions']['submit'] = array(
406 403
    '#type' => 'submit',
......
409 406
  return $form;
410 407
}
411 408

  
412

  
413 409
/**
414
 * validation function for captcha_point_admin_form
410
 * Validation function for captcha_point_admin_form.
415 411
 */
416 412
function captcha_point_admin_form_validate($form, $form_state) {
417 413
  if (!preg_match('/^[a-z0-9_]+$/', $form_state['values']['captcha_point_form_id'])) {
......
419 415
  }
420 416
}
421 417

  
422

  
423 418
/**
424 419
 * Submit function for captcha_point_admin_form.
425 420
 */
......
431 426
}
432 427

  
433 428
/**
434
 * Confirm dialog for disabling/deleting a CAPTCHA point
429
 * Confirm dialog for disabling/deleting a CAPTCHA point.
435 430
 */
436 431
function captcha_point_disable_confirm($form, &$form_state, $captcha_point_form_id, $delete) {
437 432
  $form = array();
......
496 491
  $form = array();
497 492
  if ($module && $challenge) {
498 493
    // Generate 10 example challenges.
499
    for ($i=0; $i<10; $i++) {
494
    for ($i = 0; $i < 10; $i++) {
500 495
      $form["challenge_{$i}"] = _captcha_generate_example_challenge($module, $challenge);
501 496
    }
502 497
  }
503 498
  else {
504
    // generate a list with examples of the available CAPTCHA types
499
    // Generate a list with examples of the available CAPTCHA types.
505 500
    $form['info'] = array(
506 501
      '#markup' => t('This page gives an overview of all available challenge types, generated with their current settings.'),
507 502
    );
drupal7/sites/all/modules/captcha/captcha.inc
8 8
/**
9 9
 * Helper function for adding/updating a CAPTCHA point.
10 10
 *
11
 * @param $form_id the form ID to configure.
12
 * @param captcha_type the setting for the given form_id, can be:
11
 * @param string $form_id
12
 *   the form ID to configure.
13
 *
14
 * @param string $captcha_type
15
 *   the setting for the given form_id, can be:
13 16
 *   - 'none' to disable CAPTCHA,
14 17
 *   - 'default' to use the default challenge type
15 18
 *   - NULL to remove the entry for the CAPTCHA type
16 19
 *   - something of the form 'image_captcha/Image'
17 20
 *   - an object with attributes $captcha_type->module and $captcha_type->captcha_type
18
 * @return nothing
19 21
 */
20 22
function captcha_set_form_id_setting($form_id, $captcha_type) {
21 23
  // Handle 'none'.
......
52 54
      ->execute();
53 55
  }
54 56
  else {
55
    drupal_set_message(t('Failed to set a CAPTCHA type for form %form_id: could not interpret value "@captcha_type"',
56
      array('%form_id' => $form_id, '@captcha_type' => (string)$captcha_type)), 'warning');
57
    drupal_set_message(
58
      t('Failed to set a CAPTCHA type for form %form_id: could not interpret value "@captcha_type"',
59
      array(
60
        '%form_id' => $form_id,
61
        '@captcha_type' => (string) $captcha_type,
62
      )
63
      ),
64
      'warning'
65
    );
57 66
  }
58 67
}
59 68

  
60 69
/**
61 70
 * Get the CAPTCHA setting for a given form_id.
62 71
 *
63
 * @param $form_id the form_id to query for
64
 * @param $symbolic flag to return as (symbolic) strings instead of object.
72
 * @param string $form_id
73
 *   the form_id to query for
74
 *
75
 * @param bool $symbolic
76
 *   flag to return as (symbolic) strings instead of object.
65 77
 *
66
 * @return NULL if no setting is known
78
 * @return NULL
79
 *   if no setting is known
67 80
 *   or a captcha_point object with fields 'module' and 'captcha_type'.
68 81
 *   If argument $symbolic is true, returns (symbolic) as 'none', 'default'
69 82
 *   or in the form 'captcha/Math'.
70 83
 */
71
function captcha_get_form_id_setting($form_id, $symbolic=FALSE) {
84
function captcha_get_form_id_setting($form_id, $symbolic = FALSE) {
72 85
  // Fetch setting from database.
73
  $result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id",
74
    array(':form_id' =>  $form_id));
86
  $result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id", array(':form_id' => $form_id));
75 87
  $captcha_point = $result->fetchObject();
76 88

  
77 89
  // If no setting is available in database for the given form,
78
  // but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway
79
  if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE))
80
  {
90
  // but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway.
91
  if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE)) {
81 92
    $captcha_point = (object) array('captcha_type' => 'default');
82 93
  }
83 94

  
......
104 115
  return $captcha_point;
105 116
}
106 117

  
107

  
108 118
/**
109 119
 * Helper function for generating a new CAPTCHA session.
110 120
 *
111
 * @param $form_id the form_id of the form to add a CAPTCHA to.
112
 * @param $status the initial status of the CAPTHCA session.
113
 * @return the session ID of the new CAPTCHA session.
121
 * @param string $form_id
122
 *   the form_id of the form to add a CAPTCHA to.
123
 *
124
 * @param int $status
125
 *   the initial status of the CAPTHCA session.
126
 *
127
 * @return int
128
 *   the session ID of the new CAPTCHA session.
114 129
 */
115
function _captcha_generate_captcha_session($form_id=NULL, $status=CAPTCHA_STATUS_UNSOLVED) {
130
function _captcha_generate_captcha_session($form_id = NULL, $status = CAPTCHA_STATUS_UNSOLVED) {
116 131
  global $user;
117 132
  // Initialize solution with random data.
118 133
  $solution = md5(mt_rand());
......
135 150
/**
136 151
 * Helper function for updating the solution in the CAPTCHA session table.
137 152
 *
138
 * @param $captcha_sid the CAPTCHA session ID to update.
139
 * @param $solution the new solution to associate with the given CAPTCHA session.
153
 * @param int $captcha_sid
154
 *   the CAPTCHA session ID to update.
155
 *
156
 * @param string $solution
157
 *   the new solution to associate with the given CAPTCHA session.
140 158
 */
141 159
function _captcha_update_captcha_session($captcha_sid, $solution) {
142 160
  db_update('captcha_sessions')
......
149 167
}
150 168

  
151 169
/**
152
 * Helper function for checking if CAPTCHA is required for user,
153
 * based on the CAPTCHA persistence setting, the CAPTCHA session ID and
170
 * Helper function for checking if CAPTCHA is required for user.
171
 *
172
 * Based on the CAPTCHA persistence setting, the CAPTCHA session ID and
154 173
 * user session info.
155 174
 */
156 175
function _captcha_required_for_user($captcha_sid, $form_id) {
......
174 193
    return TRUE;
175 194
  }
176 195
  else {
177
    $captcha_success_form_ids = isset($_SESSION['captcha_success_form_ids']) ? (array)($_SESSION['captcha_success_form_ids']) : array();
196
    $captcha_success_form_ids = isset($_SESSION['captcha_success_form_ids']) ? (array) ($_SESSION['captcha_success_form_ids']) : array();
178 197
    switch ($captcha_persistence) {
179 198
      case CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL:
180 199
        return (count($captcha_success_form_ids) == 0);
200

  
181 201
      case CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM_TYPE:
182 202
        return !isset($captcha_success_form_ids[$form_id]);
183 203
    }
......
189 209

  
190 210

  
191 211
/**
192
 * Get the CAPTCHA description as configured on the general CAPTCHA
193
 * settings page.
212
 * Get the CAPTCHA description as configured on the general CAPTCHA settings page.
194 213
 *
195 214
 * If the locale module is enabled, the description will be returned
196 215
 * for the current language the page is rendered for. This language
197
 * can optionally been overriden with the $lang_code argument.
216
 * can optionally been overridden with the $lang_code argument.
198 217
 *
199
 * @param $lang_code an optional language code to get the descripion for.
200
 * @return a string with (localized) CAPTCHA description.
218
 * @param string|null $lang_code
219
 *   an optional language code to get the description for.
220
 *
221
 * @return string
222
 *   String with (localized) CAPTCHA description.
201 223
 */
202
function _captcha_get_description($lang_code=NULL) {
224
function _captcha_get_description($lang_code = NULL) {
203 225
  // If no language code is given: use the language of the current page.
204 226
  global $language;
205 227
  $lang_code = isset($lang_code) ? $lang_code : $language->language;
......
217 239

  
218 240
/**
219 241
 * Parse or interpret the given captcha_type.
220
 * @param $captcha_type string representation of the CAPTCHA type,
242
 *
243
 * @param string $captcha_type
244
 *   string representation of the CAPTCHA type,
221 245
 *      e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image'
222
 * @return list($captcha_module, $captcha_type)
246
 *
247
 * @return array
248
 *   list($captcha_module, $captcha_type)
223 249
 */
224 250
function _captcha_parse_captcha_type($captcha_type) {
225 251
  if ($captcha_type == 'none') {
......
233 259

  
234 260
/**
235 261
 * Helper function to get placement information for a given form_id.
236
 * @param $form_id the form_id to get the placement information for.
237
 * @param $form if a form corresponding to the given form_id, if there
262
 *
263
 * @param string $form_id
264
 *   the form_id to get the placement information for.
265
 *
266
 * @param array $form
267
 *   if a form corresponding to the given form_id, if there
238 268
 *   is no placement info for the given form_id, this form is examined to
239 269
 *   guess the placement.
240
 * @return placement info array (@see _captcha_insert_captcha_element() for more
270
 *
271
 * @return array
272
 *   placement info array (@see _captcha_insert_captcha_element() for more
241 273
 *   info about the fields 'path', 'key' and 'weight'.
242 274
 */
243 275
function _captcha_get_captcha_placement($form_id, $form) {
......
298 330
/**
299 331
 * Helper function for searching the buttons in a form.
300 332
 *
301
 * @param $form the form to search button elements in
302
 * @return an array of paths to the buttons.
333
 * @param array $form
334
 *   the form to search button elements in
335
 *
336
 * @return array
337
 *   an array of paths to the buttons.
303 338
 *   A path is an array of keys leading to the button, the last
304 339
 *   item in the path is the weight of the button element
305 340
 *   (or NULL if undefined).
......
328 363

  
329 364
/**
330 365
 * Helper function to insert a CAPTCHA element in a form before a given form element.
331
 * @param $form the form to add the CAPTCHA element to.
332
 * @param $placement information where the CAPTCHA element should be inserted.
366
 *
367
 * @param array $form
368
 *   the form to add the CAPTCHA element to.
369
 *
370
 * @param array $placement
371
 *   information where the CAPTCHA element should be inserted.
333 372
 *   $placement should be an associative array with fields:
334 373
 *     - 'path': path (array of path items) of the container in the form where the
335 374
 *       CAPTCHA element should be inserted.
......
339 378
 *     - 'weight': if 'key' is not NULL: should be the weight of the element defined by 'key'.
340 379
 *       If 'key' is NULL and weight is not NULL: set the weight property of the CAPTCHA element
341 380
 *       to this value.
342
 * @param $captcha_element the CAPTCHA element to insert.
381
 *
382
 * @param array $captcha_element
383
 *   the CAPTCHA element to insert.
343 384
 */
344 385
function _captcha_insert_captcha_element(&$form, $placement, $captcha_element) {
345 386
  // Get path, target and target weight or use defaults if not available.
......
367 408
    if ($target_weight != NULL) {
368 409
      $captcha_element['#weight'] = $target_weight;
369 410
    }
370
    $form_stepper['captcha'] =  $captcha_element;
411
    $form_stepper['captcha'] = $captcha_element;
371 412
  }
372 413
  // If there is a target available: make sure the CAPTCHA element comes right before it.
373 414
  else {
......
375 416
    // and just append the CAPTCHA: sorting will fix the ordering anyway.
376 417
    if ($target_weight != NULL) {
377 418
      $captcha_element['#weight'] = $target_weight - .1;
378
      $form_stepper['captcha'] =  $captcha_element;
419
      $form_stepper['captcha'] = $captcha_element;
379 420
    }
380 421
    else {
381 422
      // If we can't play with weights: insert the CAPTCHA element at the right position.
......
384 425
      // chop of the end, append the CAPTCHA element and put the end back.
385 426
      $offset = array_search($target_key, array_keys($form_stepper));
386 427
      $end = array_splice($form_stepper, $offset);
387
      $form_stepper['captcha'] =  $captcha_element;
428
      $form_stepper['captcha'] = $captcha_element;
388 429
      foreach ($end as $k => $v) {
389 430
        $form_stepper[$k] = $v;
390 431
      }
391 432
    }
392 433
  }
393 434
}
394

  
drupal7/sites/all/modules/captcha/captcha.info
10 10
files[] = captcha.install
11 11
files[] = captcha.test
12 12

  
13
; Information added by Drupal.org packaging script on 2014-07-06
14
version = "7.x-1.1"
13
; Information added by Drupal.org packaging script on 2014-11-29
14
version = "7.x-1.2"
15 15
core = "7.x"
16 16
project = "captcha"
17
datestamp = "1404666828"
17
datestamp = "1417219372"
18 18

  
drupal7/sites/all/modules/captcha/captcha.install
97 97
        'type' => 'int',
98 98
        'not null' => TRUE,
99 99
        'default' => 0,
100
      )
100
      ),
101 101
    ),
102 102
    'primary key' => array('csid'),
103 103
    'indexes' => array(
......
109 109
}
110 110

  
111 111
/**
112
 * Implementation of hook_requirements().
112
 * Implements of hook_requirements().
113 113
 */
114 114
function captcha_requirements($phase) {
115 115
  $requirements = array();
......
130 130
}
131 131

  
132 132
/**
133
 * Implementation of hook_install().
133
 * Implements of hook_install().
134 134
 */
135 135
function captcha_install() {
136 136
  $t = get_t();
......
138 138
  $form_ids = array(
139 139
    'contact_site_form', 'contact_personal_form',
140 140
    'user_register_form', 'user_pass', 'user_login', 'user_login_block',
141
    'forum_node_form'
141
    'forum_node_form',
142 142
  );
143 143
  // Add form_ids of all currently known node types too.
144 144
  foreach (node_type_get_names() as $type => $name) {
......
167 167
}
168 168

  
169 169
/**
170
 * Implementation of hook_uninstall().
170
 * Implements of hook_uninstall().
171 171
 */
172 172
function captcha_uninstall() {
173 173
  drupal_uninstall_schema('captcha');
......
176 176
}
177 177

  
178 178
/**
179
 * Implementation of hook_update_N()
179
 * Implements of hook_update_N().
180 180
 */
181 181
function captcha_update_6200() {
182 182
  $items = array();
......
239 239
        'type' => 'int',
240 240
        'not null' => TRUE,
241 241
        'default' => 0,
242
      )
242
      ),
243 243
    ),
244 244
    'primary key' => array('csid'),
245 245
    'indexes' => array(
......
253 253
}
254 254

  
255 255
/**
256
 * Implementation of hook_update_N()
256
 * Implements of hook_update_N().
257
 *
257 258
 * Change the captcha points with the old text CAPTCHA, which was
258 259
 * removed from the 6.x-2.x branch, to the simple math CAPTCHA.
259 260
 */
......
264 265
}
265 266

  
266 267
/**
267
 * Implementation of hook_update_N()
268
 * Implements of hook_update_N().
269
 *
268 270
 * Add a CAPTCHA token column to captcha_sessions table.
269 271
 */
270 272
function captcha_update_6202() {
......
274 276
}
275 277

  
276 278
/**
277
 * Implementation of hook_update_N()
279
 * Implements of hook_update_N().
280
 *
278 281
 * Rename the type field to captcha_type in captcha_points.
279 282
 */
280 283
function captcha_update_6203() {
drupal7/sites/all/modules/captcha/captcha.js
14 14

  
15 15
  Drupal.behaviors.captchaAdmin = {
16 16
    attach: function (context) {
17
    	// Add onclick handler to checkbox for adding a CAPTCHA description
18
    	// so that the textfields for the CAPTCHA description are hidden
19
    	// when no description should be added.
17
      // Add onclick handler to checkbox for adding a CAPTCHA description
18
      // so that the textfields for the CAPTCHA description are hidden
19
      // when no description should be added.
20 20
      // @todo: div.form-item-captcha-description depends on theming, maybe
21 21
      // it's better to add our own wrapper with id (instead of a class).
22
    	$("#edit-captcha-add-captcha-description").click(function() {
23
    		if ($("#edit-captcha-add-captcha-description").is(":checked")) {
24
    			// Show the CAPTCHA description textfield(s).
25
    			$("div.form-item-captcha-description").show('slow');
26
    		}
27
    		else {
28
    			// Hide the CAPTCHA description textfield(s).
29
    			$("div.form-item-captcha-description").hide('slow');
30
    		}
31
    	});
32
    	// Hide the CAPTCHA description textfields if option is disabled on page load.
33
    	if (!$("#edit-captcha-add-captcha-description").is(":checked")) {
34
    		$("div.form-item-captcha-description").hide();
35
    	}
22
      $("#edit-captcha-add-captcha-description").click(function() {
23
        if ($("#edit-captcha-add-captcha-description").is(":checked")) {
24
          // Show the CAPTCHA description textfield(s).
25
          $("div.form-item-captcha-description").show('slow');
26
        }
27
        else {
28
          // Hide the CAPTCHA description textfield(s).
29
          $("div.form-item-captcha-description").hide('slow');
30
        }
31
      });
32
      // Hide the CAPTCHA description textfields if option is disabled on page load.
33
      if (!$("#edit-captcha-add-captcha-description").is(":checked")) {
34
        $("div.form-item-captcha-description").hide();
35
      }
36 36
    }
37 37

  
38 38
  };
drupal7/sites/all/modules/captcha/captcha.module
46 46
      ) . '</p>';
47 47
      $output .= '<p>' . t('CAPTCHA is a trademark of Carnegie Mellon University.') . '</p>';
48 48
      return $output;
49

  
49 50
    case 'admin/config/people/captcha':
50 51
    case 'admin/config/people/captcha/captcha':
51 52
    case 'admin/config/people/captcha/captcha/settings':
......
56 57
}
57 58

  
58 59
/**
59
 * Implementation of hook_menu().
60
 * Implements of hook_menu().
60 61
 */
61 62
function captcha_menu() {
62 63
  $items = array();
63
  // main configuration page of the basic CAPTCHA module
64
  // Main configuration page of the basic CAPTCHA module.
64 65
  $items['admin/config/people/captcha'] = array(
65 66
    'title' => 'CAPTCHA',
66 67
    'description' => 'Administer how and where CAPTCHAs are used.',
......
70 71
    'access arguments' => array('administer CAPTCHA settings'),
71 72
    'type' => MENU_NORMAL_ITEM,
72 73
  );
73
  // the default local task (needed when other modules want to offer
74
  // alternative CAPTCHA types and their own configuration page as local task)
74
  // The default local task (needed when other modules want to offer,
75
  // alternative CAPTCHA types and their own configuration page as local task).
75 76
  $items['admin/config/people/captcha/captcha'] = array(
76 77
    'title' => 'CAPTCHA',
77 78
    'access arguments' => array('administer CAPTCHA settings'),
......
106 107
}
107 108

  
108 109
/**
109
 * Implementation of hook_permission().
110
 * Implements of hook_permission().
110 111
 */
111 112
function captcha_permission() {
112 113
  return array(
......
121 122
}
122 123

  
123 124
/**
124
 * Implementation of hook_theme().
125
 * Implements of hook_theme().
125 126
 */
126 127
function captcha_theme() {
127 128
  return array(
......
135 136
}
136 137

  
137 138
/**
138
 * Implementation of hook_cron().
139
 * Implements of hook_cron().
139 140
 *
140 141
 * Remove old entries from captcha_sessions table.
141 142
 */
142 143
function captcha_cron() {
143 144
  // Remove challenges older than 1 day.
144 145
  db_delete('captcha_sessions')
145
    ->condition('timestamp', REQUEST_TIME - 60*60*24, '<')
146
    ->condition('timestamp', REQUEST_TIME - 60 * 60 * 24, '<')
146 147
    ->execute();
147 148
}
148 149

  
149

  
150 150
/**
151
 * Implementation of hook_element_info().
151
 * Implements of hook_element_info().
152 152
 */
153 153
function captcha_element_info() {
154 154
  // Define the CAPTCHA form element with default properties.
155 155
  $captcha_element = array(
156 156
    '#input' => TRUE,
157 157
    '#process' => array('captcha_element_process'),
158
    // The type of challenge: e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image', ...
158
    // The type of challenge: e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image'.
159 159
    '#captcha_type' => 'default',
160 160
    '#default_value' => '',
161 161
    // CAPTCHA in admin mode: presolve the CAPTCHA and always show it (despite previous successful responses).
......
254 254
    'captcha_sid' => $captcha_sid,
255 255
  );
256 256

  
257

  
258 257
  if (_captcha_required_for_user($captcha_sid, $this_form_id) || $element['#captcha_admin_mode']) {
259 258
    // Generate a CAPTCHA and its solution
260 259
    // (note that the CAPTCHA session ID is given as third argument).
......
263 262
      // The selected module did not return what we expected: log about it and quit.
264 263
      watchdog('CAPTCHA',
265 264
        'CAPTCHA problem: unexpected result from hook_captcha() of module %module when trying to retrieve challenge type %type for form %form_id.',
266
        array('%type' => $captcha_type_challenge, '%module' => $captcha_type_module, '%form_id' => $this_form_id),
265
        array(
266
          '%type' => $captcha_type_challenge,
267
          '%module' => $captcha_type_module,
268
          '%form_id' => $this_form_id,
269
        ),
267 270
        WATCHDOG_ERROR);
268 271
      return $element;
269 272
    }
......
300 303
  return $element;
301 304
}
302 305

  
303

  
304 306
/**
305 307
 * Theme function for a CAPTCHA element.
306 308
 *
......
324 326
  }
325 327
}
326 328

  
327

  
328 329
/**
329
 * Implementation of hook_form_alter().
330
 * Implements of hook_form_alter().
330 331
 *
331 332
 * This function adds a CAPTCHA to forms for untrusted users if needed and adds
332 333
 * CAPTCHA administration links for site administrators if this option is enabled.
......
339 340

  
340 341
    // Get CAPTCHA type and module for given form_id.
341 342
    $captcha_point = captcha_get_form_id_setting($form_id);
342
    if ($captcha_point && $captcha_point->captcha_type) {
343
    if ($captcha_point && !empty($captcha_point->captcha_type)) {
343 344
      module_load_include('inc', 'captcha');
344 345
      // Build CAPTCHA form element.
345 346
      $captcha_element = array(
......
365 366
    module_load_include('inc', 'captcha');
366 367

  
367 368
    $captcha_point = captcha_get_form_id_setting($form_id);
368
    // For administrators: show CAPTCHA info and offer link to configure it
369
    // For administrators: show CAPTCHA info and offer link to configure it.
369 370
    $captcha_element = array(
370 371
      '#type' => 'fieldset',
371 372
      '#title' => t('CAPTCHA'),
......
424 425

  
425 426
  // Add a warning about caching on the Perfomance settings page.
426 427
  if ($form_id == 'system_performance_settings') {
427
    $icon = theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('warning'), 'title' => t('warning')));
428
    $icon = theme(
429
      'image',
430
      array(
431
        'path' => 'misc/watchdog-warning.png',
432
        'width' => 18,
433
        'height' => 18,
434
        'alt' => t('warning'),
435
        'title' => t('warning'),
436
      )
437
    );
428 438
    $form['caching']['captcha'] = array(
429 439
      '#type' => 'item',
430 440
      '#title' => t('CAPTCHA'),
......
439 449

  
440 450
/**
441 451
 * CAPTCHA validation function to tests strict equality.
442
 * @param $solution the solution of the test.
443
 * @param $response the response to the test.
444
 * @return TRUE when strictly equal, FALSE otherwise.
452
 *
453
 * @param string $solution
454
 *   the solution of the test.
455
 *
456
 * @param string $response
457
 *   the response to the test.
458
 *
459
 * @return bool
460
 *   TRUE when equal (ignoring spaces), FALSE otherwise.
445 461
 */
446 462
function captcha_validate_strict_equality($solution, $response) {
447 463
  return $solution === $response;
......
449 465

  
450 466
/**
451 467
 * CAPTCHA validation function to tests case insensitive equality.
452
 * @param $solution the solution of the test.
453
 * @param $response the response to the test.
454
 * @return TRUE when case insensitive equal, FALSE otherwise.
468
 *
469
 * @param string $solution
470
 *   the solution of the test.
471
 *
472
 * @param string $response
473
 *   the response to the test.
474
 *
475
 * @return bool
476
 *   TRUE when equal (ignoring spaces), FALSE otherwise.
455 477
 */
456 478
function captcha_validate_case_insensitive_equality($solution, $response) {
457 479
  return drupal_strtolower($solution) === drupal_strtolower($response);
......
459 481

  
460 482
/**
461 483
 * CAPTCHA validation function to tests equality while ignoring spaces.
462
 * @param $solution the solution of the test.
463
 * @param $response the response to the test.
464
 * @return TRUE when equal (ignoring spaces), FALSE otherwise.
484
 *
485
 * @param string $solution
486
 *   the solution of the test.
487
 *
488
 * @param string $response
489
 *   the response to the test.
490
 *
491
 * @return bool
492
 *   TRUE when equal (ignoring spaces), FALSE otherwise.
465 493
 */
466 494
function captcha_validate_ignore_spaces($solution, $response) {
467 495
  return preg_replace('/\s/', '', $solution) === preg_replace('/\s/', '', $response);
......
469 497

  
470 498
/**
471 499
 * CAPTCHA validation function to tests case insensitive equality while ignoring spaces.
472
 * @param $solution the solution of the test.
473
 * @param $response the response to the test.
474
 * @return TRUE when equal (ignoring spaces), FALSE otherwise.
500
 *
501
 * @param string $solution
502
 *   the solution of the test.
503
 *
504
 * @param string $response
505
 *   the response to the test.
506
 *
507
 * @return bool
508
 *   TRUE when equal (ignoring spaces), FALSE otherwise.
475 509
 */
476 510
function captcha_validate_case_insensitive_ignore_spaces($solution, $response) {
477 511
  return preg_replace('/\s/', '', drupal_strtolower($solution)) === preg_replace('/\s/', '', drupal_strtolower($response));
478 512
}
479 513

  
480 514
/**
481
 * Helper function for getting the posted CAPTCHA info (posted form_id and
482
 * CAPTCHA sessions ID) from a form in case it is posted.
515
 * Helper function for getting the posted CAPTCHA info (posted form_id and CAPTCHA sessions ID) from a form in case it is posted.
483 516
 *
484 517
 * This function hides the form processing mess for several use cases an
485 518
 * browser bug workarounds.
......
494 527
 *
495 528
 * @todo for Drupal 7 version: is this IE7 workaround still needed?
496 529
 *
497
 * @param $element the CAPTCHA element.
498
 * @param $form_state the form state structure to extract the info from.
499
 * @param $this_form_id the form ID of the form we are currently processing
530
 * @param array $element
531
 *   the CAPTCHA element.
532
 *
533
 * @param array $form_state
534
 *   the form state structure to extract the info from.
535
 *
536
 * @param string $this_form_id
537
 *   the form ID of the form we are currently processing
500 538
 *     (which is not necessarily the form that was posted).
501 539
 *
502
 * @return an array with $posted_form_id and $post_captcha_sid (with NULL values
540
 * @return array
541
 *   an array with $posted_form_id and $post_captcha_sid (with NULL values
503 542
 *     if the values could not be found, e.g. for a fresh form).
504 543
 */
505 544
function _captcha_get_posted_captcha_info($element, $form_state, $this_form_id) {
......
515 554
    // from the post data.
516 555
    // Because we possibly use raw post data here,
517 556
    // we should be extra cautious and filter this data.
518
    $posted_form_id = isset($form_state['input']['form_id']) ?
519
      preg_replace("/[^a-z0-9_]/", "", (string) $form_state['input']['form_id'])
520
      : NULL;
521
    $posted_captcha_sid = isset($form_state['input']['captcha_sid']) ?
522
      (int) $form_state['input']['captcha_sid']
523
      : NULL;
524
    $posted_captcha_token = isset($form_state['input']['captcha_token']) ?
525
      preg_replace("/[^a-zA-Z0-9]/", "", (string) $form_state['input']['captcha_token'])
526
      : NULL;
557
    $posted_form_id = isset($form_state['input']['form_id']) ? preg_replace("/[^a-z0-9_]/", "", (string) $form_state['input']['form_id']) : NULL;
558
    $posted_captcha_sid = isset($form_state['input']['captcha_sid']) ? (int) $form_state['input']['captcha_sid'] : NULL;
559
    $posted_captcha_token = isset($form_state['input']['captcha_token']) ? preg_replace("/[^a-zA-Z0-9]/", "", (string) $form_state['input']['captcha_token']) : NULL;
527 560

  
528 561
    if ($posted_form_id == $this_form_id) {
529 562
      // Check if the posted CAPTCHA token is valid for the posted CAPTCHA
......
599 632
    // Get CAPTCHA validate function or fall back on strict equality.
600 633
    $captcha_validate = $element['#captcha_validate'];
601 634
    if (!function_exists($captcha_validate)) {
602
       $captcha_validate = 'captcha_validate_strict_equality';
635
      $captcha_validate = 'captcha_validate_strict_equality';
603 636
    }
604 637
    // Check the response with the CAPTCHA validation function.
605 638
    // Apart from the traditional expected $solution and received $response,
......
626 659
        ->condition('csid', $csid)
627 660
        ->expression('attempts', 'attempts + 1')
628 661
        ->execute();
629
      // set form error
662
      // Set form error.
630 663
      form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
631
      // update wrong response counter
664
      // Update wrong response counter.
632 665
      if (variable_get('captcha_enable_stats', FALSE)) {
633 666
        variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1);
634 667
      }
635
      // log to watchdog if needed
668
      // Log to watchdog if needed.
636 669
      if (variable_get('captcha_log_wrong_responses', FALSE)) {
637 670
        watchdog('CAPTCHA',
638 671
          '%form_id post blocked by CAPTCHA module: challenge %challenge (by module %module), user answered "@response", but the solution was "@solution".',
639
          array('%form_id' => $form_id,
672
          array(
673
            '%form_id' => $form_id,
640 674
            '@response' => $captcha_response, '@solution' => $solution,
641 675
            '%challenge' => $captcha_info['captcha_type'], '%module' => $captcha_info['module'],
642 676
          ),
......
652 686
 * This encompasses tasks that should happen after the general FAPI processing
653 687
 * (building, submission and validation) but before rendering (e.g. storing the solution).
654 688
 *
655
 * @param $element the CAPTCHA form element
656
 * @return the manipulated element
689
 * @param array $element
690
 *   the CAPTCHA form element
691
 *
692
 * @return array
693
 *   the manipulated element
657 694
 */
658 695
function captcha_pre_render_process($element) {
659 696
  module_load_include('inc', 'captcha');
......
661 698
  // Get form and CAPTCHA information.
662 699
  $captcha_info = $element['#captcha_info'];
663 700
  $form_id = $captcha_info['form_id'];
664
  $captcha_sid = (int)($captcha_info['captcha_sid']);
701
  $captcha_sid = (int) ($captcha_info['captcha_sid']);
665 702
  // Check if CAPTCHA is still required.
666 703
  // This check is done in a first phase during the element processing
667 704
  // (@see captcha_process), but it is also done here for better support
......
695 732
  switch ($op) {
696 733
    case 'list':
697 734
      return array('Math');
698
      break;
699 735

  
700 736
    case 'generate':
701 737
      if ($captcha_type == 'Math') {
......
741 777
}
742 778

  
743 779
/**
744
 * Implements hook_modules_enabled.
780
 * Implements hook_modules_enabled().
745 781
 */
746 782
function captcha_modules_enabled() {
747 783
  // When new modules are enabled: clear the CAPTCHA placement cache, so that
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.
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.info
10 10
files[] = image_captcha.admin.inc
11 11
files[] = image_captcha.user.inc
12 12

  
13
; Information added by Drupal.org packaging script on 2014-07-06
14
version = "7.x-1.1"
13
; Information added by Drupal.org packaging script on 2014-11-29
14
version = "7.x-1.2"
15 15
core = "7.x"
16 16
project = "captcha"
17
datestamp = "1404666828"
17
datestamp = "1417219372"
18 18

  
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.install
18 18
    if (_image_captcha_check_setup(FALSE) & IMAGE_CAPTCHA_ERROR_NO_GDLIB) {
19 19
      $requirements['image_captcha_requires_gd'] = array(
20 20
        'title' => $t('Image CAPTCHA requires GD library'),
21
        'description' =>
22
          $t('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
23
            array('!gddoc' => 'http://www.php.net/manual/en/book.image.php',)
24
          ),
21
        'description' => $t(
22
          'The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
23
          array('!gddoc' => 'http://www.php.net/manual/en/book.image.php')
24
        ),
25 25
        'severity' => REQUIREMENT_ERROR,
26 26
      );
27 27
    }
......
30 30
}
31 31

  
32 32
/**
33
 * On uninstall: remove module variables and clear variable cache
33
 * On uninstall: remove module variables and clear variable cache.
34 34
 */
35 35
function image_captcha_uninstall() {
36 36
  db_delete('variable')
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.js
6 6
      // Helper function to show/hide noise level widget.
7 7
      var noise_level_shower = function(speed) {
8 8
        speed = (typeof speed == 'undefined') ? 'slow' : speed;
9
        if ($("#edit-image-captcha-dot-noise").is(":checked")
10
            || $("#edit-image-captcha-line-noise").is(":checked")) {
9
        if ($("#edit-image-captcha-dot-noise").is(":checked") || $("#edit-image-captcha-line-noise").is(":checked")) {
11 10
          $(".form-item-image-captcha-noise-level").show(speed);
12 11
        } else {
13 12
          $(".form-item-image-captcha-noise-level").hide(speed);
14 13
        }
15
      }
14
      };
16 15
      // Add onclick handler to the dot and line noise check boxes.
17 16
      $("#edit-image-captcha-dot-noise").click(noise_level_shower);
18 17
      $("#edit-image-captcha-line-noise").click(noise_level_shower);
......
27 26
        } else {
28 27
          $(".form-item-image-captcha-bilinear-interpolation").hide(speed);
29 28
        }
30
      }
29
      };
31 30
      // Add onchange handler to the distortion level select widget.
32 31
      $("#edit-image-captcha-distortion-amplitude").change(
33 32
          smooth_distortion_shower);
34 33
      // Show or hide appropriately on page load.
35
      smooth_distortion_shower(0)
34
      smooth_distortion_shower(0);
36 35

  
37 36
    }
38 37
  };
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.module
16 16
define('IMAGE_CAPTCHA_FILE_FORMAT_PNG', 2);
17 17
define('IMAGE_CAPTCHA_FILE_FORMAT_TRANSPARENT_PNG', 3);
18 18

  
19

  
20 19
/**
21 20
 * Implements hook_help().
22 21
 */
......
33 32
 */
34 33
function image_captcha_menu() {
35 34
  $items = array();
36
  // add an administration tab for image_captcha
35
  // Add an administration tab for image_captcha.
37 36
  $items['admin/config/people/captcha/image_captcha'] = array(
38 37
    'title' => 'Image CAPTCHA',
39 38
    'file' => 'image_captcha.admin.inc',
......
50 49
    'access arguments' => array('administer CAPTCHA settings'),
51 50
    'type' => MENU_CALLBACK,
52 51
  );
53
  // callback for generating an image
52
  // Callback for generating an image.
54 53
  $items['image_captcha'] = array(
55 54
    'file' => 'image_captcha.user.inc',
56 55
    'page callback' => 'image_captcha_image',
......
63 62
/**
64 63
 * Helper function for getting the fonts to use in the image CAPTCHA.
65 64
 *
66
 * @return a list of font paths.
65
 * @return array
66
 *   a list of font paths.
67 67
 */
68 68
function _image_captcha_get_enabled_fonts() {
69 69
  if (IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT & _image_captcha_check_setup(FALSE)) {
......
81 81
/**
82 82
 * Helper function for checking if the specified fonts are available.
83 83
 *
84
 * @param $fonts paths of fonts to check.
85
 * @return list($readable_fonts, $problem_fonts)
84
 * @param array $fonts
85
 *   paths of fonts to check.
86
 *
87
 * @return array
88
 *   list($readable_fonts, $problem_fonts)
86 89
 */
87 90
function _image_captcha_check_fonts($fonts) {
88 91
  $readable_fonts = array();
......
100 103

  
101 104
/**
102 105
 * Helper function for splitting an utf8 string correctly in characters.
106
 *
103 107
 * Assumes the given utf8 string is well formed.
104 108
 * See http://en.wikipedia.org/wiki/Utf8 for more info
105 109
 */
106 110
function _image_captcha_utf8_split($str) {
107 111
  $characters = array();
108 112
  $len = strlen($str);
109
  for ($i=0; $i < $len; ) {
113
  for ($i = 0; $i < $len;) {
110 114
    $chr = ord($str[$i]);
111
    if (($chr & 0x80) == 0x00) { // one byte character (0zzzzzzz)
115
    // One byte character (0zzzzzzz)
116
    if (($chr & 0x80) == 0x00) {
112 117
      $width = 1;
113 118
    }
114 119
    else {
115
      if (($chr & 0xE0) == 0xC0) { // two byte character (first byte: 110yyyyy)
120
      // Two byte character (first byte: 110yyyyy)
121
      if (($chr & 0xE0) == 0xC0) {
116 122
        $width = 2;
117 123
      }
118
      elseif (($chr & 0xF0) == 0xE0) { // three byte character (first byte: 1110xxxx)
124
      // Three byte character (first byte: 1110xxxx)
125
      elseif (($chr & 0xF0) == 0xE0) {
119 126
        $width = 3;
120 127
      }
121
      elseif (($chr & 0xF8) == 0xF0) { // four byte character (first byte: 11110www)
128
      // Four byte character (first byte: 11110www)
129
      elseif (($chr & 0xF8) == 0xF0) {
122 130
        $width = 4;
123 131
      }
124 132
      else {
......
140 148
 * font files should be readable.
141 149
 * This functions checks these things.
142 150
 *
143
 * @param $check_fonts whether or not the enabled fonts should be checked.
151
 * @param bool $check_fonts
152
 *   whether or not the enabled fonts should be checked.
144 153
 *
145
 * @return status code: bitwise 'OR' of status flags like
154
 * @return int
155
 *   status code: bitwise 'OR' of status flags like
146 156
 *   IMAGE_CAPTCHA_ERROR_NO_GDLIB, IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT,
147 157
 *   IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM.
148 158
 */
149
function _image_captcha_check_setup($check_fonts=TRUE) {
159
function _image_captcha_check_setup($check_fonts = TRUE) {
150 160
  // Start clean.
151 161
  $status = 0;
152 162
  // Check if we can use the GD library.
......
170 180
}
171 181

  
172 182
/**
173
 * Helper function for calculating image height and width
174
 * based on given code and current font/spacing settings.
183
 * Helper function for calculating image height and width based on given code and current font/spacing settings.
175 184
 *
176
 * @return array($width, $heigh)
185
 * @return array
186
 *   array($width, $heigh)
177 187
 */
178 188
function _image_captcha_image_size($code) {
179
  // Get settings
189
  // Get settings.
180 190
  $font_size = (int) variable_get('image_captcha_font_size', 30);
181 191
  $character_spacing = (float) variable_get('image_captcha_character_spacing', '1.2');
182 192
  $characters = _image_captcha_utf8_split($code);
183 193
  $character_quantity = count($characters);
184 194

  
185
  // Calculate height and width
195
  // Calculate height and width.
186 196
  $width = $character_spacing * $font_size * $character_quantity;
187 197
  $height = 2 * $font_size;
188 198

  
189 199
  return array($width, $height);
190 200
}
191 201

  
192

  
193 202
/**
194 203
 * Implements hook_captcha().
195 204
 */
196
function image_captcha_captcha($op, $captcha_type='', $captcha_sid=NULL) {
205
function image_captcha_captcha($op, $captcha_type = '', $captcha_sid = NULL) {
197 206
  switch ($op) {
198 207
    case 'list':
199 208
      // Only offer the image CAPTCHA if it is possible to generate an image on this setup.
......
214 223
        if (variable_get('maintenance_mode', 0) && $user->uid == 0) {
215 224
          return captcha_captcha('generate', 'Math');
216 225
        }
217
        // generate a CAPTCHA code
226
        // Generate a CAPTCHA code.
218 227
        $allowed_chars = _image_captcha_utf8_split(variable_get('image_captcha_image_allowed_chars', IMAGE_CAPTCHA_ALLOWED_CHARACTERS));
219
        $code_length = (int)variable_get('image_captcha_code_length', 5);
228
        $code_length = (int) variable_get('image_captcha_code_length', 5);
220 229
        $code = '';
221 230
        for ($i = 0; $i < $code_length; $i++) {
222 231
          $code .= $allowed_chars[array_rand($allowed_chars)];
223 232
        }
224 233

  
225
        // build the result to return
234
        // Build the result to return.
226 235
        $result = array();
227 236

  
228 237
        $result['solution'] = $code;
......
241 250
        $result['form']['captcha_image'] = array(
242 251
          '#type' => 'markup',
243 252
          '#markup' => '<img src="' . $img_src
244
            . '" width="'. $width . '" height="' . $height
245
            . '" alt="' . t('Image CAPTCHA') . '" title="' . t('Image CAPTCHA') . '" />',
253
          . '" width="' . $width . '" height="' . $height
254
          . '" alt="' . t('Image CAPTCHA') . '" title="' . t('Image CAPTCHA') . '" />',
246 255
          '#weight' => -2,
247 256
        );
248 257
        $result['form']['captcha_response'] = array(
......
259 268
          case CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE:
260 269
            $result['captcha_validate'] = 'captcha_validate_ignore_spaces';
261 270
            break;
271

  
262 272
          case CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE:
263 273
            $result['captcha_validate'] = 'captcha_validate_case_insensitive_ignore_spaces';
264 274
            break;
drupal7/sites/all/modules/captcha/image_captcha/image_captcha.user.inc
12 12
 * Menu callback function that generates the CAPTCHA image.
13 13
 */
14 14
function image_captcha_image() {
15
  // If output buffering is on: discard current content and disable further buffering
15
  // If output buffering is on: discard current content and disable further buffering.
16 16
  if (ob_get_level()) {
17 17
    ob_end_clean();
18 18
  }
19 19

  
20
  if (!isset($_GET['sid'])) {
20
  if (!isset($_GET['sid']) || is_array($_GET['sid'])) {
21 21
    exit();
22 22
  }
23 23
  $captcha_sid = $_GET['sid'];
......
34 34
    $seed = hexdec(substr(md5($captcha_sid . $code), 0, 8));
35 35
    srand($seed);
36 36
    mt_srand($seed);
37
    // generate the image
37
    // Generate the image.
38 38
    $image = @_image_captcha_generate_image($code);
39
    // check of generation was successful
39
    // Check of generation was successful.
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff