diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24ee02a --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +# Ignore everything in the root except the "wp-content" directory. +/* +!.gitignore +!wp-content/ + +# Ignore everything in the "plugins" directory, except for Sailthru's +# plugin directory. +wp-content/plugins/* +!wp-content/plugins/sailthru/ + +# Ignore everything in the "themes" directory, except for Sailthru's +# theme directory. +wp-content/themes/* +!wp-content/themes/sailthru/ diff --git a/README.md b/README.md index 50dc81d..eabf8de 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ sailthru-wordpress-plugin ========================= + +For installation instructions, documentation, and examples please visit: +[http://getstarted.sailthru.com/developers/api-libraries/wordpress](http://getstarted.sailthru.com/developers/api-libraries/wordpress) diff --git a/client/Sailthru_Client.php b/client/Sailthru_Client.php index c0586b8..975ba22 100755 --- a/client/Sailthru_Client.php +++ b/client/Sailthru_Client.php @@ -13,28 +13,28 @@ class Sailthru_Client { * Sailthru API Key * @var string */ - private $api_key; + protected $api_key; /** * - * SAilthru Secret + * Sailthru Secret * @var string */ - private $secret; + protected $secret; /** * * Sailthru API URL, can be different for different users according to their settings * @var string */ - private $api_uri = 'https://api.sailthru.com'; + protected $api_uri = 'https://api.sailthru.com'; /** * * cURL or non-cURL request * @var string */ - private $http_request_type; + protected $http_request_type; /** * @@ -44,13 +44,29 @@ class Sailthru_Client { */ protected $user_agent_string; + /** + * Get information regarding last response from server + * @var type + */ + private $lastResponseInfo = null; + /** - * Instantiate a new client; constructor optionally takes overrides for api_uri. + * File Upload Flag variable + */ + private $fileUpload = false; + + private $httpHeaders = array("User-Agent: Sailthru API PHP5 Client"); + + + /** + * Instantiate a new client; constructor optionally takes overrides for api_uri and whether + * to share the version of PHP that is being used. * * @param string $api_key * @param string $secret * @param string $api_uri + * @param boolean $show_version */ public function __construct($api_key, $secret, $api_uri = false) { $this->api_key = $api_key; @@ -60,7 +76,11 @@ public function __construct($api_key, $secret, $api_uri = false) { } $this->http_request_type = function_exists('curl_init') ? 'httpRequestCurl' : 'httpRequestWithoutCurl'; - $this->user_agent_string = "Sailthru API PHP5 Client PHP Version: " . phpversion() ; + } + + public function setHttpHeaders(array $headers) { + $this->httpHeaders = array_merge($this->httpHeaders, $headers); + return true; } @@ -134,7 +154,7 @@ public function getSend($send_id) { * @link http://docs.sailthru.com/api/send */ public function cancelSend($send_id) { - return $this->apiPost('send', array('send_id' => $send_id), 'DELETE'); + return $this->apiDelete('send', array('send_id' => $send_id)); } @@ -157,7 +177,6 @@ public function getEmail($email) { * @param string $email * @param array $vars * @param array $lists - * @param array $templates * @param integer $verified 1 or 0 * @param string $optout @@ -191,6 +210,17 @@ public function setEmail($email, $vars = array(), $lists = array(), $templates = } + /** + * Update / add email address + * + * @link http://docs.sailthru.com/api/email + */ + public function setEmail2($email, array $options = array()) { + $options['email'] = $email; + return $this->apiPost('email', $options); + } + + /** * Schedule a mass mail blast * @@ -203,32 +233,25 @@ public function setEmail($email, $vars = array(), $lists = array(), $templates = * @param string $content_html the HTML-format version of the email * @param string $content_text the text-format version of the email * @param array $options associative array - * blast_id - * copy_blast - * copy_template - * replyto - * report_email - * is_link_tracking - * is_google_analytics - * is_public - * suppress_list - * test_vars - * email_hour_range - * abtest - * test_percent - * data_feed_url + * blast_id + * copy_blast + * copy_template + * replyto + * report_email + * is_link_tracking + * is_google_analytics + * is_public + * suppress_list + * test_vars + * email_hour_range + * abtest + * test_percent + * data_feed_url * @link http://docs.sailthru.com/api/blast */ - public function scheduleBlast($name, - $list, - $schedule_time, - $from_name, - $from_email, - $subject, - $content_html, - $content_text, - $options = array()) { - + public function scheduleBlast($name, $list, $schedule_time, $from_name, + $from_email, $subject, $content_html, $content_text, $options = array() + ) { $data = $options; $data['name'] = $name; $data['list'] = $list; @@ -242,6 +265,7 @@ public function scheduleBlast($name, return $this->apiPost('blast', $data); } + /** * Schedule a mass mail from a template * @@ -259,6 +283,7 @@ public function scheduleBlastFromTemplate($template, $list, $schedule_time, $opt return $this->apiPost('blast', $data); } + /** * Schedule a mass mail blast from previous blast * @@ -274,6 +299,7 @@ public function scheduleBlastFromBlast($blast_id, $schedule_time, $options = arr return $this->apiPost('blast', $data); } + /** * updates existing blast * @@ -287,32 +313,27 @@ public function scheduleBlastFromBlast($blast_id, $schedule_time, $options = arr * @param string $content_html * @param string $content_text * @param array $options associative array - * blast_id - * copy_blast - * copy_template - * replyto - * report_email - * is_link_tracking - * is_google_analytics - * is_public - * suppress_list - * test_vars - * email_hour_range - * abtest - * test_percent - * data_feed_url + * blast_id + * copy_blast + * copy_template + * replyto + * report_email + * is_link_tracking + * is_google_analytics + * is_public + * suppress_list + * test_vars + * email_hour_range + * abtest + * test_percent + * data_feed_url * @link http://docs.sailthru.com/api/blast */ - public function updateBlast($blast_id, - $name = null, - $list = null, - $schedule_time = null, - $from_name = null, - $from_email = null, - $subject = null, - $content_html = null, - $content_text = null, - $options = array()) { + public function updateBlast($blast_id, $name = null, $list = null, + $schedule_time = null, $from_name = null, $from_email = null, + $subject = null, $content_html = null, $content_text = null, + $options = array() + ) { $data = $options; $data['blast_id'] = $blast_id; if (!is_null($name)) { @@ -342,13 +363,6 @@ public function updateBlast($blast_id, return $this->apiPost('blast', $data); } - - public function sailthru_eval($datafeed, $template) { - $data['data_feed_url'] = $datafeed; - $data['template'] = $template; - $data['sysvars'] = 1; - return $this->apiPost('eval', $data); - } /** @@ -360,6 +374,18 @@ public function getBlast($blast_id) { return $this->apiGet('blast', array('blast_id' => $blast_id)); } + /** + * Get info on multiple blasts + * @param array $options associative array + * start_date (required) + * end-date (required) + * status + * @link http://docs.sailthru.com/api/blast + */ + public function getBlasts($options) { + return $this->apiGet('blast', $options); + } + /** * Delete Blast @@ -384,16 +410,33 @@ public function cancelBlast($blast_id) { return $this->apiPost('blast', $data); } + /** * Fetch information about a template * * @param string $template_name * @link http://docs.sailthru.com/api/template */ - function getTemplate($template_name) { - return $this->apiGet('template', array('template' => $template_name)); + public function getTemplate($template_name, array $options = array()) { + $options['template'] = $template_name; + return $this->apiGet('template', $options); } + + /** + * Fetch name of all existing templates + * @link http://docs.sailthru.com/api/template + */ + public function getTemplates() { + return $this->apiGet('template', array()); + } + + + public function getTemplateFromRevision($revision_id) { + return $this->apiGet('template', array('revision' => (int)$revision_id)); + } + + /** * Save a template. * @@ -401,88 +444,98 @@ function getTemplate($template_name) { * @param array $template_fields * @link http://docs.sailthru.com/api/template */ - public function saveTemplate($template_name, $template_fields = array()) { + public function saveTemplate($template_name, array $template_fields = array()) { $data = $template_fields; $data['template'] = $template_name; return $this->apiPost('template', $data); } - /** - * Download a list. Obviously, this can potentially be a very large download. - * 'txt' is default format since, its more compact as compare to others - * @param String $list - * @param String $format - * @return txt | json | xml - * @link http://docs.sailthru.com/api/list + * Save a template from revision + * + * @param string $template_name + * @param numeric $revision + * @link http://docs.sailthru.com/api/template */ - public function getList($list, $format = "txt") { - $data = array( - 'list' => $list, - 'format' => $format - ); - return $this->apiGet('list', $data); + public function saveTemplateFromRevision($template_name, $revision_id) { + $revision_id = (int)$revision_id; + return $this->saveTemplate($template_name, array('revision' => $revision_id)); } - + /** - * Get all lists metadata of a user - **/ - public function getLists() { - return $this->apiGet('list', array('list' => "")); + * Delete a template. + * + * @param string $template_name + * @param array $template_fields + * @link http://docs.sailthru.com/api/template + */ + public function deleteTemplate($template_name) { + return $this->apiDelete('template', array('template' => $template_name)); } /** - * Upload a list. The list import job is queued and will happen shortly after the API request. - * @param String $list - * @param String $emails + * Get information about a list. + * + * @param string $list + * @return array * @link http://docs.sailthru.com/api/list */ - public function saveList($list, $emails) { - $data = array( - 'list' => $list, - 'emails' => $emails - ); - return $this->apiPost('list', $data); + public function getList($list) { + return $this->apiGet('list', array('list' => $list)); } /** - * Deletes a list - * @param String $list - * @link http://docs.sailthru.com/api/list + * Get information about all lists + * + * @param string $list + * @param string $emails + * @return array + * @link http://docs.sailthru.com/api/list */ - public function deleteList($list) { - $data = array( - 'list' => $list - ); - return $this->apiDelete('list', $data); + public function getLists() { + return $this->apiGet('list'); } /** + * Create a list, or update a list. * - * Fetch email contacts from a user's address book on one of the major email websites. Currently supports AOL, Gmail, Hotmail, and Yahoo! Mail. - * - * @param String $email - * @param String $password - * @param boolean $include_names - * @link http://docs.sailthru.com/api/contacts + * @param string $list + * @param string $list + * @param string $type + * @param bool $primary + * @param array $query + * @return array + * @link http://docs.sailthru.com/api/list + * @link http://docs.sailthru.com/api/query */ - public function importContacts($email, $password, $include_names = true) { + public function saveList($list, $type = null, $primary = null, $query = array()) { $data = array( - 'email' => $email, - 'password' => $password + 'list' => $list, + 'type' => $type, + 'primary' => $primary ? 1 : 0, + 'query' => $query, ); - if ($include_names === true) { - $data['names'] = 1; - } - return $this->apiPost('contacts', $data); + return $this->apiPost('list', $data); } + /** + * Deletes a list. + * + * @param string $list + * @return array + * @link http://docs.sailthru.com/api/list + */ + public function deleteList($list) { + return $this->apiDelete('list', array('list' => $list)); + } + + /** * * Push a new piece of content to Sailthru, triggering any applicable alerts. @@ -533,14 +586,11 @@ public function getAlert($email) { * * array( - * 'type' => array( - * 'shoes', 'shirts' - * ), - * 'min' => array( - * 'price' => 3000 - * ), - * 'tags' => array('blue', 'red') + * 'match' => array( + * 'type' => array('shoes', 'shirts'), + * 'min' => array('price' => 3000), + * 'tags' => array('blue', 'red'), + * ) * ); * $response = $sailthruClient->saveAlert("praj@sailthru.com", 'realtime', 'default', null, $options); * ?> @@ -552,10 +602,10 @@ public function getAlert($email) { * @param String $template * @param String $when * @param array $options Associative array of additive nature - * match Exact-match a custom variable match[type]=shoes - * min Minimum-value variables min[price]=30000 - * max Maximum-value match max[price]=50000 - * tags Tag-match tags[]=blue + * match Exact-match a custom variable match[type]=shoes + * min Minimum-value variables min[price]=30000 + * max Maximum-value match max[price]=50000 + * tags Tag-match tags[]=blue */ public function saveAlert($email, $type, $template, $when = null, $options = array()) { $data = $options; @@ -588,21 +638,29 @@ public function deleteAlert($email, $alert_id) { * Record that a user has made a purchase, or has added items to their purchase total. * @link http://docs.sailthru.com/api/purchase */ - public function purchase($email, array $items, $incomplete = null, $message_id = null) { - $data = array( - 'email' => $email, - 'items' => $items - ); + public function purchase($email, array $items, $incomplete = null, $message_id = null, array $options = array()) { + $data = $options; + $data['email'] = $email; + $data['items'] = $items; if (!is_null($incomplete)) { $data['incomplete'] = (int)$incomplete; } if (!is_null($message_id)) { - $data['incomplete'] = $message_id; + $data['message_id'] = $message_id; } return $this->apiPost('purchase', $data); } + /** + * Make a purchase API call with incomplete flag + * @link http://docs.sailthru.com/api/purchase + */ + public function purchaseIncomplete($email, array $items, $message_id, array $options = array()) { + return $this->purchase($email, $items, 1, $message_id, $options); + } + + /** * Retrieve information about your subscriber counts on a particular list, on a particular day. * @link http://docs.sailthru.com/api/stats @@ -641,12 +699,32 @@ public function stats_blast($blast_id = null, $start_date = null, $end_date = nu return $this->stats($data); } + /** + * Retrieve information about a particular send or aggregated information from all of templates over a specified date range. + * @param array $data + */ + public function stats_send($template=null, $start_date = null, $end_date = null, array $data = array()) { + $data['stat'] = 'send'; + + if (!is_null($template)) { + $data['template'] = $template; + } + if (!is_null($start_date)) { + $data['start_date'] = $start_date; + } + if (!is_null($end_date)) { + $data['end_date'] = $end_date; + } + + return $this->stats($data); + } + /** * Make Stats API Request * @param array $data */ - protected function stats(array $data) { + public function stats(array $data) { return $this->apiGet('stats', $data); } @@ -710,6 +788,45 @@ public function receiveOptoutPost() { } + /** + * + * Hard bounce postbacks + * @return boolean + * @link http://docs.sailthru.com/api/postbacks + */ + public function receiveHardBouncePost(){ + $params = $_POST; + foreach (array('action', 'email', 'sig') as $k) { + if (!isset($params[$k])) { + return false; + } + } + if ($params['action'] != 'hardbounce') { + return false; + } + $sig = $params['sig']; + unset($params['sig']); + if ($sig != Sailthru_Util::getSignatureHash($params, $this->secret)) { + return false; + } + if (isset($params['send_id'])) { + $send_id = $params['send_id']; + $send = $this->getSend($send_id); + if (!isset($send['email'])) { + return false; + } + } + else if (isset($params['blast_id'])) { + $blast_id = $params['blast_id']; + $blast = $this->getBlast($blast_id); + if (isset($blast['error'])) { + return false; + } + } + return true; + } + + /** * * Get horizon data @@ -741,6 +858,218 @@ public function setHorizon($email, $tags = null) { } + /** + * Get status of a job + * @param String $job_id + */ + public function getJobStatus($job_id) { + return $this->apiGet('job', array('job_id' => $job_id)); + } + + + /** + * process job api call + * @param String $job + * @param array $options + * @param String $report_email + * @param String $postback_url + * @param array $binary_data_param + */ + protected function processJob($job, array $options = array(), $report_email = false, $postback_url = false, array $binary_data_param = array()) { + $data = $options; + $data['job'] = $job; + if ($report_email) { + $data['report_email'] = $report_email; + } + if ($postback_url) { + $data['postback_url'] = $postback_url; + } + return $this->apiPost('job', $data, $binary_data_param); + } + + + /** + * Process import job from given email string CSV + * @param String $list + * @param String $emails + * @param String $report_email + * @param String $postback_url + */ + public function processImportJob($list, $emails, $report_email = false, $postback_url = false) { + $data = array( + 'emails' => $emails, + 'list' => $list + ); + return $this->processJob('import', $data, $report_email, $postback_url); + } + + + /** + * Process import job from given file path of a CSV or email per line file + * + * @param String $list + * @param String $emails + * @param String $report_email + * @param String $postback_url + * + */ + public function processImportJobFromFile($list, $file_path, $report_email = false, $postback_url = false) { + $data = array( + 'file' => $file_path, + 'list' => $list + ); + return $this->processJob('import', $data, $report_email, $postback_url, array('file')); + } + + + /** + * Process a snapshot job + * + * @param array $query + * @param String $report_email + * @param String $postback_url + */ + public function processSnapshotJob(array $query, $report_email = false, $postback_url = false) { + $data = array('query' => $query); + return $this->processJob('snaphot', $data, $report_email, $postback_url); + } + + + /** + * Process a export list job + * @param String $list + * @param String $report_email + * @param String $postback_url + */ + public function processExportListJob($list, $report_email = false, $postback_url = false) { + $data = array('list' => $list); + return $this->processJob('export_list_data', $data, $report_email, $postback_url); + } + + + /** + * Export blast data in CSV format + * @param integer $blast_id + * @param String $report_email + * @param String $postback_url + */ + public function processBlastQueryJob($blast_id, $report_email = false, $postback_url = false) { + return $this->processJob('blast_query', array('blast_id' => $blast_id), $report_email, $postback_url); + } + + + /** + * Perform a bulk update of any number of user profiles from given context: String CSV, file, URL or query + * @param String $context + * @param Array $update + * @param String $report_email + * @param String $postback_url + */ + public function processUpdateJob($context, $value, array $update = array(), $report_email = false, $postback_url = false, array $file_params = array()) { + $data = array( + $context => $value + ); + if (count($update) > 0) { + $data['update'] = $update; + } + return $this->processJob('update', $data, $report_email, $postback_url, $file_params); + } + + + /** + * Perform a bulk update of any number of user profiles from given URL + * @param String $url + * @param Array $update + * @param String $report_email + * @param String $postback_url + */ + public function processUpdateJobFromUrl($url, array $update = array(), $report_email = false, $postback_url = false) { + return $this->processUpdateJob('url', $url, $update, $report_email, $postback_url); + } + + + /** + * Perform a bulk update of any number of user profiles from given file + * @param String $url + * @param Array $update + * @param String $report_email + * @param String $postback_url + */ + public function processUpdateJobFromFile($file, array $update = array(), $report_email = false, $postback_url = false) { + return $this->processUpdateJob('file', $file, $update, $report_email, $postback_url, array('file')); + } + + + /** + * Perform a bulk update of any number of user profiles from a query + * @param Array $query + * @param Array $update + * @param String $report_email + * @param String $postback_url + */ + public function processUpdateJobFromQuery($query, array $update = array(), $report_email = false, $postback_url = false) { + return $this->processUpdateJob('query', $query, $update, $report_email, $postback_url); + } + + + /** + * Perform a bulk update of any number of user profiles from emails CSV + * @param String $emails + * @param Array $update + * @param String $report_email + * @param String $postback_url + */ + public function processUpdateJobFromEmails($emails, array $update = array(), $report_email = false, $postback_url = false) { + return $this->processUpdateJob('emails', $emails, $update, $report_email, $postback_url); + } + + + /** + * Save existing user + * @param String $id + * @param Array $options + */ + public function saveUser($id, array $options = array()) { + $data = $options; + $data['id'] = $id; + return $this->apiPost('user', $data); + } + + + /** + * Creates new user + * @param Array $options + */ + public function createNewUser(array $options = array()) { + unset($options['id']); + return $this->apiPost('user', $options); + } + + /** + * Get user by Sailthru ID + * @param String $id + * @param Array $fields + */ + public function getUseBySid($id, array $fields = array()) { + return $this->apiGet('user', array('id' => $id)); + } + + /** + * Get user by specified key + * @param String $id + * @param String $key + * @param Array $fields + */ + public function getUserByKey($id, $key, array $fields = array()) { + $data = array( + 'id' => $id, + 'key' => $key, + 'fields' => $fields + ); + return $this->apiGet('user', $data); + } + + /** * * Set Horizon cookie @@ -779,11 +1108,17 @@ public function setHorizonCookie($email, $domain = null, $duration = null, $secu * @param array $headers * @return string */ - private function httpRequestCurl($url, $data, $method = 'POST') { + private function httpRequestCurl($url, array $data, $method = 'POST') { $ch = curl_init(); if ($method == 'POST') { curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&')); + if ($this->fileUpload === true) { + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + $this->fileUpload = false; + } + else { + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data, '', '&')); + } } else { $url .= '?' . http_build_query($data, '', '&'); if ($method != 'GET') { @@ -793,8 +1128,11 @@ private function httpRequestCurl($url, $data, $method = 'POST') { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: {$this->user_agent_string}")); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->httpHeaders); $data = curl_exec($ch); + $this->lastResponseInfo = curl_getinfo($ch); + curl_close($ch); if (!$data) { throw new Sailthru_Client_Exception("Bad response received from $url"); } @@ -811,6 +1149,11 @@ private function httpRequestCurl($url, $data, $method = 'POST') { * @return string */ private function httpRequestWithoutCurl($url, $data, $method = 'POST') { + if ($this->fileUpload === true) { + $this->fileUpload = false; + throw new Sailthru_Client_Exception('cURL extension is required for the request with file upload'); + } + $params = array('http' => array('method' => $method)); if ($method == 'POST') { $params['http']['content'] = is_array($data) ? http_build_query($data, '', '&') : $data; @@ -840,22 +1183,35 @@ private function httpRequestWithoutCurl($url, $data, $method = 'POST') { * @return string */ protected function httpRequest($url, $data, $method = 'POST') { - return $this->{$this->http_request_type}($url, $data, $method); + $response = $this->{$this->http_request_type}($url, $data, $method); + $json = json_decode($response, true); + if ($json === NULL) { + throw new Sailthru_Client_Exception("Response: {$response} is not a valid JSON"); + } + return $json; } + /** * Perform an API POST (or other) request, using the shared-secret auth hash. + * if binary_data_param is set, its appends '@' so that cURL can make binary POST request * * @param array $data * @return array */ - public function apiPost($action, $data, $method = 'POST') { - $data['api_key'] = $this->api_key; - $data['format'] = isset($data['format']) ? $data['format'] : 'php'; - $data['sig'] = Sailthru_Util::getSignatureHash($data, $this->secret); - $result = $this->httpRequest("$this->api_uri/$action", $data, $method); - $unserialized = @unserialize($result); - return $unserialized ? $unserialized : $result; + public function apiPost($action, $data, array $binary_data_param = array()) { + $binary_data = array(); + if (!empty ($binary_data_param)) { + foreach ($binary_data_param as $param) { + if (isset($data[$param]) && file_exists($data[$param])) { + $binary_data[$param] = "@{$data[$param]}"; + unset($data[$param]); + $this->fileUpload = true; + } + } + } + $payload = $this->prepareJsonPayload($data, $binary_data); + return $this->httpRequest("$this->api_uri/$action", $payload, 'POST'); } @@ -866,27 +1222,46 @@ public function apiPost($action, $data, $method = 'POST') { * @param array $data * @return array */ - public function apiGet($action, $data) { - $data['api_key'] = $this->api_key; - $data['format'] = isset($data['format']) ? $data['format'] : 'php'; - $data['sig'] = Sailthru_Util::getSignatureHash($data, $this->secret); - $result = $this->httpRequest("$this->api_uri/$action", $data, 'GET'); - $unserialized = @unserialize($result); - return $unserialized ? $unserialized : $result; + public function apiGet($action, $data, $method = 'GET') { + return $this->httpRequest("{$this->api_uri}/{$action}", $this->prepareJsonPayload($data), $method); } - /** + /** * Perform an API DELETE request, using the shared-secret auth hash. * * @param string $action * @param array $data * @return array - */ public function apiDelete($action, $data) { - return $this->apiPost($action, $data, 'DELETE'); + return $this->apiGet($action, $data, 'DELETE'); + } + + + /** + * get information from last server response when used with cURL + * returns associative array as per http://us.php.net/curl_getinfo + * @return array or null + */ + public function getLastResponseInfo() { + return $this->lastResponseInfo; } + + /** + * Prepare JSON payload + */ + protected function prepareJsonPayload(array $data, array $binary_data = array()) { + $payload = array( + 'api_key' => $this->api_key, + 'format' => 'json', //<3 XML + 'json' => json_encode($data) + ); + $payload['sig'] = Sailthru_Util::getSignatureHash($payload, $this->secret); + if (!empty($binary_data)) { + $payload = array_merge($payload, $binary_data); + } + return $payload; + } } -?> diff --git a/client/Sailthru_Client_Exception.php b/client/Sailthru_Client_Exception.php index 82919d2..b61ee4f 100755 --- a/client/Sailthru_Client_Exception.php +++ b/client/Sailthru_Client_Exception.php @@ -1,5 +1,5 @@ diff --git a/readme.txt b/readme.txt index ae6312b..d24f117 100644 --- a/readme.txt +++ b/readme.txt @@ -9,4 +9,5 @@ Wordpress widget for Sailthru API == Description == -Wordpress widget for Sailthru API (http://docs.sailthru.com/api). +For installation instructions, documentation, and examples please visit: +http://getstarted.sailthru.com/developers/api-libraries/wordpress diff --git a/sailthru.php b/sailthru.php index 8c6a114..c77d3f0 100644 --- a/sailthru.php +++ b/sailthru.php @@ -1,16 +1,16 @@ $list_name) { - $lists[$list_name] = in_array($id, $_POST['lists']) ? '1' : '0'; + if(in_array($id, $_POST['lists'])){ + $lists[$list_name]='1'; + } } } @@ -90,4 +92,4 @@ break; } -die(); \ No newline at end of file +die(); diff --git a/sailthru_form.php b/sailthru_form.php index 2665859..476c369 100644 --- a/sailthru_form.php +++ b/sailthru_form.php @@ -97,7 +97,7 @@ function get_all_lists() { //return array('426' => 'test'); //return array('pheonix', 'seed'); - $lists = $client->apiGet('list',false); + $lists = $client->apiGet('list',array()); $list_names = array(); foreach ($lists as $list) { diff --git a/sailthru_options.php b/sailthru_options.php index 319d27c..a09c19e 100644 --- a/sailthru_options.php +++ b/sailthru_options.php @@ -119,7 +119,7 @@ $_POST['subject'], $_POST['content'], $_POST['plaintext_body'], - array() + array("report_email" => $_POST['report_email']) ); if($r['status'] == 'scheduled') { @@ -199,6 +199,14 @@ + + + Report Email: + + + + + Select List: @@ -613,4 +621,4 @@ - \ No newline at end of file +