File: //proc/self/cwd/wp-content/plugins/bot-nemesis_6551354a614844b2a78837b5afc250af/inc/install.php
<?php
use BotNemesis\Client;
function bn_install() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
$charset_collate = $wpdb->get_charset_collate();
$bn_user_agents_keywords_table_sql = "CREATE TABLE {$wpdb->prefix}bn_user_agents_keywords (
user_agent_keyword_id BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
user_agent_keyword_value VARCHAR(255) DEFAULT '' NOT NULL,
user_agent_keyword_is_master TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
user_agent_keyword_removed TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
UNIQUE KEY id (user_agent_keyword_id)
) $charset_collate;";
dbDelta( $bn_user_agents_keywords_table_sql );
$bn_ip_addresses_table_sql = "CREATE TABLE {$wpdb->prefix}bn_ip_addresses (
ip_address_id BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
ip_address_value VARCHAR(255) DEFAULT '' NOT NULL,
ip_address_is_master TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
ip_address_removed TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
UNIQUE KEY id (ip_address_id)
) $charset_collate;";
dbDelta( $bn_ip_addresses_table_sql );
$bn_countries_table_sql = "CREATE TABLE {$wpdb->prefix}bn_countries (
country_id BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
country_name VARCHAR(255) DEFAULT '' NOT NULL,
country_blocked TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
country_is_master TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
country_removed TINYINT(1) UNSIGNED DEFAULT '0' NOT NULL,
UNIQUE KEY id (country_id)
) $charset_collate;";
dbDelta( $bn_countries_table_sql );
$bn_country_ip_addresses_table_sql = "CREATE TABLE {$wpdb->prefix}bn_country_ip_addresses (
country_ip_address_id BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
country_ip_address_country_id BIGINT UNSIGNED DEFAULT '0' NOT NULL,
country_ip_address_value VARCHAR(255) DEFAULT '' NOT NULL,
UNIQUE KEY id (country_ip_address_id)
) $charset_collate;";
dbDelta( $bn_country_ip_addresses_table_sql );
$bn_info_blurbs_table_sql = "CREATE TABLE {$wpdb->prefix}bn_info_blurbs (
info_blurb_id BIGINT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
info_blurb_key VARCHAR(255) DEFAULT '' NOT NULL,
info_blurb_text TEXT DEFAULT '' NOT NULL,
UNIQUE KEY id (info_blurb_id)
) $charset_collate;";
dbDelta( $bn_info_blurbs_table_sql );
bn_insert_default_data();
update_option('bn_db_version', BN_DB_VERSION);
update_option('bn_just_installed', 'bn_just_installed');
wp_schedule_event(time() + 86400, 'daily', 'bn_get_automatic_updates_from_master');
}
function bn_insert_default_data() {
if(BN_DB_VERSION == get_option('bn_db_version')) {
return;
}
global $wpdb;
if( ! $wpdb->query("SELECT * FROM {$wpdb->prefix}bn_countries")) {
// inserting countries, if there is no records in the table
$countries_sql = "INSERT INTO {$wpdb->prefix}bn_countries (country_name) VALUES (\"" . implode("\"),(\"", bn_get_countries_array()) . "\");";
$wpdb->query($countries_sql);
}
}
function bn_uninstall() {
wp_clear_scheduled_hook('bn_get_automatic_updates_from_master');
Client::deactivateClientAtMaster(get_option('siteurl'), get_option('bn_client_uid', ''));
}
function bn_just_installed() {
if(is_admin() && get_option('bn_just_installed')) {
delete_option('bn_just_installed');
$client_uid = Client::activateClientAtMaster(get_option('siteurl'), get_option('bn_client_uid', ''));
$client_uid = $client_uid && isset($client_uid->client_uid) ? $client_uid->client_uid : '';
update_option('bn_client_uid', $client_uid);
}
}