/**
 * Block request by country
 *
 * @param integer country ID
 * @param boolean set true to block the requet here, or false to handle outside the function
 * @return boolean true if blocked, false otherwise
 */
function antispam_block_by_country($country_ID, $assert = true)
{
    global $DB;
    $CountryCache =& get_CountryCache();
    $Country = $CountryCache->get_by_ID($country_ID, false);
    if ($Country && $Country->get('status') == 'blocked') {
        // The country exists in the database and has blocked status
        if ($assert) {
            // block the request
            $debug_message = sprintf('A request from \'%s\' was blocked because of this country is blocked.', $Country->get_name());
            exit_blocked_request('Country', $debug_message);
            // WILL exit();
        }
        // Update the number of requests from blocked countries
        $DB->query('UPDATE T_regional__country
			SET ctry_block_count = ctry_block_count + 1
			WHERE ctry_ID = ' . $Country->ID);
        return true;
    }
    return false;
}
 /**
  * Event handler: Gets invoked when an action request was called which should be blocked in specific cases
  *
  * Blocakble actions: comment post, user login/registration, email send/validation, account activation
  */
 function BeforeBlockableAction()
 {
     // Get request Ip addresses
     $request_ip_list = get_ip_list();
     foreach ($request_ip_list as $IP_address) {
         $Country = $this->get_country_by_IP($IP_address);
         if (!$Country) {
             // Country not found
             continue;
         }
         if (antispam_block_by_country($Country->ID, false)) {
             // Block the action if the country is blocked
             $debug_message = sprintf('A request with [ %s ] ip addresses was blocked because of \'%s\' is blocked.', implode(', ', $request_ip_list), $Country->get_name());
             exit_blocked_request('Country', $debug_message, 'plugin', $this->ID);
             // WILL exit();
         }
     }
 }