CC_Campaign

Class that is used for ConstantCampaign CRUD management.

Defined (1)

The class is defined in the following location(s).

/api/cc_class.php  
  1. class CC_Campaign extends CC_Utility { 
  2.  
  3. // set this to true to see the xml sent and the output received 
  4. var $sent_recived_debug = false; 
  5. var $usStates = array("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"); 
  6. var $caStates = array("AB", "BC", "MB", "NB", "NL", "NT", "NS", "NU", "ON", "PE", "QC", "SK", "YT"); 
  7. var $armedForces = array("AA", "AE", "AP"); 
  8.  
  9. /** 
  10. * Method that returns a html sample for email campaign 
  11. * @param string $sample [default is EmailContent]: EmailContent, EmailTextContent or 
  12. * PermissionReminder 
  13. * @param string $type [default is html]: html or text 
  14. * @return a default content for email content or permission reminder 
  15. */ 
  16. public function getEmailIntro($sample = 'EmailContent', $type = 'html') { 
  17. switch($sample) { 
  18. case 'EmailContent': 
  19. $file = 'EmailContent.txt'; 
  20. break; 
  21. case 'EmailTextContent': 
  22. $file = 'EmailContent.txt'; 
  23. $type = 'text'; 
  24. break; 
  25. case 'PermissionReminder': 
  26. $file = 'PermissionReminder.txt'; 
  27. break; 
  28. default: 
  29. $file = 'EmailContent.txt'; 
  30.  
  31. $handle = fopen("txt/$file", "rb"); 
  32. $contents = ''; 
  33. while (!feof($handle)) { 
  34. $contents .= fread($handle, 8192); 
  35. $contents = ($type == 'html') ? ($contents) : (trim(strip_tags($contents))); 
  36. fclose($handle); 
  37. return $contents; 
  38.  
  39.  
  40.  
  41.  
  42. /** 
  43. * Method that retrieves campaingn collections from ConstantCampaign 
  44. * If campaign_id is mentioned then only mentioned campaign is retrieved. 
  45. * If campaign_id represents a status [SENT, DRAFT, RUNNING, SCHEDULED] 
  46. * only the campaigns with that status will be retrieved 
  47. * @param string $campaign_id [default is empty] 
  48. * @return Bi-Dimenstional array with information about campaigns. 
  49. */ 
  50. public function getCampaigns($campaign_id = '', $page = '') { 
  51. $campaigns = array(); 
  52. $campaigns['items'] = array(); 
  53.  
  54. switch($campaign_id) { 
  55. case 'SENT': 
  56. case 'DRAFT': 
  57. case 'RUNNING': 
  58. case 'SCHEDULED': 
  59. $call = $this->apiPath.'/campaigns?status='.$campaign_id; 
  60. break; 
  61. case 'ALL': 
  62. $call = (!empty($page)) ? ($this->apiPath.$page) : ($this->apiPath.'/campaigns'); 
  63. break; 
  64. default: 
  65. $call = $this->apiPath.'/campaigns/'.$campaign_id; 
  66.  
  67. $return = $this->doServerCall($call); 
  68. $parsedReturn = simplexml_load_string($return); 
  69. //we parse here the link array to establish which are the next page and previous page 
  70. if($parsedReturn != false) { 
  71.  
  72. foreach ($parsedReturn->link as $item) { 
  73. $attributes = $item->Attributes(); 
  74. if (! empty($attributes['rel']) && $attributes['rel'] == 'next') { 
  75. $tmp = explode($this->login, $attributes['href']); 
  76. $campaigns['next'] = $tmp[1]; 
  77. if (! empty($attributes['rel']) && $attributes['rel'] == 'first') { 
  78. $tmp = explode($this->login, $attributes['href']); 
  79. $campaigns['first'] = $tmp[1]; 
  80. if (! empty($attributes['rel']) && $attributes['rel'] == 'current') { 
  81. $tmp = explode($this->login, $attributes['href']); 
  82. $campaigns['current'] = $tmp[1]; 
  83.  
  84. foreach ($parsedReturn->entry as $item) { 
  85. $tmp = array(); 
  86. $tmp['id'] = (string) $item->id; 
  87. $tmp['title'] = (string) $item->title; 
  88. $tmp['name'] = (string) $item->content->Campaign->Name; 
  89. $tmp['status'] = (string) $item->content->Campaign->Status; 
  90. $timestamp = strtotime($item->content->Campaign->Date); 
  91. $campaig_date = date("F j, Y, g:i a", $timestamp); 
  92. $tmp['date'] = (string) $campaig_date; 
  93. $campaigns['items'][] = $tmp; 
  94.  
  95. return $campaigns; 
  96.  
  97.  
  98. /** 
  99. * Retrieves all the details for a specific campaign identified by $id. 
  100. * @param string $id 
  101. * @return array with all information about the campaign. 
  102. */ 
  103. public function getCampaignDetails($id) { 
  104. if (!empty($id)) { 
  105. $fullContact = array(); 
  106. $call = str_replace('http://', 'https://', $id); 
  107. // Convert id URI to BASIC compliant 
  108. $return = $this->doServerCall($call); 
  109. $parsedReturn = simplexml_load_string($return); 
  110. $fullCampaign['campaignId'] = $parsedReturn->id; 
  111. $cmp_vars = get_object_vars($parsedReturn->content->Campaign); 
  112.  
  113. foreach ($cmp_vars as $var_name=>$cmp_item) { 
  114. $fullCampaign[$var_name] = $cmp_item; 
  115.  
  116. $cmp_from_email = $parsedReturn->content->Campaign->FromEmail->EmailAddress; 
  117. $fullCampaign['FromEmail'] = (string) $cmp_from_email; 
  118. $cmp_reply_email = $parsedReturn->content->Campaign->ReplyToEmail->EmailAddress; 
  119. $fullCampaign['ReplyToEmail'] = (string) $cmp_reply_email; 
  120. $fullCampaign['lists'] = array(); 
  121.  
  122. if ($parsedReturn->content->Campaign->ContactLists->ContactList) { 
  123. foreach ($parsedReturn->content->Campaign->ContactLists->ContactList as $item) { 
  124. $fullCampaign['lists'][] = trim((string) $item->Attributes()); 
  125. return $fullCampaign; 
  126. } else { 
  127. return false; 
  128.  
  129. /** 
  130. * Check if a specific campaign exist already 
  131. * @param string $id 
  132. * @param string $new_name 
  133. * @return a boolean value. 
  134. */ 
  135. public function campaignExists($id = '', $new_name) { 
  136. if(!empty($id)) { 
  137. $call = $this->apiPath.'/campaigns/'.$id; 
  138. $return = $this->doServerCall($call); 
  139. $xml = simplexml_load_string($return); 
  140. if ($xml !== false) { 
  141. $id = $xml->content->Campaign->Attributes(); 
  142. $id = $id['id']; 
  143. $name = $xml->content->Campaign->Name; 
  144. } else { 
  145. $id = null; 
  146. $name = null; 
  147. $all_campaigns = $this->getCampaigns('ALL'); 
  148. $all_campaigns = $all_campaigns['items']; 
  149. foreach ($all_campaigns as $key=>$item) { 
  150. if ($item['name'] == $new_name) { 
  151. return 1; // 1 - the new campaign has a similar name with an old one 
  152. break; 
  153. /** 
  154. * 2 - this campaign already exist 
  155. * 0 - this is a new campaign 
  156. */ 
  157. return ($id != null) ? (2) : (0); 
  158.  
  159.  
  160.  
  161. /** 
  162. * Method that delete a camaign; this will exclude 
  163. * the removed campaign from overall statistics 
  164. * @param string $id - campaign id 
  165. * @return TRUE in case of success or FALSE otherwise 
  166. */ 
  167. public function deleteCampaign($id) { 
  168. if ( empty($id)) { return false; } 
  169. $return = $this->doServerCall($id, '', 'DELETE'); 
  170. if (! empty($return) || $return === false) { return false; } 
  171. return true; 
  172.  
  173. /** 
  174. * Upload a new campaign to ConstantContact server 
  175. * @param string $campaignXML - formatted XML with campaign information 
  176. * @return TRUE in case of success or FALSE otherwise 
  177. */ 
  178. public function addCampaign($campaignXML) { 
  179. $call = $this->apiPath.'/campaigns'; 
  180. $return = $this->doServerCall($call, $campaignXML, 'POST'); 
  181. $parsedReturn = simplexml_load_string($return); 
  182. if ($return) { 
  183. return true; 
  184. } else { 
  185. $xml = simplexml_load_string($campaignXML); 
  186. $cmp_id = $xml->content->Campaign->Attributes(); 
  187. $cmp_id = $cmp_id['id']; 
  188. $cmp_name = $xml->content->Campaign->Name; 
  189. if(!empty($cmp_id)) { 
  190. $search_status = $this->campaignExists($cmp_id, $cmp_name); 
  191. switch($search_status) { 
  192. case 0: 
  193. $error = 'An Error Occurred. The campaign could not be added.'; 
  194. break; 
  195. case 1: 
  196. $error = 'The name of the campaign already exist. Each campaign must have a distinct name.'; 
  197. break; 
  198. case 2: 
  199. $error = 'This campaign already exists.'; 
  200. break; 
  201. default: 
  202. $error = 'An Error Occurred. The campaign could not be added.'; 
  203. $this->lastError = $error; 
  204. } else { 
  205. $this->lastError = 'An Error Occurred. The campaign could not be added.'; 
  206. return false; 
  207.  
  208.  
  209. /** 
  210. * Modifies a campaign 
  211. * @param string $campaignId - identifies the id for the modified campaign 
  212. * @param string $campaignXML - formed XML with campaign information 
  213. * @return TRUE in case of success or FALSE otherwise 
  214. */ 
  215. public function editCampaign($campaignId, $campaignXML) { 
  216. $return = $this->doServerCall($campaignId, $campaignXML, 'PUT'); 
  217. if ($return === false) { 
  218. $this->lastError = 'An Error Occurred. The campaign could not be edited.'; 
  219. return false; 
  220. } else { 
  221. if (! empty($return)) { 
  222. if (strpos($return, '<') !== false) { 
  223. $parsedReturn = simplexml_load_string($return); 
  224. if (! empty($parsedReturn->message)) { 
  225. $this->lastError = $parsedReturn->message; 
  226. } else { 
  227. $this->lastError = $parsedReturn->message; 
  228. return false; 
  229. return true; 
  230.  
  231. /** 
  232. * Method that validate the current campaign before sending it to server 
  233. * @param string $id 
  234. * @param array $params 
  235. * @return an error message or true 
  236. */ 
  237. public function validateCampaign( $id, $params = array() ) { 
  238. if( trim($params['cmp_name'])== '' ) { 
  239. $this->lastError = '<i>Campaign Name</i> is mandatory.'; 
  240. return true; 
  241. } elseif( trim($params['cmp_subject'])== '' ) { 
  242. $this->lastError = '<i>Subject</i> is mandatory.'; 
  243. return true; 
  244. } elseif( trim($params['cmp_from_name'])== '' ) { 
  245. $this->lastError = '<i>From Name</i> is mandatory.'; 
  246. return true; 
  247. } elseif( trim($params['cmp_from_email'])== '' ) { 
  248. $this->lastError = '<i>From Email Address</i> is mandatory.'; 
  249. return true; 
  250. } elseif( trim($params['cmp_reply_email'])== '' ) { 
  251. $this->lastError = '<i>Reply Email Address</i> is mandatory.'; 
  252. return true; 
  253. } elseif( trim($params['cmp_grt_name'])== '' ) { 
  254. $this->lastError = '<i>Greeting Name</i> is mandatory.'; 
  255. return true; 
  256. } elseif( trim($params['cmp_org_name'])== '' ) { 
  257. $this->lastError = '<i>Organization Name</i> is mandatory.'; 
  258. return true; 
  259. } elseif( trim($params['cmp_org_addr1'])== '' ) { 
  260. $this->lastError = '<i>Address 1</i> is mandatory.'; 
  261. return true; 
  262. } elseif( trim($params['cmp_org_city'])== '' ) { 
  263. $this->lastError = '<i>City</i> is mandatory.'; 
  264. return true; 
  265. } elseif( trim($params['org_zip'])== '' ) { 
  266. $this->lastError = '<i>Zip/Postal Code</i> is mandatory.'; 
  267. return true; 
  268. } elseif( trim($params['org_country'])== '' ) { 
  269. $this->lastError = '<i>Country</i> is mandatory.'; 
  270. return true; 
  271. } elseif( trim($params['cmp_html_body'])== '' ) { 
  272. $this->lastError = '<i>HTML Body</i> is mandatory.'; 
  273. return true; 
  274. } elseif ( $params["lists"] == NULL ) { 
  275. $this->lastError = 'Choose at least <i>one Campaign</i> from the list.'; 
  276. return true; 
  277. } else { 
  278. if( trim($params['cmp_perm_reminder'])== 'YES') { 
  279. $reminder_text = $params['cmp_txt_reminder']; 
  280. if(trim($reminder_text)== '') { 
  281. $this->lastError = '<i>Permission Reminder</i> is required.'; 
  282. return true; 
  283. if(trim($params['org_country']) != '') { 
  284. if( trim($params['org_country'])== 'us' ) { 
  285. if(trim($params['org_state_us']) == '' ) { 
  286. $this->lastError = '<i>State</i> is mandatory.'; 
  287. return true; 
  288. if ( in_array($params['org_state_us'], $this->caStates) ) { 
  289. $this->lastError = '<i>US State</i> is required.'; 
  290. return true; 
  291. } elseif( trim($params['org_country'])== 'ca' ) { 
  292. if(trim($params['org_state_us']) == '' ) { 
  293. $this->lastError = '<i>State</i> is mandatory.'; 
  294. return true; 
  295. if ( in_array($params['org_state_us'], $this->usStates) ) { 
  296. $this->lastError = '<i>CA State</i> is required.'; 
  297. return true; 
  298. if( trim($params['cmp_as_webpage'])== 'YES' ) { 
  299. if(trim($params['cmp_as_webtxt'])== '') { 
  300. $this->lastError = '<i>Webpage Text</i> is required.'; 
  301. return true; 
  302. if(trim($params['cmp_as_weblink'])== '') { 
  303. $this->lastError = '<i>Webpage Link Text</i> is required.'; 
  304. return true; 
  305. if( trim($params['cmp_forward'])== 'YES') { 
  306. $fwd_email = $params['cmp_fwd_email']; 
  307. if(trim($params['cmp_fwd_email'])== '') { 
  308. $this->lastError = '<i>Forward email</i> is required.'; 
  309. return true; 
  310. if( trim($params['cmp_subscribe'])== 'YES') { 
  311. if(trim($params['cmp_sub_link'])== '') { 
  312. $this->lastError = '<i>Subscribe me</i> is required.'; 
  313. return true; 
  314. else { return false; } 
  315.  
  316.  
  317. /** 
  318. * Method that compose the needed XML format for a campaign 
  319. * @param string $id 
  320. * @param array $params 
  321. * @return Formed XML 
  322. */ 
  323. public function createCampaignXML( $id, $params = array() ) { 
  324. if (empty($id)) { // Add a new Campaign 
  325. $id = str_replace('https://', 'http://', $this->apiPath."/campaigns/1100546096289"); 
  326. $standard_id = str_replace('https://', 'http://', $this->apiPath."/campaigns"); 
  327. } else { 
  328. $standard_id = $id; 
  329. $href = str_replace("http://api.constantcontact.com", "", $id); 
  330. $standard_href = str_replace("https://api.constantcontact.com", "", $this->apiPath."/campaigns"); $update_date = date("Y-m-d").'T'.date("H:i:s").'+01:00'; 
  331. $xml_string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><entry xmlns='http://www.w3.org/2005/Atom'></entry>"; 
  332. $xml_object = simplexml_load_string($xml_string); 
  333. $link_node = $xml_object->addChild("link"); 
  334. $link_node->addAttribute("href", $standard_href); //[1st *href] 
  335. $link_node->addAttribute("rel", "edit"); 
  336. $id_node = $xml_object->addChild("id", $standard_id); //[1st *id] 
  337. $title_node = $xml_object->addChild("title", htmlspecialchars($params['cmp_name'], ENT_QUOTES, 'UTF-8')); 
  338. $title_node->addAttribute("type", "text"); 
  339. $updated_node = $xml_object->addChild("updated", htmlentities($update_date)); 
  340. $author_node = $xml_object->addChild("author"); 
  341. $author_name = $author_node->addChild("name", htmlentities("Constant Contact")); 
  342. $content_node = $xml_object->addChild("content"); 
  343. $content_node->addAttribute("type", "application/vnd.ctct+xml"); 
  344. $campaign_node = $content_node->addChild("Campaign"); 
  345. $campaign_node->addAttribute("xmlns", "http://ws.constantcontact.com/ns/1.0/"); 
  346. $campaign_node->addAttribute("id", $id); //[2nd *id] 
  347. $name_node = $campaign_node->addChild("Name", urldecode(htmlspecialchars($params['cmp_name'], ENT_QUOTES, 'UTF-8'))); 
  348. $campaign_status = !empty($params['cmp_status']) ? ($params['cmp_status']) : ('Draft'); 
  349. $status_node = $campaign_node->addChild("Status", urldecode(htmlentities($campaign_status))); 
  350. $campaign_date = !empty($params['cmp_date']) ? ($params['cmp_date']) : ($update_date); 
  351. $date_node = $campaign_node->addChild("Date", urldecode(htmlentities($campaign_date))); 
  352. $subj_node = $campaign_node->addChild("Subject", urldecode(htmlspecialchars($params['cmp_subject'], ENT_QUOTES, 'UTF-8'))); 
  353. $from_name_node = $campaign_node->addChild("FromName", urldecode(htmlspecialchars($params['cmp_from_name'], ENT_QUOTES, 'UTF-8'))); 
  354. $view_as_webpage = (!empty($params['cmp_as_webpage']) && $params['cmp_as_webpage'] == 'YES') ? ('YES') : ('NO'); 
  355. $as_webpage_node = $campaign_node->addChild("ViewAsWebpage", urldecode(htmlentities($view_as_webpage))); 
  356. #$as_web_lnk_txt = ($view_as_webpage == 'YES') ? ($params['cmp_as_weblink']) : (''); 
  357. $as_web_lnk_txt = $params['cmp_as_weblink']; 
  358. $as_weblink_node = $campaign_node->addChild("ViewAsWebpageLinkText", urldecode(htmlspecialchars(($as_web_lnk_txt), ENT_QUOTES, 'UTF-8'))); 
  359. #$as_web_txt = ($view_as_webpage == 'YES') ? ($params['cmp_as_webtxt']) : (''); 
  360. $as_web_txt = $params['cmp_as_webtxt']; 
  361. $as_webtxt_node = $campaign_node->addChild("ViewAsWebpageText", urldecode(htmlspecialchars(($as_web_txt), ENT_QUOTES, 'UTF-8'))); 
  362. $perm_reminder_node = $campaign_node->addChild("PermissionReminder", urldecode(htmlentities($params['cmp_perm_reminder']))); 
  363. $permission_reminder_text = ($params['cmp_perm_reminder'] == 'YES') ? ($params['cmp_txt_reminder']) : (''); 
  364. $text_reminder_node = $campaign_node->addChild("PermissionReminderText", urldecode(htmlspecialchars(($permission_reminder_text), ENT_QUOTES, 'UTF-8'))); 
  365. $grt_sal_node = $campaign_node->addChild("GreetingSalutation", htmlspecialchars(($params['cmp_grt_sal']), ENT_QUOTES, 'UTF-8')); 
  366. $grt_name_node = $campaign_node->addChild("GreetingName", htmlentities($params['cmp_grt_name'])); 
  367. $grt_str_node = $campaign_node->addChild("GreetingString", htmlspecialchars($params['cmp_grt_str'], ENT_QUOTES, 'UTF-8')); 
  368. $org_name_node = $campaign_node->addChild("OrganizationName", htmlspecialchars($params['cmp_org_name'], ENT_QUOTES, 'UTF-8')); 
  369. $org_addr1_node = $campaign_node->addChild("OrganizationAddress1", htmlspecialchars($params['cmp_org_addr1'], ENT_QUOTES, 'UTF-8')); 
  370. $org_addr2_node = $campaign_node->addChild("OrganizationAddress2", htmlspecialchars($params['cmp_org_addr2'], ENT_QUOTES, 'UTF-8')); 
  371. $org_addr3_node = $campaign_node->addChild("OrganizationAddress3", htmlspecialchars($params['cmp_org_addr3'], ENT_QUOTES, 'UTF-8')); 
  372. $org_city_node = $campaign_node->addChild("OrganizationCity", htmlspecialchars($params['cmp_org_city'], ENT_QUOTES, 'UTF-8')); 
  373. switch($params['org_country']) { 
  374. case 'us': 
  375. $us_state = $params['org_state_us']; 
  376. break; 
  377. case 'ca': 
  378. $us_state = $params['org_state_us']; 
  379. break; 
  380. default: 
  381. $us_state = ''; 
  382. $org_state_us_node = $campaign_node->addChild("OrganizationState", htmlentities($us_state)); 
  383. switch($params['org_country']) { 
  384. case 'us': 
  385. $international_state = ''; 
  386. break; 
  387. case 'ca': 
  388. $international_state = ''; 
  389. break; 
  390. default: 
  391. $international_state = htmlspecialchars($params['org_state'], ENT_QUOTES, 'UTF-8'); 
  392. $org_state_name = $campaign_node->addChild("OrganizationInternationalState", htmlentities($international_state)); 
  393. $org_country_node = $campaign_node->addChild("OrganizationCountry", htmlentities($params['org_country'])); 
  394. $org_zip_node = $campaign_node->addChild("OrganizationPostalCode", htmlspecialchars($params['org_zip'], ENT_QUOTES, 'UTF-8')); 
  395. $include_fwd_email = (!empty($params['cmp_forward']) && $params['cmp_forward'] == 'YES') ? ('YES') : ('NO'); 
  396. #$fwd_txt = ($include_fwd_email == 'YES') ? ($params['cmp_fwd_email']) :(''); 
  397. $fwd_txt = $params['cmp_fwd_email']; 
  398. $fwd_node = $campaign_node->addChild("IncludeForwardEmail", htmlentities($include_fwd_email)); 
  399. $fwd_email_node = $campaign_node->addChild("ForwardEmailLinkText", htmlspecialchars(($fwd_txt), ENT_QUOTES, 'UTF-8')); 
  400. $include_sub_link = (!empty($params['cmp_subscribe']) && $params['cmp_subscribe'] == 'YES') ? ('YES') : ('NO'); 
  401. $sub_node = $campaign_node->addChild("IncludeSubscribeLink", htmlentities($include_sub_link)); 
  402. #$sub_txt = ($include_sub_link == 'YES') ? ($params['cmp_sub_link']) : (''); 
  403. $sub_txt = $params['cmp_sub_link']; 
  404. $sub_link_node = $campaign_node->addChild("SubscribeLinkText", htmlspecialchars(($sub_txt), ENT_QUOTES, 'UTF-8')); 
  405. $email_format_node = $campaign_node->addChild("EmailContentFormat", $params['cmp_mail_type']); 
  406. if($params['cmp_type'] != 'STOCK') { 
  407. $html_body_node = $campaign_node->addChild("EmailContent", htmlspecialchars($params['cmp_html_body'], ENT_QUOTES, 'UTF-8')); 
  408. $text_body_node = $campaign_node->addChild("EmailTextContent", "<Text>".htmlspecialchars(strip_tags($params['cmp_text_body']), ENT_QUOTES, 'UTF-8')."</Text>"); 
  409. $campaign_style_sheet = ($params['cmp_mail_type'] == 'XHTML') ? ($params['cmp_style_sheet']) : (''); 
  410. $style_sheet_node = $campaign_node->addChild("StyleSheet", htmlspecialchars($campaign_style_sheet, ENT_QUOTES, 'UTF-8')); 
  411. $campaignlists_node = $campaign_node->addChild("ContactLists"); 
  412.  
  413. if ($params['lists']) { 
  414. foreach ($params['lists'] as $list) { 
  415. $campaignlist_node = $campaignlists_node->addChild("ContactList"); 
  416. $campaignlist_node->addAttribute("id", $list); 
  417. $campaignlink_node = $campaignlist_node->addChild("link"); 
  418. $campaignlink_node->addAttribute("xmlns", "http://www.w3.org/2005/Atom"); 
  419. $campaignlink_node->addAttribute("href", str_replace("http://api.constantcontact.com", "", $list)); 
  420. $campaignlink_node->addAttribute("rel", "self"); 
  421.  
  422. $cmp_from_email = explode('|', $params['cmp_from_email']); 
  423. $fromemail_node = $campaign_node->addChild("FromEmail"); 
  424. $femail_node = $fromemail_node->addChild("Email"); 
  425. $femail_node->addAttribute("id", $cmp_from_email[1]); 
  426. $femail_node_link = $femail_node->addChild("link"); 
  427. $femail_node_link->addAttribute("xmlns", "http://www.w3.org/2005/Atom"); 
  428. $femail_node_link->addAttribute("href", str_replace("http://api.constantcontact.com", "", $cmp_from_email[1])); 
  429. $femail_node_link->addAttribute("rel", "self"); 
  430. $femail_addrs_node = $fromemail_node->addChild("EmailAddress", htmlentities($cmp_from_email[0])); $cmp_reply_email = explode('|', $params['cmp_reply_email']); 
  431. $replyemail_node = $campaign_node->addChild("ReplyToEmail"); 
  432. $remail_node = $replyemail_node->addChild("Email"); 
  433. $remail_node->addAttribute("id", $cmp_reply_email[1]); 
  434. $remail_node_link = $remail_node->addChild("link"); 
  435. $remail_node_link->addAttribute("xmlns", "http://www.w3.org/2005/Atom"); 
  436. $remail_node_link->addAttribute("href", str_replace("http://api.constantcontact.com", "", $cmp_reply_email[1])); 
  437. $remail_node_link->addAttribute("rel", "self"); 
  438. $remail_addrs_node = $replyemail_node->addChild("EmailAddress", htmlentities($cmp_reply_email[0])); $source_node = $xml_object->addChild("source"); 
  439. $sourceid_node = $source_node->addChild("id", $standard_id); //[3th *id] 
  440. $sourcetitle_node = $source_node->addChild("title", "Campaigns for customer: ".$this->login); 
  441. $sourcetitle_node->addAttribute("type", "text"); 
  442. $sourcelink1_node = $source_node->addChild("link"); 
  443. $sourcelink1_node->addAttribute("href", "campaigns"); //[2nd *href] 
  444. $sourcelink2_node = $source_node->addChild("link"); 
  445. $sourcelink2_node->addAttribute("href", "campaigns"); //[3th *href] 
  446. $sourcelink2_node->addAttribute("rel", "self"); 
  447. $sourceauthor_node = $source_node->addChild("author"); 
  448. $sauthor_name = $sourceauthor_node->addChild("name", $this->login); 
  449. $sourceupdate_node = $source_node->addChild("updated", htmlentities($update_date)); 
  450.  
  451. $entry = $xml_object->asXML(); 
  452. $search = array('>', '\"', ' ', ' ', '"/>', '&', '&lt;', '', ''); 
  453. $replace = array('>', '"', '', '', '" />', '&', '<', '&Yuml;', '&yuml;'); 
  454. $entry = str_replace($search, $replace, $entry); 
  455.  
  456. if( $this->sent_recived_debug ) { 
  457. echo "<div><p style=\"color: blue\">We sent the following XML:</p> $entry </div><hr/>"; 
  458.  
  459. return $entry; 
  460.