You are here

cleantalk.install in Anti Spam by CleanTalk 7

Install and uninstall functions, schema definition for the CleanTalk module.

File

cleantalk.install
View source
<?php

/**
 * @file
 * Install and uninstall functions, schema definition for the CleanTalk module.
 */

/**
 * Implements hook_schema().
 */
function cleantalk_schema() {
  $schema['cleantalk_timelabels'] = array(
    'description' => 'Timelabels for admin notification sending.',
    'fields' => array(
      'ct_key' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Notification ID.',
      ),
      'ct_value' => array(
        'type' => 'int',
        'length' => 12,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Time of last notification.',
      ),
    ),
    'primary key' => array(
      'ct_key',
    ),
  );
  $schema['cleantalk_cids'] = array(
    'description' => 'Comment checking results - CIDs and server responces.',
    'fields' => array(
      'cid' => array(
        'type' => 'int',
        'length' => 12,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'ID of checked comment.',
      ),
      'ct_request_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'CleanTalk request ID for comment.',
      ),
      'ct_result_comment' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'CleanTalk result for comment.',
      ),
    ),
    'primary key' => array(
      'cid',
    ),
  );
  $schema['cleantalk_uids'] = array(
    'description' => 'New user checking results - UIDs and server responces.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'length' => 12,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'ID of checked user registration.',
      ),
      'ct_request_id' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'CleanTalk request ID for user registration.',
      ),
      'ct_result_comment' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'CleanTalk result for user registration.',
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function cleantalk_uninstall() {
  variable_del('cleantalk_automod');
  variable_del('cleantalk_comments');
  variable_del('cleantalk_authkey');
  variable_del('cleantalk_ccf');
  variable_get('cleantalk_work_url');
  variable_get('cleantalk_server_url');
  variable_get('cleantalk_server_ttl');
  variable_get('cleantalk_server_changed');
}

/**
 * Implements hook_requirements().
 */

/*function cleantalk_requirements($phase) {
  $requirements = array();
  // Ensure translations don't break at install time.
  $t = get_t();

  $my_module = 'cleantalk';
  $title = 'CleanTalk PHP-antispam classes';

  drupal_load('module', 'libraries');
  $path = libraries_get_path($my_module);

  if (
    !$path ||
    !file_exists(DRUPAL_ROOT . '/' . $path . '/cleantalk.class.php') ||
    !file_exists(DRUPAL_ROOT . '/' . $path . '/JSON.php')
  ) {
    // Since Libraries 2.x, $path is FALSE if the library does not exist.
    $path = 'sites/all/libraries/cleantalk';
    $requirements[$my_module] = array(
      'title' => $t('CleanTalk PHP-antispam classes'),
      'value' => $t('Missing'),
      'severity' => REQUIREMENT_ERROR,
      'description' => $phase == 'runtime' ? _cleantalk_library_missing_message_4runtime($title, $path) : _cleantalk_library_missing_message_4install($title, $path),
    );
  }
  else {
    $requirements[$my_module] = array(
      'title' => $t('CleanTalk PHP-antispam classes'),
      'value' => $t('Installed'),
      'severity' => REQUIREMENT_OK,
    );
  }

  return $requirements;
}*/

/**
 * Cleantalk inner function - missing CleanTalk library message for install.
 */
function _cleantalk_library_missing_message_4install($title, $path) {
  $t = get_t();
  return $t('"Antispam by CleanTalk" module is DISABLED due to missing or broken CleanTalk library.') . ' <br />' . $t('Please download <a target="_blank" href="@url">@title</a>,' . ' extract the archive and copy the contents to the following location:' . '<br /><code>@path</code>.', array(
    '@url' => 'https://github.com/CleanTalk/php-antispam',
    '@path' => $path,
    '@title' => $title,
  )) . ' <br />' . $t('Make sure 2 files <strong>cleantalk.class.php</strong> and' . ' <strong>JSON.php</strong> are located there.') . '<br />';
}

Functions

Namesort descending Description
cleantalk_schema Implements hook_schema().
cleantalk_uninstall Implements hook_uninstall().
_cleantalk_library_missing_message_4install Cleantalk inner function - missing CleanTalk library message for install.