| 1 |
<?php
|
| 2 |
// $Id: captcha.install,v 1.9 2009/03/22 20:06:39 soxofaan Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_schema().
|
| 6 |
*/
|
| 7 |
function captcha_schema() {
|
| 8 |
// Table for positions and types of the challenges.
|
| 9 |
$schema['captcha_points'] = array(
|
| 10 |
'description' => 'This table describes which challenges should be added to which forms.',
|
| 11 |
'fields' => array(
|
| 12 |
'form_id' => array(
|
| 13 |
'description' => 'The form_id of the form to add a CAPTCHA to.',
|
| 14 |
'type' => 'varchar',
|
| 15 |
'length' => 128,
|
| 16 |
'not null' => TRUE,
|
| 17 |
),
|
| 18 |
'module' => array(
|
| 19 |
'description' => 'The module that provides the challenge.',
|
| 20 |
'type' => 'varchar',
|
| 21 |
'length' => 64,
|
| 22 |
),
|
| 23 |
'type' => array(
|
| 24 |
'description' => 'The challenge type to use.',
|
| 25 |
'type' => 'varchar',
|
| 26 |
'length' => 64,
|
| 27 |
),
|
| 28 |
),
|
| 29 |
'primary key' => array('form_id'),
|
| 30 |
);
|
| 31 |
// Table for the CAPTCHA sessions.
|
| 32 |
$schema['captcha_sessions'] = array(
|
| 33 |
'description' => 'Stores the data about CAPTCHA sessions (solution, IP address, timestamp, ...).',
|
| 34 |
'fields' => array(
|
| 35 |
'csid' => array(
|
| 36 |
'description' => 'CAPTCHA session ID.',
|
| 37 |
'type' => 'serial',
|
| 38 |
'not null' => TRUE,
|
| 39 |
),
|
| 40 |
'uid' => array(
|
| 41 |
'description' => "User's {users}.uid.",
|
| 42 |
'type' => 'int',
|
| 43 |
'not null' => TRUE,
|
| 44 |
'default' => 0,
|
| 45 |
),
|
| 46 |
'sid' => array(
|
| 47 |
'description' => "Session ID of the user.",
|
| 48 |
'type' => 'varchar',
|
| 49 |
'length' => 64,
|
| 50 |
'not null' => TRUE,
|
| 51 |
'default' => '',
|
| 52 |
),
|
| 53 |
'ip_address' => array(
|
| 54 |
'description' => 'IP address of the visitor.',
|
| 55 |
'type' => 'varchar',
|
| 56 |
'length' => 128,
|
| 57 |
'not null' => FALSE,
|
| 58 |
),
|
| 59 |
'timestamp' => array(
|
| 60 |
'description' => 'A Unix timestamp indicating when the challenge was generated.',
|
| 61 |
'type' => 'int',
|
| 62 |
'not null' => TRUE,
|
| 63 |
'default' => 0,
|
| 64 |
),
|
| 65 |
'form_id' => array(
|
| 66 |
'description' => 'The form_id of the form where the CAPTCHA is added to.',
|
| 67 |
'type' => 'varchar',
|
| 68 |
'length' => 128,
|
| 69 |
'not null' => TRUE,
|
| 70 |
),
|
| 71 |
'solution' => array(
|
| 72 |
'description' => 'Solution of the challenge.',
|
| 73 |
'type' => 'varchar',
|
| 74 |
'length' => 128,
|
| 75 |
'not null' => TRUE,
|
| 76 |
'default' => '',
|
| 77 |
),
|
| 78 |
'status' => array(
|
| 79 |
'description' => 'Status of the CAPTCHA session (unsolved, solved, ...)',
|
| 80 |
'type' => 'int',
|
| 81 |
'not null' => TRUE,
|
| 82 |
'default' => 0,
|
| 83 |
),
|
| 84 |
'attempts' => array(
|
| 85 |
'description' => 'The number of attempts.',
|
| 86 |
'type' => 'int',
|
| 87 |
'not null' => TRUE,
|
| 88 |
'default' => 0,
|
| 89 |
)
|
| 90 |
),
|
| 91 |
'primary key' => array('csid'),
|
| 92 |
'indexes' => array(
|
| 93 |
'csid_ip' => array('csid', 'ip_address'),
|
| 94 |
),
|
| 95 |
);
|
| 96 |
|
| 97 |
return $schema;
|
| 98 |
}
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Implementation of hook_install().
|
| 102 |
*/
|
| 103 |
function captcha_install() {
|
| 104 |
$t = get_t();
|
| 105 |
drupal_install_schema('captcha');
|
| 106 |
|
| 107 |
// insert some defaults
|
| 108 |
$form_ids = array('comment_form', 'contact_mail_user', 'contact_mail_page',
|
| 109 |
'user_register', 'user_pass', 'user_login', 'user_login_block', 'forum_node_form');
|
| 110 |
foreach ($form_ids as $form_id) {
|
| 111 |
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
|
| 112 |
}
|
| 113 |
|
| 114 |
// what to do after install?
|
| 115 |
drupal_set_message($t('You can now <a href="!captcha_admin">configure the CAPTCHA module</a> for your site.',
|
| 116 |
array('!captcha_admin' => url('admin/user/captcha'))), 'status');
|
| 117 |
}
|
| 118 |
|
| 119 |
/**
|
| 120 |
* Implementation of hook_uninstall().
|
| 121 |
*/
|
| 122 |
function captcha_uninstall() {
|
| 123 |
drupal_uninstall_schema('captcha');
|
| 124 |
db_query("DELETE FROM {variable} WHERE name LIKE 'captcha_%'");
|
| 125 |
cache_clear_all('variables', 'cache');
|
| 126 |
}
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Implementation of hook_update_N()
|
| 130 |
*/
|
| 131 |
function captcha_update_1() {
|
| 132 |
$items = array();
|
| 133 |
switch ($GLOBALS['db_type']) {
|
| 134 |
case 'mysql':
|
| 135 |
case 'mysqli':
|
| 136 |
$items[] = update_sql("CREATE TABLE {captcha_points} (
|
| 137 |
form_id varchar(128) NOT NULL,
|
| 138 |
module varchar(64) default NULL,
|
| 139 |
type varchar(64) default NULL,
|
| 140 |
PRIMARY KEY (form_id)
|
| 141 |
) /*!40100 DEFAULT CHARACTER SET utf8 */;"
|
| 142 |
);
|
| 143 |
$succes = TRUE;
|
| 144 |
break;
|
| 145 |
case 'pgsql':
|
| 146 |
$items[] = update_sql("CREATE TABLE {captcha_points} (
|
| 147 |
form_id varchar(128) NOT NULL,
|
| 148 |
module varchar(64) default NULL,
|
| 149 |
type varchar(64) default NULL,
|
| 150 |
PRIMARY KEY (form_id)
|
| 151 |
);"
|
| 152 |
);
|
| 153 |
$succes = TRUE;
|
| 154 |
break;
|
| 155 |
default:
|
| 156 |
drupal_set_message(t('Unsupported database.'), 'error');
|
| 157 |
$succes = FALSE;
|
| 158 |
break;
|
| 159 |
}
|
| 160 |
if ($succes) {
|
| 161 |
// insert some defaults
|
| 162 |
$form_ids = array('comment_form', 'contact_mail_user', 'contact_mail_page',
|
| 163 |
'user_register', 'user_pass');
|
| 164 |
foreach ($form_ids as $form_id) {
|
| 165 |
$items[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('$form_id', NULL, NULL)");
|
| 166 |
}
|
| 167 |
}
|
| 168 |
return $items;
|
| 169 |
}
|
| 170 |
|
| 171 |
/**
|
| 172 |
* Implementation of hook_update_N()
|
| 173 |
*/
|
| 174 |
function captcha_update_2() {
|
| 175 |
$items = array();
|
| 176 |
// insert some defaults
|
| 177 |
$form_ids = array('user_login', 'user_login_block');
|
| 178 |
foreach ($form_ids as $form_id) {
|
| 179 |
$items[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('$form_id', NULL, NULL)");
|
| 180 |
}
|
| 181 |
return $items;
|
| 182 |
}
|
| 183 |
|
| 184 |
/**
|
| 185 |
* Implementation of hook_update_N()
|
| 186 |
*/
|
| 187 |
function captcha_update_6200() {
|
| 188 |
$items = array();
|
| 189 |
|
| 190 |
// Table for the CAPTCHA sessions.
|
| 191 |
$schema['captcha_sessions'] = array(
|
| 192 |
'description' => 'Stores the data about CAPTCHA sessions (solution, IP address, timestamp, ...).',
|
| 193 |
'fields' => array(
|
| 194 |
'csid' => array(
|
| 195 |
'description' => 'CAPTCHA session ID.',
|
| 196 |
'type' => 'serial',
|
| 197 |
'not null' => TRUE,
|
| 198 |
),
|
| 199 |
'uid' => array(
|
| 200 |
'description' => "User's {users}.uid.",
|
| 201 |
'type' => 'int',
|
| 202 |
'not null' => TRUE,
|
| 203 |
'default' => 0,
|
| 204 |
),
|
| 205 |
'sid' => array(
|
| 206 |
'description' => "Session ID of the user.",
|
| 207 |
'type' => 'varchar',
|
| 208 |
'length' => 64,
|
| 209 |
'not null' => TRUE,
|
| 210 |
'default' => '',
|
| 211 |
),
|
| 212 |
'ip_address' => array(
|
| 213 |
'description' => 'IP address of the visitor.',
|
| 214 |
'type' => 'varchar',
|
| 215 |
'length' => 128,
|
| 216 |
'not null' => FALSE,
|
| 217 |
),
|
| 218 |
'timestamp' => array(
|
| 219 |
'description' => 'A Unix timestamp indicating when the challenge was generated.',
|
| 220 |
'type' => 'int',
|
| 221 |
'not null' => TRUE,
|
| 222 |
'default' => 0,
|
| 223 |
),
|
| 224 |
'form_id' => array(
|
| 225 |
'description' => 'The form_id of the form where the CAPTCHA is added to.',
|
| 226 |
'type' => 'varchar',
|
| 227 |
'length' => 128,
|
| 228 |
'not null' => TRUE,
|
| 229 |
),
|
| 230 |
'solution' => array(
|
| 231 |
'description' => 'Solution of the challenge.',
|
| 232 |
'type' => 'varchar',
|
| 233 |
'length' => 128,
|
| 234 |
'not null' => TRUE,
|
| 235 |
'default' => '',
|
| 236 |
),
|
| 237 |
'status' => array(
|
| 238 |
'description' => 'Status of the CAPTCHA session (unsolved, solved, ...)',
|
| 239 |
'type' => 'int',
|
| 240 |
'not null' => TRUE,
|
| 241 |
'default' => 0,
|
| 242 |
),
|
| 243 |
'attempts' => array(
|
| 244 |
'description' => 'The number of attempts.',
|
| 245 |
'type' => 'int',
|
| 246 |
'not null' => TRUE,
|
| 247 |
'default' => 0,
|
| 248 |
)
|
| 249 |
),
|
| 250 |
'primary key' => array('csid'),
|
| 251 |
'indexes' => array(
|
| 252 |
'csid_ip' => array('csid', 'ip_address'),
|
| 253 |
),
|
| 254 |
);
|
| 255 |
|
| 256 |
db_create_table($items, 'captcha_sessions', $schema['captcha_sessions']);
|
| 257 |
|
| 258 |
return $items;
|
| 259 |
}
|