Skip to content

Commit

Permalink
some code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VladCleantalk committed Apr 29, 2015
1 parent 7ad6e80 commit 4fb244f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
6 changes: 3 additions & 3 deletions cleantalk/cleantalk.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ function cleantalk_activate() {
$ct_plans_query = full_query("SELECT * from tbladdons where lower(name) like '%leantalk%'");
if (mysql_num_rows($ct_plans_query) == 0){
$addon_type=array(
"name" => 'Anti-spam protection by CleanTalk',
"description" => 'Protect your website against spam bots. Anti-spam for comments, registrations, orders, bookings and contacts. <a href="http://cleantalk.org/publicoffer">License agreement</a>.',
"billingcycle" => "Annually",
"name" => 'CleanTalk free',
"description" => 'Protect your website against spam bots.',
"billingcycle" => "Free",
"showorder" => "on",
"welcomeemail" => 0,
"weight" => 1,
Expand Down
59 changes: 35 additions & 24 deletions cleantalk/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,43 @@ function cleantalk_hook_order($vars)
$cfg=full_query("SELECT value from tbladdonmodules where module='cleantalk' and setting='partner_api_key'");
$cfg=mysql_fetch_array($cfg);

$url = 'https://api.cleantalk.org';
$data = array();
$data['method_name'] = 'get_api_key';
$data['email'] = $email;
$data['website'] = $_SERVER['HTTP_HOST'];
$data['platform'] = 'whmcs';
$data['partner_api_key'] = $cfg['value'];
$data['locale'] = 'en-US';
$auth=send_request($url,$data,false);
if($auth!==null)
if(@trim($cfg['value'])!='')
{
$auth=json_decode($auth);
if(isset($auth->data)&&isset($auth->data->auth_key))
$url = 'https://api.cleantalk.org';
$data = array();
$data['method_name'] = 'get_api_key';
$data['email'] = $email;
$data['website'] = $domain;
$data['platform'] = 'whmcs';
$data['partner_api_key'] = $cfg['value'];
$data['locale'] = 'en-US';
$auth=send_request($url,$data,false);
if($auth!==null)
{
$command = "logactivity";
$adminuser = "admin";
$values["description"] = "CleanTalk account $email succesfully created";
$results = localAPI($command,$values,$adminuser);
}
else if(isset($auth->error_no))
{
$command = "logactivity";
$adminuser = "admin";
$values["description"] = "Failed to create CleanTalk account: ".$auth->error_message;
$results = localAPI($command,$values,$adminuser);
$auth=json_decode($auth);
if(isset($auth->data)&&isset($auth->data->auth_key))
{
$command = "logactivity";
$adminuser = "admin";
$values["description"] = "CleanTalk account $email succesfully created";
$results = localAPI($command,$values,$adminuser);
}
else if(isset($auth->error_no))
{
$command = "logactivity";
$adminuser = "admin";
$values["description"] = "Failed to create CleanTalk account: ".$auth->error_message;
$results = localAPI($command,$values,$adminuser);
}
}
}
else
{
$command = "logactivity";
$adminuser = "admin";
$values["description"] = "Failed to create CleanTalk account: please enter Hoster API key";
$results = localAPI($command,$values,$adminuser);
}
}
}
}
Expand All @@ -152,4 +162,5 @@ function cleantalk_hook_order($vars)
}
}

add_hook('ShoppingCartCheckoutCompletePage', 1, 'cleantalk_hook_order');
add_hook('ShoppingCartCheckoutCompletePage', 1, 'cleantalk_hook_order');
add_hook('AcceptOrder', 1, 'cleantalk_hook_order');

0 comments on commit 4fb244f

Please sign in to comment.