Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Infusionsoft/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function initApiKeyClient($apiKey = null, $initAsFallback = false){
$this->apiKey = $apiKey;
}

$this->client = new xmlrpc_client('/api/xmlrpc', $this->getHostname(), $this->port);
//$this->client = new xmlrpc_client('/api/xmlrpc', $this->getHostname(), $this->port); // Deprecated as of Oct 2024 - Keap sunsetting legacy api keys
$this->client = new xmlrpc_client('/crm/xmlrpc', 'api.infusionsoft.com', 443);
$this->client->setCustomHeader('X-Keap-Api-Key: ' . $apiKey);
if ($initAsFallback){
$this->initOauthClient();
}
Expand Down
13 changes: 12 additions & 1 deletion Infusionsoft/config.sample.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?php

$infusionsoft_host = 'joey.infusionsoft.com';

//deprecated - Keap are sunsetting legacy Keys Oct 2024 - Comment out this line once you have set up your new SAK key
$infusionsoft_api_key = 'YOUR API KEY GOES HERE';

//Uncomment the following line once you have generated and copied in your SAK key
//$infusionsoft_sak_key = 'YOUR SERVICE ACCESS KEY (SAK) GOES HERE';


//To Add Custom Fields, use the addCustomField method like below.
//Infusionsoft_Contact::addCustomField('_LeadScore');

//Below is just some magic... Unless you are going to be communicating with more than one APP at the SAME TIME. You can ignore it.
Infusionsoft_AppPool::addApp(new Infusionsoft_App($infusionsoft_host, $infusionsoft_api_key, 443));

//Comment this line out once you have set up your new SAK key
Infusionsoft_AppPool::addApp(new Infusionsoft_App($infusionsoft_host, $infusionsoft_api_key, 443));

//Uncomment the following line once you have generated and copied in your SAK key above
//Infusionsoft_AppPool::addApp(new Infusionsoft_App($infusionsoft_host, $infusionsoft_sak_key, 443));
46 changes: 39 additions & 7 deletions Infusionsoft/xmlrpc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ class xmlrpc_client
var $curlError = null;
var $curlInfo = null;
var $curlErrorNo = null;
var $customheaders=[];

/**
* List of http compression methods accepted by the client for responses.
Expand Down Expand Up @@ -1141,6 +1142,20 @@ class xmlrpc_client
$this->user_agent = $agentstring;
}


/**
* Add a custom header
* @param type $customheader
* @return type
*/
function setCustomHeader($customheader){
foreach($this->customheaders as $ch){
if ($ch===$customheader) return;
}
$this->customheaders[] = $customheader;
}


/**
* Send an xmlrpc request
* @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request
Expand Down Expand Up @@ -1195,7 +1210,8 @@ class xmlrpc_client
$this->proxy_authtype,
$this->keepalive,
$this->key,
$this->keypass
$this->keypass,
$this->customheaders
);
}
elseif($method == 'http11')
Expand Down Expand Up @@ -1235,7 +1251,8 @@ class xmlrpc_client
$this->proxyport,
$this->proxy_user,
$this->proxy_pass,
$this->proxy_authtype
$this->proxy_authtype,
$this->customheaders
);
}

Expand All @@ -1247,7 +1264,7 @@ class xmlrpc_client
*/
function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
$username='', $password='', $authtype=1, $proxyhost='',
$proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
$proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $customheaders=[])
{
if($port==0)
{
Expand Down Expand Up @@ -1361,6 +1378,9 @@ class xmlrpc_client
// omit port if 80
$port = ($port == 80) ? '' : (':' . $port);

$customheaderString = (is_array($customheaders) && sizeof($customheaders)>0 ) ? implode("\r\n", $customheaders) . "\r\n" : "";


$op= 'POST ' . $uri. " HTTP/1.0\r\n" .
'User-Agent: ' . $this->user_agent . "\r\n" .
'Host: '. $server . $port . "\r\n" .
Expand All @@ -1369,6 +1389,7 @@ class xmlrpc_client
$accepted_encoding .
$encoding_hdr .
'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
$customheaderString .
$cookieheader .
'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
strlen($payload) . "\r\n\r\n" .
Expand Down Expand Up @@ -1436,11 +1457,11 @@ class xmlrpc_client
function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
$password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
$keepalive=false, $key='', $keypass='')
$keepalive=false, $key='', $keypass='', $customheaders=[])
{
$r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
$password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
$proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
$proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass, $customheaders);
return $r;
}

Expand All @@ -1453,7 +1474,7 @@ class xmlrpc_client
function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
$password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
$proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
$keepalive=false, $key='', $keypass='')
$keepalive=false, $key='', $keypass='', $customheaders=[])
{
if(!function_exists('curl_init'))
{
Expand Down Expand Up @@ -1581,6 +1602,12 @@ class xmlrpc_client
$headers[] = $encoding_hdr;
}

if(is_array($customheaders) && sizeof($customheaders)>0){
foreach($customheaders as $ch){
$headers[] = $ch;
}
}

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// timeout is borked
if($timeout)
Expand Down Expand Up @@ -2658,7 +2685,12 @@ class xmlrpcmsg
// **END JORDAN NOVAK EDIT**

//ForceUTF8 seems to have fixed our problems..
$data = ForceUTF8\Encoding::toUTF8($data);
if (method_exists('ForceUTF8\Encoding','toUTF8')){
$data = ForceUTF8\Encoding::toUTF8($data);
}else{
$data = preg_replace(array('/\&#[0-9]{1,4}(?![0-9]{0,3};)/'),'', $data);
$data = str_replace(array("&#1;", "&#11;", "&#0;", "&#2;", "&#3;", "&#5;", "&#6;", "&#7;", "&#12", "&#14;", "&#20;", "&#24;", "&#25;", "&#16", "&#19;", "&#8;", "&#18;", "&#180;", "&#193;", "&#214;", "&#240;", "&#255;", "&#402;", "&#8218;", "&#8482;", '￿', ''/*non-printing character, this is not an empty string*/), "", $data);
}

//0x19 is Ascii End of Medium and is causing problems, but we'll fix it AFTER ForceUTF8
//0x12 is Ascii something and is causing problems, but we'll fix it AFTER ForceUTF8
Expand Down