File: /home/bt667/www/wp-content/plugins/wp_mvplayer/ajax/addusers.php
<?php
require_once('../../../../wp-load.php');
global $wpdb;
$username = $_POST['username'];
$useremail = $_POST['useremail'];
$ip_address = $_POST['ip_address'];
$datetime = $_POST['datetime'] ;
$videoid = $_POST['videoid'] ;
// Get Video Detail
$video_table = $wpdb->prefix . "mvplayer_video";
$video_detail = $wpdb->get_row("SELECT * FROM $video_table where id= $videoid");
if($video_detail->VideoMailingList=='mailchimp'){
$apiKey = $video_detail->MailChimpApiKey;
$listId = $video_detail->MailChimpListId;
if($video_detail->MailChimpApiKey && $video_detail->MailChimpListId){
$mcapi = new MCAPI($video_detail->MailChimpApiKey,$secure=false);
$merge_vars = array('FNAME'=>$username);
//Create mailchimp API url
$memberId = md5(strtolower($useremail));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/lists/'.$listId.'/members/'.$memberId;
//Member info
$member_data = array(
'email_address'=>$useremail,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $username
]
);
$jsonString = json_encode($member_data);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonString);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
//Collecting the status
switch ($httpCode) {
case 200:
$msg = __('success','mvp');
break;
case 214:
$msg = __('Already Subscribed','mvp');
break;
default:
$msg = __('Oops, please try again.[msg_code='.$httpCode.']','mvp');
break;
}
echo $msg;
/*END :: Add New CURL Code for mailchimp AR*/
}
}else if($video_detail->VideoMailingList=='getresponse'){
if($video_detail->GetResponseApiKey && $video_detail->GetResponseCampaignId){
$api = new GetResponse($video_detail->GetResponseApiKey);
$campaign_id = $video_detail->GetResponseCampaignId;
$params = array('campaign' => array('campaignId'=>$campaign_id), 'action' => 'standard', 'name' => $username,'email' => $useremail, 'cycle_day' => '0', 'ip' => $_SERVER['REMOTE_ADDR']);
$response = $api->addContact($params);
echo "success";
}
}else if($video_detail->VideoMailingList=='aweber'){
$AWeberAccessTokens = unserialize($video_detail->AWeberAccessTokens);
$AWeberListID = $video_detail->AWeberListID;
$aweber = new AWeberAPI($AWeberAccessTokens['consumerKey'], $AWeberAccessTokens['consumerSecret']);
try{
$account = $aweber->getAccount($AWeberAccessTokens['accessKey'], $AWeberAccessTokens['accessSecret']);
$params = array(
'email' => $useremail,
'ip_address' => $_SERVER['REMOTE_ADDR'],
'name' => $username,
'ad_tracking' => 'Wordpress',
);
$account_id = $account->id;
$listURL = "/accounts/{$account_id}/lists/{$AWeberListID}/subscribers";
$subscribers = $account->loadFromUrl($listURL);
$new_subscriber = $subscribers->create($params);
echo "success";
}
catch(Exception $e){
print_r($e);
}
}else if($video_detail->VideoMailingList=='constantcontact'){
if($video_detail->ConstCntctUserName && $video_detail->ConstCntctAPIKey && $video_detail->ConstCntctSecret && $video_detail->ConstCntctListID){
try{
$user_name = $video_detail->ConstCntctUserName;
$apiKey = $video_detail->ConstCntctAPIKey;
$consumerSecret = $video_detail->ConstCntctSecret;
$Datastore = new CTCTDataStore();
$DatastoreUser = $Datastore->lookupUser($user_name,$videoid);
if($DatastoreUser){
$ConstantContact = new ConstantContact($videoid,'oauth', $apiKey, $DatastoreUser['username'], $consumerSecret);
$Contact = new Contact();
$Contact->emailAddress = $useremail;
$Contact->firstName = $username;
$Contact->lists = array($video_detail->ConstCntctListID);
$NewContact = $ConstantContact->addContact($Contact);
echo "success";
}
}catch(Exception $e){}
}
}else{
$users_table = $wpdb->prefix . "mvplayer_users";
$useripaddress = $_SERVER["REMOTE_ADDR"];
$wpdb->insert( $users_table, array('UserName' => $username,'UserMail' =>$useremail,'UserIPAddress'=>$useripaddress,'Date'=>date("Y-m-d h:i:s")));
echo "success";
}