View source
<?php
function captcha_schema() {
$schema['captcha_points'] = array(
'fields' => array(
'form_id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'module' => array(
'type' => 'varchar',
'length' => 64,
),
'type' => array(
'type' => 'varchar',
'length' => 64,
),
),
'primary key' => array(
'form_id',
),
);
return $schema;
}
function captcha_install() {
drupal_install_schema('captcha');
$form_ids = array(
'comment_form',
'contact_mail_user',
'contact_mail_page',
'user_register',
'user_pass',
'user_login',
'user_login_block',
);
foreach ($form_ids as $form_id) {
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
}
drupal_set_message(t('You can now <a href="!captcha_admin">configure the CAPTCHA module</a> for your site.', array(
'!captcha_admin' => url('admin/user/captcha'),
)), 'status');
}
function captcha_uninstall() {
drupal_uninstall_schema('captcha');
db_query("DELETE FROM {variable} WHERE name LIKE 'captcha_%'");
cache_clear_all('variables', 'cache');
}
function captcha_update_1() {
$items = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$items[] = update_sql("CREATE TABLE {captcha_points} (\n form_id varchar(128) NOT NULL,\n module varchar(64) default NULL,\n type varchar(64) default NULL,\n PRIMARY KEY (form_id)\n ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
$succes = TRUE;
break;
case 'pgsql':
$items[] = update_sql("CREATE TABLE {captcha_points} (\n form_id varchar(128) NOT NULL,\n module varchar(64) default NULL,\n type varchar(64) default NULL,\n PRIMARY KEY (form_id)\n );");
$succes = TRUE;
break;
default:
drupal_set_message(t('Unsupported database.'), 'error');
$succes = FALSE;
break;
}
if ($succes) {
$form_ids = array(
'comment_form',
'contact_mail_user',
'contact_mail_page',
'user_register',
'user_pass',
);
foreach ($form_ids as $form_id) {
$items[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('{$form_id}', NULL, NULL)");
}
}
return $items;
}
function captcha_update_2() {
$items = array();
$form_ids = array(
'user_login',
'user_login_block',
);
foreach ($form_ids as $form_id) {
$items[] = update_sql("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('{$form_id}', NULL, NULL)");
}
return $items;
}