123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * @file
- *
- * Install, update and uninstall functions for the Honeypot module.
- */
- /**
- * Implements of hook_schema().
- */
- function honeypot_schema() {
- $schema['honeypot_user'] = array(
- 'description' => 'Table that stores failed attempts to submit a form.',
- 'fields' => array(
- 'uid' => array(
- 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'uid' => array('uid'),
- 'timestamp' => array('timestamp'),
- ),
- );
- return $schema;
- }
- /**
- * Implements hook_install().
- */
- function honeypot_install() {
- drupal_set_message(st("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
- '!link' => l(st('configure Honeypot'), 'admin/config/content/honeypot')
- )));
- }
- /**
- * Implements hook_uninstall().
- */
- function honeypot_uninstall() {
- db_delete('variable')
- ->condition('name', db_like('honeypot_') . '%', 'LIKE')
- ->execute();
- $cache_tables = array('variables', 'cache_bootstrap');
- foreach ($cache_tables as $table) {
- if (db_table_exists($table)) {
- cache_clear_all($table, 'cache');
- }
- }
- }
- /**
- * Implements hook_update_N().
- */
- function honeypot_update_7001() {
- $ret = array();
- // Leaving this in because I had it in version 1.3. Silly me.
- return $ret;
- }
- /**
- * Update form names after upgrade from 6.x version.
- */
- function honeypot_update_7002() {
- $map = array(
- 'user_register' => 'user_register_form',
- 'contact_mail_page' => 'contact_site_form',
- 'contact_mail_user' => 'contact_personal_form',
- );
- foreach ($map as $d6_name => $d7_name) {
- $value = variable_get('honeypot_form_' . $d6_name, 0);
- if ($value) {
- variable_set('honeypot_form_' . $d7_name, $value);
- }
- variable_del('honeypot_form_' . $d6_name);
- }
- $comment_form_value = variable_get('honeypot_form_comment_form', 0);
- if ($comment_form_value) {
- $types = node_type_get_types();
- if (!empty($types)) {
- foreach ($types as $type) {
- $d7_name = 'honeypot_form_comment_node_' . $type->type . '_form';
- variable_set($d7_name, $comment_form_value);
- }
- }
- }
- variable_del('honeypot_form_comment_form');
- }
- /**
- * Add {honeypot_users} database table if it doesn't exist.
- */
- function honeypot_update_7003() {
- // Make sure the {honeypot_users} table doesn't already exist.
- if (!db_table_exists('honeypot_user')) {
- $table = array(
- 'description' => 'Table that stores failed attempts to submit a form.',
- 'fields' => array(
- 'uid' => array(
- 'description' => 'Foreign key to {users}.uid; uniquely identifies a Drupal user to whom this ACL data applies.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => 'Date/time when the form submission failed, as Unix timestamp.',
- 'type' => 'int',
- 'unsigned' => TRUE,
- 'not null' => TRUE,
- ),
- ),
- 'indexes' => array(
- 'uid' => array('uid'),
- 'timestamp' => array('timestamp'),
- ),
- );
- db_create_table('honeypot_user', $table);
- }
- }
|