free plugin, all of these time and effort does not generate any revenue. Also as I\'m not a very privileged person, so earning revenue matters to me for keeping my lights on and keep me motivated to do the work I love. %3$s So, if you enjoy this plugin and understand the huge effort I put into this, please consider %1$s%4$sdonating some amount%5$s (no matter how small)%2$s for keeping aliave the development of this plugin. Thank you again for using my plugin. Also if you love using this plugin, I would really appiciate if you take 2 minutes out of your busy schedule to %1$s%6$sshare your review%7$s%2$s about this plugin.', 'aicp'),
'', '',
'
fetch_data();
echo '';
}
/**
* Callback function for showing the click counter cookie expiration field
**/
public function click_cookie_expiration() {
$this->fetch_data();
echo ' ' . __( 'Hour/s', 'aicp' ) . '';
}
/**
* Callback function for showing the ban duration field
**/
public function ban_duration_field() {
$this->fetch_data();
echo ' ' . __( 'Day/s', 'aicp' ) . '';
}
/**
* Callback function to check if the user wants to use the IP-API pro keys
**/
public function ipapi_pro_check() {
$this->fetch_data();
$options = get_option( 'aicp_settings_options' );
?>
ipapi_pro_check : $options['ipapi_pro_check'], 'Yes' ) ?> />
ipapi_pro_check : $options['ipapi_pro_check'], 'No' ) ?> />
fetch_data();
$options = get_option( 'aicp_settings_options' );
?>
country_block_check : $options['country_block_check'], 'Yes' ) ?> />
country_block_check : $options['country_block_check'], 'No' ) ?> />
fetch_data();
$options = get_option( 'aicp_settings_options' );
?>
', '',
',',
'', ''
);
?>
fetch_data();
$valid_fields = array();
$flag = 0;
$valid_fields['click_limit'] = strip_tags( stripslashes( trim( $fields['click_limit'] ) ) );
if( $valid_fields['click_limit'] < 1 || ( is_numeric( $valid_fields['click_limit'] ) === FALSE ) ) {
$valid_fields['click_limit'] = $this->click_limit;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_click_limit_error', __( 'The minimum number of click limit must needs to be more than or equals to 1 and the entered value must be a number', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['click_counter_cookie_exp'] = strip_tags( stripslashes( trim( $fields['click_counter_cookie_exp'] ) ) );
if( $valid_fields['click_counter_cookie_exp'] < 1 || ( is_numeric( $valid_fields['click_counter_cookie_exp'] ) === FALSE ) ) {
$valid_fields['click_counter_cookie_exp'] = $this->click_counter_cookie_exp;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_click_counter_cookie_exp_error', __( 'The click counter cookie expiration time must be a number and cannot be less than 1 hour', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['ban_duration'] = strip_tags( stripslashes( trim( $fields['ban_duration'] ) ) );
if( $valid_fields['ban_duration'] < 1 || ( is_numeric( $valid_fields['ban_duration'] ) === FALSE ) ) {
$valid_fields['ban_duration'] = $this->ban_duration;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_ban_ducation_error', __( 'The user ban duration must needs to be more than or equals to 1 day & the entered value must be a number', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['ipapi_pro_check'] = strip_tags( stripslashes( trim( $fields['ipapi_pro_check'] ) ) );
if( !( $valid_fields['ipapi_pro_check'] == 'Yes' || $valid_fields['ipapi_pro_check'] == 'No' ) ) {
$valid_fields['ipapi_pro_check'] = $this->ipapi_pro_check;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_ipapi_pro_check_error', __( 'You are trying to pass some value that it is not supposed to get. Don\'t try nasty hacking approaches', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['ipapi_pro_key'] = strip_tags( stripslashes( trim( $fields['ipapi_pro_key'] ) ) );
if( $valid_fields['ipapi_pro_check'] == 'Yes' && trim( $valid_fields['ipapi_pro_key'] ) == '' ) {
$valid_fields['ipapi_pro_check'] = $this->ipapi_pro_check;
$valid_fields['ipapi_pro_key'] = $this->ipapi_pro_key;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_ipapi_pro_check_error', __( 'Sorry! The IP-API Pro key cannot be blank while you are selecting YES for using IP-API Pro keys. Please make sure you have provided your API key while selecting YES.', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['country_block_check'] = strip_tags( stripslashes( trim( $fields['country_block_check'] ) ) );
if( !( $valid_fields['country_block_check'] == 'Yes' || $valid_fields['country_block_check'] == 'No' ) ) {
$valid_fields['country_block_check'] = $this->country_block_check;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_country_block_check_error', __( 'You are trying to pass some value that it is not supposed to get. Don\'t try nasty hacking approaches', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
$valid_fields['ban_country_list'] = strip_tags( stripslashes( trim( $fields['ban_country_list'] ) ) );
if( $valid_fields['country_block_check'] == 'Yes' && trim( $valid_fields['ban_country_list'] ) == '' ) {
$valid_fields['country_block_check'] = $this->country_block_check;
$valid_fields['ban_country_list'] = $this->ban_country_list;
++$flag;
// Set the error message
add_settings_error( 'aicp_settings_options', 'aicp_ipapi_pro_check_error', __( 'Sorry! The banned country list cannot be blank while you are selecting YES for the question if you wanna ban any country. Please provide some country codes when you select the Ban country check option as YES.', 'aicp' ), 'error' ); // $setting, $code, $message, $type
}
//showing the success message if there is no validation error
if( $flag == 0 ) {
add_settings_error( 'aicp_settings_options', 'aicp_seetings_save', __( 'Congratulation! All of your settings have been successfully saved.', 'aicp' ), 'updated' ); // $setting, $code, $message, $type
}
//Now it's time to save the values to the server
return apply_filters( 'validate_options', $valid_fields, $fields);
}
/**
* Callback function fetch the data from the database
**/
public function fetch_data() {
$fetched_data = get_option( 'aicp_settings_options' );
if( empty( $fetched_data ) ) {
$this->click_limit = 3; //default click limit is 3
$this->click_counter_cookie_exp = 3; //default click counter cookie expiration time is 3 HOURS
$this->ban_duration = 7; //default ban duration is 7 days
$this->ipapi_pro_check = 'No'; // Default value No
$this->ipapi_pro_key = ''; // default is blank
$this->country_block_check = 'No'; //default state is No
$this->ban_country_list = ''; //default state is a blank string
} else {
//click_limit
if( empty( $fetched_data['click_limit'] ) ) {
$this->click_limit = 3; //default click limit is 3
} else {
$this->click_limit = $fetched_data['click_limit'];
}
//click_counter_cookie_exp
if( empty( $fetched_data['click_counter_cookie_exp'] ) ) {
$this->click_counter_cookie_exp = 3; //default click counter cookie expiration time is 3 HOURS
} else {
$this->click_counter_cookie_exp = $fetched_data['click_counter_cookie_exp'];
}
//ban_duration
if( empty( $fetched_data['ban_duration'] ) ) {
$this->ban_duration = 7; //default ban duration is 7 days
} else {
$this->ban_duration = $fetched_data['ban_duration'];
}
//ipapi_pro_check
if( empty( $fetched_data['ipapi_pro_check'] ) ) {
$this->ipapi_pro_check = 'No'; //default state is No
} else {
$this->ipapi_pro_check = $fetched_data['ipapi_pro_check'];
}
//ipapi_pro_key
if( empty( $fetched_data['ipapi_pro_key'] ) ) {
$this->ipapi_pro_key = ''; //default state is blank
} else {
$this->ipapi_pro_key = $fetched_data['ipapi_pro_key'];
}
//country_block_check
if( empty( $fetched_data['country_block_check'] ) ) {
$this->country_block_check = 'No'; //default state is No
} else {
$this->country_block_check = $fetched_data['country_block_check'];
}
//ban_country_list
if( empty( $fetched_data['ban_country_list'] ) ) {
$this->ban_country_list = ''; //default state is a blank string
} else {
$this->ban_country_list = $fetched_data['ban_country_list'];
}
}
}
/**
* Function to add Settings link in the Installed Plugin List Page
**/
public function plugin_add_settings_link( $links ) {
$settings_link = '' . __( 'Settings', 'aicp' ) . '';
array_push( $links, $settings_link );
return $links;
}
/**
* Callback function run the hourly cleanup job to deloete all visitors which are
* blocked more than 7 days
**/
public function do_this_hourly() {
global $wpdb;
$this->fetch_data();
$aicpOBJ = new AICP();
$query = "DELETE FROM " . $aicpOBJ->table_name . " WHERE UNIX_TIMESTAMP( " . $aicpOBJ->table_name . ".timestamp ) < UNIX_TIMESTAMP( DATE_SUB( NOW(), INTERVAL " . $this->ban_duration . " DAY ) )";
$wpdb->query( $query );
}
public function delete_notice( $state ) {
if( $state === true ) {
$class = 'notice notice-success';
$message = __( 'The selected item has been successfully deleted.', 'aicp' );
printf( '
%2$s
', $class, $message );
} else {
$class = 'notice notice-error';
$message = __( 'Please select atleast one row before processing the delete option.', 'aicp' );
printf( '
%2$s
', $class, $message );
}
}
/**
* function to check if the plugin is using the latest table structure
**/
public function table_structure_update() {
global $aicp_db_ver;
if( get_option( 'aicp_db_ver' ) != $aicp_db_ver ) {
AICP_SETUP::on_activation();
}
}
/**
* Callback function show up the banned user details page
**/
public function banned_user_details() {
/* Let's handel the bulk and single deletion process first
* before showing the table data
**/
$bannedUserTableOBJ = new AICP_BANNED_USER_TABLE();
$aicpOBJ = new AICP();
if( 'delete'=== $bannedUserTableOBJ->current_action() ) {
global $wpdb;
$fetchedID = $_REQUEST['id'];
if( is_array( $fetchedID ) ) { // for bulk operation arry will return
$selectedID = implode( ",", $fetchedID );
} else { //for singel delete just the id will return
$selectedID = $fetchedID;
}
if( empty( $selectedID ) ) {
$this->delete_notice( false );
} else {
$query = "DELETE FROM " . $aicpOBJ->table_name . " WHERE " . $aicpOBJ->table_name . ".id IN (" . $selectedID . ")";
$wpdb->query( $query );
$this->delete_notice( true );
}
}
/* End of handelling the deletion process */
/* Now it's time to show our data */
?>