~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to sites/all/modules/captcha_pack/random_captcha_type/random_captcha_type.module

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: random_captcha_type.module,v 1.11 2008/04/07 22:55:02 soxofaan Exp $
 
3
 
 
4
/**
 
5
 * Implementation of a "meta CAPTCHA" which randomly picks a CAPTCHA type
 
6
 */
 
7
 
 
8
/**
 
9
 * Implementation of hook_help().
 
10
 */
 
11
function random_captcha_type_help($path, $arg) {
 
12
  switch ($path) {
 
13
    case 'admin/user/captcha/random_captcha_type':
 
14
      return '<p>'. t('This CAPTCHA type is a "meta" CAPTCHA type, which randomly picks one of the selected CAPTCHA types.') .'</p>';
 
15
  }
 
16
}
 
17
 
 
18
/**
 
19
 * Implementation of hook_menu().
 
20
 */
 
21
function random_captcha_type_menu() {
 
22
  $items = array();
 
23
  // add an administration tab for random_captcha_type
 
24
  $items['admin/user/captcha/random_captcha_type'] = array(
 
25
    'title' => 'Random CAPTCHA type',
 
26
    'file' => 'random_captcha_type.admin.inc',
 
27
    'page callback' => 'drupal_get_form',
 
28
    'page arguments' => array('random_captcha_type_settings_form'),
 
29
    'access arguments' => array('administer CAPTCHA settings'),
 
30
    'type' => MENU_LOCAL_TASK,
 
31
  );
 
32
  return $items;
 
33
}
 
34
 
 
35
/**
 
36
 * Implementation of hook_captcha
 
37
 */
 
38
function random_captcha_type_captcha($op, $captcha_type='') {
 
39
  switch ($op) {
 
40
    case 'list':
 
41
      require_once('random_captcha_type.inc');
 
42
      $enabled_types = _random_captcha_type_get_enabled_types();
 
43
      if (count($enabled_types) < 2) {
 
44
        return;
 
45
      }
 
46
      return array('Random CAPTCHA type');
 
47
    case 'generate':
 
48
      if ($captcha_type == 'Random CAPTCHA type') {
 
49
        require_once('random_captcha_type.inc');
 
50
        if (isset($_POST['random_captcha_type'])) {
 
51
          // If this is a POST request, we're possibly in a validation phase
 
52
          // so the CAPTCHA type should be the same as in the originating form
 
53
          $module_and_type = $_POST['random_captcha_type'];
 
54
        }
 
55
        else {
 
56
          // If not, just pick a random one
 
57
          $types = _random_captcha_type_get_enabled_types();
 
58
          $module_and_type = $types[array_rand($types)];
 
59
        }
 
60
        list($module, $type) = explode('/', $module_and_type);
 
61
        // Call the generate CAPTCHA hook
 
62
        $captcha = module_invoke($module, 'captcha', 'generate', $type);
 
63
        // Store the current CAPTCHA type so it can be recovered for
 
64
        // regenerating the form in the validation phase
 
65
        $captcha['form']['random_captcha_type'] = array(
 
66
          '#type' => 'hidden',
 
67
          '#value' => $module_and_type,
 
68
        );
 
69
        return $captcha;
 
70
      }
 
71
  }
 
72
}