Source of file BoltMailHelper.php
Size: 3,613 Bytes - Last Modified: 2021-12-24T06:39:34+00:00
/var/www/docs.ssmods.com/process/src/code/helpers/BoltMailHelper.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 | <?php class BoltMailHelper { public $username = ''; public $usertoken = ''; function __construct($username='', $usertoken='') { $this->username = $username; $this->usertoken = $usertoken; } function GetResult($requesttype, $requestmethod, $details_xml='') { $xml = '<xmlrequest> <username>'.$this->username.'</username> <usertoken>'.$this->usertoken.'</usertoken> <requesttype>'.$requesttype.'</requesttype> <requestmethod>'.$requestmethod.'</requestmethod> <details> '.$details_xml.' </details> </xmlrequest>'; $ch = curl_init('http://www.boltmail.co.nz/boltmail/xml.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); $result = @curl_exec($ch); //exit($result); if($result === false) { return array( 'Success' => false, 'ErrorMessage' => "Error performing request. Failed to connect to mailing list server, please try again later.", 'Data' => '' ); } else { $xml_doc = simplexml_load_string($result); if ($xml_doc->status == 'SUCCESS') { return array( 'Success' => true, 'ErrorMessage' => "" , 'Data' => $xml_doc->data ); } else { return array( 'Success' => false, 'ErrorMessage' => (string) $xml_doc->errormessage, 'Data' => '' ); } } } function AddSubscriberToList($email, $listid, $customfields=array()) { $xml = '<emailaddress>'.$email.'</emailaddress> <mailinglist>'.$listid.'</mailinglist> <format>html</format> <confirmed>yes</confirmed>'; if (count($customfields)) { $xml .= '<customfields>'; foreach ($customfields as $k => $v) { $xml .= '<item> <fieldid>'.$k.'</fieldid> <value>'.$v.'</value> </item>'; } $xml .= '</customfields>'; } $result = $this->GetResult('subscribers', 'AddSubscriberToList', $xml); if (!$result['Success'] && is_numeric($result['ErrorMessage'])) { // Subscriber is already subscribed! // Lets update their details instead, no API exists for this? WTF? $result['ErrorMessage'] = 'You are already subscribed to this list.'; } return $result; } function GetLists() { return $this->GetResult('user', 'GetLists', ''); } function GetArchive($listids, $titleLen=40) { if (!is_array($listids)) $listids = array($listids); $lists = array(); //$listids = explode(',', $this->BoltMailListIds); foreach ($listids as $listid) { $lists[] = 'http://www.boltmail.co.nz/boltmail/rss.php?List='.$listid; } $feed = new SimplePie(); // Set which feed to process. $feed->set_feed_url($lists); // Setup a cahce dir $feed->set_cache_location(TEMP_FOLDER); // Run SimplePie. $feed->init(); // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). //$feed->handle_content_type(); $duplicates = array(); $array = array(); foreach ($feed->get_items() as $item) { $url = $item->get_permalink(); $n = array(); preg_match("#N=([0-9]+)#smi", $url, $n); if (isset($n[1])) { if (in_array($n[1],$duplicates)) continue; $duplicates[] = $n[1]; } $title = $item->get_title(); if ($title == 'No email campaigns have been sent') continue; if (strlen($title) > $titleLen) { $title = substr($title, 0, $titleLen).'...'; } array_push($array, array( 'FullTitle' => $item->get_title(), 'Title' => $title, 'URL' => $url, 'FormattedDate' => $item->get_date('F Y') )); } return new DataObjectSet($array); } } ?> |