Projet

Général

Profil

Paste
Télécharger (3,91 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / honeypot / honeypot.install @ a45e4bc1

1 11987c58 Florent Torregrosa
<?php
2
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the Honeypot module.
6
 */
7
8
/**
9
 * Implements of hook_schema().
10
 */
11
function honeypot_schema() {
12
  $schema['honeypot_user'] = array(
13
    'description' => 'Table that stores failed attempts to submit a form.',
14
    'fields' => array(
15
      'uid' => array(
16
        'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
17
        'type' => 'int',
18
        'unsigned' => TRUE,
19
        'not null' => TRUE,
20
      ),
21
      'timestamp' => array(
22
        'description' => 'Date/time when the form submission failed, as Unix timestamp.',
23
        'type' => 'int',
24
        'unsigned' => TRUE,
25
        'not null' => TRUE,
26
      ),
27
    ),
28
    'indexes' => array(
29
      'uid' => array('uid'),
30
      'timestamp' => array('timestamp'),
31
    ),
32
  );
33
  return $schema;
34
}
35
36
/**
37
 * Implements hook_install().
38
 */
39
function honeypot_install() {
40 2c8c2b87 Assos Assos
  // Create CSS file.
41
  honeypot_create_css(variable_get('honeypot_element_name', 'url'));
42
43
  if (!drupal_is_cli()) {
44
    $t = get_t();
45
    drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
46
      '!link' => l($t('configure Honeypot'), 'admin/config/content/honeypot'),
47
    )));
48
  }
49 11987c58 Florent Torregrosa
}
50
51
/**
52
 * Implements hook_uninstall().
53
 */
54
function honeypot_uninstall() {
55
  db_delete('variable')
56
    ->condition('name', db_like('honeypot_') . '%', 'LIKE')
57
    ->execute();
58
  $cache_tables = array('variables', 'cache_bootstrap');
59
  foreach ($cache_tables as $table) {
60
    if (db_table_exists($table)) {
61
      cache_clear_all($table, 'cache');
62
    }
63
  }
64 2c8c2b87 Assos Assos
65
  // Delete 'honeypot' directory from public file directory.
66
  file_unmanaged_delete_recursive('public://honeypot');
67 11987c58 Florent Torregrosa
}
68
69
/**
70
 * Implements hook_update_N().
71
 */
72
function honeypot_update_7001() {
73
  $ret = array();
74
75
  // Leaving this in because I had it in version 1.3. Silly me.
76
  return $ret;
77
}
78
79
/**
80
 * Update form names after upgrade from 6.x version.
81
 */
82
function honeypot_update_7002() {
83
  $map = array(
84
    'user_register' => 'user_register_form',
85
    'contact_mail_page' => 'contact_site_form',
86
    'contact_mail_user' => 'contact_personal_form',
87
  );
88
  foreach ($map as $d6_name => $d7_name) {
89
    $value = variable_get('honeypot_form_' . $d6_name, 0);
90
    if ($value) {
91
      variable_set('honeypot_form_' . $d7_name, $value);
92
    }
93
    variable_del('honeypot_form_' . $d6_name);
94
  }
95
96
  $comment_form_value = variable_get('honeypot_form_comment_form', 0);
97
  if ($comment_form_value) {
98
    $types = node_type_get_types();
99
    if (!empty($types)) {
100
      foreach ($types as $type) {
101
        $d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
102
        variable_set($d7_name, $comment_form_value);
103
      }
104
    }
105
  }
106
  variable_del('honeypot_form_comment_form');
107
}
108
109
/**
110
 * Add {honeypot_users} database table if it doesn't exist.
111
 */
112
function honeypot_update_7003() {
113
  // Make sure the {honeypot_users} table doesn't already exist.
114
  if (!db_table_exists('honeypot_user')) {
115
    $table = array(
116
      'description' => 'Table that stores failed attempts to submit a form.',
117
      'fields' => array(
118
        'uid' => array(
119
          'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
120
          'type' => 'int',
121
          'unsigned' => TRUE,
122
          'not null' => TRUE,
123
        ),
124
        'timestamp' => array(
125
          'description' => 'Date/time when the form submission failed, as Unix timestamp.',
126
          'type' => 'int',
127
          'unsigned' => TRUE,
128
          'not null' => TRUE,
129
        ),
130
      ),
131
      'indexes' => array(
132
        'uid' => array('uid'),
133
        'timestamp' => array('timestamp'),
134
      ),
135
    );
136
137
    db_create_table('honeypot_user', $table);
138
  }
139
}
140 2c8c2b87 Assos Assos
141
/**
142
 * Create Honeypot CSS file.
143
 */
144
function honeypot_update_7004() {
145
  module_load_include('inc', 'honeypot', 'honeypot.admin');
146
  honeypot_create_css(variable_get('honeypot_element_name', 'url'));
147
}