Skip to content

Commit ebf9d5c

Browse files
committed
added new API methods
1 parent 0da393c commit ebf9d5c

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

cleantalk.class.php

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Cleantalk base class
44
*
5-
* @version 1.35
5+
* @version 2.0
66
* @package Cleantalk
77
* @subpackage Base
88
* @author Cleantalk team ([email protected])
@@ -960,4 +960,70 @@ function stringFromUTF8($str, $data_codepage = null){
960960
}
961961
}
962962

963+
function getAutoKey($email, $host, $platform)
964+
{
965+
$request=Array();
966+
$request['method_name'] = 'get_api_key';
967+
$request['email'] = $email;
968+
$request['website'] = $host;
969+
$request['platform'] = $platform;
970+
$url='https://api.cleantalk.org';
971+
$result=sendRawRequest($url,$request);
972+
return $result;
973+
}
974+
975+
function noticePaidTill($api_key)
976+
{
977+
$request=Array();
978+
$request['method_name'] = 'notice_paid_till';
979+
$request['auth_key'] = $api_key;
980+
$url='https://api.cleantalk.org';
981+
$result=sendRawRequest($url,$request);
982+
return $result;
983+
}
984+
985+
function sendRawRequest($url,$data,$isJSON=false,$timeout=3)
986+
{
987+
$result=null;
988+
if(!$isJSON)
989+
{
990+
$data=http_build_query($data);
991+
}
992+
else
993+
{
994+
$data= json_encode($data);
995+
}
996+
if (function_exists('curl_init') && function_exists('json_decode'))
997+
{
998+
999+
$ch = curl_init();
1000+
curl_setopt($ch, CURLOPT_URL, $url);
1001+
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
1002+
curl_setopt($ch, CURLOPT_POST, true);
1003+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
1004+
1005+
// receive server response ...
1006+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1007+
// resolve 'Expect: 100-continue' issue
1008+
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
1009+
1010+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
1011+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
1012+
1013+
$result = curl_exec($ch);
1014+
curl_close($ch);
1015+
}
1016+
else
1017+
{
1018+
$opts = array(
1019+
'http'=>array(
1020+
'method'=>"POST",
1021+
'content'=>$data)
1022+
);
1023+
$context = stream_context_create($opts);
1024+
$result = @file_get_contents($url, 0, $context);
1025+
}
1026+
return $result;
1027+
}
1028+
9631029
?>

0 commit comments

Comments
 (0)