123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?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() {
- // Create CSS file.
- honeypot_create_css(variable_get('honeypot_element_name', 'url'));
- if (!drupal_is_cli()) {
- $t = get_t();
- drupal_set_message($t("Honeypot installed successfully. Please !link to protect your forms from spam bots.", array(
- '!link' => l($t('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');
- }
- }
- // Delete 'honeypot' directory from public file directory.
- file_unmanaged_delete_recursive('public://honeypot');
- }
- /**
- * 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);
- }
- }
- /**
- * Create Honeypot CSS file.
- */
- function honeypot_update_7004() {
- drupal_load('module', 'honeypot');
- module_load_include('inc', 'honeypot', 'honeypot.admin');
- honeypot_create_css(variable_get('honeypot_element_name', 'url'));
- }
|