/var/www/html/plugins/jdonation/spamdetect/spamdetect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

class plgJDonationSpamDetect extends JPlugin
{
	public function __construct(& $subject, $config)
	{
		parent::__construct($subject, $config);
	}

	function onBeforeStoreDonor() {
		require_once JPATH_ROOT.'/components/com_jdonation/helper/helper.php';
		$user_ip = DonationHelper::get_ip_address();
		$accFrequency = 0;
        $access = 'yes';
		if(function_exists('curl_version')){
			$url = 'http://api.stopforumspam.org/api';

			$data = array(
				'ip' => $userip,
				"badtorexit"
			);
			$data = http_build_query($data);
			//echo $data;die();

			// init the request, set some info, send it and finally close it

			$ch = curl_init($url);
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			$result = curl_exec($ch);
			curl_close($ch);
			$xmlDatas = simplexml_load_string($result);
			if ($xmlDatas->appears == $access && $xmlDatas->frequency >= $accFrequency) {
				JError::raiseError( 404, JText::_('Spam detected') );
				exit();
			}
		}
	}
}