cleantalk.install in Anti Spam by CleanTalk 7.2
Same filename and directory in other branches
Install and uninstall functions for the CleanTalk module.
File
cleantalk.installView source
<?php
/**
* @file
* Install and uninstall functions for the CleanTalk module.
*/
/**
* Implements hook_install().
*/
function cleantalk_install() {
variable_set('ct_sfw_last_logs_sent', time());
variable_set('ct_sfw_last_updated', time());
db_drop_table('cleantalk_timelabels');
$cleantalk_timelabels = array(
'description' => 'Timelabels for admin notification sending.',
'fields' => array(
'ct_key' => array(
'type' => 'varchar',
'length' => 64,
'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',
),
);
db_create_table('cleantalk_timelabels', $cleantalk_timelabels);
db_drop_table('cleantalk_cids');
$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' => 32,
'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',
),
);
db_create_table('cleantalk_cids', $cleantalk_cids);
db_drop_table('cleantalk_uids');
$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' => 32,
'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',
),
);
db_create_table('cleantalk_uids', $cleantalk_uids);
db_drop_table('cleantalk_sfw');
$cleantalk_sfw = array(
'description' => 'SpamFireWall data.',
'fields' => array(
'network' => array(
'type' => 'int',
'length' => 11,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Spam network.',
),
'mask' => array(
'type' => 'int',
'length' => 11,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Spam mask.',
),
),
'primary key' => array(
'network',
'mask',
),
);
db_create_table('cleantalk_sfw', $cleantalk_sfw);
db_drop_table('cleantalk_sfw_logs');
$cleantalk_sfw_logs = array(
'description' => 'Comment checking results - CIDs and server responces.',
'fields' => array(
'ip' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'default' => '',
'description' => 'IP.',
),
'all' => array(
'type' => 'int',
'description' => 'All entries.',
),
'blocked' => array(
'type' => 'int',
'description' => 'Blocked entries.',
),
'timestamp' => array(
'type' => 'int',
'description' => 'time().',
),
),
'primary key' => array(
'ip',
),
);
db_create_table('cleantalk_sfw_logs', $cleantalk_sfw_logs);
$myRoles = array(
'spammer',
);
$roles = user_roles();
$myRole = new stdClass();
foreach ($myRoles as $r) {
if (!in_array($r, $roles)) {
$myRole->name = $r;
user_role_save($myRole);
}
}
}
/**
* Implements hook_uninstall().
*/
function cleantalk_uninstall() {
$myRoles = array(
'spammer',
);
$roles = user_roles();
foreach ($myRoles as $r) {
if (in_array($r, $roles)) {
user_role_delete($r);
}
}
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');
variable_del('ct_sfw_last_logs_sent');
variable_del('ct_sfw_last_updated');
db_drop_table('cleantalk_timelabels');
db_drop_table('cleantalk_cids');
db_drop_table('cleantalk_uids');
db_drop_table('cleantalk_sfw');
db_drop_table('cleantalk_sfw_logs');
}
/**
* 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;
}*/
/**
* Add new table for SpamFireWall logs
*/
function cleantalk_update_7200(&$sandbox = NULL) {
variable_set('ct_sfw_last_logs_sent', time());
db_drop_table('cleantalk_sfw_logs');
$cleantalk_sfw_logs = array(
'description' => 'Comment checking results - CIDs and server responces.',
'fields' => array(
'ip' => array(
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'default' => '',
'description' => 'IP.',
),
'all' => array(
'type' => 'int',
'description' => 'All entries.',
),
'blocked' => array(
'type' => 'int',
'description' => 'Blocked entries.',
),
'timestamp' => array(
'type' => 'int',
'description' => 'time().',
),
),
'primary key' => array(
'ip',
),
);
db_create_table('cleantalk_sfw_logs', $cleantalk_sfw_logs);
return '* New table for SpamFireWall logs added.';
}
/**
* 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
Name | Description |
---|---|
cleantalk_install | Implements hook_install(). |
cleantalk_uninstall | Implements hook_uninstall(). |
cleantalk_update_7200 | Add new table for SpamFireWall logs |
_cleantalk_library_missing_message_4install | Cleantalk inner function - missing CleanTalk library message for install. |