Advertisement
Guest User

Untitled

a guest
May 6th, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. bb<?php
  2.  
  3. class getresponse {
  4.  
  5. function getresponse() // constructor
  6. {
  7. }
  8.  
  9. //======== USER REGISTRATION / UPDATE / DELETE ========
  10. // Add if user not there, else update
  11. function register($userId, $productId, $params)
  12. {
  13. logToFile("getresponse.class.php: register()", LOG_INFO_DAP);
  14.  
  15. $dapuser = Dap_User::loadUserById($userId);
  16. $email = trim($dapuser->getEmail());
  17. $username = trim($dapuser->getUser_name());
  18. $firstname = trim($dapuser->getFirst_name());
  19. $lastname = trim($dapuser->getLast_name());
  20. $phone = trim($dapuser->getPhone());
  21.  
  22. $data = explode(":",$params);
  23.  
  24. logToFile("getresponse.class.php: register(): phone =" . $phone, LOG_INFO_DAP);
  25.  
  26. if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $email)) {
  27. logToFile("getresponse.class.php: register(): invalid email", LOG_INFO_DAP);
  28. return "Email address is invalid";
  29. }
  30.  
  31. // format: getresponse:<your API key>:<API username>:1:0
  32.  
  33. require_once 'jsonRPCClient.php';
  34.  
  35. # your API key
  36. # available at http://www.getresponse.com/my_api_key.html
  37. $api_key = $data[1];
  38. logToFile("getresponse.class.php: register(): api_key =" . $api_key, LOG_INFO_DAP);
  39.  
  40. # API 2.x URL
  41. $api_url = 'http://api2.getresponse.com';
  42.  
  43. # initialize JSON-RPC client
  44. $client = new jsonRPCClient($api_url);
  45. $compaign_name = $data[2];
  46. logToFile("getresponse.class.php: register(): compaign_name =" . $compaign_name, LOG_INFO_DAP);
  47.  
  48. $result = NULL;
  49.  
  50. # get CAMPAIGN_ID of the campaign
  51.  
  52. try {
  53. $result = $client->get_campaigns(
  54. $api_key,
  55. array (
  56. # find by name literally
  57. 'name' => array ( 'EQUALS' => $compaign_name )
  58. )
  59. );
  60.  
  61. logToFile("getresponse.class.php: register(): result returned", LOG_INFO_DAP);
  62.  
  63. }
  64. catch (Exception $e) {
  65. # check for communication and response errors
  66. # implement handling if needed
  67. logToFile("getresponse.class.php: register(): get_campaigns ERROR =" . $e->getMessage(), LOG_INFO_DAP);
  68. return ($e->getMessage());
  69. }
  70.  
  71. # uncomment this line to preview data structure
  72. # print_r($result);
  73.  
  74. # since there can be only one campaign of this name
  75. # first key is the CAMPAIGN_ID you need
  76. $CAMPAIGN_ID = array_pop(array_keys($result));
  77. logToFile("getresponse.class.php: register(): get_campaigns CAMPAIGN_ID =" . $CAMPAIGN_ID, LOG_INFO_DAP);
  78. # add contact to 'sample_marketing' campaign
  79. try {
  80.  
  81. $customs = array();
  82. if($phone!="")
  83. $customs[]= array('name' => 'phone','content' => $phone);
  84.  
  85. if($lastname!="")
  86. $customs[]= array('name' => 'lastname','content' => $lastname);
  87.  
  88.  
  89. $customsfound = count($customs);
  90. logToFile("getresponse.class.php: register(): customsfound =" . $customsfound, LOG_INFO_DAP);
  91.  
  92. if($customsfound > 0) {
  93. $result = $client->add_contact(
  94. $api_key,
  95. array (
  96. 'campaign' => $CAMPAIGN_ID,
  97. 'name' => $firstname,
  98. 'email' => $email,
  99. 'cycle_day' => '0',
  100. 'customs' => $customs
  101. )
  102. );
  103. }
  104. else {
  105. $result = $client->add_contact(
  106. $api_key,
  107. array (
  108. 'campaign' => $CAMPAIGN_ID,
  109. 'name' => $firstname,
  110. 'email' => $email,
  111. 'cycle_day' => '0'
  112. )
  113.  
  114. );
  115. }
  116.  
  117. }
  118.  
  119. catch (Exception $e) {
  120. # check for communication and response errors
  121. # implement handling if needed
  122. logToFile("getresponse.class.php: register(): add_contact ERROR =" . $e->getMessage(), LOG_INFO_DAP);
  123. return($e->getMessage());
  124. }
  125.  
  126. logToFile("getresponse.class.php: add_contact complete", LOG_INFO_DAP);
  127.  
  128. return 0;
  129. }
  130.  
  131. }
  132. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement